akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a.back() - a[0] << endl;

    return 0;
}


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

struct query
{
    int u, v, w ;
}q[MAX] = {};

int fa[MAX] = {} ;
int cnt[MAX] = {} ;
long long w[MAX] = {} ;
bool cmp(query a, query b)
{
    return a.w < b.w ;
}

int xfind(int x)
{
    return (fa[x] == x) ? x : fa[x] = xfind(fa[x]) ;
}

int main()
{
    int n, m ;
    int ans = 0 ;
    cin >> n >> m ;
    for(int i=0; i<n; i++)
    {
        cin >> w[i] ; fa[i] = i ;
    }
    for(int i=0; i<m; i++)
    {
        cin >> q[i].u >> q[i].v >> q[i].w ;
        q[i].u--, q[i].v-- ;
    }
    sort(q,q+m,cmp) ;
    for(int i=0; i<m; i++)
    {
        int x = xfind(q[i].u) ;
        int y = xfind(q[i].v) ;
        if(x != y)
        {
            w[x] += w[y] ;
            cnt[x] += cnt[y] ;
            w[y] = 0, cnt[y] = 0 ;
            fa[y] = x ;
        }
        cnt[x]++ ;
        if(w[x] >= q[i].w)
        {
            ans += cnt[x] ;
            cnt[x] = 0 ;
        }
    }
    cout << m - ans << '\n' ;
    return 0 ;
}


Measured memory_bytes: 11264
#include <stdio.h>
#define NIL -1
#define MAX 30

struct Node {
    int oya, left, right;
};
typedef struct Node t_node;
t_node T[MAX];
int D[MAX];
int H[MAX];
int N;

void setDepth(int id, int depth)
{
    D[id] = depth;
    if (T[id].left != NIL) {
        setDepth(T[id].left, depth + 1);        
    }
    if (T[id].right != NIL) {
        setDepth(T[id].right, depth + 1);
    }
}

int setHeight(int id)
{
    int h1 = 0, h2 = 0;
    if (T[id].left != NIL) {
        h1 = setHeight(T[id].left) + 1;
    }
    if (T[id].right != NIL) {
        h2 = setHeight(T[id].right) + 1;
    }    
    return H[id] = h1 > h2 ? h1 : h2;
}

int getoya(int id)
{
    return T[id].oya;
}

int getkyoudai(int id)
{
    int i;
    for (i = 0; i < N; i++) {
        if (id != i && D[id] == D[i] && T[id].oya == T[i].oya) {
            break;
        }
    }
    return i != N ? i : NIL;
}

int getDegree(int id)
{
    int i, d = 0;
    for (i = 0; i < N; i++) {
        if (T[i].oya == id) {
            d++;
        }
    }
    return d;
}

void printTree()
{
    int root;
    int id;
    for (id = 0; id < N; id++) {
        if (T[id].oya == NIL) root = id;
    }
    
    setDepth(root, 0);
    setHeight(root);

    int p, s, d;
    for (id = 0; id < N; id++) {
        p = getoya(id);
        s = getkyoudai(id);
        d = getDegree(id);
        printf("node %d: ", id);
        printf("parent = %d, ", p);
        printf("sibling = %d, ", s);
        printf("degree = %d, ", d);
        printf("depth = %d, ", D[id]);
        printf("height = %d, ", H[id]);
        if (p == NIL) {
            puts("root"); 
            continue;
        }
        switch (d) {
            case 0: puts("leaf"); break;
            default : puts("internal node"); break;
        }
    }
}

int main()
{
    int i, j;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        T[i].oya = T[i].left = T[i].right = NIL;
    }    
    int id;
    for (i = 0; i < N; i++) {
        scanf("%d", &id);
        scanf("%d %d", &T[id].left, &T[id].right);
        T[T[id].left].oya = id;
        T[T[id].right].oya = id;
    }
 
    printTree();
    
    return 0;
}



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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    private sealed class Lesser : IComparer<int>
    {
        public int Compare(int a, int b)
        {
            return b - a;
        }
    }

    public static void Main()
    {
        var s = long.Parse(Console.ReadLine());

        var answer = new long[6];

        var t = (long)Math.Ceiling(Math.Sqrt(s));
        var u = t * t - s;
        answer[2] = answer[5] = t;

        var x = (long)Math.Floor(Math.Sqrt(u));

        for (; x > 0; --x)
        {
            if (u % x == 0)
                break;
        }

        answer[4] = x;
        answer[3] = x != 0 ? u / x : 0;

        Console.WriteLine(string.Join(" ", answer));
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1000 + 10;
int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b & 1){
            res = 1LL * res * a % mod;    
        }
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return res;
}
int r[N * N], c[N * N], visr[N], visc[N];
int main() {
    int n, m, a[N], b[N], cntc = 0, cntr = 0, ans = 1;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        if(r[a[i]]){
            ans = 0;
        }
        r[a[i]] = i;
    }
    for(int i = 1; i <= m; i++){
        scanf("%d", &b[i]);
        if(c[b[i]]){
            ans = 0;
        }
        c[b[i]] = i;
    }
    for(int i = n * m; i >= 1; i--){
        if(r[i] && c[i]){
            cntr++;
            cntc++;
        }else if(r[i]){
            cntr++;
            ans = 1LL * ans * cntc % mod;
        }else if(c[i]){
            cntc++;
            ans = 1LL * ans * cntr % mod;
        }else{
            int used = n * m - i;
            ans = 1LL * ans * (cntc * cntr - used) % mod;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2304
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ATransfer {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int A, B, C;
	    in >> A >> B >> C;
	    out << C - min(A-B, C) << "\n";
	}
};


signed main() {
	ATransfer solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;

int main(void) {
   ll N,M;
   cin>>N>>M;
   map<ll,ll> ac;
   map<ll,ll> wa;
   rep(i,0,M) {
      ll a;
      string s;
      cin>>a>>s;
      if (s[0]=='A') ac[a]++;
      if (s[0]=='W' && !ac.count(a)) wa[a]++;
   }
   ll sum_ac = 0;
   ll sum_wa = 0;
   for (auto el:ac) {
      // cout<<el.first<<" "<<el.second<<endl;
      sum_ac += 1;
   }

   for (auto el:wa) {
      // cout<<el.first<<" "<<el.second<<endl;
      if (!ac.count(el.first)) continue;
      sum_wa += el.second;
   }

   cout<<sum_ac<<" "<<sum_wa<<endl;

   



   return 0;

}



Measured memory_bytes: 6528
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
int main(){
 ll a,b,x;
 cin >> a>>b>>x;
 ll p=a/x;
 ll q=b/x;
 if(a==0) cout << q-p+1<<endl;
 else {
   p=(a-1)/x;
   cout << q-p<<endl;
 }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

h,w,k = readints()
s = [readstr() for i in range(h)]

ans = [[0]*w for i in range(h)]

n = 1
for i in range(h):
    a = s[i].count("#")
    if a == 0:
        if i!=0:
            for j in range(w):
                ans[i][j] = ans[i-1][j]
    else:
        f = 0
        for j in range(w):
            if s[i][j] =="#":
                if f:
                    n += 1
                else:
                    f += 1
            ans[i][j] = n
        n += 1

for i in range(h-2,-1,-1):
    for j in range(w):
        if ans[i][j]==0:
            ans[i][j] = ans[i+1][j]

for i in range(h):
    printline(ans[i])







Measured memory_bytes: 74720
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  string w;
  cin >> w;
  map<char, ll> cnt;
  ll N = w.size();

  rep(i, N){
    cnt[w[i]] += 1;
  }

  for(auto i = cnt.begin(); i != cnt.end(); i++){
    if((i->second) % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}


int N,K;
int table[2005][2005];

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> N >> K;
  const int L = 2*K;
  rep(i,N){
    int x,y;cin >> x >> y;
    char c; cin >> c;
    x%=L;
    y%=L;
    int black = 1;
    if(c=='W')black^=1;
    if(x>=K)black^=1;
    if(y>=K)black^=1;
    x%=K;
    y%=K;
    table[1][1]+=black;
    if(!black)black=-1;
    table[1][y+2]-=black;
    table[x+2][1]-=black;
    table[x+2][y+2]+=2*black;
  }
  int ans = 0;
  rep(x,K)rep(y,K){
    table[x+1][y+1] += table[x+1][y] + table[x][y+1] - table[x][y];
    ans = max(ans, max(table[x+1][y+1], N-table[x+1][y+1]));
  }
  //rep(x,K)repp(y,1,K)table[x][y] += table[x][y-1];
  //rep(y,K)repp(x,1,K)table[x][y] += table[x-1][y];
  //rep(x,K)rep(y,K) ans= max(ans,max(table[x][y],N-table[x][y]));
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 8448
/*input
1000000000000000000
*/

#include <iostream>
#include <map>
#include <unordered_map>

using namespace std;

long digit_dp(long N){

	static unordered_map<long, long> dp;

	if(N==0) return 1;
	if(N==1) return 2;
	if(dp.count(N)) return dp.at(N);

	long total = 0;
	total += digit_dp(N/2);
	total %= 1000000007;
	total += digit_dp((N-1)/2);
	total %= 1000000007;
	total += digit_dp((N-2)/2);
	total %= 1000000007;

	dp.insert(make_pair(N, total));

	return total;
}

int main()
{

	long N;
	cin >> N;

	cout << digit_dp(N) << endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, H, W;
    cin >> N >> H >> W;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];
    
    // calculation
    int sum = 0;
    REP(i, N) {
        if (A[i] >= H && B[i] >= W) {
            sum++;
        }
    }
    cout << sum << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
	char s[10000]={}, d[5]={};
	int i, n;
	
	scanf("%s", s);
	
	n=strlen(s);
	
	for(i=0;i<n;i++){
		switch(s[i]){
			case 'N':d[1]++; break;
			case 'E':d[2]++; break;
			case 'W':d[3]++; break;
			case 'S':d[4]++; break;
		}
	}
	
	 if(d[1]==0&&d[4]!=0){
	 	printf("No\n");
	 	return 0;
	 }
	 
	 if(d[2]==0&&d[3]!=0){
	 	printf("No\n");
	 	return 0;
	 }
	 
	 if(d[3]==0&&d[2]!=0){
	 	printf("No\n");
	 	return 0;
	 }
	 
	 if(d[4]==0&&d[1]!=0){
	 	printf("No\n");
	 	return 0;
	 }

	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, x;
vector<int> pat, len;

int calc(int l, int x)
{
    if (x == 0)
        return 0;
    if (l == 0)
        return 1;
    int mid = (len[l] + 1) / 2;
    if (x < mid)
    {
        return calc(l - 1, x - 1);
    }
    x -= mid;
    return calc(l - 1, x) + pat[l - 1] + 1;
}

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

    cin >> n >> x;
    pat.resize(n + 1);
    len.resize(n + 1);
    pat[0] = 1, len[0] = 1;
    rep(i, n)
    {
        pat[i + 1] = 2 * pat[i] + 1;
        len[i + 1] = 2 * len[i] + 3;
    }
    cout << calc(n, x) << endl;
}

Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int, input().split()))

a.sort()
ra = a.copy()
a = a[0::2]
ra = ra[1::2]
ra.reverse()
a = ra + a
for i in range(n):
    if a[i] != abs(n - 1 - i * 2):
        print(0)
        sys.exit(0)
print(2 ** (n // 2) % 1000000007)

Measured memory_bytes: 14004
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[100005],A;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i),A=max(A,a[i]);
    if(A==0){
        puts("Yes");
        return 0;
    }
    sort(a+1,a+n+1);
    if(n%3){
        puts("No");
        return 0;
    }
    n/=3;
    bool ok=1;
    for(int i=2;i<=n;++i){
        if(a[i]!=a[1]||a[n+i]!=a[n+1]||a[n*2+i]!=a[n*2+1])ok=0;
    }
    if(!ok){
        puts("No");
        return 0;
    }
    if((a[1]^a[n+1])==a[n*2+1])puts("Yes");
    else puts("No");
    //system("pause");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> A(N); // MEOMO: vector の定義数のカッコは丸カッコ()
	for (int i=0; i < N; i++) // MEMO: for iが複数あるときは初期化すること i=0
	{
		cin >> A[i];
	}

	int view;
	int cnt = 0;
	for (int i=0; i < N; i++)
	{
		view = 1;
		for (int j=0; j < i; j++)
		{
			if (A[i] >= A[j])
			{
				//ok
			}else{
				view =0;
			}
		}
		if (view){cnt += 1;}
	}
	cout << cnt << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,a[maxn],k,ans[maxn],x,cycle,b[maxn];
bool vis[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> k;
	rep(n) cin >> a[i];
	rep(n) a[i]--;
	x=0;
	rep(n) vis[i]=false;
	rep(n+1){
		if(vis[x]){
			cycle=i-ans[x];
			k-=ans[x];
			if(k>=0) print1(b[ans[x]+k%cycle]+1);
			else print1(b[ans[x]+k]+1);
			return 0;
		}
		ans[x]=i;
		b[i]=x;
		vis[x]=true;
		x=a[x];
	}
	return 0;
}

Measured memory_bytes: 8524
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
dp=[[0]*(M+1) for i in range(N+1)]
mod=10**9+7
for n in range(1,N+1):
    for m in range(1,M+1):
        x=1 if S[n-1]==T[m-1] else -dp[n-1][m-1]
        y=dp[n-1][m]+dp[n][m-1]+x
        dp[n][m]=y if y<mod else y-mod
print((dp[-1][-1]+1)%mod)

Measured memory_bytes: 691328
/** author: __nishad__ **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    string ff, ss, tt;
    cin>>ff>>ss;
    int n = ff.size();
    tt = ss;

    for(int i=0; i<n; i++){
        tt[0] = ss[n-1];
        for(int j=0; j<n-1; j++){
            tt[j+1] = ss[j];
        }
        if(tt == ff){
            cout<<"Yes";
            return 0;
        }
        ss = tt;


    }
    cout<<"No";



}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	vector<int>e[N];
	int c[N];
	vector<int>a;
	int b[N];
	bool used[N];
	vector<int>d;
	queue<int>q;
	f(i, N) {
		c[i] = 0;
		b[i] = 0;
		used[i] = false;
	}
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	f(i, n - 1) {
		scanf("%d %d", &x, &y);
		x--;
		y--;
		e[x].push_back(y);
		e[y].push_back(x);
		c[x]++;
		c[y]++;
	}
	f(i, n) {
		scanf("%d", &x);
		a.push_back(x);
	}
	f(i, n) {
		if (c[i] == 1) {
			q.push(i);
			used[i] = true;
		}
	}
	while (!q.empty()) {
		x = q.front();
		d.push_back(x);
		f(i, e[x].size()) {
			if (!used[e[x][i]]) {
				c[e[x][i]]--;
				if (c[e[x][i]] == 1) {
					q.push(e[x][i]);
					used[e[x][i]] = true;
				}
			}
		}
		q.pop();
	}
	sort(a.begin(), a.end());
	f(i, n) {
		b[d[i]] = a[i];
		if(i<(n-1))ans += a[i];
	}

	printf("%d\n", ans);
	f(i, n) {
		printf("%d",b[i]);
		if (i < (n - 1))printf(" ");
		else printf("\n");
	}

	return 0;
}


Measured memory_bytes: 7296
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+100)
from collections import *

def bfs():
    q = deque([0])
    dep = [-1]*N
    dist = [-1]*N
    dep[0] = 0
    dist[0] = 0
    
    while q:
        v = q.popleft()
        
        for nv, _, w in G[v]:
            if dep[nv]==-1:
                parent[0][nv] = v
                dep[nv] = dep[v]+1
                dist[nv] = dist[v]+w
                q.append(nv)
    
    return dep, dist
    
def lca(u, v):
    if dep[u]>dep[v]:
        u, v = v, u
    
    for i in range(log_size):
        if ((dep[v]-dep[u])>>i)&1:
            v = parent[i][v]
    
    if u==v:
        return u
    
    for i in range(log_size-1, -1, -1):
        if parent[i][u]!=parent[i][v]:
            u, v = parent[i][u], parent[i][v]
    
    return parent[0][u]
    
def calc_dist(u, v):
    return dist[u]+dist[v]-2*dist[lca(u, v)]

def dfs(v, pv, now_cnt, now_wet):
    for c in cnt[v]:
        cnt[v][c] = now_cnt[c]
    
    for c in wet[v]:
        wet[v][c] = now_wet[c]
    
    for nv, c, w in G[v]:
        if nv==pv:
            continue
        
        now_cnt[c] += 1
        now_wet[c] += w
        dfs(nv, v, now_cnt, now_wet)
        now_cnt[c] -= 1
        now_wet[c] -= w

N, Q = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b, c, d = map(int, input().split())
    G[a-1].append((b-1, c, d))
    G[b-1].append((a-1, c, d))
    
log_size = 20
parent = [[-1]*N for _ in range(log_size)]
dep, dist = bfs()

for i in range(1, log_size):
    for v in range(N):
        if parent[i-1][v]>=0:
            parent[i][v] = parent[i-1][parent[i-1][v]]

xyuv = [tuple(map(int, input().split())) for _ in range(Q)]
cnt = defaultdict(lambda: defaultdict(int))
wet = defaultdict(lambda: defaultdict(int))

for x, y, u, v in xyuv:
    cnt[u-1][x] = -1
    cnt[v-1][x] = -1
    cnt[lca(u-1, v-1)][x] = -1
    wet[u-1][x] = -1
    wet[v-1][x] = -1
    wet[lca(u-1, v-1)][x] = -1

dfs(0, -1, defaultdict(int), defaultdict(int))

for x, y, u, v in xyuv:
    l = lca(u-1, v-1)
    decr = wet[u-1][x]+wet[v-1][x]-2*wet[l][x]
    incr = y*(cnt[u-1][x]+cnt[v-1][x]-2*cnt[l][x])
    print(calc_dist(u-1, v-1)-decr+incr)

Measured memory_bytes: 929636
#include <algorithm>
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 8 && b <= 8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}


Measured memory_bytes: 256
n = int(input())
xyh = [tuple(map(int,input().split())) for i in range(n)]

candidates =[]

for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in xyh:
            if h == 0:

                continue
            if ch == None:
                ch = h + abs(x-cx) + abs(y-cy)
                continue

            if ch != h + abs(x-cx) + abs(y-cy):
                break

        else:
            xyh_c = (cx, cy, ch)
            candidates.append(xyh_c)

for xyh_c in candidates:
    cx, cy, ch = xyh_c
    for x,y,h in xyh:
        if h != max(ch - abs(x-cx) - abs(y-cy) ,0):
            break
    else:
        print(cx, cy, ch)
        exit()



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

if 1<=n<=9:
            print(n)
elif 10<=n<=99:
            print('9')
elif 100<=n<=999:
            print(9+(n-99))
elif 1000<=n<=9999:
            print('909')
elif 10000<=n<=99999:
            print(909+n-9999)
elif n==100000:
            print('90909')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int x[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    int d1=0, di=0, y, n;
    double d2=0, d3=0;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>x[i];
    }
    for(int i=0; i<n; i++) {
        cin>>y;
        d1+= abs(x[i]-y);
        d2+= (x[i]-y)*(x[i]-y);
        d3+= abs((x[i]-y)*(x[i]-y)*(x[i]-y));
        di = max(di, abs(x[i]-y));
    }
    cout<<d1<<'\n'<<sqrt(d2)<<'\n'<<pow(d3, 1.0/3.0)<<'\n'<<di<<'\n';
    return 0;
}


Measured memory_bytes: 3492
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+50;
const int inf=0x3f3f3f3f;
int n,k;
char s[10000];
int a[200050];
int vis[200050];
vector<int >g[200050];
void dfs(int t,int val)
{
    vis[t]=1;
    a[t]+=val;
    for(int i=0;i<g[t].size();i++)
    {
        int v=g[t][i];
        if(!vis[v])
        {
            dfs(v,a[t]);
        }
    }
}
int main()
{
    //freopen("/Users/zilongzhang/Desktop//l.txt","r",stdin);
       scanf("%d %d",&n,&k);
        for(int i=1;i<=n-1;i++) {
            int x, y;
            scanf("%d %d", &x, &y);
            g[x].push_back(y);
            g[y].push_back(x);
        }
        while(k--)
        {
            int x,y;
            scanf("%d %d",&x,&y);
            a[x]+=y;
        }
        dfs(1,0);
        for(int i=1;i<=n;i++)
            printf("%d ",a[i]);
    return 0;
}


Measured memory_bytes: 24320
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];

    rep(i, 3){
        cout << (char)(s[i][0] + ('A' - 'a'));
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
 
long long gcd(long long a, long long b){
  	long long M = std::max(a, b);
  	long long m = std::min(a, b);
  	if(M%m==0) return m;
  	return gcd(M%m, m);
}
 
int main(){
  	int n;
  	long long k;
  	std::cin >> n >> k;
  	std::vector<long long> a(n);
  	
  	bool abs1 = false;
  	std::cin >> a.at(0);
  	long long max = a.at(0);
  	long long prev = a.at(0);
  	if(a.at(0)==k){
         std::cout << "POSSIBLE" << "\n";
         return 0;
    }
  	for(int i=1;i<n;i++){
      	auto& e = a.at(i);
      	std::cin >> e;
      	long long g = gcd(prev, e);
      	if(k%g==0){
          	abs1=true;
        }
      	if(e==k){
          	std::cout << "POSSIBLE" << "\n";
          	return 0;
        }
      	if(g==1){
          	abs1=true;
        }
      	max = std::max(max, e);
      	prev = e;
    }
  	if(max > k && abs1){
      	std::cout << "POSSIBLE" << "\n";
    }else{
      	std::cout << "IMPOSSIBLE" << "\n";
    }
  	return 0;
}

Measured memory_bytes: 3576
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                ans -= 1
print(ans)

Measured memory_bytes: 73708
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,Pll> a,pair<ll,Pll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se.fi>b.se.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int n;cin>>n;
    V<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    ll ans=n;
    ll sum=0;
    sort(all(a));
    for(ll i=0;i<n-1;i++){
        sum+=a[i];
        if(sum*2<a[i+1]){
            ans=n-i-1;
        }
    }
    cout<<ans<<Endl;
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------







































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

using namespace std;

int main() {
  int N;
  cin >> N;
  int v;
  std::vector<int> V;
  for (int i = 0; i < N; ++i){
    cin >> v;
    V.push_back(v);
  }
  sort(V.begin(),V.end());
  float answer = V[0];
  for (int i = 1; i < N; ++i){
    answer += V[i];
    answer = answer/2;
  }
  cout << answer <<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		List<Integer> max = new LinkedList<Integer>();
		
		int n = stdIn.nextInt();
		max.add(n);		
		while( stdIn.hasNext() ){
			String[] s = stdIn.next().split(",");
			if( max.size() < s.length ){
				max.add(max.get(0)+Integer.parseInt(s[0]));
				for(int i = 1; i < s.length-1; i++){
					int x = max.get(i-1)+Integer.parseInt(s[i]);
					int y = max.get(i)+Integer.parseInt(s[i]);
					max.add(( x > y ) ? x : y);
				}
				max.add(max.get(s.length-2)+Integer.parseInt(s[s.length-1]));
				for(int i = 0; i < s.length-1; i++){
					max.remove(0);
				}
			} else {
				for(int i = 0; i < s.length; i++){
					int x = max.get(i)+Integer.parseInt(s[i]);
					int y = max.get(i+1)+Integer.parseInt(s[i]);
					max.add(( x > y ) ? x : y);
				}
				for(int i = 0; i < s.length+1; i++){
					max.remove(0);
				}
			}
			if( s.length == 1 ){
				break;
			}
		}
		System.out.println(max.get(0));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int K, A, B;
    cin >> K >> A >> B;

    if (A % K == 0 || (A / K) * K + K <= B) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(void)
{
	char s[1500];
	char ch[26] = {0};
	int i = 0;
	while(fgets(s,1500,stdin) )
	{
		while(s[i] != '\0')
		{
			if(isalpha(s[i]))
			{
				ch[toupper(s[i]) - 65]++;
			}
			i++;
		}
		i=0; 
	}
	 
	
	for(i = 0; i<26 ;i++)
	{
		printf("%c : %d\n",i+97,ch[i]);	
	}
	return 0;
}



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

int main(){
	int W, H, N;
	cin >> W >> H >> N;
	int l=0, r=W, d=0, u=H;
	rep(i,N) {
		int x, y, a;
		cin >> x >> y >> a;
		switch (a) {
			case 1:
				if (x > l) l = x;
				break;
			case 2:
				if (x < r) r = x;
				break;
			case 3:
				if (y > d) d = y;
				break;
			case 4:
				if (y < u) u = y;
				break;
		}
	}

	int ans = (r-l)*(u-d);
	if (r < l || u < d) ans = 0;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3604
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = min(a)+min(b)
for i in range(m):
  x,y,c = map(int,input().split())
  if count > a[x-1]+b[y-1]-c:
    count = a[x-1]+b[y-1]-c
    
print(count)

Measured memory_bytes: 89040
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<iostream>
#include<vector>
using namespace std;
int main(void)
{
	int n,cnt;
	int i,j,co,al,na;
	//co=???????????????al=??¢?????´???????????????na=??????????????????
	cin >> n;

	for(i=0;i<n;i++) {
		cin >> co >> al >> na;
		cnt=0;
		while(1){
			if(co>=1 && al>=1 && na>=1) {
				cnt++;
				co-=1;
				al-=1;
				na-=1;
			}
			else if(co>=2 && al>=1) {
				cnt++;
				co-=2;
				al-=1;
			}
			else if(co>=3) {
				cnt++;
				co-=3;
			}
			else break;
		}
		cout << cnt <<endl;
	}
	exit(0);
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct link{
	int xi,dis;
	link *next;
}t;
int main(){
	int N,X=0;
	cin>>N;
	t.xi=0;
	t.dis=0;
	link *p=&t;
	for(int i=0;i<N;i++){
		link *q=new link;
		scanf("%d",&q->xi);
		p->next=q;
		q->dis=abs((q->xi)-(p->xi));
		X+=q->dis;
		p=q;
		q=NULL;
	}
	link *q=new link;
	q->xi=0;
	q->dis=abs((q->xi)-(p->xi));
	p->next=q;
	X+=q->dis;
	p=q;
	q=NULL;
	q=&t;
	for(int i=0;i<N;i++,q=q->next){
		int Y=X-(q->next->dis)-(q->next->next->dis)+abs((q->next->next->xi)-(q->xi));
		printf("%d\n",Y);
	}
	return 0;
}

Measured memory_bytes: 4352
N, M, X = map(int, input().split())

nums = []

for i in range(N):
    a = list(map(int,input().split()))
    nums.append(a)

ans = 10000000000


for i in range(2**N):

    money = 0
    skill_point = [0]*M
    goal = [0]*M
    buy = []

    for k in range(N):
        if i>>k & 1:
            buy.append(nums[k])

    for d in buy:
        money += d[0]
        for e in range(M):
            skill_point[e] += d[e+1]

    for f in range(M):
        if skill_point[f] >= X:
            goal[f] = 1

    
    if (0 not in goal) and (money < ans) :
        ans = money

    

if ans != 10000000000:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 73696
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,l;
string ss[110];
signed main(){
	cin>>n>>l;
	rep(i,n){
		cin>>ss[i];
	}
	sort(ss,ss+n);
	rep(i,n){
		cout<<ss[i];
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e6+5;
int que[N],head=1,tail,n,k,cmp;
void Output(int n){ rep(i,1,n) putchar(i&1?'B':'A'); } 
int main(){
	scanf("%d%d",&n,&k); tail=n;
	rep(i,1,n){
		char c=getchar();
		while(c!='A'&&c!='B') c=getchar();
		que[i]=c=='A';
	}
	rep(i,1,min(k,2*n)){
		if(cmp^que[head]) que[head]^=1;
		else que[++tail]=cmp,cmp^=1,head++;
	}
	if(k<=2*n){
		rep(i,head,tail) putchar((que[i]^cmp)&1?'A':'B');
		return 0;
	}
	if(n&1){
		k-=2*n;
		putchar((que[head]^cmp^(k&1))&1?'A':'B');
		Output(n-1);
	}else{
		Output(n);
	}
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long hey;
#define hi string
#define pi 3.141592653589793238
#define fi first
#define mod 1000000007
#define se second
#define pb push_back 
#define pop pop_back 
#define bs binary_search
#define mp make_pair
#define ma map< hey,hey >
#define vi vector < hey > 
#define vs vector < hi > 
#define all(v) v.begin(),v.end()
#define qu priority_queue< hey >
#define endl '\n'
#define forn(a,b) for (hey i = a; i <hey(b); ++i)
#define yorn(i, n) for (hey i = 0; i <hey(n); ++i)
#define vp vector< pair<hey,hey> >
// lower bound - first element equal to or greater than given value.
// upper bound - first element greater than given value.
        // 2 Pointers is love
hey prime(hey n)
{
    if(n<=1)
	return 0;
	if(n<=3)
	return 1;
	if(n%2==0 || n%3==0)
	return 0;
	for(hey i=5;i*i<=n;i=i+6)
	{
		if(n%i==0 || n%(i+2)==0)
		return 0;
	}
	return 1;
}

void curious()
{
    hey n,x;
    cin>>n>>x;
    cout<<(n*x)<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	    curious();
	}
	return 0;
}

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

int main(){
	ll n;
	int len=0;
	string ans;
	cin>>n;

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

	reverse(ans.begin(),ans.end());

	cout<<ans<<endl;


}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  ll n,m;
  cin>>n>>m;
  set<ll> a;
  rep(i,m) {
    ll c;
    cin>>c;
    a.insert(c);
  }
  ///////////
  vector<ll> dp(n+1);
  dp[0]=1;
  if(a.count(1)){ 
   dp[1]=0;
  }
  else dp[1]=1;
  rep(i,n-1){
    
    if(!(a.count(i+2))){
    dp[i+2]=dp[i+1]+dp[i];
      dp[i+2]%=1000000007;//cout<<i<<endl;
    }
    else dp[i+2]=0;
    //cout<<dp[i+2]<<endl;
  }
  dp[n]%=1000000007;
  cout<<dp[n]<<endl;
}

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

int main()
{
	int a, b, k; cin >> a >> b >> k;

	int ans;
	int cnt = 1;

	for (int i = min(a, b); 0 < i ; i--) {

		if (a % i == 0 && b % i == 0) {
			ans = i;

			if (cnt == k) break;

			cnt++;
		}

	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, a, b;

  scanf("%d", &n);
  if (n == 1) {
    printf("Hello World\n");
  }
  else {
    scanf("%d", &a);
    scanf("%d", &b);
    printf("%d\n", a+b);
  }

  return 0;
}

Measured memory_bytes: 128
//04
#include<iostream>

using namespace std;

int h,w;
char g[100][101];

void ff(int y,int x,char c){
  if(0<=y&&y<h&&0<=x&&x<w&&g[y][x]==c){
    g[y][x]=0;
    int d[]={0,1,0,-1,0};
    for(int i=0;i<4;i++){
      ff(y+d[i],x+d[i+1],c);
    }
  }
}

int main(){
  while(cin>>h>>w,h|w){
    for(int i=0;i<h;i++){
      cin>>g[i];
    }
    int ans=0;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	if(g[y][x]){
	  ff(y,x,g[y][x]);
	  ans++;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC112D()
{
	int N, M;
	cin >> N >> M;
	int K = M / N;
	for (int i = K; K >= 1; --K)
	{
		if (M % K == 0)
		{
			cout << K << endl;
			return;
		}
	}
}

int main()
{
	ABC112D();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a , b , c , k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k;
    }
    else{
        ll sum = 0;
        sum+=a;
        k-=a;
        if(k<b){
            sum+=0;
            cout<<sum;
        }
        else{
            k-=b;
            if(k<c){
                sum = sum-k;
                cout<<sum;
            }
            else{
                sum-=c;
                cout<<sum;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////

void solve(){
  ini(A , B);
  out((A < 10 && B < 10) ? A * B : -1);
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N;
	cin >> N;

	string ans = "hon";
	vector<int> pon{ 0,1,6,8 };
	for (const auto &e : pon) if (N % 10 == e)ans[0] = 'p';
	if (N % 10 == 3)ans[0] = 'b';

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

int main()
{   int N, L;
    int sum = 0;
    int taste;
    cin >> N >> L;
    for(int i = 0; i < N; i++){
        sum += L + i;
    }
    if(L >= 0) {sum -= L;}
    else if((L + N) <= 0){sum -= (L + N - 1);}

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256