akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2005;

int x, y, n, m, Ids, answer;
int level[Nmax], t[Nmax];
bool done[Nmax], rev[Nmax<<2], erased[Nmax];
vector<int> v[Nmax];

struct Edge
{
    int x, y, id;
};
vector<Edge> edge;

void Erase(vector<int> &v, int val)
{
    v.erase(find(v.begin(), v.end(), val));
}

bool cmp(Edge a)
{
    return a.x == a.y;
}

void dfs(int node)
{
    for(auto son : v[node])
    {
        Erase(v[son], node);
        t[son] = node;
        level[son] = level[node] + 1;
        dfs(son);
    }
}

int best(int x, int y, int z)
{
    if(x == y || x == z) return x;
    if(y == z) return y;

    if(level[x] >= level[y] && level[x] >= level[z]) return best(t[x], y, z);
    if(level[y] > level[z]) return best(x, t[y], z);
    return best(x, y, t[z]);
}

void mark_all(int x, int y)
{
    while(x != y)
    {
        if(level[x] > level[y]) done[x] = 1, x = t[x];
            else done[y] = 1, y = t[y];
    }
}

void solve(vector<Edge> &w)
{
    int i, leaf = 0;
    for(i=1; !leaf; ++i)
        if(v[i].empty() && !erased[i]) leaf = i;

    if(leaf == 1) return;
    Erase(v[t[leaf]], leaf);
    erased[leaf] = 1;

    w.erase(remove_if(w.begin(), w.end(), cmp), w.end());

    int a=0, b=0;
    Edge e1, e2;
    bool change1, change2;

    vector<Edge> nw;

    for(auto e : w)
        if(e.x == leaf)
        {
            if(!a) e1 = e, change1 = 0, a = e.y;
                else if(!b) e2 = e, change2 = 0, b = e.y;
                    else nw.push_back({ t[leaf], e.y, e.id });
        }
        else if(e.y == leaf)
        {
            if(!a) e1 = e, change1 = 1, a = e.x;
                else if(!b) e2 = e, change2 = 1, b = e.x;
                    else nw.push_back({ e.x, t[leaf], e.id });
        }
        else nw.push_back(e);

    if(!a)
    {
        if(done[leaf]) answer += 2;
        solve(w);
        return;
    }

    if(done[leaf] || b) answer += 2;
        else answer ++;

    if(!b || done[leaf])
    {
        if(!change1) e1.x = t[leaf];
            else e1.y = t[leaf];
        nw.push_back(e1);

        if(b)
        {
            if(!change2) e2.x = t[leaf];
                else e2.y = t[leaf];
            nw.push_back(e2);
        }

        solve(nw);
        return;
    }

    int go = best(a, b, t[leaf]);
    mark_all(go, leaf);

    int curr = ++Ids;
    nw.push_back({a, b, Ids});

    solve(nw);

    rev[e1.id] = rev[curr] ^ change1 ^ 1;
    rev[e2.id] = rev[curr] ^ change2;
}

int main()
{
 //   freopen("input", "r", stdin);
 //   freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n >> m;
    int i;
    for(i=1; i<n; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    dfs(1);

    for(i=1; i<=m; ++i)
    {
        cin >> x >> y;
        edge.push_back({x, y, i});
    }

    Ids = m;
    solve(edge);
    cout << answer << '\n';
    for(auto e : edge)
    {
        if(rev[e.id]) swap(e.x, e.y);
        cout << e.x << ' ' << e.y << '\n';
    }

    return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);

	ll n, maxWeight;
	cin >> n >> maxWeight;
	ll values[n+1], weights[n+1], knap[n+1][maxWeight+1];
	weights[0] = values[0] = 0;

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

	for (int i = 0; i <= n; ++i)
		knap[i][0] = 0;

	for (int i = 0; i <= maxWeight; ++i)
		knap[0][i] = 0;

	for (int i = 1; i <= n; i++)
	{
		for (int m = 1; m <= maxWeight; m++)
		{
			if (weights[i] > m)
				knap[i][m] = knap[i-1][m];
			else
				knap[i][m] = max(values[i] + knap[i-1][m-weights[i]], knap[i-1][m]);
		}
	}

	cout << knap[n][maxWeight] << endl;

	return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

void solve() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;

	vector<int64> a(x), b(y), c(z);

	for(auto& elem: a) {
		cin >> elem;
	}

	for(auto& elem: b) {
		cin >> elem;
	}

	for(auto& elem: c) {
		cin >> elem;
	}

	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	sort(c.rbegin(), c.rend());

	vector<int64> answ;

	for(int i = 0; i < x; ++i) {
		for(int j = 0; j < y; ++j) {
			for(int l = 0; l < z; ++l) {
				int before = (i + 1) * (j + 1) * (l + 1) - 1;

				if(before > k) {
					break;
				}

				answ.push_back(a[i] + b[j] + c[l]);
			}
		}
	}

	sort(answ.rbegin(), answ.rend());

	for(int i = 0; i < k; ++i) {
		cout << answ[i] << '\n';
	}
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1404
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        long min = Long.MAX_VALUE;
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                min = Math.min(min, i + (n / i) - 2);
            }
        }
        System.out.println(min);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
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;
}
const long long INF = 1LL << 60;
int cnt = 0;
int main()
{
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n)
    {
        cin >> a[i];
    }

    ll ans = 0;
    bool flag = true;
    while (1)
    {
        rep(i, n)
        {
            if (a[i] % 2 == 0)
            {
                a[i] /= 2;
            }
            else
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
}


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

#define ll long long
#define ull unsigned long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()

//ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

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

    string s;
    cin >> s;
    if (s.back() == 's')
        cout << s << "es";
    else
        cout << s << 's';
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N, a[4];
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[j];
        }
        sort(a, a + 3);
        cout << (a[0]*a[0] + a[1]*a[1] == a[2]*a[2] ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N;
    cin >> N;

    vector<ll> v(N);

    rep(i, 0, N) cin >> v[i];

    map<ll, int> guu, ki;

    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            guu[v[i]]++;
        } else {
            ki[v[i]]++;
        }
    }

    using P = pair<int, int>;
    vector<P> kip, gup; //出現数、キー

    for (auto e : guu) {
        P p(e.second, e.first);
        gup.push_back(p);
    }

    for (auto e : ki) {
        P p(e.second, e.first);
        kip.push_back(p);
    }

    sort(all(gup));
    reverse(all(gup));

    sort(all(kip));
    reverse(all(kip));

    if (kip.front().second == gup.front().second) {
        if (kip.size() == 1 && gup.size() == 1) {
            cout << N / 2 << endl;
        } else if (kip.size() == 1) {
            ll kouho1 = N - kip.front().first - gup[1].first;
            ll kouho2 = N - N / 2 - gup.front().first;

            cout << min(kouho1, kouho2) << endl;
        } else if (gup.size() == 1) {
            ll kouho1 = N - gup.front().first - kip[1].first;
            ll kouho2 = N - N / 2 - kip.front().first;
            cout << min(kouho1, kouho2) << endl;
        } else {
            ll kouho1 = N - kip[0].first - gup[1].first;
            ll kouho2 = N - kip[1].first - gup[0].first;
            cout << min(kouho1, kouho2) << endl;
        }
    } else {
        ll ans = N - kip.front().first - gup.front().first;
        cout << ans << endl;
    }

//    int guu_max = 0, ki_max = 0;
//
//    for(auto e : guu){
//        chmax(guu_max,e.second);
//    }
//
//    for(auto e : ki){
//        chmax(ki_max,e.second);
//    }

//    ll ans = N / 2 - guu_max + N / 2 - ki_max;
//
//    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 8444
//
// Created by kapildd on 10/5/17.
//
#include <bits/stdc++.h>
#define MAX_X 5010
#define MAX_VAL (1e9)
using namespace std;

long long dfs(int v, vector< vector<int> >& adj, vector<int>& X) {
    vector<long long> dp(MAX_X, MAX_VAL);
    vector<long long> extra(MAX_X, MAX_VAL);
    dp[0] = 0;
    for(int i=0; i<adj[v].size(); i++) {
        int u = adj[v][i];
        long long white = dfs(u, adj, X);
        //if(white==MAX_VAL) continue;
        fill(extra.begin(), extra.end(), MAX_VAL);
        for(int j=0; j<MAX_X-white; j++) {
            extra[j+white] = min(extra[j+white], dp[j]+X[u]);
        }
        for(int j=0; j< MAX_X-X[u]; j++) {
            extra[j+X[u]] = min(extra[j+X[u]], dp[j]+white);
        }
        swap(extra, dp);
    }
    long long min_w = MAX_VAL;
    for(int i=0; i<=X[v]; i++) {
        min_w = min(min_w, dp[i]);
    }
    return min_w;
}

int main() {
    int n;
    cin>>n;
    vector<int> parent(n+1, 0), X(n+1);
    vector< vector<int> > adj(n+1);
    for(int i=2; i<=n; i++) {
        cin>>parent[i];
        adj[parent[i]].push_back(i);
    }
    for(int i=1; i<=n; i++) {
        cin>>X[i];
    }
    string ans = "IMPOSSIBLE";
    long long cval = dfs(1, adj, X);
    if(cval>=0 && cval<MAX_VAL)
        ans = "POSSIBLE";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34028
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int a[5], k, min=124, max=0;
	rep(i,5){
		cin >> a[i];
		if(a[i] < min) min = a[i];
		if(a[i] > max) max = a[i];
	}
	cin >> k;
	if(max-min > k) puts(":(");
	else puts("Yay!");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(max(max(a,b),c) == a)
    {
        cout << b * c / 2;
    }
    else if(max(max(a,b),c) == b)
    {
        cout << c * a / 2;
    }
    else
    {
        cout << a * b / 2;
    }

    return 0;
}

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

C=0
for i in range(N):
  p=B[i]
  
  #town1
  if p<=A[i]:
    A[i]-=p
    p=0
  else:
    p-=A[i]
    A[i]=0
  #town2
  if p!=0:
    if A[i+1]<p:
      p-=A[i+1]
      A[i+1]=0
    else:
      A[i+1]-=p
      p=0
      
  C+=B[i]-p
  
print(C)

Measured memory_bytes: 18476
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
r = any([r[j:j+m] for r in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print("Yes" if r else "No")

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

int main(){
    ll n;
    cin >> n;
    ll p = ll(pow(n, 0.5));
    rrep(i, p){
        if (n % (i + 1) == 0){
            cout << i + 1 + n / (i + 1) - 2 << endl;;
            break;
        }
        else continue;
    }
    return 0;
}

Measured memory_bytes: 512
from collections import defaultdict

N = int(input())
stones = []
last = None
n_stone = 0
for i in range(N):
    stone = int(input())
    if stone != last:
        stones.append(stone)
        last = stone

count = defaultdict(int)
seq = 1
for i, c in enumerate(stones):
      prev = count[c]
      count[c] = prev + seq
      seq += prev

print(seq % (10**9 + 7))

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

int main() {
	int n,m;
	cin >> n >> m;
	vector<pair<long long,long long>> a(n);
	for(int i=0;i<n;i++)
	{
		int a1,a2;
		cin >> a1 >> a2;
		a.at(i) = make_pair(a1,a2);
	}
	sort(a.begin(),a.end());
	long long k=0,h=0;
	for(int i=0;i<n;i++)
	{
		long long f=a.at(i).first,
		          s=a.at(i).second;
		if(h+s>m)
		{
			k+=f*(m-h);
			h=m;
		}
		else
		{
			k+=f*s;
			h+=s;
		}
		if(h==m)
		{
			break;
		}
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
typedef pair<int,int> pii;
typedef pair <long long,long long> pll;
typedef long long ll; 
typedef long double ld; 
const ll mod = 1e9+7;
int solve( int n, int m , vector<vector <char> > &v)
{	vector <vector <int> > dp(n+1,vector < int >(m+1));
	dp[n][m] = 1;
	for(int i = n; i>= 1; i--)
	{	for(int j = m ; j>= 1 ; j--)
		{	if(i == n && j == m)	
				continue;
			if(v[i][j] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = ((i == n) ? 0 : dp[i+1][j])  + ((j == m) ? 0 : dp[i][j+1]) ;
				
			dp[i][j]%= mod;
		}
	}
	
	return dp[1][1];
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); 
    int n,m; cin >> n>> m;
    vector <vector <char> > grid(n+1,vector <char> (m+1));
    for(int i= 1; i <= n; i++)
    {	for(int j = 1 ; j <= m ; j++)
			cin>>grid[i][j];
	}	
	cout << solve(n,m,grid);
    return 0;
}
 


Measured memory_bytes: 5248
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = Number(arr[0].split(' ')[1]);
  const b = arr[1].split(' ').map(x => Number(x));
  let count = 0;

  for (let i = 0; i < b.length; i ++) {
    if (b[i] >= a) {
      count ++;
    }
  }
  
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22964
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()

    if ("S" in s and "N" not in s) or ("N" in s and "S" not in s):
        print("No")
    elif ("W" in s and "E" not in s) or ("E" in s and "W" not in s):
        print("No")
    else:
        print("Yes")



if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll n;
ll a[3009];
ll dp[3009][3009];
ll f(ll x, ll y){
    if(dp[x][y] != -1e18)
        return dp[x][y];
    if(x > y)
        return dp[x][y] = 0;
    return dp[x][y] = max(a[x] - f(x+1, y), a[y] - f(x, y-1));
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n;
    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    for(ll i = 0; i < n; ++i)
        for(ll j = 0; j < n; ++j)
            dp[i][j] = -1e18;
    cout << f(0, n-1) << "\n";
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Last Change: 03/03/2019 20:02:18.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

class Cal {
private:
  ll A, B, Q;
  vector<ll> s;
  vector<ll> t;

private:
  ll Know(const vector<ll>& first, const vector<ll>& second, const ll x) {
    ll ans, tmpAns;
    ans = tmpAns = INT64_MAX;

    auto fItr = lower_bound(first.begin(), first.end(), x);
    // cout << *fItr << " " << flush;

    // x以上の場所にいくとき
    // x以上の値があることを保証
    if (fItr != first.end()) {
      tmpAns = *fItr - x;
      auto sItr = lower_bound(second.begin(), second.end(), *fItr);
      // cout << *sItr << " " << flush;
      //*fItrがsecondより東の場合
      if (sItr == second.end()) {
        --sItr;
        tmpAns += *fItr - *sItr;
      }
      //*fItrがsecondより西側の場合(*fItrより西にsecondはない)
      else if (sItr == second.begin()) {
        tmpAns += *sItr - *fItr;
      }
      //*fItrの東西両方にsecondがある場合
      else {
        auto prevItr = sItr;
        --prevItr;
        tmpAns += min(*sItr - *fItr, *fItr - *prevItr);
      }
      ans = tmpAns;
    }

    // x未満の場所に行くとき
    // x未満の値があることを保証
    if (fItr != first.begin()) {
      --fItr;
      tmpAns = x - *fItr;
      //この移動だけで先の移動よりも大きいときは無視
      //以下は上記の条件を満たさない。すなわちOK。
      if (tmpAns <= ans) {
        auto sItr = lower_bound(second.begin(), second.end(), *fItr);
        // cout << *sItr << " " << endl;
        if (sItr == second.end()) {
          --sItr;
          tmpAns += *fItr - *sItr;
        } else if (sItr == second.begin()) {
          tmpAns += *sItr - *fItr;
        } else {
          auto prevItr = sItr;
          --prevItr;
          tmpAns += min(*sItr - *fItr, *fItr - *prevItr);
        }
      }
      ans = min(ans, tmpAns);
    }
    return ans;
  }

  ll Solve(const ll x) {
    ll ans = INT64_MAX;

    //初めに神社の場合
    ans = Know(s, t, x);
    // cout << "  " << ans << endl;

    //初めに寺の場合
    ll tmpAns = Know(t, s, x);
    // cout << "  " << tmpAns << endl;
    ans = min(ans, tmpAns);

    // cout << "  " << tmpAns << endl;
    return ans;
  }

  void Output(ll ans) {
    cout << ans << '\n';
  }

public:
  Cal() {
    cin >> A >> B >> Q;
    s.resize(A);
    t.resize(B);
    for (int i = 0; i < A; ++i) {
      cin >> s[i];
    }
    for (int i = 0; i < B; ++i) {
      cin >> t[i];
    }
  }

  ll GetQ() {
    return Q;
  }

  void Main(ll x) {
    ll ans = Solve(x);
    Output(ans);
  }
};

int main() {
  unique_ptr<Cal> cal(new Cal());
  ll Q = cal->GetQ();
  ll x;
  for (int i = 0; i < Q; ++i) {
    cin >> x;
    cal->Main(x);
  }
  cout << flush;
  //NS::LoopUntilZeroInpput();
}



Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <climits>

using namespace std;

const int N = 5000;

int ii[N], cc[N], qu[N];
bool visited[N];

int main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int p; cin >> p, p--;
		ii[i] = p;
	}
	for (int i = 0; i < n; i++)
		cin >> cc[i];
	long long ans = LLONG_MIN;
	for (int i = 0; i < n; i++) {
		fill(visited, visited + n, false);
		int cnt = 0;
		int i_ = i;
		while (!visited[i_]) {
			qu[cnt++] = i_;
			visited[i_] = true;
			i_ = ii[i_];
		}
		int m = 0;
		int i__ = i;
		while (i__ != i_) {
			m++;
			i__ = ii[i__];
		}
		if (k < m) {
			long long a = 0;
			for (int h = 0; h < k; h++)
				ans = max(ans, a += cc[qu[h]]);
		} else {
			long long a = 0;
			for (int h = 0; h < m; h++)
				ans = max(ans, a += cc[qu[h]]);
			long long b = 0;
			for (int h = m; h < cnt; h++)
				b += cc[qu[h]];
			if (b > 0) {
				long long b_ = 0;
				for (int h = m; h < cnt && h <= k; h++) {
					ans = max(ans, a + (k - m - (h - m)) / (cnt - m) * b + b_);
					b_ += cc[qu[h]];
				}
			} else {
				long long b_ = 0;
				for (int h = m; h < cnt && h <= k; h++) {
					if (h > 0)
						ans = max(ans, a + b_);
					b_ += cc[qu[h]];
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N = 1e5+5;
int n;
int main()
{
	string a,b;
	cin>>a>>b;
	b.erase(b.size()-1,1);
	if(a==b)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0, tail=0, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail+1 == LEN) tail = 0;
  else tail++;
}

P dequeue(){
  P x;
  x = Q[head];
  if(head+1 == LEN) head = 0;
  else head++;
  return x;
}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }

  while(head != tail){
    u = dequeue();
    if(u.t<=q){
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
      
      
    }
    else{
      elaps += q;
      u.t = u.t - q;
      enqueue(u);
    }


  
  }

  
  return 0;
}



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

int main()
{
    string S;
    cin >> S;
    int res=0;
    int count=0;
    for(auto c : S){
        if(c=='A' || c=='C' || c=='G' || c=='T'){
            count++;
        }else{
            res = max(res, count);
            count=0;
        }
    }
    res = max(res, count);
    cout<<res<<endl;
}

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

int main()
{
    int N;
    cin >> N;
    cout << N*800 - N/15 * 200 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef pair<int, int> P;        
int main(){
    int n, m;
    while(cin >> n >> m && n){
        int sum = 0;
        vector<int> p(n), q(m);
        rep(i, n){
            cin >> p[i];
            sum += p[i];
        }
        rep(i, m){
            cin >> q[i];
            sum -= q[i];
        }
        int ap = INF, aq = INF;
        for(int pn : p) for(int qn : q)
          if(2 * (pn - qn) == sum && pn + qn < ap + aq){
              ap = pn;
              aq = qn;
          }
        if(ap == INF){
            puts("-1");
        }else{
            cout << ap << ' ' << aq << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3080
from itertools import product
S = input()
s_len = len(S)
output=0
l_plus=[]
for i in range(s_len-1):
    l_plus.append(S[i])
    l_plus.append("")
l_plus.append(S[s_len-1])
for l in product(["", '+'],repeat=s_len-1):
    for i in range(s_len-1):
        l_plus[2*i+1]=l[i]
    output+=eval("".join(l_plus))
print(output)


Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = true;
    private static boolean elapsed = true;
 
    private int N;
    private int T;
    private int[] A;
 
    private void solve(Scanner sc, PrintWriter out) {
        N = sc.nextInt();
        T = sc.nextInt();
        A = new int[N];
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
        }
 
        int min = Integer.MAX_VALUE;;
        int max = 0;
        int count = 0;
        for (int i = 0; i < N; ++i) {
            if (A[i] < min) {
                min = A[i];
            } else {
                int diff = A[i] - min;
                if (diff == max) {
                    ++count;
                } else if (diff > max) {
                    max = diff;
                    count = 1;
                }
            }
        }
 
        out.println(count);
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

Measured memory_bytes: 50612
S = input().split()
a2 = S[0][-1]
for i,s in enumerate(S):
	if i == 0:
		continue
	a1 = s[0]
	if a1 != a2:
		print("NO")
		break
	a2 = s[-1]
	if i == 2:
		print("YES")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
    ll g = gcd(x, y);
    return x / g * y;
}

ll f(ll n, ll c, ll d, ll e) {

    if(n == 0) {
        return 0;
    }

    ll x = n/c;
    ll y = n/d;
    ll z = n/e;

    return n - (x + y - z);
}

int main() {
    ll a, b, c, d;    
    cin >> a >> b >> c >> d;

    ll e = lcm(c, d);

    ll ans = f(b, c, d, e) - f(a-1, c, d, e);

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

Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
a, b = gets_i_list

1.upto(1500) do |i|
  if (i * 0.08).floor == a && (i * 0.1).floor == b
    puts i
    exit
  end
end

puts -1

Measured memory_bytes: 14564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl;
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef queue<int> Q;

int main()
{
    int n;
    cin >> n;
    VV d(n, V());
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        d[a - 1].push_back(b);
        d[b - 1].push_back(a);
    }
    V d1(n, 0);
    Q q1;
    q1.push(1);
    while (SZ(q1))
    {
        int i = q1.front();
        q1.pop();
        for (int t : d[i - 1])
        {
            if (d1[t - 1] == 0)
            {
                d1[t - 1] = d1[i - 1] + 1;
                q1.push(t);
            }
        }
    }
    V d2(n, 0);
    Q q2;
    q2.push(n);
    while (SZ(q2))
    {
        int i = q2.front();
        q2.pop();
        for (int t : d[i - 1])
        {
            if (d2[t - 1] == 0)
            {
                d2[t - 1] = d2[i - 1] + 1;
                q2.push(t);
            }
        }
    }
        int cntf = 0, cnts = 0;
        for (int i = 1; i < n - 1; i++)
        {
            if (d1[i] <= d2[i])
            {
                cntf++;
            }
            else
            {
                cnts++;
            }
        }
        if (cntf > cnts)
        {
            OUT("Fennec");
        }
        else
        {
            OUT("Snuke");
        }
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF=1e9;
const ll MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int H,W;
string S[26][26];
int main() {
    cin>>H>>W;
    rep(i, H) rep(j, W) cin>>S[i][j];

    rep(i, H) rep(j, W) {
        if(S[i][j] == "snuke") {
            printf("%c%d\n", j + 'A', i + 1);
        }
    }

    return 0;
}



Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
vector<int> enum_div(int n)//nの約数を列挙
{
	vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

bool isOK(int index, int key, vector<int>& v) {
    int L = 0, R = 0;
    rep(i, v.size()) {
        if (i <= index) L += v[i] % key;
        else R += key - v[i] % key;
    }
    //cout << index << " " << L << " " << R << endl;
    return L >= R;
}
int value(int index, int key, vector<int>& v) {
    int L = 0, R = 0;
    rep(i, v.size()) {
        if (i <= index) L += v[i] % key;
        else R += key - v[i] % key;
    }
    //cout << index << " " << L << " " << R << endl;
    return L;
}

int binary_search(int key, vector<int>& v) {
    int ng = -1;
    int ok = (int)v.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, v)) ok = mid;
        else ng = mid;
    }
    return ok;
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[510];
    rep(i, N) cin >> A[i];
    int sum = 0;
    rep(i, N) sum += A[i];
    //dump(sum);
    vector<int> div = enum_div(sum);
    sort(div.begin(), div.end());
    int ans = 1;
    //cout << endl;
    rep(i, div.size()) {
        if (div[i] == 1) continue;
        int num = 0;
        //cout << "***" << div[i] << "***" << endl;
        vector<int> v;
        rep(j, N) {
            v.push_back(A[j] % div[i]);
            //num += min(A[j] % div[i],  div[i] - (A[j] % div[i]));
            //cout << A[j] << " " << A[j] % div[i] << " " << div[i] - (A[j] % div[i]) << endl;
        }
        sort(v.begin(), v.end());
        int cnt = value(binary_search(div[i], v),div[i],v);
        //cout << "*" << cnt << endl;
        if (cnt <= K) ans = max(ans, div[i]);
        //cout << endl;
        //cout << div[i] << " " << num << endl;
    }
    cout << ans << endl;


    return 0;
}


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

int main() {
    int h,w;cin>>h>>w;
    vector<vector<int>> s(h,vector<int>(w,0)),wc(h,vector<int>(w,0)),hc(h,vector<int>(w,0));
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		char ch;cin>>ch;
    		if(ch=='.'){
    			s[i][j]=1;
    			wc[i][j]=1;
    			hc[i][j]=1;
    		}
    	}
    }
    for(int i=0;i<h;i++){
    	for(int j=1;j<w;j++){
    		if(wc[i][j]){
    			wc[i][j]+=wc[i][j-1];
    		}
    	}
    	for(int j=w-2;j>=0;j--){
    		if(wc[i][j]){
    			wc[i][j]=max(wc[i][j+1],wc[i][j]);
    		}
    	}
    }

    for(int j=0;j<w;j++){
    	for(int i=1;i<h;i++){
    		if(hc[i][j]){
    			hc[i][j]+=hc[i-1][j];
    		}
    	}
    	for(int i=h-2;i>=0;i--){
    		if(hc[i][j]){
    			hc[i][j]=max(hc[i+1][j],hc[i][j]);
    		}
    	}
    }
    int ans=0;
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		int temp=wc[i][j]+hc[i][j];
    		ans=max(ans,temp);
    	}
    }
    cout<<ans-1<<endl;

	return 0;
}

Measured memory_bytes: 47360
#include<bits/stdc++.h>
using namespace std;
set<int> a, b;
int main()
{
	int n, m;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++)
	{
		int x;
		scanf("%d",&x);
		a.insert(x);
	}
	scanf("%d",&m);
	for(i=0; i<m; i++) 
	{
		int x;
		scanf("%d",&x);
		b.insert(x);
	}
	vector<int> v;
	set_difference(a.begin(), a.end(), b.begin(), b.end(), back_inserter(v));
	for(i=0; i<v.size(); i++) printf("%d\n",v[i]);
	return 0;
}


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

int main(){
  int64_t k, ct=1, res=0, tmp=7;
  cin >> k;
  res=7%k;
  if(res==0){
    cout << 1;
    return 0;
  }
  while(true){
    tmp=tmp*10;
    tmp%=k;
    res+=tmp;
    res%=k;
    ct++;
    if(res==0){
      cout << ct;
      return 0;
    }
    if(ct>k){
      cout << -1;
      return 0;
    }
  }
  return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int k;
	cin >> k;
	string s;
	cin >> s;
	string str=s.substr(0, k);
	if(s.size()>k)
        str+="...";
    cout << str << endl;

	return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<string> s(N);
  for(string &x: s) cin>>x;
  int M;
  cin>>M;
  vector<string> t(M);
  for(string &x: t) cin>>x;
  
  int ans=0;
  for(int i=0;i<N;i++){
    int count=0;
  string a;
  a=s[i];
    for(int k=0;k<N;k++)
      if(s[i]==s[k]) count++; 
    for(int j=0;j<M;j++)
      if(s[i]==t[j]) count--;
   ans=max(ans,count);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s=sc.nextInt(),count=1;
		List<Integer> ary = new ArrayList<Integer>();
		ary.add(s);
		while(true) {
			count++;
			if(s%2==0) s/=2;
			else s = 3*s+1;
			if(ary.indexOf(s) != -1)break;
			ary.add(s);
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int a,b;
    cin >> a >> b;
    int x,y;
    x=max(a,b);
    y=min(a,b);
    rep(i,x)cout << y;


    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		switch (N % 10) {

		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			System.out.println("hon");
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			System.out.println("pon");
			break;
		case 3:
			System.out.println("bon");
			break;
		default:
			break;

		}

	}
}

Measured memory_bytes: 27084
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  lint N,A,B;
  cin>>N>>A>>B;
  lint t=N/(A+B);
  cout<<t*A+min((N-t*(A+B)),A)<<endl;
  return 0;
}


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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	int s;
	bool a = x >= r && x <= W -r && y >= r && y <= H - r;
	if (a){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<vector>
#include<iterator>

int main() {
  using namespace std;

  auto n = 0;
  cin >> n;

  vector<int> balls;
  multimap<int, int> mballs;
  for(int i = 0; i < n; i++)
  {
    int num = 0;
    cin >> num;
    balls.push_back(num);
    mballs.emplace(num, i);
  }

  const unordered_set<int> uniqueBalls(balls.begin(),balls.end());
  unordered_map<int, int> countBalls;
  long long cxcm1A = 0;
  for (const auto &b : uniqueBalls)
  {
    const auto c = mballs.count(b);
    countBalls.emplace(b, c);
    cxcm1A += c * (c - 1);
    mballs.erase(b);
  }

  for(int i = 0; i < n; i++)
  {
    const int kCount = countBalls.at(balls[i]);
    const long long && count = -(2 * kCount - cxcm1A - 2) / 2;
    cout << count << '\n';
  }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int n,a;
    cin >> n >> a;
    VL x(n+1);
    LL max_x = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
        x[i] -= a;
        max_x = max(max_x,x[i]);
    }
    LL max_sum = max_x * n;

    // 平均引いてるから和がマイナスになる可能性がある(可能性のある範囲は -max_x*n <= s <= max_x*n)
    // dp[n][2*max_sum]の２つめは,ループで0~2*max_x*nまで回してそれぞれで-max_x*nをすれば上記の範囲を達成できるからこうなってる
    VVL dp(n+1,VL(2*max_sum+1,0));
    dp[0][max_sum] = 1; // 0枚選ぶ時に合計が0になる場合 -> 1通り の初期化(これは計算のためで、あとで引く)
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= 2*max_sum; j++) {
            // i枚目まで選べる時に合計がj-max_sumになる場合
            if (j - x[i] < 0 or j - x[i] > 2*max_sum) {
                dp[i][j] = dp[i-1][j];
                continue;
            }
            dp[i][j] = dp[i-1][j-x[i]] + dp[i-1][j];
        }
    }

    cout << dp[n][max_sum] - 1 << endl;
    return 0;
}


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

string s,t;
int sa[100009],ta[100009];

int q,a,b,c,d;

int main(){
    cin>>s>>t;
    rep(i,s.size())sa[i+1]=sa[i]+(s[i]=='A');
    rep(i,t.size())ta[i+1]=ta[i]+(t[i]=='A');
    
    cin>>q;
    while(q--){
        cin>>a>>b>>c>>d;
        cout<<((b-a+sa[b]-sa[a-1]-d+c-ta[d]+ta[c-1])%3?"NO\n":"YES\n");
    }
}

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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
	long long int a, b = 0;
	string B; cin >> a >> B;
	int n = B.size();
	for (int i = 0; i < n; ++i) {
		if (B[i] == '.') continue;
		b = b*10 + B[i] - '0';
	}
	cout << (a*b)/100 << '\n';
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define MAXN 100005

using namespace std;
using ll = long long;

int n;
ll A[MAXN][3];
ll dp[MAXN][3];

ll solve(int x, int last) {
  if (x == n) {
    return 0;
  }
  ll& res = dp[x][last];
  if (res != -1) { return res; }
  res = -1e9;
  for (int i = 0; i < 3; i++) {
    if (i == last) { continue; }
    res = max(res, A[x][i] + solve(x + 1, i));
  }
  return res;
}


int main() {
  fill(&dp[0][0], &dp[0][0] + MAXN * 3, -1LL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i][0] >> A[i][1] >> A[i][2];
  }
  ll res = max(solve(0, 0), max(solve(0, 1), solve(0, 2)));
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 12800
function Main (input) {
  input = input.split("\n");
  input[1] = input[1].split("");
  var ans = 0;
  for (var i = 0; i < input[0]; i++) {
    if (input[1][i] == "A" && input[1][i + 1] == "B" && input[1][i + 2] == "C") {
      ans++;
    }
  }
  console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"



  void solve(){
	  char a;
	  cin >> a;
	  cout << char(a+1);
  
  
  }
	
  
  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
	solve();
	
}
		
		
		
		
	






Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 998244353
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 1;
int N, maxVal = 0;
vi D;
map<ll, ll> mp;

ll modpow(ll a, ll b, ll mod = 1000000007) {
    ll res = 1;
    for (a %= mod; b; a = a * a % mod, b >>= 1)
        if (b & 1) res = res * a % mod;
    return res;
}

void solve(){
    rep(i, N){
        if((i == 0 && D[i] != 0) || (i != 0 && D[i] == 0)){
            cout << 0 << endl;
            return;
        }
        mp[D[i]]++;
        maxVal = max(maxVal, D[i]);
    }

    int prev = 1;

    rep(i, maxVal+1){
        if(mp[i] == 0){
            cout << 0 << endl;
            return;
        }
        ans *= modpow(prev, mp[i], MOD);
        prev = mp[i];
        ans %= MOD;
    }

    cout << ans << endl;
}

int main(){
    cin >> N;
    D.resize(N);

    rep(i, N) cin >> D[i];

    solve();
}


Measured memory_bytes: 6912
N,Y=map(int,input().split())
ans1, ans2, ans3 =-1,-1,-1

for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x+5000*y+1000*(N-x-y)==Y:
            ans1,ans2,ans3= x,y,N-x-y
            break

print("{} {} {}".format(ans1,ans2,ans3))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int main(){
    int N,M;
    cin >> N >> M;
    vector<LL> x(M),v(M-1);
    for (int i = 0; i < M; i++) {
        cin >> x[i];
    }
    sort(ALL(x));
    for (int i = 1; i < M; i++) {
        v[i-1]=x[i]-x[i-1];
    }
    LL ans=0;
    sort(ALL(v));
    for (int i = 0; i < M-N; i++) {
        ans+=v[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush 
def main():
    N, M = map(int, readline().split())
    tasks = [[] for _ in range(M)]
    for _ in range(N):
        a, b = map(int, readline().split())
        if M-a<0:
            continue
        tasks[M-a].append(b)
    s = 0
    h = []
    for i in [i for i in range(M)][::-1]:
        for b in tasks[i]:
            heappush(h, -b)
        if len(h)>0:
            s+=-heappop(h)
    print(s)
if __name__ == '__main__':
    main()


Measured memory_bytes: 22360
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll N;
vector<P>v;
string solve(){
    vector<P>st(N);
    rep(i, N)st[i] = P(v[i].second, i);
    sort(st.begin(), st.end());
    rep(i, N)if(st[i].first > v[i].first)return "No";
    rep(i, N)if(st[i].second == i)return "Yes";
    vector<ll>to(N);
    rep(i, N)to[st[i].second] = i;
    vector<ll>flg(N, 0);
    ll cnt = 0;
    rep(i, N){
        if(flg[i])continue;
        ll idx = i;
        ll tmp = -1;
        while(flg[idx] == 0){
            flg[idx] = 1;
            idx = to[idx];
            tmp++;
        }
        cnt += tmp;
    }
    if(cnt <= N - 2)return "Yes";
    for(ll i = 1; i < N; i++){
        ll a0 = st[i - 1].first;
        ll a1 = st[i].first;
        ll b0 = v[i - 1].first;
        ll b1 = v[i].first;
        if(a0 <= b1 && a1 <= b0)return "Yes";
    }
    return "No";
}

int main(){

    cin >> N;
    v = vector<P>(N);
    rep(i, N)cin >> v[i].second;
    rep(i, N)cin >> v[i].first;
    sort(v.begin(), v.end());
    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 4864