akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var x int

func main() {
	tmp := NextIntsLine()
	x = tmp[0]
	answer := 0
	q := x / 11
	answer += 2 * q
	r := x % 11
	if r == 0 {
		answer += 0
	} else if r <= 6 {
		answer += 1
	} else {
		answer += 2
	}
	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
   int n;
   scanf("%d",&n);
   for(int i = 1;i <= n;++i){
     int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
     if(a*a+b*b==c*c||a*a+c*c == b*b||b*b+c*c == a*a){
     printf("YES\n");
}else{
     printf("NO\n");
}

}
}


Measured memory_bytes: 1008
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var list = nextIntArray();
	list.sort(function(a,b){
		return b - a;
	});
	var output = 0;
	for(var i = 0; i < K; i++){
		output += list[i];
	}
	myout(output);
}


Measured memory_bytes: 7628
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int keta_k(int n, int k)
{
	int keta = 0;
	while (n)
	{
		n /= k;
		keta++;
	}
	return keta;
}

int div_round(int a, int m)
{
	return (2 * a + m) / (2 * m);
}

int heikin(const std::vector<int> &X, int N)
{
	int sum = std::accumulate(begin(X), end(X), 0);
	return div_round(sum, N);
}

int main()
{
	int N;
	std::cin >> N;
	std::vector<int> X(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> X[i];
	}

	int P = heikin(X, N);
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		int d = X[i] - P;
		ans += d * d;
	}

	std::cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#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 mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// -------------------------------------------------------------------------------------

ll solve(vector<int> a) {
  ll res = 0, _sum = 0;
  bool is_sei = true;

  for(auto ai : a) {
    if((is_sei && _sum+ai>0) || (!is_sei && _sum+ai<0)) {
      _sum = _sum + ai;
    } else {
      if(is_sei) {
        res += 1 - (_sum + ai);
        _sum = 1;
      } else {
        res += 1 + (_sum + ai);
        _sum = -1;
      }
    }
    is_sei = !is_sei;
  }
  return res;
}

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

  vector<int> a(n);
  rep(i, n) cin >> a[i];

  if(a[0] < 0) {
    rep(i, n) a[i] = -a[i];
  }
  ll ans1 = solve(a);
  rep(i, n) a[i] = -a[i];
  ll ans2 = solve(a);

  cout << min(ans1, ans2) << endl;

  return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	ll A, B, C;
	cin >> A >> B >> C;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) cout << 0 << endl;
	else cout << min({ A * B, B * C, C * A }) << endl;
}

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

int main(){
    int n,k;
    cin >> n;
    cin >> k;
    int arr[n];
      for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    int dp[n];
      dp[0] = 0;
      dp[1] = abs(arr[0] - arr[1]);
      for(int i=2;i<n;i++){
        int min = -1;
        for(int j=1;j<=k;j++){
            if(i - j >= 0){
                int price = abs(arr[i] - arr[i - j]) + dp[i - j];
                if(min == -1 || min > price) min = price; 
            }else break;
        }
        dp[i] = min;
    }
      cout<< dp[n-1];
      return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
ll mod=1000000007;
typedef pair<int,int> P;

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> vt[N];
    for(int i=0; i<N-1; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        vt[a].push_back(b);
        vt[b].push_back(a);
    }
    vector<ll> posi_num(N);
    int flag[N];
    memset(flag, 0, sizeof(flag));
    flag[0]=true;
    posi_num[0]=K;
    queue<int> que;
    for(int i=0; i<vt[0].size(); i++){
        posi_num[vt[0][i]]=K-1-i;
        flag[vt[0][i]]=true;
        que.push(vt[0][i]);
    }

    while(que.size()!=0){
        int now=que.front();que.pop();
        int no_cnt=0;
        for(int i=0; i<vt[now].size(); i++){
            if(flag[vt[now][i]]==true){
                no_cnt++;
                continue;
            }
            flag[vt[now][i]]=true;
            posi_num[vt[now][i]]=K-2-i+no_cnt;
            que.push(vt[now][i]);
        }
    }
    ll ans=1;
    for(int i=0; i<N; i++){
        ans*=(ll)posi_num[i];
        ans%=mod;
    }
    cout << ans%mod << endl;


    

    return 0;
}

Measured memory_bytes: 7672
N = int(input())
d = [input() for i in range(N)]

# dを降順にソート
d.sort(reverse=True)

# 段数をカウント(1段からスタート)
count = 1

for i in range(1, N):
    if d[i] < d[i-1]:
        count += 1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;


int main(){
  string s; cin >> s;
  
  int d;
  if(s=="SUN") d = 7;
  else if(s=="MON") d = 6;
  else if(s=="TUE") d = 5;
  else if(s=="WED") d = 4;
  else if(s=="THU") d = 3;
  else if(s=="FRI") d = 2;
  else d = 1;
  
  cout << d << endl;
  
  return 0;
}

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

int main(int argc, const char * argv[]) {
    vector<string> v(3);
    for(int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    for(int i = 0; i < 3; i++) {
        cout << v[i][i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
sm = 0
x = 0
for _a in a:
  sm += abs(_a - x)
  x = _a
for i in range(1,n + 1):
  print(sm - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]))


Measured memory_bytes: 14048
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim H As Integer = NextInt()
        Dim W As Integer = NextInt()
        Dim cnt As Integer

        For i As Integer = 0 To H - 1
            Dim Ai As String = ReadLine()
            For Each c As Char In Ai
                If c = "#"c Then cnt += 1
            Next
        Next

        If cnt = H + W - 1 Then
            WriteLine("Possible")
        Else
            WriteLine("Impossible")
        End If
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20560
#include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int H, N, P, M, K, of[600];
double dp[600][128][128];

int main() {
    scanf("%d%d%d%d%d", &H, &N, &P, &M, &K);
    P--;
    memset(of, -1, sizeof(of));
    rep(i, M) {
        int A, B;
        scanf("%d%d", &A, &B);
        of[H-A] = B-1;
    }
    dp[0][0][P] = 1;
    int fix = 0;
    rep(k, H) {
        if(of[k]!=-1) fix++;
        rep(i, K+1) rep(j, N) {
            if(of[k]!=-1) {
                if(j==of[k]) dp[k+1][i][j+1] += dp[k][i][j];
                else if(j-1==of[k]) dp[k+1][i][j-1] += dp[k][i][j];
                else dp[k+1][i][j] += dp[k][i][j];
            }
            else {
                const double p = (double)(K-i)/(H-k-M+fix);
                dp[k+1][i][j] += dp[k][i][j]*(1-p);
                if(N==1) dp[k+1][i+1][j] += dp[k][i][j]*p;
                else {
                    int c = N-1;
                    if(j<N-1) {
                        dp[k+1][i+1][j+1] += dp[k][i][j]*p/(N-1);
                        c--;
                    }
                    if(j>0) {
                        dp[k+1][i+1][j-1] += dp[k][i][j]*p/(N-1);
                        c--;
                    }
                    dp[k+1][i+1][j] += dp[k][i][j]*p*c/(N-1);
                }
            }
        }
    }
    double ans = 0;
    rep(i, N) if(ans<dp[H][K][i]) ans=dp[H][K][i];
    printf("%.9f\n", ans);
    return 0;
}

Measured memory_bytes: 0
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
    // br = black_row, bc = black_column
    // 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    // マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
	
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            // マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        // 上から1行ずつ出力していく
        // 黒が少なくとも1マス含まれる行のみ実行
        if(br[i] == 1){
            // このfor文が実行される行には黒が少なくとも1マス含まれている
            for(j = 0; j < col; j++){
                // 黒が少なくとも1マス含まれる列のみ実行
                if(bc[j] == 1){
                    // マス目を出力
                    printf("%c", sq[i][j]);
                }
            }
            // 改行を出力
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


int main(){
  int n;
  cin >> n;
  bool flag = false;
  if(n % 2 == 0){
    string s;
    cin >> s;
    string u = s.substr(0, n/2);
    string t = s.substr(n/2);
    if(u==t) flag= true;
  }
  if(flag) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}
  

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

int main(){
  ll a,b,n,ans=(1e18);
  cin>>a>>b>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++)
      if(b%i==0)ans=min(ans,llabs(a-b/i*j));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1160
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
const int N=1e5;
struct S1{
	#define ls (p<<1)
	#define rs (p<<1|1)
	int tree[(N<<3)+10];
	void pushdown(int p){
		if (!tree[p])	return;
		tree[ls]=tree[rs]=tree[p];
		tree[p]=0;
	}
	void Modify(int p,int l,int r,int x,int y,int v){
		if (x>y)	return;
		if (x<=l&&r<=y){
			tree[p]=v;
			return;
		}
		pushdown(p);
		int mid=(l+r)>>1;
		if (x<=mid)	Modify(ls,l,mid,x,y,v);
		if (y>mid)	Modify(rs,mid+1,r,x,y,v);
	}
	int Query(int p,int l,int r,int x){
		if (l==r)	return tree[p];
		pushdown(p);
		int mid=(l+r)>>1;
		if (x<=mid)	return Query(ls,l,mid,x);
		else	return Query(rs,mid+1,r,x);
	}
	#undef ls
	#undef rs
}ST;//Segment Tree
int A[N+10],B[N+10];
int L[N+10],R[N+10];
ll sum[N+10],f[N+10];
int list[(N<<1)+10];
int n,K,T,tot;
ll Get(int x){
	int tmp=ST.Query(1,1,T,x);
	if (!tmp)	return 0;
	return f[tmp]+(list[L[tmp]]-list[x]+K)%K;
}
int main(){
	n=read(),K=read();
	bool flag=0;
	for (int i=1;i<=n;i++){
		A[i]=read(),B[i]=read();
		sum[i]=sum[i-1]+A[i];
		if (B[i]==2)	continue;
		if (2*A[i]>K)	flag=1;
	}
	if (flag){
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=n;i++){
		if (B[i]==1){
			L[i]=(-2*sum[i-1]%K+K)%K;
			R[i]=(-2*sum[i  ]%K+K)%K;
		}else	L[i]=0,R[i]=K-1;
		list[++tot]=L[i];
		list[++tot]=R[i];
	}
	sort(list+1,list+1+tot);
	T=unique(list+1,list+1+tot)-list-1;
	for (int i=1;i<=n;i++){
		L[i]=lower_bound(list+1,list+1+T,L[i])-list;
		R[i]=lower_bound(list+1,list+1+T,R[i])-list;
	}
	for (int i=n;i;i--){
		f[i]=Get(L[i]);
		if (R[i]<L[i])	ST.Modify(1,1,T,R[i]+1,L[i]-1,i);
		else	ST.Modify(1,1,T,1,L[i]-1,i),ST.Modify(1,1,T,R[i]+1,T,i);
	}
	ll Ans=f[1];
	for (int i=1;i<=T;i++)	Ans=min(Ans,Get(i));
	printf("%lld\n",Ans+2*sum[n]);
	return 0;
}

Measured memory_bytes: 6400
import java.io.PrintWriter;
import java.util.Scanner;

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

        if (a.equals(a.toLowerCase())) {
            a = "a";
        } else {
            a = "A";
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(a);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 35720
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll h,w;
cin >>h>>w;
char s[h][w];
for(ll i=0;i<h;i++){
for(ll j=0;j<w;j++){
cin >>s[i][j];
}
}

ll flag=0;
for(ll i=0;i<h;i++){
for(ll j=0;j<w;j++){
if(i==0&&j==0&&s[i][j]=='#'){
if(s[0][1]=='#'||s[1][0]=='#'){
}
else{
flag=1;
}
}
else if(s[0][w-1]=='#'&&i==0&&j==w-1){
if(s[0][w-2]=='#'||s[1][w-1]=='#'){
}
else{
flag=1;

}
}
else if(s[h-1][w-1]=='#'&&i==h-1&&j==w-1){
if(s[h-1][w-2]=='#'||s[h-2][w-1]=='#'){
}
else{
flag=1;

}
}
else if(s[h-1][0]=='#'&&i==h-1&&j==0){
if(s[h-1][1]=='#'||s[h-2][0]=='#'){
}
else{
flag=1;

}
}
else if(i==0&&s[i][j]=='#'){
if(s[i][j-1]=='#'||s[i][j+1]=='#'||s[i+1][j]=='#'){
}
else{
flag=1;

}
}
else if(i==h-1&&s[i][j]=='#'){
if(s[i][j-1]=='#'||s[i][j+1]=='#'||s[i-1][j]=='#'){
}
else{
flag=1;

}
}
else if(j==0&&s[i][j]=='#'){
if(s[i-1][j]=='#'||s[i+1][j]=='#'||s[i][j+1]=='#'){
}
else{
flag=1;

}
}
else if(j==w-1&&s[i][j]=='#'){
if(s[i-1][j]=='#'||s[i+1][j]=='#'||s[i][j-1]=='#'){
}
else{
flag=1;

}
}
else if(0<i&&i<h-1&&0<j&&j<w-1&&s[i][j]=='#'){
if(s[i-1][j]=='#'||s[i+1][j]=='#'||s[i][j-1]=='#'||s[i][j+1]=='#'){
}
else{
flag=1;

}
}
}
}
if(flag){
cout<<"No";
}
else
cout<<"Yes";
return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		if ( Math.abs(a-c) <= d 
				|| (Math.abs(a-b)<=d && Math.abs(b-c)<=d)
				) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <string>

using namespace std;
int main() {
    // prepare variables
    string last_week_contest;
    cin >> last_week_contest;

    // calculate answer
    string this_week_contest;
    if(last_week_contest == "ABC"){
        this_week_contest = "ARC";
    }
    else{
        this_week_contest = "ABC";
    }
    cout << this_week_contest << endl;
    return 0;
}


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

int main() {
  ll n, x, g;
  cin >> n >> x >> g;
  g -= x;
  rep(i, n - 1) {
    ll a;
    cin >> a;
    a -= x;
    a = abs(a);
    g = gcd(g, a);
  }
  cout << abs(g) << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main() {
ll n,k;
cin>>n>>k;
vector<double>p(n+1),q(n+1),r(n+1),s(n+1);
rep(i,n)cin>>p[i];
rep(i,n) q[i]=0.50+0.50*p[i];
for(ll i=0; i < n; i++) s[i+1] = s[i] + q[i+1];
for(ll j=0; j<=n-k;j++) r[j]=s[j+k]-s[j];
 sort(r.begin(), r.end()); 
 reverse(r.begin(),r.end());
 printf("%.1lf",r[0]);

return 0;
}

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

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

using namespace std;

const int INF=1<<29;

int main(){
	int W,n; scanf("%d%d",&W,&n);

	int dp[20001];
	rep(w,20001) dp[w]=INF;
	dp[0]=0;
	rep(i,n){
		int a,b; scanf("%d%d",&a,&b);
		rep(w,20001-a) dp[w+a]=min(dp[w+a],dp[w]+b);
	}
	printf("%d\n",*min_element(dp+W,dp+20001));

	return 0;
}


Measured memory_bytes: 384
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int x[252521];
int ne[252521][20],rne[252521][20];
int dp[(1<<20)+10],rdp[(1<<20)+10];
vector<int> v;
int main()
{
	int n,V;
	cin>>n>>V;
	rep(i,n) cin>>x[i];
	while(V>0){
		v.pb(V);V/=2;
	}
	v.pb(0);int m=v.size();
	rep(i,n) rep(j,m){
		rne[i][j]=i;
		if(i>0 && x[i]-x[i-1]<=v[j]) rne[i][j]=rne[i-1][j];
	}
	for(int i=n-1;i>=0;i--) rep(j,m){
		ne[i][j]=i;
		if(i<n-1 && x[i+1]-x[i]<=v[j]) ne[i][j]=ne[i+1][j];
	}
	memset(dp,0,sizeof(dp));
	rep(i,(1<<20)+5) rdp[i]=n-1;
	rep(i,(1<<m)) rep(j,m){
		if((i&(1<<j))>0) continue;
		dp[i+(1<<j)]=max(dp[i+(1<<j)],dp[i]>=n?n:ne[dp[i]][j]+1);
		rdp[i+(1<<j)]=min(rdp[i+(1<<j)],rdp[i]<0?-1:rne[rdp[i]][j]-1);
	}
	//rep(i,(1<<m)) cout<<i<<' '<<dp[i]<<' '<<rdp[i]<<endl;
	if(dp[(1<<m)-1]<n){
		//assert(dp[(1<<m)-1]<n && rdp[(1<<m)-1]>=0);
		rep(i,n) cout<<"Impossible"<<endl;
		return 0;
	}
	int now=0;
	while(now<n){
		int f=0;
		rep(i,(1<<(m-1))){
			if(dp[(1<<m)-2-(i<<1)]>=now && rdp[(i<<1)]<=ne[now][0]) f=1;
		}
		REP(i,now,ne[now][0]+1){
			if(f>0) cout<<"Possible"<<endl;
			else cout<<"Impossible"<<endl;
		}
		now=ne[now][0]+1;
	}
}


Measured memory_bytes: 46208
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define x first
#define y second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("travel_restrictions_input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        ll h,w;
        cin>>h>>w;
        ll ans=INF;
        if(h%3==0||w%3==0)
        {
            cout<<"0\n";
            continue;
        }
        for(ll i=1;i<=h;i++)
        {
            ll a1=w*i,j=h-i,a2,a3;
            a2=w*(j/2),a3=w*(j/2+j%2);
            ans=min(ans,(max(a1,max(a2,a3))-min(a1,min(a2,a3))));
            a2=j*(w/2),a3=j*(w/2+w%2);
            ans=min(ans,(max(a1,max(a2,a3))-min(a1,min(a2,a3))));
        }
        for(ll i=1;i<=w;i++)
        {
            ll a1=h*i,j=w-i,a2,a3;
            a2=h*(j/2),a3=h*(j/2+j%2);
            ans=min(ans,(max(a1,max(a2,a3))-min(a1,min(a2,a3))));
            a2=j*(h/2),a3=j*(h/2+h%2);
            ans=min(ans,(max(a1,max(a2,a3))-min(a1,min(a2,a3))));
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  sort(all(s));
  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define first f
#define second s
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	double ans = double(a[0] + a[1]) / 2;
	for (int i = 2; i < n; i++) {
		ans += a[i];
		ans /= 2;
	}
	cout << ans;
}

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

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

int main()
{
	FAST_IO;

 	ll n;
 	cin >> n;
 	ll x = n % 10;
 	if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9) cout << "hon" << endl;
 	else if(x == 3) cout << "bon" << endl;
 	else cout << "pon" << endl;   
    return 0;
}

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

using namespace std;

int main() {
    char S[6];
    for(int i=0;i<6;i++){
        cin>>S[i];
    }
    if(S[2]==S[3] && S[4]==S[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, a[100010];
    int sum = 0;

    cin >> n;

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

    sort(a, a+n);

    for (int i = 0; i < n-1; i++) {
        sum += a[i];
    }

    if (sum > a[n-1]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

int main(void){
    int N, D;
    double X,Y;
    int count =0;

    cin >> N >> D;
    for(int i=0; i<N; i++){
        cin >> X >> Y;
        double t;
        t = sqrt(X*X + Y*Y);
        if(t<=D){
            count ++;
        }
    }

    cout << count << endl;



    return 0;
}

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

#define N 1000
#define Q 1000000007

int main(void){
	int n, i, j, num=1, tmp;
	char ar[N+1][N+1];
	int pf[N+1];
	int soe[N+1];

	scanf("%d", &n);
	for(i=2; i<=n; i++){
		soe[i] = 1;
	}
	for(i=2; i*i<=n; i++){
		if(soe[i] == 0) continue;
		for(j=i*2; j<=n; j+=i){
			soe[j] = 0;
		}
	}
	
	for(i=2; i<=n; i++){
		if(soe[i] == 0) continue;
		for(j=1; j*i<=n; j++){
			ar[i][j*i]=1;
			if(j%i == 0) ar[i][j*i] += ar[i][j];
		}
	}
	for(i=2; i<=n; i++){
		if(soe[i] == 0) continue;
		for(j=i; j<=n; j+=i){
			pf[i] += ar[i][j];
		}
	}
	for(i=2; i<=n; i++){
		if(soe[i] != 0){
			tmp = num;
			for(j=0; j<pf[i]; j++){
				num = (num+tmp)%Q;
			}
		}
	}

	printf("%d\n", num);

	return 0;
	
}

Measured memory_bytes: 768
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define repn(i,a,b) for (int i=(a);i>=(b);i--)
#define repq(i,a,b) for (int i=(a);i<(b);i++)
#define pa pair<int,int>
#define be begin()
#define en end()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll modInverse(ll a, ll m) 
{ ll m0 = 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 += m0; return x; 
}
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;}
    return res;

}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b){if(a.fi==b.fi)return b.se>a.se;return a.fi>b.fi;}
void run(vector<ll>v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void solve()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum;


}

int main() 
{ 
   


    solve();

        
    
    
    return 0; 
} 

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

ab = []

for _ in range(M):
    a,b = map(int,input().split())
    ab.append((a,b))
    
ab.sort()

ans = 0
b_prev = 0

for i in range(M):
    if b_prev <= ab[i][0]:
        ans += 1
        b_prev = ab[i][1]
    else:
        b_prev = min(b_prev, ab[i][1])
    
print(ans)

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;

struct room{
  int depth;
  int doors;
  vector<int> dlist;
  room() : depth(0), doors(0), dlist() {}
};

int main(){
  int n; cin >> n;
  REP(counter, n) {
    int num;
    vector<int> data;
    int rs = 0;
    while(cin >> num and num) {
      data.push_back(num);
      if(num > 0) rs++;
    }
    vector<room> rooms(rs);
    int currentid = 0;
    int currentdepth = 0;
    vector<int> parents;
    REP(i, data.size()){
      if(data[i] > 1){
        rooms[currentid].doors = data[i];
        rooms[currentid].depth = currentdepth;
        if(parents.size() != 0){
          int parent = parents[currentdepth-1];
          rooms[parent].dlist.push_back(currentid);
          rooms[currentid].dlist.push_back(parent);
        }
        parents.push_back(currentid);
        currentid++; currentdepth++;
      } else if(data[i] == 1) {
        rooms[currentid].doors = data[i];
        rooms[currentid].depth = currentdepth;
        if(parents.size() != 0){
          int parent = parents[currentdepth-1];
          rooms[parent].dlist.push_back(currentid);
          rooms[currentid].dlist.push_back(parent);
        }
        currentdepth--;
        while(currentdepth >= 0 and rooms[parents[currentdepth]].doors == rooms[parents[currentdepth]].dlist.size()){
          parents.pop_back();
          currentdepth--;
        }
        currentdepth++; currentid++;
      } else {
        currentdepth--;
        int parent = parents[currentdepth];
        int dest = parents[currentdepth + data[i]];
        rooms[parent].dlist.push_back(dest);
        rooms[dest].dlist.push_back(parent);
        while(currentdepth >= 0 and rooms[parents[currentdepth]].doors == rooms[parents[currentdepth]].dlist.size()){
          parents.pop_back();
          currentdepth--;
        }
        currentdepth++;
      }
    }
    REP(i, rooms.size()) {
      sort(ALL(rooms[i].dlist));
      cout << i+1;
      REP(j, rooms[i].doors){
        cout << " " << rooms[i].dlist[j]+1;
      }
      cout << endl;
    }
  }
  return 0;
}

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

int main() {
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			bool res = j < a;
			if(i < b) res = !res;
			cout << res;
			// if(j != m-1) cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1280
n, m = gets.split.map(&:to_i)


# factorize m
fs = []
2.upto(Math.sqrt(m).ceil) do |i|
  cnt = 0
  while m % i == 0
    m /= i
    cnt += 1
  end

  fs << cnt if cnt != 0
end

if m != 1
  fs << 1
end

def comb(n, k)
  res = 1
  k.times do |i|
    res *= n.to_r / k.to_r
    n -= 1
    k -= 1
  end
  res.to_i
end


total = 1
fs.each do |f|
  total *= comb(n + f - 1, f)
  total %= 1_000_000_007
end

p total


Measured memory_bytes: 1916
//
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    string S;
    cin >> S;
    ll sum = 0;
    REP(i, S.size())
    {
        int n = S[i] - '0';
        sum += n;
    }
    if (sum % 9 == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3720
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			boolean flg = false;
			String [] str = sc.nextLine().split(" ");
			for(int i=0; i < 26; i++){
				for(int j=0; j < str.length; j++){
					char [] c = str[j].toCharArray();
					for(int k = 0; k < c.length; k++){
						if(c[k] >= 'a' && c[k]<='z'){
							c[k] = (char)((c[k] - 'a' + 1)%26 +'a');
						}
					}
					str[j] = new String(c);
					if(str[j].equals("this") ||str[j].equals("the") ||str[j].equals("that")){
						flg = true;
					}
				}
				if(flg){
					break;
				}
			}
			for(int i=0; i < str.length-1; i++){
				System.out.print(str[i] + " ");
			}
			System.out.println(str[str.length -1]);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int kenCount = sc.nextInt();
			int shiCount = sc.nextInt();
			int i = 0;
			// Shi[] list = new Shi[shiCount];
			List<Shi> list = new ArrayList<>(shiCount);
			while (i < shiCount) {
				Shi shi = new Shi();
				shi.idx = i;
				shi.ken = sc.nextInt();
				shi.year = sc.nextInt();
				list.add(shi);
				i++;
			}
			Collections.sort(list, (o1, o2) -> {
				if (o1.ken == o2.ken) {
					return o1.year - o2.year;
				}
				return o1.ken - o2.ken;
			});

			String[] answers = new String[shiCount];

			int[] seq = new int[kenCount + 1];
			for (Shi shi : list) {
				int ken = shi.ken;
				seq[ken]++;
				shi.birthNum = seq[ken];
				answers[shi.idx] = shi.getNumberStr();
			}

			for (String ans : answers) {
				System.out.println(ans);
			}
		}
	}

	private static class Shi {
		private int idx = 0;
		private int ken = 0;
		private int year = 0;
		private int birthNum = -1;

		private String getNumberStr() {
			return zero(ken) + zero(birthNum);
		}

		private String zero(int num) {
			String str = String.valueOf(num);
			switch (str.length()) {
			case 1:
				return "00000" + str;
			case 2:
				return "0000" + str;
			case 3:
				return "000" + str;
			case 4:
				return "00" + str;
			case 5:
				return "0" + str;
			case 6:
				return str;
			}
			return str;
		}
	}
}

Measured memory_bytes: 101608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n, W;
	cin >> n >> W;
	
	vpll item(n);
	for(pll& p : item)cin >> p.F >> p.S;
	
	sort(all(item));
	
	vvll dp(n+1, vll(W+1, 0));
	for(int i=1 ; i<=n ; ++i){
		for(int j=1 ; j<=W ; ++j){
			dp[i][j] = dp[i-1][j];
			if(j >= item[i-1].F){
				dp[i][j] = max(dp[i][j], dp[i-1][j-item[i-1].F] + item[i-1].S);
			}
		}
	}
	
	cout << dp[n][W];
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 83120
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll a, b, k; cin >> a >> b >> k;
	ll t = k;
	k -= a;
	a = max(a-t, 0ll);
	if( k > 0 ) b = max(b-k, 0ll);
	cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 A, B, M;
  std::cin >> A >> B >> M;
  std::vector<i64> a, b;
  tools::read(a, A);
  tools::read(b, B);

  i64 answer = *std::min_element(a.begin(), a.end()) + *std::min_element(b.begin(), b.end());
  for (i64 i = 0; i < M; ++i) {
    i64 x_i, y_i, c_i;
    std::cin >> x_i >> y_i >> c_i;
    --x_i;
    --y_i;
    answer = std::min(answer, a[x_i] + b[y_i] - c_i);
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 7)

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
		return

n, m = map(int, input().split())
lang = [[] for _ in range(m)]
for i in range(n):
	kl = list(map(int, input().split()))
	for j in range(1, kl[0] + 1):
		lang[kl[j] - 1].append(i)

uf = UnionFind(n)
for i in range(m):
	if len(lang[i]) <= 1:
		continue
	else:
		for j in range(len(lang[i]) - 1):
			uf.union(lang[i][j], lang[i][j + 1])

root_count = 0
for i in range(n):
	if uf.table[i] < 0:
		root_count += 1

if root_count == 1:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 119256
import java.util.Scanner;

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

		int num = 1;
		int min = 0;
		for(int i = 0; i < n; i++) {
			p[i] = scan.nextInt();
			if(i == 0) {
				min = p[i];
				continue;
			}
			if(p[i] < min) {
				num++;
				min = p[i];
			}
		}
		
		System.out.println(num);
	}
}

Measured memory_bytes: 64952
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
D = [int(input()) for _ in range(N)]
"""

N = int(input())
V = sorted(list(map(int, input().split())))

total = (V[0] + V[1]) / 2

for i in range(2, N):
    total = (total + V[i]) / 2


print(total)





# def main():


# if __name__ == '__main__':
#     main()


Measured memory_bytes: 38256
'use strict';

function Main(INPUT) {
    const S = INPUT.split("");
    let y = 700;
    for (let i = 0; i < S.length; i++) {
        y += S[i] == "o" ? 100 : 0;
    }
    console.log(y);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>

typedef long long ll;

using namespace std;

ll cnt = 0, n;

ll dfs(ll v, bool f3, bool f5, bool f7) {
    if (v > n) return 0;
    return dfs(v * 10 + 3, 1, f5, f7) + dfs(v * 10 + 5, f3, 1, f7) + dfs(v * 10 + 7, f3, f5, 1) + (f3 & f5 & f7);
}

int main() {
    cin >> n;
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N; cin >> N;
    string S; cin >> S;
    // true -> sheep, false -> wolf
    vector<bool> label(N+2);

    for(int i=0; i<(1<<2); i++){
        label[0] = ((i>>1) & 1)==1;
        label[1] = ((i>>0) & 1)==1;

        for(int j=1; j<N; j++){
            if( (S[j]=='o') && label[j]){ // S && o
                label[j+1] = label[j-1];

            }else if( (S[j]=='o') && !label[j]){ // W && o
                label[j+1] = !label[j-1];

            }else if( (S[j]=='x') && label[j]){ // S && x
                label[j+1] = !label[j-1];

            }else if( (S[j]=='x') && !label[j]){ // W && x
                label[j+1] = label[j-1];

            }
        }
        if(label[0]!=label[N])
            continue;

        if(
                (label[0] && (S[0]=='o') && (label[N-1]==label[1])) ||
                (label[0] && (S[0]=='x') && (label[N-1]!=label[1])) ||
                (!label[0] && (S[0]=='o') && (label[N-1]!=label[1])) ||
                ( !label[0] && (S[0]=='x') && (label[N-1]==label[1]))
        ){
            for(int j=0; j<N; j++){
                cout << (label[j] ? 'S' : 'W');
            }
            cout << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 576
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;

void solve(){
  int n;
  cin >> n;
  int a[n];
  for(int &i : a) cin >> i;
  sort(a, a+n);
  ll sum = a[n-1], k = n-2;
  for(int i = n-2; k > 0; i--){
    if(k == 1)
      sum += a[i], k--;
    else
      sum += 2*a[i], k-=2;
  }
  cout << sum << endl;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while(t--){
    //tt++;
    //cout << "Case #" << tt << ": ";
    solve();
  }
  return 0;
}  

Measured memory_bytes: 4436
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,d,count=0;
  cin>>a>>b>>d;
  for(int i=a; i<=b; i++)
  {
    if(i%d==0)
      count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3620