akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

int source[500][500] = {};

void copy_array(int a[],int b[],int m){
    for(int i=0;i<m;i++){
        b[i] = a[i];
    }
}

bool check(int n,int m,int sum[]){
    for(int j=0;j<m;j++){
        if(sum[j] %2 == 1) return false;
    }
    //std::cout << "      ";
    /*for(int j=0;j<m;j++){
        std::cout << sum[j] << ' ';
    }
    std::cout << '\n';
     */
    return true;
}

bool sum_calc(int f_num,int f_pos,int m,int n,int pri_sum[]){
    //std::cout << "再起\n";
    int sum[500] = {};
    //std::cout << "f_num=" << f_num << '\n';
    for(int i=f_pos;i<n-f_num+1;i++){
        //std::cout << "f_num=" << f_num << "  f_pos=" << i << '\n';
        copy_array(pri_sum,sum,m);
        
        for(int j=0;j<m;j++){
            sum[j] -= source[i][j];
        }
        
        f_num--;
        if(f_num==0){
            //std::cout << "      f_num=0\n";
            if(check(n,m,sum)){
                return true;
            }else{
                //std::cout << "失敗した\n";
                f_num++;
            }
        }else{
            if(sum_calc(f_num,i+1,m,n,sum)){
                return true;
            }else{
                f_num++;
            }
        }
    }
    //std::cout << "終了\n";
    return false;
}

void to_int(char s[],int i){
    int j=0;
    while(s[j] != '\0'){
        if(s[j] == '0'){
            source[i][j++] = 0;
        }else{
            source[i][j++] = 1;
        }
    }
}

int search(int n,int m,int sum[]){
    for(int f_num=1;f_num<n;f_num++){
        //std::cout << "f_num=" << f_num << '\n';
        if(sum_calc(f_num,0,m,n,sum)) return f_num;
    }
    return n;
}

int main(){
    int n,m;
    while(1){
        std::cin >> n >> m;
        if(n==0&&m==0) return 0;
        //std::cout << "n:" << n <<" m:" << m << '\n';
        char s[500];
        for(int i=0;i<n;i++){
            std::cin >> s ;
            to_int(s,i);
        }
        
        /*for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                std::cout << source[i][j] << ' ';
            }
            std::cout << '\n';
        }
        */
        int sum[500] = {};
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                sum[j] += source[i][j];
            }
        }
        
        if(check(n,m,sum)){
            std::cout << /*"ans=" <<*/ n << '\n';
        }else{
            int ans=n-search(n,m,sum);
            std::cout << /*"ans=" <<*/ ans << '\n';
        }
        //std::cout << '\n';
    }
    /*for(int j=0;j<m;j++){
     std::cout << sum[j] << ' ' ;
     }
     std::cout << '\n';
     */
    
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec(m);
  rep(i,m) cin >> vec.at(i).first >> vec.at(i).second;
  bool b = true;
  if(n == 3){
    for(int i = 100; i < 1000; i++) {
      string s = to_string(i);
      bool a = true;
      rep(j,m) {
        string c = to_string(vec.at(j).second);
        if(s.at(vec.at(j).first-1) != c.at(0)) a = false;
      }
      if(a) {
        cout << i << endl;
        b = false;
        break;
      }
    }
  }
  if(n == 2){
    for(int i = 10; i < 100; i++) {
      string s = to_string(i);
      bool a = true;
      rep(j,m) {
        string c = to_string(vec.at(j).second);
        if(s.at(vec.at(j).first-1) != c.at(0)) a = false;
      }
      if(a) {
        cout << i << endl;
        b = false;
        break;
      }
    }
  }
  if(n == 1){
    for(int i = 0; i < 10; i++) {
      string s = to_string(i);
      bool a = true;
      rep(j,m) {
        string c = to_string(vec.at(j).second);
        if(s.at(vec.at(j).first-1) != c.at(0)) a = false;
      }
      if(a) {
        cout << i << endl;
        b = false;
        break;
      }
    }
  }
  if(b) cout << -1 << endl;
  return 0;
}

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

int main() {
  int h,w; cin>>h>>w;
  vector<vector<char>> a(h+2, vector<char>(w+2));
  rep(i, h+2) {
    rep(j, w+2) {
      if (i==0||i==h+1||j==0||j==w+1) a[i][j] = '#';
      else cin>>a[i][j];
    }
  }
  rep(i, h+2) {
    rep(j, w+2) {
      printf("%c", a[i][j]);
    }
    printf("\n");
  }
}


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

using namespace std;

typedef long long ll;


int main() {
    int N, M;
    cin >> N >> M;

    ll s = 0;

    ll x = 1;
    for(int i = 0; i < M; i++){
        x *= 2;
    }
    s += (1900 * M + 100 * (N - M))* x;
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.Scanner;

import javax.swing.plaf.synth.SynthSeparatorUI;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		if(N % 7 == 0) System.out.println("Yes");
		else if(N % 4 == 0) System.out.println("Yes");
		else{
			int n = N / 7;
			boolean flag = false;
			for(int i = 0; i <= n; i++){
				if((N - i * 7) % 4 == 0){
					flag = true;
					break;
				}
			}
			if(flag) System.out.println("Yes");
			else System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  ll p[11]={};
  p[0]=1;
  rep(i,10){
    p[i+1]=3*p[i];
  }
  ll res=1;
  rep(i,n){
    if(a[i]%2==0)res*=2;
  }
  cout << p[n]-res << endl;
return 0;}

Measured memory_bytes: 256
N = int(input()) - 1
rst = ''
for i in range(1, 10 ** 15):
    if N >= 26 ** i:
        N -= 26 ** i
        continue
    for j in range(i):
        rst += chr(ord('a') + N % 26)
        N //= 26
    print(rst[::-1])
    break

Measured memory_bytes: 9164
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

#define sz(x) (int)(x).size()
typedef long long ll;
using namespace std;
const int mxN=1e5+5;
int parents[mxN],siz[mxN];
int cnt;

void build(int n) {
    cnt=n;
    for(int i=0; i<n; i++) {
        parents[i]=i;
        siz[i]=1;
    }
}

int find_set(int u) {
    if(parents[u]==u)
        return u;
    return parents[u]=find_set(parents[u]);
}

void union_sets(int u,int v) {
    u=find_set(u);
    v=find_set(v);
    if(u==v)
        return;
    if(siz[u]>siz[v])
        swap(u,v);
    parents[v]=u;
    siz[u]+=siz[v];
    cnt--;
}

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

    int n,m;
    cin >> n >> m;
    build(n);
    for(int i=0; i<m; i++) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        union_sets(u,v);
    }
    cout << cnt-1;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#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 REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }

void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

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

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m);
}

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

	int H,W,K;
	char S[303][303];
	int Answer[303][303];

	cin>>H>>W>>K;

	REP(i,H){
		REP(j,W){
			cin>>S[i][j];
			Answer[i][j]=0;
		}
	}

	int tem=1;
	REP(i,H){
		REP(j,W){
			if(S[i][j]=='#'){
			  Answer[i][j]=tem;

			 	for(int h=i-1; h>=0 ;h--){
			   	if(S[h][j]=='#' || Answer[h][j]!=0) break;
			    else Answer[h][j]=tem;
				}

			  for(int h=i+1; h<H ;h++){
			    if(S[h][j]=='#' || Answer[h][j]!=0) break;
			    else Answer[h][j]=tem;
				}
			  tem++;
			}
		}
	}

	FOR(j,1,W){
		if(Answer[0][j]==0){
			REP(i,H){
				Answer[i][j]=Answer[i][j-1];
			}
		}
	}

	RFOR(j,0,W-1){
		if(Answer[0][j]==0){
			REP(i,H){
				Answer[i][j]=Answer[i][j+1];
			}
		}
	}

	REP(i,H){
		REP(j,W){
			cout<<Answer[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, a, b) for (int i = a; i < b; i++)

#define MAX ((int)2.0e5)

int n, q;
int S[MAX];
int T[MAX];

bool is_exists(int v) {
  int l = 0, r = n;
  while (r - l > 1) {
	int mid = (l + r) / 2;
	if (S[mid] <= v) l = mid;
	else r = mid;
  }
  if (S[l] == v) return true;
  else return false;
}

int main() {
  cin >> n;
  rep(i, n) cin >> S[i];
  cin >> q;
  rep(i, q) cin >> T[i];

  int cnt = 0;
  rep(i, q) {
	if (is_exists(T[i])) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll x;
	cin >>x;
	ll ans =0;
	if(x>10) ans +=  x/11 * 2;
	x %=11;
	ans += x==0? 0: x<=6? 1: 2;
	cout << ans << endl;
	return 0;
}

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

int main(void){
	ll N,K;cin >> N >> K;
	ll x=N;
	ll ans=0;
	if(N%K==0){
		cout << 0 << endl;
		return 0;
	}
	x=abs(x-K);
	ans = N%K;
	ans = K-ans;
	cout << min({ans, x, N}) << endl;
}


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

using namespace std;

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

Measured memory_bytes: 256
import collections

np_list = input().split(" ")
N = int(np_list[0])
P = int(np_list[1])

sum = 0
S = list(map(lambda s:int(s),input()[::-1]))



if P == 2 or P == 5:
    for i in range(0,N):
        if S[i]%P == 0:
            sum += N-i
else :
    digit = 1
    rem_list = [0]
    for i in range(N):
        rem_list.append(((S[i]*digit)%P+rem_list[i])%P)
        digit *= 10
        digit %= P
    c = collections.Counter(rem_list[1:])
    for i in range(1,N+1):
        if rem_list[i] == 0:
            sum += 1
        temp =c[rem_list[i]]
        temp -=1
        sum += temp
        c[rem_list[i]] = temp
print(sum)


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

int main(){
    int n, a[3][3];

    rep(i,3){
        rep(j,3){
            cin >> a[i][j];
        }
    }
    cin >> n;

    int b;
    rep(i,n){
        cin >> b;
        rep(j,3){
            rep(k,3){
                if(a[j][k]==b){
                    a[j][k] = -1;
                }
            }
        }
    }
    if(a[1][1]==-1){
        if(a[0][0]==-1&&a[2][2]==-1||a[0][2]==-1&&a[2][0]==-1||a[1][0]==-1&&a[1][2]==-1||a[0][1]==-1&&a[2][1]==-1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(a[0][1]==-1){
        if(a[0][0]==-1&&a[0][2]==-1){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (a[2][1] == -1){
        if (a[2][0] == -1 && a[2][2] == -1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (a[0][0] == -1 && a[1][0] == -1 && a[2][0] == -1){
        cout << "Yes" << endl;
        return 0;
    }
    if (a[0][2] == -1 && a[1][2] == -1 && a[2][2] == -1)
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m=n1()

if n%2==0:
    if m>=2:
        e=n//2
        s=1
        l=e-s
        c=0
        while e>s and c<m:
            print(s,e)
            s+=1
            e-=1
            c+=1
        e=n
        s=n-l+1
        while e>s and c<m:
            print(s,e)
            s+=1
            e-=1
            c+=1
    else:
        print(1,2)
else:
    if m>=2:
        e=n//2+1
        s=1
        l=e-s
        c=0
        while e>s and c<m :
            print(s,e)
            s+=1
            e-=1
            c+=1
        e=n
        s=n-l+1
        while e>s and c<m:
            print(s,e)
            s+=1
            e-=1
            c+=1
    else:
        print(1,2)

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

using namespace std;

typedef long long ll;

ll n, s1, s2, ans1, ans2;

int main()
{
	ll i, a;
	
	scanf("%lld", &n);
	
	for(i=1; i<=n; i++){
		scanf("%lld", &a); s1 += a, s2 += a;
		if(s1 <= 0) ans1 += 1 - s1, s1 = 1;
		if(s2 >= 0) ans2 += s2 + 1, s2 = -1;
		swap(s1, s2); swap(ans1, ans2);
	}
	
	printf("%lld\n", min(ans1, ans2));
	
	return 0;
}

Measured memory_bytes: 256
import itertools
n, m = [int(w) for w in input().split()]

wa_n = [0] * n
ac_n = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "AC":
        ac_n[p] = 1
    else:
        if ac_n[p] == 1:
            continue
        else:
            wa_n[p] += 1


print(sum(ac_n), sum(list(itertools.compress(wa_n, ac_n))))


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

int main()
{
    ll K;
    cin >> K;
    queue<ll> que;
    que.push(1);
    que.push(2);
    que.push(3);
    que.push(4);
    que.push(5);
    que.push(6);
    que.push(7);
    que.push(8);
    que.push(9);
    for(ll i=0;i<K;i++)
    {
        ll x=que.front();
        que.pop();
        if (i==K-1)cout<<x;
        if(x%10!=0)que.push(10*x+x%10-1);
        que.push(10*x+x%10);
        if(x%10!=9)que.push(10*x+x%10+1);
    }
}

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

using namespace std;

int main()
{
    int l, r;
    cin >> l >> r;
    long long ans = 2019;
    if(r - l < 2019)
    {
        for(int i = l; i < r; i ++)
            for(int j = i + 1; j <= r;  j ++)
                ans = min(ans, 1ll * i * j % 2019);
    } else ans = 0;
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n;
    string s;
    cin>>n>>s;
    int r=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r++;
        }
    }
    if(r>n-r){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())
H = list(map(int, input().split()))
flag = True
H[0] -= 1
for i in range(1, n):
    if H[i] - H[i - 1] > 0:
        H[i] -= 1
    elif H[i] - H[i - 1] < 0:
        flag = False

print('Yes' if flag == True else 'No')

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

using namespace std;

#define m 1000000
int arr[m];
vector<int>v;

void sive()
{

    for(long long  i=2;i*i<=m;i++)
    {
        if(arr[i]==0)
        {
            for(long long  j=i*i;j<m;j+=(2*i))
                arr[j]=1;
        }
    }

    v.push_back(2);

    for(int i=3;i<m;i+=2)
    {
        if(!arr[i])
            v.push_back(i);
    }
}

int main()
{
    sive();

    int n;
    cin>>n;
    vector<int>::iterator it;
     it=lower_bound (v.begin(), v.end(), n);
     cout<<*it;

    return 0;
}


Measured memory_bytes: 4732
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[1000000], ans, dp[110000];
Pll a[200000], b[2000000];
string str, ss, dd;
bool f,ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m >> k;
	cout << (n + m)*k / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,m,k,l[100005],o[100005],t[100005],dp[100005][2],r[100005],ans;
vector<int>g[100005],G[100005];
bool vis[100005];
void dfs(int v,int p){
	vis[v]=true;
	o[v]=k;
	l[v]=k++;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i];
		if(u==p)continue;
		if(!vis[u]){
			dfs(u,v);
			l[v]=min(l[v],l[u]);
		}else l[v]=min(l[v],o[u]);
	}
}
bool bridge(int v,int u){
	if(o[u]<o[v])swap(v,u);
	return o[v]<l[u];
}
void build(int v){
	vis[v]=true;
	t[k]++;
	r[v]=k;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i];
		if(!vis[u]&&!bridge(v,u))build(u);
	}
}
void solve(int v,int p){
	vis[v]=true;
	dp[v][1]=t[v];
	for(int i=0;i<G[v].size();i++){
		int u=G[v][i];
		if(u==p)continue;
		solve(u,v);
		dp[v][0]+=max(dp[u][1],dp[u][0]);
		dp[v][1]+=dp[u][0];
	}
}
int main(void){
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].PB(b);
		g[b].PB(a);
	}
	for(int i=0;i<n;i++)if(!vis[i])dfs(i,-1);
	k=0;
	for(int i=0;i<n;i++){vis[i]=false;}
	for(int i=0;i<n;i++){
		if(!vis[i]){
			build(i);
			k++;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<g[i].size();j++){
			if(r[i]!=r[g[i][j]]){
				G[r[i]].PB(r[g[i][j]]);
			}
		}
	}
	for(int i=0;i<k;i++)vis[i]=false;
	for(int i=0;i<k;i++){
		if(!vis[i]){
			solve(i,-1);
			ans+=max(dp[i][0],dp[i][1]);
		}
	}
	printf("%d\n",ans);
}



Measured memory_bytes: 16632
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <limits>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	long long A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if (V > W) {
		long long S = V - W;
		if (abs(A - B) <= S * T) {
			cout << "YES" << endl;
		}
		else cout << "NO" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3536
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e6+5;


int  main()
{
    FAST;
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    cin>>n;
    ll cnt=0;
    for(i=1;i<n;i++)
    {
        for(j=1;i*j<n;j++)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}




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

using namespace std;

int h,w;
char s[2200][2200];
int sh[2200][2200]={0},sw[2200][2200]={0};

signed main(){
    cin>>h>>w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin>>s[i][j];
        }
    }

    for(int i=0;i<h;++i){
        int c=0,p=0;
        for(int j=0;j<w;++j){
            if(s[i][j]=='.'){
                c++;
                if(j==w-1){
                    for(int k=p;k<=j;++k){
                        sh[i][k]=c;
                    }
                    c=0;
                    p=0;
                }
                }
            else{
                for(int k=p;k<j;++k){
                    sh[i][k]=c;
                }
                    c=0;
                    if(j!=w-1)p=j+1;
                    else p=0;
                
            }
        }
    }
    for(int i=0;i<w;++i){
        int c=0,p=0;
        for(int j=0;j<h;++j){
            if(s[j][i]=='.'){
                c++;
                if(j==h-1){
                    for(int k=p;k<=j;++k){
                        sw[k][i]=c;
                    }
                    c=0;
                    p=0;
                }
            }
            else{
                for(int k=p;k<j;++k){
                    sw[k][i]=c;
                }
                c=0;
                    if(j!=h-1)p=j+1;
                    else p=0;
            }
        }
    }

    int res=-1;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(s[i][j]!='#')res=max(res,sh[i][j]+sw[i][j]-1);
            //cout<<sh[i][j];
        }
        cout<<endl;
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 42368
a,b,c,d=map(int,input())

if a+b+c+d==7:
  print(a,end=''),print('+',end=''),print(b,end=''),print('+',end=''),print(c,end=''),print('+',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a+b-c+d==7:
  print(a,end=''),print('+',end=''),print(b,end=''),print('-',end=''),print(c,end=''),print('+',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a+b+c-d==7:
  print(a,end=''),print('+',end=''),print(b,end=''),print('+',end=''),print(c,end=''),print('-',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a+b-c-d==7:
  print(a,end=''),print('+',end=''),print(b,end=''),print('-',end=''),print(c,end=''),print('-',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a-b+c+d==7:
  print(a,end=''),print('-',end=''),print(b,end=''),print('+',end=''),print(c,end=''),print('+',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a-b+c-d==7:
  print(a,end=''),print('-',end=''),print(b,end=''),print('+',end=''),print(c,end=''),print('-',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a-b-c+d==7:
  print(a,end=''),print('-',end=''),print(b,end=''),print('-',end=''),print(c,end=''),print('+',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()
if a-b-c-d==7:
  print(a,end=''),print('-',end=''),print(b,end=''),print('-',end=''),print(c,end=''),print('-',end=''),print(d,end=''),print('=',end=''),print(7)
  exit()

Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;
int main() {

	int A, B;
	cin >> A >> B;
	if ((A + B) % 3 == 0 || A%3 == 0 || B%3 == 0)
		cout << "Possible\n";
	else
		cout << "Impossible\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>
#include <iostream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

    int s = N.size();
    int res2=0;
    bool fla = true;

    for(int i = 0;i < s-1;i++)
        res2 += 9;

    for(int i = 1;i < s;i++){
        if(N.at(i) != '9')
            fla = false;
    }

    if(fla){
        res2 += int(N.at(0)) -48;
    }else{
        res2 += int(N.at(0)) -49;
    }

    cout << res2 << endl;

    
}

Measured memory_bytes: 3588
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    map<int, int> mp;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int in;
        cin >> in;
        ans += mp[i - in];
        mp[i + in]++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  std::string s,t;cin>>s>>t;
  int ans=0;
  for(int i=0;i<=s.size();i++){
    if(s[i]!=t[i])ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3816
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, m) = read!(usize, usize);
    println!("{}", (100 * n + 1800 * m) * 2usize.pow(m as u32));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,N_copy;
  string ans;
  cin >> N;
  int a[8];
  int sum=0;
  N_copy =N;
  for (int i=0;i<8;i++){
 	a[i] = (N_copy % 10);
    N_copy /= 10;
    sum += a[i];
  }
  int b;
  b = N/sum;
  
  if (sum*b ==N){
  ans = "Yes";
  }else{
  ans = "No";
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        private const long MOD = 1000000007;
        static void SolveA(string[] args)
        {
            int n = ReadAndParseInt();
            if( n == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                int a = ReadAndParseInt();
                int b = ReadAndParseInt();
                Console.WriteLine(a + b);
            }
        }
       
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	bool turn = 0;
	while(a > 0 && c > 0){
		if(turn)a-=d;
		else c-=b;
		turn = !turn;
	}
	cout << (a <= 0?"No":"Yes") << '\n';
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int cmp(int x,int y){
    return x>y;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    long long ans=0;
    ans+=a[1];
    for(int i=2;i<=n-1;i++){
        ans+=a[i/2+1];
    }
    cout<<ans;
    return 0;
}


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

using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v;
    if(n < k) {
        cout << 1 << "\n";
        return 0;
    }
    while(1) {
        int r = n % k;
        v.push_back(r);
        n /= k;
        if(n < k) {
            v.push_back(n);
            break;
        }
    }
    cout << v.size() << "\n";
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m;
vi a,b;
vvp g;

bool dfs(int v,int d){
	b[v]=1;
	a[v]=d;
	bool B=1;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i].first,c=g[v][i].second;
		if(!b[u]) B&=dfs(u,d+c);
		else if(a[u]!=a[v]+c) B=0;
	}
	return B;
}

int main(){
	cin>>n>>m;
	a=b=vi(n);
	g=vvp(n);
	for(int i=0;i<m;i++){
		int s,t,d;
		cin>>s>>t>>d;
		s--;t--;
		g[s].push_back({t,d});
		g[t].push_back({s,-d});
	}
	bool B=1;
	for(int i=0;i<n;i++) if(!b[i]){
		B&=dfs(i,0);
	}
	cout<<(B?"Yes":"No")<<endl;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ll n,k;
    cin>>n>>k;
    ll prod[n];
    ll arr[n];
    REP(i,0,n){
        cin>>arr[i];
    }
    // REP(i,0,n){
        // cout<<prod[i]<<" ";
    // }
    // cout<<endl;
    REP(i,k,n){
        if(arr[i] > arr[i-k]){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5136
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template <typename T>
struct ST{
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
  ST(){};
  ST(F f,T ti):f(f),ti(ti){}
  void init(int n_){    
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
  }
  T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};
int main(){
    auto f=[](ll a,ll b){return (a|b);};
    int n;
    cin>>n;
    string s;
    cin>>s;
    V<ll> dat(n);
    for(int i=0;i<n;i++)dat[i]=(1ll<<(s[i]-'a'));
    ST<ll> tree(f,0ll);
    tree.build(dat);
    int q;
    cin>>q;
    while(q--){
        int c;
        cin>>c;
        c--;
        if(c){
            int a,b;
            cin>>a>>b;
            ll d=tree.query(a-1,b);
            ll cnt=0;
            for(int i=0;i<26;i++){
                if(d&(1ll<<i))cnt++;
            }
            cout<<cnt<<"\n";
        }else{
            int a;char b;
            cin>>a>>b;
            tree.set_val(a-1,(1ll<<(b-'a')));
        }
    }
}


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

int div(vector<int> A, int kaisu) {
	while (true) {
		for (int i = 0; i < A.size(); i++) {
			if (A[i] % 2 == 1)return kaisu;
			A[i] /= 2;
		}
		++kaisu;
	}
}

int main(void) {
	int N;
	int kaisu(0);
	cin >> N;
	vector<int> A(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	
	
	cout << div(A, kaisu);
	return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
   char x, y;
   cin >> x >> y;
   if (x > y) {
      puts(">");
   } else if (x < y) {
      puts("<");
   } else {
      puts("=");
   }

   return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
#define N 100
 
int main(void){
  int i=0,num[N],x;
  char str[N];
 
  while(scanf("%s",str)!=EOF){
    if(str[0]=='+'){
      num[i-2]+=num[i-1];
      i--;
    }else if(str[0]=='-'){
      num[i-2]-=num[i-1];
      i--;
    }else if(str[0]=='*'){
      num[i-2]*=num[i-1];
      i--;
    }else{
      x=atoi(str);
      num[i]=x;
      i++;
    }
  }
  printf("%d\n",num[0]);
  return 0;
}

Measured memory_bytes: 548
# D - Cake 123

import heapq
import itertools

x, y, z, k = map(int, input().split())

A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())

hq = []
for i, j in itertools.product(A, B):
    heapq.heappush(hq, (i+j)*-1)

AB = []
while len(hq)>0 and len(AB)<=k:
    AB.append(heapq.heappop(hq)*-1)

hq = []
for i, j in itertools.product(AB, C):
    heapq.heappush(hq, (i+j)*-1)

for _ in range(k):
    print(heapq.heappop(hq)*-1)

Measured memory_bytes: 158892
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,m,t;
  bool f=1;
  map<int,int> d={};
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t;
    d[t]++;
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>t;
    d[t]--;
    if(d[t]<0) f=false;
  }
  if(f) cout<<"YES";
  else cout<<"NO";
  cout<<"\n";
}

Measured memory_bytes: 9600
import java.util.Scanner;

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

        if (a + b < a - b) {
            if (a - b < a * b) {
                System.out.println(a * b);
            } else {
                System.out.println(a - b);
            }
        } else {
            if (a + b < a * b) {
                System.out.println(a * b);
            } else {
                System.out.println(a + b);
            }
        }

    }
}

Measured memory_bytes: 22740
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    ll n;
    cin >> n;
    if(n % 1000 == 0){
        cout << 0 << "\n";
    }
    else{
        ll x = n / 1000;
        x++;
        x *= 1000;
        cout << x - n << "\n";
    }
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;
 
int main()
{
    std::string s;
    cin >> s;
    bool flag = false;

    unordered_map<char, int> map;
    for (int i = 0; i < s.length(); i++) {
        char a = s[i];
        if (map.find(a) != map.end()) {
            map[a] += 1;
        } else {
            map[a] = 1;
        }
    }
    if (map.size() == 2) {
        int count = 0;
        for(auto pair: map){
            if (pair.second == 2) {
                count += 1;
            } 
        }
        if (count == 2) {
            flag = true;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

const ll INF = 1e18 + 8;

void max_self (ll &a, ll b) {
    a = max(a, b);
}

void min_self (ll &a, ll b) {
    a = min(a, b);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen("input.in", "r", stdin);
    ///freopen("output.out", "w", stdout);
    ll n, m;
    cin >> n >> m;
    vector <ll> weight(n), value(n);
    for (ll i = 0; i < n; ++i)
        cin >> weight[i] >> value[i];
    ll sum_value = accumulate(value.begin(), value.end(), 0LL);
    vector <ll> dp(sum_value + 1, INF);                                 ///minimum weight to reach this value
    dp[0] = 0;
    for (ll i = 0; i < n; ++i)
        for (ll j = sum_value - value[i]; j >= 0; --j)
            min_self(dp[j + value[i]], dp[j] + weight[i]);
    ll ans = 0;
    for (ll i = 0; i <= sum_value; ++i)
        if (dp[i] <= m)
            max_self(ans, i);
    cout << ans;
    return 0;
}

/**


**/


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

using namespace std;

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

	vector<Int> v;
	for (Int i = 1; i * i <= min(A, B); ++i) {
		if (A % i == 0 && B % i == 0) {
			v.emplace_back(i);
		}
		if (A % i == 0 && B % (A / i) == 0) {
			v.emplace_back(A / i); 
		}
		if (B % i == 0 && A % (B / i) == 0) {
			v.emplace_back(B / i);
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

	int ans = 0;
	for (int i = 0; i < v.size(); ++i) {
		bool ok = true;
		for (Int j = 2; j * j <= v[i]; ++j) {
			if (v[i] % j == 0) { ok = false; }
		}
		if (ok) { ++ans; }
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;
#define ll long long int
#define pb push_back
#define rep(i, a, v) for(int i = a; i <= v; ++i)
#define vi vector<int>
#define vll vector<ll>
#define maxi 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
const double pie = 3.1415926535;
const string spaces = "    ";

ll i, j, k;
ll temp;

int main(){
    cout.tie(0);
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> heights(n + 10, 0), dp(n + 10, maxi);
    for(int i = 0; i < n; ++i){
        cin >> heights[i];
    }
    
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(heights[i + 1] - heights[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(heights[i + 2] - heights[i])); 
    }

    cout << dp[n - 1] << "\n";

    return 0;
}


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

long long N, A[1 << 18];

int main() {
	cin >> N; long long S = 0;
	for (int i = 1; i <= N; i++) { cin >> A[i]; S += A[i]; }

	long long minx = S, sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += A[i];
		minx = min(minx, abs(sum - (S - sum)));
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_diff_temperature = 600
min_diff_remparature_i = -1
for i in range(N):
    temperature = T - H[i] * 0.006
    if abs(temperature-A) < min_diff_temperature:
        min_diff_remparature_i = i
        min_diff_temperature = abs(temperature-A)

print(min_diff_remparature_i + 1)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 100000000
typedef pair<int, int> pii;

vector<int> A(10);
bool ans = false;
void dfs(int a, int b, int cnt)
{
	if (cnt == 9)
	{
		if (a < A[cnt])ans = true;
		if (b < A[cnt])ans = true;
		return;
	}
	if (A[cnt] > a)dfs(A[cnt], b, cnt + 1);
	if (A[cnt] > b)dfs(a, A[cnt], cnt + 1);
	if (A[cnt] < a && A[cnt] < b)return;
}

int main()
{
	int n;
	cin >> n;
	loop(k, n)
	{
		loop(i, 10)
		{
			cin >> A[i];
		}
		ans = false;
		dfs(0, 0, 0);
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;



long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}



int main() {

	long long ans;
	int a;

	cin >> a;

	ans = a + a*a + a*a*a;

	cout << ans << endl;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 3628
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b=parseMap(split(readline()))
    if 0 in [a%3,b%3,(a+b)%3]
        println("Possible")
    else
        println("Impossible")
    end
end
main()

Measured memory_bytes: 110404
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int N = Integer.valueOf(scn.nextLine()).intValue();
		String[] S = new String[N];
		boolean how = true;
		for (int i = 0; i < N; i++) {
			String str = scn.nextLine();
			for (int j = 0; j < i; j++) {
				if (str.equals(S[j])) {
					how = false;
					break;
				}
				if (j == i - 1) {
					String buf = S[i - 1];
					if (buf.charAt(buf.length() - 1) != str.charAt(0)) {
						how = false;
						break;
					}
				}
			}
			S[i] = str;
		}
		System.out.println(how?"Yes":"No");
		scn.close();
	}
}


Measured memory_bytes: 22612