akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
        int N,a[100],i,j=0,k=0;
        scanf("%d",&N);

        for(i=0;i<N;i++)
           scanf("%d",&a[i]);
        for(i=0;i<N;i++){
           if(a[i]%2==0){
             j++;
           if((a[i]%3==0)||(a[i]%5==0))
             k++;
           }
        }

        if(j==k) printf("APPROVED\n");
        else     printf("DENIED\n");

        return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
t=list(ss())

cs=Counter(s)
ct=Counter(t)

ck=list(cs.values())
tk=list(ct.values())

ck.sort()
tk.sort()
if ck==tk:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 95432
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

flag = 0
count = 0

for i in range(N):
    if D[i][0] == D[i][1]:
        count += 1
    else:
        count = 0
    if count >= 3:
        flag = 1
        break

if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62400
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 100010
ll a[N];

ll inv[N], fact[N], ifact[N];
 
void init_fact(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n;i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

ll comb(ll a, ll b){
	return fact[a+b]*ifact[a]%mod*ifact[b]%mod;
}

int main(){
	init_fact();
	ll n;
	cin>>n;
	vector<ll> d(n+1);
	rep(i, n+1){
		cin>>d[i];
		a[d[i]]++;
	}
	ll l = INF, r = INF;
	rep(i, n+1){
		if(a[d[i]]==2){
			l = min(l, i);
			r = min(r, n-i);
		}
	}
	cerr<<l<<" "<<r<<endl;
	vector<ll> res(n+1);
	rep(i, n+1){
		if(i==0){
			res[i] = n;
			continue;
		}
		ll x = comb(i+1, n-i);
		if(l+r>=i) x -= comb(i, l+r-i);
		res[i] = x%mod;
		if(res[i]<0) res[i] += mod;
	}
	rep(i, n+1) cout<<res[i]<<endl;
	return 0;
}


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

int main() {
	string T, P;
	cin >> T >> P;
	if (T.size() >= P.size()) {
		for (int i = 0; i <= T.size() - P.size(); ++i) {
			int j;
			for (j = 0; j < P.size(); ++j) {
				if (T[i + j] != P[j]) break;
			}
			if (P.size() == j) cout << i << endl;
		}
	}
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
	
ll mod = 1e9 + 7;
vector<pair<ll, ll>> v(100001 + 1);
 
int main(){
    ll n, m; cin >> n >> m;
    v[1].second = 1;
    for(ll i = 2; i <= n; ++i){
        v[i].first = 1;
    }
    for(ll i = 0; i < m; ++i){
        ll x, y; cin >> x >> y;
        if(v[x].first > 0){
            v[x].first--;
            if(v[y].second == 0 && v[x].second == 1){
                v[y].second++;
            }else{
                v[y].first++;
            }
        }else{
            v[x].second--;
            if(v[y].second == 0){
                v[y].second++;
            }else{
                v[y].first++;
            }
        }
    }
    ll ans = 0;
    for(auto x:v){
        //cout << x.first << " " << x.second << endl;
        if(x.second == 1) ans++;
    }
    cout << ans;
    return 0;
}


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

template<class T> void chmax(T &a, const T &b) { if(a < b) a = b; }

constexpr int offset = 300;
int dp[101][301][901];

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

	int x, y;
	cin >> x >> y;

	memset(dp, -1, sizeof(dp));
	dp[0][x][y + offset] = 0;

	for(int i = 0; i < n; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		for(int j = 0; j <= 300; ++j) {
			for(int k = 0; k <= 900; ++k) {
				if(dp[i][j][k] == -1) continue;
//				cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << endl;

				chmax(dp[i + 1][j][k], dp[i][j][k]);
				if(j - a >= 0) {
					assert(k + b <= 900);
					chmax(dp[i + 1][j - a][k + b], dp[i][j][k]);
				}

				if(k - c >= 0) {
					chmax(dp[i + 1][j][k - c], dp[i][j][k] + d);
				}
			}
		}
	}

	int ans = 0;
	for(int i = 0; i <= 300; ++i) {
		for(int j = offset; j <= 900; ++j) {
			chmax(ans, dp[n][i][j]);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 110112
#include<stdio.h>

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

int main(){
    int n;
    scanf("%d", &n);
    int a[n], l[n], r[n];
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    l[1] = a[0];
    for(int i=2; i<n; i++){
        l[i] = gcd(l[i-1], a[i-1]);
    }
    r[n-2] = a[n-1];
    for(int i=n-3; i>=0; i--){
        r[i] = gcd(r[i+1], a[i+1]);
    }
    l[0] = r[0];
    r[n-1] = l[n-1];
    int max = 0;
    for(int i=0; i<n; i++){
        int buf = gcd(l[i], r[i]);
        if(buf > max){
            max = buf;
        }
    }
    printf("%d", max);

    return 0;
}

Measured memory_bytes: 1280
M, D = map(int, input().split(" "))

out = 0
for d in range(2, D+1):
    d10 = d // 10
    d1 = d % 10
    seki = d1 * d10
    if d1 >=2 and d10 >= 2 and 1 <= seki <= M:
        out += 1

print(out)

Measured memory_bytes: 3060
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    vector<int>antennas(5);
    int limitDistance;
    for (int i = 0; i < antennas.size(); i++) cin >> antennas.at(i);
    cin >> limitDistance;
    
    bool existsUnCommunicatedAntenna = false;
    for ( int i = 0; i < antennas.size() && !existsUnCommunicatedAntenna; i++ ) {
        for ( int j = 0; j < antennas.size() && !existsUnCommunicatedAntenna; j++ ) {
            if ( i == j ) continue;
            int distance = abs(antennas.at(i) - antennas.at(j));
            if (distance > limitDistance) {
                existsUnCommunicatedAntenna = true;
            }
        }
    }
    if (existsUnCommunicatedAntenna) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
use std::env;
use std::io::prelude::*;
use std::io;
use std::fs::File;
use std::str::FromStr;
use std::io::BufReader;
fn buf_read() -> io::Result<(Vec<String>)> {
    let args: Vec<_> = env::args().collect();
    if args.len() >= 2 {
        let f = try!(File::open("input.txt"));
        let input_lines: Vec<_> = BufReader::new(f).lines().collect();
        let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
        Ok((lines))
    } else {
        let stdin = io::stdin();
        let input_lines: Vec<_> = stdin.lock().lines().collect();
        let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
        Ok((lines))
    }
}

fn main() {
    type Element = String;
    let input = buf_read().unwrap();
    let mut input_vectors: Vec<Vec<Element>> = vec![];
    for input_line in input {
        let input_str: Vec<String> = input_line.split(' ').map(String::from).collect();
        let mut input_vector: Vec<Element> = vec![];
        for input_elem_str in input_str {
            let elem: Element = Element::from_str(input_elem_str.as_str()).unwrap();
            input_vector.push(elem);
        }
        input_vectors.push(input_vector);
    }
    let stones = input_vectors[0][0].chars();
    let mut previous_stone = input_vectors[0][0].chars().next().unwrap();
    let mut sum = 0;
    for stone in stones {
        if previous_stone != stone {
            sum += 1
        };
        previous_stone = stone;
    }
    println!("{}", sum);
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
	int a = 1, b;
	while (true) {
		std::cin >> b;
		if (b == 0)break;
		if (a > 10000) {
			std::cout << "Too Large" << std::endl;
			break;
		}
		std::cout << "Case " << a << ": " << b << std::endl;
		a++;
	}
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long int N;
    cin >> N;
    vector <int> A;
    A.push_back(0);
    int temp;
    for(int i = 0; i < N; ++i) {
        cin >> temp;
        A.push_back(temp);
    }
    A.push_back(0);
    long long int ans = 0;
    for(int i = 0; i < N + 1; ++i) {
        ans += abs(A[i + 1] - A[i]);
    }
    for(int i = 1; i < N + 1; ++i) {
        cout << ans + abs(A[i + 1] - A[i - 1]) - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) << endl;
    }
}

Measured memory_bytes: 1784
s = gets.to_i

result = 1
counts = {}
(1..s).each.with_index(1) do |s ,i|
  count = 0
  while s.even? do
    s = s / 2
    count += 1
  end
  counts[i] = count
  result = i if counts[i] > counts[result]
end

p result

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

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

    if(a == 'H' && b == 'D')    cout << "D" << endl;
    if(a == 'H' && b == 'H')    cout << "H" << endl;
    if(a == 'D' && b == 'D')    cout << "H" << endl;
    if(a == 'D' && b == 'H')    cout << "D" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

// ABC 64-D
// https://beta.atcoder.jp/contests/abc064/tasks/abc064_d

public class Main {

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

		long A = in.nextInt();
		long B = in.nextInt();
		long C = in.nextInt();
		long X = in.nextInt();
		long Y = in.nextInt();
		
		long a = A * X + B * Y;
		long b = Math.min(X, Y) * 2 * C + (X - Math.min(X, Y)) * A + (Y - Math.min(X, Y)) * B;
		long c = Math.max(X, Y) * 2 * C;
		
		System.out.println(Math.min(Math.min(a, b), c));
	}
}


Measured memory_bytes: 21972
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int K = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node(i);
    for (int i = 0; i < M; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      nodes[a].adjacent.add(nodes[b]);
      nodes[b].adjacent.add(nodes[a]);
    }
    int[][] block = new int[K][2];
    for (int i = 0; i < K; i++) {
      block[i][0] = scanner.nextInt() - 1;
      block[i][1] = scanner.nextInt() - 1;
    }

    int[] group = new int[N];
    Arrays.fill(group, -1);
    int gid = 0;
    for (int i = 0; i < N; i++) {
      if (group[i] < 0) {
        dfs(nodes[i], group, gid);
        gid++;
      }
    }
    int[] gsize = new int[gid];
    for (int i = 0; i < N; i++) {
      gsize[group[i]]++;
    }
    int[] res = new int[N];
    for (int i = 0; i < N; i++) {
      res[i] = gsize[group[i]] - nodes[i].adjacent.size() - 1;
    }
    for (int i = 0; i < K; i++) {
      int c = block[i][0];
      int d = block[i][1];
      if (group[c] == group[d]) {
        res[c]--;
        res[d]--;
      }
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(res[i]).append(' ');
    }
    sb.setLength(sb.length() - 1);
    System.out.println(sb.toString());
  }

  private static void dfs(Node node, int[] group, int gid) {
    group[node.id] = gid;
    for (Node n : node.adjacent) {
      if (group[n.id] < 0) dfs(n, group, gid);
    }
  }

  private static class Node {
    private final int id;
    private final List<Node> adjacent = new ArrayList<>();

    private Node(int id) {
      this.id = id;
    }
  }
}


Measured memory_bytes: 130228
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
A = iln()

cnt = collections.Counter(A)

for i in range(1,N+1):
    print(cnt[i])

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

signed main(void)
{
	int c[3][3];
	int a0, a1, a2, b0, b1, b2;
	bool ok;

	rep(i, 3) rep(j, 3) cin >> c[i][j];
	ok = true;
	rep(i, c[0][0])
	{
		a0 = i;
		b0 = c[0][0] - i;
		b1 = c[0][1] - i;
		b2 = c[0][2] - i;
		a1 = c[1][0] - b0;
		a2 = c[2][0] - b0;
		if (a1 + b1 != c[1][1])
			ok = false;
		if (a1 + b2 != c[1][2])
			ok = false;
		if (a2 + b1 != c[2][1])
			ok = false;
		if (a2 + b2 != c[2][2])
			ok = false;
		if (ok)
			break;
	}
	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

typedef long long LL;
const int M=2e5+5;
int h[M],a[M];

LL bit[M];
inline int lowbit(int x)
{
	return x&(-x);
}
void upd(int p,LL v)
{
	for(;p<M;p+=lowbit(p))
		bit[p]=max(bit[p],v);
}
LL getmx(int p)
{
	LL mx=0;
	for(;p;p-=lowbit(p))
		mx=max(mx,bit[p]);
	return mx;
}

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		int id=h[i];
		LL dp=getmx(id-1)+a[i];
		ans=max(ans,dp);
		upd(id,dp);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	ll i, j, num, x, m, ans, a = 0, b = 0, k = 0;
	cin >> num >> x >> m;
	if (m == 1) {
		printf("0\n");
		return 0;
	}
	vector<ll> d(m, 0), s(m, 0);
	rep(i, num) {
		k++;
		a += x;
		if (d[x]) {
			k -= s[x];
			b = a - d[x];
			a = d[x];
			int c = (num - s[x]) % k;
			k = (num - s[x]) / k;
			rep(j, c) {
				x *= x;
				x %= m;
				a += x;
			}
			break;
		}
		d[x] = a;
		s[x] = k;
		x *= x;
		x %= m;
	}
	if (i == num)
		ans = a;
	else
		ans = a + b * k;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4824
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.14159265358979323846265
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
int A[100100],N;
int main()
{
	cin>>N;
	int cnt=1;
	for(int i=0;i<N;i++)
		cin>>A[i];
	vector<int> xt;
	xt.push_back(A[0]);
	for(int i=1;i<N;i++)
	{
		int pos=lower_bound(xt.begin(),xt.end(),A[i])-xt.begin();
		int sz=xt.size();
		if(pos==0)
		{
			cnt++;
			xt.insert(xt.begin(),A[i]);
		}
		else
			xt[pos-1]=A[i];
	}
	cout<<cnt<<endl;
	return 0;
}

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

const int maxn = (int) 4e5 + 5;
const int inf = 1e9;

int n, m, root;
vector<int> G[maxn];
int d[maxn], p[maxn];
int a[maxn];
int dp[maxn];

void dfs(int u) {
    if(G[u].size() == 0) {
        if(a[u] == -1) {
            dp[u] = 1;
            return ;
        }
        else if(a[u] == 0) dp[u] = maxn;
        else dp[u] = 0;
        return ;
    }
    int x = G[u][0];
    int y = G[u][1];
    int z = G[u][2];
    dfs(x);
    dfs(y);
    dfs(z);

    dp[u] = maxn;
    dp[u] = min(dp[u], dp[x] + dp[y]);
    dp[u] = min(dp[u], dp[y] + dp[z]);
    dp[u] = min(dp[u], dp[z] + dp[x]);
}

bool check(int x) {
    int cnt = 0;
    for (int i = 1; i <= n; i ++) a[i] = -1;
    for (int i = 1; i <= m; i ++) {
        a[p[i]] = (d[i] >= x);
    }
    for (int i = m + 1; i <= n; i ++) {
        cnt += (d[i] >= x);
    }
    dfs(root);
    if(dp[root] <= cnt) return 1;
    else return 0;
}



int main() {
    ///freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i ++) {
        cin >> d[i] >> p[i];
    }
    for (int i = m + 1; i <= n; i ++) {
        cin >> d[i];
    }
    queue <int> Q;
    deque<int> dq;
    for (int i = 1; i <= n; i ++) Q.push(i);
    root = n;
    while(Q.size() > 1){
        root++;
        for(int i = 1 ; i <= 3 ; i++){
            int u = Q.front() ; G[root].push_back(u) ; Q.pop();
        }
        Q.push(root);
    }
    int lo = 0;
    int hi = (int) 1e9 + 7;
    int res;
    while (lo <= hi) {
        int mid = (lo + hi) >> 1;
        if(check(mid)) {
            res =  mid;
            lo = mid + 1;
        }
        else {
            hi = mid - 1;
        }
    }
    ///for (int i = 0; i < G[8].size(); i ++) cout << G[8][i] << ' ';
    ///cout << endl;
    ///cout << check() << endl;
    cout << res << endl;
}

Measured memory_bytes: 17388
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;

typedef pair<int,int> P;
// 0 除算があったかどうか
bool flag = false;

// string -> int
int s_to_i(string s){
	int n = 0;
	for(int i=0 ; i < s.size() ; i++ ){
		n *= 10;
		n += s[i] - '0';
	}
	return n;
}

// int -> string
string i_to_s(int n){
	string s;
	do{
		s.push_back( (n%10) + '0' );
		n /= 10;
	}while(n!=0);
	reverse(s.begin(),s.end());
	return s;
}

// 演算子かどうか返す.
bool is_op(const string& s){
	return ( s == "+" || s == "-" || s == "*" || s == "/" );
}

// 数値かどうか返す.
bool is_number(const string& s){
	return ( '0' <= s[0] && s[0] <= '9' );
}

// a op b の結果を返す. 0除算があったらフラグをたてる.
int op(int a, int b, char op){
	int r;
	// 0 除算のとき
	if( b == 0 && op == '/' ){
		flag = true;
		return 0;
	}
	// 演算結果を返す
	if( op == '+' ){
		r = ( a + b ) % 256;
	}else if( op == '-' ){
		r = ( a - b + 256 ) % 256;
	}else if( op == '*' ){
		r = ( a * b ) % 256;
	}else if( op == '/' ){
		r = ( a / b ) % 256;
	}
	
	return r;
}

int main(){
	int m, n;
	map<string,P> value;
	stack< set<int> > st;
	
	cin >> m;
	for(int i = 0 ; i < m ; i++ ){
		string name;
		int lb, ub;
		cin >> name >> lb >> ub;
		value[name] = P(lb,ub);
	}
	
	cin >> n;
	vector<string> e(n);
	for(int i = 0 ; i < n ; i++ ){
		cin >> e[i];
	}
	for(int i = 0 ; i < n ; i++ ){
		// 0 除算があるとき
		if( flag ){
			break;
		}
		if( is_number(e[i]) ){ // e[i] が数値のとき
			set<int> s;
			s.insert(s_to_i(e[i]));
			st.push(s);
		}else if( is_op(e[i]) ){ // e[i] が演算子のとき
			set<int> b = st.top();
			st.pop();
			set<int> a = st.top();
			st.pop();
			
			set<int> next;
			
			// 数値の候補をすべて計算する (数値は[0,255])
			for(set<int>::iterator x = b.begin() ; x != b.end() ; ++x ){
				for(set<int>::iterator y = a.begin() ; y != a.end() ; ++y ){
					int r = op( *y, *x , e[i][0] );
					next.insert(r);
				}
			}
			st.push(next);
			
		}else{ // e[i] が変数のとき
			int l = value[e[i]].first;
			int r = value[e[i]].second;
			set<int> next;
			
			// {l, l+1, ... , r } をスタックに入れる
			for(int i = l ; i <= r ; i++ ){
				next.insert(i);
			}
			st.push(next);
		}
	}
	// 解の出力
	if( !flag ){
		cout << "correct" << endl;
	}else{
		cout << "error" << endl;
	}	
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num, ll m) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1, m)%m;
  ll p = fastpow(nodess, num / 2, m);
  p %= m;
  p *= p;
  p %= m;
  return p;
}
 
ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
/*long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}*/
long long getDist(pair<ll, ll> &u, pair<ll, ll> &v) {
  return 
     (u.f - v.f)*(u.f - v.f)  + (u.se - v.se)*(u.se-v.se);
}
 
 
 
/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/

#define int ll
const int MX = 1e3 +9;

int32_t main(){
    IO;
	ll n, a,b;
	cin>>n>>a>>b;
	int x = (n)/(a+b);
	
	cout<<x * a + min(n%(a+b), a);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  string s;
  int nq;
  cin >> s >> nq;
  string l = "", r = "";
  bool flg = 0;
  int cnt = 0;
  rep(i, nq) {
    int t;
    cin >> t;
    if(t == 1) {
      flg ^= 1;
    }
    if(t == 2) {
      int f;
      char c;
      cin >> f >> c;

      if(flg ^ (f % 2))
        l = c + l;
      else
        r = r + c;
    }
  }
  s = l + s;
  s = s + r;
  if(flg) reverse(all(s));
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 1392
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int n,A,B;

int main(){
    cin>>n;

    if(n==1){
        cout<<"Hello World"<<endl;
    }else{
        cin>>A>>B;
        cout<<A+B<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch FizzBuzzSum | diff FizzBuzzSum.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address FizzBuzzSum.cpp && ./a.out

/*
 
 4/12/2020
 
 5:02-
 
 */

LL N;

LL f(LL n) {
  return (n+1)*n/2;
}
void solve() {
  LL res=f(N);
  res-=f(N/3)*3;
  res-=f(N/5)*5;
  res+=f(N/15)*15;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  solve();
  
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

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

    int counter = 1;
    while(counter < n){
        counter *= 2;
    }

    if(counter == 1){
        std::cout << 1;
        return 0;
    }
    else if(counter == n){
        std::cout << counter;
        return 0;
    }
    else{
        std::cout << counter/2;
        return 0;
    }

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    X = input()
    # print(X)

    L = deque([])
    R = deque(list(X))
    # for _ in range(100):
    while R:
        if not L:
            L.append(R.popleft())
            continue

        pre = L.pop()
        now = R.popleft()
        if pre == 'S' and now == 'T':
            pass
        else:
            L.append(pre)
            L.append(now)
    print(len(L))


if __name__ == '__main__':
    solve()



Measured memory_bytes: 12344
{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n,m] <- parseLine <$> BS.getLine
  xs <- replicateM m (toTuple.parseLine <$> BS.getLine)
  BS.putStrLn . BS.pack . show $ solve n xs
  where
     parseLine = unfoldr (BS.readInt . BS.dropWhile isSpace)

toTuple :: [Int] -> (Int, Int)
toTuple (x:y:_) = (x, y)

solve :: Int -> [(Int,Int)] -> Int
solve n xs = case conds of
  Nothing -> -1
  Just cs -> generate n cs
  where
    conds = foldM (process n) [] xs

process :: Int -> [(Int,Int)] -> (Int,Int) -> Maybe [(Int, Int)]
process n acc (s, c) = case lookup s acc of
  Just c' -> if c /= c'
    then Nothing
    else Just acc
  Nothing -> if and [(n/=1), (s==1), (c==0)]
    then Nothing
    else Just ((s,c):acc)

generate :: Int -> [(Int,Int)] -> Int
generate n xs = read . concat . map (show . genDigit) $ [1..n]
  where
    genDigit d = if (n/=1) && (d==1)
      then fromMaybe 1 (lookup 1 xs)
      else fromMaybe 0 (lookup d xs)

Measured memory_bytes: 380
#include<stdio.h>

int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b){
		printf("%d",c);
	}
	else{
		if(a==c){
			printf("%d",b);
		}
		else{
			printf("%d",a);
		}
	}
	return 0;
}


Measured memory_bytes: 128
import queue

n = int(input())
G = [[] for i in range(n)]
vp = [() for i in range(n - 1)]

for i in range(n - 1):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        G[a].append(b)
        G[b].append(a)
        vp[i] = (a, b)

que = queue.Queue()
que.put(0)
used = [0] * n
used[0] = 1
K = 0
cs = [0] * n
dic = {}
while not que.empty():
        v = que.get()
        if len(G[v]) > K:
                K = len(G[v])
        col = 1
        for u in G[v]:
                if used[u]:
                        continue
                if col == cs[v]:
                        col += 1
                cs[u] = col
                dic[(u, v)] = col
                dic[(v, u)] = col
                col += 1
                used[u] = 1
                que.put(u)
print(K)
for i in vp:
        print(dic[i])

Measured memory_bytes: 60496
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
to = defaultdict(list)
V = 100005
X = []
for i in range(N):
	x, y = rl()
	X.append(x)
	y += V
	to[x].append(y)
	to[y].append(x)

visited = set()
nx, ny = 0, 0
def dfs(n):
	global nx, ny
	if n in visited: return
	visited.add(n)
	if n < V:
		nx += 1
	else:
		ny += 1
	for m in to[n]:
		dfs(m)

ans = 0
for x in X:
	if x in visited: continue
	nx, ny = 0, 0
	dfs(x)
	ans += nx*ny
print(ans-N)



Measured memory_bytes: 120360
N = int(input())

into = []
for i in range(1, N+1):
    res, sc_str = [x for x in input().split()]
    sc = int(sc_str)

    into.append((i, res, sc))

from operator import itemgetter

sorted_into = sorted(into, key=lambda x:(x[1],-x[2]))

for z in  sorted_into:
    print(z[0])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;
    std::sort(a.begin(), a.end());

    i64 ret = 0;
    for (int i = n - 1; i >= 0; i--) for (int j = 0; j < i; j++) {
        int k = std::upper_bound(a.begin() + j + 1, a.end(), a[i] - a[j]) - a.begin();
        ret += std::max(0, i - k);
    }

    std::cout << ret << std::endl;

    return 0;
}


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

typedef long long ll;

int main(){
  ll N,K,Q;
  cin >> N >> K >> Q;
  vector<ll> P(N, K-Q);
  vector<ll> A(Q);
  for(ll i=0; i<Q; i++){
    cin >> A[i];
  }
  for(ll i=0; i<Q; i++){
    P[A[i]-1]++;
  }
  for(ll i=0; i<N; i++){
    if (P[i]<=0) cout<<"No"<<endl;
    else cout << "Yes" <<endl;
  }
}

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

namespace AtCoder
{
    class Abc163C
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var b = new int[n];
            for (int i = 0; i < n - 1; i++)
                b[a[i] - 1]++;

            for (int i = 0; i < n; i++)
                Console.WriteLine(b[i]);
        }
    }
}


Measured memory_bytes: 40172
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

long a, b, ans;

long F(long x) {
    if ( (x + 1) % 4 == 0 ) {
        return 0;
    } else if ( (x + 1) % 4 == 1 ) {
        return x;
    } else if ( (x + 1) % 4 == 2 ) {
        return 1;
    } else {
        return 1 ^ x;
    }
}

int main() {
    scanf("%ld %ld", &a, &b);
    ans = F(a - 1) ^ F(b);
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;
const int NMAX = 1e5 + 5;
vector <vector <int>> adj(NMAX, vector <int>());
int dist[NMAX][3];
int s, t, n, m;

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0 ;i<m; i++){
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
	}
	cin >> s >> t;

	CLEAR(dist, -1);
	queue <pii> q;
	q.push(mp(s, 0));
	dist[s][0] = 0;

	while(!q.empty()){
		int node = q.front().fi;
		int parity = q.front().sc;
		q.pop();

		for(int chi: adj[node]){
			int new_parity = (parity+1) % 3;
			if(dist[chi][new_parity] == -1){
				dist[chi][new_parity] = dist[node][parity]+1;
				q.push(mp(chi, new_parity));
			}
		}
	}

	cout << (dist[t][0] == -1 ? -1 : dist[t][0]/3);
	return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <math.h>

struct POINT {
    double x;
    double y;
};

double Dist(const POINT &a, const POINT &b){
    return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );  
}

double Norm(const POINT &a){
    return sqrt( a.x * a.x + a.y * a.y );
}

double Norm2(const POINT &a){
    return a.x * a.x + a.y * a.y;
}

double Square(const POINT &a, const POINT &b, const POINT &c){    //3点を頂点に持つ"平行四辺形の"面積
    return (a.x - b.x) * (a.y - c.y) - (a.y - b.y) * (a.x - c.x);
}

int main(){
    POINT zP[3];
    for (int i = 0; i < 3; i++){
        scanf("%lf %lf", &zP[i].x, &zP[i].y);
    }
    double xAns,yAns,rAns;
    xAns = ( zP[0].y * (Norm2(zP[1]) - Norm2(zP[2])) + zP[1].y * (Norm2(zP[2]) - Norm2(zP[0])) + zP[2].y * (Norm2(zP[0]) - Norm2(zP[1])) )
           / (-2 * Square(zP[0], zP[1], zP[2]));
    yAns = ( zP[0].x * (Norm2(zP[1]) - Norm2(zP[2])) + zP[1].x * (Norm2(zP[2]) - Norm2(zP[0])) + zP[2].x * (Norm2(zP[0]) - Norm2(zP[1])) )
           / (2 * Square(zP[0], zP[1], zP[2]));
    rAns = sqrt( (zP[0].x - xAns) * (zP[0].x - xAns) + (zP[0].y - yAns) * (zP[0].y - yAns) );

    printf("%lf %lf %lf", xAns, yAns, rAns);
    
    return 0;
}


Measured memory_bytes: 2732
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if (a>=b&&-a+b<=x)
		cout << "delicious" << endl;
	else if (x >= -a + b)
		printf("safe\n");
	else
		printf("dangerous\n");

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
signed main() {
	ll n, a, cnt = 1, ans = 0; cin >> n;
	while (n > 1) {
		n /= 2; cnt *= 2; cnt++;
	}
	cout << cnt << endl;
	cin >> n; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

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

void printVector(const vector<ll>& vec) {
    for (ll value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    IO;

    ll N; cin >> N;
    string str; cin >> str;
    vl wkosuu(N), ekosuu(N);

    ll x = 0, y = 0, z=0;

    rep(i, N) {
        if (str[i] == 'E') { ++y; }
        else if (str[i] == 'W') { ++z; }
    }

    wkosuu[0] = 0;
    wkosuu[N - 1] = z;
    ekosuu[0] = y;
    ekosuu[N - 1] = 0;

    for (ll i = 1; i < N-1; ++i) {
        if (str[i-1] == 'E') {
            wkosuu[i] = wkosuu[i - 1];
        }
        else if (str[i-1] == 'W') {
            ++x;
            wkosuu[i] = x;
        }
    }

    for (ll i = 0; i < N-1; ++i) {
        if (str[i] == 'W') {
            if (i > 0) {
                ekosuu[i] = ekosuu[i - 1];
            }
        }
        else if (str[i] == 'E') {
            --y;
            ekosuu[i] = y;
        }
    }

    ll ans = N;

    rep(i, N) {
        ans = min(ans, wkosuu[i] + ekosuu[i]);
    }

    cout << ans << endl;

}

Measured memory_bytes: 8032
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 2005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char A[MAXN], B[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int a, b, c;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    int sum = min(k, a);
    k -= sum;
    if (!k) {
        printf("%d", sum);
        return 0;
    }
    k -= b;
    if (k > 0) {
        printf("%d", sum - min(k, c));
    } else {
        printf("%d", sum);
    }
    return 0;
}

Measured memory_bytes: 3832
def ispalindrome(str): return 1 if str == str[::-1] else 0

sta = input()
N = len(sta)
sta_a = sta[0:(N-1)//2]
sta_b = sta[(N-1)//2+1:]


if ispalindrome(sta) and ispalindrome(sta_a) and ispalindrome(sta_b):
  print("Yes")
else:
  print("No")
  
  


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N;
ll A[Nmax];

ll gcd(ll x, ll y){
	if(y==0) return x;
	else return gcd(y, x%y);
}

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

	vector<int> front, end;
	front.push_back(A[0]);
	for(int i=1; i<N; i++) front.push_back(gcd(front.back(), A[i]));
	end.push_back(A[N-1]);
	for(int i=N-2; i>=0; i--) end.push_back(gcd(end.back(), A[i]));
	reverse(end.begin(), end.end());

	ll ans = max(end[1], front[N-2]);
	for(int i=1; i<N-1; i++){
		ans = max(ans, gcd(front[i-1], end[i+1]));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2296
n = int(input())
Building = [[[0 for r in range(11)] for f in range(4)] for b in range(5)]
for i in range(n):
    b, f, r, v = map(int, input().split())
    Building[b][f][r] += v

for b in range(1, 5):
    for f in range(1, 4):
        for r in range(1, 11):
            print(" " + str(Building[b][f][r]), end = "")
        print()
    if b != 4:
        print("####################")

Measured memory_bytes: 7772
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,x;
	cin >>a;
	cin >>b;
	cin >>c;
	cin >>x;
	int cnt=0;
	for(int i=0;i<=a;++i){
		for(int j=0;j<=b;++j){
			for(int k=0;k<=c;++k){
				if(500*i+100*j+50*k==x){
					cnt+=1;
				}
			}
		}
	}
	cout <<cnt<<endl;
}


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

using namespace std;

int main() {
    int n, aa;
    cin >> n;
    vector<long long> a;
    for (int i = 0; i < n; i++) {
        cin >> aa;
        a.push_back(aa);
    }
    sort(a.begin(), a.end());
    int e = 0;
    long long ans[2];
    for (int i = n - 1; i > 0 && e < 2; i--) {
        if (a[i] == a[i - 1]) {
            ans[e] = a[i];
            e++;
            i--;
        }
    }
    if (e == 2) {
        cout << ans[0] * ans[1] << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    cout << n * n * n << "\n";
    return 0;
}

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

int main()
{
  int N;
  long long sum = 0;

  cin >> N;
  
  for(int i = 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0){
      sum+= i;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3632