akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N, b, back;
  cin >> N;
  bool isExist;
  bool match[N];
  vector<int> B, answer;
  for (int i=0; i<N; i++){
    cin >> b;
    B.push_back(b - 1);
  }
  while (B.size() > 0){
    back = -1;
    for (int i=0; i<B.size(); i++){
      if (i == B[i]) back = i;
    }
    if (back == -1) break;
    answer.push_back(back);
    B.erase(B.begin() + back);
  }
  if (B.size() == 0){
    for (int i=N-1; i >= 0; i--){
      cout << answer[i] + 1 << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}


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

typedef long long ll;

const int N=2e5+1e3+7;

int n,a[N];

ll ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(a[1]!=0)
	{
		puts("-1");
		return 0;
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]>a[i-1]+1)
		{
			puts("-1");
			return 0;
		}
		else if(a[i]==a[i-1]+1)
			continue;
		else
			ans+=a[i-1];
	}
	ans+=a[n];
	printf("%lld",ans);
}

Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
queue<char> Q;
char a[202];
int m,h,c;
char x;
while(1){
	cin>>a;
	if(a[0]=='-')break;
	c=strlen(a);
	for(int i=0;i<c;i++){
		Q.push(a[i]);
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>h;
		for(int j=0;j<h;j++){
			x=Q.front();
			Q.pop();
			Q.push(x);
		}
	}
	while(!Q.empty()){
		cout<<Q.front();
		Q.pop();
	}
	cout<<endl;
}
return 0;
}



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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  rep(i, k){
    if(i % 2 == 0){
      b += a/2;
      a /= 2;
    }
    else{
      a += b/2;
      b /= 2;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

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


signed main(void) {
	string s;

	cin >> s;
	ll k;
	cin >> k;

	ll ans = 0, bcou = 0;
	ll cou = 1;
	REP(i, s.length() - 1) {
		if (s[i] == s[i + 1])
			cou++;
		else {
			bcou += cou/2;
			cou = 1;
		}
	}

	bcou += cou / 2;

	ans += bcou * k;

	ll ccou = 0,dcou = 0;

	REP(i, s.length()) {
		if (s[i] != s[s.length() - 1]) {
			break;
		}
		ccou++;
	}

	for (int i = s.length() - 1; 0 <= i; i--) {
		if (s[i] != s[s.length() - 1]) {
			break;
		}
		dcou++;
	}
	if (ccou == s.length()) {
		if (s.length() % 2)
			cout << ans + k / 2 << endl;
		else
			cout << ans << endl;
	}
	else {
		if (ccou % 2 && dcou % 2) {
			ans += k - 1;
		}
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	string s;
	cin>>s;
	int n = (int)s.sz();
	bool ok = 1;
	for(int i=0;i<(n>>1);i++)
	{
		if(s[i] != s[n-1-i])
		{
			ok = 0;
			break;
		}	
	}	
	for(int i=0;i<((n-1)>>1);i++)
	{
		if(s[i] != s[((n-1)>>1)-1-i])
		{
			ok = 0;
			break;
		}	
	}	
	for(int i=(((n+3)>>1)-1);i<n;i++)
	{
		if(s[i] != s[n-1-i])
		{
			ok = 0;
			break;
		}
	}	
	if(ok)
	cout<<"Yes\n";
	else cout<<"No\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    char str;
    while(1){
        scanf("%c",&str);
        if(str >= 'A' && str <= 'Z') str += 0x20;
        else if(str >= 'a' && str <= 'z') str -= 0x20;
        printf("%c",str);
        if(str == '\n') break;
    }
    return 0;
}

Measured memory_bytes: 524
S=list(input())

S.sort()
e,w,n,s=S.count('E'),S.count('W'),S.count('N'),S.count('S')
flag=True
if max(e,w)>0 and min(e,w)==0:
  flag=False
if max(n,s)>0 and min(n,s)==0:
  flag=False
  
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define int long long
    # define mo 1000000007
    using namespace std;
    #define goku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    signed main(){
        goku
    int a,b,k;
    cin>>a>>b>>k;
    int d = min(a,k);
    a-=d;
    k-=d;
    b -= min(b,k);
    cout<<a<<" "<<b;
       return 0;
    }


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  char c; std::cin >> c;
  std::cout << char(c+1) << "\n";
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    switch_count = N if N%2 == 0 else N-1
    A.sort()
    sumA = sum(A)
    answer = sumA
    prev = sumA
    for i in range(2,switch_count+1,2):
        a = prev - A[i-1]*2 - A[i-2]*2
        answer = max(a,answer)
        prev = a
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16244
/*  UntilDeathDoesUsApart
    DO   NOT   GIVE   UP!
*/

#include <bits/stdc++.h>

using namespace std;

#define inc(a)           a.begin(), a.end()
#define dec(a)           a.rbegin(), a.rend()
#define Unique(n)        (n).erase(unique(in(n)), (n).end())
#define what_is(x)       cerr << #x << " is " << x << '\n';
#define to(i, a, n)      for(int i=a; i<n; i++)
#define fr(i, a, n)      for(int i=a; i>=n; i--)
#define read(arr, l, r)  for(int i=l; i<r; cin >> arr[i++])
#define prnt(arr, l, r)  for(int i=l; i<r; cout << arr[i++] << " \n"[i==r])

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int k; cin >> k;
    string s; cin >> s;

    if(s.size()<=k) cout << s;
    else
        cout << s.substr(0, k) + "...";

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int s=0;
  int tar=k;
  while(tar<n)
  {
    if(arr[s]<arr[tar])
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    s++;
    tar++;


  }

  
  
}


Measured memory_bytes: 4360
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>

using namespace std;


int main()
{
	string str[100],str2[200000],strmemo="";
	long long int n, m, a, b, c, now[200][200] = {},x[200006],y[200006],X=0,Y=0;
	const long long int mod = 1000000007;
	cin >> n ;
	cout << "Christmas" ;
	for (int i = n; i < 25; i++) {
		cout << " Eve";
	}
	cout << endl;
}


Measured memory_bytes: 1792
primes = [0, 0] + [1]*999999
for i in range(2, 1001):
    if primes[i]:
        for j in range(i*i, 1000001, i):
            primes[j] = 0
while True:
    try:
        data = int(input())
    except:
        break
    print(sum(1 for i in range(data, 1, -1) if primes[i]))

Measured memory_bytes: 22984
N = int(input())
is_approved = True
for a_str in input().split():
    a = int(a_str)
    if a % 2 == 0:
        if a % 3 != 0 and a % 5 != 0:
            is_approved = False
            break

if is_approved:
    print("APPROVED")
else:
    print("DENIED")

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

#define N 1010

int h, w, a, b;

int main() {
    cin >> h >> w >> a >> b;
    for (int i = 0; i < h; i ++, puts("")) for (int j = 0; j < w; j ++) {
        putchar(((i < b) ^ (j < a)) ^ '0');
    }

    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

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

    while (in.hasNext()) {
      int A = in.nextInt();
      int B = in.nextInt();
      int T = in.nextInt();

      System.out.println((T / A) * B);
    }
  }
}

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

int N,a[100010],cnt[100010];

int main(){
    cin >> N;

    int i,cntp=0,res=0;
    for (i=1; i<=N; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }

    for (i=1; i<=100000; i++)
        if (cnt[i]>0){
            if (cnt[i]%2==0) cntp++;
            res++;
        }

    if (cntp%2==1) res--;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define INF 100000000
int dp[20001][256],n,m;
main(){
  while(cin>>n>>m,n){
    int b[m];int a[n+1];
    r(i,m)cin>>b[i];
    r(i,n)cin>>a[i+1];
    r(i,n+1)r(j,256)if(dp[i][j]!=INF)dp[i][j]=INF;
    dp[0][128]=1;
    r(i,n)r(j,256)
        if(dp[i][j]!=INF)r(k,m){
          int p=j+b[k];
          if(p>255)p=255;
          if(p<0)p=0;
          dp[i+1][p]=min(dp[i+1][p],dp[i][j]+(a[i+1]-p)*(a[i+1]-p));
        }
    int p=100000000;
    r(i,256)if(dp[n][i]!=INF)
      p=min(p,dp[n][i]);
    cout<<p-1<<endl;
  }
}

Measured memory_bytes: 23036
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const double pi = 3.14159265;
const ll LLINF = 1LL << 50;
using namespace std;



int main() {
    int x;
    cin >> x;
    if (x == 1) {
        cout << 1 << endl;
        return 0;
    }
    int ans = 1;
    for (int b = 2; b <= 31; b++) {
        for (int p = 2; p <= 9; p++) {
            if (pow(b, p) <= x) ans = max(int(pow(b, p)), ans);
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
const int N = 1e5+5;
const int INF = (1<<30)-1;

int hd[N],iter[N],dis[N];
struct E{int v,w,nxt;}e[N<<3];
queue<int>Q;
bool v[N];
int p[N],q[N],c[N],d[N],cnt[N];
int n,nc,nd,tot=1,S,T;

inline void add(int u,int v,int w){
	e[++tot]={v,w,hd[u]};hd[u]=tot;
	e[++tot]={u,0,hd[v]};hd[v]=tot;
}
inline bool bfs(){
	memcpy(iter,hd,sizeof(hd));
	memset(dis,-1,sizeof(dis));
	Q.push(S);dis[S]=0;
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		for(int i=hd[x],y;i;i=e[i].nxt)
			if(e[i].w&&dis[y=e[i].v]==-1){
				dis[y]=dis[x]+1, Q.push(y);
			}
	}
	return ~dis[T];
}
int dfs(int x=S,int f=INF){
	if(x==T||!f)return f;
	int sf=0,y;
	for(int &i=iter[x];i;i=e[i].nxt)
		if(e[i].w&&dis[y=e[i].v]==dis[x]+1){
			int w=dfs(y,min(f,e[i].w));
			e[i].w-=w, e[i^1].w+=w;
			f-=w, sf+=w;
			if(!f)break;
		}
	return sf;
}

void prep(int p[],int c[],int &m){
	m = 0;
	rep(i,1,n) if(!c[i]){
		++m;
		for(int x=i;!c[x];x=p[x]) c[x] = m;
	}
}

int main() {
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",p+i),++p[i];
	rep(i,1,n)scanf("%d",q+i),++q[i];
	prep(p,c,nc);
	prep(q,d,nd);
	S = 0, T = nc+nd+1;
	int ans = n;
	rep(i,1,n){
		bool f1 = (p[i]==i), f2 = (q[i]==i);
		if(f1&&f2) --ans;
		else if(f1) ++cnt[nc+d[i]];
		else if(f2) ++cnt[c[i]];
		else{
			add(nc+d[i],c[i],1);
			if(p[i]==q[i]) add(c[i],nc+d[i],1);
		}
	}
	rep(i,1,nc) add(S,i,cnt[i]);
	rep(i,nc+1,T-1) add(i,T,cnt[i]);
	int flow = 0;
	while(bfs()) flow += dfs();
	ans -= flow;
	printf("%d\n",ans);
	return 0;
}

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

const int INF = 1000000000;

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

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

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

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

	for(int k=0;k<m;k++){
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				if(T[i][j]>T[i][k]+T[k][j]){
					T[i][j]=T[i][k]+T[k][j];
				}
			}
		}
	}

	int town;
	int ti=INF;
	for(int i=m-1;i>=0;i--){
		int t=0;
		for(int j=0;j<m;j++){
			t+=T[i][j];
		}
		if(ti>=t){
			ti=t;
			town=i;
		}
	}
	cout<<town<<" "<<ti<<endl;
	

	}

	return 0;
}

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

int main() {
    string S;
    cin >> S;
    if (S.at(2) == S.at(3) && S.at(4) == S.at(5) ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim().Select(x => x - '0').ToArray();

        var d = int.MaxValue;
        for (int i = 0; i + 2 < s.Length; i++)
        {
            var x = Math.Abs(753 - s[i] * 100 - s[i + 1] * 10 - s[i + 2]);
            d = Math.Min(d, x);
        }
        Console.WriteLine(d);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;

int f(int n) {
	if (n % 2 == 0) return n / 2;
	else return 3 * n + 1;

}

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

	vector<int> a;
	int s;
	cin >> s;
	a.emplace_back(s);
	int ans = 0;
	for (int m = 1; ;m++) {
		a.emplace_back(f(a[m - 1]));
		for (int n = 0; n < m - 1; n++) {
			if (a[m] == a[n]) {
				ans = m + 1;
				break;
			}
		}
		if (ans != 0) break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a = [input() for i in range(2)]
result = int(0)
maxAns = int(0)
for c in a[1]:
    if c == 'I':
        result += 1
    elif c == 'D':
        result -= 1
    
    if result > maxAns:
        maxAns = result

print(maxAns)

Measured memory_bytes: 3060
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Channels;
using System.IO.Pipes;

class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {

        //var N = long.Parse(Console.ReadLine());
        var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NM[0];
        var M = NM[1];

        var UF = new UnionFind(N+1);

        for (int i = 0; i < M; i++)
        {
            var AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var A = AB[0];
            var B = AB[1];
            UF.Union(A,B);
        }

        long max = 0;
        for (int i = 1; i <= N; i++)
        {
            max = Math.Max(max, UF.Size(i));
        }

        Console.WriteLine(max);
    }
}

class UnionFind



{



    // 親要素のインデックスを保持する



    // 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ



    public long[] Parents { get; set; }



    public UnionFind(long n)



    {



        this.Parents = new long[n];



        for (int i = 0; i < n; i++)



        {



            // 初期状態ではそれぞれが別のグループ(ルートは自分自身)



            // ルートなのでマイナスで要素数(1個)を保持する



            this.Parents[i] = -1;



        }



    }







    // 要素xのルート要素はどれか



    public long Find(long x)



    {



        // 親がマイナスの場合は自分自身がルート



        if (this.Parents[x] < 0) return x;



        // ルートが見つかるまで再帰的に探す



        // 見つかったルートにつなぎかえる



        this.Parents[x] = Find(this.Parents[x]);



        return this.Parents[x];



    }







    // 要素xの属するグループの要素数を取得する



    public long Size(long x)



    {



        // ルート要素を取得して、サイズを取得して返す



        return -this.Parents[this.Find(x)];



    }







    // 要素x, yが同じグループかどうか判定する



    public bool Same(long x, long y)



    {



        return this.Find(x) == this.Find(y);



    }







    // 要素x, yが属するグループを同じグループにまとめる



    public bool Union(long x, long y)



    {



        // x, y のルート



        x = this.Find(x);



        y = this.Find(y);



        // すでに同じグループの場合処理しない



        if (x == y) return false;







        // 要素数が少ないグループを多いほうに書き換えたい



        if (this.Size(x) < this.Size(y))



        {



            var tmp = x;



            x = y;



            y = tmp;



        }



        // まとめる先のグループの要素数を更新



        this.Parents[x] += this.Parents[y];



        // まとめられるグループのルートの親を書き換え



        this.Parents[y] = x;



        return true;



    }



}


Measured memory_bytes: 48484
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        


#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#V, E, r = map(int, input().split())
#INF = V * 10001

A, B, T = map(int, input().split())

ans = math.floor(T/A)*B

print(int(ans))


Measured memory_bytes: 38764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  string s,t; cin >> s >> t;
  string ans = "No";
  for(int i = 0; i < s.size(); i++){
    if(s == t) ans = "Yes";
    s = s.back() + s.substr(0,s.size()-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    string S; cin>>S;
    string A="ABC";
    int count=0;
    for(int i=0;i<N-2;i++){
        if(S.substr(i,3)==A){
            count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

struct item{
    int w;
    int v;
};

using P = pair<lint, string>;

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

    int n, w;
    cin >> n >> w;
    vector<item> items(n);
    for(int i=0; i<n; i++){
        cin >> items[i].w >> items[i].v;
    }

    sort(ALL(items), [](item &a, item &b) -> bool { return a.w < b.w; });
    vector<P> max_value_all_weight(w+1, make_pair(0, string(n, '0')));

    for(int i=0; i<w+1; i++){
        lint opt = 0;
        int choice = -1;
        int from = 0;
        for(int j=0; j<n; j++){
            if(items[j].w > i) break;
            if(max_value_all_weight[i-items[j].w].second.at(j) == '1') continue;
            if(max_value_all_weight[i-items[j].w].first + items[j].v > opt){
                opt = max_value_all_weight[i-items[j].w].first + items[j].v;
                from = i-items[j].w;
                choice = j;
            }
        }
        max_value_all_weight[i].first = opt;
        if(choice != -1){
            max_value_all_weight[i].second = max_value_all_weight[from].second;
            max_value_all_weight[i].second.at(choice) = '1';
        }
    }

    // for(auto &i : max_value_all_weight){
    //     cout << setw(3) << i.first << ' ' << i.second << endl;
    // }

    lint ans = 0;
    for(int i=0; i<w+1; i++){
        ans = max(ans, max_value_all_weight[i].first);
    }

    COUT(ans);

    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int l[105];
int d[10005];
int main()
{
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>l[i];
	}
	for(int i=1;i<=n+1;i++)
	{
		d[i]=d[i-1]+l[i-1];
	}
	int sum=0;
	for(int i=1;i<=n+1;i++)
	{
		if(d[i]<=x) sum++;
	}
	cout<<sum;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(std::string S) {
  vector<int> data;
  for (auto c : S) {
    if (c == 'A' || c == 'G' || c == 'T' || c == 'C')
      data.push_back(1);
    else
      data.push_back(0);
  }
  int best = 0;
  int cur = 0;
  for (auto elem : data) {
    if (elem == 1)
      cur++;
    else
      cur = 0;
    best = max(best, cur);
  }
  cout << best << endl;
}

int main() {
  cout << setprecision(10);
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int dp[100005];
  int h[100005];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for(int i=2; i<n; i++){
    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1] , abs(h[i] - h[i-2]) + dp[i-2]);
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cmath>
#include<stack>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int h[100005];
int dp[100005];

int main()
{
memset(dp, 0x3f ,sizeof dp);
scanf("%d",&n);
for( int i = 1 ; i <= n ; i++) scanf("%d",&h[i]);
dp[1] = 0;
for( int i = 1 ; i <= n ; i++)
{
	dp[i+1] = min(dp[i+1],dp[i]+abs(h[i] - h[i+1]));
	dp[i+2] = min(dp[i+2],dp[i]+abs(h[i] - h[i+2]));
}
printf("%d",dp[n]);

	return 0;
}




Measured memory_bytes: 1024
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<usize> = get_vec();
    let mut ss : Vec<String> = Vec::new();
    for _i in 0..v[0] {
        let s : String = get_one();
        ss.push(s);
    }
    ss.sort();
    let mut t = String::new();
    for s in ss {
        t += &s;
    }
    println!("{}", t);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
  int K,X;
  char line[128];
  fgets(line,sizeof(line),stdin);
  sscanf(line,"%d %d",&K, &X);
  if(500*K>=X){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}




Measured memory_bytes: 128
import numpy as np

N = int(input())

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

count = 0

for i in range(N-2):
    if A[i] < A[i+1] and A[i+1] < A[i+2]:
        count += 1
    elif A[i] > A[i+1] and A[i+1] > A[i+2]:
        count += 1
print(count)

Measured memory_bytes: 21040
def evaluate_grade(m: int, f: int, r: int) -> str:
    if (m == -1 or f == -1):
        if (50 <= r):
            return "C"
        else:
            return "F"

    total_score: int = m + f
    if (80 <= total_score):
        return "A"
    elif (65 <= total_score < 80):
        return "B"
    elif (50 <= total_score < 65):
        return "C"
    elif (30 <= total_score < 50):
        if (50 <= r):
            return "C"
        else:
            return "D"
    else:
        return "F"


if __name__ == "__main__":
    datasets = []

    while(True):
        m, f, r = map(lambda x: int(x), input().split())

        if (m == f == r == -1):
            break

        datasets.append([m, f, r])

    for (m, f, r) in datasets:
        print(f"{evaluate_grade(m, f, r)}")



Measured memory_bytes: 5608
N = int(input())
X = [int(i) for i in input().split()]

physical_min = float('inf')
for p in range(min(X), max(X)+1):
    physical_total = 0
    for x in X:
        physical_total += (x-p)**2
    if physical_total < physical_min:
        physical_min = physical_total
print(physical_min)

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    ll n;
    cin >> n;

    string ans;
    while (n > 0) {
        n--;
        ans.push_back(n % 26 + 'a');
        n /= 26;
    }

    reverse(all(ans));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
signed main()
{
    int n, m;
    cin >> n >> m;
    vi v = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    vi a(m);
    rep(i, m)
    {
        cin >> a[i];
        a[i]--;
    }
    vector<string> dp(n + 1, "INF");
    dp[0] = "";
    rep(i, n)
    {
        rep(j, m)
        {
            if (i + 1 - v[a[j]] < 0)
            {
                continue;
            }
            else if (dp[i + 1 - v[a[j]]] == "INF")
            {
                continue;
            }
            else
            {
                if (dp[i + 1] == "INF")
                {
                    dp[i + 1] = dp[i + 1 - v[a[j]]] + to_string(a[j] + 1);
                }
                else
                {
                    if (dp[i + 1].size() > dp[i + 1 - v[a[j]]].size() + 1)
                    {
                        continue;
                    }
                    else if (dp[i + 1].size() < dp[i + 1 - v[a[j]]].size() + 1)
                    {
                        dp[i + 1] = dp[i + 1 - v[a[j]]] + to_string(a[j] + 1);
                    }
                    else
                    {
                        dp[i + 1] = max(dp[i + 1], dp[i + 1 - v[a[j]]] + to_string(a[j] + 1));
                    }
                }
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 31872
/*
 * atcoder/dp_3rd/e.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX_N = 110;
const int MAX_V = 110000;
const ll INF = 100000000000000000;
ll N, CAP;
ll W[MAX_N], V[MAX_N];
ll dp[MAX_N][MAX_V];

void input() {
  cin >> N >> CAP;
  loop(n,0,N) {
    cin >> W[n] >> V[n];
  }
}

// 状態
// dp[n][maxv] := n番目のアイテムまでを考慮したときにmaxv以上を達成できる最小の重さw
//
// 遷移
// dp[n][maxv] = dp[n-1][maxv]  アイテムの選択肢が少なかった時よりは小さくなる
// dp[n][maxv] = dp[n][maxv-v] + w 

void solve() {
  ll max_ = 0;
  loop(n,0,N) loop(v,0,MAX_V) dp[n][v] = INF;
  for (int n=0; n<N; n++) {
    ll w = W[n], v = V[n];
    for (ll maxv=0; maxv<=1000*N; maxv++) {
      if (maxv == 0) {
        dp[n][0] = 0;
        continue;
      }

      if (n == 0) {
        if (maxv <= v) {
          dp[n][maxv] = w;
          if (w <= CAP) chmax(max_, maxv);
        }
        continue;
      }
      if (chmin(dp[n][maxv], dp[n-1][maxv])) {
        if (dp[n][maxv] <= CAP) chmax(max_, maxv);
      }
      if (maxv-v>=0)
        if (chmin(dp[n][maxv], dp[n-1][maxv-v] + w)) {
          if (dp[n][maxv] <= CAP) chmax(max_, maxv);
      }
    }
  }

  cout << max_ << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 86272
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
#define END system("PAUSE");return 0

signed main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int cnt = 0;
	cnt += H * w;
	cnt += h * W;
	cnt -= h * w;
	cout << H * W - cnt << endl;
	END;
}


Measured memory_bytes: 504
#include<stdio.h>

int main()

{
   int a[10],n,b,c,i,j,k,z,sum=0,temp;

   scanf("%d",&n);

   for(i=0;i<n;i++)
   {
      scanf("%d",&a[i]);
   }

   for(j=0;j<n;j++)
   {
      for(k=j+1;k<n;k++)
      {
         if(a[k]>a[j])
         {
            temp = a[j];

            a[j] = a[k];

            a[k] = temp;
         }
      }
   }

   for(z=0;z<n;z++)
   {
      if(z==0)
      {
         sum = sum + (a[z]/2);
      }

      else
      {
         sum = sum + a[z];
      }
   }

   printf("%d\n",sum);
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> D;
    for (int i = 0; i < N; i++){
        int d;
        cin >> d;
        D.push_back(d);
    }
    sort(D.begin(), D.end());
    int cnt = 1;
    for (int i = 1; i < N; i++){
        if (D[i-1] != D[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;
#include <cstdint>

template <std::uint_fast64_t Modulus>
class modint
{
    using u64 = std::uint_fast64_t;

public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept
    {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept
    {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept
    {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept
    {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept
    {
        a += rhs.a;
        if (a >= Modulus)
        {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept
    {
        if (a < rhs.a)
        {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept
    {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept
    {
        u64 exp = Modulus - 2;
        while (exp)
        {
            if (exp % 2)
            {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
int main()
{
    ll k;
    cin >> k;
    vector<ll> modk(k + 5);
    ll res = 1;
    ll temp = 7 % k;
    ll index = 1;
    while (true)
    {
        if (temp == 0)
        {
            break;
        }
        if (modk[temp] != 0)
        {
            index = -1;
            break;
        }
        modk[temp]++;
        temp = (temp * 10 + 7) % k;
        index++;
    }
    cout << index << endl;
    return 0;
}

Measured memory_bytes: 11072
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ld n, k;
	cin >> n >> k;
	ld prob = 0;
	for (int i = 1; i <= n; i++){
		ld tmp = 1;
		int j = i;
		while (j < k){
			tmp *= 0.5;
			j *= 2;
		}
		prob += tmp;
	}
	cout << fixed << setprecision(15) << prob / n << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

vector<vector<int>>g;

void addedge(ll x,ll y)
{
    g[x].push_back(y);
    g[y].push_back(x);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,e;
    cin>>n>>e;
    vector<int>h;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        h.push_back(x);
    }
    g.assign(n, vector<int>());
    for(int i=0;i<e;i++)
    {
        ll x,y;
        cin>>x>>y;
        addedge(--x,--y);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int flag=1;
        for(auto x:g[i])
            if(h[x]>=h[i])
                flag=0;
        ans+=flag;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8768
#include<bits/stdc++.h>
using namespace std;
string s;int ans,lmax;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
		lmax++;
		else
		{
			if(ans<lmax)
			ans=lmax;
			lmax=0;
		}
	}
	if(lmax<=ans)
	cout<<ans;
	else
	cout<<lmax;
	return 0;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int a[505];
int pre[505];
int suf[505];
int n,k;
int solve(int d)
{
    vector<int>vec;
    f(i,1,n)
    {
        int rem=a[i]%d;
        vec.pb(rem);
    }
    sort(vec.begin(),vec.end());
    int sum=0;
    int sz=vec.size();
    f(i,1,sz)
    {
        sum+=vec[i-1];
        pre[i]=sum;
    }
    sum=0;
    rf(i,sz,1)
    {
        sum+=(d-vec[i-1]);
        suf[i]=sum;
    }
    int ret=inf;
    f(i,1,sz)
    {
        int cost=max(pre[i],suf[i+1]);
        ret=min(ret,cost);
    }
    if(ret<=k)return true;
    return false;
}
 main()

{
    fast
    cin>>n>>k;
    int sum=0;
    f(i,1,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    vector<int>d;
    for(int i=1;i*i<=sum;i++)
    {
        if(sum%i==0)
        {
            d.pb(i);
            if((sum/i)!=i)
            {
                d.pb(sum/i);
            }
        }
    }
    int ses=inf;
    sort(d.rbegin(),d.rend());
    for(auto x:d)
    {
        if(solve(x)){
        cout<<x<<endl;
        return 0;
        }
    }


}





































Measured memory_bytes: 3712
def main():
    n, c, k = map(int, input().split())
    t = [int(input()) for _ in range(n)]

    t.sort()

    cnt = 0
    ans = 0
    dep = 0
    for e in t:
        if cnt == c or e > dep:
            dep = e + k
            ans += 1
            cnt = 0

        cnt += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7384
#include<stdio.h>
#define BLACK 2
#define WHITE 0
#define GRAY 1
#define INFTY 1e+9
#define MAX 100
int n,A[MAX][MAX];
void dij();
int main(){
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=INFTY;
    }
  }
  int u,k,c,v;
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      A[u][v]=c;
    }
  }
  dij();
  return 0;
}
void dij(){
  int mincost,d[MAX],color[MAX],i,v;
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    mincost=INFTY;
    int u=-1;
    for(i=0;i<n;i++){
      if(mincost>d[i]&&color[i]!=BLACK){
	u=i;
	mincost=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&A[u][v]!=INFTY){
	if(d[v]>d[u]+A[u][v]){
	  d[v]=d[u]+A[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,(d[i]==INFTY ? -1:d[i]));
  }
}



Measured memory_bytes: 2108
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define CIN2(x,y) int x,y;cin>>x>>y;
#define CIN3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define SCIN(x) string x;cin>>x;
#define SCIN2(x,y) string x,y;cin>>x>>y;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i];
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);V a(n);VECCIN(a);
    map<int,int> map_;
    REP(i,n)map_[a[i]]++;
    ll ans=0;
    FOREACH(x,map_)ans+=(x.second%2==0?0:1);
    COUT(ans);


    return 0;
}


Measured memory_bytes: 5376