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

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

#define PR pair<int, int>
#define MP make_pair
#define TO first
#define NUM second

int n;
const int MAXN = 2002000;
struct tree { PR s[3]; int val; bool lazy; } t[MAXN];
int top = 1;

void build (int x, int st, int tmp, int val) {
    if (st == n) { t[x].val = val; return; }
    t[x].s[0] = MP(++top, 0); build(t[x].s[0].TO, st + 1, tmp * 3, val + tmp * 0);
    t[x].s[1] = MP(++top, 1); build(t[x].s[1].TO, st + 1, tmp * 3, val + tmp * 1);
    t[x].s[2] = MP(++top, 2); build(t[x].s[2].TO, st + 1, tmp * 3, val + tmp * 2);
}

PR fnd (int x) {
    int u, v;
    if (t[x].s[0].NUM == 1) u = 0;
    if (t[x].s[1].NUM == 1) u = 1;
    if (t[x].s[2].NUM == 1) u = 2;
    if (t[x].s[0].NUM == 2) v = 0;
    if (t[x].s[1].NUM == 2) v = 1;
    if (t[x].s[2].NUM == 2) v = 2;
    return MP(u, v);
}

void pushdown (int x) {
    if (!t[x].lazy) return;
    t[x].lazy = false;
    for (int i = 0; i < 3; i++) {
        PR tmp = fnd(t[x].s[i].TO);
        int rua = t[x].s[i].TO;
        swap(t[rua].s[tmp.first].NUM, t[rua].s[tmp.second].NUM);
    }
    t[t[x].s[0].TO].lazy ^= 1, t[t[x].s[1].TO].lazy ^= 1, t[t[x].s[2].TO].lazy ^= 1;
}

void mod1 (int x) {
    if (!t[x].s[0].TO) return;
    pushdown(x);
    ++t[x].s[0].NUM, ++t[x].s[1].NUM, ++t[x].s[2].NUM;
    if (t[x].s[0].NUM == 3) t[x].s[0].NUM = 0, mod1(t[x].s[0].TO);
    if (t[x].s[1].NUM == 3) t[x].s[1].NUM = 0, mod1(t[x].s[1].TO);
    if (t[x].s[2].NUM == 3) t[x].s[2].NUM = 0, mod1(t[x].s[2].TO);
}

void mod2 (int x) {
    if (!t[x].s[0].TO) return;
    PR tmp = fnd(x);
    swap(t[x].s[tmp.first].NUM, t[x].s[tmp.second].NUM);
    t[x].lazy ^= 1;
}

int ans[MAXN];
void query (int x, int st, int val) {
    if (!t[x].s[0].TO) { ans[t[x].val] = val; return; }
    pushdown(x);
    query(t[x].s[0].TO, st * 3, val + st * t[x].s[0].NUM);
    query(t[x].s[1].TO, st * 3, val + st * t[x].s[1].NUM);
    query(t[x].s[2].TO, st * 3, val + st * t[x].s[2].NUM);
}

int main () {
    n = read();
    build(1, 0, 1, 0);
    char c = getchar();
    while (c != 'S' && c != 'R') c = getchar();
    while (c == 'S' || c == 'R') {
        if (c == 'S') mod2(1);
        else mod1(1);
        c = getchar();
    }
    query(1, 1, 0);
    int tmp = 1;
    while (n--) tmp *= 3;
    for (int i = 0; i < tmp; i++) printf("%d ", ans[i]);
    return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	ll a, b, n;
	cin>>a>>b>>n;
	ll elem = min(n, b-1);
	cout<<(a*elem)/b<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3652
w, h, n = map(int, input().split())
xya = [map(int, input().split()) for _ in range(n)]

can = [[1] * w for _ in range(h)]

# for c in can:
#     print(c)

# print()

for x, y, a in xya:
    if a == 1:
        for i in range(h):
            can[i][0:x] = [0] * x
    if a == 2:
        for i in range(h):
            can[i][x:] = [0] * (h - x)
    if a == 3:
        for i in range(h - y, h):
            can[i] = [0] * w
    if a == 4:
        for i in range(h - y):
            can[i] = [0] * w

# for c in can:
#     print(c)

ans = sum([sum(cw) for cw in can])
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int N;
vector<int> S;

bool binary_search(int x) {
    int ok = 0;
    int ng = N;
    while (ok < ng) {
        int mid = (ok + ng) / 2;
        if (S[mid] < x) {
            ok = mid + 1;
        } else if (x < S[mid]) {
            ng = mid;
        } else {
            return true;
        }
    }

    return false;
}

int main() {
    cin >> N;
    S.resize(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    sort(S.begin(), S.end());
    
    int q; cin >> q;
    int cnt = 0;
    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (binary_search(t)) cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<string>
using namespace std;
int main() {
 string a; 
 while(cin >> a, a != "0") {
 int sum = 0;
 for(string::iterator it = a.begin(); a.end() != it; ++it) {
 sum+= (int)(*it-'0');
 }
 cout << sum << endl;
 }
 

}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

unordered_map<string,bool> memo;
bool solve(string s) {
    if(EXIST(memo,s)) return memo[s];
    if(s=="") return memo[s]=true;
    int n=SZ(s);
    if(s[0]!='m'||s[n-1]!='w') return memo[s]=false;
    REP(i,n) {
        if(s[i]=='e') {
            if(solve(s.substr(1,i-1)) and solve(s.substr(i+1,n-i-2))) {
                return memo[s]=true;
            }
        }
    }
    return memo[s]=false;
}
signed main() {
    string s;
    cin>>s;
    cout<<(solve(s)?"Cat":"Rabbit")<<endl;
    return 0;
}

Measured memory_bytes: 7112
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  string S;
  
  cin >> n ;
  cin >> S ;
  
  map<char,long long> count;
  
  for(int i=0; i<n; i++){
    count[S.at(i)]++;
  }
  
  long long nocount;
  
  for(int i=1; i<n-1; i++){
    for(int j=0; j<min(i,n-i-1); j++){
      if(S.at(i)!=S.at(i+j+1)&&S.at(i-j-1)!=S.at(i)&&S.at(i-j-1)!=S.at(i+j+1)){
        nocount++;
      }
    }
  }

  long long ans;
  
  ans=count['R']*count['B']*count['G']-nocount;
    
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll n, a, b;

ll solve() {
    return a * (n / (a + b)) + min(a, n - (a + b) * (n / (a + b)));
}

void input() {
    cin >> n >> a >> b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3216
#!/usr/bin/env python3
#AGC32 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
m = n*(n-1)//2
ans = []
for i in range(n):
    for j in range(i+1,n):
        ans.append((i+1,j+1))
lst = []
if n % 2:
    for i in range(n//2):
        lst.append((i+1,n-i-1))
        m -= 1
else:
    for i in range(n//2):
        lst.append((i+1,n-i))
        m -= 1
for i,j in lst:
    ans.remove((i,j))
print(m)
for i,j in ans:
    print(i,j)


Measured memory_bytes: 43248
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
int main() {
  string d;
  cin>>d;
  ll n=d.size();

  ll ans=MAX;
  char target;
  loop(u,'z'-'a'+1){
    char x=(char)('a'+u);
      target=x;
  ll count=0;
  bool check=true;
    string s=d;
  loop(y,100){
    check=true;
    ll w=s.size();
    loop(i,w-1){
      if(s[i+1]!=s[i])check=false;
    }
    if(check){
      ans=min(ans,count);
      break;
    }
    string t;
  loop(i,w-1){
    if(s[i]==target||s[i+1]==target)s[i]=target;
    else s[i]=s[i];
  }
    loop(i,w-1){
      t+=s[i];
    }
    s=t;
    count++;
  }
  }
  putout(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, i, j, l, t;
    ll k, dp[100][53][53] = {}, ans[100][53][53] = {}, tans;

    scanf("%d%lld", &n, &k);
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        scanf("%lld", &dp[0][i][j]);
    }

    for (i = 0; i < n; i++) {
        ans[0][i][i] = 1;
    }

    for (t = 0; t <= 80; t++) {
        for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (l = 0; l < n; l++) {
            dp[t + 1][i][j] = (dp[t + 1][i][j] + dp[t][i][l] * dp[t][l][j] % mod) % mod;
        }
        if (k % 2 == 1) {
            for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (l = 0; l < n; l++) {
                ans[t + 1][i][j] = (ans[t + 1][i][j] + ans[t][i][l] * dp[t][l][j] % mod) % mod;
            }
        }
        else {
            for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
                ans[t + 1][i][j] = ans[t][i][j];
            }
        }
        k /= 2;
    }

    tans = 0;
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        tans = (tans + ans[t][i][j]) % mod;
    }

    printf("%lld\n", tans);

    return 0;
}

Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
struct monster {
  int at, hp;
};
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  monster a, b;
  cin >> a.hp >> a.at >> b.hp >> b.at;
  while (a.hp > 0 && b.hp > 0) {
    b.hp -= a.at;
    if (b.hp <= 0) break;
    a.hp -= b.at;
  }
  cout << (a.hp > 0 ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(){
  int h,r;
  cin >>h>>r;
  if(h+r>0){
    cout <<1<<endl;
  }else if(h+r==0){
    cout <<0<<endl;
  }else{
    cout <<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

int N, K;
std::string S;

int main(int argc, char **argv) {
    std::cin >> N >> K;
    std::cin >> S;

    std::vector<std::pair<int, int>> seg;

    int loc = 0;
    int left, right;
    while (loc < S.size()) {
        if (S[loc] == '0') {
            if (loc == 0 || S[loc-1] == '1') {
                left = loc;
            }

            if (loc == S.size() - 1 || S[loc+1] == '1') {
                right = loc;
                seg.push_back(std::pair<int, int>({left, right}));
            }
        }
        loc++;
    }

    if (seg.size() <= K) {
        std::cout << N << std::endl;
        return 0;
    }

    //for (int i = 0; i < seg.size(); i++) {
    //    std::cout << seg[i].first << " " << seg[i].second << std::endl;
    //}
    

    int ret = 0;
    for (int i = 0; i + K <= seg.size(); i++) {
        int left, right;
        if (i == 0) {
            left = 0;
        } else {
            left = seg[i-1].second + 1;
        }

        if (i + K - 1 == seg.size() - 1) {
            right = S.size() - 1;
        } else {
            right = seg[i + K].first - 1;
        }
        
        int tmp = right - left + 1;
        //std::cout << "tmp:" << left << " " << right << " " << tmp << std::endl;
        ret = std::max(ret, tmp);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

int main(void) {
	vector<int> like;
	int num = 0;
	int rabbit = 0;
	int count = 0;
	like.push_back(0);
	cin >> num;
	vector<int> check(num + 1, 0);
	rep(0, num) {
		cin >> rabbit;
		like.push_back(rabbit);
	}
	rep(1, num + 1) {
		int r_like = like[i];
		if (i == like[r_like] &&  check[r_like ]== 0) {
			count++;
			check[i] = 1;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <stdlib.h>

#define N 100

void push(int);
int pop(void);

int stack[N];
int top = 0;


int main() {
  int n, ans, num1, num2, status;
  char c[N];
  
  while(1) {

    if (scanf("%s", c) == EOF) break;
    
    else if (c[0] >= '0' && c[0] <= '9') {
      n = atoi(c);
      push(n);
    }
    else if (c[0] == '+') {
      num1 = pop();
      num2 = pop();
      n = num1 + num2;
      push(n);
    }
    else if (c[0] == '-') {
      num2 = pop();
      num1 = pop();
      push(num1 - num2);
    }
    else if (c[0] == '*') {
      num1 = pop();
      num2 = pop();
      push(num1 * num2);
    }
  }
  
  ans = pop();

  printf("%d\n", ans);

  return 0;

}



void push(int n) {
  if (top == N) {
    printf("Stack overflow!\n");
    exit(2);
  }
  stack[top] = n;
  top++;
}

int pop(void) {
  if (top == 0) {
    printf("Stack is empty!\n");
    exit(3);
  }
  top--;
  return stack[top];
}



Measured memory_bytes: 2044
use proconio::*;
use std::cmp::max;

fn main() {
    input! {
        n :usize,
        a: [i64; n],
    }

    let mut res = a[0];
    for i in 1..n {
        res = lcm(res, a[i]);
    }
    println!("{}", res);
}

fn gcd(x: i64, y: i64) -> i64 {
    if x % y == 0 {
        return y;
    }
    gcd(y, x % y)
}

fn lcm(x: i64, y: i64) -> i64 {
    x / gcd(x, y) * y
}


Measured memory_bytes: 2164
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
ll y=200005;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}
vector<ll int>ed[400010];
ll cx,cy;
ll n,m,q;
int vis[400005];
void dfs(int i){
	if(vis[i])return;
	vis[i]=1;
	if(i>=y)cy++;
	else cx++;
	for(int j:ed[i])dfs(j);
}
void solve(){
	cin>>n;
	int x[n];
	for(int i=0;i<n;i++){
		int u,v;
		cin>>u>>v;
		x[i]=u;
		ed[u].pb(y+v);
		ed[y+v].pb(u);
	}
	ll res=0;
	for(int i=0;i<n;i++){
		if(vis[x[i]])continue;
		dfs(x[i]);
		res+=cx*cy;
		cx=cy=0;
	}
	cout<<res-n;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
long long Q,H,S,D,N,ans,k;
int main()
{
    cin>>Q>>H>>S>>D>>N;
    k=min(Q*4,min(H*2,S));
    if(k*2<=D)cout<<k*N<<endl;
    else cout<<((N%2)*k)+N/2*D<<endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n - 1; ++i){
        cin >> arr[i];
    }
    int ans = 0;
    for(int i = 0; i < n - 2; ++i){
        ans += min(arr[i], arr[i + 1]);
    }
    ans += arr[0] + arr[n - 2];
    cout << ans;
    return 0;
}


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

int main(){
  int N,K;
    cin>>N;
  cin>>K;
  vector<char> S(N);
  
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
    if(S.at(K-1)=='A'){
      S.at(K-1)='a';
    }else if(S.at(K-1)=='B'){
      S.at(K-1)='b';
    }else{
      S.at(K-1)='c';
    }
  for(int j=0;j<N;j++){
    cout<<S.at(j);
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	int n,m,i,j,k,l;
	char a[50][51],b[50][51];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%s",a[i]);
	}
	for(i=0;i<m;i++){
		scanf("%s",b[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<m;k++){
				for(l=0;l<m;l++){
					if(a[i+k][j+l]!=b[k][l]){
						goto LOOP_END;
					}
				}
			}
			LOOP_END:
			if(k==m&&l==m){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 128
import itertools
N=int(input())
LN=list(input().split(' '))
LN.sort(key=int)
LN_sort=list(dict.fromkeys(LN))
cbn=list(itertools.combinations(LN_sort,3))
cnt=int(0)
for i in range(len(cbn)):
    if int(cbn[i][0])+int(cbn[i][1])>int(cbn[i][2]):
        cnt+=LN.count(cbn[i][0])*LN.count(cbn[i][1])*LN.count(cbn[i][2])

print(cnt)

Measured memory_bytes: 20484
// たぶんDP
#include <bits/stdc++.h>
using namespace std;

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int H, W, D;
vector<pair<int, int>> A;
int Q;

int main(void) {
    cin >> H >> W >> D;
    A.resize(H * W + 1);
    REP(x, 0, H) {
        REP(y, 0, W) {
            int a;
            cin >> a;
            A[a] = pair<int, int>(x, y);
        }
    }

    int d[90001] = {};
    for(int i = D + 1; i <= H * W; ++i) {
        d[i] = d[i - D] + abs(A[i].first - A[i - D].first) + abs(A[i].second - A[i - D].second);
    }

    cin >> Q;
    rep(i, Q) {
        int L, R;
        cin >> L >> R;
        cout << d[R] - d[L] << endl;
    }

    return 0;
}

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

string S,T;

int main(){

    cin>>S>>T;
    string R,U;
    int n = S.size();
    for(int i;i<S.size();i++){
        U=S[S.size()-1];
        R=S.erase(S.size()-1);
        
        S=U+R;
        
        if(S==T){
            cout<<"Yes"<<endl;
            break;
        }
        n=n-1;
    }    
    if(n==0) cout<<"No"<<endl;
 return 0;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int sum=0;
int dp(int a,int b,int c)
{
    if(a==b&&b==c)
    {
        return 1;
    }
    else if(a==(b-2)&&c==(b-1))
    {
        sum++;
        dp(a+2,b,c);

    }
    else if(a==(c-2)&&b==(c-1))
    {
        sum++;
        dp(a+2,b,c);

    }
    else if(b==(a-2)&&c==(a-1))
    {
        sum++;
        dp(a,b+2,c);

    }
    else if(b==(c-2)&&a==(c-1))
    {
        sum++;
        dp(a,b+2,c);

    }
    else if(c==(a-2)&&b==(a-1))
    {
        sum++;
        dp(a,b,c+2);

    }
    else if(c==(b-2)&&a==(b-1))
    {
        sum++;
        dp(a,b,c+2);

    }

    else if(b<a&&c<a)
    {
        sum++;
        dp(a,b+1,c+1);

    }
    else if(a<b&&c<b)
    {
        sum++;
        dp(a+1,b,c+1);
    }
    else if(a<c&&b<c)
    {
        sum++;
        dp(a+1,b+1,c);

    }
    else if(a<b&&b==c)
    {
        sum++;
        dp(a+2,b,c);

    }
    else if(a<c&&b==c)
    {
        sum++;
        dp(a+2,b,c);

    }
    else if(b<a&&a==c)
    {
        sum++;
        dp(a,b+2,c);

    }
    else if(b<c&&a==c)
    {
        sum++;
        dp(a,b+2,c);

    }
    else if(c<a&&a==b)
    {
        sum++;
        dp(a,b,c+2);

    }
    else if(c<b&&a==b)
    {
        sum++;
        dp(a,b,c+2);

    }
    return sum;
}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==0&&b==0&&c==0)
    {
        cout<<"0"<<endl;
    }
    else if(a==b&&b==c)
    {
        cout<<"0"<<endl;
    }
    else
    cout<<dp(a,b,c)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
#define NN 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mem(a,n) memset(a,n,sizeof(a))
void AIA() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
//cout<<fixed<<setprecision(20);
// freopen("stand.in","r",stdin);
// freopen("stand.out","w",stdout);
bool isprime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0)return 0;
	}
	return (n!=1);
}
ll gcd(ll x, ll y)
{
	return (y == 0 ? x : gcd(y, x % y));
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll rem(int x, int N){
	return (x % N + N) % N;
}

int main()
{
	//cout<<fixed<<setprecision(20);
	//freopen("Input.txt.txt", "r", stdin);
	//freopen("Output.txt.txt", "w", stdout);
	AIA();
	string s;
	cin>>s;
	if(s.back() == 's'){
		cout<<s<<"es";
	}
	else cout<<s<<'s';
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<int,int> m;
    int d[n];
    rep(i,n){
        cin >> d[i];
        m[d[i]]++;
    }
    if(n >= 23) {
        bool can = true;
        for(auto x : m) {
            if(x.second > 2) can = false;
            if(x.first == 12 && x.second >= 2) can = false;
            if(x.first == 0) can = false;
        }
        cout << (can? "1" : "0") << endl;
        return 0;  
    }
    int ans = 0;
    rep(i,1<<n){
        int a[n+1] = {};
        a[n] = 0;
        rep(j,n){
            if(d[j] == 0) a[j] = 0;
            else if(i & (1<<j)) a[j] = d[j];
            else a[j] = 24-d[j];
        }
        int c = 25;
        for(int j = 0; j <= n; j++){
            for(int k = j+1; k <= n; k++) {
                int g = min(abs(a[j]-a[k]),24-abs(a[j]-a[k]));
                c = min(c,g);
            }
        }
        ans = max(ans,c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
import math

N, M = map(int, input().split())
A = [ -int(a) for a in input().split() ]
heapq.heapify(A)
for m in range(M):
    heapq.heappush(A, math.ceil(heapq.heappop(A) / 2.0))

print(-sum(A))


Measured memory_bytes: 14532
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int N; std::cin >> N;

  std::vector<int> A(N);
  for(int i=0; i<N; i++) std::cin >> A[i];
  std::sort(A.begin(), A.end(), [] (int &x, int &y) { return x>y; });

  int ans = 0;
  for(int i=1; i<N-1; i++) {
    if ( A[i] >= 0 ) ans += A[i];
    else ans -= A[i];
  }
  ans += ( A.front() - A.back() );
  std::cout << ans << std::endl;


  int H = A.front(), B = A.back();
  for(int i=1; i<N-1; i++) {
    if ( A[i] >= 0 ) {
      std::cout << B << " " << A[i] << std::endl;
      B -= A[i];
    }
    else {
      std::cout << H << " " << A[i] << std::endl;
      H -= A[i];
    }
  }
  std::cout << H << " " << B << std::endl;
  return 0;
}

Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n; cin >> n;
  cout << n/3 << endl;
}

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

const ll tenPowEighteen = 1000000000000000000;

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

    set<ll> st;
    map<ll,ll> mp;
    for(ll i=2;i<=1000000;i++)
    {
        while((n%i) == 0)
        {
            st.insert(i);
            mp[i]++;
            n /= i;
        }
    }

    if(n>1)
    {
        st.insert(n);
        mp[n]++;
    }
    ll ans = 0;
    for(auto it:st)
    {
        ll val = mp[it];

        ll sum = 0;
        for(ll i=1;i<100;i++)
        {
            sum += i;
            if(sum<=val)  ans++;
            else        break;
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    x,y,a,b,c = map(int,input().split())
    R = list(map(int,input().split()))
    G = list(map(int,input().split()))
    M = list(map(int,input().split()))
    i,j,k = 0,0,0
    R.sort(reverse = True)
    G.sort(reverse = True)
    M.sort(reverse = True)
    
    ans = 0
    while i < x and j < y and k < c and k + i + j < x + y:
        tmp = max(R[i],G[j],M[k])
        ans += tmp
        if tmp == R[i]:
            i += 1
        elif tmp == G[j]:
            j += 1
        else:
            k += 1
    
    if i + j + k == x + y:
        print(ans)
        return
    
    elif k == c:
        while i < x and j < y and i + j + c < x + y:
            tmp = max(R[i],G[j])
            ans += tmp
            if tmp == R[i]:
                i += 1
            elif tmp == G[j]:
                j += 1

    if i + j + k == x + y:
        print(ans)
        return            

    elif i == x:
        t = y - k - j
        for _ in range(t):
            if k < c and G[j] < M[k]:
                ans += M[k]
                k += 1
            else:
                ans += G[j]
                j += 1
    elif j == y:
        t = x - i - k
        for _ in range(t):
            if k < c and R[i] < M[k]:
                ans += M[k]
                k += 1
            else:
                ans += R[i]
                i += 1


    
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 22720
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll n, A[200009];
ll calc(ll a){
  ll ret = 0;
  FOR(i, 0, n){
    ret += abs(A[i] - a - i - 1);
  }
  return ret;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> A[i];
  ll l = -iinf-9, r = iinf + 9, m1, m2, s1, s2;
  while(r - l > 2){
    m1 = (l + l + r) / 3;
    s1 = calc(m1);
    m2 = (l + r + r) / 3;
    s2 = calc(m2);
    if(s1 < s2){
      r = m2;
    }else{
      l = m1;
    }
  }
  ll ans = linf;
  FOR(i, l, r + 1) mins(ans, calc(i));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    stack<int>s1;
    stack<Pin>s2;
    string ch;
    int sum=0;
    cin>>ch;
    for(int i=0;i<ch.length();i++){
        if(ch[i]=='\\')s1.push(i);
        else if(ch[i]=='/'&&s1.size()>0){
            int j=s1.top();s1.pop();
            sum+=i-j;
            int a=i-j;
            while(s2.size()>0&&s2.top().fi>j){
                a+=s2.top().se;s2.pop();
            }
            s2.push(mp(j,a));
        }
    }
    V<int>ans;
    while(s2.size()){
        ans.pb(s2.top().se);
        s2.pop();
    }
    reverse(all(ans));
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i=0;i<ans.size();i++){
        cout<<" "<<ans[i];
    }cout<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------















































Measured memory_bytes: 3340
#include <stdio.h>

#define N 20
#define Q 200

int n;
int a[N];

int solve(int, int);

int main()
{

  int q, i, j, s;
  int m[Q];

  scanf("%d", &n);

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

  scanf("%d", &q);

  for(j=0; j<q; j++){
    scanf("%d", &m[j]);
  }

  for(i=0; i<q; i++){
      s = solve(0, m[i]);
      if(s == 1){
	printf("yes\n");
      }
      else if(s == 0){
	printf("no\n");
      }
  }

  return 0;
}

int solve(int i,int m)
{

  if(m == 0) return 1;

  if(i >= n) return 0;

  if((solve(i+1, m) == 1) || (solve(i+1, m-a[i]) == 1))
    return 1;

}

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

int main() {
  int n;
  cin >> n;
  vector<char> vec(n);
  int tmp = 0;
  for (int i = 0; i < vec.size(); i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < vec.size(); i++) {
    if (vec.at(i) == 'Y') {
      tmp++;
    }
  }
  if (tmp > 0) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

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

      int n = Integer.parseInt(sc.next());
      int W = Integer.parseInt(sc.next());

      long[][] dp = new long[n][W+1];

      long[] w = new long[n];
      long[] v = new long[n];
      for(int i=0;i<n;i++){
        w[i] = Long.parseLong(sc.next()); //w
        v[i] = Long.parseLong(sc.next()); //v
      }

        for(int j=0;j<=W;j++){
          if(w[0]<=j){
            dp[0][j] = v[0];
          }
        }


      for(int i=1;i<n;i++){ //今選ぼうとしてるやつ
        for(int j=0;j<=W;j++){ //選ぶ前の重さ
          if(j-w[i]>=0){ //w[i]を足した後は当然w>=j>=w[i]。
            dp[i][j] = Math.max(dp[i][j],dp[i-1][j-(int)w[i]]+v[i]);
          }
         //超えるなら選べない or i単体の方が大きい。
         dp[i][j] = Math.max(dp[i][j],dp[i-1][j]);
        }
      }

      System.out.println(dp[n-1][W]);
/*
      for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
          if(j!=W){System.out.print(dp[i][j]+" ");}
          else{System.out.println(dp[i][j]);}
        }
      }
*/

    }
}


Measured memory_bytes: 128084
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;/*
ll a[110];
int main(){
    ll n,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0;
    ll ans=0;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n){
        if(a[i]>=3200)a1++;
        else if(a[i]>=2400)a2++;
        else if(a[i]>=2000)a3++;
        else if(a[i]>=1600)a4++;
        else if(a[i]>=1200)a5++;
        else if(a[i]>=800)a6++;
        else if(a[i]>=400)a7++;
        else a8++;
    }
    if(a2>0)ans++;
    if(a3>0)ans++;
    if(a4>0)ans++;
    if(a5>0)ans++;
    if(a6>0)ans++;
    if(a7>0)ans++;
    if(a8>0)ans++;

    if(ans==0)cout<<"1"<<" ";
    else cout<<ans<<" ";
    cout<<ans+a1;
}*/
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll t[110];
int main(){
    ll n;
    cin>>n;
    rep(i,0,n)cin>>t[i];
    ll ans=t[0];
    rep(i,1,n){ans=ans/GCD(ans,t[i]);ans*=t[i];}
    cout<<ans;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
	
#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
	
template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
int i=0;
for(auto it:v){
	if(i > 0){os << ' ';}
	os << it;
	i++;
} 
return os;
}
template<class T,class TT> ostream& operator <<(ostream &os, const map<T,TT> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	} 
return os;
}
using ll = long long ;


int main(){
	ios::sync_with_stdio(false);
	// int X,Y;cin>>X>>Y;
	// map<int,int>mp;
	// int ans=0;
	// if(X<=3){
	// 	ans+=4-X;
	// }
	// if(Y<=3)ans+=4-Y;
	// if(X==1&&Y==1)ans+=1;
	// cout<<ans*100000<<endl;

	// int H,W,K;cin>>H>>W>>K;
	// vector<string>field(H);
	// for(int i=0;i<H;++i){
	// 	cin>>field[i];
	// }
	// vector<vector<int>>types(H,vector<int>(W));
	// int id=0;

	// int ah=-1;
	// int preh=-1;
	// for(int y=0;y<H;++y){
	// 	vector<int>stos;
	// 	for(int x=0;x<W;++x){
	// 		if(field[y][x]=='#')stos.push_back(x);
	// 	}
	// 	if(stos.empty()){
	// 		if(preh==-1){
	// 		}else{
	// 			types[y]=types[preh];
	// 		}
	// 	}else{
	// 		if(ah==-1)ah=y;
	// 		preh=y;
	// 		int cnt=-1;
	// 		for(int x=0;x<W;++x){
	// 			if(field[y][x]=='#'){
	// 				cnt++;
					
	// 			}
	// 			if(cnt==-1){
	// 				types[y][x]=id;
	// 			}else{
	// 				types[y][x]=id+cnt;
	// 			}
	// 		}
	// 		id+=cnt+1;
	// 	}
	// }
	// for(int y=0;y<ah;++y){
	// 	types[y]=types[ah];
	// }
	// for(int y=0;y<H;++y){
	// 	for(int x=0;x<W;++x){
	// 		cout<<types[y][x]+1;
	// 		if(x==W-1)cout<<endl;
	// 		else cout<<' ';
	// 	}
	// }

	int N;cin>>N;
	ll len=0;
	ll sum=0;
	for(int i=0;i<N;++i){
		ll a,b;cin>>a>>b;
		len+=b;
		sum+=a*b;
	}
	ll answer=0;
	answer+=len-1;
	answer+=sum>=10?((sum-1)/9):0;
	cout<<answer<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<deque>
using namespace std;
int n;
long c,h[2<<17];
long dp[2<<17];
long f(int i,int H)
{
	return dp[i]+h[i]*h[i]-2*H*h[i];
}
bool check(int x,int y,int z)
{
	long a1=-2*h[x],b1=dp[x]+h[x]*h[x],a2=-2*h[y],b2=dp[y]+h[y]*h[y],a3=-2*h[z],b3=dp[z]+h[z]*h[z];
	return (a1-a2)*(b2-b3)>=(b1-b2)*(a2-a3);
}
main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)cin>>h[i];
	deque<int>P;
	P.push_back(0);
	for(int i=1;i<n;i++)
	{
		while(P.size()>1&&f(P[0],h[i])>=f(P[1],h[i]))P.pop_front();
		dp[i]=h[i]*h[i]+c+f(P[0],h[i]);
		while(P.size()>1&&check(P[P.size()-2],P[P.size()-1],i))P.pop_back();
		P.push_back(i);
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
// #define mod 1000000007
#define mod 998244353
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int N,P[259999];
int V[555][555];
int Hk[555][555];

int getx(int val) {
  return (val-1)/N;
}

int gety(int val) {
  return (val-1)%N;
}

int getid(int x, int y){
  return N*x+y+1;
}

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

void dfs(int x, int y, int val) {
  rep(i,4) {
    int nx = x + dx[i], ny = y + dy[i];
    if(nx >= N || nx < 0) continue;
    if(ny >= N || ny < 0) continue;

    if(val < Hk[nx][ny]) {
      Hk[nx][ny] = val;
      dfs(nx,ny,val+V[nx][ny]);
    }
  }
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

  cin>>N;
  rep(i,N*N)cin>>P[i];
  rep(i,N)rep(j,N) {V[i][j]=1;Hk[i][j]=min(min(i,j),N-1-max(i,j));}

  int ans=0;
  rep(k,N*N) {
    int x = getx(P[k]), y = gety(P[k]);
    // debug(x);debug(y);
    ans += Hk[x][y];
    V[x][y]=0;
    dfs(x,y,Hk[x][y]);

  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 21744
#!/usr/bin/env python3
#AOJ D
import sys
sys.setrecursionlimit(1000000)

po = [1<<i for i in range(10)]

def solve(n,m,p,a,b):
    a -= 1
    b -= 1
    t = list(map(int,input().split()))
    v = [[] for i in range(m)]#隣接リスト
    for _ in range(p):
        x,y,z = list(map(int,input().split()))
        x -= 1
        y -= 1
        v[x].append((y,z))
        v[y].append((x,z))
    dp = [[float("inf") for _ in range(m)] for _ in range(po[n])]#縦:馬車券の頭数,横:各都市の数
    dp[0][a] = 0
    for i in range(po[n]):
        for j in range(n):
            if i&po[j]:continue#この馬車券の頭数使用済みなら終了
            k = i|po[j]#この馬車券の頭数を使用
            for x in range(m):
                for y,z in v[x]:
                    d = dp[i][x]+z/t[j]#前回までの移動にこの馬車券を用いた場合
                    if d < dp[k][y]:#より短いなら更新
                        dp[k][y] = d
    ans = float("inf")
    for i in range(po[n]):
        if dp[i][b] < ans:#ゴール地点の最小経路を更新しながら求める
            ans = dp[i][b]
    if ans == float("inf"):#ゴールできないなら
        print("Impossible")
    else:
        print(ans)

while 1:
    n,m,p,a,b = list(map(int,input().split()))
    if n == 0:
        break
    solve(n,m,p,a,b)



Measured memory_bytes: 5908
import sys
from operator import itemgetter
 
inf = 1 << 30
 
def solve():
    n = int(sys.stdin.readline())
 
    # r_max = MAX, b_min = MIN にしたとき
 
    r_max = b_max = 0
    r_min = b_min = inf

    p = []
 
    for i in range(n):
        xi, yi = map(int, sys.stdin.readline().split())

        if xi > yi:
            xi, yi = yi, xi

        p.append((xi, yi))

        r_max = max(r_max, yi)
        r_min = min(r_min, yi)
        b_max = max(b_max, xi)
        b_min = min(b_min, xi)
 
    ans1 = (r_max - r_min) * (b_max - b_min)
 
    # r_max = MAX, r_min = MIN にしたとき
 
    ans2 = (r_max - b_min)

    p.sort(key=itemgetter(0))

    b_min = p[0][0]
    b_max = p[-1][0]

    y_min = inf

    dif_b = b_max - b_min
 
    for i in range(n - 1):
        if p[i][1] == r_max:
            break
        y_min = min(y_min, p[i][1])

        b_min = min(p[i + 1][0], y_min)
        b_max = max(b_max, p[i][1])

        dif_b = min(dif_b, b_max - b_min)
 
    ans2 *= dif_b
 
    ans = min(ans1, ans2)
 
    print(ans)
 
if __name__ == '__main__':
    solve()

Measured memory_bytes: 33948
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * http://abc069.contest.atcoder.jp/tasks/arc080_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int H = sc.nextInt();
		final int W = sc.nextInt();
		final int N = sc.nextInt();
		List<Integer> a = new ArrayList<Integer>();
		for(int i=1; i<=N; i++){
			int num = sc.nextInt();
			for(int j=0; j<num; j++) a.add(i);
		}
		sc.close();
		
		int[][] ans = new int[H][W];		
		for(int y=0; y<H; y++){
			if(y%2==0){
				for(int x=0; x<W; x++){
					ans[y][x] = a.get(0);
					a.remove(0);
				}
			}else{
				for(int x=W-1; x>=0; x--){
					ans[y][x] = a.get(0);
					a.remove(0); 
				}		
			}
		}
		
		for(int y=0; y<H; y++){
			for(int x=0; x<W; x++){
				System.out.print(ans[y][x]);
				if(x!=W-1) System.out.print(" ");
			}
			System.out.println();
		}

	}

}

Measured memory_bytes: 36236