akhauriyash/Code-Regression huggingface dataset:
n = int(input())
l = sorted(list(map(int, input().split())))

count = 0
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if l[i] + l[j] > l[k]:
        if l[i] != l[j] and l[i] != l[k] and l[j] != l[k] and (l[i]+l[j]) > l[k]:
          count += 1
        
        
print(count)

Measured memory_bytes: 67960
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<int> minp(1000001);//その数を割れる最小の素数
vector<int> vec(1000001);
bool pairwise=true;

void pf(int x){
    map<int,int> soinsu;
    while(x>1){
        soinsu[minp[x]]++;
        x/=minp[x];
    }
    for(auto p:soinsu){
        if(vec[p.first])pairwise=false;
        else vec[p.first]=1;
    }
}


//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    for(int i=2;i<=sqrt(1000000);i++){
        if(minp[i]==0){
            for(int j=i;j<1000001;j+=i){
                minp[j]=i;
            }
        }
    }
    for(int i=2;i<1000001;i++){
        if(minp[i]==0)minp[i]=i;
    }
    int n,tmp,x;cin>>n>>tmp;
    pf(tmp);
    for(int i=1;i<n;i++){
        cin>>x;
        tmp=__gcd(tmp,x);
        if(pairwise)pf(x);
    }
    if(pairwise)cout<<"pairwise coprime"<<endl;
    else if(tmp==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}


Measured memory_bytes: 10952
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+5;
ll dp[N];
void solve(){
	int n; 
	cin>>n; 
	dp[0] = 1;
	for(int i=3;i<=n;i++){
		for(int j=i-3;j>=0;j--){
			dp[i] += dp[j];
			dp[i] %= mod;
		}
	}
	cout<<dp[n]<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3628
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn solve(mut n:i64) {
    if n == 0 {
        println!("0");
        return;
    }
    let mut st = Vec::<i64>::new();
    let mut bit = 1;
    while n != 0 {
        if n % (bit * 2) != 0 {
            st.push(1);
            n -= bit;
        } else {
            st.push(0);
        }
        bit *= -2;
    }
    while let Some(top) = st.pop() {
        print!("{}", top);
    }
    println!("");
}
fn main() {
    let n = read::<i64>();
    solve(n);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
int main(){
  double l = 0;
  double r = 89.99999999;
  double a,b,x;cin>>a>>b>>x;
  while((r-l) > 1e-7){
    double mid = (r+l)/2;
    double fill;
    if( (a * tan(mid*PI/180)) <= b){
      fill = (2 * b - a * tan(mid*PI/180)) * a / 2 * a;
    }else{
      fill = (a*b) / 2 * b / tan(mid*PI/180);
    }
    if( fill > x){
      l = mid;
    }else if(fill < x) {
      r = mid;
    }else{
      cout << setprecision(11) <<mid<<endl;
      return 0;
    }
    //cout<<l<<" "<<r<<" "<<(a * tan(mid*PI/180))<<" "<<fill<<endl;
  }
  cout << setprecision(11) << r << '\n';
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [0 for _ in range(n)]
dp[1] = abs(h[0]-h[1])

for i in range(2,n):
	dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]))

print(dp[n-1])

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

using namespace std;

//#define FILE_IO

int N;
int fth[1005], cnt[1005], oth[1005];
int dp[2][5005];
vector<int> edg[1005];

void DFS(int nod)
{
    for(auto nxt: edg[nod]) DFS(nxt);
    int k = 0;
    for(int i = 1; i <= 5000; i++)  dp[0][i] = 1 << 30;
    dp[0][0] = 0;
    for(auto nxt: edg[nod])
    {
        k ^= 1;
        int x = cnt[nxt], y = oth[nxt];

        for(int i = 0; i <= 5000; i++)  dp[k][i] = 1 << 30;
        for(int i = x; i <= 5000; i++)  dp[k][i] = min(dp[k][i], dp[k ^ 1][i - x] + y);
        for(int i = y; i <= 5000; i++)  dp[k][i] = min(dp[k][i], dp[k ^ 1][i - y] + x);
    }

    oth[nod] = 1 << 30;
    for(int i = 0; i <= cnt[nod]; i++)  oth[nod] = min(oth[nod], dp[k][i]);

    if(oth[nod] == (1 << 30))
    {
        printf("IMPOSSIBLE\n");
        exit(0);
    }
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 2; i <= N; i++)
    {
        scanf("%d", &fth[i]);
        edg[fth[i]].push_back(i);
    }
    for(int i = 1; i <= N; i++) scanf("%d", &cnt[i]);

    DFS(1);

    printf("POSSIBLE");

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

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

	//変数宣言
	int N = scan.nextInt();
	int[] a = new int[N];
	int[] b = new int[N];
	int[] c = new int[N];
	int[] d = new int[N];
	int[] flag = new int[N];
	int count = 0;

	//値入力
	for(int i = 0; i < N; i++){
	    a[i] = scan.nextInt();
	    b[i] = scan.nextInt();
	}
	for(int i = 0; i < N; i++){
	    c[i] = scan.nextInt();
	    d[i] = scan.nextInt();
	}
	for(int i = 0; i < N; i++){
	    flag[i] = 0;
	}

	//ソート処理
	for(int i = 0; i < N-1; i++){
	    for(int j = i+1; j < N; j++){
		if(a[i] > a[j]){
		    int tmp1 = a[i];
		    a[i] = a[j];
		    a[j] = tmp1;
		    int tmp2 = b[i];
		    b[i] = b[j];
		    b[j] = tmp2;
		}
	    }
	}
	for(int i = 0; i < N-1; i++){
	    for(int j = i+1; j < N; j++){
		if(c[i] > c[j]){
		    int tmp1 = c[i];
		    c[i] = c[j];
		    c[j] = tmp1;
		    int tmp2 = d[i];
		    d[i] = d[j];
		    d[j] = tmp2;
		}
	    }
	}

	//貪欲法	
	for(int i = 0; i < N; i++){
	    int max = -1;
	    int index = -1;
	    for(int j = N-1; j >= 0; j--){
		if(c[i] > a[j] && d[i] > b[j]){
		    if(max < b[j] && flag[j] == 0){
			max = b[j];
			index = j;
		    }
		}
	    }
	    if(index != -1){
		flag[index] = 1;
		count++;
	    }
	}

	System.out.println(count);
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        TreeSet<String> set = new TreeSet<>();
        for (int c = 'a'; c <= 'z'; c++) {
            char ch = (char) c;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == ch) {
                    for (int j = i, x = 0; j < s.length() && x <= 6; j++, x++) {
                        set.add(s.substring(i, j + 1));
                    }
                }
            }
            if(set.size()>=k) {
                break;
            }
        }
        int i = 0;
        for (String str : set) {
            if (++i == k) {
                System.out.println(str);
                break;
            }
        }
    }
}


Measured memory_bytes: 25812
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n, K;
    cin >> n >> K;

    ll res = 0;
    ll MOD = 1000000007;
    for (ll i = K; i <= n + 1; i++) {
        // min: 0 + 1 + 2 + ... + K-1
        // max: n + n-1 + ... + n-k+1
        ll mi = i * (i - 1) / 2;
        ll ma = n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2;
        res += (ma - mi + 1) % MOD;
        res %= MOD;
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3596
from bisect import bisect_left

n, m = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(m)]
pys = [[] for _ in range(n)]
for q in qs:
    p, y = q
    p -= 1
    pys[p].append(y)

for i in range(n):
    pys[i] = sorted(pys[i])

for q in qs:
    p, y = q
    p -= 1
    number = bisect_left(pys[p], y) + 1

    print(str(p + 1).zfill(6) + str(number).zfill(6))

Measured memory_bytes: 36744
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
t = intl()
m = i()
p = []
x = []
for i in range(m):
	P,X = i2()
	p.append(P)
	x.append(X)

a = sum(t)
b = a
for i in range(m):
	a -= t[ p[i]-1 ] 
	a += x[i]
	print(a)
	a = b

Measured memory_bytes: 9216
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

vector<ll> nums;

void fact(ll num, int digit) {
    if (digit == 11) return;
    
    repr(x, max<int>(0, num % 10 - 1), min<int>(9, num % 10 + 1) + 1) {
        nums.push_back(num * 10 + x);
        fact(num * 10 + x, digit + 1);
    }
}

int main() {
    int k;
    cin >> k;
    repr(x, 1, 10) {
        nums.push_back(x);
        fact(x, 1);
    }
    sort(nums.begin(), nums.end());
    cout << nums[k - 1] << endl;
}

Measured memory_bytes: 10604
t=0
r=0
for _ in range(int(input())):
    a,b=map(int,input().split())
    if a==b:
        t+=1
    else:
        t=0
    if t>=3:
        r+=1
if t>=3 or r>0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62368
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> pos(n);
    for(int i = 0; i < n; ++i){
        int p;
        cin >> p;
        --p;
        pos[p] = i;
    }
    priority_queue<int, vector<int>, greater<int>> que;
    ll res = 0;
    for(int i = 0; i < n; ++i){
        que.push(pos[i]);
        if(pos[i] == que.top()){
            ++res;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 2168
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		String target=scan.next();
		String s;
		int ans=0;
		while(true){
			s=scan.next();
			if(s.equals("END_OF_TEXT")){
				break;
			}
			else{
				if(s.equalsIgnoreCase(target)){
					ans++;
				}
			}
		}
		System.out.println(ans);
		scan.close();
	}
}

Measured memory_bytes: 18052
def getlist():
    return list(map(int, input().split()))

x, y = getlist()
if x >= 0:
    if y >= x:
        print(y - x)
    else:
        if y > 0:
            print(x - y + 2)
        else:
            print(abs(abs(x) - abs(y)) + 1)
else:
    if y <= x:
        print(x - y + 2)
    else:
        if y <= 0:
            print(y - x)
        else:
            print(abs(abs(x) - abs(y)) + 1)

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

int blk=550;

struct node{
    int l;
    int r;
    int ind;
};

bool cmp(node &a, node &b)
{
    if(a.l/blk != b.l/blk) return a.l/blk < b.l/blk;
    return a.r < b.r;
}

int m[1000010];
int cnt = 0;

void add(int &x){
    m[x]++;
    if(m[x] == 1) cnt++;
}
void remove(int &x){
    m[x]--;
    if(m[x] == 0) cnt--;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    for(int i=0;i<=1000009;i++) m[i]=0;
    int n,q;
    cin >> n >> q;
    blk = sqrt(n) + 1;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    node qry[q];
    for(int i=0;i<q;i++)
    {
        node a;
        cin >> a.l >> a.r;
        a.l-- , a.r--;
        a.ind = i;
        qry[i]=a;
    }
    sort(qry,qry+q,cmp);
    int lp=0,rp=-1;
    int arr[q];
    for(int i=0;i<q;i++)
    {
        int l = qry[i].l;
        int r = qry[i].r;
        int ind = qry[i].ind;
        while(lp<l)  remove(a[lp]) , lp++;
        while(l<lp) add(a[lp-1]) , lp--;
        while(rp<r) rp++ , add(a[rp]);
        while(rp>r) remove(a[rp]),rp--;
        arr[ind] = cnt;
    }
    for(int i=0;i<q;i++) cout << arr[i] << "\n";
}


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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=4e5+5;
int n;
vi g[N],s[N];
int mx = 0;
void dfs(int u,int p,int h){
	s[h].pb(u);
	mx = max(mx,h);
	for(auto v:g[u]){
		if(v == p)continue;
		dfs(v,u,h + 1);
	}
}
int ans[N];
vi t[5];
bool vis[N]; 
int main()
{
	cin>>n;
	int u,v;
	rep(i , 1 , n){
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	rep(i , 1 , n + 1)
		t[i%3].pb(i);
	dfs(1,0,1);
	int ev = 0,odd = 0;
	rep(i , 1 ,n + 1)
		if(i&1)odd += sz(s[i]);
		else ev += sz(s[i]);
	if(odd < ev){
		swap(odd,ev);
		for(int i = 2;i <= mx;i += 2){
			swap(s[i],s[i - 1]);
		}
	}


	if(ev <= sz(t[0])){
		rep(i , 1 , n + 1){
			if(i&1)continue;
			for(auto v:s[i]){
				ans[v] = t[0].back(),t[0].pop_back();
			}
		}
		rep(i , 1 , n + 1){
			if(i&1){
				for(auto v:s[i]){
					if(sz(t[1]))ans[v] = t[1].back(),t[1].pop_back();
					else if(sz(t[0]))ans[v] = t[0].back(),t[0].pop_back();
					else if(sz(t[2]))ans[v] = t[2].back(),t[2].pop_back();
				}
			}
		}
		
	}
	else {
		rep(i , 1 , n + 1){
			if(i&1){
				for(auto v:s[i]){
					if(sz(t[1]))ans[v] = t[1].back(),t[1].pop_back(),vis[v] = true;
				}
			}
			else{
				for(auto v:s[i]){
					if(sz(t[2]))ans[v] = t[2].back(),t[2].pop_back(),vis[v] = true;
				}
			}
		}
		rep(i , 1 , n + 1){
			if(i&1){
				for(auto v:s[i]){
					if(vis[v])continue;
					if(sz(t[1]))ans[v] = t[1].back(),t[1].pop_back();
					else if(sz(t[0]))ans[v] = t[0].back(),t[0].pop_back();
				}
			}
			else{
				for(auto v:s[i]){
					if(vis[v])continue;
					if(sz(t[2]))ans[v] = t[2].back(),t[2].pop_back();
					else if(sz(t[0]))ans[v] = t[0].back(),t[0].pop_back();
				}
			}
		}
	}
	rep(i , 1 , n + 1)cout<<ans[i]<<" ";
	return 0;
}



Measured memory_bytes: 40312
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	long N = Long.parseLong(scan.next());

	int min = Integer.MAX_VALUE;
	long A = 1;
	long B = N;
	for (; A <= B; A++) {
	    if(N % A == 0) {
		B = N / A;
		int tmp = F(A, B);
		if(tmp < min) min = tmp;
	    } else {
		B = N / A + 1;
	    }
	}

	System.out.println(min);
	scan.close();
    }

    private static int digits(long x) {
	return (int)Math.log10(x)+1;
    }

    private static int F(long a, long b) {
	int c = digits(a);
	int d = digits(b);

	return (c > d) ? c : d;
    }
}


Measured memory_bytes: 23764
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

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

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

    cout << ans << endl;

}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&m);
	if(n==1 && m==1)cev+=400000;
	if(n==1)cev+=300000;
	if(m==1)cev+=300000;
	if(n==2)cev+=200000;
	if(m==2)cev+=200000;
	if(n==3)cev+=100000;
	if(m==3)cev+=100000;
	printf("%d\n",cev);
	return 0;
}


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

a = [0]*10001

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1,101):
        v = x*x+y*y+z*z+x*y+y*z+x*z
        if  v < 10001:
        	a[v] += 1
for i in range(n):
  print(a[i+1])

Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}
int main() {
  int n;
  ll t;
  cin >> n;
  ll l = 1;
  for (int i = 0; i < (int) (n); ++i) {
    cin >> t;
    l = lcm(l, t);
  }
  cout << l;
  return 0;
}

Measured memory_bytes: 256
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
d=dict()
s2=0
for _ in range(0,m):
    k,v=list(map(int,input().split()))
    s2=s2+k
    if(d.get(v)==None):
        d[v]=k
    else:
        d[v]=d[v]+k
s=list(d.keys())
s.sort(reverse=True)
l=len(s)
g=0
c=0
q=0
#print(a,s,"_")
for i in range(0,n):
    if(s2==g):
        #print("yes")
        break
    #print(c)
    s1=s[c]
    if(a[i]<s1):
        q=q+s1
       # print(q,";",s1,d[s1],l,c)
        d[s[c]]=d[s[c]]-1
        if(d[s[c]]==0):
            c=c+1
        g=g+1
print(q+sum(a[g:]))

Measured memory_bytes: 23412
#ABC136_C
N=int(input())
H=list(map(int,input().split()))
minH=H[-1]
for i in range(1,N):
    if (H[-i-1]-minH)>1:
        print('No')
        break
    if H[-i-1]<minH:
        minH=H[-i-1] 
else:
    print('Yes')

Measured memory_bytes: 14396
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#define arr_print_d0dn(a, n) for(int i=0;i<(n)-1;++i)put_uint((a)[i]),putchar_unlocked(' ');put_uint((a)[(n)-1]),putchar_unlocked('\n')

void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
// global count variable
int cnt;
// merge sort
void merge(int *first, int *mid, int *last) {
    // left arr size
    const int N1 = (int)(mid - first);
    // right arr size
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    // sufficiently large value
    left[N1] = right[N2] = 1000000000;
    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        // insert smaller value
        *it = left[i] <= right[j] ? left[i++] : right[j++];
    }
    free(left);
    free(right);
}
void merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return;
    int *mid = first + N / 2;
    merge_sort(first, mid);
    merge_sort(mid, last);
    merge(first, mid, last);
    cnt += N;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int s[500001];
    for(int i = 0; i < n; ++i) s[i] = get_uint();
    merge_sort(s, s + n);
    arr_print_d0dn(s, n);
    put_uint(cnt), putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 5360
def solve(h, w, a, b):
    A = [[0]*w for _ in range(h)]
    for r in range(b):
        for c in range(a):
            A[r][c] = 1
    for r in range(b, h):
        for c in range(a, w):
            A[r][c] = 1
    return "\n".join(["".join(map(str, A[r])) for r in range(h)])

h, w, a, b = map(int, input().split())
print(solve(h, w, a, b))

Measured memory_bytes: 18980
function spilitInput(input) {
  var splited = [];
  var rows = input.split('\n');
  for (var i = 0; i < rows.length; i += 1) {
    splited.push(rows[i].split(' '));
  }
  return splited;
}
function Main(input) {
  var splited = spilitInput(input);
  var r_count = 0;
  for (var i = 1; i < splited.length && r_count < 3; i += 1) {
    if (splited[i][0] == splited[i][1]) {
      r_count += 1;
      if (r_count >= 3) break;
    } else {
      r_count = 0;
    }
  }
  if (r_count >= 3) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29684
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

A=2*10**5
mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, A + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,M,K=map(int,input().split())
keisuu=cmb(N*M-2,K-2,mod)

sum_=0
for i in range(N):
    a=min(abs(i),abs(N-i-1))
    b=max(abs(i),abs(N-i-1))
    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))
for i in range(M):
    a=min(abs(i),abs(M-i-1))
    b=max(abs(i),abs(M-i-1))
    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))
print((keisuu * (sum_//2))%mod)

Measured memory_bytes: 27096
////////////
//||||| ||// 
//   || ||//
//||||||||//
//|| ||   //
//|| |||||//
////////////
#include<bits/stdc++.h>
using namespace std;
#define   ll  long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
#define   MAX 1000000
#define   eps 1e-8
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll a, b, c = 0, d, e, f = 0, g, h, i, j, k, m, n, o, p, s, t, v, w, x, y, z,l;
    ll cnt = 0, l1 = 0, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
    ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string str, str1, str2, str3 = "", str4 = "";
    ll ide = 0, idx = 0, Q;
    
    cin>>str;
    ll ans=0;
    for(i=0;i<str.length();i++)
    {
    	if(str[i]=='R'){
    		c++;
    		if(i==str.length()-1)
    			ans=max(ans,c);
    	}
    	else{
    		ans=max(ans,c);
    	c=0;
        }
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
using namespace std;
//
int main(){
	string S;
	cin>>S;
	int N=S.size();
	if(S[0]!='1'||S[N-1]!='0'){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<N-1;i++){
		if(S[i]!=S[N-2-i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	int par=0;
	cout<<1<<" "<<2<<endl;
	for(int i=1;i<N-1;i++){
		cout<<par+1<<" "<<i+2<<endl;
		if(S[i]=='1'){
			par=i+1;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll fact(ll L) {
  ll res = 1;
  ll mod = 1e9 + 7;
  for (int i = 1; i <= L; i++) {
    res = (res * i) % mod;
  }
  return res;
}
ll quickpower(ll a, ll b) {
  ll res = 1;
  ll mod = 1e9 + 7;
  while (b) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    b = b >> 1;
    a = (a * a) % mod;
  }
  return res % mod;
}
int choose(ll N, ll K) {
  ll mod = 1e9 + 7;
  N += K;
  ll D = fact(N);
  ll V = (fact(K) * fact(N - K)) % mod;
  ll res = (D * quickpower(V, mod - 2)) % mod;
  return res;
}
int main() {
  int X, Y;
  cin >> X >> Y;
  ll res = 0;
  if ((2 * X - Y) % 3 == 0 && (2 * Y - X) % 3 == 0) {
    ll moves_1 = (2 * Y - X) / 3;
    ll moves_2 = (2 * X - Y) / 3;
    if (moves_1 < 0 || moves_2 < 0) {
      res = 0;
    } else {
      res = choose(moves_1, moves_2);
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 1000000

int main(){

  int i;
  int j;
  int n;
  int q;
  int left;
  int right;
  int mid;
  int count=0;
  int s[N];
  int t[N];

  scanf("%d",&n);

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

  scanf("%d",&q);

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



  for(i=0;i<q;i++){
  left = 0;
  right = n;
  while(left < right){
    mid = (left + right) / 2;
    if(s[mid]==t[i]){
      count++;
      break;
    }
    else if(t[i] < s[mid]){
      right = mid;
    }
    else left = mid + 1;
   }
  }
   printf("%d\n",count);

   return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m;
P a[5];

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++)cin >> a[i].first >> a[i].second;
	sort(a, a + m);
	if (n == 1 && m == 0) {
		cout << 0 << endl;
		return 0;
	}
	if ((a[0].first == 1) && (a[0].second == 0) &&( n != 1)) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < m - 1; i++) {
		if ((a[i].first == a[i + 1].first) && (a[i].second != a[i + 1].second)) {
			cout << -1 << endl;
			return 0;
		}
	}
	int k = 0;
	if (a[0].first == 1) {
		cout << a[0].second;
		while (1 == a[k].first)k++;
	}
	else cout << 1;
	for (int i = 2; i <= n; i++) {
		if (i == a[k].first) {
			cout << a[k].second;
			while (i==a[k].first) {
				k++;
			}
		}
		else cout << 0;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, c;
    int rectangle, diamond;

    rectangle = diamond = 0;
    while (scanf("%d,%d,%d", &a, &b, &c) != EOF){
        if (a * a + b * b == c * c){
            rectangle++;
        }
        if (a == b){
            diamond++;
        }
    }
    printf("%d\n%d\n", rectangle, diamond);

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=1e6+9;
const int mod=1e9+7;
using namespace std;
int cnt[MAX];

int main(){
	int n;
	cin>>n;
	int arr[n+1];
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	int mx=arr[1];
	int cnt=1;
	for(int i=2;i<=n;i++){
		if(arr[i]>=mx){
			cnt++;
			mx=arr[i];
		}
	}
	cout<<cnt;	

}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
int h, w, i, j;
while(1){
scanf("%d", &h);
scanf("%d", &w);
if (h==0&&w==0) {
break;
} else {
for (j=0;j<h;j++){
for (i=0;i<w;i++){
if ((i+j)%2==1) {
printf(".");
} else {
printf("#");
}
}
printf("\n");
}
printf("\n");
}
}
return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin>>S;
  int count=0;
  int i,j;
  for(i=0;i<3;i++)
  {
    if(S[i]=='o')
    {
      count++;
    }
  }
  cout<<700+count*100<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,n,a,flag1,flag2,flag3,temp,x,y;
	char str[100000],str1[200000],str2[200000],b;
	cin>>str;
	cin>>n;
	flag1=0;
	flag2=1;
	flag3=2;
	x=y=0;
	for(i=0;i<n;i++){
		cin>>a;
		if(a==1){
			flag1++;
			if(flag2<flag3){
				flag2+=2;
			}else {
				flag3+=2;
			}
		}else {
			cin>>a>>b;
			if(a==1){
				if(flag2<flag3){
					str1[x]=b;
					x++;
				}else {
				   str2[y]=b;
				   y++;
				}
			}else {
				if(flag2>flag3){
					str1[x]=b;
					x++;
				}else {
					str2[y]=b;
					y++;
				}
			}
		}
	}
	if(flag2<flag3){
		
		for(i=x-1;i>=0;i--)cout<<str1[i];
		if(flag1%2==0){
			cout<<str;
		}else {
			n=strlen(str);
			for(i=n-1;i>=0;i--){
				cout<<str[i];
			}
		}
		cout<<str2;
	}else {
		for(i=y-1;i>=0;i--)cout<<str2[i];
		if(flag1%2==0){
			cout<<str;
		}else {
			n=strlen(str);
			for(i=n-1;i>=0;i--){
				cout<<str[i];
			}
		}
		cout<<str1;
	}
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long; 
int main(){
  ll m;
  cin>>m;
  ll N;
  ll c=0;
  cin>>N;
  vector<ll>tr(N);
  for(ll i=0;i<N;i++){
    cin>>tr.at(i);
    c+=tr.at(i);
  }
  ll b=m-c;
  if(b<0){
    b=-1;
  }
  cout<<b<<endl;
  
    
  
}


Measured memory_bytes: 3704
field = [[0 for i in range(10)]for i in range (15)]
num = int(input())
for i in range (num):
	b,f,r,v = map(int,input().split())
	field[((b-1)*4)+f-1][(r-1)] += v
for i in range(15):
	if( i % 4 == 3 ):
 		field[i] = ['#'*20]
for i in range(15):
	field[i] = map(str,field[i])
for i in range(15):
		if not( i % 4 == 3 ):
			print(' '+' '.join(field[i]))
		else:
			print(''.join(field[i]))


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll N;
vector<set<int>> nbr;
vector<ll> c;
vector<ll> d;
int idx;

void operate(int n) {
  if (nbr.at(n).size() != 1)  return;
  auto it = nbr.at(n).begin();
  int r = *it;
  d.at(n) = c.at(idx++);
  nbr.at(n).erase(it);
  nbr.at(r).erase(n);
  if (nbr.at(r).size() == 0) {
    d.at(r) = c.at(idx++);
  }else {
    operate(r);
  }
}

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  nbr.resize(N+1);
  c.resize(N);
  d.resize(N+1);
  for (int i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b;
    nbr.at(a).insert(b);
    nbr.at(b).insert(a);
  }
  ll M = 0;
  for (int i = 0; i < N; i++) {
    cin >> c.at(i);
    M += c.at(i);
  }
  sort(c.begin(), c.end());
  M -= c.at(N-1);

  for (int i = 1; i <= N; i++) {
    operate(i);
  }
  cout << M << "\n";
  for (int i = 1; i <= N; i++) {
    if (i > 1)  cout << " ";
    cout << d.at(i);
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;
const int maxn=20;
char ch[maxn];
int a[maxn];
int main(){
    ll n;
    while (scanf("%s",ch)!=EOF) {
        int i=0;
        int sum=0;
        while (ch[i]>='0'&&ch[i]<='9') {
            a[i]=ch[i]-'0';
            sum+=a[i];
            i++;
        }
        sum=max(sum,a[0]-1+(i-1)*9);
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int h, w;
int c[101][101];
bool used[101][101];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

void dfs(int x, int y, int cc){
		used[x][y] = true;
		for(int i = 0; i < 4; i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w){
						if(c[nx][ny] == cc && !used[nx][ny])dfs(nx, ny, cc);
				}
		}
}

int main(int argc, char const* argv[])
{
	while(true){
			cin >> h >> w;
			if(h == 0)break;
			for(int i = 0; i < h; i++){
					string s;
					cin >> s;
					for(int j = 0; j < w; j++){
							if(s[j] == '#')c[i][j] = 0;
							else if(s[j] == '*')c[i][j] = 1;
							else c[i][j] = 2;
							used[i][j] = false;
					}
			}
			int res = 0;
			for(int i = 0; i < h; i++){
					for(int j = 0; j < w; j++){
							if(used[i][j])continue;
							res++;
							dfs(i, j, c[i][j]);
					}
			}
			cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 3676
/* ***********************************************
Author        :caowushang
Created Time  :2016/8/3 19:18:25
TASK		  :新建.cpp
LANG          :C++
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdlib>
#define inf 99999999
#define cl(x,v) memset(x,v,sizeof(x))
#define PI 3.14159265358979323
#define LL long long int
using namespace std;
const int MX=1e5+10;
const int mod=1e9+7;

int main()
{
    //freopen("in.txt","r",stdiin);
    //freopen("out.txt","w",stdout);
    string S;
    while(cin >> S)
	{
		bool s=0,e=0,n=0,w=0;
		int l=S.size();
		for(int i=0;i<l;i++)
		{
			if(S[i]=='S')s=1;
			if(S[i]=='N')n=1;
			if(S[i]=='E')e=1;
			if(S[i]=='W')w=1;
		}
		if(s^n||e^w)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}	
    return 0;
}


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

const int INF = 1001001001;

int main(){
	int H, N, amax;
	cin >> H >> N;
	vector<pair<int, int>> vp(N);
	rep(i, N){
		cin >> vp.at(i).first >> vp.at(i).second;
		if(i == 0 || amax < vp.at(i).first) amax = vp.at(i).first;
	}
	
	vector<int> dp(H+amax, INF);
	rep(i, N){
		int a = vp.at(i).first; int b = vp.at(i).second;
		rep(j, H+amax){
			if(j >= a){
				dp.at(j) = min(dp.at(j), b + dp.at(j-a));
			}else if(j == 0){
				dp.at(j) = 0;
			}else{
				dp.at(j) = min(dp.at(j), b);
			}
		}
	}
	
	int ans;
	for(int i = H; i < H+amax; i++){
		if(i == H || ans > dp.at(i)) ans = dp.at(i);
	}
	
	cout << ans << endl;
}

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

vector<int> edge[100005];
int dp[100005], X[100005];

void dfs(int x, int p){
	int t = 0;
	for(auto i: edge[x]){
		if(i == p) continue;
		dfs(i, x);
		dp[x] += dp[i];
		if(!dp[i]) ++t;
	}
	if(t) dp[x] += t-1;
	if(t || edge[x].size() == 1) X[x] = 1;
}

bool dfs(int x, int p, int c){
	if(X[x] && !c) return 1;
	for(auto i: edge[x]){
		if(p==i) continue;
		if(dfs(i, x, dp[x]>dp[i] || c)) return 1;
	}
	return 0;
}

int main(){ 
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N; cin>>N;
	for(int i=1; i<N; ++i){
		int x,y; cin>>x>>y;
		edge[x].push_back(y), edge[y].push_back(x);
	}
	dfs(0, -1);
	X[0] = 0;

	cout<<dp[0]+dfs(0, -1, 0);
	return 0;
}

Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cmath>
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i < _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i > _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i < _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)
typedef long long ll;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int dp[200005],maxi = 1;
    int n,a,c = 1;
    cin >> n;
    FOR(i,0,n)
    {
    	cin >> a;
//    	cout << a[i] << endl;
    	dp[a] = i;
	}
	FOR(i,1,n)
	{
//		cout << dp[i] <<endl;
	    if(dp[i+1] > dp[i])
	    {
	    	c++;
		}
		else
		{
			c = 1;
		}
//		cout << c << endl;
		if(maxi < c)
        {
            maxi = c;
        }
	}
	cout << n - maxi;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;


int main(){
    string L[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;

    rep(i,7){
        if( s == L[i]){
            cout << (7-i) << endl;
        }
    }

   return 0;
}

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

string FILENAME = "template";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;

#define forl(V, N) for(int V = 0; V < N; V++)
#define fore(E, X) for(auto &E:X)
#define print(X) cout << X
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define rem(X) X.top(); X.pop()
#define mid(A, B) ((A+B) / 2)
#define setmin(A, B) A = min(A, B)
#define setmax(A, B) A = max(A, B)
#define graph unordered_map<int, unordered_set<int>>
#define vi vector<int>
#define pb push_back
#define ll long long

int main() {
    int N;
    cin >> N;
    vector<vi> active;
    forl(i, N) {
        int A, B, C;
        cin >> A >> B >> C;
        active.pb({A, B, C});
    }
    ll dp[200000][3];
    dp[0][0] = active[0][0];
    dp[0][1] = active[0][1];
    dp[0][2] = active[0][2];
    forl(i, N-1) {
        forl(j, 3){
            forl(k, 3) {
                if(k == j) continue;
                setmax(dp[i+1][k], active[i+1][k] + dp[i][j]);
            }
        }
    }
    println(max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])));
}

Measured memory_bytes: 10032
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	long long pos, k, dist, nearest, fpos;
	cin>>pos>>k>>dist;
	if(pos<0)
	    pos = -pos;
	nearest = pos/dist;
	if(k<=nearest) {
	    fpos = min(abs(pos + (k*dist)), abs(pos - (k*dist)));
	} else {
	    pos = abs(pos - (nearest*dist));
	    k -= nearest;
	    if(k%2) {
	        pos = min(abs(pos + dist), abs(pos - dist));
	    }
	    fpos = pos;
	}
	cout<<fpos;
	return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

void solve()
{
    int n;
    cin >> n;
    ll a[n];

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

    int ans = 0;
    if(n<3)
    {
        cout << 0 << endl;
        return ;
    }
    sort(a, a+n);
    for(int i = 0; i<n-2; i++)
    {
        for(int j = i+1; j<n-1; j++)
        {
            for(int k = j+1; k<n; k++)
            {
                if(a[j]!=a[k]&&a[j]!=a[i]&&a[i]!=a[k] && a[i]+a[j]>a[k])
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t;
    solve();
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef uint64_t ull;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    ull k;
    cin >> n >> m >> k;
    vector<ull> a(n);
    vector<ull> b(m);
    ull last = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i] += last;
        last = a[i];
    }
    last = 0;
    for(int i=0; i<m; i++){
        cin >> b[i];
        b[i] += last;
        last = b[i];
    }
    int maxOne = 0;
    for(int i=0; i<n && a[i]<=k; i++){
        int books = i+1;
        ull rem = k-a[i];
        if(rem == 0){
            maxOne = maxOne > books ? maxOne:books;
            break;
        }

        int lo = 0;
        int hi = m;
        while(lo < hi){
            int mid = (lo+hi)/2;
            if(b[mid] == rem){
                lo = mid+1;
                break;
            }else if(b[mid]>rem){
                hi = mid;
            }else{
                lo = mid+1;
            }
        }
        books += lo;
        maxOne = maxOne > books ? maxOne:books;

    }
    int pos = 0;
    for(; pos<m; pos++){
        if(b[pos]> k){
            break;
        }
    }
    maxOne = maxOne > pos ? maxOne:pos;

    cout << maxOne << endl;

    
    return 0;
}

Measured memory_bytes: 6348
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
CD = [list(map(int, input().split())) for i in range(N)]
AB = sorted(AB, key=lambda x: x[1], reverse=True)
CD = sorted(CD)
ans = 0
for cd in CD:
    for ab in AB:
        if cd[0] > ab[0] and cd[1] > ab[1]:
            ans += 1
            AB.remove(ab)
            break


print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1 << 28
using namespace std;

int Search(vector<int> &a, vector<int> &r, int c, int n, const vector<vector<int>> &d) {
	int i, ans = INF;
	if (n == a.size()) {
		ans = 0;
		for (i = 0; i < a.size() - 1; i++)
			ans += d[r[a[i]]][r[a[i + 1]]];
		return ans;
	}
	for (i = 0; i < a.size(); i++) {
		if ((c >> i) & 1) {
			a[n] = i;
			ans = min(ans, Search(a, r, c - (1 << i), n + 1, d));
		}
	}
	return ans;
}

int main(void) {
	int num, m, r, i, j, k, a, b, c, ans;
	cin >> num >> m >> r;
	vector<vector<int>> d(num + 1, vector<int>(num + 1, INF));
	vector<int> x(r), R(r);
	for (i = 1; i <= num; i++)
		d[i][i] = 0;
	for (i = 0; i < r; i++)
		scanf("%d", &R[i]);
	for (i = 0; i < m; i++) {
		scanf("%d%d%d", &a, &b, &c);
		d[a][b] = min(d[a][b], c);
		d[b][a] = min(d[b][a], c);
	}
	for (k = 1; k <= num; k++) {
		for (i = 1; i <= num; i++) {
			for (j = 1; j <= num; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	ans = Search(x, R, (1 << r) - 1, 0, d);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 255; 
int n,mod,ans,l[N*2],r[N*2],f[N][N][N];

inline int Mod(int x){
	return x>=mod?x-mod:x;
}

int main(){
	n=read(),mod=read();
	For(i,1,2*n){
		int x=max(0,n*n-(i-1)*(i-1)),y=4*n*n-(i-1)*(i-1);
		l[i]=ceil(sqrt(x)),r[i]=min(int(sqrt(y)),2*n-1);
	}
	For(i,0,n) f[n+1][0][i]=1;
	int las=2*n+1;
	Dow(i,n+1,2){
		For(j,0,n-i+1){
			int x=1,p=las;
			while (r[p-1]<l[i-1]) --p,x=1ll*x*(r[p]+1-(2*n-p+j))%mod;
			f[i-1][j][j]=(f[i-1][j][j]+1ll*f[i][j][j]*x%mod*(r[i-1]+1-(n+j+(n-i+1-j))))%mod;
			For(k,j+1,n){
				f[i-1][j+1][k]=(f[i-1][j+1][k]+1ll*f[i][j][k]*(l[i-1]-1-(j+2*n-p))%mod*x)%mod;
				f[i-1][j][k]=(f[i-1][j][k]+1ll*f[i][j][k]*(r[i-1]+1-(n+k+(n-i+1-j)))%mod*x)%mod;
			}
		}
		while (r[las-1]<l[i-1]) --las;
	}
	For(i,0,n){
		int x=1;
		FOR(j,n+1,las) x=1ll*x*(r[j]+1-(i+(2*n-j)))%mod;
		if (i&1) ans=(ans+1ll*(mod-f[1][i][i])*x)%mod;
			else ans=(ans+1ll*f[1][i][i]*x)%mod;
	}
	printf("%d\n",(ans+mod)%mod);
}


Measured memory_bytes: 35972
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    ACGT = 'ACGT'

    ans = 0
    for i in range(len(S)):
        for j in range(i + 1, len(S) + 1):
            if j - i < ans:
                continue
            ok = True
            for c in S[i:j]:
                if c not in ACGT:
                    ok = False
                    break
            if ok and ans < j - i:
                ans = j - i

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9052
import java.util.*;

public class Main {

	public static void main(String[]$) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ((a*b)%2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}

	}

}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d, res1, res2;
    cin >> a >> b >> c >> d;
    if(a<b){
        res1 = a;
    }
    else{
        res1 = b;
    }
    
    if(c<d){
        res2 = c;
    }
    else{
        res2 = d;
    }
    cout << res1 + res2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin>>N;
  long long minimum=N-1;
  for(long long i=1;i<=sqrt(N);i++){
    if(N%i==0){
      minimum=min(minimum,N/i+i-2);
    }
  }
  cout<<minimum<<endl;
}
    


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

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  ll ret = n*(n-1) / 2;
  cout << ret << endl;
}


Measured memory_bytes: 256