akhauriyash/Code-Regression huggingface dataset:
def solve(A, B, C, X, Y):
    if A + B < C*2:
        return A * X + B * Y

    paid = 0
    if A > C * 2:
        #print("A > 2C")
        # A を買うより、C を 2 枚かったほうがお得
        paid += X * 2 * C
        Y -= X
        X = 0
    
    if Y > 0:
        if B > C * 2:
            #print("B > 2C", Y)
            paid += Y * 2 * C
            X -= Y
            Y = 0
        
    if X <= 0 and Y <= 0:
        return paid

    Z = min(X, Y)
    paid += Z * 2 * C
    X -= Z
    Y -= Z

    if X > 0:
        paid += X * A
    if Y > 0:
        paid += Y * B

    return paid

    



A, B, C, X, Y = [int(x) for x in input().split()]
# X : required of A
# Y : required of B
# A, B, C <= 10^5
print(solve(A, B, C, X, Y))


Measured memory_bytes: 3064
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let a: Vec<usize> = vec(n, |_| scan(tokens));
    let mut m1: usize = 0;
    let mut m2: usize = 0;
    for &ai in &a {
        if ai > m1 {
            m2 = m1;
            m1 = ai;
        } else if ai > m2 {
            m2 = ai;
        }
    }
    for &ai in &a {
        if ai == m1 {
            println!("{}", m2);
        } else {
            println!("{}", m1);
        }
    }
}


Measured memory_bytes: 9724
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int x = parseInt(sc.next());
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println((x-a)%b);
	}
}


Measured memory_bytes: 22484
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string name1;
    string name2;
    int sum =0;
    
    cin >> name1 >>name2;
    //cout << name1 << name2;
    
    if(name1.length()+1 != name2.length()){
        cout <<"No\n";
    }else{
        for(int i = 0;i<name1.length();i++){
            if(name1[i] != name2[i]){
                cout <<"No\n";
                break;
            }else{
                sum+=1;
            }
        }
        
    }
    if(sum == name1.length()){
        cout << "Yes\n";
    }
    
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) erase(x.begin(), x.begin+n)
// #define int long long
#define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;

signed main(void) {
  	int r;
  	cin >> r;
  	cout << 3*r*r << endl;
 	
	return 0;
}


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

a.sort()
output = 0
tmp = a[-1] // 2 if a[-1] % 2 == 0 else a[-1] // 2 + 1

for i in a[0:n:]:
    if abs(tmp - i) < abs(tmp - output):
        output = i

print(a[-1], output)


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

int main() {
  vector<char> moji(3);
  for (int i = 0; i < 3; i++) {
    cin >> moji.at(i);
  }
  
  if (moji.at(1) == 'B') {
    moji.at(1) = 'R';
  }
  else {
    moji.at(1) = 'B';
  }
  
  for (int i = 0; i < 3; i++) {
    cout << moji.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 3596
#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;
typedef pair<int, int> pii;
#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));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int f[100010];
	int N, M;
	cin >> N >> M;
	f[0] = 1;
	int rui = 1;
	eFOR(i, 1, N + 1) {
		f[i] = rui;
		rui += f[i];
		if (i - M >= 0)rui -= f[i - M];
		rui %= mod;
	}
	int ans = 1;
	REP(i, N) ans = ans * 2 % mod;
	ans -= f[N + 1];
	ans %= mod;
	if (ans < 0)ans += mod;
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 3988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws IOException {

		// --- input ---
		int val = toInt(in.readLine());
		int[][] data = new int[val][];
		for(int i=0; i < val; i++) {
			data[i] = toIntAry(in.readLine().split(" "));
		}

		// --- resolv ---
		int[] cur = {0, 0, 0};
		int[] mv = new int[3];
		for(int[] next : data) {

			for(int i=0; i < 3; i++) {
				mv[i] = Math.abs(next[i] - cur[i]);
			}

			if(mv[0] < (mv[1] + mv[2]) || mv[0] % 2 != (mv[1] + mv[2]) % 2) {
				System.out.println("No");
				return;
			}

			// current
			cur = next;
		}

		System.out.println("Yes");
	}

	public static int toInt(String val) {
		return Integer.parseInt(val);
	}

	public static int[] toIntAry(String[] vals) {
		int[] vAry = new int[vals.length];
		for(int i=0; i < vals.length; i++) {
			vAry[i] = toInt(vals[i]);
		}
		return vAry;
	}
}

Measured memory_bytes: 45164
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n = 0, x, y, sum = 0; cin >> x >> y;
	sum = x;
	while (sum <= y) {
		sum = sum * 2; n++;
	}
	cout << n << endl;
	cin >> n;
}

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

int cmp(const void*a,const void*b){
	return *(int*)a-*(int*)b;
}
int anokazu[100001]={};
int main(void){
	int N;
	int ans = 0;
	scanf("%d",&N);
	int i,j,temp;
	for(i=0;i<N;i++){
		scanf("%d",&temp);
		anokazu[temp]++;
	}
	for(i=1;i<=100000;i++){
		temp = 0;
		temp += anokazu[i-1];
		temp += anokazu[i];
		temp += anokazu[i+1];
		if(ans<temp)ans=temp;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
var lines = []; var result = 0;

var readline = require("readline");

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var N_array = N.toString().split("");

    var len = N_array.length; var f = 0;

    for (var i = 0; i < len; i++) {
        f += Number(N_array[i]);
    }
    N % f === 0 ? console.log("Yes") : console.log("No");
});

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

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  for (int &i : p) {
    cin >> i;
    i--;
  }
  for (int &i : c) cin >> i;
	
  ll ans = -1e+18;
  for (int i = 0; i < n; i++) {
    int x = i;
    vector<ll> s;
    ll res = 0;
    while (1) {
      x = p[x];
      res += c[x];
      s.push_back(res);
      if (x == i) break;
    }
		
    int sz = s.size();
    for (int j = 0; j < sz; j++) {
      if (j + 1 > k) break;
      ans = max(ans, s[j] + (res > 0 ? (k - j - 1) / sz * res : 0));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1000000000000000;
const int MAX = 1000100;
vector<pair<ll,ll>> G[MAX];//�i�s����,cost�j
ll d[MAX];
priority_queue<P,vector<P>,greater<P>> que;//(�����A�ʒu)
void dijkstra(int s){
	for(int i=0;i<MAX;i++){
		d[i] = INF;
	}
	que.push({0,s});
	while(!que.empty()){
		P p = que.top();
		que.pop();
		ll x = p.second;
		if(d[x]!=INF) continue;
		d[x] = p.first;
		for(P e: G[x]){
			que.push({d[x]+e.second,e.first});
		}
	}
}

int main(){
	int i,x,y,z,n,m,s,t;
	cin >> x >> y >> z >> n >> m >> s >> t;
	s--; t--;
	for(i=0;i<n;i++){
		int a,b; cin >> a >> b;
		a--; b--;
		G[n + m + a].push_back({i,1});
		G[n + m + x + b].push_back({i,1});
		G[i].push_back({n + m + a,1});
		G[i].push_back({n + m + x + b,1});
	}
	for(i=0;i<m;i++){
		int c,d; cin >> c >> d;
		c--; d--;
		G[n + m + x + c].push_back({n + i,1});
		G[n + i].push_back({n + m + x + c,1});
		G[n + m + x + y + d].push_back({n + i,1});
		G[n + i].push_back({n + m + x + y + d,1});
	}
	dijkstra(s);
	if(d[n + t]!=INF){
		cout << d[n + t]/2 << endl;
	}else{
		cout << -1 << endl;
	}
}
		


Measured memory_bytes: 61224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstDeif = new List<int>();
            for (int i = 0; i < sS.Length - 2; i++)
            {
                lstDeif.Add(Math.Abs(753 - int.Parse(sS.Substring(i, 3))));
            }
            lstDeif.Sort();

            // 出力
            System.Console.WriteLine("{0}", lstDeif[0].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W, -1));
    char c;
    queue<int> q1, q2, q3;
    rep(i, H) rep(j, W) {
        cin >> c;
        if (c == '#') {
            q1.push(i);
            q2.push(j);
            q3.push(0);
            A[i][j] = 0;
        }
    }
    int ans = 0;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    while (!q1.empty()) {
        int i = q1.front();
        q1.pop();
        int j = q2.front();
        q2.pop();
        int k = q3.front();
        q3.pop();
        rep(l, 4){
            int x = dx[l];
            int y = dy[l];
            int ni = i + x;
            int nj = j + y;
            if (ni < 0 || nj < 0 || ni >=H || nj >= W) continue;
            if (A[ni][nj] >= 0) continue;
            ans = max(ans, k + 1);
            A[ni][nj] = k + 1;
            q1.push(ni);
            q2.push(nj);
            q3.push(k + 1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 16512
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[2000000], ans, dp[10000000],a[2000000], b[2000000];
string str;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> str;
	cin >> n;
	rep(i,str.size()) {
		if (cnt%n == 0) {
			cout << str[i];
		}
		cnt++;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
from heapq import heapify, heappushpop

N, *A = map(int, open(0).read().split())

L, C, R = A[:N], A[N:2 * N], A[2 * N:]

F = [sum(L)]
heapify(L)
for c in C:
    F.append(F[-1] + c - heappushpop(L, c))

R = [-r for r in R]
B = [sum(R)]
heapify(R)
for c in reversed(C):
    B.append(B[-1] - c - heappushpop(R, -c))

print(max(f + b for f, b in zip(F, reversed(B))))

Measured memory_bytes: 36308
#include<stdio.h>

int main(void) {
  int i,j,n,m,N;
  
  scanf("%d",&N);
  n = 0;
  
  for(i=1; i<=N; i+=2) {
    m = 0;
    for(j=1; j<=i; j+=2) {
      if(i%j==0) 
        m++;
    }
    if(m==8)
      n +=1;
  }
  
  printf("%d\n",n);
  return(0);
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * 2963.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);

  for (int j = 1; j < a; j++) {
    ll bj = (ll)b * j;
    if (bj % a == 0) break;

    int i = (bj + a - 1) / a;
    ll ai = (ll)a * i;
    if (i < j + (ai - bj)) {
      printf("%lld\n", ai);
      return 0;
    }
  }

  puts("-1");
  return 0;
}



Measured memory_bytes: 3228
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut s: Vec<char> = Vec::with_capacity(n);
    for c in iterator.next().unwrap().chars() {
        s.push(c);
    }

    let mut ans = 0;
    for i in 1..n {
        if s[i] == 'E' {
            ans += 1;
        }
    }

    let mut prev = ans;
    for i in 1..n {
        let mut a = prev;
        if s[i] == 'E' {
            a -= 1;
        }
        if s[i - 1] == 'W' {
            a += 1;
        }
        ans = min(ans, a);
        prev = a;
    }

    return ans.to_string();
}


Measured memory_bytes: 6396
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int n,m;
	cin >> n;
	m = n;
	int a[3];
	int ans;
	rep(i, 3) {
		a[i] = n % 10;
		n/=10;
	}
	if (a[2] < a[0] || a[2] < a[1])ans = a[2] + 1;
	else ans = a[2];
	cout << ans*111;
	ed;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while i <= (n-1):
    if i == n-1:
        if a[i] == i+1:
            count += 1
            print(count)
            exit()
        else:
            break
    if a[i] == i+1 and a[i+1] == i+2:
        count += 1
        i += 2
    elif a[i] == i+1:
        count += 1
        i += 1
    else:
        i += 1

print(count)



Measured memory_bytes: 14008
using System;
using System.Collections.Generic;

namespace atcoder
{
    class Program
    { 
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            if (S[0] == S[1] && S[1] == S[2])
            {
                Console.WriteLine("No");
            }
            else Console.WriteLine("Yes");

        }
    }
}

Measured memory_bytes: 13140
while True:
	try:
		N, K, Q = map(int, input().split())
		P = [K for i in range(N)]
		dic = {i: K for i in range(1, N+1)}
		for i in range(Q):
			q = int(input())
			dic[q] += 1
			#print(dic)
		for k, v in dic.items():
			if (v-Q > 0):
				print("Yes")
			else:
				print("No")
	except:
		break			

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

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

    int cnt = 0;

    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if(i%2)
            if(x%2) cnt++;
    }

    cout << cnt;

    return 0;
}


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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	cin >> s;

	int n = s.size();

	int m = n;
	rep(i,n-1){
		if(s[i] != s[i+1]) m = min(m, max(i+1,n-(i+1)));
	}

	cout << m << endl;
}

Measured memory_bytes: 512
N ,M = (int(x) for x in input().split())
L = 0
R = N
for i in range(M):
    L_in ,R_in = (int(x) for x in input().split())
    if L < L_in:
        L = L_in
    if R > R_in:
        R = R_in

if R - L >= 0:
    print(R - L + 1)
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
std::mt19937 mt{std::random_device{}()};
template <typename S, typename T>
std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return (os << "<" << p.first << "," << p.second << ">"); }
template <typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v)
{
    os << "[";
    for (const auto& p : v) { os << p << ","; }
    return (os << "]\n");
}
template <typename T, typename C, typename A>
std::ostream& operator<<(std::ostream& os, const std::set<T, C, A>& s)
{
    os << "{";
    for (const auto& p : s) { os << p << ","; }
    return (os << "}\n");
}

int main()
{
    int N, M;
    std::cin >> N >> M;
    using P = std::pair<int, int>;
    std::vector<std::vector<int>> u(N, std::vector<int>(M, N * M));
    std::vector<int> A(N), B(M);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
        for (int j = 0; j < M; j++) {
            u[i][j] = std::min(u[i][j], A[i]);
        }
    }
    for (int i = 0; i < M; i++) {
        std::cin >> B[i];
        for (int j = 0; j < N; j++) {
            u[j][i] = std::min(u[j][i], B[i]);
        }
    }
    std::vector<ll> num(N * M + 1, 0);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            num[u[i][j]]++;
        }
    }
    for (int i = N * M - 1; i >= 0; i--) { num[i] += num[i + 1]; }
    std::vector<std::set<P>> pos(N * M + 1);
    std::vector<bool> calced(N * M + 1, false);
    for (int i = 0; i < N; i++) {
        std::set<P> cand;
        for (int j = 0; j < M; j++) {
            if (u[i][j] >= A[i]) { cand.insert({i, j}); }
        }
        if (calced[A[i]]) {
            std::set<P> tmp;
            for (const auto& p : pos[A[i]]) {
                if (cand.find(p) != cand.end()) { tmp.insert(p); }
            }
            pos[A[i]] = tmp;
        } else {
            pos[A[i]] = cand;
        }
        calced[A[i]] = true;
    }
    for (int j = 0; j < M; j++) {
        std::set<P> cand;
        for (int i = 0; i < N; i++) {
            if (u[i][j] >= B[j]) { cand.insert({i, j}); }
        }
        if (calced[B[j]]) {
            std::set<P> tmp;
            for (const auto& p : pos[B[j]]) {
                if (cand.find(p) != cand.end()) { tmp.insert(p); }
            }
            pos[B[j]] = tmp;
        } else {
            pos[B[j]] = cand;
        }
        calced[B[j]] = true;
    }
//    show(pos);
    ll ans = 1;
    for (int v = N * M; v >= 1; v--) {
        if (not pos[v].empty()) {
            (ans *= pos[v].size()) %= MOD;
        } else {
            if (v == N * M) {
                ans = 0;
            } else {
                (ans *= num[v] - (N * M - v)) %= MOD;
            }
        }
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 90496
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;


/* range: ± 3.27 * 10^4 */
using i16 = short int;
/* range: 0 to 65535 */
using u16 = short unsigned int;
/* range: ± 2.14 * 10^9 */
using i32 = int;
/* range: 0 to 4.29 * 10^9 */
using u32 = unsigned int;
/* range: ± 9.22 * 10^18 */
using i64 = long long int;
/* range: 0 to 1.84 * 10^19 */
using u64 = long long unsigned int;

i32 main() {
    i32 n = 0;
    cin >> n;
    vector<double> prob_heads(n, 0.0);
    for (i32 i = 0; i < n; i++) {
        cin >> prob_heads[i];
    }

    vector<double> dp(n + 1, 0.0);
    dp[0] = 1;
    for (i32 coin = 0; coin < n; coin++) {
        for (i32 i = coin + 1; i > 0; i--) {
            dp[i] =
                dp[i - 1] * prob_heads[coin] + dp[i] * (1 - prob_heads[coin]);
        }
        dp[0] *= (1 - prob_heads[coin]);
    }

    double ans = 0.0;
    for (auto i = n / 2 + 1; i <= n; i++) {
        ans += dp[i];
    }

    cout << fixed << setprecision(10) << ans << '\n';
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
  return (x > y) ? y : x;
}
int gcd(int n1, int n2)
{
  if (n2 != 0) return gcd(n2, n1 % n2);
  else return n1;
}
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";}
int64 binpow(int64 a, int64 b, int64 m) {
  a %= m;
  int64 res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int main()
{ fast;
  int64 n;
  cin >> n;
  int64 arr[n];
  int64 count[n] = {0};
  for (int64 i = 0; i < n; i++)
  { cin >> arr[i];
    count[arr[i]]++;
  }
  int64 ret;
  if (n % 2 == 0)
    ret = 1;
  else
    ret = 0;
  for (int64 i = 0; i < n; i++)
  { if (ret == 0 && i % 2 != 0)
      continue;
    if (ret == 1 && i % 2 == 0)
      continue;
    if (i != 0 && count[i] != 2)
    { cout << "0";
      return 0;
    }
    if (i == 0)
    { if (count[i] > 1)
      { cout << "0";
        return 0;
      }
      if (count[i] == 1 && n % 2 == 0)
      { cout << "0";
        return 0;
      }
    }
  }
  int64 mod = 1e9 + 7;
  cout << binpow(2, n / 2, mod);
  return 0;

}



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

int main()
{
  int n,y;
  cin>>n>>y;
  
  int a=0,b=0,c=0;
  
  
  for(a=0;a<=n;a++)
  {
    for(b=0;b<=n-a;b++)
    {
      c=n-a-b;
      if(10000*a+5000*b+1000*c==y)
      {
        cout<<a<<" "<<b<<" "<<c<<endl;
        return 0;
      }
    }
  }
  
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<complex>
#define N 1000
typedef std::complex<double> point;
double InnerProd(point x,point y);
point Projection(point x,point y);
int main(){
        point ans,p1,p2;
        int q;
    double x1,x2,y1,y2;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        p1=point(x1,y1);
        p2=point(x2,y2);
        scanf("%d",&q);
        for(int i=0;i<q;i++){
                scanf("%lf%lf",&x1,&y1);
                ans=p1+Projection(point(x1,y1)-p1,p2-p1);
                printf("%.10f %.10f\n",ans.real(),ans.imag());
        }

        return 0;
}
double InnerProd(point x,point y){
        return ((std::conj(x)*y).real());
}

/*x??????y???????°???±*/
point Projection(point x,point y){
        return (y*InnerProd(x,y)/std::norm(y));
}

Measured memory_bytes: 2820
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        int N = int.Parse(input);
        char[] line=Console.ReadLine().ToCharArray();
        int B = 0;
        int R = 0;
        for(int i = 0; i < N; i++)
        {
            if (line[i] == 'B') { B++; }
            else { R++; }
        }
        if (R > B) { Console.WriteLine("Yes"); }
        else { Console.WriteLine("No"); }
    }
}



Measured memory_bytes: 11092
primes = [i for i in range(10**5+1)]
primes[1] = 0 

for p in primes:
    if p > int(10**(5/2)): break
    if p == 0: continue
    for non_prime in range(2 * p, 10**5+1, p): primes[non_prime] = 0

    prime = [prime for prime in primes if prime != 0]
prime2 = set([2*i-1 for i in prime])
like2017 = sorted(list(set(prime) & prime2))

def inpl(): return [int(i) for i in input().split()]


H = [0 for i in range(10**5+2)]
for i in like2017:
    H[i] = 1
for i in range(10**5+1):
    H[i+1] += H[i] 

Q = int(input())
ans = []
for i in range(Q):
    l, r = inpl() 
    ans.append(H[r]-H[l-1])
for i in ans:
    print(i)

Measured memory_bytes: 12932
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
 
  int h, w;

  cin>>h>>w;

  for(int i=0;i<h;i++){
    int cnt;
    bool f=false;
    for(int j=0;j<w;j++){
      char c;
      cin>>c;
      if(c=='c'){
	f=true;
	cnt=0;
      }
      cout<<(j?" ":"");
      if(f) cout<<cnt++;
      else cout<<-1;
    }
    cout<<endl;
  }
   
  return 0;
}

Measured memory_bytes: 3092
n = gets.to_i
words = n.times.map{gets.chomp}
if words.count != words.uniq.count
  puts "No"
  exit 0
end

res = true
(words.count - 1).times do |count|
  if words[count][-1] != words[count + 1][0]
    puts "No"
    exit 0
  end
end

puts "Yes"

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ll K; cin >> K;
  ll i = 1;
  vector<bool> seen = vector<bool>(K, false);
  ll cur = 7%K;
  while(!seen[cur]){
    //cout << cur << endl;
    seen[cur] = true;
    if(cur == 0){
      cout << i << endl;
      exit(EXIT_SUCCESS);
    }
    i++;
    cur = (cur*10+7)%K;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3728
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int b, r, c, i, j, k, sum;
        sum = 0;
        r = scan.nextInt();
        c = scan.nextInt();
        int a[][] = new int[r + 1][c + 1];
        
        for(i = 0; i < r; i++){
            for(j = 0; j < c; j++){
                b = scan.nextInt();
                a[i][j] = b;
                sum += b;
        	}
            a[i][j] = sum;
            sum = 0;
        }
        for(j = 0; j < c + 1; j++){
            for(i = 0; i < r; i++){
                sum += a[i][j];
        	}
            a[i][j] = sum;
            sum = 0;
        }
        
        for(i = 0; i < r + 1; i++){
            for(j = 0; j < c + 1; j++){
                System.out.printf("%d", a[i][j]);
                if(j == c) break;
                System.out.printf(" ", a[i][j]);
        	}
            System.out.printf("\n");
        }
        scan.close();
    }
}



Measured memory_bytes: 57804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  bool ok = true;
  if(s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) ok = false;
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&self, mut x: usize) -> usize {
            while self.p[x] >= 0 {
                x = self.p[x] as usize;
            }
            x
        }
        pub fn same(&self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
            let mut x = self.root(x);
            let mut y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                std::mem::swap(&mut x, &mut y);
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn parent(&self, x: usize) -> Option<usize> {
            let p = self.p[x];
            if p >= 0 {
                Some(p as usize)
            } else {
                None
            }
        }
        pub fn get_size(&self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------

use proconio::*;
use proconio::marker::*;

fn run() {
    input! {
        n: usize,
        p: [(Usize1, Usize1); n],
    }
    let w = 100_000;
    let mut dp = vec![(0usize, 1usize); 2 * w];
    for p in dp.iter_mut().take(w) {
        *p = (1, 0);
    }
    let mut u = union_find::UF::new(2 * w);
    for (x, y) in p {
        if let Some((a, b)) = u.unite(x, y + w) {
            dp[a].0 += dp[b].0;
            dp[a].1 += dp[b].1;
        }
    }
    let mut ans = 0;
    for (i, p) in dp.iter().enumerate() {
        if i == u.root(i) {
            ans += p.0 * p.1;
        }
    }
    ans -= n;
//    let ans = dp.into_iter().map(|p| p.0 * p.1).sum::<usize>() - n;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8612
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

n = int(input())
s = input()

ans = 0

for i in range(n-2):
    if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
        ans += 1
print(ans)


Measured memory_bytes: 9092
package main
 
import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
)

func sum(i int) int {
    str := strconv.Itoa(i)
    
    sum := 0
    for i:=0; i< len(str); i++ {
        in, _ := strconv.Atoi(string(str[i]))
        sum+=in
    }
    return sum
}
 
func main(){
  sc := bufio.NewScanner(os.Stdin)
  sc.Scan()
  numsList := strings.Split(sc.Text(), " ")
  max, _ := strconv.Atoi(numsList[0])
  lower, _ := strconv.Atoi(numsList[1])
  upper, _ := strconv.Atoi(numsList[2])
  
  nums := make([]int, 0)
  for i:=1; i<=max; i++ {
    
    if sum(i)>=lower && upper>=sum(i) {
      nums = append(nums, i)
    }
  }

  sum := 0
  for _, n := range nums {
      sum+=n
  }
    
  fmt.Println(sum)
}

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

int main() {
  int N,A,s,t,u = 0;
  cin >> N;
  for (int i=0; i < N; i++) {
    cin >> A;
    if (A % 2)  {
      s = 0;
      break;
    } else {
      s = A;
      t = 0;
      while (s % 2 == 0 && s > 0) {
        t++;
        s /= 2;
      }
      if (u == 0) {
        u = t;
      } else if (u > t) {
        u = t;
      } 
    }
  }
  cout << u << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scr =new Scanner(System.in);
		
		int N = scr.nextInt();
		int K = scr.nextInt();
		int d = 0;
		int A;
		int result = 0;
		
		int []Ns = new int [N];
		
		for(int i = 0;i < K;i++) {
			d = scr.nextInt();
			for(int j = 0;j < d;j++) {
				A = scr.nextInt();
				Ns[A-1] = 1;
			}
		}
		
		for(int i = 0;i < N;i++) {
			if(Ns[i] == 0) {
				result += 1;
			}
		}
		
		System.out.println(result);
		
	}
}

Measured memory_bytes: 46400
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();



		System.out.println(a+a*a+a*a*a);
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 35656
while True:
  H, W = map(int, input().split())
  if H == 0 and W == 0:
    break
  print('#' * W)
  for i in range(1,H-1):
    print('#', end='')
    for j in range(1,W-1):
      print('.', end='')
    print('#')
  print('#' * W)
  print()


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

int main()
{
	int n;
	cin >> n;
	vector<ll> A(n);
	for(int i = 0;i<n;i++)cin >> A[i];
	vector<ll> ans(n);
	ll l = 0,r = A[0]*2+1;
	while(1)
	{
		int mid = (l+r)/2;
		if(mid%2==1)mid--;
		ans[0]=mid;
		for(int i = 1;i<n;i++)
		{
			ans[i] = 2*A[i-1]-ans[i-1];
		}
		int a = (ans.front()+ans.back())/2;
		if(a==A.back())break;
		ans[0]=mid+2;
		for(int i = 1;i<n;i++)
		{
			ans[i] = 2*A[i-1]-ans[i-1];
		}
		 a = (ans.front()+ans.back())/2;
		if(a==A.back())break;
		if(a<A.back())
		{
			l = mid;
		}
		else
		{
			r = mid;
		}
	}
	for(auto i:ans)cout<<i<<' ';cout<<endl;
	return 0;
}


Measured memory_bytes: 2944
// AOJ Volume 0 Problem 0045

#include <stdio.h>

int main(void)
{
    int price;
    int no;
    int sum_price;
	int sum_no;
	int no_data;
	int average;
	
    sum_no = sum_price = no_data = 0;
    
    while (scanf("%d,%d", &price, &no) != EOF){
		sum_price += (price * no);
		sum_no += no;
		no_data++;
    }

	average = ((float)sum_no / (float)no_data) + 0.5;

	printf("%d\n%.d\n", sum_price, average);
	
	return (0);
}

Measured memory_bytes: 0
from itertools import combinations_with_replacement as combi

N, M, Q = map(int, input().split())

a = [0] * 55
b = [0] * 55
c = [0] * 55
d = [0] * 55

for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

candidate = combi(range(1, M+1), N)

ans = 0

for A in candidate:
    score = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            score += d[i]

    ans = max(ans, score)

print(ans)

Measured memory_bytes: 9224
s = input().rstrip()
s1 = int(s[:2])
s2 = int(s[2:])
if 1 <= s1 <= 12:
    if 1 <= s2 <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= s2 <= 12:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 38384
N, M, X, Y = map(int, input().split())

cities_x = [int(x) for x in input().split()]
cities_y = [int(x) for x in input().split()]

max_x = max(X, max(cities_x))
min_y = min(Y, min(cities_y))

if min_y - max_x >= 1:
  print('No War')
else:
  print('War')


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

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

Measured memory_bytes: 3620
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit
# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))
    res = [0] * n
    xs = sum(a)
    res[0] = xs - 2 * (sum(a[1::2]))

    for i in range(1, n):
        res[i] = 2 * a[(i - 1) % n] - res[(i - 1) % n]

    print(*res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 60004
#include<iostream>
using namespace std;
int main()
{
  int a[200],b[200],c[200],d[200];
  int n,t;
  int k{1001};
  cin >> n >> t;
  for (int i=0;i<n;i++){
  cin >> a[i] >> b[i];
    
                  if(b[i]<=t && a[i]<k){
                    k=a[i];
                  }
   
    
                 }
  
  if ( k>=1001 ){
    cout <<"TLE"<<endl;
  }
  
    else {
      cout << k << endl;
    }
  
    
    
  
}

Measured memory_bytes: 256
S = input()

if 'R' in S:
    if S.count('R') == 1:
        print(1)
    elif S.count('R') == 3:
        print(3)
    else:
        if S[1] == 'R':
            print(2)
        else:
            print(1)
            
else:
    print(0)    


Measured memory_bytes: 61624
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string S; int Q, l[100009], r[100009], a[100009], b[100009], col[100009], cntw; bool used[100009], flag;
vector<pair<int, int>>D; vector<int>X[100009], V[100009];

int dfs(int pos) {
	int sum = 0; used[pos] = true;
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i]] == true) continue;
		sum += dfs(X[pos][i]); sum %= 26;
	}
	return (sum - b[pos] + 26) % 26;
}
void dfs2(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cntw; V[cntw].push_back(pos);
	for (int i = 0; i < X[pos].size(); i++) dfs2(X[pos][i]);
}

int main() {
	cin >> S;
	for (int i = 0; i < S.size() / 2; i++) { a[i + 1] = (S[i] - S[S.size() - i - 1]); if (a[i + 1] < 0)a[i + 1] += 26; }
	for (int i = 0; i < (S.size() / 2) + 1; i++) { b[i] = (a[i + 1] - a[i] + 26) % 26; }
	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> l[i] >> r[i]; l[i]--; r[i]--;
		if (l[i] + r[i] == S.size() - 1) continue;
		if (l[i] + r[i] >= S.size() - 1) {
			l[i] = S.size() - 1 - l[i];
			r[i] = S.size() - 1 - r[i];
			swap(l[i], r[i]);
		}
		int P1 = l[i], P2 = r[i];
		if (r[i] >= S.size() / 2) P2 = S.size() - 2 - r[i];
		D.push_back(make_pair(P1 + 1, P2 + 1));
	}
	for (int i = 0; i < D.size(); i++) {
		X[D[i].first - 1].push_back(D[i].second);
		X[D[i].second].push_back(D[i].first - 1);
	}
	for (int i = 0; i < (S.size() / 2) + 1; i++) {
		if (col[i] >= 1) continue;
		cntw++; dfs2(i);
	}
	for (int i = 1; i <= cntw; i++) {
		int U = dfs(V[i][0]);
		if (U != 0) flag = true;
	}
	if (flag == true) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

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

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

  sort(v.begin(), v.end());
  if (v[0] + v[1] == v[2]) {
    cout << "Yes" << endl;
  } else if (v[0] == v[1] + v[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#define EPS (1e-7)
using namespace std;


long long lcm(long long n, long long m) {
	long long r,x,tmp;
	x = m * n;
	/* 自然数 a > b を確認・入替 */
	if (n < m) {
		tmp = n;
		n = m;
		m = tmp;
	}

	/* ユークリッドの互除法 */
	r = n % m;
	while (r != 0) {
		n = m;
		m = r;
		r = n % m;
	}
	return x / m;

}



int main() {

	int N;
	cin >> N;
	vector<int> p(N);
	int ans=0;

	for (auto i = 0; i < N; i++)
	{
		cin >> p[i];
	}


	for (auto i = 0; i < N - 2; i++) {

		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2])
			|| (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) {
			ans += 1;
		}

	}



	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

typedef long long ll;

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

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

int main(){
	int n; scanf("%d", &n);
	ll res = 1;
	for(int i = 0; i < n; i++){
		ll t; scanf("%lld", &t);
		res = lcm(res, t);
	}
	printf("%lld\n", res);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

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

int n, p;
ll f[55][5], a[55];

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

Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
 if (A >= B && C >= D) {
   cout << B + D;
 }
 else if (A >= B && D >= C) {
   cout << B + C;
 }
  else if (B >= A && C >= D) {
   cout << A + D;
 }
  else if (B >= A && D >= C) {
   cout << A+ C;
 }
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	}

}

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

#define INF 1000000007LL
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define sz size()

int n;
string s[2];

int f(char c){
	if(c=='m')return 1000;
	if(c=='c')return 100;
	if(c=='x')return 10;
	return 1;
}

int main(){
	cin>>n;
	while(cin>>s[0]>>s[1]){
		int S[2]={},mul=1;
		rep(i,2)rep(j,s[i].sz){
			if(isdigit(s[i][j]))mul=s[i][j]-'0';
			else{
				S[i]+=mul*f(s[i][j]);
				mul=1;
			}
		}
		S[0]+=S[1];
		string t="mcxi";
		int u[]={1000,100,10,1};
		rep(i,4){
			int x=S[0]/u[i]%10;
			if(x>1)cout<<x;
			if(x>0)cout<<t[i];
		}
		cout<<endl;
	}
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin, (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int H, N;
  int sum = 0;
  int A;
  cin >> H >> N;
  rep(i, N) {
    cin >> A;
    sum += A;
  }
  if (sum >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
a = [i + 1 for i in range(k)]
b = [i + 1 for i in range(k)]
c = [i + 1 for i in range(k)]

for x in a:
    for y in b:
        for z in c:
            ans += gcd(x, y, z)

print(ans)

Measured memory_bytes: 69496