akhauriyash/Code-Regression huggingface dataset:
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}


ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll get(map<pair<ll,ll>,ll>& m, ll a, ll b) {
    auto p = make_pair(a, b);
    if (m.find(p) == m.end()) return 0;
    ll c = m[p];
    m[p] = 0;
    return c;
}

void solve()
{
    IN(n);
    map<pair<ll,ll>,ll> m;
    ll temp = 0;
    rep(i, n) {
        IN(a, b);
        if (a == 0 || b == 0) {
            if (a != 0) {
                m[make_pair(1, 0)] += 1;
                continue;
            } else if (b != 0) {
                m[make_pair(0, 1)] += 1;
                continue;
            }
            temp++;
            continue;
        }
        ll g = gcd(a, b);
        m[make_pair(a/g, b/g)] += 1;
    }
    vector<pair<ll,ll>> keys;
    for (auto&& t : m) {
        keys.emplace_back(t.first.first, t.first.second);
    }
    vector<pair<ll,ll>> v;
    rep (j, keys.size()) {
        auto& t = m[keys[j]];
        if (t == 0) continue;
        ll n1 = get(m, keys[j].second, -keys[j].first);
        ll n2 = get(m, -keys[j].second, keys[j].first);
        v.emplace_back(t, n1+n2);
    }
    ll s = 1;
    rep(i, v.size()) {
        if (v[i].second == 0) {
            s = (s * modpow(2, v[i].first, MOD)) % MOD;
        } else {
            s = (s * ((modpow(2, v[i].first, MOD) + modpow(2, v[i].second, MOD) + MOD - 1) % MOD)) % MOD;
        }
    }
    cout << (s + MOD + temp - 1) % MOD << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 24776
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N);
    readvec(a);

    int ans = llabs(W - a[N - 1]);
    if(N >= 2) ans = max(ans, llabs(a[N - 1] - a[N - 2]));

    cout << ans; 
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int digitsum(int x) {
	int sum = 0;
	while (x > 0) {
		sum += x % 10;
		x /= 10;
	}
	return sum;
}
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		int res = digitsum(i);
		if (A <= res && res <= B) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    string s, t; cin >> s >> t;
    int cnt = 0;
    REP(i, 3) {
        if(s[i] == t[i]) 
            cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
def trans(mp):
  ret = [[None] * 9 for _ in range(9)]
  for x in range(9):
    for y in range(9):
      ret[x][y] = mp[y][x]

  return ret

def fix(mp):
  fix_lst = []
  mp2 = trans(mp)
  for i in range(9):
    for j in range(9):
      if mp[i].count(mp[i][j]) > 1:
        fix_lst.append((i, j))
      if mp2[i].count(mp2[i][j]) > 1:
        fix_lst.append((j, i))

  for ulx in (0, 3, 6):
    for uly in (0, 3, 6):
      tmp = []
      for dx in (0, 1, 2):
        for dy in (0, 1, 2):
          tmp.append(mp[ulx + dx][uly + dy])

      for dx in (0, 1, 2):
        for dy in (0, 1, 2):
          if tmp.count(mp[ulx + dx][uly + dy]) > 1:
            fix_lst.append((ulx + dx, uly + dy))
  
  fix_lst = list(set(fix_lst))
  for x, y in fix_lst:
    mp[x][y] = "*"  + mp[x][y]

  return mp

def _rj(c):
  return c.rjust(2)

def print_mp(mp):
  for line in mp:
    print("".join(map(_rj, line)))

n = int(input())
for i in range(n):
  if i != 0:
    print()
  mp = [input().split() for _ in range(9)]
  mp = fix(mp)
  print_mp(mp)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

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

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

ll n;

void solve(){
 cin >> n;
 vs s(n);
 map<string,ll> mp;
  rep(i,0,n) {
   cin >> s[i];
   mp[s[i]]++;
 }
  
  ll ans=0;
  for(auto p:mp) ans++;
  
   cout << ans << endl;
 
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 25072
#include <iostream>

using namespace std;

int countAB(int n, int x);
int countABC(int n, int x);
bool calABC(int n, int x, int& a, int& b, int& c);

int countABC(int n, int x) {
	
	int a, b, c;
	int count = 0;
	if (calABC(n, x, a, b, c)) {
		
		while (c > 0) {
			count += countAB(c - 1, x - c);
			c--;
		}
		return count;
	}
	else {
		return 0;
	}
	
}

int countAB(int n, int x) {

	int count = 0;
	int a = 1, b = n;
	
	if (n * 2 - 1 < x) return 0;

	if (n < x) {
		a = x - n;
	}
	else {
		b = x - 1;
	}

	return (b - a + 1) / 2;
}


bool calABC(int n, int x, int &a, int &b, int &c) {

	if (x < 6) return false;
	if (n < 3) return false;
	if ((n - 1) * 3 < x) return false;

	a = 1; b = 2; c = n;

	while (true) {
		if (a + b + c == x) return true;

		if (a + b + c > x) {
			if (c > b + 1) c--;
			else return false;
		}
		else { //a+b+c < x
			if (b < c - 1) {
				b++;
			}
			else if (b == c - 1) {
				if (a < b - 1) {
					a++;
				}
				else if (a == b - 1)
					return false;
			}
		}
	}
}

int main() {

	int n, x;

	while (true) {

		cin >> n >> x;

		if (n == 0 && x == 0) break;

		cout << countABC(n, x) << endl;

	}
	return 0;
}



Measured memory_bytes: 3076
#include<stdio.h>

int main(void)
{
int a,b,c,w;

scanf("%d %d %d",&a,&b,&c);

if(a>b)
{
w=a;
a=b;
b=w;
}
if(a>c)
{
w=a;
a=c;
c=w;
}
if(b>c)
{
w=b;
b=c;
c=w;
}

printf("%d %d %d\n",a,b,c);

return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int in[11][11]={0};
int main(){
int n;
while(cin>>n,n){
rep(i,n){
int sum=0,j;
for(j=0;j<n;j++){
int tmp;
cin>>tmp;
sum+=tmp;
in[i][j]=tmp;
printf("%5d",tmp);
}
in[i][j]=sum;
printf("%5d\n",sum);
}

rep(i,n+1){
int sum=0;
rep(j,n){
sum+=in[j][i];
}
if(i!=n)printf("%5d",sum);
else printf("%5d\n",sum);
}
}
}

Measured memory_bytes: 1160
package main

import "fmt"

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

	var min = (N / X)

	var jud = float64(N % X)
	if jud > 0{
		min++
	}

	var res = min * T

	fmt.Println(res)
}

Measured memory_bytes: 1768
#include <iostream>
#include <string>

using namespace std;

int main(void){

    int N;
    string S;
    int count = 1;

    cin >> N;
    cin >> S;

    for(int i = 1; i < S.length(); i++){
        if(S[i] != S[i - 1])
            count++;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 1e6
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
 
int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int min(int a, int b){
    if(a<b)
        return a;
    return b;
}
 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

int mod = 1e9 + 7;

int32_t main(){
	// int n, k;
	// cin>>n>>k;
	// int a[n+1];
	// for(int i=1;i<=n;i++){
	// 	cin>>a[i];
	// }
	// //no of ways with k stones and upto ith person
	// int dp[n+1][k+1];
	// for(int i=0;i<=n;i++){
	// 	dp[i][0] =1;
	// }
	// for(int i=1;i<=n;i++){
	// 	for(int st = 1; st<=k; st++){
	// 		int ans = 0;
	// 		for(int v = 0; v<= a[i] && st - v >=0; v++){
	// 			ans += dp[i-1][st - v];
	// 			if(ans > mod)
	// 				ans -= mod;
	// 		}
	// 		dp[i][st] = ans;
	// 	}
	// }
	// cout<<dp[n][k]<<endl;
	
	int n, k;
	cin>>n>>k;
	int a[n+1];
	a[0] = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
    int dp[k+1];
    //0 stones and 0 children initially so 1 way is nothin
	dp[0] = 1;
    //for more than 1 stones but no children there is no way
    for(int i=1;i<=k;i++)
        dp[i] = 0;
	//ex if we have 4 stone and the cap on the last person is 3
	//dp[4] will appear in the foll terms dp[5] -- when last person eats 1
	//dp[6] when last person eats 2
	//dp[7] when last person eats 3
	for(int c = 1; c<=n;c++){//for each subsequent child
		int lim = a[c]; //the last child can be awarded 1...lim candies
		int temp[k+2] = {0};
		for(int st = 0; st <= k; st++){//we are seeing which stone influnces which answer
			int lo = st + 1;
			int hi = min(k, st + lim);
			temp[lo] += (dp[st]);
            if(temp[lo] >= mod)
                temp[lo] -= mod;
			temp[hi + 1] -= (dp[st]);
            temp[hi + 1] += mod;
            if(temp[hi + 1] >= mod)
                temp[hi + 1] -= mod;
		}
		//prefix sum
		int sum = 0;
		for(int i=0;i<=k;i++){
			sum += temp[i];
            if(sum >= mod)
                sum -= mod;
			dp[i] += sum;
            if(dp[i] >= mod)
                dp[i] -= mod;
		}
	}
	cout<<dp[k]<<endl;


	
}











Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb push_back


int main(){
    int N,ans=0,last,now;
    cin >> N >> last;
    rep(i,N-1){
        cin >> now;
        if(last == now) ++ans;
        last = last==now?-1:now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >>S;
        int count=0;
        int countb=0;
    if(S.size()%2==0){
        for(int i=0;i<S.size();i+=2){
            if(S.at(i)=='0'){
                count++;
            }
            if(S.at(i+1)=='1'){
                count++;
            }
        }
        for(int i=0;i<S.size();i+=2){
            if(S.at(i)=='1'){
                countb++;
            }
            if(S.at(i+1)=='0'){
                countb++;
            }
        }
    }
    else{
        for(int i=0;i<S.size();i+=2){
            if(S.at(i)=='1'){
                count++;
            }
        }
        for(int i=1;i<S.size();i+=2){
            if(S.at(i)=='0'){
                count++;
            }
        }
        for(int i=0;i<S.size();i+=2){
            if(S.at(i)=='0'){
                countb++;
            }
        }
        for(int i=1;i<S.size();i+=2){
            if(S.at(i)=='1'){
                countb++;
            }
        } 
    }
    cout <<min(count,countb)<<endl;
    
}

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

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const int inf = 1e9;
const int mod = 1e9 + 7,
N = 2e5 + 11;

int L, n;
struct edge{
    int u, v, w;
    edge() {}
    edge(int _u, int _v, int _w) {
        u = _u, v = _v, w = _w;
    }
};
vector <edge> ans;
int main() {
    #ifdef makacha
        //Test();
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    read(L);
    n = __lg(L) + 1;
    for (int i = 1; i < n; i++) {
        ans.push_back(edge(i, i + 1, 0));
        ans.push_back(edge(i, i + 1, 1 << i - 1));
    }
    if ((1 << n - 1) != L)
        for (int i = 1; i < n; i++)
            if ((L >> i - 1 & 1)) {
                L -= 1 << i - 1;
                ans.push_back(edge(i, n, L));
            }
    cout << n << ' ' << ans.size() << '\n';
    for (auto e: ans)
        cout << e.u << ' ' << e.v << ' ' << e.w << '\n';
}


Measured memory_bytes: 256
def main():
    N,M,X = [int(x) for x in input().split()]
    Cl,All = [],[]
    for i in range(N):
        tmp = [int(x) for x in input().split()]
        Cl.append(tmp[0])
        All.append((tmp[1:]))
    # print(Cl)
    # print(All)
    min_cost = sum(Cl) + 1
    for bit in range(1,1<<N):
        # print(bin(bit))
        cost = 0
        totalAl = [0]*M
        for i,al in enumerate(All):
            if (1<<i) & bit:
                # print(i)
                for j,a in enumerate(al):
                    totalAl[j] += a
                cost += Cl[i]
        check = True
        for a in totalAl:
            if a < X:
                check = False
        if check:
            min_cost = min(min_cost, cost)
    if min_cost > sum(Cl):
        print(-1)
    else:
        print(min_cost)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << fixed << setprecision(10);
    LL n, x, y;
    cin >> n >> x >> y;

    vector<LL> ret(n,0);

    REP(i, n-1)
    {
        FOR(j, i+1, n)
        {
            // 橋を使うパターン
            LL use_bridge = abs((x-1) - i);  // 橋までの距離
            use_bridge += 1;            // 橋の長さ
            use_bridge += abs((y-1) - j);

            // 橋を使わないパターン
            LL nouse_bridge = j - i;

            // 近い方を採用する
            LL ret_temp = (nouse_bridge > use_bridge) ? use_bridge : nouse_bridge;
            ret.at(ret_temp)++;
        }
    }

    FOR(i, 1, n)
    {
        cout << ret.at(i) << endl;
    }

    return 0;
}


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

int main() {
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> point(n+1,k-q);
  rep(i,0,q) {
    int a;
    cin >> a;
    point[a] += 1;
  }
  rep(i,1,n+1) {
    if (point[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3784
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	rep2(i, 1, n) {
		int sum = 0;
		sum += i / 10000;
		sum += (i % 10000) / 1000;
		sum += ((i % 10000) % 1000) / 100;
		sum += (((i % 10000) % 1000) % 100) / 10;
		sum += (((i % 10000) % 1000) % 100) % 10;
		if (a <= sum && sum <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const int N = 2000 + 5;

int n, k;
int ret;
vector<int> adj[N];
int dp[N][N];
int maxd[N];

void dfs(int u, int f = -1)
{
    dp[u][0] = 1;
    maxd[u] = 0;
    for(auto v: adj[u]) {
        if (v == f) continue;
        dfs(v, u);
        static int tmp[N];
        int nd = max(maxd[u], maxd[v] + 1);
        for(int i = 0; i <= nd; ++ i) tmp[i] = dp[u][i];
        for(int i = 0; i <= maxd[u]; ++ i) {
            for(int j = 0; j <= maxd[v]; ++ j) {
                if (i + j + 1 > k) continue;
                int ni = max(i, j + 1);
                tmp[ni] = max(tmp[ni], dp[u][i] + dp[v][j]);
            }
        }
        maxd[u] = nd;
        for(int i = 0; i <= nd; ++ i) dp[u][i] = tmp[i];
    }
    for(int i = 0; i <= maxd[u]; ++ i) {
        ret = min(ret, n - dp[u][i]);
    }
    /*
    cout << "!! " << u << endl;
        cout << dp[u][i] << ' ';
    }
    cout << endl;
    */
}

void solve()
{
    cin >> n >> k;
    ret = n;
    for(int i = 0; i < n - 1; ++ i) {
        int u, v;
        scanf("%d%d", &u, &v);
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0);
    cout << ret << endl;
}

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


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

int main() {
	
	int ab, bc, ca;
	cin >> ab >> bc >> ca;
	cout << ab * bc / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
s = input()
mod = 10**9+7

dp = [[0]*4 for i in range(len(s)+1)]
dp[0][0] = 1
for i in range(len(s)):
    
    if s[i] == "A":
        dp[i+1][1] += dp[i][0]
    elif s[i] =="B":
        dp[i+1][2] += dp[i][1]
    elif s[i] == "C":
        dp[i+1][3] += dp[i][2]
    else:
        dp[i+1][1] += dp[i][0]
        dp[i+1][2] += dp[i][1]
        dp[i+1][3] += dp[i][2]
    for j in range(4):
        if s[i] == "?":
            dp[i+1][j] = (dp[i+1][j]+dp[i][j]*3)%mod
        else:
            dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod


print(dp[-1][3]%mod)



Measured memory_bytes: 27632
#include <iostream>
#include <algorithm>
#include <vector>

int h, w, k;
char grid[6][7];

int countCases(int rCount, int cCount)
{
    int result = 0;

    std::vector<bool> rowCh(h);
    std::fill(rowCh.begin(), rowCh.end(), false);
    std::fill(rowCh.end() - rCount, rowCh.end(), true);

    do
    {
        std::vector<bool> colCh(w);
        std::fill(colCh.begin(), colCh.end(), false);
        std::fill(colCh.end() - cCount, colCh.end(), true);

        do
        {
            int black = 0;
            for (int i = 0; i < h; ++i)
                for (int j = 0; j < w; ++j)
                    if (!rowCh[i] && !colCh[j] && grid[i][j] == '#')
                        ++black;
            if (black == k)
                ++result;
        } while (std::next_permutation(colCh.begin(), colCh.end()));
    } while (std::next_permutation(rowCh.begin(), rowCh.end()));

    return result;
}

int main()
{
    scanf("%d %d %d", &h, &w, &k);

    for (int i = 0; i < h; ++i)
        scanf("%s", grid[i]);
    
    int black = 0, white = 0;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (grid[i][j] == '.')
                ++white;
            else ++black;
        }
    }

    int result = 0;
    for (int rCount = 0; rCount < h; ++rCount)
        for (int cCount = 0; cCount < w; ++cCount)
            result += countCases(rCount, cCount);
    
    printf("%d", result);

    return 0;
}

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

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

if ( a > b ){
tmp = a;
a = b;
b = tmp;
}

if ( b > c ){
tmp = b;
b = c;
c = tmp;
}

if ( a > b ){
tmp = a;
a = b;
b = tmp;
}

cout<< a << " " << b << " " << c << endl;

}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
 
using namespace std;
const ll maxn=1e6+100,inf=1e18,LOG=23,mod=1e9 + 7;

#define bt(i) (1 << (i))
#define int ll

int n, m, used[maxn], dp[maxn];
vector <int> ist, edge[maxn], rev[maxn];

void dfs(int v)
{
	used[v] = 1;
	FOR(0, i, edge[v].size())
	{
		int to = edge[v][i];
		if(used[to] == 1) continue;
		dfs(to);
	}
	ist.pb(v);
}

main()
{
	cin >> n >> m;
	forn(1, i, m)
	{
		int l, r;
		cin >> l >> r;
		edge[l].pb(r);
		rev[r].pb(l);
	}
	forn(1, i, n)
	{
		if(used[i]) continue;
		dfs(i);
	}
	int ans = 0;
	reverse(all(ist));
	FOR(0, i, ist.size())
	{
		int v = ist[i];
		FOR(0, j, rev[v].size())
		{
			int to = rev[v][j];
			dp[v] = max(dp[v], dp[to] + 1);
		}
		ans = max(dp[v], ans);
	}
	cout << ans;
}

Measured memory_bytes: 61432
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> ma;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  s = "ACL";

  rep(i, 0, n)
  {
    t += s;
  }
  out(t);
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int h,w;
string s;
vector<string> s1;
int main()
{
    cin>>h>>w;
    for(int i=0;i<h;++i)
    {
        cin>>s;
        s1.push_back(s);
        s1.push_back(s);
    }
    for(int i=0;i<s1.size();++i)
        cout<<s1[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        long res = (long) (fastExp(2, n) - 1);
        res -= (choose(n, a));
        if (res < 0) {
            res += 1000000007;
            res = res % 1000000007;
        }
        res -= (choose(n,b));
        if (res < 0) {
            res += 1000000007;
            res = res % 1000000007;
        }
        System.out.println(res);
    }

    static long choose(int a, int b) {
        long mod = 1000000007;
        long top = 1;
        long bot = 1;
        if ((a - b) > b) {
            for (int i=((a-b)+1);i<=a ;i++) {
                top = (top * i) % mod;
            }
            for (int j=1; j<=b;j++) {
                bot = (bot*j) % mod;
            }
        } else {
            for (int j=(b+1);j<=a ;j++) {
                top = (top*j) % mod;
            }
            for (int i=1;i<=(a-b);i++) {
                bot = (bot*i) % mod;
            }
        }
        return ((top * (fastExp(bot, 1000000005))) % mod);
    }

    static long fastExp(long base, long power) {
        long mod = 1000000007;

        if (power == 0) {
            return 1;
        }
        long ans = fastExp(base, (power/2));
        if (power % 2 == 1) {
            long temp = (ans*base) % mod;
            return (temp*ans) % mod;
        } else {
            return (ans*ans) % mod;
        }
    }
}


Measured memory_bytes: 24148
N, Y = map(int, input().split())
flag = False

for x in range(N+1):
    if flag == True:
        break
    for y in range(N-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y) == Y:
            print(x, y, N-x-y)
            flag = True
            break

if flag == False:
    print(-1, -1, -1)

Measured memory_bytes: 9200
number = gets.to_i

t1,x1,y1 = 0,0,0

judge = "Yes"

number.times do
  s = gets
  
  t2,x2,y2 = s.split.map(&:to_i)
  t = t2 - t1
  d = (x2 - x1).abs + (y2 - y1).abs
  if d <= t && (t - d).even?
    t1 = t2
    x1 = x2
    y1 = y2
  else
    judge = "No"
    break
  end
end
puts judge

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



int main(void){
    // Your code her
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if((abs(b-a)<=d  && abs(c-b)<=d) || abs(c-a)<=d)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<char> S(N);
    for (int i = 0; i < N; i++) {
      cin >>S.at(i);
    }
  
  int x = 0;
  
  vector<int> X(N+1);
  X.at(0) = 0;
  for (int i = 1; i < N+1; i++) {
    if (S.at(i-1) == 'I') {
      x++;
      X.at(i) = x;
    }
    else {
      x--;
      X.at(i) = x;
    }
  }
  sort(X.begin(), X.end());
  cout << X.at(N) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < n-1; i++){
		int count1[26] = {};
        int count2[26] = {};
		for (int j = 0; j <= i; j++){
			count1[s[j] - 'a']++; 
		}
		for (int j = i+1; j < n; j++){
		    count2[s[j] - 'a']++; 
		}
		int count3 = 0;
		for (int j = 0; j < 26; j++){
		    if (count1[j] > 0 && count2[j] > 0){
			   count3++;
		    }
		    if (count3 >= ans){
			   ans = count3;
		    }
	    }
	}
	cout << ans << endl;
    return 0;
}


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

using namespace std;

const int maxn=1e6+5;

typedef long long ll;

const ll mod=1e9+7;

ll a[maxn];

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	} 
	sort(a,a+n);
	ll sum=0;
	for(int i=0;i<n-k;i++){
		sum+=a[i];
	}
	printf("%lld",sum);
	return 0;
} 

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    Graph g(n);
    for (int i = 0; i < n - 1; ++i) {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    vector<int> ans(n);
    // スタート位置はjから
    for (int j = 0; j < n; ++j) {
        vector<int> dist(n, -1);
        queue<int> que;
        dist[j] = 0;
        que.push(j);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int nv : g[v]) {
                if (dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        for (int i : dist) {
            ans[i]++;
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << ans[i] / 2 << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  int p = 0;
  int w = 0;
  int g = 0;
  int y = 0;
  
  for (int i = 0; i < N; i++){
    string Si;
    cin >> Si;
    
    if (Si == "P"){
	  p++;
    }
    else if (Si == "W"){
      w++;
    }
    else if (Si == "G"){
      g++;
    }
    else if (Si == "Y"){
      y++;
    }
  }
  if (p > 0 && w > 0 && g > 0 && y > 0){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}


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

typedef long long ll;
const ll INF=1e12;
using namespace std;
int main()
{
	string s1,s2;cin>>s1>>s2;
	vector< vector<ll> > dp(1001,vector<ll>(1001,0));
	int len1=s1.length(),len2=s2.length();
	
	for(int i=1;i<=len1;i++) dp[i][0]=i;
	for(int j=1;j<=len2;j++) dp[0][j]=j;
	for(int  i=1;i<=len1;i++){
			for(int j=1;j<=len2;j++){
				dp[i][j] = min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+(s1[i-1]!=s2[j-1]));
			}
	}
	cout<<dp[len1][len2]<<endl;
}

Measured memory_bytes: 10860
<?php

fscanf(STDIN, "%s", $S);
$list = str_split($S);
$buf=[0,0];
foreach($list as $no => $str){
    if($str === $buf[0] || $str === $buf[1]){
        if($no > 1){
            echo ($no-1)." ".($no + 1);
            exit;
        }else{
            if(count($list) == 2){
                echo "1 2";
                exit;
            }
            echo "1 3";
            exit;
        }

    }else{
        $buf = [$buf[1], $str];
    }

}
echo "-1 -1";


Measured memory_bytes: 22160
N, K = list(map(int, input().split()))
# print(N)
# print(K)
h_list = [0]*100000
i = 0
for i in range(N):
    x = int(input())
    h_list[i] = x
    x = 0
j = 0
min = 1000000000
for i in range(100000 - N):
    h_list.remove(0)
# print(h_list)
h_list.sort()
# print(h_list)
y = 0
q = 0
while q < N-K+1:
    y = h_list[q + K-1] - h_list[q]
#    print(q)
#    print(h_list[q+K-1], h_list[q])
    if y < min:
        min = y
        y = 0
    else:
        y = 0
    q += 1
print(min)



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

using namespace std;

int main() {
   vector<int> arr(3);
   for (int i = 0; i < 3; ++i) {
      cin >> arr[i];
   }
   sort(arr.begin(), arr.end());
   if ((arr[0] == arr[1] && arr[1] != arr[2]) || (arr[1] == arr[2] && arr[0] != arr[1])) {
      cout << "Yes" << endl;
   } else cout << "No" << endl;
}


Measured memory_bytes: 256
h, w = list(map(int, input().split()))
s = ['.'*(w+2)]

for i in range(h):
	s.append('.'+input()+'.')
s.append('.'*(w+2))

ans = True

for i in range(1, h+1):
	for j in range(1, w+1):
		if s[i][j]=='#':
			if s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j-1]=='.' and s[i][j+1]=='.':
				ans = False

print('Yes' if ans else 'No')


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int n;
    int l[10];
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&l[i]);
    int max=0;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        if(max<l[i]) max=l[i];
        sum+=l[i];
    }
    printf("%s\n",(sum-max)>max?"Yes":"No");
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String args[]) throws IOException {
        FastReader s = new FastReader();
        int a = s.nextInt();
        int b = s.nextInt();
        if(a%2==1 && b%2==1){
            System.out.println("Odd");
        }else{
            System.out.println("Even");
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21076
import java.util.Scanner;
 
public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int h = scan.nextInt(), n = scan.nextInt();
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum+=scan.nextInt();
		}
		if (sum >= h) {
			System.out.println("Yes");	
		} else {
			System.out.println("No");
		}

	}
}

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

int main(){
	int N;
	long long ans=0;
	cin >> N;
	vector<string> S(N);
	for(auto &i:S)cin >> i;
	
	for(auto &i:S)sort(i.begin(),i.end());
	sort(S.begin(),S.end());
	
	long long c=1;
	for(int i=0;i<N;i++){
		if(i==N-1){
			ans+=c*(c-1)/2;
		}
		else if(S[i]==S[i+1])c++;
		else{
			ans+=c*(c-1)/2;
			c=1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

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

  i=1;
  int p=a[0];
  while (p!=2 && i<n) {
    p=a[p-1];
    i++;
  }

  cout << (i==n ? -1: i) << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[500][500],arr[500],p[500];
int solve(int i,int j)
{
	if(i==j)
		return 0;
	if(i>j)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	else
	{
		int temp=1e18;
		for(int k=i;k<j;k++)
			temp=min(temp,solve(i,k)+solve(k+1,j)+p[j]-p[i-1]);
		dp[i][j]=temp;
	}
	return dp[i][j];
}
signed main()
{
	int n;
	cin>>n;p[0]=0;
	for(int i=1;i<=n;i++)
	{
		p[i]=0;
		cin>>arr[i];
		p[i]=p[i-1]+arr[i];
	}
	memset(dp,-1,sizeof dp);
	cout<<solve(1,n)<<endl;
	return 0;
}

Measured memory_bytes: 2176
n, k = map(int, input().split())
s = input()

i = 0
ss = list()
while i < n:
    cnt = 1
    c = s[i]
    while i < n-1 and s[i] == s[i+1]:
        cnt += 1
        i += 1
    i += 1
    ss.append((c, cnt))

ans = 0
if len(ss) // 2 >= k:
    for j in range(k):
        ss[2 * j + 1] = ('L', ss[2*j+1][1]) if ss[2*j+1][0] == 'R' else ('R', ss[2*j+1][1])
    s = ''.join([''.join([x[0] for _ in range(x[1])]) for x in ss])
    for x in range(len(s)-1):
        if s[x] == s[x+1]:
            ans += 1
else:
    ans = len(s) - 1
print(ans)

Measured memory_bytes: 56240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)

#define PI 3.14159265358479

int main(){
	REP(i, 9){
		REP(j, 9){
			cout << i + 1 << "x" << j + 1 << "=" << (i + 1)*(j + 1) << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1112
x, y = [int(i) for i in input().split()]
mon = 0
money = [300000, 200000, 100000]
if x -1 < 3:
    mon += money[x-1]
if y -1 < 3:
    mon += money[y-1]
if x == y and x == 1:
    mon += 400000
print(mon)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
int n,a[200001];
long long sum=0;
int Abs(int a){return a>0?a:-a;}
using namespace std;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);a[i]-=i;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		sum+=1ll*Abs(a[i]-a[n/2]);
	}
	printf("%lld",sum);
}

Measured memory_bytes: 896
import heapq
from heapq import heappush,heappop

class Heap1D:
    def __init__(self, shift=20):
        self.shift = shift
        self.data = []
        self.mask = (1<<shift)-1
    
    def push(self, x):
        a, b = x
        heapq.heappush(self.data, (a<<self.shift) | b)
    
    def pop(self):
        a = heapq.heappop(self.data)
        b = a & self.mask
        a >>= self.shift
        return a,b
      
    def __len__(self):
        return len(self.data)
      
def dijkstra(start = 0):
    d = [INF for i in range(len(G))]
    d[start] = 0
    que = Heap1D()
    que.push((0, start))

    while len(que):
        p = que.pop()
        v = p[1]
        if d[v] < p[0]:
            continue
        for u in G[v].keys():
            if d[u] > d[v] + G[v][u]:
                d[u] = d[v] + G[v][u]
                que.push((d[u], u))
    return d

N,M,S=map(int,input().split())
edges = [tuple(map(int,input().split())) for _ in range(M)]
cd = [tuple(map(int,input().split())) for _ in range(N)]
INF= 10**15
mod=55

mmax = sum([edges[i][2] for i in range(M)])
if S>mmax:
  S = mmax

G=[{} for _ in range((mmax+1)*mod+N+1)]
for i in range(M):
  u,v,a,b=edges[i]
  for p in range(a,mmax+1):
    G[u+p*mod][v+(p-a)*mod] = b
    G[v+p*mod][u+(p-a)*mod] = b
    
for i in range(N):
  c,d=cd[i]
  for p in range(mmax+1-c):
    G[i+1+p*mod][i+1+(p+c)*mod] = d
  
start = 1+S*mod
d = dijkstra(start)

ans=[INF]*(N+1)
for i in range(2,len(G)+1):
  v = i%mod
  if v>N or v<2:continue
  ans[v] = min(ans[v],d[i])
  
print(*ans[2:])

Measured memory_bytes: 81512
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int n, k;
    cin >> n >> k;

    int ans = 0;
    while (n >= k) {
        ans += 1;
        n /= k;
    }

    print(1 + ans);

    return 0;
}



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

int main()
{
  int a;
  int b;
  int x;
  int y;
  int z;
  int s;
  int count;
  
  cin >> a >> b;
  
  count = 0;
  x = 1;
  while (x <= 9)
  {
    y = 0;
    while (y <= 9)
    {
      z = 0;
      while (z <= 9)
      {
        s = 10000*x + 1000*y + 100*z + 10*y + x;
        if(a <= s && s <= b)
          count++;
        z++;
      }
      y++;
    }
    x++;
  }
  cout << count<< endl;  
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
vector<pii >a,b;
ll ans;
int t,n,k,l,r;
multiset<int>s;
inline void f(vector<pii >&v){
	sort(v.begin(),v.end());
	s.clear();
	for(int i=0;i<v.size();i++){
		pii x=v[i];
		s.insert(x.sec);
		ans+=x.sec;
		while(s.size()>x.first){
			ans-=*s.begin();
			s.erase(s.begin());
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n;
		ans=0;
		a.clear(),b.clear();
		for(int i=1;i<=n;i++){
			cin>>k>>l>>r;
			if(l>r)a.pb(m_p(k,l-r));
			if(l<r)b.pb(m_p(n-k,r-l));
			ans+=min(l,r);
		}
		f(a),f(b);
		cout<<ans<<'\n';
	}
	return 0;
}

Measured memory_bytes: 9500
#include<stdio.h>
#include<string.h>
int main(void)
{
	char str1[100];
	int A,B,n,i;
	
	while(1)	{
		scanf("%s",str1);
		
		if(str1[0]=='0')	{
			break;
		}
		n=strlen(str1);
		A=0;
		B=0;
		for(i=1;i<n;i++)	{
			if(str1[i]=='A')	{
				A++;
			}
			if(str1[i]=='B')	{
				B++;
			}
		}
//		printf("aaaa\n");
		if(A > B) {
			printf("%d %d\n",A+1,B);
		}
		else if(A < B) {
			printf("%d %d\n",A,B+1);
		}
	}
	return 0;
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int visited[200005],high[200005];
typedef struct ANode{
    long long adjvex;                 
    struct ANode *nextarc;                  
} ArcNode;                      
typedef struct Vnode{               
    int count;                  
    ArcNode *firstarc;          
}VNode;                     
typedef struct node{
    VNode adjlist[100005]; 
}AdjGraph;
void add(AdjGraph *G,ll u,ll v){
    ArcNode *p;
    p=(ArcNode *)malloc(sizeof(ArcNode));
    p->adjvex=v;
    p->nextarc=G->adjlist[u].firstarc;  
    G->adjlist[u].firstarc=p;
    p=(ArcNode *)malloc(sizeof(ArcNode));
    p->adjvex=u;
    p->nextarc=G->adjlist[v].firstarc;  
    G->adjlist[v].firstarc=p;
}
void BFS(AdjGraph *G){
    ll w,i;
    ArcNode *p;
    queue<long long> qu;                                                                        
    for (i=1;i<=n;i++) visited[i]=0;                              
    visited[1]=1;                       
    qu.push(1);
    while(qu.size()){ 
        w=qu.front();
        qu.pop();                    
        p=G->adjlist[w].firstarc;            
        while (p!=NULL){    
            if (visited[p->adjvex]==0){     
                visited[p->adjvex]=1;
                high[p->adjvex]=w;       
                qu.push(p->adjvex);      
            }
            p=p->nextarc;                    
        }
        
    }
}
int main(){
    ll a,b,m;
    AdjGraph *G;
    G=(AdjGraph *)malloc(sizeof(AdjGraph));
    cin>>n>>m;
    for(ll i=1;i<=m;i++){
        cin>>a>>b;
        add(G,a,b);
	}
    for(ll i=1;i<=n;i++)
        high[i]=0;
    BFS(G);
    for(ll i=1;i<=n;i++)
        if(!visited[i]){
            cout<<"No"<<endl;
            return 0;
        }
    cout<<"Yes"<<endl;
    for(ll i=2;i<=n;i++){
        cout<<high[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 18704