akhauriyash/Code-Regression huggingface dataset:
import random

def calc_score(D, C, S, T):
    score = 0
    last = [0]*26
    for d in range(D):
        t = T[d] - 1
        score += S[d][t]
        last[t] = d + 1
        for i in range(26):
            score -= C[i]*(d + 1 - last[i])
    return score

def main():
    D = int(input())
    C = list(map(int, input().split()))
    S = []
    for i in range(D):
        S.append(list(map(int, input().split())))

    sorted_scores = []
    for i in range(D):
        scores = [(j, S[i][j]) for j in range(26)]
        sorted_scores.append(sorted(scores, key=lambda x: x[1], reverse=True))
    # print(sorted_scores)
    sorted_c = []
    sorted_c = [(i, C[i]) for i in range(26)]
    sorted_c.sort(key=lambda x: x[1], reverse=True)
    # print(sorted_c)
    last = [0]*26
    ans = []
    for d in range(D):
        score = -100*365*365
        t = 0
        for i in range(26):
            tmp = S[d][i]
            for j in range(26):
                if i != j:
                    tmp -= C[j]*(d + 1 - last[j])
            if tmp > score:
                score = tmp
                t = i + 1
        last[t - 1] = d + 1
        ans.append(t)
    score = calc_score(D, C, S, ans)

    # try to reduce penalty
    for i in range((10**3)//2):
        d = random.randint(0, D - 1)
        t = random.randint(0, 12)
        org_t = ans[d]
        ans[d] = sorted_c[t][0] + 1
        s = calc_score(D, C, S, ans)
        if s <= score:
            ans[d] = org_t
        else:
            score = s

    # try to increase score
    for i in range((10**3)//2):
        d = random.randint(0, D - 1)
        t = random.randint(0, 12)
        org_t = ans[d]
        ans[d] = sorted_scores[d][t][0] + 1
        s = calc_score(D, C, S, ans)
        if s <= score:
            ans[d] = org_t
        else:
            score = s
    print('\n'.join(map(str, ans)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 10412
#include <bits/stdc++.h>
using namespace std;
int n,d,ans;
int a[29];
int main(){
    cin>>n>>d;
    for(int i=d;i<n;i+=(d*2+1)){
        for(int j=d;j<=i+d;j++) a[j] = 1;
        for(int j=d;j>=i-d;j--) a[j] = 1;
        ans++;
    }
    for(int i=0;i<n;i++){
        if(a[i] == 1) continue;
        ans++; break;
    }
    cout<<ans<<endl;
}       


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから

void solve(){
  int n,m;
  cin>>n>>m;
  vector<int>cnt(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    cnt[a]++;cnt[b]++;
  }
  rep(i,n)cout<<cnt[i]<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int k,i,j,c=0;
  
  int s[10000];
  scanf("%d",&k);

    for(i=0;i<k;i++){
      scanf("%d",&s[i]);

    }
  for(i=0;i<k;i++){
    
    for(j=2;j<=sqrt(s[i]);j++){
      if(s[i]%j == 0){c++; break;} 
    }
  }
  printf("%d\n",k-c);
  return 0;
}
  



Measured memory_bytes: 2072
//05
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>

using namespace std;

int main(){
  for(int a,b,n;cin>>a>>b>>n;){
    stringstream ss;
    ss<<fixed<<setprecision(n+1)<<a*1./b;
    int d=ss.str().find('.');
    int ans=0;
    for(int i=1;i<=n;i++){
      ans+=ss.str()[d+i]-'0';
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#define int long long

int all(int N){
	return ((int)1 << (N + 1)) - 1;
}

int solve(int N, int X){
	if(N == 0){
		if(X == 0){
			return 0;
		}
		else{
			return 1;
		}
	}
	else{
		if(X <= 1){
			return 0;
		}
		else if(X <= ((int)1 << (N + 1)) - 2){
			return solve(N - 1, X - 1);
		}
		else if(X == ((int)1 << (N + 1)) - 1){
			return all(N - 1) + 1;
		}
		else if(X <= ((int)1 << (N + 2)) - 4){
			return all(N - 1) + 1 + solve(N - 1, X - (((int)1 << (N + 1)) - 1));
		}
		else{
			return 2 * all(N - 1) + 1;
		}
	}
}

signed main(){
	int N, X, i;
	scanf("%lld%lld", &N, &X);
	printf("%lld\n", solve(N, X));
	return 0;
}

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

using namespace std;

struct point {
    int left, right, block, id;
};

bool cmp(const point &lhs, const point &rhs) {
    if (lhs.block < rhs.block)
        return true;
    else if (lhs.block > rhs.block)
        return false;
    else
        return lhs.right < rhs.right;
}

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

    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);

    int block_size = sqrt(n);

    vector<point> query(q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d", &query[i].left, &query[i].right);
        query[i].left--, query[i].right--;
        query[i].block = query[i].left / block_size;
        query[i].id = i;
    }

    sort(query.begin(), query.end(), cmp);

    vector<int> solution(q);
    vector<int> hash(1000100);

    int left = 0, right = 0, answer = 1;
    hash[A[0]] = 1;

    for (const point &task : query) {
        while (left < task.left) {
            hash[A[left]]--;
            answer -= (hash[A[left]] == 0);
            left++;
        }
        while (left > task.left) {
            left--;
            hash[A[left]]++;
            answer += (hash[A[left]] == 1);
        }
        while (right < task.right) {
            right++;
            hash[A[right]]++;
            answer += (hash[A[right]] == 1);
        }
        while (right > task.right) {
            hash[A[right]]--;
            answer -= (hash[A[right]] == 0);
            right--;
        }
        solution[task.id] = answer;
    }

    for (int answer : solution)
        printf("%d\n", answer);

    return 0;
}

Measured memory_bytes: 19292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int n, m, x;
  cin >> n >> m >> x;
  vec1 a(m);
  for(int i = 0; i < m; i++) cin >> a.at(i);

  a.push_back(x);
  sort(a.begin(),a.end());
  int c = 0;
  for(int i = 0; i < m+1; i++) {
    if(a.at(i) > x) {
      c++;
    }
  }
  int t = m - c;
  int ans = min(c,t);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
long long int dp[1000005][2];
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	string s;
 
	cin >> s;
 	
	for(int i=0;i<1000005;i++)
	{
		dp[i][0] = 1e18;
		dp[i][1] = 1e18;
	}

	dp[0][0] = s[0] - '0';
	dp[0][1] = 10 - (s[0] - '0');

	for(int i=1;i<s.length();i++)
	{
		dp[i][0] = min(dp[i-1][0] + (s[i]-'0'),dp[i-1][1] + (s[i]-'0') + 1);
		dp[i][1] = min(dp[i-1][0] + (10 - (s[i]-'0')),dp[i-1][1] + (10 - (s[i]-'0'+1)));
	}
 
	cout << min(dp[s.length()-1][0],dp[s.length()-1][1] + 1) << '\n';
 
	return 0;
}

Measured memory_bytes: 19856
#include <iostream>
using namespace std;
bool ap[30];
int main()
{
    int i;
    char ch;
    while(1)
    {
        ch=cin.get();
        if(ch=='\n')
            break;
        ap[ch-'a']=1;
    }
    for(i=0;i<26;i++)
        if(!ap[i])
        {
            cout<<char{i+'a'};
            return 0;
        }
    cout<<"None";
    return 0;
}


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

int main(void){
    int N;
    double x = 0, ans;
    cin >> N;

    int A[N];
    for(int i=0;i<N;i++){cin >> A[i];}

    for(int i=0;i<N;i++){
        x = x + 1.0/A[i];
    }

    ans = 1/x;
    printf("%lf", ans);

}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,C,K,fir,A[110000];
int main(){
	scanf("%d%d%d",&n,&C,&K);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	fir=A[1]; int pre=1,ans=1;
	for (int i=2;i<=n;i++){
		int k=A[i];
		if (pre+C-1<i||k-fir>K){
			ans++; pre=i; fir=A[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int H,W,i,j;
    while(1){
    scanf("%d %d", &H, &W);
    if ( H == 0 && W == 0 ) break;
    for ( i = 0; i < H; i++ ){
        for ( j = 0; j < W; j++ ){
            if(i==0 || j==0 || j==W-1 ||i==H-1){
                printf("#");
            } else {
                printf(".");
            }
        }
        printf("\n");
    }
     printf("\n");
}
    return 0;
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,x,y;
  cin>>n;
  vector<pair<int,int>> v(n);
  int h[n];
  rep(i,0,n){
    cin>>v[i].f>>v[i].s>>h[i];
  }

  rep(x,0,101){
    rep(y,0,101){
      int flag=0,H=-1;
      vector<int> v1;
      rep(i,0,n){
        if(h[i]>0){
          int h1= h[i]+abs(v[i].f-x)+abs(v[i].s-y);
          if(H==-1) H=h1;
          else if(H!=h1){
            flag=1;
            break;
          }
        }
        else{
          int h1= abs(v[i].f-x)+abs(v[i].s-y);
          v1.pb(h1);
        }
      }
      rep(i,0,v1.size()) if(H>v1[i]) flag=1;
      if(flag==0 && H>=1){
        cout<<x<<" "<<y<<" "<<H<<endl;
        return;
      }
    }
  }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, rt;
pair<long long, int> d[100009];
set<pair<long long, int> > st;
vector<pair<int, int> > vec;
map<long long, int> mp;
vector<int> vec2[100009];

long long fun(int c)
{
	if (d[c].se == 1) return 1;
	long long retval = 0;
	for (int i = 0; i < (int)vec2[c].size(); i++) {
		retval += fun(vec2[c][i]);
	}
	if (c == rt) return retval;
	else return retval + d[c].se;
}

bool gun(int c, long long cd)
{
	if (cd != d[c].fi) return false;
	for (int i = 0; i < (int)vec2[c].size(); i++) {
		if (!gun(vec2[c][i], d[c].fi + n - 2*d[vec2[c][i]].se)) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> d[i].fi;
		d[i].se = 1;
		st.insert({ -d[i].fi, i });
		mp[d[i].fi] = i;
	}
	while (1) {
		auto x = st.begin();
		int cur = (*x).se;
		st.erase(x);
		long long tmp = d[cur].fi - n + 2 * d[cur].se;
		if (mp.count(tmp) == 0) {
			cout << -1 << E;
			return 0;
		}
		int to = mp[tmp];
		if (to == cur) {
			cout << -1 << E;
			return 0;
		}
		d[to].se += d[cur].se;
		vec.pb(make_pair(to, cur));
		if (vec.size() == n - 1) {
			x = st.begin();
			rt = (*x).se;
			break;
		}
	}
	for (int i = 0; i < (int)vec.size(); i++) {
		vec2[vec[i].fi].pb(vec[i].se);
	}
	if (!gun(rt, fun(rt))) {
		cout << -1 << E;
	}
	else {
		for (int i = 0; i < n - 1; i++) {
			cout << vec[i].fi << " " << vec[i].se << E;
		}
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 21108
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<pair<ll,ll> > p(n);
	for(int i = 0; i < n; i++){
		cin>>p[i].first>>p[i].second;
	}
	sort(all(p));
	ll ans=0;
	ll cnt=0;
	for(int i = 0; i < n; i++){
		if(m-cnt>=p[i].second){
			ans+=p[i].first*p[i].second;
			cnt+=p[i].second;
		}else{
			ans+=(m-cnt)*p[i].first;
			cnt+=p[i].second;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int x;
  cin >> x;
    if ((x % 10 == 0)) {
    cout << "pon" << endl;
   }
    else if ((x % 10 == 1)) {
    cout << "pon" << endl;
   }
    else if ((x % 10 == 2)) {
    cout << "hon" << endl;
   }
    else if ((x % 10 == 3)) {
    cout << "bon" << endl;
   } 
    else if ((x % 10 == 4)) {
    cout << "hon" << endl;
   }
    else if ((x % 10 == 5)) {
    cout << "hon" << endl;
   }
    else if ((x % 10 == 6)) {
    cout << "pon" << endl;
   }
    else if ((x % 10 == 7)) {
    cout << "hon" << endl;
   }
    else if ((x % 10 == 8)) {
    cout << "pon" << endl;
   }
    else if ((x % 10 == 9)) {
    cout << "hon" << endl;
   }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

signed main() {
  int N; cin  >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> Input[i];
    ans += Input[i];
  }
  cout << ans - (*max_element(Input, Input+N)) / 2 << endl;
}


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

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

    string a, b, c;
    a = "Sunny";
    b = "Cloudy";
    c = "Rainy";

    if(s == a){
        cout << b << endl;
    }else if(s == b){
        cout << c << endl;
    }else{
        cout << a << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	char x;
	cin >> x;
	if (x >= 97) {
		cout << "a" << endl;
	}
	else {
		cout << "A" << endl;
	}
	return 0;
}


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

int main() {
	int N;
  
  cin >> N;
  
  vector<string>S(N);
  
  for(int i = 0 ; i < N ; i++){
  	cin >> S.at(i);
  }
  
  
  vector<int>C(4);
  
  for(int i = 0 ; i < 4 ; i++){
 	C.at(i)= 0; 
  }
  
  for(int i = 0 ; i < N ; i++){
  	if(S.at(i)=="AC"){
    	C.at(0)++;
    }
  	if(S.at(i)=="WA"){
    	C.at(1)++;
    }
  	if(S.at(i)=="TLE"){
    	C.at(2)++;
    }
  	if(S.at(i)=="RE"){
    	C.at(3)++;
    }
  }
  
  cout << "AC x " << C.at(0) << endl;
  cout << "WA x " << C.at(1) << endl;
  cout << "TLE x " << C.at(2) << endl;
  cout << "RE x " << C.at(3) << endl;  
  
  return 0;
}	


Measured memory_bytes: 6424
def solve():
  N, M = map(int, input().split())
  ans = [0]*N
  A = [0]*N
  B = [0]*N
  for i in range(N):
    A[i],B[i] = map(int, input().split())
  X = [0]*M
  Y = [0]*M
  for i in range(M):
    X[i],Y[i] = map(int, input().split())
  for i in range(N):
    ind = -1
    d_min = float('inf')
    for j in range(M):
      d = abs(A[i]-X[j])+abs(B[i]-Y[j])
      if d<d_min:
        d_min = d
        ind = j+1
    ans[i] = ind
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 9124
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
S = list(input())

ans = 0

for l2 in range(1, N):
    same_len = 0
    for i in range(N):
        if N - 1 < l2 + i:
            continue

        if S[i] == S[l2 + i]:
            same_len += 1
        else:
            same_len = min(l2, same_len)
            ans = max(ans, same_len)
            same_len = 0
    same_len = min(l2, same_len)
    ans = max(same_len, ans)

print(ans)


Measured memory_bytes: 42716
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld long double
#define pp pair<ll,pair<ll,ll> >
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree<ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
ll powMod( ll base , ll expo )
{
    ll ans = 1 ;
    while( expo > 0 )
    {
        if( expo & 1 )
            ans = ( ans * base ) % hell ;
        expo>>=1;
        base = ( base * base )%hell;
    }
    return ans ;
}
ll findroot( ll x )
{
    ll lo = 1 , hi = hell , mid ;
    while( hi - lo > 1 )
    {
        mid = ( lo + hi ) / 2 ;
        if( mid*mid > x )
            hi = mid ;
        else
            lo = mid ;
    }
    return lo ;
}
ll calc( ll n )
{
    ll x = findroot( n ) , y ;
    y = n - x * x ;
    ll a1 , a2 , ans = 1 ;
    a1 = powMod( 3 , x ) ;
    a2 = powMod( a1 , x ) ;
    if( y < hell )
    {   
        ans = ( ans * a2 ) % hell ;
        ans = ( ans * powMod( 3 , y ) ) % hell ;
        return ans ;
    }
    else
    {
        ans = ( ans * a2 ) % hell ;
        ans = ( ans * calc(y) ) % hell ;
        return ans ;
    }
}
void solve() 
{ 
    ll a , b , k ;
    cin >> a >> b >> k ;
    vector<ll> v ;
    rep( i , 1 , 105 )
    {
        if( a % i == 0 && b % i == 0 )
            v.pb(i);
    }
    cout << v[sz(v)-k] ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

typedef tuple<int,int> point;
map<point,int> fox;

const int nmax=100010;
int x[nmax],y[nmax];

int main(void){
	int n;
	cin >> n;
	rep(i,n){
		int w;
		cin >> x[i] >> y[i] >> w;
		fox[point{x[i],y[i]}]=w;
	}
	int ans=0;
	rep(i,n){
		ans=max(ans,fox[point{x[i],y[i]}]+fox[point{x[i]+1,y[i]}]+fox[point{x[i],y[i]+1}]+fox[point{x[i]+1,y[i]+1}]);
		ans=max(ans,fox[point{x[i],y[i]}]+fox[point{x[i]+1,y[i]}]+fox[point{x[i],y[i]-1}]+fox[point{x[i]+1,y[i]-1}]);
		ans=max(ans,fox[point{x[i],y[i]}]+fox[point{x[i]-1,y[i]}]+fox[point{x[i],y[i]+1}]+fox[point{x[i]-1,y[i]+1}]);
		ans=max(ans,fox[point{x[i],y[i]}]+fox[point{x[i]-1,y[i]}]+fox[point{x[i],y[i]-1}]+fox[point{x[i]-1,y[i]-1}]);
	}
	cout << ans << " / 1" << endl;
	return 0;
}

Measured memory_bytes: 58232
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int cnt = 0;
    rep(i,n)
        if(h[i]>=k) ++cnt;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using state = string::const_iterator;

int num(state &cur);
int factor(state &cur);
int muldiv(state &cur);
int addsub(state &cur);
int expr(state &cur);

int factor(state &cur) {
    if(isdigit(*cur)) return num(cur);
    cur++;
    int ans = addsub(cur);
    cur++;
    return ans;
}

int num(state &cur) {
    int ans = *cur -'0';
    while(isdigit(*++cur)) ans = ans*10 + (*cur-'0');
    return ans;
}

int muldiv(state &cur) {
    int ans = factor(cur);
    while(true){
        if(*cur == '*'){
            cur++;
            ans *= factor(cur);
        }else if(*cur == '/'){
            cur++;
            ans /= factor(cur);
        }else break;
    }
    return ans;
}

int addsub(state &cur){
    int ans = muldiv(cur);
    while(true){
        if(*cur == '+'){
            cur++;
            ans += muldiv(cur);
        }else if(*cur == '-'){
            cur++;
            ans -= muldiv(cur);
        }else break;
    }
    return ans;
}

int expr(state &cur){
    return addsub(cur);
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        state cur = s.begin();
        cout << expr(cur) << "\n";
    }
    return 0;
}



Measured memory_bytes: 3120
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define MAX 1000100
#define N 30

int memo[MAX], n, m, goal[N], ori[N], goalstate;
queue<int> que;

inline int encode(int arr[]){
  int res = 0;
  for(int i = 0; i < n; i++) res |= (arr[i] << i);
  return res;
}

inline void decode(int state, int res[]){ for(int i = 0; i < n; i++) res[i] = (state >> i) & 1; }

inline int fill_bit(int arr[], int start){
  int sum = 0, res = 0;
  for(int i = 0; i < m; i++){
    if(start) for(int j = 0; j < arr[i]; j++) res |= 1 << (sum + j);
    sum += arr[i];
    start ^= 1;
  }
  return res;
}

int main(){
  while(scanf("%d%d", &n, &m) == 2){
    memset(memo, -1, sizeof(memo));
    
    for(int i = 0; i < n; i++) scanf("%d", ori + i);
    for(int i = 0; i < m; i++) scanf("%d", goal + i);
    
    int state = encode(ori), bits[N];
    que.push(state);
    memo[state] = 0;
    while(!que.empty()){
      state = que.front(); que.pop();
      decode(state, bits);
      
      for(int i = 0; i < n - 1; i++){
        swap(bits[i], bits[i + 1]);
        int nxtstate = encode(bits);
        if(memo[nxtstate] == -1){
          memo[nxtstate] = memo[state] + 1;
          que.push(nxtstate);
        }
        swap(bits[i], bits[i + 1]);
      }
    }
    
    int goal1, goal2;
    goal1 = fill_bit(goal, 0);
    goal2 = fill_bit(goal, 1);
    if(memo[goal1] == -1) printf("%d\n", memo[goal2]);
    else if(memo[goal2] == -1) printf("%d\n", memo[goal1]);
    else printf("%d\n", min(memo[goal1], memo[goal2]));
  }
  return 0;
}

Measured memory_bytes: 4968
package main

import "fmt"

func main() {
	var A, B, C, K int
	fmt.Scan(&A, &B, &C, &K)
	ans := 0
	if A <= K {
		ans += A * 1
		K = K - A
		if B <= K {
			K = K - B
			if C <= K {
				ans += C * (-1)
				fmt.Println(ans)
			} else {
				ans += K * (-1)
				fmt.Println(ans)
			}
		} else {
			fmt.Println(ans)
		}
	} else {
		ans += K * 1
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1752
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    long long N;
    vector<long long>A;
    long long sum = 0;
    
    cin >> N;
    
    for ( int i = 0; i < 3*N; i++ ) {
        long long a;
        cin >> a;
        A.push_back( a );
    }
    
    sort( A.begin(), A.end(), greater<long long>() );
    
    for ( int i = 0,j = 0; i < N; i++,j+=2 ) {
        sum += A[j+1];
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(string S){
	ll res = 0;
	FOR(i, 1, S.size()) {
		if (S[i-1] == S[i]) {
			res++;
			if (S[i]=='1') S[i] = '0';
			else S[i] = '1';
		}
	}
	cout << res << "\n";
}

int main(){
    string S;
	cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



using namespace std;



int main() {
  ll L; cin>>L;
  double V = 0.0;
  double a = double(L)/3.0;
  V = a*a*a;
  printf("%lf\n",V);




  return 0;
}

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

// s ????????????????????? t ?????¨??? u ????????????
// (find ????????????????????????????????????)
string replace_user(string s, string t, string u) {
    reverse(t.begin(), t.end());
    size_t N = s.length(), M = t.length();
    if(N < M) return s;

    string ret = "", temp = "";
    for(size_t i=0; i<N; i++) {
        if(temp.length() == M) {
            ret += temp.back();
            temp.pop_back();
        }
        temp = s[i] + temp;
        if(temp == t) {
            ret += u;
            temp = "";
        }
    }
    reverse(temp.begin(), temp.end());
    s = ret + temp;
    return s;
}

int N, ans = 1 << 30;
vector<string> alpha, beta;
string start, goal;
bool answerFlag = false;

void solve(string cur, int cnt=0) {
    if(cur.length() > goal.length()) return;
    if(cur == goal) {
        answerFlag = true;
        ans = min(ans, cnt);
    }
    else {
        for(int i=0; i<N; i++) {
            string nxt = replace_user(cur, alpha[i], beta[i]);
            if(cur == nxt) continue;
            solve(nxt, cnt + 1);
        }
    }
}

int main() {
    while(cin >> N, N) {
        // init
        answerFlag = false;
        ans = 1 << 30;
        alpha.resize(N);
        beta.resize(N);

        // input
        for(int i=0; i<N; i++) {
            cin >> alpha[i] >> beta[i];
        }
        cin >> start >> goal;

        // solve
        solve(start);
        if(!answerFlag) cout << -1 << endl;
        else cout << ans << endl;
    }
}

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

int main(int argc, char *argv[]) {
	int num_of_route = 0;
	int time_limit = 0;

	std::cin >> num_of_route;
	std::cin >> time_limit;

	int cost = 0;
	int time = 0;
	int min_cost = INT_MAX;
	bool found(false);
	for (int i = 0; i < num_of_route; i++) {
		std::cin >> cost;
		std::cin >> time;
		if (time <= time_limit && cost <= min_cost) {
			min_cost = cost;
			found = true;
		}
	}
	
	if (found) {
		std::cout << min_cost << std::endl;
	} else {
		std::cout << "TLE" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    
struct union_find{
  vector<int>r;
  union_find(int n):r(n,-1){
  }
  int root(int a){
    if(r[a]<0){
      return a;
    }else{
      return root(r[a]);
    }
  }
  void add(int a,int b){
    int ra=root(a);
    int rb=root(b);
    if(r[ra]>r[rb]){
      swap(ra,rb);
    }else if(ra==rb){
      return;
    }
    r[ra]+=r[rb];
    r[rb]=ra;
  }
  int sum(){
    int s=0;
    for(int i=0;i<r.size();i++){
      if(r[i]<0){
        s++;
      }
    }
    return s;
  }
};
      

int main(){
  int n,m;
  cin>>n>>m;
  union_find u(n);
  int a,b;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;
    b--;
    u.add(a,b);
  }
  cout<<u.sum()-1<<endl;
}

Measured memory_bytes: 3788
import sys
input = sys.stdin.readline
n, k, q = map(int, input().split())
def judge():
    val = {}
    for _ in range(q):
        a = int(input())
        val[a-1] = val.get(a-1,0) + 1
    #print(val)
    for i in range(n):
        if val.get(i,k-q) + (k - q) > 0:
            print('Yes')
        else:
            print('No')
if k > q:
    print(*['Yes' for _ in range(n)])
else:
    ans = judge()


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

int main(){
    int all;
    int total;
    int prace;
    while(1){
        total = 0;
        cin >> all;
        if(all == 0) break;
        for(int i=0;i<9;i++){
            cin >> prace;
            total += prace;
        }
        cout << all - total << endl;
    }
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
  x = min(a[i],b[i])
  b[i] -= x
  ans += x
  y = min(a[i+1],b[i])
  ans += y
  a[i+1] -= y
print(ans)

Measured memory_bytes: 24192
n=int(input())
a=list(map(int,input().split()))
tmp=0
for i in range(len(a)):
  tmp=a[i]
  if tmp%2==0:
    if tmp%3!=0:
      if tmp%5!=0:
        print("DENIED")
        break
  if i==n-1:
    print("APPROVED")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
using namespace std; typedef long long ll;
typedef pair<int,int> P; const int INF = 1e9+1;

int main() {
  int h,w,k; cin>>h>>w>>k;
  int an=1e9;
  string s[h]; for(int i=0;i<h;i++) cin>>s[i];
  for(int i=0;i<(1<<(h-1));i++) {
    int p[h]; p[0]=0; int sm=0, ss=1;
    for(int j=0;j<h-1;j++) {
      if (i & (1<<j)) p[j+1]=p[j]+1, sm++, ss++;
      else p[j+1] = p[j];
    }
    //for(int j=0;j<h;j++) cout<<p[j]; cout<<endl;
    //int u[ss][w], u2[ss][w];

    int r[h]; fill(r,r+h,0);
    for(int j=0;j<w;j++) {
      //cout<<j<<" "<<w<<" ";
      //cout<<j<<" ";
      int o[h]; fill(o,o+h,0);
      //cout<<j<<" ";
      for(int m=0;m<h;m++) {
        o[p[m]] += s[m][j] == '1';
      }
      //for(int m=0;m<ss&&i==2;m++) u[m][j] = r[m];
      //for(int m=0;m<ss&&i==2;m++) u2[m][j] = o[m];
      //cout<<j<<" ";
      bool cut=false;
      for(int m=0;m<ss;m++) {
        if (r[m] + o[m] > k) cut=true;
        //if (r[m] + o[m] > k) r[m]=o[m], sm++;
        //else r[m]+=o[m];
        //if (o[m] > k) sm=1e9;
      }
      if (cut) {
        sm++;
        for(int m=0;m<ss;m++) r[m]=o[m];
      } else {
        for(int m=0;m<ss;m++) r[m]+=o[m];
      }
      for(int m=0;m<ss;m++)if (o[m] > k) sm=1e9;
      //cout<<j<<" "<<w<<" ";
    }
    /*
    if (i == 2){
      for(int i=0;i<ss;i++) {
        for(int j=0;j<w;j++) cout<<u[i][j]; cout<<endl;
      } cout<<endl;
      for(int i=0;i<ss;i++) {
        for(int j=0;j<w;j++) cout<<u2[i][j]; cout<<endl;
      }
    }*/
    //for(int j=0;j<h;j++) cout<<r[p[j]]<<" ";
    //cout<<sm<<endl;
    an=min(an,sm);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles
"""
need to consider the case that ticket is not enough to lower everything
"""
N = gi()
cs = []
cs.append(1)
b6 = 6
while (b6 <= 1e5):
    cs.append(b6)
    b6 *= 6
b9 = 9
while (b9 <= 1e5):
    cs.append(b9)
    b9 *= 9
ans = [N] * (N + 1)
ans[0] = 0

for i in range(1, N + 1):
    for v in cs:
        if i >= v:
            ans[i] = min(ans[i], ans[i - v] + 1)

print(ans[N])


Measured memory_bytes: 14932
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    s = input()
    for i in range(3):
        if s[i] == s[i + 1]:
            flag = 'Bad'
            break
        else:
            flag = 'Good'
            

    print(flag)
        
        
    

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 6096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ar[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << ar[k-1] << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int solve(int n, string s)
{
  vector<int> wests(n, 0), easts(n, 0);
  for (int i = 1; i < n; ++i) {
    wests[i] = wests[i - 1] + (s[i - 1] == 'W');
  }
  for (int i = n - 2; i >= 0; --i) {
    easts[i] = easts[i + 1] + (s[i + 1] == 'E');
  }
  int ret = INF;
  for (int i = 0; i < n; ++i) {
    ret = min(ret, wests[i] + easts[i]);
  }
  return ret;
}

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = solve(n, s);
  printf("%d\n", ans);
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(a-x)<abs(b-x))cout<<"A"<<endl;
    else cout<<"B"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, k;
    cin >> n >> k;
    cin.ignore();
    string str;
    cin >> str;
    int i = 0, j = 0, ans = 0;
    while (j < n) {
        while (j < n && str[j] == '1')  j++;
        ans = max(ans, j - i);
        while (j < n && str[j] == '0')  j++;
        --k;
        if (k < 0) {
            while (i < n && str[i] == '1')  i++;
            while (i < n && str[i] == '0')  i++;
        }
        ans = max(ans, j - i);
    }
    cout << ans << endl;
}


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

using namespace std;

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

	vector< vector<char> > s(n, vector<char>(n));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> s[i][j];
		}
	}

	long long int ans = 0;

	for (int a = 0; a < n; a++) {
		bool hh = true;
		int b = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int ia = (i + a) % n;
				int ja = (j + a) % n;
				int ib = (i + b) % n;
				int jb = (j + b) % n;
				if (s[ia][jb] != s[ja][ib]) {
					hh = false;
				}
			}
		}
		if (hh) {
			ans += n - a;
		}
	}

	for (int b = 1; b < n; b++) {
		bool hh = true;
		int a = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int ia = (i + a) % n;
				int ja = (j + a) % n;
				int ib = (i + b) % n;
				int jb = (j + b) % n;
				if (s[ia][jb] != s[ja][ib]) {
					hh = false;
				}
			}
		}
		if (hh) {
			ans += n - b;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	string s;	cin >> s;
  	int cnt = 0;
  	rep(i,s.size()/2){
    	if(s.at(i) != s.at(s.size()-1-i)) cnt++;
    }
  	cout << cnt << endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

void solve()
{
  int n, c, c_input;
  cin >> n >> c;
  vector< vector<int> > cost(c, vector<int>(c));
  vector< vector<int> > grid(3, vector<int>(c, 0));

  for(int i = 0; i < c; ++i)
  {
    for(int j = 0; j < c; ++j)
    {
      cin >> cost[i][j];
    }
  }

  for(int i = 1; i <= n; ++i)
  {
    for(int j = 1; j <= n; ++j)
    {
      cin >> c_input;
      c_input--;
      grid[(i + j) % 3][c_input]++;
    }
  }

  ll ans = 1LL << 60;
  for(int c1 = 0; c1 < c; ++c1)
  {
    for(int c2 = 0; c2 < c; ++c2)
    {
      if (c1 == c2) continue;
      for(int c3 = 0; c3 < c; ++c3)
      {
        if (c1 == c3) continue;
        if (c2 == c3) continue;

        ll score = 0;
        for(int i = 0; i < c; ++i)
        {
          score += grid[0][i] * cost[i][c1];
          score += grid[1][i] * cost[i][c2];
          score += grid[2][i] * cost[i][c3];
        }
        ans = min(ans, score);

        // cout << c1 << " " << c2 << " " << c3 << " " << score << endl;
      }
    }
  }

  cout << ans;

  // 30 C 3 = 30*29*28/3*2 = 4172
  // 30 C 3 * 3! = 4172 * 6 ~= 25000

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    cout << "x";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int gate[101];
int main ()
{
    int n, m, x;
    cin >> n >> m >> x;
    int g;
    for (int i = 0; i<m; i++){
        cin >> g;
        gate[g] = 1;
    }
    int c1, c2;
    c1 = c2 = 0;
    for (int i = x; i> 0; i--){
        c1+=gate[i];
    }
    for (int i = x; i<=n; i++){
        c2+=gate[i];
    }
    cout << min(c1, c2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0, k = 0;
    cin >> n >> k;
    vector<int> p(n);
    for (int i=0; i<n; i++) {
        cin >> p.at(i);
    }
    vector<int> maxi(n), mini(n);
    int max_first = 0, min_first = 0, max_last = 0, min_last = 0;
    for (int i=0; i<k; i++) {
        while (max_last > max_first && p.at(i) > p.at(maxi.at(max_last-1))) {
            max_last--;
        }
        maxi.at(max_last) = i;
        max_last++;
    }
    for (int i=0; i<k; i++) {
        while (min_last > min_first && p.at(i) < p.at(mini.at(min_last-1))) {
            min_last--;
        }
        mini.at(min_last) = i;
        min_last++;
    }
    bool sorted = false;
    int cnt = 0;
    if (min_last - min_first == k) {
        sorted = true;
    }
    else {
        cnt++;
    }
    for (int i=0; i<n-k; i++) {
        while (max_last > max_first && p.at(i+k) > p.at(maxi.at(max_last-1))) {
            max_last--;
        }
        maxi.at(max_last) = i+k;
        max_last++;
        while (min_last > min_first && p.at(i+k) < p.at(mini.at(min_last-1))) {
            min_last--;
        }
        mini.at(min_last) = i+k;
        min_last++;
        int M = maxi.at(max_first), m = mini.at(min_first);
        if (maxi.at(max_first) == i) {
            max_first++;
        }
        if (mini.at(min_first) == i) {
            min_first++;
        }
        if (min_last - min_first == k) {
            sorted = true;
        }
        else if (M != i+k || m != i) {
            cnt++;
        }
    }
    if (sorted) {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

int main(){
  int n,a,b;
  cin >>n >>a >>b;
  int ans1 = min(a,b);
  int ans2;
  if(a+b<n) ans2 = 0;
  else ans2 = a+b-n;
  cout << ans1 << " " << ans2 << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque

def main(n, edges):
    deg = [0] * (n + 1)
    adj = {}

    for j in range(1, n + 1):
        adj[j] = []

    for u, v in edges:
        adj[u].append(v)
        deg[v] += 1

    S = deque()

    dp = [-1] * (n + 1)

    for u in range(1, n + 1):
        if deg[u] == 0:
            S.append(u)
            dp[u] = 0

    L = []

    while S:
        v = S.popleft()
        L.append(v)
        for u in adj[v]:
            deg[u] -= 1
            if deg[u] == 0:
                S.append(u)
                dp[u] = max(dp[u], dp[v] + 1)

    return max(dp)

assert main(6, [ (2, 3), (4, 5), (5, 6) ]) == 2
assert main(4, [ (1, 2), (1, 3), (3, 2), (3, 4), (2, 4) ]) == 3

n, m = map(int, input().split())
edges = []
for _ in range(m):
    u, v = map(int, input().split())
    edges.append((u, v))
ans = main(n, edges)
print(ans)



Measured memory_bytes: 78804
#include<stdio.h>
int main(void){
int i,j,k,n,x;
int count = 0;
while(1){
scanf("%d %d\n",&n ,&x);
if (n == 0 && x == 0){
break;
}
for(i=1;i <= n;i++){
for(j=1;j <= n;j++){
for(k=1;k <= n;k++){
if (i+j+k == x && i != j && i != k && j != k && i < j && j < k && i < k){
count += 1;
}
}
}
}
printf("%d\n",count);
count=0;
}
return 0;
}

Measured memory_bytes: 604
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	

	map<string,set<pair<int,int>,greater<pair<int,int>>>> A;
	int N;
	cin>>N;
	for (int i = 0; i < N; ++i)
	{
		string S;
		int P;
		cin>>S>>P;
		A[S].insert({P,i+1});
	}
	for (auto it: A)
	{
		for (auto p: it.second)
		{
			cout<<p.second<<endl;
		}
	}
	

	return 0;
}

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


int main() {
  string S, T;
  cin >> S >> T;
  int N = T.size();
  int L = S.size();
  int M = 0;
  for(int i = 0; i <= (L - N); i++){
  	string Si;
  	int count = 0;
  	Si = S.substr(i,N);
  	for(int j = 0; j < N; j++){
    	if( Si.at(j) == T.at(j) ){
    		count++;
  		}
  		else{
        	continue;
        }
    }
  	M = max(M,count);
  }
  cout << N - M << endl;
}

Measured memory_bytes: 3632
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int arr[100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,c,k;
    cin>>n>>c>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1);
    int cnt=0,ans=0;
    int patokan = arr[1]+k;
    for(int i=1;i<=n;i++){
        cnt++;
        if(arr[i]>patokan || cnt>c){
            ans++;
            patokan=arr[i]+k;
            cnt=1;
        }

    }
    cout<<ans+1<<endl;
}

Measured memory_bytes: 640