akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int remain = in.nextInt();
            int seconds = in.nextInt();

            out.println(Math.max(remain - seconds, 0));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21460
import java.util.*;
public class Main {
    
    // Normal problem about sorting
    static void solve(){
        Scanner sc = new Scanner(System.in);
        int NOC = sc.nextInt(), L = sc.nextInt(), i = 0;
        String[] s = new String[NOC];
        while(NOC-->0) s[i++] = sc.next();
        Arrays.sort(s);
        for(String a: s) System.out.print(a);
        sc.close();
    }
    
    public static void main(String args[]) {
        solve();
    }
}

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;

  long long mins = A + B + (N - 2) * A;
  long long maxs = A + B + (N - 2) * B;

  cout << max(0ll, maxs - mins + 1) << endl;
}

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


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


mod = 10**9 + 7


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


primes = factorization(M)
# 何箇所に分けるか（cnt以下）,その中でどう分けるか（しきりをどこにおくか（振り分けられないものが出ると選べれないのとおなじになるので、cnt - 選んだ数））

if N == 1 or M == 1:
    print(1)
    exit(0)
ans = 1
for p, cnt in primes:
    tmp = 0
    for i in range(1, min(cnt, N)+1):
        tmp += cmb(N, i, mod) * cmb(cnt-1, i-1, mod)
        #print(tmp, p, cnt, i)
        tmp %= mod
    ans *= tmp
    ans %= mod

print(ans)


Measured memory_bytes: 20900
using System;
using System.Linq;

namespace arc097_b
{
    public class Unionfind
    {
        public static int[] par;//親
        public static int[] rank; //深さ
        public void init(int n)//初期化
        {
            par = new int[n]; rank = new int[n];
            for (int i = 0; i < n; i++)
            {
                par[i] = i;
                rank[i] = 0;
            }
        }
        public int root(int x)//根を求める
        {
            if (par[x] == x) return x;
            else return par[x] = root(par[x]);
        }
        public void unite(int x, int y)//集合を併合
        {
            x = root(x); y = root(y);
            if (x == y) return;
            else
            {
                if (rank[x] < rank[y]) par[x] = y;
                else
                {
                    par[y] = x;
                    if (rank[x] == rank[y]) rank[x]++;
                }
            }
        }
        public bool issame(int x, int y)//同じ集合に属しているか
        {
            return root(x) == root(y);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Unionfind find = new Unionfind();
            find.init(a[0]);
            for (int i = 0; i < a[1]; i++)
            {
                int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray();
                find.unite(y[0] - 1, y[1] - 1);
            }
            int ret = 0;
            for (int i = 0; i < a[0]; i++)
            {
                if (find.issame(i, x[i] - 1)) ret++;
            }
            Console.WriteLine(ret);
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  int minus = 0;
  int small = 1000000001;
  i64 ans = 0;
  rep(i, n) {
    if (a[i] < 0) minus++;
    if (small > abs(a[i])) small = abs(a[i]);
    ans += abs(a[i]);
  }
  if (minus % 2 == 1) {
    ans -= small * 2;
  }
  cout << ans << endl;
}

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

int v, e, a, b;
std::vector<std::vector<int>> g;
std::vector<int> indeg, out;
std::vector<bool> visited;

int main() {
    std::cin >> v >> e;
    visited.assign(v, false);
    g.assign(v, std::vector<int>(0));
    indeg.assign(v, 0);
    for (int i = 0; i < e; i++) {
        std::cin >> a >> b;
        g[a].push_back(b);
    }
    for (int i = 0; i < v; i++) {
        for (int p = 0; p < g[i].size(); p++) {
            int c = g[i][p];
            indeg[c]++;
        }
    }
    for (int w = 0; w < v; w++) {
        if (indeg[w] == 0 && !visited[w]) {
            std::queue<int> q;
            q.push(w);
            while (!q.empty()) {
                auto f = q.front();
                q.pop();
                out.push_back(f);
                for (int k = 0; k < g[f].size(); k++) {
                    int x = g[f][k];
                    indeg[x]--;
                    if (indeg[x] == 0 && !visited[x]) {
                        visited[x] = true;
                        q.push(x);
                    }
                }
            }
        }
    }
    for (int i = 0; i < out.size(); i++) {
        std::cout << out[i] << std::endl;
    }
}



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

int main() {
	int a, b;
	cin >> a >> b;
	if (a < 0 || a > 9 || b < 0 || b > 9) cout << -1 << endl;
	else cout << a * b << endl;
	return 0;
}

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

struct Graph {
  int n;
  vector<vector<int>> adj;
  Graph(int n) : n(n), adj(n) { }
  void addEdge(int u, int v) {
    adj[u].push_back(v);
  }
};

// return empty list if g has no topological order
vector<int> topologicalSort(Graph g) {
  vector<int> deg(g.n);
  for (int u = 0; u < g.n; ++u)
    for (int v: g.adj[u]) ++deg[v];
  vector<int> stack; 
  for (int u = 0; u < g.n; ++u)
    if (!deg[u]) stack.push_back(u);

  vector<int> order;
  while (!stack.empty()) {
    int u = stack.back(); stack.pop_back();
    order.push_back(u);
    for (int v: g.adj[u]) 
      if (!--deg[v]) stack.push_back(v);
  }
  return order.size() == g.n ? order : vector<int>();
}

int main(){
  int N, M;
  cin >> N >> M;
  Graph g(N);
  REP(i,M) {
    int x, y;
    cin >> x >> y; --x; --y;
    g.addEdge(x, y);
  }

  vector<int> order = topologicalSort(g);

  vector<int> dp(N, 0);
  REP(i,N) {
    for(int v: g.adj[order[i]]) {
      dp[v] = max(dp[v], dp[order[i]] + 1);
    }
  }

  int ret = 0;
  REP(i,N) ret = max(ret, dp[i]);
  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 12540
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
using namespace std;
using ll=long long;

int main(){
  ll X, N; cin>>X>>N;
  map<ll, ll> P;
  for(ll i=0; i<N; i++){
    ll p; cin>>p;
    P[p]=1;
  }
  ll d=0;
  bool keizoku=1;
  while(keizoku){
    if(!P.count(X-d)){
      cout<<X-d<<endl;
      break;
    }
    if(!P.count(X+d)){
      cout<<X+d<<endl;
      break;
    }
    d++;
  }
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define se second

using namespace std;

const int nm = 200002;

int n, m, a[nm], a2[nm];
pair<int, int> b[2 * nm];

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			b[2 * j - 1] = {j - a[j], 0};
			b[2 * j] = {j + a[j], 1};
		}
		sort(b + 1, b + 2 * n + 1);
		int u = 1;
		int d = 0;
		bool diff = 0;
		for (int j = 1; j <= n; ++j) {
			while (u <= 2 * n && (b[u].fi < j || (b[u].fi == j && b[u].se == 0))) {
				if (b[u].se == 0) {
					d++;
				} else {
					d--;
				}
				u++;
			}
			if (a[j] != d) {
				a[j] = d;
				diff = 1;
			}
		}
		if (!diff) {
			break;
		}
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d ", a[i]);
	}
#ifdef LOCAL
	cout << setprecision(6) << fixed << (double) clock() / CLOCKS_PER_SEC << "\n";
#endif
}


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

using namespace std;

int main(void){
    int N;
    cin >> N;
    long long ans = 0;
    vector<int> C(N), V(N);
    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }
    for(int i = 0; i < N; i++){
        ans += max(0, V[i] - C[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int N;
  string S;
  cin >> N >> S;
  string ans = "Yes";
  if (N % 2 == 1) {
    ans = "No";
  }
  else {
    for (int i = 0; i < N / 2; i++) {
      if (S.at(i) != S.at(N / 2 + i)) {
        ans = "No";
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	long N;
	long A;
	long B;

	long C;

	long DA;
	long DB;

	std::cin >> N;
	std::cin >> A;
	std::cin >> B;

	long D;

	D = B - A;

	if (D % 2 == 0) {
		C = D / 2;
	}
	else 
	{
		DA = N - A+1;
		DB = N - B+1;
		if (DA + DB > A + B) {
			C = (A + B - 1) / 2;
		}
		else
		{
			C = (DA + DB - 1) / 2;
		}
	}

	std::cout << C;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();

        boolean flag = false;
        for (int i = 0; i <= 100; i+=4) {
            for (int j = 0; j <= 100-i; j+=7) {
                if (i+j == n)
                    flag = true;
                if (i+j > n)
                    break;
            }
        }
        
        System.out.println(flag ? "Yes" : "No");
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int ans=0;
    for(int i=0;i<n;i+=2){
        if(a.at(i)%2==1) ans++;
    }
    cout << ans << endl;
}
   


Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

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


Measured memory_bytes: 3784
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
    c = sum(a[0 : i]) + sum(b[i - 1 : n])
    if c > ans:
        ans = c
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	char input[1001];

	scanf("%s", input);
	const string s = input;
	const int n = s.size();

	scanf("%s", input);
	const string t = input;
	const int m = t.size();

	int lmin = n;

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

		for (int j = 0; j < m; j++)
		{
			cur += (s[i + j] != t[j]);
		}

		if (cur < lmin)
		{
			lmin = cur;
		}
	}

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

	return 0;
}

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

int main(){
    int n,l;
    string str;
    multiset<string> st;
    multiset<string>::iterator it;
    cin>>n>>l;
    getchar();
    for(int i=0;i<n;i++){
        getline(cin,str);
        st.insert(str);
    }
    for(it=st.begin();it!=st.end();++it){
        cout<<*it;
    }
    printf("\n");
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;

int main() {

	int n, k;
	cin >> n >> k;

	int ans;
	ans = 1;//現在の値

	for (int i = 1; i <= n; i++)
	{
		//i回目の処理
		int A, B;
		A = 2 * ans;
		B = ans + k;
		if (A < B)
		{
			ans = A;
		}
		else {
			ans = B;
		}
	}

	cout << ans << endl;
	


	return 0;
}


Measured memory_bytes: 256
a, *bcd = map(int, input())

for bits in range(1 << 3):
    value = a
    formula = [a]
    for op, num in enumerate(bcd):
        if bits & 1 << op:
            value += num
            formula.append('+')
        else:
            value -= num
            formula.append('-')
        formula.append(num)
    if value == 7:
        formula.append('=7')
        print(*map(str, formula), sep='')
        break


Measured memory_bytes: 3060
n,k = map(int,input().split())
d= {}
for i in range(n):
    a,b=map(int, input().split())
    if d.get(a):
        d[a] +=b
    else:
        d[a] = b
res = 0
for key in sorted(d.keys()):
    if d[key]+res>=k:
        print(key)
        exit()
    res += d[key]

Measured memory_bytes: 16228
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  
        static long[] a;
        static long N;
        static long K;
        
        static void Main(string[] args)
        {
          //入力を受け取る
          //long N = int.Parse(Console.ReadLine());
          int[] NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var N = NM[0];
          var M = NM[1];
          
          var L = new int[M];
          var R = new int[M];
          
          for(int i = 0; i < M ; i++){
            int[] LR = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            L[i] = LR[0];
            R[i] = LR[1];
          }
          
          //右の区間の最小値、左の区間の最大値をもとめて条件の範囲を絞る
          var range = R.Min()-L.Max()+1;
          
          //結果を出力
          if(range > 0){
            Console.WriteLine(range);
          }else{
            Console.WriteLine(0);
          }
          
        }
 }

Measured memory_bytes: 18016
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    p_list = list(map(int, input().split()))
    a_list = [i * N for i in range(1, N + 1)]
    b_list = a_list[::-1]

    for i, p in enumerate(p_list):
        a_list[p - 1] += i

    print(*a_list)
    print(*b_list)


if __name__ == '__main__':
    main()


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int ask(ll v) {
	string S;
	cout<<"? "<<v<<endl;
	cin>>S;
	return S[0]=='Y';
}

/*
int na;
ll N=5;
int ask(ll v) {
	char bufv[20];
	char bufN[20];
	sprintf(bufv,"%lld",v);
	sprintf(bufN,"%lld",N);
	string sv=bufv;
	string sN=bufN;
	
	na++;
	cout<<v<<" "<<(v<=N)<<" "<<(sv<=sN)<<" "<<sv<<":"<<sN<<endl;
	return (v<=N)==(sv<=sN);
}
*/
void ans(ll v) {
	cout<<"! "<<v<<endl;
	//cout<<na<<endl;
	exit(0);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	//cin>>N;
	
	ll p10=10000000000LL;
	for(i=10;i>=1;i--) {
		if(ask(p10)==1) break;
		p10/=10;
	}
	
	if(i==10) {
		p10=10000000000LL;;
		for(i=10;i>=1;i--) {
			if(ask(p10-1)==0) ans(p10);
			p10/=10;
		}
	}
	if(i==0) {
		for(i=10;i<=90;i+=10) {
			if(ask(i)==1) ans(i/10);
		}
	}
	ll ret=0,cm=0;
	for(;p10>=1;p10/=10) {
		int cur=-1;
		int dd[4]={8,4,2,1};
		FOR(j,4) if(cur+dd[j]<10) {
			ll tmp=ret+(cur+dd[j])*p10;
			ll tmp2=cm*10+(cur+dd[j]);
			if(ask(tmp2*1000000000LL)==0) cur+=dd[j];
		}
		cm=cm*10+cur;
		ret+=p10*cur;
	}
	
	
	ans(ret+1);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 596
n,m=list(map(int,input().split()))
A=[[] for i in range(n)]
A1=[[0 for x in range(m)] for y in range(n)]
B=0
C=0
D=0
c=[[0] for i in range(m)]
b=[[0] for i in range(m)]

for i in range(n):
    A[i] = list(map(int,input().split()))
for j in range(m):
    b[j]=int(input())
for k in range(n):
    B=0
    for l in range(m):
        B+=A[k][l]*b[l]
    print(B)




Measured memory_bytes: 6124
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

ans=0
for i in range(K):
    tt=T[i:N:K]
    l=len(tt)
    dp = [[0]*l for _ in range(3)]
    if tt[0]=="r":
        dp[2][0]=P
    if tt[0]=="s":
        dp[0][0]=R
    if tt[0]=="p":
        dp[1][0]=S
    
    for i in range(1,l):
        if tt[i]=="r":
            dp[0][i] = max(dp[1][i-1],dp[2][i-1])
            dp[1][i] = max(dp[2][i-1],dp[0][i-1])
            dp[2][i] = max(dp[0][i-1],dp[1][i-1])+P
        if tt[i]=="s":
            dp[0][i] = max(dp[1][i-1],dp[2][i-1])+R
            dp[1][i] = max(dp[2][i-1],dp[0][i-1])
            dp[2][i] = max(dp[0][i-1],dp[1][i-1])
        if tt[i]=="p":
            dp[0][i] = max(dp[1][i-1],dp[2][i-1])
            dp[1][i] = max(dp[2][i-1],dp[0][i-1])+S
            dp[2][i] = max(dp[0][i-1],dp[1][i-1])
    ans+= max(dp[h][-1] for h in range(3))
print(ans)

Measured memory_bytes: 80372
import itertools

n = int(input())

s_dict = {'M': 0,
          'A': 0,
          'R': 0,
          'C': 0,
          'H': 0}

for _ in range(n):
    s = input()
    if s[0] in s_dict.keys():
        s_dict[s[0]] += 1

candidate = []
for combi in itertools.combinations(s_dict.keys(), 3):
    if s_dict[combi[0]] != 0 and s_dict[combi[1]] != 0 and s_dict[combi[1]] != 0:
            candidate.append(combi)
            
cnt = 0
for x in candidate:
    cnt += s_dict[x[0]] * s_dict[x[1]] * s_dict[x[2]]
    
print(cnt)

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

int main() {
    int h, w;
    cin >> h >> w;

    vector <string> a(h);
    for (int i = 0; i < h; i++) {
        cin >> a.at(i);
    }

    for (int i = 0; i < w + 2; i++) cout << "#";
    cout << endl;
    for (int i = 0; i < h; i++) {
        cout << "#";
        cout << a.at(i);
        cout << "#" << endl;
    }
    for (int i = 0; i < w + 2; i++) cout << "#";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <string>
#include <iostream>

using namespace std;

int main(){
	string s;

	cin >> s;

	for(int i=1; i < (int)s.size(); i++){
		if(s[i-1]=='A' && s[i]=='C'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int min(int a, int b){
    if(a < b){
        return a;
    }else{
        return b;
    }
}

int main(void){

    int N, Ma, Mb;

    scanf("%d%d%d", &N, &Ma, &Mb);

    int a[42], b[42], c[42];

    for(int i = 0; i < N; i++){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
    }

    int dp[N+1][10*N+1][10*N+1];

    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 10*N; j++){
            for(int k = 0; k <= 10*N; k++){
                dp[i][j][k] = 1000000000;
            }
        }
    }

    dp[0][0][0] = 0;
    dp[0][a[0]][b[0]] = c[0];

    for(int i = 1; i < N; i++){
        for(int j = 0; j <= 10*N; j++){
            for(int k = 0; k <= 10*N; k++){
                if(j - a[i] < 0 || k - b[i] < 0){
                    dp[i][j][k] = dp[i-1][j][k];
                }else{
                    dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a[i]][k-b[i]] + c[i]);
                }
            }
        }
    }

    int ans = 1000000000;

    for(int i = 1; i * Ma < 10*N+1 && i * Mb < 10*N+1; i++){
        ans = min(ans, dp[N-1][i*Ma][i*Mb]);
    }

    if(ans == 1000000000){
        printf("-1\n");
    }else{
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 26848
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    n = ii()
    if n % 2 == 0:
        print(n // 2 - 1)
    else:
        print((n - 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int S, W; cin >> S >> W;
if(S > W){
  cout << "safe" << endl;
}
else{
  cout << "unsafe" << endl;
}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  int a,b;
  std::cin >> a>>b;
  if((a*b)%2==0)std::cout << "No" << std::endl;
  else std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
while True:
	n=int(input())
	if n==0:break
	a=list(map(int,input().split()))
	a.sort()
	saisho=1000000
	for i,iv in enumerate(a):
		if i!=0:
			saisho=abs(iv-b) if saisho > abs(iv-b)else saisho
		b=iv
	print(saisho)

Measured memory_bytes: 7736
#include <stdio.h>

int main(){
    int a, b, c, e = 0, t = 0, d = 0, tmp;
    while (scanf("%d%d%d", &a, &b, &c)) {
        if (b > a && b > c)
            tmp = a, a = b, b = tmp;
        if (c > a && c > b)
            tmp = a, a = c, c = tmp;
        if(c > b)
            tmp = b, b = c, c = tmp;
        
        if (a < b + c) {
            if (a * a < b * b + c * c) e++;
            if (a * a == b * b + c * c) t++;
            if (a * a > b * b + c * c) d++;
        }
        else break;
    }
    
    printf("%d %d %d %d\n", e + t + d, t, e, d);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n, a[2] = {2, 1};
    
    cin >> n;
    for(int i = 2; i < n + 1; i++)
        a[i%2] = a[0] + a[1];
    
    cout << a[n%2] << endl;
        
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[2005][2005];
int main(){
 int n;
 cin>>n;
 V<P> a(n);
 for(int i=0;i<n;i++){
     cin>>a[i].fi;
     a[i].se=i;
 }
 sort(all(a),greater<P>());
 for(int i=0;i<n;i++){
     for(int j=0;j<=i;j++){
         chmax(dp[j+1][i-j],dp[j][i-j]+a[i].fi*abs(j-a[i].se));
         chmax(dp[j][i-j+1],dp[j][i-j]+a[i].fi*abs(n-(i-j)-1-a[i].se));
     }
 }
 ll ans=0;
 for(int i=0;i<=n;i++)chmax(ans,dp[i][n-i]);
 cout<<ans<<"\n";
}

Measured memory_bytes: 26320
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	int flag1=1,sum1=0,sum2=0;
	int n;
	cin>>n;
	int a[n];
	for (int j=0;j<n;j++)
	{
		cin>>a[j];
	}
	int temp;
	for (int k=0;k<n-1;k++){
		for (int l=0;l<n-k-1;l++){
			if (a[l]<a[l+1]){
				temp=a[l];
				a[l]=a[l+1];
				a[l+1]=temp;
			}
		}
	}
	
	int i;
	for (i=0;i<n;i++)
	{
		if (flag1==1)
		{
			sum1+=a[i];
			flag1=0;
		}
		else 
		{
			sum2+=a[i];
			flag1=1;
		}
		
	}
	cout<<sum1-sum2;
}

Measured memory_bytes: 256
<?php

    $N = intval(trim(fgets(STDIN)));
    
    $B = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    if(count($B)==1){
        echo 2*$B[0];
        exit;
    }
    
    for($i=0;$i<count($B)-1;$i++){
        $new_B[] =[$B[$i],$B[$i+1]];
    }
    // var_dump($new_B); 
    for($j=0;$j<count($new_B);$j++){
        $ans[] = min($new_B[$j]);
    }
    echo array_sum($ans)+$B[0]+$B[count($B)-1];
?>

Measured memory_bytes: 16168
n = int(input())
if n % 2 == 0:
    n_edges = n * (n-1) // 2 - n // 2
    print(n_edges)
    for i in range(n - 1):
        for j in range(i + 1, n):
            if i + j + 2 == n + 1:
                continue
            else:
                print(i + 1, j + 1)
else:
    n_edges = n * (n - 1) // 2 - n // 2
    print(n_edges)
    for i in range(n - 1):
        for j in range(i + 1, n):
            if i + j + 2 == n:
                continue
            else:
                print(i + 1, j + 1)

Measured memory_bytes: 42864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[1010];
int main(){
	int x,d,i;
	cin>>x;
	for(i=2;i<=x;i++)
	{
		int n=i;
		for(d=2;d<=n;d++)
		{
			while(n%d==0) 
			{
				a[d]++;
				n/=d;
//				cout<<d<<endl;
			}
		}
		if(n!=1) a[n]++;	
	}
	
	ll sum=1;
	for(d=2;d<=x;d++)
	{
//		cout<<d<<" "<<a[d]<<endl;
		if(a[d]!=0)
		{
			sum=(sum*(a[d]+1))%1000000007;
		 } 
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,x,ans=1e9+7;
int c[105],a[105][105],pos[105];
int main()
{
	cin>>n>>m>>x;
	for (int i=1;i<=n;i++)
	{
		cin>>c[i];
		for (int j=1;j<=m;j++)  cin>>a[i][j];
	}
	while (pos[0]==0)
	{
		int in[105]={0},money=0;
		for (int i=1;i<=n;i++)
		{
			if (pos[i]==1)
			{
				money+=c[i];
				for (int j=1;j<=m;j++)  in[j]+=a[i][j];
			}
		}
		int flag=1;
		for (int i=1;i<=m;i++)
		{
			if (in[i]<x)
			{
				flag=0;
				break;
			}
		}
		if (flag==1)  ans=min(ans,money);
		
		for (int i=n;i>=0;i--)
		{
			if (pos[i]==1)  pos[i]=0;
			else
			{
				pos[i]=1;
				break;
			}
		}
	}
	if (ans!=1e9+7)  cout<<ans<<endl;
	else cout<<-1<<endl;
	
	return 0;
}


Measured memory_bytes: 3612
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);

		int n=s.nextInt();
		int m=s.nextInt();
		System.out.println(Math.max(Math.max(n+m,n-m),n*m));
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, r;
  while (cin >> n >> r && n && r) {
    vector<int> card(n);
    vector<int> tmp(n);

    REP(i, n) card[i] = n - i;
    REP(i, r) {
      int p, c;
      cin >> p >> c;
      REP(j, n) tmp[j] = card[j];
      REP(j, c) tmp[j] = card[p - 1 + j];
      REP(j, p - 1) tmp[c + j] = card[j];
      REP(j, n) card[j] = tmp[j];
    }
    cout << card[0] << endl;
  }
  return 0;
}



Measured memory_bytes: 3004
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll N, i=0;
    in(N);
    while(1) if(powll(2, ++i)>N) break;
    put(powll(2, --i));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k<a) cout << k << endl;
  else if(a<=k && k<=a+b) cout << a << endl;
  else cout << a - (k-a-b) << endl;
  return 0;
}

Measured memory_bytes: 3636
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
count = 0
n.times do
  x,y = gets.chomp.split.map(&:to_i)
  if x == y
    count+=1
  else
    count = 0
  end

  if count >= 3
    puts 'Yes'
    exit
  end
end

puts 'No'


Measured memory_bytes: 14616
// TODO 自動生成されたメソッド・スタブ

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] cut = line.split("");

		int x = Integer.parseInt(cut[0]);
		int y = Integer.parseInt(cut[1]);
		int z = Integer.parseInt(cut[2]);

		if (x == z && y * 2 / 2 == y) {

			System.out.println("Yes");

		} else  {

			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21204
using System;
using System.Linq;

namespace abc082_b
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] a = Console.ReadLine().ToArray(); Array.Sort(a);
            char[] b = Console.ReadLine().ToArray(); Array.Sort(b); Array.Reverse(b);
            Console.WriteLine(new string(a).CompareTo(new string(b)) < 0 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13408
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    ll x;
    cin >> x;
    for (ll i = 1; ; i++) {
        if (2 * x <= (i * (i + 1))) {
            cout << i;
            return 0;
        }
    }
    return 0;
}

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

int main() {
  string s;
  int cout_A = 100000000, cout_B = -1;

  cin >> s;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'A') {
      if (cout_A > i + 1)
        cout_A = i + 1;
    }

    if (s[i] == 'Z') {
      if (cout_B < i + 1)
        cout_B = i + 1;
    }
  }

  cout << cout_B - cout_A + 1 << endl;
  return 0;
}


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

using namespace std;

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

  int ans = 1;
  for (int i = 0; i < 6; ++i) {
    if (ans * 2 <= N) {
      ans *= 2;
    }
  }

  cout << ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, *g = [i.split() for i in open(0)]
h, w = map(int, n)
d = ((1, 0), (-1, 0), (0, -1), (0, 1))
for i in range(h):
    for j in range(w):
        if g[i][0][j] == "#":
            if all(g[i + p][0][j + q] == "." for p, q in d
                   if 0 <= i + p < h and 0 <= j + q < w):
                print("No")
                exit()
print("Yes")


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

//Compiler version g++ 6.3.0

int main(){
  
  int sum =0, count=1;
  int a,b,x;
  cin >> a >> b;
    while (a--) {
      cin >> x;
      sum += x;
      if(sum<=b){
        count++;
      }
    }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  long long n;
  std::cin >> n;

  vector<long long> answers(n+1, 0);

  for(int x=1; x<=100; x++){
    for(int y=1; y<=100; y++){
      for(int z=1; z<=100; z++){
        long long val = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x;
        if(n < val) continue;
        answers[val] += 1;
      }
    }
  }

  for(int i=1; i<=n; i++){
    std::cout << answers[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	ll n; cin >> n;
	ll a[201000], b[201000];
	vector<pair<ll,ll>>v;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
		v.push_back({ b[i], i });
	}
	sort(v.begin(), v.end());
	ll now = 0;
	for (int i = 0; i < n; ++i) {
		now += a[v[i].second];
		if (now > b[v[i].second]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1e9;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    string s;
    int n, d;
    cin >> s >> d;
    n = s.size();
    auto dp = make_vec(d, 2, 0LL); //dp[j][k] : (i文字目まで見た時の)dで割ったあまりがjでSより小さいことが確定している数
    dp[0][0] = 1;
    rep(i,n)
    {
        // cout << dp << endl;
        auto dp2 = make_vec(d,2,0LL);
        int c = s[i] - '0';
        rep(j,d) rep(k,2)
        {
            rep(l,10)
            {
                int nk = k;
                if(k == 0 && l < c) nk = 1;
                if(k == 0 && l > c) continue;
                int nj = (j + l) % d;
                dp2[nj][nk] += dp[j][k];
                dp2[nj][nk] %= MOD;
            }
        }
        swap(dp, dp2);
    }
    cout << (MOD + dp[0][0] + dp[0][1] - 1) % MOD << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

char s[2010][2010];
int ss[2010][2010];
int h,w;


ll sp,sh[2010],si[2010];
ll f(int base){
	//ヒストグラムの最大長方形
	ll ans=0;
	sp=0;
	rep(j,0,w){
		if(sp==0||sh[sp-1]<ss[base][j]){
			si[sp]=j;
			sh[sp]=ss[base][j];
			sp++;
		}else{
			int jj=-1;
			while(sp>0&&sh[sp-1]>=ss[base][j]){
				jj=si[sp-1];
				ll menseki=(sh[sp-1]+1)*(j-jj+1);//<--面積の計算が違う
				ans=max(ans,menseki);
				sp--;
			}
			if(jj!=-1){
				si[sp]=jj;
				sh[sp]=ss[base][j];
				sp++;
			}
		}
	}
	while(sp>0){
		ll jj=si[sp-1];
		ll menseki=(sh[sp-1]+1)*(w-jj+1);
		ans=max(ans,menseki);
		sp--;
	}
	return ans;
}

int main(){
	scanf("%d%d",&h,&w);
	rep(i,0,h)scanf("%s",s[i]);
	
	rep(i,0,h)rep(j,0,w)ss[i][j]=s[i][j]=='#'?0:1;
	//横のdiff
	rep(i,0,h)rep(j,0,w-1)ss[i][j]^=ss[i][j+1];
	//縦のdiff^1
	rep(i,0,h-1)rep(j,0,w-1)ss[i][j]^=ss[i+1][j]^1;
	
	h--;w--;
	//h*wの01配列s[i][j]であって、1からなる最大長方形を探す
	//ただし面積は(縦+1)*(横+1)で計算する
	
	//まず累積和っぽいものに変換
	//ss[i][j]は上方向にいくつ1が連続して連なっているか	
	rep(i,1,h)rep(j,0,w)if(ss[i][j]==1)ss[i][j]=ss[i-1][j]+1;
//	rep(i,0,h){rep(j,0,w)printf("%d ",ss[i][j]);puts("");}puts("");
	
	ll ans=max(h,w)+1;
	rep(i,0,h){
		ll t=f(i);
		ans=max(ans,t);
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int n;
string k;

int dp[110][3][5];

int res(int i = 0,bool under = false,int zero = n){
  if(zero == 0) return 1;
  if(i >= k.size()) return 0;
  
  int &tmp = dp[i][under][zero];
  if(tmp > 0) return tmp;

  tmp = 0;

  if(under){
    tmp += res(i+1,true,zero);
    tmp += res(i+1,true,zero-1)*9;
  }
  else{
    if(k[i] == '0'){
      tmp += res(i+1,false,zero);
    }
    else{
      tmp += res(i+1,true,zero);
      tmp += res(i+1,false,zero-1);
      tmp += res(i+1,true,zero-1)*(k[i] - '1');
    }
  }
  return tmp;
}

signed main(){
  cin >> k >> n;
  int l = k.size();
  cout << res() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int main(){string a;cin>>a;int b=0;for(int i=0;i<a.size();i++){if(a[i]=='C'&&a[i-1]=='A'){b++;}else{}}if(b==0){cout<<"No"<<endl;}else{cout<<"Yes"<<endl;}}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;

int main() {
  string S; cin >> S;
  int cnt = 0;
  for(auto p : S) {
    if(p == 'x') cnt++;
  }
  cout << (cnt < 8 ? "YES" : "NO") << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
int main()
{
    
    ll n;
    cin>>n;
    ll arr[n];
    vector<ll> v(n);
    ll cnt=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        v[i]=arr[i];
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=arr[i]) cnt++;
    }
    if(cnt<=2) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 256
N = int(input())
b = [int(_) for _ in input().split()]


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


log = []
while b:
    delit = delitable(b)
    if not delit:
        print(-1)
        break
    del b[delit[-1] - 1]
    log.append(delit[-1])
else:
    log.reverse()
    print("\n".join(map(str, log)))

Measured memory_bytes: 3064
n = int(input())
p = list(map(int, input().strip().split()))

count = 0
for i in range(1,n-1):
    if (p[i-1] > p[i] > p[i+1]) or (p[i-1] < p[i] < p[i+1]):
        count += 1

print(count)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007

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 hpns[100010][3];  //各幸福度
int dp[100010][3];  //dp[i][j]  => 前日jを選んだうえで達成できる最大値

int N, a, b, c;

int main(){
  cin >> N;

  for(int i = 1; i <= N; i++){
    cin >> a >> b >> c; 
    hpns[i][0] = a; hpns[i][1] = b; hpns[i][2] = c;
    dp[i][0] = -1; dp[i][1] = -1; dp[i][2] = -1;
  }

  dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j == k) continue;
        chmax(dp[i][j], dp[i-1][k]+hpns[i][j]);
      }
    }
  }

  cout << max(dp[N][0],  max(dp[N][1], dp[N][2])) << endl;
  return 0;

}

    

Measured memory_bytes: 2560
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int p[1001] = {0};
int main()
{
	int N = 0, K = 0;
	scanf("%d %d", &N, &K);
	int i = 0;
	for (i = 0; i < N; i++) {
		scanf("%d", &p[i]);
	}

	qsort(p, N, sizeof(int), sort_inc);
	int ans = 0;
	for (i = 0; i < K; i++) {
		ans += p[i];
	}
	printf("%d\n", ans);
	//yesno(ans);
	//okng(ans);
	return 0;
}


Measured memory_bytes: 1744
l = list(input())

ans1 = 0
ans2 = 0

for i in range(len(l)):
  if i % 2 == 0:
    if l[i] == "0":
      ans1 += 1
    if l[i] == "1":
      ans2 += 1  
  else:
    if l[i] == "1":
      ans1 += 1
    if l[i] == "0":
      ans2 += 1
    
print(min(ans1,ans2))

Measured memory_bytes: 3956
import java.util.*;

public class Main{
    public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int K =sc.nextInt();
        int ans = 0;
        for(int i=0;i<N;i++){
            if(sc.nextInt()>=K){ans++;}
        }
        System.out.println(ans);
    }
}


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

int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  int b[N];
  for (int i = 0; i < N; ++i) {
    b[i] = a[i];
    if(b[i]<0) b[i] *= -1; 
  }

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

  long long sum = 0;

  if(mincount%2==0) {
    for (int i = 0; i < N; ++i) {
      sum += b[i];
    }
  }
  else{

    long min = 1000000000;
    for (int i = 0; i < N; ++i) {
      if(b[i]<min) min = b[i];
    }

    for (int i = 0; i < N; ++i) {
      sum += b[i];
    }

    sum -= 2*min;
  }

  cout << sum << endl;

}

Measured memory_bytes: 1024