akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {

	private int cnt;
	private int M;
	private List<Integer> arrayG = new ArrayList<>();
	private static final Main my = new Main();

	public static void main(String[] args) {
		//input
		InputOutput stdIO = new InputOutput();
		int n = stdIO.getValue();
		List<Integer> arrayA = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arrayA.add(stdIO.getValue());
		}
		//sort
		my.shellSort(arrayA, n);

		//output
		System.out.println(/*"M:" + */my.M);
//		System.out.print("G[]: ");
		stdIO.<Integer> outputLine(my.arrayG);
		System.out.println(/*"cnt:" + */my.cnt);
		stdIO.outputLines(arrayA);

		//terminate
		stdIO.close();
	}

	private void shellSort(List<Integer> arrayA, int n) {
		cnt = 0;
		for (int i = 1; ((Math.pow(3, i) - 1) / 2) <= n; i++) {
			arrayG.add(0, (int) ((Math.pow(3, i) - 1) / 2));
		}
		M = arrayG.size();

		for (int i = 0; i < my.M; i++) {
//			System.out.println("insertionSort:g:" + arrayG.get(i));
			my.insertionSort(arrayA, n, arrayG.get(i));
		}
	}

	private void insertionSort(List<Integer> values, int n, int g) {

		for (int i = g; i < n; i++) {
			int v = values.get(i);
			int j = i - g;
//			System.out.println("i:" + i + " " + "j" + j);
			while (j >= 0 && values.get(j) > v) {
				values.set(j+g, values.get(j));
				values.set(j, v);
				j = j - g;
				cnt++;
//				System.out.println(values);
			}
		}
	}
}
class InputOutput {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public int getValue() {
		int n = 0;
		try {
			n = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return n;
	}

	public List<Integer> getValueLines(int n) {
		List<Integer> values = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			values.add(getValue());
		}
		return values;
	}

	public List<Integer> getLine() {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<Integer> ary = new ArrayList<>();
			for (int i = 0; i < s.length; i++) {
				ary.add(Integer.parseInt(s[i]));
			}
			return ary;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<String> getLineString() {
		try {
			String[] s = br.readLine().trim().split(" ");
			List<String> ary = Arrays.asList(s);
			return ary;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void close() {
		try {
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public <E> void outputLine(List<E> values) {
		StringBuilder line = new StringBuilder();
		for (int k = 0; k < values.size(); k++) {
			line.append(values.get(k) + " ");
		}
		System.out.println(line.delete(line.length() - 1, line.length()));
	}
	public <E> void outputLines(List<E> values) {
		for (E e : values) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 402564
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = str(input().rstrip('\n'))
    b = str(input().rstrip('\n'))
    c = str(input().rstrip('\n'))
    cnt = 0
    for i in range(n):
        if a[i] == b[i] == c[i]:
            continue
        elif a[i] == b[i]:
            cnt += 1
        elif b[i] == c[i]:
            cnt += 1
        elif a[i] == c[i]:
            cnt += 1
        else:
            cnt += 2
    print(cnt)


if __name__ == '__main__':
    slove()


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

typedef long long ll;

int main(void) {
	ll A, B, K;
	cin >> A >> B >> K;

	ll ans_a = A;
	ll ans_b = B;
	if (K >= A + B)
		ans_a = ans_b = (ll)0;
	else if (K > A) {
		ans_a = (ll)0;
		ans_b = A + B - K;
	}
	else if (K <= A)
		ans_a = A - K;

	cout << ans_a << ' ' << ans_b << '\n';
	return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())

cnh = 0
cnb = 0
for i in range(h):
    s = input()
    for j in range(w):
        if(s[j]=='#'):
            cnh +=1
        else:
            cnb+=1
            
ch = 1
if( cnh == h+w-1):
    ch = 1
else:
    ch = 0

    
if(ch==1):
    print("Possible")
else:
    print("Impossible")
    

Measured memory_bytes: 38384
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n, l;
	while (cin >> n&& n != 0) {
		cin >> l;
		string h = "", s;
		for (int i = 0; i < n; i++)
			h += "IO";
		h += "I";
		cin >> s;
		int sum = 0;
		for (int i = 0; i < l - h.length(); i++) {
			string a = s.substr(i, h.length());
			if (a == h) sum++;
		}
		cout << sum << endl;
	}
}

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

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

void solve(long long N, std::vector<long long> a) {
  // solver code

  LL target = 1;

  for (int i = 0; i < N; i++) {
    if (a[i] == target) {
      target++;
    }
  }

  LL res = target - 1;
  LL ans = (res != 0) ? N - res : -1;
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int num[4];	
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		num[s[i]-'a']++;
	}
	int x=min(num[0],min(num[1],num[2]));
	num[0]-=x;
	num[1]-=x;
	num[2]-=x;
	if((num[0]==1||num[0]==0)&&(num[1]==1||num[1]==0)&&(num[2]==1||num[2]==0)){
		puts("YES");
	}else{
		puts("NO");
	}
}

Measured memory_bytes: 512
public class Main {

  String p( int i ) {
    return String.format( "%16s", Integer.toBinaryString( i ) ).replace( " ", "0" );
  }

  int getbit( int[] b ) {
    int bit = 0;
    for( int i = 0; i < b.length; i++ ) {
      bit |= ( b[ i ] & 1 );
      if( i != b.length - 1 ) {
        bit <<= 1;
      }
    }
    return bit;
  }

  int[] bit2int( int b, int n ) {
    int bit = b;
    int[] ar = new int[ n ];
    for( int i = n - 1; i >= 0; i-- ) {
      ar[ i ] = bit % 2;
      bit /= 2;
    }
    return ar;
  }

  int getReq( int[] req, int[] opt, int first ) {
    int tmp = first;
    int bit = 0;
    for( int i = 0; i < req.length; i++ ) {
      for( int j = 0; j < req[ i ]; j++ ) {
        bit |= tmp;
        bit <<= 1;
      }
      tmp = ( tmp == 0 ? 1 : 0 );
    }
    bit >>= 1;
    return opt[ bit ];
  }

  void run(
      java.io.InputStream in,
      java.io.PrintStream out
      ) {
    java.util.Scanner sc = new java.util.Scanner( in );
    int[] opt = new int[ 65536 ];

    java.util.Arrays.fill( opt, Integer.MAX_VALUE );

    java.util.LinkedList<Integer> q =
      new java.util.LinkedList<Integer>();

    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] b = new int[ n ];
    int[] req = new int[ m ];
    for( int i = 0; i < n; i++ ) {
      b[ i ] = sc.nextInt();
    }
    for( int i = 0; i < m; i++ ) {
      req[ i ] = sc.nextInt();
    }

    opt[ getbit( b ) ] = 0;
    q.add( getbit( b ) );
//    out.println( "opt[" + p( getbit( b ) ) + "]: 0" );

    while( !q.isEmpty() ) {
      int pbt = q.poll();
      b = bit2int( pbt, n );

      // b[ i ] <--> b[ i + 1 ]
      for( int i = 0; i < n - 1; i++ ) {
        int tmp = b[ i + 1 ];
        b[ i + 1 ] = b[ i ];
        b[ i ] = tmp;

        int[] b2 = java.util.Arrays.copyOf( b, b.length );
        int bt = getbit( b2 );

        if( opt[ bt ] == Integer.MAX_VALUE ) {
//          out.println( "opt[" + p( bt ) + "]: " + ( opt[ pbt ] + 1 ) );
          opt[ bt ] = opt[ pbt ] + 1;
          q.add( bt );
        }

        tmp = b[ i + 1 ];
        b[ i + 1 ] = b[ i ];
        b[ i ] = tmp;
      }
    }

    int req0 = getReq( req, opt, 0 );
    int req1 = getReq( req, opt, 1 );
    out.println( Math.min( req0, req1 ) );

  }

  public static void main( String[] args ) {
    new Main().run( System.in, System.out );
  }

}

Measured memory_bytes: 30024
a, b, k = list(map(int, input().split()))
div_a = [d for d in range(1, a+1) if a % d == 0]
div_b = [d for d in range(1, b+1) if b % d == 0]
common = sorted(list(set(div_a) & set(div_b)), reverse=True)
print(common[k-1])

Measured memory_bytes: 3060
N,K = map(int,input().split())
H = list(map(int,input().split()))
dp = [float('inf') for i in range(N)]
#全ノードを取り敢えずinfにしておく
dp[0] = 0
for i in range(N-1):
    #足場を一個飛んだ時
    dp[i+1] = min(dp[i+1],dp[i] + abs(H[i+1] - H[i]))
    #足場をK個飛んだ時(2~K)
    for j in range(2,min(K+1,N-i)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j]- H[i]))
print(dp[N-1])

Measured memory_bytes: 57312
#!/usr/bin/env python3
import sys
INF = float("inf")


def f(n):
    if n % 2 == 0:
        if (n//2) % 2 == 0:
            return n
        else:
            return 1 ^ n
    else:
        if ((n+1)//2) % 2 == 0:
            return 0
        else:
            return 1


def solve(A: int, B: int):
    # print(f(B))
    # print(f(A-1))
    print(f(B) ^ f(A-1))

    return


def main():

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int A,B,C;
	while(~scanf("%d%d",&A,&B))
		{
			C=2*B-A;
			if(B>=0 && A<=4500 && B<=4500 && A>=0)
				printf("%d\n",C);
				return 0;
		}
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>

int main(){
    int i,n,buff;
    std::vector<int> a;

    std::cin>>n;

    for(i=0;i<n;i++){
        std::cin>>buff;
        a.push_back(buff);
    }

    for(i=n-1;i>0;i--){
        std::cout<<a[i]<<" "<<std::flush;
    }
    std::cout<<a[0]<<std::endl;

    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(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 main(){
    char c; cin>>c;
    c=c+1;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <iostream>
using namespace std;
int n, a; map<int, int> d;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		d[a]++;
	}
	int ret = 0;
	for (pair<int, int> i : d) {
		ret += i.second % 2;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <stack>
#include <iostream>
#include<cstdlib>
using namespace std;

int main()
{
  string word;
  stack<int> S;
  long long m, n;
  while (cin >> word)
  { // 入力がある限り読み込む
    if (word == "+")
    {
      m = S.top();
      S.pop();
      n = S.top();
      S.pop();
      S.push(m + n);

      // 数を2 つpop して、和をpush する
    }
    else if (word == "-")
    {
      m = S.top();
      S.pop();
      n = S.top();
      S.pop();
      S.push(n - m);
      // 数を2 つpop して、差をpush する
    }
    else if (word == "*")
    {
      m = S.top();
      S.pop();
      n = S.top();
      S.pop();
      
      S.push(m * n);
      // 数を2 つpop して、積をpush する
    }
    else
    {
      S.push(atoi(word.c_str()));
      // word を数値にしてpush する
    }
  }
  cout << S.top() << endl;
  // S の先頭要素を表示する。
}


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

int main(){
    int array[3000][2];
    int x,y,i=0;

    while(1){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        array[i][0] = x;
        array[i][1] = y;
        i++;
    }
    for(int j = 0;j<i;j++){
        if(array[j][0] < array[j][1]){
            cout << array[j][0] << " " << array[j][1] << endl;
        }else{
            cout << array[j][1] << " " << array[j][0] << endl;
        }
    }

return 0;
}



Measured memory_bytes: 3016
///Let us start the game
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define pb push_back
using ll = long long;
using ii = pair<int, int>;
using db = long double;
using ull = unsigned long long;
const int N = 2e3 + 5, M = 1e7 + 5, MOD = 1e9+7;
const db EPS = 1e-7;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);

  int A,B,C;
  cin>> A>>B>>C;
  
  C-=min(C,A-B);
  cout<<C<<'\n';



  return 0;
}


Measured memory_bytes: 256
int main(){
	int h,w,hi,wi;
	while (1){
		scanf("%d %d",&h,&w);
		if (h == 0) break;
		for (hi=0; hi<h; hi++){
			for (wi=0; wi<w; wi++)
				printf((hi%(h-1)==0||wi%(w-1)==0) ? "#":".");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
//ABC-151-D
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

vector<vector<int>> gridBFS(vector<string> & s, int sy, int sx, char wall = '#', const int INF = 1e9){
    const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};
    int h = s.size(), w = s[0].size();
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<pair<int, int>> que;
    que.emplace(sy, sx);
    dist[sy][sx] = 0;
    while(!que.empty()){
        pair<int, int> p = que.front();
        que.pop();
        for(int i = 0; i < 4; i++){
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] != wall && dist[ny][nx] == INF){
                que.emplace(ny, nx);
                dist[ny][nx] = dist[p.first][p.second] + 1;
            }
        }
    }
    return dist;
}

signed main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h){
        cin >> s[i];
    }
    int ans = 0;
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            if(s[y][x] == '.'){
                vector<vector<int>> dist = gridBFS(s, y, x, '#', -1);
                for(int i = 0; i < h; i++){
                    for(int j = 0; j < w; j++){
                        ans = max(ans, dist[i][j]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

static class Program
{
    static void Main(string[] args)
    {
        //入力
        var AStack = new Stack<char>();
        var BStack = new Stack<char>();
        var CStack = new Stack<char>();
        var input = Console.ReadLine().ToCharArray().Reverse();
        foreach(var c in input){
          AStack.Push(c);
        }

        input = Console.ReadLine().ToCharArray().Reverse();
        foreach(var c in input){
          BStack.Push(c);
        }

        input = Console.ReadLine().ToCharArray().Reverse();
        foreach(var c in input){
          CStack.Push(c);
        }

        //処理
        var next = AStack.Pop();
        while(true){
          switch(next){
            case 'a':
              if(AStack.Count == 0){
                Console.WriteLine("A");
                return;
              }
              next = AStack.Pop();
              break;
            case 'b':
              if(BStack.Count == 0){
                Console.WriteLine("B");
                return;
              }
              next = BStack.Pop();
              break;
            case 'c':
              if(CStack.Count == 0){
                Console.WriteLine("C");
                return;
              }
              next = CStack.Pop();
              break;
            }
          }
        //出力
    }
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#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; }
//Write From this Line

int main()
{
	int n, k;
	cin >> n >> k;
	n-=k;
	if(k == 1) {
		cout << 0 << endl;
	} else 
	cout << n << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

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;
}
using namespace std;

void solve(){
	int n;
    cin>>n;
    vector<int>p(n),memo;
    rep(i,n)cin>>p[i];
    rep(i,n){
        if(p[i]==i+1){
            memo.pb(i);
        }
    }
    int ans=0;
    if(memo.size()==0){
        cout<<0<<"\n";
        return;
    }
    memo.pb(1e5+5);
    for(int i=1;i<memo.size();){
        if(memo[i]-memo[i-1]==1)i+=2;//隣り合っていれば1回の操作で2個変えられる
        else i++;//それ以外は1回で1個
        ans++;
    }
    cout<<ans<<"\n";
    return;
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 1276
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define LINF ((ll)1 << 60)
#define INF (1 << 28)
template<typename T>
void chmax(T& a, T b) {
        if (a < b) a = b;
}
template<typename T>
void chmin(T& a,T b) {
        if (a > b) a = b;
}
bool debug = false;
//.....................
ull mod = (int)1e9 + 7;
const int MAX = (int)2e5 + 5;

int N;
vector<int> a;
set<int> set1;
map<int, int> m;

void solve() {
        cin >> N;
        a.resize(N);
        rep(i, N) {
                cin >> a[i];
                a[i]--;
                m[a[i]] = i;
                set1.insert(i);
        }
        set1.insert(-1);
        set1.insert(N);
        ll res = 0;
        for (int v = N - 1; v > -1; v--) {
                auto i = m[v];
                auto itr = set1.lower_bound(i);
                itr--;
                ll l = *(itr);
                itr++; itr++;
                ll r = *(itr);
                set1.erase(i);
                ll tmp = (i - l) * (r - i) * (v + 1);
                if (debug) {
                        cerr << "set : ";
                        for (auto v : set1) {
                                cerr << v << " ";
                        }
                        cerr << endl;
                        dump(i-1);
                        dump(l);
                        dump(r);
                        dump(tmp);
                        cerr << endl;
                }
                res += tmp;
        }
        cout << res << endl;
}

signed main(int argc, char *argv[]) {
        int T = 1;
        cout << fixed << setprecision(20);
        rep(i, argc) {
                if (argv[i] == "-debug"s) {
                        debug = true;
                }
        }
        rep(i, T) {
                solve();
        }
        return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,w;
	cin>>n>>w;
	vector<deque<ll>> v(4);
	ll w0=0;
	rep(i,n){
		ll W,V;
		cin>>W>>V;
		if(i==0){
			w0=W;
		}
		v[W-w0].push_back(V);
	}
	rep(i,4){
		sort(rall(v[i]));
		v[i].push_front(0);
		partial_sum(all(v[i]),v[i].begin());
	}
	ll ans=-1;
	rep(i,v[0].size())
	rep(j,v[1].size())
	rep(k,v[2].size())
	rep(l,v[3].size()){
		if(i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)>w)continue;
		ans=max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  if (n == mp.size())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace std;

int howManyTracksIsNeeded(int *w,int n,int P){		//n個の荷物を積載量Pのトラックで運ぶ時に、必要なトラックの台数を返す(不可能な時は-1を返す)
	int capacity = P;
	int trackCount = 1;
	for(int i = 0; i < n; i++){
		if( w[i] > P) return -1;
		if(capacity >= w[i]){
			capacity = capacity - w[i];
		}else{
			capacity = P;
			capacity = capacity - w[i];
			trackCount++;
		}
	}
	return trackCount;
}

bool isCapable(int *w,int n,int P,int k){
	if( howManyTracksIsNeeded(w,n,P) <= k) return true;
	return false;
}

int binarySearch(int *w,int n,int k){
	int Pmin,Pmax,P;
	Pmin = 0;
	for(int i = 0; i < n; i++){
		if( Pmin < w[i]) Pmin = w[i];
	}
	Pmax = n * Pmin;
	P = (Pmax + Pmin) / 2;
	//cout<<"----------------"<<endl;
	while( Pmax - Pmin > 1){
		//cout << "if capacity of tracks is " << P <<", "<< howManyTracksIsNeeded(w,n,P) <<" tracks are needed" << endl;
		if(isCapable(w,n,P,k)){
			//cout<< "current P " << P <<" is capable."<< endl;
			Pmax = P;
		}else{
			//cout<< "current P " << P <<" is not capable."<< endl;
			Pmin = P;
		}
		P = (Pmax + Pmin)/2;
	}
	if( !isCapable(w,n,P,k) ){
		return Pmax;
	}
	return P;
}

int main()
{
	int n,k;
	cin >> n >> k;
	int *w = new int[n];
	for(int i = 0; i < n; i++){
		cin>>w[i];
	}
	cout<< binarySearch(w,n,k) << endl;
	return 0;
}





Measured memory_bytes: 3460
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int dm = 1 << 17;
char *dn = cn, * di = dn, * owad = dn + dm - 20;
inline void putint(int X) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (X >= 10000) {
		if (X >= 100000) dig = 6;
		else dig = 5;
	}
	else {
		if (X >= 1000) dig = 4;
		else if (X >= 100) dig = 3;
		else if (X >= 10) dig = 2;
	}
	rep1(i, dig) {
		di[dig - i] = '0' + X % 10;
		X /= 10;
	}
	di[dig] = '\n';
	di += dig + 1;
}
const int bm = 500001;
int BIT[bm];
void add(int A) {
	while (A > 0) {
		BIT[A]++;
		A -= A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A < bm) {
		ret += BIT[A];
		A += A & -A;
	}
	return ret;
}
int L[500001], R[500001], C[500001], ne[500001];
int are[500001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), Q = getint();
	rep1(i, N) C[i] = getint();
	rep1(i, Q) {
		L[i] = getint();
		int r = getint();
		ne[i] = R[r];
		R[r] = i;
	}
	rep1(i, N) {
		if (are[C[i]]) add(are[C[i]]);
		are[C[i]] = i;
		
		for (int r = R[i]; r; r = ne[r]) {
			L[r] = i - L[r] - query(L[r]) + 1;
		}
	}

	rep1(i, Q) putint(L[i]);
	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 14932
#ifdef Prateek
  #include "C:\Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

vector<int> G[N];
int vis[N];

void dfs (int u) {
   vis[u] = 1;
   for(int v : G[u]) {
      if(!vis[v]) {
         dfs(v);
      }
   }
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin >> n >> m;
   for(int i = 0; i < m; ++i) {
      int u,v;
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
   }
   int ans = -1;
   for(int i = 1; i <= n; ++i) {
      if(!vis[i]) {
         ++ans;
         dfs(i);
      }
   }
   cout << ans << '\n';
   return 0;
} 

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int t , n , m , k , x , y , z;
string s;
int a[MAXX];
char c;

int main()
{
    _FastIO;

    cin >> n;
    if(n % 1000){
        cout << 1000 - (n % 1000) << endl;
    }
    else
        cout << "0" << endl;
    return 0;
}


Measured memory_bytes: 3632
import Data.List
main = getContents >>= mapM_ print . (\(x:_:xs) -> map (h x) xs) . map (map (read :: String -> Int) . words) . lines
  where h [a,b,c,d,e,f] x
          | i x s = a
          | i x t = b
          | i x u = c
          | i x (r u) = d
          | i x (r t) = e
          | i x (r s) = f
          where  i = isInfixOf
                 r = reverse
                 s = [b,c,e,d,b]
                 t = [a,d,f,c,a]
                 u = [a,b,f,e,a]

Measured memory_bytes: 3932
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long int ll;

ll GCD(ll a,ll b){
	if( a < b){
		return GCD(b,a);
	}
	if(b == 0) return a;
	if(b == 1) return 1;
	return GCD( b, a % b);
}

ll lcm(ll a, ll b){
	ll temp;
	temp = max(a,b) / GCD(a,b);
	return temp*min(a,b);
}

int main()
{
	int n;
	cin>>n;
	ll *T = new ll[n];
	rep(i,n){
		cin>>T[i];
	}
	ll ans = 1;
	rep(i,n){
		ans = lcm(T[i],ans);
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int N, answer = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		int l, r;
		scanf("%d %d", &l, &r);
		answer += (r - l + 1);
	}
	printf("%d\n", answer);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	vector<long long> ans(200005);
  	long long n;
  	cin>>n;
  	reps(i,n){
      cin>>ans[i];
    }
long long sum=0,som=0;
  for(int i=1;i<=n;i++){
    sum+=ans[i];
    while(sum>som && i<n){
      som+=ans[n];
      n--;
    }
  }
  cout<<abs(som-sum)<<'\n';
  return 0;
}

Measured memory_bytes: 1792
from itertools import accumulate as ac
n,m=map(int,input().split())
b=[0]*(n+1)
for i in range(m):
    l,r=map(int,input().split())
    b[l-1]+=1
    b[r]-=1
b=list(ac(b))[:-1]
print(b.count(m))

Measured memory_bytes: 8892
N=int(input())
A=[int(s) for s in input().split()]

sum=A[0]
if N==1:
    sum=float(sum)

for i in range(1,N):
    new=A[i]
    sum=float((new+sum)/(new*sum))
    sum=float(1/sum)

sum_end=float(sum)
print(sum_end)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._500problems
{
    class APC001C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            WriteLine(0);
            string s = Read();
            if (s[0] == 'V') return;
            char first = s[0];
            WriteLine(n - 1);
            string l = Read();
            if (l[0] == 'V') return;
            int bottom = 0;
            int top = n - 1;
            while (bottom + 1 < top)
            {
                int mid = (bottom + top) / 2;
                WriteLine(mid);
                string now = Read();
                if (now[0] == 'V') return;

                if ((mid % 2 == 0 && now[0] == first)
                    || (mid % 2 == 1 && now[0] != first))
                {
                    bottom = mid;
                }
                else
                {
                    top = mid;
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define int long long

signed main()
{
    string s;
    cin.get();
    while(getline(cin, s), s!=".") {
        stack<int> st;
        int f = 0;
        for(int i=0; i<s.size(); ++i) {
            char c = s[i];
            if(c=='(') st.push(0);
            else if(c=='[') st.push(1);
            else if(c==')') {
                if(st.empty()) {
                    cout << "no" << endl;
                    f++;
                    break;
                }
                if(st.top() == 0) st.pop();
                else {
                    cout << "no" << endl;
                    f++;
                    break;
                }
            }
            else if(c==']') {
                if(st.empty()) {
                    cout << "no" << endl;
                    f++;
                    break;
                }
                if(st.top() == 1) st.pop();
                else {
                    cout << "no" << endl;
                    f++;
                    break;
                }
            }
        }
        if(f==0) {
            if(st.empty()) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

typedef struct{
  int f,t;
  ll c;
}edge;

bool comp(const edge &l, const edge &r){
  return l.c < r.c;
}


const int V_MAX = 1e5+5;
int V;
PLI v[V_MAX];
PLI w[V_MAX];
vector<edge> es;

class UnionFind{
  private:
    vector<int> Parent;
  public:
    UnionFind(int N){
      Parent = vector<int>(N,-1);
    }

    int find(int x){
      if(Parent[x]<0)return x;
      return Parent[x] = find(Parent[x]);
    }

    int size(int x){
      return -Parent[find(x)];
    }

    bool unite(int x, int y){
      x = find(x);
      y = find(y);
      if(x==y)return false;
      if(size(x)<size(y)) swap(x,y);
      Parent[x] += Parent[y];
      Parent[y] = x;
      return true;
    }

    bool same(int x, int y){
      return find(x) == find(y);
    }
};

ll kruskal(){
  ll res = 0;
  UnionFind uni = UnionFind(V);
  for(const edge & e: es){
    if(uni.same(e.f,e.t))  continue;
    uni.unite(e.f,e.t);
    res += e.c;
  }
  return res;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V;
  rep(i,V){
    ll x,y;cin >> x >> y;
    v[i] = PLI(x,i);
    w[i] = PLI(y,i);
  }
  sort(v,v+V);
  sort(w,w+V);
  repp(i,1,V){
    ll c  = abs(v[i-1].first - v[i].first);
    int f = v[i-1].second, t = v[i].second;
    es.push_back({f,t,c});
    c  = abs(w[i-1].first - w[i].first);
    f = w[i-1].second, t = w[i].second;
    es.push_back({f,t,c});
  }
  sort(all(es),comp);
  cout << kruskal() << endl;
  return 0;
}


Measured memory_bytes: 9584
#include <cstdio>
using namespace std;

int main(){
	int n;
	while(scanf("%d", &n), n){
		int r = 2 * n;
		for(int i = 1; r >= 0 && i * i <= n; ++i){
			if(n % i == 0){
				r -= i;
				if(i * i != n){ r -= n / i; }
			}
		}
		
		if(r == 0){
			puts("perfect number");
		}
		else if(r < 0){
			puts("abundant number");
		}
		else{
			puts("deficient number");
		}
	}
}

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


   class Program
   {
       static void Main(string[] args)
       {
           var suretu = "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 num = int.Parse(Console.ReadLine());
           string[] line = suretu.Split(',');
         Console.WriteLine(line[num - 1]);
       }
   }


Measured memory_bytes: 11092
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
#define ll long long
int main(){
	ll x, y, a, b, c;
	scanf("%lld %lld %lld %lld %lld", &x, &y, &a, &b, &c);
	ll d[a], e[b], f[c + x + y], s = 0;
	for (ll i = 0; i < a; i++) scanf("%lld", &d[i]);
	for (ll i = 0; i < b; i++) scanf("%lld", &e[i]);
	for (ll i = 0; i < c; i++) scanf("%lld", &f[i]);
	sort(d, d + a, greater<ll>());
	sort(e, e + b, greater<ll>());
	for (ll i = 0; i < x; i++) f[i + c] = d[i];
	for (ll i = 0; i < y; i++) f[i + c + x] = e[i];
	sort(f, f + c + x + y, greater<ll>());
	for (ll i = 0; i < x + y; i++) s += f[i];
	printf("%lld\n", s);
}

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

using namespace std;

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

int c[10];

bool check(){
  int sum = 0, MOD = c[9];
  rep(i,3) sum = (sum + c[i]) % MOD; 
  if((c[3]+c[4]+c[5])%MOD != sum) return false;
  if((c[6]+c[7]+c[8])%MOD != sum) return false;
  if((c[0]+c[3]+c[6])%MOD != sum) return false;
  if((c[1]+c[4]+c[7])%MOD != sum) return false;
  if((c[2]+c[5]+c[8])%MOD != sum) return false;
  if((c[0]+c[4]+c[8])%MOD != sum) return false;
  if((c[2]+c[4]+c[6])%MOD != sum) return false;
  return true;
}

int rec(int p,int S){
  int res = 0;
  if(__builtin_popcount(S) == 10){
    return check();
  }
  if(!c[p]){
    rep(i,10){
      if((S >> i) & 1) continue;
      c[p] = i+1;
      res += rec(p+1,S|(1<<i));
      c[p] = 0;
    }
  }else{
    res += rec(p+1,S);
  }
  return res;
}

int main(){
  while(true){
    int S = 0;
    bool EXIT = false;
    rep(i,10){
      cin >> c[i];
      if(c[i] > 0){
        S |= 1<<(c[i]-1);
      }else if(c[i] == -1){
        EXIT = true;
      }
    }
    if(EXIT) break;
    cout << rec(0,S) << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    vector<int>v;
    int n;
    //int a,b,c;
    //string s;
    //cin>>a>>b>>c;
    //cin.ignore();
    cin>>n;
    for(int i=0 ; i<n ;i++){
        int x;
        cin>>x;
        v.push_back(x);
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    cout<<(v.size())<<endl;

    v.clear();

    //s[3]='8';
    //cout<<s<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

int main()
{
    fast

    string a;
    cin>>a;
    bool flag=false;
    for(int i=0; i<a.size(); i++)
    {
        if(a[i]=='7')
        {
            flag=true;
            break;
        }
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		char[] chars = S.toCharArray();
		String before = String.valueOf(chars[0]);
		String dummy = "";
		int count = 1;
		for (int i = 1; i < chars.length; i++) {
			dummy = dummy.concat(String.valueOf(chars[i]));
			if (!before.equals(dummy)) {
				count++;
				before = dummy;
				dummy = "";
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 41196
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;

#define INT_MAX 2147483647

long gcd(long m, long n);
long lcm(long m, long n);

int main( void ){

	int n;
	cin >> n;
	double ans = 0;
	for( int i = 0; i < n; i++ ){
		double a;
		string b;
		cin >> a >> b;
		if( b == "JPY" ) ans += a; 
		if( b == "BTC" ) ans += a*380000; 
	}

	cout << ans;
	return 0;

}

//最大公倍数
long gcd(long m, long n)
{
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
long lcm(long m, long n)
{
	return m * n / gcd(m,n); 
}

Measured memory_bytes: 256
#include <stdio.h>

void main(void){
  long a,b,c,d;
  long x[4],max;
  int i;
  
  scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
  
  max=a*c;
  x[1]=a*d;
  x[2]=b*c;
  x[3]=b*d;
  
  for(i=1;i<4;i++){
    if(max < x[i])max=x[i];
  }
  printf("%ld\n",max);
}
    
  
  

Measured memory_bytes: 1732
#include <iostream>
using namespace std;
#define LL long long
const LL MAX=1e6+10;
LL n,m,x,y,z,k,x1,y1,z1;
LL a[MAX];
int main ()
{
    a[0]=0;
    cin>>n;
    LL max1=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=a[x-1]+1;
        max1=max(max1,a[x]);
    }
    cout<<n-max1<<endl;
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    int F[65][2]; rep(i, 65)rep(j, 2)F[i][j] = 0;
    rep(i, n){
        ll a; cin >> a;
        rep(j, 60){
            if((a >> j)& 1)F[j][1]++;
            else F[j][0]++;
        }
    }
    ll res = 0;
    rep(i, 60){
        ll a = F[i][0], b = F[i][1];
        ll sum = (a * b) % MOD;
        sum = (sum * ((1LL << i) % MOD)) % MOD;
        res = (res + sum) % MOD;
    }
    cout << res << ln;
}
    


Measured memory_bytes: 3636
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    cout << (S[0] == S[1] && S[1] != S[2] && S[2] == S[3] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int a,b,res=0;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        if((x>=a)&&(y>=b)){
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
G1 = [[] for _ in range(N)]
G2 = [[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  G1[a].append(b)
  G2[b].append(a)
  
def argsort(arr, reverse=False, shift=20):
    N = len(arr)
    tmp=[0]*N
    for i in range(N):
        tmp[i] = (arr[i] << shift) | i
    tmp = sorted(tmp,reverse=reverse)
    out=[0]*N
    mask = (1<<shift) - 1
    for j in range(N):
        i = tmp[j] & mask
        out[j] = i
    return out

def dfs(a0,seen,postorder,order):
    todo = [~a0, a0]
    while todo:
        a = todo.pop()
        if a >= 0:
            seen[a] = 1
            for b in G1[a]:
                if seen[b]: continue
                todo.append(~b)
                todo.append(b)
        else:
          if postorder[~a] == -1:
            postorder[~a] = order
            order += 1
    return seen,postorder,order
  
def dfs2(v,seen):
    todo = [v]
    seen[v] = 1
    cc = [v]
    while todo:
        v = todo.pop()
        for next_v in G2[v]:
            if seen[next_v]: continue
            seen[next_v] = 1
            todo.append(next_v)
            cc.append(next_v)
    return cc,seen
  
def scc(G1,G2):
  N = len(G1)
  seen = [0]*N
  postorder=[-1]*N
  order = 0
  for i in range(N):
    if seen[i]:continue
    seen,postorder,order = dfs(i,seen,postorder,order)

  seen = [0]*N
  scclist = []
  for i in argsort(postorder,reverse=True):
    if seen[i]:continue
    cc,seen = dfs2(i,seen)
    scclist.append(cc)
  return scclist

def main():
  scclist = scc(G1,G2)
  print(len(scclist))
  for cc in scclist:
    print(len(cc),*cc)
    
if __name__=="__main__":
  main()

Measured memory_bytes: 219224
import java.util.Scanner;


public class Main {

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

		int N = sc.nextInt();

		int[][] dp = new int[N + 1][3];
		int[][] table = new int[N][3];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 3; j++) {
				table[i][j] =sc.nextInt();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if(j==k)continue;
					dp[i + 1][k] = Math.max(dp[i + 1][k], dp[i][j] + table[i][k]);
				}
			}
		}

		int ans = 0;
		for (int i = 0; i < 3; i++) {
			 ans = Math.max(ans, dp[N][i]);
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 66448