akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
#define SIZE(v) int(v.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	ll N;
	cin >> N;
	vector<P> p_fact;
	ll n = N - 1;
	for (ll K = 2;K * K <= n;++K) {
		if (n % K) continue;
		p_fact.emplace_back(K, 0);
		while (n % K == 0) {
			n /= K;
			p_fact.rbegin()->second++;
		}
	}
	if (n > 1) p_fact.emplace_back(n, 1);
	ll res = 1;
	for (auto &p : p_fact) {
		res *= p.second + 1;
	}
	for (ll K = 2;K * K <= N;++K) {
		if (N % K) continue;
		ll m = N;
		while (m % K == 0) m /= K;
		if (m % K == 1) ++res;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a[100005];
ll dp[100005];

ll fun(ll p)
{
    if(p==n-1)
    {
        return 0;
    }
    if(p>=n)
    {
        return INT_MAX;
    }
    if(dp[p]!=-1)
    {
        return dp[p];
    }
    ll l=abs(a[p]-a[p+1])+fun(p+1);
    ll r=INT_MAX;
    if((p+2)<n)
    {
        r=abs(a[p]-a[p+2])+fun(p+2);
    }
    return dp[p]=min(r,l);
}

int main() {
  
    ll i;
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        
    }
    cout<<fun(0);

   
return 0;
}

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

typedef long long ll;

using namespace std;

ll mem[2][100005];
ll sizes[105];
ll vals[105];

ll max_size;
ll dp(ll N, ll S)
{
    for(int i=1; i<=N; i++)
    {
        for(int s=0; s<=S; s++)
        {
            if(sizes[i-1] <= s)
                mem[i%2][s] = max(mem[(i-1)%2][s],
                                  mem[(i-1)%2][s-sizes[i-1]] + vals[i-1]);
            else
                mem[i%2][s] = mem[(i-1)%2][s];
        }
    }
    return mem[N%2][S];
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    ll n; cin >> n >> max_size;
    for(int i=0; i<n; i++)
        cin >> sizes[i] >> vals[i];
    cout << dp(n, max_size) << endl;
}


Measured memory_bytes: 1792
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll a,b;
  std::cin>>a>>b;

  if(b==1){
    std::cout<<0;
  }else{
    std::cout<<(b-2)/(a-1)+1;
  }

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;


/* range: ± 3.27 * 10^4 */
using i16 = short int;
/* range: 0 to 65535 */
using u16 = short unsigned int;
/* range: ± 2.14 * 10^9 */
using i32 = int;
/* range: 0 to 4.29 * 10^9 */
using u32 = unsigned int;
/* range: ± 9.22 * 10^18 */
using i64 = long long int;
/* range: 0 to 1.84 * 10^19 */
using u64 = long long unsigned int;


static constexpr i32 MAX = 1e9 + 7;

array<array<i32, 101>, 100007> memo;
i32 knapsackRecur(const vector<i32>& w, const vector<i32>& v, i32 val,
                  i32 idx = 0) {
    if (val <= 0) {
        return 0;
    }

    if (idx == w.size()) {
        return MAX;
    }

    if (memo[val][idx] != -1) {
        return memo[val][idx];
    }

    memo[val][idx] = min(knapsackRecur(w, v, val, idx + 1),
                         w[idx] + knapsackRecur(w, v, val - v[idx], idx + 1));

    return memo[val][idx];
}

i32 knapsack2(const vector<i32>& w, const vector<i32>& v, i32 capacity,
              i32 max_val) {
    for (; max_val > 0; max_val--) {
        if (knapsackRecur(w, v, max_val) <= capacity) {
            return max_val;
        }
    }
    return 0;
}

i32 main() {
    i32 items = 0, capacity = 0;
    cin >> items >> capacity;

    i32 max_val = 0;
    vector<i32> w(items), v(items);
    for (i32 i = 0; i < items; i++) {
        cin >> w[i] >> v[i];
        max_val += v[i];
    }

    memo[0].fill(-1);
    memo.fill(memo[0]);

    cout << knapsack2(w, v, capacity, max_val) << '\n';
}

Measured memory_bytes: 43096
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m,ans,r;
    ans=1;
    r=1;
    cin>>n>>m;
    int b[n]={};
    ll f[n+3];
    f[0]=0;
    f[1]=1;
    f[2]=1;
    fr(i,n+1){
        f[i+2]=f[i]+f[i+1];
        f[i+2]%=1000000007;
    }
    fr(i,m){
        int h;
        cin>>h;
        b[h-1]=1;
    }
    fr(i,n){
        if(b[i]){
            ans*=f[r];
            ans%=1000000007;
            r=0;
        }
        else{
            ++r;
        }
    }
    ans*=f[r];
    ans%=1000000007;
    cout<<ans;
}

Measured memory_bytes: 4736
#include <iostream>

using namespace std;

int main() {
 string s;
 int a, b, c, z;
 int digit = 10;
 cin >> a >> b;
 z = b;

 if (b == 100) {
   digit = 1000;
 } else if (10 <= b && b <= 99) {
   digit = 100;
 } else if (0 <= b && b <= 9) {
   digit = 10;
 }

 c = digit * a + b;

 for (int factor = 1; factor < c; factor = factor + 1) {
   if (factor * factor == c) {
     printf("Yes");
     return 0;
   }
 }

 printf("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10 , M = 5e5+10 ,  MOD = 1e9+7;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-3;
#define M_PI 3.14159265358979323846
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define pb push_back
#define F first
#define S second
#define all(v) ((v).begin()) , ((v).end())
#define sz(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 

int n, m;
char grid[105][105];
bool row[105] , col[105];



int main() {

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
	

    scanf("%d %d",&n,&m);
    for(int i = 0 ; i < n ; ++i)
        scanf("%s", grid[i]);

   
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < m ; ++j)
            if(grid[i][j] == '#')
                row[i] = 1 , col[j] = 1;
    }
   
    bool f = 0;
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < m ; ++j){
            if(row[i] && col[j]){
                printf("%c",grid[i][j]);
                f = 1;
            }
        }
        if(f)
            puts("");
        f = 0;
    }



    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <bitset>
#include <cassert>
#include <queue>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
#define get get228
const int SZ = 1e3 + 4;
const double EPS = 1e-7;
const int mod = 998244353;
const int hashpow = 127;
const int inf = 2e9;

#define kek cout << "kek"

int h, w;

void read() {
    cin >> h >> w;
}

void solve() {
    if (h == 1 || w == 1) {
        cout << 1;
        return;
    }
    cout << h * w / 2 + (h & w & 1);
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
    read();
    solve();
//    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fo(i,n) for(int i=0;i<n;i++)
#define rfo(i,n) for(int i=n-1;i>=0;i--)
#define Fo(i,q,n) for(int i=q;i<n;i++)
#define rFo(i,q,n) for(int i=n-1;i>=q;i--)
#define fO(i,n,k) for(int i=0;i<n;i+=k)
#define FO(i,q,n,k) for(int i=q;i<n;i+=k)
#define zero(a,n) memset(a,0,sizeof(a[0])*n)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
using namespace std;
const int MOD=1000000007;
void print(){cout <<endl;}
template <typename T, typename... Types> 
void print(T var1, Types... var2){cout << var1 << " " ;print(var2...) ;}
//ceil of a/b
template <typename T>
T fceil(T a,T b){return (T)(a+b-1)/b;}
//const int N=2e5;
//int arr[N+1];

ll max(ll a,ll b){
	if(a>b){return a;}
	return b;	
} 
int main(){
	int n,w;
	cin>>n>>w;
	vector<int> val(n,0);
	vector<int> wt(n,0);
	fo(i,n){
		cin>>wt[i];
		cin>>val[i];	
	}
	ll dp[n+1][w+1];
	fo(i,n+1){
		fo(j,w+1){
			if(i==0||j==0){dp[i][j]=0;continue;}
			//cout<<j<<" "<<wt[i-1]<<endl;
			if(j>=wt[i-1]){
				//cout<<"skna"<<endl;
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);	
			}
			else{
				dp[i][j] = dp[i-1][j];		
			}
		}	
	}
	//fo(i,n+1){
		//fo(j,w+1){
			//cout<<dp[i][j]<<" ";	
		//}
		//cout<<endl;	
	//}
	cout<<dp[n][w]<<endl;
	return 0;
}






/*NOTE: Take MOD after sorting and not before sorting!*/


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> t(n);
    ll total = 0;
    for(int i = 0; i < n; ++i){
        cin >> t.at(i);
        total += t.at(i);
    }

    ll m;
    cin >> m;
    vector<ll> p(m), x(m);
    for(int i = 0; i < m; ++i){
        cin >> p.at(i);
        p.at(i)--;
        cin >> x.at(i);
    }

    for(int i = 0; i < m; ++i){
        cout << total - t.at(p.at(i)) + x.at(i) << endl;
    }
    return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,l;
    cin>>n>>l;
    int sum=0;
    REP(i,n){
        sum += l+i;
    }

    int mn = INT_MAX;
    int ans;
    REP(i,n){
        int tmp = sum-(l+i);
        if(mn > abs(sum-tmp)){
            mn = abs(sum-tmp);
            ans = tmp;
        }

    }

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

Measured memory_bytes: 384
N,M,A,B=map(int,input().split())
Grid=[["."]*M for i in range(N)]
if M%2:
  for i in range(N//2):
    if B>0:
      Grid[2*i][M-1]="^"
      Grid[2*i+1][M-1]="v"
      B-=1
  
if N%2:
  for i in range(M//2):
    if A>0:
      Grid[N-1][2*i]="<"
      Grid[N-1][2*i+1]=">"
      A-=1
  
for i in range((M//2)*(N//2)):
  a,b=i//(M//2),i%(M//2)
  if A>1:
    Grid[2*a][2*b]="<"
    Grid[2*a][2*b+1]=">"
    Grid[2*a+1][2*b]="<"
    Grid[2*a+1][2*b+1]=">"
    A-=2
  elif B>1:
    Grid[2*a][2*b]="^"
    Grid[2*a][2*b+1]="^"
    Grid[2*a+1][2*b]="v"
    Grid[2*a+1][2*b+1]="v"
    B-=2
  else:
    if A==1:
      Grid[2*a][2*b]="<"
      Grid[2*a][2*b+1]=">"
      A-=1
    elif B==1:
      Grid[2*a][2*b]="^"
      Grid[2*a+1][2*b]="v"
      B-=1

if A==B==0:
  print("YES")
  for i in range(N):
    print("".join(Grid[i]))
else:
  if B==1 and M%2:
    if Grid[N-1][M-1]=="." and Grid[N-1][M-2]==">" and Grid[N-2][M-2]==".":
      Grid[N-1][M-2]="<"
      Grid[N-1][M-1]=">"
      Grid[N-1][M-3]="v"
      Grid[N-2][M-3]="^"
      print("YES")
      for i in range(N):
        print("".join(Grid[i]))
    else:
      print("NO")
  else:
    print("NO")

Measured memory_bytes: 49244
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

//最大公約数
ll gcd(ll a, ll b) {
	if (a%b == 0)
		return b;
	return gcd(b, a%b);
}

ll n, m;
ll x[100000], y[100000];


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

	FOR(i, n)
		cin >> x[i];

	FOR(i, m)
		cin >> y[i];

	ll width = 0;
	FOR(i, n - 1) {
		width += (x[i + 1] - x[i]) * (n - i - 1) * (i + 1);
		width %= mod197;
	}

	ll height = 0;
	FOR(i, m - 1) {
		height += (y[i + 1] - y[i]) * (m - i - 1) * (i + 1);
		height %= mod197;
	}

	//cerr << width << " " << height << endl;

	cout << (width * height) % mod197 << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S,T;
    cin >> S;
    cin >>T;
    int cnt=0;

    for(int i=0; i<S.size(); i++) {
        if (S[i]!=T[i]){
            cnt++;

        }


    }
    cout << cnt << endl;
}

Measured memory_bytes: 3916
# -*- coding: utf-8 -*-
import math

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())

    # 素因数分解
    div_dict = {}
    nom = n
    while True:
        for denom in range(2,int(math.sqrt(nom)+1)):
            if nom % denom == 0:
                if denom in div_dict:
                    div_dict[denom] += 1
                else:
                    div_dict[denom] = 1
                nom /= denom
                break
        else:
            if nom in div_dict:
                div_dict[nom] += 1
            else:
                div_dict[nom] = 1
            break

    if 1 in div_dict:
        del div_dict[1]

    ans = 0
    for elem in div_dict.values():
        tgt = elem
        sub = 0
        while sub < tgt:
            ans += 1
            sub += 1
            tgt -= sub

    print(ans)

# else:
    # do nothing

Measured memory_bytes: 9292
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n;string s;
    std::cin >> n>>s;
    int ans=0;
    rep(i,n){
        string a,b;
        a=s.substr(0,i+1);
        b=s.substr(i+1,n-i-1);
        std::vector<int> aa(26,0),bb(26,0);
        rep(j,a.size()){
            aa[a[j]-'a']++;
        }
        rep(j,b.size()){
            bb[b[j]-'a']++;
        }
        int dum=0;
        rep(j,26){
            if(aa[j]&&bb[j])dum++;
        }
        ans=max(ans,dum);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define VI  vector<ll>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
const ll mod=1e9+7;
double pi = 2 * acos(0.0);
#define FASTIO ios_base::sync_with_stdio(false);cout.tie(NULL);cout.tie(NULL);
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
bool cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return (a.first)<(b.first);
}
ll power(ll a,ll b)
{
        ll p=1;
        for(ll i=1;i<=b;i++)
        p*=a;

        return p;
}
ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
 }
void bfs(map<ll,vector<ll> > &g,ll src,vector<ll> &c)
{
    queue<ll> q;
    map<ll,ll> p;
    q.push(src);
    p[src]=src;
    c[src]=1;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        ll i=1;
        for(auto v:g[u])
        {
            if(c[v]==-1)
            {
                q.push(v);
                p[v]=u;
                if(i==c[u]||i==c[p[u]])
                    i++;
                if(i==c[u]||i==c[p[u]])
                    i++;
                c[v]=i;
                i++;
            }
        }
    }
}
ll dp[100005][3],a[100005][3],n;
ll fun(ll N, char x)
{
    if(N==0) return 0;
    if(dp[N][x-'a']!=-1) return dp[N][x-'a'];
    ll ans=INT_MIN;
    if(x!='a') ans=max(ans,a[N-1][0]+fun(N-1,'a'));
    if(x!='b') ans=max(ans,a[N-1][1]+fun(N-1,'b'));
    if(x!='c') ans=max(ans,a[N-1][2]+fun(N-1,'c'));
    return dp[N][x-'a']=ans;
}
int main()
{
    FASTIO;
    ll i,j;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    cout<<fun(n,'d')<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)
int n,M[MAX][MAX];

int prim(){
  int u,minv,i,v,sum=0;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    if(p[i]!=-1) sum=sum+M[i][p[i]];
  }
  
  return sum;
}
  
int main()
{
  int i,j;
  int e;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1) M[i][j]=INFTY;
      else M[i][j]=e;
    }
  }

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

  return 0;
}

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


int main(){
  double rad;
  double x;
  double y;
  int done;
  int d;
  int t;
  double pi;

  done = 0;
  pi = M_PI;

  rad = pi/2.0;
  x = 0.0;
  y = 0.0;
  while(!done){
    scanf("%d,%d", &d, &t);
    if ((d == 0) && (t == 0)){
      break;
    }
    x += d*cos(rad);
    y += d*sin(rad);
    rad -= pi*t/180; //input is clockwise. rad is ccw
  }
  printf("%d\n", (int)x);
  printf("%d\n", (int)y);

  return 0;
}

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

int main() {

    int N , M ;

    cin >> N >> M;

    vector<int> vec(M) ;

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

        cin >> vec[i] ;

    }

    int day = 0 ;

    for ( int i = 0 ; i < M ; i++ ) day += vec[i] ;

    if ( N - day >= 0) {

        cout << N - day << endl ;

    }

    else {cout << "-1" << endl ;

    }

}


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

using namespace std;

long long N, H;
long long b[100010], a = 0;

int main() {
  int i;
  scanf("%lld %lld", &N, &H);
  long long sum = 0;
  for (i = 0; i < N; i++) {
    long long k;
    scanf("%lld %lld", &k, &b[i]);
    a = max(a, k);
  }
  sort(b, b+N);
  /*for (i = 0; i < N; i++) {
    printf("a:%d b:%d", a[i], b[i]);
    }*/
  long long ans = 0;
  for (i = N-1; i >= 0 && b[i] > a; i--) {
    H -= b[i];
    ans += 1;
    if (H <= 0) {
      break;
    }
  }
  //printf("after_b:%d", ans);
  if (H >= 0) {
    long long num_a = H / a;
    ans += num_a;
    if (H % a > 0) {
      ans += 1;
    }
  }
  printf("%lld", ans);
  return 0;
}
  

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int n, m;
    cin >> n >> m;

    vector<bool> check(n, false);
    vector<int> box(n, 1);

    check[0] = true;
    roop(i, m){
        int a, b;
        cin >> a >> b;
        box[a-1]--;
        box[b-1]++;
        if(check[a-1]) check[b-1] = true;
        if(box[a-1] == 0) check[a-1] = false;
    }


    int ans = 0;
    roop(i, n) if(box[i] > 0 && check[i]) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
n,m = map(int, input().split())
link = [[] for _ in range(n)]
inc=[0]*n
for _ in range(m):
    x,y = list(map(int,input().split()))
    link[x-1].append(y-1)
    inc[y-1]+=1

s=[]
for i in range(len(inc)):
    if inc[i]==0:
        s.append(i)
res=[]
while s:
    nxt=s.pop()
    res.append(nxt)
    for m in link[nxt]:
        inc[m]-=1
        if inc[m]==0:
            s.append(m)

path=[-1]*n
for now in res:
    if path[now]==-1:
        path[now]=0
    for nxt in link[now]:
        path[nxt] = max(path[nxt],path[now]+1)

print(max(path))

Measured memory_bytes: 64160
#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;

void printList(list<int> l){
  int i = 0;
  for (list<int>::iterator it = l.begin(); it != l.end(); it++){
    if(i++) printf(" ");
    printf("%d", *it);
  }
  printf("\n");
}

int main()
{
  int n, val;
  char order[12];
  scanf("%d", &n);

  list<int> seq;
  for (int i = 0;i<n;i++){
    scanf("%s", order);
    if (order[6] == 'F') seq.pop_front();
    else if (order[6] == 'L') seq.pop_back();
    else
    {
      scanf("%d", &val);
      if (order[0] == 'i') seq.push_front(val);
      else {
        auto itr = find(seq.begin(), seq.end(), val);
        if (itr == seq.end()) continue;
        seq.erase(itr);
      }
    }
  }

  printList(seq);
  return 0;
}

Measured memory_bytes: 34044
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var S = ReadLine();

        var first = S[0..2];
        var second = S[2..4];

        bool IsYY(string s) => ('0' <= s[0] && s[0] <= '9') && ('0' <= s[1] && s[1] <= '9');
        bool IsMM(string s) => ('0' == s[0] && '1' <= s[1] && s[1] <= '9') || ('1' == s[0] && '0' <= s[1] && s[1] <= '2');

        var pattern = (IsMM(first) ? 1 : 0) + (IsMM(second) ? 2 : 0);
        var ans = pattern switch {
            0 => "NA",
            1 => "MMYY",
            2 => "YYMM",
            3 => "AMBIGUOUS"
        };

        WriteLine(ans);
    }
}


Measured memory_bytes: 25780
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.ST            (ST)
import           Data.Bits                   (shiftL, shiftR, testBit, (.&.))
import qualified Data.ByteString.Char8       as BC
import           Data.Maybe                  (fromJust)
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM


main :: IO ()
main = do
  n <- readLn
  as <- getInts
  bs <- getInts
  print $ solve n as bs

solve :: Int -> [Int] -> [Int] -> Int
solve n as bs = sum $ map kXorBit [0 .. 28] where
  bv = V.fromList bs
  kXorBit k = if odd s then t else 0 where
    t = 1 `shiftL` k
    t2 = 1 `shiftL` (k + 1)
    cs = sort' $ V.map modT2 bv
    s = sum $ map count as
    mask = t2 - 1
    modT2 = (mask .&.)
    count a = (t12 - t01) + (n - t23) where
      t01 = binarySearch cs $ t - a'
      t12 = binarySearch cs $ t2 - a'
      t23 = binarySearch cs $ 3 * t - a'
      a' = modT2 a

binarySearch :: V.Vector Int -> Int -> Int
binarySearch xs y = go 0 $ V.length xs where
  go l r
    | l == r = l
    | x < y = go (m + 1) r
    | x >= y = go l m
    where m = (r + l) `shiftR` 1
          x = xs `V.unsafeIndex` m

odd' :: Int -> Bool
odd' n = testBit n 0

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine

sort' :: V.Vector Int -> V.Vector Int
sort' = V.modify (\v -> quicksort v 0 (VM.length v))

-- https://github.com/as-capabl/haskell-qsort-pfm/blob/master/src/UV.hs
type IndType = Int

quicksort :: VM.STVector s Int -> IndType -> IndType -> ST s ()
quicksort work iStart iEnd
    | iEnd - iStart <= 1 = return ()
    | otherwise =
      do
        pivot <- VM.unsafeRead work ((iEnd + iStart) `shiftR` 1)
        med <- divide pivot iStart (iEnd - 1)
        quicksort work iStart med
        quicksort work med iEnd
  where
    divide pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise =
          do
            lower <- shrinkLower pivot iS' iE'
            higher <- shrinkHigher pivot lower iE'
            if lower >= higher
              then do
                return lower
              else do
                swapWork lower higher
                divide pivot (lower + 1) (higher - 1)

    shrinkLower pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise =
          do
            x <- VM.unsafeRead work iS'
            if x >= pivot
              then
                return iS'
              else
                shrinkLower pivot (iS' + 1) iE'

    shrinkHigher pivot iS' iE'
        | iS' > iE' = return iE'
        | otherwise =
          do
            x <- VM.unsafeRead work iE'
            if x <= pivot
              then
                return iE'
              else
                shrinkHigher pivot iS' (iE' - 1)

    swapWork i j = VM.unsafeSwap work i j


Measured memory_bytes: 37116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		boolean[] primes = new boolean[50001];
		Arrays.fill(primes, true);

		for (int i = 2; i < 50001; i++) {
			if (primes[i]) {
				for (int j = 2; j <= 50000 / i; j++) {
					primes[i * j] = false;
				}
			}
		}

		while (!(line = br.readLine()).equals("0")) {

			int n = Integer.parseInt(line);
			int c = 0;

			for (int i = 2; i <= n / 2; i++) {
				if (primes[i] && primes[n - i]) {
					c++;
				}
			}
			System.out.println(c);
		}

	}

}

Measured memory_bytes: 26008
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
ll n, m;
ll dap = 0;
ll ch1 = 0;
char a[100010];
ll sum[65];
vector<ll> vt;
struct Trie {
	bool finished;
	ll gap;
	Trie *next[2];
	Trie()
	{
		finished = 0;
		gap = 0;
		memset(next, 0, sizeof(next));
	}
	~Trie()
	{
		for (ll i = 0; i < 2; i++)
			if (next[i])
				delete next[i];
	}
	void insert(const char *key)
	{
		if (*key == '\0')
		{
			finished = 1;
			return;
		}
		else {
			ll curr = *key - '0';
			if (!next[curr]) {
				gap++;
				next[curr] = new Trie();
			}
			next[curr]->insert(key + 1);
		}
	}
	void find(ll depth)
	{
		if (!finished) {
			for (ll i = 0; i < 2 - gap; i++)
			{
				vt.push_back(m - depth);
			}
		}
		for (ll i = 0; i < 2; i++)
		{
			if (next[i])
				next[i]->find(depth + 1);
		}
	}
};
int main()
{
	Trie root;
	scanf("%lld %lld", &n, &m);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", a);
		root.insert(a);
	}
	root.find(0);
	for (int y = 0; y < vt.size(); y++)
	{
		for (ll i = 0; i < 64; i++)
		{
			if (((ll)1<<i)&vt[y])
			{
				sum[i]++;
				break;
			}
		}
	}
	for (int i = 0; i < 64; i++)
	{
		if (sum[i] % 2)
			dap = 1;
	}
	if (dap)puts("Alice");
	else puts("Bob");
}


Measured memory_bytes: 8820
l = [input() for i in range(3)]

s_a_count = 0
s_b_count = 0
s_c_count = 0

tmp = l[0][0] # 最初の文字
s_a_count += 1

while True:
    if tmp=='a':
        if s_a_count == len(l[0]):
            ans = 'A'
            break
        else:
            tmp = l[0][s_a_count]
            s_a_count += 1
    if tmp=='b':
        if s_b_count == len(l[1]):
            ans = 'B'
            break
        else:
            tmp = l[1][s_b_count]
            s_b_count += 1
    if tmp=='c':
        if s_c_count == len(l[2]):
            ans = 'C'
            break
        else:
            tmp = l[2][s_c_count]
            s_c_count += 1

print(ans)

Measured memory_bytes: 3064
L, R = map(int, input().split())
P = R - L
if P >= 2019:
    print(0)
else:
    ans = 2019
    L %= 2019
    R = L + P
    for i in range(L, R):
        for j in range(i+1, R+1):
            ans = min(ans, (i*j)%2019)
    print(ans)

Measured memory_bytes: 65200
#include<stdio.h>
 
#define N 101
#define b 2
#define w 0
#define g  1
 
int n=0,z=0,G[N][N],d[N],f[N],c[N];

 

void DFS_Visit(int u);
void DFS();
  
   
 
main(){
  int i,j,s,v,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0; j<n;j++){
      G[i][j] = 0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d", &v,&r);
    for(j=0;j<r;j++){
      scanf("%d",&s);
      G[i][s-1] = 1;
    }
  }
  DFS();
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1, d[i], f[i]);
  }
  return 0;
}




void DFS_Visit(int u){
  int t;
  c[u] = g;
  d[u] = ++z;
  for(t=0;t<n;t++){
    if(G[u][t] == 1 && c[t] == w){
      DFS_Visit(t);
    }
  }
  c[u] = b;
  f[u] = ++z;
}


void DFS(){
  int u;
  z = 0;
  for(u=0;u<n;u++){
    c[u] = w;
  }
  for(u=0;u<n;u++){
    if(c[u] == w){
      DFS_Visit(u);
     }
  }
}  



Measured memory_bytes: 2056
#include <iostream>
#include<string>
#include<algorithm>
#include <cstdint>
using namespace std;
  
int main(){
string s;
cin>>s;
int a=0;
for(int i=0;i<3;i++){
    if(s.at(i)=='o'){
        a++;
    
    }
}
cout<<700+100*a<<endl;
}
  


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

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

	int five = 0;
	int seven = 0;

	if (a == 5) five++;
	if (a == 7) seven++;
	if (b == 5) five++;
	if (b == 7) seven++;
	if (c == 5) five++;
	if (c == 7) seven++;

	if (five == 2 && seven == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
# 入力
N = int(input())
gA, sA, bA = map(int, input().split())
gB, sB, bB = map(int, input().split())

A = (gA, sA, bA)
B = (gB, sB, bB)


# 各貴金属について、買う／売る可能性のある取引所は一意に定まることを用いて
# 全探索により解を求める
def f(n, r):
    R = len(r)
    if R == 0:
        return n
    elif R == 1:
        return n + (r[-1][1] - r[-1][0]) * (n // r[-1][0])
    elif R == 2:
        res = 0
        for x in range(n // r[0][0] + 1):
            res = max(
                res,
                n + (r[0][1] - r[0][0]) * x +
                (r[-1][1] - r[-1][0]) * ((n - r[0][0] * x) // r[-1][0])
            )
        return res
    else:
        res = 0
        for x in range(n // r[0][0] + 1):
            m = n - r[0][0] * x
            for y in range(m // r[1][0] + 1):
                res = max(
                    res,
                    n + (r[0][1] - r[0][0]) * x + (r[1][1] - r[1][0]) * y +
                    (r[-1][1] - r[-1][0]) * ((m - r[1][0] * y) // r[-1][0])
                )
        return res


ans = f(
    f(
        N,
        [
            (a, b)
            for a, b in zip(A, B)
            if a < b
        ]
    ),
    [
        (b, a)
        for b, a in zip(B, A)
        if a > b
    ]
)

# 出力
print(ans)


Measured memory_bytes: 39280
import sys
n, k = map(int, input().split())
l = list(map(int, input().split()))
count = 0
li = [0 for _ in range(n)]
b = 1
for i in range(1,n + 1):
#     print(b)
    if li[b-1] != 0:
        break
    li[b-1] = i
    b = l[b-1]
    count += 1
#     print('count',count)


d = count - li[b-1] + 1
intercep = li[b-1] -1
# print('d', d, 'intercep', intercep)
if k <= intercep:
    b = 1
    for i in range(k):
        b = l[b-1]
    print(b)
    sys.exit()
    
mod = (k - intercep) % d
b = 1
for i in range(intercep + mod):
#     print('b',b)
    b = l[b-1]
print(b)

Measured memory_bytes: 32332
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define spn setprecision
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
struct data{
	int t,val,ind;
};
bool cmp(data a,data b){
	if(a.t!=b.t)return (a.t<b.t);
	return (a.val<b.val);
}
vector<data> events;
bool done[upperlimit+1];
vi active;
int main() {
	int n,i,j,k,l,r,m;
	sd(n);sd(m);
	for(i=1;i<=m;i++){
		sd(l);sd(r);
		events.pb({l,1,i});
		events.pb({r,-1,i});
	}
	sort(events.begin(),events.end(),cmp);
	int answer=0;
	for(i=0;i<events.size();i++)if(!done[events[i].ind]){
		if(events[i].val==1){
			active.pb(events[i].ind);
		}
		else{
			answer++;
			for(j=0;j<active.size();j++){
				done[active[j]]=true;
			}
			active.clear();
		}
	}
	pdn(answer);
	return 0;
}

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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define pi              3.1415926536
#define mod             1000000007
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define printl(n)       printf("%lld\n", n)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asorted(s)      sort(s.begin(), s.end())
#define dsorted(s)      sort(s.begin(), s.end(), cmp)
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
#define SIZE            100005
#define INF             1000000005
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)

ll n;
ll a[SIZE], b[SIZE], c[SIZE];
ll dp[SIZE][4];

ll solve(ll in, ll f) {
    if(in == n+1) return 0;
    if(dp[in][f] != -1) return dp[in][f];

    ll p1(0), p2(0);

    if(f == 1) {
        p1 = b[in] + solve(in+1, 2);
        p2 = c[in] + solve(in+1, 3);
    }
    if(f == 2) {
        p1 = a[in] + solve(in+1, 1);
        p2 = c[in] + solve(in+1, 3);
    }
    if(f == 3) {
        p1 = a[in] + solve(in+1, 1);
        p2 = b[in] + solve(in+1, 2);
    }

    return dp[in][f] = max(p1, p2);
}

int main() {
    ll t = 0, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0;
    ms(dp, -1);

    scl1(n);
    for1(i, n) cin >> a[i] >> b[i] >> c[i];

    ans = max(max(solve(1, 1), solve(1, 2)), solve(1, 3));
    printl(ans);

    return 0;
}



Measured memory_bytes: 10368
#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++)
typedef long long ll;

int main(){
	int s;
	cin >> s;
	map<int,int> mp;
	mp[s]++;
	int count = 1;
	while(1){
		count++;
		if(s%2==0){
			s /= 2;
			if(mp[s] != 0){
				cout << count << endl;
				return 0;
			}
			mp[s]++;
		}else{
			s = 3*s + 1;
			if(mp[s] != 0){
				cout << count << endl;
				return 0;
			}
			mp[s]++;
		}
	}
	
    return 0;
}



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

void binary(int n, std::vector<int> s, int q, std::vector<int> t) {
    int count = 0;
    int left;
    int right;
    int mid;
    for (int i = 0; i < q; i++) {
        left = 0;
        right = n;

        while (left < right) {
            mid = (left + right) / 2;
            if (t[i] == s[mid]) {
                count++;
                break;
            } else if (t[i] < s[mid]) {
                right = mid;
            } else {
                left = mid + 1; 
            }
        }
    }
    std::cout << count << std::endl;
    return;
}

int main(void) {
    int n;
    std::cin >> n;
    std::vector<int> s(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }

    int q;
    std::cin >> q;
    std::vector<int> t(q, 0);
    for (int i = 0; i < q; i++) {
        std::cin >> t[i];
    }

    binary(n, s, q, t);
    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int len;
    string s;
    cin>>len>>s;
    int ans=0;
    for(int i=0;i<len-2;i++)
    {
        if(s.substr(i,3)=="ABC") ans++;
    }
    print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define SZ(x) (int)(x).size()
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

const int N = 2005, mod = 1e9 + 7;

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

inline int sub(int a, int b){
  int ret = a - b;
  if(ret < 0) ret += mod;
  return ret;
}

int a, b, c, d;
set<ll> S;

int main(){
  scanf("%d %d %d %d", &a, &b, &c, &d);
  
  S.insert((ll)a * c);
  S.insert((ll)a * d);
  S.insert((ll)b * c);
  S.insert((ll)b * d);
  if(a <= 0 && b >= 0) S.insert(0ll);
  if(c <= 0 && d >= 0) S.insert(0ll);
  
  printf("%lld\n", *S.rbegin());
  
  return 0;
}


Measured memory_bytes: 3780
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    cnt = [0] * 3
    for a in A:
        cnt[a-1] += 1

    dp = [[[0.] * (N+1) for _ in range(N+1)] for _ in range(N+1)]
    for k in range(N+1):
        for j in range(N+1-k):
            for i in range(N+1-j-k):
                ijk = float(i + j + k)
                if ijk == 0:
                    continue
                x = N / ijk
                tmp = 0
                if i > 0:
                    tmp += (dp[i-1][j][k] + x) * (i / ijk)
                if j > 0 and i < N:
                    tmp += (dp[i+1][j-1][k] + x) * (j / ijk)
                if k > 0 and j < N:
                    tmp += (dp[i][j+1][k-1] + x) * (k / ijk)
                dp[i][j][k] = tmp
    print(dp[cnt[0]][cnt[1]][cnt[2]])


if __name__ == '__main__':
    main()


Measured memory_bytes: 255752
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MP make_pair
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

string s;
vector<pii> v;

int main()
{jizz
	int t=2,n=2;
	cin >> s;
	if(s[0]!='1'||s.back()!='0'||s[s.size()-2]!='1')
		return cout << "-1",0;
	v.pb(MP(1,2));
	for(int i=1;i+i<s.size();++i)
	{
		if(s[i]!=s[s.size()-i-2])
			return cout << "-1",0;
		++n;
		v.pb(MP(t,n));
		if(s[i]=='1')
			t=n;
	}
	while(v.size()+1<s.size())
		++n,v.pb(MP(t,n));
	for(auto i:v)
		cout << i.F << " " << i.S << "\n";
}

Measured memory_bytes: 2372
#include <stdio.h>
#include<string.h>
int main()
{
	int m,n;
	char s[105][105];
	int i,j,num;
	scanf("%d%d",&m,&n);

		for(i=0;i<m;i++)
            scanf("%s",s[i]);
			for(i=0;i<m;i++)
			{
				for(j=0;j<n;j++)
				{
					if(s[i][j]=='#'){printf("#");continue;}
					else
					{ num=0;
					  if(i-1>=0&&j-1>=0&&s[i-1][j-1]=='#')num++;
					  if(i-1>=0&&s[i-1][j]=='#')num++;
					  if(j+1<n&&i-1>=0&&s[i-1][j+1]=='#')num++;
					  if(j-1>=0&&s[i][j-1]=='#')num++;
					  if(j+1<n&&s[i][j+1]=='#')num++;
					  if(j-1>=0&&i+1<m&&s[i+1][j-1]=='#')num++;
					  if(i+1<m&&s[i+1][j]=='#')num++;
					  if(i+1<m&&j+1<n&&s[i+1][j+1]=='#')num++;
					  printf("%d",num);
					}
				}printf("\n");
			}printf("\n");
	return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

ll gcd(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

//---------------------------------------------------------------
// 最小公倍数
//---------------------------------------------------------------
ll lcm(ll a, ll b) {
	ll temp = gcd(a, b);
	return temp * (a / temp)*(b / temp);
}

int kaizyou(int n) {
	if (n == 1) {
		return 0;
	}
	int ret = 1;
	for (int i = 1; i <= n; i++) {
		ret *= i;
	}
	return ret;
}

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int K, X;
	cin >> K >> X;

	if (K * 500 >= X) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}



}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    string s;
    cin >> s;
    int n = sz(s);
    int ans = -1;
    for (int len = 1; len < n / 2; len++) {
        if (s.substr(0, len) == s.substr(len, len)) ans = len * 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256