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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

int find_lower(int *a, int n, int v){
    int l = -1, r = n;

    while (r-l > 1){
        int m = (l+r)/2;
        if (a[m] <= v) l = m;
        else r = m;
    }
    return l;
}

void init(){
}

int bin(int *p, int n, int x){
    int l = 0, r = n-1;
    while (r >= l){
        int m = (l+r)/2;
        if (p[m] == x) return m;
        if (p[m] > x) r = m-1;
        else l = m+1;
    }
    return -1;
}

bool ok(vector<int> a, int k, int x){ //n=6, k=4, x=4, a={1,2,3,4,5,6}
    int n = (int) a.size(); 
    int s = 0;
    int z = 0;
    while (n-z >= k){
        sort(a.rbegin(), a.rend());
        int g = 0;
        for (int i = 0; i < n && g < k; i++){
            if (a[i] > 0){
                g++;
                a[i]--;
                if (a[i] == 0) z++;
            }
        }
        if (g == k) s++;
    }
    return s >= x;
}

void solve(){
    ll h;
    cin >> h;
    ll p = (ll) floor(log2(h));
    cout << (ll) pow(2, p+1) - 1 << '\n';
}

int main(){
    //init();

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

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 4120
require 'prime'
a,b = gets.split.map(&:to_i)

a_primes = a.prime_division
b_primes = b.prime_division

a_primes = a_primes.map{|a| a[0]}
b_primes = b_primes.map{|b| b[0]}

primes = a_primes & b_primes

puts primes.size + 1
# require 'irb'
# binding.irb
# 
# aa = 1


Measured memory_bytes: 14208
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=0x3f3f3f3f3f3f3f3fLL;
int n,a[5];
signed main()
{
	cin>>n;
	for(int i=0;i<5;i++)cin>>a[i];
	int mi=INF;
	for(int i=0;i<5;i++)mi=min(mi,a[i]);
	cout<<((n-1)/mi+5)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define endl "\n";
#define loop(i,s,n)  for(ll i=s;i<n;i++)
#define test  ll t; cin>>t; while(t--)
#define p push_back
typedef long long ll;
int main()
{IOS
ll n,ans=0,m,k,i,j,count=0;
cin>>n>>m>>k;
ll a[n+1]={0};
ll b[m+1]={0};
for(i=0;i<n;i++)
{cin>>a[i+1];
a[i+1]+=a[i];}
for(i=0;i<m;i++)
{cin>>b[i+1];
b[i+1]+=b[i];}
for(i=0,j=m;i<=n;i++)
{if(a[i]>k)
{break;}
while(a[i]+b[j]>k)
{j--;}
ans=max(i+j,ans);}

cout<<ans;
	return 0;}


Measured memory_bytes: 6736
func readInt() -> Int {
    Int(readLine()!)!
}

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

extension Collection {
    func tuple() -> (Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!)
    }
    func tuple() -> (Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!)
    }
    func tuple() -> (Element, Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!, i.next()!)
    }
    
    func safe(at index: Index) -> Element? {
        self.indices.contains(index) ? self[index] : nil
    }
}

struct DP<Argument: Hashable, Element> {
    var dictionary = [Argument: Element]()
    
    var expression: (Argument, (Argument) -> Element) -> Element
    
    init(expression: @escaping (_ argument: Argument, _ note: (Argument) -> Element) -> Element) {
        self.expression = expression
    }
    
    subscript(_ argument: Argument) -> Element {
        mutating _read {
            if let note = dictionary[argument] {
                yield note
            } else {
                let result = expression(argument) { self[$0] }
                dictionary[argument] = result
                yield result
            }
        }
    }
}

extension Dictionary {
    init(_ initialize: (inout Self) -> ()) {
        var dictionary = Self()
        initialize(&dictionary)
        self = dictionary
    }
}

extension Int {
    var abs: Int {
        self < .zero ? -self : self
    }
}

// MARK: ---------------------------------------------------------------------

// import Foundation
let s = readLine()!
let t = readLine()!

var result = s.count
for i in 0...(s.count - t.count) {
    let startIndex = s.index(s.startIndex, offsetBy: i)
    let endIndex = s.index(startIndex, offsetBy: t.count)
    let range = startIndex..<endIndex
    let slice = s[range]
    let res = zip(slice, t).filter { $0 != $1 }.count
//    print(slice, ": ", res)
    if res < result {
        result = res
    }
}
print(result)


Measured memory_bytes: 8020
from collections import defaultdict

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

c = defaultdict(int)
c[0] = 1
s = 0
for i in range(N):
    s += A[i]
    c[s] += 1

ans = 0
for n in c.values():
    ans += n * (n - 1) // 2
print(ans)


Measured memory_bytes: 39276
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long H;
	cin>>H;
	long long sum=0;
	long long c=1;
	bool x=true;
	if(H==1){x=false;c=0;}
	while(x==1){
	    if(H==1){x=false;}
	    else{
	        H=H/2;
	        c*=2;
	        sum+=c;
	    }
	    
	    
	}
	cout<<sum+1;
}

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

const int mod = 1e9 + 7;

int main() {
	int n, w;
	cin >> n >> w;
	vector<pair<int, int>> items(n);
	for (int i = 0; i < n; i++) {
		cin >> items[i].second;
		cin >> items[i].first;
	}

	vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0));

	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= w; j++) {
			if (items[i - 1].second <= j) {
				dp[i][j] = max(items[i - 1].first + dp[i - 1][j - items[i - 1].second], dp[i - 1][j]);
			}
			else dp[i][j] = dp[i - 1][j];
		}
	}

	cout << dp[n][w];
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int NUM_BITS = 18;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

int GetBit(int x, int b) {
  return (x >> b) & 1;
}

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

int64 Solve() {
  int n, k, s, t;
  cin >> n >> k >> s >> t;

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

  auto c_table = Make2DVector<int64>(n + 1, n + 1, 0LL);
  for (int i = 0; i <= n; i++) {
    c_table[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c_table[i][j] = c_table[i - 1][j - 1] + c_table[i - 1][j];
    }
  }

  vector<int64> d_table(n + 1);
  for (int i = 0; i <= n; i++) {
    for (int j = 1; j <= min(i, k - 1); j++) {
      d_table[i] += c_table[i][j];
    }
  }

  vector<int> invalids(n);
  vector<int> bits;
  for (int b = 0; b < NUM_BITS; b++) {
    if (GetBit(s, b) == 1) {
      for (int i = 0; i < n; i++) {
        if (GetBit(xs[i], b) == 0) {
          invalids[i] = true;
        }
      }
    }
    if (GetBit(t, b) == 0) {
      for (int i = 0; i < n; i++) {
        if (GetBit(xs[i], b) == 1) {
          invalids[i] = true;
        }
      }
    }

    if (GetBit(s, b) == 0 && GetBit(t, b) == 1) {
      bits.push_back(b);
    }
  }

  int valid_count = 0;
  for (int i = 0; i < n; i++) {
    if (!invalids[i]) valid_count++;
  }
  if (valid_count == 0) return 0;

  if (bits.size() == 0) {
    int64 r = 0;
    for (int i = 1; i <= min(valid_count, k); i++) {
      r += c_table[valid_count][i];
    }
    return r;
  }

  if (k == 1) {
    return 0;
  }

  // k >= 2
  vector<int> ys;
  for (int i = 0; i < n; i++) {
    if (invalids[i]) continue;
    int x = xs[i];
    int y = 0;
    for (int j = 0; j < bits.size(); j++) {
      if (GetBit(x, bits[j])) {
        y |= 1 << j;
      }
    }
    ys.push_back(y);
  }
  
  // cout << "ys: " << ys << endl;

  int64 r = 0;
  for (int h = 0; h < ys.size(); h++) {
    vector<int> zs;
    for (int i = h + 1; i < ys.size(); i++) {
      zs.push_back(ys[i] ^ ys[h]);
    }

    int64 v = 0;
    for (int p = 0; p < 1 << bits.size(); p++) {
      if (p == 0) continue;
      // vector<int> zero_bits;
      int mask = 0;
      int bit_count = 0;
      for (int b = 0; b < bits.size(); b++) {
        if (GetBit(p, b)) {
          // zero_bits.push_back(b);
          mask |= 1 << b;
          bit_count++;
        }
      }

      int count = 0;
      for (int z : zs) {
        if (((mask ^ z) & mask) == mask) {
          count++;
        }
      }

      if (bit_count % 2 == 1) {
        v += d_table[count];
      } else {
        v -= d_table[count];
      }
    }

    r += d_table[zs.size()] - v;
  }
  return r;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  cout << Solve() << endl;
}

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

long long x[55];
long long y[55];

bool AdjMat[55][55];
bool visited[55];

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

    for(int i = 0; i < N; i ++){
        scanf("%lld%lld", &x[i], &y[i]);
    }

    int minAns = N;
    for(int i = 0; i < N; i ++){
        for(int j = i+1; j < N; j ++){
            long long P = x[i]-x[j];
            long long Q = y[i]-y[j];

            memset(AdjMat, 0, sizeof(AdjMat));
            memset(visited, 0, sizeof(visited));

            for(int a = 0; a < N; a ++){
                for(int b = 0; b < N; b ++){
                    if( x[a]-x[b] == P && y[a]-y[b] == Q ){
                        AdjMat[a][b] = 1;
                        AdjMat[b][a] = 1;
                    }
                }
            }

            int tempAns = 0;

            for(int s = 0; s < N; s ++){
                if(visited[s]){continue;}
                queue<int> q;
                q.push(s);
                visited[s] = true;
                tempAns ++;
                while(!q.empty()){
                    int u = q.front(); q.pop();
                    for(int v = 0; v < N; v ++){
                        if(AdjMat[u][v] && !visited[v]){
                            visited[v] = true;
                            q.push(v);
                        }
                    }
                }
            }
            minAns = min(minAns, tempAns);
        }
    }

    printf("%d", minAns);
    return 0;
}


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

ll k;

void solve(){
    if (k%2 == 0 || k%5 == 0){
        cout << "-1\n";
        return;
    }
    ll ans = 1;
    ll cur = 7 % k;
    while (cur != 0){
        cur = cur * 10 + 7;
        cur %= k;
        ans++;
    }
    cout << ans << "\n";
}


int main(){
   	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> k;
	solve();
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

const int MAX_N = 1e5 + 1;

int A[MAX_N], B[MAX_N];

ll parent[MAX_N], node_rank[MAX_N], sizes[MAX_N];

void init(ll n) {
    for (ll i = 0; i < n; i++) {
        parent[i] = i;
        node_rank[i] = 0;
        sizes[i] = 1;
    }
}

ll root(int x) {
    return parent[x] == x ? x : parent[x] = root(parent[x]);
}

bool same(int x, int y) {
    return root(x) == root(y);
}

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (node_rank[x] < node_rank[y]) {
        parent[x] = y;
        sizes[y] += sizes[x];
    }
    else {
        parent[y] = x;
        sizes[x] += sizes[y];
        if (node_rank[x] == node_rank[y]) node_rank[x]++;
    }
}

ll get_size(int x) {
    return sizes[root(x)];
}

int main() {
    ll N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> A[i] >> B[i];
    vector<ll> ans;
    ll set_number = N;
    init(N);
    ll now_ans = N * (N - 1) / 2;
    for (int i = M - 1; i >= 0; i--) {
        ans.push_back(now_ans);
        ll size1 = get_size(A[i]), size2= get_size(B[i]);
        if (!same(A[i], B[i])) now_ans -= size1 * size2;
        unite(A[i], B[i]);
    }
    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5364
#include <stdio.h>
int main(void){
	int W,H;
	int i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(W == 0 && H == 0){
			break;
		}
		for(j = 1; j <= H; j++){
			for(i = 1; i <= W; i++){
				if(j % 2 == 1){
					if(i % 2 == 1){
						printf("#");
					}
					else{
						printf(".");
					}
				}
				else {
					if(i % 2 == 1){
						printf(".");
					}
					else {
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


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

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

        long abMin = Math.min(a,b);
        long abMax = Math.max(a,b);
        long cdMin = Math.min(c,d);
        long cdMax = Math.max(c,d);

        long[] tmpAns = new long[4];
        tmpAns[0] = abMin * cdMin;
        tmpAns[1] = abMin * cdMax;
        tmpAns[2] = abMax * cdMin;
        tmpAns[3] = abMax * cdMax;

        Arrays.sort(tmpAns);

        System.out.println(tmpAns[3]);
    }
}


Measured memory_bytes: 35756
using System;
using System.Linq;
using System.Collections.Generic;


public class BinarySearch{
	public static void Main()
	{
		Console.ReadLine();
		var sList = ReadLineAndToIntList();
		Console.ReadLine();
		var tList = ReadLineAndToIntList();
	
		int count = 0;
		tList.ForEach(t =>{
			if(MyBinarySearch(sList, t) >= 0) count++;
		});
		
		Console.WriteLine(count);
	}
	
	//??????????????????????????????
	public static List<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (c => int.Parse(c)).ToList();
	}
	
	public static int MyBinarySearch(List<int> list, int target)
	{
		int left = 0;
		int right = list.Count();
		while( left < right )
		{
			int mid = (left + right) / 2;
			if(list[mid] == target) return mid;
			else if( target < list[mid] ) right = mid;
			else left = mid + 1;
		}
		return -1;
	}
}

Measured memory_bytes: 15384
#include <stdio.h>

int main()
{
	int a,b,ans;
	char op[10];

	while(1) {
	scanf("%d %c %d",&a,&(op[0]),&b);
	if (op[0] == '?') {
		return 0;
	}

	switch (op[0]) {
	case '+':
		ans = a + b;
		break;
	case '-':
		ans = a - b;
		break;
	case '*':
		ans = a * b;
		break;
	case '/':
		ans = a / b;
		break;

	default:
		;
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin>>d[i];
    
  }
  sort(d.begin(),d.end());
  
  cout<<d[N/2]-d[N/2-1]<<endl;

  return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <algorithm>
using namespace std;
#include <cmath>
#include <string>

int getDigit(int n){
  int digit= 0;
  while(n>0){
    digit++;
    n /= 10;
  }
  return digit;
}


int main(){
  int  a,b;
  cin>>a>>b;
  int digit = getDigit(b);
  digit = pow(10,digit);
  int newab = a*digit+ b;
  // printf("%04d",newab);
  for(int i= 0;i<newab/2;i++){
    if(i*i ==newab ){
      string hoge = "Yes";
      cout<<hoge<<endl;
      return 0;
    }
  }



  string hoge = "No";

  cout<<hoge<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (3e4) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

const int MAX = 30000;

bool mark[N];
vi arr, primes = {2,3};

void solve()
{
	int n, i, cnt = 0, bal;
	cin >> n;
	if(n == 3)
	{
		cout << "2 5 63\n";
		return;
	}
	if(n <= 15000)
	{
		if(n % 3 == 0)
		{
			fo(i,1,n-4+1)
				mark[i*2] = 1;
			mark[3] = mark[9] = mark[15] = mark[21] = 1;
		}
		else
		{
			fo(i,1,n-2+1)
				mark[i*2] = 1;
			mark[3] = mark[9] = 1;
		}
	}
	else if(n % 2 == 0)
	{
		for(i = 2; i <= MAX; i+=2)
			mark[i] = 1;
		cnt = MAX/2;
		for(i = 3; i <= MAX; i+=3)
			if(!mark[i])
			{
				mark[i] = 1;
				cnt++;
				if(cnt == n)
					break;
			}
	}
	else
	{
		for(i = 2; i < MAX; i+=2)
			mark[i] = 1;
		cnt = MAX/2 - 1;
		for(i = 3; i <= MAX; i+=3)
			if(!mark[i])
			{
				mark[i] = 1;
				cnt++;
				if(cnt == n)
					break;
			}
	}
	
	fo(i,2,MAX+1)
		if(mark[i])
			cout << i << " ";
	cout << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

#pragma warning(disable:4996)

#define MAX_N 1200
#define MAX_W 1200

int dp[MAX_N][MAX_W];
int W, N, v[MAX_N], w[MAX_N], cnt;

int main() {
	while (true) {
		cnt++;
		memset(dp, 0, sizeof(dp));
		cin >> W;
		if (W == 0) { break; }
		cin >> N;
		for (int i = 0; i < N; i++)
		{
			scanf("%d,%d", &v[i], &w[i]);
		}
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j <= W; j++)
			{
				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
				if (j + w[i] <= W)
				{
					dp[i + 1][j + w[i]] = max(dp[i][j] + v[i], dp[i + 1][j + w[i]]);
				}
			}
		}
		cout << "Case " << cnt << ":" << endl;
		int maxn = 0, maxid = 0;
		for (int j = 0; j <= W; j++)
		{
			if (maxn < dp[N][j])
			{
				maxn = dp[N][j];
				maxid = j;
			}
			else if (maxn == dp[N][j])
			{
				maxid = min(maxid, j);
			}
		}
		cout << maxn << endl;
		cout << maxid << endl;
	}
}

Measured memory_bytes: 6884
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+10;
int32_t main()
{
    int a,b;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%2019==0)
        {
            cout<<"0"<<endl;
            return 0;
        }
    }
    int mn=MOD;
    for(int i=a;i<b;i++)
    {
        for(int j=i+1;j<=b;j++)
        {
            mn=min(mn,((i%2019)*(j%2019))%2019);
        }
    }
    cout<<mn<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int[][] dp;
    static Knap[]  knaps;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        knaps = new Knap[n];
        for (int i = 0; i < n; i++) {
            knaps[i] = new Knap(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(knaps);
        dp = new int[n][w + 1];
        System.out.println(dfw(n - 1, w));
    }
    
    static int dfw(int idx, int weight) {
        if (weight < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][weight] != 0) {
            return dp[idx][weight];
        }
        if (weight % knaps[idx].weight == 0) {
            return dp[idx][weight] = weight / knaps[idx].weight * knaps[idx].value;
        }
        int max = 0;
        for (int i = 0; i * knaps[idx].weight <= weight; i++) {
            max = Math.max(max, dfw(idx - 1, weight - knaps[idx].weight * i) + knaps[idx].value * i);
        }
        return dp[idx][weight] = max;
    }
    
    static class Knap implements Comparable<Knap> {
        int value;
        int weight;
        
        public Knap(int value, int weight) {
            this.value = value;
            this.weight = weight;
        }
        
        public int compareTo(Knap another) {
            return value * another.weight - another.value * weight;
        }
    }
}


Measured memory_bytes: 31628
n, m = map(int, input().split())
req = [list(map(int, input().split())) for i in range(m)]
for i in range(10000):
    st = str(i)
    if len(st) != n:
        continue
    ok = True
    for s, c in req:
        if int(st[s-1]) != int(c):
            ok = False
    if ok:
        print(st)
        exit(0)
print(-1)


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

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

  // ここにプログラムを追記
  int count = 0;
  for(int i = A; i <= B; i++) {
    string a = std::to_string(i);
    string b = std::to_string(i);
    bool rev = true;
    for(int j = 0; j < a.length(); j++) {
      if(a[j] != b[b.length() - 1 - j]) {
        rev = false;
        break;
      }
    }
    if(rev) {
      count++;
    }
  }
  cout << count << endl;
}


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

int main() {
  int n;
  cin >> n;
  cout << "ABC" << n << endl;
  return 0;
}

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

for i in range(N, 0, -1):
    tmpA = A[i]
    tmpB = B[i-1]
    A[i] = max(0, tmpA-tmpB)
    B[i-1] = max(0, tmpB-tmpA)
    tmpA = A[i-1]
    tmpB = B[i-1]
    A[i-1] = max(0, tmpA-tmpB)
    B[i-1] = max(0, tmpB-tmpA)
print(sumA-sum(A))

Measured memory_bytes: 18624
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e16;
	const ll MOD = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];

	signed main(){
		IOS;
		int n;
		cin >> n;
		vec<string> s(2);
		cin >> s[0] >> s[1];
		ll ans = 1;
		for(int i = 0;i < n;i++){
			if(s[0][i] == s[1][i]){
				if(i == 0){
					ans = 3;
				}
				else{
					if(s[0][i - 1] == s[1][i - 1])ans *= 2;					
					ans %= MOD;
				}
			}
			else{
				if(i == 0){
					ans = 6;
				}
				else {
					if(s[0][i - 1] == s[1][i - 1])ans *= 2;
					else ans *= 3;
					ans %= MOD;
				}
				i++;
			}
		}
		dump(ans);
	}

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

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        System.out.println(n * (n - 1) / 2  + m * (m - 1) / 2);
    }

}


Measured memory_bytes: 22356
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N; string S, T;
  cin >> N >> S >> T;

  for (int i = 0; i < N; i++){
    cout << S[i] << T[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    string s;
    char buf;
    cin >> s;
    if (s.size() == 3)
    {
        buf = s[0];
        s[0] = s[2];
        s[2] = buf;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;

class BIT {
	std::vector<LL> bit;
	LL size;
public:
	BIT() { }
	BIT(LL sz) { init(sz); }
	void init(LL sz) {
		bit = std::vector<LL>((size = sz) + 1);
	}
	LL sum(LL i) {
		LL s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
}
	void add(LL i, LL x) {
		while (i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	LL N, Q, a, t, x, y;
	cin >> N >> Q;
	BIT bit(N);
	for (LL i = 1; i <= N; ++i) {
		cin >> a;
		bit.add(i, a);
	}
	for (LL i = 0; i < Q; ++i) {
		cin >> t >> x >> y;
		if (t == 0) {
			bit.add(x + 1, y);
		} else {
			cout << (bit.sum(y) - bit.sum(x)) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 8220
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();
    int ans = r;
    if(n < 10) ans = r + 100 * (10 - n);
    System.out.println(ans);
  }
}


Measured memory_bytes: 22740
import java.io.*;

 
public class Main {
	  public static void main(String args[])throws IOException
             {
		BufferedReader br =    
		    new BufferedReader(new InputStreamReader(System.in));  
		
		
		    String str1 = br.readLine();
		    int N = Integer.parseInt(str1);
		    
		    if(N%10<= 0)
		    {
		    	System.out.println(10);
		    }
		    else
		    {	
		    	int sum = 0;
		    	
		    do {	sum += N % 10;
		    } while((N/= 10)!= 0);
		    	System.out.println(sum);
		    
		    }
        
		    
        	
             }
}

Measured memory_bytes: 21204
N = int(input())
D, X = list(map(int,input().split(' ')))
A = [int(input()) for i in range(N) ]
#print(A)
count = []
for i in A:
  for j in range(0,D+1):
    if i*(j)+1 <= D:
      count.append(i*(j)+1)
    
print(len(count)+X)    
#print(count)

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

FB = 0

for i in range(N):
    if (i+1) % 15 == 0:
        continue
    elif (i+1) % 3 == 0:
        continue
    elif (i+1) % 5 == 0:
        continue
    else:
        FB=FB + i+1
        
print(FB)

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

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    int datasetCount = Integer.parseInt(input.readLine());
    for (int i = 0; i < datasetCount; i++)
    {
      String[] INPUT_STR = input.readLine().split(" ");

      System.out.println(solver(INPUT_STR) ? "YES" : "NO");
    }

  }

  private static boolean solver(String[] array)
  {
    int currentA = 0;
    int currentB = 0;
    int currentC = 0;

    for (int i = 0; i < array.length; i++)
    {
      currentA = Integer.parseInt(array[i]);
      if (currentB < currentA)
      {
        currentB = currentA;
      }
      else if (currentC < currentA)
      {
        currentC = currentA;
      }
      else
      {
        return false;
      }
    }
    return true;
  }

}

Measured memory_bytes: 24168
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(long.Parse).ToArray();
            var A = raw[0];
            var B = raw[1];
            var N = raw[2];

            Func<long, long> func = x => (long)(A * x / B) - A * (long)(x / B);

            WriteLine(func(Math.Min(B - 1, N)));
        }

    }
}


Measured memory_bytes: 28168
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        int[] a = new int[9];
        for(int i = 0; i < 9; i++){
            a[i] = sc.nextInt();    
        }
        int[] hit = new int[9];
        int n = sc.nextInt();
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            b[i] = sc.nextInt();
            for(int j = 0; j < 9; j++){
                if(b[i] == a[j]){
                    hit[j] = 1;
                }
            }    
        }

        // 処理
        String out = "No";
        //横
        for(int i = 0; i < 9; i+= 3){
            if((hit[i] + hit[i+1] + hit[i+2]) == 3){
                out = "Yes";
            }
        }
        //縦
        for(int i = 0; i < 3; i++){
            if((hit[i] + hit[i+3] + hit[i+6]) == 3){
                out = "Yes";
            }
        }
        //斜め
        if((hit[0] + hit[4] + hit[8]) == 3){
            out = "Yes";
        }
        if((hit[2] + hit[4] + hit[6]) == 3){
            out = "Yes";
        }

        // 出力
        System.out.println(out);
    }

}

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

int main()
{
  long long int sum(0);
  long long int N;
  cin >> N;
  
  for(long long int i=1;i<=N;i++)
  {
    if(i%3 !=0 && i%5!=0)
      sum += i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << '+' << endl;
	}
	else if (a*b == 15) {
		cout << '*' << endl;
	}
	else {
		cout << 'x' << endl;
	}


	return 0;
}

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

int main()
{
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;

  ll x = min(n, b-1);
  cout << (a*x/b)-a*(x/b) << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  
  sort(b.begin(), b.end());

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

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll S[N+1] = {};
    rep(i, N) S[i+1] = S[i] + A[i];
    sort(S, S+(N+1));
    ll row = 1;
    ll aim = S[0];
    ll ans = 0;
    rep(i, N){
        if(S[i+1] == aim){
            row++;
        }
        else{
            ans += row*(row-1)/2;
            row = 1;
            aim = S[i+1];
        }
    }
    ans += row*(row-1)/2;
    cout << ans << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

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

    return arr


n = int(input())
so = factorization(n)
#print(so)

#print(len(so))
flg = 0
for i in range(len(so)):
    if so[i][0] == 1: continue
    var = 1
    sta = 1 
    while(so[i][1]>=sta):
        #print(var,so[i][1])
        flg+=1
        var+=1
        sta +=var

print(flg)

Measured memory_bytes: 9496
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    string S;
    cin >> S;
    FOR(i, 1, S.size() + 1) {
        if (i % 2 == 0) {
            if (!(S[i - 1] == 'L' || S[i - 1] == 'U' || S[i - 1] == 'D')) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (!(S[i - 1] == 'R' || S[i - 1] == 'U' || S[i - 1] == 'D')) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	int n, y;
	cin >> n >> y;
	y /= 1000;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				if (i+j+k > n) break;
				if (i+j+k == n && 10*i + 5*j + k == y) {cout << i << " " << j << " " << k; return 0;}
			}
		}
	}
	cout << "-1 -1 -1";
	
	return 0;
}

Measured memory_bytes: 384
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[100100];
int d[100100];
int n;

void Solve() {
	int m;
	cin >> n >> m;
	for (size_t i = 0; i < m; i++)
	{
		cin >> t[i];
	}
	sort(t, t + m);
	ll sum = 0;
	for (size_t i = 0; i < m - 1; i++)
	{
		d[i] = t[i + 1] - t[i];
		sum += d[i];
	}
	sort(d, d + (m - 1));
	reverse(d, d + (m - 1));
	if (m <= n - 1) {
		cout << 0 << endl;
		return;
	}
	for (size_t i = 0; i < n - 1; i++)
	{
		sum -= d[i];
	}
	cout << sum << endl;
}


int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 6400
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}



signed main () {
    int a,b,c;cin >>a>>b>>c;
    int n;cin >>n;
    int time=0;
    while(a>=b){
        b*=2;
        time++;
    }
    while(b>=c){
        c*=2;
        time++;
    }
    if(time>n)cout <<"No"<<endl;
    else cout <<"Yes"<<endl;
}





Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int main(){
	int n,s,inputNum,minNum,maxNum;
	
	while(cin>>n,n){
		minNum=(int)1e+8;
		s=maxNum=0;
		
		for(int i=0;i<n;i++){
			cin>>inputNum;
			s+=inputNum;
			if(inputNum<minNum){
				minNum=inputNum;
			}
			if(inputNum>maxNum){
				maxNum=inputNum;
			}
		}
		
		s=s-maxNum-minNum;
		s=s/(n-2);
		
		cout<<s<<endl;
	}
}

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

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

using namespace std;

int main(){
  ll k,a,b;cin>>k>>a>>b;
  ll count = max<ll>(0, k-a+1);

  if(count/2>0)cout<<max(k+1, (count/2)*(b-a) + a + count%2);
  else cout<<k+1;

  return 0;
}

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

int main(){
    int n,mini = 100000000;
    cin >> n;
    int num[n];
    for(int i=0;i<n;i++){
        cin >> num[i];
        mini = min(num[i],mini);
    }
    for(int i=1;i<=mini;i++){
        if(n == 2){
            if(num[0]%i == 0 && num[1]%i == 0) cout << i << endl;
        }
        else if(n == 3){
            if(num[0]%i == 0 && num[1]%i == 0 && num[2]%i == 0) cout << i << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<n; i++)
#define rep2(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
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; }
constexpr int INF = INT_MAX/2;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	vector<int> dp(N);
	fill(all(dp), INF), dp[0] = 0;
	rep1(i, N) {
		rep2(j, K) {
			if (i-j < 0) break;
			chmin(dp[i], dp[i-j] + abs(v[i]-v[i-j]));
		}
	}
	cout << dp[N-1] << '\n';
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

ll dp[200010][4];

int main() {
  int N;cin>>N;
  vector<ll> a(N);
  rep(i,N) {
    cin>>a[i];
  }
  int extra = 1 + (N % 2);
  rep(i,N+1) rep(j,extra+1) dp[i][j] = -INF;
  dp[0][0] = 0;
  rep(i,N) {
    rep(j,extra+1) {
      chmax(dp[i+1][j+1],dp[i][j]);
      ll now = dp[i][j];
      if((i+j)%2==0) now += a[i];
      chmax(dp[i+1][j],now);
    }
  }
  cout << dp[N][extra] << endl;
} 

Measured memory_bytes: 11184
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;


void run_case() {
    LL n, m, sum = 0, t;
    cin >> n >> m;
    for(LL i = 0; i < m; ++i) {
        cin >> t;
        sum += t;
    }
    if(sum > n) cout << -1;
    else cout << n - sum;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G
typedef long long ll;
const int Mod=1e9+7,inv2=Mod+1>>1;
int qpow(int x,int y=Mod-2){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%Mod)
		if (y&1) res=1LL*res*x%Mod;
	return res;
}
int upd(int x){return x+(x>>31&Mod);}
int inv[200010];

int n,a[200010],cnt[200010],ans;
int pos[200010],postot; int D[200010],iD[200010];
int tri1[200010],tri2[200010],tri3[200010];
int L[200010],R[200010];
void add(int x,int b,int c){
	for (;x<=n;x+=x&-x){
		tri1[x]++;
		tri2[x]=upd(tri2[x]+b-Mod);
		tri3[x]=upd(tri3[x]+c-Mod);
	}
}
int ask(int *tri,int x){
	int res=0;
	for (;x;x-=x&-x) res=upd(res+tri[x]-Mod);
	return res;
}
int main()
{
	n=read();
	inv[1]=1; for(int i=2;i<=n;i++) inv[i]=1LL*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for (int i=1;i<=n;i++) cnt[a[i]=read()]++;
	int sametot=0,tot=1;
	for (int i=n;i;i--){
		sametot=(sametot+1LL*cnt[i]*(cnt[i]-1)/2)%Mod;
		cnt[i]+=cnt[i+1];
		tot=1LL*tot*(cnt[i]-n+i)%Mod;
	}
	if (tot==0) return puts("0"),0;
	ans=sametot;
	D[0]=1; iD[0]=1;
	for (int i=1;i<=n;i++){
		D[i]=D[i-1]; iD[i]=iD[i-1];
		if (cnt[i]-1-n+i) D[i]=1LL*D[i]*(cnt[i]-1-n+i)%Mod*inv[cnt[i]-n+i]%Mod,iD[i]=1LL*iD[i]*inv[cnt[i]-1-n+i]%Mod*(cnt[i]-n+i)%Mod;
		else pos[++postot]=i;
	}
	for (int i=1,j=0;i<=n;i++){
		if (j<postot&&pos[j+1]==i) j++;
		L[i]=j==0?1:pos[j];
	}
	for (int i=n,j=postot+1;i;i--){
		R[i]=j>postot?n:pos[j]-1;
		if (j>1&&pos[j-1]==i) j--;
	}
	for (int i=1;i<=n;i++){
		int l=L[a[i]],r=a[i]-1;
		if (l<=r) ans=upd((ans+1LL*D[a[i]]*(ask(tri3,r)-ask(tri3,l-1)))%Mod);
		l=a[i]+1,r=R[a[i]];
		if (l<=r) ans=upd((ans-1LL*iD[a[i]]*(ask(tri2,r)-ask(tri2,l-1)))%Mod);
		add(a[i],D[a[i]],iD[a[i]]);
		ans=(ans+2LL*(i-ask(tri1,a[i])))%Mod;
	}
	ans=1LL*ans*tot%Mod*inv2%Mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pii make_pair
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }

main()
{
    //fastio;
    int n;
    cin>>n;
    int a[n], sm=0, ans=0;
    for(int i=0; i<n; i++) {
        cin>>a[i];
        sm+=a[i];
    }
    if(sm%n==0) {
        int k=sm/n;
        for(int i=0; i<n; i++) {
            ans+=pow(a[i]-k, 2);
        }
    }
    else {
        int beshi=ceil(sm, n);
        int kom=sm/n, a1=0, a2=0;
        for(int i=0; i<n; i++) {
            a1+=pow(a[i]-beshi, 2);
        }
        for(int i=0; i<n; i++) {
            a2+=pow(a[i]-kom, 2);
        }
        ans=min(a1, a2);
    }
    cout<<ans;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(void){
    int n=0;
    int p[10];
    int max=0;
    int tmp=0;
    int sum=0;
    int flag=0;

    cin >> n;

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

    for(int i=0;i<n;i++){
        tmp=p[i];
        if(tmp>max)max=tmp;
    }

    for(int i=0;i<n;i++){
        if(p[i]==max&&flag==0){
            sum+=p[i]/2;
            flag=1;
        }else{
            sum+=p[i];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, X[200001], Y[200001], a, b;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> X[i];
        Y[i] = X[i];
    }

    sort(X+1, X+N+1);

    a = X[N/2];
    b = X[N/2+1];
 
    for(i=1; i<=N; i++){
        if(Y[i] <= a){
            cout << b << endl;
        }

        else{
            cout << a << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 5376
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]


def dfs(n, a, b, c):
    global N, A, B, C, l
    if n == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else 10 ** 100
    alpha = dfs(n + 1, a, b, c)
    beta = dfs(n + 1, a + l[n], b, c) + 10
    gamma = dfs(n + 1, a, b + l[n], c) + 10
    delta = dfs(n + 1, a, b, c + l[n]) + 10
    return min(alpha, beta, gamma, delta)


print(dfs(0, 0, 0, 0) - 30)

Measured memory_bytes: 3064
N, M, Q = map(int, input().split())
#N 500 に合わせて少し余分に準備
p = [[0] * 510 for i in range(510)]

for i in range(M):
  l, r = map(int, input().split())
  p[l][r] += 1
#print(p)
#print("")

#1 ~ N にすることで周囲に空白を用意
for i in range(1, N + 1):
  for j in range(1, N + 1):
    p[i][j] += p[i][j - 1]
#print(p)
#print("")

for i in range(1, N + 1):
  for j in range(1, N + 1):
    p[i][j] += p[i - 1][j ]    
#print(p)
#print("")

for i in range(Q):
  l, r = map(int, input().split())
  ans = p[r][r] + p[l - 1][l - 1] - p[r][l - 1] - p[l - 1][r]
  print(ans)

Measured memory_bytes: 13400