akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
g = []
for _ in range(h):
    S = input()
    tmp = [str(i) for i in S]
    g.append(tmp)
from collections import deque
# print(g)
dp = [[0]*w for _ in range(h)]
def dfs(i,j):
    seen = [[False]*w for _ in range(h)]
    seen[i][j] = True
    q = deque([])
    q.append((i,j,0))
    dist=[(1,0),(-1,0),(0,1),(0,-1)]
    while q:
        x,y,cnt = q.popleft()
        for dx,dy in dist:
            if 0 <=x+dx<h and 0<=y+dy<w and seen[x+dx][y+dy]==False and g[x+dx][y+dy]=='.':
                seen[x+dx][y+dy] = True
                q.append((x+dx,y+dy,cnt+1))
    return cnt
ans = 0
for i in range(h):
    for j in range(w):
        if g[i][j] =='.':
            ans =max(ans,dfs(i,j))
print(ans)

Measured memory_bytes: 74684
n,m,k=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b = [0] * (m+1)
for i in range(m):
  b[i+1] = b[i] + B[i]

from bisect import bisect_right

result = 0
a = k
for i in range(n+1):
  index = bisect_right(b, a)
  hon = (index - 1) + (i)
  result = max(result, hon)
  if i < n:
    a -= A[i]
  if a < 0:
    break
print(result)
    


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

LL n, m, l = 0, r = 1e12, mid;

bool check(LL x){
	if (n >= x) return m >= 2*x;
	return m-2*(x-n) >= 2*x;
}

int main(){
	scanf("%lld%lld", &n, &m);
	while (l < r){
		mid = (l+r+1) >> 1;
		if (check(mid)) l = mid;
		else r = mid-1;
	}
	printf("%lld", l);
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstdio>

using namespace std;

struct list {
	int key;
	list *next,*prev;
};

list *head, *tail, *p;

void insert_x(int key) {
	list *make = new list;
	make->key = key;
	if (head == NULL) {
		head = tail = make;
		make->next = make->prev = NULL;
	}
	else {
		head->prev = make;
		make->next = head;
		head = make;
	}
}

void deleteFirst() {
	list* tmp = head;
	if (head == tail) {
		head = tail = NULL;
	}
	else {
		head = head->next;
		head->prev = NULL;
	}
	delete tmp;
}
void deleteLast() {
	list* tmp = tail;
	if (tail == head) {
		head =  tail = NULL;
	}
	else {
		tail = tail->prev;
		tail->next = NULL;
	}
	delete tmp;
}
void delete_x(int key) {
	p = head;
	while (p->key != key) {
		if (p->next == NULL)
			return;
		p = p->next;
	}
	if (p == head)
		deleteFirst();
	else if (p == tail)
		deleteLast();
	else {
		p->prev->next = p->next;
		p->next->prev = p->prev;
		delete p;
	}
}

int main() {
	head = tail = p = NULL;
	int n=0;
	char command[12];
	int key =0;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%s", command);
		if (strcmp(command, "insert") == 0) {
			scanf("%d", &key);
			insert_x(key);
		}
		else if (strcmp(command, "delete") == 0) {
			scanf("%d", &key);
			delete_x(key);
		}
		else if (strcmp(command, "deleteFirst") == 0) {
			deleteFirst();
		}
		else if (strcmp(command, "deleteLast") == 0) {
			deleteLast();
		}
	}

	while(true){
		if (head->next != NULL) {
			cout << head->key << " ";
			head = head->next;
		}
		else {
			cout << head->key << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 32364
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  map<char,int> scnum;
  FOR(i,2,10) scnum['0'+i]=i;
  scnum['T']=10;
  scnum['J']=11;
  scnum['Q']=12;
  scnum['K']=13;
  scnum['A']=14;
  for(;;){
    string tr;
    cin >> tr;
    if(tr=="#") return 0;
    vector<vector<string> > card(4,vector<string>(13));
    REP(i,4) REP(j,13) cin >> card[i][j];
    int lead=0;
    int ns=0;
    REP(j,13){
      int str[4]={};
      REP(i,4){
	if(card[i][j][1]==card[lead][j][1]) str[i]+=50;
	if(card[i][j][1]==tr[0]) str[i]+=100;
	str[i]+=scnum[card[i][j][0]];
      }
      int tmps=0;
      int sucl=0;
      REP(i,4) if(tmps<str[i]){
	tmps=str[i];
	sucl=i;
      }
      if(sucl%2==0) ++ns;
      lead=sucl;
    }
    if(ns>6) cout << "NS " << ns-6 << endl;
    else cout << "EW " << 7-ns << endl;
    
  }
}

Measured memory_bytes: 3140
/*
ID: your_id_here
PROG: test
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
//double pi=3.1415926535898;
//double pi=acos(-1.0);
#define scarr(a,s,e) for(int i=s;i<=int(e);i++) scanf("%d ",&a[i]);
#define prarr(a,s,e) for(int i=s;i<=int(e);i++) printf("%d ",a[i]);
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define rep(i,a,b) for(int i=a;i<=int(b);++i)
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define mkp        make_pair
#define sc(x)      scanf("%d",&x)
#define scl(x)     scanf("%lld",&x)
#define pr(x)      printf("%d ",x)
#define prl(x)     printf("%lld ",x)
#define prln(x)    printf("%d\n",x)
#define prlln(x)   printf("%lld\n",x)
#define r0         return 0;
#define CC         continue;
#define scd(x)     scanf("%lf",&x)
#define prd(x)     printf("%.10f\n",x)
#define bb(x)      cerr<< x <<endl;
#define pii        pair<int,int>
#define pis        pair<int,string>
#define vi         vector<int>
#define x         first
#define y         second
//#define max(a,b) a<b?b:a __builtin_popcount;
//#define min(a,b) a<b?a:b
const ll M  = 1e9+7 ;
const ll linf = 1e18 ;
const int iinf = INT_MAX ;
const int N = 300300 ;
//////////////////////    Hi    ^_^  hack me if you can :P

int main()
{
    //freopen("output.txt","w",stdout),freopen("input.txt","r",stdin);
    speed;
    int s=0;
    int k=0;
    int n;
    cin>>n;
    while(s<n){
        s+=k++;
    }
    int d = s - n;
    for (int i=1;i<k;i++)
    if(i!=d)
        cout<<i<<endl;
    r0;
}

/*

freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}
Wj0944296025*
http://ideone.com/KrXO2S
*/
/*
for (int i=0;i<n;i++)            Hi    ^_^  hack me if you can :P
int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};
bool inside (int i,int j) {return (i>=0 && i<n && j>=0 && j<m);}

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy){
    if(!m) {d=n; xx=1; yy=0;}
    else {gcd(m,n%m,d,yy,xx); yy-=xx*(n/m);}
}

int getm(int l,int r)
{
    if(l>r)
        return N;
    if(l==r)
        return 0;
    if(l==r-1)
        return s[l] != s[r];
    if(s[l]==s[r])
        return getm(l+1,r-1);
    else
        return 1+min(getm(l+1,r),getm(l,r-1));
}

int BIT[si], a[si], n;
void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}
int query(int x)
{
    int sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

*/


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

// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main() {
    int n, k; cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    UnionFind uf(n-k+1);
    int sameflag = -1;
    for (int left = 0; left < n; ) {
        for (int right = left+1; right <= n; right++) {
            if (right == n || p[right-1] > p[right]) {
                for (int u = left; u <= right-k; u++) {
                    if (sameflag == -1) sameflag = left+1;
                    uf.unite(sameflag, u+1);
                }
                left = right;
                break;
            }
        }
    }
    set<int> s;
    for (int i = 0; i < n; i++) {
        if (i >= k) {
            if (p[i-k] == *s.begin() && *s.rbegin() < p[i]) {
                uf.unite(i-k+1, i-k+2);
            }
            s.erase(p[i-k]);
        }
        s.insert(p[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (uf.data[i] < 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int n,ans(0);
    cin >> n;
    map<string,int> s;
    rep(i,n){
        string x;
        cin >> x;
        s[x]++;
    }
    put(s.size());
    return 0;
}

Measured memory_bytes: 19120
#include <iostream>

using namespace std;

int main()
{
	int a,b;

	cin >> a >> b;

	if(a + b == 15){
		cout << "+";
	}
	else if(a * b == 15){
		cout << "*";
	}
	else{
		cout << "x";
	}

	return 0;
}


Measured memory_bytes: 256
import math
[A,B] = [int(s) for s in input().rstrip().split(' ')]
for i in range(10*B,10*B+10): #10%消費税でB円課される範囲
  if math.floor(i * 0.08) == A:
    print(i)
    break
else:
  print("-1")

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

#define fi first
#define se second

typedef pair<int, int> ii;

const int MAXN = 100005;
const int INF = 1 << 30;
 
int V, E, S, d[MAXN];
vector<ii> adjList[MAXN];
 
int main() {

    scanf("%d%d%d",&V,&E,&S);
    for (int i = 0, u, v, w; i < E; i++) {
        scanf("%d%d%d",&u,&v,&w);

        adjList[u].push_back(ii(w,v));
      //adjList[v].push_back(ii(w,u));
    }
 
    fill(d,d+V,INF); d[S] = 0;
    priority_queue< ii,vector<ii>,greater<ii> > pq; pq.push(ii(0,S));
    while(!pq.empty()) {
        ii p = pq.top(); pq.pop();
        int dist = p.fi, u = p.se;
 
        if(dist > d[u]) continue;
 
        for (int i = 0; i < adjList[u].size(); i++) {
            ii &v = adjList[u][i];
 
            if (d[v.se] > d[u] + v.fi) {
                d[v.se] = d[u] + v.fi;
                pq.push(ii(d[v.se], v.se));
            }
        }
    }
 
    for (int i = 0; i < V; i++)
        if (d[i] == INF)
            puts("INF");
        else
            printf( "%d\n", d[i] );
 
    return 0;
}

Measured memory_bytes: 11304
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
using namespace std;

// Problem  https://atcoder.jp/contests/abc128/tasks/abc128_b
// Reference https://img.atcoder.jp/abc128/editorial.pdf

vector<int> solver(int restN, vector<pair<pair<string,int>,int>> restData){
    vector<int> result(restN);

    sort(restData.begin(),restData.end());
    /** for(int j=0;j<restN;j++){
        cout << restData.at(j).first.first << " " << 
                restData.at(j).first.second << " " << 
                restData.at(j).second << endl; 
    }**/
    for(int j=0;j<restN;j++){
        result.at(j) = restData.at(j).second;
    }
    return result;
}

int main(void){
    int N;
    cin >> N;
    vector<int> answer(N);
    vector<pair<pair<string,int>,int>>  data(N);
    for(int j=0;j<N;j++){
        string Sj;
        int Pj;
        cin >> Sj >> Pj;
        data.at(j) = make_pair(make_pair(Sj,-Pj),j+1);
    }
   /** for(int j=0;j<N;j++){
        cout << data.at(j).first.first << " " << 
                data.at(j).first.second << " " << 
                data.at(j).second << endl; 
    }**/
    answer = solver(N,data);
    for(int j=0;j<N;j++){
        cout << answer.at(j) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
string n;
int sum;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<sz(n);i++) sum+=(n[i]-'0');
	cout<<(sum%9?"No":"Yes");
	re 0;
}

Measured memory_bytes: 3744
N = int(input())
S = input()

d = {0:0}
l = [0]*N
for i in range(1,N+1):
    if S[i-1] == "E":
        d[i] = d[i-1]+1
    else:
        d[i] = d[i-1]
    l[i-1] = i-1-d[i-1]-d[i]

print(min(l)+d[N])

Measured memory_bytes: 46796
n = int(input())
s = input()

count = 0
left = 0
right = 0

for i in s:
    if i == '(':
        count += 1
    else:
        count -= 1

        if count == -1:
            count = 0
            left += 1

right = count

print('(' * left + s + ')' * right)

Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main(){
    int w,h;
    while (1 > 0){
        cin >> w >> h;
        if (w == 0 && h == 0){
            break;
        }
        for (int  i = 0; i < w; i++){
            for (int j = 0; j < h; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
#include<stdio.h>
#define For(i,e) for (i=0;i<e;i++)
int main()
{
	int n,i,j;
	int matrix[11][11];
	while (1) {
		scanf("%d",&n);
		if (n==0) break;
		For (i,n) For (j,n) scanf("%d",&matrix[i][j]);
		For (i,n) matrix[n][i]=matrix[i][n]=0;
		matrix[n][n]=0;
		For (i,n) {
			For (j,n) {
				matrix[i][n]+=matrix[i][j];
				matrix[n][i]+=matrix[j][i];
			}
			matrix[n][n]+=matrix[i][n];
		}
		For (i,n+1) {
			For (j,n+1) printf("%5d",matrix[i][j]);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int N = 0;
    int ans = 0;
    
    cin >> N;
    
    int A[N];
    int B[N];
    int C[N];

    rep(i, 0, N) {
        cin >> A[i];
        A[i]--; 
    }
    rep(i, 0, N) {
        cin >> B[i];
    }
    rep(i, 0, N - 1) {
        cin >> C[i];
    }
    
    rep(i, 0, N) {
        //cout << "a " << B[A[i]] << endl;
        ans += B[A[i]];
    }

    rep(i, 0, N-1) {
        if((A[i] + 1) == A[i+1]) {
            ans += C[A[i]];
            //cout << "b " << C[A[i]] << endl;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/22.
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    int initial, year, janre;

    Main(int initial, int year, int janre){
        this.initial = initial;
        this.year = year;
        this.janre = janre;
    }


    public static void main(String args[]){
        int m, simpOrComp, commission, tmp, interest, max;
        double rate;
        Main o;
        m = sc.nextInt();
        for(int i = 0; i < m; i++){
            max = 0;
            o = new Main(sc.nextInt(), sc.nextInt(), sc.nextInt());
            for(int j = 0; j < o.janre; j++){
                tmp = o.initial;
                simpOrComp = sc.nextInt();
                rate = sc.nextDouble();
                commission = sc.nextInt();
                if(simpOrComp == 0){
                    interest = 0;
                    for(int k = 0; k < o.year; k++){
                        interest += tmp * rate;
                        tmp -= commission;
                    }
                    tmp += interest;
                }else{
                    for(int k = 0; k < o.year; k++) tmp += tmp * rate - commission;
                }
                if(max < tmp) max = tmp;
            }
            System.out.println(max);
        }
    }
}

Measured memory_bytes: 42056
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   int n;
   cin>>n;
   string str;
   int c0=0,c1=0,c2=0,c3=0;
   while(n--){
       cin>>str;
       if(str == "AC"){
           c0++;
       }
       if(str=="WA"){
           c1++;
       }
       if(str=="TLE"){
           c2++;
       }
       if(str=="RE"){
           c3++;
       }
   }

   cout<<"AC x "<<c0<<endl;
   cout<<"WA x "<<c1<<endl;
   cout<<"TLE x "<<c2<<endl;
   cout<<"RE x "<<c3<<endl;

}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



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

char number[20];
int L;
int DP[20];

int main () {
	scanf (" %s", number);
	L = strlen (number);
	long long sum = 0;
	for (int i = 0; i < (1 << (L - 1)); ++i) {
		long long cur = 0;
		for (int j = 0; j < L; ++j) {
			cur = cur * 10 + number[j] - '0';
			if (((i >> j) & 1) == 1) {
				sum += cur;
				cur = 0;
			}
		}
		sum += cur;
	}
	printf ("%lld\n", sum);
}



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

int main() {
  int N,K,A,D;
  cin>>N>>K;
  vector<int> V(N);
  for (int j=0;j<K;j++){
    cin>>D;
  for (int i = 0; i < D; i++) {
    cin >>A;
    V.at(A-1)=1;
  }
  }
  int cnt=0;
  for(int i=0;i<N;i++){if(V.at(i)==0)cnt++;}
  cout<<cnt<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 22;
const int INF = 1e17 + 239;

int n;

int dp[N][N];
int mem[N + 1][N + 1];

vector<int> solve(vector<int> ys, vector<int> cnts, vector<int> lims) {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = INF;
		}
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			mem[i][j] = -1;
		}
	}
	auto go = [&](int l, int r) {
		if (mem[l + 1][r + 1] == -1) {
			int L = -INF;
			if (l >= 0) L = ys[l];
			int R = INF;
			if (r < n) R = ys[r];
			int c = 0;
			for (int i = l; i <= r; i++) {
				if (0 <= i && i < n) {
					int one = lims[i];
					one = min(one, abs(L - ys[i]));
					one = min(one, abs(R - ys[i]));
					c += one * cnts[i];
				}
			}
			mem[l + 1][r + 1] = c;
		}
		return mem[l + 1][r + 1];
	};
	for (int i = 0; i < n; i++) {
		dp[i][1] = go(-1, i);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= n; j++) {
			if (dp[i][j] == INF) continue;
			for (int nx = i + 1; nx < n; nx++) {
				dp[nx][j + 1] = min(dp[nx][j + 1], dp[i][j] + go(i, nx)); 
			}
		}
	}
	vector<int> ans(n + 1, INF);
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= n; j++) {
			ans[j] = min(ans[j], dp[i][j] + go(i, n));
		}
	}
	ans[0] = go(-1, n);
	return ans;
}

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

	cin >> n;
	vector<int> x(n);
	vector<int> y(n);
	vector<int> cnt(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> cnt[i];
	}
	vector<int> ans(2 * n + 1, INF);
	for (int mask = 0; mask < (1 << n); mask++) {
		vector<int> lim(n);
		for (int i = 0; i < n; i++) {
			lim[i] = min(abs(x[i]), abs(y[i]));
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if ((mask >> j) & 1) {
					lim[i] = min(lim[i], abs(x[i] - x[j]));
				}
			}
		}
		vector<tuple<int, int, int>> A;
		for (int i = 0; i < n; i++) {
			A.push_back(make_tuple(y[i], cnt[i], lim[i]));
		}
		sort(A.begin(), A.end());
		vector<int> ys(n);
		vector<int> cnts(n);
		vector<int> lims(n);
		for (int i = 0; i < n; i++) {
			ys[i] = get<0>(A[i]);
			cnts[i] = get<1>(A[i]);
			lims[i] = get<2>(A[i]);
		}
		auto cost = solve(ys, cnts, lims);
		for (int i = 0; i <= n; i++) {
			ans[i + __builtin_popcount(mask)] = min(ans[i + __builtin_popcount(mask)], cost[i]);
		}
	}
	for (int i = 0; i <= n; i++) {
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    rep(i, K) {
        if(i % 2 == 0) {
            if(A % 2 != 0) A--;
            B += A / 2;
            A /= 2;
        } else {
            if(B % 2 != 0) B--;
            A += B / 2;
            B /= 2;
        }
        dump(A);
        dump(B);
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
s=input()

jud=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(len(s)):
    for j in range(26):

#        print(s[i]+ " "+str(j+ord("a")))
        if ord(s[i])==j+ord('a'):
            jud[j]+=1

a=False


#print(jud)

for i in range(26):
    if jud[i]>=2:
        a=(jud[i]>=2)
        print("no")
        break

if a==False:
    print("yes")

Measured memory_bytes: 3064
N=gets.to_i
as=[]
bs=[]
N.times{
    a, b = gets.split.map(&:to_i)
    as << a
    bs << b
}
sum = 0
(N-1).downto(0).each{|i|
    a, b = as[i], bs[i]
    diff =  (b - (a + sum) % b) % b
    sum += diff
    # puts "i=#{i}, a=#{a}, b=#{b}, diff=#{diff}, sum=#{sum}"
}
puts sum


Measured memory_bytes: 3412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  string result = "Yes";
  
  for (int i = 0; i < S.size(); i++) {
    if (i%2 == 0 && S.at(i) == 'L') result = "No";
    if (i%2 != 0 && S.at(i) == 'R') result = "No";
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import sys
N = int(input())
array_A = list(map(int,input().split()))

if not (2 <= N <= 100):
    sys.exit()
for I in range(len(array_A)):
    if not (1 <= array_A[I] <= 10 ** 9):
        sys.exit()

print(max(array_A) - min(array_A))

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string w;
  cin >> w;
  bool f = true;
  map<char,int> m;
  for(int i =  0; i < w.size();++i){
    m[w[i]]++;
  }
  for (auto&& n : m) {
    if(n.se % 2 == 1) f = false;
  }
  if(f) cout <<  "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        final int ARRAY_LEN = 1000010;

        int[] num = new int[ARRAY_LEN];
        boolean[] isMultiple = new boolean[ARRAY_LEN];
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (num[a] <= 0 && !isMultiple[a]) {
                for (int j = a*2; j < ARRAY_LEN; j+=a) {
                    isMultiple[j] = true;
                }
            }

            num[a]++;
        }

        int ans = 0;
        for (int i = 0; i < ARRAY_LEN; i++) {
            if (!isMultiple[i] && num[i] == 1)
                ans++;
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 58932
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long count = 1;
        long ans = 0;
        for (int i = 0 ; i < 50 ; i++) {
            if (h > 1) {
                ans += count;
                h /= 2;
                count *= 2;
            } else if (h == 1) {
                h = 0;
                ans += count;
            }
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

#define int ll

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os<<"("<<p.first <<", "<<p.second<<")";
  return os;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    map<int,int> mp,mpp;
    rep(i,n){
        int a;cin>>a;
        mp[a]++;
    }
    for(auto p:mp) mpp[p.second]++;
    vector<pair<int,int>> v;
    v.push_back(make_pair(INF,0));
    for(auto p:mpp)v.push_back(p);
    sort(ALL(v));reverse(ALL(v));

    vector<int> ans(n+1);
    int var=(int)mp.size();
    ans[var]=v.back().first;
    for(int i=var+1;i<=n;i++) ans[i]=0;


    for(int k=var-1;k>1;k--){
        auto p=v.back();v.pop_back();

        int rem=p.first;
        if(p.second>1)v.push_back(make_pair(p.first,p.second-1));
        while(rem){
            auto pn=v.back();v.pop_back();// 今均すの
            int need=(v.back().first-pn.first)*pn.second;
            if(rem>=need){
                rem-=need;
                auto pnn=v.back();v.pop_back();
                pnn.second=pnn.second+pn.second;
                v.push_back(pnn);
            }else{
                pair<int,int> fs=make_pair(pn.first+rem/pn.second+1,rem%pn.second);
                if(fs.second!=0){
                    if(v.back().first==fs.first){
                        fs.second+=v.back().second;v.pop_back();
                        v.push_back(fs);
                    }else{
                        v.push_back(fs);
                    }
                }
                pair<int,int> sc=make_pair(pn.first+rem/pn.second,pn.second-rem%pn.second);
                if(v.back().first==sc.first){
                    sc.second+=v.back().second;v.pop_back();
                    v.push_back(sc);   
                }else{
                    v.push_back(sc);
                }
                rem=0;
            }
        }

        ans[k]=v.back().first;
    }
    ans[1]=n;
    for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<int> cnt(100001);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        cnt[a]++;
    }
    int one = 0, two = 0;
    for (int i = 1; i <= 100000; i++) {
        if (!cnt[i]) continue;
        ((cnt[i] & 1) ? one : two)++;
    }
    one += (two >> 1) << 1;
    cout << one << endl;
    return 0;
}


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

int main(){
    int n,m; cin >> n >> m;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    else{
        vector<int> X(m);
        for(int i=0; i<m; i++) cin >> X[i];
        sort(X.begin(), X.end());
        if(n==1) cout << X[m-1] - X[0] << endl;
        else{
            vector<int> dis(m-1);
            for(int i=0; i<m-1; i++){
                dis[i] = X[i+1] -X[i];
            }
            sort(dis.begin(), dis.end());
            ll ans = X[m-1] - X[0];
            for(int i=0; i<n-1; i++) ans -= dis[m-2-i];
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 4056
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN], b[MAXN], c[MAXN];
map<int, int> ma;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) {
        b[i] = i + a[i];
        c[i] = i - a[i];
    }
    ll res = 0;
    FOR(i,1,n) {
        if (ma.count(c[i])) res += ma[c[i]];
        ma[b[i]]++;
    }
    cout << res;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  using T = tuple<int, int>;
  pqdesc<T> q;
  rep(i, a) { int x; cin >> x; q.emplace(x, 0); }
  rep(i, b) { int x; cin >> x; q.emplace(x, 1); }
  rep(i, c) { int x; cin >> x; q.emplace(x, 2); }
  i64 ans = 0;
  int m = 0;
  while (true) {
    int v, k;
    tie(v, k) = q.top();
    q.pop();
    if (k == 0 && x == 0) continue;
    if (k == 1 && y == 0) continue;
    ans += v;
    if (k == 0) x -= 1;
    if (k == 1) y -= 1;
    if (k == 2) m += 1;
    if (x + y <= m) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 5000;
const int MOD = 1000000007;
int fac[MAX], finv[MAX], inv[MAX],n;

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;
    }
}
int solve(int p,int q){
    int t=1;
    for(int i=0;i<=p;i++)t=(t*inv[2])%MOD;
    for(int i=0;i<q;i++)t=(t*(p-i))%MOD;
    for(int i=1;i<=q;i++)t=(t*inv[i])%MOD;
    for(int i=1;i<=19-p;i++){
        t=(t*(n-5+i))%MOD;
        t=(t*inv[i])%MOD;
    }
    return t;
}
     signed main(){
    int t;
    cin>>t;
    COMinit();
    for(int T=0;T<t;T++){
        cin>>n;
        int ans=0;
        if(n<5){
            cout<<0<<endl;
            continue;
        }
        for(int i=0;i<=15;i++){
            ans=(ans+solve(4+i,i))%MOD;
           // cerr<<ans<<' ';
        }
        if(n%2==0){
            for(int i=0;i<=4;i++)ans=(ans+MOD-solve(15+i,i))%MOD;
        }else for(int i=0;i<=4;i++)ans=(ans+solve(15+i,i))%MOD;

        cout<<ans<<endl;
    }

     }


 


 






    





      

        


Measured memory_bytes: 3764
L=int(input())
L-=1
if L!=1:
    n=L.bit_length()
    edge=[]
    for i in range(2,n+1):
        edge.append((i,i-1,0))
        edge.append((i,i-1,2**(i-2)))
    
    bit=[]
    for i in range(0,20):
        if L>>i &1==1:
            bit.append(i)
    
    x=L
    for j in range(len(bit)-1):
        i=bit[j]
        x-=2**i
        edge.append((n,i+1,x))
    edge.append((n,1,L))
    
    M=len(edge)
    print(n,M)
    for i in range(M):
        j,k,cost=edge[i]
        print(n+1-j,n+1-k,cost)
else:
    print(2,2)
    print(1,2,0)
    print(1,2,1)

Measured memory_bytes: 38256
#include<iostream>

int main() {
	int n;
	std::cin >> n;
	int *p = new int[n];

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

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

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

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int t;
  cin>>t;
  int x;
  int s[4];
  REP(i, 4){
    s[3-i]=t%10;
    t/=10;
  }
  REP(i, 8){
    x=s[0];
    for(int j=1; j<4; ++j){
      int y=1;
      REP(k, j-1) y*=2;
      if(i&y) x+=s[j];
      else x-= s[j];
    }
    if(x==7){
      cout<<s[0];
      cout<<((i&1)?'+':'-');
      cout<<s[1];
      cout<<((i&2)?'+':'-');
      cout<<s[2];
      cout<<((i&4)?'+':'-');
      cout<<s[3]<<"=7"<<endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    if(a>=1 && b>=1 && a<=10000 && b<=10000)
    {
      a=a*b;
      if(a%2==0)
      {
        System.out.println("Even");
      }else
      System.out.println("Odd");
    }
  }
}

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

int main(void){
    int t;
    int n,m;
    int ans;
    vector<int>h,w,hc,wc;
    while(true) {
        cin >> n>>m;
        if(n==0)break;
        h=vector<int>(1,0);
        w=vector<int>(1,0);
        ans=0;
        hc=vector<int>(1500000);
        wc=vector<int>(1500000);
        for(int i=0;i<n;i++){cin>>t;h.push_back(t+h[i]);}
        for(int i=0;i<m;i++){cin>>t;w.push_back(t+w[i]);}
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                if(i>=j)continue;
                hc[h[j]-h[i]]++;
            }
        }
        for(int i=0;i<=m;i++){
            for(int j=0;j<=m;j++){
                if(i>=j)continue;
                wc[w[j]-w[i]]++;
            }
        }
        for(int i=0;i<1500000;i++){
            ans+=hc[i]*wc[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 26176
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,j,k,m,n;
	string s;
	cin>>s;
	for(register int i=0;i<s.size();i++)
		if((!(i&1) && s[i]!='R' && s[i]!='U' && s[i]!='D') || ((i&1) && s[i]!='L' && s[i]!='U' && s[i]!='D')){printf("No\n");return 0;}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
# unionfind
class Uf:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]

N, M = map(int, input().split())
C = [False] * (M+1)
uf = Uf(M+1)
for _ in range(N):
    K, *L = map(int, input().split())
    l0 = L[0]
    C[l0] = True
    for l in L[1:]:
        uf.unite(l0, l)
        C[l] = True
roots = [uf.root(i) for i, c in enumerate(C) if c]
print("YES" if len(set(roots))==1 else "NO")


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

int main() {
    int n,m;
    cin>>n;
    int t[n+1],sum=0;
    for(int i=1;i<=n;i++){
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    int p[m],x[m];
    for(int i=0;i<m;i++){
        int sum1=sum;
        cin>>p[i]>>x[i];
        sum1=sum1-t[p[i]]+x[i];
        cout<<sum1<<endl;
    }
}

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

int main(){
    int N;
    std::cin >> N;
    std::vector< int > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    
    std::vector< int > tmp;
    for(int i=1; i<=(int)std::sqrt(A[0]); i++){
        if(A[0] % i == 0){
            tmp.push_back(i);
            if(i * i != A[0]){
                tmp.push_back(A[0] / i);
            }
        }
    }
    for(int i=1; i<=(int)std::sqrt(A[1]); i++){
        if(A[1] % i == 0){
            tmp.push_back(i);
            if(i * i != A[1]){
                tmp.push_back(A[1] / i);
            }
        }
    }
    
    std::sort(tmp.begin(), tmp.end());
    std::vector< int > GCD(1, tmp[0]);
    std::vector< int > GCD_cnt(1, 1);
    
    for(int i=1; i<(int)tmp.size(); i++){
        if(tmp[i] == tmp[i-1]){
            GCD_cnt[GCD_cnt.size() - 1]++;
        }else{
            GCD.push_back(tmp[i]);
            GCD_cnt.push_back(1);
        }
    }
    
    for(int i=2; i<N; i++){
        std::vector< int > GCD_tmp;
        std::vector< int > GCD_cnt_tmp;
        for(int j=0; j<GCD.size(); j++){
            if(A[i] % GCD[j] == 0){
                GCD_tmp.push_back(GCD[j]);
                GCD_cnt_tmp.push_back(GCD_cnt[j]+1);
            }else if(GCD_cnt[j] == i){
                GCD_tmp.push_back(GCD[j]);
                GCD_cnt_tmp.push_back(GCD_cnt[j]);
            }
        }
        GCD = GCD_tmp;
        GCD_cnt = GCD_cnt_tmp;
    }
    
    std::cout << GCD[GCD.size() - 1] << std::endl;
    
    return 0;
}



Measured memory_bytes: 3832
def main():
    A, B = map(int, input().split())
    print(lcm(A, B))

def gcd(a, b):
    if a < b:
        tmp = b
        b = a
        a = tmp
        
    while a % b != 0:
        r = a % b
        a, b = b, r
        
    return b

def lcm(a, b):
    return int(a * b / gcd(a, b))
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define rep2(i, l, r) for(Int i = (Int)(l); i < (Int)(r); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

struct T {
   T(Int n_) : n(n_), xs(2*n,((Int)1<<31)-1), ls(2*n,0), rs(2*n,0) {
      rep2(i,n,2*n) {
         ls[i] = i-n;
         rs[i] = i-n+1;
      }
      for(Int i = n-1; i >= 1; --i) {
         ls[i] = ls[2*i];
         rs[i] = rs[2*i+1];
      }
   }
   Int n;
   std::vector<Int> xs;
   std::vector<Int> ls, rs;
   void update(Int i, Int x) {
      xs[n+i] = x;
      update2((n+i)/2);
   }
   void update2(Int i) {
      if( i == 0 ) return;
      xs[i] = std::min(xs[2*i], xs[2*i+1]);
      update2(i/2);
   }
   Int find(Int l, Int r, Int i = 1) {
      if( l <= ls[i] and rs[i] <= r ) return xs[i];
      if( rs[i] <= l or r <= ls[i] ) return ((Int)1<<31) - 1;
      return std::min(find(l,r,2*i),find(l,r,2*i+1));
   }
};

int main() {
   Int n, q;
   std::cin >> n >> q;
   T t(131072);
   rep(i,q) {
      Int c, x, y;
      std::cin >> c >> x >> y;
      if( c == 0 ) {
         t.update(x,y);
      }
      else {
         printf("%ld\n", t.find(x,y+1));
      }
   }
}



Measured memory_bytes: 8916
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	vector<int>v(3);
	rep(i, 3)cin >> v[i];
	SORT(v);
	cout << v[0] + v[1] << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ff first
#define ss second
#define pi pair<ll,ll>


int main(){
	
	ll n;
	cin>>n;
	
	map<string,ll>mp;
	string s;
	
	
	for(int i=0;i<n;i++){
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"]<<"\n";
	
		
	}



Measured memory_bytes: 3620
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long x = n % k;
        System.out.println(Math.min(x, k - x));
    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N, A, B;
vector<int> P;

int main()
{
    cin >> N >> A >> B;
    P.resize(N);
    cin >> P;

    vector<int> ans(3);
    for (auto v : P)
    {
        if (v <= A) ans[0]++;
        else if (v <= B) ans[1]++;
        else ans[2]++;
    }
    cout << *min_element(ans.begin(), ans.end()) << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> map;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        map[A[i]] ++;
    }

    int first = 0;
    int second = 0;

    for (int i = 0; i < N; i++) {
        first = max(first, A[i]);
    }

    for (int i = 0; i < N; i++) {
        if (A[i] < first) second = max(second, A[i]);
    }



    for (int i = 0; i < N; i++) {
        if (A[i] == first && map[A[i]] == 1) cout << second << endl;
        else cout << first << endl;
    }
    return 0;
}

Measured memory_bytes: 7936