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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    stack < int > st ;
    string s ;
    cin >> s ;

    st.push ( s[0] - '0' ) ;
    int ans = 0 ;
    int n = s.size() ;

    for ( int i = 1 ; i < n ; i ++  )
    {
        int a = s[i] - '0' ;
        if ( st.size() && st.top() ^ a == 1 )
            ans += 2 , st.pop() ;
        else
            st.push ( a ) ;
    }

    cout << ans ; line
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <string>
#define NMAX 100000
using namespace std;

int main(){
    string str1,str2,S;
    int Ssize;
    cin >> S;


    Ssize = S.size();
    int count=1;
    int ans = 1;

    str1 = S.at(0);
    str2 = S.at(1);
     while(count<Ssize){
 
         if(str1 != str2){
            str1 = str2;
            str2.clear();
            ans++;
         }
            count++;
            str2 = str2+S.substr(count,1); 

    } 
    cout << ans << endl;

}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vec<int, 2> g(N);
    for (int i = 0; i < M; i++) {
      int x, y;
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    if (M == N - 1) {
      cout << 0 << endl;
      continue;
    }
    vector<int> used(N, 0);
    int edges = (N - 1) - M;
    int ord = 2 * edges;
    ll res = 0;
    vector<ll> extra;
    for (int i = 0; i < N; i++) {
      if (used[i]) continue;
      queue<int> q;
      used[i] = true;
      q.push(i);
      vector<ll> sub;
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        sub.push_back(a[v]);
        for (int u : g[v]) {
          if (!used[u]) {
            used[u] = true;
            q.push(u);
          }
        }
      }
      sort(sub.begin(), sub.end());
      res += sub[0];
      --ord;
      extra.insert(extra.end(), sub.begin() + 1, sub.end());
    }
    if (ord > extra.size()) {
      cout << "Impossible" << endl;
      continue;
    }
    sort(extra.begin(), extra.end());
    for (int i = 0; i < ord; i++) {
      res += extra[i];
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 8676
N ,K = map(int,input().split())
NL = [0]*N
for i in range(K):
    K = input()
    AL = list(map(int,input().split()))
    for j in AL:
        NL[j-1] += 1
ans = 0
for i in NL:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 67584
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define p 1000000007
int Plus(int x,int y){return x+y>=p?x+y-p:x+y;}
int Mul(int x,int y){return 1ll*x*y%p;}
int f[55][55][2550];
int main()
{
	f[0][0][0]=1;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
			for(int k=2*j;k<=m;++k)
			{
				f[i][j][k]=Plus(f[i][j][k],Mul(j+1,Mul(j+1,f[i-1][j+1][k-2*j])));
				f[i][j][k]=Plus(f[i][j][k],Mul(2*j+1,f[i-1][j][k-2*j]));
				if(j)
					f[i][j][k]=Plus(f[i][j][k],f[i-1][j-1][k-2*j]);
			}
	cout<<f[n][0][m];
	return 0;
}

Measured memory_bytes: 27008
#include <stdio.h>
#include <math.h>

int discriminateCircle(double xa, double ya, double ra, double xb, double yb, double rb) {
  double d = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
  double r1 = ra, r2 = rb;

  if (ra < rb) {
    r1 = rb;
    r2 = ra;
  }

  if (d > ra + rb) return 0;
  else if (d == r1 + r2 || d == r1 - r2 || r1 - r2 < d && d < r1 + r2) return 1;
  else {
    if (ra > rb) return 2;
    else return -2;
  }
}

int main(void) {
  int n;
  double xa, ya, ra, xb, yb, rb;

  scanf("%d", &n);

  while (n--) {
    scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);

    printf("%d\n", discriminateCircle(xa, ya, ra, xb, yb, rb));
  }

  return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
static const long long INF = 1e18;

string a, b;
vll bs;
ll n;
vll rpos, lpos;
void constructPos(void) {
    repi(i, 1, 6*n) 
        chmin(lpos[i%n], b[i%n] == '1' ? 0 : lpos[(i-1)%n] + 1);
    for (ll i = 6*n; i>=1; i--) 
        chmin(rpos[i%n], b[i%n] == '1' ? 0 : rpos[(i+1)%n] + 1);
}

// 右にd回移動する時、何回移動しなければならないか
ll calc(ll d) {
    ll flips = 0;
    vector<P> lr;
    rep(i, n) {
        if (a[i] != b[i+d]) {
            flips++;
            // b[i, i+d]に1がないといけない, b[i, i+d+1)に1がないといけない
            if (bs[i+d+1] - bs[i]) {
                // 1があるのでどうでもいい
                continue;
            } else {
                // 1がないので左右どちらかに寄り道しないといけない
                lr.pb(P(lpos[i], rpos[(i+d)%n])); 
            }
        }
    }
    if (!lr.size())
        return d + flips;

    sort(all(lr));
    vll rmax(lr.size()+1, -INF); // max r[i, r.size())
    for (ll i = lr.size()-1; i >= 0; i--) 
        rmax[i] = max(rmax[i+1], lr[i].se);

    ll ret = INF;
    rep(i, lr.size()+1) {
        if (!i) 
            chmin(ret, rmax[0]);
        else if (i == lr.size())
            chmin(ret, lr[lr.size()-1].fi);
        else
            chmin(ret, lr[i-1].fi + rmax[i]);
    }

    return d + flips + ret * 2;
}

ll solve(void) {
    rpos = lpos = vll(n, INF);
    bs = vll(b.size()+1);
    rep(i, b.size()) bs[i+1] = bs[i] + b[i] - '0'; 

    ll ret = INF;
    constructPos();
    rep(i, rpos.size()) { assert(rpos[i] != INF); }
    rep(i, lpos.size()) { assert(lpos[i] != INF); }
    rep(d, 2*n) chmin(ret, calc(d));

    return ret;
}

int main(void) {
    cin >> a >> b;
    n = a.size();
    ll af = 1, bf = 1;
    rep(i, n) af &= a[i] == '0', bf &= b[i] == '0';
    if (bf == 1) {
        if (af == 1) {
            cout << 0 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    a += a; a += a;
    b += b; b += b;

    ll ret = INF;
    chmin(ret, solve());
    reverse(all(a));
    reverse(all(b));
    chmin(ret, solve());
    
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

        int num = N;
        int sum = 0;
        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }

        if (N % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 22484
# https://atcoder.jp/contests/abc076/tasks/abc076_c
def solve(s, t):
    sl = len(s)
    tl = len(t)
    for i in range(sl-tl, -1, -1):
        for j, k in zip(range(i, i+tl), range(tl)):
            if s[j] == t[k] or s[j] == '?':
                if k == tl-1:
                    return (s[:i]+t+s[i+tl:]).replace('?', 'a')
            else:
                break

    return 'UNRESTORABLE'


if __name__ == '__main__':
    s = input()
    t = input()
    print(solve(s, t))


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n, k, q;
    cin >> n >> k >> q;
    vector<ll> v(n+1, 0);
    for(ll i = 0; i < q; i++)
    {

        ll x;
        cin >> x;
        v[x]++;
    }
    for(ll i = 1; i <= n; i++)
    {

        v[i]=-(q-v[i])+k;
    }
    for(ll i = 1; i <= n; i++)
    {

        if(v[i]>0) cout << "Yes\n";
        else cout << "No\n";
    }
}


Measured memory_bytes: 1408
s = input()
ans = 0
a = 0
b = False
for i in range(len(s)):
	if s[i] == "A":
		if b:
			a = 0
		a += 1
		b = False
	elif s[i] == "B":
		if b:
			a = 0
		b = True
	else:
		if b:
			ans += a
		else:
			a = 0
		b = False
print(ans)

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

using namespace std;

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

    int h, w;
    cin >> h >> w;
    vector<string> ss(h);
    for (int i = 0; i < h; i++) cin >> ss[i];

    vector<pair<int, int>> ps;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (ss[i][j] == 'B') ps.emplace_back(i, j);
        }
    }
    int nax = 0;
    for (auto &a : ps) {
        for (auto &b : ps) {
            nax = max(nax, abs(a.first - b.first) + abs(a.second - b.second));
        }
    }
    cout << nax << endl;
}


Measured memory_bytes: 3256
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int N = 3;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println((a+b)%24);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<cstdlib>
#include<typeinfo>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
    string str;
    ll K;
    cin >> str >> K;
    int i,j;
    i=0;
    while(i<str.size()){
        j=stoi(str.substr(i,1));
        if(j!=1){
          cout << j <<endl;
          return 0;
        }else{
          if(i==K-1){
              cout << 1 << endl;
              return 0;
          }
        }
        i++;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int N,K;
 cin >> N >> K;
 int l[60];
 for(int i = 0; i < N; i++){
   cin >> l[i];
 }
 sort(l, l + N);
 reverse(l, l + N );
 int sum = 0;
 for(int i = 0; i < K; i++){
   sum += l[i];
 }
 cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

bool intersect(int x1, int y1, int r1, int x2, int y2, int r2) {
	x1 -= x2;
	y1 -= y2;
	r1 += r2;
	return x1 * x1 + y1 * y1 < r1 * r1;
}

void solve() {
	int n; cin >> n; if (n == 0) exit(0);
	vector<int> x(n), y(n), r(n), c(n);
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i] >> c[i], c[i]--;
	vector<vector<bool>> bad(n, vector<bool>(n));
	for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
		if (intersect(x[i], y[i], r[i], x[j], y[j], r[j])) {
			bad[j][i] = true;
		}
	}
	vector<bool> dp(1 << n);
	dp[(1 << n) - 1] = true;
	int res = 0;
	for (int S = (1 << n) - 1; S >= 0; S--) {
		if (!dp[S]) continue;
		vector<int> v;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (S >> i & 1) {
				v.emplace_back(i);
			}
			else cnt++;
		}
		for (int i = 0; i < v.size(); i++) for (int j = i + 1; j < v.size(); j++) {
			int p = v[i], q = v[j];
			if (c[p] != c[q]) continue;
			int nS = S - (1 << p) - (1 << q);
			bool ok = true;
			for (int k = 0; k < j; k++) {
				if (k != i and bad[p][v[k]]) ok = false;
				if (k != j and bad[q][v[k]]) ok = false;
			}
			if (ok) dp[nS] = true;
		}
		chmax(res, cnt);
	}
	cout << res << "\n";
}
int main()
{

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

	int kkt = 89;
	while (kkt) {
		solve();
	}
}




Measured memory_bytes: 5120
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var (
		n   int
		err error
	)
	if sc.Scan() {
		n, err = strconv.Atoi(sc.Text())
		if err != nil {
			panic(err)
		}
	}

	list := make([]int, n)
	if sc.Scan() {
		splited := strings.Split(sc.Text(), " ")
		for i, v := range splited {
			vv, err := strconv.Atoi(v)
			if err != nil {
				panic(err)
			}

			list[i] = vv
		}
	}

	cnt, sorted := bubbleSort(list)

	s := ""
	for _, ss := range sorted {
		s = s + strconv.Itoa(ss) + " "
	}
	s = strings.TrimRight(s, " ")

	fmt.Println(s)
	fmt.Println(cnt)
}

func bubbleSort(list []int) (int, []int) {
	cnt := 0
	for i := 0; i < len(list); i++ {
		for j := len(list) - 1; j > i; j-- {
			if list[j-1] > list[j] {
				tmp := list[j-1]
				list[j-1] = list[j]
				list[j] = tmp
				cnt++
			}
		}
	}

	return cnt, list
}



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

using namespace std;

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

    vector<int> a(N);
    vector<pair<int, int>> b(N);
    int sum = 0;
    for(int i = 0; i < N; i++) {
        a[i] = L+i;
        sum += a[i];
    }

    for(int i = 0; i < N; i++) {
        int x = sum - a[i];
        b[i].first = abs(sum - x);
        b[i].second = x;
    }

    sort(b.begin(), b.end());
    cout << b[0].second << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
        int i = 1,j,temp[10000];
        while(1){
                scanf("%d",&temp[i]);
                if(temp[i] == 0){
                        break;
                }
                i++;
        }
        for(j = 1;j <= i-1;j++){
                printf("Case %d: %d\n",j,temp[j]);
        }
        return 0;
}

Measured memory_bytes: 636
n, ma, mb = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

s = 400

DP = [[0] * (s+1) for i in range(s+1)]
C = [[float("inf")] * (s+1) for i in range(s+1)]
DP[0][0] = 1
C[0][0] = 0

for k in range(n):
    for i in range(s, -1, -1):
        for j in range(s, -1, -1):
            x = i-A[k][0]
            y = j-A[k][1]
            # print(x,y,i,j)
            if x >= 0 and y >= 0 and DP[x][y] == 1 and C[x][y] + A[k][2] < C[i][j]:
                C[i][j] = C[x][y] + A[k][2]
                DP[i][j] = 1
            # print(DP)

ans = float("inf")
ma0 = ma
mb0 = mb
while ma <= s and mb <= s:
    if DP[ma][mb] == 1:
        ans = min(ans, C[ma][mb])
    ma += ma0
    mb += mb0

if ans == float("inf"):
    print(-1)
else:
    print(ans)


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

int INF=1e15;

signed main(){
    int n,x;
    cin >>n>>x;
   
    
    int dp[n][n];
    for(int i=0;i<n;i++)cin>>dp[0][i];
    for(int i=1;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j]=min(dp[i-1][j],dp[i-1][(n+j-1)%n]);
        }
    }
    int ans=INF,ans0;
    for(int i=0;i<n;i++){
        ans0=x*i;
        for(int j=0;j<n;j++){
            ans0+=dp[i][j];
        }
        ans=min(ans0,ans);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
int M,ten=1e18;
map<int,int> memf,memg;
int bp(int x,ull p){
    x%=M;
    int r=1;
    while(p){
        if(p&1)(r*=x)%=M;
        (x*=x)%=M;
        p/=2;
    }
    return r;
}
int f(int k){
    if(!k)return 0;
    if(memf.find(k)==memf.end()){
        if(k&1)memf[k]=(1+(ten%M)*f(k-1))%M;
        else memf[k]=(bp(ten,k/2)+1)*f(k/2)%M;
    }
    return memf[k];
}
int g(int k){
    if(!k)return 0;
    if(memg.find(k)==memg.end()){
        if(k&1)memg[k]=(f(k)+g(k-1))%M;
        else memg[k]=((bp(ten,k/2)+1)*g(k/2)%M+((k/2)%M)*f(k/2)%M)%M;
    }
    return memg[k];   
}

int32_t main(){
    int n,a0,d;
    cin>>n>>a0>>d>>M;
    int ans=0;ull s=0;
    for(int len=18;len>=1;--len,ten/=10){
        int mxt=ten;
        int mnt=ten/10;
        if(mxt<=a0)continue;
        int posl=(mnt-a0+d-1)/d;
        int posr=(mxt-a0-1)/d;
        // dbg(len,mxt,mnt,posl,posr);
        upx(posl,0);
        upn(posr,n-1);
        dbg(len,mxt,mnt,posl,posr);
        if(posl<=posr){
            int k=posr-posl+1;
            int al=(a0+posl*d)%M;
            memf.clear();
            memg.clear();
            int cur=bp(10,s)*(al*f(k)%M+(d%M)*g(k-1)%M)%M;
            (ans+=cur)%=M;
            s+=(ull)k*(ull)len;
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
long long H, W;
long long solve(long long a, long long b) {
	long long cnt = (1LL << 60);
	for (long long i = 1; i < a; i++) {
		long long B = i*b;
		if ((a - i) % 2 == 0 || b % 2 == 0)cnt = min(cnt, abs(B -  (a*b - B) / 2));
		else {
			long long A1 = min(a - i, b);
			long long P = (a - i)*b;
			long long p[3] = { B,(P + A1) / 2,(P - A1) / 2 };
			sort(p, p + 3);
			cnt = min(cnt, p[2] - p[0]);
		}
	}
	return cnt;
}
int main() {
	cin >> H >> W;
	cout << min(solve(H, W), solve(W, H)) << endl;
	return 0;
}

Measured memory_bytes: 256
import math
L,R = map( int,input().split() )
ans = ( L * (L+1) ) % 2019  
for i in range(L,R):
    if ans == 0:
        break
    j = i + 1
    a = ( i * j ) % 2019
    ans = min(a, ans)
    plus = i % 2019
    while(True):
        over = math.ceil( ( 2019 - a ) / plus )
        j = j + over
        if j > R:
            break
        a = ( i * j) % 2019
        ans = min(a,ans)
        if ans == 0:
            break
print(ans)

Measured memory_bytes: 3064
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

H,W,A,B = inpl()

ans = [['0']*W for _ in range(H)]

for y in range(H):
    for x in range(W):
        if x < A and y < B:
            ans[y][x] = '1'
        elif x >= A and y >= B:
            ans[y][x] = '1'

for a in ans:
    print(''.join(a))


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

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

int main() {
    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vii dp(10050, vi(10050, INF));
    rep(i, n + 1) dp[i][0] = 0;
    rep(i, n) {
        rep(j, h + 1) {
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][min(h, j + a[i])], dp[i + 1][j] + b[i]);

            // debug(i);
            // debug(j);
            // debug(dp[i][j]);
        }
    }
    out(dp[n][h]);
    return 0;
}


Measured memory_bytes: 395136
s = list(input().strip())
q = int(input().strip())
queries = []
one_count = 0
one_counts = []
for i in range(q):
    inp = input().split()
    queries.append(inp)
    if inp[0] == "1":
        one_count += 1
    one_counts.append(one_count)
one_counts = list(map(lambda x: (one_count - x), one_counts))
if one_count % 2 == 1:
    s = s[::-1]
pre = []
suf = []
for i in range(q):
    if queries[i][0] == "1":
        continue
    elif queries[i][0] == "2":
        if queries[i][1] == "1":
            if one_counts[i] % 2 == 0:
                pre.append(queries[i][2])
            else:
                suf.append(queries[i][2])
        elif queries[i][1] == "2":
            if one_counts[i] % 2 == 0:
                suf.append(queries[i][2])
            else:
                pre.append(queries[i][2])
print("".join(pre[::-1] + s + suf))


Measured memory_bytes: 118648
#include <iostream>
using namespace std;
int main() {
  int a, b, r = 0;
  cin >> a >> b;
  for (int i = a; i <= b; i++)
    if (i % 10 == i / 10000 && i % 100 / 10 == i / 1000 % 10)
      r++;
  cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string S, A;

    cin >> S;

    A = "Yes";

    if (S == "AAA")
    {

        A = "No";
    }

    if (S == "BBB")
    {

        A = "No";
    }

    cout << A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
ll n,k,ling;
ll a[maxn];
bool check(ll x){
	ll cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]==0){
			if(x>=0)cnt+=n-1;
			continue;
		}
		else if(a[i]<0){
			ll tmp=0;
			if(x>=0)tmp=x/a[i];//a[i]*tmp<=x
			else {
				if(x%a[i]==0)tmp=x/a[i];
				else tmp=x/a[i]+1;
			}
			cnt+=n-(lower_bound(a,a+n,tmp)-a);
		}
		else if(a[i]>0){
			ll tmp=0;
			if(x>=0)tmp=x/a[i];
			else{
				if(x%a[i]==0)tmp=x/a[i];
				else tmp=x/a[i]-1;
			}
			cnt+=upper_bound(a,a+n,tmp)-a;
		}
		if(a[i]*a[i]<=x)cnt--;
		//cout<<cnt<<endl;
	}
	return cnt/2>=k;
}
int main(){
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a,a+n);
	ll l=-1e18,r=1e18,ans=0;
	while(l<=r){
		ll mid=(l+r)/2;
		if(check(mid))r=mid-1,ans=mid;
		else l=mid+1;
	}

	//check(-6);
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,k;
    scanf("%d %d", &n, &k);
    vector<char> viDontHave(n,1);
    for (int i = 0; i < k; i++){
    int iDi;
    scanf("%d", &iDi);
        for(int j = 0; j < iDi; j++){
            int iNum;
            scanf("%d",&iNum);
            viDontHave[iNum-1] = 0;
        }
    }
    int nCount = 0;
    for(int i = 0; i < n; i++){
        nCount += viDontHave[i];
    }
    printf("%d", nCount);
    return 0;
}


Measured memory_bytes: 3160
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

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

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

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

int M, N;
int F[100][10];
int P[100][10];
int A[100010];

int main() {
    cin >> N;
    int st = 0, sx = 0, sy = 0;
    REP(i, N) {
        int t, x, y;
        cin >> t >> x >> y;
        if((t-st)<abs(sx - x) + abs(sy - y)){
            PRI("No")
            return 0;
        }
        if (((t-st) - (abs(sx - x) + abs(sy - y))) % 2 != 0) {
            PRI("No")
            return 0;
        }
        sx = x;
        sy = y;
        st = t;
    }
    PRI("Yes")
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc084.contest.atcoder.jp/tasks/abc084_c>
問題文============================================================
 Atcoder国に、 1 本の東西方向に走る鉄道が完成しました。
 
 この鉄道には N 個の駅があり、西から順に 1,2,…,N の番号がついています。
 
 明日、鉄道の開通式が開かれます。
 
 この鉄道では、1≦i≦N−1 を満たす全ての整数 i に対して、駅 i から駅 i+1 に、
 Ci 秒で向かう列車が運行されます。ただし、これら以外の列車は運行されません。
 
 駅 i から駅 i+1 に移動する列車のうち最初の列車は、
 開通式開始 Si 秒後に駅 i を発車し、その後は Fi 秒おきに駅 i を発車する列車があります。
 
 また、Si は Fi で割り切れることが保証されます。
 
 つまり、A％B で A を B で割った余りを表すとき、
 Si≦t,t％Fi=0 を満たす全ての t に対してのみ、開通式開始 t 秒後に駅 i を出発し、
 開通式開始 t+Ci 秒後に駅 i+1 に到着する列車があります。
 
 列車の乗り降りにかかる時間を考えないとき、全ての駅 i に対して、
 開通式開始時に駅 i にいる場合、駅 N に到着できるのは最も早くて開通式開始何秒後か、答えてください。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> C(N,0),S(N,0),F(N,0);
    for(int i = 0; i < N-1;i++) cin >> C[i] >> S[i] >> F[i];
    for(int s = 0; s < N;s++){
        int ans = S[s] + C[s];
        for(int i = s+1; i < N-1;i++){
            if(ans <= S[i]){
                ans = S[i] + C[i];
            }else{
                ans = (ans - S[i] + F[i]-1)/F[i] * F[i] + S[i] + C[i];
            }
        }
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 256
//Keep Working Hard
  // I__Like__Food  

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;
  const double PI = 3.1415926535898;


int32_t main()
{






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

    bool ok = true;

    while(true)
    {
    	if(ok)
    	{
    		c-=b;
    		ok ^=1;
    	}
    	else
    	{
    		a-=d;
    		ok ^=1;
    	}

    	if(a <= 0)
    	{
    		cout << "No";
    		return 0;
    	}
    	if(c <=0)
    	{
    		cout << "Yes";
    		return 0;
    	}
    }




    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll A,B;
  cin>>A>>B;
  int ans=0;
  for(int i=A; i<=B; ++i){
    int x,y,z,w;
    x=i%10;
    y=i/10%10;
    z=i/1000%10;
    w=i/10000%10;
    if(x==w&&y==z)
    {ans++;}}
    cout<<ans<<endl;
    
  }




  


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

int main()
{
	int A[3];
	scanf("%d%d%d",A,A+1,A+2);
	sort(A,A+3);
	if((A[2]-A[1]+A[2]-A[0])%2==0)
		printf("%d\n",(A[2]-A[1]+A[2]-A[0])/2);
	else
		printf("%d\n",1+(A[2]+1-A[1]+A[2]+1-A[0]-1)/2);
	
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

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

    vector<int> dp(n, INT_MAX);
    
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    
    for(int i = 2;i < n; i++){
        dp[i] = min(dp[i],dp[i-1]+abs(h[i-1] - h[i]));
        dp[i] = min(dp[i],dp[i-2]+abs(h[i-2] - h[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, m, tot, cnt[3], col[MAXN];
vector <pii> adj[MAXN];
bool flg;
LL ans;

inline void Dfs(int x)
{
	cnt[col[x]] ++;
	tot += adj[x].size();
	for (auto e : adj[x])
		if (!~col[e.xx])
			col[e.xx] = (col[x] + e.yy) % 3, Dfs(e.xx);
		else if (col[e.xx] != (col[x] + e.yy) % 3)
			flg = true;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read(), mset(col, -1);
	for (int i = 1, x, y; i <= m; i ++)
		x = Read(), y = Read(), adj[x].pb(mp(y, 1)), adj[y].pb(mp(x, 2));
	for (int i = 1; i <= n; i ++)
		if (!~col[i])
		{
			col[i] = tot = cnt[0] = cnt[1] = cnt[2] = flg = 0, Dfs(i);
			if (flg)
				ans += 1LL * (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
			else if (!cnt[0] || !cnt[1] || !cnt[2])
				ans += tot >> 1;
			else
				ans += 1LL * cnt[0] * cnt[1] + 1LL * cnt[1] * cnt[2] + 1LL * cnt[2] * cnt[0];
		}
	return printf("%lld\n", ans), 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

ll powmod(ll x, ll k)
{
	ll res = 1;
	for (; k; x = x * x % MOD, k /= 2) {
		if (k & 1) {
			res = res * x % MOD;
		}
	}
	return res;
}

ll fac[10010], ifac[10010];

ll comb(int n, int k)
{
	if (n < 0 || k < 0 || k > n) return 0;
	return fac[n] * ifac[k] % MOD * ifac[n-k] % MOD;
}


int main() {
	fac[0] = 1;
	for (int i = 1; i < 10010; ++i) {
		fac[i] = fac[i-1] * i % MOD;
	}

	ifac[10000] = powmod(fac[10000], MOD - 2);
	for (int i = 9999; i >= 0; --i) {
		ifac[i] = ifac[i+1] * (i+1) % MOD;
	}

	int N, A, B, C;
	cin >> N >> A >> B >> C;

	if (B % 2 != 0) {
		puts("0");
		return 0;
	}

	ll ret = 0;

	for (int i = 0; i <= C/3; ++i) { //3,3,3
		for (int j = 0; j <= A; ++j) { //3,1
			if (j + i * 3 > C) break;
			int one = A - j;
			int gr = B / 2;
			int z3 = C - i * 3 - j;

			if (gr == 0 && z3 > 0) continue;

			ll val = comb(one + i + j + gr, one) * comb(i + j + gr, i) % MOD * comb(j + gr, j) % MOD;
			if (gr > 0) val = val * comb(z3 + gr - 1, z3) % MOD;
			ret = (ret + val) % MOD;
		}
	}

	cout << ret << endl;

	return 0;
}

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

int main() {
	string s; cin >> s;
	int k; cin >> k;
	vector<string>dict;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j + i - 1 < s.size(); j++) {
			dict.push_back(s.substr(j, i));
		}
	}
	dict.push_back(s);
	sort(dict.begin(), dict.end());
	unique(dict.begin(), dict.end());
	cout << dict[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 1660
//
// Created by myabu on 2020/02/01.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int a,b;

    cin>>a>>b;

//    int count = 0;
//    for (int i = 1; i <= a; ++i) {
//        for (int j = 1; j <= b; ++j) {
//            if(i==j)count++;
//        }
//    }
//
//    cout<<count<<endl;

//    cout<<min(a,b)<<endl;

    if(a>b)a--;
    cout<<a<<endl;

    return 0;
}

Measured memory_bytes: 888
#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> ;

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};

ll gcd(ll a,ll b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
  return a/ gcd(a,b) * b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a,b;
  cin >> a;
  b = a;
  rep(i,n-1){
    cin >> a;
    b = lcm(a,b);
  }
  cout << b << endl;
  
  return 0;
}


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

int main()
{
    int n;
    cin >> n;

    int ans = 0;
    int now = 1;

    rep(i, n)
    {
        int a;
        cin >> a;
        if (a == now)
            ++now;
        else
            ++ans;
    }

    if (ans == n)
        ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 100 + 1
int main(void){
	char taro[MAX_LENGTH],hanako[MAX_LENGTH];
	int n,t_score = 0,h_score = 0;

	scanf("%d", &n);

	while(n--){
		scanf("%100s %100s", taro, hanako);

		if(strcmp(taro, hanako) > 0){
			t_score += 3;
		}
		else if(strcmp(taro, hanako) < 0){
			h_score += 3;
		}
		else{
			t_score++;
			h_score++;
		}
	}

	printf("%d %d\n", t_score, h_score);

	return 0;
}

Measured memory_bytes: 604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day3/problems/F>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void solve(){
    int Q; cin >> Q;
    while(Q--){
        ll cnt = 0;
        string S,T; cin >> S >> T;
        int x = (int)S.length()-1;
        while(x>=0){
            if(S[x]=='1') break;
            x--;
        }
        int y = (int)T.length()-1;
        while(y>=0){
            if(T[y]=='1') break;
            y--;
        }
        int dif = x;
        for(int i = 0; i < S.length();i++){
            if(S[i] == T[i]) continue;
            dif = i;
            break;
        }
        cnt = abs(x-dif) + abs(y-dif);
        cout << cnt << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 3200
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a = I()
b = I()
h = I()
print((a+b)*h//2)

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

int main(){
  
  string S;
  int cnt=0;
  cin>>S;
  for(int i=0; i<S.size()-1; i++){
    if(S[i]!=S[i+1])cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3748
N, W = map(int, raw_input().split())
L = sorted([int(raw_input()) for _ in xrange(N)])
total = sum(L)
dp = [1] + [0] * W
ans = 0 if total > W else 1
for i, w in zip(xrange(N, -1, -1), L[::-1]):
    total -= w
    res = W - total
    if res >= 0:
        ans = (ans + sum(dp[max(0, res - w + 1):res + 1])) % (10**9 + 7)
    for j in xrange(W, w - 1, -1):
        dp[j] += dp[j - w]
print ans

Measured memory_bytes: 4436
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

    string S;
    cin >> S;

    bool checker = false;

    for(int i = 0; i < S.length(); i++) {
        if(i % 2 == 0) {
            if(S[i] == 'L') {
                checker = true;
                break;
            }
        } else {
            if(S[i] == 'R') {
                checker = true;
                break;
            }
        }
    }

    if(!checker) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> vec;
    map<int, map<int, int>> nums;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        vec.emplace_back(x % m, x);
        nums[x % m][x]++;
    }
    // sort(vec.begin(), vec.end());

    // int num = vec[1].second;
    // int num2 = lower_bound(vec.begin(), vec.end(), pair<int, int>{m - num, -1}) -> second;
    // cout<<num<<' '<<num2<<endl;
    int ans = 0;

    for(int i=0;i<m;i++){
        if(i == (m - i) % m){
            int s1 = 0;
            auto& m1 = nums[i];
            for(auto& p : m1){ s1 += p.second; }
            ans += s1 / 2;
        }else{
            if(i > (m - i) % m){ break; }
            // if(!nums.count(i) || !nums.count((m - i) % m)){ continue; }
            auto& m1 = nums[i];
            auto& m2 = nums[(m - i) % m];
            int s1 = 0, s2 = 0;
            for(auto& p : m1){ s1 += p.second; }
            for(auto& p : m2){ s2 += p.second; }
            ans += min(s1, s2);
            if(s1 == s2){ continue; }
            if(s1 < s2){
                swap(s1, s2);
                swap(m1, m2);
            }
            vector<int> v;
            for(auto& p : m1){ v.push_back(p.second); }
            sort(v.begin(), v.end());
            // sort(v.begin(), v.end(), [](int a, int b){return (a % 2) < (b % 2); });
            // sort(v.begin(), v.end(), [](int a, int b){return !((a % 2) == 0 && (b % 2) == 1); });
            // sort(v.begin(), v.end(), [](int a, int b){return ((a % 2) == 1 && (b % 2) == 0); });
            // println(v);
            // sort(v.begin(), v.end(), [](int a, int b){return (a % 2) < (b % 2); });
            for(int& i : v){
                if(i % 2 == 1){
                    if(s2 == 0){
                        break;
                    }
                    s2--;
                    i--;
                }
            }
            sort(v.begin(), v.end());
            for(int& i : v){
                int d = min(i, s2);
                s2 -= d;
                i -= d;
            }
            for(int& i : v){
                // cnt += i;
                ans += i / 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13556
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String line = scanner.nextLine();
			int result = -1;
			for (int i = 0; i < 10; i++) {
				String newLine = line.replace("X", String.valueOf(i)).replace(
						"+", "=");
				String[] strs = newLine.split("=");
				if ((strs[0].length() > 1 && strs[0].charAt(0) == '0')
						|| (strs[1].length() > 1 && strs[1].charAt(0) == '0')
						|| (strs[2].length() > 1 && strs[2].charAt(0) == '0')) {
					continue;
				}
				BigInteger[] num = new BigInteger[3];
				for (int j = 0; j < 3; j++) {
					num[j] = new BigInteger(strs[j]);
				}
				if (num[0].add(num[1]).equals(num[2])) {
					result = i;
					break;
				}

			}
			System.out.println(result == -1 ? "NA" : result);
		}
	}
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

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

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0;
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({a, ex});
	}
	if (N != 1) res.push_back({N, 1});
	return res;
}


int main(void){

	int N; cin >> N;

	map<ll, ll> mp;
	FOR(i,1,N+1){
		auto pf = prime_factorize(i);
		for(auto p: pf){
			mp[p.first] += p.second;
		}
	}

	ll ans = 1;
	for(auto p : mp){
		ans *= (p.second+1);
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 3616