akhauriyash/Code-Regression huggingface dataset:
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n%M) * (f(n - 1) % M);
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, K; cin >> N >> K;

	map<ll, ll> p;
	rep(i, K) {
		ll d; cin >> d;
		vector<ll> A(d);
		rep(i, d)cin >> A[i];

		rep(i, d)p[A[i]] = 1;
	}

	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		if (p[i] == 0) ans++;
	}

	cout << ans << endl;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  rep(i, 5) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i + 1 << endl;
    }
  }
}


Measured memory_bytes: 3564
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var n int
	fmt.Fscan(in, &n)

	c := 0

	for i := 1; i <= n; i += 2 {
		if cc(i) == 8 {
			c++
		}
	}

	fmt.Fprintln(out, c)
}

func cc(n int) int {
	cm := map[int]int{}
	next := true
	for next {
		next = false
		for i := 2; i <= n; i++ {
			if n%i == 0 {
				cm[i]++
				next = true
				n /= i
				break
			}
		}
	}
	ret := 1
	for _, v := range cm {
		ret *= (v + 1)
	}
	return ret
}


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

int arr[300005];
int n, a, b;

void fail()
{
	printf("-1\n");
	exit(0);
}

int main()
{
	scanf("%d%d%d", &n, &a, &b);
	if (a+b > n+1) fail();
	if (b < (n+a-1)/a) fail();
	for (int i = 0;i < n;i++) arr[i] = max(0, n-a*(i/a+1))+(i%a)+1;
	for (int i = 0;i < n;i++) if (i/a+n-i == b)
	{
		int d = min(a, (n/a==i/a)?n%a:a)-i%a-1;
		for (int j = i/a*a;j <= i;j++) arr[j] += d;
		for (int j = i+1;j < n;j++) arr[j] = n-j;
		break;
	}
	for (int i = 0;i < n;i++) printf("%d%c", arr[i], " \n"[i+1==n]);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	int d[N];
	rep(i, 0, N) cin >> d[i];
	set<int> s;
	rep(i, 0, N) s.insert(d[i]);

	cout << s.size() << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#define INF 2100000000
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b < c)
	{
		cout << a + b + 1 + b;
	}
	else {
		cout << c + b;
	}
}

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

using namespace std;

//#define int long long

int n, m;
vector<pair<int, int>> g[1000];
char used[1000];
int a[1000][1000];
int p[1000], q[1000];
int an[200010];

void dfs(int v, int root){
    used[v] = true;
    a[root][v] = 1;
    for(auto to: g[v]){
        if(!used[to.first]) dfs(to.first, root);
    }
}

void dfs2(int v, int num, int dont, int t){
    used[v] = true;
    if(t == 0) p[v] = num;
    else q[v] = num;
    for(auto to: g[v]){
        if(to.first == dont) continue;
        if(!used[to.first]){
            dfs2(to.first, num, dont, t);
        }
    }
}

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int from, to;
        cin >> from >> to;
        g[from - 1].push_back({to - 1, i});
    }
    for(int i = 0; i < n; i++){
        memset(used, 0, sizeof(used));
        dfs(i, i);
    }
    for(int i = 0; i < n; i++){
        memset(p, -1, sizeof(p));
        memset(q, -1, sizeof(q));
        memset(used, 0, sizeof(used));
        for(int j = 0; j < (int)g[i].size(); j++){
            if(!used[g[i][j].first]) dfs2(g[i][j].first, j, i, 0);
        }
        memset(used, 0, sizeof(used));
        for(int j = (int)g[i].size() - 1; j >= 0; j--){
            if(!used[g[i][j].first]) dfs2(g[i][j].first, j, i, 1);
        }
        for(int j = 0; j < (int)g[i].size(); j++){
            if(p[g[i][j].first] != j || q[g[i][j].first] != j){
                int ai = i, bi = g[i][j].first;
                if(a[bi][ai]) an[g[i][j].second] = 1;
            }
            else{
                int ai = i, bi = g[i][j].first;
                if(!a[bi][ai]) an[g[i][j].second] = 1;
            }
        }
    }
    for(int i = 0; i < m; i++){
        if(an[i]) cout << "same" << endl;
        else cout << "diff" << endl;
    }
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  if(n/(a+b)==0){
    if(n<=a){
    cout<<n<<endl;
    }
    else if(a<=n && n<=(a+b)){
    cout<<a<<endl;
    }
  }
  else{
    if((n%(a+b))<=a){
      cout<<(n/(a+b))*a+(n%(a+b))<<endl;
    }
    else if(a<=(n%(a+b)) && (n%(a+b))<=(a+b)){
      cout<<(n/(a+b)+1)*a<<endl;
    }
  }
    return 0;
}             
    


Measured memory_bytes: 256
require 'prime'
MOD = 10**9+7


def fact(n)
  if n==0
    1
  else
    (1..n).inject(&:*)
  end
end

def C(n,k)
  (n-k+1..n).inject(&:*) / fact(k)
end


N,M = gets.split.map(&:to_i)


ans = 1

Prime.prime_division(M).each do |prime,exp|
  ans = (ans * C(exp+N-1,exp)) % MOD
end

puts ans


Measured memory_bytes: 4732
n, Y = map(int, input().split())
for x in range(n+1):
  for y in range(n-x+1):
    z = n-x-y
    if 0 <= z <= n and 10000*x+5000*y+1000*z == Y:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mp make_pair
#define mm(a) memset(a,-1,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define endl "\n"
#define ld long double
#define mod 1000000007
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    BRAHAMASTRA
    ll t; t=1;
    // cin >>t;
    while(t--)
    {
        ll n; cin >>n;
        ll num = 7%n;
        rep(i,0,1e8)
        {
            if(num==0)return cout<<i+1,0;
            num = (10*num+7)%n;
        }
        cout<<"-1\n";
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> a(n+1);
  vector<int64_t> b(n);
  REP(i,n+1){
    cin >> a.at(i);
  }
  REP(i,n){
    cin >> b.at(i);
  }
  int64_t t=0;
  int64_t p=a.at(0);
  int64_t tmp=0;
  REP(i,n){
    t += min(p, b.at(i));
    if (b.at(i) - p > 0){
      t += min(b.at(i) - p, a.at(i+1));
      p = max(a.at(i+1) - (b.at(i) - p),tmp);
    }else{
      p = a.at(i+1);
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

string shuffle(string str, int h){
    string head=str.substr(0,h);
    string tail=str.substr(h,str.size()-h);
    return tail+head;
    
}

int main(){
    string cards;
    int m,h;
    while (1){
        cin>>cards;
        if(cards=="-")break;
        
        cin >>m;
        for(int i=0;i<m;i++){
            cin>>h;
            cards=shuffle(cards,h);
            
        }
        cout<<cards<<endl;;
    }
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int i, j, k, x, y;
int n, m;

vector<int> graph[int(1e6)];
int memo[int(1e6)];

int dfs(int index)
{
    if(memo[index]!=0){
        return memo[index];
    }
    else{
    int sum = 0;
    for (auto z : graph[index])
    {
        sum = max(sum,dfs(z));
    }
    return memo[index] = sum + 1;
}}

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

    cin >> n >> m;

    for (i = 0; i < m; i++)
    {
        cin >> x >> y;
        graph[x].pb(y);
    }
    
    int res = 0;
    for (i = 1; i <= n; i++)
    {
        res = max(res, dfs(i));
    }
    cout << res-1 << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    rep(i, s.size()) s[i] = 'x';
    cout << s << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <limits.h>
//#include <conio.h>
using namespace std;

#define Rep(i,n) for(int i = 0; i < n; ++i )
#define For(i,s,e) for(int i = s; i < e; ++i )
#define ll long long

long a,b,c;

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

	cin >> a >> b >> c;
	cout << int(a*b/2) << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    fore = [0]*N
    back=[0]*N
    fore[0] = A[0]
    back[-1] = A[-1]
    for i in range(1, N):
        fore[i] = gcd(fore[i-1], A[i])
    for i in reversed(list(range(0, N-1))):
        back[i] = gcd(back[i+1], A[i])
    maximum = 0
    for i in range(N):
        f = fore[i-1] if i != 0 else 0
        b = back[i+1] if i != N-1 else 0
        m = gcd(f, b)
        maximum = max(m, maximum)
    print(maximum)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
main()

Measured memory_bytes: 14436
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long int arr[n+1][4];
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i][1]>>arr[i][2]>>arr[i][3];
	}
	long long int dp[n+1][4];
	dp[1][1]=arr[1][1];
	dp[1][2]=arr[1][2];
	dp[1][3]=arr[1][3];
	for(int i=2;i<=n;i++)
	{
		dp[i][1]=arr[i][1]+max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=arr[i][3]+max(dp[i-1][1],dp[i-1][2]);
	}
	cout<<max(max(dp[n][1],dp[n][2]),dp[n][3])<<endl;
}

Measured memory_bytes: 6528
import itertools
from collections import defaultdict
# 順列生成
def permutation(list_):
    return list(itertools.permutations(list_))

def main():
    N = int(input())
    P = "".join([str(x) for x in input().split()])
    Q = "".join([str(x) for x in input().split()])
    
    ls = [ "".join(i) for i in permutation([str(i+1) for i in range(N)])]
    dic = defaultdict(int)
    for num,i in enumerate(ls):
        dic[i] = (num+1)
    print(abs(dic[P]-dic[Q]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 50928
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 998244353;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

int main() {

	ll n;
	cin >> n;
	vector<pll> a(n), b(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	for (ll i = 0; i < n; i++)
	{
		cin >> b[i].first;
		b[i].second = i;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	for (ll i = 0; i < n; i++)
	{
		if (a[i].first > b[i].first) {
			cout << "No\n";
			return 0;
		}
	}
	for (ll i = 0; i < n-1; i++)
	{
		if (a[i + 1].first <= b[i].first) {
			printf("Yes\n");
			return 0;
		}
	}

	vector<ll> p(n);
	for (ll i = 0; i < n; i++)
	{
		p[a[i].second] = b[i].second;
	}
	ll x = 0;
	ll len = 0;
	do {
		x = p[x];
		len++;
	} while (x != 0);

	if (len == n) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}


	return 0;
}


Measured memory_bytes: 4600
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int red = 0, blue = 0;
	rep(i,s.size()){
		if(s[i] == '0') red++;
		else blue++;
	}
	int ans = min(red, blue) * 2;
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    string S;
    cin >> S;
    int n = 0, s = 0, e = 0, w = 0;
    rep(i,sz(S)) {
        if(S[i] == 'N') n++;
        if(S[i] == 'S') s++;
        if(S[i] == 'E') e++;
        if(S[i] == 'W') w++;
    }
    bool ok = false;
    if(((s == 0 && n == 0) || (s != 0 && n != 0)) && ((e == 0 && w == 0) || (e != 0 && w != 0)))
        ok = true;
    YesorNo(ok);
}

Measured memory_bytes: 3692
(* nCr = {(n-r+1)/r}nCr-1 *)
let const = 998244353
let ( *$ ) x y = (x * y) mod const
let ( +$ ) x y = (x + y) mod const
let rec power x n =
  if n <= 0 then 1
  else if n mod 2 = 0 then
    power (x *$ x) (n/2)
  else
    x *$ power x (n - 1)
let mod_inv x =
  power x (const - 2)
  
let () =
  let n, a, b, k = Scanf.scanf "%d %d %d %d"
                     (fun n a b k -> n, a, b, k) in
  let binomial = Array.make (n + 1) 1 in
  for i = 1 to n do
    binomial.(i) <- binomial.(i-1)  *$ (n+1-i) *$ mod_inv i
  done;
  Array.init (n+1) (fun x ->
      let y = (k - a * x) / b in
      if a * x + b * y = k && 0 <= y && y <= n then
        binomial.(x) *$ binomial.(y)
      else
        0)
  |> Array.fold_left (fun x y -> x +$ y) 0
  |> Printf.printf "%d\n"



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

using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    int low = 1000000000, dif = 0, a[n], cnt = 1;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        low = min(low, a[i]);
        if (dif == a[i] - low) cnt++;
        else if (dif < a[i] - low) {
            dif = a[i] - low;
            cnt = 1;
        }
        // cerr << low << ' ' << dif << '\n';
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007
int gcd(int x, int y)
{

    if (x % y == 0) {
        return y;
    }
    else {
        return gcd(y, x % y);
    }

}

int main()
{
    int N;
    vec(A)
        cin >> N;
    int all[N];
    fx(N){
        vecp(A)
            if (x == 0) {
            all[x] = A.at(x);
                }else {
            all[x] = gcd(all[x-1],A.at(x));
        }
    }


    int dp[N];
if(N>2){
    for(int x=2;x<N;x++){
      if(x==2){
        dp[x] = max(gcd(A.at(0),A.at(2)),gcd(A.at(2),A.at(1)));
      }else{
        dp[x] = max(gcd(dp[x-1],A.at(x)),all[x-1]);
      }
    }
    ce(dp[N-1])
}else{
  ce(max(A.at(0),A.at(1)))
}
}


Measured memory_bytes: 1528
#include<iostream>
using namespace std;
struct Node{
   int parent,left,right;
};
const int NIL = -1;

void Preorder(Node A[], int n, int root) {
    if ( root != NIL ) {
    cout<<" "<<root;
    Preorder( A, n, A[root].left);
    Preorder( A, n, A[root].right);
   }
}
void Inorder(Node A[], int n, int root) {
    if ( root != NIL ) {
         Inorder( A, n, A[root].left);
        cout<<" "<<root;
       Inorder( A, n, A[root].right);
     }
}

void Postorder(Node A[], int n, int root) {
   if ( root != NIL ) {
      Postorder( A, n, A[root].left);
    Postorder( A, n, A[root].right);
      cout<<" "<<root;
    }
}
int main(){
	int n;
	cin>>n;
	Node *A = new Node[n];
   int v,left,right;
   for(int i=0;i<n;i++) { 
   		A[i].left = A[i].right = A[i].parent = NIL;
   }

   for(int i=0;i<n;i++){
   		cin>>v>>left>>right;
   		A[v].left=left;
   		A[v].right=right;
   		A[left].parent = v;
   		A[right].parent = v;
    }


   int root=0;
   for ( int i = 0; i < n; i++ ) {
   	   if ( A[i].parent == NIL ) root = i;
   }

  cout<<"Preorder"<<endl;
  Preorder(A, n, root);
  cout<<endl;

  cout<<"Inorder"<<endl;
  Inorder(A, n, root);
  cout<<endl;
  
  cout<<"Postorder"<<endl;
  Postorder(A, n, root);
  cout<<endl;
  
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n;
  std::string xs;
  Solver() {
    S002 reader;
    reader >= n >= xs;
  }
  void solve() {
    std::string ys(n, ' ');
    for(char c0 : {'S', 'W'}) {
      for(char c1 : {'S', 'W'}) {
        ys[0] = c0, ys[1] = c1;
        for(long i = 2; i < n; ++i) {
          if( ( xs[i-1] == 'o' and ys[i-1] == 'S' ) or
              ( xs[i-1] == 'x' and ys[i-1] == 'W' )    ) {
            ys[i] = ys[i-2];
          }
          else {
            ys[i] = 'S' + 'W' - ys[i-2];
          }
        }
        bool res = true;
        if( ys[n-1] == 'S' and xs[n-1] == 'o' and ys[n-2] != ys[0] ) res = false;
        if( ys[n-1] == 'S' and xs[n-1] == 'x' and ys[n-2] == ys[0] ) res = false;
        if( ys[n-1] == 'W' and xs[n-1] == 'o' and ys[n-2] == ys[0] ) res = false;
        if( ys[n-1] == 'W' and xs[n-1] == 'x' and ys[n-2] != ys[0] ) res = false;
        if( ys[0] == 'S' and xs[0] == 'o' and ys[n-1] != ys[1] ) res = false;
        if( ys[0] == 'S' and xs[0] == 'x' and ys[n-1] == ys[1] ) res = false;
        if( ys[0] == 'W' and xs[0] == 'o' and ys[n-1] == ys[1] ) res = false;
        if( ys[0] == 'W' and xs[0] == 'x' and ys[n-1] != ys[1] ) res = false;
        if( res ) {
          printf("%s\n", ys.c_str());
          return;
        }
      }
    }
    puts("-1");
  }
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}



Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    vector<string> vec;
    int n, l;
    cin >> n >> l;
    imfor(i, n) {
        string s;
        cin >> s;
        vec.push_back(s);
    }
    sort(vec.begin(), vec.end());
    for (auto x : vec) {
        cout << x;
    }
    cout << endl;
}

Measured memory_bytes: 256
usr=input()
lst = usr.split('/')
a = int(lst[0])
string = lst[1]
if string[0] == '0':
  b = int(string[1])
else:
  b = int(string)

if a <= 2019 and b <5:
  print('Heisei')
else:
  print('TBD')



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

int n, m, i, w;
long long v;
long long dp [100001];

int main ()
    {
    scanf ("%d%d",&n,&m);
    while (n--)
        {
        scanf ("%d%lld",&w,&v);
        for (i=m; i>=0; i--)
            if (i-w>=0)
                dp[i]=max(dp[i],dp[i-w]+v);
        }
    printf ("%lld\n",dp[m]);
    return 0;
    }


Measured memory_bytes: 1024
n = int(input())
Adj = [0 for i in range(n)]

for i in range(n):
    row = list(map(int, input().split(' ')))
    Adj[row[0] - 1] = row

for adj in Adj:
    k = adj[1]
    E = adj[2:2+k]
    row = [0 for i in range(n)]
    for i in E:
        row[i - 1] = 1
    print(' '.join(map(str, row)))



Measured memory_bytes: 5612
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int a[6]={6,36,216,1296,7776,46656};
int b[6]={9,81,729,6561,59049};
int reg(int c,int d){
	if(c==11)return d;
	int e,f;
	if(c<6){
		e=a[c];
		f=6;
	}
	else {
		e=b[c-6];
		f=9;
	}
	int res=1000000;
	for(int i=0;i<f;++i){
		if(d<i*e)break;
		res=min(res,i+reg(c+1,d-i*e));
	}
	return res;
}

int main() {
	int n;
	cin>>n;
	cout<<reg(0,n)<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Set<Integer> set = new TreeSet<>();
        for (int i = 1 ; i <= Math.sqrt(m) ; i++) {
            if (m % i == 0) {
                set.add(m / i);
                set.add(i);
            }
        }
        //setにはいっている数字のなかでNより大きい最小の数字をだしたい。
        for (Integer num : set) {
            if (num >= n) {
                System.out.println(m / num);
                return;
            }
        }
    }

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const double EPS = 1e-11;

double width(vector<pair<int,int> > polygon, double x) {
  vector<double> w;
  for (int i = 0; i < polygon.size() ; i++) {
    pair<int,int> p = polygon[i], q = polygon[(i+1)%polygon.size()];
    if (abs(p.first - x) < EPS)
      w.push_back(1.0*p.second);
    else if ((p.first < x && x < q.first) || (p.first > x && x > q.first)) {
      int x0 = p.first, y0 = p.second;
      int x1 = q.first, y1 = q.second;
      w.push_back(y0 + 1.0*(y1-y0)*(x-x0)/(x1-x0));
    }
  }
  sort(w.begin(), w.end());
  return w[w.size()-1] - w[0];
}

double volume(vector<pair<int,int> > pxy, vector<pair<int,int> > pxz, vector<int> X) {
  double total = 0.0;
  int xmin = max((*min_element(pxy.begin(), pxy.end())).first,
                 (*min_element(pxz.begin(), pxz.end())).first);
  int xmax = min((*max_element(pxy.begin(), pxy.end())).first,
                 (*max_element(pxz.begin(), pxz.end())).first);
  sort(X.begin(), X.end());
  for (int i = 0; i < X.size()-1; i++) {
    int a = X[i], b = X[i+1];
    if (!(xmin <= a && a <= xmax && xmin <= b && b <= xmax))
      continue;
    double m = (a+b)/2.0;
    double va = width(pxy, a)*width(pxz, a);
    double vb = width(pxy, b)*width(pxz, b);
    double vm = width(pxy, m)*width(pxz, m);
    double area = ((b-a)/6.0)*(va + 4.0*vm + vb);
    total += area;
  }
  return total;
}

int main() {
  int M, N;
  while (cin >> M >> N && M > 0) {
    vector<pair<int,int> > PXY, PXZ;
    vector<int> X;
    int x, y, z;
    for (int i = 0; i < M; i++) {
      cin >> x >> y;
      PXY.push_back(make_pair(x,y));
      X.push_back(x);
    }
    for (int i = 0; i < N; i++) {
      cin >> x >> z;
      PXZ.push_back(make_pair(x,z));
      X.push_back(x);
    }
    cout << fixed << volume(PXY, PXZ, X) << endl;
  }
}




Measured memory_bytes: 3208
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

#define CAKE 6

const int inf = 1<<28;

struct Node{
  vector<int> con;
  vector<int> cost;
};

struct State{
  int now;
  int cakes;
  int cost;
  State(int now, int cakes, int cost):now(now),cakes(cakes),cost(cost){}
  bool operator>(const State &t)const{
    return cost>t.cost;
  }
};

typedef vector<Node> Graph;

int dijkstra(int m, int n, const Graph &G, int s){
  priority_queue<State,vector<State>,greater<State> > pq;
  State init(s,0,0);
  int ret = inf;
  int A[(1<<6)][G.size()];
  bool vis[(1<<6)][G.size()];
  
  for(int i = 0; i < (1<<6); ++i){
    for(int j = 0; j < G.size(); ++j){
      vis[i][j] = false;
      A[i][j] = inf;
    }
  }
  
  pq.push(init);
  while(!pq.empty()){
    State now = pq.top();
    pq.pop();

    if( !vis[now.cakes][now.now] ){
      //vis[now.cakes][now.now] = true;
    }else continue;
    
    int nowid = now.now;
    for(int i = 0; i < G[nowid].con.size(); ++i){
      int nextid = G[nowid].con[i];
      int nextcake = now.cakes;
      int nextcost = now.cost + G[nowid].cost[i];
      //cout << " NOW : " << nowid << " NEXT : " << nextid << " COST : " << G[nowid].cost[i] << endl;
      if( 1<=nextid&&nextid<1+m ){
	if( nextcake & (1<<(nextid-1)) ) continue;
	else nextcake |= (1<<(nextid-1));
      }
      if( A[nextcake][nextid] > nextcost ){
	A[nextcake][nextid] = nextcost;
	if( !vis[nextcake][nextid] ){
	  pq.push( State(nextid,nextcake,nextcost) );
	}
      }
    }
  }
  
  for(int i = 0; i < (1<<6); ++i){
    ret = min( ret, A[i][1+n+m] );
  }
  return ret;
}

int convNode(int m, int n, const string &s){
  int ret = -1;
  string p = s;
  p.erase(p.begin());
  if( s[0] == 'C' ){ ret = atoi(p.c_str()); }
  if( s[0] == 'L' ){ ret = m+atoi(p.c_str()); }
  if( s[0] == 'H' ){ ret = 0; }
  if( s[0] == 'D' ){ ret = n+m+1; }
  return ret;
}

void createEdge(int m, int n, int cake[], Graph &G, const string &s, const string &d, int c){
  int src = convNode( m,n,s );
  int dst = convNode( m,n,d );
  
  //  cout << src << ' ' << dst << endl;
  G[src].con.push_back( dst );
  if( d[0] == 'C' ){
    G[src].cost.push_back( c - cake[ dst-1 ] );
  }else{
    G[src].cost.push_back( c );
  }

  G[dst].con.push_back( src );
  if( s[0] == 'C' ){
    G[dst].cost.push_back( c - cake[ src-1] );  
  }else{
    G[dst].cost.push_back( c );
  }
}

int main()
{
  while(true){
    int cake[6]={0,};
    Graph G;
    int m,n,k,d;
    cin >> m >> n >> k >> d;
    if( m == 0 && n == 0 && k == 0 && d == 0 ) break;
    
    for(int i = 0; i < m; ++i){
      cin >> cake[i];
    }

    G.resize(1+n+m+1);
    for(int i = 0; i < d; ++i){
      string src,dst;
      int cost;
      cin >> src >> dst >> cost;
      createEdge( m, n, cake, G, src, dst, k*cost );
    }

    cout << dijkstra( m, n, G, 0 ) << endl;
    
  }
  return 0;
}

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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  int ans = 0;
  int x = 0;
  rep(i, n) {
    ans = (ans + (ll)a[i] * x) % mod;
    x = (x + a[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pb push_back
#define mp make_pair
const unsigned int mod = 1e9+7;
const int mx=1e5+5;
long long v[mx];
ll n,a,b;
bool ok(ll k){
	ll cnt=0;
	for(int i=0;i<n;++i){
		ll now=max(0LL,v[i]-b*k);//now=
		cnt+=(now+a-1)/a;
	}
	return cnt<=k;
}	
int main(){
	/*freopen(".gir", "r", stdin);
	freopen(".cik", "w", stdout); 
    */ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> n >> a >> b ;
	rep(i,n)cin >> v[i];
	a-=b;
	ll l=-1;
	ll r=1000000009;
	while(r-l>1){
		ll m=(l+r)/2;
		if(ok(m))r=m;
		else l=m;
	}
	cout << r << endl;
}
	

Measured memory_bytes: 1024
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 2e5 + 5;

int n;
pair<int, int> p[MAXN];

int main() {	
 
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		p[i] = mp(x, i);
	}
	sort (p + 1, p + 1 + n);
	for (int i = 1; i <= n; i++) {
		cout << p[i].S << ' ';
	}
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll grid[101][101], h, w, n, a, x, y;

int main()
{
	cin >> h >> w >> n;
	for(int i = 0; i < n; i++){
		cin >> a;
		for(int j = 0; j < a; j++){
			grid[x][y]=i+1;
			if(x%2==0){
				if(y+1<w){
					y++;
				}
				else{
					x++;
				}
			}
			else{
				if(y-1>=0){
					y--;
				}
				else{
					x++;
				}
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cout << grid[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
k,n=map(int,input().split())
a=[int(i) for i in input().split()]

saitanhiku=a[2]-a[1]
for i in range(n-1):
    if a[i+1]-a[i]>=saitanhiku:
        saitanhiku=a[i+1]-a[i]
if (k-a[n-1])+a[0]>=saitanhiku:
    saitanhiku=k-a[n-1]+a[0]
print(k-saitanhiku)

Measured memory_bytes: 31828
#include <bits/stdc++.h>
#define rep( i, n ) for (ll i = 0; i < ( ll )(n); i++)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;



int main(){
    ll x,k,d;
    ll ans;
    cin>>x>>k>>d;

    if(x==0){
        if(k%2==0) ans=0;
        else ans=d;
    }
    else{
    if(x<0) x=-x;
        if((x/d)>=k){
            ans=x-k*d;
        }
        else{
            ll e=ceil(x/d);
            if((k-e)%2==1) ans=d-x%d;
            else ans=x%d;
        }
    }
    cout<<abs(ans);
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
using ll = long long;
using P = pair<ll, ll>;
vector<int> to[100005];
int cost[100005];

int x[10];
int y[10];

double dist(ll i, ll j) {
    int xx = (x[i]-x[j])*(x[i]-x[j]);
    int yy = (y[i]-y[j])*(y[i]-y[j]);
    return sqrt(xx+yy);
}

signed main(){
    long long n;
    cin >> n;
    long double ans = 0;
    vector<int> np(n);
    rep(i, n) np[i] = i;
    long fac = 1;
    FOR(i,1, n+1) fac *= i; 
    //cout << fac << endl;
    rep(i, n) {
        cin >> x[i] >> y[i];
    }

    do {
        for(int i = 0; i<n-1; i++) {
            ans += dist(np[i], np[i+1]);
            //cout << np[i]<< " " <<np[i+1]<<" "<<dist(np[i], np[i+1]) << endl;
        }
    }while(next_permutation(np.begin(), np.end()));

    cout << setprecision(15) << ans/fac << endl;

    return 0;
}



Measured memory_bytes: 2560
def doit(str, min, cnt)
  p = str.to_i
  if p < min
    cnt += 1
    min = p
  end
  [min, cnt]
end

n = gets.to_i
str = ''
nums = []
min = 9999999
cnt = 0
while true
  c = $stdin.getc
  if 48 <= c.ord && c.ord <= 57
    str << c 
  else
    min, cnt = doit(str, min, cnt)
    if c == ' '
      str = ''
    else
      break
    end
  end
end

puts cnt


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	cout << max({ a + b,a - b,a*b }) << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	string s;
	cin >> s;
	std::vector<char> v;
	for(int i=0;i< s.length();i++){
		if(v.empty() && s[i]=='B') ;
		else if (s[i]=='0')v.PB('0');
		else if(s[i]=='1')v.PB('1');
		else if(s[i]=='B')v.pop_back();
	}
	for(int i=0; i < v.size();i++)cout <<v[i];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int h,w;
string s[50];

ll d[50][50];
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};

void solve(){
	queue<P> que;
	que.push(P(0,0));
	while(que.size()){
		P p = que.front();
		que.pop();
		rep(i,4){
			ll ny=p.first+dy[i];
			ll nx=p.second+dx[i];
			if(ny>=0&&ny<h&&nx>=0&&nx<w){
				if(s[ny][nx]=='#')continue;
				if(d[ny][nx]>d[p.first][p.second]+1){
					que.push(P(ny,nx));
					d[ny][nx]=d[p.first][p.second]+1;
				}
			}
		}
	}
}

int main(){
	cin>>h>>w;
	rep(i,h)rep(j,w)d[i][j]=INF;
	d[0][0]=0;
	ll b = 0;
	rep(i,h){
		cin>>s[i];
		rep(j,w)b+=(s[i][j]=='#');
	}
	solve();
	if(d[h-1][w-1]!=INF){
		cout<<h*w-d[h-1][w-1]-1-b<<endl;
	}
	else{
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();

        StringBuilder ans = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            int x = i;

            if (x % 3 == 0) {
                ans.append(" ").append(i);
            } else {
                while (x != 0) {
                    if (x % 10 == 3) {
                        ans.append(" ").append(i);
                        break;
                    } else {
                        x /= 10;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

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

int main() {
    int L, R;
    cin >> L >> R;
    int ans;
    if ((R-L) >= 2019) {
        ans = 0;
    } else {
        ans = 10000;
        for (int i = L; i <= R - 1; ++i) {
            for (int j = i + 1; j <= R; ++j) {
                int res = ((i % 2019) * (j % 2019)) % 2019;
                if (res < ans) {
                    ans = res;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    if (i)
    {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

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

  vector<int> vec(n);
  rep(i, n)
  {
    cin >> vec.at(i);
  }

  reverse(all(vec));

  rep(i, n)
  {
    if (i)
    {
      printf(" ");
    }
    printf("%d", vec.at(i));
  }

  printf("\n");
}



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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)3e5+1;
ll N, arr[MAXN], rem[60], ct[60];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> arr[i];
        for(int j=0; j<60; j++)
        {
            ct[j] += arr[i]%2;
            arr[i]/=2;
        }
    }
    rem[0] = 1;
    for(int i=1; i<60; i++)
    {
        rem[i] = times(rem[i-1], 2);
    }
    ll ans = 0;
    for(int j=0; j<60; j++)
    {
        ans = add(ans, times(rem[j], times(ct[j],(N-ct[j]))));
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
    int a, b, c,d,e,f;
    scanf("%d %d %d",&a, &b, &c);
    if(a<b){
        if(b<c){
            d=a+b;
        }else{
            d=a+c;
        }
    }else if(b<c){
        if(a<c){
            d=a+b;
        }else{
            d=b+c;
        }

    }else{
        d=b+c;
    }
    printf("%d",d);
return 0;
}
    

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int max_d(long n){
    if(n > 0){
        long d = 1;
        while(true){
            if(((long)pow(4, d) - 1) / 3 >= n){
                return (int)(d * 2 - 1);
            }
            else d++;
        }
    }
    else if(n < 0){
        long d = 1;
        while(true){
            if(-((long)pow(4, d) - 1) * 2 / 3 <= n){
                return (int)(d * 2);
            }
            else d++;
        }
    }
    else{
        return -1;
    }
}

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

    if(n == 0){
        cout << 0 << endl;
        return 0;
    }

    int bit[40]; memset(bit, 0, sizeof(bit));
    int fi = 0;
    while(n != 0){
        int d = max_d(n);
        if(fi == 0) fi = d;
        bit[d] = 1;
        n -= (long)pow(-2, d - 1);
    }
    for(int i = fi; i >= 1; i--){
        cout << bit[i];
    }
    cout << endl;
}

Measured memory_bytes: 256