akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define MAX 10001
#define INF (1<<29)
 
int main()
{
    int Tc,N;
    string s;
    cin >> Tc;
    while(Tc--)
    {
        cin >> N >> s;
        bool b[2][MAX] = {{}};
        for(int i = 0 ; i <= N ; i++)
        {
            if(i != 0 && s[2*i-1] == 'Y') b[0][i] = 1;
            if(i != N && s[2*i] == 'Y') b[0][i] = 1;
            if(i != 0 && s[2*i-1+2*N] == 'Y') b[1][i] = 1;
            if(i != N && s[2*i+2*N] == 'Y') b[1][i] = 1;
        }
         
        auto solve = [=]()
            {
                vector<vector<int>> dp(2, vector<int>(MAX, INF));
                if(b[0][0] && b[1][0])
                {
                    dp[1][0] = 2;
                }
                if(b[0][0] && !b[1][0])
                {
                    dp[0][0] = 1;
                    dp[1][0] = 1;
                }
                if(!b[0][0] && b[1][0])
                {
                    dp[1][0] = 2;
                }
                if(!b[0][0] && !b[1][0])
                {
                    dp[0][0] = 0;
                    dp[1][0] = 1;
                }
                
                for(int i = 1 ; i <= N ; i++)
                {
                    if(b[0][i] && b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+4,dp[1][i-1]+3));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+3,dp[1][i-1]+3));
                    }
                    if(b[0][i] && !b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+2,dp[1][i-1]+2));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+2,dp[1][i-1]+2));
                    }
                    if(!b[0][i] && b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+4,dp[1][i-1]+3));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+3,dp[1][i-1]+2));
                    }
                    if(!b[0][i] && !b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+1,dp[1][i-1]+2));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+2,dp[1][i-1]+1));
                    }
                }
                return dp[0][N];
            };
         
        cout << solve() << endl;
    }   
    return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
using namespace std;
 
const ll inf = 1e17;
const ll N = 1e4+10;
const ll bits = 30;
const ll mod = 1e9+7;
 
struct item{
    ll a,b;
};

ll dp[N];

bool comp(item a, item b){
    return a.a < b.a;
}


  
// Driver code 
int main() 
{   FASTIO;
 
    ll n,t;
    cin>>n>>t;

    vector<item>arr(n);
 
    for(int i=0;i<n;i++){
        cin>>arr[i].a>>arr[i].b;
    }
 
    sort(arr.begin(),arr.end(),comp);
 
 
 
    for(int i=0;i<n;i++){
 
            for(int j=t-1;j>=0;j--){
                if(j+arr[i].a>t){
                    dp[t] = max(dp[j]+arr[i].b,dp[t]);
                }else{
                    dp[j+arr[i].a] = max(dp[j]+arr[i].b,dp[j+arr[i].a]);
                }    
 
            }
            
        }

 
    ll ans = 0;
 
    for(int i=0;i<=t;i++){
        // cout<<dp[i]<<"\n";
        ans = max(ans,dp[i]);
    }
 
    cout<<ans<<"\n";
 
 
} 

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

namespace ITP1_11_A2
{
    class Program
    {
        static void Main(string[] args)
        {
            // サイコロの目の配列が与えられる。
            // 転がす4方向を示すE,N,S,Wが与えられる。
            // 初期状態では[5]が底面となる。
            // すべての命令を実行した後のサイコロの上面の数を出力するプログラム

            int[] dice = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            char[] way = Console.ReadLine().ToCharArray();

            Cast cast = new Cast();
            cast.diceCast(dice, way);

            Console.WriteLine(dice[0]);
        }
    }
    public class Cast
    {
        public void diceCast(int[] dice, char[] way)
        {
            for (int i = 0; i < way.Length; i++)
            {
                int zero = dice[0];                                 // dice[0]の値を保存しておく変数zero

                if (way[i] == 'E')
                {
                    dice[0] = dice[3];
                    dice[3] = dice[5];
                    dice[5] = dice[2];
                    dice[2] = zero;
                }

                else if (way[i] == 'N')
                {
                    dice[0] = dice[1];
                    dice[1] = dice[5];
                    dice[5] = dice[4];
                    dice[4] = zero;
                }

                else if (way[i] == 'S')
                {
                    dice[0] = dice[4];
                    dice[4] = dice[5];
                    dice[5] = dice[1];
                    dice[1] = zero;
                }
                else
                {
                    dice[0] = dice[2];
                    dice[2] = dice[5];
                    dice[5] = dice[3];
                    dice[3] = zero;
                }
            }
        }
    }
}


Measured memory_bytes: 18420
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Queue<ItemPair> list = new LinkedList<ItemPair>();
		Scanner k = new Scanner(System.in);
		
		int processes = k.nextInt();
		int quantum = k.nextInt();
		
		//Fill the queue
		for(int x = 0; x < processes; x++) {
			String inputName = k.next();
			int inputTime = k.nextInt();
			
			ItemPair itemPair = new ItemPair(inputTime, inputName);
			list.add(itemPair);
		}
		
		int timeStart = 0;
		while(!list.isEmpty()) {
			
			ItemPair temp = list.poll();
			
			if(temp.send_time() > quantum) {
				temp.set_time(temp.send_time() - quantum);
				timeStart += quantum;
				list.add(temp);
			} else {
				timeStart += temp.send_time();
				System.out.println(temp.send_name() + " " + timeStart);
			}
		}
		
	}
}

//Each node in the queue will have these properties
class ItemPair {
	String name;
	int time;
	
	public ItemPair(int x, String y) {
		time = x;
		name = y;
	}
	public void set_time(int newTime) {
		this.time = newTime;
	}
	public int send_time() {
		return time;
	}
	public String send_name() {
		return name;
	}
	
	
	
}



Measured memory_bytes: 76128
#include <cstdio>
#include <algorithm>
#include <cstdint>
#include <cinttypes>
#include <cstring>

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;

inline i32 diff(i32 x, i32 y) {
	return x > y ? x - y : y - x;
}

const i32 MaxN = 100001;

i32 dp[MaxN], A[MaxN];

signed main(signed argc, char **argv) {
	i32 n, k;
	scanf("%" SCNdFAST32 "%" SCNdFAST32, &n, &k);

	for (i32 i = 0; i < n; ++ i) {
		scanf("%" SCNdFAST32, A + i);
	}
	
	memset(dp, 0x3f, sizeof dp);
	
	dp[0] = 0;

	for (i32 i = 0; i < n; ++ i)  {
		for (i32 j = 1; j <= k; ++ j) {
			if (i - j < 0) {
				break;
			}
			dp[i] = std::min(dp[i], dp[i - j] + diff(A[i], A[i - j]));
		}
	}

	printf("%" SCNdFAST32, dp[n - 1]);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define per(x,a,b) for(int x=a;x>=b;x--)
using namespace std;

int a[maxn],n;
ll s[maxn],p;
map<ll,int> m;
vector<int> v;
set<int> st;
queue<int> q;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>p;
	rep(i,1,n)
		cin>>a[i];
	m[0]++;
	ll ans=0;
	for(int i=1;i<=n;i++){
		s[i]=s[i-1]+a[i];
		ans+=m[s[i]%p];
		m[s[i]%p]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7040
#include <stdio.h>
 
int main(void){
	int a, b, ans;
  
  	scanf("%d %d", &a, &b);
  
  	ans = a * b;
  
  	if(a<10 && b<10){
      	printf("%d", ans);
    }else{
		printf("-1");
    }
  
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[505050];
ll A[505050];
ll i, j, k,ans;



int main(){
    scanf("%s",S);
    N=strlen(S);
    N++;
    k = 0;
    while(true){
        //printf("%lld ", i);
        ll a = i;
        while(i<N-1&&S[i]=='>'){
            i++;
        }
        ans += max(k, i - a);
        fornum(j,a+1,i){
            ans += i - j;
        }
        if(i==N-1){
            break;
        }
        a = i;
        while(i<N-1&&S[i]=='<'){
            i++;
        }
        k = i - a;
        fornum(j,a,i){
            ans += j - a;
        }
        if(i==N-1){
            ans += k;
            break;
        }
    }
    
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 2688
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	in := strings.Split(nextLine(), " ")
	n, _ := strconv.Atoi(in[0])
	a, _ := strconv.Atoi(in[1])
	b, _ := strconv.Atoi(in[2])

	res := 0

	for i := 1; i <= n; i++ {
		iStr := strconv.Itoa(i)
		sum := 0

		for j := 0; j < len(iStr); j++ {
			v, _ := strconv.Atoi(iStr[j : j+1])
			sum += v
		}

		if a <= sum && b >= sum {
			res += i
		}
	}

	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 200010
#define Abs(a) a>0?a:-a
char s[MAXN];
int n,ls,ans;
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)
		if(ls==0&&s[i]=='T')
			ans++;
		else if(s[i]=='T')
			ls++;
		else if(s[i]=='S')
			ls--;
	ans+=Abs(ls);
	printf("%d\n",ans);
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
int H ,W;
int i, j;
while(1){
scanf("%d %d" ,&H ,&W);
if(H == 0 && W == 0) break;
for ( i = 0; i < H; i++ ){
for ( j = 0; j < W; j++ ){
if(j==0||j==W-1||i==0||i==H-1){
printf("#");
}else{
printf(".");
}
}
printf("\n");
}
puts("");
}
return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
 
using namespace std;
 
typedef tuple< int, int, int > Pi;
 
int N, M, L[200000], R[200000];
int ans = 11451419;
Pi first[200000], second[200000];
 
int check(int vq)
{
  vector< Pi > que2;
  int tail = 1;
  bool used[200000] = {};
  for(int i = 0; i < N; i++) {
    int l, r, idx;
    tie(l, r, idx) = first[i];
    if(tail <= l && tail < vq) {
      tail++;
      used[idx] = true;
    }
  }
  int head = M;
  int ret = 0;
  for(int i = 0; i < N; i++) {
    int l, r, idx;
    tie(r, l, idx) = second[i];
    if(used[idx]) continue;
    r *= -1;
    if(r <= head && head >= tail) {
      head--;
    } else {
      ++ret;
    }
  }
  ans = min(ans, ret);
  return (ret);
}
 
int main()
{
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> L[i] >> R[i];
  for(int i = 0; i < N; i++) first[i] = make_tuple(L[i], -R[i], i);
  for(int i = 0; i < N; i++) second[i] = make_tuple(-R[i], L[i], i);
  sort(second, second + N);
  sort(first, first + N);
 
  int low = 1, high = M + 1;
  while(high - low > 1) {
    int mid = (low + high) >> 1;
    (check(mid) - check(mid - 1) > 0 ? low : high) = mid;
  }
  check(0);
  check(M + 1);
  cout << ans << endl;
}

Measured memory_bytes: 6656
#include<iostream>
#define MAX 110
using namespace std;
int main(){
	int n,k;
	while(cin>>n>>k,n||k){
		int tab[MAX],s[MAX],x;
		for(int i=0;i<k;i++)
		tab[i]=0;
		for(int i=0;i<k;i++)
		cin>>s[i];
		for(int i=0;i<n;i++)
		for(int j=0;j<k;j++){
			cin>>x;
			tab[j]+=x;
		}int i;
		for(i=0;i<k;i++)
		if(tab[i]>s[i])
		break;
		if(i==k)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 852
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2,mod); }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


int f[2][200005];
map<pair<int,int>,int>mp;
int find(int x,int id){return f[id][x]==x?x:f[id][x]=find(f[id][x],id);}
void mer(int x,int y,int id){
    x=find(x,id);
    y=find(y,id);
    if(x!=y)f[id][x]=y;
}
signed main() {
    //ifstream cin("E:\\acm dream\\in.in");
	//ofstream cout("E:\\acm dream\\out.out");
	FIO;
    #ifdef err
	double be = clock();
    #endif

    int n,k,l;cin>>n>>k>>l;
    _for(i,1,n+1)f[0][i]=f[1][i]=i;
    _for(i,0,k){
        int u,v;cin>>u>>v;
        mer(u,v,0);
    }
    _for(i,0,l){
        int u,v;cin>>u>>v;
        mer(u,v,1);
    }
    _for(i,1,n+1)mp[{find(i,0),find(i,1)}]++;
    _for(i,1,n+1)cout<<mp[{find(i,0),find(i,1)}]<<' ';
    
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 16520
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int b[102];
    for (i = 0; i < n; i++)
        scanf("%d", &b[i]);
    int ans[102];
    int j, max;
    for (i = n - 1; i >= 0; i--)
    {
        max = -1;
        for (j = 0; j <= i; j++)
        {
            if (b[j] == j + 1)
            {
                max = j;
            }
        }
        if (max == -1)
        {
            printf("-1\n");
            return 0;
        }
        ans[i] = b[max];
        for (j = max; j < i; j++)
            b[j] = b[j + 1];
    }
    for (i = 0; i < n; i++)
        printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 128
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$e = trim(fgets(STDIN));
$k = trim(fgets(STDIN));

echo $k >= ( $e-$a ) ? "Yay!" : ":(";
?>


Measured memory_bytes: 4604
#include <stdio.h>
int main()
{
	int N;
	scanf("%d",&N);
	int i;
	int a[105];
	for(i=0;i<=104;i++)
	{
		a[i]=0;
	}
	for (i=1;i<=N;i++)
	{
		int num;
		int t=0;
		num=i;
		while(num%2==0)
		{
			num=num/2;
			t+=1;
		}
		a[i-1]=t;
	}
	int max=0;
	int x,y;
	for(x=0;x<=N-1;x++)
	{
		if(a[x]>max)
		{
			max=a[x];
			y=x;
		}
	}
	printf("%d",y+1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, M, X, i, j, C[20], A[20][20], judge=0, ans=INF;

    cin >> N >> M >> X;

    for(i=1; i<=N; i++){
        cin >> C[i];

        for(j=1; j<=M; j++){
            cin >> A[i][j];
        }
    }

    vector<ll> v;

    for(i=1; i<=N; i++){
        v.push_back(i);
    }

    // {0, 1, ..., N-1} の部分集合の全探索(SとTに分ける)
    for (ll bit = 0; bit < (1<<N); bit++) {
        vector<ll> S, T;
        ll sum[20]={0}, p=0;

        for (ll i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                // Sの末尾にiを追加する
                S.push_back(i);
            }
            else{
                T.push_back(i);
            }
        }

        for (ll i = 0; i < (ll)S.size(); ++i) {
            p += C[S[i]+1];
            for(j=1; j<=M; j++){
                sum[j] += A[S[i]+1][j];
            }
        }

        ll judge=1;

        for(i=1; i<=M; i++){
            if(sum[i]<X) judge=0;
        }

        if(judge==1) chmin(ans,p);
    }

    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
n = int(input())
apple = []
for _ in range(2):
    apple.append(list(map(int, input().split())))
orange = []
for i in range(n):
    a = apple[0]
    b = apple[1]
    orange.append(sum(a[0:i+1] + b[i:n]))
print(max(orange))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+100;
//map<int,int> mmpe,mmpo;
struct node{
    int num;
    int cnt;
    node(){}
    node(int _num,int _cnt){
        num=_num;
        cnt=_cnt;
    }
    bool operator<(const node &rhs)const
    {
        return cnt>rhs.cnt;
    }
}datae[maxn],datao[maxn];
void init0(){
    for(int i=0;i<maxn;i++){
        datae[i].cnt=datao[i].cnt=0;
        datae[i].num=datao[i].num=i;
    }
}
int main()
{
    int n;
    while(scanf("%d",&n)==1){
        init0();
        for(int i=1;i<=n;i++){
            int tmp;
            scanf("%d",&tmp);
            if(i%2==1){///奇数{
                datao[tmp].cnt++;
            }
            else {
                datae[tmp].cnt++;
            }
        }
        sort(datae,datae+maxn);
        sort(datao,datao+maxn);
        if(datae[0].num!=datao[0].num){
            int ans=n-datae[0].cnt-datao[0].cnt;
//            cout<<datae[0].cnt<<"   "<<datao[0].cnt<<endl;
            printf("%d\n",ans);
        }
        else{///
            int ans1=n-datae[0].cnt-datao[1].cnt;
            int ans2=n-datae[1].cnt-datao[0].cnt;
//            cout<<datae[0].cnt<<"   "<<datao[1].cnt<<endl;
//            cout<<datae[1].cnt<<"   "<<datao[0].cnt<<endl;
//            cout<<ans1<<"  "<<ans2<<endl;
            printf("%d\n",min(ans1,ans2));
        }
    }
}


Measured memory_bytes: 1792
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 100000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

ll pow(ll a,ll b){
	ll res = 1 ;
	for(int i=0;i<b;i++) res *= a ;
	return res ;
}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vvll dp(m+1,vll(pow(2,n),INF)) ;
	dp.at(0).at(0) = 0 ;
	for(int i=0;i<m;i++){
		ll a,b ;
		cin >> a >> b ;
		ll bit = 0 ;
		for(int j=0;j<b;j++){
			ll c ; cin >> c ;
			bit |= (1<<(c-1)) ;
		}
		for(int j=0;j<dp.at(0).size();j++){
			dp.at(i+1).at(j|bit) = min(dp.at(i+1).at(j|bit),dp.at(i).at(j)+a) ;
			dp.at(i+1).at(j) = min(dp.at(i+1).at(j),dp.at(i).at(j)) ;
		}
	}
	if(dp.at(m).at(dp.at(m).size()-1)==INF){
		cout << -1 << endl ;
		return 0 ;
	}
	cout << dp.at(m).at(dp.at(m).size()-1) << endl ;
}


Measured memory_bytes: 32384
const INF: i32 = 1e9 as i32;

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [i32; n],
    }

    h.sort();

    let begin = h.iter();
    let end = h.iter().skip(k - 1);

    let mut ret = INF;
    for (l, r) in begin.zip(end) {
        let diff = *r - *l;
        if ret > diff {
            ret = diff;
        }
    }
    println!("{:?}", ret);
}


Measured memory_bytes: 6396
m = gets.to_i
es = Array.new(m) { [] }
cs = Array.new m, 0
gets.to_i.times do
  x, y = gets.split.map {|s| s.to_i - 1 }
  next if x == 1 || y == 1
  es[x] << y
  cs[y] += 1
end
todo = m.times.select {|i| cs[i].zero? }
rs = []
until todo.empty?
  x = todo.pop
  rs << x unless x == 1
  es[x].each {|y|
    cs[y] -= 1
    todo << y if cs[y].zero?
  }
end
rs << 1
rs.each {|x| p x + 1 }

Measured memory_bytes: 8744
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> A(N);rep(i,N)cin >> A[i];
    int q;cin >> q;
    vector<int> m(q);rep(i,q)cin >> m[i];

    vector<int> bit_flag(22);
    rep(i,22){
        bit_flag[i] = (1 << i);
    }

    map<int,int> M;

    for(int bit = 0;bit < (1 << N);bit++){
        int tmp = 0;
        rep(k,N){
            if(bit & bit_flag[k]){
                tmp += A[k];
            }
        }   
        M[tmp]++;
    }

    rep(i,q){
        bool ok = false;
        if(M[m[i]] > 0)cout << "yes" << endl;
        else cout << "no" << endl;
    }
}



Measured memory_bytes: 3124
w,h,n=input().split()
w,h,n=int(w),int(h),int(n)
s=[[0 for i in range(w)] for j in range(h)]

for i in range(n):
    x,y,a=input().split()
    x,y,a=int(x),int(y),int(a)
    if a==1:
        if x==0:
            pass
        else:
            for j in range(h):
                s[j][:x]=[1 for k in range(x)]
    elif a==2:
        if x==w:
            pass
        else:
            for j in range(h):
                s[j][x:]=[1 for k in range(w-x)]
    elif a==3:
        if y==0:
            pass
        else:
            for j in range(y):
                s[h-j-1]=[1 for k in range(w)]
    else:
        if y==h:
            pass
        else:
            for j in range(h-y):
                s[j]=[1 for k in range(w)]
c=0
for i in range(h):
    for j in range(w):
        if s[i][j]==0:
            c+=1
#print(d)
#print(s)
print(c)


Measured memory_bytes: 3188
n,k,q=map(int,input().split())
a=[]
while True:
  try:
    a.append(int(input()))
  except:
    break;
t=[0]*n
for i in a:
  t[i-1]+=1
for i in t:
  if i >= q - k + 1:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 8620
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

l = INT()
ans = pow(l / 3, 3)
print(ans)

Measured memory_bytes: 59628
n = int(input())
a = list(map(int, input().split() ))
b = list(map(int, input().split() ))
c = list(map(int, input().split() ))

ans = 0
for k in range(n-1):
	if a[k+1] - a[k] == 1 :
		ans += c[a[k] - 1]

print(ans + sum(b))


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

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)

#define mx              1234567899
#define PI              2*acos(0.0)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for(__typeof(i) i=a; i<=b; i++)
#define rev(i,a,b)      for(__typeof(i) i=a; i>=b; i--)

using namespace std;

ll gcd(ll a,ll b)
{
    if(b==0) return a;
    if(a%b==0) return b;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}


ll solution(ll a,ll b,ll c)
{
    ll res = a;
    res-=(a/b);
    res-=(a/c);
    res+=a/(lcm(b,c));

    return res;
}

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = solution(b,c,d)-solution(a-1,c,d);
    cout<<ans<<endl;
}



Measured memory_bytes: 256
import sys

def main(n):
    """ main
    """
    result = []

    n = n - 1

    while True:
        result.append(chr(97 + n%26))
        n = int(n / 26) - 1

        if n < 0:
            break

    result.reverse()

    return "".join(result)

if __name__ == "__main__":
    N = int(sys.stdin.readline())

    print(main(N))

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    int a,b,c;
    cin >> a >> b >> c;
    int i;
    int m = a%b;
    rep(i,b){
        if (m*i%b==c){
            pri("YES");
    return 0;
        }
    }
    pri("NO");
    


    return 0;
}



Measured memory_bytes: 256
N = int(input())
import itertools

count = 0
data = [3,5,7]
for i in range(3, len(str(N))+1):
    l = list(itertools.product(data, repeat=i))
    for j in range(len(l)):
        n = 0
        if 3 in l[j] and 5 in l[j] and 7 in l[j]:
            for keta in range(i-1,-1,-1):
                n += 10**keta * l[j][keta]
            if n <= N:
                count += 1
print(count)

Measured memory_bytes: 6752
#include <iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int M = (N*(N-1))/2;
    if(K > M-(N-1)){
        cout << -1 << endl;
        return 0;
    }
    int L = (M-(N-1))-K;
    int v = N-1+L;
    
    cout << v << endl;
    for(int i = 2; i <= N; i++){
        cout << 1 <<  ' '<< i << endl;
    }
    int sum = 0;
    if(L == 0) return 0;
    for(int i = 2; i <= N; i++){
        for(int j = i+1; j <= N; j++){
            cout << i << ' ' << j << endl;
            sum++;
            if(sum >= L) return 0;
        }
    }
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010], t;
void solve(){
	cin >> n >> t;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	int mi = INF, ma = 0, cnt = 0, ans = 0, cnt2 = 0, mma = 0;
	for(int i = 0; i < n; i++){
		bool update = 0;
		if(chmin(mi, a[i])) {cnt=1; cnt2=0; ma=0; update=1;}
		if(chmax(ma, a[i])) {cnt2=1; update=1;}
		if(chmax(mma, ma-mi)) ans = 1;
		else if(mma == ma-mi && update) ans++;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
  int R;
  cin >> R;
  if(R<1200)  cout << "ABC" << endl;
  else if(R<2800) cout << "ARC" << endl;
  else  cout << "AGC" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    WeightedGraph<ll> g(n);
    rep (i, n - 1) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    for (auto &dist : dijkstra(g, 0)) {
        // eprintf("%lld\n", dist);
        cout << dist % 2 << "\n";
    }
    return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int dfs(int k,vvi &G) {
  if(sz(G[k])==0) return 0;
  vi res;
  for(auto t:G[k]) {
    res.push_back(dfs(t,G));
  }
  sort(rng(res));
  reverse(rng(res));
  int r = 0;
  rep(i,sz(res)) {
    chmax(r,res[i]+i+1);
  }
  return r;
}
  
int main() {
  int N;
  cin >> N;
  vvi G(N);
  srep(i,1,N) {
    int j;
    cin >> j;
    j--;
    G[j].push_back(i);
  }
  cout << dfs(0,G) << endl;
  return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
int main(){
    char b; cin >> b;
    if(b == 'A'){
        cout << 'T' << endl;
    }
    else if(b == 'T'){
        cout << 'A' << endl;
    }
    else if(b == 'G') {
        cout << 'C' << endl;
    }
    else if(b == 'C'){
        cout << 'G' << endl;
    }
 return 0;
}

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

class Main {
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);

	public void solve() {
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();

		if (A > B) {
			out.println(0);
			return;
		}
		if (N == 1) {
			if (A == B) {
				out.println(1);
			} else {
				out.println(0);
			}
			return;
		}

		long max = (A + B) + (N - 2) * B;
		long min = (A + B) + (N - 2) * A;

		out.println(max-min+1);
	}




	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 22612
#a
from collections import deque
n = int(input())
b = list(map(int, input().split()))

is_valid = True
for x in range(len(b)):
    if b[x] > x + 1:
        print(-1)
        is_valid =False
        break

if is_valid:
    generate = deque()
    while b:
        for x in reversed(range(len(b))):
            if (x + 1) == b[x]:
                i = b.pop(x)
#                 print(i)
                generate.appendleft(i)
#                 print(f'b: {b}')
                break

    for x in range(len(generate)):
        print(generate[x])

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string S;
int main(int argc, char **argv) {
    cin >> S;
    int res = 0;
    string prev = "#";
    string cur = "";
    for(int i = 0; i < S.size(); ++i) {
        cur.push_back(S[i]);
        if(cur == prev) {

        } else {
            prev = cur;
            cur = "";
            res++;
        }

    }
    

    cout << res << endl;
}

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

namespace AtCoder_20190707_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            string[] a = Console.ReadLine().Split(' ');
            int[] An = new int[a.Length];

            bool isDenied = false;

            for (int i = 0; i < a.Length; i++)
            {
                An[i] = int.Parse(a[i]);
            }

            for (int i = 0; i < An.Length; i++)
            {
                if(An[i] % 2 == 0)
                {
                    if(An[i] % 3 != 0 && An[i] % 5 != 0)
                    {
                        isDenied = true;
                    }
                }
            }

            if (isDenied)
            {
                Console.WriteLine("DENIED");
            }
            else
            {
                Console.WriteLine("APPROVED");
            }
        }
    }
}


Measured memory_bytes: 11092
package main

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

func solve() {
	s, t := getString(), getString()
	a, b := getInt(), getInt()
	u := getString()

	switch u {
	case s:
		a--
	case t:
		b--
	}

	fmt.Fprintln(wr, a, b)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

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

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

int r, g;

int main()
{
    cin >> r >> g;
    cout << 2 * g - r << endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, W;
    cin >> N >> W;

    vector<ll> A;
    vector<ll> B;
    vector<ll> C;
    vector<ll> D;

    ll base;
    // cout << N << endl;
    REP(i, N){
        ll w, v;
        cin >> w >> v;
        // cout << i << " " << w << endl;
        if(i==0){
            base = w;
            A.push_back(v);
        }
        else if(w == base){
            A.push_back(v);
            // cout << "A" << endl;
        }
        else if(w == base+1){
            B.push_back(v);
            // cout << "B" << endl;
        }
        else if(w == base+2){
            C.push_back(v);
            // cout << "C" << endl;
        }
        else{
            D.push_back(v);
            // cout << "D" << endl;
        }
    }
    
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());
    sort(D.begin(), D.end(), greater<ll>());

    ll AS = A.size();
    ll BS = B.size();
    ll CS = C.size();
    ll DS = D.size();

    vector<ll> sumA(AS+1);
    sumA[1] = A[0];
    for(ll i=2; i<=AS; i++){
        sumA[i] = sumA[i-1] + A[i-1];
        // cout << "A:" << sumA[i] << endl;
    }

    vector<ll> sumB(BS+1, 0);
    if(BS > 0){
        sumB[1] = B[0];
        for(ll i=2; i<=BS; i++){
            sumB[i] = sumB[i-1] + B[i-1];
            // cout << "B:" << sumB[i] << endl;
        }
    }
    
    vector<ll> sumC(CS+1, 0);
    if(CS > 0){
        sumC[1] = C[0];
        for(ll i=2; i<=CS; i++){
            sumC[i] = sumC[i-1] + C[i-1];
            // cout << "C:" << sumC[i] << endl;
        }
    }
    
    vector<ll> sumD(DS+1, 0);
    if(DS>0){
        sumD[1] = D[0];
        for(ll i=2; i<=DS; i++){
            sumD[i] = sumD[i-1] + D[i-1];
            // cout << "D:" << sumD[i] << endl;
        }
    }
    // cout << AS << BS << CS << DS << endl;
    // cout << sumC[0] << endl;
    ll ans = 0;
    for(ll i=0; i<=AS; i++){
        for(ll j=0; j<=BS; j++){
            for(ll k=0; k<=CS; k++){
                for(ll l=0; l<=DS; l++){
                    if(i*base + j*(base+1) + k*(base+2) + l*(base+3) > W) continue;
                    ans = max(ans, sumA[i]+sumB[j]+sumC[k]+sumD[l]);
                }
            }
        }  
    }    
    cout << ans << endl;
    return 0;
}

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

class Main {
    public static void main(String[] args) throws IOException {
		
		// ** For submission. 
		Scanner sc = new Scanner(System.in);
		
		// Write your code here. 
		
        int n = sc.nextInt();
        int L = sc.nextInt();
        
        String[] strs = new String[n];
        for (int i = 0; i < n; i++) {
        	strs[i] = sc.next();
		}
        
        Arrays.sort(strs);
        
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strs.length; i++) {
			sb.append(strs[i]);
		}
        
        System.out.println(sb.toString());
        
    }
}







































Measured memory_bytes: 23764
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll a,b;
  cin >> a >> b;
  ll k = b - a;
  cout << k * (k+1) / 2 - b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {
	ll a, b;
	cin >> a >> b;
	ll ans = -10000;
	MAX(ans, a + b);
	MAX(ans, a - b);
	MAX(ans, a * b);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int		main(void)
{
	int a,b;
	int count = 0;
	int sum = 1;

	scanf("%d%d", &a,&b);
	if (a <= 0)
		printf("%d", 0);
	while (sum < b)
	{
		sum--;
		sum += a;
		count++;
		if (sum >= b)
			break ;
	}
	printf("%d", count);
	return (0);
}


Measured memory_bytes: 128