akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter
N_MAX = 200000 + 5
INF = 10**9 + 7
sys.setrecursionlimit(N_MAX)
MOD = 10**9 + 7

N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]

Q = int(sys.stdin.readline())

sum = sum(A)

C = Counter(A)

for i in range(Q):
    b, c = map(int, sys.stdin.readline().split())

    # b の数を求める (=c)
    n = C[b]
    # b の合計を求める
    # sum から引く
    sum -= b * n
    C[b] = 0
    # c の合計を求める
    # sum に足す
    sum += c * n
    C[c] += n
    print(sum)


Measured memory_bytes: 24320
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

S = input()

if S[-1] != "s":
    out = S + "s"
else:
    out = S + "es"
print(out)

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

using namespace std;

int a,b,n,ans;

int digsum(int m){
    int ret=0;
    while(m){
        ret+=m%10;
        m/=10;
    }
    return ret;
}

int main(){
    ans=378173829;
    cin>>n;
    a=1;
    b=n-1;
    while(b!=0){
        ans=min(ans,digsum(a)+digsum(b));
        a++;
        b--;
    }
    cout<<ans<<endl;
}

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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;
using EDGE = vector<int>;
using GRAPH = vector<EDGE>;

////////////////////////////////
struct unionfind_rank{
    std::vector<int> data;
    unionfind_rank(int n):data(n,-1){};
    int root(int idx){
        return data[idx]<0?idx:data[idx]=root(data[idx]);
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    bool join(int x,int y){
        x = root(x); y = root(y);
        if(x==y)return false;
        if(data[x]>data[y])std::swap(x,y);
        // data[x] += data[y];
        if(data[x] == data[y])data[x] -= 1;
        data[y] = x;
        return true;
    }
    int rank(int x){
        x = root(x);
        return -data[x] + 1;
    }
};

int main()
{
    int n,q;
    cin >> n >> q;
    unionfind_rank uf(n);
    for(int i=0;i<q;i++){
        int c,x,y;
        cin >> c >> x >> y;
        if(c == 0)uf.join(x,y);
        else cout << (int)uf.same(x,y) << endl;
    }
}


Measured memory_bytes: 3144
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()
S = np.array(list(S), dtype='U1')

ans = INF
for c in S:
    D = np.zeros(len(S), dtype=int)
    cnt = 0
    for i in range(len(S)):
        if S[i] == c:
            cnt = 0
        else:
            cnt += 1
        D[i] = max(D[i], cnt)
    cnt = 0
    for i in reversed(range(len(S))):
        if S[i] == c:
            cnt = 0
        else:
            cnt += 1
        D[i] = max(D[i], cnt)
    ans = min(ans, D.max())
print(ans)


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

int main(){

  long long N, K, S;
  cin>>N>>K>>S;
  
  for(long long i=0; i<N; i++){
    
    if(i<K){
      cout<<S<<" ";
    }else{
      if(S==1000000000){
        cout<<999999999<<" ";
      }else{
        cout<<1000000000<<" ";
      }
    }
  }
  return 0;
}

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

int main(void){
    while(1){
        string x;
        cin >> x;
        if(x == "0") break;
        int sum = 0;
        for(int i = 0; i < x.size(); i++) sum += x[i] - '0';
        cout << sum << endl;
    }
    return 0;
}


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

int main(){
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L.at(i);
  }
  int Ans=10000000;
  int subAns=0;
  for(int i=0; i<(int)pow(4, N); i++){
    int P=i;
    vector<int> result(4);
    vector<int> Num(4);
    subAns=0;
    for(int j=0; j<N; j++){
      result.at(P%4)+=L.at(j);
      Num.at(P%4)++;
      P/=4;
    }
    if(Num.at(0)*Num.at(1)*Num.at(2)!=0){
      subAns=(Num.at(0)+Num.at(1)+Num.at(2)-3)*10+abs(result.at(0)-A)+abs(result.at(1)-B)+abs(result.at(2)-C);
      Ans=min(Ans, subAns);
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


int main(){
	int n,m,ans=0;
    cin>>n>>m;
    if(n>1){
        ans+=n*(n-1)/2;
    }
    if(m>1){
        ans+=m*(m-1)/2;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
//Educational DP Contest P-Independent set
//https://atcoder.jp/contests/dp/tasks/dp_p
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

ll n;
vector<vector<ll>> g(100010);
vector<bool> used(100010,false);

P dfs(ll v,vector<bool> &used){
  used[v]=true;
  if(g[v].size()==1 && used[g[v][0]]) return P(1,2);
  P ret=P(1,1);
  for(auto itr:g[v]){
    if(used[itr]) continue;
    P now=dfs(itr,used);
    (ret.fi*=now.se)%=mod;
    (ret.se*=now.fi)%=mod;
  }
  (ret.se+=ret.fi)%=mod;
  return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n-1){
      ll a,b;
      cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    cout<<dfs(1,used).se<<endl;
}

Measured memory_bytes: 11264
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

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

	string s;
	cin >> s;

	int cnt[26] = {};
	rep(i, sz(s)) {
		cnt[s[i] - 'a']++;
	}
	rep(i, 26) {
		if (cnt[i] & 1) {
			cout << "No" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 384
import Control.Monad
import Control.Applicative

solve ev od = solve' ev od
  where
    solve' :: String -> String -> String
    solve' [] [] = []
    solve' (x:xs) [] = [x]
    solve' (x:xs) (y:ys) = x : y : solve' xs ys

main :: IO ()
main = do
  ev <- getLine
  od <- getLine
  putStrLn $ solve ev od


Measured memory_bytes: 508
N=int(input())
#sum[k:1 to N]floor(N/K)
ans=0
j=1
while(j*(j*1)<=N):
    b=1+(N//j)
    a=1+(N//(j+1))
    tmp=((N//a)*((N//a)+1))//2
    tmpa=(a*(a-1))//2
    tmpb=(b*(b-1))//2
    ans+=(tmpb-tmpa)*tmp
    j+=1
for i in range(1,a):
    ans+=i*((N//i)*((N//i)+1))//2
print(ans)


Measured memory_bytes: 9136
#include <iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    double n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    
 
    
    if(ceil(n/a)*b<ceil(n/c)*d){
        cout<<ceil(n/a)*b<<endl;
    }
    
    else
        cout<<ceil(n/c)*d<<endl;
    
    
    

    

    return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;

typedef unsigned long long ull;

string str;
vector<ull> a;
ull nd[12]={31,28,31,30,31,30,31,31,30,31,30,31};
ull ud[12]={31,29,31,30,31,30,31,31,30,31,30,31};

bool uruY(ull y){
	if(y%400==0)return true;
	if(y%100==0)return false;
	if(y%4==0)return true;
	return false;
}

ull GetDays(ull y,ull m,ull d){
	// 1・2月 → 前年の13・14月
	if (m <= 2){
		--y;
		m += 12;
	}
	ull dy = 365 * (y - 1); // 経過年数×365日
	ull c = y / 100;
	ull dl = (y >> 2) - c + (c >> 2); // うるう年分
	ull dm = (m * 979 - 1033) >> 5; // 1月1日から m 月1日までの日数
	return dy + dl + dm + d - 1;
}

void check(ull maya,ull y){
	y--;
	while(1){
		if(uruY(y)){
			for(ull m=1;m<=12;m++){
				for(ull d=1;d<=ud[m-1];d++){
					if(GetDays(y,m,d)==maya){
						printf("%llu.%llu.%llu\n",y,m,d);
						return;
					}
				}
			}
		}else{
			for(ull m=1;m<=12;m++){
				for(ull d=1;d<=nd[m-1];d++){
					if(GetDays(y,m,d)==maya){
						printf("%llu.%llu.%llu\n",y,m,d);
						return;
					}
				}
			}
		}
		y++;
	}
}
int main(void){
	ull now=GetDays(2012,12,21);
	while(getline(cin,str)){
		if(str=="#")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='.')str[i]=' ';
		}
		stringstream ss(str);
		int in;
		a.clear();
		while(ss >> in){
			a.push_back(in);
		}
		if(a.size()==3){
			ull next=GetDays(a[0],a[1],a[2]);
			//printf("%llu %llu\n",next,now);
			next-=now;
			next=next%(13*20*20*18*20);
			ull ki=next%20;
			next=next/20;
			ull w=next%18;
			next=next/18;
			ull t=next%20;
			next=next/20;
			ull ka=next%20;
			next=next/20;
			ull b=next%13;
			printf("%llu.%llu.%llu.%llu.%llu\n",b,ka,t,w,ki);
		}else{
			ull maya=a[0]*(20*20*18*20);
			maya+=a[1]*(20*18*20);
			maya+=a[2]*(18*20);
			maya+=a[3]*20;
			maya+=a[4];
			maya+=now;
			ull y=2012,m=12,d=21;
			while(GetDays(y,m,d)<maya)y+=400;
			while(GetDays(y,m,d)>maya+365)y--;
			check(maya,y);
		}
	}
    return 0;
}

Measured memory_bytes: 1264
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
//const int MOD = 1000000007;
const int MOD = 998244353;
//const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

int dp[301][90001];

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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	int sum = accumulate(v.begin(), v.end(), 0);
	dp[0][0] = 2;
	dp[0][v[0]] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= 90000; j++) {
			dp[i][j] = dp[i - 1][j] * 2;
			dp[i][j] %= MOD;
		}
		for (int j = v[i]; j <= 90000; j++) {
			dp[i][j] += dp[i - 1][j - v[i]];
			dp[i][j] %= MOD;
		}
	}
	long long int ans = 1;
	for (int i = 0; i < N; i++) {
		ans *= 3;
		ans %= MOD;
	}
	long long int minus = 0;
	for (int i = (sum + 1) / 2; i <= 90000; i++) {
		minus+= dp[N - 1][i];
		minus %= MOD;
	}
	ans -= minus * 3;
	ans += MOD;
	ans += MOD;
	ans += MOD;
	ans %= MOD;
	for (int i = 0; i <= 300; i++) {
		for (int j = 0; j <= 90000; j++)dp[i][j] = 0;
	}
	dp[0][0] = 1;
	dp[0][v[0]] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= 90000; j++) {
			dp[i][j] = dp[i - 1][j];
		}
		for (int j = v[i]; j <= 90000; j++) {
			dp[i][j] += dp[i - 1][j - v[i]];
			dp[i][j] %= MOD;
		}
	}
	if (sum % 2 == 0) {
		ans += dp[N - 1][sum / 2];
		ans %= MOD;
		ans += dp[N - 1][sum / 2];
		ans %= MOD;
		ans += dp[N - 1][sum / 2];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 106112
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <time.h>
using namespace std;
#define sci(n) scanf("%lld", &(n))
#define scd(n) scanf("%Ld", &(n))

typedef long long LL;
typedef pair<LL, LL> PLL;

LL cb[57][75];

LL c(LL n, LL k) {
	if (k > (n / 2)) { k = n - k; }
	if (k<0 || k>n) {
		return 0;
	}
	if (k < 1) {
		return 1;
	}
	if (n == k) {
		return 1;
	}
	LL& ret = cb[n][k];
	if (ret != -1) {
		return ret;
	}
	return ret = (c(n - 1, k) + c(n - 1, k - 1));
}

LL fac(LL n) {
	LL ret = 1;
	if (n == 0) { return 0; }
	while (n >= 1) {ret *= n; n--;}
	return ret;
}

bool isAllSame(vector<LL>& v,LL st, LL fin) {
	return v[st] == v[fin - 1];
}

int main(void)
{
	memset(cb, -1, sizeof(cb));
	LL n, a, b;
	sci(n), sci(a), sci(b);
	vector<LL> v(n,0),prefix(n,0);
	for (int i = 0; i < n; i++) sci(v[i]); 
	sort(v.begin(), v.end(), std::greater<LL>());
	prefix[0] = v[0];
	for (int i = 1; i < n; i++) prefix[i] = prefix[i - 1] + v[i];
	//for (int i = 0; i < v.size(); i++) {printf("%lld ", v[i]);}
	double avg = (double)prefix[a - 1] / a; printf("%lf\n", avg);
	LL ans = 0;
	LL pick = v[0], uni = 0, cnt = 1, samenumcnt = 0;
	map<LL, LL> mp;
	for (int i = 0; i < a; i++) {mp[v[i]]++;}

	for (int i = 0; i < v.size(); i++) {
		if (isAllSame(v, i, a)) {
			uni += 1; 
			if(i<a){
				samenumcnt += 1;
			}
		}
	}
	if (samenumcnt == a) {
		for (int i = a; i <= b; i++) {
			ans += c(uni, i);
		}
	}
	else {	
		ans += c(uni, samenumcnt); 
	}
	time_t st, fin;
	int moroje_ganbatte = 1;
	st = clock();
	for (;;) {
		fin = clock();
		if (fin - st > 19010) {
			break;
		}
		moroje_ganbatte++;
	}
	printf("%lld", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int n,a;
	while(cin >> n,n){
		long long int p = 0;
		vector<long long int> J(n-1);
		for(int i = 0; i < n; i++){
			cin >> a;
			p += a;
		}
		long long int ans = p * n;
		for(int i = 1; i < n; i++){
			cin >> J[i-1];
		}
		sort(J.begin(),J.end());
		for(int i = n - 1; i >= 1; i--){
			p += J[i-1];
			ans = max(ans,p * i);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1716
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,t;
    cin >> n >> t;
    ll a[n],ans=t;
    for (ll i=0;i<n;i++)cin >> a[i];
    for (ll i=1;i<n;i++){
        if (a[i]-a[i-1]<t){
            ans-=t-a[i]+a[i-1];
            ans+=t;
        }else{
            ans+=t;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
from heapq import heappop, heappush

INF = 10 ** 20

def main():
  n = int(input())
  edges = [[] for _ in range(n)]
  for _ in range(n - 1):
    s, t, w = map(int, input().split())
    edges[s].append((w, t))
    edges[t].append((w, s))
  
  def func(start):
    cost = [INF] * n
    que = [(0, start)]
    cost[start] = 0
    
    while que:
      acc, num = heappop(que)
      for weight, to in edges[num]:
        if weight + acc < cost[to]:
          cost[to] = weight + acc
          heappush(que, (weight + acc, to))
    return cost
  
  cost1 = func(0)
  max_ind = cost1.index(max(cost1))
  cost2 = func(max_ind)
  max_ind2 = cost2.index(max(cost2))
  cost3 = func(max_ind2)
  for i in range(n):
    print(max(cost2[i], cost3[i]))
main()


Measured memory_bytes: 11016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x, y, u, v, d[1024][1024] = {};
    ll c[1024][1024] = {1};
    cin >> n >> x >> y >> u >> v;
    for (int i = 1; i <= n; i++) for (int j = 0; j <= i; j++) {
        c[i][j] = c[i - 1][j];
        if (j) {
            c[i][j] += c[i - 1][j - 1];
            if (c[i][j] >= mod) c[i][j] -= mod;
        }
    }
    d[x - 1][0] = 1;
    for (int i = x; i <= y; i++) {
        for (int j = 0; j <= n; j++) {
            d[i][j] = d[i - 1][j];
            for (int k = u; k <= v && j >= i * k; k++) {
                ll w = d[i - 1][j - i * k] * c[n - j + i * k][i * k] % mod;
                for (int l = 0; l < k; l++) w = w * c[i * k - i * l - 1][i - 1] % mod;
                d[i][j] += w;
                if (d[i][j] >= mod) d[i][j] -= mod;
            }
            //cout << d[i][j] << " \n"[j == n];
        }
    }
    cout << d[y][n] << '\n';
}



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

using namespace std;



int main(){
  int n,i,j;
  cin >> n;
  int h[n];
  for(i=0;i<n;i++){
    cin >> h[i];
  }
  string ans = "Yes";

  int maxh[n];
  int max = 0;
  for(i=0;i<n;i++){
    if(max <= h[i]) {
      max = h[i];
      maxh[i] = max;
    }
    else maxh[i] = max;
  }


  for(i=0;i<n;i++){
    if(maxh[i]-h[i] >= 2) ans  = "No";
  }

  cout << ans << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
string s;
int a[300007];
long long x[7],y[7];
int main(){
    int n;
    cin>>n;
    cin>>s;
    int len=s.size();
    for(int i=0;i<len;++i){
        if(s[i]=='B')
            a[i]=1;
        else if(s[i]=='G')
            a[i]=2;
    }
    long long ans=1;
    for(int i=2;i<=n;++i)
        ans=1ll*ans*i%mod;
    for(int i=0;i<len;++i){
        if(y[a[i]])
            ans=ans*y[a[i]]--%mod;
        else if(x[(a[i]+1)%3])
            ans=ans*x[(a[i]+1)%3]--%mod,y[(a[i]+2)%3]++;
        else if(x[(a[i]+2)%3])
            ans=ans*x[(a[i]+2)%3]--%mod,y[(a[i]+1)%3]++;
        else
            x[a[i]]++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1796
import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int d = Integer.parseInt(sc.next());
        
        int[] c = new int[26];
        for(int i=0; i<26; i++){
            c[i] = Integer.parseInt(sc.next());
        }
        
        int[][] s = new int[d][26];
        for(int i=0; i<d; i++){
            for(int j=0; j<26; j++){
                s[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        int[] lastday = new int[26];
        
        long score = 0;
        for(int day=1; day<=d; day++){
            long max = (long)-1e8;
            int maxcontest = -1;
            for(int i=0; i<26; i++){
                long tmp = score + s[day-1][i];
                for(int j=0; j<26; j++){
                    if(i==j){
                        continue;
                    }
                    tmp -= c[j] * (day-lastday[j]);
                }
                if(max < tmp){
                    max = tmp;
                    maxcontest = i;
                }
            }
            
            lastday[maxcontest] = day;
            score = max;
            System.out.println(maxcontest+1);
        }
        
    }
    
}


Measured memory_bytes: 42480
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define LL long long
using namespace std;
 
int n, m, act[5], q[1005];
LL ans, b[1005], a[1005][5];

bool CMP(LL x, LL y) {return x>y;}

void dfs(int x)
{
	if(x==3)
	{
		LL temp=0; memset(b, 0, sizeof(b));
		for(int i=0; i<3; i++)
		{
			if(act[i]==1)
			{
				for(int j=1; j<=n; j++) b[j]+=a[j][i];
			}
			else
			{
				for(int j=1; j<=n; j++) b[j]-=a[j][i];
			}
		}
		sort(b+1, b+n+1, CMP);
		for(int i=1; i<=m; i++) temp+=b[i];
		if(temp>ans) ans=temp;
		return;
	}
	for(int i=1; i<=2; i++)
	{
		act[x]=i;
		dfs(x+1);
	}
}
 
int main()
{
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%lld%lld%lld", &a[i][0], &a[i][1], &a[i][2]);
	dfs(0);
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; char s[100001]; int main(){ scanf("%s",s+1); register int sum=0,l=strlen(s+1),p=0,g=0; for(register int i=1;i<=l;++i) if(s[i]=='g') if(g>p)++sum, ++p; else ++g; else if(g>p) ++p; else --sum,g++; return printf("%d",sum),0;} 


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

typedef long double number;
const number eps = 1e-10;
typedef vector<number> array;
typedef vector<array> matrix;
struct LUinfo {
  vector<number> value;
  vector<int> index;
};
// O( n^3 ), Gaussian forward elimination
LUinfo LU_decomposition(matrix A) {
  const int n = A.size();
  LUinfo data;
  for (int i = 0; i < n; ++i) {
    int pivot = i;
    for (int j = i+1; j < n; ++j)
      if (abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
    swap(A[pivot], A[i]);
    data.index.push_back(pivot);
    // if A[i][i] == 0, LU decomposition failed.
    for(int j = i+1; j < n; ++j) {
      A[j][i] /= A[i][i];
      for(int k = i+1; k < n; ++k)
        A[j][k] -= A[i][k] * A[j][i];
      data.value.push_back(A[j][i]);
    }
  }
  for(int i = n-1; i >= 0; --i) {
    for(int j = i+1; j < n; ++j)
      data.value.push_back(A[i][j]);
    data.value.push_back(A[i][i]);
  }
  return data;
}
// O( n^2 ) Gaussian backward substitution
array LU_backsubstitution(const LUinfo &data, array b) {
  const int n = b.size();
  int k = 0;
  for (int i = 0; i < n; ++i){
    swap(b[data.index[i]], b[i]);
    for(int j = i+1; j < n; ++j)
      b[j] -= b[i] * data.value[k++];
  }
  for (int i = n-1; i >= 0; --i) {
    for (int j = i+1; j < n; ++j)
      b[i] -= b[j] * data.value[k++];
    b[i] /= data.value[k++];
  }
  return b;
}

int n, s, t, a[100][100], d[100][100];
bool sg[100];
int main(){
	while(cin >> n >> s >> t && n){;
		s--; t--;
		rep(i, n) cin >> sg[i];
		rep(i, n) rep(j, n){
			cin >> a[i][j];
			d[i][j] = a[i][j] ? a[i][j] : inf;
		}
		rep(i, n) d[i][i] = 0;
		rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		
		if(d[s][t] == inf){
			cout << "impossible" <<endl;
			continue;
		}
		
		matrix m(n, array(n));
		array e(n);
		
		rep(i, n) if(i != t){
			vi cand;
			rep(j, n) if(a[i][j]){
				if(sg[i] && a[i][j] + d[j][t] != d[i][t]) continue;
				cand.pb(j);
			}
			rep(j, cand.size()){
				m[i][cand[j]] = -1.0l / cand.size();
				e[i] += a[i][cand[j]] * 1.0l / cand.size();
			}
			m[i][i] = 1;
		}
		m[t][t] = 1;
		
		e = LU_backsubstitution(LU_decomposition(m), e);
		
		cout << fixed << setprecision(20) << e[s] << endl;
	}
	return 0;
}

Measured memory_bytes: 2084
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

int main()
{
    int a,b,c;
    cin >> a >> b >> c ;

    p(a*b/2)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}

int main(){
  string s;
  cin>>s;
  ll ans=0;
  ll b=0;
  rep(i,s.size()){
    if(s[i]=='B')b++;
    else ans+=b;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3756
# C
n = int(input()) 
a = list(map(int, input().split()))

from functools import reduce
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

gcd=reduce(gcd,a)
print(gcd)

Measured memory_bytes: 14252
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll x,y,z;

int main(){
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int a, b;
    cin >> a >> b;
    cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible");
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int sum=0,cnt=0;
    vector<int>a;
    while(sum<n){
        sum+=cnt+1;
        a.push_back(cnt+1);
        cnt++;
    }
    for(int x:a){
        if(x!=sum-n)cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    
    double prob[N + 1];
    double dp[N + 1][N + 1], res = 0;
    
    for(int i = 1; i <= N; ++i)
        cin >> prob[i];
        
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j)
            dp[i][j] = 0;
    }    
    
    dp[1][0] = 1.0 - prob[1];
    for(int i = 2; i <= N; ++i)
        dp[i][0] = dp[i - 1][0] * (1.0 - prob[i]);
        
    dp[1][1] = prob[1];
    for(int i = 2; i <= N; ++i)
        dp[i][i] = dp[i - 1][i - 1] * prob[i];
        
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j < i; ++j)
            dp[i][j] = dp[i - 1][j] * (1.0 - prob[i]) + dp[i - 1][j - 1] * prob[i];
    }
    
    
    for(int i = N / 2 + 1; i <= N; ++i)
        res += dp[N][i];
    
   
    cout << fixed << setprecision(10) << res;
    
    return 0;
}


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

void solve(){
    double a, b, x;
    cin >> a >> b >> x;

    constexpr int d = std::numeric_limits<float>::max_digits10;
    if (x <= a * a * b / 2.0) {
        cout << setprecision(d) << (M_PI / 2.0 - atan2(2*x, a * b * b)) * 180.0 / M_PI << endl;
    } else {
        cout << setprecision(d) << (M_PI / 2.0 - atan2(a*a*a, 2*(a*a*b - x))) * 180.0 / M_PI << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

#define S second
#define F first
#define all(a) a.begin() , a.end()
#define pb push_back 
#define DBG cout<<"debug\n";

typedef long long ll;

const int N = 2 * 1e5 + 10;
const ll inf = 9e18 + 9; 

ll res;
ll a[N];

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

void solve(){

    int h , w;
    cin>>h>>w;
    string s[h];

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

    vector<pair<int,int>> pt;

    for(int i = 0; i < h ; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j] == '.') {
                pt.push_back({i,j});
            }
        }
    }

    int dist[h + 1][w + 1];
    int vist[h + 1][w + 1];
    queue<pair<int,int>> q;
    int max_all = 0;
    for(auto i : pt) {

        memset(dist , INT_MAX, sizeof dist);
        memset(vist , 0 , sizeof vist);
        int sx = i.first;
        int sy = i.second;
        vist[sx][sy] = 1;
        dist[sx][sy] = 0;
        q.push({sx ,sy});
        int max_now = 0;
        while(!q.empty()) {
            pair<int , int> p = q.front();
            q.pop();
            int newx = p.first;
            int newy = p.second;

            for(int k = 0; k < 4 ; k++) {
                int x = newx + dx[k];
                int y = newy + dy[k];

                if(x >= 0 && x < h && y >= 0 && y < w &&  vist[x][y] == 0 && s[x][y] == '.') {
                    q.push({x , y});
                    dist[x][y] = dist[newx][newy] + 1;
                    vist[x][y] = 1;
                    max_now = max(max_now , dist[x][y]);
                }
            }
        }

        max_all = max(max_all , max_now);
    }

    cout<<max_all<<"\n";
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

const long long MOD = 1000000007;
long long dp[100010];

int main(void) {
    long long N, M;
    cin >> N >> M;
    std::vector< long long > a(M);
    for (int i = 0; i < M; ++i) {
        cin >> a[i];
    }
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= N; ++i) {
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        // printf("dp[%d] = %lld\n", i, dp[i]);
    }
    long long ans = 1, step = 0;
    for (int i = 0; i < M; ++i) {
        if (step == a[i]) {
            printf("0\n");
            return 0;
        }
        ans  = (ans * dp[a[i] - 1 - step]) % MOD;
        step = a[i] + 1;
    }
    ans = (ans * dp[N - step]) % MOD;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1792
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();

    let mut c: Vec<char> = buf.chars().collect();
    let len = c.len();

    c.sort();
    c.dedup();

    if c.len() == len {
        println!("yes");
    } else {
        println!("no");
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int N;
int m[10][10];

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

    rep(i, 1, N+1) {
        string s = to_string(i);
        int l = s[0] - '0', r = s[s.size()-1] - '0';

        if (l == r) ans++;

        ans += m[r][l]*2;
        
        m[l][r]++;

        


    }


  
    printf("%d\n", ans);

	return 0;
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long 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
#define ll long long int

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0,ans;
    ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='W')cnt++;
    }
    int cnt_2=0;
    for(int j=n-1;j>=n-cnt;j--){
        if(s[j]=='W')cnt_2++;
    }
    cout<<cnt-cnt_2<<"\n";
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int c=0;
    cin>>s>>t;
    if(s[0]==t[0])c++;
    if(s[1]==t[1])c++;
    if(s[2]==t[2])c++;
    printf("%d\n",c);
    return 0;
}


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

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

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

using namespace std;

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

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

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

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

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

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

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

int N, M, K, T, Q, H, W;
signed main() {
	int C;
	cin >> N >> C;
	vector< vector< int > > D(C, vector< int >(C));
	rep(i, C) rep(j, C) cin >> D[i][j];
	vector< vector< int > > grid(N, vector< int >(N));
	rep(i, N) rep(j, N) {
		cin >> grid[i][j];
		--grid[i][j];
	}
	vector< vector< int > > A(3, vector< int >(C, 0));
	rep(i, N) rep(j, N) A[(i + j) % 3][grid[i][j]]++;
	int ans = LINF;
	rep(k1, C) rep(k2, C) if (k1 != k2) rep(k3, C) if (k1 != k3 && k2 != k3) {
		vector< int > to(3);
		to[0] = k1;
		to[1] = k2;
		to[2] = k3;
		int tmp = 0;
		rep(i, 3) {
			rep(j, C) {
				tmp += D[j][to[i]] * A[i][j];
			}
		}
		chmin(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

const int mxN = 1e5+7;
const int INF = 1e9 + 5;

int main() {
	int n, w;
	cin >> n >> w;
	vector<int> val(n), weight(n);
	
	int sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> weight[i] >> val[i];
		sum += val[i];
	}
	
	vector<int> dp(sum + 1, INF);
	int ans = 0;
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = sum; j >= val[i]; j--) {
			//cerr << dp[j] << " " << dp[j-val[i]] + weight[i] << "\n";
			dp[j] = min(dp[j], dp[j - val[i]] + weight[i]);
		}
	}
	
	//cerr << sum << "\n";
	
	for(int i = 0; i <= sum; i++) {
		if(dp[i] <= w) {
			ans = max(ans, i);
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3776
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: 8900
#include<bits/stdc++.h>
using namespace std;

#define int long long

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

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

int N,M;
int P[111111],Y[111111];

vint lis[111111];

signed main(){
    cin>>N>>M;
    rep(i,M){
        cin>>P[i]>>Y[i];
        lis[P[i]].pb(Y[i]);
    }
    rep(i,N)sort(all(lis[i+1]));

    rep(i,M){
        printf("%06lld",P[i]);
        int k=lower_bound(all(lis[P[i]]),Y[i])-lis[P[i]].begin()+1;
        printf("%06lld\n",k);
    }
    return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    ll n,d,a;
    cin >> n >> d >> a;
    vector<PLL> monster(n);
    rp(i,n) {
        ll x,h;
        cin >> x >> h;
        monster.at(i)=mp(x,(h+a-1)/a);
    }
    sort(all(monster));
    ll ans=0;
    ll bom=0;
    queue<PLL> bombed;
    rp(i,n){
        ll pos=monster.at(i).first,life=monster.at(i).second;
        while(!bombed.empty()&&bombed.front().first<pos-d-d){
            PLL pl=bombed.front(); bombed.pop();
            bom -= pl.second;
        }
        if(life<=bom) continue;
        ans += life-bom;
        bombed.push(mp(pos,life-bom));
        bom=life;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 4992
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(target: int, deposit: int) -> int:
    value = deposit
    year = 0
    while value < target:
        value += value // 100
        year += 1
    return year


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    X = int(input())
    result = solve(X, 100)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)


Measured memory_bytes: 82680
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int a = 1, b = 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a *= 3;
    if (x % 2 == 0) b *= 2;
  }
  cout << a - b << endl;
  return 0;
}

Measured memory_bytes: 256
def Sieve_of_Eratosthenes(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime

n,p=map(int,input().split())


if n>50: print(1)
elif n==1: print(p)
else:
    prime=Sieve_of_Eratosthenes(int(p**(1/n)))
    ans=1
    for i in range(2,len(prime)):
        if prime[i]==False: continue
        tmp=0
        while p%i==0:
            p//=i
            tmp+=1
        for _ in range(tmp//n):
                ans*=i
    print(ans)

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

main(){
  string n;
  cin >> n;
  if (n[0]=='1') n[0]='9';
  else n[0]='1';
  if (n[1]=='1') n[1]='9';
  else n[1]='1';
  if (n[2]=='1') n[2]='9';
  else n[2]='1';

cout << n << endl;
}


Measured memory_bytes: 256
I=lambda:map(int,input().split())
n,q=I()
e=[[]for _ in range(n)]
d=[0]*n
for _ in range(n-1):
    a,b=I()
    e[a-1]+=b-1,
    e[b-1]+=a-1,
for _ in range(q):
    p,x=I()
    d[p-1]+=x
f=[1]+[0]*n
q=[0]
while q:
    v=q.pop()
    for w in e[v]:
        if f[w]:continue
        f[w]=1
        d[w]+=d[v]
        q+=w,
print(*d)

Measured memory_bytes: 55828