akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int a, b, c, m; scan(a, b, c);)
		out((55 - a - b - c) / 7 <= 20 - a - b ? "YES" : "NO", '\n');
}


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

const int A = 1000005;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    //頻度を求める配列
    vector<int> c(A);

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

    bool pairwise = true;
    for(int i=2; i< A; ++i){
        int cnt = 0;
        for(int j=i; j<A; j += i){
            cnt += c[j];
        }
        if(cnt > 1) pairwise = false;
    }

    if(pairwise){
        cout << "pairwise coprime" << endl;
        return 0;
    }

    //gcd(0, x) =x なので初期値は0が都合良い
    int g = 0;
    for(int i=0; i<n; ++i){
        g = gcd(g, a[i]);
    }

    if(g == 1){
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 11184
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 0
min_h = 10**9
for i in range(N):
    tmp = abs(A - (T - H[i] * 0.006))
    if min_h > tmp:
        min_h = tmp
        ans = i + 1
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
     
    char s[4];
    int result=0;
     
    scanf("%s",s);
     
    if(s[0]=='R'){
      if(s[1]=='R'){
        if(s[2]=='R'){
          result=3;
        }else{
          result=2;
        }
      }else if(s[1]=='S'){
        result=1;
      }
    }
     
    if(s[0]=='S'){
      if(s[1]=='S'){
        if(s[2]=='S'){
          result=0;
        }else if(s[2]=='R'){
          result=1;
        }    
      }else if(s[1]=='R'){
        if(s[2]=='R'){
            result=2;
        }else{
          result=1;
        }
    }
  }
    
     
    printf("%d",result);

}


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

int main(void) {
  int N;
  cin >> N;
  map<int, int> count;
  rep(i, N) {
    int a;
    cin >> a;
    count[a]++;
  }

  int K = (int)count.size();
  int dup_num = N - K;
  if (dup_num % 2)
    cout << K - 1 << endl;
  else
    cout << K << endl;
  return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
string st,xst;
int main()
{
    cin>>st;
    for(int i=0;i<st.size();i++)
        if(st[i]=='0' || st[i]=='1') xst+=st[i];
        else
            if(xst.size()>0) xst.erase(xst.size()-1,1);
    cout<<xst<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

#define pi 3.14159265358979323846

int32_t main(){
	int r;
	cin >> r;
	
	cout << fixed << setprecision(10) << 2.0 * pi * r;

	return 0;
}



Measured memory_bytes: 3784
def score(x):
    if x == 1:
        return 300000
    if x == 2:
        return 200000
    if x == 3:
        return 100000
    return 0 

x, y = [int(x) for x in input().split(' ')]

s = score(x) + score(y)
if x == 1 and y == 1:
    s += 400000

print(s)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	int a, b;
	int ans = 6;
	cin >> a >> b;
	cout << ans - a - b << endl;
}

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

Measured memory_bytes: 256
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

ll dp1[105][105][105], dp2[105][10010], dp[105][105], trans[105];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll s, t, u, n, o, d;
	cin >> s >> t >> u >> n >> o >> d;
	vector<ll> e(t), c(t), h(n), a(n);
	for (ll i = 0; i < t; ++i) cin >> e[i] >> c[i];
	for (ll i = 0; i < n; ++i) cin >> h[i] >> a[i];

	// dp1[トレーニングi][体力j][トレーニングした回数k]
	memset(dp1, -1, sizeof(dp1));
	dp1[0][0][0] = 0;
	for (ll i = 0; i < t; ++i) for (ll j = 0; j <= s; ++j) for (ll k = 0; k <= i; ++k) {
		if (dp1[i][j][k] == -1) continue;
		if (j + e[i] <= s && k + 1 <= u) {
			dp1[i + 1][j + e[i]][k + 1] = max(dp1[i + 1][j + e[i]][k + 1], dp1[i][j][k] + c[i]);
		}
		dp1[i + 1][j][k] = max(dp1[i + 1][j][k], dp1[i][j][k]);
	}

	//for (ll i = 0; i <= t; ++i) for (ll j = 0; j <= s; ++j) for (ll k = 0; k <= i; ++k) {
	//	cout << i << " " << j << " " << k << " " << dp1[i][j][k] << endl;
	//}

	// dp2[ドーナツi][カロリーj]
	dp2[0][0] = 0;
	for (ll i = 0; i < n; ++i) {
		for (ll j = 0; j < 10010; ++j) dp2[i + 1][j] = dp2[i][j];
		for (ll j = 0; j < 10010; ++j) {
			if (j + a[i] < 10010) dp2[i+1][j + a[i]] = max(dp2[i+1][j + a[i]], dp2[i+1][j] + h[i]);
		}
	}

	//for (ll i = 0; i <= n; ++i) for (ll j = 0; j <= 10; ++j) {
	//	cout << i << " " << j << " " << dp2[i][j] << endl;
	//}

	// trans[体力i] = 幸福度
	memset(trans, -1, sizeof(trans));
	for (ll i = 0; i <= s; ++i) {
		//cout << i << " " << dp1[t][i][u] << " " << dp2[n][dp1[t - 1][i][u]] << endl;
		if (dp1[t][i][u] != -1) trans[i] = dp2[n][dp1[t][i][u]];
	}

	for (ll i = 0; i <= s; ++i) {
		//cout << i << " " << trans[i] << endl;
	}

	// dp[i日目][体力j] = 幸福の最大
	memset(dp, -1, sizeof(dp));
	dp[0][s] = 0;
	for (ll i = 0; i < d; ++i) for (ll j = 0; j <= s; ++j) {
		if (dp[i][j] == -1) continue;
		for (ll k = 0; k <= j; ++k) {
			if (trans[k] != -1) {
				dp[i + 1][min(s, j - k + o)] = max(dp[i + 1][min(s, j - k + o)], dp[i][j] + trans[k]);
			}
		}
	}

	for (ll i = 0; i < d; ++i) for (ll j = 0; j <= s; ++j) {
		//cout << i << " " << j << " " << dp[i][j] << endl;
	}

	ll ret = -1;
	for (ll i = 0; i <= s; ++i) {
		ret = max(ret, dp[d][i]);
	}
	cout << ret << endl;
}


Measured memory_bytes: 20184
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

fn main() {
    let (h, w): (usize, usize);
    input!(h, w);
    let mut v = Vec::new();
    for _ in 0..h {
        v.push(input_line_str());
    }
    for z in &v {
        p(z);
        p(z);
    }
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)

#define BR "\n"
#define SP " "

int main() {
  int n;
  cin >> n;
  int a = 0, b = 0;
  rep0(i, n) {
    string l, r;
    cin >> l >> r;
    if (l > r) {
      a += 3;
    } else if (l < r) {
      b += 3;
    } else {
      a += 1;
      b += 1;
    }
  }
  cout << a << SP << b << BR;
  return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> Ls(N);
    for (auto & e : Ls) cin >> e;
    sort(Ls.begin(), Ls.end());
    int cum = accumulate(Ls.rbegin(), Ls.rbegin() + K, 0);
    cout << cum << endl;
    return 0;
}

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

int main() {
  vector<vector<int>> C(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> C[i][j];

  int ok = false;

  rep(a1, 101) {
    rep(a2, 101) {
      rep(a3, 101) {
        int b1 = C[0][0] - a1;
        int b2 = C[1][1] - a2;
        int b3 = C[2][2] - a3;
        if (a1 + b1 == C[0][0] && a1 + b2 == C[0][1] && a1 + b3 == C[0][2] &&
            a2 + b1 == C[1][0] && a2 + b2 == C[1][1] && a2 + b3 == C[1][2] &&
            a3 + b1 == C[2][0] && a3 + b2 == C[2][1] && a3 + b3 == C[2][2])
          ok = true;
      }
    }
  }

  if (ok)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    ll N;
    cin >> N;
    ll max = 0;
    for (ll number = 0; number <= N; ++number) {
        if (number * number <= N) {
            max = number * number;
            continue;
        } else {
            break;
        }
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 384
# 初期入力
import sys
input = sys.stdin.readline
A500 = int(input())
B100 = int(input())
C50 = int(input())
X = int(input())

ans =0
num_500 =0
#500円を最大何枚使えるか
if 1 <= X //500 <=A500: 
    num_500 =X//500
elif X //500 <1:
    num_500 =0
else:
    num_500 =A500

#100円を最大何枚使えるか
num_100_list =[0]
num_100 =0
if num_500 !=0:
    for i in range(num_500+1):
        if 1 <= (X -500*i) /100 <=B100:
            num_100_list.append( (X -500*i) //100 )
        elif (X -500*i) /100 <1:
            num_100_list.append(0)
        else:
            num_100_list.append(B100)
else:
    if 1 <= X //100 <=B100: 
        num_100 =X//100
    elif X //100 <1:
        num_100 =0
    else:
        num_100 =B100
num_100 =max(max(num_100_list),num_100)

num_50 =0
#if num_500 * num_100 !=0:
for i in range(num_500 +1):
    for j in range(num_100 +1):
        if 0 <=(X -500*i -100 *j) /50 <=C50:
            #print(i,j)
            ans +=1

print(ans)

Measured memory_bytes: 3064
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    string s;
    cin >> s;

    map<char, ll> mp;
    for(char c : s){
        mp[c]++;
    }

    ll answer = 1;
    for(auto p : mp){
        ll count = p.second;
        answer *= count+1;
        answer %= mod;
    }

    p(answer-1);
    
    return 0;
}

Measured memory_bytes: 512
import qualified Data.ByteString.Char8 as B
import qualified Data.Sequence as SQ

main :: IO ()
main = do
    s <- B.getLine :: IO B.ByteString
    q <- readLn :: IO Int

    let
        solve :: (SQ.Seq Char, SQ.Seq Char) -> Int -> Int -> IO (SQ.Seq Char, SQ.Seq Char, Int)
        solve (sqx,sqy) n cnt
            | n == 0 = return (sqx,sqy,cnt) 
            | otherwise = do
                xs <- words <$> getLine :: IO [String]
                case (length xs) of
                    1 -> do
                        solve (sqx,sqy) (n-1) (cnt+1)
                    _ -> do
                        let [_,f,[c]] = xs
                        case (f, even cnt) of
                            ("1", True) -> solve ((SQ.<|) c sqx, sqy) (n-1) cnt
                            ("1", False) -> solve (sqx, (SQ.|>) sqy c) (n-1) cnt
                            ("2", True) -> solve (sqx, (SQ.|>) sqy c) (n-1) cnt
                            ("2", False) -> solve ((SQ.<|) c sqx, sqy)  (n-1) cnt
        
        outl :: SQ.Seq Char -> IO ()
        outl sq =
            case SQ.viewl sq of
                c SQ.:< sq' -> do
                    putChar c
                    outl sq'
                SQ.EmptyL -> return ()

        outr :: SQ.Seq Char -> IO ()
        outr sq =
            case SQ.viewr sq of
                sq' SQ.:> c -> do
                    putChar c
                    outr sq'
                SQ.EmptyR -> return ()


    (sqx,sqy,cnt) <- solve (SQ.empty, SQ.empty) q 0

    if (even cnt)
        then do
            outl sqx
            B.putStr s
            outl sqy
            putStrLn ""
        else do
            outr sqy
            B.putStr $ B.reverse s
            outr sqx
            putStrLn ""

Measured memory_bytes: 21884
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const int inf = 2e9;

template<class T> bool warshall_floyd(VV<T>& d) {
  int n = d.size();
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[i][k] != inf and d[k][j] != inf) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) if (d[i][i] < 0) return true;
  return false;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> d; assign(d, n, n, inf);
  for (int i = 0; i < n; i++) d[i][i] = 0;
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    d[a][b] = c;
  }
  if (warshall_floyd<int>(d)) cout << "NEGATIVE CYCLE" << '\n';
  else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cout << (d[i][j] != inf ? to_string(d[i][j]) : "INF") << (j < n - 1 ? ' ' : '\n');
    }
  }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,Q;
int A[222222],B[222222];

signed main(){
    scanf("%lld%lld",&N,&Q);
    N*=2;
    rep(i,N)scanf("%lld",&A[i]);
    rep(i,N)scanf("%lld",&B[i]);

    multiset<int>x,y;
    int sumx=0;
    int base=accumulate(A,A+N,0ll);
    for(int i=1;i+1<N;i++){
        if(A[i]<=B[i]){
            x.insert(B[i]-A[i]);
            sumx+=B[i]-A[i];
        }
        else{
            y.insert(B[i]-A[i]);
        }
    }

    while(Q--){
        int p,a,b;
        scanf("%lld%lld%lld",&p,&a,&b);
        p--;

        base-=A[p];
        if(1<=p&&p+1<N){
            if(A[p]<=B[p]){
                sumx-=B[p]-A[p];
                auto it=x.find(B[p]-A[p]);
                x.erase(it);
            }
            else{
                auto it=y.find(B[p]-A[p]);
                y.erase(it);
            }
        }

        A[p]=a;B[p]=b;
        base+=A[p];
        if(1<=p&&p+1<N){
            if(A[p]<=B[p]){
                x.insert(B[p]-A[p]);
                sumx+=B[p]-A[p];
            }
            else{
                y.insert(B[p]-A[p]);
            }
        }

        int ans=0;
        if(x.size()%2==0){
            ans=sumx;
        }
        else{
            ans=sumx-*x.begin();
            chmax(ans,sumx+*y.rbegin());
        }
        printf("%lld\n",ans+base);
    }
    return 0;
}


Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a,b,c;
    int x,y;
    cin>>a>>b>>c>>x>>y;
    int v=0;
    if(2*c<=a+b){
        v+=c*2*min(x,y);
        if(x>y){
            if(2*c*(x-y)<a*(x-y))
                v+=2*c*(x-y);
            else
                v+=a*(x-y);
        }
        else{
            if(2*c*(y-x)<b*(y-x))
                v+=2*c*(y-x);
            else
                v+=b*(y-x);
        }
    }
    else{
        v=(a+b)*min(x,y);
        if(x>y){
            if(2*c*(x-y)<a*(x-y))
                v+=2*c*(x-y);
            else
                v+=a*(x-y);
        }
        else{
            if(2*c*(y-x)<b*(y-x))
                v+=2*c*(y-x);
            else
                v+=b*(y-x);
        }
    }
    printf("%d\n",v);
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


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

int main() {
    int l, r;
    cin >> l >> r;
    int lmod = l % 2019;
    int rmod = r % 2019;
    int ret = 0;
    if (lmod < rmod && (r - l < 2019)){
        ret = 2020;
        for (int i = lmod; i < rmod;i++){
            for (int j = i + 1; j <= rmod; j++){
                if ((i * j) % 2019 < ret){
                    ret = (i * j) % 2019;
                }
            }
        }
    }
    else{
        ret = 0;
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	string s, t;
	cin >> s >> t;
	if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}



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

int main(){
    ll n,sx,sy,sh;
    cin >> n;
    vector<ll> x(n),y(n),h(n);
    for(int i = 0;i < n;i ++){
        cin >> x[i] >> y[i] >>h[i];
        if(h[i]) sx = x[i],sy = y[i],sh = h[i];
    }
    for(ll cx = 0;cx < 101;cx ++){
        for(ll cy = 0;cy < 101;cy ++){
            ll H = sh+abs(sx-cx)+abs(sy-cy);
            bool isP = true;
            for(int i = 0;i < n;i ++){
                if(h[i]&&H!=h[i]+abs(x[i]-cx)+abs(y[i]-cy)) {isP=false;break;}
                if(!h[i]&&H>abs(x[i]-cx)+abs(y[i]-cy)) {isP=false;break;}
            }
            if(isP) {cout << cx << " " << cy << " " << H << endl;return 0;}
        }
    } 
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;

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

	vvi num(n+1, vi(2));
	vvi cost(n+1, vi(n+1, 100000000));

	REP(i, n) {
		cin >> num[i+1][0] >> num[i+1][1];
	}

	REP(i, n+1) {
		cost[1][i] = 0;
	}
	
	FOR(i, 2, n) {
		FOR(j, 1, n-i+1) {
			FOR(k, j, i+j-2) {
				int mul = num[j][0] * num[k][1] * num[k+1][0] * num[i+j-1][1];
				cost[i][j] = min(cost[i][j], mul+cost[k-j+1][j]+cost[i+j-k-1][k+1]);
			}
		}
	}

	cout << cost[n][1] << endl;
	return 0;
}

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

int main()
{
  int x;
  cin >> x;
  if (x >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n;
    cin >> n;
    if(n == 1) {cout << 1 << "\n"; return 0;}

    for (int i = 1; i <= n; ++i) {
        if(n < i*i) {cout << (ll)(i-1)*(i-1) << "\n"; return 0;}
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int main()
{
	int w,h;
	while(scanf(" %d %d",&w,&h),w) 
	{
		int W[h][w];
		int H[h][w];

		for(int i = 0; i < 2*h-1; ++i)
		{
			for(int j = 0; j < (i%2==0?w-1:w); ++j)
			{
				if(i%2==0)
				{
					scanf(" %d",&W[i/2][j]);
				}
				else
				{
					scanf(" %d",&H[i/2][j]);
				}
			}
		}
		queue<int> xs,ys,steps;
		xs.push(0); ys.push(0); steps.push(1);
		bool used[h][w];
		memset(used,0,sizeof(used));
		int ans=0;
		int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
		while(!xs.empty()) 
		{
			int x=xs.front(),y=ys.front(),step=steps.front();
			xs.pop(); ys.pop(); steps.pop();
			if(y==h-1&&x==w-1)
			{
				ans=step;
				break;
			}
			for(int i = 0; i < 4; ++i)
			{
				int nx=x+dx[i],ny=y+dy[i];
				if(0<=nx&&nx<w&&0<=ny&&ny<h&&!used[ny][nx])
				{
					if( (i==0&&!W[y][x])|| (i==1&&!H[y][x]) || (i==2&&!W[y][nx]) || (i==3&&!H[ny][x]))
					{
						used[ny][nx]=true;
						xs.push(nx); ys.push(ny); steps.push(step+1);
					}
				}
			}
		}
		cout<<ans<<endl;
	}
  return 0;
}

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

int main() {
    string S; cin >> S;
    if (S == "SSS") {
        cout << 0 << endl;
    } else if (S == "RRS" || S == "SRR") {
        cout << 2 << endl;
    } else if (S == "RRR") {
        cout << 3 << endl;
    } else {
        cout << 1 << endl;
    }
}

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

using namespace std;

int main() {

	int n;
	cin >> n;
	map<string, int> m;
	string ss[] = {"AC", "WA", "TLE", "RE"};
	while (n--) {
		string s;
		cin >> s;
		
		m[s]++;
	}

	for (auto s: ss) {
		cout << s << " x " << m[s] << "\n";
	}

	return 0;
}

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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<ll>());
	queue<ll> qu;	
	ll ans = 0;
	qu.push(a[0]);
	for (ll i = 1; i < n; i++) {
		ans += qu.front();
		qu.pop();
		qu.push(a[i]);
		qu.push(a[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

    int a ,b;
    int x;
    double y;

    cin >> a >> b;

    x = (a + b) / 2;
    y = (a + b) % 2;

    if(y > 0) cout << x+1 << endl;
    else cout << x << endl;

    return 0;


}

Measured memory_bytes: 256
x, y = map(int, input().split())
if x >= 0 and y >= 0 and x <= y:
  ans = y - x
elif x >= 0 and y > 0 and x >= y:
  ans = x -  y + 2
elif x <= 0 and y <= 0 and x <= y:
  ans = y - x
elif x < 0 and y <= 0 and x >= y:
  ans = x - y + 2
elif x >= 0 and y <= 0:
  ans = abs(x - abs(y)) + 1
elif x <= 0 and y >= 0:
  ans = abs(y - abs(x)) + 1
print(ans)

Measured memory_bytes: 9156
#include <stdio.h>

int main() {
    
    char a[20];
    scanf("%s", &a);
    a[5] = ' ';
    a[13] = ' ';
    
    for(int i = 0 ; a[i] != '\0'; i++){
        printf("%c", a[i]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1648
a = input()
a = sorted(a)
b = input()
b = sorted(b)
ml = min(len(a),len(b))
cnt = 0
if min(a) < max(b):
    print("Yes")
    cnt = 1
elif a[0:ml] == b[0:ml]:
    if len(a) < len(b):
        print("Yes")
        cnt = 1
if cnt == 0:
    print("No")


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}

ll f[maxs];

void solve(){
    
    ll x,n;
    cin >> x >> n;
    ll a[n+1];
    for(ll i=1;i<n+1;i++){
        cin >> a[i] ;
        f[a[i]]++;
    }
    if(f[x] == 0){
        cout << x;
        return;
    }
    ll ans=oo;
    ll no;
    for(ll i = 0;i<=200;i++){
        if(f[i] == 0){
            ll d = abs(i-x);
            if(d < ans){
                ans = d;
                no = i;
            }
        }
    }
    cout << no;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  string s;
  cin >> s;
  if (s <= "2019/04/30") {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
            using namespace std;
             
            int main() {
              int x=0,y=0,z=0,w=0;
              cin >>x >>y>>z>>w;
              int l=x+y;
              int r=z+w;
              if (l==r){cout<<"Balanced";} else if (l>r) {cout<<"Left";} else {cout<<"Right";};
              
            }

Measured memory_bytes: 256
//04
#include<iostream>
#include<set>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int gx,gy,p;
    cin>>gx>>gy>>p;
    bool mt[16][16][16][16]={{{{}}}};
    while(p--){
      int x,xx,y,yy;
      cin>>x>>y>>xx>>yy;
      mt[x][y][xx][yy]=mt[xx][yy][x][y]=true;
    }
    int g[17][17]={1};
    for(int y=0;y<=gy;y++){
      for(int x=0;x<=gx;x++){
	if(!mt[x][y][x+1][y]){
	  g[y][x+1]+=g[y][x];
	}
	if(!mt[x][y][x][y+1]){
	  g[y+1][x]+=g[y][x];
	}
      }
    }
    if(g[gy][gx]){
      cout<<g[gy][gx]<<endl;
    }else{
      cout<<"Miserable Hokusai!"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1232
s = input()
a,b,c,d = s[0], s[1],s[2],s[3]

ops = ["+","-"]

for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            x = eval(a+op1+b+op2+c+op3+d)
            if x == 7:
                print(a+op1+b+op2+c+op3+d+"=7")
                exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

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

  cout << a + a*a + a*a*a << endl;

  return 0;
}

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

int main(){
  int N,A,x;
  cin >> N >> A;
  x = N % 500;
  x -= A;
  if(x <= 0){
   cout << "Yes" << endl;
  }
  else{
   cout << "No" << endl;
  }
}

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

int main() {
	int A,B,ans;
	cin>>A>>B;
	if((A==1&&B==2)||(A==2&&B==1)){
		cout<<3<<endl;
	}
	else if((A==2&&B==3)||(A==3&&B==2)){
		cout<<1<<endl;
	}
	else{
		cout<<2<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m, memo[N];
V<int> e[N];
int dfs(int a){
  if(memo[a] >= 0) return memo[a];
  memo[a] = 0;
  for(int b: e[a]) maxs(memo[a], dfs(b) + 1);
  return memo[a];
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  Fill(memo, -1);
  FOR(i, 0, m){
    int x, y;
    cin >> x >> y;
    x--; y--;
    e[y].pb(x);
  }
  int ans = 0;
  FOR(i, 0, n) maxs(ans, dfs(i));
  cout << ans << endl;
}

Measured memory_bytes: 9088
import sys
from collections import deque

n = int(input())
ary = deque([])

for line in sys.stdin:
    op = line.strip().split()
    cmd = op[0]

    if cmd[0] == 'i':
        x = op[1]
        ary.appendleft(x)

    elif len(cmd) == 6:
        x = op[1]
        if x in ary:
            ary.remove(x)

    elif len(cmd) == 10:
        ary.pop()

    else:
        ary.popleft()

print(*ary)



Measured memory_bytes: 69812
# coding : utf-8

N = int(input())
S = input()

a = [chr(i) for i in range(65, 65+26)]

for i in range(len(S)):
    if(ord(S[i])+N <= 90):
        print(chr(ord(S[i])+N), end="")
    elif(ord(S[i])+N > 90):
        print( chr( 65 + N - (91-ord(S[i])) ), end="" )

Measured memory_bytes: 4468
#include <iostream>
#include <vector>
using namespace std;
int isprime(int x){
  for(int p=2;p*p<=x;p++)if(x%p==0)return 0;
  return 1;
}
int main(){
  int N,M;
  scanf("%d%d",&N,&M);
  if(isprime(M)){
    printf("%d\n",1);
    return 0;
  }
  for(int n=N;;n++){
    if(M%n==0){
      printf("%d\n",M/n);
      break;
    }
  }
}

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

map<ll, ll> primeFactors;

void primeFactorization(ll n) {
    ll N = n;
    for (int i=2; i<=sqrt(n); i++) {
        if (N%i == 0) primeFactors[i] = 0;
        while (N%i == 0) {
            N /= i;
            primeFactors[i]++;
        }
    }
    if (N != 1) primeFactors[N] = 1;
}

int main(){
    ll N;
    cin >> N;
    primeFactorization(N);
    ll count = 0;
    for (auto primeFactor : primeFactors) {
        ll e = 1;
        ll ePrime = primeFactor.second; 
        while (e <= ePrime) {
            N /= (ll)pow(primeFactor.first, e);
            ePrime -= e;
            e++;
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 4016
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}


const ll MOD = 998244353;
ll calc_pow(ll x, ll n){
	ll ret = 1;
	while(n>0){
		if(n & 1) ret = ret*x%MOD;
		x = x*x%MOD;
		n >>= 1;
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	REP(i,n) cin >> d[i];
	
	vector<int> c(n,0);
	if(d[0]!=0){
		cout << 0 << endl;
		return 0;
	}
	
	int dmax = 0;
	REP(i,n){
		c[d[i]]++;
		chmax(dmax, d[i]);
	}
	
	
	
	if(c[0]!=1){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	FOR(i,1,dmax+1){
		if(c[i]==0){
			cout << 0 << endl;
			return 0;
		}
		ll a = calc_pow(c[i-1], c[i]);
		ans = (ans*a)%MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <stack>
#include <complex>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,n) loop(i,0,n)
#define all(c) (c).begin(), (c).end()
typedef complex<int> P;

const int MAX_M = 1.5e6+10;
const int SIZE = 2000;
int ps[MAX_M/2];
bool isp[MAX_M];
int grid[SIZE][SIZE]={};
P itop[MAX_M];
pair<int,int> dp[SIZE][SIZE];

int cnt_p = 0;

void make_es(){
    fill(isp,isp+MAX_M,true);
    isp[0]=isp[1]=false;
    rep(i,MAX_M){
        if(!isp[i]) continue;
        ps[cnt_p++] = i;
        for(int j=i<<1; j<MAX_M; j+=i){
            isp[j] = false;
        }
    }
}

P const ii(0,1);

int n,m;

pair<int,int> rec(int y, int x){
    if(dp[y][x].first!=-1) return dp[y][x];

    pair<int,int> res(0,0);
    if(isp[grid[y][x]]){
        res.first = 1;
        res.second = grid[y][x];
    }
    pair<int,int> best(0,0);
    loop(i,-1,2){
        if(grid[y+1][x+i]<=m){
            auto t = rec(y+1,x+i);
            best = max(t,best);
        }
    }

    if(best.first != 0){
        res.first += best.first;
        res.second = best.second;
    }

    dp[y][x] = res;
    return res;
}

int main(){
    make_es();

    P p(SIZE/2,SIZE/2);
    P dir(0,1);
    for(int i=1; i<MAX_M; i++){
        grid[p.real()][p.imag()] = i;
        itop[i]=p;
        p+=dir;
        P q = p+dir*ii;
        if(grid[q.real()][q.imag()] == 0){
            dir*=ii;
        }
    }

    while(cin>>m>>n, n+m){
        auto t = make_pair(-1,-1);
        rep(i,SIZE)rep(j,SIZE) dp[i][j] = t;

        auto u = itop[n];
        auto ans = rec(u.real(), u.imag());
        cout << ans.first << " " << ans.second << endl;
    }
}

Measured memory_bytes: 60664
function f()
    N = parse(Int, readline())
    A = parse.(Int, split(readline()))
    ans = 1
    flag = 0
    for i in 2:N
        if flag == 1
            if A[i]<A[i-1]
                ans += 1;
                flag = 0
            end
        elseif flag == 0
            if A[i]>A[i-1]
                flag = 1
            elseif A[i]<A[i-1]
                flag = -1
            end
        else
            if A[i]>A[i-1]
                ans += 1
                flag = 0
            end
        end
    end
    
    println(Int(ans))
end
f()

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO() \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

const int SZ = 1e5 + 1;
int n;
vi adj[SZ];
ll dp[SZ][2];

void dfs(int v, int par) {
    ll black = 1, white = 1;
    for (auto u : adj[v]) {
        if (u == par)    continue;
        if (dp[u][0] == 0)  dfs(u, v);
        black = (black * dp[u][1]) % MOD;
        white = (white * (dp[u][0] + dp[u][1]) % MOD) % MOD;
    }
    dp[v][0] = black, dp[v][1] = white;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[--u].pb(--v);
        adj[v].pb(u);
    }
    memset(dp, 0, sizeof(dp));
    dfs(0, 0);
    cout << (dp[0][0] + dp[0][1]) % MOD << endl;
    return 0;
}


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

int main(){ 
    int n,t,a; cin>>n>>t>>a;
    int h,ans,r=1000000;
    for(int i=0;i<n;i++){
        cin>>h;
        int tt;
        tt=1000*t-h*6;
        tt=tt-a*1000;
        if(tt<0) tt=-tt;
        if(tt<=r){
            r=tt;
            ans=i+1;
            }
        }
    cout<<ans<<endl;
    }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
int mod=1000000007;

ll fact[100005];

ll calc(ll n,ll k){
  if(k==0) return 1;
  ll m=n*n %mod;
  if(k%2) return n*calc(m,k/2) %mod;
  else return calc(m,k/2) %mod;
  }
  

ll comb(ll n,ll k){
  ll ret=fact[n];
  ret=ret*calc(fact[k],mod-2) %mod;
  ret=ret*calc(fact[n-k],mod-2) %mod;
  return ret;
  }
  
int main(){
  ll n;cin>>n;
  int a[n];
  rep(i,n)a[i+1]=0;
  ll left,right;
  rep(i,n+1){
    int x;
    cin>>x;
    if(a[x]==0)a[x]=i+1;
    else {
      left=a[x];right=i+1;
      break;
      }
    }
  fact[0]=1;
  rep(i,n+1)fact[i+1]=(i+1)*fact[i] %mod;
  rep(i,n+1){
    if(right-left+i<=n){
      ll ans=comb(n+1,i+1)-comb(n-right+left,i);
      if(ans<0)ans+=mod;
      cout<<ans<<endl;
      }
    else
      cout<<comb(n+1,i+1)<<endl;
    }
  return 0;
    
    
} 


Measured memory_bytes: 2432
#include<stdio.h>
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int,int,int,int);
void mergeSort(int A[],int,int,int);

int main(){
  int A[MAX],n,i;
    cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A,n,0,n);

  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }

  printf("\n");
  printf("%d\n",cnt);
  return 0;
}

void merge(int A[],int n,int left,int mid,int right){
  int n1,n2,i,j=0,k;
  n1=mid-left;
  n2 = right - mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  i=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]) A[k]=L[i++];
    else  A[k] = R[j++];
  }
}

void mergeSort(int A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"	
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e18;

void solve(){
	int n;
	cin>>n;
	vi a(n);
	unordered_map<int,int> mp;
	ll sum=0;
	rep(i,0,n){
		cin>>a[i];
		sum+=a[i];
		if(mp.find(a[i])==mp.end()){
			mp[a[i]]=0;
		}
		mp[a[i]]++;
	}
	int q;
	cin>>q;
	rep(i,0,q){
		int b,c;
		cin>>b>>c;
		if(mp.find(c)==mp.end()){
			mp[c]=0;
		}
		sum+=(c-b)*mp[b];
		mp[c]+=mp[b];
		mp[b]=0;
		cout<<sum<<ln;
	}
}

int main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 7492
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final FastIn in = new FastIn();
	private static final PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		Solver sol = new Solver();
		sol.solve();
		out.close();
	}
	private static final class Solver {
		public void solve() {
			int n = in.nextInt(), l = in.nextInt();
			String[] s = new String[n];
			for (int i = 0; i < n; ++i) s[i] = in.next();
			Arrays.sort(s);
			for (int i = 0; i < n; ++i)
				out.print(s[i]);
			out.println();
		}
	}
	private static final class FastIn {
		private BufferedReader br;
		private StringTokenizer st;
		public FastIn() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
			st = null;
		}
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 34896
'use strict';
(function(input){
  input=input.trim().split(/\n+/);
  input=input.map((str,i)=>str.split(/\s+/).concat(i));
  input.shift();
  input.sort(function(a,b){
    if([a[0],b[0]].sort()[0]===a[0]){
      if(a[0]!==b[0])
        return -1;
      else
        return -(a[1]-b[1])
    }else return +1;
  });
  console.log(input.map(a=>a[2]).join('\n').trim());
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 11468
abs = []
for i in range(3):
  a, b = map(int, input().split())
  abs.append(a)
  abs.append(b)

ok = True
for i in [1,2,3,4]:
  icnt = abs.count(i)
  if icnt == 0 or icnt > 2:
    ok = False

if ok:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e4 + 5, mod = 1e9 + 7;

int fact[N], inv[N];

int mul(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return 1ll * a * b % mod;
}

int fp(int b, int p){
    if(!p) return 1;
    int ret = fp(b, p >> 1);
    ret = mul(ret, ret);
    if(p&1) ret = mul(ret, b);
    return ret;
}

void pre(){
    fact[0] = inv[0] = 1;
    for(int i = 1; i < N; i++){
        fact[i] = mul(fact[i - 1], i);
        inv[i] = fp(fact[i], mod - 2);
    }
}

int ncr(int n, int r){
    int ret = mul(fact[n], inv[n - r]);
    return mul(ret, inv[r]);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pre();
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        int kam = k - i;
        int tmp = n - k - i + 1;
        if(tmp < 0){
            cout << 0 << '\n';
            continue;
        }
        cout << mul(ncr(kam + i - 1, kam), ncr(tmp + i, i)) << '\n';
    }

    return 0;

}


Measured memory_bytes: 640