akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int L;
  cin >> L;
  stack<int> s;
  set<int> se;
  for(int i=1; i<=L; i++){
    int q;
    cin >> q;
    if(q < 0){
      q = abs(q);
      if(se.size() == 0){
        cout << i<< endl;
        return 0;
      }
      if(s.top() == q){
        s.pop();
        se.erase(q);
        continue;
      }
      cout << i << endl;
      return 0;
    }else{
      if(se.count(q)){
        cout << i << endl;
        return 0;
      }
      se.insert(q);
      s.push(q);
    }
  }
  cout << "OK" << endl;
  return 0;
}



Measured memory_bytes: 3120
n, q = map(int, (input().split()))
s = input()

tbl = [0] * n
cnt = 0
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1
    tbl[i] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(tbl[r - 1] - tbl[l - 1])


Measured memory_bytes: 6084
ts = input().split(" ")
stack = []
for t in ts:
    if t not in ("-", "+", "*"):
        stack.append(int(t))
    else:
        n2 = stack.pop()
        n1 = stack.pop()
        if t == "-":
            stack.append(n1 - n2)
        elif t == "+":
            stack.append(n1 + n2)
        else:
            stack.append(n1 * n2)
print(stack.pop())

Measured memory_bytes: 7656
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 2510;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,a,b;
    cin >> n >> m;
    vector<P> island;
    rep(i,m){
        cin >> a >> b;
        island.push_back(P(b,a));
    }
    SORT(island);
    int now = 1,c = 0;
    rep(i,m){
        tie(b,a) = island[i];
        if (now <= a){
            c++;
            now = b;
        }
    }
    PRINT(c);
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> v[N];
vector<bool> vs(N);
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll x,n,i;
    cin>>n;
    vector<ll> v;
    map<ll,ll> mp,mp1;
    for(i=0;i<n;i++)
    {
        cin>>x;
        mp1[x]++;
        v.push_back(x);
    }
   
    sort(v.begin(),v.end());
    ll cnt=0,j;
    for(i=0;i<n;i++)
    {
        if(mp.find(v[i])==mp.end())
        {
            if(mp1[v[i]]==1)
            {
                cnt++;
            }
            for(j=v[i];j<=1000000;j+=v[i])
            {
                mp[j]++;
            }
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 82132
#include<iostream>
#include<vector>
#include<algorithm>


using namespace std;

int bi(int key, vector<int> dis){

    int l=0, r=dis.size()-1;
    while(r-l>1){
        int md=(l+r)/2;
        if(key<=dis[md]) r=md;
        else l=md;
    }

    return r;
}


int main(){

while(1){
    int d;
    cin>> d;
    if(d==0) break;
    int n, m;
    cin>> n>> m;
    vector<int> dis;
    dis.push_back(0);
    for(int i=1; i<n; i++){
        int x;
        cin>> x;
        dis.push_back(x);
    }
    dis.push_back(d);

    sort(dis.begin(), dis.end());
    int ans=0;
    for(int i=0; i<m; i++){
        int k;
        cin>> k;
        int id=bi(k, dis);
        ans+=min(dis[id]-k, k-dis[id-1]);
    }

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

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

main(){
  int n,s;
  while(cin>>n>>s && n){
    int r[101]={0};
    for(int i=0;i<n;i++){
      int tmp;cin>>tmp;r[tmp]++;
    }
    int ans = 0;
    for(int i=0;i<101;i++){
      if (i+i > s && r[i])ans += (r[i]*(r[i]-1))/2;
      for(int j=i+1;j<101;j++){
	if (i+j > s && r[i] && r[j])ans += r[i]*r[j];
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
   lli A,B,C,N,M,K,L,R,sum=0,num=0;
   cin >> A >> B >> L >> R;
   N=lcm(L,R);
   sum=B/L+B/R+(A-1)/N-(A-1)/L-(A-1)/R-B/N;
   Out(B-A+1-sum);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    ll n;
    cin >> n;
    ll res = 2*(n/11);
    if(n%11) res++;
    if(n%11 > 6) res++;
    cout << res;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
import math

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    # N = int(input())
    A,B = [int(a) for a in input().split()]
    # H = [
    #     int(input())
    #     for _ in range(N)
    # ]
    # A = [int(a) for a in input().split()]
    print(max(max(A+B,A-B),A*B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#include <stdio.h>

int main(void)
{
	double r, menseki, enshu, pi;
	pi = 3.141592653589;
	scanf("%lf", &r);
	menseki = r * r * pi;
	enshu = 2 * r * pi;

	printf("%f %f\n", menseki, enshu);

	return 0;
}

Measured memory_bytes: 648
def main():
    N,M = map(int,input().split())
    P = 10**9+7

    #全部：mPn ** 2通り
    #A:mPn通り
    mPn = M
    for i in range(M-N+1,M):
        mPn = mPn * i % P
    

    '''
    #Bのダメなパターン:固定したAに対して、∑(k=1...N)(-1)**(k)*nCk*(m-k)P(n-k)
    #   少なくとも1つがAと同じ
    #       Aと同じ箇所の取り方：nC1
    #       N-1個の数の組み合わせ：(m-1)(m-2)...(m-n+1) = (m-1)P(n-1)
    #   少なくとも2つがAと同じ
    #       Aと同じ箇所の取り方：nC2
    #       N-2個の数の組み合わせ：(m-2)(m-3)...(m-n+1) = (m-2)P(n-2)

    '''
    num_b = 0
    nCk = 1
    m_kPn_k = mPn

    for k in range(1,N+1):
        nCk = nCk * (N-k+1) * pow(k,P-2,P) % P
        m_kPn_k = m_kPn_k * pow(M-k+1,P-2,P) % P
        num_b = (num_b + ((-1) ** (k-1)) * nCk * m_kPn_k) % P
    print((mPn ** 2 - mPn * num_b)% P)
main()


Measured memory_bytes: 73360
#include <stdio.h>
#include <stdlib.h>

int Depth(int**,int*,int,int);

int main(){
  int n,i,j,**tree,*node,kazu,ban,oya[100001];

  scanf("%d",&n);
  tree=(int **)malloc(n*sizeof(int *));
  for(i=0;i<100001;i++) oya[i]=-1;   /* 初期化 */

  for(i=0;i<n;i++){
    scanf("%d%d",&ban,&kazu);
    

    node=(int *)malloc((kazu+2)*sizeof(int));
    node[0]=ban;
    node[1]=kazu;

    for(j=0;j<kazu;j++){
      scanf("%d",&node[j+2]);
      
      oya[node[j+2]]=node[0];
    }

    tree[ban]=node;
  }


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

    printf("node %d: parent = %d, depth = %d, ",i,oya[i],Depth(tree,oya,0,i) );
    
    if(oya[tree[i][0]]==-1){
      printf("root, [");
      for(j=0;j<tree[i][1];j++){
	if(j!=0) printf(", ");
	printf("%d",tree[i][2+j]);
      }
    
    }else if(tree[i][1]==0){
      printf("leaf, [");
    }
    else {
      printf("internal node, [");
      for(j=0;j<tree[i][1];j++){
	if(j!=0) printf(", ");
	printf("%d", tree[i][j+2]);
      }
    }

   printf("]\n");
	   
    
  }

  for(i=0;i<n;i++){
    free(tree[i]);
  }
  free(tree);
  
  return;
}


int Depth(int **tree,int *oya,int depth,int ko){
  if(oya[ko]==-1)return depth;

  else return Depth(tree,oya,depth+1,oya[ko]);
}



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

public class Main {

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

		int n = sc.nextInt();

		String s = sc.next();
		int k = s.length();

		int[][] dp = new int[n + 2][n + 1];
		dp[0][0] = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				if (j == 0) {
					dp[j][i] += dp[j][i - 1];
					dp[j][i] %= MOD;
					dp[j][i] += dp[j + 1][i - 1];
					dp[j][i] %= MOD;
				} else {
					dp[j][i] += dp[j - 1][i - 1];
					dp[j][i] %= MOD;
					dp[j][i] += dp[j - 1][i - 1];
					dp[j][i] %= MOD;
					dp[j][i] += dp[j + 1][i - 1];
					dp[j][i] %= MOD;
				}
			}
		}

		pr.println(dp[k][n] * pow((MOD + 1) / 2, k) % MOD);

		pr.close();
		sc.close();
	}

	static final int MOD = 1_000_000_007;

	private static long pow(int a, long n) {
		long loop = n;
		long ret = 1;
		long x = a;
		while (loop > 0) {
			if (loop % 2 == 1) {
				ret = ret * x % MOD;
			}
			x = x * x % MOD;
			loop /= 2;
		}

		return ret;
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
//					it = Arrays.asList(br.readLine().split(" ")).iterator();
					it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

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

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

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

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

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 125640
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int a,b,m;
    cin>>a>>b>>m;
    vector<int> av(a),bv(b);
    rep(i,a)cin>>av[i];
    rep(i,b)cin>>bv[i];
    int ans=LLONG_MAX;
    rep(i,m){
        int x,y,c;
        cin>>x>>y>>c;
        ans=min(av[x-1]+bv[y-1]-c,ans);
    }
    sort(av.begin(),av.end());
    sort(bv.begin(),bv.end());
    ans=min(ans,av[0]+bv[0]);
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    if (n >= 1000) {
      System.out.println("ABD");
    } else {
      System.out.println("ABC");
    }

  }
}

Measured memory_bytes: 35816
import sys
from collections import deque

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

n, m = nm()
s = list(map(lambda x: ord(x) - ord('A'), list(ns())))
G = [list() for _ in range(n)]
w = [[0, 0] for _ in range(n)]
for _ in range(m):
  u, v = nm()
  u -= 1; v -= 1
  G[u].append(v)
  G[v].append(u)
  w[u][s[v]] += 1
  w[v][s[u]] += 1

dele = [0]*n
q = deque()
for v in range(n):
  if not w[v][0] * w[v][1]:
    q.append(v)
    dele[v] = 1
while q:
  v = q.popleft()
  for x in G[v]:
    w[x][s[v]] -= 1
    if w[x][s[v]] == 0 and not dele[x]:
      dele[x] = 1
      q.append(x)
print('Yes' if sum(dele) < n else 'No')

Measured memory_bytes: 64012
import sys
import random
sys.setrecursionlimit(200000)
input = sys.stdin.readline

K, S = map(int, input().split())

ans = 0
for i in range(K + 1):
    for j in range(K + 1):
        t = S - i - j
        if 0 <= t and t <= K:
            ans += 1

print(ans)

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


int main(){
  double w,h,x,y;
  cin >> w >>h >> x >> y;
  cout << w*h/2 << " ";

  if(w==2*x && h==2*y) cout  << 1;
  else cout << 0; 
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0xff,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

//int a[101];
int main(){
	int n;
	cin>>n;
	double d=0;
	rep(i,n){
		double a;
		cin>>a;
		d+=(1/a);
	}
	d=1/d;
	printf("%.10lf",d);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(input().split())
b = []

if n % 2 == 0:
  for i in range(n//2):
    b.append(a[n-1-i*2])
  for i in range(n//2):
    b.append(a[i*2])
else:
  for i in range(n//2+1):
    b.append(a[n-i*2-1])
  for i in range(n//2):
    b.append(a[i*2+1])

print(" ".join(b))


Measured memory_bytes: 25668
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> cnt(N, 0);
    for(long long i = 1; i*i <= N; i++){
        for(long long j = 1; j*j <= N; j++){
            for(long long k = 1; k * k <= N; k++){
                long long t = i * i + j*j + k * k + i * k + j * k + i * j;
                if(t <= N) cnt[t-1]++;
            }
        }
    }
    for(int i = 0; i < N; i++) cout << cnt[i] << endl;
}

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


int main() {
  int n,ans,num;
  cin >> n;
  ans=1000-(n%1000);
  if(ans==1000)
    ans=0;
  cout << ans << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

const ll RANGE = 31622; // < sqrt(X) : sqrt(10^9) = 31622.8

int x;

ll mod5(ll n)
{
	return ((((((((n*n) % MOD) * n) % MOD)* n) % MOD)* n) % MOD);
}

bool calc(ll diff)
{
	if (diff > RANGE)
	{
		return false;
	}
	// a - b は x の約数
	// a-b = diff
	for(int a = 0; a < RANGE; ++a)
	{
		int b = a - diff;
		if(((mod5(a) - mod5(b)) + MOD) % MOD == x % MOD)
		{
			cout << a << " " << b << endl;
			return true;
		}
	}
	return false;
}

void solve()
{
	cin >> x;

	for (int i = 1; i * i <= x; i++)
	{
		if(x % i == 0)
		{
			if (calc(i)) return;
			if (calc(x / i)) return;
		}
	}

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3652
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

# sys.setrecursionlimit(10**6)
def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def get_string(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):
n = int(input())
li = sorted(get_list(), reverse = True)

ans = li[0]
pos = 1
enter = 2
while enter < n:
    ans += li[pos]*2
    enter += 2
    pos += 1
    # print(ans)
if enter == n + 1:
    ans -= li[pos-1]
print(ans)


'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 94384
fun main(args: Array<String>) {
        val (n, m) = readNext().split(" ")
        val a = Integer.parseInt(n)
        val b =  Integer.parseInt(m)
        val result = Math.max(Math.max(a + b , a - b), a * b)
        println(result)
    }


    fun readNext(): String {
        return readLine()!!
    }


Measured memory_bytes: 37688
def binarySearch(l, v):
    stt = 0
    end = len(l)
    while stt < end:
        mid = (stt + end) // 2
        lmid = l[mid]
        if lmid == v:
            return mid
        if lmid > v:
            end = mid
        else:
            stt = mid + 1
    raise ValueError

n = raw_input()
S = [int(x) for x in raw_input().split()]
q = raw_input()
T = [int(x) for x in raw_input().split()]

ans = 0
for t in T:
    try:
        binarySearch(S, t)
        ans += 1
    except ValueError:
        pass

print ans

Measured memory_bytes: 14708
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define DEBUG 0
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#define endl '\n'
#define range 200010
#endif

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}
int dp[range][2];
int main(){

	//freopen("input.txt","r",stdin);
	clock_t clk = clock();
	string s;
	cin>>s;
	dp[0][0] = 1;
	dp[0][1] = -1;
	dp[1][0] = (s[0] == s[1])?-1:2;
	dp[1][1] = 1;
	for(int i=2;i<s.size();i++){
		{	dp[i][0] = -1;
			if(dp[i-1][1] != -1)
				dp[i][0] = max(dp[i][0], dp[i-1][1]+1);
			if(s[i] != s[i-1] && dp[i-1][0] != -1)
				dp[i][0] = max(dp[i][0], dp[i-1][0]+1);
		}
		{	
			dp[i][1] = -1;
			if(dp[i-2][0] != -1)
			dp[i][1] = max(dp[i][1], dp[i-2][0]+1);
			if(dp[i-1][2] != -1){
				if(s[i] != s[i-2] || s[i-1] != s[i-3])
					dp[i][1] = max(dp[i][1], dp[i-2][1]+1);
			}
		}
	}    
	int n = s.size();
	/*forn(i,2){
		forn(j,n)cout<<dp[j][i]<<" ";cout<<endl;
	}*/
	cout<<max(dp[n-1][0], dp[n-1][1]);


    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}





Measured memory_bytes: 2180
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

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

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"2018
218
" => r"Yes",

r"2763
0
" => r"No",

r"37
514
" => r"Yes"
}

use std::cmp;
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: i32,
        a: i32
    }

    let amari = n % 500;
    if amari > a {
        "No".to_string()
    } else {
        "Yes".to_string()
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int card[51],s[51];
int n,r;
void shuffle(int p,int c){
	for(int i=1;i<p;i++){
		s[i]=card[i];
	}
	for(int i=1;i<=c;i++){
		card[i]=card[p-1+i];
	}
	for(int i=1;i<p;i++){
		card[i+c]=s[i];
	}
}


int main(){
	int p,c;
	while(1){
		cin >>n>>r;
		if(n==0&&r==0)break;
		for(int i=1;i<=n;i++){
			card[i]=n-i+1;
		}
		for(int i=0;i<r;i++){
			cin >>p>>c;
			shuffle(p,c);
			//for(int j=1;j<=n;j++){
			//	cout << card[j]<<" ";
			//}
		}
		cout <<card[1] <<endl;
	}
	return 0;
}

Measured memory_bytes: 3076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Plush Toys
 */
public class Main {

	static final int INF = 1 << 29;

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

		line = br.readLine();

		int N, M;
		N = parseInt(line.substring(0, line.indexOf(' ')));
		M = parseInt(line.substring(line.indexOf(' ') + 1));

		int[] P = new int[N];
		int[] C = new int[M];
		int[] S = new int[1 << M];
		int[][] diff = new int[N][M];

		for (int i = 0; i < N; i++) {
			P[i] = parseInt(br.readLine()) - 1;
			C[P[i]]++;
		}

		for (int i = 0; i < 1 << M; i++) {
			for (int j = 0; j < M; j++) {
				if ((i >> j & 1) == 1) {
					S[i] += C[j];
				}
			}
		}

		for (int i = 0; i < N; i++) {
			Arrays.fill(diff[i], -1);
		}

		//
		int[] dp = new int[1 << M];

		Arrays.fill(dp, INF);
		dp[0] = 0;

		for (int i = 0; i < 1 << M; i++) {
			for (int j = 0; j < M; j++) {
				if ((i >> j & 1) == 0) {
					if (diff[S[i]][j] == -1) {
						diff[S[i]][j] = 0;
						for (int k = 0; k < C[j]; k++) {
							if (P[S[i] + k] != j) diff[S[i]][j]++;
						}
					}
					dp[i | 1 << j] = Math.min(dp[i | 1 << j], dp[i] + diff[S[i]][j]);
				}
			}
		}

		System.out.println(dp[(1 << M) - 1]);
	}
}

Measured memory_bytes: 53020
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N>>W;
    vector<int> we(N+1,0), va(N+1,0);
    reps(i,1,N+1) cin>>we.at(i)>>va.at(i);
    vector<vector<ll>> dp(N+1,vector<ll>(W+1,-1));
    dp[0][0] = 0;
    reps(i,1,N+1){
        rep(j,W+1){
            dp[i][j] = dp[i-1][j];
            if(j>=we.at(i) && dp[i-1][j-we.at(i)] != -1) {
                dp[i][j] = max(dp[i][j],dp[i-1][j-we.at(i)]+va.at(i));
            }
        }
    }
    ll ans = 0;
    rep(i,W+1) ans = max(ans,dp[N][i]);
    cout<<ans<<endl;
    /*rep(i,N+1){
        rep(j,W+1){
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }*/
}

Measured memory_bytes: 80256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Jan 17 15:56:11 2019
//
package main

import (
	"fmt"
	"sort"
)

var H, W int

func max(slice ...int) int {
	sort.Ints(slice)
	return slice[len(slice)-1]
}

func min(slice ...int) int {
	sort.Ints(slice)
	return slice[0]
}

func minDiffArea(a, b, c int) int {
	return max(a, b, c) - min(a, b, c)
}

func splitH() int {
	arr := make([]int, H-1)
	for h := range arr {
		a := (h + 1) * W
		b := (H - (h + 1)) / 2 * W
		c := H*W - a - b
		arr[h] = minDiffArea(a, b, c)
	}
	return min(arr...)
}

func splitV() int {
	arr := make([]int, W-1)
	for w := range arr {
		a := (w + 1) * H
		b := (W - (w + 1)) / 2 * H
		c := H*W - a - b
		arr[w] = minDiffArea(a, b, c)
	}
	return min(arr...)
}

func splitHV() int {
	arr := make([]int, H-1)
	for h := range arr {
		a := (H - h - 1) * W
		b := (h + 1) * (W / 2)
		c := H*W - a - b
		arr[h] = minDiffArea(a, b, c)
	}
	return min(arr...)
}

func splitVH() int {
	arr := make([]int, W-1)
	for w := range arr {
		a := (W - w - 1) * H
		b := (w + 1) * (H / 2)
		c := H*W - a - b
		arr[w] = minDiffArea(a, b, c)
	}

	return min(arr...)
}

func main() {
	fmt.Scan(&H, &W)

	fmt.Println(min(splitH(), splitHV(), splitV(), splitVH()))
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	int n;cin>>n;
	int h[n];rep(i,0,n)cin>>h[i];
	int dp[n]={-1};
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;++i){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}



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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, h, m;
    cin >> a >> b >> h >> m;

    ld alpha = 30 * h + 0.5 * m;
    ld beta = 6 * m;
    ld theta = max(alpha, beta) - min(alpha, beta);
    theta = min(theta, 360 - theta);

    ld d = sqrtl(a * a + b * b - 2 * a * b * cosl(PI * theta / 180.0));

    SPC(18);
    out(d);

    return 0;
}


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

#define PI 3.14159265358979323846

using namespace std;

int n , m , x , sum;

int main()
{
    cin >> n >> m;
    for(int i = 1 ; i <= m ; i++)
    {
        cin >> x;
        sum += x;
    }
    if(n < sum)
        cout << "-1\n";
    else cout << n - sum << '\n';
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int n, k;
    cin >> n >> k ;
    vi a(n);
    rep(i, n) cin >> a.at(i);
    //二分探索
    int l = 0, r = 1e9;
    while(r-l > 1) {
        int x = (l+r)/2;
        auto f = [&](int x) {
            ll now = 0;
            rep(i, n) now += (a.at(i)-1)/x;
            return now <= k;
        };
        if (f(x)) r = x; else l = x;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3972
//カタラン数を語らん!w

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<pair<long long, long long>> vertexs[500];
pair<long long, long long> dijk[500][500];
int main(){
#define int long long
	iostream::sync_with_stdio(false);
	int n, m, l;
	cin >> n >> m >> l;
	REP(i, m) {
		long long a, b, c;
		cin >> a >> b >> c;
		if (c > l) continue;
		vertexs[a].push_back(make_pair(b, c));
		vertexs[b].push_back(make_pair(a, c));
	}
	for (int i = 1; i <= n; ++i) {
		REP(q, 500) {
			dijk[i][q] = make_pair(1000, 0);
		}
		priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>> next;
		next.push(make_tuple(0, 0, i));
		dijk[i][i] = make_pair(0, 0);
		while (next.empty() == false) {
			tuple<long long, long long, long long> now = next.top();
			next.pop();
			int spot = get<2>(now);
			if (get<0>(now) != dijk[i][spot].first || get<1>(now) != dijk[i][spot].second) continue;
			REP(q, vertexs[spot].size()) {
				int next_point = get<0>(now);
				int next_cost = get<1>(now) + vertexs[spot][q].second;
				if (next_cost > l) {
					next_cost = vertexs[spot][q].second;
					next_point++;
				}
				int itr = vertexs[spot][q].first;
				if (dijk[i][itr].first > next_point || (dijk[i][itr].first == next_point && dijk[i][itr].second > next_cost)) {
					dijk[i][itr] = make_pair(next_point, next_cost);
					next.push(make_tuple(next_point, next_cost, itr));
				}
			}
		}
		REP(q, 500) {
			if (dijk[i][q].first == 1000) {
				dijk[i][q].first = -1;
			}
		}
	}
	int query;
	cin >> query;
	REP(i, query) {
		int a, b;
		cin >> a >> b;
		cout << dijk[a][b].first << endl;
	}
}


Measured memory_bytes: 6580
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
sa = [0] * (n + 1)
for i in range(n):
    sa[i + 1] = sa[i] + a[i]
ans = 0
for i in range(n - 1):
    temp = sa[i + 1] * a[i + 1] % mod
    ans += temp
    ans %= mod
print(ans)


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll h, w, a, b, ans, kai[2000010];

ll nCk(ll n, ll k) {
	ll bunsi = kai[n];
	ll bunbo = (kai[k] * kai[n-k])%mod;
	
	ll gyaku[30];	// 元の数字の2^k乗の%mod
	gyaku[0] = bunbo;
	reps(i,1,30) gyaku[i] = (gyaku[i-1]*gyaku[i-1])%mod;
	bunbo = 1;
	rep(i,30) if ((mod-2)>>i & 1) bunbo = (bunbo*gyaku[i])%mod;
	return (bunsi*bunbo)%mod;
}

int main() {
	cin >> h >> w >> a >> b;
	h--, w--, a--, b--;
	// 何回もやることになるから2*10^6までの階乗%modを求めておく
	kai[0] = kai[1] = 1;
	repst(i,2,2000000) kai[i] = (kai[i-1]*i)%mod;
	rep(i,w-b) ans = (ans + nCk(h-a+b+i, b+i+1) * nCk(a+w-b-i-1, w-b-i-1))%mod;
	cout << ans << ln;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll s,w;
    cin>>s>>w;
    cout<<(s<=w?"unsafe":"safe")<<endl;
    return 0;
}

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 105, INF = 1e9;

int n, m;
char board[N][N];
int dp[N][N][2 * N];

int main() {
    
    scanf("%d %d", &n, &m);
    
    for (int i = 1; i <= n; i++) {
        scanf("%s", &board[i][1]);
        for (int j = 1; j <= m; j++) {
            board[i][j] = (board[i][j] == '#' ? 1 : 0);
        }
    }
    
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            for (int k = 0; k <= n + m + 1; k++) {
                dp[i][j][k] = INF;
            }
        }
    } 
    dp[0][1][0] = 0;
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (int k = 0; k <= n + m; k++) {
                if (k % 2 == board[i][j]) {
                    dp[i][j][k] = min({dp[i][j][k], dp[i][j - 1][k], dp[i - 1][j][k]});
                    dp[i][j][k] = min({dp[i][j][k], dp[i][j - 1][k + 1], dp[i - 1][j][k + 1], k > 0 ? dp[i - 1][j][k - 1] + 1 : INF, k > 0 ? dp[i][j - 1][k - 1] + 1 : INF});
                }
            }
        }
    }
    
    int ans = INF;
    for (int k = 0; k <= n + m; k++) {
        ans = min(ans, dp[n][m][k]);
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  int x[m];
  for (int i = 0; i < m; i++) {
    cin >> x[i];
  }
  sort(x, x+m);
  int a[m-1];
  for (int i = 0; i < m-1; i++) {
    a[i] = x[i+1] - x[i];
  }
  sort(a,a+m-1);
  int ans = 0;
  for (int i = 0; i < (m-1)-(n-1); i++) {
    ans += a[i];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int A, B, C, D;

int main(void) {

	cin >> A >> B >> C >> D;

	if (A + B > C + D) {
		cout << "Left" << endl;
	}
	else if (A + B < C + D) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let n = int();
    println!("{}", n * (n + 1) / 2)
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[505][505];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
        }
    }
    vector<pll> ans;
    REP(i, H) {
        REP(j, W) {
            if (A[i][j] % 2 == 0)
                continue;
            if (j + 1 < W) {
                A[i][j]--;
                A[i][j + 1]++;
                ans.push_back(pll(i + 1, j + 1));
                ans.push_back(pll(i + 1, j + 2));
            }
            else if (i + 1 < H) {
                A[i][j]--;
                A[i + 1][j]++;
                ans.push_back(pll(i + 1, j + 1));
                ans.push_back(pll(i + 2, j + 1));
            }
        }
    }
    ll N = ans.size();
    cout << N / 2 << endl;
    REP(i, N / 2) {
        ll p = i * 2, q = i * 2 + 1;
        cout << ans[p].first << " " << ans[p].second << " " << ans[q].first << " " << ans[q].second << endl;
    }
    return 0;
}

Measured memory_bytes: 8172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF 2000'000'000
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);//freopen("out", "w", stdout);
	int ans = 0, cur = 0;
	string s;
	cin >> s;
	for(char c : s){
		if(c == 'R'){
			ans = max(ans, ++cur);
		}
		else
			cur = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3608
sub f{$_-$u[$_]?(map$_=&f,$u[$_])[0]:$_}
map{
	@u=0..$`;
	($==f$_=<>=~$"*$')-($%=f$_=$`)and$u[$%]=$=for 1..$_;
	@{$|--}=map f,@u
}<>=~/ \d+/g;
print${$0[$_]}{$1[$_]},$/for grep++${$0[$_]}{$1[$_]},1..$`


Measured memory_bytes: 160128
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	ff 				first
#define 	ss				second
#define 	pb				push_back
#define 	mp				make_pair
#define 	bb 				begin()
#define     rb              rbegin()
#define 	ee 				end()
#define     ub              upper_bound
#define     lb              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define     sorta(v)         sort(all(a))
#define     sortd(v)        sort(all(a), greater<ll >())
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vvll            vector<vll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

bool compare_float(double x, double y){
    return fabs(x - y) < DBL_EPSILON;
}

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(11);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 11)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005



void solve(){
    ll k, ans = 1, rem = 7;
    cin >> k;

    map<ll, ll> hmp;

    while(rem%k && hmp[rem%k] != 1){
        hmp[rem%k] = 1;
        rem = (10*rem + 7)%k;
        ans++;
    }

    if(rem%k)
        cout << -1 << nl;
    else
        cout << ans << nl;
}

 
int main(){
    boost;
    // cal(1);

    // // For getting input from input.txt file 
    // freopen("timber_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);


    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 66084
import collections

N, K = [int(s) for s in raw_input().split(' ')]
dest = [int(s)-1 for s in raw_input().split(' ')]

ans = 0

if dest[0] != 0:
    dest[0] = 0
    ans += 1

if K >= N:
    print(ans)
    raise SystemExit

source = collections.defaultdict(list)
for v in range(1,N):
    source[dest[v]].append(v)


dist = [0]*N
dist[0] = 0
topo = []
queue = collections.deque()
queue.append(0)
while queue:
    u = queue.popleft()
    topo.append(u)
    for v in source[u]:
        dist[v] = dist[u]+1
        queue.append(v)

#print(topo)
#print({i:d for (i,d) in enumerate(dist)})
#print(repr(source))
#raise SystemExit

good = set()
for u in reversed(topo):
    if u in good:
        continue
    if dist[u] <= K:
        break
    ans += 1
    ancestor = u
    for _ in range(K-1):
        ancestor = dest[ancestor]
    #print(ancestor)
    desc = []#collections.deque()
    good.add(ancestor)
    desc.append(ancestor)
    i = 0
    while i < len(desc):
        anc = desc[i]
        i += 1
        for v in source[anc]:
            if v not in good:
                good.add(v)
                desc.append(v)
print(ans)

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

int main(){
	int N;
	cin >> N;
	priority_queue<int> L;
	rep(i, 2 * N) {
		int l;
		cin >> l;
		L.push(l);
	}
	int ans = 0;
	rep(i,N) {
		L.pop();
		ans += L.top();
		L.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read_vec::<i64>();
    let ans = if n[0] == 1 {
        1
    } else {
        n[0]  - n[1] + 1
    };
    println!("{}",ans );
}

Measured memory_bytes: 4352
n,T=map(int,input().split())
t=list(map(int,input().split()))
ans=0
s=0
for i in range(1,n):
    if t[i]-t[i-1]<=T:
        s+=t[i]-t[i-1]
        continue
    else:
        ans+=s+T
        s=0
ans+=s+T
print(ans)

Measured memory_bytes: 25200