akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
        return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
        return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
                in >> x;
        return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
    for (const vector<T> &x : v)
                out << x << '\n';
        return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
                out << x << ' ';
        return out;
}
 
template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
    for (const T &x : s)
            out << x << ' ';
        return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl "\n"
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll n;
    cin>>n;
    ll ans=power(10,n)-2*power(9,n)+power(8,n);
    ans=(ans+100*mod)%mod;
    cout<<ans<<nl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int x,y,z,idx=0,sum;
    int formula = 0;
    int n;cin>>n;
    int start = 1;
    while(start <= n){
            int sqr = sqrt(start);
            sum = 0;
            for(x=1;x<=sqr;x++){
                for(y=1;y<=sqr;y++){
                    for(z=1;z<=sqr;z++){
                        formula = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
                        if(formula == start)
                            sum++;
                        else if(formula > start)
                            break;
                    }
                }
            }
            cout<<sum<<endl;
            start++;
    }
    return 0;
}


Measured memory_bytes: 3468
#include<stdio.h>
int main()
{
    int n,i;
    long long int a[20000],sum=0,mini,maxi;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        sum = sum+a[i];
    }
        mini = a[0];
        maxi = a[0];
        for(i=1;i<n;i++)
        {
            if(a[i] > maxi)
        {
            maxi = a[i];
        }

        if(a[i] < mini)
        {
            mini = a[i];
        }
        }
        printf("%lld %lld %lld\n",mini,maxi,sum);
        return 0;
}




Measured memory_bytes: 2100
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef LOCAL
    #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define debug(...) 42
    #define eprintf(...) 42
#endif

#define PI 3.1415926535897932384626433832795
#define INF 2e9
#define SINV(t) greater<t>()
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(auto i=(v).begin(); i!=(v).end(); ++i)
#define ALL(x) (x).begin(),(x).end()

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

typedef long long ll;
#define vv(t) vector<t>

#define CHC(mp, x) if(mp.end() != mp.find(x))

template<typename T>
inline T lcm(T a, T b) {return a / __gcd(a, b) * b;}

#pragma endregion

template<typename T>
void SV(vector<T> v){
    REP(i,v.size()){
        #ifdef LOCAL
            cout << i << " : " << v[i] << endl;
        #endif
    }
}
int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}

int main(void){
    int K, A, B;
    cin >> K >> A >> B;
    int m = B / K;
    if(m*K < A){
        cout << "NG\n";
    }else{
        cout << "OK\n";
    }
    return 0;
}


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

char mas[510][510];

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

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

    int last = 0;
    int white = 0;
    int re[510] = {};
    for(int j = 0;j < n;j++){
        for(int i = 0;i < n;i++){
            re[j] += mas[i][j] == '.' ? 1 : 0;
            white += mas[i][j] == '.' ? 1 : 0;
        }

        if(re[j] != 0) last++;
    }

    if(white == n*n){
        cout << -1 << endl;
        return 0;
    }

    int ans = INT_MAX;

    for(int i = 0;i < n;i++){
        int cnt = 0;
        for(int j = 0;j < n;j++){
            if(mas[i][j] == '.'){
                cnt++;
            }
        }

        if(re[i] == n){
            cnt++;
        }

        ans = min(ans, cnt);
    }

    cout << ans+last << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
	static int[]heap;
    static int MAXHEAP=2000000;
    static int n=0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
	    int i;
	    String hz;
		heap=new int[MAXHEAP+1];
       Scanner sca= new Scanner(System.in);
       while(true){
	   hz=sca.next();
	   if(hz.equals("insert")){
	    maxHeapInsert(sca.nextInt());
	   }else if(hz.equals("extract")){
	       System.out.println(extract());
	   }else if(hz.equals("end")){
	    break;
	   }
       }
	}
	public static void maxHeapify(int i){
		int l,r,largest,hz;
		l=i*2;
		r=i*2+1;
		if(l<=n&&heap[l]>heap[i]){
			largest=l;
		}else{
			largest=i;
		}
		if(r<=n&&heap[r]>heap[largest])largest=r;
		if(largest!=i){
			hz=heap[largest];
			heap[largest]=heap[i];
			heap[i]=hz;
			maxHeapify(largest);
		}
	}
    public static void maxHeapInsert(int key){
	n++;
	heap[n]=Integer.MIN_VALUE;
	heapIncreaseKey(n,key);
    }
    public static void heapIncreaseKey(int i,int key){
	int hz;
       	if (key<heap[i])return;
	heap[i]=key;
	while(i>1&&heap[i/2]<heap[i]){
	    hz=heap[i/2];
	    heap[i/2]=heap[i];
	    heap[i]=hz;
	    i/=2;
	}
    }
    public static int extract(){
	int i,max;
	if(n<1)return Integer.MIN_VALUE;
	max=heap[1];
	heap[1]=heap[n];
	n--;
	maxHeapify(1);
	return max;
    }

}




Measured memory_bytes: 557532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    int cnt = 0;
    string ans = "No";
    REP(_, N) {
        int D1, D2; cin >> D1 >> D2;
        if (D1 == D2) {
            cnt++;
            if (cnt == 3) ans = "Yes";
        } else {
            cnt = 0;
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3644
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m,k] <- getIntList
    as <- getIntList
    bs <- getIntList
    let sa = takeWhile (<=k) $ scanl (+) 0 as
        sb = takeWhile (<=k) $ scanl (+) 0 bs
    let ansa = maximum $ solve k (length sa - 1) (reverse sa) sb
        ansb = maximum $ solve k (length sb - 1) (reverse sb) sa
    print $ max ansa ansb

solve k l [] _ = [0]
solve k l _ [] = [0]
solve k l (a:sa) (b:sb)
    | a + b <= k = l : solve k (l+1) (a:sa) sb
    | a + b > k = solve k (l-1) sa (b:sb)                    

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

using namespace std;
const int N = 1e6 + 5, MOD = 1e9 + 7;
int fac[N], inv[N];

int mul(int a, int b) {return 1ll * a * b % MOD;}
int Pow(int a, int b) {
    int res = 1;
    for (; b; b>>=1, a = mul(a, a)) if (b&1) res = mul(res, a);
    return res;
}
int C(int n, int k) {
    if (k > n || k < 0 || n < 0) return 0;
    return mul(fac[n], mul(inv[k], inv[n - k]));
}

int main() {
    int n; cin >> n;
    fac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
    inv[n] = Pow(fac[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--) inv[i] = mul(inv[i + 1], i + 1);
    int ans = fac[n];
    for (int k = 1; k < n; k++) ans = (ans - mul(C(k - 1, n - k - 1), mul(fac[n - k - 1], fac[k])) + MOD) % MOD;
    cout << ans << "\n";


    return 0;
}


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

ll digitDP(ll tsum, int n){
  vector<vl> dp(n+1, vl(tsum+1,0) );
  dp[0][0] = 1;
  rep(i,n){
    rep(j,tsum+1){
      rep(k,10){
	int nj = j+k;
	if(nj>tsum)continue;
	dp[i+1][nj] += dp[i][j];
      }
    }
  }

  ll ans = 0;
  rep(i,tsum) ans += dp[n][i];

  return ans;
}

unordered_map<ll,ll> memo;
ll memoDP(int cur_step, ll cur_prod, ll cur_sum,
	  const ll tprod, const ll tsum, const int n){
  ll key = cur_prod*4000+cur_sum*20+cur_step;
  if(memo.count(key))return memo[key];

  if(cur_step == n){
    return (cur_sum == tsum && cur_prod < tprod) ? 1 : 0;
  }

  ll ans = 0;
  rep(i,10){
    if(cur_sum+i > tsum)break;
    if(cur_prod*(i+1) >= tprod)break;
    ans += memoDP(cur_step+1, cur_prod*(i+1), cur_sum+i, tprod, tsum, n);
  }

  return memo[key] = ans;
}

ll memoDP2(int cur_step, ll cur_prod, ll cur_sum, const string &d, ll flag,
	  const ll tprod, const ll tsum, const int n){
  ll key = cur_prod*6000+cur_sum*40+cur_step*2+flag;
  if(memo.count(key))return memo[key];

  if(cur_step == n){
    return (cur_sum == 0 && cur_prod == 1 && flag) ? 1 : 0;
  }

  ll ans = 0;
  rep(i,10){
    if(cur_sum-i < 0)continue;
    if(cur_prod%(i+1) != 0)continue;
    int k = d[cur_step]-'0';
    if(i==k){
      ans += memoDP2(cur_step+1, cur_prod/(i+1), cur_sum-i, d, flag, tprod, tsum, n);
    }else if(i<k){
      ans += memoDP2(cur_step+1, cur_prod/(i+1), cur_sum-i, d, 1, tprod, tsum, n);
    }else if(flag){
      ans += memoDP2(cur_step+1, cur_prod/(i+1), cur_sum-i, d, 1, tprod, tsum, n);
    }
  }

  return memo[key] = ans;
}

int main(){
  ll tsum = 0, tprod = 1, tint = 0;
  string d;
  cin >> d;
  int n = d.size();
  
  rep(i,n){
    ll dint = d[i]-'0';
    tsum += dint;
    tprod *= (dint+1);
    tint = tint*10 + dint;
  }

  ll ans = 0;
  ans += digitDP(tsum,  n);

  memo.clear();
  ans += memoDP(0, 1, 0, tprod, tsum, n);

  memo.clear();
  ans += memoDP2(0, tprod, tsum, d, 0, tprod, tsum, n);

  cout << ans << endl;
}

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

typedef pair<int, int> ii;

const int N = 104;
int n, a[N], b[N];
vector<int> ans;

void sol() {
	while (n > 0) {
		int pos = -1;
		for (int i = n; i >= 1; --i) 
			if (a[i] == i) { pos = i; break; }
		if (pos == -1) { cout << -1 << '\n'; exit(0); }

		ans.push_back(a[pos]);

		int num = 0;
		for (int i = 1; i <= n; ++i) if (i != pos) b[++num] = a[i];
		for (int i = 1; i <= num; ++i) a[i] = b[i]; n = num;
	}
	
	reverse(ans.begin(), ans.end());
	for (int val : ans) cout << val << '\n';
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

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

	sol();

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
  string s;
  cin>>s;
  if(s[0]=='A') cout<<'T'<<endl;
  else if(s[0]=='T') cout<<'A'<<endl;
  else if(s[0]=='G') cout<<'C'<<endl;
  else cout<<'G'<<endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
s=[]
sum=0
for i in range(N):
    s.append(int(input()))
    sum+=s[i]

#print("sum="+str(sum))

min=100000000

if sum%10==0:
    for i in range(N):
        if(min>=s[i] and s[i]%10!=0):
            min=s[i]
#            print("err")
if sum%10!=0:
    print(sum)
elif min!=100000000:
    print(sum-min)
else:
    print(0)

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s; cin >> s;
    ll sum = 0;
    int locate=0;
    rep( bit, 0, (1<<(s.size()-1)) ) {
        locate = 0;
        rep( shift, 0, s.size()-1 ) {
            if( bit & (1<<shift) ) {
                sum += stoll(s.substr(locate,shift-locate+1));
                locate = shift+1;
            }
        }
        sum += stoll(s.substr(locate));
    }
    cout << sum << endl;
}   

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

const int MAXN = 3000 + 5;

using namespace std;

int n;
long double dp[MAXN][MAXN],probability[MAXN];

int main()
{
    cin>>n;
    for(int i = 1; i <= n; i++)
        cin>>probability[i];
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= i; j++){
            dp[i + 1][j] += dp[i][j] * (1 - probability[i + 1]);
            dp[i + 1][j + 1] += dp[i][j] * probability[i + 1];
        }
    }
    
    long double ans = 0;

    for(int j = n / 2 + 1; j <= n; j++)
        ans += dp[n][j];
    cout<<setprecision(10) << fixed << ans;


    return 0;
}

Measured memory_bytes: 139392
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
bool ok;
char str[1024];
pair<pair<int,int>,int>eq(int a);
pair<pair<int,int>,int>ter(int a){
	if(str[a]=='('){
		pair<pair<int,int>,int>res=eq(a+1);
		res.second++;
		return res;
	}else if(str[a]=='i'){
		return make_pair(make_pair(0,1),a);
	}else{
		int res=0;
		int at=a;
		while(str[at]>='0'&&str[at]<='9'){
			res*=10;
			res+=str[at]-'0';
			if(res>10000)ok=false;
			at++;
		}
		return make_pair(make_pair(res,0),at-1);
	}
}
pair<pair<int,int>,int>fac(int a){
	pair<pair<int,int>,int>t=ter(a);
	pair<int,int>ret=t.first;
	while(str[t.second+1]=='*'){
		t=ter(t.second+2);
		int L=ret.first*t.first.first-ret.second*t.first.second;
		ret.second=ret.first*t.first.second+ret.second*t.first.first;
		ret.first=L;
		if(ret.first<-10000||ret.first>10000||ret.second<-10000||ret.second>10000)ok=false;
	}
	return make_pair(ret,t.second);
}
pair<pair<int,int>,int>eq(int a){
	pair<pair<int,int>,int>t=fac(a);
	pair<int,int>ret=t.first;
	while(str[t.second+1]=='+'||str[t.second+1]=='-'){
		if(str[t.second+1]=='+'){
			t=fac(t.second+2);
			ret.first+=t.first.first;
			ret.second+=t.first.second;
			if(ret.first<-10000||ret.first>10000||ret.second<-10000||ret.second>10000)ok=false;
		}else{
			t=fac(t.second+2);
			ret.first-=t.first.first;
			ret.second-=t.first.second;
			if(ret.first<-10000||ret.first>10000||ret.second<-10000||ret.second>10000)ok=false;
		}
	}
	return make_pair(ret,t.second);
}
int main(){
	while(~scanf("%s",str)){
		ok=true;
		pair<int,int>res=eq(0).first;
		if(!ok)printf("overflow\n");
        else{
            if(res.first){
                printf("%d",res.first);
                if(res.second>0)printf("+%di",res.second);
                else if(res.second<0)printf("%di",res.second);
                printf("\n");
            }else if(res.second)printf("%di\n",res.second);
            else printf("0\n");
        }
	}
}

Measured memory_bytes: 996
import java.io.PrintWriter
import java.lang.reflect.Modifier

class Comb(n: Int) {

    companion object {
        const val MOD = ModInt.MOD
    }

    private val fact = LongArray(n + 1)
    private val factInv = LongArray(n + 1)

    init {
        fact[0] = 1L
        for (i in 1..n) {
            fact[i] = fact[i - 1] * i % MOD
        }
        factInv[n] = ModInt(fact[n]).inv().x
        for (i in n downTo 1) {
            factInv[i - 1] = factInv[i] * i % MOD
        }
    }

    fun comb(n: Int, k: Int): Long {
        if (k !in 0..n) return 0L
        return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD
    }

}

class ModInt(x: Long) {

    companion object {
        const val MOD = 1e9.toLong() + 7
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val cb = Comb(2000)
    val pw = PrintWriter(System.out)
    for (i in 1..k) {
        val x = cb.comb(n - k + 1, i) * cb.comb(k - 1, i - 1)
        pw.println(ModInt(x))
    }
    pw.flush()
}


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
//#define int long long

int goal,ans=INF;
set<int> s;
decltype(s)::iterator it;
int fh[3][3];

int tohash(){
	int hash=0;
	lp(i,3){
		lp(j,3){
			hash*=10;
			hash+=fh[i][j];
		}
	}
	return hash;
}

void fromhash(int h){
	lp(i,3){
		lp(j,3){
			fh[2-i][2-j]=h%10;
			h/=10;
		}
	}
	return;
}

void solve(){
	lp(i,3)lp(j,3){
		fh[i][j]=i*3+j+1;
	}
	fh[2][2]=0;
	queue<pair<int,int> > q;
	q.push(make_pair(tohash(),0));
	if(tohash()==goal){
		ans=0;
		return;
	}
	int cost;
	int x,y;
	while(!q.empty()){
		cost=q.front().second;
		fromhash(q.front().first);
		q.pop();
		lp(i,3){
			lp(j,3){
				if(fh[i][j]==0){
					x=i;y=j;
					break;
				}
			}
		}
		if(x!=0){
			swap(fh[x][y],fh[x-1][y]);
			int memo=tohash();
			if(memo==goal){
				ans=cost+1;
				return;
			}
			it=s.find(memo);
			if(it==s.end()){
				q.push(make_pair(memo,cost+1));
				s.insert(memo);
			}
			swap(fh[x][y],fh[x-1][y]);
		}
		if(y!=0){
			swap(fh[x][y],fh[x][y-1]);
			int memo=tohash();
			if(memo==goal){
				ans=cost+1;
				return;
			}
			it=s.find(memo);
			if(it==s.end()){
				q.push(make_pair(memo,cost+1));
				s.insert(memo);
			}
			swap(fh[x][y],fh[x][y-1]);
		}
		if(x!=2){
			swap(fh[x][y],fh[x+1][y]);
			int memo=tohash();
			if(memo==goal){
				ans=cost+1;
				return;
			}
			it=s.find(memo);
			if(it==s.end()){
				q.push(make_pair(memo,cost+1));
				s.insert(memo);
			}
			swap(fh[x][y],fh[x+1][y]);
		}
		if(y!=2){
			swap(fh[x][y],fh[x][y+1]);
			int memo=tohash();
			if(memo==goal){
				ans=cost+1;
				return;
			}
			it=s.find(memo);
			if(it==s.end()){
				q.push(make_pair(memo,cost+1));
				s.insert(memo);
			}
			swap(fh[x][y],fh[x][y+1]);
		}
	}
}

signed main(){
	lp(i,3){
		lp(j,3){
			cin>>fh[i][j];
		}
	}
	goal=tohash();
	s.insert(goal);
	solve();
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 11660
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    string s;
    cin >> s;
    int len = (int)s.size();
    bool is = true;
    int a_cnt = 0, b_cnt = 0, c_cnt = 0;
    rep(i, len){
        if(s[i] == 'a') a_cnt++;
        if(s[i] == 'b') b_cnt++;
        if(s[i] == 'c') c_cnt++;
    }
    int line = len / 3;
    if(a_cnt < line || b_cnt < line || c_cnt < line) is = false;
    a_cnt -= line;
    b_cnt -= line;
    c_cnt -= line;
    if(a_cnt > 1 || b_cnt > 1 || c_cnt > 1) is = false;
    if(is) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

int n,k,c,l[N],r[N];
string s;
signed main(){
    FastIO;
    cin>>n>>k>>c>>s;
    bool ok=1;
    int prev=-1e9,curr=1;
    rep(i,0,n-1) if(s[i]=='o' and (i-prev>c)){
        if(curr>k) ok=0;
        l[i]=curr++;
        prev=i;
    }
    prev=1e9,curr=1;
    repb(i,n-1,0) if(s[i]=='o' and (prev-i>c)){
        if(curr>k) ok=0;
        r[i]=curr++;
        prev=i;
    }
    if(!ok) return 0;
    rep(i,0,n-1) if(l[i] and r[i] and l[i]+r[i]==k+1) cout<<i+1<<'\n';
    return 0;
}


Measured memory_bytes: 3348
N=input()
if N[-1]=='2' or N[-1]=='4' or N[-1]=='5' or N[-1]=='7' or N[-1]=='9':
    print('hon')
elif N[-1]=='0' or N[-1]=='1' or N[-1]=='6' or N[-1]=='8':
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9116
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int k;
  cin >> k;
  int arr[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};
  cout << arr[k - 1] << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
D = [[i, abs(a+b)] for i, (a, b) in enumerate(AB)]
D.sort(key=lambda x:x[1], reverse=True)
ta = [0, 0]
for j, (i, d) in enumerate(D):
  ta[j%2]+=AB[i][j%2]
print(ta[0]-ta[1])

Measured memory_bytes: 75096
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5;
struct Element
{
    int u,v,opt;
} p[N+3];
int fa[N+3];
ll n,q,c,m;

int find(int u) {return fa[u]==u?u:fa[u]=find(fa[u]);}

int main()
{
    cin>>n>>m>>q;
    for(int i=1; i<=n; i++) fa[i] = i;
    for(int i=1; i<=q; i++)
    {
        scanf("%d%d%d",&p[i].u,&p[i].v,&p[i].opt); p[i].u++; p[i].v++;
        if(p[i].opt==0)
        {
            int uu = find(p[i].u),vv = find(p[i].v);
            if(uu!=vv) {fa[uu] = vv;}
        }
    }
    ll huan = 0; c = 0;
    for(int i=1; i<=n; i++) {if(i==find(i)) c++;}
    for(int i=1; i<=q; i++){
        if(p[i].opt==1){
            huan++;
            int uu = find(p[i].u),vv = find(p[i].v);
            if(uu==vv) {puts("No"); return 0;}
        }
    }
    ll l = huan?max(3ll,(ll)c):c-1ll,r = 1ll*c*(c-1ll)/2ll;
    if(m-(n-c)>=l && m-(n-c)<=r) {puts("Yes");}
    else {puts("No");}
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  for(int i=0;i<3;i=i+1){
    if(S[i]=='1'){
      S[i]='9';
    }else{
      S[i]='1';
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
 
public class AchieveTheGoal {
    public static void Main(){
        string[] line = Console.ReadLine().Split(' ');
        int N = int.Parse(line[0]);
        int M = int.Parse(line[1]);
        int correctNum = 0;
        int totalPenalty = 0;
        Dictionary<int, bool> isCorrect = new Dictionary<int, bool>();
        Dictionary<int, int> penaltyNum = new Dictionary<int, int>();
        for (int i = 0; i < M ; i++ )
        {
            line = Console.ReadLine().Split(' ');
            int p = int.Parse(line[0]);
            if (!isCorrect.ContainsKey(p))
            {
                if (line[1] == "WA")
                {
                    if (!penaltyNum.ContainsKey(p)) penaltyNum[p] = 1;
                    else penaltyNum[p]++;
                }
                else if (line[1] == "AC")
                {
                    correctNum++;
                    if (penaltyNum.ContainsKey(p))  totalPenalty += penaltyNum[p];
                    isCorrect[p] = true;
                }
            }
        }
        Console.WriteLine(correctNum+" "+totalPenalty);
    }
}

Measured memory_bytes: 21072
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007   
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

void solve(){
    int a, b;
    cin >> a >> b;
    cout << (a*b)/__gcd(a, b) << endl;
} 
signed main(){  
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
    //  cin >> t;  
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}

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

int main(){
  int n,m,c;
  cin >> n >> m >> c;
  int a;
  int b[m];
  int sum = 0;
  int count = 0;
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  for(int i=0;i < n;i++){
    for(int j=0;j < m;j++){
      cin >> a;
      sum = a * b[j] + sum; 
    }
    if(sum + c > 0){
      count = count + 1;
    }
    sum = 0;
  }
  cout << count << endl;
}

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

int main() {
    long n, m, x, y;
    long A[100], B[100];
    cin >> n >> m >> x >> y;
    for (long i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (long i = 0; i < m; i++) {
        cin >> B[i];
    }

    sort(A, A + n);
    sort(B, B + m);

    if (min(y, B[0]) - max(x, A[n - 1]) > 0) {
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;

ll xs[] = {-1, 1, 0, 0};
ll ys[] = {0, 0, -1, 1};

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin >> t;
	if(t/90 == 1 or t%10 == 9)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <algorithm>
long long n, q, m, p, fl, fr, c;
long long d[500001];
long long e[500000];
long long f[500000];
long long l[500000];
long long r[500000];
long long ans[500000];
long long treesize = 1024 * 512;
long long segtree[1024 * 1024];
long long stl[1024 * 1024];
long long str[1024 * 1024];
long long compare(long long cx, long long cy) {
	//比較演算など
	return cx + cy;
}
void maketree(long long sx) {
	//maketree(1)
	if (sx >= treesize) {
		stl[sx] = sx - treesize;
		str[sx] = sx - treesize;
		return;
	}
	maketree(sx * 2);
	maketree(sx * 2 + 1);
	segtree[sx] = compare(segtree[sx * 2], segtree[sx * 2 + 1]);
	stl[sx] = stl[sx * 2];
	str[sx] = str[sx * 2 + 1];
}
long long rmq(long long sl, long long sr, long long sx) {
	//sl<=x<=sr
	//rmq(sl,sr,1)
	if (sl == stl[sx] && sr == str[sx])return segtree[sx];
	long long stm = (stl[sx] + str[sx]) / 2;
	if (sr <= stm)return rmq(sl, sr, sx * 2);
	if (sl > stm)return rmq(sl, sr, sx * 2 + 1);
	return compare(rmq(sl, stm, sx * 2), rmq(stm + 1, sr, sx * 2 + 1));
}
void change(long long sx) {
	segtree[sx]++;
	if (sx > 1)change(sx / 2);
}
int main() {
	maketree(1);
	scanf("%lld%lld", &n, &q);
	for (long long i = 1; i <= n; i++) {
		scanf("%lld", &c);
		if (d[c]) {
			e[m] = d[c] * 1000000 + i;
			m++;
		}
		d[c] = i;
	}
	std::sort(e, e + m);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld", l + i, r + i);
		f[i] = l[i] * 1000000 * 1000000 + r[i] * 1000000 + i;
		ans[i] = r[i] - l[i] + 1;
	}
	std::sort(f, f + q);
	p = m;
	for (long long i = q - 1; i >= 0; i--) {
		fl = f[i] / 1000000 / 1000000;
		fr = f[i] / 1000000 % 1000000;
		while (p > 0 && e[p - 1] / 1000000 >= fl) {
			p--;
			change(e[p] % 1000000 + treesize);
			//printf("\n%lld %lld\n", e[p] / 1000000, e[p] % 1000000);
		}
		//printf("\nf%lld %lld\n", fl, fr);
		ans[f[i] % 1000000] -= rmq(0, fr, 1);
	}
	for (int i = 0; i < q; i++) {
		printf("%lld\n", ans[i]);
	}
}

Measured memory_bytes: 48376
/*
*
* author: ian macleod
*
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector<long long int> vll;

#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b) for(ll i=a;i>=b;i--)

ll power(ll x, ll y) {
    ll res = 1;     // Initialize result
    x = x ;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}


void solve() {
    
    string a;
    cin >> a;
    if (a == "ARC") {
        cout << "ABC" << endl;
    }
    else {
        cout << "ARC" << endl;
    }
    return ;
}



int main() {
    solve();
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,a,b=0,c=0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    b += a%4 == 2;
    c += !(a%4);
  }
  if (c >= N/2 || N <= b+2*c) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    int ans = 700;
    rep(i, 3){
        if(s[i] == 'o'){
            ans += 100;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, t = gets.split.map(&:to_i)

ct = []
n.times do
  ct << gets.split.map(&:to_i)
end

ct = ct.sort {|a, b| a[0] <=> b[0]}
ct.each do |x|
  if x[1] <= t
    puts x[0]
    exit
  end
end

puts 'TLE'


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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int a[200001];
int32_t main() {
    nitin;
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int num;
        cin>>num;
        a[num]++;
    }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<endl;
    return 0;
}

Measured memory_bytes: 5168
#include <stdio.h>
#include <vector>
#include <array>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>

using std::string;
using std::vector;


int main(){
    int n = 0;
    scanf("%d", &n);
    int list[2][1000];
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < n; j++) {
            int v = -1;
            scanf("%d", &v);
            list[i][j] = v;
        }
    }

    for(int p = 1; p <= 3; p++) {
        double sum = 0.0;
        for(int i = 0; i < n; i++) {
            sum += std::fabs(std::pow(list[0][i] - list[1][i], p));
        }
        printf("%lf\n", std::pow(double(sum), 1.0 / double(p)));
    }

    double max = 0.0;
    for(int i = 0; i < n; i++) {
        max = std::max(std::fabs(list[0][i] - list[1][i]), max);
    }
    printf("%lf\n", max);

    return 0;
}


Measured memory_bytes: 3372
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
	var list = [tmp[0], tmp[1], tmp[2]]
    list = fswap(list)
  	list = sswap(list)
  	console.log(...list)
}

function fswap(list) {
  var temp = list[0]
  list[0]= list[1]
  list[1] = temp
  return list
}
function sswap(list) {
  var temp = list[0]
  list[0]= list[2]
  list[2] = temp
  return list
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n){
        cin >> v[i];
    }
    int ans = 1e9;
    sort(v.begin(),v.end());
    for (int i = 0;i < n-k+1;i++){
        ans = min(ans,v[i+k-1]-v[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
N, x = map(int, input().split())
fav = sorted(map(int, input().split()))
oura=[int()]*N

oura[0] = fav[0]
for i in range(len(fav)-1):
    oura[i+1] = oura[i] + fav[i+1]


sai = 0
for j in range(len(oura)):
    if oura[j] > x:
        sai = j
        break
    elif j != N-1:
        continue
    elif oura[N-1] == x:
        sai = N
    else:
        sai = N-1

print (sai)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int every=0;
void make(){
  int last=0;
  rep(i,999){
    rep(j,10){
      if (i%3==0) last = 20;
      else if(j%2==0) last=19;
      else last = 20;
      rep(k,last){
        every++;
      }
    }
  }
}
int main(){
  int n;
  cin >> n;
  make();
  rep(i,n){
    int y,m,d,count=0,last;
    cin >> y >> m >> d;
    rep(i,y){
      rep(j,10){
        if(i==y && j==m){
          count += d;
          //cout << every << endl;
          cout << every-count+1 << endl;
          break;
        }
        else{
          if(i%3==0) last=20;
          else if(j%2==0) last=19;
          else last = 20;
        }
        rep(i,last) count++;
      }
    }
  }
  return 0;
}




Measured memory_bytes: 3092
n, c = map(int, input().split())
cost = []
grid = []
for i in range(c):
    cost.append(list(map(int, input().split())))
for i in range(n):
    grid.append(list(map(int, input().split())))
div_3 = [[0 for i in range(c+1)] for j in range(3)]
for i in range(n):
    for j in range(n):
        div_3[(i+j+2)%3][grid[i][j]-1] += 1
ans = 10**9
for zero in range(c):
    for one in range(c):
        for two in range(c):
            if len(set([zero,one,two])) <= 2:
                continue
            cand = 0
            #3で割った余りがone,zeroとかの色で決まっている状態
            cand += sum([div_3[0][i] * cost[i][zero] for i in range(c) if i != zero])
            cand += sum([div_3[1][i] * cost[i][one]  for i in range(c) if i != one])
            cand += sum([div_3[2][i] * cost[i][two]  for i in range(c) if i != two])
            ans = min(ans, cand)
print(ans)



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

int main() {
    string S;
    cin >> S;
    if(S == "hi") {
        cout << "Yes" << endl;
    } 
    else if(S == "hihi") {
        cout << "Yes" << endl;
    }
    else if(S == "hihihi") {
        cout << "Yes" << endl;
    }
    else if(S == "hihihihi" ) {
        cout << "Yes" << endl;
    }
    else if(S == "hihihihihi") {
        cout << "Yes" << endl;
    }  
    else {
        cout << "No" <<  endl;
    }
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.ans = n*(n-1)//2

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
    
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        sx = self.size(x)
        sy = self.size(y)
        self.ans += sx*(sx-1)//2 + sy*(sy-1)//2
        self.ans -= (sx+sy)*(sx+sy-1)//2

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

######
N,M = map(int,input().split())
uf = UnionFind(N)
ans = [uf.ans]
pp = [list(map(int,input().split())) for i in range(M)]
for i in range(M,1,-1):
  uf.union(pp[i-1][0]-1, pp[i-1][1]-1)
  ans.append(uf.ans)
for i in range(M-1,-1,-1):
  print(ans[i])

Measured memory_bytes: 34640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
    long long a, b;
    cin >> a >> b;
    if (b == 0) {
	cout << a * a;
	return 0;
    }
    long long ans = 0;
    for (long long i = b + 1; i <= a; ++i) {
	ans += (a + 1) / i * (i - b);
	if ((a + 1) % i >= b) {
	    ans += (a + 1) % i - b;
	}
    }
    cout << ans;
    return 0;
}


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

#define ll long long
#define ar array
#define INF INT_MAX

void solve(){
	int n;
	cin>>n;
	int h[n],dp[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
	}
	dp[0]=0;dp[1]=abs(h[0]-h[1]);
	for (int i = 2; i < n; ++i)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}
	

Measured memory_bytes: 4404
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        Arrays.sort(array);
        // 中央の要素の小さい側 + 1
        int idx = n / 2 - 1;
        int center = array[idx] + 1;
        idx++;
        int cnt = 0;
        while (true) {
            if (array[idx] >= center) {
                cnt++;
            } else {
                break;
            }
            center++;
        }
        System.out.println(cnt);
    }
}


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

using namespace std;

const int nmax = 1e5 + 10;

int n;
int a[nmax], cnt[nmax];
vector < int > g[nmax];

void no_solution() {
    printf("NO\n");
    exit(0);
}

void dfs(int node, int dad) {
    bool leaf = 1;
    for (auto &it : g[node]) {
        if (it == dad) continue;
        leaf = 0; dfs(it, node);
        cnt[node] += cnt[it];
    }

    if (leaf == 1) cnt[node] = a[node];
    else cnt[node] = a[node] * 2 - cnt[node];
}

bool dfs2(int node, int dad) {
    int sum = 0; bool leaf = 1;
    for (auto &it : g[node])
        if (it == dad) sum += cnt[node];
        else leaf = 0, sum += cnt[it];

    if (!leaf)
        for (auto &it : g[node])
            if (it == dad && cnt[node] * 2 > sum) return 0;
            else if (it != dad && cnt[it] * 2 > sum) return 0;

    for (auto &it : g[node]) {
        if (it == dad) continue;
        if (dfs2(it, node) == 0) return 0;
    }

    return 1;
}

int main()
{
    //freopen("input","r",stdin);
    //freopen("output","w",stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i < n; ++i) {
        int x, y; scanf("%d %d", &x, &y);

        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(1, 0);

    if (g[1].size() == 1) cnt[1] -= a[1];
    if (cnt[1] != 0) no_solution();

    for (int node = 2; node <= n; ++node)
        if (cnt[node] < 0) no_solution();

    int root = 1, dad = 0;
    if (g[1].size() == 1) root = g[1][0], dad = 1;
    if (!dfs2(root, dad)) no_solution();

    printf("YES\n");
    return 0;
}


Measured memory_bytes: 10496
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


const int max_comb=210000;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

ll comb(int a, int b){     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(int a, int b){     // P(a,b) = a! * (a-b)!^(-1)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
    }
    return;
}


int main(int argc, char* argv[])
{
    int h,w,a,b;
    scanf("%d%d%d%d", &h, &w, &a, &b);

    pre_comb();
    ll ans = 0;
    int i;
    for(i=0; i<=MIN(h-a-1,w-b-1); i++) {
        ans = (ans + comb(h-a-1+b,b+i) * comb(a+w-b-1,a+i)) %MOD;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3584