akhauriyash/Code-Regression huggingface dataset:
// B - i18n

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int n = s.size() - 2;

	cout << *s.begin() << n << *s.rbegin() << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

nums = []
for num in range(A, min(A+K, B+1)):
  nums.append(num)
for num in range(max(B-K+1, A), B+1):
  if not num in nums:
    nums.append(num)
nums.sort()
for num in nums:
  print(num)

Measured memory_bytes: 3060
# coding: utf-8
# ABC146A

weekday = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
s = input()
wdn = weekday.index(s)
if wdn == 0:
    res = 7
else:
    res = (7 - wdn) % 7
print(res)

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 100007 , alp = 26 , mo = 1000000007;

int n,s[_],cnt[alp]={0};

int main()
{
	n=ty(),ts(s+1);
	for(int i=1;i<=n;i++)s[i]-='a',cnt[s[i]]++;

	lint ans=1;
	for(int i=0;i<alp;i++)ans=ans*(cnt[i]+1)%mo;
	printf("%lld\n",(ans-1+mo)%mo);
	
	return 0;
}


Measured memory_bytes: 640
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    B = [int(x) for x in input().split()]

    ans = 0
    for i in range(1,N-1): # loop over except 0 and -1
        ans += min(B[i-1],B[i])
    ans += (B[0]+B[-1]) # head and tail
    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc140","c",main)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main()
{
   /* vector<int>v;
    vector<int>v1;
    vector<int>v2;
    set <char>s;
    int t,coun1=0,a,ans3,coun2=0,x,y=0,ans1=0,b,sum=0,flag=0,ans2;*/

    long double li=1;
    long long ai,n;

    cin >> n;

   for(long long i=0;i<n;i++)
   {
       cin >> ai;
       
       if(ai==0)
       {
           cout << "0" << endl;
           return 0;
       }

       li=li*ai;



   }

   if(li > 1000000000000000000 || li < 0)
       {
           cout << "-1";

       }
   else
   {

           cout << (long long)li;

   }






return 0;
}

Measured memory_bytes: 3652
package main

import "fmt"

func main(){
  var a, b, c int
  fmt.Scan(&a, &b, &c)
  if a > c{
    fmt.Println("NO")
  }else{
    if c - a <= b{
      fmt.Println("YES")
    }else{
      fmt.Println("NO")
    }
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

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

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

int powmd(int a, int b) {
	if (b == 1)	return a;
	if (b == 0)	return 1;

	int half = powmd(a, b / 2);
	int ans = half * half;
	ans %= mod;
	if (b & 1) {
		ans *= a;
	}
	ans %= mod;
	return ans;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int dp[3005][3005];

void build_dp(string &s, int n) {
	dp[n][0] = (s[n - 2] == '>') ? 1 : 0;
	dp[n][1] = (s[n - 2] == '<') ? 1 : 0;
	for (int i = n - 1; i >= 2; i--) {
		int total = n - i + 1;

		for (int g = 0; g <= total; g++) {
			if (i == n and g == 0)	continue;
			if (g == 0) {
				if (i == n) continue;
				if (s[i - 2] == '<')continue;
				dp[i][g] = 0;
				for (int j = 1; j <= total; j++) {
					dp[i][g] = (dp[i][g] + dp[i + 1][total - j]) % mod;
				}
			}
			else {
				if (s[i - 2] == '>') {
					dp[i][g] = dp[i][g - 1] - dp[i + 1][g - 1] + mod;
					dp[i][g] %= mod;
				}
				else {
					dp[i][g] = dp[i][g - 1] + dp[i + 1][g - 1];
					dp[i][g] %= mod;
				}
			}
		}
	}

}

int32_t main() {

	fastIO();
	int n;
	string s;
	cin >> n >> s;
	build_dp(s, n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += dp[2][i];
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  string s;
  cin >> s;
  string ans = "AC";
  
  int count = 0;
  REP(i, s.size()) {
    if (i == 0) {
      if (s[i] != 'A')
        ans = "WA";
    }
    
    else if (i >= 2 && i != s.size() - 1 && s[i] == 'C')
      ++count;
    
    else if (s[i] < 'a' || s [i] > 'z')
      ans = "WA";
  }
  
  if (count != 1)
    ans = "WA";
  
  cout << ans << endl;
  
  return 0;
}

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

const int nax = 1e6 + 5;
int child[nax][26];
bitset<nax> is_end;
int nxt = 1;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; 
    cin >> n;
    vector<string> in(n);
    vector<vector<int>> paths(n);
    memset(child, 0, sizeof child);
    for (int i = 0; i < n; ++i) {
        auto &s = in[i];
        cin >> s;
        reverse(begin(s), end(s));
        int node = 0;
        for (char ch : s) {
            paths[i].push_back(node);
            if (child[node][ch-'a'] == 0) {
                child[node][ch-'a'] = nxt++;
            }
            node = child[node][ch-'a'];
        }
        is_end[node] = 1;
    }
    long long ans = 0;
    
    for (int i = 0; i < n; ++i) {
        auto &s = in[i];
        set<int> suffix;
        
        for (int j = (int)s.size() - 1; j >= 0; --j) {
            int node = paths[i][j];
            suffix.insert(s[j]);
            for (char ch : suffix) {
                ans += is_end[child[node][ch-'a']];
            }
            cout << "\n";
        }
    }
    
    cout << ans - n;
}


Measured memory_bytes: 124084
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


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

	ll h, w, m;
	cin >> h >> w >> m;
	vector<ll> x(m), y(m);
	vector<ll> xx(h, 0), yy(w, 0);
	rep(i, m)
	{
		cin >> x[i] >> y[i];
		xx[x[i] - 1]++;
		yy[y[i] - 1]++;
	}

	ll maxx = 0, maxy = 0;

	rep(i, h)
	{
		if (maxx < xx[i])
		{
			maxx = xx[i];
		}
	}
	ll kohox = 0;
	rep(i, h)
	{
		if (maxx == xx[i])
			kohox++;
	}

	rep(i, w)
	{
		if (maxy < yy[i])
			maxy = yy[i];
	}
	ll kohoy = 0;
	rep(i, w)
	{
		if (maxy == yy[i])
			kohoy++;
	}
	ll ans = kohox * kohoy;

	rep(i, m)
	{
		if (maxx + maxy == xx[x[i] - 1] + yy[y[i] - 1])
			ans--;
	}

	if (ans)
		cout << maxx + maxy << endl;
	else
		cout << maxx + maxy - 1 << endl;

	return 0;
}

Measured memory_bytes: 12680
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll ss=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        ss+=a[i];
    }
    sort(a,a+n);
    ll j=n-1;
    for(ll i=0;i<k;i++){
        if(j==-1){
            break;
        }
        ss-=a[j--];
    }
    cout<<ss<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 1792
// AtCoder ABC109: D - Make Them Even
// 2019.9.12 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

int H, W;
char a[505][505]; int f[505];
int ans[250100][4], sz;

inline static void pr(int r1, int c1, int r2, int c2) {
	ans[sz][0] = r1, ans[sz][1] = c1, ans[sz][2] = r2, ans[sz++][3] = c2;
}

int main()
{
	int i, r, c, t, sw;
	
	H = in(), W = in();
	for (r = 1; r <= H; r++) {
		t = 0; for (c = 1; c <= W; c++) {
			a[r][c] = in();
			if (a[r][c] & 1) t++;
		}
		f[r] = t;
	}

	sw = 1; for (r = 1; r <= H; r++) if (f[r]) {
		if (sw) {
			for (c = 1; c < W; c++) if (a[r][c] & 1) {
				pr(r, c, r, c+1), a[r][c+1]++;
			}
			if (r < H && (a[r][W] & 1)) {
				pr(r, W, r+1, W), a[r+1][W]++;
				if (a[r+1][W] & 1) f[r+1]++;
			}
		} else {
			for (c = W; c > 1; c--) if (a[r][c] & 1) {
				pr(r, c, r, c-1), a[r][c-1]++;
			}
			if (r < H && (a[r][1] & 1)) {
				pr(r, 1, r+1, 1), a[r+1][1]++;
				if (a[r+1][1] & 1) f[r+1]++;
			}
		}
		sw = !sw;
	}
	out(sz), pc('\n');
	for (i = 0; i < sz; i++) {
		out(ans[i][0]), pc(' '), out(ans[i][1]), pc(' ');
		out(ans[i][2]), pc(' '), out(ans[i][3]), pc('\n');
	}
	return 0;
}


Measured memory_bytes: 6144
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    d=dict()
    m=10**18+100
    for i in range(N):
        A, B = map(int, input().split())
        if A==0 and B==0:
            d[-m]=d.get(-m,0)+1
        elif B==0:
            d[m]=d.get(m,0)+1
        elif A==0:
            d[0]=d.get(0,0)+1
        else:
            sa=sb=1
            if A<0:
                sa=-1
                A*=-1
            if B<0:
                sb=-1
                B*=-1

            g=math.gcd(A,B)
            A=A//g
            B=B//g
            if sa==-1 and sb==-1:
                t=(A,B)
            elif sb==-1:
                t=(-A,B)
            else:
                t=(sa*A,sb*B)
            d[t]=d.get(t,0)+1
    
        
    #print(d)
    ks=set(d.keys())
    alis=[]
    tot=1
    for i, k in enumerate(ks):
        if d[k]==-1.0:
            continue
        if k==-m:
            continue
        if k==m:
            ik=0
        elif k==0:    
            ik=m
        elif k[0]<0:
            ik=(k[1],-k[0])
        else:
            ik=(-k[1],k[0])
        #print(ik)
        if ik in ks:
            d1,d2=d[k],d[ik]
            tot=(tot*((pow(2,d1,mod)-1)+(pow(2,d2,mod)-1)+1)%mod)%mod
            d[ik]=-1

        else:
            tot=(tot*pow(2,d[k],mod))%mod

    tot-=1
    tot+=d.get(-m,0)%mod
    tot%=mod
    
    print(tot)




if __name__ == "__main__":
    main()

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

using namespace std;

int main() {
	int N;

	cin >> N;

	int ans = N;
	for (int six = 0; six <= N; six++) {
		int cnt = 0, rem;
		//6^iで引き出す額
		rem = six;
		while (rem > 0) { cnt += rem % 6; rem /= 6; }
		//残りを9^iで引き出す
		rem = N - six;
		while (rem > 0) { cnt += rem % 9; rem /= 9; }

		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;

int main() {
	int n, k, q;
    cin>>n>>k>>q;
	vector<int> p(n + 1, k - q);
	for (int i = 1;i <= q;i++) {
		int temp;
		cin >> temp;
		p[temp]++;
	}
	for (int i = 1;i <= n;i++) {
		if (p[i] <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
// Problem : A - αlphabet
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	char ch;
	cin>>ch;
	if(ch<=90)
	cout<<"A";
	else cout<<'a';
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<deque>
#include<algorithm>
using namespace std;

// (target, cost)
vector<pair<int, int> > adj[100000];
bool checked[100000];


int main(){
    int K;
    cin >> K;

    for(int i = 1; i < K; i++){
        adj[i].push_back(make_pair((i+1)%K, 1));
        adj[i].push_back(make_pair((i*10) % K, 0));
    }
    // (now, cost)
    deque<pair<int, int> > deq;
    deq.push_back(make_pair(1, 1));
    checked[1] = true;
    while(!deq.empty()){
        int now = deq[0].first;
        int cost = deq[0].second;
        deq.pop_front();
        //cout << now << ", " << cost << endl;
        if(now == 0){
            cout << cost << endl;
            return 0;
        }
        if(!checked[(now * 10) % K]){
            deq.push_front(make_pair((now * 10) % K, cost));
            checked[(now * 10) % K] = true;
        }
        if(!checked[(now + 1) % K]){
            deq.push_back(make_pair((now + 1) % K, cost + 1));
        }
    }
}



Measured memory_bytes: 6400
unittest
{
	assert( [ "3 1", "1 2 1" ].solve == 2 );
	assert( [ "6 5", "1 2 1", "2 3 2", "1 3 3", "4 5 4", "5 6 5" ].solve == 2 );
	assert( [ "100000 1", "1 100000 100" ].solve == 99999 );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	auto xyzs = new long[ 3 ][ m ];
	foreach( ref xyz; xyzs )
	{
		input.popFront;
		xyz = input.front.split.to!( long[] );
		xyz[ 0 .. 2 ] -= 1;
	}
	
	auto uft = UnionFindTree( n );
	foreach( xyz; xyzs )
	{
		uft.unite( xyz[ 0 ], xyz[ 1 ] );
	}
	return uft.rootnum;
}

// UnionFind木
struct UnionFindTree
{
	long[] ps;
	long[] rs;
	long   rn;
	
	this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
		rn = n;
	}
	
	long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	auto same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	auto unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
		rn--;
	}
	
	auto rootnum()
	{
		return rn;
	}
	
	auto toString()
	{
		return ps.to!( string );
	}
}


Measured memory_bytes: 7792
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)
*/

f(_, _, [], []).
f(_, [], Xs, Xs).

f(YI, [X|Xs], [Y|Ys], [Z|Zs]) :- 
    YI = X,
    Z is Y + 1,
    YI2 is YI + 1,
    f(YI2, Xs, Ys, Zs).

f(YI, [X|Xs], [Y|Ys], [Z|Zs]) :-
    Z is Y,
    YI2 is YI + 1,
    f(YI2, [X|Xs], Ys, Zs).

countX([], _, 0) :- !.
countX([Y|Ys], X, N) :- Y =:= X, countX(Ys, X, N2), N is N2 + 1, !.
countX([_|Ys], X, N) :- countX(Ys, X, N).

g(0, Xs) :-
    countX(Xs, 0, Z),
    writeln(Z).

g(N, Xs) :-
    get_number(D),
    get_numbers(D, Ys),
    f(1, Ys, Xs, Xs2),
    N2 is N - 1,
    g(N2, Xs2).

repX(0, _, []) :- !.
repX(N, X, [Y|Ys]) :- N2 is N - 1, Y is X, repX(N2, X, Ys).

main :-
    get_number(N, K),
    repX(N, 0, Xs),
    g(K, Xs).


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

using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  int answer = 0;
  for (int X = 0; X <= min(K, S); X++) {
    int rest = S - X;
    if (rest > 2 * K) continue;
    int Y_min = max(0, rest - K);
    int Y_max = rest - Y_min;
    answer += Y_max - Y_min + 1;
  }
  cout << answer << "\n";

  return 0;
}


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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
int main() {
    string s;
    cin>>s;
    if(s[2]==s[3] && s[5]==s[4])
    puts("Yes");
    else
    puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define lc (rt << 1)
#define rc (rt << 1) | 1
using namespace std;
typedef long long LL;
const int MAXN = 500005;
const int INF = 0x3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, k, a[MAXN], deg[MAXN], ans[MAXN];
int seg[MAXN << 2];
vector<int> g[MAXN];
priority_queue<int> q;

void Update(int rt, int b, int e, int p, int v) {
	seg[rt] = min(seg[rt], v);
	if (b == e) return;
	int mid = (b + e) >> 1;
	if (p <= mid) Update(lc, b, mid, p, v);
	else Update(rc, mid + 1, e, p, v);
}

int Query(int rt, int b, int e, int l, int r) {
	if (l <= b && e <= r) return seg[rt];
	int mid = (b + e) >> 1;
	if (r <= mid) return Query(lc, b, mid, l, r);
	if (l > mid) return Query(rc, mid + 1, e, l, r);
	return min( Query(lc, b, mid, l, r), Query(rc, mid + 1, e, l, r) );
}

void Link(int i) {
	int l, r, x;
	l = a[i] + 1, r = min(n, a[i] + k - 1);
	if (l <= r) {
		x = Query(1, 1, n, l, r);
		if (x < INF) {
			g[a[i]].push_back(a[x]);
			++deg[a[x]];
//printf("add %d %d\n", a[i], a[x]);
		}
	}
	r = a[i] - 1, l = max(1, a[i] - k + 1);
	if (l <= r) {
		x = Query(1, 1, n, l, r);
		if (x < INF) {
			g[a[i]].push_back(a[x]);
			++deg[a[x]];
//printf("add %d %d\n", a[i], a[x]);
		}
	}
}

void init() {
	read(n); read(k);
	for (int i = 1; i <= n; ++i) {
		int x; read(x);
		a[x] = i;
	}
}

void solve() {
	mset(seg, 0x3f);
	for (int i = n; i >= 1; --i) {
		Link(i);
		Update(1, 1, n, a[i], i);
	}
	for (int i = 1; i <= n; ++i) {
		if (!deg[i]) {
			q.push(-i);
		}
	}
	int pos = 0;
	while (!q.empty()) {
		int u = -q.top();
		q.pop();
		ans[u] = ++pos;
		for (auto v : g[u]) {
			if (--deg[v] == 0) {
				q.push(-v);
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", ans[i]);
	}
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 44544
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    ll cnt = n / (a+b);
    n -= cnt * (a+b);
    ll ans = cnt * a;
    if(n >= a) ans += a;
    else ans += n;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n,m,t;
    scanf("%d %d",&n,&m);
    int a[n][m], b[m], ans[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
       }
    }
    for(int i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<n;i++){
        t=0;
        for(int j=0;j<m;j++){
            t+=(a[i][j]*b[j]);
        }
        ans[i]=t;
    }
    for(int i=0;i<n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 3240
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF (1<<30)
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

struct Edge {
	int to; ll cost;
	Edge(int t, ll c) { to = t; cost = c; }
};
using Pi = pair<ll, int>;
using Graph = vector<vector<Edge>>;
vector<ll> dijkstra(const Graph& graph, int start)
{
	priority_queue<Pi, vector<Pi>, greater<Pi>> pq;	//コスト、頂点
	pq.push(make_pair(0, start));
	vector<ll> cost(graph.size(), INFLL);
	cost[start] = 0;
	while (!pq.empty()) {
		auto top = pq.top(); pq.pop();
		ll c = top.first;
		int v = top.second;
		if (c > cost[v]) continue;
		for (Edge e : graph[v]) {
			ll nc = c + e.cost;
			if (nc >= cost[e.to]) continue;
			pq.push(make_pair(nc, e.to));
			cost[e.to] = nc;
		}
	}
	return cost;
}

int main()
{
	const ll have = 1000000000000000;
	int N, M, S, T; cin >> N >> M >> S >> T; --S; --T;
	Graph Yen(N), Snk(N);
	rep(i, M) {
		int u, v, a, b; cin >> u >> v >> a >> b;--u;--v;
		Yen[u].emplace_back(Edge(v, a));
		Yen[v].emplace_back(Edge(u, a));
		Snk[u].emplace_back(Edge(v, b));
		Snk[v].emplace_back(Edge(u, b));
	}
	auto yen = dijkstra(Yen, S);
	auto snk = dijkstra(Snk, T);
	vector<ll> used(N);
	ll minuse = INFLL;
	for (int year = N - 1; year >= 0; --year) {
		chmin(minuse, yen[year] + snk[year]);
		used[year] = minuse;
	}
	rep(i, N) cout << have - used[i] << endl;
	return 0;
}


Measured memory_bytes: 20676
# coding: utf-8
import sys
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 一番左を赤として2倍、Counter、N文字ずつ選ぶ
# 制約が少ないので全探索も可能
N = ir()
S = sr()
answer = 0
former = S[:N]
latter = S[N:][::-1]

dic_left = defaultdict(int)
for pattern in range(1<<N):
    red = ''; blue = ''
    for i in range(N):
        if pattern>>i & 1:
            red += S[i]
        else:
            blue += S[i]
    key = (red, blue)
    if key in dic_left:
        dic_left[key] += 1
    else:
        dic_left[key] = 1

dic_right = defaultdict(int)
for pattern in range(1<<N):
    red = ''; blue = ''
    for i in range(N):
        if pattern>>i & 1:
            red += latter[i]
        else:
            blue += latter[i]
    key = (red, blue)
    if key in dic_right:
        dic_right[key] += 1
    else:
        dic_right[key] = 1

answer = 0
for k, v in dic_left.items():
    if k in dic_right:
        answer += v * dic_right[k]

print(answer)
# 解説

Measured memory_bytes: 160892
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;
    int s;
    if (n - a - b >= 0) {
        s = 0;
    } else {
        s = a + b - n;
    }

    cout << min(a, b) << " " << s << 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 ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvii vector<vector<ii>>
#define vvll vector<vector<ll>>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

void write();
template <typename T, typename... Args>
void write(T x, Args... args);

void solve() {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    vector<vector<pair<ll, ll>>> res(n,
                                     vector<pair<ll, ll>>(n, {-1e18, -1e18}));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j + i < n; ++j) {
            if (i == 0) {
                res[j][j] = {a[j], 0};
                continue;
            }

            int l = j, r = j + i;
            if (res[l][r - 1].se + a[r] > res[l][r].fi)
                res[l][r] = {res[l][r - 1].se + a[r], res[l][r - 1].fi};

            if (res[l + 1][r].se + a[l] > res[l][r].fi)
                res[l][r] = {res[l + 1][r].se + a[l], res[l + 1][r].fi};
        }

    // for (int i = 0; i < n; ++i)
    //     for (int j = i; j < n; ++j) write(i, j, res[i][j].fi, res[i][j].se);

    write(res[0][n - 1].fi - res[0][n - 1].se);
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}
template <typename T, typename... Args>
void write(T x, Args... args) {
    cout << x;
    if (sizeof...(args)) {
        cout << ' ';
        write(args...);
    } else
        cout << '\n';
}

Measured memory_bytes: 141056
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll y,z,n,p,m=0,k,h,w,sum=0,sum_a=0,sum_b=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u,v;
    bool ok=true;
    string a[4] = {"maerd","remaerd","esare","resare"};
    cin >> s;
    for(int i=s.size()-1; i>=5; i--){
        if(s[i] == 'm'){
            for(int j=1;j<5;j++){
                i--;
                if(s[i] != a[0][j]){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(s[i]=='e'){
            for(int j=1;j<5;j++){
                i--;
                if(s[i] != a[2][j]){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(s[i]== 'r'){
            if(s[i-2]=='m'){
                for(int j=1;j<7;j++){
                    i--;
                    if(s[i] != a[1][j]){
                        cout << "NO" << endl;
                        return 0;
                    }
                }
            }
            else if (s[i-2]=='s'){
                for(int j=1;j<6;j++){
                    i--;
                    if(s[i] != a[3][j]){
                        cout << "NO" << endl;
                        return 0;
                    }
                }
            }
            else {
                cout << "NO" << endl;
                return 0;
            }
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ub upper_bound
#define int long long
#define vbe(sdk) sdk.begin(), sdk.end()
#define pb push_back
#define loop(i, a, b) for (int i = a; i < b; ++i)
#define rloop(i, a, b) for (int i = a; i >= b; --i)
#define mp make_pair
#define mod 1000000007
#define endl '\n'
#define vvll vector<vector<int>>
#define vll vector<int>
#define mint map<int, int>
#define arry(x) (int)x.size()
#define sll set<int>
#define pll pair<int, int>
#define F first
#define S second
#define pi 3.14159265358979323846
using namespace std;
const int MAX = 100001;


void solve()
{
        int s,w;
        cin>>s>>w;
        if(w>=s)
        {
            cout<<"unsafe\n";
        }
        else
        {
            cout<<"safe\n";
        }
        
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #else
    // // online submission
    // #endif


    int t = 1;
   // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int d[4] = {};
    int M = N;
    d[0] = M/1000; 
    M -= d[0]*1000;  
    d[1] = M/100; 
    M -= d[1]*100;
    d[2] = M/10; 
    M -= d[2]*10;
    d[3] = M; 
    M -= d[3];
    if((d[0]==d[1]&&d[1]==d[2]) || (d[1]==d[2]&&d[2]==d[3])) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
r=p[:]

ans=0
for i in range(n):
  if p[i]==i+1:
    ans+=1
    if i!=n-1:
      p[i]=r[i+1]
      p[i+1]=r[i]
      
print(ans)

Measured memory_bytes: 14008
n,h = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

maxa = 0
for a,b in ab:
    maxa = max(maxa,a)

ab.sort(key = lambda x: x[1], reverse = True)

ans = 0

for a,b in ab:
    if h <= 0:
        break
    else:
        if maxa > b:
            break
        else:
            h -= b
            ans += 1

if h > 0:
    ans += -(-h // maxa)

print(ans)


Measured memory_bytes: 64728
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 1e+18
#define MOD 998244353
using namespace std;

int main(){
    int H,W;
    cin >> H >> W;
    
    ll N=0;
    ll a[H][W];
    ll b[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> a[i][j];
            b[i][j]=a[i][j];
        }
    }
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(i==H-1 && j==W-1){continue;}
            
            if(a[i][j]%2==1){
                if(j==W-1){
                    a[i][j]--;
                    a[i+1][j]++;
                    N++;
                }else{
                    a[i][j]--;
                    a[i][j+1]++;
                    N++;
                }
            }
        }
    }
    
    cout<<N<<endl;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(i==H-1 && j==W-1){continue;}
            
            if(b[i][j]%2==1){
                if(j==W-1){
                    b[i][j]--;
                    b[i+1][j]++;
                    
                    cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
                }else{
                    b[i][j]--;
                    b[i][j+1]++;
                    
                    cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 6016
#include <stdio.h>

int bubbleSort(int A[], int N) {
  int times = 0;
  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j < i; j++) {
      if (A[j] > A[j + 1]) {
        int tmp = A[j];
        A[j] = A[j + 1];
        A[j + 1] = tmp;
        times++;
      }
    }
  }
  return times;
}

void printArr(int A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(void) {
  int N;
  scanf("%d", &N);
  int A[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  int t = bubbleSort(A, N);
  printArr(A, N);
  printf("%d\n", t);
  
  return 0;
}


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


using namespace std;

int main(){
  int n; cin >> n;
  vector<int> v(n);

  for(int i = 0; i < n; ++i){
    cin >> v[i]; v[i] -= i;
  }
  sort(v.begin(),v.end());
  int base = v[n/2];
  long long ans = 0;
  for(int e:v){
    ans += abs(e-base);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
from collections import defaultdict


def prime_factorization(n):
    divs = defaultdict(int)

    while n % 2 == 0:
        divs[2] += 1
        n //= 2

    i = 3
    while i <= int(n ** .5) + 1:
        while n % i == 0:
            divs[i] += 1
            n //= i
        i += 2
    if n != 1:
        divs[n] += 1

    return divs

import bisect
N = int(input())
divs = prime_factorization(N)

MAX_VAL = 13
table = [n * (n + 1) // 2 for n in range(1, MAX_VAL)]
ans = 0
for key, value in divs.items():
    idx = bisect.bisect_left(table, value)
    ans += idx + 1 if table[idx] == value else idx

print(ans)


Measured memory_bytes: 9728
#include<cstdio>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);

    bool flag = false;
    for(int i=0; i<3; i++){
        if(n%10 == 7){
            flag = true;
            break;
        }
        n /= 10;
    }
    if(flag)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int num, oddCount = 0, times4 = 0, times2 = 0, tmp;
    cin >> num;
    for(int i = 0; i < num; i++){
        cin >> tmp;
        if(tmp & 1) ++oddCount;
        else if(tmp % 4 == 0) ++times4;
        else if(tmp % 2 == 0) ++times2;
    }
    if(times4 >= oddCount) cout << "Yes" << endl;
    else if(times4 + 1 >= oddCount && times2 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};
int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0, X, Y, Z; i < M; i++) {
        cin >> X >> Y >> Z;
        uf.unite(X - 1, Y - 1);
    }
    unordered_set<int> us;
    for (int i = 0; i < N; i++) us.insert(uf.find(i));
    cout << us.size() << endl;
}

Measured memory_bytes: 4772
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
	int c = 1, W;

	while(cin >> W, W) {
		int n, mx = 0, w[1000], d[1000];
		long dp[1001] = {0};
		cin >> n;
		for(int i = 0; i < n; i++)
			scanf("%d,%d", &d[i], &w[i]);
		for(int i = 1; i <= W; i++)
			dp[i] = -1;

		for(int i = 0; i < n; i++) {
			for(int j = W - w[i]; j >= 0; j--) {
				if(dp[j] >= 0 && j + w[i] <= W) {
					dp[j + w[i]] = ((dp[j + w[i]] > dp[j] + d[i]) ? dp[j + w[i]] : (dp[j] + d[i]));
				}
			}
		}

		for(int i = 0; i <= W; i++)
			if(dp[i] > dp[mx]) mx = i;

		cout << "Case " << c++ << ":" << endl;
		cout << dp[mx] << endl;
		cout << mx << endl;
	}

	return 0;
}

Measured memory_bytes: 1256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()


signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,m;
   cin>>n>>m;
   if(n<m)
   {
       cout<<min(n,abs(n-m))<<endl;
   }
   else
   {
       int x=n%m;
       cout<<min(x,m-x)<<endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string a;
	cin >> a;
	
	int n = (int)a.size();
	vector< vector<int> > sum(n + 1, vector<int>(26, 0));
	
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < 26; ++j) {
			sum[i + 1][j] += sum[i][j];
		}
		
		int x = (int)(a[i] - 'a');
		
		sum[i + 1][x] = sum[i][x] + 1;
	}
	
	
	ll ans = 1LL;
	for(int i = 0; i < n; ++i) {
		int v = (int)(a[i] - 'a');
		int b = n - i - 1 - (sum[n][v] - sum[i + 1][v]);
		ans += b;
	}

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


Measured memory_bytes: 30020
n=int(input())
li=sorted(list(map(int, input().split())),reverse=1)
res=0
for x in range(n):
    for y in range(x+1,n):
        for z in range(y+1,n):
            a=li[x]
            b=li[y]
            c=li[z]
            if (a<b+c) and a!=b and b!=c:
                res+=1
print(res)

Measured memory_bytes: 68028
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int n;
	cin >> n;
	rep(i, 9) {
		rep (j, 9) {
			if ((i + 1) * (j + 1) == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys


def main():
    n = int(sys.stdin.readline())

    if n < 105:
        print(0)
        exit()

    dp = [0] * 201
    ans = 0

    for i in range(1, n + 1):
        for j in range(105, n + 1):
            if j % i == 0:
                dp[j] += 1

    for i in range(105, n + 1, 2):
        if dp[i] >= 8:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
#include<iostream>
#include<queue>
#include<cstring>
#include<vector>

using namespace std;
typedef long long ll;
const int N = 1e6+5,M=N*2;
ll h[N],st[N],dist[N],cnt,n,m;
const ll inf = 0x3f3f3f3f3f3f3f3f;
struct node {
	ll to,nxt,w;
}eg[M*2];
void add(ll u,ll v,ll w){
	eg[cnt].w=w;eg[cnt].to=v;eg[cnt].nxt=h[u];h[u]=cnt++;
}
priority_queue<ll,vector<ll>,greater<ll> >q;
ll dijkstra(ll u){
	memset(st,0,sizeof(st));
//	memset(dist,0x3f,sizeof(dist));
	for(ll i=1;i<=n;i++) dist[i]=inf;
	dist[u]=0;
	q.push(u);
	while(!q.empty()){
		ll u=q.top();
		q.pop();
//		cout<<"*****************\n";
//		if(st[u]) continue;
//		st[u]=1;
		for(ll i=h[u];i!=-1;i=eg[i].nxt){
			ll v = eg[i].to;
//			if(st[v]) continue;
			if(dist[v]>dist[u]+eg[i].w){
				dist[v]=dist[u]+eg[i].w;
				q.push(v);
			} 
		}
	}
	if(dist[n]==inf) return -1;
	return dist[n];
}

int main(){
	memset(h,-1,sizeof(h));
	cnt=0;
	cin>>n>>m;
	for(ll i=1;i<=n;i++) add(i,i-1,0);
	for(ll i=0;i<m;i++){
		ll u,v,w;
		cin>>u>>v>>w;
		add(u,v,w);
	}
	cout<<dijkstra(1)<<endl;
	
	return 0;
}

Measured memory_bytes: 33264
#include <iostream>
using namespace std;
int main() {
	int N, H, W;
	int ans = 0;
	cin >> N >> H >> W;
	int A[N], B[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		if (A[i] >= H && B[i] >= W) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long int a,b;
	cin>>a>>b;
	if(a>0&&b>0)cout<<"Positive"<<endl;
	else{
		if(a<0&&b<0){
			if((a-b+1)%2==0)cout<<"Positive"<<endl;
			else cout<<"Negative"<<endl;
		}
		else cout<<"Zero"<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	
	int n;
	while(cin>>n && n){
		map<string,string> change;
		for(int i=0;i<n;i++){
			string s1,s2;
			cin>>s1>>s2;
			change[s1]=s2;
		}
		
		int m;
		cin>>m;
		string ans;
		for(int i=0;i<m;i++){
			string s;
			cin>>s;
			if(change.find(s)!=change.end())s=change[s];
			ans+=s;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1348
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    V vec(n,-1);
    rep(i,m){
        ll s,y;
        cin>>s>>y;
        s--;
        if(vec[s]!=-1&&vec[s]!=y){
            cout<<-1<<endl;
            return 0;
        }
        if(s==0&&y==0){
            if(n==1){
                continue;
            }
            cout<<-1<<endl;
            return 0;
        }
        vec[s]=y;
    }
    if(n==1){
        if(vec[0]==-1){
            cout<<0<<endl;
            return 0;
        }
        cout<<vec[0]<<endl;
        return 0;
    }
    rep(i,n){
        if(i==0){
            if(vec[i]==-1){
                vec[i]=1;
            }
        }
    }
    ll sum=0;
    rep(i,n){
        if(vec[i]>=1){
            sum+=vec[i]*pow(10,n-i-1);
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 512