akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <array>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <map>
using namespace std;

int main()
{
	int n;
	string str;
	cin >> n >> str;

	for (int i = 0; i < str.length(); i++)
	{
		if (str[i] + n > 'Z')
			str[i] += n - 26;
		else str[i] += n;
	}

	cout << str;
}

Measured memory_bytes: 3624
import math
A,B=map(int,input().split())
X=math.sqrt(min(A,B))
L=[]
for i in range(1,int(X)+1):
	if A%i==0:
		L.append(i)
		L.append(A//i)
L=set(L)
L=sorted(L)
S=[]
for i in L:
	if B%i==0:
		S.append(i)
ans=1
for i in S:
	if i==1:continue
	count=0
	for j in range(2,int(math.sqrt(i))+1):
		if i%j==0:
			count+=1
			break
	if count==0:
		ans+=1
print(ans)

Measured memory_bytes: 3956
N = int(input())

l = len(str(N))
ans = 0

if l%2 == 0:
    for i in range(l//2):
        ans += 9*10**(2*i)
    print(ans)
else:
    for i in range(l//2):
        ans += 9*10**(2*i)
    ans += N - 10**(l-1) + 1
    print(ans)

Measured memory_bytes: 3060
#include <iostream>

const int MAX_H = 100, MAX_W = 100, v[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
std::string map[MAX_H];
int W, H;

//x,y »ÝÌÊu c Á·¶
void dfs(int x, int y, char c){
	map[y][x] = ' ';

	for(int i=0;i<4;i++){
		int nx = x + v[i][0], ny = y + v[i][1];
		if(nx >= 0 && nx < W && ny >= 0 && ny < H && map[ny][nx] == c)dfs(nx,ny,c);
	}
	return ;
}

int main(){
	//Input
	while(std::cin >> H >> W,W||H){
		for(int i = 0;i < H;i++){
			std::cin >> map[i];
		}
		
		//Processing
		int res = 0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(map[i][j] != ' ')
					res++,dfs(j,i,map[i][j]);
			}
		}
		
		std::cout << res << std::endl;
	}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pt;

#define fi first
#define se second
#define lson (p<<1)+1
#define rson (p<<1)+2
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll n, m, s;

int main () {
    fastIO;
    cin >> n >> m >> s;
    cout << (s + max(n, m) - 1) / max(n, m);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define v vector
#define mp make_pair
typedef long long ll;
typedef pair<int, int > pii;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }

// A
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k;
	string s;
	cin >> n >> k >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s << "\n";
}



Measured memory_bytes: 892
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    int n,a;cin>>n>>a;
    if(n%500<=a) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,s;
  cin>>k>>s;
  int c=0;
  for(int i=0;i<=k;i++)
    for(int j=0;j<=k&&i+j<=s;j++)
      if(s-i-j<=k)
        c++;
  cout<<c<<endl;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,p,c1=0,c2=0,f[100005]={},pe[100005]={};
  string s;
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> p >> s;
    if(s=="AC") {
      f[p]=1;
    }
    else if(!f[p]&&s=="WA") {
      pe[p]++;
    }
  }
  for(int i=1; i<=n; i++) {
    if(f[i]) {
      c1++;
      c2+=pe[i];
    }
  }
  cout << c1 << " " << c2 << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

int lcm(int a, int b) {
  if ((a == 0) || (b == 0)) return 0;
  return ((a / gcd(a, b)) * b);
}

int main() {
  int K; cin >> K;
  LL sum = 0;
  for (int a = 1; a <= K; ++a) {
    for (int b = 1; b <= K; ++b) {
      for (int c = 1; c <= K; ++c) {
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        long c = sc.NextLong();
        long[] x = new long[n + 2];
        int[] v = new int[n + 2];
        for (int i = 1; i <= n; i++)
        {
            x[i] = sc.NextLong();
            v[i] = sc.NextInt();
        }
        x[n + 1] = c;

        long[,] sum = new long[2, n * 2 + 10];
        long d = 0;
        for (int i = 1; i <= n; i++)
        {
            d += v[i] - (x[i] - x[i - 1]);
            sum[0, i] = Math.Max(sum[0, i - 1], d);
        }

        d = 0;
        for (int i = n; i >= 1; i--)
        {
            d += v[i] - (x[i + 1] - x[i]);
            sum[1, i] = Math.Max(sum[1, i + 1], d);
        }

        long max = 0;
        for (int i = 0; i <= n; i++)
        {
            long res = sum[0, i] + sum[1, i + 1] - x[i];
            max = Math.Max(max, res);

            res = sum[0, i] + sum[1, i + 1] - c + x[i + 1];
            max = Math.Max(max, res);
        }
        Console.WriteLine(max);
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 19004
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        if(a % 500 <= b){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }



}




Measured memory_bytes: 23124
#include <iostream>
using namespace std;
int main(){
  int n, *p;
  cin >> n;
  p = new int[n];
  for(int i=0;i<n;++i){
    cin >> p[i];
  }
  int min = p[0], count = 0;
  for(int i=0;i<n;++i){
    if(p[i]<=min){
      ++count;
      min = p[i];
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
  long double A, B, H, M, radH, radM, ans;
  cin >> A >> B >> H >> M;
  radH = (2 * M_PI * H / 12)+(2 * M_PI * M / (60*12));
  radM = 2 * M_PI * M / 60;
  ans = sqrt(A * A + B * B - 2 * A * B * cos(abs(radH - radM)));
  printf("%.9Lf\n", ans);
}

Measured memory_bytes: 4132
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N;
        is >> N;
        if(!is) return;
        ll ans = (N-1) * N / 2ll;
        cout << ans << endl;
        

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_D.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 256
//「幾何、中央値など、最大値を求めるときは二分探索法」を考える。

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static string s = Console.ReadLine();
static int n = s.Length;
static bool isChanging;

	static void Main()
	{
    Console.WriteLine(Search(1, n, 1));  
	}

  static long Search(long min, long max, int MinorMax)//二分探索法で最小値-1最大値1を求める
  {
    while (true)
    {
      long mid = min + (max - min) / 2;
      if(MinorMax == 1)
      {
        if(Check(mid)) min = mid;//さらに大きくても成り立つかも
        else max = mid;
      }else
      {
        if(Check(mid)) max = mid;//さらに小さくても成り立つかも
        else min = mid;
      }

      if(max - min <= 1)
      {
        if(MinorMax == 1)
        {
          if(Check(max)) return max;//最大値で成り立つかの確認を優先
          else return min;
        }else
        {
          if(Check(min)) return min;//最小値で成り立つかの確認を優先
          else return max;
        }

      break;
      }  
    }
  }

  static bool Check(long testNum)
  {//左から順に全て0にした時、左からtestNum個が全て0になれば良い。
    isChanging = false;

    for(int i = 0; i <= n-(int)testNum; i++)
    {
      if(s[i] == '0' && isChanging || s[i] == '1' && !isChanging)
      {
        isChanging = !isChanging;
      }
    }

    for(int i = n-(int)testNum+1; i < testNum; i++)
    {
      if(s[i] == '0' && isChanging || s[i] == '1' && !isChanging) return false;
    }

    return true;
  }  
}


Measured memory_bytes: 13524
import sys
from functools import lru_cache


sys.setrecursionlimit(200000)
fin = sys.stdin.readline
num_matches_required = {n: nmatches for n, nmatches 
    in zip(range(1, 10), (2, 5, 5, 4, 5, 6, 3, 7, 6))}

N, M = map(int, fin().split())
nums = sorted(map(int, fin().split()), reverse=True)

@lru_cache(None)
def rec(i):
    if i < 0: 
        return float('-inf')
    elif i == 0: 
        return 0
    else:
        return max(
            rec(i - num_matches_required[num]) for num in nums
        ) + 1


num_digits = rec(N)
cur_num_matches = N
result = []
while cur_num_matches:
    for num in nums:
        if rec(cur_num_matches - num_matches_required[num]) == num_digits - len(result) - 1:
            result.append(str(num))
            cur_num_matches -= num_matches_required[num]
            break

print("".join(result))


Measured memory_bytes: 54492
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){ return a<b?a=b,1:0; }
template<class T> inline bool chkmin(T& a,T b){ return a>b?a=b,1:0; }
template<typename T> inline T& read(T& x){
    static char c; bool flag=0;
    while(!isdigit(c=getchar())) if(c=='-') flag=1;
    for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
    if(flag) x=-x;
    return x;
}
const int maxn=200010,INF=0x3f3f3f3f;
int n,q,a[maxn],s[maxn],f[maxn],ans;
struct data{
    int l,r;
    bool operator < (const data& rhs) const{
        return l<rhs.l;
    }
} t[maxn];
namespace SGT{
#define ls h<<1
#define rs h<<1|1
#define mid ((l+r)>>1)
#define lc l,mid
#define rc mid+1,r
    int T[maxn*3][2];
    void creat(){ memset(T,INF,sizeof T); }
    void pushup(int h){
        T[h][0]=min(T[ls][0],T[rs][0]);
        T[h][1]=min(T[ls][1],T[rs][1]);
    }
    void update(int h,int l,int r,int p,int w,int op){
        if(l==r) return void(chkmin(T[h][op],w));
        if(p<=mid) update(ls,lc,p,w,op);
        else update(rs,rc,p,w,op);
        pushup(h);
    }
    int query(int h,int l,int r,int L,int R,int op){
        if(L>R) return INF;
        if(L<=l&&r<=R) return T[h][op];
        int res=INF;
        if(L<=mid) chkmin(res,query(ls,lc,L,R,op));
        if(R>mid) chkmin(res,query(rs,rc,L,R,op));
        return res;
    }
}
using namespace SGT;
int main(){
    read(n);
    for(int i=1;i<=n;i++) s[i]=s[i-1]+read(a[i]);
    read(q);
    for(int i=1;i<=q;i++) read(t[i].l),read(t[i].r);
    sort(t+1,t+q+1);
    creat();
    f[0]=s[n];
    for(int i=1;i<=q;i++){
        f[i]=s[n]+(t[i].r-t[i].l+1)-(s[t[i].r]-s[t[i].l-1])*2;
        chkmin(f[i],query(1,1,n,1,t[i].l-1,0)+(t[i].r-t[i].l+1)-2*(s[t[i].r]-s[t[i].l-1]));
        chkmin(f[i],query(1,1,n,t[i].l,t[i].r-1,1)+t[i].r-2*s[t[i].r]);
        update(1,1,n,t[i].r,f[i],0);
        update(1,1,n,t[i].r,f[i]-t[i].r+2*s[t[i].r],1);
    }
    ans=INF;
    for(int i=0;i<=q;i++) chkmin(ans,f[i]);
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

int main()
{
    int a,b,c, k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while (b <= a) {
        b *= 2;
        cnt++;
    }
    while (c <= b) {
        c *= 2;
        cnt++;
    }
    if (cnt <= k) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3592
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
a = [e for row in a for e in row]
ans = 0
i = 0
while n > 0:
    ans += 1
    if a[i] == 2:
        print(ans)
        quit()
    else:
        i = a[i]-1
    n -= 1
print(-1)


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  string t = "";
  for(int i = 0; i < s.size(); i++) {
    switch(s[i]) {
    case '0': t += '0'; break;
    case '1': t += '1'; break;
    case 'B': if(t.size() > 0) t = t.substr(0, t.size()-1); break;
    }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main()
{
  int N;
  cin >> N;
  int P[N+10];
  rep(i,N) cin >> P[i];
  
  int min = P[0];
  int ans = 0;
  
  rep(i,N){
    if(min >= P[i]){
      min = P[i];
      ans++;
    }
  }

  cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> S(2 * N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        S[i] += S[i];
    }
    for (int i = N; i < 2 * N; i++) {
        S[i] = S[i - N];
    }

    int ans = 0;
    for (int a = 0; a < N; a++) {
        bool ok = true;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (S[i + a][j] != S[j + a][i]) {
                    ok = false;
                }
            }
        }
        if (ok) {
            ans++;
        }
    }

    cout << ans * N << endl;
}


Measured memory_bytes: 768
//Let's play :)
#include<bits/stdc++.h>
using namespace std;

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    tarzan;
    int test = 1;
    //cin >> test;
    while(test--) {
        int n;
        cin >> n;
        int a[n];
        map<int, int> mp;
        for(int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;
        }
        int ans = 0;
        for(auto it : mp) {
            ans = ans + (it.second) * (it.second - 1) / 2;
        }
        for(int i = 0; i < n; i++) {
            int finans = ans;
            finans -= (mp[a[i]]) * (mp[a[i]] - 1) / 2;
            finans += (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2;
            cout << finans << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 12376
//not answered

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
#include <cmath>

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << c+b-d << " " << d+c-a << " ";
  cout << a+b-d << " " << b+c-a << endl;;
}


Measured memory_bytes: 256
// atcoder/abc154/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  int k;
  while (cin >> s >> k) {

    const int N = 1000 + 5;
    const int M = 2;
    const int K = 3 + 2;
    lli dp[N][M][K];
    fill(&dp[0][0][0], &dp[N - 1][M - 1][K - 1] + 1, 0);
    dp[0][false][0] = 1;

    for (int i = 0; i < s.size(); ++i) {
      for (int j = false; j <= true; ++j) {
        for (int x = 0; x < K; ++x) {
          unless (dp[i][j][x]) continue;
          // cout << ">> " << i << ' ' << j << ' ' << x << endl;
          int z = s[i] - '0';
          for (int y = 0; y <= (j ? 9 : z); ++y) {
            int p = (x + (y != 0));
            if (p <= k) {
              // cout << i + 1 << ' ' << (j | (y < z)) << ' ' << x + (y != 0) << endl;
              dp[i + 1][j | (y < z)][x + (y != 0)] += dp[i][j][x];
            }
          }
        }
      }
    }
    // cout << dp[s.size()][false][k] << ' ' << dp[s.size()][true][k] << endl;
    cout << dp[s.size()][false][k] + dp[s.size()][true][k] << endl;
    // cout << endl;
    // break;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 200003;
ll n,ans[N];
pair <ll,ll> x[N];

int main(){
	cin>>n;
	FOR(i,0,n){
		cin>>x[i].first;
		x[i].second=i;
	}
	sort(x,x+n);
	FOR(i,0,n){
		if(i<n/2)ans[x[i].second]=x[n/2].first;
		else ans[x[i].second]=x[n/2-1].first;
	}
	FOR(i,0,n){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6912
N = int(input())


# try div
def prime_factorize(n: int): 
    ret = []

    while n % 2 == 0:
        ret.append(2)
        n //= 2
    
    f = 3
    while f * f <= n:
        if n % f == 0:
            ret.append(f)
            n //= f
        else:
            f += 2
    
    if n != 1:
        ret.append(n)
    
    return ret


pf = prime_factorize(N)
# print(pf)
ans = 0
from collections import Counter

cpf = Counter(pf)
# print(cpf)
for k, v in cpf.items():
    e = v
    tmp = 0
    cur = 1

    while e >= cur:
        e -= cur
        cur += 1
        tmp += 1
    
    ans += tmp

print(ans)




Measured memory_bytes: 9448
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);
#define curMod 998244353

int main(){
		//do_not_disturb
		int n, i;
		cin >> n;
		double a[n];
		
		for(i = 0; i < n; i++){
			cin >> a[i];
		}
		sort(a, a+n);
		for(i = 1; i < n; i++){
			a[i] = (a[i]+a[i-1])/2.;
		}
		cout << a[n-1];
		
    return 0;
} // What is to be written here?


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define ll long long

int main()
{
	int N, T;
	int t[200001];
	cin >> N >> T;
	REP(i, 0, N) cin >> t[i];

	ll X = 0;
	REP(i, 0, N - 1) {
		if (t[i] + T > t[i + 1]) {
			X += (t[i + 1] - t[i]);
		}
		else {
			X += T;
		}
	}
	X += T;

	cout << X << endl;
	return 0;
}

Measured memory_bytes: 1024
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
6.long double | 输出浮点数
7.注意特判!(prince and princess)
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
double tmp=0,tot=0;
double x[10],y[10];
double dis(int X,int Y){
	double tmp=(x[X]-x[Y])*(x[X]-x[Y])+(y[X]-y[Y])*(y[X]-y[Y]);
	return sqrt(tmp);
}
int main(){
	int n;
	int a[10];
	cin>>n;
	rb(i,1,n) cin>>x[i]>>y[i];
	rb(i,1,n) a[i]=i;
	do{
		tot++;
		rb(i,2,n){
			tmp+=dis(a[i],a[i-1]);
		}
	}while(next_permutation(a+1,a+1+n));
	printf("%.14f\n",(double)(tmp)/(double)(tot));
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 10000
int naturalnumber(int x);
int main(void){
  
  int A[N], i, n, j, c=0, s;
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  
  for(i = 0; i < n; i++){ 
    s = A[i];      
    if(naturalnumber(s) == 1) c++;
  }
  printf("%d\n", c);
  return 0;
}

int naturalnumber(s){
  int j;
  
  if(s == 2 || s == 3 || s == 5 || s == 7) return 1;  
  if(s%2 == 0) return 0;
  for(j = 3; j <= sqrt(s); j += 2){
    if(s%j == 0) return 0;       
  }
  
  return 1;
}



Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

//-------------------------------------------------------//


int main() {
	string a, b;
	cin >> a >> b;
	
	int n1 = a.size(), n2 = b.size(), ans = 10001;
	
	for(int i = 0; i < n1; i++) {
		if(i+n2 > n1) break;
		int cur = 0;
		
		for(int j = 0; j < n2; j++) {
			if(a[i+j] != b[j]) cur++;
		}
		
		ans = min(ans, cur);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int compare(long int *a, long int *b) {
    long int buf = *a - *b;
    if (buf < 0) return -1;
    else if (buf > 0) return 1;
    return 0;
}

int main() {
    int n = 0, k = 0;
    scanf("%d %d\n", &n, &k);
    long int v[n];
    for (int i=0; i<n; i++) scanf("%ld", &v[i]);
    long int max = 0;
    for (int i=1; i<=k; i++) {
        if (i > n) break;
        for (int j=0; j<=i; j++) {
            long int *a = (long int *)malloc(sizeof(long int)*i);
            int poi = k - i;
            for (int l=0; l<i; l++) {
                if (l < j) a[l] = v[l];
                else a[l] = v[n-i+l];
            }
            qsort(a, i, sizeof(long int), compare);
            int check = 0;
            while (check < poi) {
                if (a[check] >= 0) break;
                check++;
            }
            long int sum = 0;
            for (int l=check; l<i; l++) {
                sum += a[l];
            }
            if (sum > max) max = sum;
            free(a);
        }
    }
    printf("%ld\n", max);
    return 0;
}


Measured memory_bytes: 128
/**
Bismillahir Rahmanir Rahim
!~~~~~~~~~~~~!
|Naimul Islam|
!~~~~~~~~~~~~!
*/
#include<bits/stdc++.h>

using namespace std;

typedef     unsigned long long  ull;
typedef     long long           ll;

#define     CS(x)        cout << "Case " << x << ": ";

#define in() ( { int a ; scanf("%d",&a); a; } )     //int x= in()

#define     PI           (acos(-1))
#define     sq(x)          ((x) * (x))
#define     mod          (1000000007)
#define     EPS          1e-9
#define     inf          1 << 30

#define     eb           emplace_back
#define     mp           make_pair
#define     SZ(_n)       (int)_n.size()
#define     ALL(_n)      _n.begin(), _n.end()
#define     Clear(a,b)   memset(a,b,sizeof(a))

#define     sp           ' '
#define     endl         "\n"
#define     nl           cout << endl
#define     r0           return 0

#define     Check(x)     cout << #x << " is " << x <<endl;
#define     precision(n) cout << fixed << setprecision(n);
#define     dbg          cout << "KHELA HOBE" << endl;
#define     doura      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz 10100000
//long long primes[sz];
int cnt;
bool siv[sz];

void sieve()
{
    long long i, j;
    siv[0] = siv[1] = 1;

    for(i=3; i*i<sz; i+=2)    ///কোন সংখ্যা প্রাইম তা চেক করার জন্য
    {
        if(!siv[i])
        {
            for(j = i*i; j<sz; j += i+i)
                siv[j] = 1;
        }
    }
    for(i=4; i<sz; i+=2)
    {
        siv[i] = 1;
    }
//    primes[cnt++] = 2;
//    for(i=3; i<sz; i+=2)    ///প্রাইম সংখ্যাগুলা একটা অ্যারে তে রাখতেসি
//    {
//        if(!siv[i])
//            primes[cnt++] = i;
//    }
}

int main()
{
	doura;
	sieve();
    int n;
    cin >> n;
//    int p = upper_bound(primes, primes+cnt, n)-primes;
//    Check(p);
    while(siv[n])n++;
    cout << n <<endl;


    r0;
}















Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct node
{
	int l,r;
}gate[100005];

int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)cin>>gate[i].l>>gate[i].r;
    
    int left=gate[1].l;
	int right=gate[1].r;
    
    for(int i=1;i<=m;i++)
      {
      	if(left<gate[i].l)left=gate[i].l;
      	if(right>gate[i].r)right=gate[i].r;
	  }
	int ans=0;
	if(left<=right)ans=right-left+1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		mut d: [usize; n],
	}

	d.sort();
	d.dedup();
	println!("{}", d.len());
}



Measured memory_bytes: 2196
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){

    int n,r;
    cin >> n >> r;

    if(n < 10){
        r = r+100*(10 - n);
        cout << r << endl;
    }else{
        cout << r << endl;

    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}


int main()
{

       double d,t,s;
       cin>>d>>t>>s;
       double temp=d/s;
       if(temp<=t) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;



	return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n-1) {
        if(a[i] > a[i+1]) {
            ans += abs(a[i]-a[i+1]);
            a[i+1] += abs(a[i]-a[i+1]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define MAXN   1015
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n , cnt = 0 , cnt1 = 0 , cnt2 = 0 ;
    cin >> n ;
    vector < int > v(n) , v2(n) , v3(n);
    for ( int i = 0 ; i < n ; i++)
        cin >> v2[i];
    for ( int i = 0 ; i < n ; i++)
        cin >> v3[i];
    for ( int i = 0 ; i < n ; i++)
         v[i] = i+1 ;
    do{
        cnt++ ;
        if ( v == v2)cnt1 = cnt ;
        if (v == v3)cnt2 = cnt ;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(cnt1-cnt2);
}


Measured memory_bytes: 256
/*
[abc148] A - Round One
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int A, B;

ll solve() {
    if (A > B) {
        swap(A, B);
    }
    if (A == 2 && B == 3) {
        return 1;
    }
    if (A == 1 && B == 3) {
        return 2;
    }

    return 3;
}

int main() {
    cin >> A >> B;

    cout << solve() << endl;

    return 0;
}


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

using namespace std;

void funcA(){

  int x;
  cin >> x;
  if (x == 0) cout << 1;
  else cout << 0;

}

void funcB() {

  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  long long ac, ad, bc, bd;
  ac = a * c;
  ad = a * d;
  bc = b * c;
  bd = b * d;

  long long maxnum;
  maxnum = max(ac, ad);
  maxnum = max(maxnum, bc);
  maxnum = max(maxnum, bd);

  cout << maxnum;
  

  /*
  cin >> a >> b >> c >> d;

  if (b > 0 && d > 0) {
    if (a * c > b * d) cout << a * c;
    else cout << b * d;
  }
  else if(a < 0 && c < 0) {
    cout << a * c;
    }
  else if (a > 0 && b > 0 && c >)
  }
  */


}

int main() {

  //funcA();
  funcB();

  return 0;
}


Measured memory_bytes: 3648
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		s: String,
	}

	let v: Vec<char> = s.chars().collect();
	if v[v.len()-1] == 's' {
		println!("{}es", s)
	}
	else {
		println!("{}s", s);
	}
}


Measured memory_bytes: 2164
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var nodes [][]int
var counter []int

func main() {
	sc.Split(bufio.ScanWords)
	n, q := readInt(), readInt()

	nodes = make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt(), readInt()
		a--
		b--
		nodes[a] = append(nodes[a], b)
		nodes[b] = append(nodes[b], a)
	}

	counter = make([]int, n)
	for i := 0; i < q; i++ {
		p, x := readInt(), readInt()
		p--
		counter[p] += x
	}

	dfs(0, -1)

	for i := 0; i < n; i++ {
		fmt.Printf("%d ", counter[i])
	}
}

func dfs(current, parent int) {
	for _, next := range nodes[current] {
		if next == parent {
			continue
		}
		counter[next] += counter[current]
		dfs(next, current)
	}
}


Measured memory_bytes: 50048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=2e5+1;
const int inf=1e9;
int main(){
	int H,W,N; cin>>H>>W>>N;
	int x,y; cin>>x>>y; x--; y--;
	string s,t; cin>>s>>t;
	int a = y, b = y, c = x, d = x;
	rep(i,0,N){
		if(s[i] == 'L') a--;
		else if(s[i] == 'R') b++;
		else if(s[i] == 'U') c--;
		else if(s[i] == 'D') d++;
		if(a < 0 || b >= W || c < 0 || d >= H){ cout<<"NO"<<endl; return 0; }
		if(t[i] == 'L' && b > 0) b--;
		else if(t[i] == 'R' && a < W-1) a++;
		else if(t[i] == 'U' && d > 0) d--;
		else if(t[i] == 'D' && c < H-1) c++;
	}cout<<"YES"<<endl;
}

Measured memory_bytes: 900
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int bs = 0, ws = 0;
  for(int i = 0; i < s.length(); i++) {
    if(i % 2 xor (s.at(i) == '1')) ws++;
    else bs++;
  }
  cout << (bs < ws ? bs : ws) << endl;
}

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

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

    if(e - a > k) cout << ":(" << endl;
    if(e - a <= k) cout << "Yay!" << endl;
    return 0;
}

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

int main(void)
{
    int i, n, tscore, hscore;
    char taro[SIZE], hana[SIZE];
    
    tscore = hscore = 0;
    scanf("%d", &n);
    for ( i=0; i<n; ++i) {
        scanf("%s", taro);
        scanf("%s", hana);
        if ( strcmp(taro, hana) == 0){
            ++tscore;
            ++hscore;
        }else if ( strcmp(taro, hana) > 0)
            tscore += 3;
        else if ( strcmp(taro, hana) < 0)
            hscore += 3;
    }
    printf("%d %d\n", tscore, hscore);
    
    return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
int depth[MAXN];
int ans[MAXN];
bool chk[MAXN];

void dfs(int here,int p)
{
    int there;

    for(int i=0;i<graph[here].size();i++){
        there = graph[here][i];
        if(there==p)continue;
        depth[there] = depth[here]+1;
        dfs(there,here);
    }
    return;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    graph = vector<vector<int> > (n+1);

    for(int i=1;i<n;i++){
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    dfs(1,0);

    for(int i=1;i<=n;i++){
        if(depth[i]&1)++cnt;
    }

    if(cnt<=(n/3)){
        cur = 0;
        for(int i=1;i<=n;i++){
            if(depth[i]&1){
                ++cur;
                ans[i] = (cur*3);
                chk[cur*3] = true;
            }
        }
        idx = 1;

        for(int i=1;i<=n;i++){
            if(!(depth[i]&1)){
                while(chk[idx])idx++;
                ans[i] = idx;
                chk[idx] = true;
            }
        }
    }
    else if((n-cnt)<=(n/3)){
        cur = 0;
        for(int i=1;i<=n;i++){
            if(!(depth[i]&1)){
                ++cur;
                ans[i] = (cur*3);
                chk[cur*3] = true;
            }
        }
        idx = 1;

        for(int i=1;i<=n;i++){
            if(depth[i]&1){
                while(chk[idx])idx++;
                ans[i] = idx;
                chk[idx] = true;
            }
        }
    }
    else {
        vector<int> odd;
        vector<int> even;

        for(int i=1;i<=n;i++){
            if(depth[i]&1)odd.push_back(i);
            else even.push_back(i);
        }

        idx = 1;

        for(int i=0;i<odd.size();i++){
            cur = odd[i];
            ans[cur] = idx;
            idx+=3;
            if(idx>n)break;
        }

        idx = 2;

        for(int i=0;i<even.size();i++){
            cur = even[i];
            ans[cur] = idx;
            idx+=3;
            if(idx>n)break;
        }

        idx = 1;

        for(int i=1;i<=n;i++){
            if(!ans[i]){
                ans[i] = idx*3;
                ++idx;
            }
        }
    }

    for(int i=1;i<=n;i++)
        cout<<ans[i]<<" ";

    return 0;
}


Measured memory_bytes: 18204
while True:
    n, x = map(int,input().split())
    if n == 0 and x == 0:
        break
    cnt = 0
    for num1 in range(1, n+1):
        for num2 in range(num1+1, n+1):
            if num1 + num2 >= x:
                continue
            for num3 in range(num2+1, n+1):
                if num1 + num2 + num3 == x:
                    cnt += 1
    print(cnt)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;

int N;
bool xx[365][4][4];
int dp[3][3][365][7][7][7][7];

bool isin(int x, int y, int depth)
{
  if(0 <= x && 0 <= y && x < 3 && y < 3) {
    for(int i = 0; i < 2; i++) {
      for(int j = 0; j < 2; j++) {
        if(xx[depth][x + i][y + j]) return(false);
      }
    }
    return(true);
  }
  return(false);
}

bool rec(int x, int y, int depth, int lt, int lb, int rt, int rb)
{
  if(x == 0 && y == 0) lt = 0;
  if(x == 0 && y == 2) lb = 0;
  if(x == 2 && y == 0) rt = 0;
  if(x == 2 && y == 2) rb = 0;
  if(lt > 6 || lb > 6 || rt > 6 || rb > 6) return(false);
  if(!isin(x, y, depth)) return(false);
  if(depth == N) return(true);
  auto& curr = dp[x][y][depth][lt][lb][rt][rb];
  if(~curr) return(curr);
  for(int i = -2; i <= 2; i++) {
    if(rec(x + i, y, depth + 1, lt + 1, lb + 1, rt + 1, rb + 1)) return(curr = true);
    if(rec(x, y + i, depth + 1, lt + 1, lb + 1, rt + 1, rb + 1)) return(curr = true);
  }
  return(curr = false);
}

int main()
{
  while(cin >> N, N) {
    memset(dp, -1, sizeof(dp));
    for(int k = 0; k < N; k++) {
      for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
          cin >> xx[k][i][j];
        }
      }
    }
    cout << rec(1, 1, 0, 1, 1, 1, 1) << endl;
  }
}

Measured memory_bytes: 33904
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;

int p[10];
int c[10];
int d, g;

int solve(int x) {
    if (x >= (1 << d)) {
        return int(INF);
    }

    int ans = 0;
    int cnt = 0;

    for (int i = 0; i < d; i++) {
        if (((x >> i) & 1) == 1) {
            ans += p[i] * 100 * (i + 1);
            ans += c[i];
            cnt += p[i];
        }
    }

    if (ans < g)
        return min(int(INF), solve(x + 1));
    if (ans == g)
        return min(cnt, solve(x + 1));

    int acnt = cnt;
    for (int i = 0; i < d; i++) {
        if ((x >> i) & 1) {
            int tmpp = p[i];
            int tmpc = cnt;
            int tans = ans;
            tans -= c[i];
            tans -= (i + 1) * 100;
            tmpc--;
            tmpp--;
            while (tmpp >= 1) {
                if (tans < g) {
                    acnt = min(acnt, tmpc + 1);
                    break;
                }
                tmpp--;
                tmpc--;
                tans -= (i + 1) * 100;
            }
            acnt = min(acnt, tmpc + 1);
        }
    }
    return min(acnt, solve(x + 1));
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> d >> g;
    for (int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
    }
    cout << solve(1) << endl;


    return 0;
}

Measured memory_bytes: 3684
N, M = map(int, input().split())
Q = 1000000007
A = set()
for _ in range(M):
    A.add(int(input()))

p = []
for i in range(1, N+1):
    if i in A:
        p.append(0)
    elif i == 1:
        p.append(1)
    elif i == 2:
        p.append(p[0] + 1)
    else:
        p.append(p[i-2] + p[i-3])

print(p[N-1] % Q)

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1000000007

using namespace std;

int main()
{
  string s, ans;
  cin >> s;

  rep(i, s.size()) {
    if (s[i] == 'B') {
      if (ans.size()) {
        ans.erase(ans.size() - 1);
      }
    } else {
      ans += s[i];
    }
  }

  cout << ans << endl;
}


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

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

#define rrep(i,n) for(int i =n; i >=0; --i)

#define rep_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

const ll MOD = 1000000007;

const  long double PI=(acos(-1));

const  long double EPS=0.0000000001;

int main(){
    
    string s,t;cin >> s >> t;
    int a,b;cin >> a >> b;

    string u; cin >> u;

    int ans = a+b;

    if( s == u ) a--;
    if( t == u ) b--;
    cout << a << " " << b<< endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 998244353;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sumxor,sum,ans;
ll a,b,c,d,e,f,g,h,w,v;
ll x[800005],y[800005],z[900005];

bool solve(ll a){
	//a回でできますか？
	num = 0;
	for(i=0;i<n;i++){
		b = x[i] + a;
		num += (b+1)/(n+1);
	}
	//pe("a = ");pe(a);
	//pe("num = ");p(num);
	if(num == a){
		return true;
	}
	return false;
}


int main(){	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x[i];
		sum += x[i];
	}
	a = n * (n-1);
	//sum - a回　~ sum - a + n * n回の中にある
	//O(n^3)
	for(ll i=max(0ll,sum-a);i<=sum-a+n*n;i++){
		if(solve(i)){
			p(i);
			return 0;
		}
	}


	

	
	return 0;
}

Measured memory_bytes: 8064