akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node
{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
 
Node root;
Node treeMinimum(Node x)
{  
  while(x->left!=NIL)
    {
      x = x->left;
    }
  return x;
}

Node treeSearch(Node x, int k)
{
  if(x == NIL || k == x->key)
    {
      return x;
    }
  if(k < x->key)
    {
      return treeSearch(x->left, k);
    }
  else
    {
      return treeSearch(x->right, k);
    }
}
 
Node treeSuccessor(Node x)
{ 
  Node y;
  if(x->right != NIL)
    {
      return treeMinimum(x->right);
    } 
  y = x->parent;
  while(y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }
  return y;
}
 
void treeDelete(Node z)
{
  Node y;
  Node x; 
  if(z->left == NIL || z->right == NIL)
    {
      y=z;
    }
  else
    {
      y=treeSuccessor(z);
    }
  if(y->left != NIL)
    {
      x=y->left;
    }
  else
    {
      x=y->right;
    }
  if(x != NIL)
    { 
      x->parent = y->parent;
    }
  if(y->parent == NIL)
    {
      root=x;
    }
  else if(y ==(y->parent)->left)
    {    
      (y->parent)->left=x;
    } 
  else
    { 
      (y->parent)->right=x;
    }
  if(y != z)
    {   
      z->key=z->key;
    }
}

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
	{      
	  x=x->left;
	}    
      else
	{
	  x=x->right;
	}
    }
  
  z->parent=y;
  if(y==NIL)
    { 
      root=z;
    }
  else if(z->key < y->key)
    {
      y->left=z;
    }
  else
    {
      y->right=z;
    }
}

void inorder(Node x)
{  
  if(x!=NIL)
    {
      inorder(x->left);
      printf(" %d", x->key);
      inorder(x->right);
    }
}

void preorder(Node x)
{ 
  if(x!=NIL)
    {
      printf(" %d", x->key);
      preorder(x->left);
      preorder(x->right);
    }
}
 

int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  root=NIL;
 
  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
	  if ( t != NIL )
	    {	    
	      printf("yes\n");
	    }
	  else
	    {
	      printf("no\n");
	    }
	}
      else if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      else if ( com[0] == 'd' )
	{
	  scanf("%d", &x);
	  treeDelete(treeSearch(root, x));
	}
    } 
  return 0;
}

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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  cout << fixed << setprecision(15);
  double a = 30 * H + 0.5 * M;
  double b = 6 * M;
  double deg = min(abs(a - b), 360 - abs(a - b));
  if (a == b) {
    cout << abs(A - B) << endl;
    return 0;
  }
  if (deg == 0) {
    cout << A + B << endl;
    return 0;
  }
  double PI = acos(-1);
  double rad = deg * PI / 180;
  double c = A * A + B * B - 2 * A * B * cos(rad);
  cout << sqrt(c) << endl;
}

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

int main(){
  string s;
  int k;
  cin>>k>>s;
  if(s.size()<=k){
    cout<<s<<endl;
  }else{
    for(int i=0;i<k;i++){
      cout<<s[i]<<flush;
    }
    cout<<"..."<<endl;
  }
}

Measured memory_bytes: 3628
#import collections as c
#ip = lambda : map(int, input().split())

#################
K=int(input())
al = [int(i) for i in input().split()]

s,l = 2,2

if al[-1] != 2:
    print(-1)
    exit()
if K==1:
    print(s,l+al[0]-1)

for i in range(K-1,-1,-1):
    c = 0
    if s%al[i-1]==0:
        tmps = s
    else:tmps = s + al[i-1] - s%al[i-1]
    if tmps <= l+al[i]-1:
        s = tmps
        c+=1
        l = (l+al[i]-1)//al[i-1]*al[i-1]

    if c==0:
        print(-1)
        exit()
    if i==1:
        print(s,l+al[0]-1)

Measured memory_bytes: 14428
def resolve():
  a, b, c, x, y = map(int, input().split())
  ans = a * x + b * y
  ans = min(ans, max(x, y) * c * 2)
  if x >= y:
    ans = min(ans, y * c * 2 + (x - y) * a)
  else:
    ans = min(ans, x * c * 2 + (y - x) * b)

  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    ll h, w; cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1;
        return;
    }
    ll p = h * w;
    if (p % 2) cout << p/2 + 1;
    else cout << p/2;

}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int ans=0;
  string s;
  cin >> s;
  for(int i=0; i<4; i++) {
    if(s[i]=='+') {
      ans++;
    }
    else {
      ans--;
    }
  }
  cout << ans << endl;
}

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

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(int x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(int x){
	write(x);puts("");
}
#include <cstring>
#define Max 1005
int n,m,k,ans,num,x,a[Max];

int main(){
	n=read();m=read();k=read();
	for(int i=1;i<=m;i++){
		a[read()]=1;
	}
	for(int i=1;i<=k;i++){
		ans+=a[i];
	}
	for(int i=k;i<=n;i++){
		num+=a[i];
	}
	writeln(min(ans,num));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,k,a[202020]; 
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>k;
	fo(i,0,n)cin>>a[i];
	int l=0,r=1e9+5;
	while(l<=r){
		int mid=(l+r)/2;
		if(mid==0)break;
		ll x=0;
		fo(i,0,n)x+=(a[i]-1)/mid;
		if(x>k)l=mid+1;
		else r=mid-1;
	}
	ll x=0;
	if(l<=1){
		cout<<"1\n";
		return 0;
	}
	fo(i,0,n)x+=(a[i]-1)/(l-1);
	if(x<=k)cout<<l-1<<endl;
	else cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	ll n;
	cin>>n;
	cout<<(n*(n-1))/2;
 
	return 0;	
}


Measured memory_bytes: 256
N = int(input())
money = 1000
M = N//2
prices = list(map(int, input().split()))
prices.append(0)
dp = [[0 for j in range(M+1)]for i in range(N+1)]
dp[0][0] = money
max_p = money

for i in range(1, N+1):
    for j in range(M+1):
        dp[i][j] = dp[i-1][j]
        if j > 0:
            for l in range(i):
                x = dp[l][j-1] % prices[l] + dp[l][j-1]//prices[l]*prices[i]
                if dp[i][j] < x:
                    dp[i][j] = x
            if max_p < dp[i][j]:
                max_p = dp[i][j]
print(max_p)


Measured memory_bytes: 9232
#include<stdio.h>

int main()
{
	int i, cnt = 0;
	char S[4], T[4];
		scanf("%s", S);
		scanf("%s", T);
		for (i = 0; i < 3; i++) {
			if (S[i] == T[i])
				cnt++;
		}
		printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    #define Mod 1000000007
    #define INF 1e9
    #define INFL 9e18
    #define EPS 1e-9
    #define pb push_back
    #define mp make_pair
    #define SET(a) memset(a,-1,sizeof(a))
    #define CLR(a) memset(a,0,sizeof(a))
    #define CPY(a,b) memcpy(a,b,sizeof(a))
    #define all(a) (a).begin(),(a).end()
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define N 100005
    #define fs first
    #define sc second
    using namespace std;

    typedef  long long int ll;
    typedef pair<ll,ll> ii;
    typedef vector <ii> vii;
    typedef vector <ll> vi;


    int main()
    {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios;

    ll n;
    int arr[5][105],dp[105];
cin>>n;
for(int i=1;i<=2;i++)
{
    for(int j=1;j<=n;j++)
        cin>>arr[i][j];
}
dp[n]=arr[2][n];
for(int i=n-1;i>=1;i--)
    dp[i]=dp[i+1]+arr[2][i];
ll ans=0,sum=0;
for(int i=1;i<=n;i++)
{
    sum+=arr[1][i];
   // cout<<sum+dp[i]<<endl;
    ans=max(ans,sum+dp[i]);
}
cout<<ans<<endl;





    return 0;


    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N, P;
  cin >> N >> P;
  string S;
  cin >> S;
  lint ans = 0;
  if(P == 2) {
    REP(i, N) {
      if(S[i] == '0' || S[i] == '2' || S[i] == '4' || S[i] == '6' || S[i] == '8') ans += i+1;
    }
  } else if(P == 5) {
    REP(i, N) {
      if(S[i] == '0' || S[i] == '5') ans += i+1;
    }
  } else {
    vector<lint> cnt(P);
    cnt[0] += 1;
    lint now = 0;
    lint base = 1;
    IREP(i, N) {
      now = (now + (S[i]-'0')*base)%P;
      cnt[now]++;
      base = base * 10 % P;
    }
    REP(i, P) {
      ans += cnt[i]*(cnt[i]-1)/2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
using System;
using System.Linq;

namespace ABC154C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            Console.WriteLine(As.GroupBy(x => x).Count() == N ? "YES" : "NO");
        }
    }
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int k, x; cin >> k >> x;
    int left = x - k + 1;
    if( left < -1e6 ) left = -1e6;
    int right = x + k - 1;
    if( right > 1e6 ) right = 1e6;

    FOR( i, left, right + 1 ){
        cout << i;
        if( i == right ) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int N;
  std::cin >> N;

  int min = 999999999;
  for ( int i = 1; i <= N /2; i++ ) {
    int A = i;
    int B = N - i;
    int sum = 0;
    while ( A > 0 || B > 0 ) {
      sum += ( A % 10 ) + ( B % 10 );
      A /= 10;
      B /= 10;
    }
    if ( sum < min ) {
      min = sum;
    }
  }
  std::cout << min << std::endl;
  return 0;
}


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

ll n,c[51],d[51][21][2],v[51][21][2];
string s[51];

ll fnc(int ke, int pos, bool dik) {
   if(pos == s[ke].size()) return 0;
   ll &done = v[ke][pos][dik];
   ll &w = d[ke][pos][dik];
   if(done) return w;
   done = 1, w = 1e18;

   bool pal = 1;
   if(!dik) {
      for(int j=pos, k=s[ke].size()-1; j<k; j++, k--) {
         if(s[ke][j] != s[ke][k]) pal = 0;
      }
   }
   else {
      for(int j=0, k=pos; j<k; j++, k--) {
         if(s[ke][j] != s[ke][k]) pal = 0;
      }
   }
   if(pal) return w = 0;

   for(int i=0; i<n; i++) {
      bool yes = 1;
      int j, k;
      if(!dik) {
         for(j=pos, k=s[i].size()-1; j<s[ke].size() && k>=0 && yes; j++, k--) {
            if(s[ke][j] != s[i][k]) yes = 0;
         }
         if(yes) {
            if(k < 0) w = min(w, c[i] + fnc(ke, j, 0));
            else w = min(w, c[i] + fnc(i, k, 1));
         }
      }
      else {
         for(j=pos, k=0; k<s[i].size() && j>=0 && yes; j--, k++) {
            if(s[ke][j] != s[i][k]) yes = 0;
         }
         if(yes) {
            if(j < 0) w = min(w, c[i] + fnc(i, k, 0));
            else w = min(w, c[i] + fnc(ke, j, 1));
         }
      }
   }
   return w;
}

int main() {
   cin >> n;
   for(int i=0; i<n; i++) cin >> s[i] >> c[i];
   ll ans = 1e18;
   for(int i=0; i<n; i++) ans = min(ans, c[i] + fnc(i, 0, 0));
   if(ans == 1e18) ans = -1;
   cout << ans << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define int long long
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e5+5;


int32_t main() {
	int n, m;
	cin >> n >> m;
	vector<int> cont(n+5, 0);
	for(int i = 0; i < m; i++) {
		int l, r;
		cin >> l >> r;
		cont[l]++;
		cont[r+1]--;
	}
	int s = 0, ans = 0;
	for(int i = 1; i <= n; i++) {
		s += cont[i];
		if(s == m) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
struct po {
    ll n;
    stack<pair<ll, ll>> pll;
};
 
vector<po> nya;
 
void dfs(po *p, ll d, ll cost[], bool visited[]) {
    if(!visited[(*p).n]) {
        cost[(*p).n] = d;
        visited[(*p).n] = true;
        for(;!(*p).pll.empty();) {
            dfs(&nya[(*p).pll.top().first], d + (*p).pll.top().second, cost, visited);
            (*p).pll.pop();
        }
    }
}
 
int main() {
    ll N;
    cin >> N;
    ll cost[N + 1];
    nya.resize(N + 1);
    for(int i = 0;i <= N;i++) {
        nya[i].n = i;
    }
    for(int i = 0;i < N - 1;i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        nya[u].pll.push(pair<ll, ll>(v, w));
        nya[v].pll.push(pair<ll, ll>(u, w));
    }
    bool visited[N + 1];
    fill(visited, visited + N + 1, false);
    dfs(&nya[1], 0, cost, visited);
 
    for(int i = 1;i <= N;i++) {
        cout << cost[i]%2 << endl;
    }
    return 0;
}

Measured memory_bytes: 69248
n = int(input())
t = list(map(int,input().split()))
m = int(input())
origin,ans = [],[]

for _ in range(m):
	p,x = map(int,input().split())
	origin.append(t[p-1])
	t[p-1] = x
	ans.append(sum(t))
	t[p-1] = origin[0]
	origin = []

for i in range(m):
	print(ans[i])

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val flag = (0 until s.length).map{i ->
        s.substring(s.length-1-i..s.length-1) + s.substring(0..s.length-2-i)
    }.any{it == t}

    println(if (flag) "Yes" else "No")
}

Measured memory_bytes: 33700
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	if (a%4==0||a%7==0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	for (int i=1;i*4+7<=a;i++)
	{
		if ((a-i*4)%7==0)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
# 素数と個数を求める
def factorize(n):
    res = []
    for i in range(2,n):
        if i*i > n: break
        if n%i: continue
        res += [[i,0]]
        while n%i == 0:
            n //= i
            res[-1][1] += 1
    if n != 1: res += [[n,1]]
    return res

n = int(input())
P = factorize(n)
ans = 0
for p, c in P:
    for i in range(1, c+1):
        if c <= 0: break
        c -= i
        if c >= 0: ans += 1
print(ans)


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

vector<int> G;

int root(int x){
    if(x == G[x]) return x;
    else return G[x] = root(G[x]);
}

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

    int n, m;
    cin >> n >> m;
    vector<int> A(m), B(m);
    REP(i, m){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    G.resize(n);

    int cnt = 0;
    REP(i, m){
        REP(j, n) G[j] = j;

        REP(j, m){
            if(i == j) continue;
            int t1, t2;
            t1 = root(A[j]);
            t2 = root(B[j]);
            if(t1 == t2) continue;
            if(t1 > t2) swap(t1, t2);
            G[t1] = t2;
        }
        
        set<int> st;
        REP(j, n){
            st.insert(root(j));
        }

        if(st.size() != 1) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

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

long long INF = 1LL<<60;
int main(){
    ll a,b;
    cin>>a>>b;
    ll GCD=gcd(a,b);
    ll ans=1;
    ll p=2;
    while(p*p<=GCD){
        if(GCD%p==0)ans++;
        while(GCD%p==0)GCD/=p;
        p++;
    }
    if(GCD!=1)ans++;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    if(k<n){
      System.out.println(k*x + (n-k)*y);
    }else{
      System.out.println(n*x);
    }
  }
}

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

const int MOD = 1e9 + 7;

const int N = 1e5;

int fact[N + N - 2 + 1];

int bin_pow(int x, int a) {
    int res = 1;
    while (a > 0) {
        if (a & 1) {
            res = (res * 1ll * x) % MOD;
        }
        x = (x * 1ll * x) % MOD;
        a >>= 1;
    }
    return res;
}

int rev(int x) {
    return bin_pow(x, MOD - 2);
}

int mult(int a, int b) {
    return (a * 1ll * b) % MOD;
}

int sum(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}

int cnk(int n, int k) {
    return mult(mult(fact[n], rev(fact[n - k])), rev(fact[k]));
}

int main() {
    fact[0] = 1;
    for (int i = 1; i <= N + N - 2; ++i) {
        fact[i] = mult(i, fact[i - 1]);
    }

    int H, W, A, B;
    scanf("%d%d%d%d", &H, &W, &A, &B);

    int ans = 0;
    for (int x1 = B + 1; x1 <= W; ++x1) {
        int y1 = H - A;
        int x2 = W - x1 + 1;
        int y2 = A;
        ans = sum(ans, mult(cnk(x1 + y1 - 2, x1 - 1), cnk(x2 + y2 - 2, x2 - 1)));
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

vector<bool> sieve(1000007,true);

void help(){
     sieve[0] = false;
     sieve[1] = false;

     for(int i=2;i*i<=1000000;++i){
        if(sieve[i]){
            for(int j=i*i;j<=1000000;j+=i)
                sieve[j] = false;

        }
     }


}

int main() {
   fastIO



   int k,x;
   cin>>k>>x;

   set<int> st;

   for(int i=x;i>x-k;--i)
    st.insert(i);

    for(int i=x;i<k+x;++i)
    st.insert(i);

    for(auto ans:st)
        cout<<ans<<" ";



   return 0 ;
      }


Measured memory_bytes: 384
import math

a, b, x = map(int, input().split())

t = 2*x/(a*a)-b
if t >= 0 :
    print(math.degrees(math.atan2(2*b-2*x/(a*a), a)))
else :
    print(math.degrees(math.atan2(b, 2*x/(a*b))))

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

int func1(int ,int);

int main(){
  int out;
  int x,y;
  scanf("%d %d",&x,&y);
  if(x < 1 || y > 1000000000) exit(2);
  out = func1(x,y);
  printf("%d\n",out);
  return 0;
}

int func1(int x,int y){
  int a;
  int b;
  if (x > y) {
    a = y;
    y = x;
    x = a;
  }
  while ((b = y % x) != 0) {
    y = x;
    x = b;
  }
  return x;
}



Measured memory_bytes: 2048
//おまじない
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
//#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;

int main(){
    
    ll n,k;
    ll a[maxn];
    ll sum[maxn+1];
    ll ans = 0;
    map<ll,int> m;
    
    sum[0]=0;
    m[0]=1;
    
    cin >> n>>k;
    rep(i,n){
        cin >> a[i];
        a[i]--;
        sum[i+1]=sum[i]+a[i];
        if(i+1-k>=0)m[sum[i+1-k]%k]--;
        ans += m[sum[i+1]%k];
        m[sum[i+1]%k]++;
    }
    
    cout << ans<<endl;
    
    
    return 0;
}


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

int main() {

    string S;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < S.size(); ++i)
    {
        if(i >= S.size()-1-i) {
            break;
        }

        // cout << S[i] << ", " << S[S.size()-1-i] << endl;
        if(S[i] != S[S.size()-1-i]) {
            ans++;
        }

    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n; i++) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	ll res = 0;
	for (int i = 0; i < n; i++){
		auto iter_a = lower_bound(a.begin(), a.end(), b[i]);
		auto iter_c = upper_bound(c.begin(), c.end(), b[i]);
		int idx_a = distance(a.begin(), iter_a);
		int idx_c = distance(c.begin(), iter_c);
		res += idx_a*(c.size()-idx_c);
	}
	cout << res << endl;

}


Measured memory_bytes: 1408
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	num, _ := strconv.Atoi(next())
	return num
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

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

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

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

func main() {

	scanner.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	a := nextInts(n)

	dp := make([]int, n)
	for i := 1; i < n; i++ {
		dp[i] = math.MaxInt32
		stop := max(-1, i-(k+1))
		for j := i - 1; j > stop; j-- {
			if j >= 0 {
				dp[i] = min(dp[j]+abs(a[i]-a[j]), dp[i])
			}
		}
	}

	fmt.Println(dp[n-1])
}


Measured memory_bytes: 2816
import sys

n = int(sys.stdin.readline().rstrip())

def base_convert(n, b):
    res = ''
    while n:
        r = abs(n % b)
        res = str(r) + res
        n = (n - r) // b

    return int(res) if res else 0

def main():
    return base_convert(n, -2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
#include<vector> 
#include<iterator> 
#include<deque> 
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i <(n) ; i++)
#define rep2(i,s,n) for(long long i = (s); i < (n) ; i++)
#define ll long long
#define INF 9999999999;


int main(){
  int N,K;
  cin >> N>>K;
  vector<ll> v(N,0);
  vector<int> c(N);
  rep(i,N) cin >> c[i];

  rep2(i,1,N){
    ll v_temp = INF;
    rep2(j,1,K+1){
      int s=i-j;
      if(s<0){
        s = i-1;
      }
      ll cost = abs(c[i]-c[s]);
      if(v_temp > v[s] + cost) v_temp = v[s] + cost;
    }
    v[i] = v_temp;
    //rep(j,N) cout << v[j] <<" ";
    //cout << endl;
  }
  cout << v[N-1] <<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <complex>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;

#define INT_MAX std::numeric_limits<int>().max()
#define INT_MIN std::numeric_limits<int>().min()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

//#define _DEBUG_ 2
void run() {
	ll N, K;
	cin >> N >> K;
	vector<ll> cnt(100001, 0);
	std::set<ll> number;
	REP(i, N) {
		ll a, b;
		cin >> a >> b;
		cnt[a] += b;
		number.insert(a);
	}

	ll rank = 0;
	for (auto& p : number) {
		rank += cnt[p];
		if (rank >= K) {
			cout << p << endl;
			break;
		}
	}

}

int main() {
#ifdef _DEBUG_
	using std::chrono::system_clock;
	using std::chrono::duration_cast;
	system_clock::time_point  start, end;
	std::ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
	for (int i = 0; i < _DEBUG_; i++) {
		cout << "-------------------------- (cnt:" << i << ")" << endl;
		start = system_clock::now();
		run();
		end = system_clock::now();
		int elapsed = duration_cast<std::chrono::milliseconds>(end - start).count();
		cout << "-------------------------- (time:" << elapsed << "ms)" << endl << endl;
	}
#else
	run();
#endif
	return 0;
}

Measured memory_bytes: 3968
#include<stdio.h>

int main(void)
{
	char s[101];
	int i;
	int count=0;
	
	scanf("%s",s);
	
	for(i=0;i<100;i++){
		if(i%2==0&&s[i]=='L')
			count=1;
		if(i%2==1&&s[i]=='R')
			count=1;
	}
	
	if(count==1)
		printf("No");
	else
		printf("Yes");
	return 0;
}
			

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int N, Q, s, t;
long long a[200005], da[200005];
long tem = 0;

int main() {

	cin >> N >> Q >> s >> t;

	for (int i = 0; i < N+1; i++) {
		cin >> a[i];

		if (i != 0) {
			da[i] = a[i] - a[i - 1];
		}
	}

	for (int i = 1; i < N + 1; i++) {
		if (da[i] > 0) {
			tem -= s*da[i];
		}
		else {
			tem -= t*da[i];
		}
	}


	for (int i = 0; i < Q; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		r++;

		if (0 <= da[l]) {
			tem += s*da[l];
		}
		else {
			tem += t*da[l];
		}

		if (r <= N) {
			if (0 <= da[r]) {
				tem += s*da[r];
			}
			else {
				tem += t*da[r];
			}
		}

		da[l] += x;
		da[r] -= x;

		if (0 <= da[l]) {
			tem -= s*da[l];
		}
		else {
			tem -= t*da[l];
		}

		if (r <= N) {
			if (0 <= da[r]) {
				tem -= s*da[r];
			}
			else {
				tem -= t*da[r];
			}
		}


		cout << tem << endl;
	}



	return 0;
}



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

int main(){
  int n,i,j,minj=0,a=0,count=0;
  int *raw;

  scanf("%d",&n);

  if(1>n || n > 100 ) exit(8);

  raw = (int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++){
    scanf("%d",raw+i);
    if(0 > raw[i] ||100 <  raw[i]) exit(8);
  }

  for(i=0; i<n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(raw[j] < raw[minj])
	minj = j;
    }
    a = raw[i];
    raw[i]=raw[minj];
    raw[minj]=a;
    if(i != minj) count++;
    
  }
  

  for(i=0; i < n; i++){
    if(i)printf(" ");
    printf("%d",raw[i]);
  }

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

  free(raw);

  return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MAXN=300001;
ll par[MAXN];
ll rnk[MAXN];
ll Size[MAXN];

void shoki(){
    for(ll i=0;i<MAXN;i++) {par[i]=i; rnk[i]=0; Size[i]=1;}
}

ll sch(ll x){
    if(par[x]==x) return x;
    else return par[x]=sch(par[x]);
}

void con(ll A,ll B){
    A=sch(A);
    B=sch(B);
    if(A==B) return;
    if(rnk[A]>rnk[B]) swap(A,B);
    par[A]=B;
    Size[B]+=Size[A];
    Size[A]=Size[B];
    if(rnk[A]==rnk[B]) rnk[B]++;

    return;
}

ll is_size(ll k){
    return Size[sch(k)];
}

bool same(ll A,ll B){
    return sch(A)==sch(B);
}

int main(){
    shoki();
    ll N,M; cin>>N>>M;
    rep(i,M){
        ll a,b; cin>>a>>b; a--; b--;
        con(a,b);
    }
    ll ans=-INF;
    rep(i,N) ans=max(ans,is_size(i));
    cout<<ans<<endl;

}

Measured memory_bytes: 10648
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}void _p() {cout << "]\n";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=========================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   
    cin>>n;
    string a;
    while (n>0)
    {
        a+=char('a'+(n-1)%26);
        n=(n-1)/26;
    }
    
    reverse(all(a));
    
    
    cout<< a <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}


Measured memory_bytes: 3644
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main(){
    nextLine()
    S := nextLine()

    var leftAdd int = 0
    var tmp int = 0

    for _, ch := range S{
        if ch == ')'{
            if tmp == 0 {
                leftAdd += 1
            }else{
                tmp -= 1
            }
        }else{
            tmp += 1
        }
    }


    for i := 0; i < leftAdd; i++ {
        fmt.Print("(")
    }
    fmt.Print(S)
    for i := 0; i < tmp; i++ {
        fmt.Print(")")
    }
    fmt.Print("\n")
}


Measured memory_bytes: 640
#include <stdio.h>

int factorial(int n){
    unsigned long long int ret=1;
    for(int i=1;i<=n;i++)ret=(ret*i)%1000000007;
    return (int)ret;
}//n!のMOD10^9+7を返すやつ

int main(void){
    int N;
    scanf("%d",&N);
    printf("%d\n",factorial(N));
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll a=s.size();
        if(a%2==0)
        {
            a--;
            a--;
        }
       else
       {
           a--;
       }
        
            
            x:
            for(ll i=0;i<a/2-1;i++)
            {
                if(s[i]!=s[a/2+i])
                {
                    a--;
                    a--;
                    goto x;
                }
            }
        
        cout<<a;
    }    
    return 0;
}


Measured memory_bytes: 3620
R,G,B,n=map(int,input().split())
sum_rg=[0 for i in range(n+1)]
for r in range(n+1):
	for g in range(n+1):
		tmp=R*r+G*g
		if tmp>n:
			break
		else:
			#print(f'Bb:{n-tmp}')
			sum_rg[n-tmp]+=1
#print(sum_rg)
count=0
for i in range(n//B+1):
	count+=sum_rg[i*B]
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int maxn = 1e5 + 10;
ll A[maxn];

ll LCM(ll a, ll b) {
  return a / __gcd(a,b) * b;
}

int main() {
  fastio;
  ll N, M;
  cin >> N >> M;
  ll lcm = 1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    // if (A[i] & 1) { cout << 0 << endl; return 0; }
    A[i] /= 2;
    lcm = LCM(lcm, A[i]);
    if (lcm > M) {
      cout << 0 << endl;
      return 0;
    }
  }

  for (int i = 0; i < N; i++) {
    if ((lcm / A[i]) % 2 == 0) {
      cout << 0 << endl; return 0;
    }
  }

  ll res = (M / lcm);
  res = (res + 2 - 1) / 2;
  cout << res << endl;
  
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
    // ここに処理を記述

    string S;
    cin >> S;

    ll K;
    cin >> K;

    ll ans = 0;

    if(S.length() == 1){
        ans = K / 2;
        cout << ans << "\n";
        return 0;
    }
    else if(S.find_first_not_of(S[0]) == string::npos){
        ans = S.length() * K / 2;
        cout << ans << "\n";
        return 0;
    }

    bool top_check = true;
    bool flg = true;
    char temp = S[0];
    int count = 0;
    REP(i,S.length()){
        if(S[i] == temp){
            count++;
        }
        else if(top_check == true){
            top_check = false;
            if(count % 2 == 0) flg = false;
            ans += (count/2);
            temp = S[i];
            count = 1;
        }
        else{
            ans += (count/2);
            temp = S[i];
            count = 1;
        }
    }
    ans += (count/2);
    if(count % 2 == 0) flg = false;
    if(S[0] != S[S.length() - 1]) flg = false;

    ans = ans * K;

    if(flg == true) ans += (K - 1);

    cout << ans << "\n";

return 0;
}

Measured memory_bytes: 256
S = input()
# S = "JSKK"
r = "No"
S_unique = list(set(S))
if len(S_unique) == 2:
    T = S[1] + S[2] + S[3]
    T_unique = list(set(T))
    if len(T_unique) == 2:
        T = S[0] + S[2] + S[3]
        T_unique = list(set(T))
        if len(T_unique) == 2:
            T = S[0] + S[1] + S[3]
            T_unique = list(set(T))
            if len(T_unique) == 2:
                T = S[0] + S[1] + S[2]
                T_unique = list(set(T))
                if len(T_unique) == 2:
                    r = "Yes"
print(r)

Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, LL> Vec2;
typedef tuple<LL, LL, LL> Tll;
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
struct Edge { LL to, cost; };
LL h, w, n, m, s, t, k, ans = 0, a[1000000], pos[10000][10000], sum, dp[10000][10000];
int main() {
	cin >> n >> m;
	s = log10(m);
	m += n*pow(10, s+1);
	LL i = 1;
	while (m>=i*i) {
		if (m == i*i) {
			cout << "Yes" << endl;
			return 0;
		}
		i++;
	}
	cout << "No" << endl;
	return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

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

//ａをbで割る
long long mod_div(long long a,long long b){
	if(a % b == 0)return a/b;
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}
 
ll kaijo[111111];
vector<ll> v;

void seica(){
	kaijo[0] = 1;
	for(ll i = 1;i < 111111;i++){
		kaijo[i] = kaijo[i-1] * i % MOD;
	}
}

int main(){
	
	seica();
	ll n, m;cin >> n >> m;
	
	for(int i = 2;i*i <= m;i++){
		int cou = 0;
		while(m % i == 0){
			cou++;
			m /= i;
		}
		if(cou)v.PB(cou);
	}
	if(m > 1)v.PB(1);
	
	ll ans = 1;
	REP(i,v.size()){
		ans *= (mod_div(kaijo[n+v[i]-1],(kaijo[n-1]*kaijo[v[i]])%MOD));
		ans %= MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <string> 
#include <cctype>

std::string s;
std::string p;

int main()
{
	std::getline(std::cin, s);
	std::getline(std::cin, p);

	int s_len = s.length();
	int p_len = p.length();

	bool flag1 = false;
	for (int i = 0; i < s_len; i++)
	{
		bool flag2 = true;
		for (int j = 0; j < p_len; j++)
		{
			int s_i = (i + j < s_len) ? (i + j) : (i + j) % s_len;
			if (s[s_i] != p[j])flag2 = false;
		}
		if (flag2)
		{
			flag1 = true;
			break;
		}
	}
	if (flag1)
	{
		std::cout << "Yes\n";
	}
	else
	{
		std::cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3200
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    string x;
    cin >> x;
    vector<int> bi(N);
    int cnt = 0;
    rep(i, N) {
        bi[i] = x[i] - '0';
        if (bi[i] == 1)
            cnt++;
    }

    ll MOD1 = cnt - 1, MOD2 = cnt + 1;
    ll can1 = 0, can2 = 0, exp = 0;

    for (int i = N - 1; i > -1; i--) {
        if (MOD1 > 0)
            can1 += modpow(2, exp, MOD1) * bi[i] % MOD1;
        can2 += modpow(2, exp, MOD2) * bi[i] % MOD2;
        exp++;
    }

    for (int i = 0; i < N; i++) {
        bool judge = 0;
        ll first;
        if (bi[i] == 0) {
            first = (can2 + modpow(2, N - 1 - i, MOD2)) % MOD2;
        } else {
            if (MOD1 <= 0)
                first = 0, judge = 1;
            else first = (can1 - modpow(2, N - 1 - i, MOD1)) % MOD1;
        }

        int ans;
        if (judge) ans = 0;
        else ans = 1;
        while (first != 0) {
            first %= __builtin_popcount(first);
            ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4428
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  char a,b;
  cin >> a >> b;
  
  if(a == b) cout << "H" << endl;
  else cout << "D" << endl;

  return 0;
}

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 998244353

const int N = 200000;

int n,k;
long long S[2031][2031];
long long dp[2031][2031];

int used[2031];

long long C[4031][4031];

long long solver(int n,int pairs,int fr){
	//cout<<n<<" "<<pairs<<" "<<fr<<endl;
	long long res=0;
	for (int in_pairs=0;in_pairs<=n;in_pairs++){
		long long here=dp[pairs][in_pairs];
		//cout<<in_pairs<<" @"<<here<<endl;
		long long not_in_pairs=n-in_pairs;
		// split "not in pairs" over fr spots
		if (fr==0){
			if (not_in_pairs==0)
				res+=here;
			continue;
		}
		//cout<<in_pairs<<" "<<not_in_pairs<<" "<<fr<<" "<<here<<endl;
		long long ways_to_split=C[not_in_pairs+fr-1][fr-1];
		here*=ways_to_split;
		res+=here%bs;
	}
	return res%bs;
}
int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);

	for (int i=0;i<=4000;i++){
		for (int j=0;j<=i;j++){
			if (j==0||j==i)
				C[i][j]=1;
			else
			{
				C[i][j]=C[i-1][j]+C[i-1][j-1];
				C[i][j]%=bs;
			}
		}
	}

	cin>>k>>n;

	dp[0][0]=1;
	for (int i=1;i<=2000;i++){
		for (int j=0;j<=2000;j++){
			S[i-1][j]=dp[i-1][j];
			if (j>0)
				S[i-1][j]+=S[i-1][j-1];
			S[i-1][j]%=bs;
		}
		for (int j=0;j<=2000;j++){
			// don't take
			dp[i][j]=dp[i-1][j];
			if (j>0) // take some
			{
				dp[i][j]=dp[i][j]+S[i-1][j-1]*2;
				dp[i][j]%=bs;
			}
		}
	}

	for (int s=2;s<=2*k;s++){
		for (int i=1;i<=k;i++){
			used[i]=0;
		}

		int fr=0;
		int pairs=0;

		for (int j=1;j<=k;j++){
			if (used[j])
				continue;
			used[j]=1;
			if (j*2==s)
				continue;
			int rem=s-j;
			if (rem<1||rem>k)
				fr++;
			else
			{
				pairs++;
				used[rem]=1;
			}
		}

		//cout<<fr<<" "<<pairs<<endl;

		if (s%2==1){
			long long res=0;
			//cout<<pairs<<" "<<fr<<endl;
			res=solver(n,pairs,fr);
			cout<<res<<endl;
		}
		else
		{
			long long res=0;
			res=solver(n,pairs,fr)+solver(n-1,pairs,fr);
			res%=bs;
			cout<<res<<endl;
		}
	}

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 189440