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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vi a(n);
    ll odd = 0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2 == 1) odd++;
    }
    if(odd%2 == 0){
        cout<<"YES\n";
    } else {
        cout<<"NO\n";
    }


    timer();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll x,y,z; cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<endl;
    return 0;
}

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

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

  switch (D) {
    case 25:
      cout << "Christmas" << endl;
      break;
    case 24:
      cout << "Christmas Eve" << endl;
      break;
    case 23:
      cout << "Christmas Eve Eve" << endl;
      break;
    case 22:
      cout << "Christmas Eve Eve Eve" << endl;
      break;
  }

  return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll x,a,b;
    cin >> x >> a >> b;
    if(b-a > x)cout << "dangerous" << endl;
    else if(b-a > 0)cout << "safe" << endl;
    else cout << "delicious" << endl;
    return 0;
}

Measured memory_bytes: 256
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int a,b,c,k; cin >>a>>b>>c>>k;
    if(a >= k) cout << k << endl;
    else if(k <= b) cout << a << endl;
    else cout << a + -1*(k-a-b) << endl;
}

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

bool isprime(ll x) {
  if (x <= 1) return false;
  for (ll i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}

int main() {
  const ll n = 2e5;
  vector<ll> s(n);
  for (ll i = 1; i < n; i++)
    s[i] = s[i - 1] + ((i & 1) && isprime(i) && isprime((i + 1) / 2));
  ll q;
  cin >> q;
  for (ll i = 0; i < q; i++) {
    ll l, r;
    cin >> l >> r;
    cout << s[r] - s[l - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 4648
// https://atcoder.jp/contests/abc045/tasks/abc045_b

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n = 0, c[3] = {0, 0, 0};
  string p = "abc", P = "ABC", s[3];

  cin >> s[0] >> s[1] >> s[2];

  while (true)
  {
    if (c[n] == s[n].length())
      break;
    n = p.find(s[n][c[n]++]);
  }

  string r = P.substr(n, 1);

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
def main():
    s = input()
    t = input()

    sList, tList = list(s), list(t)

    sList.sort()
    tList.sort(reverse=True)

    sortedS = ''.join(sList)
    sortedT = ''.join(tList)

    if sortedS < sortedT:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,(int)s.size()) {
    if( i + 1 < (int)s.size() && s[i] != s[i+1] ) {
      ++cnt;
      ++i;
    }
  }
  cout << cnt << endl;
  compute();
  return 0;
}



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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string p; cin >> p;
    if (p == s) a--; else b--;
    cout << a << " " << b << "\n";

    return 0;
}

Measured memory_bytes: 256
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let x: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let primes = prime_sieve(2 * x);
    let mut ans = 0;
    for p in primes {
        if p >= x {
            ans = p;
            break;
        }
    }
    println!("{}", ans);
}

fn prime_sieve(n: usize) -> Vec<usize> {
    let mut table: Vec<usize> = vec![0; (n + 1) as usize];
    let mut primes: Vec<usize> = Vec::new();

    for i in 2..(n+1) {
        if table[i as usize] == 0 {
            primes.push(i);
            for j in 2..n {
                if i * j > n {
                    break
                }
                table[(i * j) as usize] = 1
            }
        }
    }

    primes
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n, m;
int f[N];
int fd(int x) { return x==f[x]?x:f[x]=fd(f[x]); }
void init() {
	rep(i, 1, n + 1) f[i] = i;
}
int main() {
	while(~scanf("%d%d", &n,&m)) {
		init();
		rep(i, 0, m) {
			int u, v, c; scanf("%d%d%d",&u, &v, &c);
			int fu = fd(u), fv = fd(v);
			f[fv] = fu;
		}
		int ret = 0;
		rep(i, 1, n + 1) if(i == fd(i)) ret++;
		printf("%d\n", ret);
	}
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		String[] line1b = line1.split(" ");
		int n = Integer.parseInt(line1b[0]);
		int m = Integer.parseInt(line1b[1]);

		String[] all = new String[n + m];

		int[] mm = new int[m];

		for (int i = 0; i < n + m; i++) {
			all[i] = sc.nextLine();
			if (i >= n) {
				mm[i - n] = Integer.parseInt(all[i]);
			}
		}

		int[] nn = new int[m];

		for (int i = 0; i < n; i++) {
			String[] kari = all[i].split(" ");
			int sum = 0;
			for (int j = 0; j < m; j++) {
				nn[j] = Integer.parseInt(kari[j]);
				sum += nn[j] * mm[j];
			}
			System.out.println(sum);
		}
	}

}

Measured memory_bytes: 29672
import java.util.Scanner;

class Main { 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        
        boolean primes[] = new boolean [100000000];
        for(int n = 2; n < primes.length; n++){
            if(primes[n]) continue;
            for(int m = 2 * n; m < primes.length; m += n){
                primes[m] = true;
            }
        }
               
        while (N != 0) {
            int num = in.nextInt();
            if (!primes[num]) count++;
            N--;
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 129892
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int N, M;
  cin >> N >> M;
  vector<int> hlist(N);
  rep(i,N) {
    int h;
    cin >> h;
    hlist.at(i) = h;
  }
  
  vector<queue<int>> miti(N, queue<int>());
  rep(i,M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    miti.at(a).push(b);
    miti.at(b).push(a);
  }
  
  int ans = 0;
  rep(i,N) {
    int jud = 0;
    queue<int> q = miti.at(i);
    int h = hlist.at(i);
    while(!q.empty()) {
      int k = q.front();
      q.pop();
      if (h>hlist.at(k)) continue;
      else jud++;
    }
    if (jud==0) ans++;
  }
  
  cout << ans << endl;
      

}

Measured memory_bytes: 71476
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <string>
using namespace std;

int main() {
	int n;
	cin >> n;
	int score[2] = {0,0};
	string t,h;
	for(int i=0; i<n; i++){
		cin >> t;
		cin >> h;
		if(t > h) score[0]+=3;
		else if(t < h) score[1]+=3;
		else{
			score[0]+=1;
			score[1]+=1;
		}
	}
	cout << score[0] << " " << score[1] << endl;
	//printf("%s\n", t);
	return 0;
}


Measured memory_bytes: 3200
#Aをソートしておく，時間ギリギリにi番目の料理を頼むことで固定．
N,T = map(int,input().split())
AB = [[0,0] for _ in range(N)]

for i in range(N):
    AB[i][0],AB[i][1] = map(int,input().split())

AB.sort()
#ソートした時のbの情報を維持しないと

# T-1分以内にi番目以外の料理をできるだけ完食する
#DP1[i][t]はi番目の料理まででt分後までに完食で得られる幸福度の最大(商品番号は1から振る)


dp1 =[[0]*T for _ in range(N+1)]

for i in range(N):
    for t in range(1,T):
        dp1[i+1][t] = dp1[i][t]
        if t-AB[i][0]>=0:
            dp1[i+1][t]=max(dp1[i][t],dp1[i][t-AB[i][0]]+AB[i][1])
            
ans=0
for i in range(N):
    ans=max(ans,dp1[i][-1]+AB[i][1])
print(ans)

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

int main(){
LOOP:
    int n, m;
    while(cin >> n >> m, n|m){
        vector<int> taro(n), hana(m);
        rep(i, n)cin >> taro[i];
        rep(i, m)cin >> hana[i];
        sort(all(taro));
        sort(all(hana));
        int diff = accumulate(all(taro), 0) - accumulate(all(hana), 0);
        rep(i, n)rep(j, m){
            if(diff != 2 * (taro[i] - hana[j]))continue;
            cout << taro[i] << ' ' << hana[j] << '\n';
            goto LOOP;
        }
        cout << "-1\n";
    }
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  for (int i = 0; i < N; ++i)
  {
    ans = min(ans * 2, ans + K);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[1], reverse=True)
cd.sort()

ans = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            ans += 1
            ab.remove([a, b])
            break

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

int N,K,Q,A[2020];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<ll> a(n);
    map<ll,int> mp;
    REP(i,n){
        cin>>a[i];
        mp[a[i]]=i;
    }
    int ans=0;
    VSORT(a);
    REP(i,n){
        if(mp[a[i]]%2==0 && i%2==1) ans++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 7296
n=int(input())
e=[[]for i in range(n)]
for i in range(n-1):a,b=map(int,input().split());e[a-1].append(b-1);e[b-1].append(a-1)
c,Q,l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0
print(sum(c[1:]))
while Q:
 a=Q.pop()
 if l[a]!=0:continue
 l[a]=c[i];i+=1
 for j in e[a]:Q.append(j)
print(*l)

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

int main(){
    int n, k;
    cin >> n >> k;
    ll a[n+1];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll sum1[100005] = {};
    ll sum2[100005] = {};
    for(int i = 0; i < n; i++){
        sum1[i + 1] = sum1[i] + max(0LL, a[i]);
        sum2[i + 1] = sum2[i] + a[i];
    }
    ll ans = -1e18;
    for(int i = 0; i + k <= n; i++){
        ll tmp = sum1[i] + sum1[n] - sum1[i+k];
        tmp += max(0LL, sum2[i+k] - sum2[i]);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int k, n, a[200200];

int main()
{
	scanf ("%d %d", &k, &n);
	for (int i = 0; i < n; i++) scanf ("%d", &a[i]);
	int mx = k + a[0] - a[n-1];
	for (int i = 1; i < n; i++){
		int d = a[i] - a[i - 1];
		if (mx < d)
			mx = d;
	}
	printf ("%d\n", k - mx);

	return 0;
}

Measured memory_bytes: 3932
n, m = map(int, input().split())
c = list(map(int, input().split()))

INF = 10**9
MAX = n + 1
dp = [INF for _ in range(MAX)]
dp[0] = 0
for i in range(m):
    for j in range(len(dp)):
        if j + c[i] < MAX:
            dp[j+c[i]] = min(dp[j] + 1, dp[j+c[i]])

min_v = dp[-1]
for i in range(len(dp)):
    idx = len(dp) - 1 - i
    min_v = min(min_v, dp[idx])
    dp[idx] = min_v

print(dp[n])



Measured memory_bytes: 7636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
 // #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif
ll n,l;
cin>>n;
string a;
cin>>a;
ll i;
l=a.size();
if(l<=n)
{for(i=0;i<l;i++)
    cout<<a[i];
}
if(l>n)
{for(i=0;i<n;i++)
    cout<<a[i];
    cout<<"...";
}
return 0;}

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


int F(long long A, long long B)
{
	long long C = max(A,B);
	int n = 0;
	while (C > 0)
	{
		C /= 10;
		n += 1;
	}
	return n;
}

int main()
{
	long long n; cin >> n;
	int m = 1e9;
	for (long long i = 1; i*i <= n; ++i)
	{
		long long j = n / i; 
		if (j * i == n)
			m = min(m, F(i, j));
	}
	cout << m << endl;
}



Measured memory_bytes: 3624
#include <stdio.h>

#define len_string_max 4

int calculate_points (char* data_string)
{
    // constants for `calculate_points`
    const char* sym_pls1 = '+';
    const char* sym_mns1 = '-';

    // variables for `calculate_points`
    int points;

    // STEP.01
    // initialize the points
    points = 0;

    // STEP.02
    // calculate the points using given string
    for (size_t itr = 0; itr < len_string_max; itr++)
    {
        if (data_string[itr] == sym_pls1) points++;
        if (data_string[itr] == sym_mns1) points--;
    }

    // STEP.END
    return points;
}

int main (void)
{
    // variables for `main`
    char given_string[len_string_max];

    // STEP.01
    // read out the given string
    scanf("%s", given_string);

    // STEP.02
    // calcualte & output the points
    printf("%d\n", calculate_points(given_string));

    // STEP.END
    return 0;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}
// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll n,d;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    ll cnt =0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            for(ll k=j+1;k<n;k++)
            {
                if(arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[k]!=arr[i]&&arr[i]+arr[j]>arr[k]&&arr[j]+arr[k]>arr[i]&&arr[k]+arr[i]>arr[j])
					cnt++;
            }
        }
    }
    cout<<cnt<<'\n';
}

// Driver Function
int main()
{
    ll compte = 1;
   // test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3604
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s <- C.getLine
  let r = C.reverse s
  let b = isIn $ C.unpack r
  if b then putStrLn "YES"
       else putStrLn "NO"

isIn
  :: String -> Bool
isIn s = isIn' s False
  where
    isIn' ""                               b = b 
    isIn' ('r':'e':'m':'a':'e':'r':'d':ss) _ = isIn' ss True 
    isIn'         ('m':'a':'e':'r':'d':ss) _ = isIn' ss True 
    isIn'     ('r':'e':'s':'a':'r':'e':ss) _ = isIn' ss True
    isIn'         ('e':'s':'a':'r':'e':ss) _ = isIn' ss True
    isIn' _                                _ = False

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

using namespace std;

int main(){
	int t;
	cin>>t;
	vector<long long> a(t);
	for(int i=0;i<t;i++){
		cin>>a[i];
	}
	int s=0;
	for(int i=0;i<t-2;i++){
		for(int j=i+1;j<t-1;j++){
			if(a[i]!=a[j])
			for(int k=j+1;k<t;k++){
				if(a[i]!=a[k]&&a[j]!=a[k]){
					if(2ll*max(max(a[i],a[j]),a[k])<(a[i]+a[j]+a[k])){
						s++;
					}
				}
			}
		}
	}
	cout<<s<<endl;
}



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

using namespace std;

int main() {
	int n; cin >> n;
	int cnt4=0,cnt2=0,cnt1=0;
	for(int i=0;i<n;++i) {
		int a; cin >> a;
		if(a%4==0) ++cnt4;
		else if(a%2==0) cnt2=1;
		else ++cnt1;
	}
	if(cnt1+cnt2-1<=cnt4) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


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

const int INF = 100100100;

int c[15][1005];

int main(){
	int h,w,k;
	cin >> h >> w >> k;
	
	vector<string> s(h);
	rep(i,h){
		cin >> s[i];
	}
	
	int ans = INF;
	
	rep(bit, 1<<(h-1)){
		int div = 0;
		vector<int> id(h);
		bool ok = true;
		rep(i,h){
			id[i] = div;
			if(bit >> i & 1) div++;
		}
		div++;
		
		rep(i,div)rep(j,w) c[i][j] = 0;
		rep(i,h)rep(j,w) c[id[i]][j] += s[i][j] - '0';
		
		rep(i,div){
			rep(j,w){
				if(c[i][j] > k) ok = false;
			}
		}
		if(!ok) continue;
		
		int count = div - 1;
		
		vector<int> now(div,0);
		rep(j,w){
			bool flag = true;
			rep(i,div){
				now[i] += c[i][j];
			}
			rep(i,div){
				if(now[i] > k){
					flag = false;
				}
			}
			if(!flag){
				rep(i,div){
					now[i] = c[i][j];
				}
				count++;
			}
		}
		
		ans = min(ans, count);
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
	int N;
	cin >> N;
 
	if ((N + 3) % 10 == 0 || (N + 30) % 100 == N % 10 || (N + 300) % 1000 == N % 100 ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();

        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i-1) == 'A' && s.charAt(i) == 'C') arr[i]++;
            arr[i] += arr[i-1]; // plus curr value with prev 
        }

        for (int i = 0; i < q; i++) {
            int start = sc.nextInt() - 1;
            int end = sc.nextInt() - 1;

            System.out.println(arr[end] - arr[start]);
        }
    }
}

Measured memory_bytes: 63960
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[401]  = {};
ll sm[401] = {};

ll dp[401][401] = {};

ll solve(int l, int r){
    if (l == r) return 0;
    if (dp[l][r]) return dp[l][r];
    ll res = LONG_LONG_MAX;
    ll dif = sm[r] - sm[l-1];
    for(int i = l; i < r; i++){
        res = min(res, solve(l, i) + solve(i+1, r) + dif);
    }
    dp[l][r] = res;
    return dp[l][r];
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sm[i] += a[i] + sm[i-1];
    }
    cout << solve(1, n) << endl;
}

Measured memory_bytes: 1536
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  unordered_map<int64_t, int64_t> numP;
  rep(i, N) {
    int64_t a;
    cin >> a;
    A[i] = a;
    numP[a + (i + 1)]++;
  }

  int64_t answer = 0;
  rep(i, N) {
    int64_t key = (i + 1) - A[i];
    answer += numP[key];
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=2e5+100;
ll n,V;
ll v[100],w[100];
ll ansv,answ,ans;

int dp[N];
vector<int>ve;
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    ve.push_back(1);
    int k=6;
    for(int i=0;i<=n;i++) dp[i]=i;
    while(k<=n){
         ve.push_back(k);
         k*=6;
    }
    k=9;
    while(k<=n){
        ve.push_back(k);
        k*=9;
    }

    for(int i=0;i<ve.size();i++){
        for(int j=ve[i];j<=n;j++){
            dp[j]=min(dp[j],dp[j-ve[i]]+1);
        }
    }
    cout<<dp[n]<<endl;
}


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

ll k, a[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	k = read();
	printf("%lld\n", a[k]);
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

X,K,D=map(int,input().split())

if X<0:
    X=-X

A=X//D

if K<A:
    print(X-K*D)
else:
    K-=A
    X-=A*D

    if K%2==0:
        print(X)
    else:
        print(abs(X-D))


Measured memory_bytes: 9068
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int N;
double ans = 0.0;
vector<vector<vector<double>>> dp; 

double coins_alt(vector<double>& v, int i, int tail_size)
{
  if (i == v.size())
  {
    return 1.0;
  }
  double ans = 0.0;
  if (tail_size < N/2)
  {
    if (dp[0][i+1][tail_size+1] == -1) 
    {
      dp[0][i+1][tail_size+1] = coins_alt(v, i+1, tail_size+1);
    }
    ans = (1.0 - v[i]) * dp[0][i+1][tail_size+1];
  }
  if (dp[0][i+1][tail_size] == -1)
  {
    dp[0][i+1][tail_size] = coins_alt(v, i+1, tail_size);
  }
  ans += v[i] * dp[0][i+1][tail_size];
  return ans;
}

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

  std::cin >> N;

dp.push_back(vector<vector<double>>(N+1, vector<double>(N+1, -1.0)));
dp.push_back(vector<vector<double>>(N+1, vector<double>(N+1, -1.0)));

  vector<double> head(N, 0.0);

  for (auto& p : head)
  {
    std::cin >> p;
  }

  auto ans = coins_alt(head, 0, 0);

  std::cout << std::setprecision(10) << ans;

  return 0;
}

Measured memory_bytes: 141440
import sys

inputs = [row.split() for row in sys.stdin.readlines()]

values = []
for current_row in inputs:
    for value in current_row:
        values.append(int(value))

if values[1] < values[0]:
    val_1 = values[0]
    values[0]=values[0]-1
else:
    val_1 = values[1]
    values[1]=values[1]-1

if values[1] < values[0]:
    val_2 = values[0]
else:
    val_2 = values[1]

print(val_1+val_2)




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

int n,sum = 1;
string s;

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

	for(int i=1; i<n; i++)
		if(s[i]!=s[i-1])
			sum++;

	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 512
from sys import stdin

def main():
    from collections import defaultdict
    input = stdin.readline

    n = int(input())
    a = sorted(list(map(int, input().split())))
    p = defaultdict(int)
    for x in a:
        p[x] += 1
    f = [True] * (10 ** 6 + 1)
    for k, v in p.items():
        if v > 1:
            f[k] = False
        for i in range(k + k, 10 ** 6 + 1, k):
            f[i] = False
    print(sum(1 for x in a if f[x]))
main()

Measured memory_bytes: 40128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const ll INF = ll(1e18) + 1;

int main() {
  ll n, W;
  cin >> n >> W;
  vector<ll> w(n);
  vector<ll> v(n);
  vector<vector<ll>> bag(4);
  rep(i, n) {
    cin >> w[i] >> v[i];
  }

  ll base = w[0];
  rep(i, n) {
    ll weight = w[i] - base;
    bag[weight].push_back(v[i]);
  }

  ll ans = 0;
  rep(i, 4) {
    sort(bag[i].rbegin(), bag[i].rend());
    bag[i].insert(bag[i].begin(), 0);
  }

  ll cur1 = 0;
  rep(i, bag[0].size()) {
    cur1 += bag[0][i];
    ll cur2 = 0;
    rep(j, bag[1].size()) {
      cur2  += bag[1][j];
      ll cur3 = 0;
      rep(k, bag[2].size()) {
        cur3 += bag[2][k];
        ll cur4 = 0;
        rep(l, bag[3].size()) {
          cur4 += bag[3][l];
          ll value = cur1 + cur2 + cur3 + cur4;
          ll weight = i * base + (1 + base) * j + (2 + base) * k + (3 + base) * l;
          if(weight > W) continue;
          ans = max(ans, value);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = s; i < n; i++)
#define INF 10000000000
using namespace std;

struct BR {double x, y, r;};

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

	int N;
	BR b[1002];
	cin >> b[0].x >> b[0].y >> b[1].x >> b[1].y >> N;
	N += 2;
	REP(i, N, 2) {
		cin >> b[i].x >> b[i].y >> b[i].r;
	}

	using P = pair<double, int>;
	vector<P> G[1002];
	REP(i, N, 0) {
		REP(j, N, i + 1) {
			double dis = max(0.0, sqrt((b[i].x - b[j].x) * (b[i].x - b[j].x) + (b[i].y - b[j].y) * (b[i].y - b[j].y)) - b[i].r - b[j].r);
			G[i].emplace_back(dis, j);
			G[j].emplace_back(dis, i);
		}
	}
	double d[1002];
	fill(d, d + N, INF);
	d[0] = 0.0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.emplace(0.0, 0);
	while (que.size()) {
		double dis = que.top().first;
		int c = que.top().second;
		que.pop();
		if (dis > d[c]) continue;
		for (P p : G[c]) {
			if (d[p.second] > d[c] + p.first) {
				d[p.second] = d[c] + p.first;
				que.emplace(d[p.second], p.second);
			}
		}
	}
	cout << fixed << setprecision(12) << d[1] << endl;

	return 0;
}

Measured memory_bytes: 20740
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
void solve(void)
{
  string str;
  cin>>str;
  sort(str.begin(),str.end());
  if(str =="abc")
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    string s;cin>>s;
    if(s.size()<4){
        cout<<"No"<<endl;return 0;
    }
    string t=s.substr(0,4);
    if(t=="YAKI") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
# import math
n = int(input())
a = list(map(int, input().split()))


def f(list):
    a = 1
    for i in list:
        a = a*i
    return a


def main():

    if 0 in a:
        print(0)
    else:
        prod = 1
        for i in a:
            prod *= i
            if prod > 10**18:
                print(-1)
                return
        print(prod)


main()
# log_prod_a = sum(map(math.log10, a))
# if log_prod_a < 18.0:
#     print(f(a))
# else:
#     print(-1)


Measured memory_bytes: 88024
// #pragma GCC optimize "trapv"

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int> 
#define vll vector<ll> 
#define vpll vector<pair<ll ,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define MAP map<ll ,ll>
#define UMAP unordered_map<ll , ll>
#define endl "\n"
#define SET set<ll> 
#define SETC set<char>
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define fastcout ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcases int tt = 1 ; cin >> tt ; for(int i = 1 ; i <= tt ; ++i)
#define codejam cout << "Case #"<<i <<": "; 
#define FOR(i,a,n) for(int i = a ; i <= n ; ++i)
#define FORback(i,a,n) for(int i = n ; i >= a ; --i)
#define time cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define ll long long int
const ll INF = 1e13+7;
const ll mod = 1e9+7;

vvll graph;
vvll dp;

ll doSome(int curr , int color , int parent){

    ll ans= 0 ;

    if(dp[curr][color] != -1){
        return dp[curr][color];
    }

    ll temp = 1;
    ll temp2 = 1;
    
    for(auto x : graph[curr]){

        if(x != parent){
            // let's say it's black
            temp *= doSome(x , 1 , curr);
            temp %= mod;
            if(color){
                temp2 *= doSome(x , 0 , curr);
                temp2 %= mod;
            }
        }

    }
    if(color){
        ans += temp2;
        ans %= mod;
    }
    
    ans += temp;

    return dp[curr][color] = ans%mod;

}

void solv(){
    ll n ;
    cin >> n ;
    graph.assign(n+2 , vll());
    FOR(i , 1 ,n-1){
        ll a , b ;
        cin >> a >> b ;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ll ans = 0;
    dp.assign(n+2 , vll(2 , -1));
        // here i have taken color 1 as white and 0 as black
    ans += doSome(1 , 1  , -1);
    cout << ans  << endl;
}

int main(){
    fast ;    
    // testcases{
        // codejam ;
        solv();
    // } 
}


Measured memory_bytes: 22416
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline int read() {
    int res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n, ans;
int a[N];

int main() {
    n = read();
    for (int i = 1; i <= n; i++) {
        a[i] = read();
    }
    std::sort(a + 1, a + n + 1);
    for (int i = n; i >= 1; i--) {
        for (int j = i - 1; j >= 1; j--) {
            int db = a[i] - a[j];
            int pos = std::upper_bound(a + 1, a + j, db) - a;
            if (pos < j) {
                // printf("%d %d %d\n", a[i], a[j], a[pos]);
                ans += j - pos;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
	int n;
	string S[50];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> S[i];
	}
	
	int cnt[26];
	int min[26];
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 26; j++){
			cnt[j] = 0;
		}
		for(int c = 0; c < S[i].size(); c++){
			cnt[S[i][c] - 'a' + 0]++;
		}
		for(int j = 0; j < 26; j++){
			if(i == 0){
				min[j] = cnt[j];
			}
			else if(min[j] >= cnt[j]){
				min[j] = cnt[j];
			}
		}
	}
	
	for(int j = 0; j < 26; j++){
		for(int i = 0; i < min[j]; i++){
			char ans = j + 'a';
			cout << ans;
		}
	}

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

typedef long long ll;

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

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int panel[2][100];

void arrFillZero(int *arr, int length){
  fill(&arr[0],&arr[length],0);
}

int main(void){

  int N;
  cin >> N;
  int imos1[N];
  int imos2[N];

  arrFillZero(imos1,N);
  arrFillZero(imos2,N);

  REP(i,2){
    REP(k,N){
      cin >> panel[i][k];
    }
  }
  imos1[0]   = panel[0][0];
  imos2[N-1] = panel[1][N-1];
  FOR(i,1,N){
    imos1[i] += imos1[i-1] + panel[0][i];
  }
  for(int i = N-2; i>=0; i--){
    imos2[i] += imos2[i+1] + panel[1][i];
  }

  int ans = 0;
  REP(i,N){
    ans = max(imos1[i]+imos2[i],ans);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define pb push_back
#define LL long long
const int N=300010;
using namespace std;

int n,m;

struct nn{
	int pos,val;
};

int cmp(nn A,nn B){
	return A.val>B.val;
}

nn hlp[6];
nn mx[2][N];

void READ(){
	scanf("%d",&m);
	n=(1<<m)-1;
	rep(i,0,n){
		scanf("%d",&mx[0][i].val);
		mx[0][i].pos=mx[1][i].pos=i;
		mx[1][i].val=0;
	}
}

void CHK(int x,int y){
	hlp[1]=mx[0][x];hlp[2]=mx[1][x];hlp[3]=mx[0][y];hlp[4]=mx[1][y];
	sort(hlp+1,hlp+4+1,cmp);
	mx[0][x]=hlp[1];
	rep(i,2,4){
		if(hlp[i].pos!=hlp[1].pos){
			mx[1][x]=hlp[i];
			return;
		}
	}
}

void INIT(){
	rep(i,0,n){
		rep(j,0,m-1){
			if(!(i&(1<<j)))continue;
			CHK(i,i^(1<<j));
		}
	}
}

int GET(int x){
	int ans=mx[0][x].val+mx[1][x].val;
	int flp=0;
	tep(i,m-1,1){
		if(!(x&(1<<i)))continue;
		int now=(flp|((1<<i)-1));
		ans=max(ans,mx[0][now].val+mx[1][now].val);
		flp|=(1<<i);
	}
	return ans;
}

int main(){
	READ();
	INIT();
	rep(i,1,n)printf("%d\n",GET(i));
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int N; cin >> N;
    int f = 0, d = 0, n = 0;
    REP(i, N) { int k; cin >> k; if (k % 4 == 0) f++; else if (k % 2 == 0) d++; }
    n = N - (f + d);
    cout << (n + d % 2 - f <= 1 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
/// 2:30 PM 21/06/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    string ans = "";
    while (n > 0) {
        n--;
        ans += ('a' + (n % 26));
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 3616
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val h = (0 until n).map { sc.next().toInt() }
    println(problem116c(n, h))
}

fun problem116c(n: Int, h: List<Int>): Int {
    val h = h.toIntArray()
    val list = IntArray(n) { 0 }
    var count = 0
    while (true) {
        var isSame = true
        for (i in 0 until n) {
            if (list[i] != h[i]) {
                list[i] += 1
                if (isSame) count++
                isSame = false
            } else {
                isSame = true
            }
        }
        if (list.toList() == h.toList()) break
    }
    return count
}

Measured memory_bytes: 36212
#input
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[0], A[1] = B[0], B[0]
for i in range(1, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]

print(sum(A))

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
// #include<algorithm>
// #include<queue>
// #include<string>
#include <iomanip>
using namespace std;

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

    double r = 0;

    for(int i=0;i<n;i++){
        r += (double)(1/(double)v[i]);
    }
    r = (double)(1/(double)r);

    cout<<setprecision(7)<<r<<endl;
    
}

Measured memory_bytes: 256
count = 0
S= input()
T= input()
forecast1 = S[0]
result1 =T[0]

if forecast1 == result1:
    count = count + 1

forecast2 = S[1]
result2 = T[1]

if forecast2 == result2:
    count = count + 1

forecast3 = S[2]
result3 = T[2]

if forecast3 == result3:
    count = count + 1

print(count)

Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {
  rep(i, v.size()) is >> v[i]; return is;
}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
  rep(i, v.size()) os << v[i] << " "; os << endl; return os;
}
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;


int main() {
  ll n; cin >> n;
  V l(n), r(n);
  rep(i, n) cin >> l[i] >> r[i];
  sort(all(l), greater<int>());
  sort(all(r));

  ll ans = 0, ans1 = 0;
  rep(i, n) chmax(ans1, ans1+l[i]-r[i]);
  chmax(ans, ans1);

  ans1 = l[0];
  rep(i, n-1) chmax(ans1, ans1+l[i+1]-r[i]);
  chmax(ans, ans1);

  ans1 = -r[0];
  rep(i, n-1) chmax(ans1, ans1+l[i]-r[i+1]);
  chmax(ans, ans1);
  
  ans *= 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
def main():
    n = int(input())
    d = list(map(int,input().split()))
    diff = d.sort()
    if len(d) % 2 == 0:
        takai = len(d)//2
        hikui = takai - 1
        ans = d[takai] - d[hikui]
        print(ans)

    else:
        print(0)

main()

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

int main()
{
	int i, N;
	long long a[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &(a[i]));
	
	long long sum[200001] = {}, min;
	for (i = 1; i <= N; i++) sum[i] = sum[i-1] + a[i];
	for (i = 2, min = llabs(sum[N] - sum[1] * 2); i < N; i++) {
		if (llabs(sum[N] - sum[i] * 2) < min) min = llabs(sum[N] - sum[i] * 2);
	}
	
	printf("%lld\n", min);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#define max(x, y) ((x)<(y) ? (y) : (x))

int main(){
  long mod = 1e9+7;
  int n, m;  scanf("%d %d", &n, &m);
  int a[100005] = {0}; a[m+1] = n+1;  a[0] = -10000;
  for(int i=1; i<=m; i++){
    scanf("%d", a+i);
    if(a[i] - a[i-1] <= 1){
      printf("0\n");
      return 0;
    }
  }
  if(a[m+1] - a[m] <= 1){ printf("0\n"); return 0; }
  a[0] = 1;
  int now = 0, b[100005] = {0}, maxi = 0;
  for(int i=1; i<=m+1; i++){
    b[i] = a[i] - 1 - now;
    maxi = max(maxi, b[i]);
    now = a[i] + 1;
  }

  long fibo[100005] = {0};  fibo[1] = fibo[0] = 1;
  for(int i=2; i<=maxi; i++)
    fibo[i] = (fibo[i-1] + fibo[i-2]) % mod;

  long ans = 1;
  for(int i=1; i<=m+1; i++)
    if(b[i])
      ans = (ans * fibo[b[i]]) % mod;


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


Measured memory_bytes: 3292
#include<iostream>
#include<vector>

using namespace std;

int N,M;
const int maxN=100100;
vector<int> G[maxN];
int H[maxN];

void add_edge(int from, int to){
    G[from].push_back(to);
    G[to].push_back(from);
}

void input(){
    cin >> N >> M;
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        add_edge(a-1, b-1);
    }
}

int main(){
    input();
    int count=0;
    for(int v=0;v<N;v++){
        bool c=true;
        for(int j=0;j<G[v].size();j++){
            int u=G[v][j];
            if(H[u]>=H[v]) c=false;
        }
        if(c) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 8720
#include<stdio.h>
int main()
{
   

    int N;
  
    scanf("%d", &N);
  	int A[N];
  	int B[N];
  	int C[N-1];
  
  	int i=0;
  for(i=0;i<N;i++){
	scanf("%d", &A[i]);
  }
  
  int sum = 0;
   for(i=0;i<N;i++){
	scanf("%d", &B[i]);
     sum = sum + B[i];
    // printf("sum%d",sum);
  }
   int ch[N-1];
   for(i=0;i<N-1;i++){
	scanf("%d", &C[i]);
     ch[i] = 0;
  }
 
     for(i=0;i<N-1;i++){
	if(A[i] == A[i+1]-1){
      ch[A[i]-1] = 1;
   //   printf("i:%d",i);
    }
  }
  
  for(i=0;i<N-1;i++){
	if(ch[i] == 1){
     // printf("i:%d",i);
		sum = sum +C[i];
      //printf("sum:%d",sum);
    }
  }
  
  
  
 
    printf("%d",sum);//printf("%c",s[0])//文字一つ分のみを出力

    return 0;
}

Measured memory_bytes: 128
#include "iostream"

using namespace std;

int gcd(int a,int b){
	if(a<b){
		swap(a,b);
	}
	while(b){
		a%=b;
		swap(a,b);
	}
	return a;
}

int main(){
	int N,M,K;
	cin>>N>>M>>K;
	cout<<N*M/gcd(N,M)/gcd(N,M)*K<<endl;
	
	return 0;
}


Measured memory_bytes: 3104