akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        ll N, A, B;
        cin >> N >> A >> B;
        cout << min(A, B) << ' ' << max(0LL, A+B-N) << endl;
}


Measured memory_bytes: 3632
#ifndef TEMPLATE
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x,v) memset((x),(v),sizeof((x)));
#define A(x) (x).begin(),(x).end()
#define re(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define erp(i,k,n) for(int i=n;i>=k;i--)
#define input(v,n) re(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using vvi = vector<vi>;
using tp = tuple<int,int,int>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
#endif
// ===================== MANASH =================== //

int n;

void test() {

      cin >> n;
      int m; cin >> m;
      vi dp(n+1);
      vvi adj(n+1);
      bool vis[n+1] = {0}, in[n+1] = {0};
      re(i,m) {
            int a,b;
            cin >> a >> b;
            adj[a].push_back(b);
            in[b] = true;
      }

      function<void(int)> dfs = [&]( int u ) {
            dp[u] = 0;
            vis[u] = 1;
            for( int v : adj[u]) {
                  if(!vis[v]) dfs(v);
                  dp[u] = max(dp[u],1+dp[v]);
            }
      };

      rep(i,1,n) if( !in[i] and !vis[i]) {
            dfs(i);
      }
      cout << *max_element(A(dp));
}

signed main() {

      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
      int T = 1;
      //cin >> T;
      for( int tt = 1; tt <= T; tt++) {
            //cout << "Case #" << tt << " ";
            test();
            cout << "\n";
      }
      return 0;

}

Measured memory_bytes: 17452
import numpy as np

in1 = input()
N = int(in1.split()[0])
D = int(in1.split()[1])
count=0

for i in range(N):
  in_xy = input()
  x = int(in_xy.split()[0])
  y = int(in_xy.split()[1])
  dist = np.sqrt(x*x+y*y)
  if(dist <= D):
    count+=1
print(count)

Measured memory_bytes: 26848
#include<iostream>
using namespace std;
int main(){
  long long int n,i=1,ans=0;
  cin>>n;
  while(1){
    long long int s=i*i;
    if(s>n) break;
    else ans=s;
    i++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <ctime>
#include <iomanip>
#include <numeric>
using namespace std;
const int MAX = 2e5 + 4;
int convert(int n, int k)
{
	int counter = 0;
	while (n)
	{
		n /= k;
		counter++;
	}
	return counter;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	cout << convert(n, k);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000009
#define rep(i,n) for (ll i = 0; i < n; i++)
#define  pb push_back
#define mp make_pair

 int main(){
    ios::sync_with_stdio(false);
  cin.tie(0);
ll a,b,c,d ;
cin>>a>>b>>c>>d;
 ll ans1 = a*c;
 ll ans2 = a*d;
 ll ans3 = b*c;
 ll ans4 = b*d;
 ll ans = max(max(ans1,ans2),max(ans3,ans4));
 cout<<ans;
     }
     
 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const ll mod = 1e9 + 7;

int main()
{
    int n, j;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    ll h, w;
    rep(i, n - 1)
    {
        if (a[i] == a[i + 1])
        {
            h = a[i];
            i += 2;
            j = i;
            break;
        }
        j = i;
    }
    for (int k = j; k < n - 1; k++)
    {
        if (a[k] == a[k + 1])
        {
            w = a[k];
            cout << h * w << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll n,m,n1,ans,r,a,b,i,j,t;
   while(cin>>n)
   {
      n1=n/10;
      r=n%10;
      if(n1==9||r==9)printf("Yes\n");
      else printf("No\n");
   }
   return 0;
}


Measured memory_bytes: 256
//遅延セグ木早書きチャレンジ0:00~
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<17)
class RAQxRMQ{
private:
    ll dat[N*2],laz[N*2];
    void eval(int k){
	dat[k]+=laz[k];
	if(k<N-1){
	    laz[k*2+1]+=laz[k];
	    laz[k*2+2]+=laz[k];
	}
	laz[k]=0;
    }
    ll dfs(int l,int r,int a,int b,int k){
	eval(k);
	if(l<=a&&b<=r)return dat[k];
	if(b<=l||r<=a)return (ll)mod*(ll)mod;
	ll vl=dfs(l,r,a,(a+b)/2,k*2+1);
	ll vr=dfs(l,r,(a+b)/2,b,k*2+2);
	return min(vl,vr);
    }
    void ufs(int l,int r,int a,int b,int k,ll x){
	eval(k);
	if(l<=a&&b<=r){laz[k]+=x;eval(k);return;}
	if(b<=l||r<=a)return;
	ufs(l,r,a,(a+b)/2,k*2+1,x);
	ufs(l,r,(a+b)/2,b,k*2+2,x);
	dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
public:
    void Init(){
	lol(i,2*N)dat[i]=laz[i]=0;
    }
    void Add(int l,int r,ll x){
	ufs(l,r+1,0,N,0,x);
    }
    ll Min(int l,int r){
	return dfs(l,r+1,0,N,0);
    }
};
int main(){
    int n,q;cin>>n>>q;
    RAQxRMQ seg;seg.Init();
    while(q--){
	ll z,a,b,c;
	cin>>z;
	if(z==0){
	    cin>>a>>b>>c;
	    seg.Add(a,b,c);
	}
	if(z==1){
	    cin>>a>>b;
	    cout<<seg.Min(a,b)<<endl;
	}
    }
    return 0;
}



Measured memory_bytes: 7196
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
char s[200005];
int main()
{
	int cnt=0;
	scanf("%s",&s);
	int n=strlen(s);
	string a="",b="";
	for(int i=0;i<n;i++)
	{
		a+=s[i];
		if(a!=b)
		{
			b=a;
			cnt++;
			a="";
		}
	}
	printf("%d\n",cnt);
	return 0;
} 

Measured memory_bytes: 384
k_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(k_list[k - 1])

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

int main() {

int K,S;
cin >> K >> S;
int ans = 0;

for(int x=0; x <= K ; x++){
  for(int y=0; y <= K; y++){
    int z = S - x - y;
    if(z >= 0 && K >= z){
      ans +=1;
    }
  }
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 3524
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a,v=map(int, input().split())
b,w=map(int, input().split())
t=int(input())
if (v-w)*t>=abs(a-b):
    print("YES")
else:
    print("NO")

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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    long long a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<a){
        cout << k << "\n";
        return 0;
    }
    if(k<=a+b) {
        cout << a << "\n";
        return 0;
    }
    cout << 2*a-k+b << "\n";
    return 0;
} 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(int k) {
        if(data[k] < 0) return k;
        return data[k] = find(data[k]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int k) {
        return -data[find(k)];
    }
};

int main() {
    int h, w;
    cin >> h >> w;
    UnionFind uf(h * w);
    char masu[h + 2][w + 2];
    // Fill(masu, 'X');
    fill(masu[0], masu[h + 2], 'X');
    rep(i, h) rep(j, w) cin >> masu[i + 1][j + 1];
    int v[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    map<int, int> bk;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            rep(k,4)
                if(masu[i][j] == '.' && masu[i + v[k][0]][j + v[k][1]] == '#'){
                    uf.unite((i-1) * w + j - 1, (i + v[k][0] - 1) * w + j + v[k][1] - 1);
                }
    rep(i, h) rep(j, w) if(masu[i + 1][j + 1] == '#') bk[uf.find(i * w + j)]++;
    ll ans = 0;
    for(auto b : bk)
        ans += (ll)b.second * (uf.size(b.first) - b.second);
    cout << ans << endl;
}


Measured memory_bytes: 7424
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sn = new Scanner(System.in);
		while(true){
			int n = sn.nextInt();
			int m = sn.nextInt();
			if(n == 0 && m == 0) break;
			ArrayList<Integer> vegies = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				vegies.add(sn.nextInt());
			}
			Collections.sort(vegies);
			Collections.reverse(vegies);

			int sum = 0;
			for(int i = 0; i < n; i++){
				if((i+1)%m != 0) sum += vegies.get(i);
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 66776
a,b = map(int, input().split())
#最大公約数
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
#print(gcd(a,b))

  #最小公倍数
def lcm(a,b):
  return a*b//gcd(a,b)

print(lcm(a,b))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    ll ans=0,l,r;
    if(n%2==0){//偶数の場合
        l=n/2-1;
        r=n-1;
        ans+=abs(v[r]-v[l]);
        if(n!=2){
            l=0;
            ans+=abs(v[r]-v[l]);
        }
        int flag=0;
        r--;
        while(l!=n/2-1){
            if(flag==0){//rを引いた
                ans+=abs(v[r]-v[l]);
                flag=1-flag;
                l++;
            }else if(flag==1){
                ans+=abs(v[r]-v[l]);
                flag=1-flag;
                r--;
            }
        }
        ll tmp=0;
        l=0;
        r=n/2;
        tmp+=abs(v[r]-v[l]);
        if(n!=2){
            r=n-1;
            tmp+=abs(v[r]-v[l]);
        }
        flag=0;
        l++;
        while(r!=n/2){
            if(flag==1){
                tmp+=abs(v[r]-v[l]);
                flag=1-flag;
                l++;
            }else if(flag==0){
                tmp+=abs(v[r]-v[l]);
                flag=1-flag;
                r--;
            }
        }
        ans=max(ans,tmp);
    }else if(n%2==1){//奇数の場合
        l=n/2;
        r=n-1;
        ans+=abs(v[r]-v[l]);
        l=0;
        ans+=abs(v[r]-v[l]);
        int flag=0;
        r--;
        while(r!=n/2){
            if(flag==0){//rを引いた
                ans+=abs(v[r]-v[l]);
                flag=1-flag;
                l++;
            }else if(flag==1){
                ans+=abs(v[r]-v[l]);
                flag=1-flag;
                r--;
            }
        }
        ll tmp=0;
        l=0;
        r=n/2;
        tmp+=abs(v[r]-v[l]);
        r=n-1;
        tmp+=abs(v[r]-v[l]);
        flag=0;
        l++;
        while(l!=n/2){
            if(flag==1){//rを引いた
                tmp+=abs(v[r]-v[l]);
                flag=1-flag;
                l++;
            }else if(flag==0){
                tmp+=abs(v[r]-v[l]);
                flag=1-flag;
                r--;
            }
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

ll dp[200005][3];
void solve()
{
    IN(n, k, r, s, p);
    string t; cin >> t;
    ll sum = 0;
    for (int j = 0; j < k; ++j)
    {
        int index = 0;
        for(int i = j; i < n; i += k)
        {
            index = i+k;
            chmax(dp[i+k][2], (t[i] == 'r' ? p : 0) + max(dp[i][0], dp[i][1]));
            chmax(dp[i+k][0], (t[i] == 's' ? r : 0) + max(dp[i][1], dp[i][2]));
            chmax(dp[i+k][1], (t[i] == 'p' ? s : 0) + max(dp[i][2], dp[i][0]));
        }
        sum += max(max(dp[index][0], dp[index][1]), dp[index][2]);
    }
    cout << sum << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 4560
struct FenwickTree{T}
    bi_tree::Vector{T} #bi_tree is shorthand for Binary Indexed Tree, an alternative name for Fenwick Tree
    n::Int
end

"""
    FenwickTree{T}(n::Integer)
Constructs a [`FenwickTree`](https://en.wikipedia.org/wiki/Fenwick_tree) of length `n`.
"""
FenwickTree{T}(n::Integer) where T = FenwickTree{T}(zeros(T, n), n)

"""
    FenwickTree(counts::AbstractArray)
Constructs a [`FenwickTree`](https://en.wikipedia.org/wiki/Fenwick_tree) from an array of `counts`
"""
function FenwickTree(a::AbstractVector{U}) where U
    n = length(a)
    tree = FenwickTree{U}(n)
    @inbounds for i = 1:n
        inc!(tree, i, a[i])
    end
    tree
end

Base.length(ft::FenwickTree) = ft.n
Base.eltype(::Type{FenwickTree{T}}) where T = T

"""
    inc!(ft::FenwickTree{T}, ind::Integer, val)
Increases the value of the [`FenwickTree`] by `val` from the index `ind` upto the length of the Fenwick Tree.
"""
function inc!(ft::FenwickTree{T}, ind::Integer, val = 1) where T
    val0 = convert(T, val)
    i = ind
    n = ft.n
    @boundscheck 1 <= i <= n || throw(ArgumentError("$i should be in between 1 and $n"))
    @inbounds while i <= n
        ft.bi_tree[i] += val0
        i += i&(-i)
    end
end

"""
    dec!(ft::FenwickTree, ind::Integer, val)
Decreases the value of the [`FenwickTree`] by `val` from the index `ind` upto the length of the Fenwick Tree.
"""
dec!(ft::FenwickTree, ind::Integer, val = 1 ) = inc!(ft, ind, -val)

"""
    incdec!(ft::FenwickTree{T}, left::Integer, right::Integer, val)
Increases the value of the [`FenwickTree`] by `val` from the indices from `left` and decreases it from the `right`.
"""
function incdec!(ft::FenwickTree{T}, left::Integer, right::Integer, val = one(T)) where T
    val0 = convert(T, val)
    inc!(ft, left, val0)
    dec!(ft, right, val0)
end

"""
    prefixsum(ft::FenwickTree{T}, ind::Integer)
Return the cumulative sum from index 1 upto `ind` of the [`FenwickTree`](@ref)
# Examples
```
julia> f = FenwickTree{Int}(6)
julia> inc!(f, 2, 5)
julia> prefixsum(f, 1)
 0
julia> prefixsum(f, 3)
 5
```
"""
function prefixsum(ft::FenwickTree{T}, ind::Integer) where T
    sum = zero(T)
    ind < 1 && return sum
    i = ind
    n = ft.n
    @boundscheck 1 <= i <= n || throw(ArgumentError("$i should be in between 1 and $n"))
    @inbounds while i > 0
        sum += ft.bi_tree[i]
        i -= i&(-i)
    end
    sum
end

Base.getindex(ft::FenwickTree{T}, ind::Integer) where T = prefixsum(ft, ind)
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n,q = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	ft = FenwickTree(a)
	for query in 1:q
		x,y,z = readline() |> split |> parseMap
		if x == 0
			inc!(ft,y+1,z)
		else
			println(prefixsum(ft,z)-(y>0 ? prefixsum(ft,y) : 0))
		end
	end
end

main()

Measured memory_bytes: 238500
<>;@y=map-$t+($t=$_),glob<>;map{@s=$_?@s[@s]:0..$#y;@s[$_-1,$_]=@s[$_,$_-1]for<>;@y=@y[@s]if$'>>$_&1}<>!~($/=$")..59;print$z+=$_,$"for@y

Measured memory_bytes: 48904
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
char s[407];
int main(){
    cin>>s+1;
    long long k;
    cin>>k;
    long long ans=0;
    long long n=strlen(s+1);
    for(long long i=n+1;i<=2*n;++i)
        s[i]=s[i-n];
    long long pos=0;
    for(long long i=2;i<=n;++i){
        if(s[i]!=s[i-1]){
            pos=i;
            break;
        }
    }
    if(n==1){
        cout<<k/2;
        return 0;
    }
    if(!pos)
        ans=n*k/2;
    else{
        long long cnt=1;
        for(long long i=pos;i<=n+pos-1;++i){
            if(s[i]==s[i-1])
                ++cnt;
            else{
                ans+=cnt/2;
                cnt=1;
            }
        }
        ans+=cnt/2;
        ans*=k-1;
        ans+=(pos-1)/2;
        cnt=1;
        for(long long i=pos;i<=n;++i){
            if(s[i]==s[i-1])
                ++cnt;
            else{
                ans+=cnt/2;
                cnt=1;
            }
        }
        ans+=cnt/2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b,c;
 	cin >> a>>b>>c;
 	if(a+b>=c&&a<=c){
 		cout << "YES" << endl;
 	}else{
 		cout << "NO" << endl;
 	}
 }

Measured memory_bytes: 256
let nk = stdin.ReadLine().Split() |> Array.map int
let (n, k) = (nk.[0], nk.[1])
let p = stdin.ReadLine().Split() |> Array.map int
let accum = p |> Array.fold (fun list elem -> (list |> List.head |> (+) elem)::list) [0] |> List.rev |> Array.ofList
let maxSum = [|k..n|] |> Array.map (fun x -> accum.[x] - accum.[x - k]) |> Array.max
((maxSum + k) |> double) / 2.0 |> stdout.WriteLine

Measured memory_bytes: 41300
H = int(input())
W = int(input())
N = int(input())

counter = 0
i = 0

if (H >= W):
    while(True):
        if (H*i) < N:
            counter += 1
        else:
            break
        i += 1
else:
    while(True):
        if (W*i) < N:
            counter += 1
        else:
            break
        i += 1

print(counter)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;;
#define llong long long
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
llong gcd( llong m, llong n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}
llong lcm( llong m, llong n )
{
    if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n);
}
int main(){
    llong n, m;cin >> n >> m;
    string s, t; cin >> s >> t;
    llong gc = gcd(n,m);
    llong lc = lcm(n,m);
    llong ans;
    if(n!=1 && m!=1){

    if(gc == 1){
        if(s[0]==t[0]){
        ans = n * m;
        }else{
            ans = -1;
        }
    }else {
        llong sstep = n/gc;
        llong mstep = m/gc;
        for(llong i =0; i<gc; i++){
            if(s[i*sstep] != t[i * mstep]){
                ans = -1;
                break;
            }else{
                if(i == gc-1){
                    ans = lc;
                }
            }

        }
    }
    }
    if(n==1 || m ==1){
            if(t[0]!=s[0]){
                ans = -1;
            }else{
                    ans = max(n,m);
            }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
# abc085_c

n, y = gets.split.map(&:to_i)

ans = [-1, -1, -1]

lambda do
  0.upto(n) do |a|
    0.upto(n - a) do |b|
      c = n - a - b
      if y == 10000*a + 5000*b + 1000*c
        ans = [a, b, c]
        return
      end
    end
  end
end.()
puts ans.join(' ')


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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n;
  cin >> n;
  cout << n/3 << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n,x;
	
	cin >> n >> x;
	
	vector<int>l(n,0);
	for(int i = 0; i < n; i++) {
		cin >> l.at(i);
	}
	
	int h = 0;
	int ans = 1;
	int i = 0;
	while (h <= x && i < n){
		h+= l.at(i);
		if(h > x) {
			//超えちゃってるので足さない
			
			//cout << "Over" << endl;
			
			
		} else {
			ans++;
			
			//cout << "Get " << h << ", " << ans << endl;
			
		}
		i++;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int x, A, B;
    cin >> x >> A >> B;
    cout << ( abs( A - x ) > abs( B - x ) ? "B" : "A" ) << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

k = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

answer = 0
nums = list(range(1, k+1))
for balls in itertools.combinations_with_replacement(nums, 3):
    i, j, l = balls[0], balls[1], balls[2]
    ans = gcd(i, j)
    ans = gcd(ans, l)
    if len(set(balls)) == 1:
        answer += ans
    elif len(set(balls)) == 2:
        answer += ans*3
    elif len(set(balls)) == 3:
        answer += ans*6
            
print(answer)

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

#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back

const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll GetDigit(ll num) {return log10(num)+1;}

int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    for(ll i = 0; i < n; i++) cin >> s[i];

    ll abc[n][27];
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < 26; j++){
            char c = 'a' + j;
            abc[i][j] = count(all(s[i]), c);
        }
    }

    string ans = "";
    for(ll i = 0; i < 26; i++){
        ll cnt = 1000000;
        for(ll j = 0; j < n; j++){
            cnt = min(cnt, abc[j][i]);
        }
        for(ll j = 0; j < cnt; j++){
            ans += (char)('a' + i);
        }
    }

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

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

int main(){
    int n,m;

    cin >> n >> m;

    vector<int> ac(n);
    vector<int> wa(n);

    for(int i=0; i<m; i++){
        int p;
        string s;
        cin >> p >> s;
        if(s == "AC"){
            ac[p-1]++;
        }else if(ac[p-1]==0){
            wa[p-1]++;
        }
    }

    int a=0,w=0;
    for(int i=0;i <n; i++){
        if(ac[i]>0){
            a++;
            w += wa[i];
        }
    }

    cout << a << " " << w << endl;
    
}

Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    auto tSit = new long[](100);
    tSit[] = -1;
    auto sheets = new int[](17);
    sheets[] = -1;
    int findSheet(int n) {
iLoop:foreach(i; iota(17)) {
            foreach(j; iota(i, 17)) {
                if(sheets[j] != -1) {
                    continue iLoop;
                }
                if(j-i+1 == n) {
                    return i;
                }
            }
        }
      return -1;
    }
    DList!int q;
    int t;
    while(tSit.back == -1) {
        foreach(ref i; sheets) {
            if(i >= 0 && t - tSit[i] == 17*(i%2) + 3*(i%3) + 19) {
                i = -1;
            }
        }
        if(t%5 == 0 && t/5 < 100) {
            q.insertBack(t/5);
        }
        while(!q.empty()) {
            auto i = q.front;
            auto n = (i%5 == 1 ? 5: 2);
            auto s = findSheet(n);
            if(s >= 0) {
                tSit[i] = t;
                foreach(j; iota(s, s+n)) {
                    sheets[j] = i;
                }
                q.removeFront();
            } else {
                break;
            }
        }
        ++t;
    }
    while(!stdin.eof()) {
        auto l = readln().chomp();
        if(l == "") {
            break;
        }
        auto n = l.to!int;
        writeln(tSit[n] - 5*n);
    }
}

Measured memory_bytes: 2460
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  for(int i = 1; i <= N; ++i) {
    int ans = 0;
    bool flag = false;
    for(int k = 1; k <= 100; ++k) {
      int x = k * k;
      for(int m = 1; m <= 100; ++m) {
        int y = m * m;
        ll res = x + y + (k * m);
        if(res > i) {
          break;
        }
        for(int l = 1; l <= 100; ++l) {
          int z = l * l;
          ll tmp = x + y + z + (k * m) + (m * l) + (l * k);
          if(tmp > i) {
            break;
          }
          if(i == tmp) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3552
n = int(input())
s = list(map(int, input().split()))
import numpy as np
s_array = np.array(s)
process = 0
while np.all(s_array%2 == 0):
    s_array = np.array(list(map(lambda x: x/2, s_array)))
    process += 1
else:
    print(process)

Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a)); sort(all(c));
    ll ans = 0;
    rep(i,n) {
        ll anibu = lower_bound(all(a),b[i]) - a.begin(); //b[i]より小となる個数
        ll cnibu = c.end() - upper_bound(all(c),b[i]); //b[i]より大となる個数
        ans += anibu*cnibu;
    }
    cout << ans << endl;
}    

Measured memory_bytes: 4552
#include <iostream>
#include <cmath>

int main( void )
{
	int n;
	std::cin >> n;

	int ans = 0;
	if( n % 2 == 0 ) {
		ans = n;
	}
	else {
		ans = n * 2;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#Two Switches
A,B,C,D = map(int,input().split())
if A <= C <= D <= B:
    print(D-C)
elif C <= A <= B <= D:
    print(B-A)
elif C <= A <= D <= B:
    print(D-A)
elif A <= C <= B <= D:
    print(B-C)
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int N,i; cin >> N >> i;
  cout << N-i+1 << endl;
}


Measured memory_bytes: 256
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 2e3 + 100, P = 924844033;

int n, k;
int vis[N][2];
LL f[N][2], g[N][2], fac[N];

int dfs(int i, int j) {
  vis[i][j] = 1;
  if (i + k > n) return 1;
  return dfs(i + k, j ^ 1) + 1;
}

void go(int len) {
  for (int i = 1; i <= len; i++) {
    memset(g, 0, sizeof g);
    for (int j = 0; j <= n; j++) {
      g[j][0] = (g[j][0] + f[j][0] + f[j][1]) % P;
      if (i != len) g[j + 1][1] = (g[j + 1][1] + f[j][0]) % P;
    }
    swap(f, g);
  }
}

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");

  cin >> n >> k;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % P;
  f[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 2; j++) {
      if (!vis[i][j]) go(dfs(i, j));
    }
  }
  LL ans = fac[n], t = -1;
  for (int i = 1; i <= n; i++) {
    ans = (ans + (g[i][0] + g[i][1]) * fac[n - i] % P * t) % P;
    t = -t;
  }
  cout << (ans + P) % P << endl;
  return 0;
}


Measured memory_bytes: 512
S = input()
y = int(S[0:4])
m = int(S[5:7])
d = int(S[8:10])
heisei_flag = 0
if y < 2018:
    heisei_flag = 1
elif y == 2019 and m <= 4:
    heisei_flag = 1

if heisei_flag == 1:
    print('Heisei')
else:
    print('TBD')

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

testimony = [[] for _ in range(n)]

for i in range(n):
    m = int(input())
    for j in range(m):
        x, y = map(int, input().split())
        x -= 1
        testimony[i].append([x, y])

ans = 0
for i in range(1 << n):
    flag = True

    for j in range(n):

        #if dishonest(=0), skip
        if (i >> j) & 1 == 0:
            continue

        for x, y in testimony[j]:
            if (i >> x) & 1 != y:
                flag = False

    if flag is True:
        ans = max(ans, bin(i).count("1"))

print(ans)

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

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    ll happy = 0;
    ll X;
    cin >> X;

    happy += (X/500)*1000;
    X -= (X/500)*500;
    happy += (X/5)*5;

    cout << happy << endl;

}



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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7
#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int n; cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];
  sort(d.begin(), d.end(), greater<int>());

  num = 1;
  for (int i = 1; i < n; ++i) {
    if (d[i-1] > d[i])++num;
  }
  
  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""


N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0

for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))


Measured memory_bytes: 7736
def nextPow(x):
    xx = 1
    while xx * 2 <= x:
        xx *= 2
    return xx

# 3//2 == 1
# 偶数と奇数は同じ答え
# 2 => 2 + 1
# 4 => 6 + 1
# 6 => 6 + 1
# 8 => 20 + 1
# 10 => 20 + 1
# 10 => 5,5, 7+7 + 3 + 3 1

import math

H = int(input())
result = 1

# ２の乗数分の配列が出来るはず
# 2の乗数で 敵の数が増える
# 2,4,8,16....
# 乗数が上がるごとに
# 2の乗数が一個増えると、その乗数 -1 増える

first = 1
if H == 1:
    print(1)
    exit(0)
elif H == 2:
    print(first + 1 + 1)
    exit(0)
elif H == 3:
    print(first + 1 + 1)
    exit(0)

result = 1
np = nextPow(H)
result += (np - 1) * 2

print(result)

# first = 1
# if H == 1:
#     print(1)
# elif H == 2:
#     print(first + 1 + 1)
# elif H == 3:
#     print(first + 1 + 1)
# elif H == 4:
#     print(first + 3 + 3)
# elif H == 5:
#     print(first + 3 + 3)
# elif H == 6:
#     print(first + 3 + 3)
# elif H == 7:
#     print(first + 3 + 3)
# elif H == 8:
#     print(first + 7 + 7)
# elif H == 9:
#     print(first + 7 + 7)
# elif H == 10:
#     print(first + 7 + 7)
# elif H == 11:
#     print(first + 7 + 7)
# elif H == 12:
#     print(first + 7 + 7)
# elif H == 13:
#     print(first + 7 + 7)
# elif H == 14:
#     print(first + 7 + 7)
# elif H == 15:
#     print(first + 7 + 7)
# elif H == 16:
#     print(first + 15 + 15)


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

char Data[100][100];
int H,W;
void dl (int x,int y,char target) {
	//cout << x << "/" << y << "/" << target << endl;
	Data[y][x] = '+';
	for (int i = -1;i < 2;i++) {
		//cout << "	" << i << "/" << Data[y][x+i] << ":";
		if (i==0) continue;
		if(x+i>=0 && x+i < W && Data[y][x+i] == target) {
			dl(x+i,y,target);
		}
		if(y+i>=0 && y+i < H && Data[y+i][x] == target) {
			dl(x,y+i,target);
		}
	}	
	return;
}
int main() {
	for(;;) {
		int ans = 0;
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		
		for (int i = 0;i < H;i++) {
			cin >> Data[i];
		}
		for (int i = 0;i < H;i++) {
			for (int j = 0;j < W;j++) {
				if (Data[i][j] != '+') {
					ans++;
					dl(j,i,Data[i][j]);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  vll s; 
  vll ord(n+1,-1); 
  ll c=1, l=0;
  {
    ll v=1;
    while(ord[v]==-1){
      ord[v]=s.size();
      s.push_back(v);
      v=a[v-1];
    }
    c=s.size()-ord[v];
    l=ord[v];
  }
  
  if(k<l) cout<<s[k]<<endl;
  else{
    k-=l;
    k%=c;
    cout<<s[l+k]<<endl;
  }
  
  
}

Measured memory_bytes: 8436
S = input()

YYMM = MMYY = False
if 1 <= int(S[:2]) <= 12:
    MMYY = True
if 1 <= int(S[2:]) <= 12:
    YYMM = True

ans = "NA"
if YYMM and MMYY:
    ans = "AMBIGUOUS"
elif YYMM:
    ans = "YYMM"
elif MMYY:
    ans = "MMYY"
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,m,to[200001],next[200001],tot,col[100001],head[100001],sum[3],cnt;
long long ans;
bool vis[100001],flag;
void add(int u,int v){to[++tot]=v,next[tot]=head[u],head[u]=tot;}
void dfs(int x,int color){
    ++cnt;
    col[x]=color;
    sum[color]++;
    vis[x]=true;
    for(int i=head[x];i;i=next[i]){
        if(!vis[to[i]])dfs(to[i],3-color);
        else if(col[x]==col[to[i]])flag=true;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }
    for(int i=1;i<=n;i++)if(!vis[i]){
        dfs(i,1);
        if(!flag)ans+=1LL*sum[1]*sum[2];
        else ans+=1LL*cnt*(cnt-1)/2;
        sum[1]=sum[2]=flag=cnt=0;
    }
    printf("%lld\n",ans-m);
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,Y;cin>>N>>Y;
	for(int x=0;x<=N;x++)
	{
		for(int y=0;y<=N-x;y++)
		{
			int z = N-x-y;
			int total = x*1e4 + y*5*1e3 + 1e3*z;
			if(total==Y)
			{
				cout<<x<<" "<<y<<" "<<z<<"\n";
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1\n";
	return 0;
}

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

using namespace std;

int main(int argc, char** argv)
{
    int a1, a2, a3; cin >> a1 >> a2 >> a3;
    vector<int> nums{a1, a2, a3};
    sort(nums.begin(), nums.end());
    int cost = 0;
    for (int i = 1; i < nums.size(); i++) {
        cost += nums[i] - nums[i-1];
    }
    cout << cost << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int  N, K;
    cin >> N >> K;

    int answer = 1;
    for (int i = 0; i < N; i++){
        if (answer < K){
            answer = answer * 2;
        }
        else {
            answer += K;
        }
    }
    cout << answer << endl;
}

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

int main()
{
    long long N, A, B, C, D;
    std::cin >> N >> A >> B >> C >> D;

    std::string out = "NO";
    for(int i=0; i<N; i++){
        long long l = C * i - D * (N-1-i);
        long long h = D * i - C * (N-1-i);
        if(l <= B-A && B-A <= h){
            out = "YES"; break;
        }
    }
    std::cout << out << std::endl;
}

Measured memory_bytes: 256
#define N 100001 
long p[N],r[N],n,m,i,b[N],a[N][2],c,d;int f(int x){if(p[x]==x)return x;return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);p[x]=y;r[y]+=r[x];r[x]=r[y];}int main(){scanf("%d%d",&n,&m);for(i=0;i<m;i++)scanf("%d%d",a[i],&a[i][1]);b[m]=n*(n-1)/2;for(i=0;i++<N;){p[i]=i;r[i]=1;};for(i=m;i-->0;){c=a[i][0],d=a[i][1];b[i]=b[i+1];if(f(c)!=f(d)){b[i]-=r[f(c)]*r[f(d)];u(c,d);}}for(i=0;i++<m;)printf("%ld\n",b[i]);}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int t , n;
int a[MAXX];

int main()
{
    string s , t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long gcd (long long x, long long y) {
    if (x < y) swap(x, y);
    if (y == 0) return x;
    return gcd(x % y, y);
}

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

long long f(long long x, long long a, long long b) {
    return x - x/a - x/b + x/lcm(a,b);
}
int main() {
    long long A, B;
    int C, D;
    cin >> A >> B >> C >> D;
    cout << f(B, C, D) - f(A-1, C, D) << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] chars = sc.next().toCharArray();

        char current = chars[0];
        int ans = 0;
        for (int i = 1; i < chars.length; i++) {
            if (current != chars[i]) {
                ans++;
                current = chars[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25804
#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll gcd(ll a,ll b)
{
  if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}

int  main()
{
 
   IOS;
    ll h,w;
    cin>>h>>w;
    ll dp[40][40]={0};
     for(ll i=1;i<=h;i++)
    {
        for(ll j=1;j<=w;j++)
        {
          char x;
          cin>>x;
          if(x=='.')
              dp[i][j]=1;
            else
              dp[i][j]=2;
        }
      }
      ll sp[500][500]={0};
      for(ll i=1;i<=h*w;i++)
    {
        for(ll j=1;j<=h*w;j++)
        {
          sp[i][j]=mod;
        }}
    for(ll i=1;i<=h;i++)
    {
      //cout<<"\n";
        for(ll j=1;j<=w;j++)
        {
          //cout<<dp[i][j]<<" ";
            ll k=(i-1)*w+j;
            if(dp[i][j]==2)
              continue;
            if(dp[i+1][j]==1)
            {
              ll r=(i)*w+j;
              sp[k][r]=1;
            }
            if(dp[i][j-1]==1)
            {
                ll r=(i-1)*w+j-1;
                sp[k][r]=1;
            }
            if(dp[i-1][j]==1)
            {
                  ll r=(i-2)*w+j;
                  sp[k][r]=1;
            }
            if(dp[i][j+1]==1)
            {
                  ll r=(i-1)*w+j+1;
              sp[k][r]=1;
            }


        }
    }
    for(ll i=1;i<=h*w;i++)
    {
        for(ll j=1;j<=h*w;j++)
        {
         // cout<<i<<" "<<j<<" "<<sp[i][j]<<"\n";
          if(i==j)
            sp[i][j]=0;
        }
    }
    ll ans=0;
    for(ll k=1;k<=h*w;k++)
      for(ll i=1;i<=h*w;i++)
          for(ll j=1;j<=h*w;j++)
          {
            sp[i][j]=min(sp[i][j],sp[i][k]+sp[k][j]);

            if(sp[i][j]==mod)
              continue;
            
          }

          for(ll i=1;i<=h*w;i++)
              for(ll j=1;j<=h*w;j++)
              {
                if(sp[i][j]==mod)
                  continue;
             
                ans=max(ans,sp[i][j]);
              }
          cout<<ans;
   }


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
const int N=3e5+10;
int a[N];
int dp[N];
int main(int argc, char *argv[])
{
	int n,ans=0;
	cin>>n;
	
	for(int i=0;i<n*3;i++){
		cin>>a[i];
		}
		dp[0]=a[0];
		dp[1]=a[1];
		dp[2]=a[2];
	  for(int i=3;i<n*3;i++){
	  	for(int j=i-3-(i%3);j<=i-3-(i%3)+2;j++){
	  		if(j==i-3)
	  		continue;
	     dp[i]=max(dp[i],dp[j]+a[i]);	
	  	}
	  	}
	  	for(int i=n*3-1;i>=n*3-3;i--)
	  	ans=max(ans,dp[i]);
	  	cout<<ans;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    if(s == "Sunny")
        cout << "Cloudy" << endl;
    if(s == "Cloudy")
        cout << "Rainy" << endl;
    if(s == "Rainy")
        cout << "Sunny" << endl;
}

Measured memory_bytes: 256