akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int64_t ans = 0;
  
  for (int i = 1; i <= N;i++){
    if (i % 3 == 0){
      continue;
    }
    else if (i % 5 == 0){
      continue;
    }
    else{
      ans += i;
    }
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))
d = {}
for a in A:
    if a in d: d[a] += 1
    else: d[a] = 1
ans = 0
for k,v in d.items():
    if k < v: ans += v-k
    if k > v: ans += v
print(ans)

Measured memory_bytes: 18160
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define uqv(v) v.erase(unique(all(v)), v.end());
#define INF 1e9
#define LINF 1e18

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

int arr[55];

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

	int n;
	string s;
	cin >> n >> s;
	int cnt = 1;
	for(int i = 1; i < n; i++) {
			if(s[i] != s[i-1]) cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string str;
  int a=0, b=0, c=0;
  
  cin >> str;
  
  for(int i=0 ; i < 3; i++){
    if(str[i] == 'a') a++;
    else if(str[i] == 'b') b++;
    else if(str[i] == 'c') c++;
  }
  
  if(a == 1 && b == 1 && c == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
/*
 * Author: GSaMenezes 
 * 
 */
 
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define repn(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
 
const ll INF = 1e18+5;
 
int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    int n, W;
    cin >> n >> W;
    vi v(n), w(n);
    int max_val = 0;
    rep(i, 0, n){
		cin >> w[i]  >> v[i];
		max_val += v[i];
	}
	vector <ll> dp(max_val + 5, INF);
	dp[0] = 0;
    rep(i, 0, n){
		for(int j = max_val - v[i]; j >= 0; --j){
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
		}
	}
	int ans = 0;
	repn(i, 0, max_val){
		if(dp[i] <= W)
			ans = max(ans, i);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
using LL = long long;

int N;
int P[100];
LL dp[100][21];

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

    fill(dp[0], dp[99], 0);

    dp[0][P[0]] = 1;

    for (int i = 0; i < N - 2; i++) {
        for (int j = 0; j <= 20; j++) {
            if (dp[i][j]) {
                if (j + P[i + 1] <= 20)
                    dp[i + 1][j + P[i + 1]] += dp[i][j];
                if (j - P[i + 1] >= 0)
                    dp[i + 1][j - P[i + 1]] += dp[i][j];
            }
        }
    }

    cout << dp[N - 2][P[N - 1]] << endl;
}


Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] p = new int[N];
    for(int i = 0; i < N; i++){
      p[i] = sc.nextInt();
    }

    Arrays.sort(p);

    p[N - 1] /= 2;
    int sum = 0;
    for (int i = 0; i < N; i++){
      sum += p[i];
    }

    System.out.println(sum);
  }
}


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

int main() {
  int A,B;
  cin>>A>>B;
  
  int sum=0;
  for(int i=A;i<=B;i++){
    string N=std::to_string(i);
    if(N.at(0)==N.at(4)&&N.at(1)==N.at(3)) sum+=1;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n+2)
	aa[0] = math.MaxInt64
	for i := 0; i < n; i++ {
		aa[i+1] = getNextInt64(scanner)
	}
	var y, c int64
	y = 1000
	for i := 1; i < n+1; i++ {
		if aa[i-1] > aa[i] && aa[i] <= aa[i+1] {
			c += y / aa[i]
			y -= aa[i] * c
			continue
		}
		if aa[i-1] <= aa[i] && aa[i] > aa[i+1] {
			y += aa[i] * c
			c = 0
		}
	}
	fmt.Fprintln(writer, y)
}


Measured memory_bytes: 1824
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int N,M;
pair<int,int> p[10000];

int main(){
	while(cin>>N>>M&&N){
		int ans=0;
		rep(i,N){
			cin>>p[i].second>>p[i].first;
			ans+=p[i].second*p[i].first;
			p[i].first*=-1;
		}
		sort(p,p+N);
		rep(i,N){
			if(M>=p[i].second){M-=p[i].second;ans+=p[i].second*p[i].first;}
			else{ans+=M*p[i].first;break;}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
int main() {
	char ch;
	int n;
	scanf("%d",&n);
	int a[n+1];
	int xo = 0;
	for(int i=0;i<n;i++)scanf("%d",&a[i]),xo = xo^a[i];
	for(int i=0;i<n;i++) {
		printf("%d ",xo^a[i]);
	}
}

Measured memory_bytes: 4500
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n;
    cin>>n;
    int a[n+1],b[n],p=0;
    ll sum=0;
    for(int i=0;i<=n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        int t=min(b[i],a[i]);
        b[i]-=t;
        a[i]-=t;
        int k=min(b[i],a[i+1]);
        a[i+1]-=k;
        b[i]-=k;
        sum+=t+k;
    }
    cout<<sum<<endl;




}
//Alhamdulillah








Measured memory_bytes: 4352
N,Q = map(int,input().split())
a,b = [N]*(N+1),[N]*(N+1)

H,W = N,N

black = (N-2)**2

for _ in range(Q):
  t,x = map(int,input().split())
  if t == 1:
    if x < W:
      for i in range(x,W):
        b[i] = H
      W = x

    black -= b[x] - 2
  
  else:
    if x < H:
      for i in range(x,H):
        a[i] = W
      H = x

    black -= a[x] - 2
  

print(black)

Measured memory_bytes: 13340
#include <bits/stdc++.h>
using namespace std;
 
bool lucky7(string n) {
    for (int i = 0; i < n.size(); i++) {
        if (n.at(i) - '0' == 7) {
            return true;
        }
    }
 
    return false;
}
 
int main() {
    string n;
    cin >> n;
    if (lucky7(n)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3600
N, M = map(int, input().split())
V = []
INF = float("inf")
dp = [INF]*(1<<N)
dp[0] = 0
for i in range(M):
  a,b = map(int, input().split())
  c = list(map(int, input().split()))
  k = 0
  for j in range(b):
    k |= 1<<(c[j]-1)
  V.append((a,k))
  dp[k] = min(dp[k],a)

for i in range(1<<N):
  for a,k in V:
    dp[i|k] = min(dp[i|k],dp[i]+dp[k])  
print(dp[-1] if dp[-1] != INF else -1)

Measured memory_bytes: 46552
def koyakusu(x, y)
  loop do
    k = y % x
    if k == 0
      return x
    end
    y = x
    x = k
  end
end

def kobaisu(x, y)
  return x * y / koyakusu(x, y)
end

n = gets.to_i
array = gets.chomp.split(" ").map(&:to_i);
a = array.dup

(a.size - 1).times do
  a.sort!
  a << kobaisu(a[0], a[1] )
  a.slice!(0..1)
end
m = a[0] - 1
ans = 0
array.each do |i|
  ans += m % i
end
puts ans

Measured memory_bytes: 20576
import sys
input = sys.stdin.readline
import math

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')


def main():

    N, K = MAPINT()
    D = LMAPSTR()
    
    str_n = str(N)
    
    for i in range(N, 100000):
      str_i = str(i)
      for s in str_i:
        if s in D:
          break
      else:
        print(str_i)
        exit()

        
if __name__ == "__main__":
    main()


Measured memory_bytes: 72512
import sys



bingo = [[int(c) for c in input().split()] for _ in range(3)]
n = int(input())
a = [int(input()) for _ in range(n)]

ans = [[0,0,0],[0,0,0],[0,0,0]]
num =0

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[i] == bingo[j][k]:
                ans[j][k] = 1
                num += 1
if num < 3:
    print("No")
    exit()

if ans[1][1] == 1:
    if (ans[0][0] == 1 and ans[2][2]==1) or ( ans[0][2] == 1 and ans[2][0] == 1):
        print("Yes")
        exit()


for i in range(3):

    if ans[i][0] == 1 and ans[i][1] == 1 and ans[i][2] == 1:
        print("Yes")
        exit()
    elif ans[0][i] == 1 and ans[1][i] == 1 and ans[2][i] == 1:
        print("Yes")
        exit()


print("No")


Measured memory_bytes: 3064
n = int(input())

if n < 4:
    print('No')
    exit()
elif n % 7 == 0 or n % 4 == 0:
    print('Yes')
    exit()
elif n % 7 % 4 == 0 or n % 4 % 7 == 0:
    print('Yes')
    exit()
else:
    for i in range(1, n % 7):
        tmp = n - 7 * i
        if tmp < 0:
            break
        elif tmp % 4 == 0:
            print('Yes')
            exit()
    for i in range(1, n & 4):
        tmp = n - 4 * i
        if tmp < 0:
            break
        elif tmp % 7 == 0:                                                                                      
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3064
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == "W":
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.right, self.front, self.bottom, self.top, self.back, self.left
        
        if i =="E":
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.left, self.front, self.top, self.bottom, self.back, self.right
        
        if i =="S":
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.back, self.top, self.right, self.left, self.bottom, self.front
            
        if i =="N":
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.front, self.bottom, self.right, self.left, self.top, self.back

    def Open(self):
        print(self.top)

        
        
numbers = [int(x) for x in input().split(" ")]
commands = [str(c) for c in input()]

my_label = numbers
dice = Dice(my_label)

for c in commands:
    dice.Roll(c)

dice.Open()



Measured memory_bytes: 5612
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()

int main(){
    int n, m; cin>>n>>m;
    vector<int> to[1005];
    rep(i, m){
        int a, b; cin>>a>>b; a--; b--;
        to[a].push_back(b);
    }

    int k = -1;
    
    vector<int> ans(n+1);

    rep(i, n){
        vector<int> dist(n, -1), pre(n);
        queue<int> bfs;
        bfs.push(i);
        dist[i] = 0; pre[i] = -1;
        bool brk = false;
        int last;
        while(!bfs.empty()){
            int x = bfs.front(); bfs.pop();
            for(int& y : to[x]){
                if(y == i){
                    brk = true;
                    last = x;
                    break;
                }
                if(dist[y] == -1){
                    dist[y] = dist[x] + 1;
                }
                else continue;
                pre[y] = x;
                bfs.push(y);
            }
            if(brk){
                break;
            }
        }

        if(brk && dist[last]+1 < ans.size()){
            ans.clear();
            while(last != -1){
                ans.push_back(last);
                last = pre[last];
            }
        }
    }

    if(ans.size() == n+1){
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    rep(i, ans.size()){
        cout << ans[i]+1 << endl;
    }

}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#define int long long
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
using lint=int64_t;
using namespace std;

signed main()
{
	lint N;
	cin >> N;

	map<lint,lint> indexof;
	for(lint i=1;i<=N;i++)
	{
		lint val;
		cin >> val;
		indexof[val]=i;
	}

	multiset<int>st;
	st.insert(0);
	st.insert(0);
	st.insert(N+1);
	st.insert(N+1);
     int ans = 0;
	for(int i=N;i>=1;i--){
		st.insert(indexof[i]);
	//	_deb(i);
	//	_deb(indexof[i]);
	//	for(auto e:st) cout<<"  "<<e;cout<<endl;cout<<endl;
		auto it = st.find(indexof[i]);
		int  m = *it;
		it--;
		int b = *it; it--;
		int a = *it;
		it++;it++;it++;
		int x = *it;
		it++;
		int y = *it;
        ans += ( ( (x-m) * (b-a) ) +( (m-b) * (y-x)) ) * i;

		// cout<<a <<" "<<b <<" "<<m<<" "<<x <<" " << y<<endl;

	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 11136
import math
h = int(input())
# cnt = 0
# while h > 0:
#     if h == 1:
#         cnt += 1
#         break
#     else:
#         h //= 2
#         cnt += 1

ans = math.log2(h)
ans = int(ans)
#
# print(2 ** cnt - 1)
print(2 ** (int(ans) + 1) - 1)

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

A = X
loop_end = N
loop = [A]
loop_set = set(loop)
loop_last = -1
for i in range(1, N):
	A = (A * A) % M
	if A in loop_set:
		loop_last = A
		loop_end = i
		break
	loop_set.add(A)
	loop.append(A)

total_head = 0
total_loop = 0
total_tail = 0

i = 0
while i < N:
	A = loop[i]
	if A == loop_last:
		break
	total_head += A
	loop_set.remove(A)
	i += 1

if loop_end < N:
	loop_len = loop_end - i
	loop_rest = (N - i) % loop_len
	loop_count = (N - i - loop_rest) // loop_len
	while i < loop_end:
		total_loop += loop[i]
		i += 1
	i += loop_len * (loop_count - 1)
	A = loop[-1]
	A = (A * A) % M
	while i < N:
		total_tail += A
		A = (A * A) % M
		i += 1
else:
	loop_count = 0

#print(total_head, total_loop, loop_count, total_tail)

print(total_head + total_loop * loop_count + total_tail)


Measured memory_bytes: 13040
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define x first
#define y second
#define pb push_back
typedef pair<int, int> pii;
const int maxn = 1000005;
vector<pii> ver, line[maxn];
vector<int> g[maxn];
int n, m, fa[maxn], cur, was[maxn], newn, dis[maxn];
int getfa(int u) {
    return fa[u] == u ? u : fa[u] = getfa(fa[u]);
}
void merge(int u, int v) {
    if (was[u] != cur) {
        was[u] = cur;
        ver.pb(pii(0, u));
        fa[u] = u;
    }
    if (was[v] != cur) {
        was[v] = cur;
        ver.pb(pii(0, v));
        fa[v] = v;
    }
    fa[getfa(u)] = getfa(v);
}
int main() {
    scanf("%d %d", &n, &m), newn = n;
    for (int u, v, w, i = 1; i <= m; i++) {
        scanf("%d %d %d", &u, &v, &w);
        line[w].pb(pii(u, v));
    }
    for (int i = 1; i <= 1000000; i++) {
        ver.clear(), ++cur;
        for (int j = 0; j < line[i].size(); j++) {
            merge(line[i][j].x, line[i][j].y);
        }
        for (int j = 0; j < ver.size(); j++) {
            ver[j].x = getfa(ver[j].y);
        }
        sort(ver.begin(), ver.end());
        for (int j = 0, k = 0; j < ver.size(); j = k) {
            ++newn;
            while (k < ver.size() && ver[j].x == ver[k].x) {
                g[newn].pb(ver[k].y);
                g[ver[k++].y].pb(newn);
            }
        }
    }
    queue<int> que;
    que.push(1);
    for (int i = 2; i <= newn; i++) {
        dis[i] = -2;
    }
    dis[1] = 0;
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (int i = 0; i < g[u].size(); i++) {
            int v = g[u][i];
            if (dis[v] == -2) {
                dis[v] = dis[u] + 1;
                que.push(v);
            }
        }
    }
    printf("%d\n", dis[n] >> 1);
    return 0;
}

Measured memory_bytes: 73984
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a != b && b == c) {
    cout << a << endl;
  }
  if (a != b && a == c) {
    cout << b << endl;
  }
  if (a == b && b != c) {
    cout << c << endl;
  }
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l_list = []
r_list = []
ans = [0]*m
for i in range(m):
    l, r = map(int, input().split())
    l_list += [l]
    r_list += [r]
if min(r_list) - max(l_list) >= 0:
    print(min(r_list) - max(l_list) + 1)
else:
    print(0)

Measured memory_bytes: 11764
#include<bits/stdc++.h>
using namespace std;
map<string ,int > m;
int main()
{
      int n,maxv=0;
      string s;
      cin>>n;
      while(n--)
      {
            cin>>s;
            m[s]++;
      }
      for(auto itr = m.begin();itr!=m.end();itr++)
      {
            if(maxv<itr->second)
                  maxv=itr->second;

      }
      for(auto itr = m.begin();itr!=m.end();itr++)
      {
            if(itr->second==maxv)
                  cout<<itr->first<<endl;
      }
      m.clear();
}


Measured memory_bytes: 25216
use std::io::Read;

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 d: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut sum = 0;
    for i in 0..n {
        for j in 0..n {
            if j > i {
                sum += d[i] * d[j];
            }
        }
    }
    return sum.to_string();
}


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

int main() {
    int n, ans = 0;;
    cin >> n;
    int a[n+2];
    a[0] = a[n+1] = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n + 1; i++) ans += abs(a[i] - a[i-1]);
    for (int i = 1; i <= n; i++) {
        cout << ans - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

int to[N << 1],nex[N << 1],beg[N],deg[N],Ans[N],rest[N],A[N];
int e,ans = 0;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline void add(int x,int y) {
	to[++e] = y,nex[e] = beg[x],beg[x] = e;
}

inline void dfs(int x,int fa) {
	int cur = 0;
	for(int i = beg[x];i;i = nex[i]) {
		if(to[i] == fa) continue;
		dfs(to[i],x),cur++;
	}
	ans -= cur / 2,cur &= 1;
	if(!cur && x > 1) ans++;
}

inline int check(int Ban,int top,int val) {
	int pos = top,tot = 0;
	For(i,1,top) {
		if(i == Ban) continue;
		while(pos && (A[i] + A[pos] > val || pos == Ban)) pos--;
		if(i >= pos) break;
		tot++,pos--;
	}
//	debug(tot);
	return tot;
}

inline void Dp(int x,int fa,int val) {
	int total = 0,top = 0;
	for(int i = beg[x];i;i = nex[i]) {
		if(to[i] == fa) continue;
		Dp(to[i],x,val);
	}
	for(int i = beg[x];i;i = nex[i]) {
		if(to[i] == fa) continue;
		total += Ans[to[i]];
		A[++top] = rest[to[i]];
	}
	sort(A + 1,A + top + 1);
//	cout << A[top] << " " << val << endl;
	while(top && A[top] >= val) top--;
	A[top + 1] = 0;
	int pos = top,tot = 0;
//	debug(top);
	For(i,1,top) {
		while(A[i] + A[pos] > val) pos--;
		if(i >= pos) break;
		tot++,pos--;
	}
//	debug(tot);
	int l = 1,r = top + 1;
	while(l < r) {
		int mid = (l + r) >> 1;
//		debug(mid);
		if(check(mid,top,val) < tot) l = mid + 1;
		else r = mid;
	}
//	debug(l);
	rest[x] = A[l] + 1;Ans[x] = total - tot;
	if(l == top + 1 && x > 1) Ans[x]++;
//	cout << x << " " << Ans[x] << " " << total << " " << tot << " " << rest[x] << endl;
}

int main() {
	int n = read();
	For(i,1,n - 1) {
		int x = read(),y = read();
		add(x,y),add(y,x);
	}
	dfs(1,0);
	int l = 1,r = n;
	while(l < r) {
		int mid = (l + r) >> 1;
//		debug(mid);
		Dp(1,0,mid);
//		debug(Ans[1]);
//		cout << "------" << endl;
		if(Ans[1] > ans) l = mid + 1;
		else r = mid;
	}

	printf("%d %d\n",ans,l);

	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int a,b,c,ans;
int main()
{ 
  A:
  cin >> a >> b >> c;
  if(a!=b&&b!=c&&c!=a){
    if(a<b&&a<c){a=a+2;
                 ans++;
                }
    if(b<a&&b<c){b=b+2;
                 ans++;
                }
    if(c<b&&c<a){c=c+2;
                 ans++;
                }goto A;
  }else if(a==b&&b!=c){if(a>c){c=c+2;
                               ans++;
                              }
                       else{a++;
                            b++;
                            ans++;
                           }goto A;
  }else if(b==c&&a!=c){if(b>a){a=a+2;
                               ans++;
                              }
                       else{c++;
                            b++;
                            ans++;
                           }goto A;
  }else if(a==c&&b!=c){if(c>b){b=b+2;
                               ans++;
                              }
                       else{c++;
                            a++;
                            ans++;
                           }goto A;
                      }
  else{printf("%d",ans);
        goto B;
       }
  goto A;
  B:;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		long re = 0;
		List<Long> list = new ArrayList<Long>();
		for (int i = 0; i < N; i++) {
			long temp = sc.nextLong();
			re += temp;
			int count = 0;
			while (count < M && temp > 0) {
				list.add(temp / 2 + temp % 2);
				temp /= 2;
				count++;
			}
		}
		Collections.sort(list);
		for (int i = 0; i < M && i < list.size(); i++) {
			re -= list.get(list.size() - 1 - i);
		}
		System.out.println(re);
	}
}

Measured memory_bytes: 154212
N = gets.to_i
I = 2**N - 1
alist=[]
xlist=[]
ylist=[]
for i in 0..N-1
  A = gets.to_i
  X,Y = A.times.map{gets.split.map(&:to_i)}.transpose
  alist.push(A)
  xlist.push(X)
  ylist.push(Y)
end
result = 0
for i in 0..I
  breakflag = false
  S = []
  N.times do |j|
    if i & 1 == 1
      S.push(1)
    else
      S.push(0)
    end
    i = i >> 1
  end
  # 検査開始
  for n in 0..N-1
    if S[n] == 1
      for a in 0..alist[n]-1
        if S[xlist[n][a]-1] != ylist[n][a]
          breakflag = true
          break
        end
      end
    end
    break if breakflag
  end
  if breakflag == false
    if result < S.count(1)
      result = S.count(1)
    end
  end
end
p result

Measured memory_bytes: 2172
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	ll a, b;
	scanf("%ld %ld", &a, &b);
	while(--n){
		ll na, nb;
		scanf("%ld %ld", &na, &nb);
		ll x = (a+na-1)/na, y = (b+nb-1)/nb;
		if(x>y) std::swap(x, y);
		if(a<=x*na and b<=x*nb) a = na*x, b = nb*x;
		else a = na*y, b = nb*y;
	}
	printf("%ld\n", a+b);
	return 0;
}



Measured memory_bytes: 256
import sys
s = list(raw_input()[::-1])
t = list(raw_input()[::-1])
for i in xrange(0, len(s)-len(t)+1):
    for j in xrange(len(t)):
        if ("?" == s[i+j]) or (t[j] == s[i+j]):
            continue
        break
    else:
        for j in xrange(len(t)):
            s[i+j] = t[j]
        break
else:
    print "UNRESTORABLE"
    sys.exit()
print "".join([(lambda x: "a" if x == "?" else x)(s[i]) for i in xrange(len(s))])[::-1]


Measured memory_bytes: 2568
import math
from functools import reduce
from collections import deque
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,k,*A = get_all_int()

    # NGの上限
    l = 0
    # OKの下限
    r = 10**9

    while l+1 < r:
        c = (l+r)//2

        # 全ての丸太を長さc以下にするのに何回かかるか？
        x = 0
        for a in A:
            # 切り上げ-1
            x += (a+c-1)//c - 1
        
        # log(l, r, c, x)

        if x <= k:
            # OK
            r = c
        else:
            # NG
            l = c

    print(r)

main()

Measured memory_bytes: 105028
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
ll n, x, h, w;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x;
  h = n-x;
  w = x;
  ll ans = h;
  while(true){
    ans += w * (h / w) * 2;
    h %= w;
    if(h == 0) break;
    ans += h + w;
    w -= h;
    swap(h, w);
  }
  cout << ans << endl;
  return 0;
}

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

#define int long long
#define MOD 1000000007 

int pow_mod(int a, int b){
	int ans = 1;
	while(b > 0){
		if(b & 1) ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

int ncr(int n, int r){
	int si = 1;
	int bo = 1;
	for(int i = 0;i < r;i++){
		si = (si*(n-i)) % MOD;
		bo = (bo*(i+1)) % MOD;
	}

	return si * pow_mod(bo, MOD-2) % MOD;
}

signed main(){
	int n, a, b;
	cin >> n >> a >> b;
	int ans = pow_mod(2, n);
	ans = (MOD+ans-1) % MOD;
	ans = (MOD+ans-ncr(n, a)) % MOD;
	ans = (MOD+ans-ncr(n, b)) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
//tt89 ;)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void testcase(int t) { cout<<"Case #"<<t<<": "; }
void online() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif //ONLINE_JUDGE
}
const int mod= 1e9+7;

int main() {
    fastIO;
    int n; cin>>n;
    vector<int> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    int q; cin>>q;
    unordered_map<int,int> m;
    ll sum=0;
    for(auto i:arr) { sum+=i; m[i]++; }

    while(q--) {
        int a,b; cin>>a>>b;
        m[b]+=m[a];
        sum+= m[a]*(b-a);
        m.erase(a);

        cout<<sum<<endl;
    }

    return 0;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}
int D,G;
LL bonus[11];
LL cnt[11];

int cal(vector<int> &A){
    int ret_val = 0;
    int need = G;

    _for(i,0,D){
        int k = A[i];
        int c = cnt[k];
        int bo = bonus[k];
        int score = (k+1)*100;
        if(need - c*score <= 0) {ret_val += ((need%score) == 0?need/score:need/score+1);return ret_val;}
        if(need -c*score - bo <= 0) return ret_val + c;
        need -= c*score;
        need -= bo;
        ret_val += c;
    }

}

int main()
{
    cin >> D >> G;
    _for(i,0,D){
        scanf("%lld %lld",&cnt[i],&bonus[i]);
    }
    vector<int> A;
    _for(i,0,D){
        A.push_back(i);
    }

    int ans = 1e9;

    do{
        ans = min(ans,cal(A));
    }while(next_permutation(ALL(A)));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;  
char a[100000000];
int main(){  
    cin>>a;
    int ans=0,flag=1,x,y;
    for(int i=0;a[i]!='\0';i++){
        if(a[i]=='A'){
            x=i;
            break;
        }
    }
    for(int i=strlen(a);i>=0;i--){
        if(a[i]=='Z'){
            cout<<i-x+1<<endl;
            return 0;
        }
    }
    return 0;
}  

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

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

    int ans[110000];
    for (int i = 1; i <= N; i++) {
        ans[A[i]] = i;
    }

    for (int i = 1; i <= N; i++) {
        if(i != 1) {
            cout << " ";
        }
        cout << ans[i];
    }
    cout << endl;
    return 0;
    
    


}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
string s;
cin>>s;
int n=s.length();
int ans=0;
rep(i,1,n-1)if(s[i]!=s[i-1])ans++;
ol(ans);
return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	
	register int a , b;
	
	scanf("%d%d",&a,&b);
	
	if(a <= 0 && b >= 0)	puts("Zero");
	else {
		if(a < 0) {
			if((b-a+1) % 2 != 0)	puts("Negative");
			else	puts("Positive");
		}
		else	puts("Positive");
	}
	
	return 0;
	
}

Measured memory_bytes: 384
x,y = map(int,input().split())
gp_1 = [1,3,5,7,8,10,12]
gp_2 = [4,6,9,11]
print("Yes" if (x in gp_1 and y in gp_1) or (x in gp_2 and y in gp_2) else "No")


Measured memory_bytes: 38384
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>

using namespace std;

int main() {
	int n;
	long a;
	cin >> n;
	long long count = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		while ((a%2)==0) {
			a /= 2;
			count++;
		}

	}
	cout<< count;
	return 0;
}


Measured memory_bytes: 256
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''
p = 10 ** 9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''


#a = list(map(int, input().split()))

n,k = list(map(int, input().split()))

if(n>=10):
    print(k)
else:
    print(k+(10-n)*100)
        




























Measured memory_bytes: 64748
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;

int main(){
    int n; cin >> n;
    long a[n+1], b[n], ans=0.0;
    rep(i, n + 1) {
        cin >> a[i];
    }
    rep(i, n) cin >> b[i];
    rep (i, n) {
        if(b[i] == 0) continue;

        if (b[i] <= a[i]) {
            ans += b[i];
            continue;
        }

        if (b[i] <= a[i] + a[i+1]) {
            ans += b[i];
            b[i] -= a[i];
            a[i+1] -= b[i];
            continue;
        }

        ans += a[i] + a[i+1];
        a[i+1] = 0;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 2;
const int INF = 2e18;

signed main() {
    double L;
    cin >> L;
    vector<double> temp(3, (L / 3));
    cout << fixed << setprecision(10) << temp[0] * temp[1] * temp[2] << endl;
}


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

int main(){
  int A,B,C,X; cin >> A >> B >> C >> X;
  int count=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){
          count++;
        }else if(500*i+100*j+50*k>X){
          break;
        }
      }
    }
  }
  cout << count << endl;
}

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

int main(){ 
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  auto tmp = p;
  sort(tmp.begin(), tmp.end());
  int a = 0, b = 0;
  int cnt = 0;
  do {
    bool fp = true, fq = true;

    for (int i = 0; i < n; i++) {
      if (tmp[i] != p[i]) fp = false;
      if (tmp[i] != q[i]) fq = false;
    }
    if (fp) a = cnt;
    if (fq) b = cnt;
    cnt++;
  } while (next_permutation(tmp.begin(), tmp.end()));
  cout << abs(a - b) << endl;
  return 0;
} 

Measured memory_bytes: 256
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
right,up,n= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
left,down = (0,0)
for i in range(n):
    w,h,c =  (int(i) for i in input().split())
    if c == 1:
        left = max(w,left)
    if c == 2:
        right = min(w,right)
    if c == 3:
        down = max(down,h)
    if c == 4:
        up = min(up,h)
l = max(right-left,0)
w = max(up-down,0)
print(l*w)

Measured memory_bytes: 5052
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
 
 
int main(void){
    int N;
    cin >>N;
    if(N>=30){
        cout << "Yes"<<endl;
    }else{
        cout <<"No"<<endl;
    }
}


Measured memory_bytes: 3632
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Queue <String> N = new LinkedList<>();
		Queue <Integer> Q = new LinkedList<>();
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
		int task = sc.nextInt();	

		for(int i = 0; i < n; i++) {
			N.add(sc.next());
			Q.add(sc.nextInt());
		}
		sc.close();
		
		Queue <String> N_ans = new LinkedList<>();
		Queue <Integer> Q_ans = new LinkedList<>();
		
		
		int time = 0;
		int R = 0;
		String S = "";
		while (!Q.isEmpty()) {
			R = Q.poll();
			S = N.poll();
			if (R>task){
				R-=task;
				Q.add(R);
				N.add(S);
				time+=task;
			}
			else {
				time+=R;
				Q_ans.add(time);
				N_ans.add(S);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(N_ans.poll() + " ");
			System.out.println(Q_ans.poll());
		}
	}

}



Measured memory_bytes: 80444
N,h=gets.split(' ').map(&:to_i)
res,a,b=0,[],[]
N.times{|i|a[i],b[i]=gets.split(' ').map(&:to_i)}
a=a.sort.reverse
b=b.sort.reverse
while h>0
  if b[0]!=nil&&a[0]<b[0]
    h-=b.shift
    res+=1
  else
    res+=(h.to_f/a[0]).ceil
    h=-1
  end
end
puts res

Measured memory_bytes: 8540
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
using ll = long long;
const int M = 100010;


int main() {
	ll b=0,w=0,ans=0,sum=0;
	string s;
	cin>>s;
	rep(i,0,s.size()){
		if(s[i]=='B')b++;
		else w++,sum+=i+1;;
	}
	w=w*(1+w)/2;
	ans=sum-w;
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int n;
vector< pair<int, int> > p;
vector< vector<int> > d;
vector<bool> vis;

int func(int pos) {
  vis[pos] = true;
  int r = 1;
  for(int i=0; i<d[pos].size(); i++) {
    if(!vis[d[pos][i]]) {
      r = max(r, func(d[pos][i]) + 1);
    }
  }
  vis[pos] = false;
  return r;
}

int main() {
  while(true) {
    cin >> n;
    if(n == 0) break;
    p.assign(n, {0,0});
    d.assign(100, vector<int>(0,0));
    vis.assign(100, false);
    for(int i=0; i<n; i++) {
      cin >> p[i].first >> p[i].second;
      p[i].first--;
      p[i].second--;
      d[p[i].first].push_back(p[i].second);
      d[p[i].second].push_back(p[i].first);
    }

    int ans = 0;
    for(int i=0; i<100; i++) ans = max(ans, func(i));

    cout << ans << endl;
  }

  return 0;
}


//EOF



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  ll count = 0;
  if(a%2==1||b%2==1||c%2==1){
      print(count);
      return 0;
  }
  if (a == b&&b == c){
    print(-1);
    return 0;
  }
  while (1){
    ll A = a;
    ll B = b;
    ll C = c;
    a = B / 2 + C / 2;
    b = A / 2 + C / 2;
    c = A / 2 + B / 2;
    count++;
    if(a%2==1||b%2==1||c%2==1){
      print(count);
      return 0;
    }
  }
}

Measured memory_bytes: 3604
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char table[1000][1000];
bool done[1000][1000];
int main() {
	int H,W,K;
	cin >> H >> W >> K;
	vector<P> cur,nex;
	for(int i=0;i<H;i++){
		cin >> table[i];
		for(int j=0;j<W;j++){
			if(table[i][j]=='S'){
				cur.push_back(P(i,j));
				done[i][j]=true;
			}
		}
	}
	int ret=1<<29;
	for(int i=0;i<=K;i++){
		nex.clear();
		for(auto p:cur){
			int dx=1,dy=0;
			int v=min({p.first,H-1-p.first,p.second,W-1-p.second});
			if(v==0){
				ret=1;
				continue;
			}
			ret=min(ret,2+(v-1)/K);
			for(int k=0;k<4;k++,dx=-dx,swap(dx,dy)){
				int x=p.first+dx;
				int y=p.second+dy;
				if(!done[x][y]&&table[x][y]=='.'){
					done[x][y]=true;
					nex.push_back(P(x,y));
				}
			}
		}
		swap(nex,cur);
	}
	cout << ret << endl;



	return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int compare (const void *a, const void *b)
{
    if(*(intmax_t *)a - *(intmax_t *)b < 0)
        return 1;
    if(*(intmax_t *)a - *(intmax_t *)b > 0)
        return -1;
    return 0;
}

int main (void)
{
    intmax_t N, A[200000], a[200000];

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
        a[i] = A[i];
    }

    qsort(a, N, sizeof(intmax_t), compare);

    for (size_t i = 0; i < N; i++) {
        if (a[0] == A[i]) {
            printf("%jd\n", a[1]);
        } else {
            printf("%jd\n", a[0]);
        }
    }

    return 0;
}


Measured memory_bytes: 4860
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>

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

    int a,b;
    int num;
    while (std::cin >> a >> b) {
        num = a+b;
        unsigned digit=0;
        while(num!=0){
            num /= 10;
            digit++;
        }
        std::cout << digit << std::endl;
    }
    
    return EXIT_SUCCESS;
}


Measured memory_bytes: 3076
#include<stdio.h>

int main() {
	int a, b;

	scanf("%d%d", &a, &b);

	if (a >= 13)
		printf("%d\n", b);
	else if (a >= 6)
		printf("%d\n", b / 2);
	else
		printf("0\n");

	return 0;
}

Measured memory_bytes: 128