akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in int read()
	{
		int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=21;
int n,k,c[1<<N],ch[1<<N][2],f[N][1<<N],ans=1;
int main()
{
	n=read(),k=read();char nc=0;
	for(int i=0;i<=n;i++)
	{
		for(int x=0;x<1<<i;x++) {while(nc<48||nc>57)nc=gc();f[i][1<<i^x]=nc^48;nc=0;}
	}
	c[0]=-1;for(int i=1;i<2<<n;i++) c[i]=c[i>>1]+1;
	for(int s=2;s<2<<n;s++)
	if(s>>(c[s]-1)&1) ch[s][1]=s^1<<c[s],ch[s][0]=ch[ch[s][1]][0];
	else ch[s][0]=s^3<<(c[s]-1),ch[s][1]=ch[ch[s][0]][1];
	for(int i=n;i;i--) for(int s=1<<i;s<2<<n;s++) if(f[i][s])
	{
		int b=s>>i,t=(s&((1<<i)-1))^1<<i;
		if(ch[t][0]) f[c[ch[t][0]]][(b<<1^1)<<c[ch[t][0]]^ch[t][0]]+=f[i][s];
		if(ch[t][1]) f[c[ch[t][1]]][(b<<1^0)<<c[ch[t][1]]^ch[t][1]]+=f[i][s];
		f[0][b]+=f[i][s];
	}
	for(int s=2;s<2<<n;s++) if(f[0][s]>=k&&c[s]>c[ans]) ans=s;
	int j=n; while(~ans>>j&1) j--;
	while(j--) sr[++C]=(ans>>j&1)+48;
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 192108
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{      
      List<string> youso = new List<string>();
      string line = "";
      while((line=Console.ReadLine()) != null)
      {
        youso.Add(line.ToString());
      }
      
      
            int indata_n = int.Parse(youso[0]);
            string[] indata_s = youso[1].Split(' ');
            List<double> dataList = new List<double>();
            foreach (string s in indata_s)
            {
                dataList.Add(double.Parse(s));
            }
            dataList.Sort();

            double dfirst = dataList[0];
            double answer;
            double gyaku = 0;
            for (int i = 1; i < indata_n; i++)
            {
                gyaku = (dfirst + dataList[i]) / 2;
                dfirst = gyaku;
            }

            answer = gyaku;

      
      Console.WriteLine(answer);        
    }
}

Measured memory_bytes: 13396
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)

    while (sc.hasNext()) {
      val s = sc.next() split Array('+', '=')
      val ans = (0 to 9).find(X => {
        val a = s(0).replaceAll("X", "" + X)
        val b = s(1).replaceAll("X", "" + X)
        val c = s(2).replaceAll("X", "" + X)
        val flg = (check(a) && check(b) && check(c) && BigInt(a) + BigInt(b) == BigInt(c))
        flg
      })

      println(ans.getOrElse("NA"))
    }
  }

  private def check(s: String): Boolean = {
    val res: Boolean = (s.length == 1 || s(0) != '0')
    res
  }
}

Measured memory_bytes: 48532
import heapq
hp=[]
heapq.heapify(hp)
tmp=input()
while True:
    if tmp.startswith("insert"):
        order,number=tmp.split()
        number=int(number)
        heapq.heappush(hp,-number)
    elif tmp.startswith("extract"):
        print(-heapq.heappop(hp))
    elif tmp.startswith("end"):
        break
    tmp=input()
    


Measured memory_bytes: 45312
import sys
class Dice:
    def __init__(self, f):
        self.f = f[:]

    def roll(self, s):
        for f in s:
            n = self.f[:]
            if f == 'E':
                t = n[0]
                n[0] = n[3]
                n[3] = n[5]
                n[5] = n[2]
                n[2] = t
            elif f == 'W':
                t = n[0]
                n[0] = n[2]
                n[2] = n[5]
                n[5] = n[3]
                n[3] = t
            elif f == 'N':
                t = n[0]
                n[0] = n[1]
                n[1] = n[5]
                n[5] = n[4]
                n[4] = t
            else:
                t = n[0]
                n[0] = n[4]
                n[4] = n[5]
                n[5] = n[1]
                n[1] = t
            self.f = n

    def to_top(self, index):
        if index == 1:
            self.roll('N')
        elif index == 2:
            self.roll('W')
        elif index == 3:
            self.roll('E')
        elif index == 4:
            self.roll('S')
        elif index == 5:
            self.roll('NN')
        return self

    def side_roll(self):
        t  = self.f[1]
        self.f[1] = self.f[2]
        self.f[2] = self.f[4]
        self.f[4] = self.f[3]
        self.f[3] = t
        return self

    def all_face(self):
        faces = []
        for i in range(0,6):
            t = Dice(self.f[:])
            faces.append(t.to_top(i).f[:])
            for j in range(3):
                faces.append(t.side_roll().f[:])
        return faces

d1, d2 = (Dice(list(input().split())) for _ in range(2))
fs = d1.all_face()
print('Yes' if d2.f in fs else 'No')

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int k=0;
int n=0;

int dfs(bool three, bool five, bool seven, ll target , int cnt){

	int ans =0;

	if(cnt ==k) {
		if( three && five && seven && target <=n){
		return 1;
		}
		return 0;
	}

	for(int i=3; i<=7;  i +=2){

		if(i ==3){
			ans +=dfs(true,five,seven, target*10+i, cnt+1);
		}
		if(i ==5){
			ans +=dfs(three,true,seven, target*10+i, cnt+1);
		}
		if(i ==7){
			ans +=dfs(three,five,true, target*10+i, cnt+1);
		}

	}
	return ans;
}
int digit(int x){
	int cnt=0;

	while(x){
		cnt++;
		x /=10;


	}

	return cnt;
}

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

	cin>>n;

	k = digit(n);

	int sum =0;

	for(int i=k; i>=3; i--){
	sum +=dfs(false,false,false,0,0);
	k--;
	}
	writeln(sum);




}



Measured memory_bytes: 256
S = input()
ids = [[] for i in range(26)]

for i,c in enumerate(S):
    j = ord(c) - ord('a')
    ids[j].append(i)

for arr in ids:
    if len(arr) < 2: continue
    for i1,i2 in zip(arr,arr[1:]):
        if i2 - i1 <= 2:
            print(i1+1, i2+1)
            exit()
print(-1,-1)

Measured memory_bytes: 7576
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
queue<int> q;
int n;
vector<int> edge[100010];
int a[100010];
int b[100010];
int main()
{
	cin >>n;
	for (int i=0;i<n-1;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	fill(a,a+n,-1);
	fill(b,b+n,-1);
	q.push(0);
	a[0]=0;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		int t=a[x];
		for (int i=0;i<edge[x].size();i++)
		{
			int xi=edge[x][i];
			if (a[xi]==-1)
			{
				q.push(xi);
				a[xi]=t+1;
			}
		}
	}
	q.push(n-1);
	b[n-1]=0;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		int t=b[x];
		for (int i=0;i<edge[x].size();i++)
		{
			int xi=edge[x][i];
			if (b[xi]==-1)
			{
				q.push(xi);
				b[xi]=t+1;
			}
		}
	}
	int r1=0,r2=0;
	for (int i=0;i<n;i++)
	{
		if (a[i]<=b[i]) r1++;
		else r2++;
	}
	cout <<(r1>r2 ? "Fennec" : "Snuke");
	return 0;
}

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

ll n,s;

bool works(ll k){
    if (k == 1) return 0;
    ll t = n;
    ll sd = 0;
    while(t>0){
        sd += t%k;
        t /=k;
    }
    return (sd == s);
}

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

    cin >> n >> s;
    if(s>n){
        cout << -1;
        return 0;
    }
    if(s==n){
        cout << n+1;
        return 0;
    }
    vector<ll> W;
    for(ll i=1;i<=n-s;i++){
        if(i*i>n-s) break;
        if((n-s)%i==0){
            ll a = (n-s)/i+1;
            ll b = i+1;
            if(works(a)){
                W.push_back(a);
            }
            if(works(b)){
                W.push_back(b);
            }
        }
    }

    sort(W.begin(),W.end());
    if(W.size()>0) cout << W[0];
    else cout << -1;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#define int long long
signed main()
{
    int money = 100;
    int goal;
    std::cin >> goal;
    int ans = 0;

    while (money < goal)
    {
        int add = (money/100)*1;
        if (add < 1)
        {
            add = 1;
        }
        money += add;
        ans++;
    }

    std::cout << ans;
}

Measured memory_bytes: 3636
#include<iostream>
#include<unordered_set>
using namespace std;
int main()
{
    unordered_set <int> map;
    int N;
    cin >> N;
    bool ans = true;
    for(int i = 0; i < N; i++)
    {
		int x;
		cin >> x;
		if(map.find(x) == map.end())
		{
			map.insert(x);
		}
		else
		{
			ans = false;
			break;
		}
	}
	if(ans)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	return 0;
}


Measured memory_bytes: 8520
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


set<int> SET;

int main(){

	int N;
	scanf("%d",&N);

	int tmp;
	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		SET.insert(tmp);
	}

	int M;
	scanf("%d",&M);

	for(int i = 0; i < M; i++){

		scanf("%d",&tmp);
		if(SET.count(tmp)){

			SET.erase(tmp);
		}else{

			SET.insert(tmp);
		}
	}

	for(auto at = SET.begin(); at != SET.end(); at++){

		printf("%d\n",*at);
	}

	return 0;
}



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

int main(void)
{
    char S[11]={};
    char T[12]={};
    scanf("%s",S);
    scanf("%s",T);
    T[strlen(S)]='\0';

    if(strcmp(S,T)==0){
        printf("Yes");
    } else {
        printf("No");
    }
    return 0;
}


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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for (int i = 0; i <= a * 500; i += 500) {
    for (int j = 0; j <= b * 100; j += 100) {
      for (int z = 0; z <= c * 50; z += 50) {
        if (i + j + z == x) cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

using namespace std;

int s[1000][1000];

int main() {
	int h, w, a, b;

	cin >> h >> w >> a >> b;


	for(int i = 0;i<w;i++){
		if((0<=b-1&&i<=a-1)||(0>b-1&&i>a-1))
		s[0][i] = 0;
			else
			s[0][i] = 1;
	}
	
	
	for (int i = 1; i < h; i++) {
		for (int j = 0; j <w; j++) {
		
			if((i<=b-1&&j<=a-1)||(i>b-1&&j>a-1))
			s[i][j] = 0;
			else
			s[i][j] = 1;
		}
		cout << endl;
	}





	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout<< s[i][j];
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N;
string S;

template<typename T> class BinaryIndexedTree {
  vector<T> vec;
  const ll n;

public:
  BinaryIndexedTree(T _n) : vec(_n + 1), n(_n) {}
  T query(ll x) { return _query(x + 1); }
  void update(ll x, T k) { _update(x + 1, k); }

private:
  T _query(ll x) {
    T ret = 0;
    for(ll i = x; i > 0; i -= i & (-i)) ret += vec[i];
    return ret;
  }

  void _update(ll x, T k) {
    for(ll i = x; i <= n; i += i & (-i)) vec[i] += k;
  }
};

int main(void) {
  cin >> S;
  N = S.length();

  vector< vector<ll> > pos(256);
  REP(i, 0, N) pos[S[i]].push_back(i);

  ll odd = 0, p;
  vector<ll> target(N);
  REP(i, 0, 256) {
    if(pos[i].size() % 2 == 1) odd++;
    REP(j, 0, pos[i].size()) {
      target[pos[i][j]] = pos[i][pos[i].size() - j - 1];
      if(j == pos[i].size() - j - 1) p = target[pos[i][j]];
    }
  }

  if(odd > 1) {
    cout << -1 << endl;
    return 0;
  }

  BinaryIndexedTree<ll> bit(N);
  vector<bool> used(N, false);
  ll ans = 0, q = 0;
  REP(i, 0, N) {
    ll j = N - i - 1, t = target[i];
    if(bit.query(N - 1) == N / 2) break;
    if(used[i]) continue;
    if(target[i] == i) continue;
    // cout << i << " " << j << " " << t << endl;
    // cout << "  " << N - t - 1 << " " << (bit.query(N - 1) - bit.query(t)) << endl;
    ans += (N - t - 1) - (bit.query(N - 1) - bit.query(t));
    if(odd == 1 && i < p) q++;
    bit.update(t, 1);
    used[t] = true;
  }
  if(odd == 1 && (N + 1) / 2 - q - 1 >= 0) ans += (N + 1) / 2 - q - 1;
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  cout << vec.at(n - 1) - vec.at(0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
typedef struct{
  char egara;
  int value;
} card;
 
int main()
{
  int i,j,N,minj,judge=0;
  card C[36],C2[36],c;
 
 
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf(" %c%d",&C[i].egara,&C[i].value);
  }
  for(i=0;i<N;i++){
    C2[i]=C[i];
  }
 
 
  /* BubbleSort */
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(C[j].value < C[j-1].value){
    c = C[j];
    C[j] = C[j-1];
    C[j-1]=c;
      }
    }
  }
 
 
  /* SelectionSort */
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(C2[j].value < C2[minj].value){
    minj = j;
      }
    }
    if(minj!=i){
      c = C2[i];
      C2[i] = C2[minj];
      C2[minj]=c;
    }
  }
 
  for(i=0;i<N-1;i++){
    printf("%c%d ",C[i].egara,C[i].value);
  }
  printf("%c%d\n",C[i].egara,C[i].value);
 
  printf("Stable\n");
 
  for(i=0;i<N-1;i++){
    printf("%c%d ",C2[i].egara,C2[i].value);
  }
  printf("%c%d\n",C2[i].egara,C2[i].value);
 
  /* ?????? */
  for(i=0;i<N;i++){
    if(C2[i].egara!=C[i].egara){
      judge=1;
      break; 
    }
  }
  if(judge==1) printf("Not stable\n");
  else printf("Stable\n");
  return 0;
}

Measured memory_bytes: 608
from itertools import accumulate
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
imos = [0]*(N+1)
count = 0
for i in range(M):
    l, r = [int(_) for _ in stdin.readline().rstrip().split()]
    imos[l-1]+=1
    imos[r]-=1
imos = list(accumulate(imos))
for i in range(N+1):
    if imos[i] == M:
        count += 1
print(count)

Measured memory_bytes: 48092
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



int N, M, Q;

void search(vector<vector<int>>&g, vector<vector<int>>&dp, int v, int d, int c) {

	if (dp[v][d] != 0)return;
	for (int i = d; 0 <= i && dp[v][i] == 0; i--)dp[v][i] = c;
	if (d == 0)return;
	for (int x : g[v]) {
		search(g, dp, x, d - 1, c);
	}
}


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

	cin >> N >> M;
	vector<vector<int>>g(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cin >> Q;
	vector<array<int, 3>>query(Q);
	rep(i, Q)rep(j, 3)cin >> query[i][j];
	rep(i, Q)query[i][0]--;

	vector<vector<int>>dp(N, vector<int>(11, 0));

	for(int q = Q-1; 0 <= q; q--) {
		search(g, dp, query[q][0], query[q][1], query[q][2]);
	}

	rep(i, N)cout << dp[i][0] << endl;

	return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; ll K; cin >> N >> K;
    int P[N]; rep(i, N){int a; cin >> a; P[i] = a-1;}
    ll ans = -mod;
    ll C[N]; rep(i, N){ll c; cin >> c; C[i] = c; ans = max(ans, c);}

    if(K > N){
        rep(i, N){
            int pos = P[i];
            int len = 1;
            ll mx_in_loop = C[pos];
            ll acc = C[pos];
            while(pos != i){
                pos = P[pos];
                acc += C[pos];
                mx_in_loop = max(mx_in_loop, acc);
                len++;
            }
            ll num_loop = K/len - 1;
            ll remain = K - num_loop*len;
            pos = i;
            ll acc2 = 0;
            ll mx = 0;
            rep(j, remain){
                pos = P[pos];
                acc2 += C[pos];
                mx = max(mx, acc2);
            }
            if(acc >= 0) ans = max(ans, acc*num_loop + mx);
            else ans = max(ans, mx_in_loop);
        }
        cout << ans << endl;
    } 
    else{
        rep(i, N){
            ll acc = 0;
            int pos = i;
            rep(j, K){
                pos = P[pos];
                acc += C[pos];
                ans = max(ans, acc);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int coin = 0;
  if (a > b) {
    coin += a;
    --a;
  } else {
    coin += b;
    --b;
  }
  if (a > b) {
    coin += a;
    --a;
  } else {
    coin += b;
    --b;
  }
  cout << coin << endl;
  return 0;
}

Measured memory_bytes: 256
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  n, d= I()
  cnt = 0
  for i in range(n):
    x, y = I()
    if (x**2 + y**2)**0.5 <= d:
      cnt += 1
  print(cnt)
   
if __name__ == '__main__':
  main()

Measured memory_bytes: 9632
#include<iostream>
#include<stdio.h>
#include<vector>

const int INF = 9999999;

using namespace std;

int main(){

    int n, m;
    cin>> n>> m;

    int dp[m+1][n+1];

    for(int j=0; j<n+1; j++){
        dp[0][j] = INF;
    }
    for(int i=0; i<m+1; i++){
        dp[i][0] = 0;
    }

    vector<int> coin(m+1);
    for(int i=1; i<m+1; i++){
        cin>> coin[i];
    }

    for(int i=1; i<m+1; i++){
        for(int j=1; j<n+1; j++){
            if(j<coin[i]){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = min(dp[i-1][j], dp[i][j-coin[i]]+1);
            }
        }
    }

    cout<< dp[m][n]<< endl;
    return 0;
}

Measured memory_bytes: 5292
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, M = map(int, readline().split())
    *A, = map(int, readline().split())
    *B, = map(int, readline().split())
    C = []
    prv = 0
    for i in range(M):
        C.append((A[i+1] - prv, 1 << B[i]))
        prv = A[i+1]
    ans = 0
    for i in range(N-1, -1, -1):
        v = 1 << (i+1)
        C1 = []
        r = 0; p = 0
        for c, b in C:
            if r:
                if (b & v) == (p & v) > 0:
                    b0 = b | p
                elif b & v:
                    b0 = p
                elif p & v:
                    b0 = b
                else:
                    b0 = b | p
                    ans += 1
                if C1 and C1[-1][1] == b0:
                    c1, b1 = C1.pop()
                    C1.append((1+c1, b0))
                else:
                    C1.append((1, b0))
                c -= 1
            if c > 1:
                if b & v == 0:
                    ans += c // 2
                if C1 and C1[-1][1] == b:
                    c1, b1 = C1.pop()
                    C1.append((c//2+c1, b))
                else:
                    C1.append((c//2, b))
            if c % 2:
                r = 1; p = b
            else:
                r = 0
        C = C1
    c, p = C[0]
    if p & 1 == 0:
        ans += 1
    write("%d\n" % ans)
solve()


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

using namespace std;

int main(){

    long long n,k,x,y,total=0;
    
    cin >> n >> k;
    cin >> x >> y;

    for(long long i=1;i<=n;i++){
        if(i<=k){
            total+=x;
        }
        else{
            total+=y;
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
accepted = set()
penalty = 0
wa_cnt =  [0]*N

for m in range(M):
    p,s = input().split()
    p = int(p) - 1
    if p in accepted:
        continue
    if s == 'AC':
        accepted.add(p)
        penalty += wa_cnt[p]
    else:
        wa_cnt[p] += 1
print(len(accepted), penalty)




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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define rep(i,n) repl(i,0,n-1)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int main(){
  cin.sync_with_stdio(false);
  int n ,a;
cin >> n >> a;
cout << n*n-a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans=1145141919,nw,ne,kw,ke;
int db[5700000][3];
char s[5700000];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        if(s[i]=='W')kw++;
        if(s[i]=='E')ke++;
    }
    for(int i=0;i<n;i++){
        if(s[i]=='E')ne++;
        db[i][1]=ke-ne;
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='W')nw++;
        db[i][0]=kw-nw;
    }

    for(int i=0;i<n;i++){
        ans=min(ans,db[i][0]+db[i][1]);
    }

    cout<<ans<<endl;

}


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

int A, B;

bool kaibun_5(int n) {
    bool ret = true;

    string str_n = to_string(n);
    for (int i = 0; i < 2; i++) {
        if (str_n[i] != str_n[4-i]) {
            ret = false;
        }
    }

    return ret;
}

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

    int ans = 0;
    for (int i = A; i <= B; i++) {
        if (kaibun_5(i)) {
            ans++;
        }
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int c,x,i,a[40001],b[40001];
        for(i=0;i<n;i++)cin>>a[i];
        for(i=0;i<n;i++)cin>>b[i];
        sort(a,a+n,greater<int>());
        sort(b,b+n,greater<int>());
        bool o=true;
        for(int i=0;i<n-1;i++){
            int* xx=lower_bound(b, b+i, a[i]);
            x=xx - b + (*xx<a[i]);
          //  cout<<x<<" "<<i/2<<endl;
            if(x>i/2){
                o=false;
                cout<<i+1<<endl;
                break;
            }
        }
        if(o)cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1492
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int w=s.nextInt();
    int[] weights=new int[n];
    int[] value=new int[n];
    for(int i=0;i<n;i++){
      weights[i]=s.nextInt();
      value[i]=s.nextInt();
    }
    long[][] dp=new long[n+1][w+1];
    for(int i=1;i<=n;i++){
      for(int j=1;j<=w;j++){
        if(weights[i-1]>j){
          dp[i][j]=dp[i-1][j];
        }
        else{
          dp[i][j]=Math.max(dp[i-1][j],value[i-1]+dp[i-1][j-weights[i-1]]);
        }
      }
    }
    long max=Long.MIN_VALUE;
    for(int i=1;i<=w;i++)
      max=Math.max(dp[n][i],max);
      System.out.println(max);
    }
  }
  

Measured memory_bytes: 126544
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <iomanip>
#include <climits>
#include <string>
#include <sstream>
#include <numeric>
#include <stack>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string S;
	cin >> S;
	if (S[0] == S[1] && S[1] == S[2]) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  vector<int> ans;

  int n; cin >> n;
  vector<int> b(n); REP(i, n) cin >> b[i];

  while((int)(b.size())>0) {
    bool flg = false;
    for (int i=(int)(b.size())-1; i>=0; i--) {
      if (b[i] == i+1) {
        ans.push_back(i+1);
        b.erase(b.begin()+i);
        flg = true;
        break;
      }
    }
    if (!flg) break;
  }

  reverse(ans.begin(), ans.end());
  if ((int)(ans.size()) < n) {
    cout << -1 << endl;
  } else {
    for (auto& v : ans) {
      cout << v << endl;
    }
  }

}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <functional>

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	int x = n / k;
	cout << (x * k == n ? 0 : 1) << endl;
	return 0;	
}

Measured memory_bytes: 256
object Main extends App {
  val Array(n,k) = readLine.split(" ").map{_.toInt}
  val a = readLine.split(" ").map{_.toInt}
  val memo = new Array[Int](n+1)
  a.foreach{v => memo(v) = memo(v) + 1}
  
  val memo2 = memo.sorted.toList.filter{_ != 0}
  val dif = Array(memo2.length - k,0).max
  
  println(memo2.take(dif).sum)
}

Measured memory_bytes: 75752
/*************************************************************************

       Author:            palayutm
       Created Time :     Mon 10 Oct 2016 12:29:08 PM CST

       File Name:         c.cc
       Description:       new style, new life

 ************************************************************************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(int argc, const char *argv[])
{
  int w, h;
  cin >> w >> h;
  vector<pair<int, int> > vec;
  for (int i = 0; i < w; i ++) {
    int t;
    cin >> t;
    vec.push_back(make_pair(t, 0));
  }
  for (int i = 0; i < h; i ++) {
    int t;
    cin >> t;
    vec.push_back(make_pair(t, 1));
  }
  w ++, h ++;
  sort(vec.begin(), vec.end());
  ll ans = 0;
  for (auto x : vec) {
    if (x.second == 0 && w > 1) {
      w --;
      ans += (ll)x.first * h;
    } else if (x.second == 1 && h > 1) {
      h --;
      ans += (ll)x.first * w;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N,M,R;
  cin>>N>>M>>R;
  VL S(R);
  rep(i,R) cin>>S[i];
  VL A(M),B(M),C(M);
  rep(i,M) cin>>A[i]>>B[i]>>C[i];
  VVL X(N,VL(N));
  rep(i,N) rep(j,N) if(i!=j) X[i][j]=(1<<29);
  rep(i,M){
    X[A[i]-1][B[i]-1]=C[i];
    X[B[i]-1][A[i]-1]=C[i];
  }
  rep(k,N) rep(i,N) rep(j,N) X[i][j]=min(X[i][j],X[i][k]+X[k][j]);
  ll ans=(1<<29);
  sort(all(S));
  do{
    ll sum=0;
    rep(i,R-1) sum+=X[S[i]-1][S[i+1]-1];
    ans=min(ans,sum);
  }while(next_permutation(all(S)));
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import queue
h,w=map(int,input().split())
s=[input() for _ in range(h)]
INF=10**18
dx=[-1,0,1,0]
dy=[0,-1,0,1]
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':continue
    d=[[INF]*w for _ in range(h)]
    d[i][j]=0
    q=queue.Queue()
    q.put((i,j))
    while not q.empty():
      x,y=q.get()
      for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if 0<=nx<h and 0<=ny<w:
          if s[nx][ny]=='.' and d[nx][ny]==INF:
            q.put((nx,ny))
            d[nx][ny]=d[x][y]+1
            ans=max(ans,d[nx][ny])
print(ans)

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

int main(){
	int k,x;
	cin >> k >> x;
	for(int i = x - k + 1;i < x + k - 1;i++){
		cout << i << " ";
	}
	cout << x + k - 1 << endl;
	return 0;
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int a[n + 1];
    a[0] = 0;
    for(int i = 1;i < n + 1;i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    long long int ans = LLONG_MAX;
    for(int i = 1;i < n + 1;i++)
    {
        long long int temp = fabs(a[i] - (a[n] - a[i]));
        if(temp < ans)
        {
            ans = temp;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

struct UF
{
	vector<int> par; // 親
	// 初期化
	UF(int n):par(n) {
		for(int i = 0; i < n; i++){
			par[i] = i;
		}
	}
	// 木の根を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		// 木の高さが高い方を代表ノードにする
		par[x] = y;
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
};


int main()
{
	int n,m;
	cin >> n >> m;
	
	UF uf(n+m+10);
	
	REP(i,n)
	{
		int k;cin >> k;
		REP(j,k)
		{
			int l;cin >> l;
			uf.unite(i+1,n+l);
		}
	}
	
	set<int> s;
	
	for(int i = 1;i < n+1;i++)
	{
		//cout << uf.find(i) << endl;;
		s.insert(uf.find(i));
	}
	
	if(s.size() == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cassert>
//#define NDEBUG

/* 奇数行目 "#"始まり 1行出力 */
void OutOddLine(int w){
	using namespace std;
	for (int i = 1; i <= w; i++){	/* 横幅分の#.#. (左端: #) */
		switch(i % 2){
		case 0: cout << ".";		/* 左端から偶数個目 */
				break;
		case 1: cout << "#";		/* 左端から奇数個目 */
				break;
		}
	}
	cout << "\n";
}
/* 偶数行目 "."始まり 1行出力 */
void OutEvenLine(int w){
	using namespace std;
	for (int i = 1; i <= w; i++){	/* 横幅分の.#.# (左端: .) */
		switch(i % 2){
		case 0: cout << "#";		/* 左端から偶数個目 */
				break;		
		case 1: cout << ".";		/* 左端から奇数個目 */
				break;		
		}
	}
	cout << "\n";
}

int main(void){
	using namespace std;
	static const int INPUT_H_MIN = 1;	/* 前提は3以上だが、入力終了時は0 */
	static const int INPUT_H_MAX = 300;
	static const int INPUT_W_MIN = 1;	/* 前提は3以上だが、入力終了時は0 */
	static const int INPUT_W_MAX = 300;
	int input_h = 0;
	int input_w = 0;
	
	do{
		/* 高さHと横幅Wを入力 */
		cin >> input_h >> input_w;
		
		/* 入力値が、  両方0(入力終了時) or 前提条件 最大・最小の制限内の入力 */
		assert ((input_h == 0 && input_w == 0 ) || (INPUT_H_MIN <= input_h && input_h <= INPUT_H_MAX));
		assert ((input_h == 0 && input_w == 0 ) || (INPUT_W_MIN <= input_w && input_w <= INPUT_W_MAX));

		if(input_h != 0 && input_w != 0 ){
			/* 出力 */
			for (int i = 1; i <= input_h; i++){
				switch(i % 2){
				case 0: OutEvenLine(input_w);	/* 上から偶数行目 */
						break;
				case 1: OutOddLine(input_w);	/* 上から奇数行目 */
						break;
				}
			}
			cout << "\n";
		}
		else{
			break;
		}
	}while(input_h != 0 && input_w != 0);
	
	return 0;
}



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

int main(){
    int a,b;
    cin >> a >> b;
    
    if(a < b) cout << "a < b" << endl;
    if(a > b) cout << "a > b" << endl;
    if(a == b) cout << "a == b" << endl;
    
    return 0;
}


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

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100; b *= 100;

    int now_water, max_water=0, limit_water=f;
    int now_sugar, max_sugar=0, limit_sugar;
    double now_density, max_density=0, limit_density = (double)(e) / (double)(100+e);


    for(int i=0; a*i<=limit_water; i++) {
        for(int j=0; a*i+b*j<=limit_water; j++) {
            now_water = a*i + b*j;
            limit_sugar = f - now_water;

            for(int k=0; c*k<=limit_sugar; k++) {
                for(int l=0; c*k+d*l<=limit_sugar; l++) {
                    now_sugar = c*k + d*l;
                    if(now_water + now_sugar==0) continue;
                    now_density = (double)(now_sugar) / (double)(now_water + now_sugar);

                    if(now_density<=limit_density && max_density<=now_density) {
                        max_density = now_density;
                        max_water = now_water;
                        max_sugar = now_sugar;
                    }
                }
            }
        }
    }

    cout << max_water + max_sugar << ' ' << max_sugar << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int kind = 0;
	int cost = 0;
	cin >> kind >> cost;
	int num[200] = {0};
	int total = 0;
	int min = 100000;
	for ( int i = 0; i < kind; i++ ) {
		cin >> num[i];
		total += num[i];
		if ( min > num[i] ) {
			min = num[i];
		} // if
		
	} // for
	
	cost -= total;
	cout << cost/min + kind;
} // int main()

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	map<pair<int, int>, int> K;
	pairs(C)
	fx(N) {
		int a, b, h;
		cin >> a >> b >> h;
		K[make_pair(a, b)] = h;
		pb(C, make_pair(a, b))
	}


		fyg(101,0) {
			fzg(101,0) {

				int H;
				fx(N) {
					if (K[C.at(x)] != 0) {
						H = abs(y - C.at(x).first) + abs(z - C.at(x).second) + K[C.at(x)];
						break;
					}

				}
				bool flag = true;
				fx(N) {
					if (K[C.at(x)]!=0) {
						if (abs(y - C.at(x).first) + abs(z - C.at(x).second) + K[C.at(x)]!=H) {
							flag = false;
							break;
						}
					}
				}

				if (flag) {
					fx(N) {
						if (max(H- abs(y - C.at(x).first) - abs(z - C.at(x).second),0 )!= K[C.at(x)]) {
							flag = false;
							break;
						}
					}

					if (flag) {
						cout << y << ' ' << z << ' ' << H << endl;
						y = 100; z = 100;
					}

				}

			}
		}

	

    return 0;
}



Measured memory_bytes: 256
#
# abc069 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 4"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 2"""
        output = """1"""
        self.assertIO(input, output)


def resolve():
    n, m = map(int, input().split())
    print((n-1)*(m-1))


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll mod=1000000007; // 998244353 = (119<<23)+1
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// head
const int N=15;
vector<vi> price(N,vi(N));
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m,x;
	cin>>n>>m>>x;
	rep(i,0,n) {
		cin>>price[i][0];
		rep(j,1,m+1) cin>>price[i][j];
	}
	int ans=INT_MAX;
	rep(i,0,(1<<n)) {
		//cout<<i<<'\n';
		bool ok=true;
		int tot=0;
		rep(j,0,n) if((i&(1<<j))) tot+=price[j][0];
		rep(j,1,m+1) {
			int sum=0;
			rep(k,0,n) if((i&(1<<k))) {
				sum+=price[k][j];
			}
			//cout<<sum<<' ';
			if(sum<x) {
				ok=false;
				//break;
			}
		}
		if(ok) {
			//cout<<i<<' '<<tot<<'\n';;
			ans=min(ans,tot);
		}
	}
	if(ans==INT_MAX) cout<<-1;
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 3656
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, *a = map(int, read().split())
memo = 1
cnt = 0
mod = 10 ** 9 + 7
for aa in a:
    q = memo * aa // gcd(memo, aa)
    cnt *= q // memo
    memo = q
    cnt += q // aa
print(cnt % mod)


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

using namespace std;

priority_queue<int> que;
int ans = 0;

int main()
{
    int N, tmp;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        que.push(tmp);
    }
    tmp = que.top();
    que.pop();
    ans++;
    while(!que.empty()) {
        if (que.top() != tmp){
            tmp = que.top();
            ans++;
        }
        que.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
	ios_base::sync_with_stdio(0);
	int a,b,x,n,T,cas=0;
	cin>>x>>n;
	int s=0;
	for(int i=0;i<n;++i) {
		cin>>a;
		s+=a;
	}
	if(s>=x) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

tower_height = 0
tower_height_list = []
for i in range(1,999+1):
    tower_height += i
    tower_height_list.append(tower_height)
    i += 1

for i in range(len(tower_height_list)):
    if tower_height_list[i] - b == tower_height_list[i-1] - a:
        print(tower_height_list[i] - b)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int L, K;
Int mem[300][2], used[300][2];
Int dfs(Int sum, Int dark){
  if(sum > L) return 0;
  if(used[sum][dark]++) return mem[sum][dark];
  Int res = dark;
  if(dark) res += dfs(sum + 1, 0);
  else {
    res += dfs(sum + 1, 1);
    res += dfs(sum + K, 1);
  }
  return mem[sum][dark] = res; 
}
signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>L>>K;
  Int ans = dfs(0, 0);
  cout<<ans<<endl;
  return 0;
}



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

int main(){
	int n, m;
	cin >> n >> m;
	vector<int>a(m), b(m);
	for (int i = 0;i < m;i++) {
		cin >> a[i] >> b[i];
	}

	int ans = 0;
	for (int i = 0;i < m;i++) {
		bool edge[55][55];
		for (int j = 1;j <= n;j++) {
			for (int k = 1;k <= n;k++) {
				edge[j][k] = false;
			}
		}
		for (int j = 0;j < m;j++) {
			if (j == i) {
				continue;
			}
			edge[a[j]][b[j]] = true;
			edge[b[j]][a[j]] = true;
		}
		bool visited[55];
		for (int j = 1;j <= n;j++) {
			visited[j] = false;
		}
		queue<int>q;
		visited[1] = true;
		q.push(1);
		while (!q.empty()) {
			int qf = q.front();q.pop();
			for (int j = 1;j <= n;j++) {
				if (edge[qf][j] && !visited[j]) {
					visited[j] = true;
					q.push(j);
				}
			}
		}
		bool b = true;
		for (int j = 1;j <= n;j++) {
			b = b && visited[j];
		}
		if (!b) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type Restaurant struct {
	index     int
	locataion string
	value     int
}

type rest []Restaurant

func (r rest) Len() int {
	return len(r)
}
func (r rest) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func (r rest) Less(i, j int) bool {
	if r[i].locataion == r[j].locataion {
		return r[i].value > r[j].value
	}
	return r[i].locataion < r[j].locataion
}
func main() {
	var n int
	fmt.Scan(&n)

	list := make(rest, n)
	for i := 0; i < n; i++ {
		list[i].index = i + 1
		fmt.Scan(&list[i].locataion, &list[i].value)
	}

	sort.Sort(list)
	for i := range list {
		fmt.Println(list[i].index)
	}

}


Measured memory_bytes: 512