akhauriyash/Code-Regression huggingface dataset:
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n, a, b := sc.getInt3()

	var ans int
	ans += (n / (a + b)) * a
	ans += min(n%(a+b), a)

	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const long double PI = acos(-1.0);
//const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}
signed main(){
	my_io();
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int oddcount = 0;
	int fourcount = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 1) {
			oddcount++;
		}
		if (a[i] % 4 == 0) {
			fourcount++;
		}
	}
	if (oddcount + fourcount == n && oddcount - fourcount <= 1) {
		cout << "Yes" << endl;
	}
	else if (oddcount > fourcount) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int main()
{
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= k + x - 1; i++)
    {
        cout << i << ' ';
    }

    return 0;
}


Measured memory_bytes: 256
<?php

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


while ($tmp = trim(fgets(STDIN))){
$list = explode(" ", $tmp);
//var_dump($list);
$a = gcd($list[0], $list[1]);
$b = ($list[1] / $a) * $list[0];
echo $a . " " . $b . PHP_EOL;
}

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

int main() {

    int n;

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

    int cnt = 0;
    vector< bool > in(n + 1, false);
    for(int i = n; i > 0; i--) {
        int sum = 0;
        for(int j = i + i; j <= n; j += i) {
            if(in[j]) sum++;
        }
        if(sum % 2 != a[i - 1]) in[i] = true, cnt++;
    }

    cout << cnt << endl;
    for(int i = 1; i <= n && cnt; i++) {
        if(in[i]) {
            if(cnt > 1) cout << i << " ";
            else cout << i << endl;
            cnt--;
        }
    }
}


Measured memory_bytes: 1920
#include <string.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main()
{
	int num;
	cin >> num;
	
	char tytle[50][1000];
	int time[50];
	for (int i = 0; i < num;i++) {
	
		cin >> tytle[i] >> time[i];
	}

	char sleep[1000];
	cin >> sleep;

	int a;
	for (int i = 0; i < num;i++) {
		if (strcmp(tytle[i],sleep)==0) {
			a = i;
		}
	}

	int ans = 0;
	for (int i = a+1; i < num;i++) {
		ans += time[i];
	}

	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    ll n;cin>>n;
    cout<<n*n;
    return 0;
}

    


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

int main(void) {
    int N,A,B;
    int num;
    int sum = 0;

    std::cin >> N >> A >> B;

    for(int i = 1; i <= N; i++) {
        num = ((i/10000)%10) + ((i/1000)%10) + ((i/100)%10) + ((i/10)%10) + (i%10);
        if(num >= A && num <= B)
            sum += i;
    }

    std::cout << sum << std::endl;

    return 0;
}


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

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


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

int main(){
	string num;
	while (1) {
		int m = 0;
		cin >> num;
		if (num[0] == '0')
			break;
		for (int i = 0;i < num.size();i++) {
			num[i] = num[i] + '0';
			m = m + num[i]-96;
		}
		cout << m << endl;
	}


    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	int X;
	cin >> X;

	int a = X / 100;

	int b = X % 100;

	if (a*5 >= b) { cout <<1; }
	else { cout << 0; }

	system("PAUSE");
}

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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n;
pair<int, int> a[200000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i].first, a[i].second = i;
  sort(a, a + n);
  int r = 0;
  for (int i = 0; i < n; i += 2)
    r += (i % 2) != (a[i].second % 2);
  cout << r << "\n";
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<bool> d;
    d.resize(10);
    fill(ALL(d), true);
    REP(i, K) {
        int x;
        cin >> x;
        d[x] = false;
    }
    for(int i = N;;i++) {
        int x = i;

        bool p = true;
        for(;0 < x;x /= 10) {
            p = p && d[x%10];
        }
        if(p) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
using System;

namespace cola2
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());

            int hour = num / 3600;
            num = num - 3600 * hour;

            int min = num / 60;
            num = num - 60 * min;

            Console.WriteLine("{0}:{1}:{2}", hour, min, num);
        }
    }
}

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}


int main() {
    string s;
    R s;
    int a=stoi(s.substr(0, 2));
    int b=stoi(s.substr(2, 2));
    bool f1 = (1<=a && a<=12);
    bool f2 = (1<=b && b<=12);
    if(f1&&f2)co("AMBIGUOUS");
    else if(f1)co("MMYY");
    else if(f2)co("YYMM");
    else co("NA");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ;
#define MOD 1000000007
#define ll long long 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define ff first
#define ss second

using namespace std;

int n ;
vvi v(100010 , vi(4));
int dp[100010][5];

int solve(int i , int la){

	if( i == n+1)return 0;

	if(dp[i][la] != -1)return dp[i][la];

	if(la == 1)
		return dp[i][la]=max(v[i][2] + solve(i+1 , 2) , v[i][3] +solve(i+1 , 3));

	if(la == 2)
		return dp[i][la]=max(v[i][1] + solve(i+1 , 1) , v[i][3] +solve(i+1 , 3));

	if(la == 3)
		return dp[i][la]=max(v[i][1] + solve(i+1 , 1) , v[i][2] +solve(i+1 , 2));	

}

int main(){   

fastio
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt","w", stdout);
// #endif

cin>>n;
for(int i =1 ; i<=n  ; i++){
	cin>>v[i][1]>>v[i][2]>>v[i][3];
}

memset(dp , -1, sizeof(dp));
cout<<max(v[1][1] + solve(2, 1) ,max( v[1][2] + solve(2 , 2) , v[1][3] + solve(2, 3)));


return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int tmp = A.at(i);
		if (A.at(tmp - 1) == i + 1) {
			cnt++;
		}
	}
	cout << cnt / 2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n;
vpii v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(k, 0, 2){
    FOR(i, 0, n){
      int a;
      cin >> a;
      v.pb(mp(a, k));
    }
  }
  sort(rng(v));
  int d = 0;
  ll ans = 1;
  each(itr, v){
    if(itr->se){
      if(d < 0) ans = ans*(-d)%mod;
      d++;
    }else{
      if(d > 0) ans = ans*d%mod;
      d--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

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

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

Int h, w;

int main(){
	cin >> h >> w;
	//if(h < w) swap(h,w);
	
	if(h % 3 == 0 || w % 3 == 0){
		cout << 0 << endl;
	}
	else{
		Int a, b, c;
		a = (h / 3 + 1) * w;
		b = w / 2 * (h - (h / 3 + 1));
		c = h * w - a - b;
		int ans1 = max(a, max(b, c)) - min(a, min(b, c));
		
		Int d, e, f;
		d = (h / 3) * w;
		e = w / 2 * (h - (h / 3));
		f = h * w - d - e;
		
		/*Int aa, bb, cc;
		aa = h / 3 * w;
		bb = (h / 3 + 1) * w;
		cc = h * w - aa - bb;*/
		//w
		int ans3 = w;
		
		int ans2 = max(d, max(e, f)) - min(d, min(e, f));
		
		Int a1, b1, c1;
		a1 = (w / 3 + 1) * h;
		b1 = h / 2 * (w - (w / 3 + 1));
		c1 = h * w - a1 - b1;
		int ans4 = max(a1, max(b1, c1)) - min(a1, min(b1, c1));
		
		Int d1, e1, f1;
		d1 = (w / 3) * h;
		e1 = h / 2 * (w - (w / 3));
		f1 = h * w - d1 - e1;
		
		/*Int aa, bb, cc;
		aa = h / 3 * w;
		bb = (h / 3 + 1) * w;
		cc = h * w - aa - bb;*/
		//w
		int ans6 = h;
		
		int ans5 = max(d1, max(e1, f1)) - min(d1, min(e1, f1));
		
		cout << min(min(ans1, min(ans2, ans3)),min(ans4, min(ans5, ans6))) << endl;
	}
	
	return 0;
}

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

using namespace std;

string S;


int main(){

	cin>>S;

	int pos=S.length()-1;
	int ans=1;

	while(1){

		if(pos<0){
			break;
		}

		if(S[pos]=='m'){
			if(pos-4>=0){
				if(S.substr(pos-4,5)!="dream"){
					ans=0;
					break;
				}
				else{
					pos=pos-5;
				}
			}
			else{
				ans=0;
				break;
			}
		}
		else if(S[pos]=='e'){
			if(pos-4>=0){
				if(S.substr(pos-4,5)!="erase"){
					ans=0;
					break;
				}
				else{
					pos=pos-5;
				}
			}
			else{
				ans=0;
				break;
			}
		}
		else if(S[pos]=='r'){
			if(pos-2<0){
				ans=0;
				break;
			}
			if(S[pos-2]=='m'){
			if(pos-6>=0){
				if(S.substr(pos-6,7)!="dreamer"){
					ans=0;
					break;
				}
				else{
					pos=pos-7;
				}
			}
			else{
				ans=0;
				break;
			}
			}
			else if(S[pos-2]=='s'){
			if(pos-5>=0){
				if(S.substr(pos-5,6)!="eraser"){
					ans=0;
					break;
				}
				else{
					pos=pos-6;
				}
			}
			else{
				ans=0;
				break;
			}
			}
			else{
				ans=0;
				break;
			}
		}
		else{
			ans=0;
			break;
		}
	}

	if(ans==1){printf("YES\n");}
	else{printf("NO\n");}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{

int a,b,c,d,i;
map<int,int>mp;
cin >> a;
c=a;
a--;
while(a--)
{
    cin >> b;
    mp[b]++;

//cout << a <<endl;



}
for(i=1;i<=c;i++)
    cout << mp[i] << endl;

}


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

ans = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1,n+1):
    mm = list(str(i))
    a = 0
    for j in range(len(mm)):
        a += int(mm[j])*(10**j)
    
    mm1 = int((list(str(i)))[0])
    mm2 = int((list(str(i)))[-1])
    if not(mm2!=0):
        continue
    #print(mm1,mm2,i)
    ans[mm1-1][mm2-1] +=1

cnt = 0
for i in range(9):
    for j in range(9):
        cnt += ans[i][j]*ans[j][i]


print(cnt)

# for i in range(9):
#     print(*ans[i])

    








Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<iostream>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  int n; cin >>n;
  vector<vector<int>> vec(n,vector<int>(2));
  rep(i,n) cin >>vec[i][0]>>vec[i][1];
  double key=0;
  sort(vec.begin(),vec.end());
  do {
    for (int i = 0; i < n-1; i++) {
        key+=(double)sqrt((vec[i][0]-vec[i+1][0])*(vec[i][0]-vec[i+1][0])+(vec[i][1]-vec[i+1][1])*(vec[i][1]-vec[i+1][1]));
    }
  
} while(next_permutation(vec.begin(),vec.end()));
  rep2(i,1,n+1)key/=i;
  cout <<fixed<<setprecision(6)<<key<<endl;
}

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

string S;
int i;

ll dfs() {
  ll ret = 0;
  i++;

  if('0' <= S[i] && S[i] <= '9') {
    while('0' <= S[i] && S[i] <= '9') {
      ret = ret * 10 + (S[i] - '0');
      i++;
    }
    ret = (ret + 1) / 2;
  } else {
    vector<ll> x;
    while(S[i] == '[') x.push_back(dfs());
    sort(x.begin(), x.end());
    REP(j, 0, (x.size() + 1) / 2) ret += x[j];
  }

  i++;
  return ret;
}

int main(void) {
  ll N;
  cin >> N;
  REP(j, 0, N) {
    cin >> S;
    i = 0;
    cout << dfs() << endl;
  }
}



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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;

  int ans = 0;
  rep(i, si(s)) {
    if (s[i] == '+') ++ans;
    else --ans;
  }

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

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>>c;
    for(int i = 0;i < n;i++){
        int a,b;
        cin >> a >> b;
        c.emplace_back(b,a);
    }
    sort(c.begin(),c.end());
    int ans = 0;
    bool flag = true;
    for(auto v: c){
        ans += v.second;
        if(ans > v.first){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 2420
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    s = input()
    print(s[0] + str(len(s) - 2) + s[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 4076
//abc169

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

int main() {
  int n;
  int zero=0;
  cin >> n;
  int64_t ans = 1;
  std::vector<long> v(n);

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


  for(int i=0 ; i<n ; i++){
    if(v[i] <= 1000000000000000000 / ans){
      ans *= v[i];
    }else{
      ans = -1;
      break;
    }
  }

  for(int i=0 ; i<n ; i++){
    if(v[i]==0){
      zero++;
    }
    if(zero > 0){
      ans = 0;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 4028
integer :: piyo(3),i
character(3) :: s
read*,s

piyo = 0
do i = 1,3
  select case( s(i:i) )
  case( 'a' )
    piyo(1) = piyo(1) + 1
  case( 'b' )
    piyo(2) = piyo(2) + 1
  case( 'c' )
    piyo(3) = piyo(3) + 1
  end select
end do

do i = 1,3
  if( piyo(i)/=1 )then
    print*,'No'
    stop
  end if
end do
print*,'Yes'
end

Measured memory_bytes: 256
n, h = map(int, input().split())
a = []
b = []
for _ in range(n):
    tmp_a, tmp_b = map(int, input().split())
    a.append(tmp_a)
    b.append(tmp_b)

v = max(a)
b.sort(reverse=True)
i = 0
while i < n and b[i] > v and h > 0:
    h -= b[i]
    i += 1

if h <= 0:
    print(i)
else:
    print(i + (h + v - 1) // v)

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

int main(){
    int K;
    string S;
    cin >> K;
    cin >> S;
    int ans=(int)(S.length());
    if(ans<=K){
        cout << S << endl;
    }else{
        cout << S.substr(0,K)+ "..."<<endl;
    }
    return 0;

}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
long long maxim(long long a, long long b) { return a > b ? a : b; }
int main(){
    long long n,i,j,ans=0,height=0,a[200020]={};
    scanf("%lld",&n);
    for(i=0; i<n; i++){
        scanf("%lld",&a[i]);
        if(i>0){
            ans+=maxim(height-a[i],0);
        }
        height=maxim(height,a[i]);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3292
//abc123 b 最後に注文するものを決める
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n; cin>>n;
    if(n%2==0) cout<<n<<endl;
    else cout<<n*2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    VI v(n);
    int sum = 0;
    rep(i, n)
    {
        cin >> v[i];
        sum += v[i];
    }
    int num = 0;
    rep(i, n)
    {
        if (v[i] * 4 * m >= sum)
            num++;
    }
    if (num >= m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    char str[20];
    int i;
    scanf("%s",str);
    
    i=strlen(str)-1;
    
    for(;i>=0;i--){
        printf("%c",str[i]);
    }
    printf("\n");
    return(0);
}



Measured memory_bytes: 2044
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <string>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;

vector<LL> ver[15];
LL f[2][140][20000][2];

char str[20];

int main() {
    ver[0].push_back(1);
    for (int i = 0; i < 14; ++i) {
        for (int j = 0; j < ver[i].size(); ++j) {
            for (int k = 1; k <= 10; ++k)
                ver[i + 1].push_back(ver[i][j] * k);
        }
        sort(ver[i + 1].begin(), ver[i + 1].end());
        ver[i + 1].erase(unique(ver[i + 1].begin(), ver[i + 1].end()), ver[i + 1].end());
    }
    gets(str + 1);
    int n = strlen(str + 1);
    reverse(str + 1, str + 1 + n);
    int S = 0;
    LL P = 1;
    for (int i = 1; i <= n; ++i) {
        int tmp = str[i] - '0';
        S += tmp;
        P *= tmp + 1;
    }
    int cur = 0, nex = 1;
    f[cur][0][0][1] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= S; ++j)
            for (int k = 0; k < ver[i].size(); ++k)
                for (int l = 0; l < 2; ++l)
                    f[nex][j][k][l] = 0;
        int ch = str[i] - '0';
        for (int j = 0; j <= S; ++j)
            for (int k = 0; k < ver[i - 1].size(); ++k)
                for (int l = 0; l < 2; ++l)
                    if (f[cur][j][k][l]) {
                        for (int p = 0; p < 10; ++p) {
                            if (j + p > S) continue;
                            int j1 = j + p;
                            int k1 = lower_bound(ver[i].begin(), ver[i].end(), ver[i - 1][k] * (p + 1)) - ver[i].begin();
                            int l1 = l;
                            if (p > ch) l1 = 1;
                            if (p < ch) l1 = 0;
                            f[nex][j1][k1][l1] += f[cur][j][k][l];
                        }
                    }
        swap(cur, nex);
    }
    LL ans = 0;
    for (int j = 0; j <= S; ++j)
        for (int k = 0; k < ver[n].size(); ++k)
            for (int l = 0; l < 2; ++l) {
                if (j != S) {
                    ans += f[cur][j][k][l];
                }
                else {
                    if (ver[n][k] != P) {
                        if (ver[n][k] < P) ans += f[cur][j][k][l];
                    }
                    else if (l == 0) ans += f[cur][j][k][l];
                }
            }
    cout << ans << endl;
}

Measured memory_bytes: 86780
n,m = [int(i) for i in input().split()]
ab = []
for i in range(n):
  a = [int(i) for i in input().split()]
  ab.append(a)
from operator import itemgetter
ab = sorted(ab,key=itemgetter(0))

ans = 0
for i in ab:
  if m>i[1]:
    ans += i[0]*i[1]
    m -= i[1]
  else:
    ans += i[0]*m
    break
print(ans)

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

int main(){
  int x;
  scanf("%d",&x);
  
  int ureshisa = 0;
  int have500Yen = 0;
  int have5Yen = 0;
   //500円集計
   have500Yen = x / 500;
   x -= 500 * have500Yen;
   ureshisa += 1000 * have500Yen;
    
   //5円集計
   have5Yen = x / 5;
   ureshisa += 5 * have5Yen;
  
  printf("%d", ureshisa);
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	int result = 0;
	for (int i = 1; i <= N; i++)
	{
		result += i;
	}

	cout << result;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
const int N = 210;
int dp[N][N];

int gcd(int a, int b){
	if(dp[a][b]) return dp[a][b];
  	if(dp[b][a]) {
    	dp[a][b] = dp[b][a];
      	return dp[a][b];
    }
    else{
        if(a % b == 0){
            dp[a][b] = b;
            dp[b][a] = b;
            return b;
        }else{
            int aaaa = gcd(b, a - (a / b) * b);
            dp[a][b] = aaaa;
            dp[b][a] = aaaa;
            return aaaa;
        }

    }
}

int main(){
  int k;
  cin >> k;
  for(int i = 1; i <= k; i ++){
  	for(int j = 1; j <= i; j ++){
    	gcd(i, j);
    }
  }
  long long res = 0;
  for(int i = 1; i <= k; i ++){
  	for(int j = 1; j <= k; j ++){
    	for(int m = 1; m <= k; m ++){
        	res += dp[dp[i][j]][dp[j][m]];
        }
    }
  }
 cout << res;
}

Measured memory_bytes: 3320
import copy
h, w, K  = map(int, input().split())
c = []
for i in range(h):
    r = list(input())
    c.append(r)

def count(A):
    ret = 0
    for r in A:
        ret += r.count("#")
    return ret
ans = 0

for bit in range(1<<(h+w)):
    tmp = copy.deepcopy(c)
    for j in range(h+w):
        if (bit&(1<<j)):
            # print(j)
            # 行方向
            if j < h:
                for k in range(w):
                    tmp[j][k] = "a"
            # 列方向
            else:
                for k in range(h):
                    tmp[k][j-h] = "a"
    x = count(tmp)
    if count(tmp) == K:
        ans += 1
print(ans)

Measured memory_bytes: 9376
package main
import (
    "fmt"
    "math"
)

var zero = make(map[int]float64)
var one  = make(map[int]float64)

func main(){
    var N, K int
    var s string
    fmt.Scan(&N, &K, &s)
    fmt.Println(search(s, N, K))
}

func search(s string, N, K int) float64{
    padding(s, N, K)
    var ans, count float64
    for i, n:=0, 1; i<=len(zero); i++{
        if i == 0{
            if s[0] == 49 {
                count += one[K] + zero[K]
                n = 0
            }
            for j:=0; j<K; j++{
                count += zero[i+j] + one[i+j]
            }
        } else {
            count += zero [i+K-n] + one[i+K-n] - zero[i-n] - one[i-1-n]
        }
        
        ans = math.Max(ans, float64(count))
    } 
    return ans
}

func padding(s string, N, K int){
    for i, now:= 0, 0; now<N; i++ {
        for now < N && s[now] == 48{
            zero[i]++
            now ++
        }
        for now < N && s[now] == 49{
            one[i]++
            now ++
        }
    }
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef deque<int> di;
typedef pair<int,int> pi;
#define pb push_back
#define mp make_pair
#define mh make_heap
#define pf push_front
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define FOR(i,a,b) for(ll i=a;i<b;i++)


int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    string s;
    cin>>s;
    ll best=0,count_=0,flag=0;

        if(s[0]=='R' && s[1]=='R' && s[2]=='R')
            cout<<3<<endl;
        else if((s[0]=='R'&& s[1]=='R') || (s[1]=='R'&& s[2]=='R'))
            cout<<2<<endl;
        else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
            cout<<1<<endl;
        else
            cout<<0<<endl;



    return 0;
}


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

int main()
{
  char sin[4];
  int s[4];

  for(int i = 0; i < 4; i++){
    cin >> sin[i];
    s[i] = sin[i] - '0';
  }

  bool yymm = false;
  bool mmyy = false;

  int yy = s[0] * 10 + s[1];
  int mm = s[2] * 10 + s[3];

  if(0 < yy && yy <= 12) mmyy = true;
  if(0 < mm && mm <= 12) yymm = true;

  if(yymm && mmyy){
    cout << "AMBIGUOUS" << endl;
  }

  else if(yymm){
    cout << "YYMM" << endl;
  }

  else if(mmyy){
    cout << "MMYY" << endl;
  }

  else{
    cout << "NA" << endl;
  }

  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		//入力導入部
		Scanner sc=new Scanner(System.in);
		
		
		while(true){
		int m=sc.nextInt();
		int f=sc.nextInt();
		int r=sc.nextInt();
		if(m==-1&&f==-1&&r==-1)break;
		//成績部分
		else{int t=m+f;
			
			if(m==-1||f==-1)System.out.println("F");
			else if(t>=80)System.out.println("A");
			else if(t>=65)System.out.println("B");
			else if(t>=50)System.out.println("C");
			else if(t>=30)System.out.println(r>=50?"C":"D");
			else System.out.println("F");
		}
		}sc.close();

	}

}

Measured memory_bytes: 19272
#include                          <bits/stdc++.h>
#define     lli                   unsigned long long int
#define     ll                    long long int
#define     PI                    acos(-1.0)
#define     UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define     timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     ALL(V)                (V).begin(), (V).end()
#define     MEMSET(a, val)        memset(a, val, sizeof(a))
#define     FILE_INPUT            freopen("input.txt", "r", stdin) , freopen("output.txt", "w", stdout)
#define     DEBUG                 printf("---- ekhane asi ekhon ---- \n");
#define     SQR(x)                ((x)*(x))
using       namespace             std;


template    <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template    <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }
template    <class T> T POW(T x, T n) { if(n == 0) return 1; if(n&1) return x*POW(x, n-1);  else return SQR(POW(x, n/2));}

long long   Bigmod(long long base, long long power, long long MOD) {long long ret = 1; while(power) {if(power & 1) ret = (ret*base)%MOD; base = (base*base)%MOD; power >>= 1;} return ret;}
bool        isVowel(char ch) {ch = toupper(ch); if(ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E') return true; return false;}
long long   ModInverse(long long number, long long MOD) {return Bigmod(number, MOD-2, MOD);}
bool        isConst(char ch) {if(isalpha(ch) && !isVowel(ch)) return true; return false;}
int         toInt(string s)  {int si; stringstream ss(s); ss >> si; return si;}

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


//------------------- Let`s Start ------------------------ //


int main()
{
    timesave;

    int n, d, x, a;

    cin >> n;
    cin >> d >> x;

    int total = x;

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

        total += (d-1) / a;
        total++;
    }

    cout << total << endl;


	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int n,a,b;
int ans=0;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		int p=i,s=0;
		{
			while(p)
			{
				s+=p%10;
				p=p/10;
			}
		}
		if(s>=a&&s<=b)ans+=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  vector<ll> t(100001);
  FOR(i,2,100001) {
    ll m = 1;
    bool ok = false;
    for(int k = 2; k*k <= i; ++k) {
      if ((i%k) == 0) {
        if (k*k < i) {
          m *= i;
        } else {
          m *= k;
        }
        if (m >= 2*i) ok = true;
      }
    }
    if (ok) {
      t[i] = t[i-1] + 1;
    } else {
      t[i] = t[i-1];
    }
  }
  int q;
  cin>>q;
  REP(i,q) {
    int n;
    cin>>n;
    cout<<t[n]<<endl;
  }
  return 0;
}



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

int main() {
  int k,n;
  cin >> k>>n;
  vector<int> v(n);
  rep(i,n){
    cin >> v.at(i);
  }
  vector<int> vec(n);
  vec.at(n-1) = abs(k - v.at(n-1) + v.at(0));
  
  rep(i,n-1){
    vec.at(i) = abs(v.at(i) -v.at(i+1));
  }
  
  vector<int> sum(n);
  rep(i,n){
    sum.at(i) = k - vec.at(i);
  }
  sort(sum.begin(),sum.end());
  cout << sum.at(0) << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

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

  int ans = 100000;
  int tmp;
  int sum1 = 0, sum2 = 0;
  for ( int t = 1; t < n; ++t ) {
    sum1 = 0;
    sum2 = 0;
    for ( int i = 0; i < n; ++i ) {
      if( i <= t ) sum1 += w[i];
      else sum2 += w[i];
    }
    tmp = sum2 - sum1;
    ans = min( ans, abs(tmp) );
  }

  cout << ans << '\n';

  return 0;
}

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

long long mod=1000000007LL;

template<typename T>
constexpr T modpow(T a,T n){//(a^n)%MOD
    T ret=1;
    while(n>0){
        if((n&1)!=0){//n%2==1
            ret=ret*a%mod;
        }
        a=a*a%mod;
        n=n/2;
    }
    return ret;
}

std::vector<long long> fac;
std::vector<long long> ifac;

//long long mod=1000000007LL;

template <typename T>
T modcomb(T a, T b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    long long tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

void combinit(int maxn){
    fac.resize(maxn);
    ifac.resize(maxn);
    fac[0] = 1;
    ifac[0] = 1;
    for(long long i = 0; i<maxn; i++){
        fac[i+1] = fac[i]*(i+1) % mod;
        ifac[i+1] = ifac[i]*modpow(i+1, mod-2) % mod;
    }
}

using namespace std;
using ll=long long;

int main(){
    ll n,k;
    cin>>n>>k;
    combinit(2*n);
    if(n-1<=k)cout<<modcomb(2*n-1,n-1)<<endl;
    else{
        ll ans=0;
        for (ll i = 0; i <= k; ++i) {
            ans+=modcomb(n-1,i)*modcomb(n,i);
            ans%=mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

void open(vi a){
	cout<<a[0];
	for(int i=1;i<a.size();i++) cout<<' '<<a[i];
	cout<<endl;
}

int n;
vi p,a,b;

int main(){
	cin>>n;
	p=a=b=vi(n);
	for(int i=0;i<n;i++) cin>>p[i];
	for(int i=0;i<n;i++) a[i]=b[n-i-1]=40000*(i+1);
	for(int i=0;i<n;i++){
		b[p[i]-1]+=i;
	}
	open(a);
	open(b);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int A;
  cin >> A;
  set<int> s;
  int a = A;
  int m = 1;
  while(!s.count(a)){
    s.insert(a);
    if(a %2 == 0) {
      a /= 2;
    }
    else {
      a = 3*a + 1;
    }
    m++;
  }
  cout << m << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N, M;

vector<int> k;
vector<int> s;
vector<int> p;

int anser = 0;

bool chika(int i, string num){
    
    
    
    if(i == N){
        
        int fff = 0;
        int stop = 0;
        //cout << num << endl;//
        for (int l = 0; l < M; l++) {
            
            int su = 0;
            
            
            for (int ll = fff; ll < fff+k[l]; ll++) {
                
                //cout << "aa "  << s[ll] << "a " <<atoi((num.substr(s[ll]-1,1)).c_str()) << endl;//
                su += atoi((num.substr(s[ll]-1,1)).c_str());
                
            }
            
            fff += k[l];
            
            //cout << su << endl;//
            
            if (su%2 != p[l]) {
                stop = 10;
                break;
            }
            
            
            
            
        }
        
        
        if (stop == 0) {
            anser += 1;
           // cout << num << endl;//
        }
        
        
        
        return false;
    }
    
    
    if(chika(i+1, num+"0")){
        return true;
    }
    
    if (chika(i+1, num+"1")) {
        return true;
    }
    
    
    return false;
}








int main(){
    
    cin >> N >> M;
    vector<int> kk(M);
    vector<int> ss;
    vector<int> pp(M);
    
    

    
    for (int i = 0; i < M; i++) {
        cin >> kk[i];
        k.push_back(kk[i]);
        for (int j = 0; j < k[i]; j++) {
            int sss;
            cin >> sss;
            ss.push_back(sss);
        }
        
    }
    for (int i = 0; i < ss.size(); i++) {
        
        s.push_back(ss[i]);
    }
    
    for (int i = 0; i < M; i++) {
        cin >> pp[i];
        p.push_back(pp[i]);
    }
    
    
    
    chika(0, "");
    
    
    cout << anser << endl;
    
    
    
    return 0;
    
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

priority_queue<int> pq;
vector<vector<int> > d;
int main(void){
  int ans = 0;
  int n, m;
  cin >> n >> m;
  d.resize(m+1);
  rep(i,n){
    int a, b;
    cin >> a >> b;
    if(m-a >= 0){
        d[m-a].push_back(b);
    }
  }
  for(int dd = m; dd >= 0; --dd){
    rep(i, d[dd].size()){
      pq.push(d[dd][i]);
    }
    if(!pq.empty()){
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5504
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <math.h>
using namespace std;


int main() {
	int N;
	cin >> N;
	int* arr = new int[N];
	int* look = new int[N];

	for (int i = 0; i < N; ++i)
	{
		cin >> arr[i];
		look[i] = 0;
	}
	long long ans = 0;
	for (int i = 0; i < N-1 ; ++i)
	{
		if(i+arr[i]<N)
			look[i + arr[i]]++;
	}
	for (int i = N - 1; i > 0; --i)
	{
		if (i-arr[i]>=0 )
		{
			ans+=look[i-arr[i]];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5200
#include<stdio.h>
int F[45];
int Fi(int num){
  if(num < 2){
    return (1);
  }
  else if(0 < F[num]){
    return F[num];
}
  F[num] = Fi(num - 1) + Fi(num - 2);
  return F[num];
    }
int main(){
  int length;
  scanf("%d",&length);
  printf("%d\n",Fi(length));
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int isprime(int );

int main(){

int i,n,sum,a[10000];
scanf("%d",&n);
for(i = 1 ;i <= n; i++){
scanf("%d",&a[i]);
if(isprime(a[i]) == 1) sum++;
}
printf("%d\n",sum);

return 0;
}

int isprime(int x){
  int i;

if(x == 2) return 1;

if(x < 2 || x%2 == 0) return 0;

i = 3;
while(i <= sqrt(x)){
if(x%i == 0) return 0;
i = i+2;
}
return 1;
}

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

using namespace std;

int main(void)
{
	string a,b;
	cin >> a >> b;
	if(a.size()>b.size())
	{
		cout << "GREATER" << endl;
		return 0;
	}
	if(a.size()<b.size())
	{
		cout << "LESS" << endl;
		return 0;
	}
	for(int i=1;i<=a.size();i++)
	{
		if(a[i-1]>b[i-1])
		{
			cout << "GREATER" << endl;
			return 0;
		}
		if(a[i-1]<b[i-1])
		{
			cout << "LESS" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000000000010000;

ll kai[100010];
ll bit[700010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 700005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

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

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

ll N, X, D;
vector<P> range[200010];
map<ll, ll> MOD;
ll cnt;
ll ans;

void solve() {
	cin >> N >> X >> D;
	if (D < 0) {
		D *= -1;
		X -= (N - 1) * D;
	}
	if (D == 0) {
		if (X == 0) {
			cout << 1 << endl;
		}
		else {
			cout << N + 1 << endl;
		}
		return;
	}

	for (ll k = 0; k <= N; k++) {
		ll x = X * (2 * k - N);
		ll sma, lar;
		if (k == 0) {
			sma = x - N * (N - 1) / 2 * D;
			lar = sma;
		}
		else if (k == N) {
			sma = x + N * (N - 1) / 2 * D;
			lar = sma;
		}
		else {
			sma = x + (k * (k - 1) / 2 - (N - k) * (N + k - 1) / 2) * D;
			lar = x + ((2 * N - k - 1) * k / 2 - (N - k) * (N - k - 1) / 2) * D;
		}

		ll j;
		if (lar < 0) {
			j = 2 * D - ((-1 * lar) % (2 * D));
			j %= 2 * D;
		}
		else {
			j = lar % (2 * D);
		}
		ll S = (sma - j) / (2 * D);
		ll T = (lar - j) / (2 * D);
		if (MOD[j] == 0) {
			cnt++;
			MOD[j] = cnt;
		}
		range[MOD[j]].push_back(P(S, T));
	}
	for (ll i = 1; i <= N + 1; i++) {
		if (range[i].size() == 0) break;
		sort(range[i].begin(), range[i].end());
		ll lar = -INF;
		for (P p: range[i]) {
			ll a = p.f, b = p.s;
			if (lar < a) {
				ans += b - a + 1;
				lar = b;
			}
			else if (lar < b) {
				ans += b - lar;
				lar = b;
			}
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}
////////////////////////////////////////////////////////////////////////////////////////////jagfhaoi;sd;joi;asdfjzasdi;lfjoi;ernjsdoivcnoizvdfnvdfnon/////////////////////////////////////////////////////////
////////////////////jgoiadhsjgoi;vsjvgfonhjasoivhoivhno

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

int main(){
    ll n;
    cin >> n;
    vector<int> ns(n);
    rep(i, n){
        cin >> ns.at(i);
    }
    sort(ns.begin(), ns.end());
    int sum = 0;
    rep(i, n-1) if(ns.at(i) == ns.at(i+1)) sum++;
    cout << n - sum - sum%2 << endl;
    return 0;
}

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

int main(){
        int n,m,i,l_pre,r_pre,l,r;
        cin >> n >> m;
        cin >> l_pre >> r_pre;
        for(i=1;i<m;++i){
                cin >> l >> r;
                if(r<r_pre) r_pre = r;
                if(l>l_pre) l_pre = l;
        }
        if(l_pre>r_pre) r_pre = l_pre-1;
        cout << r_pre-l_pre+1 << endl;
        return 0;
}

Measured memory_bytes: 3580
package main

import "fmt"

func diff(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func dist(x1, y1, x2, y2 int) int {
	return diff(x1, x2) + diff(y1, y2)
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]int, n)
	bs := make([]int, n)
	cs := make([]int, m)
	ds := make([]int, m)
	for i := range as {
		fmt.Scan(&as[i], &bs[i])
	}
	for i := range cs {
		fmt.Scan(&cs[i], &ds[i])
	}

	for i := range as {
		a := as[i]
		b := bs[i]
		min := dist(a, b, cs[0], ds[0])
		min_j := 0
		for j := range cs {
			c := cs[j]
			d := ds[j]
			if v := dist(a, b, c, d); v < min {
				min = v
				min_j = j
			}
		}
		fmt.Println(min_j + 1)
	}
}


Measured memory_bytes: 512