akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

vvl matmul(vvl &dp, vvl &mt){
    ll m=mt.size();
    vvl ret(m,vl(m,0));
    rep(i,m)rep(j,m)rep(k,m){
        ret[i][j]+=dp[i][k]*mt[k][j];
        ret[i][j]%=MOD;
    }
    return ret;
}

void matpow(vvl &dp, vvl &mt, ll k){
    ll m=dp.size();
    while(k){
        if(k&1)dp=matmul(dp,mt);
        mt=matmul(mt,mt);
        k/=2;
    }
}

int main(){
  ll n,k;cin >> n >>k;
  vvl dp(n,vl(n)),mat(n,vl(n));
  rep(i,n)dp[i][i]=1;
  rep(i,n)rep(j,n)cin >> mat[i][j];
  matpow(dp,mat,k);
  ll ans=0;
  rep(i,n){
    rep(j,n){
      ans+=dp[i][j];
      ans%=MOD;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3680
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    counter = collections.Counter()
    for _ in range(N):
        a, b = il()
        counter[a] += b
    counter = sorted(counter.items(), key=lambda x: x[0])

    k = 0
    for key, value in counter:
        k += value
        if k >= K:
            print(key)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 21444
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  string s;
  cin >> s;
  int flag[15] = {};
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      flag[i] = 1;
    }
  }
  int ans = 0;
  int tmp = 0;
  for(int i = 0; i <= 10; i++) {
    if(flag[i] == 1) {
      tmp++;
    }else {
      tmp = 0;
    }
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define a first
#define b second
#define pb push_back
const int MAX = 101010;
int connection[MAX]; // 連結成分番号を保存.
int appearance[MAX]; // 連結成分番号の出現回数.
int ans[MAX];
vvi F(MAX);  // 友達関係.
vector<P> B; // ブロック関係.

// グラフを幅優先探索する.
// https://ja.wikipedia.org/wiki/幅優先探索
// ※bfsの動作確認用.
// @param G: グラフ.
// @param s: グラフの探索開始頂点.
// @param l: 連結成分番号(※1以上).
// @return: 特に無し.
void bfs(vvi &G, int s, int l){
    
    // 1. 空のキュー.
    queue<int> q;
    
    // 2. 訪問済みフラグ設定.
    connection[s] = l;
    
    // 3. 探索地点 s をキュー q に追加.
    q.push(s);
    while(!q.empty()){
        
        // 4. キューから取り出す.
        int u = q.front();
        q.pop();
        
        // 5. 取り出した要素を処理.
        for(auto &e : G[u]){
            
            // 6. 訪問済であれば, 処理をスキップ.
            if(connection[e] > 0)            continue;
            if(connection[e] == 0 && e != s) connection[e] = l, q.push(e);
        }
    }
    return;
}

int main(){
    
    // 1. 入力情報.
    int N, M, K;
    scanf("%d %d %d", &N, &M, &K);
    int a, b;
    rep(i, M){
        scanf("%d %d", &a, &b);
        a--, b--;
        F[a].pb(b);
        F[b].pb(a);
    }
    rep(i, K){
        scanf("%d %d", &a, &b);
        a--, b--;
        B.pb({a, b});
    }
    
    // 2. 各頂点に対する連結成分番号を設定.
    int id = 0;
    rep(i, N) if(connection[i] == 0) bfs(F, i, ++id);
    // rep(i, N) printf("i=%d con=%d\n", i, connection[i]);
    
    // 3. 各連結成分番号の出現回数を計算.
    rep(i, N) appearance[connection[i]]++;
    
    // 4. 友達候補の集計.
    rep(i, N){
        // 友達候補の数を計算.
        ans[i] += appearance[connection[i]];
        // 自分自身は, 減算.
        ans[i]--;
        // 友達関係を減算.
        ans[i] -= F[i].size();
    }
    
    // 5. ブロック関係を減算.
    rep(i, K){
        a = B[i].a;
        b = B[i].b;
        // 同じ連結成分にある場合だけ, 減算.
        if(connection[a] == connection[b]) ans[a]--, ans[b]--;
    }
    
    // 6. 出力.
    rep(i, N){
        printf("%d", ans[i]);
        if(i < N - 1) printf(" ");
    }
    return 0;
    
}

Measured memory_bytes: 8688
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string c; cin >> c;
    if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u") {
        puts("vowel");
    } else puts("consonant");
    return 0;
}

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

#define int long long

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int k, a, b;
	cin >> k >> a >> b;
	int temp = (b/k)*k;
	if(temp >= a) {
		cout << "OK";
	} else {
		cout << "NG";
	}
				
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
main(){
	daman
	int n;
	cin>>n;
	string str;
	map<string,int>m;
	
	for(int i=0;i<n;i++)
	{
		cin>>str;
		m[str]++;
	}
	
	cout<<"AC x "<<m["AC"]<<"\n";
	cout<<"WA x "<<m["WA"]<<"\n";
	cout<<"TLE x "<<m["TLE"]<<"\n";
	cout<<"RE x "<<m["RE"]<<"\n";
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        if (a.charAt(a.length() - 1) == b.charAt(0) &&
                b.charAt(b.length() - 1) == c.charAt(0))
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main () {
    string s;
    cin >> s;
    int l = s.length();
    string t = "keyence";
    if (s == t) {
        puts("YES");
        return 0;
    }
    for (int i = 0; i < l; i++) {
        int j = s.length() - t.length() + i;
        if (!(j < l)) break;
        string a = "";
        for (int k = 0; k < i; k++) a += s[k];
        for (int k = j; k < l; k++) a += s[k];
        if (a == t) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<char> x(4);
  for(int i=0;i<4;i++){cin>>x[i];}
  int z=0;
  for(int i=0;i<2;i++){
    if(x[i]==x[i+1]&&x[i+1]==x[i+2]){
      z++;
      break;
    }
  }
  switch (z){
      case 1:cout<<"Yes"; break;
      case 0:cout<<"No"; break;
  }
      
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
using P = pair<int,int>;


int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;

    int happ = 0;
    int left = 0, right = 0;
    while(left < S.size()){
        while(S[left] == S[right] && right < S.size()) right++;
        happ += right - left -1;
        left = right;
    }
    cout << min(N-1, happ+2*K) << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int num = 0;

		if (n >= 3 * 5 * 7) {
			num++;
			if (n >= 3 * 5 * 11) {
				num++;
				if (n >= 3 * 5 * 13) {
					num++;
				}
			}
		}

		if (n >= 3 * 3 * 3 * 5) {
			num++;
			if (n >= 3 * 3 * 3 * 7) {
				num++;

			}
		}

		System.out.println(num);

	}
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	}

}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  ll a,b;cin>>a>>b;
  ll n=b-a+1LL;
  if(n==1LL){
    cout << a << endl;
    return 0;
  }
  ll out;
  if(b%2LL==0){
    --n;
    if(a%2LL==0LL){
      if((n/2LL)%2LL==0LL){
        out = b^0LL;
      } else{
        out = b^1LL;
      }
    } else {
      --n;
      if((n/2LL)%2LL==0LL){
        out = b^0LL^a;
      } else{
        out = b^1LL^a;
      }
    }
  } else{
    if(a%2LL==0LL){
      if((n/2LL)%2LL==0LL){
        out = 0LL;
      } else{
        out = 1LL;
      }
    } else {
      --n;
      if((n/2LL)%2LL==0LL){
        out = 0LL^a;
      } else{
        out = 1LL^a;
      }
    }
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");

		int N = Integer.parseInt(lines[0]);
		int A = Integer.parseInt(lines[1]);
		int B = Integer.parseInt(lines[2]);

		if(N * A < B) {
			System.out.println(N*A);
		}else {
			System.out.println(B);
		}
	}

}


Measured memory_bytes: 35632
from collections import Counter
def primes(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n = n // i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def comb(m,n):
  if n > m - n:
    n = m - n
  r = 1
  for k in range(m, m - n, -1):
    r *= k
  d = 1
  for k in range(1, n + 1):
    d *= k
  return r // d

N,M = map(int, input().split())
ans = 1
for v in Counter(primes(M)).values():
  ans *= comb(N+v-1,N-1)
  ans %= 10**9+7
print(ans)


Measured memory_bytes: 3316
D, N = map(int, input().split())

if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)

elif D == 1:
    if N == 100:
        print(N*100+100)
    else:
        print(N*100)

elif D == 2:
    if N == 100:
        print(N*10000+10000)
    else:
        print(N*10000)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] surface =  br.readLine().split(" ");
   String ordern = br.readLine();
   int n = Integer.parseInt( ordern );


   Dise dice1 = new Dise();
   dice1.setSurface(surface);
   dice1.SetDice(1, 2 , 3);


   for(int i = 0; i < n ; i++){

	   String[] order = br.readLine().split(" ");
	   dice1.RegulateDice( Integer.parseInt( order[0] ) ,Integer.parseInt( order[1] ));
	   System.out.println(dice1.surface[dice1.Right] );
	   dice1.SetDice(1, 2 , 3);

   }

  }
}

class Dise{

	int[] surface = new int [6];
    int Top,Bottom,Right,Left,Front,Back;


	void setSurface(String[] SurfaceString){

		for(int i = 0; i < 6; i++){

			surface[i] = Integer.parseInt( SurfaceString[i] );

		}

	}

    void SetDice(int top, int front, int right){
	   Top  = top - 1;
       Front = front - 1;
       Right = right - 1;
       Bottom = 5- (top - 1);
       Back = 5- (front - 1);
       Left = 5- (right - 1);
    }//SetDice


    void RegulateDice( int setTop, int setFront  ){


    	if( surface[Left] == setTop )   {


    	    RollDice("E");

    	}else if( surface[Right] == setTop ){

    		RollDice("W");

    	}else if( surface[Front] == setTop ){

    		RollDice("N");

    	}else if( surface[Back] == setTop ){

    		RollDice("S");

    	}else if( surface[Bottom] == setTop ) {

    		RollDice("NN");

    	}else {



    	}

    	if( surface[Left] == setFront )   {

      	  RollDice("NES");

      	}else if( surface[Right] == setFront ){

      		RollDice("NWS");

      	}else if(surface[Back]== setFront){

      		RollDice("NEES");

      	}

    	
    }

    void RollDice(String RollString){

    	String[] SurfaceString =  RollString.split("");
    	for(int i = 0; i < SurfaceString.length ; i++){

    		if( SurfaceString[i].equals("W") ){

    			Bottom = Left;
    			Left = Top;
    			Top = 5 - Bottom;
    			Right = 5 - Left;

    		}else if( SurfaceString[i].equals("S")){

    			Bottom = Front;
    			Front = Top;
    			Top = 5 - Bottom;
    			Back = 5 - Front;

    		}else if( SurfaceString[i].equals("E")){

    			Bottom = Right;
    			Right = Top;
    			Top = 5 - Bottom;
    			Left = 5 - Right;

    		}else{

    			Bottom = Back;
    			Back = Top;
    			Top = 5 - Bottom;
    			Front = 5 - Back;

    		}
    	}


    }//RollDice

}

Measured memory_bytes: 24584
#include <iostream>

using namespace std;

int div[17];

int dfs(int num, int s)
{
    int ret = 0;

    if (num == 0)
        return 1;
    else if (num < 0)
        return 0;

    for (int i = s; i < 17; i++) {
        if (num < div[i])
            break;
        ret += dfs(num - div[i], i);
    }
    return ret;
}

int main()
{
    int n;

    for (int i = 1; i <= 17; i++)
        div[i - 1] = i * i;

    while (cin >> n, n) {
        int ans = 0;

        cout << dfs(n, 0) << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
import Data.List

main :: IO ()
main = do
  n <- readLn
  as <- map read . words <$> getLine
  let b = calcB n as
  print $ sadness n as b

calcB :: Int -> [Int] -> Int
calcB n as = median $ sort $ zipWith (-) as [1..]

median :: [Int] -> Int
median xs = go l r ys zs
  where
    (l:ys) = xs
    (r:zs) = reverse xs
    go l r [] [] = l + (r - l) `div` 2
    go l r (y:ys) (z:zs)
      | y > z = l + (r - l) `div` 2
      | otherwise = go y z ys zs

sadness :: Int -> [Int] -> Int -> Int
sadness n as b = sum 
  [ abs (a - (b + i)) | (a, i) <- zip as [1..] ]

Measured memory_bytes: 120188
k = int(input())
l = [0 for x in range(100005)]
for i in range(10):
	l[i] = i+1
temp = 0
i = 9
while i < k:
	if l[temp] % 10 == 9:
		l[i] = l[temp] * 10 + 8
		l[i+1] = l[temp] * 10 + 9 
		i+=2
	elif l[temp] % 10 == 0:
		l[i] = l[temp] * 10
		l[i+1] = l[temp] * 10 + 1
		i+=2
	else:
		l[i] = l[temp] * 10 + l[temp] % 10 - 1
		l[i+1] = l[temp] * 10 + l[temp] % 10
		l[i+2] = l[temp] * 10 + l[temp] % 10 + 1
		i+=3
	temp+=1
print(l[k-1])
		

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

YES = "Yes"
NO = "No"

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

scores = [0] * K
scores[0] = A[0]
i = 1
while i < K:
    scores[i] = A[i]
    i += 1

while i < N:
    if A[i] > scores[i % K]:
        print(YES)
    else:
        print(NO)
    scores[i % K] = A[i]
    i += 1

Measured memory_bytes: 31620
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using vvvvector = vector<vvector<vector<t>>>;
template<class t>
using vvvvvector = vector<vvvvector<t>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	vector<pll> line(n);
	foreach(i, line)cin>>i.first>>i.second;
	sort(all(line), greater<pll>());
	line.insert(line.begin(), pll(0, 0));
	set<pll> s;
	multiset<ll> als;
	multiset<ll> ars;
	multiset<ll> bls;
	multiset<ll> brs;
	repa(i, n+1){
		s.emplace(line[i].first, i);
		s.emplace(line[i].second+1, -i);
		bls.insert(line[i].first);
		brs.insert(line[i].second);
	}
	ll ans = 0;
	foreach(i, s){
		if(i.second>0){
			int place = i.second;
			als.insert(line[place].first);
			ars.insert(line[place].second);
			bls.erase(bls.find(line[place].first));
			brs.erase(brs.find(line[place].second));
			if(bls.empty())continue;
			ll sum = max(0ll, *ars.begin() - *als.rbegin() + 1) + max(0ll, *brs.begin() - *bls.rbegin() + 1);
			chmax(ans, sum);
		}else{
			int place = -i.second;
			als.erase(als.find(line[place].first));
			ars.erase(ars.find(line[place].second));
			bls.insert(line[place].first);
			brs.insert(line[place].second);
			if(als.empty())continue;
			ll sum = max(0ll, *ars.begin() - *als.rbegin() + 1) + max(0ll, *brs.begin() - *bls.rbegin() + 1);
			chmax(ans, sum);
		}
	}
	als.clear();
	ars.clear();
	repa(i, n+1){
		als.insert(line[i].first);
		ars.insert(line[i].second);
	}
	repa(i, n+1){
		ll sum = line[i].second - line[i].first + 1;
		als.erase(als.find(line[i].first));
		ars.erase(ars.find(line[i].second));
		sum += max(0ll, *ars.begin() - *als.rbegin() + 1);
		als.insert(line[i].first);
		ars.insert(line[i].second);
		chmax(ans, sum);
	}

	cout <<  ans << endl;
	return 0;
}




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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    constexpr int INF = 1'000'000'000;
    vector<int> dp(N, INF);
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        if (i + 1 < N) {
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        }
        if (i + 2 < N) {
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
        }
    }
    cout << dp[N - 1] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;

int n,a[200005],b[200005];

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	int p=1,q=n;
	for (int i=1;i<=n;i++)
	{
		if (i%2) b[p++]=a[n+1-i]; else b[q--]=a[n+1-i];
	}
	for (int i=1;i<=n;i++) cout<<b[i]<<" ";
	return 0;
}

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

using namespace std;

typedef long long int ll;

#define fin(ans) cout << (ans) << endl;

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

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

void Main()
{
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll flag = 0, q, p, v;
  q = b / c - a / c;
  if(a % c == 0) q++;
  p = b / d - a / d;
  if(a % d == 0) p++;
  v = b / (lcm(c, d)) - a / (lcm(c, d));
  if(a % (lcm(c, d)) == 0) v++;
  flag = p + q - v;
  ll w = b - a + 1;
  fin(w - flag);
  return;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> a_accum(n+1);
    rep(i, n) {
        ll a;
        cin >> a;
        a_accum[i+1] = a + a_accum[i];
    }
    ll ans = 1e18;
    for ( int i = 1; i < n; ++i ) {
        ans = min(ans, abs(a_accum[n] - a_accum[i] - a_accum[i]));
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int x[n], y[n];
  rep(i, n) cin >> x[i];
  rep(i, n) y[i] = x[i];
  sort(y, y+n);
  int l = y[n/2-1], r = y[n/2];
  rep(i, n) cout << (x[i] <= l ? r : l) << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;

const int N=3e5+10;


int main(){
    //freopen("a.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x,a,b;
    cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,k,s;
int a[max_n];
int main(){
    scanf("%d%d%d",&n,&k,&s);
    for(int i=1;i<=k;i++)a[i]=s;
    int x;
    if(s==1000000000)x=1000000000-1;
    else x=s+1;
    for(int i=k+1;i<=n;i++)a[i]=x;
    for(int i=1;i<=n;i++)printf("%d%c",a[i],i==n?'\n':' ');
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#define M 110

int main(void){
  int i;
  int n,m,p,x;
  int status[M];
  int pool;

  for(;;){
    scanf("%d%d%d",&n,&m,&p);
    if(n==0 && m==0 && p==0)
      break;

    for(i=0;i<n;i++){
      scanf("%d",&x);
      status[i]=x;
    }

    pool=0;
    for(i=0;i<n;i++)
      pool+=status[i]*(100-p);

    if(status[m-1]==0)
      printf("0\n");
    else
      printf("%d\n",pool/status[m-1]);
  }

  return 0;
}

Measured memory_bytes: 0
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (w, a, b) = readListOfInt()
    val distance = if(a <= b && b <= a+w || a <= b+w && b+w <= a) 0 
        else Math.min(Math.abs(b-(a+w)), Math.abs(a-(b+w))) 

    println(distance)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(): Map<T, Int>
    = this.groupBy { it }.mapValues { it.value.size }

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 36076
while True:
	H,W=map(int,input().split())
	if H==0 and W==0:
		break
	for i in range(H):
		for j in range(W):
			if i==0 or i==H-1:
				print("#", end="")
			else:
				if j==0 or j==W-1:
					print("#", end="")	
				else:
					print(".", end="")
		print()
	print()


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

int main() {
  string s;
  int q;
  cin>>s>>q;

  int time = 1;
  bool rev = false;
  string front;
  while(time<=q) {
    int t;
    cin>>t;
    if(t==1) rev = !rev;
    else {
      int f;
      char c;
      cin>>f>>c;
      if((!rev && f==1) || (rev && f==2)) front.push_back(c);
      else s = s+c;
    }
    time++;
  }

  string ans;
  if(rev) {
    reverse(s.begin(), s.end());
    ans = s+front;
  }

  else {
    reverse(front.begin(), front.end());
    ans = front+s;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1648
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = [0]
c = n
d = 1
for i in range(n-1):
    if a[i] == a[i + 1]:
        d += 1
        c -= 1
    else:
        b.append(d)
        d = 1
b.append(d)
b.sort()
for i in range(len(b) - 1):
    b[i+1] += b[i]
print(b[max(0, c-k)])


Measured memory_bytes: 32228
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] c = new int [9];
        for(int i=0; i<N; i++){
            int tmp = sc.nextInt()/400;
            if(tmp>8)tmp=8;
            c[tmp]++;
        }
        int max,min=0;
        for(int i=0; i<8; i++){
            if(c[i]!=0)min++;
        }
        if(min==0){
            min=1;
            max=c[8];
        }else{
            max=min+c[8];
        }
        System.out.println(min+" "+max);
    }
}

Measured memory_bytes: 23508
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func main(){
	var N, M, ans int
	fmt.Scan(&N, &M)
	like_list := make([]int, M)
	for i:=0; i<N; i++ {
		sc.Scan()
		input := strings.Split(sc.Text(), " ")
		for i, v := range input {
			vn, _ := strconv.Atoi(v)
			if i!=0 {
				like_list[vn-1]++
			}
		}
	}
	for _, v := range like_list {
		if v == N {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        ans += s[i] != t[i];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3900
from collections import deque

n,k,l = map(int,input().split())
ep = [[] for i in range(n)]
er = [[] for i in range(n)]

gp = [-1]*n
gr = [-1]*n

for i in range(k):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ep[a].append(b)
    ep[b].append(a)
for i in range(l):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    er[a].append(b)
    er[b].append(a)

def dfs(e,g):
    count = 0
    for i in range(n):
        if g[i] == -1:
            g[i] = count

            q = deque([])
            q.append(i)
            while q:
                now = q.pop()

                for nex in e[now]:
                    if g[nex] == -1:
                        g[nex] = g[now]
                        q.append(nex)
            count += 1

    return g
gp = dfs(ep,gp)
gr = dfs(er,gr)
l = []
dic = {}
for i in range(n):
    s = (gp[i],gr[i])
    l.append(s)
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = [0]*n

for i in range(n):
    ans[i] = dic[l[i]]
print(*ans)

Measured memory_bytes: 91252
def main():
  s = int(input())
  #s = input()
  #s = input().split()
  #s = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 2
  lis = []
  if s == 1 or s == 2:
    print(4)
    exit()
  while s > 1:
    if s % 2 == 0:
      s //= 2
    else:
      s = s*3 + 1
    count += 1
  print(count)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    INF = 10**9

    H, W, K = map(int, input().split())
    chocolate = [ input() for _ in range(H) ]
    
    loop_H = range(H)
    min_cut = INF-1
    for div in range(1 << (H-1)):
        # 横割りでグループ分け
        group = [[]]
        group_number = 0
        for i in loop_H:
            group[group_number].append(i)
            if div >> i & 1:
                group.append([])
                group_number += 1
        # 縦に切っていく
        cut = group_number
        cnt = [0] * len(group)
        w = 0
        while w < W:
            now = [0] * len(group)
            for g in range(len(group)):
                for i in group[g]:
                    if chocolate[i][w] == '1':
                        now[g] += 1
                if now[g] > K:
                    cut = INF
                    break
                if cnt[g] + now[g] > K:
                    cut += 1
                    w -= 1
                    cnt = [0] * len(group)
                    break
                cnt[g] += now[g]
            if cut >= min_cut:
                break
            w += 1
        if cut < min_cut:
            min_cut = cut
    print(min_cut)

main()

Measured memory_bytes: 3064
def f(x):
    return ord(x) - ord('a')


base = ord('a')


def g(x):
    return chr(base + x)


n = int(input())

cnt = [[0] * 26 for _ in range(n)]
for i in range(n):
    for c in list(input()):
        cnt[i][f(c)] += 1

res = ''
for i in range(26):
    spam = min([cnt[j][i] for j in range(n)])
    res += g(i)*spam
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
	long long N,i,A[100001];
	stack<long long>odd,even;
int main()
{
	cin>>N;
	for(i=0;i<N;i++)
	{
		cin>>A[i];
		if(A[i]%2==1)
		{
			odd.push(A[i]);
		}
		else
		{
			even.push(A[i]);
		}
		while(odd.size()>1)
		{
			long long total=odd.top();
			odd.pop();
			total+=odd.top();
			odd.pop();
			even.push(total);
		}
		while(even.size()>1)
		{
			long long total=even.top();
			even.pop();
			total+=even.top();
			even.pop();
			even.push(total);
		}
	}
	if(even.size()+odd.size()==1) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 1024
""" AtCoder """

import sys
input = sys.stdin.readline

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(X)
y.append(Y)

if max(x) < min(y):
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
// fuck rating
// experience matters

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (int i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
ll nsum(ll n){return (1ll * n * (n + 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;}


#define MAX_SIZE 1005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
            for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
    for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}
        


vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};



//---------VIPUL SHARMA----------\\


void solve(){
    ll n;
    cin>>n;
    ll l[4000];
    l[0]=1,l[1]=1;
    for(int i=2;i<=3999;i++){
        l[i]=(l[i-1]*i)%md;
    }


    ll ans=0;
    fi(i,1,n/3+1){
        ll cur=n-(3*i);
        ll z=l[cur+i-1];
        z=(z*modinv(l[i-1]))%md;
        z=(z*modinv(l[cur]))%md;
        ans=(ans+z)%md;
    }
    cout<<(ans+md)%md;
}



int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    
    return 0;
}










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

ans = [0 for i in range(n-1)]

for i in range(1, n):
    for j in range(i+1, n+1):
        t = min(abs(j-i), abs(x-i)+1+abs(y-j))
        ans[t-1] += 1

for a in ans:
    print(a)


Measured memory_bytes: 3444
//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
//#include <string.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)
    cin >> a[i];
    map<int, int> mp;
    long long ans = 0;
    rep(j,n){
        int sa = j - a[j];
        int wa = j + a[j];
        ans += mp[sa];
        mp[wa]++;
    }
    
    cout << ans <<endl;
    
}


Measured memory_bytes: 21060
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        while (a[i] % 2 == 0) {
            ret++;
            a[i] /= 2;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 384
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

ll h[N], a[N], t[4*N], dp[N], mmax;

void update(int v, int tl, int tr, int pos, ll val) {
	if(tl == tr) {
		t[v] = val;
		return;
	}
	int mid = (tl + tr) / 2;
	if(pos <= mid) update(v + v, tl, mid, pos, val);
	else update(v + v + 1, mid + 1, tr, pos, val);
	t[v] = max(t[v + v], t[v + v + 1]);
}

ll get(int v, int tl, int tr, int l, int r) {
	if(tl >= l && tr <= r) return t[v];
	if(tl > r || tr < l) return 0;
	int mid = (tl + tr) / 2;
	return max(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n;
	cin >> n;

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

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

	for (int i = 1; i <= n; i++) {
		dp[i] = get(1, 1, n, 1, h[i] - 1) + a[i];
		update(1, 1, n, h[i], dp[i]);
		mmax = max(mmax, dp[i]);
	}

	cout << mmax;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch FlipAndRectangles | diff FlipAndRectangles.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address FlipAndRectangles.cpp && ./a.out

/*
 
 11/9/2019
 
 16:34-16:41 give up
 
 11/10/2019
 
 15:40- read editorial
 
 http://kmjp.hatenablog.jp/entry/2017/08/24/0930
 https://youtu.be/xRYReB8pc2E?t=2803
 
 */

const int MAX_N=2000+1;
string G[MAX_N];
int H,W;

int cum[MAX_N][MAX_N];
void solve() {
  REP(i,H-1) {
    cum[i][W-1]=1;
    for(int j=W-2; j>=0; --j) {
      int cur=G[i][j]==G[i+1][j],r=G[i][j+1]==G[i+1][j+1];
      if(cur==r) cum[i][j]=cum[i][j+1];
      cum[i][j]+=1;
    }
//    dumpC(cum[i],cum[i]+W);
  }
  
  int res=max(H,W);
  REP(j,W) {
    stack<II> S; S.emplace(0,0);
    REP(i,H) {
      int a=cum[i][j],b=i;
      while(SZ(S)&&S.top().first>=a) {
        auto p=S.top(); S.pop();
        int x=i-p.second+1,y=p.first;
        SMAX(res,x*y);
        b=p.second;
      }
      S.emplace(a,b);
    }
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>H>>W;
  REP(i,H) cin>>G[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 20096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =100;
int main()
{
    ll n,x[N];
    while(~scanf("%lld",&n))
    {
        ll ans =0;
        for(int i=0;i<n;i++)
            scanf("%lld",&x[i]);
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                ans +=x[i]*x[j];
        printf("%lld\n",ans);
    }
    return 0;
}


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

#define             ll  long long
#define            ull  unsigned long long
#define            P_B  push_back
#define            M_P  make_pair
#define             vi  vector<int>
#define             vl  vector<ll>
#define            vii  vector<pair<int, int> >
#define            vll  vector<pair<ll, ll> >
#define            pii  pair<int, int>
#define            pll  pair<ll, ll>
#define         DBG(x)  printf("%s %d\n", #x, x)
#define       DBGLL(x)  printf("%s %lld\n", #x, x)
#define         SCI(x)  scanf("%d",&x)
#define         SCD(x)  scanf("%lf",&x)
#define         SCS(x)  scanf("%s",x)
#define         CLR(x)  memset(x, 0, sizeof(x))
#define        CLRN(x)  memset(x, -1, sizeof(x))
#define        SCLL(x)  scanf("%lld", &x)
#define      FOR(i, n)  for(int i = 0; i < n; i++)
#define  FORR(i, m, n)  for(int i = m; i < n; i++)
#define     SCI2(m, n)  scanf("%d%d", &m, &n)
#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)
#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)
#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)
#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)
#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)

#define            Mod  1000000007
#define            INF  100000000



int main()
{
	string s;
	int d;
	cin >> s >> d;
	int len = s.size();
	ll dp[105][2];
	CLR(dp);
	dp[0][0] = 1;
	FOR(i, len){
		ll tdp[105][2];
		CLR(tdp);
		FOR(j, d){
			FOR(k, 10){
				if(k == s[i] - '0'){
					tdp[(j+k)%d][0] += dp[j][0];
					tdp[(j+k)%d][0] %= Mod;
				}
				// if( k <= s[i]-'0'){
					if(k < s[i]-'0'){
						tdp[(j+k)%d][1] += dp[j][0];
					}
					tdp[(j+k)%d][1] += dp[j][1];
					tdp[(j+k)%d][1] %= Mod;
					// DBGLL(tdp[(j+k)%d][1]);
					// DBGLL(dp[j][1]);
				// }
				// else{

				// }
			}
		}
		FOR(j, d){
			dp[j][0] = tdp[j][0];
			dp[j][1] = tdp[j][1];
		}
	}
	// DBGLL(dp[0][0]);
	// DBGLL(dp[0][1]);
	ll ans = (dp[0][0] + dp[0][1])%Mod;
	--ans;
	if(ans < 0) ans = Mod - 1;
	printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int n,a;
  cin >> n >> a;
  vector<int> x(n);
  rep(i,n) cin >> x.at(i);
  rep(i,n) x.at(i) -= a;
  vector<vector<ll>> dp(n+1,vector<ll>(10000,0));
  dp.at(0).at(5000) = 1;
  for(int i=1;i<=n;i++){
    rep(j,10000){
      if(0 <= j-x.at(i-1) && j-x.at(i-1) < 10000 ){
        dp.at(i).at(j) = dp.at(i-1).at(j) + dp.at(i-1).at(j-x.at(i-1));
      }else{
        dp.at(i).at(j) = dp.at(i-1).at(j) ;
      }
    }
  }
  cout << dp.at(n).at(5000)-1 << endl;
  /*rep(i,n+1){
    for(int j=4990;j<5010;j++){
      cout << dp.at(i).at(j) << " ";
    }
    cout << endl;
  }*/

  return 0;
}



Measured memory_bytes: 4352