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

#define int long long
int INF = INT_MAX;

void maxself(int &a, int b) {a=max(a,b);}
void minself(int &a, int b) {a=min(a,b);}

int32_t main(){
    int n,w;cin>>n>>w;
    vector<int> values(n), wieght(n);

    for(int i=0;i<n;i++){
        cin>>wieght[i]>>values[i];
    }
    int sum_value=0;
    for(auto x: values){
        sum_value+=x;
    }
    vector<int> dp(sum_value+1, INF);
    dp[0]=0;
    //dp[i] is the minimum total weight of items with total value exactly i
    for(int i=0;i<n;i++){
        for(int value_already=sum_value-values[i]; value_already>=0; value_already--){
            minself(dp[value_already+values[i]], dp[value_already]+wieght[i]);
        }
    }
    int ans=0;
    for(int i=sum_value;i>=0;i--){
        if(dp[i]<=w) maxself(ans, i);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3976
lia = input().split()
lib = input().split()
lic = input().split()
n=int(input())
num_list=[input() for i in range(n)]

ans=0

for i in range(0,3):
  for l in range(0,n):
    if lia[i]==num_list[l]:
      lia[i]=0
for i in range(0,3):
  for l in range(0,n):
    if lib[i]==num_list[l]:
      lib[i]=0
for i in range(0,3):
  for l in range(0,n):
    if lic[i]==num_list[l]:
      lic[i]=0
    
if lia.count(0)==3:
  ans=1
if lib.count(0)==3:
  ans=1
if lic.count(0)==3:
  ans=1
for k in range(0,3):
  if lia[k]==lib[k]==lic[k]:
    ans=1
    
if lia[0]==lib[1]==lic[2] or lia[2]==lib[1]==lic[0]:
  ans=1
  
if ans==1:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
sx, sy, tx, ty = gets.split.map(&:to_i)
a = tx - sx
b = ty - sy
print "U" * b + "R" * a
print "D" * b + "L" * a
print "L" + "U" * (b + 1) + "R" * (a + 1) + "D"
print "R" + "D" * (b + 1) + "L" * (a + 1) + "U" + "\n"

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a>b&&c>d)
    cout << b+d << endl;
    else if(a<=b && c>d)
    cout << a+d << endl;
    else if(a<=b && c<=d)
    cout << a+c << endl;
    else
    cout << b+c << endl;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B 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 LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false); 
    
    int N, X; cin >> N >> X;
    vi L(N + 1); FOR(i, 1, N+1) cin >> L[i];

    vi D(10010, 0);

    D[1] = 0;
    int ans = 1;
    FOR(i,2,N+2) {
        D[i] = D[i - 1] + L[i - 1];
        if (D[i] <= X) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,ans=0;
    vector<pair<ll,ll> > v;
    ll a,b;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        v.pb(make_pair(b-1,a-1));
    }
    sort(be(v));
    for(int i=0;i<m;i++){
        swap(v[i].first,v[i].second);
    }
    ll index=-1;
    for(int i=0;i<m;i++){
        if(v[i].first>=index){
            ans++;
            index=v[i].second;
        }
    }
    cout << ans<<endl;
    return 0;
}


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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator& itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator& begin() {return i;}
  Iterator& end() {return n;}
};

template<class T> inline T at(const vector<T> &v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

template<class T> inline bool is_max(T &a, const T &b) {return a < b ? a = b, true : false;}
template<class T> inline bool is_min(T &a, const T &b) {return a > b ? a = b, true : false;}

class BipMatch {
private:
  vector<vector<int>> g;
  vector<int> match;
  vector<bool> used;
  
  bool dfs(int v) {
    used[v] = true;
    for (int u : g[v]) {
      int w = match[u];
      if (w < 0 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
  
public:
  int next() {
    g.emplace_back(vector<int>());
    return g.size() - 1;
  }
  
  void add_edge(int u, int v) {
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  
  int run() {
    match = vector<int>(g.size(), 0);
    used = vector<bool>(g.size(), false);
    int res = 0;
    fill(match.begin(), match.end(), -1);
    for (int i : range(g.size())) if (match[i] < 0) {
      fill(used.begin(), used.end(), 0);
      if (dfs(i)) res++;
    }
    return res;
  }
};

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0) break;
    int b[m], r[n];
    for (int i : range(m)) cin >> b[i];
    for (int i : range(n)) cin >> r[i];
    BipMatch bm;
    int bi[m], ri[n];
    for (int i : range(m)) bi[i] = bm.next();
    for (int i : range(n)) ri[i] = bm.next();
    for (int i : range(m)) for (int j : range(n)) if (__gcd(b[i], r[j]) > 1) bm.add_edge(bi[i], ri[j]);
    cout << bm.run() << endl;
  }
}

Measured memory_bytes: 2720
#include <iostream>
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; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 89588
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
  A[i] -= i+1
#print(A)
A.sort()
dic = {}
for x in A:
  if x not in dic:
    dic[x] = 1
  else:
    dic[x] += 1
S = list(dic.keys())
now = 0
for x in A:
  now += abs(A[0]-x)
#print(now)
prev = A[0]
left = dic[S[0]]; right = N- left
for i in range(1,len(S)):
  dif = (left-right)*(S[i]-S[i-1])
  if dif < 0:
    now += dif
  left += dic[S[i]]
  right -= dic[S[i]]
print(now)

Measured memory_bytes: 127428
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;
template<typename T>
T fastPow(T a, T b, T mod = 0) {
	if (a == 0 and b == 0) {
		return -1;
	}
	if (a == 0) {
		return 0;
	}
	if (b == 0) {
		return 1;
	}
	long long tmp = fastPow(a, b / 2, mod);
	if (mod != 0) {
		if (b % 2 == 0) {
			return (tmp * tmp) % mod;
		}
		else {
			return ((tmp*tmp) % mod * (a % mod)) % mod;
		}
	}
	else {
		if (b % 2 == 0) {
			return (tmp*tmp);
		}
		else {
			return tmp * tmp * a;
		}
	}
}

void print(string& st, vector<bool>& op) {
	cout << st[0];
	for (ll i = 1; i < 4; i++) {
		if (op[i] == true) {
			cout << "+";
		}
		else {
			cout << "-";
		}
		cout << st[i];
	}
	cout << "=7";
	cout << endl;
}

int main() {
	string s;
	cin >> s;
	vector <bool> ops;
	ops.resize(4);

	for (ll q = 0; q < fastPow(2, 3); q++) {
		ll nowQ = q;
		ll p = 1;
		while (nowQ > 0) {
			ops[p] = nowQ % 2;
			p++;
			nowQ /= 2;
		}

		ll tmpAns = s[0] - '0';

		for (ll i = 1; i < 4; i++) {
			if (ops[i] == true) {
				tmpAns += s[i] - '0';
			}
			else {
				tmpAns -= s[i] - '0';
			}
		}

		if (tmpAns == 7) {
			print(s, ops);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <algorithm>

using namespace std;

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  int min=a[0],max=a[0];
  for(int i=1;i<n;i++){
    min=std::min(min,a[i]);
    max=std::max(max,a[i]);
  }
  
  cout<<max-min;
  
  return 0;
}

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

//Pipeline Scheduling
public class Main{

	List<Integer>[] e;
	boolean[][] t;
	int res, n;
	
	void dfs(int k, int h, int max){
		if(k==10){
			res = Math.min(res, max); return;
		}
		if(res<=max||res<=h+n)return;
		for(int i=h;i<=max;i++){
			boolean ok = true;
			for(int y=0;y<5;y++){
				if(!ok)break;
				for(int x:e[y]){
					if(t[y][i+x]){
						ok = false; break;
					}
				}
			}
			if(ok){
				int m = 0;
				for(int y=0;y<5;y++){
					for(int x:e[y]){
						t[y][i+x] = true;
						m = Math.max(m, i+x);
					}
				}
				dfs(k+1, i+1, m);
				for(int y=0;y<5;y++){
					for(int x:e[y]){
						t[y][i+x] = false;
					}
				}
			}
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			e = new List[5];
			for(int i=0;i<5;i++)e[i]=new ArrayList<Integer>();
			t = new boolean[5][210];
			for(int i=0;i<5;i++){
				char[] s = sc.next().toCharArray();
				for(int j=0;j<n;j++)if(s[j]=='X'){
					t[i][j] = true; e[i].add(j);
				}
			}
			res = 1<<29;
			dfs(1, 0, n);
			System.out.println(res+1);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define piii pair<int,pair<int,int> >

#define readN(N,X) for(int i=0;i<N;i++) scanf("%d",&X[i]);
using namespace std;
int M;
int N;
vector<pii> path;
ll dist[1004][1004];
ll skor[1004];
int vis[1004];
int main(){
	read(N);
	read(M);

	FOR(i,0,M){
		int a,b,c;
		read(a); read(b); read(c);
		a--;
		b--;
		path.push_back(make_pair(a,b));
		dist[a][b] = c;

	}

	bool relax = 0;
	bool relaxN;
	FOR(i,0,N) skor[i] = 0;
	skor[0] = 0;
	vis[0] = 1;
	FOR(k,0,10000){
		relax = 0;
		relaxN = 0;
		FOR(i,0,M){
			pii lho = path[i];
			int a = lho.first;
			int b = lho.second;

			if (!vis[a]) continue;
			if (vis[b] == 0 || skor[b] < skor[a] + dist[a][b]){
				relax = 1;
				if (b == N-1) relaxN = 1;
				skor[b] = skor[a] + dist[a][b];
				vis[b] = 1;
			}
		}
	}
	if (relaxN) cout<<"inf"<<endl;
	else cout<<skor[N-1]<<endl;

}

Measured memory_bytes: 6784
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
#define MOD (1e9+7)
typedef pair < ll, ll> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}


ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N)//素数列挙
{
	std::vector<bool> is_prime(N + 1);
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	std::vector<int> P;
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

double R;
int main()
{
	cin >> R;
	double ans = (double)2 * R * PI;
		printf("% .6f", ans);
}


Measured memory_bytes: 3820
#include <stdio.h>
int Binarysearch(int*,int,int);
#define N 100005

int main()
{
  int i,s,array[N],t,m,sum=0;

  scanf("%d",&s);
  for(i=0;i<s;i++)
    {
      scanf("%d",&array[i]);
    }
  scanf("%d",&t);
  for(i=0;i<t;i++)
    {
      scanf("%d",&m);
      if(Binarysearch(array,s,m)) sum++;
    }
  printf("%d\n",sum);
  return 0;
}

int Binarysearch(int A[],int x, int key)
{
  int left=0,right,mid=0;
  right=x;
  while(left<right)
    {
      mid=(left+right)/2;
      if(key==A[mid]) return 1;
      else if(key<A[mid]) right=mid;
      else if(key>A[mid]) left=mid+1;
    }
  return 0;
}

Measured memory_bytes: 3036
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            long a = sc.nextLong();
            long b = sc.nextLong();
            long res1 = gcd(a, b);
            long res2 = a/res1*b;
            System.out.println(res1+" "+res2);
        }
    }
    public static long gcd(long a, long b){
        if(b==0) return a;
        else return gcd(b, a%b);
    }
}


Measured memory_bytes: 25952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define x first
#define y second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define szz(x) (int) (x).size()
#define FOR(i,a,b) for (int i = (a), _for = (b); i < _for; i++)
#define REP(i,n) FOR(i,0,(n))
#define _ << " " <<
const ll MOD = 1000000007ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
inline ll SUB(ll a, ll b) { return a-b >= 0ll ? a-b : a-b+MOD; }
inline ll ADD(ll a, ll b) { return a+b >= MOD ? a+b-MOD : a+b; }
inline ll MUL(ll a, ll b) { return a*b % MOD; }

const int MAXX = 1000;
int n, m;
int grid[MAXX + 3][MAXX + 3];
ll dp[MAXX + 3][MAXX + 3];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<string> grid(n);
  REP(i,n) cin >> grid[i];
  dp[0][0] = 1;
  REP(i,n) REP(j,m) {
    if (grid[i][j] != '.') continue;
    if (i > 0 && grid[i-1][j] == '.') dp[i][j] = ADD(dp[i][j], dp[i-1][j]);
    if (j > 0 && grid[i][j-1] == '.') dp[i][j] = ADD(dp[i][j], dp[i][j-1]);
  }
  cout << dp[n-1][m-1] << endl;
}


Measured memory_bytes: 9472
N = int(input())

s = [0] * N
t = [0] * N
for i in range(N):
    s[i], t[i] = input().split()
    t[i] = int(t[i])

X = input()

switch = 0
ans = 0

for i in range(N):
    if(switch == 1):
        ans += t[i];
    if(s[i] == X):
        switch = 1
        continue

print(ans)

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

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

const int INF = 1001001001;

int dp[5005][5005];

int main() {

    int n;
    string s;
    cin >> n >> s;

    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[i] != s[j]) {
                dp[i][j] = 0;
            } else {
                dp[i][j] = dp[i + 1][j + 1] + 1;
            }
        }
    }
    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if (i >= j) continue;
            int now = min(dp[i][j], j - i);
            ans = max(ans, now);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 98048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

struct MyStruct {
	int a, b;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.b != t.b)
		return s.b < t.b; //syoujunn
	return s.a > t.a;
}


int main() {
	long long l, r;
	cin >> l >> r;

	long long ql = l / 2019;
	long long rl = l % 2019;
	long long qr = r / 2019;
	long long rr = r % 2019;

	long long ans=3000;

	if (ql == qr) {
		FOR(i, rl, rr) {
			FOR(j, i + 1, rr) {
				ans = min((long long)i*j % 2019, ans);
			}
		}
	}
	else {
		ans = 0;
	}

	ANS(ans);
	return 0;
}


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

int main() {
  int N, K, x, i;
  cin >> N >> K;
  while (N) {
    cin >> x;
    if (x > K - x) i += K - x;
    else i += x;
    N--;
  }
  cout << i * 2 << endl;
}

Measured memory_bytes: 256
Uses math;
var
	h,w,ans:Longint;
begin
	read(h,w);
	if(h mod 3=0)or(w mod 3=0)then write(0)
	else if h mod 2=0 then if w mod 2=0 then write(Min(h div 2,w div 2))else write(Min(h div 2,w))
	else if w mod 2=0 then write(Min(h,w div 2))
	else if w=h then write(h-(h+1)div 6)else write(Min(w,h));
end.


Measured memory_bytes: 128
#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--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll dp[305][305][305];

int main(){
    int n, k; cin >> n >> k;
    vector<ll> h(n+1);
    FOR(i, 1, n+1) cin >> h[i];

    rep(i,n+1){
        rep(j,n+1){
            rep(s,n+1){
                dp[i][j][s] = 1e18;
            }
        }
    }

    dp[0][0][0] = 0;

    rep(i, n){
        int m = min(i, k);
        rep(j, m+1){
            rep(s, j+1){
                chmin(dp[i+1][j][0], dp[i][j][s] + max(0LL, h[i+1] - h[i-s]));

                chmin(dp[i+1][j+1][s+1], dp[i][j][s]);
            }
        }
    }

    ll ans = 1e18;
    rep(j, k+1){
        rep(s, j+1){
            chmin(ans, dp[n][j][s]);
        }
    }
    cout << ans << endl;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int nmax=100010;
const ll mod=1000000007;
bool used[nmax];



ll power(ll a,ll n){
	ll b=1LL;
	while(n){
		if(n&1) b=b*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return b%mod;
}

int par[nmax],ranks[nmax],sz[nmax];

void init(int n){rep(i,n) par[i]=i,ranks[i]=sz[i]=0;}
int find(int x){return (x==par[x])?x:par[x]=find(par[x]);}
void unite(int a,int b){
	a=find(a),b=find(b);
	if(ranks[a]<ranks[b])
		par[a]=b;
	else{
		par[b]=a;
		if(ranks[a]==ranks[b]) ranks[a]++;
	}
	return ;
}
bool same(int a,int b){return find(a)==find(b);}


int main(void){
	int n,m;
	while(cin >> n >> m){
		if(n==0&&m==0) break;
		rep(i,n) used[i]=false;
		init(n);

		rep(i,m){
			int a,b;
			cin >> a >> b;
			a--,b--;
			unite(a,b);
		}

		rep(i,n) sz[find(i)]++;

		if(m==0)
			cout << power(2,n) << endl;
		else{
			ll ans=1LL,num=0,res=0;
			rep(i,n){
				if(sz[i]>=2)
					num++;
				if(sz[i]==1)
					res++;
			}
			ans*=power(2,res);
			ans%=mod;
			ans*=power(2,num);
			ans%=mod;
			ans=(ans+1)%mod;
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define m_p			make_pair
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i =a, i>=b;i--)
#define sz(x)       (int)x.size()
#define F			first
#define S			second
#define debug(x)	for(int i=0;i<x;i++) cout<<"##########"<<endl
#define M			1000000007
#define ll			long long int
#define lMax		LLONG_MAX
#define pii 		pair<int ,int >
#define	all(a)		a.begin(), a.end()
#define vi 			vector<int> 
#define vii 		vector<pii>

// queue<int> , prefix_sum(a,a+n) , reverse(a,a+n) , priority_queue <int> max heap , priority_queue <int, vector<int>, greater<int> > min heap;
// == > != precedence gretaer then & , << precedence greater than <= == => , 
//int chk, cnt, fl, pos, in, src, tar, val, res. dummy;  fill (myvector.begin(),myvector.begin()+4,5), freq;

void solve()
{
	int n,k;
	cin>>n>>k;
	
	int arr[n];
	rep(i,0,n) cin>>arr[i];
	
	int dp[k+1]={0};
	
	rep(stones,1,k+1)
	{
		rep(i,0,n)
		{
			if(stones>=arr[i])
			{
				if(!dp[stones-arr[i]])
				{
					dp[stones]=1;
					break;
				}
			}
		}
	}
//	
//	rep(i,0,k+1) cout<<dp[i]<<" ";
//	cout<<endl;
	string ans;
	if(dp[k]) ans="First";
	else ans="Second";
	
	cout<<ans<<endl;
}


signed main()
{
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int t=1;
		while(t--)
		{
			solve();
		}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc116/b.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int visited[1000005];
int MAX = 1000000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int s;
    cin >> s;
    rep(i, MAX + 1){
        visited[i] = 0;
    }
    visited[s] = 1;
    int flag = 0;
    int tmp = s;
    int cnt = 1;
    while(flag == 0){
        cnt++;
        if(tmp % 2 == 0){
            tmp /= 2;
        }else{
            tmp = 3 * tmp + 1;
        }
        if(tmp <= MAX){
            if(visited[tmp] == 1){
                flag = 1;
                cout << cnt << "\n";
            }else{
                visited[tmp] = 1;
            }
        }
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {
  ll N; cin >> N;
  vvi x(100001), y(100001);
  for (ll i = 0; i < N; i++) {
    ll a, b; cin >> a >> b;
    x[a].push_back(b);
    y[b].push_back(a);
  }

  ll ans = 0;

  vvi visited(100001, vi(2));
  for (ll i = 0; i <= 100000; i++) {
    if (!visited[i][0] && x[i].size()) {
      vi cnt(3);
      queue<pii> q;
      q.push({i, 0});
      visited[i][0] = 1;
      cnt[0] += 1;
      while (q.size()) {
        pii fr = q.front();
        q.pop();
        if (fr.second == 0) {
          for (ll to: x[fr.first]) {
            if (!visited[to][1]) {
              visited[to][1] = 1;
              cnt[1] += 1;
              q.push({to, 1});
            }
          }
        } else {
          for (ll to: y[fr.first]) {
            if (!visited[to][0]) {
              visited[to][0] = 1;
              cnt[0] += 1;
              q.push({to, 0});
            }
          }
        }
      }
      ans += cnt[0] * cnt[1];
    }
  }

  cout << ans - N << endl;
}


Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


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

    vector<ll> ans(n);
    rep(i,n){
        if(i%2==0) ans[0]+=a[i];
        else ans[0]-=a[i];
    }

    for(int i=1;i<n;i++){
        ans[i]=2*a[i-1]-ans[i-1];
    }

    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;
}


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

int H, W, N;
int a[10001];
int field[101][101];

void solve(){
    int color = 1;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(i%2 == 0){
                if(a[color] > 0) field[i][j] = color;
                else field[i][j] = ++color;
            }
            else{
                if(a[color] > 0) field[i][W-1-j] = color;
                else field[i][W-1-j] = ++color;
            }
            a[color]--;
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << field[i][j] << " ";
        }
        cout << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> N;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define MAX_N 100010

/*
iの答え＝
(属する連結成分の個数)-(直接の友達)-(連結成分のうちブロック関係な人)-(自分自身)

連結成分の個数、どうやったら早くできるかな

連結成分の個数はBSFじゃないと求められないと思ってたけど
mergeするときのrankをsizeにしておけば超簡単に求められる
テンプレをこっちに修正しておこ、、、

グラフの入力も全く必要なかった、、、笑
*/

int par[MAX_N];//親の番号
int siz[MAX_N];//木のサイズ
//int rnk[MAX_N];

void init(int n)
{
  //根の定義・・・par[i]=iの時iを根という
  //最初全てが根
  for (int i=0;i<=n;i++){
    par[i]=i;
    siz[i]=1;
  }
}

//木の根を求める
int root(int x){
  if (par[x]==x){  //xが根の時
    return (x); 
  }else{
    par[x]=root(par[x]);//xを、xの親の根につなぎ直す
    return par[x]; //経路圧縮
  }
}

//x,yが同じ集合に属しているか、つまり同じ根に繋がっているか
bool same(int x,int y){
  return ( root(x)==root(y) );
}

//x,yの属する集合を合併する
bool merge(int x, int y) {
   x = root(x); y = root(y);
   if (x == y) return false;
   if (siz[x] < siz[y]) swap(x, y);
   siz[x]+=siz[y];
   par[y] = x; //ランクが大きい方に小さい方を繋げる
   return true;
}

int treesize(int x)
{
  return (siz[root(x)]); 
}

int main()
{
  ll N,M,K;cin>>N>>M>>K;
  
  init(N);//Union Find

  vector<ll> f(N+1,0),br(N+1,0);//直接の友達とパスでつながっているブロック関係
  for (int i=1;i<=M;i++)
  {
    ll a,b;cin>>a>>b;
    f[a]++;f[b]++;
    merge(a,b);
  }
  for (int i=1;i<=K;i++)
  {
    ll a,b;cin>>a>>b;
    if (same(a,b))
    {
      br[a]++;br[b]++; 
    }
  }
  
  vector<ll> tree(N+1);
  for (int i=1;i<=N;i++)
  {
    tree[i]=treesize(i);
    //cout<<treesize[i]<<endl;
  }
  
  for (int i=1;i<=N;i++)
  {
    ll ans = tree[i]-f[i]-br[i]-1;
    cout<<ans<<" ";
  }
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    int A,B,C;
    cin>>A>>B>>C;

    if(A==B){
        cout <<C<<endl;
        return 0;
    }
    if(B==C){
        cout<<A<<endl;
        return 0;
    }
    if(A==C){
        cout<<B<<endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
import math
import fractions

MOD = 1000000007

N = int(input())
A = list(map(int, input().split()))

mod = 1000000007


def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]


def mod_inv(a):
    x = extgcd(a,MOD)[0]
    return (MOD+x%MOD)%MOD


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


all = Counter()
for i in range(N):
    li = prime_factorize(A[i])
    tmp = Counter(li)
    for k, v in tmp.items():
        if all[k] < v:
            all[k] = v

# print(all)
lsm = 1
for k, v in all.items():
    lsm = lsm*(k**v)%MOD
# print(lsm)

ans = 0
for i in range(N):
    ans = (ans + lsm * mod_inv(A[i])) % MOD

print(ans)

Measured memory_bytes: 78036
from string import digits, ascii_uppercase
def parse(S):
    S += "$"
    cur = 0
    res = []
    def expr():
        nonlocal cur
        R = []; l = 0
        while 1:
            c = S[cur]
            if c in digits:
                v = number()
                if S[cur] == '(':
                    cur += 1 # '('
                    R0, l0 = expr()
                    cur += 1 # ')'
                    l += v * l0
                    R.append((v, l0, R0))
                else:
                    c = S[cur]
                    cur += 1 # 'A' ~ 'Z'
                    l += v
                    R.append((v, 1, [c]))
            elif c in ascii_uppercase:
                cur += 1 # 'A' ~ 'Z'
                l += 1
                R.append(c)
            else:
                break
        return R, l

    def number():
        nonlocal cur
        v = 0
        while 1:
            c = S[cur]
            if c not in digits:
                break
            v = 10*v + int(c)
            cur += 1 # '0' ~ '9'
        return v

    R, l = expr()
    return R, l

def solve(res, x):
    R, l = res
    if l <= x:
        return "0"
    cur = R
    while 1:
        for data in cur:
            if isinstance(data, str):
                if x == 0:
                    return data
                x -= 1
            else:
                v, l, R = data
                if x < v*l:
                    cur = R
                    x %= l
                    break
                x -= v*l

while 1:
    S, x = input().split()
    if S == "0":
        break
    x = int(x)
    R, l = res = parse(S)
    if l <= x:
        print("0")
        continue
    print(solve(res, x))



Measured memory_bytes: 6800
#include<iostream>

int main(){
		int Hills[10],i,j,n;

		for(i=0;i<10;i++){
			std::cin>>Hills[i];
			}
        for(i=0;i<9;i++){
			for(j=i+1;j<10;j++){
				if(Hills[i]<Hills[j]){
					n=Hills[i];
					Hills[i]=Hills[j];
					Hills[j]=n;
					}
				}
			}

		for(i=0;i<3;i++){
			std::cout<<Hills[i]<<std::endl;
			}
return 0;
}              

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A, B, K;

int main()
{
  std::cin >> K >> A >> B;

  repi( i, A, B+1 ) if( i%K == 0 )
  {
    std::cout << "OK" << std::endl;
    return 0;
  }

  std::cout << "NG" << std::endl;

  return 0;
}

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

int main()
{
  string S;
  int64_t K;
  cin >> S >> K;
  for (int i = 0; i < S.size(); i++)
  {
    int64_t sint = S[i] - 'a';
    int64_t toA = 26 - sint;
    if (toA != 26 && K >= toA)
    {
      K -= toA;
      S[i] = 'a';
    }
  }
  if (K > 0)
  {
    int64_t sint = S[S.size() - 1] - 'a';
    int64_t after = (sint + K) % 26;
    S[S.size() - 1] = 'a' + after;
  }
  cout << S << endl;
}


Measured memory_bytes: 512
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define pb  push_back
#define mp make_pair
#define ll long long
#define pr pair<int, int> 
#define vpr vector<pr> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define Test printf("Case %d: ",tc++);
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
const int mod = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 1e6 + 5;
int vis[N];

int solve() 
{
	//happy coding

	int n;
	cin>>n;
	ll sum = 0;
	for(int i=1;i<=n;i++){
		if(i%3==0){
			vis[i] = 1;
		}else if(i%5==0){
			vis[i] = 1;
		}else{
			sum+=(ll)i;
		}
	}
	cout<<sum<<endl;

	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 7496
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
char st[MAXN];
int n,s[MAXN],nw[MAXN],a[30][MAXN],num[MAXN];
int lowbit(int x) { return x&(-x); }
void update(int x,int y) { for (;x<=n;x+=lowbit(x)) s[x]+=y; }
int query(int x) { int ans=0; for (;x;x-=lowbit(x)) ans+=s[x]; return ans; }
int main()
{
	scanf("%s",st+1),n=strlen(st+1);
	for (int i=0;i<26;i++) nw[i]=1;
	for (int i=1;i<=n;i++) a[st[i]-'a'][++num[st[i]-'a']]=i,update(i,1);
	int p=0;
	for (int i=0;i<26;i++) if (num[i]%2==1) p++;
	if (p>1) { puts("-1"); return 0; }
	ll ans=0;
	for (int i=1;i<=n;i++)
	{
		int t=st[i]-'a';
		if (nw[t]==num[t]-nw[t]+1) ans+=abs(query(n)/2+1-query(i)),update(i,-1),nw[t]++;
		if (nw[t]>=num[t]-nw[t]+1) continue;
		int x=a[t][nw[t]],y=a[t][num[t]-nw[t]+1]; nw[t]++;
		ans+=query(n)-query(y);
		update(x,-1),update(y,-1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5640
#define _USE_MATH_DEFINES
//
#include <bits/stdc++.h>
//
using namespace std;
//
#define krep(i, k, n) for (int i = k; i < n; ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define toupp(s) transform(s.begin(), s.end(), s.begin(), ::toupper) // string
#define tolow(s) transform(s.begin(), s.end(), s.begin(), ::tolower) // string
#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define __sort(v) sort(v.begin(), v.end())               // vector
#define __stable_sort(v) stable_sort(v.begin(), v.end()) // vector
#define __exists(c, v) (find(all(c), (v)) != (c).end())  // vector
#define __unique(v)                                                            \
  __sort(v);                                                                   \
  v.erase(unique(v.begin(), v.end()), v.end()) // vector
#define __swap(a, b, tmp)                                                      \
  tmp = a;                                                                     \
  a = b;                                                                       \
  b = tmp;
#define __memset(a) memset(a, 0, sizeof(a));
//
#define dumpVar(v) cerr << setw(30) << #v " = [" << v << "]" << endl
#define dumpArr(v, n)                                                          \
  for (int i = 0; i < n; ++i) {                                                \
    cerr << v[i] << ", ";                                                      \
  }                                                                            \
  cerr << endl
#define dumpPair(p) cerr << "<" << p.first << ", " << p.second << ">" << endl
//
typedef long long ll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
//
int main() {
  ios::sync_with_stdio(false);
  //
  /* code start */

  int A, B;
  cin >> A >> B;
  B += B;

  if (B > A) {
    cout << "0" << endl;
  } else {
    cout << A - B << endl;
  }

  /* code end   */
  //
  return 0;
}


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


int main(){
  long long n,d;
  cin >> d >> n;
  if(d==0){
    if(n<100){
      cout << n << endl;
    }else{
      cout << n+1 << endl;
    }
  }else{
    if(n==100){
      long long h=pow(100,d);
      cout << h*101 << endl;
    }else{
      long long h=pow(100,d);
      cout << h*n << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;

bool
check(int N, int K, ll mid, vector<int> &arr)
{
  ll cnt = 0;
  rep(i, 0, N){
    cnt += (arr[i] - 1) / mid;
  }
  return cnt <= K;
}

int
main()
{
  int N, K; cin >> N >> K;
  vector<int> arr(N);
  rep(i, 0, N) cin >> arr[i];
  if(K == 0){
    auto it =  max_element(arr.begin(), arr.end());
    cout << *it << endl;
    return 0;
  }

  int ok = 1000000001;
  int ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(check(N, K, mid, arr)){
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok << endl;

}

Measured memory_bytes: 3980
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    dp = [0] * 61
    for i in range(60, -1, -1):
        for v in a:
            dp[i] += v >> i & 1
    t = 0
    for i in range(61):
        t += dp[i] * (n - dp[i]) * pow(2, i)
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 89712
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	N := nextInt()
	result := 0
	for i := 1; i < N; i++ {
		result += (N - 1) / i
	}
	fmt.Println(result)
}


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

int main(){
	int n;
	int R[200000];
	int maxes[200000];

	cin >> n;

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

	for(int i = n-1; i >= 0; i--){
		maxes[i] = max(maxes[i + 1], R[i]);
	}

	// for(int i = 0; i < n; i++){
	// 	cout << R[i] << "  " << maxes[i] << endl;
	// }

	int result = R[1] - R[0];


	for(int i = 0; i < n - 1; i++){
		result = max(result, maxes[i+1]-R[i]);
	}
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e3+5,MOD=998244353;
int n,m,ans;
int a[N],f[N]; 
signed main(){
	scanf("%lld%lld",&n,&m);
	for (register int i=1; i<=n; ++i) scanf("%lld",&a[i]); 
	for (register int i=1; i<=n; ++i)
	{
		//f[j]表示必须选a[i]，总体积为j的方案数 
		for (register int j=m; j>a[i]; --j) f[j]=(f[j]+f[j-a[i]])%MOD;
		f[a[i]]=(f[a[i]]+i)%MOD;   //对于f[a[i]]，需要加上i，表示在[1,i]内枚举一个起点，而终点为i 
		ans=(ans+f[m]*(n-i+1)%MOD)%MOD; 
		f[m]=0;   //因为f[m]的定义为必须选a[i]，总体积为m的方案数，而下一步的必须选的是a[i+1]，所以清0
		//而为什么别的不用清0，因为别的不清0就相当于省略枚举了一个[1,i)中的j，只要直接累加f[]即可 
	}
	printf("%lld\n",ans);
return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n; cin>>n;
    int p,max=0,sum=0;
    for(int i=0;i<n;i++){
        cin>>p;
        sum+=p;
        if(p>max)max=p;
    }
    cout<<sum-(max/2)<<endl;
}

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

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

 	long long ans = 0;
 	if(n*2 <= m){

 		m = m -2*n;
 		ans = ans + n + m/4; 
 	}   
 	else{

 		ans = m/2;
 	}
 	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int x,y,s;
int tax(int x,int p)
{
  int t;
  t=p*(100+x)/100;
  return t;
}

int max(int m1,int m2)
{
  if(m1>=m2)
    return m1;
  else
    return m2;
}

int solve()
{
  int maxium=0;
  for(int i=1;i<s;i++)
    for(int j=i;j<s;j++)
      if(tax(x,i)+tax(x,j)==s)
	maxium=max(maxium,tax(y,i)+tax(y,j));
  return maxium;
  
}

int main()
{
  while(cin>>x>>y>>s&&x>0)
    {
      cout<<solve()<<endl;
    }
  return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, M;
  cin >> N >> M;
  vector <int> L(M);
  vector <int> R(M);
  rep(i,M) cin >> L[i] >> R[i];
  int ans = max(0, *min_element(all(R)) - *max_element(all(L)) + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
int ct = 0;
int N, M, C;
cin >> N >> M >> C;
vector<int> B;
vector<int> A;
for(int i = 0; i < M; i++)
{
  int tmp;
  cin >> tmp;
  B.push_back(tmp);
}
for(int i = 0; i < N; i++)
{
  A.resize(0);
   for(int j = 0; j < M; j++)
  {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  } 
  if(std::inner_product(A.begin(), A.end(), B.begin(), 0) + C > 0) ct++;
}
  cout << ct;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp>
  using namespace __gnu_pbds;
  using namespace std;
  #define int         long long
  #define mod         1000000007
  #define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  #define f(i,n)      for(int i=0;i<n;i++)
  #define fp(i,k,n)   for(int i=k;i<=n;i++)
  #define fr(i,k,n)   for(int i=k;i>=n;i--)
  #define pb          push_back
  #define pii         pair<int,int>
  #define vi          vector<int>
  #define vii         vector<pii>
  #define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
  #define F           first
  #define S           second
  #define sz(x)       (int)(x).size()
  #define lb          lower_bound
  #define ub          upper_bound
  #define mems(x)     memset(x,0,sizeof(x))
  #define all(a)      a.begin(),a.end()
  typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

  /*---------------------------------------------------------------------------------------------------*/

  void solve()
  {
    int n,k;
    cin >> n >> k;
    int a[n+1];
    f(i,n)
     cin >> a[i+1];
    sort(a+1,a+1+n);
    if(k==0)
    {
        cout << a[n] << '\n';return;
    }
    int low=0,high=mod;
    while(high-low>1)
    {
      int mid=(low+high)/2;
      int cnt=0;
      fp(i,1,n)
        cnt+=(a[i]-1)/mid;
      if(cnt<=k)
        high=mid;
      else
        low=mid;
    }
    cout << high << '\n';
    return;
  } 

  signed main()
  {
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    FAST
    int T=1;
    // cin >> T;
    while(T--)
    {
      solve();
    }
    return 0;
  }


Measured memory_bytes: 5148