akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ll n, k;
  cin >> n >> k;
  vector< ll > a(n);
  for (ll i=0; i<n; ++i) cin >> a[i];
  unordered_map< ll, ll > near;
  vector< ll > cstartidx(n+1, n);
  //cstartidx[n-1] = n-1;
  //near[a[n-1]] = n-1;
  for (ll i=n-1; i>=0; --i) {
    if (near.count(a[i]) > 0) {
      cstartidx[i] = cstartidx[near[a[i]]+1];
    } else cstartidx[i] = i;
    //cerr << cstartidx[i] << " ";
    near[a[i]] = i;
  }
  //cerr << endl;
  vector< ll > nstartidx(n);
  for (ll i=0; i<n; ++i) {
    if (cstartidx[i]==n) nstartidx[i] = n;
    else nstartidx[i] = (cstartidx[near[a[cstartidx[i]]]+1]);
    //cerr << nstartidx[i] << " ";
  }
  //cerr << endl;
  ul start = 0;
  vector< ll > v(n+1, -1);
  bool l_flg = false;
  for (ll i=0; i<k-1; ++i) {
    if (start == n) {
      k -= (k-2-i)/(i+1)*(i+1);
      start = 0;
      continue;
    }
    v[start] = i;
    /*
    if (!l_flg)
      cerr << i << " " << start << endl;
      */
    start = nstartidx[start];
    if (!l_flg) {
      if (v[start] >= 0) {
        l_flg = true;
        k -= (k-2-i)/(i+1-v[start])*(i+1-v[start]);
        //cerr << start << ":" << v[start] << " " << i << endl;
      }
    }
  }
  vector< ll > s;
  unordered_map< ll, ll > cnt;
  for (ll i=start; i<n; ++i) {
    if (cnt.count(a[i]) == 0 || cnt[a[i]] == 0) {
      s.push_back(a[i]);
      cnt[a[i]] = 1;
    } else {
      while (cnt[a[i]] > 0) {
        cnt[s[s.size()-1]]--;
        s.pop_back();
      }
    }
  }
  if (s.size() == 0) return 0;
  for (ll i=0; i<s.size(); ++i) cout << s[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 25872
# include <iostream>
# include <string>
# include <set>
using namespace std;
int main(void)
{
	int n;
	set<string> a;
	string str,s;
	scanf("%d",&n);
	while(n--)
	{
		cin>>str>>s;
		if(str == "insert") a.insert(s);
		else 
		{
			if(a.find(s) == a.end()) printf("no\n");
			else printf("yes\n");
		}
	}
	return 0;
}


Measured memory_bytes: 32604
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int[][] a = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = scanner.nextInt();
            }
        }

        int[] x = new int[h * w];
        int[] y = new int[h * w];

        for (int i = 0; i < h; i++) {
            Arrays.fill(x, i * w, i * w + w, i);
            for (int j = 0; j < w; j++) {
                y[i * w + j] = i % 2 == 0 ? j : w - j - 1;
            }
        }

        List<Integer> ans = new ArrayList<>();

        for (int i = 0; i < h * w - 1; i++) {
            if (a[x[i]][y[i]] % 2 == 1) {
                ans.add(i);
                a[x[i + 1]][y[i + 1]]++;
            }
        }

        System.out.println(ans.size());
        for (int i : ans) {
            System.out.println((x[i] + 1) + " " + (y[i] + 1) + " " + (x[i + 1] + 1) + " " + (y[i + 1] + 1));
        }
    }
}

Measured memory_bytes: 102904
// 2020-08-23 16:10:26
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

ll dp[60][3000], p[60][3000];
void answer() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  dp[0][0] = 1;
  rep(i, n) {
    swap(dp, p);
    memset(dp, 0, sizeof dp);
    repc(j, i) repc(k, j*50) {
      dp[j][k] += p[j][k];
      dp[j+1][k+x[i]] += p[j][k];
    }
  }
  ll ans = 0;
  REPC(i, 1, n) ans += dp[i][a*i];
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main(){
	long long int s = 0, n;
	cin >> n;
	long long int a[n], b[n], c[n], d[n], e[n];
	bool flag = true;
	for(int j = 0; j < n; j++){
		cin >> a[j];
	}
	for(int j = 0; j < n; j++){
		cin >> b[j];
	}
	for(int j = 0; j < n; j++){
		cin >> c[j];
	}
	for(int j = 0; j < n; j++){
		d[j] = 0;
		e[j] = 0;
	}
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	int p = 0;
	for(int i = 0; i < n; i++){
		flag = true;
		if(i > 0){
			d[i] = d[i - 1];
		}
		for(int j = p; j < n; j++){
			if(b[i] > a[j]){
				d[i] += 1;
			}else{
				p = j;
				flag = false;
				break;
			}
		}
		if(flag) p = n;
	}
	p = 0;
	for(int i = 0; i < n; i++){
		flag = true;
		if(i > 0){
			e[i] = e[i - 1];
		}
		for(int j = p; j < n; j++){
			if(c[i] > b[j]){
				e[i] += d[j];
			}else{
				p = j;
				flag = false;
				break;
			}
		}
		if(flag) p = n;
		s += e[i];
	}
	cout << s << endl;
	return 0;
}

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

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

using namespace std;

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

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  vi32 history(n);
  int ans = 0;
  rep(i, n) {
    if (i - k >= 0) {
      if (history[i - k] == 1 && t[i] == 's') continue;
      if (history[i - k] == 2 && t[i] == 'p') continue;
      if (history[i - k] == 3 && t[i] == 'r') continue;
    }
    if (t[i] == 'r') {
      ans += p;
      history[i] = 3;
    }
    if (t[i] == 's') {
      ans += r;
      history[i] = 1;
    }
    if (t[i] == 'p') {
      ans += s;
      history[i] = 2;
    }
  }
  cout << ans << endl;
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int a,b;
  cin >> a >> b;
  if((a*b) % 2 == 1){
    cout << "Odd" << endl;
  }else{
    cout <<"Even" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  string s, t; cin >> s >> t;
  int a, b; cin >> a >> b;
  string u; cin >> u;
  if (u == s) --a;
  if (u == t) --b;
  cout
    << a << SPACE
    << b << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//環境で固定された変数を宣言
#define IN 200000
#define INPUTSIZE IN+2

int main() {
	//変数宣言
	int i, j;
	char Sin[INPUTSIZE], Tin[INPUTSIZE];
	char c;
	
	//入力受付
	fgets(Sin, INPUTSIZE, stdin);
	fgets(Tin, INPUTSIZE, stdin);
	int size = strlen(Sin);

	//文字列交換
	for (i = 0; i < size; i++) {
		if (Sin[i] != Tin[i]) {
			c = Sin[i];
			for (j = 0; j < size; j++) {
				if (Sin[j] == c || Sin[j] == Tin[i]) {
					if (j < i) goto MyEndFlag;
					if (Sin[j] == c) Sin[j] = Tin[i];
					else if(Sin[j] == Tin[i]) Sin[j] = c;
					//if (j <= i && Sin[j] != Tin[j]) {
					//	//終了タグに強制移動
					//	goto MyEndFlag;
					//}
				}
			}
		}
	}
	//プログラムの終了
	MyEndFlag:
	printf(i == size ? "Yes\n":"No\n");
	return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func main() {
	sc := NewScanner()

	X := sc.NextInt()

	k := 3

	i := 0
	for i = 0; i < X; i++ {
		k = k * 2 + 1
	}
	
	fmt.Println(k - 1)

}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	for b > 0 {
		a, b = b, a % b
	}
	return a
}

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

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}




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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

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

    vector<vector<int>> v(10, vector<int>(10, 0));
    for (int x = 1; x <= n; x++) {
        int left = x / (pow(10, to_string(x).size() - 1)), right = x % 10;
        dd(left, right);
        v[left][right]++;
    }
    // (A,B)
    int ans = 0;
    for (int x = 1; x <= n; x++) {
        int left = x / (pow(10, to_string(x).size() - 1)), right = x % 10;
        ans = (ans + (v[right][left] % MOD)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		
		System.out.println("A" + b.substring(0, 1)+ "C");
	}
 
}

Measured memory_bytes: 21588
int main(void) {
    int i,j,H,W;
    
    while (1) {
    scanf("%d",&H);
    scanf("%d",&W);
        if (H==0&&W==0){
            break;
        }
    for (i=0; i<H; i++) {
    for (j=0; j<W; j++) {
        printf("#");
    }
    printf("\n");
    }
        printf("\n");
    }
    return 0;
}

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

int main(void){
    int K;
    cin>>K;
    int result;
    if(K%2==0){
        result = (K/2) * (K/2);
        cout<<result<<endl;
    }else{
        result = (K/2) * ((K+1)/2);
        cout<<result<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

lli ac[MAXN][3], dp[MAXN][3];
lli n;

lli f(lli x, lli option) {
    if (x > n) return 0;
    if (dp[x][option] != -1) return dp[x][option];

    lli ans = 0;
    for (int i = 0; i < 3; ++i) {
        if (i == option) continue;
        ans = max(ans, ac[x][i] + f(x + 1, i));
    }
    return dp[x][option] = ans;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> ac[i][j];
        }
    }

    memset(dp, -1, sizeof(dp));
    lli ans = max(ac[1][0] + f(2, 0), max(ac[1][1] + f(2, 1), ac[1][2] + f(2, 2)));
    cout << ans << endl;
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;

    solve();

    return 0;
}

Measured memory_bytes: 12800
S = input()


def main(s):
    l = len(s)

    left = s[:int((l - 1) / 2)]
    right = s[int((l + 3) / 2) - 1:l]

    s_rev = ''.join(list(reversed(s)))
    left_rev = ''.join(list(reversed(left)))
    right_rev = ''.join(list(reversed(right)))

    if s == s_rev and left == left_rev and right == right_rev and ( 3 <= l <= 99 ):
        res = 'Yes'
    else:
        res = 'No'
    return res


print(main(S))


Measured memory_bytes: 3064
#include <stdio.h>

int main() {
    int X, Y, Z;
    scanf("%d %d %d", &X, &Y, &Z);
    int n = X / (Y + Z);
    if (X % (Y + Z) < Z) {
        printf("%d\n", n - 1);
    } else {
        printf("%d\n", n);
    }
    return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;

int n, d;
int a[maxn];
ll ans;

int main(){
	scanf("%d%d", &n, &d);
	FOR(i, 0, n){
		scanf("%d", a + i);
		ans += a[i];
	}
	FOR(i, 1, n)
		a[i] = min(a[i], a[i - 1] + d);
	for(int i = n - 2; i >= 0; --i)
		a[i] = min(a[i], a[i + 1] + d);
	FOR(i, 1, n - 1)
		ans += a[i];
	ans += 1ll * d * (n - 1);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
n,m = map(int,input().split())

d = [False for _ in range(n)]
w = 0
a = 0
for i in range(m):
    P,S = input().split()
    P = int(P)
    if(S == 'WA'):
        if(d[P-1] >= 0):d[P-1] += 1
    elif(S == 'AC'):
        if(d[P-1] >= 0):
            a += 1
            w += d[P-1]
            d[P-1] = -1

print(a,w)


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

bool isRegistered(string id, vector<string>::iterator registered_id_begin, vector<string>::iterator registered_id_end){

  for(vector<string>::iterator i = registered_id_begin; i != registered_id_end; i++){
    if(id == *i)
      return true;
  }
  return false;
}

int main(void){
  int N;
  cin >> N;
  vector<string> registered_id;
  for(int i=0; i < N; i++){
    string tmp; cin >> tmp;
    registered_id.push_back(tmp);
  }
  int M;
  cin >> M;
  vector<string> touched_id;
  for(int i=0; i < M; i++){
    string tmp; cin >> tmp;
    touched_id.push_back(tmp);
  }

  bool locked = true;
  for(int i=0; i < M; i++){
    if(isRegistered(touched_id[i], registered_id.begin(), registered_id.end())){
      if(locked){
	cout << "Opened by " << touched_id[i] << endl;
	locked = false;
      }else{
	cout << "Closed by " << touched_id[i] << endl;
	locked = true;
      }
    }else{
      cout << "Unknown " << touched_id[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=305;
int n,m,mod,C[N][N],f[N][N],g[N][N];
int main(){
	scanf("%d%d%d",&n,&m,&mod);++n;++m;
	for(int i=C[0][0]=1;i<=n;++i)
		for(int j=C[i][0];j<=i;++j)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	for(int i=1;i<=m;++i)f[1][i]=1,g[1][i]=i;
	for(int i=2;i<=n;++i)
		for(int j=1;j<=m;++j){
			for(int k=1;k<i;++k)
				f[i][j]=(f[i][j]+1ll*g[k][j-1]*f[i-k][j]%mod*C[i-2][k-1])%mod;
			g[i][j]=(g[i][j-1]+f[i][j])%mod;
		}
	printf("%d\n",f[n][m]);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, t;
    cin >> n >> t;
    vector<ll> v(n);
    for(auto& i : v) cin >> i;

    ll bottom = INF, profit = 0, ans = 0;

    REP(i, n){
        if(v[i] - bottom > profit){
            profit = v[i] - bottom;
            ans = 1;
        }else if(v[i] - bottom == profit){
            ans++;
        }
        bottom = min(bottom, v[i]);
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
ll n,m,k;
cin >> n>>m>>k;
COMinit();
ll ni=COM(n*m-2,k-2);
ll sumx=0;
rep(i,n){
    sumx+=(n-i)*m*m*i;
    sumx%=mo;
}
ll sumy=0;
rep(i,m){
    sumy+=(m-i)*n*n*i;
    sumy%=mo;
}
ans=ni*(sumx+sumy);
ans%=mo;

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

Measured memory_bytes: 12160
from itertools import product
n=int(input())
num_list=['7','5','3']
c=0
for j in range(1,10):
    for i in (product(num_list,repeat=j)):
        check=i.count('7')*i.count('3')*i.count('5')
        if int(''.join(i))<=n and check:
            c+=1
print(c)

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

using namespace std;

int main() {
  string s; cin >> s;
  int a=0,b=0,c=0;
  for(int i=0;i<s.size();++i)
    if(s[i]=='A') a++;
    else if(s[i]=='B') b++;
    else c++;
  while(s.size()>3) {
    int tmp=0;
    int gene;
    int mini=min({a,b,c});
    int cnt=0;
    if(mini==a) gene=0,cnt++;
    if(mini==b) gene=1,cnt++;
    if(mini==c) gene=2,cnt++;
    if(cnt>1) break;
    for(int i=0;i<s.size();++i) {
      if(i+2<s.size()&&s.substr(i,3)=="ABC") {
        s=s.substr(0,i)+(char)(gene+'A')+s.substr(i+3,s.size()-(i+3));
        tmp++;
      }
    }
    if(tmp==0) break;
    a-=tmp; b-=tmp; c-=tmp;
    (gene==0?a:(gene==1?b:c))+=tmp;
  }
  if(s=="ABC") cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

int main()
{
    double x1,x2,y1,y2,ans;
    cin>>x1>>y1>>x2>>y2;
    ans = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);

    printf("%f\n", sqrt(ans));
}



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

using namespace std;

int main(void)
{
	int dayNum[13]={
		0,31,29,31,30,31,30,31,31,30,31,30,31
	};
	string youbi[7]={
		"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"
	};
	int manth,day;
	while(cin>>manth>>day)
	{
		if(manth==0)
		{
			break;
		}
		int sum=0;
		for(int i=0;i<manth;i++)
		{
			sum+=dayNum[i];
		}
		sum+=day;
		cout<<youbi[sum%7]<<endl;
	}
}

Measured memory_bytes: 1196
#include <stdio.h>

typedef long long int llint;

#define DEEP 20

llint seg1[(1 << (DEEP + 1))];
llint seg2[(1 << (DEEP + 1))];

llint gcd(llint a,llint b)
{
	if(a % b == 0)
	{
		return b;
	}
	return gcd(b,a % b);
}

llint sai(llint a,llint b)
{
	return a / gcd(a,b) * b;
}

llint d[111111];

#define mod 1000000007

int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i = 0; i < n; i++)
	{
		llint w;
		scanf("%lld",&w);
		d[i] = w - 1;
	}
	for(int i = 0; i < n; i++)
	{
		llint w;
		llint all;
		if(d[i] == i)
		{
			w = 1;
			all = d[i] + 1;
		}
		else
		{
			llint now = i;
			all = now + 1;
			for(int ii = 1; ii <= 50; ii++)
			{
				now = d[now];
				if(now == i)
				{
					w = ii;
					break;
				}
				all += now + 1;
			}
		}
		seg1[(1 << DEEP) - 1 + i] = w;
		seg2[(1 << DEEP) - 1 + i] = all % mod;
	}
	for(int i = n; i < (1 << DEEP); i++)
	{
		seg1[(1 << DEEP) - 1 + i] = 1;
		seg2[(1 << DEEP) - 1 + i] = 0;
	}
	for(int i = (1 << DEEP) - 2; i >= 0; i--)
	{
		seg1[i] = sai(seg1[i * 2 + 1],seg1[i * 2 + 2]);
		seg2[i] = ((seg1[i] / seg1[i * 2 + 1]) % mod * seg2[i * 2 + 1] % mod + (seg1[i] / seg1[i * 2 + 2]) % mod * seg2[i * 2 + 2] % mod) % mod;
	}
	for(int k = 0; k < q; k++)
	{
		llint a,b;
		scanf("%lld%lld",&a,&b);
		llint now1 = (1 << DEEP) + a - 2;
		llint now2 = (1 << DEEP) + b - 2;
		if(now1 != now2)
		{
			llint gc1 = seg1[now1];
			llint k1 = seg2[now1];
			llint gc2 = seg1[now2];
			llint k2 = seg2[now2];
			while(now1 != now2)
			{
				llint o1 = (now1 - 1) / 2;
				llint o2 = (now2 - 1) / 2;
				if(o1 == o2)
				{
					break;
				}
				if(now1 % 2 == 1)
				{
					llint gc = sai(gc1,seg1[now1 + 1]);
					k1 = ((gc / gc1) % mod * k1 % mod + (gc / seg1[now1 + 1]) % mod * seg2[now1 + 1] % mod) % mod;
					gc1 = gc;
				}
				if(now2 % 2 == 0)
				{
					llint gc = sai(gc2,seg1[now2 - 1]);
					k2 = ((gc / gc2) % mod * k2 % mod + (gc / seg1[now2 - 1]) % mod * seg2[now2 - 1] % mod) % mod;
					gc2 = gc;
				}
				now1 = o1;
				now2 = o2;
			}
			llint w = sai(gc1,gc2);
			llint wq = ((w / gc1) % mod * k1 % mod + (w / gc2) % mod * k2 % mod) % mod;
			printf("%lld\n",wq);
		}
		else
		{
			printf("%lld\n",seg2[now1]);
		}
	}
	return 0;
}

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

#define A 2000001
#define B 10000

int main(){
  unsigned short *m,*n;
  int S[B+1],q,i,j;

  scanf("%d",&q);

  m = malloc(sizeof(short)*q+1);
  n = malloc(sizeof(short)*q+1);

  for(i=0;i<=B;i++){
    S[i]=0;
  }

  for(i=0;i<q;i++){
    scanf("%hu",&m[i+1]);
    S[ m[i+1] ]++;
  }

  for(i=1;i<=B;i++){
    S[i]= S[i]+S[i-1];
  }

  for(j=1;j<=q;j++){
    n[ S[ m[j] ] ] = m[j];
    S[ m[j] ]--;
  }

  for(i=1;i<=q;i++){
    if(i>1) printf(" ");
    printf("%d",n[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 9620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF 1LL<<60

using namespace std;

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

ll calc(vector<int> A, ll b){
	int N = (int)A.size();
	ll res = 0LL;
	rep (i, N){
		res += abs((ll)A[i] - b);
	} // end rep
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> A(N, 0);
	rep (i, N) cin >> A[i];
	
	rep (i, N){
		A[i] -= (i + 1);
	} // end rep

	ll lo = -(ll)1e9;
	ll hi = (ll)1e9;

	ll res = INF;
	int cnt = 0;
	while(lo < hi && cnt < 50){
		ll mid1 = (2LL * lo + hi) / 3LL;
		ll mid2 = (lo + 2LL * hi) / 3LL;
		ll curr1 = calc(A, mid1);
		ll curr2 = calc(A, mid2);
		if (curr1 > curr2){
			lo = mid1;
			res = min(res, curr2);
		}else{
			hi = mid2;
			res = min(res, curr1);
		} // end if
		++cnt;
	} // end while
	
	cout << res << endl;
			
	return 0;
}

Measured memory_bytes: 1800
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	if (v[N - 1] > 2) {
		cout << -1 << endl;
		return 0;
	}
	R = v[N - 1] + 1;
	L = 2;
	for (int i = N - 2; i >= 0; i--) {
		if (R < v[i]) {
			cout << "-1\n";
			return 0;
		}
		R = (R / v[i] + 1)*v[i] - 1;
		L = (L / v[i] + !!(L % v[i]))*v[i];
	}
	if (L > R) {
		cout << -1 << endl;
		return 0;
	}
	cout << L << " " << R << endl;
	return 0;
}

Measured memory_bytes: 1024
from fractions import gcd
#input
N = int(input())
A = [int(i) for i in input().split()]
#cluc left and right gcd 
left = [0]*N
right = [0]*N
count = 0
left[0] = A[0]
right[-1] = A[-1]
Ans = []

for i in A[1:]:
    left[count+1] = gcd(left[count],i)
    count += 1

for i in reversed(A[:-1]):
    right[count-1] = gcd(right[count],i)
    count -= 1
# make ans
Ans.append(right[1])
Ans.append(left[-2])
for i in range(N-2):
    Ans.append(gcd(left[i],right[i+2]))
print(max(Ans))

Measured memory_bytes: 16136
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N,border=0,H[100000],Highest=0;
    cin >>N;
    for(int i=0;i<N;i++){
        cin >>H[i];
    }
    for(int i=0;i<N-2;i++){
        if(H[i+1]-H[i]>1&&border<H[i+1]){
            border=H[i+1]-1;
        }
        if(H[i]>Highest){
            Highest=H[i]-1;
        }
        if(H[i+2]<border||Highest>H[i]){
            cout <<"No";
            return 0;
        }
    }
    cout <<"Yes";
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

long long sum(long long a, long long b) {
	return (a + b) % 1000000007;
}

int main(void) {
	long long a[65][3];
	long long N,M;
	int i,j,p[64];
	long long ans;
	scanf("%lld", &N);
	M = N;
	for (i = 0; i < 64; i++) {
		p[63 - i] = M % 2;
		M = M / 2;
	}

	a[0][0] = 1; 
	a[0][1] = 0;
	a[0][2] = 0;
	for (i = 1; i < 65; i++) {
		if (p[i-1] == 0) {
			a[i][2] = (3*a[i - 1][2]+ a[i - 1][1]) % 1000000007;
			a[i][1] = a[i - 1][1];
			a[i][0] = (a[i - 1][0]+ a[i - 1][1]) % 1000000007;
		}
		else {
			a[i][2] = (3 * a[i - 1][2] + a[i - 1][1] + a[i - 1][1]) % 1000000007;
			a[i][1] = (a[i - 1][1]+ a[i - 1][0]) % 1000000007;
			a[i][0] = a[i - 1][0];
		}
		/*printf("p[%d] = %d, a[%d][0] = %lld\n	", i, p[i], i, a[i][0]);*/
	}

	ans = 0;
	ans = (a[64][0] + a[64][1] + a[64][2]) % 1000000007;

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



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<deque>
#include<cctype>
using namespace std;
int main() 
{
	int a,b,c;
	cin>>a>>b>>c;
	int d=a-b;
	int e=d/c;
	int f=e*c;
	int ans=d-f;
	cout<<ans;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    vector<vector<ll> > dp(n+1, vector<ll> (13, 0));
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        if(s[i] == '?'){
            for(int j=0;j<13;j++){
                for(int num = 0; num < 10;num++)
                    (dp[i+1][(j*10+num) % 13] += dp[i][j]) %= mod;
            }
        }else{
            ll num = s[i] - '0';
            for(int j=0;j<13;j++){
                (dp[i+1][(j*10+num) % 13] += dp[i][j]) %= mod;
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 16604
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	if _, err := fmt.Scan(&a, &b, &c); err != nil {
		panic(err)
	}

	nDivisor := 0
	for i := a; i <= b; i++ {
		if c % i == 0 {
			nDivisor++
		}
	}

	fmt.Println(nDivisor)
}



Measured memory_bytes: 1184
#include <stdio.h>
int main(void)
{
	int r;
	int d;
	int first;
	scanf("%d %d %d",&r,&d,&first);
	for(int i=0;i<10;i++)
	{
		long long int x = r*first - d;
		printf("%lld\n",x);
		first = x;
	}
	return 0;
}


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

int main(){
  string S;
  cin >> S;
  bool A=false;
  for(char C='a';C<='z';C++){
    int count=0;
    for(int i=0;i<S.size();i++){
      if(S.at(i)==C){
        count++;
      }
    }
    if(count%2==1){
      A=true;
      break;
    }
  }
  if(!A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
def pfn(N):
    factor=[]
    N=int(N)
    if N==1:
        return []
    else:
        for num in range(2, N+1):
            while N % num==0:
                N //=num
                factor.append(num)
        return factor
            
N=int(input())
factor=[]
for i in range(1, N+1):
    factor+=pfn(i)
    
p=1
factor_set=list(set(factor))
for x in factor_set:
    p*=factor.count(x)+1
    
print(p%(10**9+7))

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}
int co[N];
int main()
{
  int n;
  cin>>n;
  rep(i, 0, n)
  {
    int a;
    cin>>a;
    co[a]++;
  }
  for(int i=n-1; i>=0; i-=2)
  {
    if(i != 0 && co[i] != 2) {
      cout<<0<<endl;
      return 0;
    }
    if(i == 0 && co[i] != 1)
    {
      cout<<0<<endl;
      return 0;
    }
  }
  llt ans = ppow(2, n / 2);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12416
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
   ll N;
   scanf("%lld",&N);
   ll sum=0;
   ll bmin=100000000000;
   bool flag=false;
   for(ll i=0;i<N;i++){
      ll a,b;
      scanf("%lld%lld",&a,&b);
      sum+=a;
      if(a!=b) flag=true;
      if(a>b&&bmin>b) bmin=b;
   }
   if(flag) printf("%lld\n",sum-bmin);
   else printf("0\n");
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>

#define SIZE 100005
#define MOD 1000000007

using namespace std;

class DModSum {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        long long int ans;
        for (int i = 1; i < n; ++i) {
            ans += i;
        }
        cout << ans << endl;
    }
};


int main() {
    DModSum solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

const int ms = 1e2+9, mw = 1e5+9;
const int inf = 0x3f3f3f3f3f3f3f3f;

int n, w;
int dp[ms][mw], matrix[ms][mw];

int solve(int pos, int W){

  if(W < 0)
    return -inf;

  if(pos == n)
    return 0;

  int &ans = dp[pos][W];
  if(~ans) return ans;

  ans = 0;


  ans = max(solve(pos +1, W), solve(pos+1, W - matrix[pos][0])  + matrix[pos][1]);

  return ans;
}



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

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

  memset(dp, -1, sizeof dp);

  cout<<solve(0, w);
}

Measured memory_bytes: 162432
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;

vector<ll> divisor(ll x){
    vector<ll> res;
    for(int i = 1; (ll)i * i <= x; ++i){
        if(x % i == 0){
            res.push_back(i);
            if(i * i != x)  res.push_back(x / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

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

    int n;
    ll m;
    cin >> n >> m;
    vector<ll> div = divisor(m);
    int sz = div.size();
    ll res = 0;
    ll foo = m / n;
    for(int i = 0; i < sz; ++i){
        if(div[i] <= foo)   chmax(res, div[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
using System;
class main
{
    static void Main(string[] args)
    {
        string s = string.Empty;
        while ((s = Console.ReadLine()) != null)
        {
            string[] s1 = s.Split(' ');
            long[] a = new long[3];
            a[0] = long.Parse(s1[0]);
            a[1] = long.Parse(s1[1]);
            a[2] = 0;
            Array.Sort(a);
            Array.Reverse(a);
            long c = a[0] * a[1];
            if (a[1] != 0)
                while (true)
                {
                    a[2] = a[1];
                    a[1] = a[0] % a[1];
                    a[0] = a[2];
                    if (a[1] == 0)
                    {
                        Console.WriteLine("{0} {1}", a[0], (c / a[0]));
                        break;
                    }
                }
            else
                Console.WriteLine("{0} {1}", a[0], (c / a[0]));
        }
    }
}

Measured memory_bytes: 5724
n = int(input())

P = [(0.0,0.0), (100.0, 0)]

import copy
import math
sin60 = math.sin(math.radians(60))
cos60 = math.cos(math.radians(60))
for _ in range(n):
    next_p = []
    for p1, p2 in zip(P[:-1], P[1:]):
        l = (p1[0]*2/3+p2[0]*1/3, p1[1]*2/3+p2[1]*1/3) 
        r = (p1[0]*1/3+p2[0]*2/3, p1[1]*1/3+p2[1]*2/3)
        x = cos60*(r[0]-l[0])-sin60*(r[1]-l[1])+l[0]
        y = sin60*(r[0]-l[0])+cos60*(r[1]-l[1])+l[1]
        next_p.append(p1)
        next_p.append(l)
        next_p.append((x, y))
        next_p.append(r)
    next_p.append(P[-1])
    P = copy.copy(next_p)

for p in P:
    print(p[0], p[1])
        
    


Measured memory_bytes: 6948
#include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int gcd(int a, int b){
  int r = a % b;
  if(r != 0){
    b = gcd(b, r);
  }
  return b;
}

int main(){
  int a, b;

  while(cin >> a >> b){

    int g = gcd(a, b);

    int lcm = a * (b / g);

    cout << g << " " << lcm << endl;
  }

  return 0;
}

Measured memory_bytes: 3024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int a, b, c;
	
	cin >> a >> b >> c;

	if ((a + b == c) || (a+c == b) || (b + c == a))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())

l=max(L)
r=min(R)
ans=(r+1-l)

if ans<=0:
    print(0)
else:
    print(ans)

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

using namespace std;

const int mod = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  int size = s.size();
  vector<vector<long long>> dp(size + 1, vector<long long>(4, 0));
  dp[0][0] = 1;
  for (int i = 0; i < size; i++)
  {
    if (s[i] == 'A' || s[i] == '?')
      dp[i + 1][1] += (dp[i + 1][1] + dp[i][0]) % mod;
    if (s[i] == 'B' || s[i] == '?')
      dp[i + 1][2] += (dp[i + 1][2] + dp[i][1]) % mod;
    if (s[i] == 'C' || s[i] == '?')
      dp[i + 1][3] += (dp[i + 1][3] + dp[i][2]) % mod;
    for (int j = 0; j < 4; j++)
      dp[i + 1][j] += dp[i][j] * (s[i] == '?' ? 3 : 1) % mod;
  }
  cout << dp[size][3] % mod << endl;

  return 0;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int N,T;
  cin >> N >> T;
  
  bool x = false;
  int cost = 1000;
  int c,t;
  rep(i,N){
    cin >> c >> t;
    if(t<=T){
      cost = min(c, cost);
      x = true;
    }
  }
  
  if(x){
    cout << cost << endl;
  }
  else{
    cout << "TLE" << endl;
  }
}      
       

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

enum {kRabbit = 0, kCat};
enum {kMigishita = 0, kMigiue};

#define F first
#define S second

int main(void){
    vi t(2);
    for(int n, m; cin >> n >> t[kRabbit] >> t[kCat] >> m;){
        vector<vvi> mats(2, vvi(n, vi(n)));

        //(num) -> (y, x)
        vector<map<int, pii>> dic(2);

        rep(i, 2){
            rep(y, n){
                rep(x, n){
                    int num;
                    cin >> num;

                    mats[i][y][x] = num;
                    dic[i][num] = mp(y, x);
                }
            }
        }

        vvi rowCnt(2, vi(n));
        vvi colCnt(2, vi(n));
        vvi nanameCnt(2, vi(2));

        string res = "UNKNOWN";
        rep(i, m){
            int num; cin >> num;

            rep(j, 2){
                if(dic[j].find(num) == dic[j].end()) continue;

                int y = dic[j][num].F, 
                    x = dic[j][num].S;

                rowCnt[j][y]++;
                colCnt[j][x]++;

                int delta = 0;
                if(y == x){
                    if(++nanameCnt[j][0] == n) delta++;
                }
                if(y == n - 1 - x){
                    if(++nanameCnt[j][1] == n) delta++;
                }

                if(rowCnt[j][y] == n) delta++;
                if(colCnt[j][x] == n) delta++;

                if(delta >= 1 && n == 1) delta = 1;
                t[j] -= delta;
            }

            if(res != "UNKNOWN") continue;

            if(t[0] <= 0){
                if(t[1] <= 0){
                    res = "DRAW";
                }
                else res = "USAGI";
            }
            else if(t[1] <= 0) res = "NEKO";
        }

        if(res == "UNKNOWN") res = "DRAW";

        cout << res << endl;
    }

	return 0;
}

Measured memory_bytes: 20272
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+11;
const int mod=998244353;
int n,ans=1,a[N],v[N];
int qpow(int a,int b){
    int re=1;
    while(b){
        if(b&1) re=(re*1ll*a)%mod;
        b>>=1;a=(a*1ll*a)%mod;
    }return re;
}
int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
signed main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=read();
    if(a[1]!=0) return puts("0"),0;
    sort(a+1,a+n+1);
    for(int i=2;i<=n;i++){
        if(a[i]==0) return puts("0"),0;
        if(a[i]!=a[i-1]&&a[i]!=a[i-1]+1) return puts("0"),0;
    }
    for(int i=1;i<=n;i++) ++v[a[i]];
    for(int i=1;i<=n;i++){
        if(!v[i]) break;
        ans=(ans*1ll*qpow(v[i-1],v[i]))%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792