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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; gi(n), gi(m);
	print((n*(n-1)+m*(m-1))/2);
}


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

int main()
{
  int N,M;
  vector<int> a(10001);
  cin >> N >> M;
  for(int i=0; i<M; i++)
  {
  cin >> a.at(i);
  }
  for(int i=0; i<M; i++)
  {
   	N-=a.at(i);
  }
  if(N>=0)
    cout << N << endl;
  else
    cout <<"-1"<< endl;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, B, Ai, digit;
  string As;
  cin >> N >> B;
  
  while(N > 0){
  Ai = N % B;
  N = (N - Ai) / B;
  As = to_string(Ai) + As;
  }
  digit = As.size();
  
  cout << digit << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>x>>y;
    cout<<x*y;


    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int W=sc.nextInt(),H=sc.nextInt();
        int x=sc.nextInt(),y=sc.nextInt();
        int r=sc.nextInt();
        if((x-r>=0)&&(y-r>=0)&&(x+r<=W)&&(r+y<=H))System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 17232
/* Palindromic Numbers */
#include <bits/stdc++.h>

using namespace std;

int main()
{
    string num;
    cin >> num;
    string num1 = num;
    reverse(num1.begin(), num1.end());
    if (num == num1){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    int ans=-1;
    for(int i=0;i<=n;i++){
        int val=i*108/100;
        if(val==n){
            ans=i;
            break;
        }
        if(val>n)break;
    }

    if(ans==-1){
        cout << ":(" << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main(){
   long long N,M;
   cin>>N>>M;
   if(M<N)swap(N,M);
   if(N==1&&M==1){
       cout<<1;
   } else if(N==1&&M!=1){
        cout<<M-2;
    }else{
        cout<<(N-2)*(M-2);
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 300005
using namespace std;

int n, c[N], s[N], ans[N];
int main()
{
	int i, j, t;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%d", &t);
		c[t]++;
		s[c[t]]++;
	}
	for (i = 1; i <= n; i++) s[i] += s[i - 1];
	for (i = n, j = 1; i > 0; i--) {
		for (; ; j++) {
			if (s[j] < j * i) break;
		}
		ans[i] = j - 1;
	}
	for (i = 1; i <= n; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    rep(i,n)std::cin >> a[i];

    int ma=INF;
    int ans=0;
    rep(i,n){
        if(ma>a[i])ans++;
        ma=min(a[i],ma);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            //for (; ; )
           // {
                string S = Console.ReadLine();
                string[] date = S.Split('/');
                int month = int.Parse(date[1]);


                if (month <= 4)
                {
                    Console.WriteLine("Heisei");
                }
                else
                {
                    Console.WriteLine("TBD");
                }
            //}
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>

using namespace std;

#define DATA_MAX 20

void car_in( int car[] , int num );
void car_out( int car[] );


int main(void)
{
	int car[DATA_MAX];
	int num;

	while(1){

		cin >> num;
		if( cin.eof() ) break;

		if( num == 0 ){
			car_out( car );
		}
		else{
			car_in( car , num );
		}
	}

}

void car_in( int car[] , int num )
{
	for( int i = DATA_MAX - 1 ; i > 0 ; i-- )
	{
		car[i] = car[i-1];
	}
	car[0] = num;

	return;
}

void car_out( int car[] )
{
	cout << car[0] << endl;

	for( int i = 0 ; i < DATA_MAX-1 ; i++ )
	{
		car[i] = car[i+1];
	}

	return;
}

Measured memory_bytes: 1160
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
	  Scanner scanner = new Scanner(System.in);
	  ArrayList<Integer> list = new ArrayList<Integer>();
	  list.add(Integer.parseInt(scanner.next()));
	  list.add(Integer.parseInt(scanner.next()));
	  list.add(Integer.parseInt(scanner.next()));
	  Collections.sort(list);
	  if(list.get(0) == 5 && list.get(1) == 5 &&list.get(2) == 7) {
		  System.out.print("YES");
	  }else {
		  System.out.print("NO");
	  }
	  
	  scanner.close();
  }
}

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

// Caleb Faith Adnaka XI105
int main() {

    int R;
    cin >> R;
    
    if (R < 1200){
        cout << "ABC\n";
    }
    else if (R < 2800){
        cout << "ARC\n";
    }
    else{
        cout << "AGC\n";
    }

}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
// Binary Indexed Tree (Fenwick Tree)
template <typename T>
struct BIT {
    ll n;
    vector<T> d;
    BIT(ll n = 0) : n(n), d(n + 1) {}
    void add(ll i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] += x;
        }
    }
    T sum(ll i) {
        T x = 0;
        for (i++; i; i -= i & -i) {
            x += d[i];
        }
        return x;
    }
};

using arr = array<ll, 3>;
int main() {
    init();
    ll N, Q;
    cin >> N >> Q;
    vl C(N);
    rep(i, N) cin >> C[i], C[i]--;

    vc<arr> qr(Q);
    rep(i, Q){
        ll l, r;
        cin >> l >> r;
        l--, r--;
        qr[i] = arr({l, r, i});
    }
    sort(all(qr), [](arr a1, arr a2) { return a1[1] < a2[1]; });

    BIT<ll> bt(N + 1);
    vl ans(Q), lp(N, -1);

    ll now = 0;
    rep(i, Q){
        auto [l, r, id] = qr[i];
        while(now<=r){
            ll c = C[now];
            if (lp[c] != -1) bt.add(lp[c] + 1, -1);
            bt.add(now + 1);
            lp[c] = now;
            now++;
        }
        ans[id] = bt.sum(r + 1) - bt.sum(l);
    }


    rep(i, Q) cout << ans[i] << '\n';
}

Measured memory_bytes: 31140
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
}

Measured memory_bytes: 3660
using System;
using System.Linq;

namespace ABC153B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string[] input2 = Console.ReadLine().Split(' ');
            int[] skill = input2.Select(int.Parse).ToArray();

            int h = int.Parse(input[0]);
            int n = int.Parse(input[1]);

            if(skill.Sum() >= h)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 19680
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

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

    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    cout << *std::max_element(a.begin(), a.end()) - *std::min_element(a.begin(), a.end()) << endl;

    return 0;
}


Measured memory_bytes: 256
import math
def myAnswer(N:int, A:int, B:int) -> int:
   counter =(N // (A + B))
   ans = counter * A
   if(N % (A + B) < A):
      ans += N % (A + B)
   else:
      ans += A
   return ans 

def modelAnswer():
   tmp=1
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

const long mod = 998244353;
struct mint {
    long long x;
    mint(const long long x=0) : x(x%mod) {}

    mint& operator+=(const mint a) {
        if ( (x+=a.x) >= mod) x-=mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ( (x+= mod-a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x*=a.x) %= mod;
        return *this;
    }
    mint& operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint& operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint& operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }

    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint& operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main() {
    long n;
    mint ans(1);
    cin >> n;
    vector<long> dl(n);
    map<long,long> dc;


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

    if (dl[0] != 0) ans.x = 0;
    if (dc[0] > 1) ans.x = 0;
    if (n>2 && dc[1]<=0) ans.x = 0;

    for (auto d : dc) {
        if (d.first < 2) continue;
        ans *= mint(dc[d.first-1]).pow(d.second);
    }

    cout << ans.x << endl;
}

Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main(void){
 int a,b;
 while(cin>>a>>b){
  int oa=a,ob=b;
  while(b!=0)
  {
   int r=a%b;
   a=b;
   b=r;
  }
  cout<<a<<" "<<(oa/a*ob)<<endl;
 }
}

Measured memory_bytes: 1160
<?php

list($H,$W,$N) = explode(" ",trim(fgets(STDIN)));

$ans = array(1 => 0,
             2 => 0,
             3 => 0,
             4 => 0,
             5 => 0,
             6 => 0,
             7 => 0,
             8 => 0,
             9 => 0
             );

$count = ($H - 2) * ($W - 2);

if($N > 0){
    for($i = 1;$i <= $N;$i++){
        list($a,$b) = explode(" ",trim(fgets(STDIN)));
        for($j = -1;$j <= 1;$j++){
            if($a + $j > 1 && $a + $j < $H){
                for($k = -1;$k <= 1;$k++){
                    if($b + $k > 1 && $b + $k < $W){
                        if(isset($map[$a + $j][$b + $k])){
                            $map[$a + $j][$b + $k] ++;
                        }else{
                            $map[$a + $j][$b + $k] = 1;
                        }
                    }
                }
            }
        }
    }
    
    foreach($map as $val){
        foreach($val as $val2){
            $ans[$val2] ++;
            $count --;
        }
    }
}

echo $count . PHP_EOL . implode(PHP_EOL,$ans);

?>

Measured memory_bytes: 219768
#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[110][110];
char a[110][110];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>c[i][j];
	for(int i=1;i<=2*n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=c[(i+1)/2][j];
	for(int i=1;i<=2*n;i++)
		{
			for(int j=1;j<=m;j++)cout<<a[i][j];
			cout<<endl;
		}
	return 0;
}

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

int main(void){
    while (1) {
        int n, m, h[1550], w[1550], hs[1550], ws[1550];
        cin >> n >> m;
        if (n == 0 && m == 0) return 0;
        
        for (int i = 0; i <= n; i++) {
            if (i != n) cin >> h[i];
            if (i == 0) hs[i] = 0;
            else hs[i] = hs[i - 1] + h[i - 1];
        }
        for (int i = 0; i <= m; i++) {
            if (i != m) cin >> w[i];
            if (i == 0) ws[i] = 0;
            else ws[i] = ws[i - 1] + w[i - 1];
        }
        
        vector<int> ns, we;
        for (int i = 0; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) ns.push_back(hs[j] - hs[i]);
        }
        for (int i = 0; i <= m; i++) {
            for (int j = i + 1; j <= m; j++) we.push_back(ws[j] - ws[i]);
        }
        
        sort(ns.begin(), ns.end());
        sort(we.begin(), we.end());
        
        /*
        for (int i = 0; i  < ns.size(); i++) cout << ns[i] << " ";
        cout << endl;
        for (int i = 0; i < we.size(); i++) cout << we[i] << " " ;
        cout << endl;*/
        
        int idx1 = 0, idx2 = 0, ans = 0;
        while (idx1 != ns.size() && idx2 != we.size()) {
            if (ns[idx1] < we[idx2]) idx1++;
            else if (ns[idx1] > we[idx2]) idx2++;
            else {
                int same = ns[idx1], sub1 = 0, sub2 = 0;
                while (ns[idx1 + sub1] == same && idx1 + sub1 < ns.size()) sub1++;
                while (we[idx2 + sub2] == same && idx2 + sub2 < we.size()) sub2++;
                //cout << same << " " << sub1 << " " << sub2 << endl;
                ans += sub1 * sub2;
                idx1 += sub1;
                idx2 += sub2;
            }
        }
        
        cout << ans << endl;
    }
}



Measured memory_bytes: 19808
#include <iostream>
#include <vector>
using namespace std;
 
#define MAX_P 1000000
 
int main(){
    bool prime[MAX_P];
    prime[0] = false;
    prime[1] = false;
    for( int i = 2; i < MAX_P; i++ ) prime[i] = true;
    for( int i = 2; i < MAX_P; i++ ){
        if( prime[i] ){
            for( int j = 2*i; j < MAX_P; j += i ){
                prime[j] = false;
            }
        }
    }
    int n, x;
    while( cin >> n >> x, n || x ){
        vector<bool> dp(x+1);
        for( int i = 0; i <= x; i++ ) dp[i] = false;
        vector<int> p(n);
        for( int i = 0; i < n; i++ ){
            cin >> p[i];
        }
        dp[0] = true;
        int max = 0;
        for( int i = 0; i <= x; i++ ){
            if( dp[i] ){
                if( prime[i] && max < i ) max = i;
                for( int j = 0; j < n; j++ ){
                    if( i+p[j] <= x ) dp[i+p[j]] = true;
                }
            }
        }
        if( max > 0 ) cout << max << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int n, cs, ct;
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; ++i)
		if(s[i] == 'S')
			++cs;
		else
		{
			if(cs) --cs;
			else ++ct;
		}
	printf("%d\n", cs + ct);
	return 0;
}
		 

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,nu=0;
    cin>>n;
    if(n>=100&&n<=999)
    while(n)
    {
        int t;
        t=n%10;
        if(t==7) {nu++;printf("Yes\n");break;}
        n=n/10;
    }
    if(!nu) printf("No\n");
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A[3];
int main(){
  int res;
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<3;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(3==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = A[0];
      for(KL2GvlyY=1;KL2GvlyY<3;KL2GvlyY++){
        Q5VJL1cS = min_L(Q5VJL1cS, A[KL2GvlyY]);
      }
    }
    {
      int cTE1_r3A, e98WHCEY;
      if(3==0){
        cTE1_r3A = 0;
      }
      else{
        cTE1_r3A = A[0];
        for(e98WHCEY=1;e98WHCEY<3;e98WHCEY++){
          cTE1_r3A = max_L(cTE1_r3A, A[e98WHCEY]);
        }
      }
      res =cTE1_r3A-Q5VJL1cS;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A[3];
// {
//   int res;
//   rd(A(3));
//   res = max(A(3)) - min(A(3));
//   wt(res);
// }


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#define MAXN 10
#define LL long long
int h,w;
char mp[MAXN][MAXN];
bool b[MAXN][MAXN];
const int dx[]={1,0},dy[]={0,1};//1 3
int cnt=0,ans=1/*起点*/;
void dfs(int x,int y)
{
	for(int i=0;i<2;i++)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>0&&nx<=h&&ny>0&&ny<=w&&!b[nx][ny]&&mp[nx][ny]=='#')
		{
			b[nx][ny]=1;
			dfs(nx,ny);
			b[nx][ny]=0;
			ans++;
			break;//能往下走就往下走，否则才往右走，这里是要找到一条路，否则它会把其它路的答案算进来
		}
	}
}
int main()
{
	scanf("%d %d",&h,&w);
	for(int i=1;i<=h;i++)
	{
		scanf("%s",mp[i]+1);
		for(int j=1;j<=w;j++)
			if(mp[i][j]=='#') cnt++;
	}
	b[1][1]=1;
	dfs(1,1);
	if(ans==cnt) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#include<array>
using namespace std;
#define int long long
#define fast_cin ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define endl "\n"
#define with_tests int t; cin >> t; while(t--){ solve(); cout << endl; }
#define without_tests solve(); cout << endl;
#define CEIL(x, y) (ll)ceil((long double)(x)/(long double)(y))
#define epsilon 1e-9 
typedef long long ll;
const int mod = 1e9+7;
const int N = 1e5+1;

void solve(){
    
    int n, w;
    cin >> n >> w;
    vector<int> vi(n), wi(n);
    for(int i=0; i<n; i++){
        cin >> wi[i] >> vi[i];
    }
    vector<int> dp(w+1);
    for(int j=0; j<n; j++){
        for(int i=w; i>=0; i--){
            if(i-wi[j] < 0){
                break;
            }
            if(i-wi[j] == 0 || dp[i-wi[j]] != 0)
                dp[i] = max(dp[i-wi[j]] + vi[j], dp[i]);
        }
    }
    int ans = 0;
    for(int i=0; i<=w; i++){
        ans = max(ans, dp[i]);
        // cout << dp[i] << " ";
    }
    cout << ans;

}

int32_t main(){

    fast_cin;
    // with_tests;
    without_tests;

    return 0;
}


Measured memory_bytes: 3940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str_abcd = br.readLine().split(" ");
        int a = Integer.parseInt(str_abcd[0]);
        int b = Integer.parseInt(str_abcd[1]);
        int c = Integer.parseInt(str_abcd[2]);
        int d = Integer.parseInt(str_abcd[3]);
        
        String ans = "No";
        if ((Math.abs(b - a) <= d && Math.abs(c - b) <= d) || Math.abs(c - a) <= d) {
            ans = "Yes";
        }
        
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

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

int main() {
    int A, B, C; cin >> A >> B >> C;
    int K;  cin >> K;
    int max_num;
    max_num = max(A,B);
    max_num = max(max_num,C);
    int ans = max_num;
    rep(i,K)  ans *= 2;
    ans = ans + A + B + C - max_num;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    while(cin >> n)
    {
        int Min=1000000000,ipt,t = 0;
        long long int ans = 0;
        for (int ctr = 0;ctr<n;ctr++)
        {
            cin >> ipt;
            if(ipt<0)
            {
                ipt = -ipt;
                t++;
            }
            if(ipt<Min)
                Min = ipt;
            ans+=ipt;
        }
        if(t%2)
        {
            ans-=2*Min;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    set<string> results;
    for (int i = 0; i < n; i++)
    {
        string str;
        cin >> str;

        results.insert(str);
    }

    const int ans = results.size();

    cout << ans << endl;
}


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

int main(){
	vector<int> vect(3);
	int ans;
	cin >> vect[0] >> vect[1] >> vect[2];
	sort(vect.begin(), vect.end());
	ans = vect[2] - vect[1] - vect[0];
	if (ans > 0)cout << ans << endl;
	else cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif

static void C_task();

int main()
{
	C_task();
	
	fflush(stdout);
	return 0;
}

static void C_task()
{
	static char substr[10000][11] = { 0 };

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

	for (int i = 0; i < N; i++) {
		scanf(" %s", substr[i]);
	}

	char lastChar = 0;
	bool isBFirst = false;
	int aCount, bCount;
	int abCount = 0, aLast = 0, bFirst = 0, baCount = 0;

	for (int i = 0; i < N; i++) {
		lastChar = 0;
		isBFirst = false;
		aCount = bCount = 0;

		if (substr[i][0] == 'B') {
			isBFirst = true;
		}
		
		for (int j = 0; j < 10; j++) {
			if (substr[i][j] == 'A') {
				lastChar = 'A';
				aCount++;
			}
			else if (substr[i][j] == 'B') {
				if (lastChar == 'A') {
					abCount++;
				}
				lastChar = 'B';
				bCount++;
			}
			else if (substr[i][j] == '\0') {
				break;
			}
			else {
				lastChar = 0;
			}
		}
		
		if ((lastChar == 'A') && (isBFirst)) {
			baCount++;
		}
		else if (lastChar == 'A') {
			aLast++;
		}
		else if (isBFirst) {
			bFirst++;
		}
	}

	if (aLast > 0) {
		abCount += std::min(aLast, baCount);
		abCount += std::max(0, baCount - aLast);
		abCount += std::min(aLast, bFirst);
	}
	else {
		abCount += std::max(0, baCount - 1);
		abCount += std::min(((baCount > 0) ? 1 : 0), bFirst);
	}

	printf("%d\n", abCount);
}


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

int main(){
    int n,tmp;
    scanf("%d",&n);
    int d[100001];
    bool x[100001];
    for (int i=0;i<100001;i++) x[i]=0;
    d[0]=1;
    int t[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
    for (int i=1;i<100001;i++) {
        for (int j=0;j<12;j++) {
            tmp=i+t[j]-1;
            if (tmp>100000) break;
            if (x[tmp]==0) {
                d[tmp]=d[i-1]+1;
                x[tmp]=1;
            } else {
                d[tmp]=min(d[tmp],d[i-1]+1);
            }
        }
    }
    printf("%d\n",d[n]-1);
    return 0;
}


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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

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

	int A, B, sum = 0;

	cin >> A >> B;

	sum = (B-1+A-2)/(A-1);

	cout << sum << "\n";
	return 0;		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0
 
ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}
 
int h,w,n,k;
 
int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}
 
int ans[50][50];
 
void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if((h == w && rand()%2) || h > w){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}
 
int main(){
    srand(time(0));
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);
 
    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }
 
    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>t(N+1);
  vector<int>x(N+1);
  vector<int>y(N+1);
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(int i=1;i<N+1;i++){
    cin>>t[i]>>x[i]>>y[i];
  }
  bool flag=true;
  for(int i=1;i<N+1;i++){
    int l=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    int T=t[i]-t[i-1];
    if(l%2!=T%2){
      flag=false;
    }
    if(l>T){
      flag=false;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 1408
class SegmentTree():
    maxval=(1<<31)-1

    def __init__(self,n,val=maxval):
        self.offset=self.setOffset(n)
        self.segTree=[val]*(2*self.offset+1)

    def init_array(self,array):
        for i in range(len(array)):
            self.segTree[i+self.offset]=array[i]
        for i in range(offset-1,-1,-1):
            self.segTree[i]=self.minChild(i)

    def setOffset(self,n):
        if n==1:
            return 1
        else:
            return (1<<(n-1).bit_length())-1

    def update(self,k,x):
        k+=self.offset
        self.segTree[k]=x
        while k:
            k=(k-1)>>1
            self.segTree[k]=self.minChild(k)

    def min_query(self,p,q):
        if p>=q:
            return

        p+=self.offset
        q+=self.offset-1
        segmin=self.maxval

        while q-p>1:
            #p%2==0
            if not p&1:
                segmin=min(segmin,self.segTree[p])
            #q%2==1
            if q&1:
                segmin=min(segmin,self.segTree[q])
                q-=1
            p=p>>1
            q=(q-1)>>1

        if p==q:
            return min(segmin,self.segTree[p])
        else:
            return min(min(segmin,self.segTree[p]),self.segTree[q])

    def minChild(self,n):
        return min(self.segTree[2*n+1],self.segTree[2*n+2])

n,q=map(int,input().split())
ST=SegmentTree(n)
for i in range(q):
    qry=list(map(int,input().split()))
    if qry[0]==0:
        ST.update(qry[1],qry[2])
    else:
        print(ST.min_query(qry[1],qry[2]+1))



Measured memory_bytes: 8692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long
#define dp down
#define dp1 up

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

const ll inf = 0x3f3f3f3f3f3f3f;
//const ll mod = 1e9 + 7;
const int N = 2e5 + 11;
const int NMAX = 1e4 + 11;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;

//ifstream cin ("test.in");
//ofstream cout ("test.out");

int n, mod, down[N], up[N];

vector<int>v[N];


void dfs1(int nod, int p){

    ll cur = 1;

    for(auto it : v[nod]){
        if(it == p)continue;
        dfs1(it, nod);
        cur = ((cur*(down[it] + 1))%mod + mod)%mod;
    }

    down[nod] = cur;
}

void dfs2(int nod, int p){

    auto pos = find(all(v[nod]),p);
    if(pos != v[nod].end())v[nod].erase(pos);

    vector<int>L(sz(v[nod]) + 5, 0);
    vector<int>R(sz(v[nod]) + 5, 0);

    int len = sz(v[nod]);

    if(!len)return;

    L[0] = 1;
    for(int i = 1; i < len; i++){
        L[i] = ((L[i - 1]*(down[v[nod][i - 1]] + 1))%mod + mod)%mod;
    }

    R[len - 1] = 1;
    for(int i = len - 2; i >= 0; i--){
        R[i] = ((R[i + 1]*(down[v[nod][i + 1]] + 1))%mod + mod)%mod;
    }

    for(int i = 0; i < len; i++){

        int it = v[nod][i];

        up[it] = (((up[nod] + 1)*(L[i]%mod)*(R[i]%mod))%mod + mod)%mod;

        dfs2(it,nod);
    }


}

void dfs(int nd, int parent)
{
  auto I = find(v[nd].begin(), v[nd].end(), parent);
  if (I != v[nd].end()) v[nd].erase(I);

  if((int)v[nd].size() >= 1)
  {
    int n= v[nd].size();
    vector<ll> L(n, 0) , R(n, 0);
    L[0] = 1;
    R[n-1] = 1;
    for(int i=1; i<n; i++)
      L[i] = L[i-1] * (dp[v[nd][i-1]]+1) %mod;
    for(int i=n-2; i>=0; i--)
      R[i] = R[i+1] * (dp[v[nd][i+1]]+1) % mod;

    for(int i=0; i<n; i++)
    {
      int y = v[nd][i];
      dp1[y] = (dp1[nd] +1) * L[i]%mod*R[i]%mod;
      dfs(y, nd);
    }
  }
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    cin >> n >> mod;

    for(int i = 1,x,y; i < n; i++){
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs1(1,0);

    dfs(1,0);

    for(int i = 1; i <= n; i++){
        cout << ((down[i]*(up[i] + 1))%mod + mod)%mod << '\n';
    }


}

Measured memory_bytes: 20480
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> N >> M >> L;
    ll dp[301][301];
    ll ans[90000];
    rep(i, N){
        rep(j, N){
            dp[i][j] = MAX;
            if(i == j) dp[i][j] = 0; 
        }
    }
    rep(i, M){
        cin >> A >> B >> C;
        dp[A-1][B-1] = C;
        dp[B-1][A-1] = C;
    }
    rep(i, N){
        rep(j, N){
            rep(k, N){
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]); 
            }
        }
    }
    rep(i, N){
        rep(j, N){
            if(dp[i][j] <= L) dp[i][j] = 1;
            else dp[i][j] = MAX; 
        }
    }

    rep(i, N){
        rep(j, N){
            rep(k, N){
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]); 
            }
        }
    }

    cin >> Q;
    rep(i, Q){
        cin >> S >> T;
        ans[i] = dp[S-1][T-1];
        if(dp[S-1][T-1] == MAX) ans[i] = 0;
    }
    rep(i, Q) cout << ans[i]-1 << endl;
}

Measured memory_bytes: 1920
from collections import deque

INF = 1000000000
h,w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sx, sy):
    ds = [[1,0], [-1,0], [0,1], [0,-1]]
    distance = [[-1 for _ in range(h)] for _ in range(w)]
    q = deque([[sx, sy]])
    distance[sx][sy] = 0

    while q:
        x, y = q.popleft()
        #print('-----', x, y)
        for dx, dy in ds:
            nx, ny = x+dx, y+dy
            if (nx >= 0) and (nx <= w-1) and (ny >= 0) and (ny <= h-1):
                #print(nx, ny)
                if maze[ny][nx] != '#' and distance[nx][ny] == -1:
                    q.append([nx, ny])
                    distance[nx][ny] = distance[x][y] + 1
    return max(map(max, distance))

count = 0
for s_x in range(w):
    for s_y in range(h):
        if maze[s_y][s_x] == '.':
            count = max(count, bfs(s_x, s_y))

print(count)


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
 
int main() {
  int  n; cin>>n;
  ll ans=1LL;
  rep(i,n){
    ll t;
    cin >> t;
    ans=lcm(ans,t);
  }
  cout<<ans<<endl;
  
}
  



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

int main()
{
	int n;
	cin >> n;
	auto t = vector<vector<pair<int, int>>>(n + 1);
	for(auto i = 1; i < n; ++i){
		int u, v, w;
		cin >> u >> v >> w;
		t[u].push_back(make_pair(v, w));
		t[v].push_back(make_pair(u, w));
	}
	auto ans = vector<int>(n + 1, -1);
	auto rec = [&t, &ans](auto rec, int a, int c) -> void {
		ans[a] = c;
		for(auto p : t[a]){
			if(ans[p.first] >= 0) continue;
			rec(rec, p.first, (c + p.second) % 2);
		}
	};
	rec(rec, 1, 0);
	for(auto i = 1; i <= n; ++i){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 7168
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <complex>

using namespace std;
typedef long long ll;

typedef long double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos(-1);
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}


bool near(P a, P b) {
    return !sgn(abs(a-b));
}

R cross(P a, P b) { return imag(conj(a)*b); }
R dot(P a, P b) { return real(conj(a)*b); }

struct L {
    P x, y;
    L() {};
    L(P x, P y) :x(x), y(y) {};
};

namespace std {
    bool operator < (P a, P b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    bool operator > (P a, P b) {
        return (b < a);
    }
}

/* 1->cclock
  -1->clock
   0->on
   2->back
  -2->front
  */
int ccw(P a, P b, P c) {
    assert(!near(a, b));
    if (near(a, c) || near(b, c)) return 0;
    int s = sgn(cross(b-a, c-a));
    if (s) return s;
    if (a > b) swap(a, b);
    if (c < a) return 2;
    if (b < c) return -2;
    return 0;
}

typedef vector<P> Pol;

Pol convex(Pol p) {
    sort(p.begin(), p.end());
    if (p.size() <= 2) return p;
    Pol up;
    for (P d: p) {
        //if (up.size() > 1) printf("ccw%d\n",  ccw(up[up.size()-2], up[up.size()-1], d) );
        while (up.size() > 1 && ccw(up[up.size()-2], up[up.size()-1], d) > 0) {
        //    printf("pop\n");
            up.pop_back();
        }
        //printf("push\n");
        up.push_back(d);
    }
    reverse(up.begin(), up.end());
    Pol down;
    for (P d: p) {
        while (down.size() > 1 && ccw(down[down.size()-2], down[down.size()-1], d) < 0) down.pop_back();
        down.push_back(d);
    }
    //printf("%ld %ld\n", up.size(), down.size());
    down.insert(down.begin(), up.begin()+1, up.end()-1);
    return down;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) break;
        Pol p;
        for (int i = 0; i < n; i++) {
            R x, y;
            scanf("%Lf,%Lf", &x, &y);
            p.push_back(P(x, y));
        }
        cout << n-convex(p).size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
n,x,m = map(int, raw_input().split())
ans = 0

seen = {}
reverse = {}
c = 0
while(x not in seen):
	seen[x] = c
	reverse[c] = x
	c+=1
	x = (x**2) % m
#print seen[x], c-1 
#print [(key, reverse[key])for key in sorted(reverse.keys())]
def f(n,a,b,reverse):
	ans = 0
	#print a,b
	for i in xrange(b+1):
		if n > 0:
			ans += reverse[i]
			n-=1
		else:
			break
	if n > 0:
		t = sum([reverse[uu] for uu in xrange(a,b+1)] or [0])
		ans += n/(b-a+1) * t
		n %= (b-a+1)

		for i in xrange(a,b+1):
			if n > 0:
				ans += reverse[i]
				n-=1
			else:
				break

	return ans


print f(n, seen[x], c-1, reverse)




Measured memory_bytes: 87408
import itertools
N,M,Q=map(int,input().split())
a_b_c_d=[list(map(int,input().split())) for _ in range(Q)]
nums=[i for i in range(1,M+1)]
A_s=itertools.combinations_with_replacement(nums,N)
ans=0
for A in A_s:
    tmp=0
    for i in range(Q):
        if A[a_b_c_d[i][1]-1]-A[a_b_c_d[i][0]-1]==a_b_c_d[i][2]:
            tmp+=a_b_c_d[i][3]
    if tmp>ans:
        ans=tmp
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;
const int nax = 2005;
int a[nax];
map<tuple<int,int,int>,int> mp;
int n;
void solve()
  {
     cin>>n;
     loop(i,0,n)
      {
        cin>>a[i];
        //mp[a[i]]++;
      }
     int cnt = 0;
     sort(a,a+n);
     loop(i,0,n)
      {
        loop(j,i+1,n)
         {
          loop(k,j+1,n)
            {
              if(a[i] < a[j] + a[k] && a[j] < a[i] + a[k] && a[k] < a[j] + a[i] )
              {
                 cnt++;
                /*mp[{i,j,k}]++;
                mp[{j,i,k}]++;
                mp[{i,k,j}]++;
                mp[{j,k,i}]++;
                mp[{k,i,j}]++;
                mp[{k,j,i}]++;*/
              }
            }
         }
      }
   /* for(auto x : mp)
       cerr<<get<0>(x.ff)<<" "<<get<1>(x.ff)<<" "<<get<2>(x.ff)<<END;
    cout<<cnt<<" ";*/
    cout<<cnt;
  }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3648
use std::collections::BinaryHeap;

#[derive(Debug, Clone, Copy)]
struct Edge {
    from: usize,
    to: usize,
    weight: i64,
}

use std::cmp;
use std::cmp::Ordering;
impl cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> Ordering {
        match self.weight.cmp(&other.weight) {
            Ordering::Equal => Ordering::Equal,
            Ordering::Less => Ordering::Greater,
            Ordering::Greater => Ordering::Less,
        }
    }
}

impl cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl cmp::Eq for Edge {}

impl cmp::PartialEq for Edge {
    fn eq(&self, other: &Self) -> bool {
        self.weight == other.weight
    }
}

impl Edge {
    fn new(from: usize, to: usize, weight: i64) -> Self {
        Self { from, to, weight }
    }
}

fn solve(graph: Vec<Vec<(usize, i64)>>) {
    let size = graph.len();
    let mut is_in_tree: Vec<bool> = vec![false; size];
    let mut num_of_nodes = 0;
    let mut edges = BinaryHeap::new();
    let mut min_weight = 0;
    // Initialize
    is_in_tree[0] = true;
    num_of_nodes += 1;
    for &(to, weight) in &graph[0] {
        edges.push(Edge::new(0, to, weight));
    }
    while num_of_nodes < size {
        let Edge { from, to, weight } = edges.pop().unwrap();
        if is_in_tree[to] {
            continue;
        } else {
            is_in_tree[to] = true;
            num_of_nodes += 1;
            min_weight += weight;
            for &(to, weight) in &graph[to] {
                edges.push(Edge::new(from, to, weight));
            }
        }
    }
    println!("{}", min_weight);
}

use std::io::{BufRead, BufReader};
fn main() {
    let mut read = BufReader::new(std::io::stdin())
        .lines()
        .filter_map(|e| e.ok());
    let (v, _e) = {
        let line = read.next().unwrap();
        let line: Vec<&str> = line.split(' ').collect();
        let v: usize = line[0].parse().unwrap();
        let e: usize = line[1].parse().unwrap();
        (v, e)
    };
    let graph = {
        let mut graph: Vec<Vec<_>> = vec![vec![]; v]; // Adj list
        for edge in read {
            if edge.is_empty() {
                break;
            }
            let mut edge = edge.split(' ');
            let start: usize = edge.next().unwrap().parse().unwrap();
            let end: usize = edge.next().unwrap().parse().unwrap();
            let weight: i64 = edge.next().unwrap().parse().unwrap();
            graph[start].push((end, weight));
            graph[end].push((start,weight));
        }
        graph
    };
    solve(graph);
}



Measured memory_bytes: 20628