akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

//func init() {
//	sc.Split(bufio.ScanWords)
//}

func countSlimes(s string) (count int) {
	old := '0'
	for _, ss := range s {
		if old != ss {
			count++
			old = ss
		}
	}
	return
}

func main() {
	getInt()
	S := getString()
	cnt := countSlimes(S)
	fmt.Println(cnt)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

# 逆元comb
def comb(n, k):
    k = min(n-k,k)
    ans = 1
    for i in range(1, k + 1):
        ans *= (n + 1 - i) * pow(i,MOD-2,MOD)
        ans %= MOD
        
    return ans

def solve(n: int, k: int):
    # nC0---n-1
    comb1 = [0]*n
    comb1[0] = 1
    for i in range(1, n):
        comb1[i] = (comb1[i-1]*(n + 1 - i) * pow(i,MOD-2,MOD))%MOD

    # nC0---n-1
    comb2 = [0]*(n-1)
    comb2[0] = 1
    for i in range(1, n-1):
        comb2[i] = (comb2[i-1]*(n - i) * pow(i,MOD-2,MOD))%MOD

    
    if k >= n-1: ## なんでもいける
        answer = 0
        for i in range(n): # i はゼロの数
            if i == 0:
                answer += 1
            else:
                answer += comb1[i]*comb2[n-1-i]%MOD
        print(answer%MOD)
        return
    else:
        answer = 0
        for i in range(k+1): # i はゼロの数
            if i == 0:
                answer += 1
            else:
                answer += comb1[i]*comb2[n-1-i]%MOD
        print(answer%MOD)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(n, k)

if __name__ == '__main__':
    main()


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

int pre[200010],suf[200010],n;
char s[200010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();
	scanf("%s",s+1);
	for (int i=1;i<=n;i++) pre[i]=pre[i-1]+(s[i]=='#');
	for (int i=n;i;i--) suf[i]=suf[i+1]+(s[i]=='.');
	int ans=10000000;
	for (int i=0;i<=n;i++) ans=min(ans,pre[i]+suf[i+1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll a,b,c;cin>>a>>b>>c;
    ll mx=max({a,b,c});
    if( (3*mx)%2 == (a+b+c)%2 )cout<< (3*mx - (a+b+c))/2;
    else cout<<(3*(mx+1) - (a+b+c))/2;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    map<char,int> dic;
    cin>>s;
    
    ll total=0;
    rep(i,s.size()){
        char c=s[i];
        total+=i-dic[c];
        dic[c]++;
    }
    cout1(total+1)
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret%=mod;
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
int main(){
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  bool f=false;
  if(a==b&&c==d) f=true;
  if(a==c&&b==d) f=true;
  if(a==d&&b==c) f=true;
  if(a==b&&b==c&&c==d) f=false;
  cout<<(f?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
  
typedef struct{
  char name[11];
  int time;
}process;
  
int main(){
  long long  n, q, i, j, sp, ep, stime = 0;
  process p[520000];
  scanf("%lld%lld", &n, &q);
  for(i = 0; i < n; ++i) scanf("%s%d", p[i].name, &p[i].time);
  
  sp = 0; ep = n - 1;
  while(sp <= ep){
    if(p[sp].time > q){
      stime += q;
      p[sp].time -= q;
      p[++ep] = p[sp];
    }
    else{
      stime += p[sp].time;
      printf("%s %lld\n", p[sp].name, stime);
    }
    sp++;
  }
  return 0;
}


Measured memory_bytes: 4732
#include <iostream>

using namespace std;

int bexp(int a, int x, int p) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return a * bexp(a, x - 1, p) % p;
    }
    int t = bexp(a, x / 2, p);
    return t * t % p;
}

int inv(int a, int p) {
    return bexp(a, p - 2, p);
}

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

    int c[p][p];
    for (int i = 0; i < p; i++) {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i; j++) {
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % p;
        }
    }

    int e[p][p];
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < p; j++) {
            e[i][j] = j == 0 ? 1 : e[i][j-1] * i % p;
        }
    }

    int b[p];
    for (int i = p - 1; i >= 0; i--) {
        int x = 0, y = 0;
        int neg = 1;
        for (int j = 0; j <= i; j++) {
            y = ((y + a[j] * c[i][j] * neg) % p + p) % p;
            x = ((x + e[j][i] * c[i][j] * neg) % p + p) % p;
            neg = -neg;
        }
        b[i] = x == 0 ? 0 : y * inv(x, p) % p;

        for (int j = 0; j < p; j++) {
            a[j] = ((a[j] - b[i] * e[j][i]) % p + p) % p;
        }
    }

    for (int i = 0; i < p; i++) {
        cout << b[i] << (i == p - 1 ? '\n' : ' ');
    }

    return 0;
}


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

int main()
{
    string s;
    cin >> s;
  
    
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
  
    else
    {
        cout << "Good" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
m=max(x,y)
n=min(x,y)

if  m==x:
    mm=a
    nn=b
else:
    mm=b
    nn=a

if (a+b)<=2*c:
    print(a*x+b*y)
else:
    if 2*c*n+mm*(m-n)<=2*c*m:
        print(2*c*n+mm*(m-n))
    else:
        print(2*c*m)

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

using namespace std;
using ll =long long;
//nCm 
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nCmここまで

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int n , k; 	
	cin >> n >> k; 	
	int p[n];
	rep(i,n) cin >> p[i] ;
	int M = 0 ;
	int M_index = 0 ;

	rep(i,k){
		M +=p[i];
	}
	int now = M ;
	for(int i = 1; i < n-k+1 ;i++){
		now -= p[i-1];
		now += p[i+k-1];//i = n-kまで i 	
		if(chmax(M,now)){
			M_index = i ;
		}
	}
	

	cout << setprecision(10);
	double ans = 0 ;

	rep(i,k){
		int sum = p[M_index+i] * ( p[M_index+i] + 1) / 2;
		ans += (double)sum/(double)p[M_index+i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int m, n;
	while(~scanf("%d %d", &m, &n)){
		printf("%d\n", n * 2 - m);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	// 入力
	int h = sca.nextInt();
	int w = sca.nextInt();
	int n = sca.nextInt();

	// hとwで大きいほうについて黒く塗ることを考える
	int pivot = 0;
	int non_pivot = 0;
	int ans = 0;
	if(h < w) {
		pivot = w;
		non_pivot = h;
	}
	else {
		pivot = h;
		non_pivot = w;
	}
	for(int i = 1; i <= non_pivot; i++) {
		if(n <= i*pivot) {
			ans = i;
			break;
		}
	}

	System.out.println(ans);

	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true){
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if (m == -1 && f == -1 && r == -1) {
				break;
			} else if (m == -1 || f == -1) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65 && m + f < 80) {
				System.out.println("B");
			} else if ((m + f >= 50 && m + f < 65) || r >= 50) {
				System.out.println("C");
			} else if (m + f >= 30 && m + f < 50) {
				System.out.println("D");
			} else if (m + f < 30) {
				System.out.println("F");
			}
		}
	}

}

Measured memory_bytes: 26156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pi 3.14159265  //35897932384626433
#define MOD 1000000007
#define all(s) s.begin(),s.end()
#define mp make_pair
#define vc vector<int>
#define vp vector<pair<ll,ll> >
#define sec second
#define sz(x) (int)((x).size())
#define timesaver ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
const int N =  1e5 + 5;
ll gcd(ll a, ll b){ if(a==0) return b; else return gcd(b%a,a);}
ll power(ll base,ll exp,ll mod=MOD) {ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

int a[N];
int main()
{
 int x, y, sum = 0;
 cin >> x >> y;
 for (int i = 0; i < x; ++i)
 {
   /* code */
  cin >> a[i];
 }
 sort(a, a + x);
 for (int i = x - 1, ct = 0; ct < y && i >= 0; --i)
 {
   /* code */
  sum += a[i];
  ct++;
 }
 cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

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



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,k; cin>>n>>k;
    string s; cin>>s;
    ll x=0;
    int m=s.size();
    rep(i,m-1){
        if(s[i]!=s[i+1])x++;
    }
    cout<<min(n-1,n-1-(x-2*k))<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        Integer[] c = new Integer[n];
        for (int i = 0; i < n ; i++) {
            c[i] = in.nextInt();
        }
        Arrays.sort(c, Comparator.reverseOrder());
        int a = 0;
        int b = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                a += c[i];
            } else {
                b += c[i];
            }
        }
        out.println(a - b);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;cin>>a>>b;
    cout<<6-a-b;
    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
int main()
{
	int n,k,i;
	int sum = 0;
	scanf("%d %d", &n, &k);

	for(i=1;i<=n;i++){
		if(i == 1){
			sum = k * 1;
		}
		else{
			sum *= (k-1);
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

namespace {
using namespace std;
using ll = long long;
using ull = unsigned long long;
}

string S;

void input() {
    cin >> S;
}

ll solve() {
    ll count[2] = {0,0};
    char bw = '0';
    for (int n = 0; n < 2; n++) {
        for (auto s : S) {
            if (s != bw) {
                count[n]++;
            }
            if (bw == '0')
                bw = '1';
            else
                bw = '0';
        }
        bw = '1';
    }
    return min(count[0], count[1]);
}

int main() {
    input();
    cout << solve() << endl;
    
    return 0;
}



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

int main(){
	int n,k,y,x;
    cin>>n>>k>>y>>x;
    int gokei=0;
    for (int i=1;i<=n;i++){
    	if(i<=k){
        	gokei +=y;
        }else{
        	gokei +=x;
        }
    }
  cout<<gokei<<endl;
}    

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char str[21];
	int a,b;
	scanf("%s",str);
	a=strlen(str);
	for(b=0;b<a;b++){
		printf("%c",str[a-b-1]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  string s;
  R s;
  priority_queue<int> q1;
  priority_queue<int,vector<int>,greater<int> > q2;
  rep(i,n) {
    if(s[i]=='R') q1.push(i);
    else q2.push(i);
  }
  int ans=0;
  while(q1.size()&&q1.top()!=q1.size()-1) {
    int x=q1.top();q1.pop();
    int y=q2.top();q2.pop();
    ans++;
    q1.push(y);
    q2.push(x);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 4704
def count(A, a):
    count = 1 if A[0] >= a else 0
    for i in range(len(A)-1):
        if A[i] < a and A[i+1] >= a:
            count += 1
    return count

N = int(input())
H = list(map(int, input().split()))

ans = 0
pre_h = 0
for h in sorted(set(H)):
    ans += count(H, h) * (h - pre_h)
    pre_h = h
print(ans)


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

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short

#define pb push_back

#define fst first
#define snd second
#define mp make_pair

#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define frl(i,n) for(long long i=0;i<n;i++)

#define ms(x,i)	memset(x,i,sizeof(x))
#define dbg(x)	cout << #x << " = " << x << "\n"
#define displayvec(vec) cout<<#vec<<": "; for(auto vd : vec) cout<<vd<<" "; cout<<"\n"

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++) is >> v[i];
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++) os << v[i] << " ";
  os << endl;
  return os;
}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, W;
    cin>>n>>W;

    vector< ll > w(n + 2), v(n + 2);

    for(ll i = 1; i <= n; ++i) cin>>w[i]>>v[i];

    vector< ll > dp(W + 1, -1);

    dp[0] = 0;
    for(ll i = 1; i <= n; ++i){
            vector< pll > weights;
        for(ll weight = w[i]; weight <= W; ++weight){
            if(dp[weight - w[i]] != -1){
                weights.emplace_back(make_pair(weight, max(dp[weight], dp[weight - w[i]] + v[i])));
            }
        }
        for(auto ws : weights){
            dp[ws.first] = ws.second;
        }
    }

    cout<<*max_element(dp.begin(), dp.end())<<"\n";
    return 0;
}


Measured memory_bytes: 7612
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100005],sum[100005];
int main(){
	int n,i;
	long long cont;
	while(cin>>n){
		cont=0;
	 for (i=0;i<n;i++)
	 cin>>a[i];
	 sort(a,a+n);
	 sum[0]=a[0];
	 for (i=1;i<n;i++)
	 sum[i]=sum[i-1]+a[i];
	 for (i=n;i>0;i--)
	 if (a[i]<=sum[i-1]*2)
	 cont++;
	 else
	 break;
	 cout<<cont<<endl;
	}
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int[][] place = new int[2][n];
		for(int i = 0; i < n; i++) {
			place[0][i] = sc.nextInt();
			place[1][i] = sc.nextInt();
		}
		double ans = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				double x = Math.pow(place[0][i]-place[0][j], 2);
				double y = Math.pow(place[1][i]-place[1][j], 2);
				ans += Math.sqrt(x+y);
			}
		}
		System.out.println(ans/n);
	}
	
	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;
	    }
	}
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> P(N), C(N);
    vector<vector<ll>> V;
    map<ll, ll> M, W; 
    for(int i = 0; i < N; i++) {
        cin >> P[i]; P[i]--;
        W[i] = P[i];
    }
    for(int i = 0; i < N; i++) cin >> C[i];
    vector<bool> vis(N+1, false);
    for(int i = 0; i < N; i++){
        vector<ll> temp;
        ll idx = i;
        while(!vis[idx]){
            vis[idx] = true;
            temp.push_back(C[idx]);
            idx = W[idx];
        }
        if(temp.size() != 0)V.push_back(temp);
    }
    
    ll ans_ = -INF;
    for(auto v : V){
        vector<ll> U = v;
        ll n = v.size();
        for(int i = 0; i < n; i++) U.push_back(U[i]);
        ll ans = -INF;
        
        unordered_map<ll, ll> MP;
        for(int i = 1; i <= n; i++){
            ll cnt = 0;
            for(int j = 0; j < i; j++) cnt += U[j];
            MP[i] = cnt;
            for(int j = i; j < 2*n; j++){
                cnt += U[j];
                cnt -= U[j-i];
                MP[i] = max(cnt, MP[i]);
            }
        }

        ll MAX1 = -INF; for(int i = 1; i <= n; i++) MAX1 = max(MAX1, MP[i]);
        ll MAX2 = -INF; for(int i = 1; i <= K%n; i++) MAX2 = max(MAX2, MP[i]);
        if(n <= K){
            ll SUM = 0;
            for(int i = 0; i < n; i++) SUM += U[i];
            SUM = max(0LL, SUM);
            ans = max((K/n-1)*SUM + MAX1 , (K/n)*SUM + MAX2);
        }
        else {
            ans = MAX2;
        }
        ans_ = max(ans, ans_);
    }
    cout << ans_ << endl;
    

}

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

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

typedef long long ll;

int n, k;

int Check(int p, vector<int> v) {
	ll sum = 0;
	int	cnt = 0;
	int i = 0;
	while (i < n) {
		if (cnt == k) {
			return false;
		}
		cnt += 1;
		sum = 0;
		while (sum + v[i] <= p) {
			sum += v[i];
			i++;
			if (i == n) return true;
		}
	}
	return true;
}



int main() {
	// input
	cin >> n >> k;
	vector<int> w(n);
	rep(i, n) cin >> w[i];
	ll left, right, mid;
	left = 0;
	right = max_k;
	while (right - left > 1) {
		mid = (left + right) / 2;
		if (Check(mid, w)) {
			right = mid;
		}
		else
		{
			left = mid;
		}
	}

	cout << right << endl;

	return 0;
}


Measured memory_bytes: 3600
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, t; cin >> n >> t;
    vll a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];
    vll ord(n); iota(ALL(ord), 0LL);
    sort(ALL(ord), [&](ll i, ll j){
        return a[i] < a[j];
    });

    vvll dp(n + 1, vll(t + 1, 0));
    rep(i, 1, n + 1) {
        REP(j, t) {
            chmax(dp[i][j], dp[i-1][j]);
            chmax(dp[i][min(j + a[ord[i-1]], t)], dp[i-1][j] + b[ord[i-1]]);
        }
    }

    ll ans = 0;
    rep(i, 1, n+1) {
        REP(j, t + 1) {
            chmax(ans, dp[i][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

int main()
{
    int n, andy = 0;
    std::cin >> n;
    for (int i = 1; i <= n; i++) { andy += i; }
    std::cout << andy << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}


int main(void){
    int n;
	cin>>n;
    string c;
    cin>>c;
    int white=0;
    int red = 0;
	for(int i=0;i<n;i++){
		if(c[i]=='R')red++;
	}
    int ans = n;
	for(int i=0;i<=n+1;i++){
        if(i==0)ans = min(ans,red);
        else{
            if(i==n+1){
                ans = min(ans,white);
            }
            else{
                if(c[i-1]=='W')white++;
                else red--;
                if(white<=red)ans = min(ans,red);
                else ans = min(ans,white);
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3712
import sys
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
ans = 0
a = []
b = []
for i in range(n):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

a = a[::-1]
b = b[::-1]

for i in range(n):
    if (ans + a[i]) % b[i] == 0:
        pass
    else:
        ans += b[i] - ((ans + a[i]) % b[i])

    # #bの方が大きい
    # if a[i] < b[i]:
    #     ans += b[i] - ((ans + a[i]) % b[i])
    # # aと増加分の方が大きい
    # else:
    #     # ボタン押さなくて良い場合
    #     if (ans + a[i]) % b[i] == 0:
    #         continue
    #     else:
    #         ans += b[i] - ((ans + a[i]) % b[i])

print(ans)


Measured memory_bytes: 18972
import sys
input = sys.stdin.readline

N=int(input().rstrip('\n'))
S=list(input().rstrip('\n'))
score = [S.count('R'),S.count('W')]
sta = 'R'
ws = 0
rs = S.count('R')
sto = 0
for i in range(N):
  if S[i] != sta:
    if sta=='W':
      ws += sto
      sto = 1
      score.append(max(rs,ws))
      sta ='R'
    else:
      rs -= sto
      sto = 1
      score.append(max(rs,ws))
      sta ='W'
  else:
    sto += 1
print(min(score))

Measured memory_bytes: 12864
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int dp[40][500][500];
struct Med{
  int a;
  int b;
  int c;
};
signed main(){
  int n,ma,mb;cin>>n>>ma>>mb;
  vector<Med> med(n);
  rep(i,40){
    rep(j,500){
      rep(k,500){
        dp[i][j][k]=inf;
      }
    }
  }
  dp[0][0][0]=0;
  rep(i,n){
    cin>>med[i].a>>med[i].b>>med[i].c;
  }
  dp[0][med[0].a][med[0].b]=med[0].c;
  rep1(i,n-1){
    rep(j,500){
      rep(k,500){
        if(j-med[i].a<0||k-med[i].b<0){
          dp[i][j][k]=dp[i-1][j][k];
          continue;
        }
        dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-med[i].a][k-med[i].b]+med[i].c);
      }
    }
  }
  int res=inf;
  rep1(j,499){
    rep1(k,499){
      if(j*mb==k*ma){
        res=min(res,dp[n-1][j][k]);
      }
    }
  }
  if(res==inf){
    res=-1;
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 78336
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    xs <- getIntList
    putStrLn $ if all (<=8) xs then "Yay!" else ":("

Measured memory_bytes: 380
#!/usr/bin/env python3

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

for i in range(N):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            print("DENIED")
            exit()

print("APPROVED")



Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include<string>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	string s;

	cin >> s;

	if (s == "AKIHABARA") { printf("YES");return 0; }
	if (s == "KIHABARA") { printf("YES");return 0; }

	if (s == "AKIHBARA") { printf("YES");return 0; }
	if (s == "AKIHABRA") { printf("YES");return 0; }
	if (s == "AKIHABAR") { printf("YES");return 0; }
	if (s == "KIHBARA") { printf("YES");return 0; }
	if (s == "KIHABRA") { printf("YES");return 0; }
	if (s == "KIHABAR") { printf("YES");return 0; }
	if (s == "AKIHBRA") { printf("YES");return 0; }
	if (s == "AKIHBAR") { printf("YES");return 0; }
	if (s == "AKIHABR") { printf("YES");return 0; }
	if (s == "KIHBRA") { printf("YES");return 0; }
	if (s == "KIHBAR") { printf("YES");return 0; }
	if (s == "KIHBRA") { printf("YES");return 0; }
	if (s == "KIHABR") { printf("YES");return 0; }
	if (s == "AKIHBR") { printf("YES");return 0; }
	if (s == "KIHBR") { printf("YES");return 0; }
	cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int geth(int x, int y, pair<pair<int,int>,int> xyh){
    return max(0, xyh.second+abs(x-xyh.first.first)+abs(y-xyh.first.second));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<pair<pair<int,int>,int>> xyh;
    tuple<int, int, int> tt;
    rep(i,n) {
        ll x,y,h; cin>>x>>y>>h;
        xyh.push_back(make_pair(make_pair(x,y),h));
        if(xyh[i].second >=1) tt = make_tuple(x,y,h);
    }
    vector<tuple<int,int,int>> ans;
    for(int xx=0; xx<=100;xx++){
        for(int yy=0; yy<=100; yy++){
            ll tmp = get<2>(tt)+abs(xx-get<0>(tt))+abs(yy-get<1>(tt));
            tmp = max(tmp, 0ll);
            // int tmp = geth(xx,yy,xyh[0]); // H
            bool isok = true;
            for(int i=0; i<n;i++) {
                ll h2 = max(tmp-abs(xx-xyh[i].first.first)-abs(yy-xyh[i].first.second), 0ll);
                if(h2 != xyh[i].second){
                    isok=false;
                    // break;
                }
                // if(tmp != geth(xx,yy,xyh[i])){
                //     tmp = -1;
                //     break;
                // }
            }
            if(isok){
                ans.push_back(make_tuple(xx,yy,tmp));
            } 
        }
    }

    if(ans.size() !=0){
        cout << get<0>(ans[0])<<" "<<get<1>(ans[0])<<" "<<get<2>(ans[0])<<endl;
    }
    
}

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

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	string s[2];
	cin>>s[0]>>s[1];
	if(s[0][0]==s[1][2]&&s[0][1]==s[1][1]&&s[0][2]==s[1][0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
		
		
		return 0;
}


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

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

    int ans = 0;
    int now = 0;
    for (int i = 0; i < (n+1); i++) {
        now += l[i];
        ans++;
        if ( now > x ) {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int A, B;
  scanf("%d%d", &A, &B);

  int ans = A+B;
  ans = max(A-B, ans);
  ans = max(A*B, ans);

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=1e16;
const ll ms=(1e6) +5;


char ar[ms];


int main()
{
    idfc;

    string s;
    cin>>s;

    int fl=0;
    int a=2e5+1;
    int b=2e5;

    int n=s.length();
    int i;
    for(i=0;i<n;i++)
    {
        b++;
        ar[b]=s[i];
    }

    int q;
    cin>>q;
    int t;
    char e;
    int tt;
    while (q--)
    {
        cin>>t;
        if(t==1)
        {
            if(fl)fl=0;
            else fl=1;
        }
        else{
           cin>>tt>>e;
           //cin>>e;
         //  cout<<tt<<" "<<e<<endl;
           if(tt==1)
           {
               if(fl)
               {
                   b++;
                   ar[b]=e;
               }
               else{
                   a--;
                   ar[a]=e;
               }
           }
           else{
              // b++;
               if(fl)
               {
                   a--;
                   ar[a]=e;
               }
               else{
                   b++;
                   ar[b]=e;
               }
           }
        }
    }

  //  cout<<a<<" "<<b<<endl;
    if(fl)
    {
        for(i=b;i>=a;i--)cout<<ar[i];
    }
    else{
        for(i=a;i<=b;i++)cout<<ar[i];
    }


    return 0;
}

Measured memory_bytes: 1104
import itertools

def solve():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))


    cnt = 1
    ans = 0
    for i in itertools.permutations(range(1, n+1)):
        if i == p:
            ans += cnt
        if i == q:
            ans -= cnt
        cnt += 1


    return abs(ans)

    
print(solve())


Measured memory_bytes: 3060
/*
* @author:  codancer
* @createTime:  time
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;	
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]

hlst=[x for x,_ in hw]
wlst=[x for _,x in hw]

hcnt=Counter(hlst)
wcnt=Counter(wlst)


_,hmax=hcnt.most_common(1)[0]
_,wmax=wcnt.most_common(1)[0]
hcand=set([k for k,v in hcnt.items() if v==hmax])
wcand=set([k for k,v in wcnt.items() if v==wmax])

ng=[]

for hh,ww in hw:
    if hh in hcand and ww in wcand:
        ng.append((hh,ww))

if len(hcand)*len(wcand)>len(ng):
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

Measured memory_bytes: 134444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    S += '2';
    vector<int> vec;
    vec.push_back(0);
    int cnt = 1;
    for(int i = 1;i < N + 1;i++) {
        if(S.at(i) != S.at(i - 1)) {
            vec.push_back(cnt);
            cnt = 1;
        }
        else {
            cnt++;
        }
    }
    if(S.at(0) == '0') {
        cnt = 0;
    }
    else {
        cnt = 1;
    }
    vec.push_back(0);
    int ret = 0;
    for(int i = cnt;i <= vec.size();i += 2) {
        int cnt2 = 0;
        for(int j = 0;j < K * 2 + 1;j++) {
            if(i + j >= vec.size()) {
                break;
            }
            cnt2 += vec.at(i + j);
        }
        ret = max(ret,cnt2);
    }
    cout << ret << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    string c1;
    string c2;
    cin >> c1 >> c2;
    ((c1[0] == c2[2] && c1[2] == c2[0] && c1[1] == c2[1]) ? puts("YES") : puts("NO"));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;


int n;
int main(){
	cin>>n;
	int a,b,c,d;
	a=n/1000;
	n-=a*1000;
	b=n/100;
	n-=b*100;
	c=n/10;
	n-=c*10;
	d=n;
	int a2=0;
	if(a==b&&b==c) a2=1;
	if(b==c&&c==d) a2=1;
	if(a2==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int A, B, C; 
  int X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans = 1001001001;

  for (int z = 0; z <= 2 * max(X, Y); z += 2) {
    int x = max(0, X - z/2);
    int y = max(0, Y - z/2);
    ll cur = z * C + x * A + y * B;
    chmin(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
ll n, a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a % 2 == 1)
        {
            cout << "first"
                 << "\n";
            return 0;
        }
    }
    cout << "second"
         << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = s; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

int main() {
    string s;
    cin >> s;
    ll bc = 0, ret = 0;
    for(char c : s) {
        if (c == 'W') ret += bc;
        else ++bc; 
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AGC027A solver = new AGC027A();
        solver.solve(1, in, out);
        out.close();
    }

    static class AGC027A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int x = in.nextInt();
            int aList[] = new int[N];
            int ans = 0;
            for (int i = 0; i < N; i++) {
                aList[i] = in.nextInt();
            }
            Arrays.sort(aList);
            for (int i = 0; i < N - 1; i++) {
                if (x >= aList[i]) {
                    ans++;
                    x -= aList[i];
                }
            }
            if (x == aList[N - 1]) {
                ans++;
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 22740
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
int main(int argc, char const *argv[])
{
    int n,k;cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;++i)cin>>h[i];
    vector<ll> dp(n,INF);
    dp[0]=0;
    for(int i=1;i<n;++i){
        int min_idx = max(0,i-k);
        for(int j=min_idx;j<i;++j){
            if(dp[j] + abs(h[i]-h[j]) < dp[i] ){
                dp[i] = dp[j] + abs(h[i]-h[j]);
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.util.Arrays;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt(), a[] = new int[(n + 1) / 2], max = 0;
        for (int i = 0, temp; i < n; i++) {
            if (((temp = scanner.nextInt()) & 1) == (n & 1)) {
                System.out.println(0);
                return;
            }
            a[(temp - (~n & 1)) / 2]++;
            max = Math.max(max, temp);
        }

        long ans = 1;
        if ((n & 1) == 1)
            a = Arrays.copyOfRange(a, 1, a.length);
        for (int i = 0; i < a.length; i++) {
            if (a[i] != 2) {
                System.out.println(0);
                return;
            }
            ans = ans * 2 % 1000000007;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 48196
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

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


        Integer min = INF;
        List<Integer> list = new ArrayList<Integer>();
        for (int tmp = 1; tmp <= n ; tmp++) {
            Integer a = tmp + l - 1;
            list.add(a);
            if(Math.abs(min) > Math.abs(a)){
                min = a;
            }
        }
        list.remove(min);
        int result = list.stream().mapToInt(s -> s).sum();
        System.out.println(result);

    }
}


Measured memory_bytes: 29012