akhauriyash/Code-Regression huggingface dataset:
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vector<string> c;
vl a;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    c = vector<string>(2*N);
    a = vl(2*N);
    for(int i = 0; i < 2*N; ++i){
        cin >> c[i];
        cin >> a[i];
    }
    solve();
}

// 1 ≤ N ≤ 2000
// 1 ≤ a_i ≤ N
// c_i = W または c_i = B
// i ≠ j なら、 (a_i,c_i) ≠ (a_j,c_j)

#ifndef ONLINE_JUDGE
#include "../template/template.hpp"
#endif

struct BinaryIndexedTree {
    int sz;
    vector<ll> data;

    BinaryIndexedTree(int sz):sz(sz){
        data.assign(sz,0);
    }

    void add(int x,int val){
        while(x<sz)data[x]+=val,x|=x+1;
    }

    ll sum(int to){
        to=min(to,sz-1);
        ll ret=0;
        while(to>=0)ret+=data[to],to=(to&(to+1))-1;
        return ret;
    }

    ll sum(int from,int to){
        if(from>to)return 0;
        return sum(to)-sum(from-1);
    }
};

vvl g(vp &x,vp &y){
    vvl ret(N+1,vl(N));
    BinaryIndexedTree bit(2*N);
    rrep(i,N){
        bit.add(y[i].second,1);
        rep(j,N)ret[i][j]=bit.sum(x[j].second);
    }
    return ret;
}
ll f(vp &x){
    ll ret=0;
    BinaryIndexedTree bit(N);
    rep(i,N){
        ret+=bit.sum(x[i].first,N-1);
        bit.add(x[i].first,1);
    }
    return ret;
}

// ll N, vector<string> c, vl a
// 目標を達成するために必要な操作回数の最小値を出力せよ。
void solve(){
    vp b,w;
    rep(i,2*N){
        if(c[i]=="B")b.emplace_back(a[i]-1,i);
        else w.emplace_back(a[i]-1,i);
    }

    ll ans=0;
    ans+=f(b);
    ans+=f(w);

    sort(all(b));
    sort(all(w));

    vvl cost1=g(b,w);
    vvl cost2=g(w,b);
    vvl dp(N+1,vl(N+1,LINF));
    dp[0][0]=0;
    repe(i,N)repe(j,N){
        if(i<N)chmin(dp[i+1][j],dp[i][j]+cost1[j][i]);
        if(j<N)chmin(dp[i][j+1],dp[i][j]+cost2[i][j]);
    }
    ans+=dp[N][N];

    cout<<ans<<endl;
}


Measured memory_bytes: 94592
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<bool>> VVB;
typedef pair<int,int> PII;
typedef pair<char,int> PCI;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

#define process first
#define movecnt second

int N, M;
VVB area;
vector<PCI> ms;
int posx, posy;

bool check () {
	rep (i, area.size()) {
		rep (j, area[i].size()) {
			if (area[i][j]) return false;
		}
	}
	return true;
}

void move (int movex, int movey, int cnt) {
	rep (i, cnt) {
		if (xyrange(posx, 0, 20, posy, 0, 20)) {
			posx += movex;
			posy += movey;
			area[posy][posx] = false;
		}
	}
}

bool solve () {
	posx = posy = 10;
	area[posy][posx] = false;
	for (auto &m : ms) {
		switch (m.process) {
			case 'N':
				move(0, 1, m.movecnt);
				break;
			case 'S':
				move(0, -1, m.movecnt);
				break;
			case 'E':
				move(1, 0, m.movecnt);
				break;
			case 'W':
				move(-1, 0, m.movecnt);
				break;

		}
	}
	return check();
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> N, N) {
		area.clear();
		area.resize(21, VB(21, false));
		ms.clear();
		rep (i, N) {
			int x, y;
			cin >> x >> y;
			area[y][x] = true;
		}
		cin >> M;
		rep (i, M) {
			PCI m;
			cin >> m.process >> m.movecnt;
			ms.pb(m);
		}

		cout << (solve()? "Yes" : "No") << endl;
	}
	return 0;
}

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

int main() {
	int m, f, r;
	char c;
	while (1) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;
		if (m == -1 || f == -1) c = 'F';
		else if (m + f >= 80) c = 'A';
		else if (m + f >= 65) c = 'B';
		else if (m + f >= 50) c = 'C';
		else if (m + f >= 30) c = (r >= 50 ? 'C' : 'D');
		else c = 'F';
		cout << c << endl;
	}
}

Measured memory_bytes: 1152
K, N = map(int, input().split())
lst = list(map(int, input().split()))

max_dist = 0
for i in range(N-1):
    if max_dist < lst[i+1]-lst[i]:
      max_dist = lst[i+1]-lst[i]

if max_dist < lst[0] + (K-lst[-1]):
      max_dist = lst[0] + (K-lst[-1])

print(K - max_dist)

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

typedef struct LIST {
  struct LIST *prev;	// 前
  struct LIST *next;	// 後ろ
  int key;
} LIST;

void insert(int key);	// 追加する
void delete(LIST *p);	// 削除する
void show_list(LIST *p);
void free_list(LIST *p);
LIST *search(int key);

LIST head;	  

int main() {
  int n,i;
  int key;
  char c[13];
  LIST *p;

  head.next = &head;
  head.prev = &head;

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

    if('i'==c[0]){
      scanf("%d",&key);
      insert(key);
    }

    else if(strcmp("delete",c)==0){
      scanf("%d",&key);
      if(search(key)!=&head) delete(search(key));
    }

    else if('F'==c[6]){
      delete(head.next);
    }

    else if('L'==c[6]){
      delete(head.prev);
    }
  }
  show_list(head.next);

  free_list(head.next);	// リストの解放
  return 0;			// 正常終了
}


void insert(int key) {
  LIST *p1;		// 追加
  LIST *p2;		// 挿入前: p -> p2  ⇒　挿入後; p -> p1 -> p2
  LIST *p = &head;	
  /* 記憶領域の確保 */
  if ((p1 = (LIST *) malloc(sizeof(LIST))) == NULL) {
    printf("malloc error\n");
    exit(0);
  }

  p1->key = key;

  // 挿入前: p -> p2  ⇒　挿入後; p -> p1 -> p2
  p1->next = head.next;
  head.next->prev = p1;
  head.next = p1;
  p1->prev = &head;
}

// 削除する
void delete(LIST *p) {	// prev -> p -> next　⇒  prev -> next
  LIST *prev = p->prev;
  LIST *next = p->next;
  free(p);
  prev->next = next;
  next->prev = prev;
}

/*** リストの表示 ***/
void show_list(LIST *p) {
  while (p != &head) {	/* 次ポインタがNULLまで処理 */
    printf("%d", p->key);
    p = p->next;
    if(p!=&head) printf(" ");
  }
  printf("\n");
}

/*** リストの解放 ***/
void free_list(LIST *p) {
  while (p != &head) {     /* 次ポインタがNULLまで処理 */
    LIST *p2 = p->next;
    free(p);
    p = p2;
  }
}

LIST *search(int key){
  LIST *p;
  p=head.next;
  while(p!=&head && p->key!=key){
    p = p->next;
  }
  if(p==&head) return &head;
  else return p;
}

Measured memory_bytes: 31660
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

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

  int res = 0;
  for (char c : s) {
    if (c == 'I') {
      x++;
      res = max(res, x);
    } else {
      x--;
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int v = N;
        int ans = 1;
        int cnt = 0;
        while (v > 1) {
            v >>= 1;
            cnt++;
            ans *= 2;
        }

        System.out.println(ans);

        return;
    }

}

Measured memory_bytes: 23892
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

void print_vector(vector<int>& v) {
    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << "\n";
    return;
}

// class Solution {
// public:
//     int trap(vector<int>& height) {
//         return 0;    
//     }
// };

int main()
{
    int a[105];
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];
    int ans = 0;
    int i = 0;
    int j = i;
    while (j < N) {
        while (j < N && a[j] == a[i]) j++;
        int cnt = j - i;
        ans += cnt / 2;
        i = j;
        j++;
    }
    cout << ans << "\n";

    return 0;
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N, as[200020];
  vector<int> bs;

  void init() {
    cin >> N;
    rep(i, N) {
      cin >> as[i];
      bs.push_back(as[i]-i-1);
    }
    sort(bs.begin(), bs.end());
  }

  ll calc(int b) {
    ll res = 0;
    rep(i, N) res += abs(as[i] - (b + i + 1));
    return res;
  }

  void solve() {
    if(bs.size()%2) {
      cout << calc(bs[(bs.size()-1)/2]) << "\n";
    } else {
      cout << min(calc(bs[(bs.size())/2]), calc(bs[(bs.size()-1)/2])) << "\n";
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 4956
main = do
    dice <- getLine
    let (n1:n2:n3:n4:n5:n6:_) = map (\x -> read x :: Int) $ words dice
    commands <- getLine
    let finDice = roll commands (n1, n2, n3, n4, n5, n6)
    putStrLn $ top finDice

type Dice = (Int, Int, Int, Int, Int, Int)

roll :: String -> Dice -> Dice
roll [] dice = dice
roll (x:xs) dice
  | x == 'N' = roll xs $ rollN dice
  | x == 'E' = roll xs $ rollE dice
  | x == 'W' = roll xs $ rollW dice
  | x == 'S' = roll xs $ rollS dice
  | otherwise = dice

top :: Dice -> String
top (n1,_,_,_,_,_) = show n1

rollN :: Dice -> Dice
rollN (n1, n2, n3, n4, n5, n6) = (n2, n6, n3, n4, n1, n5)

rollE :: Dice -> Dice
rollE (n1, n2, n3, n4, n5, n6) = (n4, n2, n1, n6, n5, n3)

rollW :: Dice -> Dice
rollW (n1, n2, n3, n4, n5, n6) = (n3, n2, n6, n1, n5, n4)

rollS :: Dice -> Dice
rollS (n1, n2, n3, n4, n5, n6) = (n5, n1, n3, n4, n6, n2)


Measured memory_bytes: 3628
#include <stdio.h>
#define F 44
 
  int main(){
    int i, n;
 
    scanf("%d", &n);
    printf("%d\n", fibonacci(n));
 
    return 0;
  }
 
  int fibonacci(int n){
    int i;
    int a = 1, b = 1, temp = 1;
 
    for(i = 2; i <= n; i++){
      temp = a + b;
      a = b;
      b = temp;
    }
    return temp;
  }

Measured memory_bytes: 596
var
  a:array[1..100] of ansistring;
  t:ansistring;
  i,j,n,m:longint;
 function pd(n,m:ansistring;k:longint):boolean;
  begin
    if ord(n[k])>ord(m[k]) then exit(true)
      else if ord(n[k])<ord(m[k]) then exit(false)
             else exit(pd(n,m,k+1));
  end;
begin
  readln(n,m);
  for i:=1 to n do readln(a[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if pd(a[i],a[j],1) then
        begin
          t:=a[i]; a[i]:=a[j]; a[j]:=t;
        end;
  for i:=1 to n do write(a[i]);
end.

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m<0 && f<0 && r<0) break;
            if(m<0 || f<0) System.out.println("F");
            else if(m+f>=80) System.out.println("A");
            else if(m+f>=65) System.out.println("B");
            else if(m+f>=50) System.out.println("C");
            else if(m+f>=30){
                if(r>=50) System.out.println("C");
                else System.out.println("D");
            }
            else System.out.println("F");
        }
        sc.close();
    }
}


Measured memory_bytes: 26236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,a,n) for(ll i=(a); i<(ll)(n); i++)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(v) (v).begin(), (v).end()

int main(void) {
    int N;
    int minus=1;
    cin >> N;
    int A;
    for (int i=0; i<N; i++) {
        cin >> A;
        if (A % 2 == 0) minus *= 2;
    }
    cout << pow(3,N) - minus << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    def lcm(a,b):
        #return  (a * b *pow(math.gcd(a, b),mod-2,mod))%mod
        return (a*b//math.gcd(a,b))
    x=1
    
    for a in A:
        x=lcm(a,x)
    #print(x)
    x%=mod
    ans=0
    for a in A:
        ans=(ans+x*pow(a,mod-2,mod))%mod
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 78696
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;
int main() {
	string s;
	cin >> s;
	int x = count(s.begin(), s.end(), 'x');

	cout << (x > 7 ? "NO" : "YES") << endl;
	return 0;
}


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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n), dp(k + 1);
	for (int &i : a) cin >> i;
	for (int i = 0; i <= k; i++) {
		int got = false;
		for (int j : a) {
			if (j <= i)
				got |= !dp[i - j];
		}
		if (got) dp[i] = true;
	}

	cout << (dp[k] ? "First" : "Second") << endl;
}
// Remember to clear the global containers



// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


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

int main(){
  int N; cin >>N;
  pair<int,int> BA[N];
  for(int i=0;i<N;i++){
    int a,b; cin >>a >>b;
    BA[i].first = b;
    BA[i].second = a;
  }
  sort(BA,BA+N);

  long int time=0;
  for(int i=0;i<N;i++){
    time += BA[i].second;
    if(time > BA[i].first){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_163_CirclePond
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            // 整数の入力
            double R = double.Parse(Console.ReadLine());
            double result;
            result = R * 2 * Math.PI;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27588
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;


int main()
{
	int n;
	cin>>n;
	unsigned long long int sum = 0;
	for(int i = 0 ; i < n; i++){
		int num;
		cin>>num;
		sum += (num-1);
	}
	cout<<sum<<endl;
	return 0;
}



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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  lli n;
  while (cin >> n) {
    const int N = 70;
    const int M = 20;
    const lli mod = 1e9 + 7;
    lli dp[N][M];
    fill(&dp[0][0], &dp[N - 1][M - 1] + 1, 0);
    dp[0][0] = 1;

    // cout << ">>>> " << n << endl;
    
    vector<int> v;
    for (lli i = 1; i <= n; i *= 2LL) {
      v.push_back((bool)(n & i));
    }
    reverse(v.begin(), v.end());

    for (int nth = 0; nth < v.size(); ++nth) {
      for (int i = 0; i < 3; ++i) {
        {
          int a = 0, b = 0;
          const int j = i * 2 + v[nth] - a - b;
          if (0 <= j) {
            (dp[nth + 1][min(j, 2)] += dp[nth][i]) %= mod;
          }
        }
        {
          int a = 1, b = 1;
          const int j = i * 2 + v[nth] - a - b;
          if (0 <= j) {
            (dp[nth + 1][min(j, 2)] += dp[nth][i]) %= mod;
          }
        }
        {
          int a = 0, b = 1;
          const int j = i * 2 + v[nth] - a - b;
          if (0 <= j) {
            (dp[nth + 1][min(j, 2)] += dp[nth][i]) %= mod;
          }
        }
      }
    }
    lli sum = dp[v.size()][0] + dp[v.size()][1] + dp[v.size()][2];
    sum %= mod;
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		int sequenceNumber = Integer.parseInt(sc.next());
		
		int argments[] = new int[sequenceNumber];
		
		for(int i = 0;i<argments.length;i++){
			
			argments[i] = Integer.parseInt(sc.next());
			
		}
		int min = min(argments);
		int max = max(argments);
		long sum = sum(argments);
		
		System.out.println(min +" " + max + " " + sum);
		
		sc.close();
	}

	private static long sum(int[] argments) {
		
		long sum = 0;
		for(int i = 0;i<argments.length;i++){
			
			sum += argments[i];
			
		}
		
		return sum;
	}

	private static int max(int[] argments) {
		
		int max = argments[0];
		for(int i = 1;i<argments.length;i++){
			
			if(max < argments[i]){
				max = argments[i];
			}
		}
		
		
		return max;
	}

	private static int min(int[] argments) {
		
		int min = argments[0];
		for(int i = 1;i<argments.length;i++){
			
			if(min > argments[i]){
				min = argments[i];
			}
		}
		
		
		return min;
	}

}


Measured memory_bytes: 40644
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,a,b,c,d ;
	cin >> n >> a >> b >> c >> d ;
	vc root(n+2,'#') ;
	for(int i=1;i<=n;i++) cin >> root.at(i) ;
	if(c<d){
		ll pos = b ;
		while(pos<d){
			if(root.at(pos+1)=='.') pos++ ;
			else if(root.at(pos+2)=='.') pos += 2 ;
			else break ;
		}
		if(pos!=d){
			cout << "No" << endl ;
			return 0 ;
		}
		pos = a ;
		while(pos<c){
			if(root.at(pos+1)=='.') pos++ ;
			else if(root.at(pos+2)=='.') pos += 2 ;
			else break ;
		}
		if(pos!=c){
			cout << "No" << endl ;
			return 0 ;
		}
		cout << "Yes" << endl ;
	}else{
		bool ok = false ;
		for(int i=b;i<=d;i++){
			if(root.at(i)=='#') continue ;
			if(root.at(i-1)=='.'&&root.at(i+1)=='.') ok = true ;
		}
		if(!ok){
			cout << "No" << endl ;
			return 0 ;
		}
		ll pos = b ;
		while(pos<d){
			if(root.at(pos+1)=='.') pos++ ;
			else if(root.at(pos+2)=='.') pos += 2 ;
			else break ;
		}
		if(pos!=d){
			cout << "No" << endl ;
			return 0 ;
		}
		pos = a ;
		while(pos<c){
			if(root.at(pos+1)=='.') pos++ ;
			else if(root.at(pos+2)=='.') pos += 2 ;
			else break ;
		}
		if(pos!=c){
			cout << "No" << endl ;
			return 0 ;
		}
		cout << "Yes" << endl ;
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

const double eps = 1e-10;

class Point {
public:
    double x, y;
    Point(double _x = 0., double _y = 0.) : x(_x), y(_y) {}
};

istream& operator >> (istream& in, Point& P)
{
    in >> P.x >> P.y;
    return in;
}

ostream& operator << (ostream& out, const Point& P)
{
    out << P.x << " " << P.y;
    return out;
}

double Dist(const Point& P, const Point& Q)
{
    double dx = P.x - Q.x;
    double dy = P.y - Q.y;
    return sqrt(dx * dx + dy * dy);
}

class Circle {
public:
    Point c;
    double r;
    Circle(const Point& _c = Point(), double _r = 0.) : c(_c), r(_r) {}
};

istream& operator >> (istream& in, Circle& C)
{
    in >> C.c >> C.r;
    return in;
}

int CircStatus(const Circle& C1, const Circle& C2)
{
    double d = Dist(C1.c, C2.c);
    if (d > C1.r + C2.r + eps) {
        return 4;
    } else if (d > C1.r + C2.r -eps) {
        return 3;
    } else if (d > fabs(C1.r - C2.r) + eps) {
        return 2;
    } else if (d > fabs(C1.r - C2.r) - eps) {
        return 1;
    } else {
        return 0;
    }
}

class Vector {
public:
    double x, y;
    Vector(double _x = 0., double _y = 0.) : x(_x), y(_y) {}
    Vector(const Point& P) : x(P.x), y(P.y) {}
    Vector(const Point& St, const Point& End) : x(End.x - St.x), y(End.y - St.y) {}
    inline double InnerProd(const Vector& V)
    {
        return x * V.x + y * V.y;
    }
    inline double OuterProd(const Vector& V)
    {
        return x * V.y - y * V.x;
    }
    inline double Length()
    {
        return sqrt((*this).InnerProd(*this));
    }
};

Vector operator+(const Vector& V1, const Vector& V2)
{
    return Vector(V1.x + V2.x, V1.y + V2.y);
}

Vector operator*(double d, const Vector& V)
{
    return Vector(d * V.x, d * V.y);
}

Vector operator/(const Vector&V, double d)
{
    return Vector(V.x / d, V.y / d);
}

bool operator<(const Vector& V1, const Vector& V2)
{
    return V1.x < V2.x || (V1.x == V2.x && V1.y < V2.y);
}

ostream& operator<<(ostream& out, const Vector V)
{
    out << V.x << " " << V.y;
    return out;
}

void PrintCross(const Circle& C, const Point& St, const Point& End)
{
    Vector LineVec(St, End);
    Vector LineUnitVec = LineVec / LineVec.Length();
    Vector RefVec(St, C.c);
    double ParaDist = LineUnitVec.InnerProd(RefVec);
    double PerpDist = fabs(LineUnitVec.OuterProd(RefVec));
    double ParaDistDiff = sqrt(C.r * C.r - PerpDist * PerpDist);
    Vector Res1 = St + (ParaDist - ParaDistDiff) * LineUnitVec;
    Vector Res2 = St + (ParaDist + ParaDistDiff) * LineUnitVec;
    if (Res2 < Res1) {
        swap(Res1, Res2);
    }
    cout << Res1 << " " << Res2 << endl;
}

int main()
{
    Circle C;
    cin >> C;
    int q;
    cin >> q;
    Point St, End;
    cout << fixed << setprecision(10);
    for (int i = 0; i < q; ++i) {
        cin >> St >> End;
        PrintCross(C, St, End);
    }
    
    return 0;
}



Measured memory_bytes: 3288
n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
g = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
for i in range(1, n+1):
    now = h[i]
    next = 0
    for j in g[i]:
        next = max(next, h[j])
    if now > next:
        ans += 1

print(ans)


Measured memory_bytes: 29352
#include <iostream>
#include <algorithm>

int main() {
	int h, n;
	std::cin >> h >> n;

	int a[1010], b[1010];
	for (int i = 0; i < n; ++i)
		std::cin >> a[i] >> b[i];

	int dp[10010] = { 0 };
	dp[h] = 0;
	for (int i = 0; i < h; ++i)
		dp[i] = 1e9;

	for (int i = h; i > 0; --i) {
		for (int j = 0; j < n; ++j) {
			int pos = std::max(0, i - a[j]);
			dp[pos] = std::min(dp[pos], dp[i] + b[j]);
		}
	}

	std::cout << dp[0];
}

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

int main(){
   ll A;
   long double B;

   cin>>A>>B;

   cout << (ll)(A*B) << endl;
}


Measured memory_bytes: 3708
#include <iostream>

using namespace std;

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int i = 0; i <= 3000; i++) {
        for (int j = 0; j <= 3000; j++) {
            int t = i * R + j * G;
            if (t <= N and (N - t) % B == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<vector>
#include<cstring>
#include<set>
#include<queue>
#include<map>
#include<climits>
#include<cmath>
#include<iomanip>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll unsigned long long int
#define db double
#define all(v) v.begin(),v.end()

using namespace std;



ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}


/*
vi<ll> v;
 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}
 */








int main(){
    IOS;
   ll t=1;
   cin>>t;
   while(t--){
       ll n,a,b,c,d,ma,mb,mc,md;
       cin>>n>>a>>b>>c>>d;
       map<pair<ll,ll>,ll> m;
       priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
       pq.push({(ll)0,n});
       while(pq.top().S!=0){
           n=pq.top().S;
           ll z=pq.top().F;
          // cout<<z<<" "<<n<<"\n";
           pq.pop();
           ll x,y;
           x=(n/5);
           y=n%5;
           if(m[{z+c+y*d,x}]==0){
           pq.push({z+c+y*d,x});
            m[{z+c+y*d,x}]=1;
           }
           if(y!=0){
               x++;
               y=5*x-n;
                if(m[{z+c+y*d,x}]==0){
               pq.push({z+c+y*d,x});
                 m[{z+c+y*d,x}]=1;
                }
           }
           x=(n/3);
           y=n%3;
           if(m[{z+b+y*d,x}]==0){
                pq.push({z+b+y*d,x});
                 m[{z+b+y*d,x}]=1;
                }
          
           if(y!=0){
               x++;
               y=3*x-n;
                if(m[{z+b+y*d,x}]==0){
                pq.push({z+b+y*d,x});
                 m[{z+b+y*d,x}]=1;
                }
           }
           x=(n/2);
           y=n%2;
           if(m[{z+a+y*d,x}]==0){
                pq.push({z+a+y*d,x});
                 m[{z+a+y*d,x}]=1;
                }
        
           if(y!=0){
               x++;
               y=2*x-n;
               if(  m[{z+a+y*d,x}]==0)
               pq.push({z+a+y*d,x});
                 m[{z+a+y*d,x}]=1;
           }
           if(m[{z+n*d,(ll)0}]==0){
           pq.push({z+n*d,(ll)0});
           m[{z+n*d,(ll)0}]=1;
           }
       }

      cout<<pq.top().F<<"\n";
       
   }
      
}    

Measured memory_bytes: 13864
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];
    let p = read_as_vec::<u32>();

    let mut ans = 0;
    for i in 0..n-2{
        if ((p[i] < p[i+1]) && (p[i+1] < p[i+2])) || ((p[i] > p[i+1]) && (p[i+1] > p[i+2])){
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#define MAX 1000001
#define INF 20000000

typedef struct{
  int A;
  char C;
}Card;


Card A[MAX];
Card B[MAX];

Card L[MAX/2+2],R[MAX/2+2];

void quickSort(int,int);
int partition(int,int);

void merge(int,int,int,int);
void mergeSort(int,int,int);

int main(){
  int i;
  int n;
  int c;
  int flag=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%c",&c);
    scanf("%c%d",&A[i].C,&A[i].A);
    B[i].A=A[i].A;
    B[i].C=A[i].C;
  }

  quickSort(0,n-1);
  mergeSort(n,0,n);
  
  for(i=0;i<n;i++){
    if(B[i].A==A[i].A&&B[i].C!=A[i].C){
      flag=0;
      break;
    }
  }

  if(flag==1)printf("Stable\n");
  else if(flag==0)printf("Not stable\n");

  for(i=0;i<n;i++)printf("%c %d\n",A[i].C,A[i].A);
  return 0;
}

int partition(int p,int r){
  int i,j;
  int x;
  Card t;

  x=A[r].A;
  i=p-1;
  
  for(j=p;j<r;j++){
    if(x>=A[j].A){
      t=A[j];
      A[j]=A[i+1];
      A[i+1]=t;
      i++;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
 
  return i+1;
}

void quickSort(int p,int r){
  int q;
  
  if(p<r){
    q=partition(p,r);
    quickSort(p,q-1);
    quickSort(q+1,r);
  }
}

void merge(int n,int left,int mid,int right){
  int i,j,k;
  int n1;
  int n2;

  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++) L[i]=B[left+i];
  for(i=0;i<n2;i++) R[i]=B[mid+i];

  L[n1].A=INF;
  R[n2].A=INF;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i].A<=R[j].A){
      B[k]=L[i];
      i++;
    }else{
      B[k]=R[j];
      j++;
    }
  }
}

void mergeSort(int n,int left,int right){
  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(n,left,mid);
    mergeSort(n,mid,right);
    merge(n,left,mid,right);
  }
}


Measured memory_bytes: 4076
//author:ynymxiaolongbao
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<stack>
#include<fstream>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pair<ll,ll> >plll;
typedef pair<pair<ll,ll>,pair<ll,ll> >pllll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mp make_pair
pll mpll(ll a,ll b){return mp(a,b);}
plll mplll(ll a,ll b,ll c){return mp(a,mp(b,c));}
pllll mpllll(ll a,ll b,ll c,ll d){return mp(mp(a,b),mp(c,d));}
#define inf 4e18

//mod↓
#define mod 1000000007
#define pl(a,b) a=(a+b)%mod;
ll powmod(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define FAC 1000010
ll fac[FAC],ivf[FAC],inv[FAC];
void initfac(){
	fac[0]=ivf[0]=inv[1]=1;
	for(ll i=1;i<FAC;i++){
		if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
		ivf[i]=ivf[i-1]*inv[i]%mod;
		fac[i]=fac[i-1]*i%mod;
	}
}
ll Pmod(ll n,ll k){
	if(n<k)return 0;
	if(k<0)return 0;
	return fac[n]*ivf[n-k]%mod;
}
ll Cmod(ll n,ll k){
	if(n<k)return 0;
	if(k<0)return 0;
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
//mod↑

class UnionFind{
	public:
	int n,*dat;
	int comp;
	void init(int N){
		n=N;
		dat=new int[n];
		rep(i,n)dat[i]=-1;
		comp=n;
	}
	int par(int x){
		if(dat[x]<0)return x;
		return par(dat[x]);
	}
	void unite(int a,int b){
		a=par(a),b=par(b);
		if(a==b)return;
		if(-dat[a]<-dat[b])swap(a,b);
		dat[a]+=dat[b];
		dat[b]=a;
		comp--;
	}
	bool same(int a,int b){
		a=par(a),b=par(b);
		return a==b;
	}
	int size(int a){
		a=par(a);
		return -dat[a];
	}
};
class Dijkstra{
	public:
	int n;
	ll *dist,*pre;
	vector<int> *to;
	vector<ll> *len;
	void init(int N){
		n=N;
		dist=new ll[n];
		pre=new ll[n];
		to=new vector<int>[n];
		len=new vector<ll>[n];
	}
	void aed(int a,int b,ll c){
		to[a].push_back(b);
		len[a].push_back(c);
	}
	void aeud(int a,int b,ll c){
		aed(a,b,c);
		aed(b,a,c);
	}
	void work(int s){
		rep(i,n)dist[i]=inf;
		priority_queue<plll,vector<plll>,greater<plll> > Q;
		Q.push(mplll(0,s,-1));
		while(!Q.empty()){
			ll cost=Q.top().first;
			ll x=Q.top().second.first;
			ll from=Q.top().second.second;
			Q.pop();
			if(dist[x]<=cost)continue;
			dist[x]=cost;
			pre[x]=from;
			rep(i,to[x].size()){
				Q.push(mplll(cost+len[x][i],to[x][i],x));
			}
		}
	}
};

#define ARR 500010
int v,e,r;
int s[ARR],t[ARR],d[ARR];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>v>>e>>r;
	Dijkstra dijk;
	dijk.init(v);
	rep(i,e){
		cin>>s[i]>>t[i]>>d[i];
		dijk.aed(s[i],t[i],d[i]);
	}
	dijk.work(r);
	rep(i,v){
		ll res=dijk.dist[i];
		if(res==inf)cout<<"INF\n";
		else cout<<res<<"\n";
	}
}



Measured memory_bytes: 31472
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string o,e;
    cin >> o >> e;
    string ans = "";
    int so = (int)o.size();
    int se = (int)e.size();
    int ie=0;
    int io=0;
    REP(i,so+se){
        if(i%2==1){
            ans+={e[ie]};
            ie++;
        }else{
            ans+={o[io]};
            io++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from math import gcd
from collections import defaultdict
MOD = 10**9+7
n = int(input())
cnt = defaultdict(lambda: [0, 0])
zeros = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == b == 0:
        zeros += 1
        continue
    if a < 0 or (a == 0 and b < 0):
        a *= -1
        b *= -1
    g = gcd(a, b)
    a //= g
    b //= g
    if b > 0:
        cnt[(a, b)][0] += 1
    else:
        cnt[(-b, a)][1] += 1

ans = 1
for v, v2 in cnt.values():
    ans *= 1+pow(2, v, MOD)-1+pow(2, v2, MOD)-1
    ans %= MOD
ans = (ans+zeros-1) % MOD
print(ans)


Measured memory_bytes: 60744
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

if n >= m:
    print(0)
else:
    x_sub = []
    for i in range(m-1):
        x_sub.append(x[i+1] - x[i])
    x_sub = sorted(x_sub)
    print(sum(x_sub[:m-n]))

Measured memory_bytes: 13960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int n; cin >> n;
	for(int i=1;i<=10000;i++){
		if(n < i*100) continue;
		int zan = n-i*100;
		if(zan <= 5*i){
			cout << 1 << endl; return 0;
		}
	}
	cout<<0<<endl;
}


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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

int multiple(int k){
    int mul = 0;
    do {
        mul += k % 10;
        k /= 10;
    } while(k != 0);
    return mul;
}

void solve()
{
    int k;
    cin >> k;
    vector<bool> flag(k, false);
    deque<pair<int, int>> dq;
    dq.push_back(make_pair(1, 1));
    while(!dq.empty()){
        auto p = dq.front();
        dq.pop_front();
        int node = p.first;
        int dis = p.second;
        if(flag[node]) continue;
        flag[node] = true;
        if(node == 0) {
            cout << dis << endl;
            return;
        }
        dq.push_back(make_pair((node+1) % k, dis+1));
        dq.push_front(make_pair(node*10%k, dis));
    }

}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1024
class BinaryIndexedTree(object):
    def __init__(self, N):
        self.N = N
        self.bit = [0] * (N + 1)

    def bit_add(self, index, num):
        while (index <= self.N):
            self.bit[index] += num
            index += index & -index
        return

    def bit_sum(self,index):
        result = 0
        while (index > 0):
            result += self.bit[index]
            index -= index & -index
        return result

    def bit_sum_range(self, l, r):
        if (l == r):
            return 1
        else:
            return self.bit_sum(r) - self.bit_sum(l - 1)

def main():
    from sys import stdin
    N, Q = list(map(int, input().split()))
    c = list(map(int, input().split()))
    readline = stdin.readline
    query = [list(map(int, readline().split())) + [i] for i in range(Q)]
    query_result = [0 for i in range(Q)]
    collar_pos = [-1] * (N + 1)
    bit = BinaryIndexedTree(N)

    sorted_query = sorted(query, key=lambda query: query[1])

    index = 1
    for query in sorted_query:
        l, r, q = query
        while (index <= r):
            # update BIT
            if (collar_pos[c[index-1]] != -1):
                bit.bit_add(collar_pos[c[index-1]], -1)
            bit.bit_add(index, 1)
            # update collar_pos
            collar_pos[c[index-1]] = index
            index += 1
        query_result[q] = bit.bit_sum_range(l, r)

    print(*query_result, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 243304
# -*- coding: utf-8 -*-
import sys
def formula(num):
    if (int(num) % 2 == 1):
        return int(3*num + 1)
    else:
        return int(num / 2)

s = int(input())
nums = [s]

n = formula(s)
while(True):
    if ( n in nums ):
        print(len(nums) + 1)
        sys.exit(0)
    nums.append(n)
    n = formula(n)

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

#define task "M"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 101, mod = 1e9 + 7;
int n, k, dp[2][100002];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> k;
    int now = 1, lst = 0;
    rep(i, 0, k) dp[now][i] = 1;
    rep(i, 1, n)
    {
        int a;
        cin >> a;
        swap(now, lst);
        dp[now][0] = dp[lst][0];
        rep(j, 1, k) dp[now][j] = ((dp[now][j - 1] + (dp[lst][j] - (((j - a - 1) >= 0) ? dp[lst][j - a - 1] : 0))) % mod + mod) % mod;
    }
    cout << (dp[now][k] - dp[now][k - 1] + mod) % mod;
    return 0;
}


Measured memory_bytes: 4408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005; 
int main ( ){
fast_io();
string s ;
cin >> s ;
int q ;
cin >> q ;
string front,back ; 
bool state = false ;
int cnt = 0; 
while (q-- ){
int t ;
cin >> t ;

if ( t == 2 ){
	
	int f ;
	char c ;
	cin >> f >> c ;
	if (!state){
		if (f==1)
			front+=c ;
		else
			back +=c ; 
	}
	else
	{		if (f!=1)
			front+=c ;
			else
			back +=c ; 	
	} 


}
else
	state = state^1 ,++cnt  ; 




}


reverse(all(front));
front += s ;
front += back ;
if (cnt % 2 )
reverse(all(front)); 
cout << front ;
br

return 0 ;
 
}


Measured memory_bytes: 1300
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
Alice = 0
Bob = 0
for i in range(0, len(a), 2):
    Alice += a[i]
    if i + 1 < len(a):
        Bob += a[i + 1]
print(Alice - Bob)


Measured memory_bytes: 3060
import math
n, x = list(map(int, input().split())) # 整数
array = list(map(int, input().strip().split()))
array.sort()
ans = 0
l = len(array)
for i in array:
    l -= 1
    x = x-i
    if l == 0:
        if x != 0:
            break
            
    if x < 0:
        break
    ans += 1
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N;
ll x, y;

int main()
{
	cin >> N;
	cin >> x >> y;
	for(int i=1; i<N;++i){
		ll p, q;
		cin >> p >> q;
		ll n = max((x+p-1)/p, (y+q-1)/q);
		x = n*p;
		y = n*q;
	}
	cout << x + y << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int A[1000];
  int N,count;
  scanf("%d",&N);
  for (int i = 0;i<N;i++){
    scanf("%d",&A[i]);
  }
  sort(A,A+N);
  for(int j = 0;j < N;j++){
    if(A[j]!=A[j+1]){
      count += 1;
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 256
combi = []
for i in range(0, 51):
	combi.append(0)

for a in range(0, 10):
	for b in range(0, 10):
		for c in range(0, 10):
			for d in range(0, 10):
				combi[a+b+c+d] += 1

while True:
	try:
		n = int(raw_input())
		print combi[n]
	except:
		break

Measured memory_bytes: 6240