akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
constexpr int INF = 1e9, MOD = 1e9 + 7;
constexpr int64_t LINF = 5e18, LMOD = 998244353;
// #include <atcoder/all>
// using namespace atcoder;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int64_t a[200010];
int main() {
	int64_t n; cin >> n;
	int64_t x, m; cin >> x >> m;
	set<pair<int64_t, int64_t>> st;
	a[0] = x;
	st.emplace(x, 0);
	int64_t l = -1, r;
	for(int64_t i = 1; i < n; ++i) {
		x *= x;
		x %= m;
		// cerr << x << '\n';
		a[i] = x;
		auto itr = st.lower_bound({x, 0});
		if(itr != st.end()) {
			if(itr->first == x) {
				l = itr->second;
				r = i - 1;
				break;
			}
		}
		st.emplace(x, i);
	}
	// cerr << l << " " << r << '\n';
	int64_t ans = 0;
	if(l < 0) {
		for(int i = 0; i < n; ++i) {
			ans += a[i];
		}
		cout << ans << '\n';
		return 0;
	}
	for(int i = 0; i < l; ++i) {
		ans += a[i];
	}
	int64_t lo = 0;
	for(int i = l; i <= r; ++i) {
		lo += a[i];
	}
	int64_t cnt = (n - l) / (r - l + 1);
	int64_t mo = (n - l) % (r - l + 1);
	// cerr << cnt << " " << mo << '\n';
	ans += cnt * lo;
	for(int i = 0; i < mo; ++i) {
		ans += a[l + i];
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 7072
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	static IntStream REPS(int r){
		return IntStream.range(0,r);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INTS(int l){
		return REPS(l).map(i->getInt());
	}
	public static void main(String[]__){
		System.out.println(
				Long.parseLong(s.next()+s.next()+s.next())
				%4==0?"YES":"NO"
				);
	}
}


Measured memory_bytes: 21716
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

//	public static int max = 0;

	public static int[] a = {1, 2};

	public static void main(String[] args) {

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		int n = sc.nextInt();
//		int m = sc.nextInt();
		String s = sc.next();
		String t = sc.next();

//		int[] ans = new int[n];

//		ArrayList<Integer> list = new ArrayList<>();


		//-------------------------------------------------------------------------------------

		String[] sa = s.split("");
		String[] ta = t.split("");
		
		for(int i = 0; i < sa.length; i++) {
			if(!sa[i].equals(ta[i])) {
				f = true;
				break;
			}
		}

		//-------------------------------------------------------------------------------------

//		for(int i = 0; i < n; i++) {
//			System.out.println(ans[i]);
//		}

		if(!f) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

//		System.out.println(ans);

		sc.close();
	}
}

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

int main(){
	int n,s,t;
	cin >> n >> s >> t;
	int dist;
	cout << "? " << s << " " << t << endl;
	cout.flush();
	cin >> dist; 
	vector<int> ds(n+1), dt(n+1);
	vector<pair<int, int> > ds_sorted;
	for(int i=1; i<=n; i++){
		if(i==s or i==t) continue;
		cout << "? " << s << " " << i << endl;
		cout.flush();
		cin >> ds[i];
		cout << "? " << i << " " << t << endl;
		cout.flush();
		cin >> dt[i];
		if(ds[i] + dt[i] == dist){
			ds_sorted.emplace_back(ds[i], i);
		}
	}
	sort(ds_sorted.begin(), ds_sorted.end());
	/*
	for(auto p: ds_sorted){
		cout << p.first << " " << p.second << endl;
		cout.flush();
	}
	*/
	vector<int> ans(1, s);
	int curr = s;
	for(auto pii: ds_sorted){
		cout << "? " << curr << " " << pii.second << endl;
		cout.flush();
		int ret;
		cin >> ret;
		if(ret + dt[pii.second] == dist){
			dist -= ret;
			curr = pii.second;
			ans.push_back(pii.second);
		}
	}

	cout << "! ";
	for(int i: ans){
		cout << i << " ";
	}
	cout << t << endl;
	cout.flush();
	
	int ret;
	if(cin >> ret){
		if(ret == -1){
			return -1;
		}
	}
	return 0;
}


Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll cnt = 0;
	while(b <= a) {
		++cnt;
		b *= 2;
	}
	while(c <= b) {
		++cnt;
		c *= 2;
	}
	if(cnt <= k) {
		cout << "Yes";
	}
	else cout << "No";
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> cnt(N);
    for(int i=0;i<N-1;i++){
        int a;cin>>a;
        a--;
        cnt[a]++;
    }
    for(int i=0;i<N;i++) cout<<cnt[i]<<"\n";
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define SORT(v) sort(v.begin(),v.end())
#define fori(i,a,b) for(ll i=a;i<b;i++)
#define M 1000000007
#define deb(x) cout<< #x << " " << x << endl;

double pi=3.14159265358979323846;

typedef pair<int,int> pii;
typedef pair<long long int, long long int>pll;
typedef vector<int>vi;
typedef vector<long long int>vl;
#define MAXN 10000001
 
int main ()
{
    ll T;
   T=1;
   //cin>>T;
    while(T--)
    {	
    ll n,k;
    cin>>n>>k;
    vi v(n);
    fori(i,0,n)cin>>v[i];
    vi dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    ll mn=INT_MAX;
    for(ll i=2;i<n;i++){
    	for(ll j=i-1;j>=(max((ll)(0),i-k));j--){
    		dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
    	}
    }
    
	cout<<dp[n-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c;
    cin>>a>>b>>c;
    if(b*c>=a) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    int bu[40];
    memset(bu, 0, sizeof(bu));
    REP(i,n) {
        int k;
        cin >> k;
        REP(j,k) {
            int a;
            cin >> a;
            bu[a]++;
        }
    }
    int cnt = 0;
    REP(i,40) {
        if (bu[i]==n) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1.0/LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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 gcd(int a,int b){return b?gcd(b,a%b):a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

class CGreenBin {
public:
    int N;
    ll ans = 0;
    map<string, int> m;

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        REP(i, N) {
            string s; in >> s;
            sort(ALL(s));
            if (m.find(s) == m.end()) {
                m[s] = 1;
                continue;
            }
            else {
                ans += m[s];
                m[s]++;
            }
        }
        OUT(ans);
    }
};


int main() {
    CGreenBin solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


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


int main()
{
  ll n, g;
  cin >> n;
  vecll a(n);
  forll(i, 0, n)
	cin >> a[i];
  sort(a.begin(), a.end());
  g = a[0];
  forll(i, 1, n){
	g = gcd(a[i], g);
  }
  cout << g << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int k;cin>>k;
	int ans = 0;
	for(int i = 1; i <= k; i++) {
		for(int j = 1;j <= k; j++) {
			for(int l = 1;  l <= k; l++) {
				ans += __gcd(i,__gcd(j,l));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt;
use std::io::{self, BufWriter, Read, StdinLock, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};


fn solve(n: usize) -> u64 {
    let mut v = vec![0; n + 1];
    v[0] = 2;
    v[1] = 1;
    for i in 2..n + 1 {
        v[i] = v[i - 1] + v[i - 2];
    }
    v[n]
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next()));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(1024),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        let buf = &mut self.buf;
        buf.clear();
        self.bytes
            .by_ref()
            .map(Result::unwrap)
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
            .foreach(|c| buf.push(c));
        str::from_utf8(&buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
        <T3 as FromStr>::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }
}


trait Foreach {
    type Item;
    fn foreach<F: FnMut(Self::Item)>(self, f: F);
}

impl<T, I: Iterator<Item = T>> Foreach for I {
    type Item = T;

    fn foreach<F: FnMut(T)>(self, mut f: F) {
        self.fold((), move |(), x| f(x));
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: fmt::Display, I: IntoIterator<Item = T>>(xs: I) {
    let stdout = io::stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    for x in xs.into_iter() {
        writeln!(stdout, "{}", x).unwrap();
    }
    stdout.flush().unwrap();
}


#[allow(dead_code)]
fn print_or<T: fmt::Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

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

    int n;cin>>n;
    vector<ll> a(n+1),xo(n+1),sum(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        xo[i]=a[i]^xo[i-1];
        sum[i]=a[i]+sum[i-1];
    }
    ll res=0;
    int l=0;
    for(int i=1;i<=n;i++){
        while(sum[i]-sum[l]!=(xo[i]^xo[l])){
            l++;
        }
        res+=i-l;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
const ull MOD = 1000000007;
const int MAX_N = 100000;
ull fact[MAX_N + 1];
int main(){
    vector<ull> ans;
    fact[0] = 0;
    fact[1] = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    while (1){
        int N, R;
        ull num = 0;
        cin >> N;
        if (N == 0) break;
        ans.push_back(0);
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        cin >> R;
        vector<int> s(2*R+1, 0);
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            int t = word[s[i]];
            word[s[i]] = word[s[i+R]];
            word[s[i+R]] = t;
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        s.push_back(N);
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ull tmp = fact[N - s[i] - 1], tmp2 = 0;
            tmp *= word[s[i]];
            tmp = tmp % MOD;
            for (int j = i; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? 1 : 0);
                if (s[j] + 1 != s[j + 1]){
                    word[s[j] + 1] -= (word[s[j] + 1] > word[s[i]] ? 1 : 0);
                }
            }
            for (int j = s[i] + 1; j < s[i + 1]; j++){
                tmp2 += fact[N - j - 1];
                tmp2 = tmp2 % MOD;
            }
            for (int j = i + 1; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i] + 1] ? s[i+1] - s[i] - 1 : 0);
                if (s[j] + 1 != s[j + 1]){
                    word[s[j] + 1] -= (word[s[j] + 1] > word[s[i] + 1] ? s[i+1] - s[i] - 1 : 0);
                }
            }
            tmp2 *= word[s[i] + 1] % MOD;
            tmp += tmp2;
            tmp += *(ans.end() - 1);
            *(ans.end() - 1) = tmp % MOD;
        }
    }
    for (int i = 0, l = ans.size(); i < l; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 2780
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define N 1000005

using namespace std;

void solve()
{
	ll d, t, s;
	cin >> d >> t >> s;
	if (t * s >= d)cout << "Yes" << endl;
	else cout << "No" << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e16
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a(M), c(M, 0);
    REP(i, M){
        int b;
        cin >> a[i] >> b;
        int tmp;
        REP(j, b){
            cin >> tmp;
            c[i] += pow(2, tmp - 1);
        }
    }
    //REP(i, M) cout << c[i] << endl;
    vector<vector<ll>> dp(M+1, vector<ll>(pow(2, N), INF));
    dp[0][0] = 0;
    REP(i, M){
        REP(j, pow(2, N)){
            ll tmp = j | c[i];
            //cout << i << " " << j << " " << tmp <<endl;
            //cout << dp[i][j] << endl;
            //cout << dp[i][tmp] << endl;
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][tmp] = min(min(dp[i][tmp], dp[i][j] + a[i]),dp[i+1][tmp]);
            //cout << dp[i+1][j] << endl;
            //cout << dp[i+1][tmp] << endl;

        }
    }
    ll ans = dp[M][pow(2, N)-1] >= INF ? -1 : dp[M][pow(2, N)-1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 32384
#include <cstdio>
#include <iostream>
using namespace std;
int cnt;
struct Card{char suit,v;};
void selection_sort(Card *C,int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(C[j].v<C[minj].v)minj=j;
    }
    Card t;
    t=C[i];
    C[i]=C[minj];
    C[minj]=t;
    
   
  }
}
void bubble_sort(Card *C,int N){
  bool f=true;
  while(f){
    f=false;
    for(int j=N-1;j>=1;j--){
      if(C[j].v<C[j-1].v){
	Card t=C[j];
	C[j]=C[j-1];
	C[j-1]=t;
	f=true;
      }
    }
  }
}
void print_(Card *C,int N){
  for(int i=0;i<N;i++){
    cout << C[i].suit << C[i].v;
    if(i!=N-1)printf(" ");
  }
  cout << endl;
}
int main(){
  int N;
  Card C[101],C2[101];
  cin >> N;
  for(int i=0;i<N;i++){cin >> C[i].suit >> C[i].v; C2[i]=C[i];}
 
  bubble_sort(C,N);
  print_(C,N);
  cout << "Stable" << endl;
  selection_sort(C2,N);
  print_(C2,N);
  bool equal=true;
  for(int i=0;i<N;i++){
    if(C[i].suit!=C2[i].suit)equal=false;
  }
  if(equal)cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <deque>
#include <utility>
#include <set>
#include <queue>
#include <functional>

#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define RREP(i, n) RFOR(i, 0, n)
#define RFOR(i, a, b) for(int i = int(b) - 1; i >= int(a); --i)

#define CHMAX(a, b) a = (a < b ? b : a)

constexpr double EPS = 1e-7;

using PAIR = std::pair<int, int>;

PAIR dp[102][49901];
// dp[i][j] = i番目まで見て小銭をj円持ってる時の(最大500円枚数, そのときの最小消費金額)

signed main() {

	while (true) {
		int n;
		std::cin >> n;
		if (n == 0) break;
		std::vector<int> p(n);
		REP(i, n) std::cin >> p[i];

		REP(i, n + 1) REP(j, 49901) dp[i][j] = PAIR(-1, 0);
		dp[0][0] = PAIR(0, 0);
		REP(i, n) REP(j, 49901) {
			if (dp[i][j].first == -1) continue;
			CHMAX(dp[i + 1][j], dp[i][j]);
			if (p[i] % 1000 > 500) {
				CHMAX(dp[i + 1][j + 1000 - p[i] % 1000], PAIR(dp[i][j].first, dp[i][j].second - p[i]));
				if (p[i] % 1000 - 500 <= j) {
					CHMAX(dp[i + 1][j - (p[i] % 1000 - 500)], PAIR(dp[i][j].first + 1, dp[i][j].second - p[i]));
				}
			}
			else if (p[i] % 1000 == 0) {
				if (j >= 500) {
					CHMAX(dp[i + 1][j - 500], PAIR(dp[i][j].first + 1, dp[i][j].second - p[i]));
				}
			}
			else {
				CHMAX(dp[i + 1][j + 500 - p[i] % 1000], PAIR(dp[i][j].first + 1, dp[i][j].second - p[i]));
			}
		}

		PAIR ans(-1, 0);
		REP(j, 49901) CHMAX(ans, dp[n][j]);
		std::cout << ans.first << " " << -ans.second << "\n";
	}

	return 0;
}


Measured memory_bytes: 42480
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] temp = br.readLine().split(" ");
		int[] data1 = new int[n];
		for(int i = 0;i < n;i++){
			data1[i] = Integer.parseInt(temp[i]);
		}
		temp = br.readLine().split(" ");
		int[] data2 = new int[n];
		for(int i = 0;i < n;i++){
			data2[i] = Integer.parseInt(temp[i]);
		}

		double dist1 = 0, dist2 = 0, dist3 = 0, distInf = 0;

		for(int i = 0;i < n;i++){
			int diff = abs(data1[i] - data2[i]);

			dist1 += diff;
			dist2 += diff * diff;
			dist3 += diff * diff * diff;
			distInf = (distInf < diff) ? diff : distInf;
		}

		dist2 = sqrt(dist2);
		dist3 = pow(dist3, 1.0/3.0);

		System.out.printf("%f%n", dist1);
		System.out.printf("%f%n", dist2);
		System.out.printf("%f%n", dist3);
		System.out.printf("%f%n", distInf);
	}

}

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

int digit;
int count_digit(ll num) {
    if (num != 0) {
        count_digit(num/10);
        digit++;
    }
    return digit;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    ll ans = 1;

    bool zeroflag = false;
    rep(i,n) {
        if (a[i] == 0) {
            zeroflag = true;
        }
    }
    /*
    bool over18flag = false;
    rep(i,n) {
        digit = 0;
        if (count_digit(a[i]) == 18) {
            over18flag = true;
        }
    }
    */

    if (zeroflag) {
        cout << "0" << endl;
    } else {
        rep(i,n) {
            
            int now_digit = 0;
            int time_digit = 0;
            digit = 0;
            now_digit = count_digit(ans)-1;
            digit = 0;
            time_digit = count_digit(a[i])-1;
            /*
            if (now_digit + time_digit > 17) {
                cout << "-1" << endl;
                break;
            }
            */

            ans *= a[i];
            if (ans > 1000000000000000000) {
                cout << "-1" << endl;
                break;
            }
            if (now_digit + time_digit > 17 && ans != 1000000000000000000) {
                cout << "-1" << endl;
                break;
            }
            if (i == n-1) {
                cout << ans << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
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;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int K;
  string S;

  cin >> K >> S;

  if (K >= S.length()) {
    cout << S << endl;
  } else {
    // 文字列を取る

    cout << S.substr(0, K) + "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main(){
	int N;
	cin >> N;
	int a[N+10],go=0,color[8]={},sum=0;
	for(int i=0; i<N; i++){
		cin >> a[i];
		if(a[i]/400 < 8)
			color[a[i]/400]+=1;
      else go+=1;
	}for(int i=0; i<8; i++){
		if(color[i] != 0) sum+=1;
	}
	if(sum!=0)
		cout << sum << ' ' << sum+go << endl;
	else
		cout << '1' << ' ' << go << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <algorithm>
#include <utility>

using namespace std;

int main () {
  char c[11],cc[5]="2018";
  cin >> c;
  strncpy(c,cc,4);
  cout << c << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll                    long long int
#define fo(i,a,b)          for( i=(ll)a;i<(ll)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define vi                    vector<ll>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define all(p)                p.begin(),p.end()
#define max(x,y)              (x>=y)?x:y
//#define min(x,y)              (x<=y)?x:y
#define mid(s,e)              (s+(e-s)/2)
#define start()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll min(ll x,ll y)
{
		return x<=y?x:y;
}

int main()
{
   ll n,m;
   cin>>n>>m;
   vector<ll> heights(n+1);
   vector<int> vis(n+1,1);
   for(int i=1;i<n+1;i++)
   {
       cin>>heights[i];
   }
//    vector<vector<int>> adj(n+1,vector<int>(n+1,0));
   for(int i=0;i<m;i++)
   {
       ll a,b;
       cin>>a>>b;
    //    adj[a][b]=1;
    //    adj[b][a]=1;
        if(heights[a]>heights[b])vis[b]=0;
        else if(heights[a]==heights[b]){vis[a]=0;vis[b]=0;}
        else vis[a]=0;
   }
   ll ans=0;
   for(int i=1;i<n+1;i++)
   {
    //    cout<<i<<" "<<vis[i]<<endl;
       if(vis[i]==1)ans++;
   }
   cout<<ans;



}

Measured memory_bytes: 4580
#include "iostream"
#include "vector"

int main(void) {
	int n, m;
	std::cin >> n >> m;

	std::vector<int>k(m);
	std::vector<std::vector<int>>s(m, std::vector<int>());
	for (int i = 0; i < m; ++i) {
		std::cin >> k.at(i);
		for (int j = 0; j < k.at(i); ++j) {
			int num;
			std::cin >> num;
			num--;
			s.at(i).push_back(num);
		}
	}

	std::vector<int>p(m);
	for (int i = 0; i < m; ++i)
		std::cin >> p.at(i);

	int ans = 0;
	for (int push = 0; push < 1 << n; ++push) {
		bool itti = true;
		for (int i = 0; i < m; ++i) {
			int push_num = 0;
			for (int j = 0; j < k.at(i); ++j)
				if (push & 1U << s.at(i).at(j))
					push_num++;
			if ((push_num & 1U) != p.at(i)) {
				itti = false;
				break;
			}
		}
		if (itti)
			ans++;
	}
	std::cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::vector<int64_t> T(N);
	for (auto& v : T)
	{
		std::cin >> v;
	}
	int64_t M;
	std::cin >> M;

	int64_t sum_T = 0;
	for (auto v : T)
	{
		sum_T += v;
	}

	for (int64_t i = 0; i < M; i++)
	{
		int64_t P, M;
		std::cin >> P >> M;
		int64_t ans = sum_T - T[P - 1] + M;
		std::cout << ans << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int gcd2(int a,int b){
	if(a%b==0){
		return a;
	}else{
		return b%a;
	}
}
int gcd(int a,int b,int c){
	if(b%a==0&&c%a==0) return a;
	else if (b%a==0)return gcd(c%a,b,a);
	else if (c%a==0)return gcd(b%a,c,a);
	else{
		if(c%a<b%a) return gcd(c%a,b%a,a); else return gcd(b%a,c%a,a);
	}
	return 0;
}
int main(){
	int k;
	cin>>k;
	long long int sum=0;
	for (int a=1;a<=k;a++){
		for (int b=1;b<=k;b++){
			for (int c=1;c<=k;c++){
				if(a<b&&a<c) sum+=gcd(a,b,c);
				else if(b<c) sum+=gcd(b,c,a);
				else sum+=gcd(c,b,a);
			}
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)


int main(){
    int n;
    cin >> n;
    int t[n];
    long long tsum = 0;
    rep(i,n) {
        cin >> t[i];
        tsum += t[i];
    }
    int m;
    cin >> m;
    vector<pair<int, int> > vp;
    int p,x;
    rep(i,m){
        cin >> p >> x;
        pair<int, int> pa;
        pa.first = p;
        pa.second = x;
        vp.push_back(pa);
    }
    rep(i,m){
        p = vp[i].first;
        x = vp[i].second;
        cout << tsum - t[p-1] + x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
bool prime[100010], ansprime[100010];
int ruiseki[100010], gokei;
int main() {
	for (int i = 2; i < 100010; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0)goto age;
		}
		prime[i] = true;
	age:;
	}
	for (int i = 2; i < 100010; i++) {
		if (prime[i] && prime[(i + 1) / 2]) {
			ansprime[i] = true;
			gokei++;
		}
	}
	for (int i = 2; i < 100010; i++) {
		ruiseki[i] = ruiseki[i - 1] + ansprime[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		cout << ruiseki[r] - ruiseki[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


def lcm(a, b):
    return (a * b) // gcd(a, b)

def modinv(x):
    return pow(x, mod-2, mod)

L = reduce(lcm, a)

for i in range(n):
    # ans += (L // a[i])
    ans += L * modinv(a[i])

print(ans % mod)

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

int main(){
  int N;
  cin >>N;
  int A[2][N];
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      cin>>A[i][j];
    }
  }
  
  int maxa=0;

  for (int i=0;i<N;i++){
      int sum1=0;
      int sum2=0;
    for(int j=0;j<i+1;j++){
      sum1=sum1+A[0][j];
    }
    for(int j=i;j<N;j++){
      sum2=sum2+A[1][j];
    }
    maxa=max(maxa,sum1+sum2);
  }
  cout<<maxa<<endl;
  return 0;
}



  

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N;
  double T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  REP(i, N) cin >> H[i];

  int idx = -1;
  double mi;
  for (int i = 0; i < N; i++) {
    double tmp = T - 0.006*H[i];
    if (idx == -1 || fabs(tmp - A) < mi) {
      idx = i;
      mi = fabs(tmp - A);
    }
  }
  cout << (idx + 1) << endl;

	return 0;
}



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

int main()
{
    int n;
    cin>>n;
    bool flag=0;
    while(n)
    {
        if(n%10==7) flag=1;
        n/=10;
    }
    flag?cout<<"Yes":cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3624
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let mut x: i32 = sc.read();
    let mut y: i32 = sc.read();
    let mut z: i32 = sc.read();
    std::mem::swap(&mut x, &mut y);
    std::mem::swap(&mut x, &mut z);
    println!("{} {} {}", x, y, z);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] f = new int[n+1];
        for(int i=1; i<=n; i++) {
            f[i] = f[i % Integer.bitCount(i)]+1;
        }
        char[] c = sc.next().toCharArray();
        int nb = 0;
        for(int i=0; i<n; i++) {
            if(c[i] == '1') nb++;
        }
        int[][] a = new int[n][3];
        int[] base = new int[3];
        for(int k = -1; k<=1; k++) {
            int l = nb + k;
            if(l <= 0 || l > n) continue;
            a[0][k+1] = 1 % l;
            if(c[n-1] == '1') {
                base[k+1] += a[0][k+1];
                base[k+1] %= l;
            }
            for(int i=1; i<n; i++) {
                a[i][k+1] = (a[i-1][k+1] * 2) % l;
                if(c[n-1-i] == '1') {
                    base[k+1] += a[i][k+1];
                    base[k+1] %= l;
                }
            }
        }
        for(int i=n-1; i>=0; i--) {
            int res = 0;
            if(c[n-1-i] == '1') {
                int l = nb - 1;
                if(l==0) {
                    res = 0;
                } else {
                    res = f[(base[0] - a[i][0] + l) % l] + 1;
                }
            } else {
                int l = nb + 1;
                res = f[(base[2] + a[i][2]) % l] + 1;
            }
            System.out.println(res);
        }




    }




}

Measured memory_bytes: 68040
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
    vector<string> S(H);
    for(int i=0; i<H; i++) cin >> S[i];

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            int cnt = 0;
            for(int k=0; k<8; k++){
                int y = i+dy[k];
                int x = j+dx[k];
                if(x < 0 || x >= W || y < 0 || y >= H) continue;
                if(S[y][x] == '#') cnt++;
            }
            S[i][j] = cnt + '0';
        }
    }
    for(int i=0; i<H; i++)
        cout << S[i] << endl;


    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : abc127b.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int r, D, x;
	cin >> r >> D >> x;
	for(int i = 0; i < 10; ++i){
		x = r * x - D;
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from itertools import product
N=int(input())
F = [[[0 for _ in range(3)] for _ in range(6)] for _ in range(N+1)]
for i in range(1,N+1):
    A = list(map(int,input().split()))
    F[i][1][1] = A[0]
    F[i][1][2] = A[1]
    F[i][2][1] = A[2]
    F[i][2][2] = A[3]
    F[i][3][1] = A[4]
    F[i][3][2] = A[5]
    F[i][4][1] = A[6]
    F[i][4][2] = A[7]
    F[i][5][1] = A[8]
    F[i][5][2] = A[9]
P = [[0 for _ in range(11)] for _ in range(N+1)]
for i in range(1,N+1):
    P[i] = list(map(int,input().split()))
pmax = -10**10
for x in product((0,1),repeat=10):
    if sum(x)>0:
        G = [[0 for _ in range(3)] for _ in range(6)]
        G[1][1] = x[0]
        G[1][2] = x[1]
        G[2][1] = x[2]
        G[2][2] = x[3]
        G[3][1] = x[4]
        G[3][2] = x[5]
        G[4][1] = x[6]
        G[4][2] = x[7]
        G[5][1] = x[8]
        G[5][2] = x[9]
        p = 0
        for i in range(1,N+1):
            cnt = 0
            for j in range(1,6):
                for k in range(1,3):
                    if F[i][j][k]==1 and G[j][k]==1:
                        cnt += 1
            p += P[i][cnt]
        pmax = max(pmax,p)
print(pmax)    

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  2019 = 3*673
}*/

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

  vi a(n);
  rep(i, 0, n){
    cin >> a[i];
  }

  vi b(n);
  rep(i, 0, n){
    b[0] += (i%2 ? -1 : 1)*a[i];
  }

  rep(i, 0, n-1){
    b[i+1] = (b[i]-a[i])*(-1) + (n%2 ? 1 : -1)*a[i];
  }

  rep(i, 0, n){
    cout << b[i] << " \n"[i==n-1];
  }

  return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
#include<float.h>

float maxof(float max, float x) {
  max = (max > x) ? max:x;
  return max;
}

float minof(float min, float y) {
  min = (min < y) ? min:y;
  return min;
}

int main() {
  float input, max, min;

  max = 0.0;
  min = FLT_MAX;

  while(scanf("%f", &input) != EOF) {
    max = maxof(max, input);
    min = minof(min, input);
  };

  printf("%0.1f\n", max - min);

  return 0;
}

Measured memory_bytes: 644
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

bool ok;
string s[8];
int nums[24][3] = {
	{0, 1, 3}, {0, 3, 4}, {0, 4, 2}, {0, 2, 1},
	{1, 5, 3}, {1, 3, 0}, {1, 0, 2}, {1, 2, 5},
	{2, 1, 0}, {2, 0, 4}, {2, 4, 5}, {2, 5, 1},
	{3, 1, 5}, {3, 5, 4}, {3, 4, 0}, {3, 0, 1},
	{4, 0, 3}, {4, 3, 5}, {4, 5, 2}, {4, 2, 0},
	{5, 1, 2}, {5, 2, 4}, {5, 4, 3}, {5, 3, 1},
};
char dices[4][4][4][6];

bool dfs(int state, int n){
	if(ok) return true;
	bool res = false;
	if(n == 8){
		ok = true;
		return true;
	}
	if(n == 0){
		rep(i, 24){
			dices[1][1][1][3] = s[0][5-nums[i][0]];
			dices[1][1][1][4] = s[0][5-nums[i][1]];
			dices[1][1][1][5] = s[0][5-nums[i][2]];
			res |= dfs(1, 1);
			dices[1][1][1][3] = '*';
			dices[1][1][1][4] = '*';
			dices[1][1][1][5] = '*';
		}	
		
	}else{
		int z = n / 4 + 1;
		int y = (n % 4) / 2 + 1;
		int x = n % 2 + 1;
		rep(i, 8){
			if(state & (1 << i)) continue;
			rep(j, 24){
				bool f1 = (dices[x][y][z-1][3] == '*' ||
					abs(dices[x][y][z-1][3] - s[i][nums[j][0]]) == 32);
				bool f2 = (dices[x][y-1][z][4] == '*' || 
					abs(dices[x][y-1][z][4] - s[i][nums[j][1]]) == 32);
				bool f3 = (dices[x-1][y][z][5] == '*' ||
					abs(dices[x-1][y][z][5] - s[i][nums[j][2]]) == 32);
				if(f1 && f2 && f3){
					dices[x][y][z][3] = s[i][5-nums[j][0]];
					dices[x][y][z][4] = s[i][5-nums[j][1]];
					dices[x][y][z][5] = s[i][5-nums[j][2]];
					res |= dfs(state | 1 << i, n + 1);
					dices[x][y][z][3] = '*';
					dices[x][y][z][4] = '*';
					dices[x][y][z][5] = '*';
				}
			}
		}
	}
	return res;
}

int main(){
	while(cin >> s[0] && s[0] != "0"){
		ok = false;
		rep2(i, 1, 8) cin >> s[i];
		fill(&dices[0][0][0][0], &dices[0][0][0][0]+4*4*4*6, '*');
		if(dfs(0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define double long double
#define Sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<int,int> P;
const int MOD=1000000007;


void solve(long long n, std::vector<long long> p){
    int mi, ma, cnt=0;
    for (size_t i = 2; i < n; i++)
    {
        mi = min({p[i-2], p[i-1], p[i]});
        ma = max({p[i-2], p[i-1], p[i]});
        if (mi != p[i-1] && ma != p[i-1])
        {
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> p(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&p[i]);
    }
    solve(n, std::move(p));
    return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
A = list(map(int, input().split()))

max_A = max(A)
if max_A == 0:
  max_A_bin_len = 1
else:
  max_A_bin_len = len(bin(max_A)) - 2
  if K == 0:
    K_bin_len = 1
  else:
    K_bin_len = len(bin(K)) - 2
max_bin_len = max(max_A_bin_len, K_bin_len)
A_bin = [bin(a)[2:].zfill(max_bin_len) for a in A]
K_bin = bin(K)[2:].zfill(max_bin_len)

ans_cand1 = 0
ans_cand2 = 0
can_choose = 0
can_choose_forever = 0
calc_ans_cand2 = 0
start_calc_ans_cand2 = 0
for bit in range(max_bin_len):
  if not can_choose:
    if K_bin[bit] == '1':
      can_choose = 1
  A_one_num = 0
  for a in A_bin:
    if a[bit] == '1':
      A_one_num += 1
  if can_choose:
    if A_one_num < N-A_one_num:
      if not can_choose_forever:
        can_choose = 0
        if not calc_ans_cand2:
          ans_cand2 = ans_cand1 + (2**(max_bin_len-bit-1)) * A_one_num
          start_calc_ans_cand2 = 1
    else:
      can_choose_forever = 1
    ans_cand1 += (2**(max_bin_len-bit-1)) * (max(A_one_num, N-A_one_num))
  else:
    ans_cand1 += (2**(max_bin_len-bit-1)) * A_one_num
  if calc_ans_cand2:
    ans_cand2 += (2**(max_bin_len-bit-1)) * (max(A_one_num, N-A_one_num))
  if start_calc_ans_cand2:
    calc_ans_cand2 = 1
print(max(ans_cand1, ans_cand2))

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    bool flag = 1;
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        flag = 0;
        break;
      }
    }
    if (flag) {
      a.erase(a.begin() + i);
      i--;
      h--;
    }
  }

  vector<vector<char>> b(w, vector<char>(h));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      b[j][i] = a[i][j];
    }
  }
  for (int i = 0; i < w; i++) {
    bool flag = 1;
    for (int j = 0; j < h; j++) {
      if (b[i][j] == '#') {
        flag = 0;
        break;
      }
    }
    if (flag) {
      b.erase(b.begin() + i);
      i--;
      w--;
    }
  }
  vector<vector<char>> ans(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans[i][j] = b[j][i];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j];
    }
    cout << '\n';
  }
}

Measured memory_bytes: 256
n=int(input())
t=list(map(int,input().split()))
v=list(map(int,input().split()))
T=sum(t)
ansv=[0]
for i in range(n):
  ansv[-1]=min(ansv[-1],v[i])
  for j in range(t[i]*2):
    ansv.append(v[i])
ansv[-1]=0
#for i in range(len(ansv)):
#  print(i/2,ansv[i])
for i in range(2*T):
  ansv[i+1]=min(ansv[i]+0.5,ansv[i+1])
for i in range(2*T,0,-1):
  ansv[i-1]=min(ansv[i]+0.5,ansv[i-1])
print(sum(ansv)/2)
#print(len(ansv))
#for i in range(len(ansv)):
#  print(i/2,ansv[i])

Measured memory_bytes: 9392
w, h, n = map(int, input().split())
data = [list(map(int, input().split())) for i in range(n)]

x=[]
y=[]
a=[]

for j in range(n):
    x.append(data[j][0])
    y.append(data[j][1])
    a.append(data[j][2])

x1=0
x2=w
y1=0
y2=h

for j in range(n):
    if a[j]==1 and x[j]>x1:
        x1=x[j]
    elif a[j]==2 and x[j]<x2:
        x2=x[j]
    elif a[j]==3 and y[j]>y1:
        y1=y[j]
    elif a[j]==4 and y[j]<y2:
        y2=y[j]

if x1>x2 or y1>y2:
    print(0)

else:
    print((x2-x1)*(y2-y1))

Measured memory_bytes: 3064
import math

N = int(input())
A = list(map(int, input().split()))

count = [0]*N
for i in range(N):
    count[A[i] - 1] += 1

sum = 0
for i in range(N):
    t = count[i]
    if t >= 2:
        sum += math.factorial(t) // (math.factorial(t - 2) * 2)

for i in range(N):
    t = count[A[i] - 1]
    if t > 1:
        print(sum - t + 1)
    else:
        print(sum)
        

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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=1e5+2;
const int inf= 0x3f3f3f3f;
void solve(){
 int a,b,c;
 sl(a);sl(b);sl(c);
 set<int>v;
 v.insert(a);
  v.insert(b);
   v.insert(c);
   if(v.size()==2){
	   cout<<"Yes"<<endl;
	   return;
   }
   cout<<"No"<<endl;




}

signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();

   }
  return 0;
}


Measured memory_bytes: 256