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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

vll z_array(string &s){
  ll n = s.size();
  vll res(n,0);
  res[0] = n;

  ll i = 1, j = 0;
  while(i < n){
    while(i + j < n && s[j] == s[i + j]) j++;
    res[i] = j;

    if(j == 0){ i++; continue;}

    ll k = 1;
    while(k < j && k + res[k] < j){
      res[i + k] = res[k];
      k++;
    }

    i += k; j -= k;
  }

  return res;
}
//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  string s;
  cin >> n >> s;
  ll ans = 0;
  for(ll i=0;i<n;i++){
    vll z = z_array(s);
    for(ll j=0;j<z.size();j++){
      if(j >= z[j]) ans = max(ans,z[j]);
    }
    ll m = s.size();
    s = s.substr(1,m-1);
  }

  cout << ans <<endl;


    
  return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <vector>
#include <tuple>

struct union_find {
  std::vector<int> par;
  union_find(int N): par(N, -1) {}
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  std::tuple<int, int> unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return { -1, -1 };
    if(par[x] > par[y]) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return { x, y };
  }
  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  i64 N, M;
  cin >> N >> M;
  union_find uf(N);
  while(M--) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  set<i64> st;
  rep(i,0,N) {
    st.insert(uf.root(i));
  }
  cout << st.size() - 1 << endl;
}


Measured memory_bytes: 7436
#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
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
 
int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}
 
int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}
 
int main()
{
    int a,b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << endl;
    }else if(a >= 6){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int solve(vector<int> a, vector<int> b) {
	int ret = 0;
	rep(i, 0, a.size()) {
		if (a[i] == b[i])continue;
		auto it = find(a.begin() + i, a.end(), b[i]);
		swap(*it, a[i]);
		ret += it - a.begin() - i;
	}
	dumpc(a);
	dumpc(b);
	return ret;
}

signed main() {
	int N, M; cin >> N >> M;
	vector<int> a(N), b(M + 1, 0);
	rep(i, 0, N)cin >> a[i];
	rep(i, 0, M)cin >> b[i];
	int o = 0, e = 0;
	for (int i = 0; i < M; i += 2) {
		o += b[i];
		e += b[i + 1];
	}
	vector<int> c;
	int c1 = accumulate(all(a), 0);
	if (o == e) {
		for (int i = 0; i < M; i += 2) {
			rep(j, 0, b[i])c.emplace_back(1);
			rep(j, 0, b[i + 1])c.emplace_back(0);
		}
		int ans = solve(a, c);
		c.clear();
		for (int i = 0; i < M; i += 2) {
			rep(j, 0, b[i])c.emplace_back(0);
			rep(j, 0, b[i + 1])c.emplace_back(1);
		}
		chmin(ans, solve(a, c));
		cout << ans << endl;
	}
	else {
		if (c1 == o) {
			for (int i = 0; i < M; i += 2) {
				rep(j, 0, b[i])c.emplace_back(1);
				rep(j, 0, b[i + 1])c.emplace_back(0);
			}
			cout << solve(a, c) << endl;
		}
		else {
			for (int i = 0; i < M; i += 2) {
				rep(j, 0, b[i])c.emplace_back(0);
				rep(j, 0, b[i + 1])c.emplace_back(1);
			}
			cout << solve(a, c) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){

  int x,t;
  int a = 0;
  int b = 0;


  scanf("%d", &x);

  t = x;
  while(t >= 500){
    a++;
    t = t - 500;
  }

  t = x;

  if(a != 0){
    t = t % (a*500);
  }

  while(t >= 5){
    b++;
    t = t - 5;
  }

  if(a == 0 && b == 0) printf("0\n");

  else printf("%d\n", 1000*a + 5*b);

  return 0;
}

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

int main(){
	int n,m;
	cin >> n >> m;
	priority_queue<double> a;
	rep(i,n){
		double tmp;
		cin >> tmp;
		a.push(tmp);
	}
	
	rep(i,m){
		double tmp = a.top();
		a.pop();
		a.push(tmp/2.0);
	}
	
	ll res = 0;
	while(!a.empty()){
		res += a.top();
		a.pop();
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1400
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    S = input().rstrip()
    T = input().rstrip()
    L = [[S[i],T[i]] for i in range(len(S))]
    L.sort(key = lambda x: x[0])
    D = defaultdict(int)
    D2 = defaultdict(int)
    for a, b in L:
        if (D[a] == 0 or D[a] == b) and (D2[b] == 0 or D2[b] == a):
            D[a]=b
            D2[b]=a
        else:
            print("No")
            exit()
    print("Yes")
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 30300
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine().Split(' ');
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);

            WriteLine(Enumerable.Range(1, (b - a) - 1).Sum() - a); 

        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int h, w;

bool is_strawberry_in_row(vector<string> &cake, int r) {
	for (int i = 0; i < w; ++i) {
		if (cake[r][i] == '#') {
			return true;
		}
	}

	return false;
} 

bool is_strawberry_in_column(vector<string> &cake, int start_row, int end_row, int col) {
	for (int i = start_row; i <= end_row; ++i) {
		if (cake[i][col] == '#') {
			return true;
		}
	}

	return false;
}

void cut_piece(vector<vector<int> > &pieces, int sr, int er, int sc, int ec, int counter) {
	for (int i = sr; i <= er; ++i) { 
		for (int j = sc; j <= ec; ++j) {
			pieces[i][j] = counter;
		}
	}
}

int main() {

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

	int k;
	cin >> h >> w >> k;

	vector<string> cake(h);
	for (int i = 0; i < h; ++i) {
		cin >> cake[i];
	}	

	vector<pair<int, int> > horizontal_sections;
	int start_row = 0, end_row = 0;
	int curr_count = 0;
	while (end_row < h) {
		if (is_strawberry_in_row(cake, end_row)) {
			++curr_count;
		}

		if (curr_count == 2) {
			horizontal_sections.push_back({start_row, end_row - 1});
			start_row = end_row;
			curr_count = 1;
		}

		++end_row;
	}

	horizontal_sections.push_back({start_row, end_row - 1});
	vector<vector<int> > pieces(h, vector<int> (w));
	int counter = 1;
	for (int i = 0; i < (int) horizontal_sections.size(); ++i) {
		int start_row = horizontal_sections[i].first;
		int end_row = horizontal_sections[i].second;
		int start_col = 0, end_col = 0;
		int curr_count = 0;
		while (end_col < w) {
			if (is_strawberry_in_column(cake, start_row, end_row, end_col)) {
				++curr_count;
			}

			if (curr_count == 2) {
				cut_piece(pieces, start_row, end_row, start_col, end_col - 1, counter);
				start_col = end_col;
				++counter;
				curr_count = 1;
			}

			++end_col;
		}

		cut_piece(pieces, start_row, end_row, start_col, end_col - 1, counter);
		++counter;
	}

	cout << pieces;

	return 0;

}

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

m = 2020202020
b = sum(A)
a = 0
for i in range(N):
  a += A[i]
  b -= A[i]
  ab = abs(a-b)
  if ab < m:
    m = ab
print(m)

  

Measured memory_bytes: 88016
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int max = Math.max(A, B);
            if (A == B) {
                out.println(max * 2);
            } else {
                out.println(max * 2 - 1);
            }
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    i64 a1 = a * c, a2 = a * d, a3 = b * c, a4 = b * d;
    cout << max(a1, max(a2, max(a3, a4))) << endl;
}


Measured memory_bytes: 3656
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
A,B,C,K = inputlist()
if abs(B-A) >= 10**18:
    print("Unfair")
    exit()
ans = A-B
if K % 2 == 1:
    ans *= -1
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int M = 1e6;
set<int> adj[M];
int nd, indeg[M];
bool vis[M];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	map<pair<int, int>, int > mp;
	int mat[n][n - 1];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			cin >> mat[i][j];
			mat[i][j]--;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 2; j++) {
			pair<int, int> p1 = {i, mat[i][j]}, p2 = {i, mat[i][j + 1]};
			if (p1.first > p1.second)
				swap(p1.first, p1.second);
			if (p2.first > p2.second)
				swap(p2.first, p2.second);
			if (mp.find(p1) == mp.end())
				mp[p1] = nd++;
			if (mp.find(p2) == mp.end())
				mp[p2] = nd++;
			if (adj[mp[p1]].find(mp[p2]) == adj[mp[p1]].end()) {
				adj[mp[p1]].insert(mp[p2]);
				indeg[mp[p2]]++;
			}
		}
	}
	queue<pair<int, int> > q;
	for (int i = 0; i < nd; i++) {
		if (indeg[i] == 0) {
			vis[i] = true;
			q.push({i, 1});
		}
	}
	int ans = -1;
	while (!q.empty()) {
		int v = q.front().first, d = q.front().second;
		q.pop();
		for (auto nbr : adj[v])
			indeg[nbr]--;
		ans = d;
		for (auto nbr : adj[v]) {
			if (!vis[nbr] && indeg[nbr] == 0) {
				vis[nbr] = true;
				q.push({nbr, d + 1});
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i])
			ans = -1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 134828
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;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 SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define VI vector<int>
#define PB(x) push_back(x)
#define SZ(x) end(x) - begin(x)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void CO(auto &a) {REP(i, SZ(a)) cout << i << ": " << a[i] << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int n,k;
	string s;
	cin >> n >> s >> k;
	REP(i,n){
		if (s[i] != s[k-1]){
			s[i] = '*';
		}
	}
	
	cout << s << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

ll N,M,K,H,W;

long long modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
    // a/b =equiv=  (a%MOD) * modinv(b, MOD) % MOD;
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b and a != c){
        cout << "Yes";
        return 0;
    } 
    if(a == c and a != b){
        cout << "Yes";
        return 0;
    }
    if(b == c and b != a){
        cout <<"Yes";
        return 0;
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

mp = [0] * n
for _ in range(k):
  d = int(input())
  a = list(map(int, input().split()))
  for i in range(d):
    mp[a[i] - 1] = mp[a[i] - 1] + 1

ans = 0
for i in range(n):
  if mp[i] == 0:
    ans = ans + 1

print(ans)


Measured memory_bytes: 9124
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
const int M=1e9+7;
int main(){
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++){
		if(i%d==0)ans++;
	}
	cout<<ans;
	return 0;
}

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

int main() {
  string S;
  cin >> S;

  bool flag = false;
  int ans = 0;

  for (int i = 0; i < S.size(); i++) {
    if (i == S.size() - 2 && S.at(i) == S.at(i + 1)) {
      ans++;
      break;
    }

    if (flag == true && S.at(i) == S.at(i - 1)) {
      ans ++;
      i++;
      flag = false;
    } else {
      ans++;
      flag = true;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

template<typename T> 
T calc_gcd(T a, T b) {
	if (b > a)swap(a, b);
	while (a % b) {
		a = a % b;
		swap(a, b);
	}
	return b;
}

int main(){
    int a,b;
    cin>>a>>b;
    cout<<calc_gcd(a,b)<<"\n";
}


Measured memory_bytes: 3120
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

As = []
q = [[]]
while len(q) > 0:
    arg = q.pop()
    if len(arg) == N:
        As.append(arg)
    else:
        A_str = 1 if len(arg) == 0 else arg[-1]
        for i in range(A_str, M + 1):
            q.append(arg + [i])

ans = 0
for A in As:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A[bj - 1] - A[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, k;
  while (cin >> n >> k) {
    if (n == 0 && k == 0) break;
    int a[n];
    REP(i, n) cin >> a[i];
    int sum[n + 1];
    sum[0] = 0;
    REP(i, n) sum[i + 1] = sum[i] + a[i];
    int ans = -1e9;
    for (int i = 0; i + k <= n; ++i) {
      ans = max(ans, sum[i + k] - sum[i]);
    }
    cout << ans << endl;
  }
  return 0;
}


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

namespace AOJ1_3_C
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i > 0; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                int x = int.Parse(str[0]);
                int y = int.Parse(str[1]);
                if (x == 0 && y == 0) break;
                else
                {
                    Console.WriteLine(Math.Min(x, y) + " " + Math.Max(x, y));
                }
            }
        }
    }
}



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

#include <string>
using namespace std;

void solve(long long N, std::vector<long long> P, std::vector<long long> Q) {
    string pstr = "";
    for (vector<long long>::iterator i = P.begin(); i < P.end(); i++) {
        pstr += to_string(*i);
    }
    string qstr = "";
    for (vector<long long>::iterator i = Q.begin(); i < Q.end(); i++) {
        qstr += to_string(*i);
    }
    long long a, b;
    long long cnt = 1;
    vector<long long> v(N);
    iota(v.begin(), v.end(), 1);
    do {
        string str = "";
        for (auto x : v) str += to_string(x);
        if (str == pstr) {
            a = cnt;
        }
        if (str == qstr) {
            b = cnt;
        }
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> P(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &P[i]);
    }
    std::vector<long long> Q(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int l;
		cin >> l;
		double a = (l*1.0)/3;
		cout << fixed << setprecision(10) << a*a*a;
	}
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),Y=in();
	int MX=Y/10000;
	for(int x=0;x<=MX;x++){
		int MY=(Y-10000*x)/5000;
		for(int y=0;y<=MY;y++){
			int z=(Y-10000*x-5000*y)/1000;
			if((x+y+z)==N){
				out(x,y,z);
				return 0;
			}
		}
	}

	out(-1,-1,-1);
	return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> l(n);
    REP(i, n){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    ll ans = 0;
    for(ll i = 0; i < l.size(); ++i){
        const ll a = l.at(i);
        for(ll j = i + 1; j < l.size(); ++j){
            const ll b = l.at(j);

            const ll cub = a + b;
            const ll clb = max(a - b, b - a);
            auto it_lb = upper_bound(l.begin() + j + 1, l.end(), clb);
            if(it_lb == l.end()){ continue; }
            auto it_ub = lower_bound(l.begin() + j + 1, l.end(), cub);
            if(it_ub == l.begin() + j + 1){
                continue;
            }
            it_ub -= 1;
            if(*it_ub >= a + b){ continue; }
            ans += (it_ub - it_lb) + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	    ll n;
	    cin>>n;
	    ll d[n];
	    for(ll i=0;i<n;i++)
	    	cin>>d[i];
	    sort(d,d+n);
	    cout<<d[n/2]-d[n/2-1];
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL n,m;
    cin>>n>>m;
    if(n==m)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat)


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    s = S()
    count = 0

    if len(s) % 2 == 1:
        print('No')
        return

    for i in range(0, len(s), 2):
        if s[i] == 'h' and s[i+1] == 'i':
            # print(s[i], s[i+1])
            count += 1

    if count == len(s) // 2:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38636
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, N) {
        if(S[i] == 'R')
            cnt++;
    }
    int res = 0;
    rep(i, cnt) {
        if(S[i] == 'W')
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

vector<ll> adj[100005];
ll dp[100005];

void initialise(){
    memset(dp,-1,sizeof(dp));
}

ll dfs(ll n)
{   
    if(dp[n]!=-1)
        return dp[n];

    ll temp=0;

    loop(i,0,adj[n].size())
        temp=max(temp,dfs(adj[n][i])+1);

    dp[n]=temp;
    return temp;
}

int main()
{   
    IOS;

    ll n,m,x,y,maxi=0;
    cin>>n>>m;

    loop(i,0,m)
    {
        cin>>x>>y;
        adj[x].PB(y);
    }

    initialise();

    loop(i,1,n+1)
        maxi=max(maxi,dfs(i));

    d1(maxi);
}

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

using namespace std;
#define int64 long long

const int nMax = 100010;

int n, m;
int nTest;

void outerInit()
{
    if (ifstream("test.inp")) freopen("test.inp", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(9) << fixed;
}

void enter()
{
    cin >> m >> n;
    if (n == 100) n++;
    for (int i = 1; i <= m; ++i) n *= 100;
    cout << n;
}

void init()
{
}

void solve()
{
}

int main()
{
    outerInit();

    nTest = 1;
    // cin >> nTest;
    for (int i = 1; i <= nTest; ++i)
    {
        if (i > 1) cout << "\n";
        enter();
        init();
        solve();
    }
}

Measured memory_bytes: 256
n, m = (int(i) for i in input().split())
xlist=list(int(i) for i in input().split())
ylist=list(int(i) for i in input().split())

#x=xlist[-1]-xlist[0]
#y=ylist[-1]-ylist[0]

tate=0
yoko=0

for i in range(n-1):
    now=xlist[i+1]-xlist[i]
    now*=(i+1)*(n-i-1)
    tate+=now
    tate%=(10**9+7)


for j in range(m-1):
    now=ylist[j+1]-ylist[j]
    now*=(j+1)*(m-j-1)
    yoko+=now
    yoko%=(10**9+7)

#print(tate, yoko)

print((tate*yoko)%(10**9+7))

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

using namespace std;

string s;
int n;
char alph[52] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int main() {
    cin>>n;
    cin>>s;
    for (int i=26; i<52; i++) alph[i]=alph[i-26];
    for (int i=0; i<s.length(); i++){
        s[i]=alph[s[i]-65+n];
    }
       
    cout<<s;
}

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

A.sort()
# print(A)
flag = False
for i in range(len(A)):
    if(i+1 < len(A)):
        if(A[i] == A[i+1]):
            print("NO")
            flag = True
            break
if(not flag):
    print("YES")

Measured memory_bytes: 26804
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    n--;
    vector<int>c(n),s(n),f(n);
    rep(i,n)cin>>c[i]>>s[i]>>f[i];
    rep(i,n){
        int x=c[i]+s[i];
        for(int j=i+1; j<n; ++j){
            if(x<s[j])x=s[j];
            if((x-s[j])%f[j]!=0)x+=f[j]-((x-s[j])%f[j]);
            x+=c[j];
        }
        cout<<x<<endl;
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
/// 1行の文字を空白で分割してVec<T>にする。
fn read_split<T : std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

fn read_one<T : std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse().ok().unwrap()
}

/// 複数回read_splitを行う
fn read_split_multi<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| read_split()).collect()
}

fn main() {
    let _ : usize = read_one();
    let var_t : Vec<i32> = read_split();
    let var_m : usize = read_one();
    let var_p_x : Vec<Vec<i32>> = read_split_multi(var_m as i32);
    let question_all_time : i32 = var_t.iter().sum();
    for p_x in var_p_x {
        let p = p_x[0] as usize;
        let answer = question_all_time - var_t[p - 1] + p_x[1];
        println!("{}", answer);
    }

}

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

// computational complexity : O(V^3)

const long long int INF = 1e12;
int V,E;// number of (vertices, edges)
vector<vector<long long int>> d;// d[i][j] = shortest distances between i and j

int main(){
    int R;
    cin >> V >> E >> R;
    d.assign(V, vector<long long int>(V, INF));
    for (int i=0; i<V; i++){
        d[i][i] = 0;
    }
    vector<int> r(R);
    for (int i=0; i<R; i++){
        cin >> r[i];
        r[i] -= 1;
    }
    sort(r.begin(),r.end());

    for (int i=0; i<E; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u -= 1;
        v -= 1;
        d[u][v] = w;
        d[v][u] = w;
    }

    // naive DP
    for (int k=0; k<V; k++){// potential relay points
        for (int i=0; i<V; i++){
            for (int j=0; j<V; j++){
                d[i][j] = min(
                    d[i][j],// without going through k
                    d[i][k] + d[k][j]// with going through k
                );
            }
        }
    }

    long long int ans = INF;
    do{
        long long int sum = 0;
        for (int i=0; i<R-1; i++) sum += d[r[i]][r[i+1]];
        //cout << sum << endl;
        ans = min(ans, sum);
    }while(next_permutation(r.begin(),r.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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 main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<tuple<double,double,double>> circles;
    rep(i,2){
        double tx,ty;cin>>tx>>ty;
        circles.push_back(make_tuple(tx,ty,0));
    }
    double n;cin>>n;
    rep(i,n){
        double tx,ty,tr;cin>>tx>>ty>>tr;
        circles.push_back(make_tuple(tx,ty,tr));
    }
    function<double(double,double,double,double)> distance = [=](double ax, double ay, double bx, double by){
        return sqrt(pow(ax-bx,2)+pow(ay-by,2));
    };
    vector<vector<double>> mat(n+2,vector<double>(n+2,0));
    rep(i,n+2){
        rep(j,n+2){
            double dist = max(0.0,(get<2>(circles[i])+get<2>(circles[j]))*(-1.0)+
            distance(get<0>(circles[i]), get<1>(circles[i]),
            get<0>(circles[j]), get<1>(circles[j])));
            mat[i][j] = mat[j][i] = dist;
        }
    }
    DEBUG{
        rep(i,n+2){
            rep(j,n+2){
                cout << mat[i][j] << " ";
            }
            cout << endl;
        }
    }
    priority_queue<pair<double,double>, vector<pair<double,double>>,greater<pair<double,double>>> pq;
    vector<double> d(n+2,1e+14);
    vector<bool> check(n+2,false);
    pq.push(make_pair(0,0));
    d[0]=0;
    while(!pq.empty()){
        auto now = pq.top();
        DEBUG{
            cout << "now: " << now.second << endl;
        }
        pq.pop();
        if(check[now.second]){
            continue;
        }
        check[now.second]=true;
        rep(i,n+2){
            if(!check[i]){
                if(chmin(d[i],d[now.second]+mat[i][now.second])){
                    pq.push(make_pair(d[i],i));
                }
            }
        }
    }
    printf("%.10lf\n",d[1]);
    return 0;
}


Measured memory_bytes: 13428
#include <stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    long a[n+1],b[n],ans=0;
    for(i=0;i<n+1;i++) scanf("%ld",&a[i]);
    for(i=0;i<n;i++) scanf("%ld",&b[i]);
    for(i=0;i<n;i++){
        if(a[i]>b[i]) ans+=b[i];
        else if(a[i]+a[i+1]>b[i]){
            ans+=b[i];
            a[i+1]=a[i+1]-(b[i]-a[i]);
        }
        else{
            ans+=a[i]+a[i+1];
            a[i]=0;
            a[i+1]=0;
        }
    }
    printf("%ld",ans);
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int x,a,b;cin>>x>>a>>b;
    if(abs(x-a)>=abs(x-b)){
        cout<<"B"<<endl;
    }else{
        cout<<"A"<<endl;
    }
}


Measured memory_bytes: 3544
#include <stdio.h>

int Dice(int ,int);

int main(void){
    int i,n,D[7];
    int x,y;
    int num[24][2];
    
    for(i=1;i<=6;i++){
        scanf("%d",&D[i]);
    } 
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&num[i][0],&num[i][1]);
    }
    for(i=0;i<n;i++){
            if(num[i][0]==D[1]) x=1;
            else if(num[i][0]==D[2]) x=2;
            else if(num[i][0]==D[3]) x=3;
            else if(num[i][0]==D[4]) x=4;
            else if(num[i][0]==D[5]) x=5;
            else if(num[i][0]==D[6]) x=6;
            if(num[i][1]==D[1]) y=1;
            else if(num[i][1]==D[2]) y=2;
            else if(num[i][1]==D[3]) y=3;
            else if(num[i][1]==D[4]) y=4;
            else if(num[i][1]==D[5]) y=5;
            else if(num[i][1]==D[6]) y=6;
    printf("%d\n",D[Dice(x,y)]);        
    }

    
    return 0;
}

int Dice(int x,int y){
    int a;
    if((x==2&&y==3)||(x==4&&y==2)||(x==5&&y==4)||(x==3&&y==5)) a=1;
    if((x==1&&y==4)||(x==3&&y==1)||(x==6&&y==3)||(x==4&&y==6)) a=2;
    if((x==1&&y==2)||(x==5&&y==1)||(x==6&&y==5)||(x==2&&y==6)) a=3;
    if((x==1&&y==5)||(x==2&&y==1)||(x==6&&y==2)||(x==5&&y==6)) a=4;
    if((x==1&&y==3)||(x==4&&y==1)||(x==6&&y==4)||(x==3&&y==6)) a=5;
    if((x==2&&y==4)||(x==3&&y==2)||(x==5&&y==3)||(x==4&&y==5)) a=6;

    return a;
}


Measured memory_bytes: 2044
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

string s;

int main(){
	cin>>s;
	if(s.size()%2==0^s[0]!=s.back()) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

Measured memory_bytes: 512
from bisect import bisect
def inpl(): return list(map(int, input().split()))

N, L = inpl()
DP = [1e10]*(10**5 + 2)
DP[0] = 0
for i in range(N):
    DP2 = [1e10]*(10**5 + 2)
    w, v = inpl()

    for i in range(10**5, v-1, -1):
        DP2[i] = min(DP[i-v] + w, DP[i], DP2[i+1])
    for i in range(v-1, -1, -1):
        DP2[i] = min(DP[i], DP2[i+1])
    DP = DP2
print(bisect(DP, L)-1)

Measured memory_bytes: 128232
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main() {
  
  int N, K;
  scanf("%d %d", &N, &K);
  
  long long n = N/K;
  long long m = (N+K/2)/K;
  long long ans = n*n*n;
  if (K % 2 == 0) {
  	ans += m*m*m;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	REP(i, a) cin >> p[i];
	sort(p.rbegin(), p.rend());
	REP(i, b) cin >> q[i];
	sort(q.rbegin(), q.rend());
	REP(i, c) cin >> r[i];
	sort(r.rbegin(), r.rend());

	vector<ll> res;
	REP(i, x) res.push_back(p[i]);
	REP(i, y) res.push_back(q[i]);
	sort(res.begin(), res.end());
	REP(i, min((int)r.size(), (int)res.size())) {
		res[i] = max(res[i], r[i]);
	}
	cout << accumulate(res.begin(), res.end(), 0L) << '\n';
    return 0;
}


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

int main(){
    int n;
    ll d;
    cin >> n >> d;

    int ans = 0;

    d *= d;

    rep(i, n){
        ll a, b;
        cin >> a >> b;

        ll d1;

        d1 = pow(a,2) + pow(b, 2);

        if (d1 <= d){
            ans++;
        }
    }

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

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
#define PI 3.14159265359
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int main() {
	int h, a; cin >> h >> a;
	int sum = 0;
	REP(i, a) {
		int a; cin >> a;
		sum += a;
	}
	if (sum >= h)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

typedef long long ll;

#define N 100010

int n,Ans,T;
int A[N];
map<int,bool> flag;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}


int main()
{
	n=read();T=read();
	for(int i=1;i<=n;i++)
	{
		A[i]=read();
	}
	int Min=A[1],Max=0,Ans=0;
	for(int i=2;i<=n;i++)
	{
		int now=A[i]-Min;
		if(now>Max)
			Max=now;
		Min=min(Min,A[i]);
	}
	for(int i=n;i>=1;i--)
	{
		int now=A[i]+Max;
		flag[A[i]]=true;
		if(!flag[now])
			continue;
		Ans++;
	}
	cout<<Ans<<endl;				
	return 0;
}

Measured memory_bytes: 9984
import std.stdio;
import std.range;
import std.conv;
import std.algorithm;
import std.string;
import std.array;
import std.conv;
import std.typecons;

void main()
{
    int[11][4][5] bewur;
    int n = 0;
    readf("%d\n", &n);
    auto a = new Tuple!(int, "b", int, "f", int, "r", int, "v")[n];
    for (int i = 0; i < n; i++)
    {
        readf("%d %d %d %d\n", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
        bewur[a[i].b][a[i].f][a[i].r] += a[i].v;
    }
    for (int b = 1; b <= 4; b++)
    {
    for (int f = 1; f <= 3; f++)
    {
    for (int r = 1; r <= 10; r++)
    {
    write(" ",bewur[b][f][r]);
    }writeln();
    }
    if (b != 4)writeln("####################");
    }
}



Measured memory_bytes: 2532
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <ld,ld>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
//const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("robot.in","r",stdin);
   freopen("robot.out","w",stdout);
}
const ll INF = (ll)1e9 + 7ll;
const ll INF1 = 998244353;
const ll INF2 = (ll)1e9 + 9ll;
const ll LLINF = (ll)1e18 + 1;
const ll INTmx = (int)2e9;
const ld EPS = (ld)1e-15;
const int N = 90;
ll a[N];
int main()
{
    //file();
    boos();
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
	}
	ll tek = 1000;
	ll kol = 0;
	int last = 1;
	for(int i = 2;i <= n;i++)
	{
		if(a[i] >= a[i - 1])
		{
			last = i - 1;
			kol = tek / a[i - 1];
			tek = tek % a[i - 1];
			tek += kol * a[i];
		}else {
			continue;
		}
	}
	cout << tek;
}

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

int main() {
    string a, b;
    cin >> a >> b;

    if (a.size()==b.size()) {
        for (int i=0; i<a.size(); i++) {
            cout << a.at(i) << b.at(i);
        }
        cout << endl;
    }
    else {
        for (int i=0; i<b.size(); i++) {
            cout << a.at(i) << b.at(i);
        }
        cout << a.at(a.size()-1) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100];

signed main() {
	int i;
	
	cin >> n;
	
	int sumA = 0;
	rep(i, n) {
		cin >> a[i];
		sumA += a[i];
	}
	
	int mini = 1145141919;
	int id = 0;
	rep(i, n) {
		int diff = abs(sumA - n * a[i]);
		if (mini > diff) {
			mini = diff;
			id = i;
		}
	}
	cout << id << endl;
	return 0;
}

Measured memory_bytes: 256