akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fname "B"
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << '\n'
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
int cnt[200];

int main()
{
	if (fopen(fname".INP", "r")) {
		freopen(fname".INP", "r", stdin);
		freopen(fname".OUT", "w", stdout);
	}
	ios_base::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	REP0(i, s.size()) ++cnt[int(s[i])];
	bool check = true;
	REP0(i, 150) if (cnt[i] % 2 == 1) check = false;
	if (check) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n, max_len;
int num[11], dp[11];

int main(){
    //freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    while(n--){
        for(int i=0; i<10; i++){
            scanf("%d", &num[i]);
        }
        memset(dp, 0, sizeof(dp));
        max_len = 1;
        dp[0] = 1;
        
        for(int i=1; i<10; i++){
            for(int j=0; j<i; j++){
                if(num[i] < num[j])
                    dp[i] = max(dp[i], dp[j] + 1);
            }
            max_len = max(max_len, dp[i]);
        }

        if(max_len > 2)
            printf("NO\n");
        else 
            printf("YES\n");
    }
    return 0;
}


Measured memory_bytes: 2548
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        for(int d = 0; d < lines.length - 1; d++){
            String[] str = lines[d].split(" ");
            int[] q = new int[str.length];
            for ( int i = 0; i < str.length; i++){
                q[i] = Integer.parseInt(str[i]);
            }
            int n = q[0];
            int x = q[1];
            int num = 0;
            for (int i = 1; i <= n-2; i++){
                for(int j = i + 1; j <= n-1; j++){
                    for(int k = j + 1; k <= n; k++){
                        if( i + j + k == x){
                            num++;
                            break;
                        }
                    }
                }
            }
            System.out.println(num);
        }
   }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}


Measured memory_bytes: 26976
#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>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
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};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#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,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;}

/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
bool used[500005];
char s[500005],t[500005];
bool flag,dame;

ll pow(ll n){
	num = 1;
	for(int i=0;i<n;i++)num *= 2;
	return num;
}

int main(){
	cin >> m >> k;
	if(k == 0){
		for(i=0;i<pow(m+1);i++){
			pe(i/2);
		}
		el;
		return 0;
	}else if(k < pow(m)){
		c = 0;
		for(i=0;i<pow(m);i++){
			if(i != k){
				c = (c ^ i);
			}
			//pe(c);
		}
		//p(c);
		if(c != k){
			p(-1);
			return 0;
		}
		x[1] = k;
		x[0] = x[2] = (k + 1) % pow(m);
		a = 3;
		b = pow(m+1)-1;
		c = (k + 2) % pow(m);
		while(1){
			if(a == b){
				x[a] = k;
				break;
			}else{
				x[a] = x[b] = c;
				c = (c + 1) % pow(m);
				a ++;
				b --;
			}
		}
		for(i=0;i<pow(m+1);i++){
			pe(x[i]);
		}
		el;
		return 0;
	}else{
		p(-1);
	}
	return 0;
}

Measured memory_bytes: 30208
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	long long maxx = 0;
	long long ans=0;
	long long x;
	for (int i=1; i<=n; i++) {
		cin>>x;
		if (x>=maxx) {
			maxx=x;
		} else {
			ans+=(maxx-x);
		}
	}
	cout<<ans<<"\n";
return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n(s.size());
    vector<int> answer(n, 0);
    for (int i = 0; i < n; ++i) {
        assert (s[i] == 'R');
        int j = i;
        while (s[j+1] == 'R') ++j;
        int x = j;
        ++j;
        while (j+1 < n && s[j+1] == 'L') ++j;
        for (int k = i; k <= j; ++k) {
            if (k%2 == x%2) {
                ++answer[x];
            } else {
                ++answer[x+1];
            }
        }
        i = j;
    }
    for (int a : answer) {
        cout << a << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1104
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long int LL;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef string::iterator STI;

int n, k;
int c[5010], r[5010];

vector<int> df_cango[5010];
bool df_visited[5010];

vector<int> dj_cango[5010];
bool dj_visited[5010];
priority_queue<PII, VP, greater<PII> > dj_search;

void dfs(int start)
{
  queue<int> df_search;
  memset(df_visited, false, sizeof df_visited);

  df_search.push(start);
  df_visited[start] = true;
  
  for(int i = 1; i <= r[start]; i++){
    int sz = df_search.size();
    for(int j = 0; j < sz && !df_search.empty(); j++){
      int now = df_search.front();
      df_search.pop();

      for(int k = 0; k < df_cango[now].size(); k++){
	if(!df_visited[df_cango[now][k]]){
	  df_visited[df_cango[now][k]] = true;
	  dj_cango[start].PB(df_cango[now][k]);
	  df_search.push(df_cango[now][k]);
	}
      }
    }
  }

  return;
}

int dijk()
{
  dj_search.push(MP(0, 1));
  
  while(!dj_search.empty()){
    PII now = dj_search.top();
    dj_search.pop();

    if(now.second == n)
      return now.first;

    if(!dj_visited[now.second]){
      dj_visited[now.second] = true;
      for(int i = 0; i < dj_cango[now.second].size(); i++){
	if(!dj_visited[dj_cango[now.second][i]]){
	  dj_search.push(MP(now.first + c[now.second], dj_cango[now.second][i]));
	}
      }
    }
  }			 
}

int main()
{
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> c[i] >> r[i];
  for(int i = 1; i <= k; i++){
    int a, b;
    cin >> a >> b;
    df_cango[a].PB(b);
    df_cango[b].PB(a);
  }

  for(int i = 1; i <= n; i++)
    dfs(i);

  cout << dijk() << endl;
  
  return 0;
}

Measured memory_bytes: 135092
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        b = N - r * R - g * G
        if b < 0 or b % B != 0:
            continue
        ans += 1
print(ans)

Measured memory_bytes: 67112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

string s;
int N, a, b, cnt, dob;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        int sz = s.size();
        b += s[0] == 'B';
        a += s[sz - 1] == 'A';
        if (s[0] == 'B' && s[sz - 1] == 'A')
            a--, b--, dob++;

        for (int j = 0; j + 1 < sz; j++)
            cnt += (s[j] == 'A' && s[j + 1] == 'B');
    }
    if (dob > 0 && (a > 0 || b > 0))
        a++, b++;
    cnt += (dob - 1) * (dob >= 2);
    cout << cnt + min(a, b) << endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    string s; cin >> s;
    int sum = 0;
    for(auto c : s) sum += (c - '0');
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long A = l[0], B = l[1], C = l[2], K = l[3];

            if (K % 2 == 0)
                Console.WriteLine(A - B);
            else
                Console.WriteLine(B - A);
        }
    }
}


Measured memory_bytes: 11348
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m,s;

int main() {
	qr(n); qr(m);
	for(int i=1,x;i<=m;i++)
		qr(x),s+=x;
	if(n<s) puts("-1");
	else pr2(n-s);
	return 0;
}



Measured memory_bytes: 3652
N = int(input())
X = list(map(int, input().split()))
_min = min(X)
_max = max(X)
_sum = 1000000000
for i in range(_min, _max+1):
    temp = 0
    for x in X:
        temp += (x - i) * (x - i)
    if temp < _sum:
        _sum = temp
print(_sum)


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

int main() {
    long long a, b;
    cin >> a >> b;
    if (a > 0 && b > 0) {
        cout << "Positive" << endl;
    } else if (a <= 0 && b >= 0) {
        cout << "Zero" << endl;
    } else {
        if ((b - a + 1) % 2 == 1) {
            cout << "Negative" << endl;
        } else {
            cout << "Positive" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter


def main():
    n = input()
    a = input().split()
    ans_base = 0
    counter = Counter(a)
    for v in counter.values():
        ans_base += v * (v-1) // 2

    for v in a:
        cnt = counter[v]
        if 2 <= cnt:
            print(ans_base - cnt * (cnt - 1) // 2 + (cnt - 1) * (cnt-2) // 2)
        else:
            print(ans_base)


if __name__ == '__main__':
    main()


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

int N, A, B;

int digitSum(int n) {
  if(n < 10) return n;
  return (n % 10) + digitSum(n/10);
}

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

  int ans = 0;
  for(int i = 1; i <= N; i++){
    int sum = digitSum(i);
    if(A <= sum && sum <= B) ans += i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))




#62
s = list(input())
jg = {}

for i in range(len(s)):
    if s[i] in jg:
        print("no")
        break
    else:
        jg[s[i]] = 1
    
    if i == len(s)-1:
        print("yes")






Measured memory_bytes: 2940
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
INPUT = [list(map(int, input().split())) for _ in range(q)]
ans = 0

for A in combinations_with_replacement(range(1, m + 1), n):
    temp = 0
    for a, b, c, d in INPUT :
        a -= 1; b -= 1
        if A[b] - A[a] == c:
            temp += d
    ans = max(ans, temp)
print(ans)


Measured memory_bytes: 80248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
double lim[40100];
void update(int now,double t,double v){
    now*=2;
    t*=2;
    for(int i=now;i<=now+t;i++){
        chmin(lim[i],v);
    }
}
int main(){
    int n;cin >> n;
    vector<double> t(n),v(n);
    for(int i=0;i<n;i++) cin >> t[i];
    for(int i=0;i<n;i++) cin >> v[i];
    int tot=0;
    for(int i=0;i<n;i++) tot+=t[i];
    fill(lim,lim+40100,INF);
    int now=0;
    for(int i=0;i<n;i++){
        update(now,t[i],v[i]);
        now+=t[i];
    }
    lim[0]=0;
    lim[2*tot]=0;
    for(int i=0;i<=2*tot;i++) chmin(lim[i+1],lim[i]+0.5);
    for(int i=2*tot;i>=0;i--) chmin(lim[i-1],lim[i]+0.5);
    double ans=0.0;
    for(int i=0;i<2*tot;i++){
        ans+=(lim[i]+lim[i+1])/2*0.5;
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char a[10];
int main(){
	scanf("%s",a);
	int len=strlen(a);
	for(int i=0;i<len-1;i++){
		if(a[i]=='A' && a[i+1]=='C'){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int reem(int a,int b)
{
	if((a+b)<24)

	{
		return a+b;
	}
	else
		return ((a+b)-24);
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b;
	cin>> a>>b;
	cout<<reem(a,b)<<"\n";
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] cards = new int[n+1];
		
		for (int i = 1; i <= n; i++) {
			 int card = sc.nextInt();
			 cards[i] += card;
		}
		
		long res = 0;
		
		for (int i = 1; i <= n; i++) {
			res += cards[i]/2;
			cards[i] -= cards[i]/2 * 2;
			if (i < n && cards[i] > 0 && cards[i+1] > 0) {
				int min = Math.min(cards[i], cards[i+1]);
				res += min;
				cards[i] -= min;
				cards[i+1] -= min;
			} 
		}
		
		System.out.println(res);
	}
	
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}

Measured memory_bytes: 36656
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#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 rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 1e9 + 10;

int N,M,X;
int C[20];
int A[20][20];
int v[20];

signed main()
{
	cin>>N>>M>>X;
	rep(i, N) {
		cin>>C[i];
		rep(j, M) {
			cin >> A[i][j];
		}
	}

	int ans = inf;

	rep(S, (1<<N)) {
		memset(v, 0, sizeof v);
		int cost = 0;
		rep(i, N) {
			if (S>>i&1) {
				cost += C[i];
				rep(j, M) {
					v[j] += A[i][j];
				}
			}
		}

		bool ok = true;

		rep(j, M) {
			if (v[j] < X) ok = false;
		}

		if (ok)
			chmin(ans, cost);
	}

	if (ans == inf) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
}




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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m; cin>>n>>m;
    vector<vector<ll>> s(m);
    rep(i,m){
        ll k; cin>>k;
        rep(j,k){
            ll sw; cin>>sw;
            sw--;
            s[i].push_back(sw);
        }
    }
    vector<ll> p(m);
    rep(i,m) cin>>p[i];

    ll ans=0;
    for(int i=0;i<(1<<n);i++){
        bool ok=true;
        rep(j,m){
            ll cnt=0;
            for(auto on:s[j]){
                if(i&1<<on) cnt++;
            }
            if(cnt%2!=p[j]) ok=false;
        }
        if(ok) ++ans;
    }

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

Measured memory_bytes: 3628
// 上級者の解答を勉強する.
// maroonrk氏.
// https://atcoder.jp/contests/agc036/submissions/6420041
#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
    return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
    os<<"{";
    for(auto e:v)os<<e<<",";
    return os<<"}";
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);
    
    int n,k;cin>>n>>k;
    k*=n;
    vi a(n);
    map<int,vi> idx;
    rep(i,n){
        cin>>a[i];
        idx[a[i]].pb(i);
    }
    vi w(n);
    for(auto kv:idx){
        int s=kv.b.size();
        kv.b.pb(kv.b[0]+n);
        rep(i,s){
            w[kv.b[i]]=kv.b[i+1]-kv.b[i]+1;
        }
    }
    const int inf=LLONG_MAX/3;
    const int L=60;
    vc<vi> nx{w};
    rep(_,L){
        vi&x=nx.back();
        vi y(n);
        rep(i,n)y[i]=min(inf,x[i]+x[(i+x[i])%n]);
        nx.pb(y);
    }
    int cur=0;
    per(i,L+1){
        if(cur+nx[i][cur%n]<=k)
            cur+=nx[i][cur%n];
    }
    if(cur==k)
        return 0;
    vi ans;
    set<int> has;
    rng(i,cur%n,n){
        if(has.count(a[i])){
            while(1){
                int v=ans.back();
                ans.pop_back();
                has.erase(v);
                if(v==a[i])break;
            }
        }else{
            ans.pb(a[i]);
            has.insert(a[i]);
        }
    }
    rep(i,ans.size()){
        cout<<ans[i];
        if(i<int(ans.size())-1)
            cout<<" ";
        else
            cout<<endl;
    }
}

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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    string s;

    cin >> s;

    cout << s[0] + s[1] + s[2]  - 3 * '0' << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
#l, r = list(map(int, input().split()))
# A = list(map(int, input().split()))
a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
#a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#x = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
# for i in range(1, int(n**0.5)+1):
total = sum(a)
s = 0
for i in range(1, n):
    if i % 2 != 0:
        s += a[i]
x = []
x.append(total - 2*s)
for i in range(1, n):
    x.append(2*a[i-1]-x[i-1])

for i in range(n):
    print(x[i], end=" ")


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

using namespace std;

#define MAX (1<<15)

int main()
{
    int N;
    int dp[MAX+1][5] = {};
    dp[0][0] = 1;
    for (int i = 1; i <= MAX; i++) {
        for (int j = i*i; j <= MAX; j++) {
            for (int k = 0; k < 4; k++) {
                dp[j][k+1] += dp[j-i*i][k];
            }
        }
    }
    
    while (cin >> N, N) {
        int sum = 0;
        for (int i = 1; i <= 4; i++) {
            sum += dp[N][i];
        }
        cout << sum << endl;
    }        
    return 0;
}

Measured memory_bytes: 3708
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N=20,P=1e9+7;

int n,m,p,a[N],f[N][1<<16|5],fac[1<<16|5],inv[1<<16|5];

inline int C(int x,int y){
  if(x<y) return 0;
  return 1LL*fac[x]*inv[y]%P*inv[x-y]%P;
}

int pw[N];

inline void add(int &x,int y){
  (x+=y)%=P;
}

int main(){
  scanf("%d%d",&n,&m);
  pw[0]=1; for(int i=1;i<=n;i++) pw[i]=pw[i-1]*2; p=pw[n];
  fac[0]=1; for(int i=1;i<=p;i++) fac[i]=1LL*fac[i-1]*i%P;
  inv[1]=1; for(int i=2;i<=p;i++) inv[i]=1LL*(P-P/i)*inv[P%i]%P;
  inv[0]=1; for(int i=1;i<=p;i++) inv[i]=1LL*inv[i]*inv[i-1]%P;
  for(int i=1;i<=m;i++) scanf("%d",&a[i]);
  sort(a+1,a+1+m); int ans=0; f[m+1][0]=1;
  for(int i=m;i;i--){
    for(int S=0;S<(1<<n);S++) f[i][S]=f[i+1][S];
    for(int S=0;S<(1<<n);S++){
      int cnt=0;
      for(int j=1;j<=n;j++)
	if(S>>(j-1)&1) cnt+=pw[j-1];
      int rst=p-a[i]-cnt;
      for(int j=1;j<=n;j++)
	if(S>>(j-1)&1);else{
	  if(pw[j-1]-1>rst) continue;
	  add(f[i][S|(1<<j-1)],1LL*f[i+1][S]*C(rst,pw[j-1]-1)%P*fac[pw[j-1]]%P);
	}
    }
  }
  for(int i=0;i<(1<<n);i++){
    int cur=f[1][i],cnt=0,tot=0;
    for(int j=1;j<=n;j++)
      if((i>>(j-1))&1) cnt+=pw[j-1],tot++;
    cur=1LL*cur*fac[p-cnt-1]%P;
    if(tot&1) ans=(ans-cur)%P;
    else ans=(ans+cur)%P;
  }
  ans=1LL*ans*p%P;
  printf("%d\n",(ans+P)%P);
  return 0;
}


Measured memory_bytes: 4864
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			list.add(scan.nextInt());
		}

		int count = 0;
		int min = Collections.max(list);

		for(int i = 0; i < n; i++) {
			if(list.get(i) <= min) {
				min = list.get(i);
				count++;
			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 81336
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count=0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x==500*i+100*j+50*k:
                count=count+1
            

print(count)



Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

int main() {

	
	int a[3]; cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == a[1] && a[1] != a[2]) { cout << "Yes" << endl; return 0; }
	if (a[1] == a[2] && a[1] != a[0]) { cout << "Yes" << endl; return 0; }
	cout << "No" << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

string x, y;
ll n, m, a, e, s, r, dp[105][105];

ll solve(ll l){
    for(int i=0;i<=n;i++){
        fill(dp[i], dp[i]+m+1, LLONG_MAX/3);
    }

    dp[0][0] = 0;
    for(int i=1;i<=n;i++){
        dp[i][0] = e*i;
    }
    for(int i=1;i<=m;i++){
        dp[0][i] = a*i;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(x[i]==y[j]){
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (j<l ? r : 0));
            }
            else{
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + s + (j<l ? r : 0));
            }
            dp[i+1][j+1] = min({dp[i+1][j+1], dp[i+1][j] + a, dp[i][j+1] + e});
        }
    }
    
    return dp[n][m];
}

int main(){
    while(cin >> x){
        if(x == "#")break;
        cin >> y >> a >> e >> s >> r;
        n = ll(x.size());
        m = ll(y.size());
        ll ans = LONG_LONG_MAX;
        
        for(int i=0;i<m;i++){
            ans = min(solve(i), ans);
            y.insert(y.begin() ,y.back());
            y.erase(--y.end());
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const ll max_co = 3234600000;
vl ans;
void solve(ll i){
    ll r = i%10;
    ll a = i*10+r;
    if(a>max_co)return;
    ans.push_back(a);
    solve(a);
    if(r!=0){
    ll b = i*10+r-1;
    if(b>max_co)return;
    ans.push_back(b);
    solve(b);
    }
    if(r!=9){
    ll c= i*10+r+1;
    if(c>max_co)return;
    ans.push_back(c);
    solve(c);
    }

}
int main(){
 int n,m;
 cin>>n;
 rep(i,10){
     if(i==0)continue;
     ans.push_back(i);
     solve(i);
 }
 sort(been(ans));
 cout<<ans[n-1]<<endl;
}

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

int main(){
  long long i,j,X;
  cin >> X;
  int N = 1000;
  bool flag = false;
  for(i=0; i<N-1; i++){
    for(j=i+1; j<N; j++){
      if(pow(j,5)-pow(i,5) == X) flag = true;
      if(flag) break;
    }
    if(flag) break;
  }
  if(flag){cout << j << " " << i; return 0;}
  for(i=0; i<N; i++){
    for(j=0; j>-N; j--){
      if(pow(i,5)-pow(j,5) == X) flag = true;
      if(flag) break;
    }
    if(flag) break;
  }
  cout << i << " " << j;
  return 0;
}

Measured memory_bytes: 4060
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int q;
	cin>>q;
	for(;q--;){
		int c,a,n;
		cin>>c>>a>>n;
		int num,team=0;
		
		num = min({c,a,n});
		team+=num; c-=num; a-=num; n-=num;
		
		num = min(c/2,a);
		team+=num; c-=num*2; a-=num;
		
		num = c/3;
		team+=num;
		cout<<team<<endl;
	}
}

Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
       
        static void SolveA()
        {
            string s = Console.ReadLine();
            int ans = 0;
            for(int i=0;i<s.Length;++i)
            {
                if(s[i] == '1') { ans++; }
            }
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////

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

    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X;
    X.resize(N);
    for (int i = 0; i < N; i++)
        cin >> X[i];

    vector<int> dif;
    for (int i = 0; i < N - 1; i++)
        dif.push_back(X[i + 1] - X[i]);
    sort(dif.begin(), dif.end());

    int64 pref = 0;
    int64 teleports = (int64) (N - 1) * B; 

    int64 result = teleports;

    for (int i = 0; i < dif.size(); i++) {
        pref += dif[i];
        teleports -= B;
        result = min(result, pref * A + teleports);
    }

    cout << result << "\n";

    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    vector<ll> v(3);
    forn(3) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    if ((v[0] == v[1] and v[1] != v[2]) or (v[1] == v[2] and v[1] != v[0])) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 256
from collections import deque

def bfs(s, g, color, indeg, out):
    q = deque()
    q.append(s)
    color[s] = True
    while len(q) != 0:
        u = q.popleft()
        out.append(u)
        for i in range(len(g[u])):
            v = g[u][i]
            indeg[v] -= 1
            if indeg[v] == 0 and not color[v]:
                color[v] = True
                q.append(v)


def tsort(n, g):
    color = [False] * n
    indeg = [0] * n
    for u in range(n):
        for i in range(len(g[u])):
            v = g[u][i]
            indeg[v] += 1

    out = []
    for u in range(n):
        if indeg[u] == 0 and not color[u]:
            bfs(u, g, color, indeg, out)

    for line in out:
        print(line)


if __name__ == '__main__':
    n, m = [int(v) for v in input().split()]
    g = [[] for i in range(n)]
    for i in range(m):
        s, t = [int(v) for v in input().split()]
        g[s].append(t)

    tsort(n, g)


Measured memory_bytes: 9144
n = int(input())
d, x = map(int, input().split())
arr = []
ans = 0
ans += x

for _ in range(n):
    day_sum = 1
    keisu = 1
    num = int(input())

    while day_sum <= d:
        ans += 1
        keisu += 1
        day_sum += num
print(ans)


Measured memory_bytes: 9084
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int main()
{
  ll N,M, K;
  cin >> N >> M >> K;
  vector<ll> A(N+1,0);
  vector<ll> B(M+1,0);
  for(int i = 1;i <= N;i++){
    ll a;
    cin >> a;
    A[i] += A[i-1] + a;
  }
  for(int i = 1;i <= M;i++){
    ll b;
    cin >> b;
    B[i] += B[i-1] + b;
  }
  ll ans = 0;
  ll b_books = M;
  for(int i = 0;i <= N;i++){
    while(b_books >= 0 && A[i] + B[b_books] > K){
      b_books--;
    }
    if (b_books >= 0){
      ans = max(ans,i+b_books);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6420
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M];
        int[] b = new int[M];
        int[] c = new int[M];
        int[][] d = new int[N + 1][N + 1];

        for(int i=1; i<=N; i++){
            for(int j=1; j<=N; j++){
                if(i==j){
                    d[i][j] = 0;
                }
                else{
                    d[i][j] = Integer.MAX_VALUE / 2;
                }
            }
        }
        
        for(int i=0; i<M; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
            d[a[i]][b[i]] = c[i];
            d[b[i]][a[i]] = c[i];
        }
        int ans = 0;
        for(int k=1; k<=N; k++){
            for(int i=1; i<=N; i++){
                for(int j=1; j<=N; j++){
                    if(d[i][j]>d[i][k]+d[k][j]){
                        d[i][j] = d[i][k] + d[k][j];
                    }
                }
            }
        }
        boolean[] memo = new boolean[M];
        for(int i=1; i<=N; i++){
            for(int j=1; j<=N; j++){
                for(int k=0; k<M; k++){
                    if(d[i][j]==d[i][a[k]]+c[k]+d[b[k]][j] && !memo[k]){
                        ans++;
                        memo[k] = true;
                    }
                }
            }
        }
        System.out.println(M - ans);
    }
}

Measured memory_bytes: 27752
#include <iostream>
#include <vector>

using std::vector;

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
    os << p.first << " " << p.second;
    return os;
}

int main() {
    using std::cin;
    using std::cout;

    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H);
    for (vector<int> &ai : a) {
        ai.resize(W);
        for (int &aij : ai) {
            cin >> aij;
        }
    }

    using XY = std::pair<int, int>;
    vector<std::pair<XY, XY>> ans;
    // 奇数のやつを右に寄せる
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W - 1; ++j) {
            if (a[i][j] % 2) {
                // a[i][j]--;
                a[i][j + 1]++;
                ans.push_back({{i + 1, j + 1}, {i + 1, j + 2}});
            }
        }
    }
    // 右に寄せたやつをしたに寄せる
    for (int i = 0; i < H - 1; ++i) {
        if (a[i][W - 1] % 2) {
            // a[i][W-1]--;
            a[i + 1][W - 1]++;
            ans.push_back({{i + 1, W}, {i + 2, W}});
        }
    }

    // N = ans.size
    cout << ans.size() << '\n';
    for (const std::pair<XY, XY> &xyxy : ans) {
        cout << xyxy << '\n';
    }

    return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using PZL = vector<vector<int>>;

int potential(PZL p) {
    int res = 0;
    rep(i, 3) {
        rep(j, 3) {
            int x = (p[i][j] - 1) % 3;
            int y = (p[i][j] - 1) / 3;
            if (p[i][j] == 0) {
                x = 2;
                y = 2;
            }
            res += abs(j - x) + abs(i - y);
        }
    }
    return res;
}

ll hashing(PZL p) {
    ll res = 0;
    ll base = 1;
    rep(i, 3) {
        rep(j, 3) {
            res += p[i][j] * base;
            base *= 9;
        }
    }
    return res;
}

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

    PZL pazzle(3, vector<int>(3)); 
    rep(i, 3) {
        rep(j, 3) cin>>pazzle[i][j];
    }

    PZL ans {
        vector<int> {1, 2, 3},
        vector<int> {4, 5, 6},
        vector<int> {7, 8, 0},
    };
    vector<P> direc {P(1, 0), P(-1, 0), P(0, 1), P(0, -1)};
    priority_queue<pair<P, PZL>, vector<pair<P, PZL>>, greater<pair<P, PZL>>> q;
    set<ll> visited;
    q.push(pair<P, PZL>(P(potential(pazzle), 0), pazzle));

    int res = 0;
    while (!q.empty()) {
        pair<P, PZL> p = q.top(); q.pop();
        PZL pzl = p.second;
        int w = p.first.second;
        
        if (pzl == ans) {
            res = w;
            break;
        }

        ll hash = hashing(pzl);
        if (visited.find(hash) != visited.end()) continue;
        visited.insert(hash);

        P z;
        rep(i, 3) {
            rep(j, 3) {
                if (pzl[i][j] == 0) z = P(i, j);
            }
        }
        for (auto d : direc) {
            int ni = z.first + d.first;
            int nj = z.second + d.second;
            if (ni < 0 || ni >= 3 || nj < 0 || nj >= 3) continue;
            swap(pzl[z.first][z.second], pzl[ni][nj]);
            q.push(pair<P, PZL>(P(w + 1 + potential(pzl), w + 1), pzl));
            swap(pzl[z.first][z.second], pzl[ni][nj]);
        }
    }
    cout<<res<<endl;
}



Measured memory_bytes: 7596
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n;
    cin>>n;
    ll mn=0;
    ll ans=0;
    ll a;
    rep(i,n){
        if(mn==0){
            cin>>mn;
            ans++;
        }else{
           cin>>a;
           if(a<=mn){
               mn=a;
               ans++;
           }
        }
    }
    cout<<ans<<endl;
    }


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	string s;
	cin >> n >> s;
	map<char, int> cnt;
	for (char i : s) {
		++cnt[i];
	}
	ll res = 1LL * cnt['R'] * cnt['G'] * cnt['B'];
	for (int j = 1; j < n - 1; ++j) {
		for (int d = 1; j - d >= 0 && j + d < n; ++d) {
			if (s[j] != s[j + d] && s[j] != s[j - d] && s[j - d] != s[j + d]) --res;
		}
	}
	cout << res;
}

Measured memory_bytes: 3640
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
 
int main() {
  
 ll start=1, end= 5000;
 
 ll X;
 cin >>X;
 ll P=100;
 int years=0;
 while(P<X){
     P+=P/100;
     years++;
 }
 
 cout<<years;
 

}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i ++)
#define for1(i, n) for (int i = 1; i <= n; i ++)
#define repn(i, n) for (int i = n-1; i >= 0; i --)
#define rep1(i, n) for (int i = n; i >= 1; i --)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<pii> qpii;
 
void test_case() {
	ll n; cin >> n;
	ll ALP = 26;
	string ans = "";
	while (n > 0) {
		ans += char('a' + ((n-1)%ALP));
		n = (n-1)/ALP;
	}
	reverse(all(ans));
	cout << ans << '\n';
}
 
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; 
	//cin >> q;
	while (q--) {
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int gcd(int m, int n)
{
    if (m < n)
        return gcd(n, m);
    if (n == 0)
        return m;
    return gcd(n, m % n);
}

int main(void)
{
    int n, x;
    cin >> n >> x;
    int a[n];
    REP(i, n)
    {
        cin >> a[i];
        a[i] = abs(a[i] - x);
    }
    int ans = a[0];
    REP(i, n)
    {
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

int32_t main(){_
   
   cin>>n;

   int ans = 0;
   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
      if (i % 2 and a[i] % 2){
         ans++;
      }
   }

   cout<<ans;
   

   return 0;
}

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

using namespace std;
typedef long long LL;
inline int toint(char c){
    if(isdigit(c)) return c - '0';
    else if(isupper(c)) return c - 'A' + 10;
    else if(islower(c)) return c - 'a' + 36;
}

int main(){
    int n;
    while(cin >> n){
        LL sum = 0;
        for(int i = 0; i < n; i++){
            LL x = 0;
            int p;
            char m[100];
            scanf("%d %s", &p, m);
            for(int idx = 0; m[idx]; idx++){
                x = x * p + toint(m[idx]);
            }
            sum = sum ^ x;
        }
        if(sum == 0){
            cout << "lose" << endl;
        }else{
            cout << "win" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1236
use proconio::input;

fn main() {
  input! {
    n: usize,
    k: usize,
    mut ais: [usize;n],
  }
  ais.sort();
  ais.reverse();

  let mut l = 0;
  let mut r = 1_000_000_000;
  let mut result = 0;
  let mut c = (l + r) / 2;
  while r - l > 1 {
    c = (l + r) / 2;
    let mut sum = 0;
    for v in ais.iter() {
      let v = *v;
      sum += (v - 1) / c;
    }
    
    if sum <= k {
      r = c;
    } else {
      l = c;
    }
  }
  
  println!("{}", r);
}

Measured memory_bytes: 6220