akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader(System.in);
        StringBuilder sb = new StringBuilder();
        int i,j;
        int n=in.nextInt();
        int k=in.nextInt();
        long ans=0,mod=1000_000_007;
        long arr[]=new long[n+1];
        for(i=0;i<=n;i++) {
            arr[i] = i;
            if(i!=0)
                arr[i]=(arr[i]+arr[i-1])%mod;
        }
        for(i=k-1;i<=n;i++){
            long a=arr[i];
            long b=(arr[n]-arr[Math.max(0,n-(i+1))]+mod)%mod;
            //System.out.println(a+" "+b);
            ans=(ans+(b-a+1+mod))%mod;
        }
        System.out.println(ans);
    }
}
class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c !=10 && c!=13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    char nextChar() throws IOException{
        int c;
        for (c = scan(); c <= 32; c = scan());
        return (char)c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}


Measured memory_bytes: 33920
def is_valid():
    x_removed_S = S.replace("x", "")
    M = len(x_removed_S)
    for i in range(M // 2):
        if x_removed_S[i] != x_removed_S[M - i - 1]:
            return False
    return True


S = input()
N = len(S)
if is_valid():
    ans = 0
    left, right = 0, N - 1
    while left < right:
        if S[left] == S[right]:
            left += 1
            right -= 1
            continue
        elif S[left] == "x":
            ans += 1
            left += 1
        else:
            ans += 1
            right -= 1
    print(ans)
else:
    print(-1)


Measured memory_bytes: 9172
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
#include <array>
using namespace std;
int n;
int a[200000];
int pa[200000];
vector<int> ch[200000];
int ans[200000];
void dfs(int now,int dp[200000],int mem){
	int md;
	int id=lower_bound(dp,dp+n,a[now])-dp;
	if(dp[id]==1e9+7){
		md=dp[id];
		dp[id]=a[now];
		ans[now]=mem+1;
	}else{
		md=dp[id];
		dp[id]=a[now];
		ans[now]=mem;
	}
	for(int i=0;i<ch[now].size();i++){
		if(ch[now][i]==pa[now]){
			continue;
		}else{
			pa[ch[now][i]]=now;
			dfs(ch[now][i],dp,ans[now]);
		}
	}
	dp[id]=md;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		ch[u].push_back(v);
		ch[v].push_back(u);
	}
	pa[0]=-1;
	int dp[200000];
	for(int i=0;i<n;i++){
		dp[i]=1e9+7;
	}
	dfs(0,dp,0);
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

const int maxN = 1e5 + 5;

signed main() {
  int n, m;
  std::cin >> n >> m;
  vector<vi> reward(m + 1);
  REP(i, n) {
    int a, b;
    a = read();
    b = read();
    if (a <= m)
      reward[a].PB(b);
  }
  int ans = 0;
  priority_queue<int> q;
  for (int i = 1; i <= m; i++) {
    for (auto &v : reward[i])
      q.push(v);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  print(ans);
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct z_array {
  vector<int> prefix;
  void build(const string &s) {
    prefix.assign(s.size(),0);
    for(int i=1, j=0; i < (int)s.size(); ++i) {
      if(i+prefix[i-j] < j+prefix[j]) {
        prefix[i] = prefix[i-j];
      }
      else {
        int k = std::max(0,j+prefix[j]-i);
        while(i+k < (int)s.size() && s[k] == s[i+k]) ++k;
        prefix[i] = k;
        j = i;
      }
    }
    prefix[0] = s.size();
  }
  int operator[](const int i) const{ 
    assert(i < (int)prefix.size());
    return prefix[i];
  }
  int size(){ return prefix.size();}
};


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n) {
    z_array z;
    z.build(s.substr(i));
    int maxi = 0;
    rep(j,z.size()) {
      if (j >= z[j]) chmax(maxi,z[j]);
    }
    chmax(ans, maxi);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c;
string s, t;

int main()
{
	cin >> a>>b ;	
	
	cout << (a+2*b)/(2*b+1)<< endl;
}


Measured memory_bytes: 256
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

range (x:y:ys) = (x, y) : range (y:ys)
range _ = []

speed (l, r) v x
  | x <= l    = v + (l - x)
  | x <= r    = v
  | otherwise = v + (x - r)

main :: IO ()
main = do
  n  <- readInt
  ts <- map fromIntegral <$> scanl1 (+) <$> ((0:) . (0:)) <$> (++ [0]) <$> readInts
  vs <- map fromIntegral <$> (0 :) <$> (++ [0]) <$> readInts
  let end = last ts
      calc x = minimum $ map ($ x) speeds
        where speeds = zipWith speed (range ts) vs
      metric = map calc $ takeWhile (<= end) (iterate (+ 0.5) 0)
      areas = foldr f (0.0, 0.0) metric
        where f b (s, a) = (s + (a + b) / 4, b) 

  putStrLn $ doubleFmt (fst areas)

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll ans;
    if (x / d > k) {
        ans = x - d * k;
    } else {
        ll e = x / d;
        k -= e;
        x %= d;
        if (k % 2 == 1)
            x = abs(x - d);
        ans = x;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


int main()
{
	int a;
	int b;
	scanf("%d",&a);
	scanf("%d",&b);	
if(a<2*b){
		printf("0");
	}else{
		printf("%d",a-2*b);
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ull unsigned long long
#define lli long long int
#define pb push_back
#define all(x) x.begin(),x.end()
ll mob=1000000007;
using namespace std;
int main()
{ 
int n,k;

cin>>n>>k;
int a[n+1];
memset(a,0,sizeof(a));
while(k--)
{
    int d;
    cin>>d;
    FOR(i,d)
    {
        int y;cin>>y;
        a[y]++;
    }
    
}
 int  r=0;
For(i,1,n+1)
{
    if(!a[i]) r++;
    
}

cout << r;
return 0;
}











Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  string k = "";
  rep(i, s.length()) {
    if (s[i] == '0')
      k += '0';
    else if (s[i] == '1')
      k += '1';
    else if (k.length() >= 1)
      k = k.substr(0, k.length() - 1);
  }
  cout << k << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
    long long int sum=0;
    for(long long  int i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
        sum+=i;
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking 
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF (1ll<<60)
using namespace std;
const int mo=1000000007;
int power(int x,int y){
 	int s=1;
  	for (;y;y/=2,x=1ll*x*x%mo)
   		if (y&1) s=1ll*s*x%mo;
   	return s; 
}
const int N=25005,M=405;
int n,k,m,a[N];
int fac[N],inv[N];
int f[N][M],g[N][M];
int cnt[M],ans;
void solve1(){
	printf("%d\n",1ll*(n-m+1)*power(k,n-m)%mo);
}
int main(){
	scanf("%d%d%d",&n,&k,&m);
  	For(i,1,m) scanf("%d",&a[i]);
   	For(i,1,m-k+1){
   		CLR(cnt,0); int fl=0;
   		For(j,i,i+k-1) cnt[a[j]]++;
   		For(j,1,k) if (!cnt[j]) fl=1;
   		if (!fl) return solve1(),0;
   	}
   	fac[0]=1;
   	For(i,1,n) fac[i]=1ll*fac[i-1]*i%mo;
   	For(i,0,n) inv[i]=power(fac[i],mo-2);
   	f[0][0]=1;
   	int pre=min(m,k),nxt=pre;
   	CLR(cnt,0);
   	For(i,1,m)
   		if ((++cnt[a[i]])==2){
   			pre=i-1; break;
   		}
   	CLR(cnt,0);
   	Rep(i,m,1)
   		if ((++cnt[a[i]])==2){
   			nxt=m-i; break;
   		}
   	For(i,1,n){
   		For(j,1,k-1) f[i][j]=f[i-1][j];
   		Rep(j,k-2,1) UPD(f[i][j],f[i][j+1]);
   		For(j,1,k) UPD(f[i][j],1ll*f[i-1][j-1]*(k-j+1)%mo);
   	}
   	For(i,1,n-m)
   		UPD(ans,1ll*f[i][k]*power(k,n-m-i)%mo*(n-m-i+1)%mo);
   	For(j,pre,k-1) For(i,j,n) if (i+m-pre<=n)
   		UPD(g[i+m-pre][(nxt==m?j:nxt)],1ll*f[i][j]*inv[k]%mo*fac[k-pre]%mo);
   	For(j,1,pre) For(i,k,n) if (i+m-j<=n)
   		UPD(ans,1ll*f[i][k]*inv[k]%mo*fac[k-j]%mo*power(k,(n-(i+m-j)))%mo);
   	memset(f,0,sizeof(f));
   	For(i,1,n){
   		For(j,1,k-1) f[i][j]=f[i-1][j];
   		Rep(j,k-2,1) UPD(f[i][j],f[i][j+1]);
   		For(j,1,k) UPD(f[i][j],1ll*f[i-1][j-1]*(k-j+1)%mo);
   		For(j,1,k) UPD(f[i][j],g[i][j]);
   	}
   	For(i,1,n) UPD(ans,1ll*f[i][k]*power(k,n-i)%mo);
   	printf("%d\n",ans);
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

int a,b,c,d;cin>>a>>b>>c>>d;
  int l = max(a, c);
  int r = min(b, d);
  cout<<max(0, r-l)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>

#define REP(i,N) for(int i = 0; i <N; i++)
using namespace std;


const int MOD = pow(10,9)+7;
const int MAX = 2047483647;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> P;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}

ll gcb(ll a, ll b){/// ユークリッドの互除法: O(log)
    
    if(b == 0) return a;
    
    return gcb(b,a%b);
}


ll lcm(ll a, ll b){
    
    return  a/gcb(a,b) * b; ///gcbは約数
}


int is_consistent(int x, int y, int h, map<P, int> mp){
    
    
    for(auto m:mp){
        auto ht = m.second;
        auto p = m.first;
        
        
        if (max(0,(h - abs(x-p.first) - abs(y-p.second))) < ht){
            return -1;
        }else if (max(0,(h - abs(x-p.first) - abs(y-p.second))) > ht){
            return 1;
        }
        
    }
    
    return 0;
    
    
}

int main() {
    
    int n = in();
    
    map<P, int > mp;
    
    int ymin = INT_MAX;
    int ymax = INT_MIN;
    
    for(auto i = 0; i<n; i++){
        
        auto x = in();
        auto y = in();
        auto h = in();
        
        if (h > ymax) ymax = h;
        if (h < ymin) ymin = h;
        
        mp.insert(make_pair(make_pair(x,y),h));
        
    }
    
    auto left = ymax;
    auto right = ymin+200;
    auto middle = (left + right)/2;
    
    for(auto ix = 0; ix<=100; ix++){
         for(auto iy = 0; iy <=100; iy++){
             left = ymax;
             right = ymin+200;
             
             while(left <= right){
                 
                 middle = (left+right)/2;
                 
                 auto check = is_consistent(ix,iy,middle,mp);
                 
                 if (check == -1){
                     
                     left = middle+1;
                     continue;
                 }else if (check == 1){
                     right = middle-1;
                     continue;
                 }
                 

                 cout << ix << " " << iy << " " << middle << endl;
                 return 0;
             }
             
         }
    }
    
    
    
    
    

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	char O[55],E[55];
	scanf("%s %s",O,E);

	for(int i = 0; O[i] != '\0'; i++){

		printf("%c",O[i]);
		if(E[i] != '\0'){
			printf("%c",E[i]);
		}
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
#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> mass(n+1);
  rep(i, n) {
    cin >> mass[i+1];
  }
  int cnt = 0;
  for(int i=1;i<=n;i++) {
    if(i % 2 == 1 && mass[i] % 2 == 1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
    long long h;
    int k = 0;
    scanf("%lld",&h);
    long long result = 1;
    while(result <= h){
        result *= 2;
        k++;
    }
    k--;
    long long mm = 1;
    mm = mm << k;
    mm*=2;

    cout<<mm-1<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> p(m);
  vector<ll> y(m);
  vector<tuple<ll, ll, ll>> s;
  for (ll i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    s.emplace_back(p[i], y[i], i);
  }
  sort(s.begin(), s.end());
  // for (ll i = 0; i < m; i++) {
  //   tuple<ll, ll, ll> t = s[i];
  //   cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
  // }
  map<ll, ll> mp;
  vector<pair<ll, string>> ans;
  for (auto x : s) {
    // cout << get<0>(x) << " " << get<1>(x) << " " << get<2>(x) << endl;
    string f = "000000";
    string b = "000000";
    ll city = get<0>(x);
    mp[city]++;
    for (ll i = 5; i >= 0; i--) {
      ll num = city % 10;
      f[i] = num + '0';
      city /= 10;
    }
    ll city_num = mp[get<0>(x)];
    for (ll i = 5; i >= 0; i--) {
      ll num = city_num % 10;
      b[i] = num + '0';
      city_num /= 10;
    }
    ans.push_back(pair<ll, string>(get<2>(x), f + b));
  }
  sort(ans.begin(), ans.end());
  for (auto x : ans) {
    cout << x.second << endl;
  }
}

Measured memory_bytes: 17276
#include <iostream>

using namespace std;

int main(){
	int N;
	int K;
	int Q;

	cin >> N >> K >> Q;

	int margine = Q - K + 1;

	int A_count[N+1] = {0};
	int A[Q];

	for(int j = 0; j < Q; j++){
		cin >> A[j];
		A_count[A[j]]++;
	}

	for(int i = 1; i < N+1; i++){
		if(A_count[i] >= margine){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
//#include <math.h>
int main(void) 
{
    ll n, m;
    cin >>n >>m;
    
    
    if (n != m) {
        cout<< "No";
        return 0;
    }
   
    
    
    cout << "Yes";
    
    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main() {
    int n, cards[4][13], i, j, number;
    char card, n2s[4] = "SHCD";
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            cards[i][j] = 0;
        }
    }
    scanf("%d", &n);
    getchar();
    for (i = 0; i < n; i++) {
        scanf("%c %d", &card, &number);
        getchar();
        int suit = 0;
        switch (card) {
            case 'S':
                suit = 0;
                break;
            case 'H':
                suit = 1;
                break;
            case 'C':
                suit = 2;
                break;
            case 'D':
                suit = 3;
                break;
        }
        cards[suit][number - 1] = 1;
    }
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            if (!cards[i][j]) {
                printf("%c %d\n", n2s[i], j + 1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
// Problem : B - Mix Juice
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 *   ﷽
 * In the name of Allah,the Most Gracious,the Most Merciful
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <climits>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for(auto &e : arr) cin>>e;
	sort(arr.begin(), arr.end());
	int sum = 0;
	for(int t=0;t<k;t++) sum+=arr[t];
	cout <<sum;
	return 0;
}

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

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using ull = unsigned long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    long double h, w; cin >> h >> w;
    ll ans = ceil(h * w / 2);
    if (h == 1 or w == 1) ans = 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////




int main(){
    
    ll n,W;cin>>n>>W;
    ll w[n+1],v[n+1];rep(i,1,n)cin>>w[i]>>v[i];
    ll dp[n+1][W+1];memset(dp,0,sizeof(dp));
    
    rep(i,1,n){
        rep(j,0,W){
            dp[i][j]=dp[i-1][j];
            if(j-w[i]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    /*rep(i,0,n){
        rep(j,0,W){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    ll ans=0;
    rep(j,0,W)ans=max(ans,dp[n][j]);
    cout<<ans<<endl;
    
    return 0;
}




Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <deque>

using namespace std;

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

	deque<char> deq(s.begin(), s.end());

	int q, t, f;
	char c;
	cin >> q;

	bool is_normal = true;
	for (int i = 0; i < q; i++) {
		cin >> t;
		if (t == 1) {
			is_normal = !is_normal;
		} else {
			cin >> f >> c;
			if (f == 1) {
				is_normal ? deq.push_front(c): deq.push_back(c);
			} else {
				is_normal ? deq.push_back(c): deq.push_front(c);
			}
		}
	}

	if (!is_normal) {
		reverse(deq.begin(), deq.end());
	}
	string ans = string(deq.begin(), deq.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
  float a, b, c, d, e, f;
  float x, y;

  while (scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF) {
    y = (d * c - a * f) / (b * d - a * e);
    x = (c - b * y) / a;
    printf("%.3f %.3f\n", x, y);
  }

  return 0;
}

Measured memory_bytes: 648
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const r = +lines[0].split(" ")[0];
	const D = +lines[0].split(" ")[1];
	const x = +lines[0].split(" ")[2];
	
	const ans = [];
	let last = x;
	for(let i=0; i<10; i++){
		last = r*last - D;
		ans.push(last);
	}
	
	console.log(ans.join("\n"));
});

Measured memory_bytes: 21576
import functools
import sys

sys.setrecursionlimit(1000000)

N, = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]

@functools.lru_cache(None)
def dp(i, k):
    if k <= 0:
        return 0
    rem = N - i
    if k > (rem // 2) + (rem % 2):
        return -float('inf')
    return max(arr[i] + dp(i + 2, k - 1), dp(i + 1, k))


sol = dp(0, N // 2)

print(sol)


Measured memory_bytes: 176664
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int i;
	if(s.length()%2==0)
		i=s.length()-3;
	else
		i=s.length()-2;
	while(1)
	{
		int f=0,h=i/2+1;
		while(s[f]==s[h])
		{
			f++;
			h++;
			if(h>i)
				break;
		}
		if(f==i/2+1)
		{
			cout<<i+1<<endl;
			return 0;
		}
		else
		{
			i=i-2;
		}		
	}
	return 0;

}

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

#define MOD 1000000007

using namespace std;


int main()
{
	int n,a,ans=0,sum=0;
	int x[200];
	cin >> n >> a;
	
	vector<vector<int>> v(n,vector<int>(a));
	
	for(int i=0;i<n;i++){
		for(int j=0;j<a;j++){
			cin >> v[i][j];
		}
	}
	for(int i=0;i<200;i++){
		x[i] = i*i;
	}
		
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sum = 0;
			for(int k=0;k<a;k++){
				sum += (v[i][k] - v[j][k])*(v[i][k] - v[j][k]);
			}
			
			for(int k=0;k<200;k++){
				if(sum == x[k])ans++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
nn = []
mm = []
ll = []
ans = 0
for i in range(N):
  k = input()
  nn.append(k)
  ll.append(k)
M = int(input())
l_s = set(ll)
for i in range(M):
  k = input()
  mm.append(k)
for i in l_s:
  count = 0
  for j in nn:
    if i == j:
      count += 1
  for j in mm:
    if i == j:
      count -= 1
  if count > ans:
    ans = count
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int a,b,c,d;cin >>a>>b>>c>>d;
  string s = "Left";
  if(a+b==c+d){
    s = "Balanced";
  }else if(a+b<c+d){
    s = "Right";
  }
  cout << s;
}



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

using namespace std;

int main(int argc, char * argv[])
{
	string goal("CODEFESTIVAL2016");
	string x;
	while (getline(cin, x)) {
		unsigned int count = 0;

		for (unsigned int i = 0; i < x.size(); ++i) {
			if(x[i] != goal[i]) {
				++count;
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

int n;
int a[100001];

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

    scanf("%d", &n);
    
    for (int i = 1; i <= n; i++) {
        int t;
        scanf("%d", &t);
        a[i] = t;
    }
    
    int now ,c;
    now = 1;
    c = 0;
    
    for (;;) {
        if (now == 2) {
            cout << c;
            break;
        }
        if (c >= n) {
            cout << -1;
            break;
        }
        
        c++;
        now = a[now];
    }
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

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

    int X = scanner.nextInt();
    int Y = scanner.nextInt();

    if((Y-2*X)%2 != 0){
      System.out.println("No");
      scanner.close();
      return;
    }

    int kame = (Y-2*X) / 2;

    if(kame >= 0 && kame <= X){
      System.out.println("Yes");

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

    scanner.close();
    return;
    

  }
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,t;
  cin>>n>>t;
  int imos[t+1];
  memset(imos,0,sizeof(imos));
  for(int i=0;i<n;i++){
    int l,r;
    cin>>l>>r;
    imos[l]++;
    imos[r]--;
  }
  for(int i=0;i<t;i++) imos[i+1]+=imos[i];
  cout<<*max_element(imos,imos+t+1)<<endl;
  return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;
ll a[310][310];
ll dp[310][310];


int main(){
    int n;

    rep(i,310){
        rep(j,310){
            dp[i][j] = 1e15;
        }
    }
    ll ans = 0;
    cin >> n;

    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
            dp[i][j] = a[i][j];
        }
    }

    rep(k,n){
        rep(i,n){
            rep(j,n){
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
            }
        }
    }

    rep(i,n){
        rep(j,n){
            if(dp[i][j] < a[i][j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }

    rep(i,n){
        rep(j,n){
            bool flag = true;
            rep(k,n){
                if(i == k || j == k) continue;
                if(dp[i][j] == dp[i][k] + dp[k][j]) flag = false;
            }
            if(flag) ans += dp[i][j];
        }
    }


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


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

int main(){
  int N,K;
  cin >> N >> K;
  int number=1;
  
  for(int i=0 ; i<N ; i++){
    if(number*2 < number+K)
      number=number*2;
    else
      number=number+K;
  }
  cout << number << endl;
}

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
hasi = Array.new(n,0)
m.times do
  a,b = gets.split.map(&:to_i)
  if h[a-1] > h[b-1]
    hasi[b-1] += 1
  elsif h[a-1] == h[b-1]
    hasi[a-1] += 1
    hasi[b-1] += 1
  else
    hasi[a-1] += 1
  end
end
sum = 0
hasi.each do |a|
  if a == 0
    sum += 1
  end
end
puts sum


Measured memory_bytes: 22492
import math

def lca(x, y):
    if d[x] < d[y]:
        x,y = y,x
    dy = d[y]
    k = d[x]-dy
    while k:
        x = p[x][int(math.log(k,2))]
        k = d[x]-dy

    if x == y:
        return x

    for i in range(h)[::-1]:
        if p[x][i] != p[y][i]:
            x = p[x][i]
            y = p[y][i]
    return p[x][0]
if __name__ == "__main__":
    n = int(input())
    d = [0]*n
    d[0] = 1
    p = [[] for i in range(n)]
    p[0].append(0)
    for i in range(n):
        vi = map(int, input().split()[1:])
        nd = d[i]+1
        for j in vi:
            p[j].append(i)
            d[j] = nd
    h = int(math.log(max(d),2))+1
    for i in range(h-1):
        for x in range(n):
            p[x].append(p[p[x][i]][i])
    q = int(input())
    for _ in range(q):
        x,y = map(int, input().split())
        print(lca(x,y))



Measured memory_bytes: 43104
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int main()
{
    char a;
    scanf("%c",&a);
    if(a=='A')
        printf("T\n");
    else if(a=='T')
        printf("A\n");
    else if(a=='C')
        printf("G\n");
    else
        printf("C\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
int main()
{
    double a,b,x;
    scanf("%lf%lf%lf",&a,&b,&x);
    double h=x/(a*a);
    if(2*h>=b)
    {
        a=a/2;
        b=b-h;
        printf("%.10f\n",atan(b/a)*180/pi);
    }
    else
    {
        double s=h*a;
        a=s*2/b;
        printf("%.10f\n",atan(b/a)*180/pi);
    }
}

/*
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
ll powmod(ll a,ll b ,ll mod){
    ll p=1;
    a%=mod;
    while(b){
        if(b&1)p=(p*(a%mod))%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return p;
}
const int SIZE = 1e5+5;
int cnt[SIZE];
int arr[SIZE];
int main(){
    int n;scanf("%d",&n);
    int maxx=-1;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        cnt[arr[i]]++;
        maxx = max(maxx,arr[i]);
    }
    ll res = 1;
    for(int i=1;i<=maxx;i++){
        res *= powmod(arr[i-1],arr[i],MOD);
        res %= MOD;
    }
    printf("%lld",res);
}
*/


Measured memory_bytes: 256
// ========================================================================================================
// Library
// ========================================================================================================
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ========================================================================================================
// ========================================================================================================

int main()
{
	fastIOS();

	int a,b; cin >> a >> b;
    
    if(a==b)
    {
        cout << 0 << endl;
    }
    else{
        if((a%2 != 0 && b%2==0) || (a%2==0 && b%2 != 0)){
            cout << "IMPOSSIBLE\n";
        }
        else{
            cout << (a+b)/2 << endl;
        }
    }
    
    return 0;
    
    
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,k;

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

  cin>>n>>k;
  if(k==1)cout<<0<<endl;
  else cout<<((n-k+1)-1)<<endl;

  return 0;
}


Measured memory_bytes: 256
while 1:
	n,a,b = map(int,raw_input().split())
	if n == 0: break
	dp = [0]*(n+1)
	if a < n+1: dp[a] = 1
	if b < n+1: dp[b] = 1
	for i in range(n+1):
		if dp[i]:
			if i+a < n+1: dp[i+a] = 1
			if i+b < n+1: dp[i+b] = 1
	print n - sum(dp)

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

int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> ab(n);

    rep(i,n){
        ll a,b;
        cin >> a >> b;
        ab.at(i) = make_pair(b,a);
    }
    
    sort(ab.begin(), ab.end());

    ll spend =0;
    for(auto p : ab){
        ll time, deadline;
        tie(deadline, time) = p;
        spend += time;
        if(deadline < spend){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,L;
  cin>>N>>L;
  vector<string> s(N);
  rep(i,N) cin>>s[i];
  sort(all(s));
  string ans="";
  rep(i,N) ans+=s[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(void){
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
    if((i % 2) == 0){
      if(s[i] == 'L'){
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      if(s[i] == 'R'){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
from collections import namedtuple
Card = namedtuple('Card', 'suit value')

def partition(A,p,r):
    x = A[r]
    i = p
    for j in range(p,r):
        if A[j].value <= x.value:
            A[i],A[j] = A[j],A[i]
            i += 1
    A[i],A[r] = A[r],A[i]
    return i

def quickSort(A,p,r):
    if p < r:
        q = partition(A,p,r)
        quickSort(A,p,q-1)
        quickSort(A,q+1,r)

def merge(L,R):
    global cnt
    n = len(L)+len(R)
    A = []
    i = j = 0
    L.append(Card('X',-1))
    R.append(Card('X',-1))
    for _ in range(n):
        if L[i].value > R[j].value:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
    return A

def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 

if __name__=='__main__':
    n = int(input()) 
    Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))
    Cq = Co[:]
    Cm = mergeSort(Co[:])
    quickSort(Cq,0,n-1)
    print("Stable" if Cq==Cm[::-1] else "Not stable")
    for c in Cq: print(c.suit,c.value)

Measured memory_bytes: 42512
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int result = 0;
    int sum = 0;
    int tmp;
    for (int i = 0; i < n; i++) {
      result += sum * (tmp = sc.nextInt());
      sum += tmp;
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 23764
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, M = map(int, input().split())

if abs(N - M) > 1:
    print(0)
    exit()

def f(n):
    ret = 1
    while n > 1:
        ret *= n
        ret %= MOD
        n -= 1
    return ret

ans = 1
ans *= f(N)
ans *= f(M)
if N == M:
    ans *= 2
print(ans % MOD)

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

int     main() {
        int N;
        cin >>N;
        long S=0;
        long SS=0;
        for (int i=0; i<N; i++) {
                long A;
                cin >>A;
                SS +=A;
                if (0==A) {
                        S += SS/2;
                        SS=0;
                }
        }
        S += SS/2;
        cout <<S <<endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			int m = sc.nextInt();
			List<List<Integer>> jobs = new ArrayList<>(m);
			for(int i = 0 ; i < m ; i++) {
				jobs.add(new ArrayList<>());
			}
			int a;
			int b;
			for(int i = 0 ; i < n ; i++) {
				a = sc.nextInt();
				b = sc.nextInt();
				if(m < a) {
					continue;
				}
				List<Integer> vList = jobs.get(m - a);
				if(vList == null) {
					vList = new ArrayList<>();
				}
				vList.add(b);
			}

			long value = 0;
			PriorityQueue<Integer> q = new PriorityQueue<>((o1, o2) -> {
				return Integer.compare(o2, o1);
			});

			for(ListIterator<List<Integer>> ite = jobs.listIterator(jobs.size()) ; ite.hasPrevious() ;) {
				for(Integer v : ite.previous()) {
					q.add(v);
				}
				if(!q.isEmpty()) {
					value += q.poll();
				}
			}
			System.out.println(value);
		}
	}

}


Measured memory_bytes: 99404
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pi 3.14159265358979
int main() {
	int a, b;
	string op;
	for (int i = 0;; i++) {
		cin >> a >> op >> b;
		if (op == "?")break;
		if (op == "+")cout << a + b << endl;
		if (op == "-")cout << a - b << endl;
		if (op == "*")cout << a * b << endl;
		if (op == "/")cout << a / b << endl;
	}
	return 0;
}


Measured memory_bytes: 3144
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch); 
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch); 
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
#define   pr 	pair<int, int> 
#define   vpr 	vector<pr> 
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()
const int M           	= 1e9 + 7;
const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int N1            = 1e5 + 5;

int solve() 
{
	//happy coding

	int n;
	cin>>n;
	int a,b;
	cin>>a>>b;
	if(n*((a/n)+1)<=b||a%n==0||b%n==0){
		cout<<"OK"<<endl;
	}else{
		cout<<"NG"<<endl;
	}

	return 0;
	//error();
}
int main(){
	int test = 1;
	//readline(test);//(void)getchar();
	while (test--)solve();return 0;
}

Measured memory_bytes: 3604
import sys
N = int(input())
lis = [int(i) for i in sys.stdin.readline().split()]
res = [0,abs(lis[1]-lis[0])]
for i in range(2,N):
    tmp = min(abs(lis[i]-lis[i-1]) + res[-1],abs(lis[i] - lis[i-2]) + res[-2])
    res.append(tmp)
    res.pop(0)
print(res[-1])

Measured memory_bytes: 13888
// template {{{
#include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 3050;

int n;
string s;
ll mem[N][N];
ll dp(int lo, int hi)
{
    if (lo == 0 && hi == 0) return 1;
    ll &ret = mem[lo][hi];
    if (ret != -1) return ret;
    ret = 0;
    int pos = n-(lo+hi)-1;
    assert(pos < n-1);
    if (s[pos] == '<') {
        if (!hi) return ret; // no more hi
        ret += dp(lo, hi-1); // use the lowest hi
        ret += dp(lo+1, hi-1); // skip the lowest hi
    }
    else {
        if (!lo) return ret; // no more lo
        ret += dp(lo-1, hi); // use the lowest lo
        ret += dp(lo-1, hi+1); // skip the lowest lo
    }
    ret %= MOD;
    return ret;
}

void solve()
{
    memset(mem, -1, sizeof(mem));
    cin >> n >> s;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + dp(i-1, n-i)) % MOD;
    }
    cout << ans << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 73216