akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

long long int A, B;

set<long long int> SA,SB;

set<long long int> S, T;

vector<long long int> V;

int C[1000006];
int D[10];
long long int VAL[10];
int p = 0;

int main(void) {

	cin >> A >> B;

	for (long long int i = 1; i*i <=A; i++) {
		if (A%i == 0) { SA.insert(i); SA.insert(A / i); }
	}

	for (long long int i = 1; i*i <= B; i++) {
		if (B%i == 0) { SB.insert(i); SB.insert(B / i); }
	}

	for (auto h : SA) {
		if (SB.count(h) > 0) { V.push_back(h); S.insert(h); }
	}


	T = S;
	for (auto h : S) {
		if (h > 1) {
			for (auto y : T) {
				if (y > h && y%h == 0) { T.erase(y); }
			}
		}
	}

	cout << T.size() << endl;

	
/*
	for (auto h : S) {
		if (h <= 1000000) { C[h] = 1; }
		else { D[p] = 1; VAL[p] = h; p++; }
	}

	for (auto h : S) {
		if (h <= 1000000 && h>1) {
			for (int j = 2; j*h <= 1000000; j++) { C[j*h] = 0; }
			for (int i = 0; i < p; i++) { if (VAL[i] % h == 0) { D[i] = 0; } }
		}
		else if(h>1000000){
			for (int i = 0; i <= p; i++) {
				if (VAL[i] == h) { continue; }
				if (VAL[i] % h == 0) { D[i] = 0; }
			}
		}
	}

	



	int ans = 0;
	for (int i = 1; i <= 1000000; i++) {
		if (C[i] == 1) { ans++; }
	}



	for (int i = 0; i < p; i++) { if (D[i] == 1) { ans++; } }

	cout << ans << endl;
	*/



	return 0;
}

Measured memory_bytes: 1536
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<bitset>
#include<random>
#include<cstdint>
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
ll inf=1<<21;
int main(){
      ll N;
      string s;
      ll q;
      cin>>N>>s>>q;
      rep0(ijfijeij,q){
            ll k;
            cin>>k;
            ll cntD=0;
            ll cntM=0;
            ll cntDM=0;
            ll ans=0;
            rep0(i,N){
                  if(s[i]=='D') cntD++;
                  if(s[i]=='M'){
                        cntM++;
                        cntDM+=cntD;
                  }
                  if(i>=k){
                        if(s[i-k]=='M'){
                              cntM--;
                        }
                        if(s[i-k]=='D'){
                              cntDM-=cntM;
                              cntD--;
                        }
                  }
                  if(s[i]=='C'){
                        ans+=cntDM;
                  }
            }
            cout<<ans<<endl;
      }

      return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

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


int main(){
    int n;  cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
        cin >> t[i];
    }
    string x;   cin >> x;
    int res = 0;
    bool state = false;
    for(int i = 0; i < n; i++){
        if(state){
            res += t[i];
        }
        if(x == s[i])   state = true;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n;
	string s,t;
	cin >> n;
	vector<string>w(n);
	for (int i = 0; i < n; i++)cin >> w[i];
	
	for (int i = 0; i < n-1; i++) {
		s = w[i];
		t = w[i + 1];
		if (s[s.length() - 1] != t[0] || count(w.begin(), w.end(), s) != 1)return cout << "No" << endl, 0;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int ct = 0;
  int a[3];

  scanf("%d", &ct);
  for(int i = 0; i < ct; i++) {
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    sort(a, a + 3);
    printf("%s\n", a[2] * a[2] == a[0] * a[0] + a[1] * a[1] ? "YES" : "NO");
  }
  return 0;
}

Measured memory_bytes: 1024
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;

  int n, m; rd(n, m);
  auto l=new int[](m), r=new int[](m), d=new int[](m);
  foreach(i; 0..m){
    rd(l[i], r[i], d[i]);
    l[i]--; r[i]--;
  }

  alias T=Tuple!(int, "to", long, "d");
  auto g=new T[][](n), rev=new T[][](n);
  foreach(i; 0..m){
    g[l[i]]~=T(r[i], d[i]);
    rev[r[i]]~=T(l[i], d[i]);
  }
  auto a=new long[](n), vis=new bool[](n);
  long dmin=0, dmax=0;
  bool fun(int cur, int pre=-1, long p=0){
    // writeln(cur);
    if(vis[cur]){
      if(a[cur]!=p) return false;
      else return true;
    }else{
      vis[cur]=true;
      a[cur]=p;
      dmin=min(dmin, p);
      dmax=max(dmax, p);
    }
    bool ret=true;
    foreach(e; g[cur]){
      if(e.to==pre) continue;
      ret&=fun(e.to, cur, p+e.d);
    }
    foreach(e; rev[cur]){
      if(e.to==pre) continue;
      ret&=fun(e.to, cur, p-e.d);
    }
    return ret;
  }
  foreach(i; 0..n)if(vis[i]==false){
    // writeln(i);
    dmin=dmax=0;
    if(fun(i)==false){writeln("No"); return;}
    if(dmax-dmin>1_000_000_000){writeln("No"); return;}
  }

  writeln("Yes");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}

Measured memory_bytes: 36604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  vector<string> S(h); rep(i, h) cin >> S[i];
  vector<string> ans(h, string(w, ' '));
  rep(i, h) rep(j, w) {
    if(S[i][j] == '#') {
      ans[i][j] = '#';
      continue;
    }
    int cnt = 0;
    for(int dx=-1; dx<=1; dx++) {
      for(int dy=-1; dy<=1; dy++) {
        if(dx == 0 && dy == 0) continue;
        int x = i + dx;
        int y = j + dy;
        if(x < 0 || x >= h || y < 0 || y >= w) continue;
        if(S[x][y] == '#') cnt++;
      }
    }
    ans[i][j] = char('0'+cnt);
  }
  rep(i, h) cout << ans[i] << endk;
  return 0;
}


Measured memory_bytes: 3652
#ABC-127-C
N, M = map(int, input().split())
L_list  = []
R_list = []
for _ in range(M):
    Li, Ri = map(int, input().split())
    L_list.append(Li)
    R_list.append(Ri)

max_L = max(L_list)
min_R = min(R_list)

if max_L > min_R:
    print(0)
else:
    print(min_R-max_L+1)


Measured memory_bytes: 11028
#include<stdio.h>
#include<string.h>

long gcd(int n, int m);
int main(void)
{
	int N, a[200001];
	int i;
	int count=0, flag=1, pre=0, error=0;
	scanf("%d", &N);
	for(i=1;i<=N;i++)
	{
		scanf("%d", &a[i]);
		if(a[i]==flag)
		{
			count=count+i-1-pre;
			pre=i;
			flag++;
			error=1;
		}
	}
	if(!error) printf("%d", -1);
	else printf("%d", count+N-pre);


	return 0;
}


Measured memory_bytes: 1024
A,B,C = map(int,input().split())
if A == 5:
    if B == 5:
        if C == 7:
            print("YES")
        else:
            print("NO")
    elif B == 7:
        if C == 5:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
elif A == 7:
    if B == 5 and C == 5:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    a, b = LI()
    if a <= b:
        print(a)
    else:
        print(a-1)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n = II()
    ans = []
    sosu = [2]
    i = 2
    while len(ans) != n:
        for k in sosu:
            if i % k == 0:
                i += 1
                break
        else:
            sosu.append(i)
            if i % 5 == 1:
                ans.append(i)
            i += 1
    for i in ans:
        print(i, end=" ")
    print()
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39152
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
    int a, b; cin>>a>>b;
  if(a<=0 && 0<=b) cout<<"Zero"<<endl;
  else if(a>0) cout<<"Positive"<<endl;
  else if((b-a+1)%2==0) cout<<"Positive"<<endl;
  else cout<<"Negative"<<endl;
    return 0;
}

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

string s;

int main(){
	cin >> s;
	for(int i=1;i<s.size();i++){
		if(s[i] == s[i-1]){
			cout << "Bad\n";
			return 0;
		}
	}
	cout << "Good\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

VI bin(int x, int n){
    VI ret(n);
    REP(i,n){
        ret[i] = x % 2;
        x /= 2;
    }
    return ret;
}

int count(int x){
    int ret = 0;
    while (x){
        ret += (x % 2);
        x /= 2;
    }
    return ret;
}

void make(int a, int b, int n, VI &ans){
    if (n == 1){
        if (a == 0){
            ans.push_back(0);
            ans.push_back(1);
        }else{
            ans.push_back(1);
            ans.push_back(0);
        }
        return;
    }
    if (a != 0){
        make(0, a ^ b, n, ans);
        REP(i,1<<n) ans[i] ^= a;
        return;
    }
    if (b & (1 << (n - 1))){
        VI tmp;
        make(0, 1, n - 1, ans);
        make(1, b - (1 << (n - 1)), n - 1, tmp);
        for (int x : tmp) ans.push_back(x + (1 << (n - 1)));
    }else{
        VI v1, v2;
        make(0, b, n - 1, v1);
        int p = v1[(1 << (n - 1)) - 2];
        make(p, b, n - 1, v2);
        REP(i,(1<<(n-1))-1) ans.push_back(v1[i]);
        for (int x : v2) ans.push_back(x + (1 << (n - 1)));
        ans.push_back(v1.back());
    }
}

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

    VI ba = bin(a, n), bb = bin(b, n);
    int d = 0;
    REP(i,n) d += (ba[i] != bb[i]);

    if (d % 2 == 0){
        cout << "NO" << endl;
        return 0;
    }

    VI ans;
    make(a, b, n, ans);
    cout << "YES" << endl;
    for (int x : ans) printf("%d ", x);
    cout << endl;

    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,string>> input(m);
  for(int i=0;i<m;i++){
    int p;
    string res;
    cin >> p >> res;
    --p;
    input.at(i) = make_pair(p,res);
  }
  
  vector<int> wa(n,0);
  vector<bool> ac(n,false);
  
  for(int i=0;i<m;i++){
    int p = input.at(i).first;
    string res = input.at(i).second;
    if(!ac.at(p) && res == "WA"){
      wa.at(p)++;
    }else if(res == "AC"){
      ac.at(p) = true;
    }
  }
  
  int acnum=0;
  int wanum=0;
  for(int i=0;i<n;i++){
    if(ac.at(i)){
      acnum++;
      wanum += wa.at(i);
    }
  }
  
  cout << acnum << " " << wanum << endl;
  
  return(0);
}

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

using ll = long long;
constexpr ll MOD = 998244353;

ll a[3030], dp[3030][3][6060];

int main() {
	int n, s;
	scanf("%d %d", &n, &s);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= s; ++j) {
			(dp[i + 1][0][j] += dp[i][0][j]) %= MOD;
			(dp[i + 1][1][j] += dp[i][0][j] + dp[i][1][j]) %= MOD;
			(dp[i + 1][2][j] += dp[i][0][j] + dp[i][1][j] + dp[i][2][j]) %= MOD;
			(dp[i + 1][1][j + a[i]] += dp[i][0][j] + dp[i][1][j]) %= MOD;
			(dp[i + 1][2][j + a[i]] += dp[i][0][j] + dp[i][1][j]) %= MOD;
		}
	}
	printf("%d", dp[n][2][s]);
	return 0;
}

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

const int C = 40;
const int N = 10000 / C + 10;
vector<int> ax[N][N];
vector<int> ay[N][N];

int main()
{
	while ( true )
	{
		for ( int i=0; i<N; i++ )
		for ( int j=0; j<N; j++ )
			ax[i][j].clear(),
			ay[i][j].clear();

		int AN, BN, R;
		cin >> AN >> BN >> R;
		if ( AN == 0  &&  BN == 0 )
			break;

		for ( int i=0; i<AN; i++ )
		{
			int x, y;
			cin >> x >> y;
			ax[x/C+1][y/C+1].push_back( x );
			ay[x/C+1][y/C+1].push_back( y );
		}

		long long ans = 0;

		for ( int i=0; i<BN; i++ )
		{
			int x, y;
			cin >> x >> y;

			for ( int tx=x/C; tx<x/C+3; tx++ )
			for ( int ty=y/C; ty<y/C+3; ty++ )
			for ( int j=0; j<(int)ax[tx][ty].size(); j++ )
			{
				int cx = ax[tx][ty][j];
				int cy = ay[tx][ty][j];

				if ( (x-cx)*(x-cx) + (y-cy)*(y-cy) <= 16*R*R )
					ans++;
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 4964
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }

    let a = a - 1;
    let b = b - 1;
    println!("{}", b / a + (if b % a != 0 { 1 } else {0}));
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**9)
class UnionFind:#
    def __init__(self,N):#親のリスト、ランク(部分木の高さ)の初期化
        self.parent=[i for i in range(N)]
        self.rank=[0]*N
    def root(self,a):#根を返す
        if self.parent[a]==a:
            return a
        else:
            self.parent[a]=self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):#同じ木に属するか(根が同じか)
        return self.root(a)==self.root(b)
    def unite(self,a,b):#木をつなげる
        ra=self.root(a)
        rb=self.root(b)
        if ra==rb:
            return
        if self.rank[ra]<self.rank[rb]:
            self.parent[ra]=rb
        else:
            self.parent[rb]=ra
            if self.rank[ra]==self.rank[rb]:
                self.rank[ra]+=1
N,M,K=map(int,input().split())
uf=UnionFind(N)
lfriend=[0 for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    uf.unite(a-1,b-1)
    lfriend[a-1]+=1
    lfriend[b-1]+=1
lnfam=[0 for i in range(N)]
for i in range(N):
    rt=uf.root(i)
    lnfam[rt]+=1
lnblock=[0 for i in range(N)]
for i in range(K):
    c,d=map(int,input().split())
    if uf.root(c-1)==uf.root(d-1):
        lnblock[c-1]+=1
        lnblock[d-1]+=1
for i in range(N):
    print(lnfam[uf.root(i)]-lfriend[i]-lnblock[i]-1,end=" ")
print()
#print("lfriend",lfriend)


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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1000000007;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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




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

int ceil(int a, int b){
    if(a % b == 0) return a/b;
    else return a/b + 1;
}

signed main(){

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

    
    int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;


    double ans = -1;
    int s = 0;
    int sugar = 0;

    rep(i,0,31){
        rep(j,0,31){
            int water = i * a + j * b;
            if(water * 100 <= f){
                rep(k,0,ceil(f - water * 100,c) + 1){
                    if(water * 100 + k * c <= f && water * e >= k * c){
                        int dnum = min((f - water * 100 - k * c) / d, (water * e - k * c)/ d);
                        int sugarsum = k * c + dnum * d;
                        if(water == 0) continue;
                        int beaker = water * 100 + sugarsum;
                        if(ans < (double)sugarsum / (double)beaker){

                            ans = (double)sugarsum / (double)beaker;
                            s = beaker;
                            sugar = sugarsum;
                        }
                    }
                }
            }
        }
    }
   
   
   
    cout << s << " " << sugar << endl;






   








    
    












    

    








    






    


    
    

    
    






    




    

    





    

   




    

    

    



    
    



    







    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        
        int n,k;
        cin>>n>>k;
        ll ans=0;
        ll ar[n];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
        }
        sort(ar,ar+n);
        int i=0;
        while(k--)
        {
            ans+=ar[i];
            i++;
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e12;
int N = 5 + 1e5;


int main()
{
	int n; cin >> n;
	vector<int> aa(n);
	rep(i, n) cin >> aa[i];
	vector<int> bb(n);
	bb = aa;
	sort(bb.rbegin(), bb.rend());
	rep(i, n) {
		if (aa[i] == bb[0]) cout << bb[1] << endl;
		else cout << bb[0] << endl;
	}
}

Measured memory_bytes: 4752
import sys
from collections import deque

input = sys.stdin.readline


def bfs(S, sh, sw, dist):
    dist[sh][sw] = 0
    queue = deque([(sh, sw)])
    while queue:
        h, w = queue.popleft()
        for i, j in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            y, x = h + i, w + j
            if S[y][x] == "#":
                continue
            if dist[y][x] == -1:
                dist[y][x] = dist[h][w] + 1
                queue.append((y, x))


def main():
    H, W = map(int, input().split())
    S = [None] * (H + 2)
    S[0] = S[-1] = "#" * (W + 2)
    for i in range(1, H + 1):
        S[i] = "".join(["#", input().rstrip(), "#"])

    ans = 0
    for sh in range(1, H + 1):
        for sw in range(1, W + 1):
            if S[sh][sw] == "#":
                continue
            dist = [[-1] * (W + 2) for _ in range(H + 2)]
            bfs(S, sh, sw, dist)
            max_dist = max(map(max, dist))
            ans = max(ans, max_dist)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9388
z[4000],*a=z,*b=z+2000,m,i,j,t,u;main(n){for(;m=scanf("%d",&n)-++n;m=!printf("%d\n",m))for(i=n;i--;j=a,a=b,b=j)for(j=n;j--;t>m?m=t:0)t=b[j]=n+~i&&getchar()>45?1+fmin(u=a[j],t<u?t:u):0;}

Measured memory_bytes: 0
from math import log
def solve(N, K):
    if N == 0:
        return 0
    if N == 1:
        if K == 1:
            return 1
        return 0
    num = int(log(N, 10))
    if K == 1:
        res = 9 * num + N//(10**num)
        return res
    if K == 2:
        res = 9 ** 2 * (num*(num-1))//2 
        res += (N//(10**num) - 1)*num*9
        res += solve(N - N//(10**num)*(10**num), 1)
        return res
    if K == 3:
        res = 9 ** 3 * (num*(num-1)*(num-2))//6
        res += (N//(10**num) - 1)*(num*(num-1))*81//2
        res += solve(N - N//(10**num)*(10**num), 2)
        return res
N = int(input())
K = int(input())
print(solve(N, K))

Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,n) for(ll i=0; i<int(n); ++i)
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
typedef long long ll;

void solve()
{
    int n;
    cin>>n;
    vector<pii> v(n);
    For(i,n) cin>>v[i].ff>>v[i].ss;
    bool fg=false;
    for(int i=2; i<n; i++)
    {
        if(v[i-2].ff==v[i-2].ss && v[i-1].ff==v[i-1].ss && v[i].ff==v[i].ss)
        {
            fg = true;
        }
    }
    cout<<(fg?"Yes":"No")<<endl;
}

int main(){
    optimize();
    ll T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3508
/*
 * Matheus Oliveira
 * 13:53:14 02/04/2019
 * 122d.cpp
*/

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

#define EPS
#define INF
#define MAXN
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, ini, fim) printf("%s: ", #x); for(int i = ini; i <= fim; i++) printf("%d%c", x[i], (i == fim) ? '\n' : ' ');

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;

int n;
map< pis, ll > dp;

string base = "ACGT";
const ll mod = 1000000007;

ll add(ll a, ll b) {
	return ((a%mod) + (b%mod)) % mod;
}

bool valid(string str) {
	string aux;

	if( str.find("AGC") == -1 ) {
		for(int i = 1; i < 4; i++) {
			aux = str;
			swap(aux[i], aux[i-1]);
			if( aux.find("AGC") != -1 ) return false;
		}
		return true;
	}
	
	return false;
}

ll solve(int pos, string prev) {
	if(pos >= n) return 1;
	if( dp.count( mp(pos, prev) ) ) return dp[ mp(pos, prev) ];

	ll ans = 0;
	string aux;

	for(int i = 0; i < 4; i++) {
		aux = prev;
		aux += base[i];
		if( valid(aux) ) ans = add(ans, solve(pos+1, aux.substr(1, 3)));
	}

	return dp[ mp(pos, prev) ] = ans;
}

int main() {
	scanf("%d", &n);
	printf("%lld\n", solve(0, "ZZZ"));
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main(void){
    string o,e;
    cin>>o>>e;
    int i=0;
    while(i<max(o.size(),e.size())){
        if(i<o.size()){
            cout<<o[i];
        }
        if(i<e.size()){
            cout<<e[i];
        }
        i++;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
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>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    vector <ll> arr(n+1);
    for (int z=0;z<n-1;z++){
        ll temp;
        cin >> temp;
        arr[temp]++;
    }
    for (int z=1;z<=n;z++){
        cout << arr[z] << endl;
    }
}

Measured memory_bytes: 4784
def main():
    _ = input()
    H = [int(x) for x in input().split()]
    ans = 0
    now = 0
    old = H[0]
    for h in H[1:]:
        if old >= h:
            now += 1
            ans = now if now > ans else ans
        else: 
            now = 0
        old = h
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14224
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
const ll inf = 1ll<<50;
ll f[N] , x[N] , q[N];
int n , T , E , l , r;

ll Dp(int i,int j){
    return (x[j - 1] - x[i]) * 3 + max(0ll , T - 2 * (x[j - 1] - x[i])) + x[j] - x[j - 1] + f[j];
}

int main(){
    scanf("%d%d%d",&n,&E,&T);
    rep(i,1,n+1) scanf("%lld",x + i);
    x[n + 1] = E;
    ll A = inf;
    q[r++] = n + 1;
    for(int i=n;i>=1;--i){
        f[i] = f[i + 1] + x[i + 1] - x[i] + T;
        while(2 * (x[q[l] - 1] - x[i]) >= T) A = min(A , x[q[l] - 1] * 2 + x[q[l]] + f[q[l]]) , ++l;
        if(l < r) f[i] = min(f[i] , Dp(i , q[l]));
        f[i] = min(f[i] , A - x[i] * 3);
        while(l < r && Dp(i , i) <= Dp(i , q[r - 1])) --r;
        q[r++] = i;
    }
    printf("%lld\n",x[1] + f[1]);
    return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n];
        for (int i=0;i<n;i++){
            a[i] = scan.nextInt();
        }

        Arrays.sort(a);
        long min = find(a[0],a[1]);
        for (int i=2;i<n;i++){
            min = find(a[i],min);
        }

        System.out.println(min);
    }

    static long find(long a, long b){
        if (a==b){
            return a;
        }

        while (b > 0){
            long remain = (long) a%b;
            a = b;
            b = remain;
        }
        return a;
    }
}

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

int main() {
  int s;
  cin>>s;
  if(s==2){
    cout<<"4"<< endl;
    return 0;
  }
  vector<int>A(1000001);
  A.at(0)=s;
  for(int i=0;i<1000000;i++){
    if(A.at(i)%2==0){
      A.at(i+1)=A.at(i)/2;
    }
    else{
      A.at(i+1)=3*A.at(i)+1;
    }
  }
  int b=0;
  for(int i=0;i<1000001;i++){
    for(int j=0;j<i;j++){
      if(A.at(i)==A.at(j)){
        cout<<i+1<< endl;
        return 0;
      }
    }
  }
}

      

    


Measured memory_bytes: 4096
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a + b + c == 17 && a*b*c == 5 * 7 * 5)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

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

int main()
{
	int n , k;
		cin >> n >> k;
	int b;
	int c = 1;
	int z;
	int a = n;
	
	for ( a ; a > 0 ; a--)
	{
		b = c + a*k;
		
		if ( b >= c*2 + (a - 1)*k)
			z = c*2 + (a - 1)*k;
		else
			break;	
		
		c *= 2;
	}
	cout << z;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class A {
public:
	void solve(istream& in, ostream& out) {
        int a, b, h;
        in >> a >> b >> h;
        out << ((a + b) * h / 2) << endl;
	}
};

int main() {
	A solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;

ll lcm(ll a,ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    int ans = 0;
    for (int i = 0; i < N;i++)
    {
        cin >> P[i];
    }
    for (int i = 1; i < N-1;i++)
    {
        if(P[i-1] < P[i] && P[i] < P[i+1] || P[i+1] < P[i] && P[i] < P[i-1]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()

    a = []
    direct = [[True for i in range(n)]for j in range(n)]

    for i in range(n):
        a.append(li())


    for k in range(n):
        for i in range(n):
            for j in range(n):
                if a[i][j] > a[i][k] + a[k][j]:
                    print(-1)
                    return
                
                if i==k or k == j:
                    continue
                if a[i][j] == a[i][k] + a[k][j]:
                    direct[i][j] = False
    
    ans = 0
    for i in range(n):
        for j in range(n):
            if direct[i][j]:
                ans += a[i][j]
    print(ans//2)


main()

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

using namespace std;


int main() {
    string s;
    int w;
    cin >> s >> w;
    string ans = "";
    for(int i = 0; i < s.size(); i++) {
        if(i % w == 0) {
            ans += s[i];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
 
using namespace std;
 
int main() {
  int N,K;
  string S;
  vector<int> v;
  cin>>N>>K>>S;
  char now='1';
  int cnt=0;
  for(int i=0;i<N;i++){
    if(now==S[i]){
      cnt++;
    }else{
      v.push_back(cnt);
      cnt=1;
      now=S[i];
    }
  }
  if(cnt!=0)v.push_back(cnt);
  if(now=='0')v.push_back(0);

  int ans=0;
  if(2*K+1>=v.size()){
    ans=N;
  }else{
    vector<int>sum(v.size());
    sum[0]=v[0];
    for(int i=1;i<v.size();i++){
      sum[i]=sum[i-1]+v[i];
    }
    for(int i=0;2*K+i<v.size();i+=2){
      if(i==0){
        ans=max(ans,sum[2*K+i]);
      }else{
        ans=max(ans,sum[2*K+i]-sum[i-1]);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl "\n"
#define INF 1000000000
#define MOD 1000000007

void solve() {
    int n,r = 0,ans = 0;
    string s;
    cin >> n >> s;
    rep(i,0,sz(s)) {
        if (s[i] == 'R') {
            ++r;
        }
    }
    rep(i,0,r) {
        if (s[i] == 'W') {
            ++ans;
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3784
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define IREP(i, v) for(auto i = (v).begin(); i != (v).end(); ++i)
#define IRREP(i, v) for(auto i = (v).rbegin(); i != (v).rend(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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


int main(){
    int n; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    ll ans(LLONG_MAX);
    REP(s, 2){
        ll sum(0);
        ll cnt(0);
        REP(i, n){
            int sgn = (s + i) % 2 * 2 - 1;
            sum += a[i];
            if(sum / sgn <= 0){
                cnt += abs(sum - sgn);
                sum = sgn;
            }
        }
       chmin(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct ban
{
    int l, r, x;
};

int n, m;
ban a[N];

vector<int> v[N];

long long t[N * 4];
long long laz[N * 4];

void shi(int pos)
{
    t[pos * 2] += laz[pos];
    laz[pos * 2] += laz[pos];
    t[pos * 2 + 1] += laz[pos];
    laz[pos * 2 + 1] += laz[pos];
    laz[pos] = 0;
}

void ubd(int tl, int tr, int l, int r, long long y, int pos)
{
    if (tl == l && tr == r)
    {
        t[pos] += y;
        laz[pos] += y;
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    if (r <= m)
        ubd(tl, m, l, r, y, pos * 2);
    else if (l > m)
        ubd(m + 1, tr, l, r, y, pos * 2 + 1);
    else
    {
        ubd(tl, m, l, m, y, pos * 2);
        ubd(m + 1, tr, m + 1, r, y, pos * 2 + 1);
    }
    t[pos] = max(t[pos * 2], t[pos * 2 + 1]);
}

long long qry(int tl, int tr, int l, int r, int pos)
{
    if (tl == l && tr == r)
        return t[pos];
    int m = (tl + tr) / 2;
    if (r <= m)
        return qry(tl, m, l, r, pos * 2);
    if (l > m)
        return qry(m + 1, tr, l, r, pos * 2 + 1);
    return max(qry(tl, m, l, m, pos * 2),
     qry(m + 1, tr, m + 1, r, pos * 2 + 1));
}

long long dp[N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i)
    {
        scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].x);
    }
    for (int i = 1; i <= m; ++i)
    {
        v[a[i].l].push_back(i);
        v[a[i].r + 1].push_back(-i);
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < v[i].size(); ++j)
        {
            int x = v[i][j];
            if (x > 0)
            {
                ubd(0, n, 0, a[x].l - 1, a[x].x, 1);
            }
            else
            {
                ubd(0, n, 0, a[-x].l - 1, -a[-x].x, 1);
            }
        }
        dp[i] = qry(0, n, 0, i - 1, 1);
        ubd(0, n, i, i, dp[i], 1);
    }
    long long ans = 0;
    for (int i = 0; i <= n; ++i)
        ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 MOD = 1000000007;

map<long long, long long> primeFact(long long n) {
    map<long long, long long> prime;
    for(long long i = 2; i * i <= n; i++) {
        long long cnt = 0;
        while(n % i == 0) {
            cnt++;
            n /= i;
        }
        if(cnt) prime[i] = cnt;
    }
    if(n > 1) prime[n]++;
    return prime;
}

long long powMod(long long x, long long n, long long mod = 1000000007) {
    long long res = 1LL;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return res;
}

long long invMod(long long n, long long mod = 1000000007) {
    return powMod(n, mod - 2, mod);
}

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    map<int64, int64> ma;
    for(int i = 0; i < N; ++i) {
        for(auto &p : primeFact(A[i])) {
            int64 n, k; tie(n, k) = p;
            ma[n] = max(ma[n], k);
        }
    }
    int64 L = 1LL;
    for(auto &p : ma) {
        int64 n, k; tie(n, k) = p;
        L = L * powMod(n, k) % MOD;
    }
    int64 ans = 0;
    for(int i = 0; i < N; ++i) {
        ans += L * invMod(A[i]);
        ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 896
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

//Greatest Common Divisor 最大公約数
long long int gcd(long long int m,long long int n){
	//引数に０がある場合は０を返す
	/*if((0==m)||(0==n)) return 0;
	
	//ユークリッドの互除法
	while(m!=n){
		if(m>n) m=m-n;
		else n=n-m;
	}*/
	return __gcd(m,n);
}

//Least Common Multiple 最小公倍数
long long int lcm(long long int m,long long int n){
	//引数に０がある場合は０を返す
	if((0==m)||(0==n)) return 0;

	//lcm=m*n/gcd(m,n) ⇔ m*n==gcd*lcm
	return ((m/gcd(m,n))*n); 
}

int main(){
    ios::sync_with_stdio(false);
    long long int n,l;
    cin>>n;
    vector<long long int>a(n);
    for(long long int i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<a[0];
        return 0;
    }
    for(long long int i=0;i<n-1;i++){
        l=lcm(a[i],a[i+1]);
        a[i+1]=l;
    }
    cout<<l;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{   char s[13];
    scanf("%s",s);
    for(int i=0;i<4;i++)
    printf("%c",s[i]);
    printf(" ");
    for(int i=4;i<12;i++)
    printf("%c",s[i]);
 	printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
template<typename T1,typename T2>std::istream& operator>>(std::istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a){out<<a.fr<<" "<<a.sc;return out;}

const int N=4e6+5;
#define NCR
#define PRIME	M
int pw(int a,int b,int p){
	if(b==0)return 1;
	int t=pw(a,b/2,p);
	if(b%2)return (((a*t)%p)*t)%p;
	else return ((t*t)%p);
}
int fact[N],invfact[N];
void init(){
	int p=PRIME;
	fact[0]=1;
	int i;
	for(i=1;i<N;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=pw(fact[i],p-2,p);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
int ncr(int n,int r){
	return (((fact[n]*invfact[r])%PRIME)*invfact[n-r])%PRIME;
}

int f(int r1,int r2,int k){
	int ans= ncr(k+1+r2,k) - ncr(k+r1,k)+M;
	ans%=M;
	return ans;
}

void solve(){
	int r1,r2,c1,c2;
	cin>>r1>>c1>>r2>>c2;
	int ans=f(r1,r2,c2+1);
	ans = ans - f(r1,r2,c1);
	ans+=M;
	ans%=M;
	cout<<ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 62720
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    int A,B,C;
    cin >> A >> B >> C;
    string out = "bust";
    if(A+B+C <= 21) out ="win";
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
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-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

// 012
//0012
//1101
//2210

int n;

int main(){
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++){
		char c;
		cin>>c;
		a[i]=c-'0';
	}
	while(1){
		if(a.size()==1) break;
		vi b(n-1);
		int mx=0;
		for(int i=0;i<n-1;i++){
			b[i]=abs(a[i]-a[i+1]);
			mx=max(mx,b[i]);
		}
		a=b;
		n--;
		if(mx<=2) break;
	}
	if(n==1) cout<<a[0]<<endl;
	else{
		int t1=0,t2=0;
		bool flag=0;
		for(int i=0;i<n;i++) if(a[i]){
			int x=n-1,y=i,B=1;
			while(x){
				if(x%2<y%2) B=0;
				x/=2;
				y/=2;
			}
			if(a[i]==1) (t1+=B)%=2,flag=1;
			else (t2+=B)%=2;
		}
		cout<<(flag?t1:t2*2)<<endl;
	}
}

Measured memory_bytes: 8064
#whats the difference with max(st1,st2)
def maxs(s1, s2):
    if len(s1) > len(s2): return s1
    elif len(s1) < len(s2): return s2
        
    if s1 > s2: return s1
    else: return s2

def nozero(st):
    return st.lstrip('0')

while True:
    Map=[]
    w,h=map(int,raw_input().split(' '))
    if (w==0 and h==0):break
    for i in range(h):
        Map.append(raw_input())

    res=''
    #always init 2d list this way
    dp=[['' for __ in range(w)] for __ in range(h)]

    for i in range(h):
        for j in range(w):
            if(Map[i][j].isalpha()):
                continue

            if j>0:
                dp[i][j]=maxs(dp[i][j],dp[i][j-1])

            if i>0:
                dp[i][j]=maxs(dp[i][j],dp[i-1][j])
                    
            dp[i][j]+=Map[i][j]
            if ('0' in dp[i][j]):dp[i][j]=nozero(dp[i][j])
            if dp[i][j] is '0':dp[i][j]=''
            res=maxs(res,dp[i][j])


    print res

Measured memory_bytes: 6276