akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
 
using namespace std;
 
const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);


int ans,N,M;
int v[10];
vector<vector<int>> g;
void dfs(int x,int d){
    if(d==N){
        ans++;
        return ;
    }
    for(int i=0;i<g[x].size();i++){
        int next = g[x][i];
        if(v[next])continue;
        v[next] = 1;
        dfs(next,d+1);
        v[next] = 0;
    }
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N >> M;
    g.resize(N);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    v[0] = 1;
    dfs(0,1);
    v[0] = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if((a%2==0)or(b%2==0)){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
S = N.times.map { gets.split.map(&:to_i) }.sort_by{|v| -v[1] }
ufs = Array.new(M + 1, &:itself)

class << ufs
  def set_right(l, r)
    loop do
      break if l >= r
      m = self[l]
      self[l] = r
      l = m
    end
    r
  end

  def right(l)
    loop do
      return self.size if l >= self.size
      return l if l == self[l]
      l = self[l]
    end
  end

  def next_clear_index(l)
    r = right(l)
    r >= self.size ? nil : r
  end

  def extend_seq!(l)
    r = next_clear_index(l)
    set_right(l, r + 1) if r
  end
end

puts S.inject(0){|s, (a, b)| ufs.extend_seq!(a) ? s + b : s }



Measured memory_bytes: 12668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":	" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////

int main() {
  ll n,a,b; cin>>n>>a>>b;

  if (abs(a-b)%2 == 0) {
    cout << abs(a-b)/2 << endl;
    return 0;
  }

  if (a-1 < n-b) {
    cout << a+(b-a-1)/2 << endl;
  } else {
    cout << n-b+1+(b-a-1)/2 << endl;
  }

  return 0;
}


Measured memory_bytes: 3580
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]
dd = inputs[0][1]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p dd
end

puts (nn.to_f/(2*dd+1)).ceil


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    
    string str;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='0'){
            str+='0';
        }else if(s[i]=='1'){
            str+='1';
        }else if(s[i]=='B'){
            if(!str.empty()){
                str.pop_back();
            }
        }
    }
    
    cout<<str<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<ll, ll> > BA(N);
    REP(i,N){
        ll a, b;
        cin >> a >> b;
        BA[i] = make_pair(b,a);
    }

    sort(BA.rbegin(), BA.rend());

    set<int> D;
    REP(i,M){
        D.insert(i);
    }

    ll ans = 0;
    for(auto&& p : BA){
        ll b = p.first;
        ll a = p.second;

        auto iter = D.lower_bound(a-1);
        if(iter != D.end()){
            D.erase(iter);
            ans += b;
        }
    }

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


Measured memory_bytes: 6528
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )

using namespace std;

int N, D;

int main(void) {
    scanf("%d %d", &N, &D);

    int ans = N / (2 * D + 1);

    if ( N % (2 * D + 1) != 0 ) ans += 1;
    
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};

int main(){


	int i,j,r,c,n[110][110];

	cin >> r >> c;

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

	for(j=0; j<c+1; j++)
		for(i=0; i<r; i++)
			n[r][j] += n[i][j];

	for(i=0; i<r+1; i++){
		for(j=0; j<c+1; j++){
			if(j==c) cout << n[i][j] << endl;
			else	 cout << n[i][j] << " ";	
		}
		
	}
  
		
	return 0;			



}

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

using namespace std;

int n, a[20][20], x, y, m;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			a[i][j] = -1; 

	for (int i = 1; i <= n; i++) {
		cin >> m;
		for (int j = 1; j <= m; j++) {
			cin >> x >> y;
			a[i][x] = y;
		}
	}

	int mx = 0;
	for (int mask = 1; mask < (1 << n); mask++) {
		int nr = __builtin_popcount(mask);
		bool flag = 1;
		for (int bit = 0; bit < n; bit++) {
			if ((1 << bit) & mask) {
				int pos = bit + 1;
				for (int j = 1; j <= n; j++) {
					if (a[pos][j] == 1 && ((1 << (j - 1)) & mask) == 0) {
						flag = 0;
						break; 
					}
					if (a[pos][j] == 0 && ((1 << (j - 1)) & mask) != 0) {
						flag = 0;
						break;
					}
				}
			}
		}

		if (flag)
			mx = max(mx, nr);
	}

	cout << mx;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
const int N = 1e5 + 5;

int32_t main() {
	int n,m;
	cin>>n>>m;
	vector<int>g[n+1];
	vector<int>ans(n+1,0);
	for(int i=0,u,v;i<m;i++){
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int cnt = 1;
	queue<int>q;
	q.push(1);
	ans[1]  = 1;
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int v:g[x]){
			if(!ans[v]){
				q.push(v);
				ans[v] = x;
				cnt++;
			}
		}
	}
	if(cnt!=n)
		cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++)
			cout<<ans[i]<<endl;
	}
}


Measured memory_bytes: 10308
#include <bits/stdc++.h>
#define pb push_back
#define P push
#define S second
#define F first
using namespace std;
typedef long long ll;

ll num[10009];
int main() {
    ll n;
    cin>>n;
    for(int i=0;i<n*2;i++){
        cin>>num[i];
    }
    sort(num,num+(n*2));
    ll res=0;
    for(int i=0;i<n*2;i+=2){
        res+=min(num[i],num[i+1]);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int n , a[100005];
int main() {
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i) scanf("%d" , a + i);
    sort(a + 1 , a + 1 + n , greater<int>());
    for(int i = 1 ; i <= n ; ++i) if(a[i + 1] < i + 1) {
        int j = i;
        while(a[j + 1] == i) ++j;
        if((a[i] - i)&1 || (j - i)&1) return puts("First") & 0;
        else return puts("Second") & 0;
    }
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr ll INF = 1e15;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 1; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n, m;
    cin >> n >> m;
    vector<ll> dp(1 << n, INF);
    dp[0] = 0;
    for (int kaf = 0; kaf < m; kaf++)
    {
        int a, b;
        cin >> a >> b;
        int mask = 0;
        for (int i = 0; i < b; i++)
        {
            int c;
            cin >> c;
            c--;
            mask |= (1 << c);
        }
        for (int i = 0; i < (1 << n); i++)
        {
            dp[i | mask] = min(dp[i | mask], dp[i] + a);
        }
    }
    cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void Show_Square(int W)
{
	int i;

	for (i = 0; i < W; i++)
	{
		printf("#");
	}

	printf("\n");
}

int main(void)
{
	int W, H, j, k;

	while (1)
	{
		scanf("%d %d", &H, &W);

		if ((H == 0) && (W == 0))
		{
			break;
		}

		Show_Square(W);

		for (j = 0; j < (H - 2); j++)
		{
			printf("#");

			for (k = 0; k < W - 2; k++)
			{
				printf(".");
			}

			printf("#");
			printf("\n");
		}

		Show_Square(W);

		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int>p(N);
  vector<int>q(N);
  for(int i = 0;i<N;i++){
  cin >> p.at(i);
  }
  for(int i = 0;i<N;i++){
  q.at(i) = p.at(N-1-i);
  }
  for(int i = 0;i<N-1;i++){
  cout << q.at(i) <<" " ;
}
    cout<<q.at(N-1);
cout << endl;
}




Measured memory_bytes: 3084
#include<stdio.h>
#include<string.h>
int main(){
    int a=0;
    char s[4],b,c,d=0,e=0;
    scanf("%s",s);
    for(int i=0;i<3;i++){
        if(strncmp(&s[i],&s[i+1],1)==0){
            a++;
        }
    }
    if(a>0){
        printf("Bad\n");
    }
    else{
        printf("Good\n");
    }
    return 0;
}


Measured memory_bytes: 128
#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 x, a, b;
  cin >> x >> a >> b;
  if(-a+b <= 0) cout << "delicious" << endl;
  else if (-a+b <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

int N;
vector<string> g;
string row;
bool possible = true;
int ans = 0;

void solvefori(int start) {
  queue<int> q;
  int level[300];
  for(int i = 0;i < N;i++) level[i] = 0;

  level[start] = 1;
  q.push(start);
  ans = max(ans, 1);
  while (!q.empty()) {
    int x = q.front();
    int xlevel = level[x];
    q.pop();

    for(int j = 0;j < N;j++) {
      if(g[x][j] == '1') {
          if(level[j] == 0) {
            level[j] = xlevel+1;
            q.push(j);
            ans = max(ans, level[j]);
          } else if(level[j] == xlevel) {
            possible = false;
          }
      }
    }
  }

}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin >> N;
  for(int i = 0;i < N;i++) {
    cin >> row;
    g.push_back(row);
  }

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

  if(!possible) {
     cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

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


int main() {
    ll N,D,X;
    cin >> N >> D >> X;
    
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }

    ll ans=0;
    rep(i,N){
        ll j=0,day=0;
        while(day<D){
            day = j*A[i]+1;
            if(day > D){
                break;
            }
            j++;
            ans++;          
        }        
    }
    ans += X;

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

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

    int a[m],b[m];    
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    }

    int ans=0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(j==i) continue;
            uf.merge(a[j],b[j]);
        }
        int p=uf.root(0);
        bool ok=false;
        rep(i,n){
            if(uf.root(i)!=p) ok=true;
        }
        if(ok) ans++;
    }

    cout<<ans<<endl;
}




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

using namespace std;
int n,i,j,k,x,dp[100005],mars[100005];
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    dp[0]=1;
    for(i=1; i<=n; i++)
    {
        cin>>x;
        for(j=k; j>=0; j--)
        {
            int l=j+1,r=j+min(x,k-j);
            if(l<=r)
            {
                mars[l]+=dp[j];
                if(mars[l]>=mod)mars[l]-=mod;
                if(r+1<=k)
                {
                    mars[r+1]-=dp[j];
                    if(mars[r+1]<0)mars[r+1]+=mod;
                }
            }
        }
        int s=0;
        for(j=0; j<=k; j++)
        {
            s+=mars[j];
            mars[j]=0;
            if(s>=mod)s-=mod;
            dp[j]+=s;
            if(dp[j]>=mod)dp[j]-=mod;
        }
    }
    cout<<dp[k];
    return 0;
}


Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a + 1):
	if 500 * i <= x:
		p = x - 500 * i
		for j in range(b + 1):
			if 100 * j <= p:
				q = p - 100 * j
				for k in range(c + 1):
					if q - 50 * k == 0:
						cnt += 1

print(cnt)

Measured memory_bytes: 3064
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Mon Dec 24 16:36:13 2018
//
package main

import (
	"fmt"
	"sort"
)

type cake struct {
	x, y, z int
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	cakes := make([]cake, N)
	for i := range cakes {
		fmt.Scan(&cakes[i].x, &cakes[i].y, &cakes[i].z)
	}

	ans := -1 << 60
	for ci := -1; ci <= 1; ci += 2 {
		for cj := -1; cj <= 1; cj += 2 {
			for ck := -1; ck <= 1; ck += 2 {
				arr := make([]int, N)
				for i, c := range cakes {
					arr[i] = ci*c.x + cj*c.y + ck*c.z
				}
				sort.Ints(arr)

				total := 0
				for _, a := range arr[len(arr)-M:] {
					total += a
				}
				ans = max(ans, total)
			}
		}
	}

	fmt.Println(ans)
}


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

int main(){
	double s[10], sum;
	while(cin >> s[0]){
		for(int i = 1; i < 10; i++){
			if(i%2 == 1) s[i] = s[i-1] * 2;
			else s[i] = s[i-1] / 3;
		}

		for(int i = 0; i < 10; i++){
			sum += s[i];
		}
		printf("%.8lf\n", sum);
		sum = 0;
	}
}

Measured memory_bytes: 1236
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD 1e9+7
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

class Node
{
	public:
		int data;
		Node* left;
		Node* right;
		Node(int x);
};

Node::Node(int x)
{
	this->data = x;
	this->left = NULL;
	this->right = NULL;
}

Node* insert(Node* root,Node* temp)
{
	queue <Node*> q;
	q.push(root);
	while(!q.empty())
	{
		if(q.front()->left == NULL)
		{
			q.front()->left = temp;
			break;
		}
		else if(q.front()->right == NULL)
		{
			q.push(q.front()->left);
			q.front()->right = temp;
			break;
		}
		else
		{
			q.push(q.front()->left);
			q.push(q.front()->right);
			q.pop();
		}
	}
	return root;
}

void display(Node* root)
{
	queue <Node*> q;
	q.push(root);
	while(!q.empty())
	{
		cout<<q.front()->data<<" ";
		if(q.front()->left != NULL)
			q.push(q.front()->left);
		if(q.front()->right != NULL)
			q.push(q.front()->right);
		q.pop();
	}
	cout<<endl;
}

int main()
{
	fast
	int n;
	  cin>>n;
	  int ans = 0;
	  if(n%1000 == 0)
	    cout<<0;
	  else
	  {
	    int temp = n/1000;
	    cout<<((temp+1)*1000)-n<<endl;
	  }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  int u = 0; int v = 1e9;
  for (int i = 0; i < n; i++) {
    int a, b; cin >> a >> b;
    if (v >= b) {
      v = b; u = a;
    }
  }
  cout << u + v << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(0);
}
///////////////////////////
const int N = 5 + 1e5;


int n;
int ans,a[5];
int main() {

    for(int i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    a[0]+=a[2]-a[1];
    ans=a[2]-a[1];
    ans+=(a[2]-a[0])/2;
    if((a[2]-a[0])%2)ans+=2;
    cout<<ans;

    return 0;
}


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

using namespace std;

const int N = 200005;

int n;
long long a[N];

int main(){
	scanf("%d", &n);
	long long sum = 0;
	for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]), sum += a[i];
	long long ans = 1e18;
	for(int i = 1; i < n; ++i){
		sum -= a[i];
		a[i] += a[i-1];
		ans = min(ans, llabs(sum - a[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
typedef std::pair<int,int> P;


	ll ans=0;
	ll N,K,A[500010];


int main(){
	ios_base::sync_with_stdio(false);
	cin>>N>>K;
	REP(i,N)cin>>A[i];
//	ll id=0;
//	REP(i,N){
//		if(A[i]==1)id=i;
//	}
	ans=1+((N-K)%(K-1)==0?(N-K)/(K-1):(N-K)/(K-1)+1);
	/*ans+=
	((N-1-id)%(K-1)==0?(N-1-id)/(K-1):(N-1-id)/(K-1)+1)
	+((id)%(K-1)==0?(id)/(K-1):(id)/(K-1)+1);
	if(N==K)ans=1;*/
	cout<<ans<<endl;
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<vector<int>> hoge(n-1,vector<int>(3));
	for(int i=0;i<n-1;i++){
		cin>>hoge.at(i).at(0)>>hoge.at(i).at(1)>>hoge.at(i).at(2);
	}

	for(int i=0;i<n-1;i++){
		int cnt=0;

		for(int j=i;j<n-1;j++){
			int c=hoge.at(j).at(0);
			int s=hoge.at(j).at(1);
			int f=hoge.at(j).at(2);

			if(cnt<=s) cnt+=s-cnt;
			else cnt+=ceil((double)(cnt-s)/f)*f - (cnt-s);

			cnt+=c;
		}

		cout<<cnt<<endl;
	}

	cout<<0<<endl;

	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int A[101];
int last[101];
string R;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K;
	FOR(i,K) {
		cin>>A[i];
		N+=A[i];
	}
	
	if(*max_element(A,A+K)>*min_element(A,A+K)*2) return _P("-1\n");
	MINUS(last);
	while(R.size()<N) {
		/*
		cout<<"!"<<R.size()<<" ";
		FOR(i,4) cout<<A[i]<<" ";
		cout<<endl;
		*/
		string tar;
		tar.push_back(120);
		for(int len=1;len<=K;len++) {
			if(R.size()+len<K) continue;
			if(R.size()+len>N) continue;
			
			int B[101];
			int did[101]={};
			FOR(i,K) B[i]=A[i];
			FOR(i,K-len) did[R[R.size()-1-i]]=1;
			string cand;
			FOR(i,K) if(did[i]==0) cand.push_back(i),B[i]--;
			x=*max_element(B,B+K);
			y=*min_element(B,B+K);
			if(y<0 || x>2*y+1) continue;
			
			if(x==2*y+1) {
				string AA,BB,CC;
				FOR(i,K) if(did[i]==0) {
					if(B[i]==x) AA.push_back(i);
					else if(B[i]==y) BB.push_back(i);
					else CC.push_back(i);
				}
				int ok=1;
				FOR(i,K) if(did[i]==0 && B[i]==x) {
					FOR(j,K) if(did[i]&&B[j]==y) ok=0;
				}
				if(ok==0) continue;
				cand.clear();
				while(AA.size()+BB.size()+CC.size()) {
					if(AA.size()) {
						if(CC.size()&&CC[0]<AA[0]) {
							cand+=CC[0];
							CC.erase(CC.begin());
						}
						else {
							cand+=AA[0];
							AA.erase(AA.begin());
						}
					}
					else if(BB.size()) {
						if(CC.size()&&CC[0]<BB[0]) {
							cand+=CC[0];
							CC.erase(CC.begin());
						}
						else {
							cand+=BB[0];
							BB.erase(BB.begin());
						}
					}
					else {
						cand+=CC[0];
						CC.erase(CC.begin());
					}
				}
				
			}
			tar=min(tar,cand);
		}
		
		//cout<<"#"<<tar.size()<<endl;
		R+=tar;
		FORR(a,tar) A[a]--;
	}
	
	FORR(c,R) cout<<((int)c+1)<<" ";
	cout<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3676
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
//        int[] d = new int[n+1];
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
//                d[j]++;
                ans += j;
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 35460
#include<bits/stdc++.h>
using namespace std;
using Data=tuple<string,int,int>;

int main(){
  int i,N,P;
  char s[100];
  vector<Data> x;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",s);
    string ss=s;
    scanf("%d",&P);
    x.push_back(Data(ss,-P,i));
  }
  sort(x.begin(),x.end());

  for(i=0;i<N;i++){
    int &ans=get<2>(x[i]);
    printf("%d\n",ans+1);
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
ll gcd(ll a, ll b)
{
   if (b == 0)
   {
       return a;
   }
    return gcd(b, a%b);
}
void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}

int main() {
    int n,m;
    string s,t;
    cin >> s >> t;
    ll ans = 0;
    rep(i, 0, s.size()){
        if(s[i]!=t[i])ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N - 1; i++)
    {
        int buf;
        cin >> buf;
        A.at(buf - 1)++;
    }

    for (int i = 0; i < N; i++)
        cout << A.at(i) << endl;

    return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	double a,b,c,d,e,f;
	while (cin >> a >> b >> c >> d >> e >> f)
	{
		double x,y;
		y = (a*f-c*d)/(a*e-b*d);
		x = (c-b*y)/a;
		printf("%.3f %.3f\n",x,y);
	}
}

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

using namespace std;

class WeightUnionFind{
    public:
        vector<int> par, diff_w, rank;

        WeightUnionFind(int N){
            par.resize(N,0);
            diff_w.resize(N,0);
            rank.resize(N,0);
            for(int i=0;i<N;i++){
                par[i] = i;
            }
        }

        int root(int x){
            if(x == par[x]){
                return par[x];
            }else{
                int r = root(par[x]);
                diff_w[x] += diff_w[par[x]];
                return par[x] = r;
            }
        }

        void unite(int x, int y, int w){
            w += weight(x); w -= weight(y);
            x = root(x);
            y = root(y);
            if(x==y) return;
            else{
                if(rank[x] < rank[y]){ swap(x,y); w = -w; }
                if(rank[x] == rank[y]) rank[y]++;
                par[y] = x;
                diff_w[y] = w;
            }
        }

        int weight(int x){
            root(x);
            return diff_w[x];
        }
        
        int diff(int x, int y){
            return weight(y) - weight(x);
        }
        bool same(int x, int y){
            return root(x) == root(y);
        }
};

int main(){
    int N, M;
    cin >> N >> M;
    int l,r,d;
    WeightUnionFind wuf = WeightUnionFind(N);

    for(int i=0;i<M;i++){
        cin >> l >> r >> d;
        l--; r--;
        if(wuf.same(l,r)){
            if(wuf.diff(l,r) != d){
                cout << "No" << endl;
                return 0;
            }
        }else{
            wuf.unite(l,r,d);
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input().rstrip()
    print(s if len(s) == 2 else s[::-1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<pair<int, int>> B(H*W);
    vector<int> A(H*W, 0);
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int a;
            cin >> a;
            B[a - 1].first = i;
            B[a - 1].second = j;
        }
    }
    for (int i = H * W - D - 1; i >= 0; i--)
    {
        A[i] = A[i + D] + abs(B[i].first - B[i + D].first) + abs(B[i].second - B[i + D].second);
    }
    int Q;
    cin >> Q;
    vector<int> L(Q), R(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> L[i] >> R[i];
    }
    for (int i = 0; i < Q; i++)
    {
        cout << A[L[i] - 1] - A[R[i] - 1] << endl;
    }
    cin >> Q;
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ull binpowmod(ull x,ull y,ull p)/* (x^y)%p in O(log y) */{ull res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first)
        return true;
    else if(x.first==y.first)
        return x.second>y.second;
    else
        return false;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}
vector<int> g[200001];
void solve()
{   
    int n;
    cin>>n;
    vector<int> p(n+1);
    for(int i=2;i<=n;i++){
        int x;
        cin>>x;
        p[i]=x;
    }
    for(int i=1;i<=n;i++){
        g[p[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){
        if(!g[i].size())
            cout<<0<<'\n';
        else
            cout<<g[i].size()<<'\n';
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 15004
/**
 *    DP
 *    26.04.2020 13:33
**/

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  char c;
  cin >> H >> W;
  vector<vector<char>> grid (H, vector<char> (W, '.'));
  vector<vector<long long>> dp (H + 1, vector<long long> (W + 1, 0));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c;
      grid[i][j] = c;
    }
  }
  /*
  dp[i][j] = number of ways to reach grid [i][j]
  dp[i][j] = dp[i-1][j] + dp[i][j-1]
  */
  dp[1][1] = 1;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (i == 1 && j == 1) continue;
      if (grid[i - 1][j - 1] != '#') {
        dp[i][j] = (dp[i][j - 1] % MOD + dp[i - 1][j] % MOD) % MOD;
      }
    }
  }
  cout << dp[H][W] << "\n";
  return 0;
}


Measured memory_bytes: 9088
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=INF,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi V(n);
  VIN(V)
  map<int,int> Odd;
  map<int,int> Even;
  Vi mOdd(1);
  mOdd = {0};
  Vi mEven(1);
  mEven = {0};
  REP(i,n){
    if(i%2==0) Odd[V[i]]++;
    else Even[V[i]]++;
  }
  int maxEO = 0;
  int maxEE = 0;
  for(auto p:Odd){
    mOdd.pb(p.second);
    x = max(x,p.second);
    if(x==p.second) a = p.first;
  }
  for(auto p:Even){
    mEven.pb(p.second);
    y = max(y,p.second);
    if(y==p.second) b = p.first;
  }
  RSORT(mOdd);
  RSORT(mEven);
  if(a!=b) OUT(n/2-mOdd[0] + n/2-mEven[0]);
  else OUT(min(n/2-mOdd[0]+n/2-mEven[1],n/2-mOdd[1]+n/2-mEven[0]));
}

Measured memory_bytes: 8444
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int ruisekiwa[200001][2];

int main() {
	int ans = 100000000;
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		ruisekiwa[i + 1][0] = ruisekiwa[i][0];
		ruisekiwa[i + 1][1] = ruisekiwa[i][1];
		if (s[i] == '.')ruisekiwa[i + 1][0]++;
		else ruisekiwa[i + 1][1]++;
	}

	for (int i = 0; i <= s.size(); i++) {
		int tmp = (ruisekiwa[i][1] + (ruisekiwa[n][0] - ruisekiwa[i][0]));
		ans = min(tmp, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2180
import math
A,B,H,M=map(int,input().split())
a=((H+M/60)/12)*2
b=(M/60)*2
if a-b<=1:
  omega=a-b
else:
  omega=2-(a-b)
print((A**2+B**2-2*A*B*math.cos(omega*math.pi))**(1/2))


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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;
}

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,C;
int D[30][30];
int cnum[3][30];
pv<int,int> v[3];

void input() {
	cin>>N>>C;
	for(int i=0; i<C; i++)for(int j=0; j<C; j++) cin>>D[i][j];
	for(int i=0; i<N; i++)for(int j=0; j<N; j++) {
		int c; cin>>c; c--;
		cnum[(i+j)%3][c]++;
	}
}

void solve() {
	for(int i=0; i<3; i++) {
		for(int j=0; j<C; j++) {
			int tmp=0;
			for(int k=0; k<C; k++) {
				tmp+=D[k][j]*cnum[i][k];
			}
			v[i].pushb({tmp,j});
		}
	}
	for(int i=0; i<3; i++) sort(all(v[i]));
	
	int res=INTINF;
	for(int i=0; i<min(C,5); i++)for(int j=0; j<min(C,5); j++)for(int k=0; k<min(C,5); k++) {
		if(v[0][i].se==v[1][j].se ||
		   v[1][j].se==v[2][k].se ||
		   v[2][k].se==v[0][i].se) continue;
		
		chmin(res,v[0][i].fi+v[1][j].fi+v[2][k].fi);
	}
	cout<<res<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, string> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int n;
	cin >> n;
	string s[n];
	rep(i, n) cin >> s[i];
	vector< pair<int, string> > v;
	sort(s, s + n);
	//v.push_back(P(1, s[0]));
	int t = 1;
	REP(i, 1, n) {
		if(s[i] == s[i-1]) {
			t++;
		} else {
			v.push_back(P(t, s[i-1]));
			t = 1;
		}
	}
	v.push_back(P(t, s[n-1]));

	sort(all(v), greater<>());
	vector<string> res;
	rep(i, v.size()) {
		if(v[i].first != v[0].first) break;
		res.push_back(v[i].second);
	}

	sort(all(res));
	rep(i, res.size()) cout << res[i] << endl;
	//rep(i, v.size()) cout << v[i].first << " " << v[i].second;
	return 0;
}

Measured memory_bytes: 20460
def read_int_list():
    return list(int(i) for i in input().split())

n,m,k = read_int_list()

ans = "No"
flag = False
for i in range(0,n+1):
    for j in range(0,m+1):
        black = (i*m + j*n) - (i*j)*2
        if black == k:
            ans = "Yes"
            flag = True
            break
    if flag:
        break
print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        int[] arrMoto = Console.ReadLine().Split(' ').Select(r => int.Parse(r)).ToArray();
        int x = arrMoto[0];
        int y = arrMoto[1];
        IEnumerable<long> redApple = Console.ReadLine().Split(' ').Select(o => long.Parse(o)).OrderByDescending(r => r).Take(x);
        IEnumerable<long> greenApple = Console.ReadLine().Split(' ').Select(o => long.Parse(o)).OrderByDescending(r => r).Take(y);
        IEnumerable<long> noColorApple = Console.ReadLine().Split(' ').Select(o => long.Parse(o));
        long ans = redApple.Concat(greenApple).Concat(noColorApple).OrderByDescending(r => r).Take(x + y).Sum();
        Console.WriteLine(ans);
    }


  

}



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

int main(){
    using namespace std;
    int N;
    double A[1000];
    double answer = 0;
    cin >> N;
    for (int i = 0; i < N ;i++){
        cin >> A[i];
        answer += 1/A[i];
    }
    cout << 1/answer << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
	public class Main{
		public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			int xp = sc.nextInt();// price per 1L 
			int ybp = sc.nextInt();// basic price of Y 
			int yo = sc.nextInt(); // overlimit of Y 
			int ytp = sc.nextInt();// tukika of Y per 1 L 
			int wp = sc.nextInt();//water p
			int min = xp * wp;
			int sum = ybp;
			if(wp > yo){
				sum = (wp - yo) * ytp + ybp; 
			}
			if(sum < min){
				System.out.println(sum);
			}else{
				System.out.println(min);
			}
			sc.close();
		}	
	}		

Measured memory_bytes: 26096
def CountMine(x, y):
    count = 0
    for k in range(3):
        for l in range(3):
            if S[x-1+k][y-1+l] == '#':
                count += 1
    return count
    
    

H, W = list(map(int, input().split()))
S = [[0]*(W+2)] + [[0] + list(input()) + [0] for _ in range(H)] + [[0]*(W+2)]

for i in range(H):
    for j in range(W):
        if S[i+1][j+1] == '.':
            print(CountMine(i+1, j+1), end="")
        else:
            print('#', end="")
    print('\n')

Measured memory_bytes: 3444
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    p(min(a,b) + min(c,d));
        
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

from collections import deque

def main():

    lines = input()
    n, k = list(map(int, lines[0].split()))
    a = [[] for i in range(n+1)]

    for i in range(1, n):
        r, l = list(map(int, lines[i].split()))
        a[r].append(l)
        a[l].append(r)

    que = deque()
    que.append(1)
    colors = [-1] * (n+1)
    colors[1] = k
    ways = k

    while que:
        p = que.popleft()
        # root no toki
        if p == 1:
            now_color = k
            for son in a[p]:
                now_color -= 1
                ways = (ways * now_color) % 1_000_000_007
                colors[son] = now_color
                que.append(son)
        else:
            now_color = k-1
            for son in a[p]:
                if colors[son] < 0:
                    now_color -= 1
                    colors[son] = now_color
                    ways = (ways * now_color) % 1_000_000_007
                    que.append(son)

    print(ways)

main()



Measured memory_bytes: 38400