akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
 
main = abc161a

abc161a = do
    [a, b, c] <- getIntList
    putStrLn $ show c ++ " " ++ show a ++ " " ++ show b


readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine


Measured memory_bytes: 380
import bisect
N = 10**6
dp = [1] * (N+1)
dp[0] =  dp[1] =  0
prime = []
for i in range(2,N+1):
    if dp[i]:
        for j in range(i*i, N+1, i):
            dp[j] = 0
like2017 = [0] * (N+1)
for n in range(N+1):
    if dp[n]==0:
        continue
    query = (n+1)//2
    if dp[query]==1:
        like2017[n] = 1


for n in range(N):
    like2017[n+1] += like2017[n]

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


Measured memory_bytes: 66268
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAX 100000

int i;
int a[MAX];

void wariate() 
{
	for (i = 0; i < MAX; i++){
		a[i] = i;
	}
}

int search(int c)
{
	if (c == a[c]) {
		return c;
	}
     
	return a[c] = search(a[c]);
}
 
int main()
{
 	int n, m, q;
 	int s, t;

 	wariate();

	scanf("%d %d",&n, &m);
 
	for (i = 0; i < m; i++){
		scanf("%d %d",&s, &t);
		if (search(s) != search(t)) {
			a[search(t)] = search(s);
		}
	}
	
	scanf("%d",&q);
	
	for (i = 0; i < q; i++){
		scanf("%d %d",&s, &t);
		
		if (search(s) == search(t)){
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}

	return 0;
}




Measured memory_bytes: 2108
#include <iostream>

using namespace std;

int main(){

int n,val;
cin>>n;

val=n-1;

for(int i=2;i<n;i++){
  if (n%i != 0){val += n/i;}
  else val += (n/i)-1;
}

cout<<val<<endl;

  return 0;
}


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

int main() {

  int x, y;
  cin >> x >> y;
  
  if(y%2 != 0){
    cout << "No" << endl;
    return 0;
  }
  
  int tsuru, kame;
  
  kame = (y - 2 * x)/2;
  tsuru = (4 * x - y)/2;
    
  if(kame >= 0 && tsuru >= 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

inline int read()
{
	char c=getchar();int num=0,f=1;
	for(;!isdigit(c);c=getchar())
		f=c=='-'?-1:f;
	for(;isdigit(c);c=getchar())
		num=num*10+c-'0';
	return num*f;
}

const int N=2e5+5;
const int mod=1e9+7;

int n,x[N],v[N],lef[N],rig[N];
int f[N],sum[N],sta[N],top;

struct Poi
{
	int x,v;
	bool operator < (const Poi &A) const
	{
		return v<A.v;
	}
}a[N];
struct Line
{
	int l,r;
	bool operator < (const Line &A) const
	{
		return r==A.r?l<A.l:r<A.r;
	}
}ln[N];

int main()
{
	n=read();
	for(int i=1;i<=n;++i) a[i].x=read(),a[i].v=read();
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		if(!top||a[i].x>a[sta[top]].x) sta[++top]=i;
		int l=1,r=top,mid;
		while(l<=r)
		{
			mid=(l+r)>>1;
			if(a[sta[mid]].x>=a[i].x) r=mid-1;
			else l=mid+1;
		}
		lef[i]=sta[r+1];
	}
	top=0;
	for(int i=n;i;--i)
	{
		if(!top||a[i].x<a[sta[top]].x) sta[++top]=i;
		int l=1,r=top,mid;
		while(l<=r)
		{
			mid=(l+r)>>1;
			if(a[sta[mid]].x<=a[i].x) r=mid-1;
			else l=mid+1;
		}
		rig[i]=sta[r+1];
	}
	for(int i=1;i<=n;++i) ln[i].l=lef[i],ln[i].r=rig[i];
	sort(ln+1,ln+n+1);
	int now=1,ans=0;
	for(int i=1;i<=n;++i)
	{
		while(ln[now].r<ln[i].l-1) ++now;
		f[i]=(sum[i-1]-sum[now-1])%mod;
		if(ln[i].l==1) ++f[i];
		if(ln[i].r==n) ans=(ans+f[i])%mod;
		sum[i]=(sum[i-1]+f[i])%mod;
	}
	cout<<(ans+mod)%mod;
	return 0;
}

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

int main() {
  int a,b;
  int A = 0;
  int B = 0;
  cin >> a >> b;
  if (a>b){
    while(a>0){
      B+=b*pow(10,a-1);
      a= a-1;
    }
    cout << B << endl;
  }
  else{
    while(b>0){
      A+=a*pow(10,b-1);
      b= b-1;
    }
    cout << A << endl;
  }
  
}
  

Measured memory_bytes: 256
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()+[(0,0)]
v2c=Counter(v2).most_common()+[(0,0)]

if v1c[0][0]==v2c[0][0]:
    print(min(n-v1c[0][1]-v2c[1][1],n-v1c[1][1]-v2c[0][1]))

else:
    print(n-v1c[0][1]-v2c[0][1])

Measured memory_bytes: 23636
N = int(input())
A = list(map(int, input().split()))
Ans = sum(A)
D = [0] * (10**5 + 1)
for i in A:
  D[i] += 1
  
Q = int(input())
for i in range(Q):
  B, C = map(int, input().split())
  D[C] += D[B]
  b = D[B]
  D[B] = 0
  Ans += b * (C - B)
  print(Ans)
  

Measured memory_bytes: 20924
import copy

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


n = int(input())
for i in range(n):
    idx, value = map(int, input().split())
    T = copy.deepcopy(t)
    t[idx - 1] = value
    print(sum(t))
    t = copy.deepcopy(T)


Measured memory_bytes: 3444
#include <iostream>
using namespace std;
int main(){
	int n,ans;
	string s;
	cin >> n >> s;
	ans = 0;
	for(int i=0;i<s.size()-2;i++)
	{
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
		{
			ans += 1;		
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
import sys
inputs = sys.stdin.readlines()

h, w = map(int, inputs[0].split())
S = [list(map(lambda x: 0 if x=='#' else 1, row)) for row in inputs[1:]]

w_costs = [[0]*w for _ in range(h)]
h_costs = [[0]*w for _ in range(h)]

def row_search(x, y):
    x_, cost = x, 0
    while x+1 < w and S[y][x+1]:
        x += 1
        cost += 1
    while x_ <= x:
        w_costs[y][x] = cost
        x -= 1
def col_search(x, y):
    y_, cost = y, 0
    while y+1 < h and S[y+1][x]:
        y += 1
        cost += 1
    while y_ <= y:
        h_costs[y][x] = cost
        y -= 1

for y in range(h):
    for x in range(w):
        if S[y][x]:
            if w_costs[y][x] == 0:
                row_search(x, y)
            if h_costs[y][x] == 0:
                col_search(x, y)

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, w_costs[y][x] + h_costs[y][x] + 1)
print(ans)

Measured memory_bytes: 149768
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    K=int(input())
    q,r=divmod(K,50)
    a=[50+q]*r+[49-r+q]*(50-r)
    print(50)
    print(*a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
program ABC079D
    implicit none
    integer(8)::H,W
    integer(8)::cost(10,10)
    integer(8),allocatable,dimension(:,:)::A
    integer(8)::i,j
    integer(8)::ans
    read*,H,W
    do i=1,10
        read*,cost(i,:)
    end do
    call Warshall_Floyd(10_8,cost)

    allocate(A(H,W))
    do i=1,H
        read*,A(i,:)
    end do
    
    ans=0
    do i=1,H
        do j=1,W
            if(A(i,j)==-1)cycle
            ans=ans+Cost(A(i,j)+1_8,2_8)
        end do
    end do
    print"(i0)",ans
    contains
subroutine Warshall_Floyd(n,Route)
  !nは頂点の数、Routeは全ての経路の長さを記録したもの
  !以下の型宣言は場合に応じて変えること
  implicit none
  integer(8), intent(in) :: n
  integer(8), intent(inout) :: Route(n, n)
  integer(8) :: i, j, k

    do k = 1, n
      do i = 1, n
        do j = 1, n
          Route(j, i) = min( Route(j, i), Route(j, k) + Route(k, i))
        end do
      end do
    end do
end subroutine Warshall_Floyd
end program 

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

int H,W,N;
int is_del[31][31] = {};
char F[31][31],C[31][31];

bool del(){
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) is_del[i][j] = 0;
    bool update = false;
    for(int i=1;i<=H;i++){
        int l = 1,r = 1;
        while(r<=W){
            if(C[i][l]=='.'){l++; r = l; continue;}
            if(C[i][l]==C[i][r]){
                r++;
                if(r==W+1 && r-l>=N){
                    for(int j=l;j<r;j++) is_del[i][j] = 1;
                    l = r;
                }
            }else{
                if(r-l>=N) for(int j=l;j<r;j++) is_del[i][j] = 1;
                l = r;
            }
        }
    }
    for(int j=1;j<=W;j++){
        int l = 1,r = 1;
        while(r<=H){
            if(C[l][j]=='.'){l++;r = l;continue;}
            if(C[l][j]==C[r][j]){
                r++;
                if(r==H+1 && r-l>=N){
                    for(int i=l;i<r;i++) is_del[i][j] = 1;
                    l = r;
                }
            }else{
                if(r-l>=N) for(int i=l;i<r;i++) is_del[i][j] = 1;
                l = r;
            }
        }
    }
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++)if(is_del[i][j]){C[i][j] = '.'; update = true;}
/*    for(int j=1;j<=W;j++) for(int i=1;i<=H;i++){
        if(i!=1 && C[i][j]!='.'){
            int now = i;
            while(now>1 && C[now-1][j]=='.'){swap(C[now][j],C[now-1][j]); now--; update = true;}
        }
    }*/
    return update;
}

bool simulate(int x,int y){
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){C[i][j] = F[i][j];}
    swap(C[x][y],C[x][y+1]);
    while(true){
        for(int j=1;j<=W;j++) for(int i=1;i<=H;i++){
            if(i!=1 && C[i][j]!='.'){
                int now = i;
                while(now>1 && C[now-1][j]=='.'){swap(C[now][j],C[now-1][j]); now--;}
            }
        }
        if(!del()) break;
    }
    bool ok = true;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) ok = (ok && C[i][j]=='.');
    return ok;
}

int main(){
    cin >> H >> W >> N;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) cin >> F[H-i+1][j];
    bool ok = false;
    for(int j=1;j<W;j++) for(int i=1;i<=H;i++) if(F[i][j]!='.' || F[i][j+1]!='.') ok = (ok | simulate(i,j));
    cout << (ok? "YES":"NO") << endl;
}


Measured memory_bytes: 3112
/**
 *   author: r1933
**/
#include "bits/stdc++.h"

using namespace std;

#define all(x) x.begin(), x.end()
using i64 = long long;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<i64> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  sort(all(h), greater<>());
  i64 minv = LINF;
  for (int i = k - 1; i < n; ++i) {
    i64 diff = abs(h[i] - h[i-k+1]);
    minv = min(minv, diff);
  }
  cout << minv << "\n";
  return 0;
}


Measured memory_bytes: 1024
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var k = next();
  var s = xArray(0,k+1);
  var ans = k;
  s[k] = 1;
  for(var i = k-1; i > 0; i--){
    s[i] = pow(k/i|0, n);
    for(var j = i+i; j <= k; j += i){
      s[i] -= s[j];
    }
    s[i] %= mod;
    if(s[i] < 0)s[i] += mod;
    ans += mul(s[i], i);
 }
  return ans % mod;
}

Measured memory_bytes: 38460
/*
  AtCoder Beginner Contest 096
  B - Maximum Sum
*/

#include<iostream>
using namespace std;

int A, B, C, K;

int main() {
  scanf("%d%d%d%d", &A, &B, &C, &K);
  if (A >= C && A >= B) {
    for (int i = 0; i < K; ++i) A *= 2;
  }
  else if (B >= C && B >= A) {
    for (int i = 0; i < K; ++i) B *= 2;
  }
  else if (C >= A && C >= B) {
    for (int i = 0; i < K; ++i) C *= 2;
  }
  printf("%d\n", A + B + C);
  return 0;
}

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

using namespace std;
using i64 = long long;
using f64 = double;

#define FOR(i, s, n) for (size_t i = (s); i < (size_t)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

template <typename T, typename U>
inline bool chmax(T &a, U b) {
  return a < b ? (a = b, true) : false;
}

template <typename T, typename U>
inline bool chmin(T &a, U b) {
  return a > b ? (a = b, true) : false;
}

int main() {
  int64_t N, D, x, y;
  int count = 0;
  cin >> N >> D;
  REP(i, N) {
    cin >> x >> y;
    if (x * x + y * y <= D * D) {
      count++;
    }
  }
  cout << count;
  return 0;
}


Measured memory_bytes: 3612
n = int(input())
a = [[0]*9 for x in range(9)]
for i in range(1,n+1):
    s = str(i)
    if s[-1]=="0":
        continue
    a[int(s[0])-1][int(s[-1])-1] += 1
ans = 0
for i in range(9):
    for j in range(9):
        ans += a[i][j]*a[j][i]

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define ll long long
#define mod (1000000007LL)
using namespace std;
vector<ll> h, a;
map<ll,ll> best;
vector<int> arr;
ll tree[800005];
void update(int i, int l, int r, int index, ll value) {
	if( index > r || index < l) return;
	if(l == r ) {
		tree[i] = value;
		return;
	}
	int m = l + (r-l)/2;
	update(2*i, l, m, index, value);
	update(2*i + 1, m+1, r, index, value);
	tree[i] = max(tree[2*i], tree[2*i+1]);
}
ll query(int i,int l, int r, int ql, int qr) {
	if(l > qr || ql > r) return 0;
	if(ql <= l && r <= qr) return tree[i];
	int m = l + (r-l)/2;
	return max(query(2*i,l,m,ql,qr), 
				query(2*i+1, m+1,r, ql, qr));
}
int main() {
	ll N;
	cin>>N;
	h.resize(N);
	a.resize(N);
	arr.push_back(0);
	for(int i=0;i<N;i++) {
		cin>>h[i];
		arr.push_back(h[i]);
	}
	for(int i=0; i<N; i++) {
		cin>>a[i];
	}
	sort(arr.begin(), arr.end());
	int index = lower_bound(arr.begin(), arr.end(), h[N-1]) - arr.begin();
	update(1,1,N, index, a[N-1]);
	
	for(int i=N-2;i>=0; i--) {
		index = upper_bound(arr.begin(), arr.end(), h[i]) - arr.begin();
		ll cur = a[i] + query(1,1,N, index, N);
		index = lower_bound(arr.begin(), arr.end(), h[i]) - arr.begin();
		update(1,1,N, index, cur);
	}
	cout<<query(1,1,N,1,N)<<endl;
 	return 0;
}

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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	int sum=0;
	if(a==b)
	{
		cout<<a+a;
		return 0;
	}
	int big=max(a,b);
    if(a==big)
    {
    	sum+=big;
    	big=max(a-1,b);
    	sum+=big;
    }
    else
    {
    	sum+=big;
    	big=max(a,b-1);
    	sum+=big;
    	
    }
    
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        long n = long.Parse(Console.ReadLine());
        
        for(long i=(long)Math.Sqrt(n); i>0; i--){
            double quot = n / (double)i;
            
            if(quot-Math.Floor(quot)==0){
                Console.WriteLine(i+n/i-2);
                return;
            }
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    for (int i = 0; i < n; i++){
        cin >> x[i] >> u[i];
    }
    double ans = 0;
    for (int i = 0; i < n; i++){
        if (u[i] == "BTC"){
            ans += 380000.0 * x[i];
        }else{
            ans += x[i];
        }
    }
    cout << ans << endl;

    return 0;
}














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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var q = new Queue<int>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            foreach (var x in line) q.Enqueue(int.Parse(x));
            var ba = 32;
            while (ba > 0)
            {
                ba -= (ba - 1) % 5;
                Console.WriteLine(ba);
                var jiro = q.Dequeue();  q.Enqueue(jiro);
                ba = Math.Max(0, ba - jiro);
                Console.WriteLine(ba);
            }
        }
    }
}

Measured memory_bytes: 10048
n = int(input())
l = list(map(int, input().split()))
mod = 10**9 + 7
def gcd(a,b):
  while b: a,b = b,a%b
  return a
lcm = lambda a,b: a*b//gcd(a,b)
t = 1
for x in l: t = lcm(t,x)
print(sum(t//x for x in l)%mod)

Measured memory_bytes: 4084
import unittest
import functools


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 3, 4]), 13)

    def test_2(self):
        self.assertEqual(think([12, 12, 12, 12, 12]), 5)

    def test_3(self):
        self.assertEqual(think([1000000, 999999, 999998]), 996989508)

    def test_4(self):
        self.assertEqual(gcd(3, 2), 1)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    mode = 10 ** 9 + 7

    lcm_of_all_a = functools.reduce(lambda x, y: lcm(x, y), a, 1)
    lcm_of_all_a %= mode   # THIS LINE IS KEY POINT

    b = map(lambda x: lcm_of_all_a * inverse(x, mode) % mode, a)
    return sum(b) % mode


def write(result):
    print(result)


def lcm(a, b):
    return (a * b) // gcd(a, b)


def gcd(a, b):
    if a < b:
        return gcd(b, a)

    while True:
        if a % b == 0:
            return b
        a, b = b, a % b


def inverse(x, mode):
    return pow(x, mode - 2, mode)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 54760
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,m;
  cin >> n >> m;

  cout << (n-1)*(m-1) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n=0,m=0;
	cin>>n>>m;
	if(m<=0&&n+m-1>=0)
		cout<<(m+n+m-1)*n/2<<endl;
	else if(m>0)
		cout<<(m+1+n+m-1)*(n-1)/2<<endl;
	else if(n+m-1<0)
		cout<<(m+n+m-2)*(n-1)/2<<endl;
	return 0;
} 

Measured memory_bytes: 256
n, k = [int(a) for a in input().split()]
V = [int(a) for a in input().split()]

ans = 0
have = []
val = 0

for l in range(0, min(k, n) + 1):
    if l > 0:
        have = V[0 : l]
        have.sort()
        val = sum(V[0 : l])

    for r in range(0, min(k - l, n - l) + 1):
        if r > 0:
            have.append(V[-r])
            have.sort()
            val += V[-r]

        d = 0
        t_val = val
        while d < min(l + r, k - l - r):
            if have[d] > 0: break
            t_val -= have[d]
            d += 1  # 戻す

        ans = max(ans, t_val)

print(ans)

Measured memory_bytes: 39664
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    std::string s;
    std::cin >> s;

    int count[2] = {0};
    for (std::size_t i = 0; i < s.size(); ++i) {
        if (s[i] == '0') {
            ++(count[0]);
        } else {
            ++(count[1]);
        }
    }

    std::cout << std::min(count[0], count[1]) * 2 << std::endl;

    return 0;
}


Measured memory_bytes: 512
S = Array.new(gets.to_i)
S.map!{gets.to_i}

wk = S.inject(:+)
if wk % 10 == 0 then
  t = S.select{|s| s % 10 > 0}.min
  puts t.nil? ? 0 : wk - t
    
else
  puts wk
end


Measured memory_bytes: 1788
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	double n,a;
	int b;
	cin>>n>>a>>b;
	int div = ceil(a/n);
	if(div*n<=b) cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
	return 0;
}



Measured memory_bytes: 3860
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vvvi= vector<vvi>;
using vs= vector<string>;

#define endl "\n"

/* At most three _per row_
 */
void solve() {
    cini(r);
    cini(c);
    cini(k);

    vvi v(r+1, vi(c+1, 0));
    for(int i=0; i<k; i++) {
        cini(rr);
        cini(cc);
        cin>>v[rr][cc];
    }

    vvvi dp(r+1, vvi(c+1, vi(4)));

    for(int i=1; i<=r; i++) {
        for(int j=1; j<=c; j++) {
            dp[i][j][0]=*max_element(all(dp[i-1][j]));
            dp[i][j][1]=dp[i][j][0]+v[i][j];
            for(k=1; k<4; k++) {
                dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k]);
                dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k-1]+v[i][j]);
            }
        }
    }

    int ans=*max_element(all(dp[r][c]));
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

int main(){
	int i,n;
	cin >>n;
	if(n>=400&&n<=599)n=8;
	else if(n>=600&&n<=799)n=7;
	else if(n>=800&&n<=999)n=6;
	else if(n>=1000&&n<=1199)n=5;
	else if(n>=1200&&n<=1399)n=4;
	else if(n>=1400&&n<=1599)n=3;
	else if(n>=1600&&n<=1799)n=2;
	else if(n>=1800&&n<=1999)n=1;
	cout <<n<<endl;
	return 0;
}

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

constexpr int MAXN = 2e5 + 5;

using namespace std;
using A = int [MAXN];

template <typename T>
inline void read(T &x) {
    int f = 1; x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int n, m;
pair<int, int> bomb[MAXN];
vector< pair<int, int> > G[MAXN];
vector<int> res;
A diff, fa, cnt, sz, pos;

inline int find(int x) {
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}

inline void dfs(int cur, int fa, int id) {
    sz[cur] = diff[cur];
    for (auto &e : G[cur]) {
        int to = e.first, toId = e.second;
        if (to == fa) continue;
        dfs(to, cur, toId);
        sz[cur] += sz[to];
    }
    if (sz[cur] & 1) res.emplace_back(id);
}

int main() {
    read(n), read(m);
    for (int i = 1; i <= n; i++)
        read(bomb[i].first), read(bomb[i].second);
    sort(bomb + 1, bomb + n + 1);
    for (int i = 1; i <= n + 1; i++) //差分
        pos[i] = bomb[i].first, diff[i] = bomb[i].second ^ bomb[i - 1].second, fa[i] = i;
    for (int i = 1, l, r; i <= m; i++) {
        read(l), read(r);
        l = lower_bound(pos + 1, pos + n + 1, l) - pos;
        r = upper_bound(pos + 1, pos + n + 1, r) - pos;
        int r1 = find(l), r2 = find(r);
        if (r1 == r2) continue;
        fa[r1] = r2;
        G[l].emplace_back(make_pair(r, i));
        G[r].emplace_back(make_pair(l, i));
    }
    for (int i = 1; i <= n + 1; i++)
        if (diff[i]) cnt[find(i)]++;
    for (int i = 1; i <= n + 1; i++) 
        if (find(i) == i && (cnt[i] & 1)) {
            cout << -1 << endl;
            return 0;
        }
    for (int i = 1; i <= n + 1; i++)
        if (find(i) == i) dfs(i, 0, 0);
    printf("%d\n", res.size());
    sort(res.begin(), res.end());
    for (auto &i : res) printf("%d ", i);
    return 0;
}

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

remain = n%7
remain4s = []
while True:
    remain4 = remain%4
    if remain4 == 0:
        print('Yes')
        break
    else:
        remain += 7
        if remain > n:
            print('No')
            break
    if remain4 in remain4s:
        print('No')
        break
    else:
        remain4s.append(remain4)

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kamol Paul
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define long long long
typedef pair < long , long > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
class CTaxIncrease {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a,b;
	    in>>a>>b;
	    for(int i=1;i<=10000000;i++){
	        int x = (2*i)/25;
	        int y = i/10;
	        if(x==a && y== b){
	            out<<i;
	            return;
	        }
	    }
	    out<<"-1\n";
	    return;

	}
};


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	CTaxIncrease solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a % 2 == 0 || b % 2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

using namespace std;
int n,a,b;
bool test(int num)
{
    int total=0;
    while (num)
    {
        total = total +num%10;
        num = num/10;
    }
    if(total >=a&&total<=b)
    {
        return true;
    }
    else
    {
        return false;
    }
    


}


int main()
{
    
    cin>>n>>a>>b;
    int answer=0;
    for (size_t i = 1; i <= n; i++)
    {
        if(test(i))
        {
            answer = answer + i;
        }
    }
    cout<<answer<<endl;

}

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

using ll = long long;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> h = {0};
        vector<int> w = {0};
        for(int i = 0; i < N; ++i) {
            int t; cin >> t;
            h.push_back(h.back() + t);
        }
        for(int i = 0; i < M; ++i) {
            int t; cin >> t;
            w.push_back(w.back() + t);
        }
        vector<int> h_cnt(1500001);
        vector<int> w_cnt(1500001);
        for(int i = 0; i <= N; ++i) {
            for(int j = i + 1; j <= N; ++j) {
                h_cnt[h[j] - h[i]] += 1;
            }
        }
        for(int i = 0; i <= M; ++i) {
            for(int j = i + 1; j <= M; ++j) {
                w_cnt[w[j] - w[i]] += 1;
            }
        }
        ll res = 0;
        for(int i = 0; i < 1500001; ++i) {
            res += h_cnt[i] * w_cnt[i];
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 14512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

			for (int i = A; i <= B; i++){

				if (i % K == 0){
					System.out.println("OK");
					return;
				}

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

	}

}


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

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

  if ((a + b) > (c + d)) {
    cout << "Left" << endl;
  }
  else if ((a + b) == (c + d)) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<int> D;

int main() {
	cin >> N;
	D.resize(N);
	for (int n = 0; n < N; n++)cin >> D[n];
	long long ans = 0;
	for (int a = 0; a < N; a++) {
		for (int b = a + 1; b < N; b++) {
			ans += D[a] * D[b];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, m,i,count=0;
	scanf("%d %d", &n, &m);
	int h[n], good[n], jSta[m], jFin[m];
	for (i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		good[i] = 0;
	}
  
	for (i = 0; i < m; i++) {
		scanf("%d %d", &jSta[i], &jFin[i]);
      if(h[jSta[i]-1] > h[jFin[i]-1]) good[jFin[i]-1]= 1;
      else if(h[jSta[i]-1] < h[jFin[i]-1])good[jSta[i]-1] = 1;
      else{good[jFin[i]-1]= 1; good[jSta[i]-1] = 1;}
	}
	for (i = 0; i < n; i++) {
		if (good[i] == 0) count++;
	}
	printf("%d", count);
}


Measured memory_bytes: 3276
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a < b && b < c) {
			System.out.println("Yes");

		}else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 26324
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
inline int getint()
{
	int r = 0,s = 0;char c = getchar();for(;!isdigit(c);c = getchar()) s |= c == '-';
	for(;isdigit(c);c = getchar()) r = (((r << 2) + r) << 1) + (c ^ '0');return s ? -r : r;
}
const int N = 2000100;
int n,m,k;
int S[N],T[N];
char buf[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	scanf("%s",buf + 1);for(int i = 1;i < N;i++) S[i] = i > n ? 0 : buf[n - i + 1] ^ '0';
	scanf("%s",buf + 1);for(int i = 1;i < N;i++) T[i] = i > m ? 0 : buf[m - i + 1] ^ '0';
	for(int i = std::max(m,n);i;i--)
	{
		if(!(S[i] == 1 && T[i] == 1)) continue;
		S[i] = T[i] = 0;
		++S[i + 1];++T[i + 1];
		int j = i + 1,t = k - 1;
		while(t)
		{
			if(S[j] == 2) ++S[j + 1],S[j] = 0;
			else if(T[j] == 2) ++T[j + 1],T[j] = 0;
			else if((S[j] == 1) && (T[j] == 1)) S[j] = T[j] = 0,--t,++S[j + 1],++T[j + 1];
			else break;
			j++;
		}
		if(S[j] == 2) ++S[j + 1],S[j] = 0;
		if(T[j] == 2) ++T[j + 1],T[j] = 0;
	}
	int p = N - 1;while(p && !S[p]) --p;
	if(p){while(p) putchar(S[p--] ^ '0');puts("");}
	else puts("0");
	p = N - 1;while(p && !T[p]) --p;
	if(p){while(p) putchar(T[p--] ^ '0');puts("");}
	else puts("0");
	return 0;
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	unordered_map<string,ll> m;
	ll count1=0,count2=0,count3=0,count4=0;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		if(s=="AC")
		{
			count1++;
		}
		else if(s=="WA")
		{
			count2++;
		}
		else if(s=="TLE")
		{
			count3++;
			
		}
		else
		{
			count4++;
		}
	}
	cout<<"AC"<<" x "<<count1<<endl;
	cout<<"WA"<<" x "<<count2<<endl;
	cout<<"TLE"<<" x "<<count3<<endl;
	cout<<"RE"<<" x "<<count4<<endl;
	
	
}

Measured memory_bytes: 3600
import heapq

n, m = map(int, input().split())
ps = list(map(lambda x: -x, map(int, input().split())))
heapq.heapify(ps)

for _ in range(m):
    p = -heapq.heappop(ps)
    heapq.heappush(ps, -(p // 2))
print(-sum(ps))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

ll culc(ll A,ll B,ll x){
    ll a,b,c,d;
    a = A / B;
    b = A % B;
    c = x / B;
    d = x % B;
    return B*a*c + a*d + b*c + (b*d)/B; 
}

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

    ll A,B,N;
    cin >> A;
    cin >> B; 
    cin >> N;

    // cout << N << "\n";

    ll result = culc(A,B,min(B-1,N));


    cout << result;
}

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

using namespace std;

bool afterHeisei(int year, int month, int day) {
    if (year > 2019)
        return true;
    else if (year == 2019)
    {
        if (month > 4)
            return true;
    }
    return false;
}

int main() {
    string input;
    cin >> input;
    int year = atoi(input.substr(0, 4).c_str());
    int month = atoi(input.substr(5, 2).c_str());
    int day = atoi(input.substr(8, 2).c_str());

    string ret = afterHeisei(year, month, day) ? "TBD" : "Heisei";
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H, W = [int(x) for x in input().rstrip().split()]
s = []
for _ in range(H):
    s.append(list(input().rstrip()))

def bomb(x, y):
    cnt = 0
    for k in [[x+1, y], [x+1, y+1], [x+1, y-1], [x, y+1], [x, y-1], [x-1, y], [x-1, y+1], [x-1, y-1]]:
        if 0 <= k[0] < H and 0 <= k[1] < W:
            if s[k[0]][k[1]] == "#":
                cnt += 1
    return str(cnt)

for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            s[i][j] = bomb(i, j)
for l in s:
    print("".join(l))

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

int main(){
    int n,x;
    cin >> n >> x;
    int l[n]={};

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

    int count=1;
    int z=0;
    for(int y=0;y<n;y++){
        z=z+l[y];
        if(z<=x){
            count++;
        }else{
            break;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int n = in.readInt();
		int x = (int)Math.sqrt(n);
		System.out.println(x*x);
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21076
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

int N;

struct G {
    int T;
    int S;
}
G[] gs;

bool input() {
    scanf("%d\n", &N);
    if (N == 0) return false;
    gs = new G[N];
    foreach (i; 0 .. N) {
        int M, L; scanf("%d %d\n", &M, &L);
        gs[i].S = L;
        foreach (j; 0 .. M) {
            int S, E; scanf("%d %d\n", &S, &E);
            for (int t = S; t < E; t++) {
                gs[i].T |= (1 << t);
            }
        }
    }
    return true;
}

void solve() {
    int dfs(int index, int T) {
        if (index == N) return 0;
        int ret = 0;
        if (!(T & gs[index].T)) {
            ret = dfs(index + 1, T | gs[index].T) + gs[index].S;
        }
        return max(ret, dfs(index + 1, T));
    }
    writeln(dfs(0, 0));
}

void main() {
    while (input) solve;
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

class UnionFind {
    size_t size;
public:
    vector<size_t> node;
    UnionFind(size_t n) : node(n), size(n) {
        for(size_t i = 0; i < n; i++) node[i] = i;
    }
    size_t root(size_t x) {
        if (node[x] == x) return x;
        return node[x] = root(node[x]);
    }
    void unite(size_t x, size_t y) {
        size_t rx = root(x);
        size_t ry = root(y);
        if (rx == ry) return;
        node[rx] = ry;
    }
    bool same(size_t x, size_t y) {
        size_t rx = root(x);
        size_t ry = root(y);
        return rx == ry;
    }
    set<size_t> roots(void) {
        set<size_t> roots;
        for(size_t _i=0; _i<size; _i++) roots.insert(root(_i));
        return roots;
    }
};

ll N, M;

int main() {
    cin >> N >> M;
    int x, y, z;
    UnionFind uf(N);
    REP(i, M) {
        cin >> x >> y >> z;
        uf.unite(--x, --y);
    }
    auto ans = uf.roots().size();
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[N+1]{};
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			for(int k=1;k<=100;k++){
				int W = i*i + j*j + k*k + i*j + j*k + k*i;
				if(W<=N) A[W]++;
			}
		}
	}
	for(int i=1;i<=N;i++){
		cout << A[i] << endl;
	}
}

Measured memory_bytes: 3680
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String s[]=line.split(" ",0);
        int n[]=new int[2];
        for(int i=0;i<2;i++){
            n[i]=Integer.parseInt(s[i]);
        }
        long num[]=new long[n[0]];
        long num1[]=new long[n[0]];
        long num2[]=new long[n[0]];
        for(int i=0;i<n[0];i++){
            line=sc.nextLine();
            String s2[]=line.split(" ",0);
            num[i]=Long.parseLong(s2[0]);
            num1[i]=Long.parseLong(s2[1]);
            num2[i]=Long.parseLong(s2[2]);
        }
        long ans=0;
        for(int i=0;i<8;i++){
            long anan=0;
            long n1[]=num;
            long n2[]=num1;
            long n3[]=num2;
            if(i==4){
                for(int k=0;k<n[0];k++)
                n1[k]*=-1;
            }
            if(i==1||i==3||i==5||i==7){
                for(int k=0;k<n[0];k++)
                n2[k]*=-1;
            }
                for(int k=0;k<n[0];k++)
                n3[k]*=-1;
            long an[]=new long[n[0]];
for(int t=0;t<n[0];t++){
//System.out.println(n3[t]);
}
            for(int j=0;j<n[0];j++){
                an[j]=n1[j]+n2[j]+n3[j];
            }

            Arrays.sort(an);
            for(int j=0;j<n[1];j++){
                anan+=an[j];
            }
//System.out.println(anan);
            if(anan>ans){
                ans=anan;
            } if(-anan>ans){
                ans=-anan;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26964
N, M, X, Y = [int(v) for v in input().split()]
x = [int(v) for v in input().split()]
y = [int(v) for v in input().split()]
x.append(X)
y.append(Y)

if max(x) < min(y):
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long dp[55][55][55*55];
int x[55];
int main()
{
	int n,a;
	cin>>n>>a;
	for(int i=1;i<=n;i++)
		cin>>x[i];
	dp[1][1][x[1]]=1;
	for(int i=2;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=a*n;k++)
			{
				dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
				if(j==1)
					dp[i][j][k]+=(x[i]==k);
			}
	long long sum=0;
	for(int i=1;i<=n;i++)
		sum+=dp[n][i][a*i];
	cout<<sum<<endl;
	return 0;
}
//

Measured memory_bytes: 65792
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
	int x,y,ans=0;
	cin >> x >> y;
	for (int i=x;i<=y;i++)
	{
		if (i%10==i/10000 && i%100/10==i%10000/1000)ans++;
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

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

const int N = 1000005;
int n, a[N];
char s[N];
bool ans;

int main() {
	scanf("%d%s", &n, s), --n;
	for(int i = 0; i <= n; ++i) {
		a[i] = s[i] - '1';
		if((n & i) == i) ans ^= a[i] & 1;
	}
	if(ans) return puts("1"), 0;
	for(int i = 0; i <= n; ++i) {
		if(a[i] & 1) return puts("0"), 0;
		a[i] >>= 1;
	}		
	ans = 0;
	for(int i = 0; i <= n; ++i) 	
		if((n & i) == i) ans ^= a[i] & 1;
	puts(ans ? "2" : "0");
	return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  vi v(n, 0);
  FOR(i, 1, n) {
    if (s[i - 1] == 'A' and s[i] == 'C') {
      v[i]++;
    }
    v[i] += v[i - 1];
  }

  REP(i, q) {
    int l, r;
    cin >> l >> r;

    l--;
    r--;
    cout << v[r] - v[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1488
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

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

    cout << (e-a <= k ? "Yay!" : ":(") << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) {
      cin >> A[i];
    }
  
    vector<int> rev(N+1);
    for (int i = 1; i <= N; i++) {
        rev[A[i]] = i;
    }

    for (int i = 1; i <= N; i++) {
        cout << rev[i] << endl;
    }
}

Measured memory_bytes: 1664