akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int main () {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n) cin >> p[i];
  vi q(n);
  rep(i,n) cin >> q[i];
  
  vector<int> v;
  rep(i,n) v.push_back(i+1);
  
  int cnt = 1;
  int a, b;
  do {
    bool match = true;
    rep(i,n) {
      if (v[i] != p[i]) {
        match = false;
        break;
      }
    }
    if (match) a = cnt;

    match = true;
    rep(i,n) {
      if (v[i] != q[i]) {
        match = false;
        break;
      }
    }
    if (match) b = cnt;

    cnt++;
  } while (next_permutation(v.begin(), v.end()));

  int ans = abs(a-b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
use std::io;
use std::cmp;
use std::collections::BinaryHeap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn find_ans(hints: Vec<(i32,i32,i32)>) -> (i32,i32,i32) {
    for i in 0..101 {
        for j in 0..101 {
            let h = hints[0].2 + (hints[0].0 - i).abs() + (hints[0].1 - j).abs();
            let res = hints.iter().any(|hint| {
                if hint.2 != 0 {
                    h != hint.2 + (hint.0 - i).abs() + (hint.1 - j).abs()
                } else {
                    (hint.0 - i).abs() + (hint.1 - j).abs() < h
                }
            });
            if !res {
                return (i,j,h);
            }
        }
    }
    (0,0,0)
}


fn main() {
    let n: usize = read_line().trim().parse().unwrap();
    let mut hints:Vec<(i32,i32,i32)> = Vec::with_capacity(n);

    for _ in 0..n {
        let xyh: Vec<i32> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        hints.push((xyh[0], xyh[1], xyh[2]));
    }
    hints.sort_by(|a,b| b.2.cmp(&a.2));

    let ans = find_ans(hints);
    println!("{} {} {}", ans.0, ans.1, ans.2);
}


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

int main() {
  string a;
  cin >> a;
  if(a.at(0)=='7'){
    cout << "Yes" << endl;
  }
  else if(a.at(1)=='7'){
    cout << "Yes" << endl;
  }
  else if(a.at(2)=='7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
 
}


Measured memory_bytes: 3636
#!/usr/bin/python
# -*- coding: utf-8 -*-

s = raw_input()
H, W = [int(x) for x in s.split()]
# H, W = 500,500
A = [None] * H

for i in xrange(H):
	s = raw_input()
	A[i] = [int(x) for x in s.split()]
	# A[i] = [j for j in xrange(W)]

choose = [[False]*W for i in xrange(H)]
answer = -1
answerOps = []
ops = []

def dfs(y, x, even):
	global H, W, A, answer, answerOps, ops

	if x >= W:
		x, y = 0, y+1
	if x == 0 and y == H:
		if even > answer:
			answer = even
			answerOps = ops
		return
	if even + (H-y-1)*W + (W-x) <= answer:
		return

	# print y, x, A[y][x], even
	# print A

	coin = A[y][x]
	if coin % 2 == 1:
		A[y][x] = 0
		if x+1 < W:
			A[y][x+1] += coin
			ops.append((y, x, y, x+1))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y][x+1] -= coin

		if y+1 < H:
			A[y+1][x] += coin
			ops.append((y, x, y+1, x))
			dfs(y, x+1, even+1)
			ops = ops[:-1]
			A[y+1][x] -= coin
		A[y][x] = coin

		dfs(y, x+1, even)
	else:
		dfs(y, x+1, even+1)


# dfs(0, 0, 0)


def check(y, x):
	if x+1 < W:
		if A[y][x+1] % 2 == 1:
			return 'right'
	if y+1 < H:
		if A[y+1][x] % 2 == 1:
			return 'down'
	if x+1 < W:
		return 'right'
	if y+1 < H:
		return 'down'

for i in xrange(H):
	for j in range(W):
		if A[i][j] % 2 == 1:
			ret = check(i, j)
			if ret == 'right':
				A[i][j+1] += A[i][j]
				answerOps.append((i, j, i, j+1))
			elif ret == 'down':
				A[i+1][j] += A[i][j]
				answerOps.append((i, j, i+1, j))

print len(answerOps)
for t in answerOps:
	print '%d %d %d %d' % tuple([x+1 for x in t])

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

int binarysearch(int* S, int size, int key)
{
    int left = 0, right = size;
    int mid;

    while(left < right){
        mid = (left + right) / 2;
        if(S[mid] == key){
            return mid;
        }else if(key < S[mid]){
            right = mid;
        }else if(key < S[mid + 1]){
            return size;
        }else{
            left = mid + 1;
        }
    };
    return size;
}

int main()
{
    int i, n, q, S[1000000], T[500000], C;
    cin >> n;
    for(i = 0; i < n; i++) cin >> S[i];
    cin >> q;
    for(i = 0; i < q; i++) cin >> T[i];

    C = 0;
    for(int i = 0; i < q; i++){
        if(binarysearch(S, n, T[i]) < n) C++;
    }
    cout << C << endl;

    return 0;
}

Measured memory_bytes: 3604
package main
import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string


	fmt.Scanf("%d",&n)
	fmt.Scanf("%s",&s)

	ans := 0

	for i,_ := range s {
		a := s[0:i+1]
		b := s[i+1:n]

		ans2 := 0
		for j:= 0; j<26; j++ {
			va := strings.Count(a,string(j+97))
			vb := strings.Count(b,string(j+97))
			if va > 0 && vb > 0 {
				ans2++
				
			}
		}
		if ans2 > ans {
			ans = ans2
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.nio.file.FileSystemAlreadyExistsException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<String> words = new ArrayList<>();
        boolean failed = false;

        for (int i = 0; i < N; i++) {
            String currentWord = sc.next();
            
            if (i == 0) {
                words.add(currentWord);
            } else {
                String prevWord = words.get(words.size() - 1);
                if (prevWord.substring(prevWord.length() - 1, prevWord.length()).equals(currentWord.substring(0, 1))) {
                    boolean sameWordFlg = false;
                    for (String element : words) {
                        if (element != null && element.equals(currentWord)) {
                            sameWordFlg = true;
                            break;
                        }
                    }
                    if (!sameWordFlg) {
                        words.add(currentWord);
                    } else {
                        failed = true;
                    }
                }  else {
                    failed = true;
                }
            }
        }

        if (failed) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N;
  cin >> N;

  ll ans = 0;
  for (ll x = 1; x <= N; x += 2)
  {
    ll X = x;

    ll cnt = 0;
    for (ll d = 1; d <= X; d++)
    {
      if (X % d == 0)
        cnt++;
    }
    if (cnt == 8)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}


int main(){ 
  int a, b, c;
  cin >> a >> b >> c;
  for(int i = 1;i <= b;i++){
    if((a * i) % b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 3568
'use strict'

function main(input) {
  let nums = input
    .split('')
    .map(v => ~~v)
    .slice(0, -1)
  let n = nums.length
  let blue = nums.reduce((a, c) => a + c)
  let red = n - blue

  console.log(Math.min(red, blue) * 2)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main () {
    int N, M;
    string S;

    cin >> N >> S;

    if (S.substr(0, N/2) == S.substr(N/2, N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main(){
int n;

double res,part=0;
cin>>n;
double a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<n;i++){
    part=part+(1/a[i]);
}
res=1/part;
cout<<res<<endl;
    

    return 0;
}


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

int main(){
  while(1){
    int n,p;
    cin >> n >> p;
    if(n == 0&& p == 0)break;
    int owan = p;
    vector<int> human(n,0);
    int current = 0;
    while(1){
      if(owan > 0){
	human[current]++;
	owan--;
      }else{
	if(human[current] == p){
	  
	  break;
	}else{ 
	  owan = human[current];
	  human[current] = 0;
	}
      }
      current++;
      if(current == n)current = 0;
      //      cout << current << " debug" << endl;
    }
    cout << current << endl;
  }
  return 0;
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

void solve(){
        
    //     int a,b,c,d,fo = 1;
    //     cin >> a >> b >> c >> d;
    //     while(true){
    //         if(min(a,b) >= max(c,d)){fo = 1;break;}
    //         else {
    //             if(c < d)swap(c,d);
    //             if(a < b)swap(a,b);
    //             d -= b;
    //             c -= b;
    //         }
    //         if(min(c,d) >= max(a,b)){fo = 0;break;}
    //         else {
    //             if(c < d)swap(c,d);
    //             if(a < b)swap(a,b);
    //             b -= d;
    //             a -= d;
    //         }
    //     }
    // if(fo)cout << "Yes\n";
    // else cout << "No\n";    
    int n;
    cin >> n;
    set<string>s;
    for(int i = 0;i < n;++i){
        string x;
        cin >> x;
        s.insert(x);
    }
    cout << sz(s) << "\n";
}

signed main()
{
    showoff;
    int t;
    //cin >> t;
    t = 1;
    while(t--){
        solve();
    }
    
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 


Measured memory_bytes: 19188
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
ll fpow(ll x,ll y){x=x%MOD;ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  ll n,w;
  cin>>n>>w;
  ll dp[100005];
  for(int i=0;i<100005;i++)
  dp[i]=1e18;
  dp[0]=0;
  ll wt[n],val[n];
  for(int i=0;i<n;i++)
  cin>>wt[i]>>val[i];
  for(int i=0;i<n;i++)
  {
    for(int j=100000;j>=val[i];j--)
    dp[j]=min(dp[j],dp[j-val[i]]+wt[i]);

  }
  ll res=0;
  for(int i=1;i<=100000;i++)
  {
    if(dp[i]<=w)
    res=i;
  }
  cout<<res;

}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <sstream>

using namespace std;
string bubble_sort(string, int, int&);
string select_sort(string, int, int&, int&);
string stringArrayToString(string*, int);

int main()
{
	string str;
	getline(cin, str);
	int num;
	stringstream num_ss(str);
	num_ss >> num;

	getline(cin, str);
	int counter = 0;
	int stability = 0;

	cout << bubble_sort(str, num, counter) << endl;
	cout << "Stable" << endl;
	cout << select_sort(str, num, counter, stability) << endl;
	cout << (stability == 0 ? "Stable" : "Not stable") << endl;
	return 0;
}
string bubble_sort(string str, int ary_size, int &counter) {
	string* ary = new string[ary_size];
	stringstream ss(str);
	string buff;
	int cnt = 0;
	while (getline(ss, buff, ' ')) {
		stringstream tss(buff);
		tss >> ary[cnt];
		cnt++;
	}

	// main.
	for (int j = ary_size - 2; j >= 0; j--) {
		for (int i = 0; i <= j; i++) {
			if (ary[i + 1][1] < ary[i][1]) {
				string tmp = ary[i];
				ary[i] = ary[i + 1];
				ary[i + 1] = tmp;
				counter++;
			}
		}
	}
	return stringArrayToString(ary, ary_size);
}

string select_sort(string str, int ary_size, int &counter, int &stability) {
	string* ary = new string[ary_size];
	stringstream ss(str);
	string buff;
	int cnt = 0;
	while (getline(ss, buff, ' ')) {
		stringstream tss(buff);
		tss >> ary[cnt];
		cnt++;
	}

	// main.
	// stability 0: stable, 1: not-stable

	for (int i = 0; i < ary_size; i++) {
		int min = i;
		int same_num_lst = -1;
		int stbl_flg = 0;

		for (int j = i + 1; j < ary_size; j++) {
			if (ary[i][1] == ary[j][1]) {
				stbl_flg = 1;
			}

			if (ary[min][1] > ary[j][1]) {
				min = j;
			} 
		}
		
		if (min != i) {
			string tmp = ary[min];
			ary[min] = ary[i];
			ary[i] = tmp;
			counter++;

			if (stbl_flg == 1) {
				stability = 1;
			}
		}
	}

	return stringArrayToString(ary, ary_size);
}
string stringArrayToString(string* ary, int ary_size) {
	string str = "";
	for (int i = 0; i < ary_size; i++) {
		if (i == ary_size - 1) {
			str += ary[i];
		}
		else {
			str += ary[i] + " ";
		}
	}
	return str;
}

Measured memory_bytes: 3208
#include <stdio.h>
 
#define S(num)  ((num) * (num))
#define H(n)    ((5.0) * (n) - (5.0))
 
int main(void)
{
    float in_data;
    float time;
    float high;
    int i;
     
    while (scanf("%f", &in_data) != EOF){
        in_data*=in_data/19.6;
        i = 0;
        while (1)if (++i-1. >= in_data/5) break;
         
        printf("%d\n", i);
    }
     
    return (0);
}

Measured memory_bytes: 624
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

ar = [0]*n

for k in range(n):
  for j in range(n):
    if j <= k:
      ar[k] += x[j]
    if j >= k:
      ar[k] += y[j]
print(max(ar))

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<char> A){rep(i,A.size()){cout << A[i];}cout << endl;}
void print(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << endl;}

int main(){
    string s;
    cin >> s;
    int cnt1 = 0,cnt2 = 0;
    rep(i,s.size()){
        if (s[i] == '1')cnt1++;
        else cnt2++;
    }
    cout << 2*min(cnt1,cnt2) << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

public class Program
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        long a = long.Parse(s[0]);
        long b = long.Parse(s[1]);
        long x = long.Parse(s[2]);
        long ans = 0;
        ans = (b / x) - (a / x);
        if (a % x == 0) ans += 1;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
# coding: utf-8
# Your code here!
def max_heapify(A, idx):
    left = (idx+1)*2-1
    right = (idx+1)*2
    #print('idx={}, left={}, right={}'.format(idx, left, right))
    largest = idx
    if left < len(A) and A[largest] < A[left]:
        largest = left
    if right < len(A) and A[largest] < A[right]:
        largest = right
    if largest != idx:
        A[idx], A[largest] = A[largest], A[idx]
        max_heapify(A, largest)

def build_max_heap(A):
    #print(*A)
    for i in range(len(A)//2, -1, -1):
        max_heapify(A, i)
        #print('{}:'.format(i), *A)
    
n = int(input())

a = [int(i) for i in input().split()]

build_max_heap(a)

print('', *a)



Measured memory_bytes: 63968
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define for1(i, a, b) for(i = a; i <= b; ++i)
#define for0(i, a, b) for(i = a; i < b; ++i)
#define forw1(i, a, b) for(i = a; i >= b; --i)
#define forw0(i, a, b) for(i = a - 1; i >= b; --i)
#define fora(v, a) for(auto v : a)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

using namespace std;
using cd = complex<double>;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<cd> vcd;
typedef vector<ii> vii;
typedef vector<vector<int> > vvi;

const int modd1 = 1e9 + 7, modd2 = 998244353, maxn = 10, K = 26;
const double pi = acos(-1);
int n, m;

void solve(){
	int i, j, k, l, r;
	cin >> n >> k;
	int p[n + 4];
	for1(i, 1, n){
		cin >> p[i];
	}
	sort(p + 1, p + n + 1);
	int ans = 0;
	for1(i, 1, k){
		ans += p[i];
	}
	cout << ans;
}

signed main() {
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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 C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 2000
#define K10 10000
#define K5 5000
#define K1 1000

i64 N, Y;

void solve() {
  i64 rem, k;
  for (i64 i = 0; i <= N; i++) {
    for (i64 j = 0; (i + j) <= N; j++) {
      rem = Y - K10 * i - K5 * j;
      if (rem < 0) continue;
      if (rem % K1 == 0) {
        k = rem / K1;
        if (i + j + k == N) {
          cout << i << " " << j << " " << k << endl;
          return;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

int main() {
  cin >> N >> Y;

  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
  int n;
  ll a,b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  ll ans = 0;
  for(int i=1;i<n;i++){
    ans += min(b,(x[i]-x[i-1])*a);
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int H, W, M;
set<i_i> st;

void input() {
    cin >> H >> W >> M;
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        st.insert({a, b});
    }
}

void solve() {
    map<int, int> mph, mpw;
    int hmaxval = 0;
    int wmaxval = 0;
    vector<int> hmax, wmax;
    for(auto tmp : st) {
        chmax(hmaxval, ++mph[tmp.first]);
        chmax(wmaxval, ++mpw[tmp.second]);
    }
    for(auto tmp : mph) {
        if(hmaxval == tmp.second) hmax.push_back(tmp.first);
    }
    for(auto tmp : mpw) {
        if(wmaxval == tmp.second) wmax.push_back(tmp.first);
    }
    int ANS = hmaxval + wmaxval - 1;
    for(auto h : hmax) {
        for(auto w : wmax) {
            if(st.find({h, w}) == st.end()) {
                ANS++;
                cout << ANS << endl;
                return;
            }
        }
    }
    cout << ANS << endl;
}

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

Measured memory_bytes: 49572
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.array;
import std.typecons;
import std.container;

void main() {
	auto inp = readln.split.map!(to!int);
	int N = inp[0], R = inp[1], L = inp[2];
	alias Tuple!(int, "point", int, "time") Team;
	Team[] datas = new Team[N];
	foreach (i; 0..N) datas[i] = tuple(0, 0);
	int t = 0;
	alias Tuple!(int, "id", int, "point") MaxInfo;
	MaxInfo maxInfo = tuple(0,0);
	foreach (i; 0..R) {
		auto input = readln.split.map!(to!int).array;
		input[0]--;
		datas[input[0]].point += input[2];
		auto t2 = input[1];
		datas[maxInfo.id].time += t2 - t;
		if (datas[input[0]].point > maxInfo.point || (datas[input[0]].point == maxInfo.point && input[0] < maxInfo.id)) {
			maxInfo = tuple(input[0], datas[input[0]].point);
		} else if (maxInfo.id == input[0]) {
			int max = 0, id = 0;
			foreach (j; 0..N) {
				if (datas[j].point > max) {
					max = datas[j].point;
					id = j;
				}
			}
			maxInfo = tuple(id, max);
		}
		t = t2;
	}
	datas[maxInfo.id].time += L - t;
	int max = 0;
	int maxId = 0;
	foreach(i; 0..N) {
		if (datas[i].time > max) {
			max = datas[i].time;
			maxId = i;
		}
	}
	writeln(maxId+1);
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const ll mod=1e9+7;
const ll inf=1e16;
const ll N=1e5+10;

int main()
{
	boost;
	ll n;
	cin>>n;
	ll a[n+1],b[n];
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=min(a[i],b[i]);
		ll temp=min(a[i],b[i]);
		b[i]-=temp;
		a[i]-=temp;
		temp=min(a[i+1],b[i]);
		b[i]-=temp;
		a[i+1]-=temp;	
		ans+=temp;
	}
	cout<<ans;	
	return 0;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	cout << (h * w - w * a - h * b + a * b) << endl;
	return 0;
}
 

Measured memory_bytes: 256
using System;

class main{
  static void Main(string[] args){
    string[] s = Console.ReadLine().Split(" ");
    int tap = int.Parse(s[0])-1;
    int sockets = int.Parse(s[1]);
    if(sockets == 1){
      Console.Write("0");
      return;
    }
    
    for(int i = 1; i != 0; i++){
      if(tap * i + 1 >= sockets){
        Console.Write(i);
        break;
      }
    }
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);
    rep(i,N-1) cin >> C.at(i) >> S.at(i) >> F.at(i);
    for (int i = 0; i < N; ++i) {
        if (i == N - 1) {
            cout << 0 << endl;
        } else {
            int ans = 0;
            for (int j = i; j < N - 1; ++j) {
                if (ans >= S.at(j)) ans += (F.at(j) - ans % F.at(j)) % F.at(j) + C.at(j);
                else ans = S.at(j) + C.at(j);
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s, a = "ACGT";
int res, l;

signed main() {
	cin >> s;
	each(i,s) {
		if (count(all(a), i)) l++;
		else l = 0;
		chmax(res, l);
	}
	cout << res << endl;
}

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

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

		for(;;){
			int h = scan.nextInt();
			int w = scan.nextInt();

			if(h == 0 && w == 0)
				break;

			String ht = String.join("", Collections.nCopies(w, "#"))+"\n";
			String md = "#"+String.join("", Collections.nCopies(w-2, "."))+"#\n";
			System.out.println(ht + String.join("", Collections.nCopies(h-2, md)) + ht);
		}
	}
}



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

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

const int MAX_N = 200100;
int n, k;
int p[MAX_N];
double e[MAX_N];
double res = 0;
double ans;

double E (int n) {
    double ev = (double)(n + 1) / 2.0;
    return ev;
}

int main() {

    cin >> n >> k;
    rep(i, n) {
        cin >> p[i];
        e[i] = E(p[i]);
        if(i < k) res += e[i];
    }


    ans = res;
    for (int i = 0; i < n - k; i++) {
        res =  res - e[i] + e[i+k];
        if (ans < res) ans = res;
    }

    cout << fixed;
    cout << std::setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
from math import *
while True:
    n = input()
    if n==0:
        break
    score_li = map(int,raw_input().split())
    score_sum = sum(score_li)
    ave = score_sum/float(n)
    variance = 0
    for i in xrange(n):
        variance += (score_li[i]-ave)**2
    variance /=float(n)
    sd = sqrt(variance) #sd:standard deviation
    print sd

Measured memory_bytes: 6560
c,d,s="%d %d\n";main(a,b,n){for(;scanf(s+3,&n),n;printf(s,c,d))for(c=d=0;n--;*(a<b?&d:&c)+=a,*(b<a?&c:&d)+=b)scanf(s,&a,&b);}

Measured memory_bytes: 0
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const N = lines[0] - 0
    const A = lines[1].split(' ').map(Number)

    let odd = 0
    for (let i = 0; i < N; i++) {
      odd += A[i] % 2
    }

    console.log(odd % 2 ? 'NO' : 'YES')

})(input)


Measured memory_bytes: 40312
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]

ans = 10 ** 5
for bit in range(2 ** (H - 1)):    
    cur = [0] * H
    gnum = 0

    # Group each row
    for i in range(H - 1):
        if not (bit & (1 << i)):
            cur[i + 1] = cur[i]
        else:
            cur[i + 1] = cur[i] + 1
            gnum += 1

    gok = True
    add = 0
    nums = [0] * (gnum + 1)
    # For each column
    for j in range(W):
        ones = [0] * (gnum + 1)
        ok = True
        # For each row
        for i in range(H):
            ones[cur[i]] += int(S[i][j])
            nums[cur[i]] += int(S[i][j])
            if ones[cur[i]] > K: gok = False;
            if nums[cur[i]] > K: ok = False;
                
        if not ok:
            add += 1
            nums = ones[:]
            
    if gok:
        ans = min(ans, gnum + add)
                
    
print(ans)


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

int main(){


  int a,b,c,d;
  
  cin >> a>>b>>c>>d;

  
  cout<< (a+b+c+d)/60 <<endl<< (a+b+c+d)%60 <<endl;


  
  
  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll max_d = 40 * 10;
        ll n, d;
        cin >> n >> d;

        vvl x(n, vl(d));
        rep(i, n) rep(j, d) cin >> x[i][j];

        ll ans = 0;
        rep(i, n - 1) {
            for (long long j = i + 1; j < n; ++j) {
                ll cal = 0;
                rep(k, d) {
                    cal += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                rep(k, max_d + 1) {
                    if (k * k == cal) ans++;
                }
            }
        }
        cout << ans << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  long long x=1;
  int count=0;
  while(1){
    if(x>n)break;
    x*=k;
    count++;
  }
  cout<<count<<endl;
  return 0;
}

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

int main() {
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  int A=a-'0', B=b-'0', C=c-'0', D=d-'0';
  string ansab,ansbc,anscd;
  
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
        int seven=A;
        
        if(i==0)
          seven+=B;
        else
          seven-=B;
        
        if(j==0)
          seven+=C;
        else
          seven-=C;

        if(k==0)
          seven+=D;
        else
          seven-=D;
        
        if(seven==7){
          ansab = i==0 ? "+":"-";
          ansbc = j==0 ? "+":"-";
          anscd = k==0 ? "+":"-";
        }
      }
    }
  }
  cout<<a+ansab+b+ansbc+c+anscd+d<<"=7"<<endl;
}


Measured memory_bytes: 3596
let () =
  let n = read_int () in
  let r1 = read_int () in
  let r2 = read_int () in
  let rec iter mp mr m =
    if m = 0 then mp
    else let r = read_int () in
         iter (max mp (r - mr)) (min mr r) (m-1) in
  iter (r2 - r1) (min r1 r2) (n-2) |> string_of_int |> print_endline

Measured memory_bytes: 4308
import java.util.*;

public class Main {
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long K = scanner.nextLong();
        ArrayList<Long> already = new ArrayList<>();
        long minAnswer = N;
        minAnswer = Math.min(N%K, Math.abs(N%K-K));
        System.out.println(minAnswer);
    }
}


Measured memory_bytes: 22996
#include<cstdio>
#include<cmath> 
using namespace std;
long long n,ans;
int s;
int main() {
	scanf("%lld",&n);
	for(int i=sqrt(n); i>0; --i)
		if(n%i==0) {
			ans=n/i;
			break;
		}
	while(ans>0) {
		++s;
		ans/=10;
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  char e;
  cin>>e;
  if(e>='A' && e<='Z') cout<<"A";
  else cout<<"a";
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3636
// https://atcoder.jp/contests/abc136/tasks/abc136_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn isok(a: &Vec<i32>, d: i32, k: i32) -> bool {
    let n = a.len();
    let mut modulo = vec![];
    for ai in a {
        if ai % d >= 1 {
            modulo.push(ai%d);
        }
    }
    modulo.sort();

    let n = modulo.len();
    let mut sum = vec![0; n+1];
    for i in 0..n {
        sum[i+1] = sum[i] + modulo[i];
    }
    let cnt = (sum[n] / d) as usize;

    let mut best = k+1;
    for i in 0..n {
        let mut up = 0;
        for j in i..i+cnt {
            up += modulo[j%n];
        }
        let dw = sum[n] - up;
        let up = (d * cnt as i32) - up;
        if (max(up, dw) - min(up, dw)) % d == 0 {
           best = min(best, max(up, dw));
        }
    }
    best <= k
}

fn main() {
    input! {
        n: usize, k: i32,
        a: [i32; n]
    };
    let sum = a.iter().fold(0, |a,c| a+c);

    let mut divisors = vec![];
    for w in 1..sum+1 {
        if w * w >= sum {
            if w * w == sum {
                divisors.push(w);
            }
            break;
        }
        if sum % w == 0 {
            divisors.push(sum/w);
            divisors.push(w);
        }
    }
    divisors.sort();
    divisors.reverse();

    let mut ans = 1;
    for d in divisors {
        if isok(&a, d, k) {
            ans = d;
            break;
        }
    }

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


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()

int main() {
    long long n,k;
    cin >> n >> k;
    long long count = 0;
    while(n>0){
        n /= k;
        count++;
    }
    dunk(count);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(void)
{
	double r;
	
	std::cin >> r;
	std::cout << fixed << std::setprecision(6) << r * r * M_PI << " " << fixed << std::setprecision(6) << 2.0 * M_PI * r << std::endl;
	
	return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323


void solve()
{
       ll n, W;
       cin >> n >> W;
       vector<ll> dp(W+1);
       for(ll item = 0; item < n; item++){
              ll weight, value;
              cin >> weight >> value;
              for(ll weight_already = W - weight; weight_already >=0; weight_already--){  // direction of this loop would have been reverse if we could take one item more than once
                     dp[weight_already+weight] = max(dp[weight_already+weight], dp[weight_already] + value);
              }
       }
       ll ans=0;
       rep(i, 0, W+1) ans = max(ans, dp[i]);
       cout << ans;
}



int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

template<class Key, class T>
class pair_radix_heap_64 {
    using key_type = Key;
    using value_type = std::pair<key_type, T>;
    using const_reference = const value_type&;
    using size_type = size_t;

    size_type sz;
    key_type last;
    std::vector<std::vector<value_type>> v;

    size_type find_bucket(key_type a) {
        return a ? 64 - __builtin_clzl(a) : 0;
    }

public:
    pair_radix_heap_64() : sz(0), last(0), v(65) {}

    const size_type size() noexcept {
        return sz;
    }

    template<class... Args>
    void emplace(key_type key, Args... args){
        assert(key >= last);
        auto k = find_bucket(key ^ last);
        v[k].emplace_back(key, T(std::forward<Args>(args)...));
        if(v[k][0] > v[k].back())std::swap(v[k][0], v[k].back());
        ++sz;
    }

    void pull(){
        assert(sz >= 0);
        if(!v[0].empty())return;

        size_type i = 0;
        while(v[++i].empty());
        last = v[i][0].first;
        for(const auto& j : v[i]){
            auto k = find_bucket(j.first ^ last);
            v[k].push_back(j);
            if(v[k][0] > v[k].back())std::swap(v[k][0], v[k].back());
        }
        v[i].clear();
    }

    const_reference top(){
        pull();
        return v[0].back();
    }

    void pop(){
        pull();
        v[0].pop_back();
        --sz;
    }
};

int main() {
    using namespace std;
    unsigned long X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<unsigned long> A(X), B(Y), C(Z);
    for(auto &i : A)cin >> i;
    for(auto &i : B)cin >> i;
    for(auto &i : C)cin >> i;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    auto def = A.back() + B.back() + C.back();

    for(unsigned long i = 0; i + 1 < X; ++i)A[i] = A[i + 1] - A[i];
    for(unsigned long i = 0; i + 1 < Y; ++i)B[i] = B[i + 1] - B[i];
    for(unsigned long i = 0; i + 1 < Z; ++i)C[i] = C[i + 1] - C[i];
    A.pop_back();
    B.pop_back();
    C.pop_back();
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    reverse(C.begin(), C.end());

    unordered_map<unsigned long, bool> mp;
    //priority_queue<pair<unsigned long, unsigned long>> pq;
    pair_radix_heap_64<unsigned long, unsigned long> pq;
    constexpr unsigned long mask = numeric_limits<unsigned long>::max();
    pq.emplace(~def, 0);
    mp[0] = true;

    unsigned long cnt{0};
    while(cnt != K){
        ++cnt;
        auto tmp = pq.top();
        cout << ~tmp.first << endl;
        pq.pop();
        auto x = tmp.second & 1023, y = (tmp.second >> 10) & 1023, z = (tmp.second >> 20) & 1023;
        if(x + 1 != X && !mp[tmp.second + 1]){
            pq.emplace(~(~tmp.first - A[x]), tmp.second + 1);
            mp[tmp.second + 1] = true;
        }
        if(y + 1 != Y && !mp[tmp.second + 1024]){
            pq.emplace(~(~tmp.first - B[y]), tmp.second + 1024);
            mp[tmp.second + 1024] = true;
        }
        if(z + 1 != Z &&!mp[tmp.second + 1048576]){
            pq.emplace(~(~tmp.first - C[z]), tmp.second + 1048576);
            mp[tmp.second + 1048576] = true;
        }
    }

    return 0;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    StringBuilder sb1 = new StringBuilder();
    for (int i = 0; i < b; i++) sb1.append(a);
    StringBuilder sb2 = new StringBuilder();
    for (int i = 0; i < a; i++) sb2.append(b);
    if (sb1.toString().compareTo(sb2.toString()) < 0) {
      System.out.println(sb1.toString());
    } else {
      System.out.println(sb2.toString());
    }
  }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define MAXN 10000

using namespace std;
typedef long long ll;

int main()
{
	//freopen("t.txt","r",stdin);
	string s;
	cin>>s;
	int a[30]={0};
	
	for (int i=0;i<4;i++){
		int tmp = s[i]-'A';
		a[tmp]++;
	}
	int d=0;
	for (int i=0;i<26;i++)	{
		if (a[i]==2){
			d++;	
		}
		
	}
	if (d==2){
		cout<<"Yes";return 0;
	}
	cout<<"No"; return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int main(void){
  int X = 2000001;
  int a, b;
  cin >> a >> b;
  for(int i = b-a+1; i < b+a; i++){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    string s;
    cin>>s;
    string ans = "2018";
    ans += s.substr(4, 6);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256