akhauriyash/Code-Regression huggingface dataset:
X, N = map(int, input().split(" "))
if N==0:
  print(X)
  exit()
P = list(map(int, input().split(" ")))
P.sort()

for i in range(N):
  if(P[i] > X):
    L = P[:i][::-1]
    U = P[i:]
    break
  elif(i == N-1):
    L = P[::-1]
    U = []

if (len(L) == 0 or L[0] != X):
  print(X)
  exit()

lans = -1
for i in range(1, len(L)):
  if (L[i-1] - L[i] > 1):
    lans = L[i-1]-1
    break
if(lans == -1):
  lans = L[len(L)-1]-1

if (len(U) == 0 or U[0] != X+1):
  uans = X+1
else:
  uans = -1
  for i in range(1, len(U)):
   if (U[i] - U[i-1] > 1):
      uans = U[i-1]+1
      break
  if(uans == -1):
    uans = U[len(U)-1]+1

if(abs(lans-X) <= abs(uans-X)):
  print(lans)
else:
  print(uans)


Measured memory_bytes: 62256
#include <bits/stdc++.h>
using namespace std;
#define REP(name, start, stop) for (auto(name) = (start); (name) < (stop); (name)++)
using ll = long long;
using vi = vector<ll>;

int main(void) {
    ll n, m;
    cin >> n >> m;
    ll cnt = 0;
    if (n >= 2) {
        cnt += n * (n - 1) / 2;
    }
    if (m >= 2) {
        cnt += m * (m - 1) / 2;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define REP(i , n) for(Long i = 0; i < (Long)n ; i++)
#define pb push_back

using namespace std;

typedef long long Long;

const Long MX = 1e6;
const Long ALPH = 3;

struct Trie{
	Long memo[MX][ALPH];
	Long level[MX];
	Long nodos = 1;
	
	void addWord(string &s){
		Long sz = s.size();
		Long u = 0;
		REP(i , sz){
			Long c = s[i] - '0';
			if(memo[u][c] == 0){
				memo[u][c] = nodos++;
				level[u] = i ;	
			}
			u = memo[u][c];
		}
	}
}trie;


Long f(Long x){
	for(Long i = 0; i < 60; i++){
		if(((x>>i)&1) == 1){
			return i+1;
		}
	}
	return 1;	
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	Long N, L;
	cin >> N >> L;
	REP(i , N){
		string s;
		cin >> s;
		trie.addWord(s);
	}
	Long ans = 0;
	for(Long i = 0; i < trie.nodos; i++){
		if(trie.memo[i][0] != 0 && trie.memo[i][1] == 0){
			ans = ans ^ f(L - trie.level[i]);
			
			
		}
		if(trie.memo[i][0] == 0 && trie.memo[i][1] != 0){
			ans = ans ^ f(L - trie.level[i]);
		}
	}


	if(ans == 0){
		cout << "Bob" << endl;	
	} else {
		cout << "Alice" << endl;	
	}
	return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   ll n; cin >> n;
   int sum = 0;
   ll tmp = n;
   while(n)
   {
      sum += n%10;
      n/=10;
   }
   if(tmp%sum)
      cout << "No" << nl;
   else
      cout << "Yes" << nl;

   return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
    double a,b,c,d,e,f;
    double x, y;
    while (cin>>a>>b>>c>>d>>e>>f) {
        x = (c-(f-(d/a)*c)/(e-(d/a)*b)*b)/a;
        y = (f-(d/a)*c)/(e-(d/a)*b);
        cout << fixed << setprecision(3) << x << " " << y << endl;
    }
}

Measured memory_bytes: 1280
#include<iostream>

int N, K;
int x[100];

int main(){
    std::cin >> N >> K;
    for(int i = 0; i < N; i++){
        std::cin >> x[i];
    }
    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += x[i] < K-x[i] ? x[i] : K-x[i];
    }

    std::cout << sum*2;
    return 0;
}

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



namespace ConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {

            
            int  postition=0,range=0;

            string[] mass = Console.ReadLine().Split(' ');


            int[] result = new int[3];

            int[] listinput = new int[mass.Length];

            for (int i = 0; i < mass.Length; i++)
            {
                listinput[i] = int.Parse(mass[i]);
            }
            range = int.Parse(mass[0]);

            postition = int.Parse(mass[1]);

            int nowposition = postition - (range - 1);

            for(int i= 0; i<=(range-1)*2;i++)
            {

                Console.Write(nowposition);
                Console.Write(" ");
                nowposition++;
            }

            range = 0;

        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define out(x) cout << x << endl;
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n;
	cin >> n;
	if(n < 1200) cout << "ABC" << endl;
	else if(n < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}

Measured memory_bytes: 384
-- https://github.com/minoki/my-atcoder-solutions
-- {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Maybe
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

-- 有向グラフに閉路があるか判定する
hasCycle :: V.Vector [Int] -> Bool
hasCycle edges = (== Nothing) $ runST $ runMaybeT $ do
  let !n = V.length edges  -- 頂点の個数
  seen <- UM.replicate n (0 :: Int) -- 0: new, 1: DFSの最中, 2: チェック済み
  let dfs !x = do
        -- x を通る閉路があるかチェックする
        UM.write seen x 1
        forM_ (edges V.! x) $ \y -> do
          -- 辺 (x,y) が存在
          s <- UM.read seen y
          case s of 0 -> dfs y
                    1 -> mzero -- コールスタックのどこかで dfs y が呼ばれている。閉路
                    _ -> return ()
        UM.write seen x 2
  forM_ [0..n-1] $ \x -> do
    s <- UM.read seen x
    when (s == 0) $ dfs x
  return ()

-- DAGの最長路の長さを返す
longest :: V.Vector [Int] -> Int
longest edges = U.maximum $ U.create $ do
  let n = V.length edges
  vec <- UM.replicate n (-1 :: Int)
  let dfs !x = do
        v <- UM.read vec x
        if v == -1
          then do ys <- mapM dfs (edges V.! x)
                  let !v = 1 + maximum (0 : ys)
                  UM.write vec x v
                  return v
          else return v
  forM_ [0..n-1] $ \i -> dfs i
  return vec

main = do
  n <- readLn
  xs <- V.replicateM n $ do
    U.map (subtract 1) . U.unfoldrN (n-1) (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let m = n * (n - 1) `quot` 2  -- グラフの頂点数
  let -- (i,j) (0 <= i < j < n) を 0 以上 m 未満の整数値にコードする
      makePair :: Int -> Int -> Int
      makePair i j | i < j = n * i - (i + 1) * i `quot` 2 + j - i - 1
                   | otherwise = undefined
  -- 「試合 (i,j) よりも試合 (i',j') の方を後に行う場合に辺 makePair i j → makePair i' j' が存在する」ようなグラフを作る
  let edges :: V.Vector [Int]
      edges = V.create $ do
        e <- VM.replicate m []
        V.forM_ (V.indexed xs) $ \(i,ys) -> do
          U.forM_ (U.zip ys (U.tail ys)) $ \(a,b) -> do
            -- (i,a) -> (i,b)
            let !b' = makePair (min i b) (max i b)
            VM.modify e (b' :) (makePair (min i a) (max i a))
        return e
  print $ if hasCycle edges
          then -1
          else longest edges


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

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

    int h, w, d;
    cin >> h >> w >> d;

    char c[502];
    c[w] = '\n';
    c[w + 1] = 0;

    for (int i = 0; i < h; i++) {
        int x = h - i + d - h % d;
        for (int j = 0; j < w; j++) {
            c[j] = "RYGB"[(i + j) / d % 2 + (x + j) / d % 2 * 2];
        }
        cout << c;
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
 
void solve() {
	int n, x = 0, res = 0;
	 cin >> n;
	 int arr[n];
	 vector<bool> v(1001000, 0);
	 for(int i = 0; i < n; ++i) {
		 cin >> arr[i];
		 }
		 sort(arr, arr + n);
		 for(int i = 0; i < n; ++i) {
			 if(arr[i] == arr[i + 1] && (i + 1 <= n - 1)) {
				 if(v[arr[i]]) continue;
				 v[arr[i]] = 1;
				 for(int j = 2 * arr[i]; j <= 1001000; j += arr[i]) {
					 v[j] = 1;
					 }
					 continue;
				 }
			  if(!v[arr[i]]) res++;
			  v[arr[i]] = 1;
		  for(int j = 2 * arr[i]; j <= 1001000; j += arr[i]) {
			 v[j] = 1;
		 }
	}
	cout << res << endl;
}
 
int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.precision(20);
	solve();
	return 0;
}
 
 


Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#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 all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> c(n-1), s(n-1), f(n-1);
    rep (i, n-1) {
        cin >> c[i] >> s[i] >> f[i];
    }
    rep (i, n) {
        int t = 0;
        rep (j, i, n-1) {
            if (t <s[j]) {
                t = s[j] + c[j];
            } else {
                t = ceil(1.0 * t / f[j]) * f[j] + c[j];
            }
        }
        cout << t << endl;
    }
}


Measured memory_bytes: 256
S = list(input())
S.reverse()
S = "".join(S)
ans = "YES"
while len(S) > 0:
        if S[:5] == "maerd" or S[:5] == "esare":
                S = S[5:]
        elif S[:6] == "resare":
                S = S[6:]
        elif S[:7] == "remaerd":
                S = S[7:]
        else:
                ans = "NO"
                break
print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <cmath>
#define X 1000000007
typedef long long ll;
using namespace std;

ll powdiv(ll m, ll n) {
		if (n == 1) {
				return m % X;
		}
		if (n % 2 == 0) {
				ll a = powdiv(m, n / 2) % X;
				return a * a % X;
		} else {
				ll a = powdiv(m, n / 2) % X;
				return a * a % X * m  % X;
		}
}

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

		cout << powdiv(m, n) << endl;

		return 0;
}

Measured memory_bytes: 3096
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        int n = in.nextInt();
        int [][]arr = new int[n][3];
        for(int i=0;i<n;i++){
            arr[i][0] = in.nextInt();
            arr[i][1] = in.nextInt();
            arr[i][2] = in.nextInt();
        }
        int [][]dp = new int[n][3];
        for(int []i : dp)Arrays.fill(i,-1);
        int ans  = recur(0,arr,-1,dp);
        System.out.println(ans);
    }
    public static int recur(int index,int [][]arr,int prev,int [][]dp){
        if(index==arr.length)return 0;
        int ans = 0;

        if(prev!=-1&&dp[index][prev]!=-1)return dp[index][prev];
        for(int i=0;i<3;i++){
           if(i==prev)continue;
           ans = Math.max(ans,arr[index][i]+recur(index+1,arr,i,dp));
        }
        if(prev==-1)return ans;
        return dp[index][prev] = ans;
    }
}


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

const int maxn = 2e5 + 10;
int n, m, tot, data[maxn];

struct node {
  int l, r;
  
  inline bool operator < (const node &o) const {
    return l < o.l || (l == o.l && r < o.r);
  }
} a[maxn];

priority_queue <int, vector <int>, greater <int> > Q;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].l, &a[i].r);
  }
  int L = 1, R = m;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    Q.push(a[i].r);
    if (L <= R && L <= a[i].l) {
      L++;
    } else {
      data[++tot] = Q.top(), Q.pop();
    }
  }
  int ans = 0;
  sort(data + 1, data + tot + 1);
  for (int i = tot; i; i--) {
    L <= R && R >= data[i] ? R-- : ans++;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 3192
using System;

class main{
public static void Main(String[] g){
string[] s=new string[200];
for(int i=0;i<200;i++){
s[i]=Console.ReadLine();
}

string[] s1=new string[2];
long a, b, d, dk;

foreach(string sa in s){
if(sa==null)continue;
s1=sa.Split(' ');

a=long.Parse(s1[0]);
b=long.Parse(s1[1]);
d=a+b;
dk=d.ToString().Length;
Console.WriteLine(dk);
}

}}

Measured memory_bytes: 8912
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String x = sc.next();
            String y = sc.next();
            //compareToで比較xとyを比較してxが大きいと1が小さいと-1が返ってくる
            if(x.compareTo(y) > 0){
              System.out.println(">");
            } else if(x.compareTo(y) == 0){
              System.out.println("=");
            } else {
              System.out.println("<");
            }
          }
}

Measured memory_bytes: 23252
#include<cstdio>

int n;
char s[20];
int main(){
	scanf("%s",s);

	for(int i = 0;s[i] != '\0';i++)n++;// |s|

	for(int i = 0;i < n;i++)
		s[i] -= '0';

	n--;// n = |s| - 1にする

	long ans = 0;
	for(int S = 0;S < (1 << n);S++) {   //+を入れるか入れないかについてのBIT集合
		long sum = 0;
		long a = s[0];
		for(int i = 0;i < n;i++) {
			if(S & (1 << i)) {
				sum += a;
				a = s[i + 1];
			}else {
				a *= 10;
				a += s[i + 1];
			}
		}
		sum += a;

		ans += sum;
	}
	printf("%ld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n, x, t;
  cin >> n >> x >> t;
  cout << t * (n/x) + t * (n%x != 0) << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3572
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int>a(N);
  int alice=0;
  int bob=0;
  rep(i,N)cin>>a[i];
  sort(a.begin(),a.end());
  rep(i,N){
    if(i%2==0)alice+=a[i];
    else bob+=a[i];
  }
  cout<<abs(alice-bob)<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;


int main()
{
    int N;cin >> N;
    int P[N];
    int cnt=0;
    int min_=1000000007;
    for(int i=0;i<N;++i) cin >> P[i];

    for(int i=0;i<N;++i)
    {
        if(P[i]==min(P[i],min_))
        {
            cnt++;
            min_ = P[i];
        }
    }
    cout << cnt <<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	c=0;
	do{
		scanf("%d%d",&a,&b);
		while(a!=c){
			for(d=0;d!=b;d++){
				printf("#");
			}
			printf("\n");
			c++;
			if(c==a){
				printf("\n");
			}
		}
	c=0;
	}while(a+b!=0);
	return 0;
}

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

int main()
{
    int a,b,i,s=0,c=0,m,j=0;
    cin>>a>>b;
    int arr[a];
    for(i=1;i<=a;i++)
    {
        arr[i-1]=b+i-1;
    }

    m= abs(arr[j]);

     for(i=1;i<a;i++)
     {
         if(m> abs(arr[i]))
         {
            m=abs(arr[i]);
            j=i;
         }

     }

    for(i=0;i<a;i++)
    {
        s+=arr[i];
    }
    c=s-arr[j];

    cout<<c<<endl;



    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
const int N=1e5+5;
int n;

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

namespace G{
	int cnt,fir[N];
	bool linked[N];
	struct edge{
		int to,nx;
	}eg[N<<1];

	inline void add(const int a,const int b){
		eg[++cnt]=(edge){b,fir[a]};
		fir[a]=cnt;
	}

	void dfs(const int x,const int fa){
		for(int i=fir[x]; i; i=eg[i].nx){
			const int y=eg[i].to;
			if(y==fa) continue;
			dfs(y,x);
			if(!linked[y]){
				if(linked[x]) return;
				linked[x]=linked[y]=1;
			}
		}
	}

	bool link(){
		for(int i=1; i<=n; ++i){
			if(!linked[i]) return 0;
		}
		return 1;
	}
}

int main(){
	n=nxi();
	for(int i=1; i<n; ++i){
		const int a=nxi(),b=nxi();
		G::add(a,b);
		G::add(b,a);
	}
	G::dfs(1,1);
	puts(G::link()?"Second":"First");
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int m,d;
  while(cin>>m>>d,m+d){
    int day = 0;
    m--;
    // 2 , 4 , 6 , 9 . 11 
    int month[12] = {31,29,31,30,31,30,
		     31,31,30,31,30,31};
    rep(i,m){
      day+=month[i];
    }
    day=(day + d + 7 - 1)%7;
    switch(day){
    case 0:
      cout<<"Thursday"<<endl;
      break;
    case 1:
      cout<<"Friday"<<endl;
      break;
    case 2:
      cout<<"Saturday"<<endl;
      break;
    case 3:
      cout<<"Sunday"<<endl;
      break;
    case 4:
      cout<<"Monday"<<endl;
      break;
    case 5:
      cout<<"Tuesday"<<endl;
      break;
    case 6:
      cout<<"Wednesday"<<endl;
      break;
    }
    

  }
}

Measured memory_bytes: 1152
S=input()
if S=="RRR" :
  print(3)
elif S=="RRS" :
  print(2)
elif S=="SRR" :
  print(2)
elif S=="RSS" :
  print(1)
elif S=="SRS" :
  print(1)
elif S=="SSR" :
  print(1)
elif S=="RSR" :
  print(1)
else :
  print(0)

Measured memory_bytes: 9072
unittest
{
	assert( [ "4 5" ].parse.expand.solve == "Possible" );
	assert( [ "1 1" ].parse.expand.solve == "Impossible" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( long[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( long a, long b )
{
	return ( ( a % 3 == 0 ) || ( b % 3 == 0 ) || ( ( a + b ) % 3 == 0 ) ) ? "Possible" : "Impossible";
}


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

using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    map<int, int> mp;
    for(int i = 0; i < n; i ++)
    {
        scanf("%d", &a[i]);
        mp[a[i]] ++;
    }
    if(mp.size() == 1)
    {
        printf("%s\n", mp[0] ? "Yes" : "No");
    }
    else if(mp.size() == 2)
    {
        int x = mp[0], y = n - mp[0];
        if(x && x * 2 == y) printf("Yes\n");
        else puts("No");
    }
    else if(mp.size() == 3)
    {
        int x[3], y[3], cur = 0;
        for(auto p : mp)
        {
            x[cur] = p.second;
            y[cur ++] = p.first;
        }
        if(x[0] == x[1] && x[0] == x[2] && (y[0] ^ y[1]) == y[2]) puts("Yes");
        else puts("No");
    }else puts("No");
    return 0;
}


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

int main(){
    int n, q;
    string s;
    cin >> n >> q >> s;

    int l[q+10];
    int r[q+10];
    for (int i = 0; i < q; ++i){
        cin >> l[i] >> r[i];
    }

    int ac_pos[n+1]{0};
    for (int i = 0; i < n; ++i){
        if (i==0){
            continue;
        }
        if (s[i-1]=='A' && s[i]=='C'){
            ac_pos[i] = ac_pos[i-1] + 1;
        }else{
            ac_pos[i] = ac_pos[i-1];
        }
//        cout << "i " << i << " ac_pos[i] " << ac_pos[i] << endl;

    }

    for (int j = 0; j <q; ++j){
//        cout << r[j] << " " <<  l[j] << endl;
        cout << ac_pos[r[j]-1] - ac_pos[l[j]-1] << endl;
    }
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*string s;
	cin >> s;
	rep(i, 3)cout << s[i];*/


	ll a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	if (a <= b) {
		if (a + v * t >= b + w * t)puts("YES");
		else puts("NO");
	}
	else {
		if (a - v * t <= b - w * t)puts("YES");
		else puts("NO");
	}

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,ii,jj;
ll n,m,ans=0,sum;
ll x,y,k;
ll a[100005];
ll hidari,migi,mid;
bool dp[5105][5105];
int dd[5100];
 
 
 
bool solve(ll x){
	if(dd[x]==2){
		return true;
	}else if(dd[x]==1){
		return false;
	}
    //x番目を除いたらどうなるか
    for(i=0;i<n+2;i++){
        for(j=0;j<k+2;j++){
            dp[i][j]=false;
        }
    }
    ll z=1;
	dp[0][0]=true;
    for(i=0;i<n;i++){
        if(i==x)continue;
        for(j=0;j<k;j++){
            if(dp[z-1][j] && j+a[i]<=k+5)dp[z][j+a[i]]=true;
            if(dp[z-1][j])dp[z][j]=true;
        }
        z++;
    }
	bool flag=false;
	y = max(0ll,k-a[x]);
    for(j=y;j<k;j++){
        if(j>=0 && dp[n-1][j])flag=true;
    }
	if(flag){
		dd[x] = 2;
		return true;//必要
	}else{
		dd[x] = 1;
		return false;//不必要
	}
}
 
 // huhitu huhitu huhitu huhitu hitu hitu って並ぶ
 // 1 1 1 1 2 2 2 2 2
int main(){
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    hidari=0;
    migi=n-1;
    while(migi-hidari>8){
        mid=(migi+hidari)/2;
        if(solve(mid)){
            migi=mid;
        }else{
            hidari=mid;
        }
    }
	/*for(int i=0;i<n;i++){
		if(solve(i)){
			pe(i);p("は必要");
		}else{
			pe(i);p("は不必要");
		}
	}*/
    for(ii=hidari-10;ii<=hidari+10;ii++){
        if(ii<0 || ii>=n)continue;
        if(!solve(ii)){
			ans=ii;
		}else{
			ans = ii-1;
			break;
		}
        
    }
	p(ans+1);
    return 0;
}

Measured memory_bytes: 31232
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

const int MAX_N = 2e5 + 10;
int N;
int A[MAX_N], B[MAX_N];

int main()
{
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    cin >> A[i] >> B[i];
  }
  ll mid_a = 0;
  ll mid_b = 0;
  ll result = 0;
  sort(A, A + N);
  sort(B, B + N);
  if (N % 2 == 0)
  {
    mid_a = (A[N / 2 - 1] + A[N / 2]);
    mid_b = (B[N / 2 - 1] + B[N / 2]);
    result = (mid_b - mid_a) + 1;
  }
  else
  {
    mid_a = A[N / 2];
    mid_b = B[N / 2];
    result = mid_b - mid_a + 1;
  }
  cout << result << endl;
}


Measured memory_bytes: 5192
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

if S[0] == '<':
    a[0] = 0
    l.append(0)
if S[-1] == '>':
    a[N-1] = 0
    l.append(N-1)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-3 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

for i in range(1,N-1):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1


if S[0] == '>':
    a[0] = a[1]+1

if S[-1] == '<':
    a[N-1] = a[N-2]+1

print(sum(a))

Measured memory_bytes: 54728
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 40

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

struct edge {
    int src;
    int dst;
    int64_t npoint;
};

#define VERTEX_MAX 1000
#define EDGE_MAX 2000
#define INF (1LL<<50)

int main(void) {
    int vs, es;
    struct edge edges[EDGE_MAX];
    get_int2(&vs, &es);
    int i, j;
    for(i = 0; i < es; i++) {
        int src, dst, np;
        get_int3(&src, &dst, &np);
        // 1-indexed -> 0-indexed
        src--; dst--;
        // directed graph
        edges[i] = (struct edge){src, dst, -np};
    }

    static int64_t min_dist[VERTEX_MAX];
    for(i = 0; i < vs; i++) {
        min_dist[i] = INF;
    }
    min_dist[0] = 0;
    // bellman
    for(i = 0; i < vs; i++) {
        int flag = 0;
        for(j = 0; j < es; j++) {
            struct edge e = edges[j];
            if(min_dist[e.src] == INF) continue;
            int64_t new = min_dist[e.src] + e.npoint;
            if(min_dist[e.dst] > new) {
                flag = 1;
                min_dist[e.dst] = new;
            }
        }
        if(!flag) break;
    }

    // check negative cycle( by bellman-ford algorithm )
    static int check_negative[VERTEX_MAX]; // default=0
    for(i = 0; i < vs; i++) {
        for(j = 0; j < es; j++) {
            struct edge e = edges[j];
            if(min_dist[e.src] == INF) continue;
            int64_t new = min_dist[e.src] + e.npoint;
            if(min_dist[e.dst] > new) {
                check_negative[e.dst] = 1;
                min_dist[e.dst] = new;
            }
            if(check_negative[e.src]) {
                check_negative[e.dst] = 1;
            }
        }
    }

    if(check_negative[vs-1]) {
        printf("inf\n");
    } else {
        printf("%lld\n", -min_dist[vs-1]);
    }

    return 0;
}

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

using namespace std;

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

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define FOR(a ,b) for(int i = a; i < b; i++) 
#define e "\n"
const int INF = 1e9 + 5;

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> h (n);
	for(int &x : h) cin >> x;
	
	vector<int> dp (n,INF);
	dp[0] = 0;
	for(int i = 0; i < n;i++){
		for(int j = i+1; j <= (i+k);j++){
			if(j < n) dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
		}
	}
	cout << dp[n-1] << e;
}


Measured memory_bytes: 1024
<?php
 $arr = explode(" ",trim(fgets(STDIN)));
    $res = 1;
    $cnt = 0;
    while($res<$arr[1]) {
     $res--;
     $res += $arr[0];
     $cnt++;
     if($res>=$arr[1]) break;
    }
    echo $cnt;
    


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

int n, m;

int main(){
  	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
       		string s;
          	cin >> s;
          	if(s == "snuke"){
            	printf("%c%d\n", 'A' + j - 1, i);
              	return 0;
            }
        }
    }
}

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        char c;
        cin >> c;

        printf("%c\n", c + 1);
    }
}


Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int j=1;int cnt=0;
   for(int i=0;i<n;i++)
   {
       if(a[i]==j)
       {
           cnt++;
           j++;
       }
   }
   if(cnt==0)
   {
       cout<<-1<<endl;
       return 0;
   }
   cout<<n-cnt<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int N;
string moji[10000];
int AB = 0;
int Alast = 0;
int Bfirst = 0;
int same = 0;

signed main(void) {
    cin >> N;
    rep(i,N){
        cin >> moji[i];

        rep(j,moji[i].size()){
            if(moji[i][j] == 'A' && moji[i][j+1] == 'B'){
                AB++;
            }
        }

        if(moji[i][moji[i].size()-1] == 'A'){
            Alast++;
        }

        if(moji[i][0] == 'B'){
            Bfirst++;
        }

        if(moji[i][moji[i].size()-1] == 'A' && moji[i][0] == 'B'){
            same++;
        }
    }


    if(same == max(Alast, Bfirst) && same > 0){
        cout << AB + min(Alast, Bfirst) - 1 << endl;
    }else{
        cout << AB + min(Alast, Bfirst) << endl;
    }


    return 0;
}


Measured memory_bytes: 768
MAX = 2*10**5+100
fact = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX
 
def C_init():
    fact[0] = 1
    fact[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    
    for i in range(2, MAX):
        fact[i] = fact[i-1]*i%MOD
        inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i] = finv[i-1]*inv[i]%MOD

n, a, b = map(int, input().split())
MOD = 10**9+7
nCa = 1

for i in range(n-a+1, n+1):
    nCa *= i
    nCa %= MOD

nCb = 1

for i in range(n-b+1, n+1):
    nCb *= i
    nCb %= MOD

C_init()

for i in range(1, a+1):
    nCa *= inv[i]
    nCa %= MOD

for i in range(1, b+1):
    nCb *= inv[i]
    nCb %= MOD

ans = pow(2, n, MOD)-nCa-nCb-1
ans %= MOD

print(ans)

Measured memory_bytes: 44528
import numpy as np
n=int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10**9+7
sm=0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    sm += 2 ** i * c1 * (n-c1)
    arr >>= 1

print(sm%mod)


Measured memory_bytes: 68512
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	ll x,ans=0;
	cin >> x;
	ans += (x / 11)*2;
	x %= 11;
	if (1<=x &&x <= 6)ans += 1;
	else if (x >= 7)ans += 2;
	cout << ans << endl;
	return 0;
}

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

 

int main() {
    ll x;
    cin >> x;
    ll ans = x / 11 * 2;
    if (x % 11 != 0) ++ans;
    if (x % 11 > 6) ++ans;
    cout << ans << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	long long int Y = 0;
	long long int R = 1;
	if (N == M) {

		for (int i = 1; i <= N; i++) {
			R *= i;
			if (R >= 1000000007) {
				R = R % 1000000007;
			}
		}
		
		if (R*R >= 1000000007) {
			R = R*R % 1000000007;
		}
		else {
			R = R * R;
		}

		Y = R* 2;
	}
	else if (abs(N - M) == 1) {
		for (int i = 1; i <= min(N, M); i++) {
			R *= i;
			if (R >= 1000000007) {
				R = R % 1000000007;
			}
		}
		if (R*R >= 1000000007) {
			R = R * R % 1000000007;
		}
		else {
			R=R*R;
		}
		Y = R*max(N, M);
	}
	if (Y >= 1000000007) {
		Y = Y % 1000000007;
	}

	cout << Y << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable: 4996)

#include<stdio.h>
#include<iostream>

using namespace std;

int main() {
	int A, B, sum = 0;
	scanf("%d %d", &A, &B);

	int diff = B-A;
	for (int i = 1; i < diff; i++) {
		sum = sum + i;
	}
	printf("%d", sum- A);
	return 0;
}

Measured memory_bytes: 256
n = int(input())

B = [int(x) for x in input().split()]

ans = 0
ans += B[0]

for i in range(1,n-1):
    if(B[i-1] <= B[i]):
        ans += B[i-1]

    else:
        ans += B[i]

ans += B[n-2]
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
#include <bitset>
using namespace std;
int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
struct NODE{
  int to,cost,tick;
  NODE(int to,int cost,int tick) : to(to),cost(cost),tick(tick){}
  NODE(){}
  bool operator < (const NODE &a)const{
    return cost > a.cost;
  }
};
int main(){
  int c,n,m,s,d,a,b,f;
  while(cin>>c>>n>>m>>s>>d&&c&&n&&m&&s&&d){
    vector<NODE> edge[101];
    
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(NODE(b,f,-1));
      edge[b].push_back(NODE(a,f,-1));
    }
    bool done[101][20] = {};
    priority_queue<NODE> Q;
    Q.push(NODE(s,0,c));
    while(!Q.empty()){
      NODE q = Q.top();Q.pop();
      if(done[q.to][q.tick] == true)continue;
      done[q.to][q.tick] = true;
      if(q.to == d){
	cout << q.cost << endl;
	break;
      }
      for(int i=0;i<edge[q.to].size();i++){
	Q.push(NODE(edge[q.to][i].to,q.cost + edge[q.to][i].cost,q.tick));
	if(q.tick){
	  Q.push(NODE(edge[q.to][i].to,q.cost + (edge[q.to][i].cost/2),q.tick-1));
	}
      }
    }
  }
}

Measured memory_bytes: 1316
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var A = BigInteger.Parse(ReadLine());
            var B = BigInteger.Parse(ReadLine());
            if (B < A)
                WriteLine("GREATER");
            else if (A < B)
                WriteLine("LESS");
            else
                WriteLine("EQUAL");
        }
        


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main(void){
    ll n; cin >> n;
    vector<ll>t(n);
    for(int i=0;i<n;i++) cin >> t[i];
    ll ans=t[0];
    for(int i=0;i<n;i++){
        ans = ans / euclidean_gcd(ans, t[i]);
        ans = ans * t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    
    int n;
    cin >> n;
    long a ;
    cin >> a;
    long min_val = a;
    long diff_max= -999999999;
    for(int i = 1;i < n;i++){
        cin >> a;
        diff_max = max(a - min_val,diff_max);
        min_val = min(a,min_val);
        
    }
    cout << diff_max << "\n";
    return 0;
}


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


using namespace std;

#define re return
#define sz(a) (int)a.size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 0; i < int(n); i++)


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

ll n, ans;
vector<ll> a, b;

int main() {
	//iostream::sync_with_stdio(0);
	//freopen("a.in", "r", stdin);
	cin >> n;
	a.resize(n);
	b.resize(n);
	forn (i, n)
		cin >> a[i] >> b[i];
	for (int i = n - 1; i >= 0; i--) {
		ll ck = (a[i] + ans) % b[i];
		if (ck > 0) {
			ans += b[i] - ck;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

void printArray(int A[], int num){
    for(int j=0; j<num; j++){
        if (j > 0) printf(" ");
        printf("%d", A[j]);
    }
    printf("\n");
}

void insertionSort(int A[], int num){
    int j, i;

    for(i=1; i<num; i++){
        j = i - 1;
        while (j >= 0){
            if(A[j] > A[j+1]){
                swap(A[j], A[j+1]);
            }
            j--;
        }
        printArray(A, num);
    }
}

int main(){
   
    int num;
    int A[100];

    cin >> num;

    for(int i=0; i<num; i++){
        cin >> A[i];
    }

    printArray(A, num);

    insertionSort(A, num);

    return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<typename X>
struct WUFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  vector<X> diff_weight;//差分重み
  int n;

  WUFT(int _n){
    n = _n;
    par.resize(n);
    rank.resize(n,0);
    size.resize(n,1);
    diff_weight.resize(n,0);
    rep(i,n) par[i] = i;
  }

  //xの根を返す,差分重みを更新
  int find(int x){
    if(par[x] == x) return x;
    else{
      int r = find(par[x]);
      diff_weight[x] += diff_weight[par[x]]; //累積和
      return par[x] = r;
    }
  }

  X weight(int x){
    find(x);
    return diff_weight[x];
  }

  X diff(int x,int y){
    return weight(y) - weight(x);
  }
  
  //x,yを距離wで併合
  bool unite(int x,int y,X w){
    w += weight(x); w -= weight(y);
    x = find(x); y = find(y);
    if(x == y) return false;

    if(rank[x] < rank[y]){ // x(の根)をy(の根)の下にくっつける
      par[x] = y;
      size[y] += size[x];
      diff_weight[x] = -w;
    }
    else{ // y(の根)をx(の根)の下にくっつける
      par[y] = x;
      size[x] += size[y];
      diff_weight[y] = w;
      if(rank[x] == rank[y]) rank[x]++;
    }
    return true;
  }

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

  int usize(int x){
    return size[find(x)];
  }
};
int main()
{
  int n,q;cin >> n >> q;
  vector<int> c(q),x(q),y(q),z(q);
  rep(i,q){
    cin >> c[i];
    if(c[i]==0) cin >> x[i] >> y[i] >> z[i];
    else cin >> x[i] >> y[i];
  }

  WUFT<int> wuf(n);
  rep(i,q){
    if(c[i]==0) wuf.unite(x[i],y[i],z[i]);
    else{
      if(wuf.same(x[i],y[i])) cout << wuf.diff(x[i],y[i]) << "\n";
      else cout << "?" << "\n";
    }

  }
  return 0;
}



Measured memory_bytes: 7560
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/

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

typedef long long int LLi;
typedef long long LL;
typedef vector<LLi> VLL;
typedef vector<string> VS;
typedef vector<pair<LLi, LLi> > VP;


#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;

LLi max_3(LLi a, LLi b, LLi c)
{
    return max(a,max(b,c));
}
LLi min_3(LLi a, LLi b, LLi c)
{
    return min(a,min(b,c));
}

LLi concate(LLi a, LLi b)
{
    ostringstream os;
    os <<a <<b;
    istringstream is(os.str());
    LLi c;
    is>> c;
    return c;
}


LLi check(char c)
{
    return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}

main()
{
    LLi q,t;
//    cin>>t;
 //   while(t--)
   // {
        LLi a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
        LLi aa[1000];
        LLi flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
        LLi ma=0, mi=100000000;
        LLi mid=0, temp=0, stop=0, start=0;
        double pi= 3.141592653589793;
        double d1=0.0, d2, d3, d4;
        VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
        VS vs, vs1, vs2, vs3, vs4;
        VP vp, vp1,vp2;
        char ch, ch1, ch2[1001];
        string str, str1, str2, str3, str4, str5;
        pair<LLi, LLi> pa;
//        list<LLi> li, li1;
  //      map<LLi, LLi> mp, mp1;
        set<LLi> st;
    //    map<LLi ,LLi> :: iterator imll;
        VLL :: iterator ivll;
        set<LLi> :: iterator isll;
        VP :: iterator ivp;

        cin>>ch;
        if(ch<97)
        {
            cout<<"A"<<endl;
        }
        else cout<<"a"<<endl;



 //    }

    exit()


}


Measured memory_bytes: 3604
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int k2 = 2*k;
		int[][] mat = new int[4*k-1][4*k-1];
		
		for (int i=0;i<n;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			String s = sc.next();
			if (s.equals("W"))
				y += k;
			x %= k2;
			y %= k2;
			
			for (int a=0;a<4;a++) {
				int c = x + a*k;
				if (c>=mat.length)
					break;
				for (int b=0;b<4;b++) {
					int r = y + b*k;
					if (r>=mat.length)
						break;
					int sign = ((a^b)&1)==1 ? -1 : 1;
					mat[c][r] += sign * ((a==0||b==0) ? 1 : 2);
				}
			}
		}
		
		for (int c=0;c<mat.length;c++) {
			for (int r=1;r<mat.length;r++) {
				mat[c][r] += mat[c][r-1];
			}
		}
		for (int r=0;r<mat.length;r++) {
			for (int c=1;c<mat.length;c++) {
				mat[c][r] += mat[c-1][r];
			}
		}

		int ans = 0;
		int x = mat.length-1;
		int y = x;
		for (int c=0;c<k2;c++) {
			for (int r=0;r<k;r++) {
				ans = Math.max(ans, mat[x-c][y-r]);
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 165772
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#define debug(x)   cerr<<#x<<" = "<<x<<endl
#else
#define debug(x) 
#endif
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define pii pair<int,int>
#define endl '\n'
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int inf = 1e18 + 5;
int dp[3002][6009];

signed main()
{
    #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif 
    IOS
    int n,W; cin>>n>>W;
    pair<int, int> wei[n];
    for(int i=0;i<n;i++)
    {
        cin>>wei[i].fi>>wei[i].se;
    }
    sort(wei, wei+n);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=W+3000;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j >= wei[i-1].fi && j-wei[i-1].fi < W) dp[i][j] = max(dp[i][j] , dp[i-1][j-wei[i-1].fi] + wei[i-1].se);  
        }
        
    }
    int ans = 0;
    for(int i=0;i<=W+3000;i++) ans = max(ans , dp[n][i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 141184