akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
       ll k,n; cin >> k >> n;
       vll a(n);
       rep(i,n) cin >> a[i];
       // cout << a[n-1]-a[0] << endl;
       ll ans = 1e9;
       ans  = min(ans,a[n-1]-a[0]);
       rep(i,n-1){
            ans = min(ans,a[i]-a[i+1]+k);
       }
       cout << ans << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
  int data[20001] = {};

  for (int i = 1; i < 20001; ++i) {
    int v = 0;
    for (int a = i; a % 5 == 0; a /= 5)
      ++v;
    data[i] = data[i-1] + v;
  }

  while (true) {
    int x;
    cin >> x;
    if (x == 0)
      break;
    cout << data[x] << endl;
  }
}


Measured memory_bytes: 3156
N = int(input().rstrip())
As = [int(x) for x in input().rstrip().split()]

base = 1
l = []
for x in As:
    if x == base:
        l.append(x)
        base += 1

if len(l) == 0:
    print('-1')
else:
    print(N - len(l))

Measured memory_bytes: 25768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,W,i,j;
    cin>>n>>W;
    ll w[n+4],v[n+4];
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll x[n+2][W+2];
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=W;j++)
        {
            if(i==0 || j==0){x[i][j]=0;}
            else if(j>=w[i-1])
            {
                x[i][j]=max(x[i-1][j],x[i-1][j-w[i-1]]+v[i-1]);
            }
            else
            {
                x[i][j]=x[i-1][j];
            }
        }
    }
    cout<<x[n][W]<<"\n";
}

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

template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<998244353>;

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

    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        if (i == 0 && d) {
            cout << 0 << endl;
            return 0;
        }
        mp[d]++;
    }

    if (mp[0] > 1) {
        cout << 0 << endl;
        return 0;
    }

    mint ans = 1;
    for (int i = 1; i < mp.size(); i++) {
        ans *= pow(mint(mp[i - 1]), mp[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4992
from itertools import permutations
N, M = map(int, input().split())
g = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    g[a][b] = g[b][a] = 1

cnt = 0
for e in permutations(range(1, N)):
    for a, b in zip([0] + list(e[:-1]), e):
        if not g[a][b]:
            break
    else:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(9);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]>=3200){
      b[8]++;
    }
    else{
      b[a[i]/400]++;
    }
  }
  int ans=0;
  for(int i=0;i<=7;i++){
    if(b[i]!=0){
      ans++;
    }
  }
  if(ans==0){
    cout << 1 << ' ' << b[8] << endl;
  }
  else{
    cout << ans << ' ' << ans+b[8] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define Inf 0x7fffffff
int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
    	if(n<=1199)
    	cout<<"ABC"<<endl;
    	else if(n<=2799)
    	cout<<"ARC"<<endl;
    	else 
    	cout<<"AGC"<<endl;
	}
    return 0;
}


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

using namespace std;

int main() {
    vector<vector<int> > g(3, vector<int>(3));
    vector<vector<bool> > f(3, vector<bool>(3));
    for (auto &i : g) {
        for (auto &j : i) {
            cin >> j;
        }
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (g[j][k] == b) {
                    f[j][k] = true;
                }
            }
        }
    }
    if (f[0][0] && f[0][1] && f[0][2] || f[0][0] && f[1][0] && f[2][0] ||
        f[0][0] && f[1][1] && f[2][2] || f[0][2] && f[1][1] && f[2][0] ||
        f[1][0] && f[1][1] && f[1][2] || f[2][0] && f[2][1] && f[2][2] ||
        f[0][1] && f[1][1] && f[2][1] || f[0][2] && f[1][2] && f[2][2]) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

cnt = 0
ans = 1
for i in range(1, N + 1):
    x = i
    c = 0
    while x % 2 == 0:
        x //= 2
        c += 1
    if cnt < c:
        cnt = c
        ans = i

print(ans)

Measured memory_bytes: 3572
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_D() {}


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

    int N, K; cin >> N >> K;
    string S; cin >> S;

    string T = S + "E";

    // 00011011100100
    // o[i] =      { 2, 3, 1}
    // z[i] =     {3, 1, 2, 2}
    // oz[i] = {0, 3, 2, 1, 3, 2, 1, 2}
    vi oz;
    int ol = 0, zl = 0;
    REP(i, N) {
        if (T[i] == '0') zl++;
        else ol++;

        if (T[i]!=T[i+1]){
            if (T[i]=='0') {
                if (oz.size() == 0) oz.push_back(0);
                oz.push_back(zl);
            }
            else {
                oz.push_back(ol);
            }

            zl = 0;
            ol = 0;
        }
    }

    // sum[i] : sum of oz [0,i] 
    // oz[i] =   {3, 2, 1, 3, 2, 1, 2, 0}
    // sum[i] = {0, 3, 5, 6, 9, 11, 12, 14, 14} 
    //          {-, o, oz, ozo, ozoz, ozozo, ozozoz, ozozozo}
    int L = oz.size();
    vi sum(L + 1, 0);
    sum[0] = 0;
    FOR(i, 0, L) {
        sum[i+1] = sum[i] + oz[i];
    }

    // K=0 : o (sum[1] - sum[0]), ozo -zo (sum[3] - sum[2])
    // K=1 : ozo (sum[3]-sum[0]), ozozo - oz (sum[5] - sum[2])
    // K=2 : ozozo(sum[5]-sum[0]), ozozozo - oz  (sum[7] - sum[2])
    int ans = 0;
    for(int i=0; i<L; i+=2) {
        int l = i;
        int r = min(i + 2 * K + 1, L);
        int len = sum[r] - sum[l];
        ans = max(ans, len);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;}
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;}
    return false;
}

struct BipartiteGraph{
    int n,num;
    vector<int> par,rank;
    BipartiteGraph(int n):n(n),num(2*n),par(2*n),rank(2*n,1){
        iota(all(par),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
    void add_edge(int u,int v){
        merge(u,v+n),merge(u+n,v);
    }
    bool build(){
        rep(i,n) if (same(i,i+n)) return false;
        return true;
    }
};

template<typename T>
void Warshall_Floyd(vector<vector<T>> &d,T id){
    rep(k,d.size()){
        rep(i,d.size()){
            rep(j,d.size()){
                if (d[i][k]==id||d[k][j]==id) continue;
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<vector<int>> d(N,vector<int>(N,INF));
    rep(i,N) d[i][i]=0;
    BipartiteGraph BG(N);
    rep(i,N) rep(j,N){
        char a; cin >> a;
        int x=a-'0';
        if (x) d[i][j]=d[j][i]=1,BG.add_edge(i,j);
    }
    if (!BG.build()){
        cout << -1 << endl;
        return 0;
    }
    Warshall_Floyd(d,(int)INF);
    int ans=0;
    rep(i,N) rep(j,N) if (d[i][j]!=INF) chmax(ans,d[i][j]);
    cout << ans+1 << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		long a = Long.parseLong(strArr[0]);
		long b = Long.parseLong(strArr[1]);
		long c = Long.parseLong(strArr[2]);
		long d = Long.parseLong(strArr[3]);
		long max = a * c;
		if (max < a * d)
			max = a * d;
		if (max < b * c)
			max = b * c;
		if (max < b * d)
			max = b * d;
		System.out.println(max);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 25272
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  v<int> a(N);
  int sum = 0;
  rep(i,N){
    cin >> a[i];
    sum^=a[i];
  }
  rep(i,N){
    int num = sum^a[i];
    cout << num << endl;
  }
  return 0;
}


Measured memory_bytes: 4708
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    long long N;
    cin >> N;
    long long sum = 0;

    for (long long i = 1; i <= N; ++i)
    {
        if (i % 3 == 0 || i % 5 == 0) continue;
        else sum += i;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, l[105], x, ans = 1;
  scanf("%d %d", &n, &x);
  for(int i = 0; i < n; i++) scanf("%d", &l[i]);

  int d = 0;
  for(int i = 1; i <= n; i++){
    d += l[i - 1];
    if(d <= x) ans++;
  }

  printf("%d\n", ans);

  return 0;
}
					    


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second

ll FastModExp(ll a,ll b,ll m)
{
// To compute a^b mod m
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=(res*a)%m;
        }
        a=(a*a)%m;
        b=b>>1;
    }

    return res;
}
int main()
{
    ll n,i,j,c=0;
    cin>>n;
    vector<ll> v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    ll mx=v[0];
    for(auto h:v)
    {
        if(h>=mx) c++;
        mx=max(mx,h);
    }
    cout<<c;
    
    return 0;
}





Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        String ans = "";

        if(Math.abs(c-a) <= d) {
            ans = "Yes";
        } else if(Math.abs(b-a) <= d && Math.abs(c-b) <= d) {
            ans = "Yes";
        } else {
            ans = "No";
        }

        System.out.println(ans);
    }
}

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

using namespace std;

void bfs(vector<int>& parent, vector<vector<int>>& to){
  queue<int> q;
  q.push(0);
  parent[0] = 0;
  while(!q.empty()){
    int node = q.front();
    q.pop();
    
    for(int next : to[node]){
      if(parent[next] >= 0) continue;
      
      parent[next] = node;
      q.push(next);
    }
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<vector<int>> to(N);
  for(int i = 0; i < M; i++){
    int A, B;
    cin >> A >> B;
    --A; --B;
    
    to[A].push_back(B);
    to[B].push_back(A);
  }
  
  vector<int> parent(N, -1);
  bfs(parent, to);
  
  puts("Yes");
  for(int i = 1; i < N; i++) cout << parent[i] + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 10156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<string, string> P;
const ll MOD = 1000000007LL;

int main() {
	string S;
	cin >> S;
	int x = 0;
	for (int i = 0; i < 4; i++) {
		if (S[i] == '+') x++;
		else x--;
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#ifdef LOCAL_ENV
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#else
const bool test = false;
#define dump(x) 
#endif
 
#else
const bool test = false;
#define dump(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
void solve();
 
class Solver {
public:
  int N, A, B;
 
  void solve() {
    cin >> N >> A >> B;
    cout << min(A * N, B) << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


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

if k == n:
    print(0)
    exit()

dp = [[0 for _ in range(n)] for _ in range(n-k)]

dp[0] = [] + h

for x in range(1, n-k):
    for y in range(n):
        temp = float('inf')
        for i in range(y):
            temp = min(temp, dp[x-1][i] + max(0, h[y] - h[i]))
        dp[x][y] = temp

#for x in dp: print(x)

print(min(dp[n-k-1]))

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

int main() {

    int A,B;
    cin >> A >> B;
    
                                                                                                                                                                                                                                                                                                                                                                                                  
        if (A >= 13) {
            cout << B << endl;
        }
    
        if (6 <= A && A <= 12) {
            cout << B / 2 << endl;
        }
    
        if (A <= 5) {
            cout << 0 << endl;
        }
        
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toLong)
    val ls = mutableListOf<Pair<Long, Long>>()
    (1..n).forEach {
        val (a, b) = readLine()!!.split(" ").map(String::toLong)
        ls.add(Pair(a, b))
    }
    ls.sortBy { it.first }
    var needs = m
    var cost = 0L
    for ((a, b) in ls) {
        if(needs < b){
            cost += needs * a
            break
        }else{
            cost += b * a
            needs -= b
        }
    }
    println(cost)
}

Measured memory_bytes: 86364
#include<iostream>
#include<queue>
#include<string>

using namespace std;

pair <string, int> P;

int main(void) {
  int n;
  int quantum;

  queue<pair<string, int> > Q;
  cin >> n;
  cin >> quantum;

  pair<string, int> inputer;
  for(int i = 0; i < n; i++) {
    cin >> inputer.first;
    cin >> inputer.second;
    Q.push(inputer);
  }
  
  int minTime;
  int passedTime = 0;
  while(!Q.empty()) {
    pair<string, int> item = Q.front();
    Q.pop();
    int sub = item.second - quantum;
    minTime = min(item.second, quantum);
    passedTime += minTime;
    if(sub > 0) {
      pair<string, int> adder;
      adder.first = item.first;
      adder.second = sub;
      Q.push(adder);
    }
    else {
      cout << item.first << " " << passedTime << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int dir = -1;
int low = 0,high,mid = 0;
int f(int x){
	if(x<=mid)return low;
	else return min(high,low+x-mid);
}
int X,K,Q;
struct query{
	int type; // 0 upd,1 query
	int time,a,id;
	query(int type,int time,int a,int id):type(type),time(time),a(a),id(id){}
};
bool comp(query a,query b){
	return a.time < b.time;
}
vector<query> qs;
int ans[100100];
void update(int T){
	if(dir==-1){
		if(low<T)mid = min(X,mid+T-low);
		low = max(0,low-T);
		high = max(0,high-T);
	}else{
		low = min(X,low+T);
		high = min(X,high+T);
	}
}
int main(){
	scanf("%d",&X);
	high = X;
	scanf("%d",&K);
	for(int i=0;i<K;i++){
		int r;
		scanf("%d",&r);
		qs.pb(query(0,r,-1,-1));
	}
	scanf("%d",&Q);
	for(int i=0;i<Q;i++){
		int t,a;
		scanf("%d %d",&t,&a);
		qs.pb(query(1,t,a,i));
	}
	sort(all(qs),comp);
	int prev = 0;
	for(int i=0;i<qs.size();i++){
		//printf("%d: %d %d %d %d\n",i,qs[i].type,qs[i].time,qs[i].a,qs[i].id);
		//printf("low %d high %d mid %d\n",low,high,mid);
		if(qs[i].type==0){
			update(qs[i].time-prev);
			dir*=-1;
		}else{
			update(qs[i].time-prev);
			ans[qs[i].id]=f(qs[i].a);
		}
		prev = qs[i].time;
	}
	for(int i=0;i<Q;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 6512
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, m, x, y, mxx = -100, miy = 100;
    scanf("%d%d%d%d", &n, &m, &x, &y);
    for (int i = 0, j; i < n; ++i)
    {
        scanf("%d", &j);
        mxx = max(mxx, j);
    }
    for (int i = 0, j; i < m; ++i)
    {
        scanf("%d", &j);
        miy = min(miy, j);
    }
    printf(max(x, mxx) < min(y, miy) ? "No War\n" : "War");
}


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

#define _BIGNUM_ 100000000

using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A+B >= C) {
    cout << B+C << endl;
  } else {
    int d = 0;
    for (int j = A+B; j > 0 && C > 0; --j) {
      d += 1;
      C -= 1;
      
    }
    cout << B+d+1 << endl;
  }
}


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


int main(void) {
    using namespace std;

    long n, z, w;
    cin >> n >> z >> w;
    vector<long> a(n);
    for(auto &x: a) cin >> x;

    vector<long> dpx(n, 0), dpy(n, 1e10);

    dpx[n-1] = abs(a[n-2] - a[n-1]);
    dpy[n-1] = abs(a[n-2] - a[n-1]);

    for(int i=n-2; i>0; i--) {
        dpy[i] = abs(a[i-1] - a[n-1]);
        for(int j=i+1; j<n; j++)
            dpy[i] = min(dpy[i], dpx[j]);

        dpx[i] = abs(a[i-1] - a[n-1]);
        for(int j=i+1; j<n; j++)
            dpx[i] = max(dpx[i], dpy[j]);
    }
    {
        int i = 0;
        dpy[i] = abs(z - a[n-1]);
        for(int j=i+1; j<n; j++)
            dpy[i] = min(dpy[i], dpx[j]);

        dpx[i] = abs(w - a[n-1]);
        for(int j=i+1; j<n; j++)
            dpx[i] = max(dpx[i], dpy[j]);
    }

    cout << dpx[0] << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
summ = 0
i = 0
while i < N-1:
  summ += abs(A[i]-A[i+1])
  i += 1
print(abs(A[1])+abs(A[N-1])+summ-abs(A[0]-A[1]))
j = 1
while j < N-1:
  print(abs(A[0])+abs(A[N-1])+summ-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])+abs(A[j-1]-A[j+1]))
  j += 1
print(abs(A[0])+abs(A[N-2])+summ-abs(A[N-2]-A[N-1]))

Measured memory_bytes: 14048
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)


int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x_vec(N);
	vector<int> y_vec(M);
	rep(i, N) cin >> x_vec.at(i);
	rep(i, M) cin >> y_vec.at(i);

	sort(x_vec.begin(), x_vec.end(), greater<int>());
	sort(y_vec.begin(), y_vec.end());
	int max_x = x_vec.at(0);
	int min_y = y_vec.at(0);

	if (max_x < X or Y <= min_y or max_x >= min_y) cout << "War" << endl;
	else cout << "No War" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string n;
    cin >> n;
    for (int i = 0; i < n.size(); ++i) {
        if (n[i] == '1') {
            n[i] = '9';
        } else {
            n[i] = '1';
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)

int main(){
  string n;
  LL check=0;
  cin >> n;
  
  REP(i,0,n.size()){
    check += n[i] - '0';
  }
  if((check%9) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}


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

int main(){
  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; x++){
    for (int y = 0; y <= k; y++){
      int z = s - x -y;
      if (0 <= z && z <= k) count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
let () =
  Scanf.scanf "%d %d %d" (fun a b c ->
    let m = max a (max b c) in
    let a, b, c = m-a, m-b, m-c in
    a/2 + b/2 + c/2 + [|0;2;1|].(a mod 2 + b mod 2 + c mod 2))
  |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k;
bool b[205][205];
int q[205],h,t;int dis[205],vis[205];
char c[205];
int bfs(int x){
	h=0;q[t=1]=x;
	memset(dis,10,sizeof(dis));
	memset(vis,0,sizeof(vis));
	dis[x]=0;vis[x]=1;
	while(h<t){
		int u=q[++h];
		for(int i=1;i<=n;i++)if(i!=u&&b[u][i]){
			if(vis[i]&&(dis[i]+dis[u]+1)&1){
				cout<<-1;
				exit(0);
			}
			if(!vis[i])dis[i]=dis[u]+1,vis[i]=1,q[++t]=i;
		}
	}int all=0;
	for(int i=1;i<=n;i++)if(vis[i])all=max(all,dis[i]);
	return all;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%s",c+1);
		for(int j=1;j<=n;j++)b[i][j]=(c[j]=='1');
	}
	int ret=0;
	for(int i=1;i<=n;i++)ret=max(ret,bfs(i));cout<<ret+1;
    return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

const double PI = acos(-1);

int main(){

    int X;
    cin >> X;

    // A > 0 > B
    for(int A = 1; A*A*A*A*A <= X; A++){
        for (int B = -1; -B*B*B*B*B <= X; B--){
            if (A*A*A*A*A - B*B*B*B*B == X){
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }

    // A > B >= 0
    for(int A = 1; A*A*A*A <= X; A++){
        for (int B = 0; B < A; B++){
            if (A*A*A*A*A - B*B*B*B*B == X){
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3196
require 'prime'
# n = gets.chomp.to_i
a, b = gets.chomp.split().map(&:to_i)

a_prime = a.prime_division.map{|x,y| x}
b_prime = b.prime_division.map{|x,y| x}
nums = a_prime & b_prime

ans = 0
d = nums.size
(2**d).times do |i|
  bits = i.to_s(2).split(//)
  (d - bits.length).times{bits.unshift('0')}

  selected = []
  bits.each_with_index do |bit, i|
    if bit == '1'
      selected.push nums[i]
    end
  end

  if selected.combination(2).all?{|x,y| x.gcd(y) == 1}
    # p ['selected', selected]
    ans = [ans, selected.count].max
  end

end

puts ans + 1



Measured memory_bytes: 2300
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SI(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define debugV(x) for(int i=0;i<((ll)(x).size());i++)cerr << #x <<"at:"<<i<< ": " << x[i] << "\n"//手動デバッグ 
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
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 gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    int n,k;cin>>n>>k;
    vector<ll> h(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(ALL(h));
    ll ans=INF;
    rep(i,n-k+1){
        ans=min(h[i+k-1]-h[i],ans);
    }
    O(ans);
    
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = 1<<28;
struct edge{
  int to,cost;
  edge(int a,int c){
    to = a;
    cost = c;
  }
};
typedef pair<int,pair<int,int> > P;

void dijk(int s,int g,vector<vector<int> > &field,vector<vector<edge> > &G){
  priority_queue<P,vector<P>,greater<P> > que;
  field[s][0] = 0;
  que.push(P(0,pair<int,int>(s,0)));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second.first;
    int v_f = p.second.second;
    if(field[v][v_f] < p.first)continue;
    for(int i = 0;i < G[v].size();i++){
      edge e = G[v][i];
      if(field[e.to][v_f] > field[v][v_f]+e.cost){
	field[e.to][v_f] = field[v][v_f]+e.cost;
	que.push(P(field[e.to][v_f],pair<int,int>(e.to,v_f)));
      }
      if(v_f == 0){
	for(int j = 0;j < G[e.to].size();j++){
	  edge ne = G[e.to][j];
	  if(field[ne.to][1] > field[v][v_f]){
	    field[ne.to][1] = field[v][v_f];
	    que.push(P(field[ne.to][1],pair<int,int>(ne.to,1)));
	  }
	}
      }
    }
  }
}
int main(){
  int n,m;
  while(cin >> n >> m,n != 0 || m != 0){
    vector<vector<int> > field(n,vector<int>(2,INF));
    vector<vector<edge> > G(n);
    for(int i = 0;i < m;i++){
      int a,b,c;
      cin >> a >> b >> c;      
      G[a-1].push_back(edge(b-1,c));
      G[b-1].push_back(edge(a-1,c));
    }
    dijk(0,n-1,field,G);
    int ans;
    if(field[n-1][0] < field[n-1][1]){
      cout << field[n-1][0] << endl;
    }else{
      cout << field[n-1][1] << endl;
    }
    
  }

  return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
#include<math.h>
int main()
{
   int A,B=0,C=0,D,e,f,g=0;
   scanf("%d",&A);
   D=A;
   while(D/10>0)
   {
       B+=1;
      D=D/10;

   }
   e=B;
   f=B;
   if(e%2==0){
       for(int i=e;i>=1;i--){
    C+=(pow(10,i-1)-pow(10,i-2));
   i--;
   }
   C+=(A-pow(10,B));
   printf("%d",C+1);
   }else if(f%2==1){
       for(int i=f;i>=1;i--){
    g+=(pow(10,i)-pow(10,(i-1)));
    i--;
       }
       printf("%d",g);
   }
return 0;
}

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

int main(){
  long long int n,m,c,i,j,t;
  long long int anstemp = 0;
  long long int ans = 0;
  scanf("%lld",&n);
  scanf("%lld",&m);
  scanf("%lld",&c);
  long long int b[m];
  for(i=0;i<m;i++) {
    scanf("%lld",&b[i]);
  }
  for(j=0;j<n;j++) {
    anstemp = 0;
    for(i=0;i<m;i++) {
      scanf("%lld",&t);
      anstemp += t * b[i];
    }
    if(anstemp+c>0) {
      ans++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;

  cin>>N;
  for(int i=0; i<3; i++){
    N=N%10;
  }

  if(N==3){
    cout<<"bon"<<endl;
  }
  else if(N==0||N==1||N==6||N==8){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"hon"<<endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){	
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	char c;
	cin >> c;
	switch (c)
	{
		case 'A':
			cout << 'T' << '\n';
			break;
		case 'C':
			cout << 'G' << '\n';
			break;
		case 'G':
			cout << 'C' << '\n';
			break;
		case 'T':
			cout << 'A' << '\n';
			break;
	
		default:
			break;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{   
 public void yatary() {  
      Scanner sc = new Scanner(System.in); 
        int x; 
        int y;  
        x = sc.nextInt();
       y = sc.nextInt();
        while(x!=0 || y!=0){
          if(x > y){
              System.out.println(y + " " + x);
          }else{
                 System.out.println(x + " " + y);
          }    
             x = sc.nextInt();
          y = sc.nextInt();
      }
     }
public static void main(String[] args){ 
    new Main().yatary();    
}
} 

Measured memory_bytes: 27236
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
#define ll long long
#define fo(i,v,e) for(v=i;v<e;v++)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define deb(x...)
#endif

vector<ll> sieveOfErthnosis(ll n)
{
    vector<bool>flag(n+5,false);
    vector<ll>primes;
    for(int i=2;i*i<=n;i++)
    {
        if(!flag[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {flag[j]=true;}
        }
    }
    for (int  i = 2; i < n+1; i++)
    {
        if(!flag[i])primes.pb(i);
    }
    return primes;
}
void init()
{

}
ll get(ll n)
{
    return (n*(n-1))/2;
}
void solve()
{
    ll n,i,j,ans = 0;cin>>n;
    vl arr(n),count(n+1,0);
    fo(0,i,n)
    {
        cin>>arr[i];
        count[arr[i]]++;;
    }
    fo(0,i,n+1)
    {
        ans+=get(count[i]);
    }
    fo(0,i,n)
    {
        cout<<ans-get(count[arr[i]])+get(count[arr[i]]-1)<<endl;
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    #endif
    init();
    auto start = high_resolution_clock::now(); 
    int T = 1;
    // cin>>T;
	while(T--)
	{
		solve();
	}
    auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<milliseconds>(stop - start); 
    #ifndef ONLINE_JUDGE
	// cout << "time taken : "<<duration.count()<<" ms" << endl;
     #endif
}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int  q1,b,q2,ans;
int c1,c2;
int L,R,M;

int  calcB(int A){
  int money = b-A*c1;
  if(money>=0)return money/c2;
  else return -1000;
}

  
bool check(int x){
  int A,B;
  A=x;
  B=calcB(A);
  if(B>=0&&A>0&&A+B>=q1)return true;
  else return false;
}

int main(){
  while(cin>>q1){
    ans=-1;
    if(q1==0)break;
    cin>>b>>c1>>c2>>q2;

    L=1;
    R=q2;
    M=(L+R)/2;

    while(L<=R){
      if(check(M)&&!check(M+1)){
	break;
      }else if(check(M)){
	L=M+1;
	M=(L+R)/2;
      }else{
	R=M-1;
	M=(L+R)/2;
      }
	
    }


    if(check(M)&&check(M+1)==false  || (M==q2&&check(M))){
      
      cout<<M<<' '<<calcB(M)<<endl;
    } else cout<<"NA"<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

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

    int n;
    while (cin >> n, n) {
        int w, h;
        cin >> w >> h;
        vector<vector<bool>> exist(w, vector<bool>(h, false));
        rep(i, n) {
            int x, y;
            cin >> x >> y;
            x--; y--;
            exist[x][y] = true;
        }

        int s, t;
        cin >> s >> t;
        int ans = 0;
        rep(x, w - s + 1) {
            rep(y, h - t + 1) {
                int cnt = 0;
                rep(i, s) {
                    rep(j, t) {
                        cnt += exist[x + i][y + j];
                    }
                }
                ans = max(ans, cnt);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3028
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]

B = []
cnt = 0
for i in A:
    if i < 0:
        cnt += 1
    B.append(abs(i))

if cnt % 2 == 0:
    print(sum(B))
else:
    print(sum(B) - 2 * min(B))

Measured memory_bytes: 21536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
typedef long long ll;
int main(void){
  int n;
  int i,j,k;
  int c;
  vector<int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>k;
  cout<<a[k-1];
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
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; }

ll n, m;

int main() {
    cin >> n >> m;
    vector<ll> xvec(n, 0);
    vector<ll> yvec(n, 0);
    vector<ll> zvec(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> xvec.at(i) >> yvec.at(i) >> zvec.at(i);
    }

    ll ans = 0;
    for(int i = -1; i <= 1; i+=2) {
        for(int j = -1; j <= 1; j+=2) {
            for(int k = -1; k <= 1; k+=2) {
                ll sum = 0;
                vector<ll> ansvec;
                for(int l = 0; l < n; ++l) {
                    ansvec.emplace_back(xvec.at(l)*i + yvec.at(l)*j + zvec.at(l)*k);
                }
                sort(ansvec.begin(), ansvec.end(), greater<ll>());
                for(int l = 0; l < m; ++l) sum += ansvec.at(l);
                chmax(ans, sum);
            }
        }
    }
    
    cout << ans << endl;
}

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

vector<int> distribute_r(int x, int d) {
    vector<int> cnt(d);
    int quotient = x / d, fraction = x % d;
    for (int r = 0; r < d; r++) cnt[r] = quotient + (r < fraction);
    return cnt;
}

vector<int> operator-(vector<int> a, vector<int> b) {
    for (int i = 0; i < a.size(); i++) a[i] -= b[i];
    return a;
}

int main() {
    int L, R; cin >> L >> R;
    auto cnt = distribute_r(R + 1, 2019) - distribute_r(L, 2019);
    int ans = 2019;
    for (int i = 0; i < 2019; i++) for (int j = 0; j < 2019; j++) {
        if (cnt[i] == 0 || cnt[j] == 0) continue;
        if (i == j && cnt[i] < 2) continue;
        ans = min(ans, i * j % 2019);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char card[3][101]; // a=0,b=1,c=2
  int a_len,b_len,c_len;
  int i_a=0,i_b=0,i_c=0,now=0;
  
  scanf("%s",card[0]);
  a_len=strlen(card[0]);

  scanf("%s",card[1]);
  b_len=strlen(card[1]);

  scanf("%s",card[2]);
  c_len=strlen(card[2]);
  
  while(a_len>0 && b_len>0 && c_len){
    //printf("*%c\n",now+'A');
    switch(now){
      case 0:
        if(i_a==a_len){
          printf("A");
          return 0;
        }
        
        switch(card[0][i_a]){
          case 'a':
            i_a++;
            break;
          case 'b':
            now=1;
            i_a++;
            break;
          case 'c':
            now=2;
            i_a++;
        }
        break;
      case 1:
        if(i_b==b_len){
          printf("B");
          return 0;
        }
        
        switch(card[1][i_b]){
          case 'a':
            now=0;
            i_b++;
            break;
          case 'b':
            i_b++;
            break;
          case 'c':
            now=2;
            i_b++;
        }
        break;
      case 2:
        if(i_c==c_len){
          printf("C");
          return 0;
        }
        
        switch(card[2][i_c]){
          case 'a':
            now=0;
            i_c++;
            break;
          case 'b':
            now=1;
            i_c++;
            break;
          case 'c':
            i_c++;
        }
    }
  }
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
    int N,A[1000],i,same,ans=0;
    scanf("%d",&N);
    for(i=0;i<N;i++)scanf("%d",&A[i]);
    same=1;
    for(i=1;i<N;i++){
        if(A[i-1]==A[i]){
            same++;
        }else{
            ans+=same/2;
            same=1;
        }
    }
    ans+=same/2;
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,w;
	cin >> h >> w;
	vector<string> field(h);
	REP(i,h) cin >> field[i];
	vector<vector<int>> dist(h+1, vector<int>(w+1, 1e9));
	dist[0][0] = 0;
	REP(i,h) REP(j,w){
		if(i>0){
			int tmp = dist[i-1][j];
			if(field[i][j]=='#' && field[i-1][j]=='.') tmp++;
			dist[i][j] = min(dist[i][j], tmp);
		}
		if(j>0){
			int tmp = dist[i][j-1];
			if(field[i][j]=='#' && field[i][j-1]=='.') tmp++;
			dist[i][j] = min(dist[i][j], tmp);
		}
	}
	if(field[0][0]=='#') dist[h-1][w-1]++;
	cout << dist[h-1][w-1] << '\n';
	return 0;
}



Measured memory_bytes: 384