akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
typedef complex<double> P;
const double EPS = 1e-8;
int sign(double x) {
    if(x > EPS) return 1;
    if(x < -EPS) return -1;
    return 0;
}
struct C{
    P p;
    double r;
};
vector<P> pCC(C a, C b) {
    vector<P> res;

    double d = abs(b.p - a.p);
    double l1 = abs(a.r - b.r);
    double l2 = a.r + b.r; 

    if(sign(d) == 0 && sign(l1) == 0) assert(false); // 円が等しい
    if(sign(d - l1) < 0 || sign(d - l2) > 0) return res; // 交わらない

    double th1 = arg(b.p - a.p);

    if(sign(d - l1) == 0 || sign(d - l2) == 0) { // 一点で交わる
        res.push_back(a.p + polar(a.r, th1));
    } else { // 二点で交わる
        double th2 = acos( (a.r * a.r - b.r * b.r + d * d) / (2 * a.r * d) );
        res.push_back(a.p + polar(a.r, th1 - th2));
        res.push_back(a.p + polar(a.r, th1 + th2));
    }

    return res;
}

int main() {
    int n;
    while(cin >> n && n > 0) {
        vector<P> ps(n);
        vector<double> l(n);
        REP(i, n) {
            double x, y;
            cin >> x >> y;
            ps[i] = {x, y};
            cin >> l[i];
        }
        double lb = 0, ub = *min_element(l.begin(), l.end());
        REP(_, 60) {
            double h = (lb + ub) / 2;
            vector<C> cs(n);
            REP(i, n) {
                double r = sqrt(l[i] * l[i] - h * h);
                cs[i] = {ps[i], r};
            }
            vector<P> cand = ps;
            REP(i, n) REP(j, n) if(i != j) {
                for(auto p : pCC(cs[i], cs[j])){
                    cand.push_back(p);
                }
            }
            bool ok = false;
            for(auto p : cand) {
                int cnt = 0;
                REP(i, n) {
                    double d = abs(cs[i].p - p);
                    if(sign(d - cs[i].r) <= 0) {
                        cnt++;
                    }
                }
                if(cnt == n) ok = true;
            }
            if(ok) {
                lb = h;
            } else {
                ub = h;
            }
        }
        printf("%.12f\n", lb);
    }
    return 0;
}

Measured memory_bytes: 1416
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

int main() {
    int n, goal;
    cin >> n >> goal;

    int x[n], maxNum;
    maxNum = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        maxNum = max(maxNum, x[i]);
    }

    long dp[n + 1][maxNum * n + 1][51];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= maxNum * n; j++) {
            for (int k = 0; k <= 50; k++) dp[i][j][k] = 0;
        }
    }
    dp[0][0][0] = 1;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= maxNum * (n - 1); j++) {
            for (int k = 0; k < n; k++) {
                // x_i を使った場合
                dp[i][j + x[i - 1]][k + 1] += dp[i - 1][j][k];

                // x_i を使わない場合
                dp[i][j][k] += dp[i - 1][j][k];
            }
        }
    }
    long res = 0;
    for (int i = 1; i <= maxNum * n; i++) {
        for (int j = 1; j <= 50; j++) if (dp[n][i][j] > 0 && i % j == 0 && i / j == goal) res += dp[n][i][j];
    }
    cout << res << endl;
}


Measured memory_bytes: 51072
//package com.zhangyong.algorithm;

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        private FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }

    private void solve() {
        //0 31 29 31 30 31 30 31 31 30 31 30 31
        int[] arr = new int[]{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int x, y;
        x = in.nextInt();
        y = in.nextInt();
        if (arr[x] == arr[y]) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    private void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
   int N,M;
   cin>>N>>M;
   int a[M],b[M];
   for(int i=0;i<M;i++){
      cin>>a[i]>>b[i];
   }
   int num[N];
   for(int i=0;i<N;i++){
       num[i]=0;
   }
   for(int i=0;i<M;i++){
       num[a[i]-1]++;
       num[b[i]-1]++;
   }
   for(int i=0;i<N;i++){
       cout<<num[i]<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;

int calc_score(int D, vector<int>& c, vector<vector<int>>& s,
               vector<int>& ret) {
  vector<int> last(26, -1);
  int csum = accumulate(c.begin(), c.end(), 0);
  int score = 0, dec = 0;
  for (int d = 0; d < D; d++) {
    dec += csum - c[ret[d]] * (d - last[ret[d]]);
    score += s[d][ret[d]] - dec;
    last[ret[d]] = d;
  }
  return score;
}

int calc_diff(int D, vector<int>& c, vector<vector<int>>& s, vector<int>& ret,
              int dc, int nc) {  // dc... day changed  nc... new contest
  int diff = 0, oc = ret[dc];    // oc... old contest
  diff += s[dc][nc] - s[dc][oc];

  int poc = -1, pnc = -1, noc = D, nnc = D;  // prev, next day

  for (int i = 0; i < dc; i++) {
    if (ret[i] == oc) poc = i;
    if (ret[i] == nc) pnc = i;
  }

  for (int i = D - 1; i > dc; i--) {
    if (ret[i] == oc) noc = i;
    if (ret[i] == nc) nnc = i;
  }
  diff -= c[oc] * (noc - dc) * (dc - poc) - c[nc] * (nnc - dc) * (dc - pnc);
  
  cerr << diff << endl;
  
  return diff;
}

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  vector<vector<pair<int, int>>> s_sorted(D, vector<pair<int, int>>(26));
  for (int i = 0; i < 26; i++) cin >> c[i];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> ret(D);
  for (int i = 0; i < D; i++) {
    cin >> ret[i];
    ret[i]--;
  }
  
  int sc = calc_score(D, c, s, ret);
  
  int M, d, q;
  cin >> M;
  for(int i=0; i<M; i++){
    cin >> d >> q;
    sc += calc_diff(D, c, s, ret, d-1, q-1);
    cout << sc << endl;
  	ret[d-1]=q-1;
  }
  
  return 0;
}

Measured memory_bytes: 3256
// cited from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8.
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// My code -----------------------------------------

use std::collections::HashMap;
use std::vec::Vec;

const DAYS: u32 = 365;
//const DAYS: u32 = 5; // for testing
const TYPES: usize = 26;

struct Solver {
    c: Vec<i64>,
    sd: Vec<Vec<i64>>,
}

impl Solver {
    fn new(c: Vec<i64>, sd: Vec<Vec<i64>>) -> Self {
        Self { c, sd }
    }

    fn compute_score(&self, history: &[usize], current_type: usize) -> i64 {
        let d = history.len() as i64;
        let mut score: i64 = self.sd[d as usize][current_type];
        let mut last = HashMap::new();
        for (i, t) in history.iter().enumerate() {
            last.insert(t, i as i64);
        }
        last.insert(&current_type, d);

        for t in 0..TYPES {
            match last.get(&t) {
                Some(last_d) => score -= self.c[t] * (d - last_d),
                None => score -= self.c[t] * (d + 1),
            }
        }

        score
    }

    fn solve(&mut self) -> Vec<usize> {
        let mut history = Vec::<usize>::new();
        for d in 0..DAYS {
            let mut local_max_score: i64 = std::i64::MIN;
            let mut best_type: usize = 0;
            for current_type in 0..TYPES {
                let local_score = self.compute_score(&history[..], current_type);
                if local_score > local_max_score {
                    local_max_score = local_score;
                    best_type = current_type;
                }
            }
            history.push(best_type);
        }

        history
    }
}

fn main() {
    input! {
        days: i64,
        c : [i64; TYPES],
        sd: [[i64; TYPES]; DAYS],
    }

    let mut solver = Solver::new(c, sd);
    let results = solver.solve();
    for t in results {
        println!("{}", t + 1);
    }
}


Measured memory_bytes: 2312
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    static final int modnum = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<String> list = new ArrayList<String>();
        sc.nextLine();
        for (int i = 0; i < N; i++) {
            list.add(sc.nextLine());
        }
        int ans = 0;

        int a = 0;
        int b = 0;
        int ab = 0;

        for (String str : list) {
            for (int i = 0; i < str.length() - 1; i++) {
                if (str.charAt(i) == 'A' && str.charAt(i + 1) == 'B')
                    ans++;
            }
            // if(str.contains("AB")){
            // ans++;
            // }

            if (str.charAt(0) == 'B' && str.charAt(str.length() - 1) == 'A') {
                ab++;
            } else {
                if (str.charAt(str.length() - 1) == 'A') {
                    a++;
                }
                if (str.charAt(0) == 'B') {
                    b++;
                }
            }
        }
        // System.out.println(ans+" "+a+" "+b+" "+ab);


        if(ab>0){
            ans += ab-1;
            if(a>0){
                ans++;
                a--;
            }
            if(b>0){
                ans++;
                b--;
            }
                ans+=Math.min(a, b);
        }else{
            ans+=Math.min(a, b);
        }

        // ans += Math.min(a, b);
        // if (Math.min(a, b) == ab)
        //     ans--;
        // ans += Math.min(a+b-ab,0);

        System.out.println(ans);
    }
}

Measured memory_bytes: 41888
n, q = map(int, input().split())
s = list(str(input()))


t = [0] * (n+1)
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]


t[-1] = t[-2]


for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 8536
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
	int c[10][10];
	FOR(i,3){
		FOR(j,3){
			cin >> c[i][j];
		}
	}
	bool ans=1;
	int a[]={c[0][1]-c[0][0],c[0][2]-c[0][1]};
	for(int i=1;i<3;i++){
		for(int j=1;j<3;j++){
			if(c[i][j]-c[i][j-1]!=a[j-1])ans=0;
		}
	}

	int b[]={c[1][0]-c[0][0],c[2][0]-c[1][0]};
	for(int i=1;i<3;i++){
		for(int j=1;j<3;j++){
			if(c[j][i]-c[j-1][i]!=b[j-1])ans=0;
		}
	}
	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n;
	cin>>n;
	vector<ll> t,x,y;
	x.pb(0);
	y.pb(0);
	t.pb(0);
	for(int i=0;i<n;i++){
		ll tt,tx,ty;
		cin>>tt>>tx>>ty;
		t.pb(tt);
		x.pb(tx);
		y.pb(ty);
	}
	for(int i=1;i<=n;i++){
		ll dist = abs( x[i] - x[i-1] ) + abs( y[i] -y[i-1] );
		ll dur = t[i] - t[i-1];
		if( dist > dur || (dur-dist)%2==1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 2912
import java.util.Scanner;

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

        String A = sc.next();
        String B = sc.next();
        String C = sc.next();

        if (A.charAt(A.length()-1) == B.charAt(0) && B.charAt(B.length()-1) == C.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
// #include <chrono>
// #include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846
 
ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}
 
int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}



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

// int t;
// cin >> t;
// while(t--){



// }
	int a,b,c;
cin >> a >> b>> c;
swap(a,b);
swap(a,c);
cout << a << ' ' << b << ' ' << c << endl;




return 0;
	
	}


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


int main () {
  int a , b , c , x ;
  cin >> a >> b >> c >> x ;
  
  int ans = 0 ;
  
  for(int i = 0 ; i < a + 1 ; i++ ) {
    for(int j = 0 ; j < b + 1 ; j++ ) {
      for(int k = 0 ; k < c + 1 ; k++ ) {
        if( 500 * i + 100 * j + 50 * k == x ) ans ++ ;
      }
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 3; ++i) {
	if (n % 10 == 7) {
		cout << "Yes" << endl;
		return 0;
	}
	n /= 10;
	}
	cout << "No" << endl;
	return 0;
}

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

int n, ans, tmin[100005<<2];
struct seg {
	int l, r;
} s[100005];

bool cmp(seg a, seg b) { return a.l > b.l; }

int query(int o, int l, int r, int x, int y) {
	int res = 1e9;
	if(x <= l && r <= y) 
		return tmin[o];
	int mid = (l + r)>>1;
	if(mid >= x) res = min(res, query(o<<1, l, mid, x, y));
	if(mid < y) res = min(res, query(o<<1|1, mid + 1, r, x, y));
	return res;
}

void Build(int o, int l, int r) {
	if(l == r) {
		tmin[o] = s[l].r;
		return;
	}
	int mid = (l + r)>>1;
	Build(o<<1, l, mid);
	Build(o<<1|1, mid + 1, r);
	tmin[o] = min(tmin[o<<1], tmin[o<<1|1]);
	return;
}

void update(int o, int l, int r, int x, int val) {
	if(l == r) {
		tmin[o] = val;
		return;
	}
	int mid = (l + r)>>1;
	if(mid >= x) update(o<<1, l, mid, x, val);
	else update(o<<1|1, mid + 1, r, x, val);
	tmin[o] = min(tmin[o<<1], tmin[o<<1|1]);
	return;
}

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) 
		scanf("%d%d", &s[i].l, &s[i].r);
	sort(s + 1, s + n + 1, cmp);
	int ver = s[1].r;
	Build(1, 1, n);
	for(int i = 1; i < n; i++) {
		ver = min(ver, s[i].r);
		ans = max(ans, max(0, ver - s[1].l + 1) + max(0, query(1, 1, n, i + 1, n) - s[i + 1].l + 1));
	}
	for(int i = 1; i <= n; i++) {
		update(1, 1, n, i, 1e9);
		ans = max(ans, s[i].r - s[i].l + 1 + max(0, query(1, 1, n, 1, n) - ((i == 1) ? s[2].l : s[1].l) + 1));
		update(1, 1, n, i, s[i].r);
	} 
	cout<<ans<<endl;
} 












Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
bool vis[200010];
int dp[200010];

int main(int argc, char const *argv[])
{
	ios_base :: sync_with_stdio (false);
	cin.tie(0);
	
	memset(dp, -1, sizeof dp);
 	int n;
 	cin >> n;
 	int ans = 0;
 	for(int i = 1; i <= n; i++) {
 		int x;
 		cin >> x;
 		if(dp[x-1] != -1) {
 			dp[x] = 1 + dp[x-1]; 
 		} else {
 			dp[x] = 1;
 		}
 		ans = max(ans, dp[x]);
 	}
 	cout << (n - ans) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define pb push_back
#define pf push_front
#define mod 1000000007
#define ull unsigned long long int
#define what_is(qq) cerr << #qq << " is " << qq << "\n"

int frogJump(vector<int> h, int n, int k)
{
  vector<int> dp(n+1);
  dp[1] = 0;
  for(int i=2;i<=n;i++)
  {
    dp[i] = inf;
    for(int j=i-1;j>=1&&(i-j)<=k;j--)
    {
      dp[i] = min(dp[i],abs(h[i]-h[j]) + dp[j]);
    }
  }
  return dp[n];
}

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

  vector<int> h(n+1);

  for(int i=1;i<=n;i++)
  {
    cin>>h[i];
  }

  cout<<frogJump(h,n,k)<<"\n";

}


Measured memory_bytes: 4564
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
constexpr double eps = 1e-6;
constexpr ll LINF = 100200300400500600ll;
constexpr int INF = 2*((1<<30)-1)+1;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {-1,0,1,0};
constexpr int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int n,m;
  cin>>n>>m;
  vi a(m);
  cin>>a;
  int ans = n-accumulate(rng(a),0);
  if(ans>=0){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
using lint = long long;

struct RMQ{
  static const lint MAX_N = 3e5;
  lint n,dat[2 * MAX_N-1];
  RMQ(){}
  RMQ(lint n_){init(n_);}
  void init(lint n_){
    n = 1;
    while(n < n_) n *= 2;
    for(int i = 0; i < 2 * n-1; i++) dat[i] = 0;
  }
  void update(lint k, lint a){
    k += n-1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  lint query(lint a, lint b, lint k, lint l, lint r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return dat[k];
    else{
      lint vl = query(a, b,k * 2 + 1, l, (l + r) / 2);
      lint vr=query(a, b, k * 2 + 2,(l + r) / 2, r);
      return max(vl, vr);
    }
  }
  lint query(lint a,lint b){
    return query(a, b, 0, 0, n);
  }
};

signed main(){
  int N; cin >> N;
	vector<lint> h(N), a(N);
	RMQ rmq(N + 10);
	for(int i = 0; i < N; i++) cin >> h[i];
	for(int i = 0; i < N; i++) cin >> a[i];
	lint ans = 0;
	for(int i = 0; i < N; i++){
		lint ans1 = a[i] + rmq.query(0, h[i]);
		ans = max(ans, ans1);
		rmq.update(h[i], ans1);
	}
	cout << ans << endl;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, l = 1, r = 1;
    vector<int> a;

    cin >> n >> k;
    a.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        r = max(r, a[i]);
    }

    while (l <= r) {
        int m = l + (r - l) / 2;
        int need = 0;

        for (int &v : a)
            need += (v - 1) / m;

        if (need > k)
            l = m + 1;
        else
            r = m - 1;

    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 3964
#include <iostream>

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a - b < c) cout << c - (a - b) << endl;
	else cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,d;
    cin>>n>>d;
    vector<vector<int>> hoge(n,vector<int>(d));
    
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>hoge.at(i).at(j);
        }
    }
    
    int ans=0;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i<j){
                int dis=0;
                for(int k=0;k<d;k++){
                dis+=(hoge.at(i).at(k)-hoge.at(j).at(k))*(hoge.at(i).at(k)-hoge.at(j).at(k));
                }
                //cout<<pow(dis,0.5)<<endl;
                if(ceil(pow(dis,0.5))==floor(pow(dis,0.5))) ans++;
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n, p = map(int, input().split())
s = input()

res = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            res += i + 1
else:
    s = s[::-1]
    cnt = {0: 1}
    now = 0
    d = 1
    for i in range(n):
        now = (now + int(s[i]) * d) % p
        res += cnt.get(now, 0)
        d = (d * 10) % p
        cnt[now] = cnt.get(now, 0) + 1

print(res)


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

int main(){
    // int x, y, maxv;
    // cin >> x >> y;

    // maxv = (x > y) ? x : y;

    // cout << maxv << endl;

    int a, b, c;

    cin >> a >> b >> c;

    if(a < b && b < c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3076
/*
 * A.cpp
 *
 *  Created on: 2017/07/09
 *      Author: LitMc
 */

//#define MYDEBUG
#include <bits/stdc++.h>

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
#define EPS = 1e-14;
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;
using std::ostream;
typedef std::complex<int> P;

template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}

static const ll MOD = 1000000007;
static const ll MAX_A = 110;
ll c[MAX_A][MAX_A];
ll n, p;
vector<ll> a;
ll even, odd;

void tbl() {
  memset(c, 0, sizeof(c));
  rep(n,0,MAX_A)
  {
    c[n][0] = 1;
    REP(r,1,n)
    {
      c[n][r] = c[n - 1][r - 1] + c[n - 1][r];
    }
  }
}
ll ncr(ll n, ll r) {
  if (r > n / 2) {
    r = n - r;
  }
  return c[n][r];
}
void solve() {
  tbl();
  cin >> n >> p;
  even = odd = 0;
  rep(i,0,n)
  {
    ll ai;
    cin >> ai;
    a.push_back(ai);
    if (ai % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  ll e = 0, o = 0;
  REP(k,0,even)
  {
    e += ncr(even, k);
  }
  for (ll k = p; k <= odd; k += 2) {
    o += ncr(odd, k);
  }
  ll ans = e * o;
  dbp3(e, o, ans);
  cout << ans << endl;
}

int main() {
  solve();
//  cout << 100 << " " << 1 << " ";
//  cout << rand() % 100 + 1;
//  REP(i,2,100)
//  {
//    cout << " " << rand() % 100 + 1;
//  }
//  cout << endl;
}



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

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    pair<int, int> res(0, p);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        t.first += x.cost;
        res = max(res, t);
    }
    return res;
}

int main()
{
    cin >> N;
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Measured memory_bytes: 15944
n, a, b, c = map(int, input().split())
_l = [int(input()) for i in range(n)]

inf = 10**9


# DP
def f(i, _a, _b, _c):
    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値
    if i == n:
        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf

    # i番目を使わないとき
    val1 = f(i + 1, _a, _b, _c)
    # i番目をAに使うとき
    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)
    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)
    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)
    return min(val1, val2, val3, val4)


print(f(0, 0, 0, 0))


Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
d=[-1,-1,-1]
ans=1
for aa in a:
  ans*=d.count(aa-1)
  ans%=mod
  if aa-1 in d:
    d[d.index(aa-1)]+=1
print(ans)


Measured memory_bytes: 20796
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
	int a[5];
	scanf("%d %d %d", &a[1], &a[2], &a[3]);
	sort(a + 1, a + 1 + 3);
	printf("%d\n", abs(a[2] - a[1]) + abs(a[3] - a[2]));
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	b := sc.Bytes()
	x := 1
	if b[0] == 45 {
		x *= -1
		b = b[1:]
	}
	for _, v := range b {
		n = n*10 + int(v-48)
	}
	return n * x
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	max := -inf
	min := inf
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ri()
		if a[i] > max {
			max = a[i]
		}
		if a[i] < min {
			min = a[i]
		}
	}

	minCost := inf
	for x := min; x <= max; x++ {
		cost := 0
		for _, aa := range a {
			cost += abs(aa-x) * abs(aa-x)
		}

		if cost < minCost {
			minCost = cost
		}
	}
	fmt.Println(minCost)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	static int n, score;
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt();
		score = 0;
		if(n == 0)
			return false;
		for(int i = 0; i < n/4; i++){
			score += sc.nextInt();
		}
		return true;
	}
	static void solve(){
		System.out.println(score);
	}

}

Measured memory_bytes: 12000
def judge(lst, k):
	sum = 0
	for i in range(0, len(lst)):
		sum = sum + lst[i][1]
		if sum >= k: return lst[i][0]
	return -1

N, K = map(int, raw_input().split())
inpt = []
for i in range(0, N):
	inpt.append(map(int, raw_input().split()))
inpt.sort(key = lambda x: x[0])
print judge(inpt, K)


Measured memory_bytes: 24308
n, k = list(map(int, input().split()))
x, y = 0, 0
for i in range(1, n + 1):
	if i % k == 0:
		x += 1
	elif i % k == int(k / 2):
		y += 1
if k % 2 == 0:
	print(x ** 3 + y ** 3)
else:
	print(x ** 3)

Measured memory_bytes: 3060
H,W =map(int,input().split())
i=0

bombMap=[]
result=[]
while i<H:
  tempLine=input()
  tempAray=[]
  tempResult=[]
  j=0
  
  while j<len(tempLine):
    tempAray.append(tempLine[j])
    tempResult.append(0)
    j=j+1
  bombMap.append(tempAray)
  result.append(tempResult)
  
  i=i+1

i=0
while i<H:
  j=0
  while j<W:
    if bombMap[i][j]=="#":
      result[i][j]="#"
      y=i-1
      while y< i+2:
        x=j-1
        while x<j+2:
          if 0<=y and 0<=x and y<H and x<W:
            
            if bombMap[y][x]!="#":
              #print(bombMap[y][x])
              result[y][x]=result[y][x]+1
              #print(result[y][x])
          x=x+1        
        y=y+1
    
    j=j+1  
  i=i+1
  
  
#print(bombMap)
#print(result)

i=0
while i<H:
  j=0
  temp=""
  while j<W:
    temp=temp+str(result[i][j])
    j=j+1
  print(temp)
  i=i+1

Measured memory_bytes: 3064
N = int(input())
a = list(map(int,input().split()))

#print(a)

ans = int(a[0])
for i in range(1,N):
    if ans > 10**18:
        break
    else:
        ans = ans * int(a[i])
if 0 in a:
    print(0)
elif ans > 10**18:
    print(-1)
else:
    print(ans)


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

int res;
int x;
string s;

int main()
{
  cin >> res;

  while(cin >> s >> x){
    if(s == "+"){ res += x;  continue; }
    if(s == "-"){ res -= x;  continue; }
    if(s == "*"){ res *= x;  continue; }
    if(s == "/"){ res /= x;  continue; }
    if(s == "=") break;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		final int X = 0;
		final int Y = 1;
		final int SIZE = 2;
		int countAxis = 0;
		int maxThickness = 0;

		// ?????£???(??¨??????0??§??????)??§?¨??????????
		int[][] axis = new int[10][10];
		for (int countX = 0; countX < 10; countX++) {
			for (int countY = 0; countY < 10; countY++) {
				axis[countX][countY] = 0;
			}
		}
		BufferedReader input = new BufferedReader(new InputStreamReader(
				System.in));
		// ???????????????
		while (true) {

			String inputData = input.readLine();

			if (inputData == null || inputData.equals("")) {
				break;
			}

			String[] data = inputData.split(",");

			if (Integer.parseInt(data[SIZE]) == 1) {
				makeSmallArea(axis, Integer.parseInt(data[X]),
						Integer.parseInt(data[Y]));
			}

			if (Integer.parseInt(data[SIZE]) == 2) {
				makeMiddleArea(axis, Integer.parseInt(data[X]),
						Integer.parseInt(data[Y]));

			}

			if (Integer.parseInt(data[SIZE]) == 3) {
				makeBigArea(axis, Integer.parseInt(data[X]),
						Integer.parseInt(data[Y]));

			}

		}
		countAxis = 0;
		for (int countX = 0; countX < 10; countX++) {
			for (int countY = 0; countY < 10; countY++) {
				if (axis[countX][countY] == 0) {
					countAxis++;
				}
				if (axis[countX][countY] > maxThickness) {
					maxThickness = axis[countX][countY];
				}

			}
		}

		System.out.println(countAxis);
		System.out.println(maxThickness);
	}

	static void makeSmallArea(int[][] axis, int xAxis, int yAxis) {
		if (xAxis >= 1) {
			axis[xAxis - 1][yAxis]++;
		}
		if (xAxis <= 8) {
			axis[xAxis + 1][yAxis]++;
		}
		if (yAxis >= 1) {
			axis[xAxis][yAxis - 1]++;
		}
		if (yAxis <= 8) {
			axis[xAxis][yAxis + 1]++;
		}
		axis[xAxis][yAxis]++;
	}

	static void makeMiddleArea(int[][] axis, int xAxis, int yAxis) {
		makeSmallArea(axis, xAxis, yAxis);
		if (xAxis >= 1 && yAxis >= 1) {
			axis[xAxis - 1][yAxis - 1]++;

		}
		if (xAxis >= 1 && yAxis <= 8) {
			axis[xAxis - 1][yAxis + 1]++;

		}
		if (xAxis <= 8 && yAxis >= 1) {
			axis[xAxis + 1][yAxis - 1]++;
		}
		if (xAxis <= 8 && yAxis <= 8) {
			axis[xAxis + 1][yAxis + 1]++;

		}
	}

	static void makeBigArea(int[][] axis, int xAxis, int yAxis) {
		makeMiddleArea(axis, xAxis, yAxis);
		if (xAxis >= 2) {
			axis[xAxis - 2][yAxis]++;
		}
		if (xAxis <= 7) {
			axis[xAxis + 2][yAxis]++;
		}
		if (yAxis >= 2) {
			axis[xAxis][yAxis - 2]++;
		}
		if (yAxis <= 7) {
			axis[xAxis][yAxis + 2]++;
		}
	}
}

Measured memory_bytes: 16924
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    cout<<a*b/__gcd(a,b);}

Measured memory_bytes: 256
a,b,c,x,y = list(map(int,input().split()))

if 2*c > a+b:
    ans = a*x + b*y
else:
    ans = min(x,y)*2*c+(x-min(x,y))*(min(2*c,a))+(y-min(x,y))*(min(2*c,b))

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    string s, t;
    cin >> s >> t;
    vvi dp(s.size() + 1, vi(t.size() + 1, 0));
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = 1 + dp[i][j];
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    int ss = s.size();
    int tt = t.size();
    string ret = "";
    while (ss != 0 && tt != 0) {
        if (s[ss - 1] == t[tt - 1] /*dp[ss][tt] == dp[ss - 1][tt - 1] + 1*/) {
            ret = s[ss - 1] + ret;
            ss--;
            tt--;
        } else if (dp[ss][tt] == dp[ss - 1][tt])
            ss--;
        else
            tt--;
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
  int K;cin >> K;
  if(K<=9){
    cout << K << endl;
    return 0;
  }
  vector<ll> ANS(1,1);
  vector<ll> X(9,1);
  int count = 9;
  for(int i=1;i<9;i++){
    X[i] = X[i-1] + 1;
    ANS.push_back(X[i]);
  }
  while(1){
    vector<ll> Y;
    int L = X.size();
    for(int i=0;i<L;i++){
      ll x = X[i];
      ll d = x%10;
      if(d==0){
        Y.push_back(x*10);
        Y.push_back(x*10+1);
        ANS.push_back(x*10);
        ANS.push_back(x*10+1);
        count += 2;
      }else if(d==9){
        Y.push_back(x*10+8);
        Y.push_back(x*10+9);
        ANS.push_back(x*10+8);
        ANS.push_back(x*10+9);
        count += 2;
      }else{
        for(int j=d-1;j<=d+1;j++){
          Y.push_back(x*10+j);
          ANS.push_back(x*10+j);
        }
        count += 3;
      }
    }
    if(count >= K){
      cout << ANS[K-1] << endl;
      return 0;
    }
    X = Y;
  }
}

Measured memory_bytes: 4208
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	
	bool yes = false;
	
	if( a == b && b != c ) yes = true;
	if( a == c && a != b ) yes = true;
	if( b == c && a != c ) yes = true;
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;
int N, C;

std::vector< std::bitset<30> > used;

int main() {
    std::cin >> N >> C;
    used.resize(1e5+1, std::bitset<30>(0));

    int l = 1e5+1, r = 0;
    int s, t, c;
    REP(i, N) {
        std::cin >> s >> t >> c;
        s--, t--;

        for(int j=s; j<=t; ++j) {
            used[j][c] = 1;
        }

        l = std::min(l, s);
        r = std::max(r, t);
    }

    int ans = 0;
    for(int i=l; i<=r; ++i) {
        ans = std::max(ans, (int)used[i].count());
    }
    std::cout << ans << std::endl;

}       

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  string s;cin>>s;

  int c=0;
  rep(i,0,3){
    if(s[i]=='1')c++;
  }

  out(c);


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    int a = k/2;
    cout << a * (k-a) << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import product

h, w, k = list(map(int, input().split()))

seqs = [s for s in product([0,1], repeat=w-1) if not any(x&y for x,y in zip(s,s[1:]))]
cache = {}

def f(x, y):
  if y > h:
    return int(x == k)

  if (x,y) in cache:
    return cache[(x,y)]

  r = 0
  for s in seqs:
    nx = x
    if x < w and s[x-1]:
      nx += 1
    elif x > 1 and s[x-2]:
      nx -= 1
    r = (r + f(nx, y+1)) % (10**9+7)

  cache[(x,y)] = r
  return r

print(f(1, 1))

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

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

    bool ok = true;

    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (x % 2 == 0 && !(x % 3 == 0 || x % 5 == 0)) {
            ok = false;
        }
    }

    if (ok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	k = 1
	for i in 1:n
		if a[i]%2 == 0
			k *= 2
		end
	end
	println(3^n-k)
end

main()

Measured memory_bytes: 112016
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
  input! {
    k: usize,
    s: Chars,
  }
  if s.len() <= k {
    for &c in &s {
      print!("{}", c);
    }
    println!("");
  } else {
    for &c in s.iter().take(k) {
      print!("{}", c);
    }
    println!("...");
  }
}


Measured memory_bytes: 2168