akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <vector>

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

int main() {
    string S;
    cin >> S;
    if (S=="Sunny") cout << "Cloudy";
    if (S=="Cloudy") cout << "Rainy";
    if (S=="Rainy") cout << "Sunny";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(a+b==c+d)
        System.out.println( "Balanced" );
        else if(a+b<c+d)
        System.out.println( "Right" );
        else
        System.out.println( "Left" );
    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

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

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

    int min = (unsigned int)~0 >> 1;
    int max = ~min;

    for (int i = 0; i < n; i++) {
        if (a[i] < min) {
            min = a[i];
        }
        if (a[i] > max) {
            max = a[i];
        }
    }

    cout << max - min << endl;

}

Measured memory_bytes: 256
import java.io.*;
import static java.lang.Integer.parseInt;

public class Main {
    
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String str;
        int i = 0;
        while((str = br.readLine())!=null&&i<200){
            String[] num = str.split(" ",0);
            int x = parseInt(num[0]);
            int y = parseInt(num[1]);
            if(0<=x&&x<=1000000&&0<=y&&y<=1000000){
            int z = x+y;
            System.out.println(Integer.toString(z).length());
            }
            i++;
        }
    }
}

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


int main()
{
	    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
   ll n,w;
   cin>>n>>w;
   vector<pair<ll,ll>>v;
   vector<ll>v1(w+1,0),v2(w+1,0);
   ll x,y;
   for(int i=0;i<n;i++)
   {
        cin>>x>>y;
        v.push_back(make_pair(x,y));
   }
      	 //        for(int k=0;k<=w;k++)
        //     cout<<v2[k]<<" ";
        // cout<<endl;

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

   	      for(int j=0;j<v[i].first;j++)
   	      	v2[i]=v1[i];
   	     for(int j=v[i].first;j<=w;j++)
   	     {
              v2[j]=max(v1[j],v[i].second+v1[j-v[i].first]);
   	     }
   	       
      	        for(int k=0;k<=w;k++)
               v1[k]=v2[k];
   	     v2.clear();
   }
   ll p=0;
   for(int i=0;i<=w;i++)
   	p=max(p,v1[i]);
   cout<<p<<endl;

	return 0;
}

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

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


  int hf= ceil((double)h/2);
  int wf= ceil((double)w/2);

    int he= floor((double)h/2);
  int we= floor((double)w/2);

  long long ans=((long long)hf*wf)+((long long)he*we);

  
   if(h==1 || w==1)
  cout<<"1";

  else
   cout<<ans;

  
   
  
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;string S;
    cin >> N >> S;
    int ans = 0;
    for(int i=1;i<N;++i){ // cutting pos
        int cnt = 0;
        for(char c='a';c<='z';++c){
            bool cl = false, cr = false;
            for(int l=0;l<i;++l){
                if(S[l]==c) cl = true;
            }
            for(int r=i;r<N;++r){
                if(S[r]==c) cr = true;
            }
            if(cl && cr) ++cnt;
        }
        chmax(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
(** val add : int -> int -> int **)

let rec add = ( + )

(** val sub : int -> int -> int **)

let rec sub = ( - )

module Nat =
 struct
  (** val div2 : int -> int **)

  let rec div2 = (fun x -> x / 2)
 end

(** val lower_bound_aux : (int -> bool) -> int -> int -> int **)

let rec lower_bound_aux p_dec x x0 =
  (fun fO fS n -> if n = 0 then fO () else fS (n-1))
    (fun _ ->
    x)
    (fun n0 ->
    if p_dec (add x (Nat.div2 (succ n0)))
    then lower_bound_aux p_dec x (Nat.div2 (succ n0))
    else lower_bound_aux p_dec (add (succ (Nat.div2 (succ n0))) x)
           (sub (succ n0) (succ (Nat.div2 (succ n0)))))
    x0

(** val lower_bound : (int -> bool) -> int -> int -> int **)

let lower_bound p_dec alpha beta =
  lower_bound_aux p_dec alpha (sub beta alpha)

(** val upper_bound_obligation_1 : (int -> bool) -> int -> bool **)

let upper_bound_obligation_1 p_dec n =
  let s = p_dec (succ n) in if s then false else true

(** val upper_bound : (int -> bool) -> int -> int -> int **)

let upper_bound p_dec =
  lower_bound (upper_bound_obligation_1 p_dec)

(** val upper_bound : (int -> bool) -> int -> int -> int **)

let upper_bound p_dec =
  lower_bound (upper_bound_obligation_1 p_dec)

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let bs = Array.init n (fun _ -> Scanf.scanf "%d " (fun b -> b)) in
  let cs = Array.init n (fun _ -> Scanf.scanf "%d " (fun c -> c)) in
  Array.sort compare as_;
  Array.sort compare bs;
  Array.sort compare cs;
  let cbs = Array.map (fun c -> lower_bound (fun j -> try c <= bs.(j) with _ -> true) 0 n) cs in
  let bas = Array.map (fun b -> lower_bound (fun i -> try b <= as_.(i) with _ -> true) 0 n) bs in
  let sum_ba = Array.make n 0 in
  sum_ba.(0) <- bas.(0);
  for i = 1 to n - 1 do
    sum_ba.(i) <- bas.(i) - bas.(i - 1) + sum_ba.(i - 1)
  done;
  let sum_cb = Array.make n 0 in
  for i = 0 to cbs.(0) - 1 do
    sum_cb.(0) <- sum_ba.(i) + sum_cb.(0)
  done;
  for i = 1 to n - 1 do
    for j = cbs.(i - 1) to cbs.(i) - 1 do
      sum_cb.(i) <- sum_ba.(j) + sum_cb.(i)
    done;
    sum_cb.(i) <- sum_cb.(i - 1) + sum_cb.(i)
  done;
  for i = 1 to n - 1 do
    sum_cb.(i) <- sum_cb.(i - 1) + sum_cb.(i);
  done;
  Printf.printf "%d\n" sum_cb.(n - 1)

Measured memory_bytes: 8960
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;




int main(){
ll n;
string s;
cin>>n>>s;
ll ans =0;
ll x=0;

for(ll i=0;i<s.size();i++){
  if(s[i]=='I')
  x++;
  else
  x--;

  if(x>ans)
  ans =x;


}



cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <numeric>
#include <unordered_map>
#include <bitset>
#include <queue>

#ifdef WIN32
#define I64 "%I64d"
#else
#define I64 "%lld"
#endif
#define speed() ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair
#define y1 y1asd
#define F first
#define S second
#define all(s) (s).begin(), (s).end()
#define sqr(xx) ((xx)*(xx))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
const int inf = (1 << 30) - 1;
const int sz = (int)2e5 + 5;
const double eps = 1e-7;

ll s, x, n, ans;
map <ll, ll> cnt;
void solve() {
    cin >> n;
    cnt[0] = 1;
    for (int i = 0; i < n; i++) {
        cin >> s;
        x += s;
        ans += cnt[x];
        cnt[x]++;
    }
    cout << ans;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


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

int main(){
  int N;
  cin >> N;
  long ans=0;
  for(int i=1; i<=N; i++){
    if(i%3 != 0 && i%5 !=0){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N;
int A[111][111];

signed main(){
    cin>>N;
    rep(i,N)rep(j,N)cin>>A[i][j];
    int ans=0;
    rep(i,N)rep(j,i)ans+=min(A[i][j],A[j][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3168
/*{{{*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#define assrt(...)  debug( \
if (not (__VA_ARGS__)) \
{ \
    print(__LINE__, ':', #__VA_ARGS__); \
    exit(1); \
} \
)
#else
#define debug(...) {}
#define assrt(...)
#endif

#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()

using namespace std;
using ll = long long;
using ld = long double;
template < typename t >
using V = vector< t >;

template< typename t > 
int size(const t& c)
{return c.size();}

void print()
{cout << '\n';}

template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}

template< typename a, typename b >
inline ostream& operator<<(ostream& os, const pair< a, b > p)
{return os << '(' << p.st << ", " << p.nd << ')';}

template< typename t >
void print_range(t a, const t& b)
{while (a != b) cout << (*a++) << ' '; cout << '\n';}

#define flag() __LINE__"| "__PRETTY_FUNCTION__
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cout<<#__VA_ARGS__": ";print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 2e5, cax = 2e5, mod = 1e9 + 7;

int n, tab[nax + 1], las[cax + 1], dp[nax + 3];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> tab[i];

    fill(begin(las) + 1, begin(las) + cax + 1, n + 1);

    dp[n + 1] = 0;
    dp[n] = 1;

    las[tab[n]] = n;

    for (int i = n - 1; i >= 1; --i)
    {
        int v = las[tab[i]];
        if (v - i > 1)
            dp[i] += dp[v];
        dp[i] += dp[i + 1];
        if (dp[i] >= mod) dp[i] -= mod;
        las[tab[i]] = i;
    }

    print(dp[1]);
}

Measured memory_bytes: 2560
var pass = 0;

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input) {
  var result = input.match(/[0-9]+/g);
  for (var i in result) {
    pass += Number(result[i]);
  }
});
process.stdin.on('end', function() {
  console.log(pass);
});

Measured memory_bytes: 7644
#include<iostream>
using namespace std;
int main(){
	int kai, aicec;
	int aice[11] = { 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; //??????
	int count[11] = { 0 };
	cin >> kai;
	while (kai != 0){//???????????¶
		for (int i = 0; i < kai; i++){
			cin >> aicec;
			for (int l = 1; l <= 10; l++){//??????
				if (aice[l] == aicec) count[l]++;//????????????
			}
		}
		for (int i = 1; i <= 10; i++){
			if (count[i] == 0)cout << "-" << endl;
			else {
				for (int l = 0; l < count[i]; l++){
					cout << "*";
				}cout << endl;
			}
		}
		for (int i = 1; i <= 10; i++) count[i] = 0;
		cin >> kai;
	}
	return 0;
}

Measured memory_bytes: 1152
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 10, S = (1 << N) + 10, mod = 998244353;

inline void add(int& a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

inline int mul(ll a, int b) {
	return (a * b) % mod;
}

string a[N];
int h, w, cnt[S], p2[N];
int dp[S][S][2][2];
bool seen[S][S][2][2], dp2[S][S], seen2[S][S];

int main() {
	fast_cin();
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		cin >> a[i];
		for (auto& c : a[i]) {
			c = (1 << (c == '#'));
		}
	}
	for (int i = 0; i <= max(h, w); ++i) {
		p2[i] = (1 << i);
	}
	int mrows = (1 << h), mcols = (1 << w);
	for (int mask = 0; mask < max(mrows, mcols); ++mask) {
		cnt[mask] = __builtin_popcount(mask);
	}
	for (int rows = 0; rows < mrows; ++rows) {
		for (int cols = 0; cols < mcols; ++cols) {
			bool& ans = dp2[rows][cols];
			vector<int> cr(h, 0), cc(w, 0);
			for (int i = 0; i < h; ++i) {
				if (!((rows >> i) & 1)) {
					continue;
				}
				for (int j = 0; j < w; ++j) {
					if (!((cols >> j) & 1)) {
						continue;
					}
					cr[i] |= a[i][j];
					cc[j] |= a[i][j];
				}
			}
			ans = true;
			for (int i = 0; i < h; ++i) {
				ans &= !((rows >> i) & 1) or (cr[i] == 3);
			}
			for (int j = 0; j < w; ++j) {
				ans &= !((cols >> j) & 1) or (cc[j] == 3);
			}
		}
	}
	for (int rows = 0; rows < mrows; ++rows) {
		for (int cols = 0; cols < mcols; ++cols) {
			for (int turn = 0; turn < 2; ++turn) {
				for (int must = 0; must < 2; ++must) {
					int& ans = dp[rows][cols][turn][must];
					if (!rows or !cols) {
						ans = (must == 0);
					} else {
						add(ans, dp2[rows][cols]);
						int submask = (turn ? cols : rows);
						while (submask) {
							int nrows = rows - (turn ? 0 : submask);
							int ncols = cols - (turn ? submask : 0);
							add(ans, dp[nrows][ncols][turn ^ 1][1]);
							if (must == 0) {
								add(ans, dp[nrows][ncols][turn ^ 1][1]);
								if (cnt[submask] > 1) {
									add(ans, mul(p2[cnt[submask]] - 2, dp[nrows][ncols][turn ^ 1][0]));
								}
							}
							submask = (submask - 1) & (turn ? cols : rows);
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int mask = 0; mask < (1 << w); ++mask) {
		// add(ans, mul(p2[cnt[mask]], solve((1 << h) - 1, (1 << w) - 1 - mask, 0, 0)));
		add(ans, mul(p2[cnt[mask]], dp[(1 << h) - 1][(1 << w) - 1 - mask][0][0]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 19968
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(c == 1)
		cout << "Open" << endl;
	else if(a == 1 && b == 1)
		cout << "Open" << endl;
	else
		cout << "Close" << endl;
	return 0;
}

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

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 700;
  vector<tuple<int, int, int>> lri(q);
  rep(i, q) lri[i] = make_tuple(lr[i].first / sq, lr[i].second, i);
  sort(lri.begin(), lri.end());

  VI ans(q);

  VI cnt(n+1);
  int prev = -1;
  int lx, rx;
  int sum = 0;
  for (auto [ls, r, i] : lri) {
    if (ls != prev) {
      fill(cnt.begin(), cnt.end(), 0);
      lx = rx = r;
      prev = ls;
      sum = 0;
    }
    int l = lr[i].first;
    assert(r == lr[i].second); assert(rx <= r);
    int cx;
    while (lx > l) if (cnt[cx=c[--lx]]++ == 0) sum += 1;
    while (lx < l) if (--cnt[c[lx++]] == 0) sum -= 1;
    while (rx < r) if (cnt[cx=c[rx++]]++ == 0) sum += 1;
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


Measured memory_bytes: 19320
import sys

def main():
  input = sys.stdin.readline
  N, M, Q  = map(int, input().split())
  
  DP = [[0 for _ in range(N+1)] for _ in range(N+1)] 
  for _ in range(M):
    l, r = map(int, input().split())
    DP[l][r] += 1

  cum = [[0 for _ in range(N+1)] for _ in range(N+1)]
  for i in range(1, N+1):
    for j in range(1, N+1):
      cum[i][j] = DP[i][j] + cum[i-1][j] + cum[i][j-1] - cum[i-1][j-1]

  for _ in range(Q):
    p, q = map(int, input().split())
    print(cum[q][q] - cum[p-1][q] - cum[q][p-1] + cum[p-1][p-1])


if __name__ == '__main__':
  main()

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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, x = LI()
    a = LI()

    # 隣り合う2つの和
    s = [a[i] + a[i+1] for i in range(N - 1)]
    # 隣り合う2つの和をx以下にしたもの
    s_after = [min(i, x) for i in s]

    # 隣り合う2つの和をx以下にしたものから元の数列を復元
    a_after = [0] * N
    a_after[0] = min(a[0], s_after[0])
    for i in range(N - 1):
        a_after[i+1] = min(s_after[i] - a_after[i], a[i+1])

    ans = sum(a) - sum(a_after)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 22640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ret = -1;
        for (int i = 1; i <= 10000; i++) {
            int a = (int)(i*0.08);
            int b = (int)(i*0.1);
            if (a == A & b == B) {
                ret = i;
                break;
            }
        }
        System.out.println(ret);
    }
}

Measured memory_bytes: 22868
let inf = 10101010101010
let () =
  Scanf.scanf "%d %d" @@ fun d g ->
  let pc =
    List.sort (fun x y -> compare y x) @@ Array.to_list @@ Array.init d (fun i ->
      Scanf.scanf " %d %d" (fun x y -> i, x, y)) in

  Array.init (1 lsl d) (fun b ->
    let s', n' = 
      List.fold_left (fun (s, n) (i, p, c) ->
        if b land (1 lsl i) <> 0 then begin
          (s + p * 100 * (i+1) + c, n + p)
        end else (s, n)) (0, 0) pc
    in
    let s, n =
      List.fold_left (fun (s, n) (i, p, c) ->
      if b land (1 lsl i) <> 0 then begin
        (s, n)
      end else begin
        let u = 100 * (i+1) in
        let m = (g - s + u - 1) / u |> min (p-1) |> max 0 in
        (s + m * u, n + m)
      end) (s', n') pc in
    if s >= g then n else inf
  ) |> Array.fold_left min inf |> Printf.printf "%d\n"


Measured memory_bytes: 1024
x,n=map(int,input().split())
p=list(map(int,input().split()))
tmp=1000
for i in range(-100,300):
    if not i in p:
        tmp=min(tmp,abs(x-i))
for i in range(-100,300):
    if abs(x-i) == tmp and not i in p:
        print(i)
        exit()

Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main() {
    long mod = 1e9+7;
    int N;
    cin>>N;
    long A[N], AA[N];
    for(int i=0;i<N;++i){
        cin>>A[i];
        AA[i] = A[i];
    }
    vector<int> prime;
    map<int, int> primemap;
    for(int i=0;i<N;++i){
        for(int j=2;j<2000;++j){
            int tmp = 0;
            while(A[i]%j == 0){
                if(primemap[j]==0) prime.push_back(j);
                tmp++;
                A[i] /= j;
            }
            if(primemap[j] < tmp) primemap[j] = tmp;
        }
        if(A[i] != 1){
            if(primemap[A[i]]==0){
                prime.push_back(A[i]);
                primemap[A[i]] = 1;
            }
        }
    }
    /**
    for(int i=0;i<prime.size();++i){
        cout<<prime[i]<<" "<<primemap[prime[i]]<<endl;
    }
    **/

    long lcm = 1;
    long two;
    long tmplcm;
    for(int i=0;i<prime.size();++i){
        while(primemap[prime[i]]>0){
            lcm *= prime[i];
            primemap[prime[i]]--;
            lcm %= mod;
        }
    }

    long shitaA[N];
    for(int i=0;i<N;++i){
        shitaA[i] = 1;
    }
    long tmpmod;
    long tmpshita;
    for(int i=0;i<N;++i){
        tmpmod = mod - 2;
        while(tmpmod > 0){
            tmpshita = AA[i];
            two = 1;
            while(two <= tmpmod){
                two *= 2;
                if(two > tmpmod) break;
                tmpshita *= tmpshita%mod;
                tmpshita %= mod;
            }
            two /= 2;
            tmpmod -= two;
            shitaA[i] *= tmpshita;
            shitaA[i] %= mod;
        }
    }
    long B = 0;
    for(int i=0;i<N;++i){
        B += lcm * shitaA[i] % mod;
        B %= mod;
    }
    cout<<B<<endl;;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int mod = 1000000000 + 7;

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

    long long A[N], table[N];
    long long ans = 0;

    for (int i = 0; i < N; ++i){
        cin >> A[i];
    }
    for (int i = N - 2; i >= 0; --i){
        ans = (ans + A[i] * A[i + 1]) % mod;
        A[i] = (A[i] + A[i + 1]) % mod;
    }

    cout << ans << endl;

}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ic pair <int, char>
#define sort(v) sort(v.begin(),v.end())
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


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

    int cnt=0;
    int len=s.size();
    for(int i=0; i<len; i++){
        if(s[i]!=ss[i]) cnt++;
    }
    pf("%d\n",cnt);


    return 0;
}


Measured memory_bytes: 3848
// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x,a,b) for(int x=a;x<=b;x++)
#define FORD(x,a,b) for(int x=a;x>=b;x--)
#define maxn 100005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x,y) memset(x,y,sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)

using namespace std;
int n,a,b;
int type;
deque<char> q;
int main()
{
   ios_base::sync_with_stdio(NULL);
   cin.tie(NULL);
   cout.tie(NULL);
    string s;
    cin >> s;
    for(int i=0; i<s.size(); ++i) q.pb(s[i]);
    cin >> n;
    int ok = 0;
    for(int i=1; i<=n; ++i)
    {
        cin >> type;
        if(type == 1) ok ^= 1;
        else 
        {
            char c;
            cin >> type >> c;
            -- type;
            type ^= ok;
            if(type == 1) q.pb(c);
            else q.push_front(c);
        }
    }
    if(ok) 
    {
        while(q.size())
        {
            cout << q.back();
            q.pop_back();
        }
    }
    else for(auto x : q) cout << x;
}


Measured memory_bytes: 976
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int n;
  scanf("%d",&n);
  double x;
  char u[5];
  int i;
  double ans = 0;
  for(i=0;i<n;i++) {
    scanf("%lf",&x);
    scanf("%s",u);
    if(u[0] == 'J') {
      ans += x;
    } else {
      ans += x * 380000.0;
    }
   
  }

  printf("%g\n",ans);

  return 0;
}


Measured memory_bytes: 128
require 'prime'
n = gets.to_i
ans = 0
if n == 1
    puts ans
else
    a = n.prime_division
    a.each do |x,y|
        i = 0
        while true
            i+=1
            if i<=y
                ans+=1
                y-=i
            else
                break
            end
        end
    end
    puts ans
end

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

template<typename ...> static inline int gc(void) { return getchar(); }
static inline long long read(){
    long long int k=gc(),x=0;
    for(;k<48||k>57;k=gc());
    for(;k>47&&k<58;k=gc())x=x*10+k-48;
    return x;
}

long long d[300001], m, i, M, N, O, a[300000];
priority_queue<long long> q, l;

int main(){
    N = read();
    M = N << 1;
    O = N * 3;
    for(; i < O; ++i){
        a[i] = read();
    }
    for(i = 0; i < M; ++i){
        q.push(-a[i]);
        m += a[i];
        if(N <= i){
            m += q.top();
            q.pop();
        }
        d[i + 1] = m;
    }
    m = 0;
    for(i = O; --i >= N;){
        l.push(a[i]);
        m += a[i];
        if(i < M){
            m -= l.top();
            l.pop();
        }
        d[i] -= m;
    }
    printf("%lld", *max_element(d + N, d + M + 1));
    return 0;
}


Measured memory_bytes: 7156
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>

using namespace std;

inline int read()
{
  int x=0,f=1;char ch=getchar();
  while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
  while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
  return x*f;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
  int a[10000];
  int n, flag, i, j, count=0;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
	scanf("%d", &a[i]);
	flag=1;

	if(a[i]<2) flag=0;
	else if(a[i]==2) flag=1;
	else if(a[i]%2 == 0) flag=0;
	else{
	  for(j=3; j<= a[i]/j; j+=2){
		if(a[i]%j==0) flag=0;
	  }
	}
	if(flag==1) count++;
  }
  
  printf("%d\n", count);
  
  return 0;
}

Measured memory_bytes: 632
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

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

int main()
{
        int X, Y, Z, K;
        cin >> X >> Y >> Z >> K;
        vector<ll> A(X + 1), B(Y + 1), C(Z + 1);

        for (int i = 0; i < X; i++)
        {
                cin >> A[i];
        }
        for (int i = 0; i < Y; i++)
        {
                cin >> B[i];
        }
        for (int i = 0; i < Z; i++)
        {
                cin >> C[i];
        }
        sort(A.begin(), A.end(), greater<ll>());
        sort(B.begin(), B.end(), greater<ll>());
        sort(C.begin(), C.end(), greater<ll>());
        vector<ll> ABC;
        for (int a = 0; a < X; a++)
        {
                for (int b = 0; b < Y; b++)
                {
                        if ((a + 1) * (b + 1) > K)
                        {
                                break;
                        }

                        for (int c = 0; c < Z; c++)
                        {
                                if ((a + 1) * (b + 1) * (c + 1) > K)
                                {
                                        break;
                                }
                                ABC.push_back(A[a] + B[b] + C[c]);
                        }
                }
        }
        sort(ABC.begin(), ABC.end(), greater<ll>());

        for (int i = 0; i < K; i++)
        {
                cout << ABC[i] << endl;
        }

        return 0;
}


Measured memory_bytes: 1404
#include<stdio.h>
int main(){

int N,k,a[100],m=1,n,tmp,A=0;

scanf("%d",&N);

for(k=0;k<N;k++)
scanf("%d",&a[k]);

for(m=0;m<N;m++){
for(n=N-1;n>m;n--){

if(a[n-1]>a[n]){
tmp=a[n];
a[n]=a[n-1];
a[n-1]=tmp;
A++;
}

}

}


for(k=0;k<N;k++){
printf("%d",a[k]);

if(k!=N-1)
printf(" ");
}

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

}


Measured memory_bytes: 1964
#!/usr/bin/env ruby

s = gets.chomp

size = s.size
a = ''
b = ''
i = '0'
size.times do
  a += i
  if i == '0'
    i = '1'
  else
    i = '0'
  end
  b += i
end

res1 = s.to_i(2) ^ a.to_i(2)
res2 = s.to_i(2) ^ b.to_i(2)

aa = res1.to_s(2).split(//).map(&:to_i).inject(:+)
bb = res2.to_s(2).split(//).map(&:to_i).inject(:+)
max = aa < bb ? aa : bb
puts max


Measured memory_bytes: 102280
fn read_ls<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let l:Vec<i32> = read_ls();
    let (a, b, c) = (l[0], l[1], l[2]);
    let mut cn = 0;
    for i in a..(b+1) {
        if c % i == 0 { cn += 1 }
    }
    println!("{}", cn)
}



Measured memory_bytes: 5028
N, M = gets.split.map(&:to_i)
ans = []
N.times do
  ans.push 0
end

hasAns = true
M.times do
  s, c = gets.split.map(&:to_i)
  s -= 1
  if hasAns && (ans[s] == 0 || ans[s] == c) then
    ans[s] = c
    if s == 0 && c == 0 && N > 1 then
      hasAns = false
    end
  else
    hasAns = false
  end
end

if N > 1 && ans[0] == 0 then
  ans[0] = 1
end

if hasAns then
  puts ans.join
else
  puts '-1'
end


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <tuple>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(std::min<int>(l_, r_)), r(r_) {}
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): r(std::max<int>(l_, r_) - 1), l(l_ - 1) {}
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

int main() {
  int N;
  std::cin >> N;
  std::map<std::string, int> map;
  for (int i: range(0, N)) {
    std::string S;
    std::cin >> S;
    map[S]++;
  }
  int max = 0;
  for (auto p: map) {
    chmax(max, p.second);
  }
  for (auto p: map) {
    if (p.second == max) {
      std::cout << p.first << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 1 << 16;
const int LOGN = 19;

int n, m, k;
int a[10];

void solve(int test)
{
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x;
    for (int j = 0; j < x; ++j) {
      cin >> y;
      a[y - 1] |= 1 << i;
    }
  }
  int mask = 0;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    mask |= abs(x - 1) << i;
  }
  int ans = 0;
  for (int i = 0; i < 1 << n; ++i) {
    int cur = mask;
    for (int j = 0; j < 10; ++j) {
      if ((i >> j) & 1) {
        cur ^= a[j];
      }
    }
    ans += (cur == (1 << m) - 1);
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
//  ll ans;
//  if(n < k) {
//    ans = n;
//  } else if(n == k) {
//    ans = 0;
//  } else {
//    ll ama = n % k;
//    ans = min(ama, abs(k-ama));
//  }
  ll ans = min(n%k, abs(k-(n%k)));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define NMAX 51
#define INF (1<<30)

int N;
int TL[NMAX];// 左端から切れ目までの長さ

// 最小のピース長 lmin に対する適切な最大のピース長を動的計画法で求める
int lmax(int lmin){
  //  cout << "lmin = " << lmin << endl;
  int dp[NMAX];// i 番目の切れ目まで考えるときの適切な最大のピース長
  dp[0]=0;

  for(int i=1;i<=N;i++){ // ピースの右端
    //    cout << "i = " << i << endl;
    dp[i]=INF;
    for(int j=0;j<i;j++){ // ピースの左端
      if(i==N && j==0) continue;// 最低でも1箇所はカットする
      //      cout << "(" << j << "," << i << ") "; 
      int lpiece=TL[i]-TL[j]; // ピースの長さ
      //      cout << "lpiece = " << lpiece << endl;
      if(lpiece >= lmin)
	dp[i]=min( max(lpiece,dp[j]) ,dp[i]);
      //      cout << " dp[" << i << "] = " << dp[i];
    }
    //    cout << endl;
  }
  return dp[N];
}

int main(){
  cin >> N;
  TL[0]=0;
  for(int i=1;i<=N;i++){
    int l;
    cin >> l;
    TL[i]=TL[i-1]+l; // 左端から切れ目までの長さ
  }

  int ans=INF;
  for(int i=0;i<N;i++){// left of minimum piece
    for(int j=i+1;j<=N;j++){// right of minimum piece
      if(i==0 && j==N) continue;
      int lmin=TL[j]-TL[i];// length of minimum piece
      ans = min( lmax(lmin)-lmin ,ans);
      //      cout << "ans = " << ans << endl;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int A=26;
bool used[A];

signed main()
{
    string s; cin>>s;
    REP(i,SZ(s)) used[s[i]-'a']=1;
    
    for(char c='a';c<='z';c++){
        if(!used[c-'a']){
            cout<<s+c<<endl;
            return 0;
        }
    }
    
    for(int i=A-2;i>=0;i--){
        if(s[i]<s[i+1]){
            char c='~';
            for(int j=i+1;j<A;j++){
                if(s[j]>s[i]) c=min(c,s[j]);
            }
            cout<<s.substr(0,i)+c<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 256
//
// Created by sark2 on 19-10-2019.
//

#include "bits/stdc++.h"

#define pb push_back
using namespace std;
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cases int t;cin>>t;while(t--)
typedef long double ld;
typedef long long ll;
const int mod = 1e9 + 7;


void add_self(int& a, int b);

int main() {
    IOS

    string k;
    cin>>k;

    int d; cin>>d;

    int n = k.length();

    vector<vector<int>> dp(d, vector<int>(2));
    //dp[sum][sm_already] - # of ways to choose digits so far
    // such that the sum of digits modulo d is 'sum' and
    //'sm_already' says whether we already has chosen some digit smaller
    // than in K

    dp[0][0] = 1;

    for(int where = 0; where < n; ++where){
        vector<vector<int>>new_dp(d, vector<int>(2));
        for(int sum = 0; sum < d; ++sum){
            for(bool sm_already : {false, true}){
                for(int digit = 0; digit <= 9; ++digit){
                    if(digit > k[where]-'0' && !sm_already)
                        break;
                    add_self(new_dp[(sum+digit)%d][sm_already || (digit < k[where]-'0')], dp[sum][sm_already]);
                }
            }
        }
        dp = new_dp;
    }

    int ans = (dp[0][false]+dp[0][true])%mod;
    --ans;
    if(ans == -1)
        ans += mod;

    cout<<ans<<"\n";




}

void add_self(int& a, int b) {
    a += b;
    if(a >= mod)
        a -= mod;
}


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

using ll=long long;
#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)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int a,b;
	cin >> a >> b;
	if(a > 8 || b > 8) cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

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

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

using namespace std;

int main(){
  string s;cin>>s;
  if(s.size()==2)cout<<s;
  else rep(i, 3)cout<<s[2-i];
  return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vl a(n);
		rep(i,n) cin>>a[i];
		sort(all(a));

		ll prev=0,grundy=0;
		rep(i,n){
			ll cnt=a[i]-prev;
			if(cnt%2)
				grundy^=n-i;
			prev=a[i];
		}
		cout<<(grundy?"first":"second")<<endl;
	}
}


Measured memory_bytes: 1024
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d %d",&n,&m,&k);
	swap(n,m);
	swap(n,k);
	printf("%d %d %d\n",n,m,k);
	return 0;
}



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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	int N,M;
	cin >> N >> M;
	set<int> A;
	REP(i,M){
	    int a;
	    cin >> a;
	    A.insert(a);
	}

	static ll dp[100002] = {};
	dp[0] = 1;
	if (!SIN(1,A)) dp[1] = 1;
	FORq(i,2,N){
	    if (SIN(i,A)){
	    	continue;
	    }

	    dp[i] = (dp[i-1] + dp[i-2]) % MOD;
	}

	cout << dp[N] << "\n";
}

Measured memory_bytes: 4992
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    G = [[] for _ in range(N)]
    E = []
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        G[a].append(b)
        G[b].append(a)
        E.append((a, b))
    par = [-1] * N
    par[N - 1] = N - 1
    stk = [N - 1]
    while stk:
        v = stk.pop()
        for to in G[v]:
            if par[to] >= 0:
                continue
            par[to] = v
            stk.append(to)
    path = []
    v = 0
    while v != N - 1:
        path.append(v)
        v = par[v]
    path.append(N - 1)
    m = (len(path) - 1) // 2
    x, y = path[m], path[m + 1]
    uf = UnionFindTree(N)
    for a, b in E:
        if a == x and b == y or a == y and b == x:
            continue
        uf.union(a, b)
    print('Fennec' if uf.size(0) > uf.size(N - 1) else 'Snuke')

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return False
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x
        return True

    def same(self, x, y): return self.find(x) == self.find(y)
    def size(self, x): return -self.parent[self.find(x)]

if __name__ == '__main__':
    main()


Measured memory_bytes: 67632
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N, K;
    K = 2;
    int h[100001];
    cin >> N;
    rep(i, 0, N) cin >> h[i];    
    int dp[100001];
    rep(i, 0, 100001) dp[i] = inf;
    dp[0] = 0;
    for(int i=0; i<N; i++){
        for(int k=1; k<=K; k++){
            if(i-k >= 0){
                dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]));
            }
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  ll n,m,ans;cin>>n>>m;
  if(n*m==1)ans=1;
  else if(n==1||m==1)ans=n*m-2;
  else ans=n*m-2*(n+m)+4;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
a.sort()
ans=a.pop(-1)
n-=2
while n!=0:
    if n>1:
        ans+=a.pop(-1)*2
        n-=2
    if n==1:
        ans+=a.pop(-1)
        n-=1
print(ans)

Measured memory_bytes: 31756
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string t;
int dp[200010][2];
int main(){
	std::cin>>t;
	rep(i,t.size()+1)dp[i][0]=dp[i][1]=-INF;
	dp[0][1]=0;
	rep(i,t.size()){
		if(t[i]=='P'){
			chmax(dp[i+1][0],dp[i][0]);
			chmax(dp[i+1][0],dp[i][1]);
		}
		else if(t[i]=='D'){
			chmax(dp[i+1][1],dp[i][0]+2);
			chmax(dp[i+1][1],dp[i][1]+1);
		}
		else{
			chmax(dp[i+1][0],dp[i][0]);
			chmax(dp[i+1][0],dp[i][1]);
			chmax(dp[i+1][1],dp[i][0]+2);
			chmax(dp[i+1][1],dp[i][1]+1);
		}
	}
	std::string ans;
	int a;
	if(dp[t.size()][0]<dp[t.size()][1])a=1;
	else a=0;
	for(int i=t.size();i>0;i--){
		if(a==1){
			ans+='D';
			if(dp[i][1]==dp[i-1][0]+2)a=0;
			else a=1;
		}
		else{
			ans+='P';
			if(dp[i][0]==dp[i-1][0])a=0;
			else a=1;
		}
	}
	std::reverse(all(ans));
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 5512
#include<stdio.h>

int main(void)
{
	int i,x=0;
	
	for(i=0;i<=10000;i++)
	{
			scanf("%d",&x);
			if(x==0) break;
			printf("Case %d: %d\n",i+1,x);
	}
	return 0;
}


Measured memory_bytes: 600