akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
vector<ll> takahashi;
vector<ll> aoki;
bool custom_1(int a, int b) {
  if(takahashi[a] - aoki[b] == takahashi[b] - aoki[a]) return (takahashi[a] > takahashi[b]);
  else return (takahashi[a] - aoki[b] > takahashi[b] - aoki[a]);
}
bool custom_2(int a, int b) {
  if(aoki[a] - takahashi[b] == aoki[b] - takahashi[a]) return (aoki[a] > aoki[b]);
  else return (aoki[a] - takahashi[b] > aoki[b] - takahashi[a]);
}
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  string s;
  cin >> s;
  if(s.size() == 26) {
    int max = 0;
    int idx = -1;
    for(int i = 24;i>=0;i--) {
      if(s[i] < s[i+1]) {
        idx = i;
        break;
      }
    }
    if(idx == -1) cout << -1 << endl;
    else {
      char q = 'z';
      for(int i=25;i>idx;i--) {
        if(s[i] > s[idx]) chmin(q, s[i]);
      }
      cout << s.substr(0, idx) + q << endl;
    }
  }
  else {
    vector<int> used(26);
    rep(i, s.size()) {
      used[s[i]-'a'] = 1;
    }
    char q;
    rep(i, 26) {
      if(!used[i]) {
        q = 'a' + i;
        break;
      }
    }

    cout << s + q << endl;
  }
}


Measured memory_bytes: 256
import itertools
N = int(input())

base = [1]
for i in range(1, 7):
    if 6 ** i <= N:
        base.append(6 ** i)
for i in range(1, 6):
    if 9 ** i <= N:
        base.append(9 ** i)
ans = N
dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = min([dp[i - j] + 1 if i - j >= 0 else j for j in base])

print(dp[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

struct UnionFind
{
    vector<int> par, rank;

    UnionFind(int N) : par(N), rank(N)
    {
        rep(i, N) par[i] = i, rank[i] = 0;
    }

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

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (rank[rx] < rank[ry])
        {
            par[rx] = ry;
        }
        else
        {
            par[ry] = rx;
            if (rank[rx] == rank[ry])
                rank[rx]++;
        }
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int N, M;
    cin >> N >> M;

    UnionFind tree(N);
    rep(i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        tree.unite(x, y);
    }

    set<int> st;
    rep(i, N) {
        st.insert(tree.root(i));
    }

    cout << (int)st.size() << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int a[N+1];
  for(int i = 1; i <= N; i++) cin >> a[i];
  int ans = 0, pos = 1;
  while(ans <= N){
    if(pos == 2) break;
    ans++;
    pos = a[pos];
  }
  if(ans == N+1) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i, N) for (long long i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N)
    {
        cin >> a.at(i);
    }
    vector<ll> b(N, 0);
    rep(i, N)
    {
        b.at(a.at(i) - 1)++;
    }
    ll sum = 0;
    rep(i, N)
    {
        if (b.at(i) == 0 || b.at(i) == 1)
        {
            continue;
        }
        sum += (b.at(i) * (b.at(i) - 1)) / 2;
    }
    rep(k, N)
    {
        ll sum_k = sum;
        sum_k -= b.at(a.at(k) - 1) - 1;
        cout << sum_k << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

vector <vpi> adj;
vi val, visited;
int n, m;

void input()
{
	int x, y, z;
	cin >> n >> m;
	adj.resize(n + 1);
	val.resize(n + 1);
	visited.resize(n + 1);
	
	for (int i = 1; i <= m; i++)
	{
		cin >> x >> y >> z;
		adj[x].push_back({y, z});
		adj[y].push_back({x, -z});
	}
}

void dfs (int cur)
{
	visited[cur] = true;
	for (pi i: adj[cur])
		if (!visited[i.first])
		{
			val[i.first] = val[cur] + i.second;
			dfs(i.first);
		}
		
		else if (val[i.first] != val[cur] + i.second) 
		{
			cout << "No";
			exit(0);
		}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
	
	for (int i = 1; i <= n; i++)
		if (!visited[i]) dfs(i); 
	cout << "Yes";
}

Measured memory_bytes: 16384
#include <stdio.h>
 
using namespace std;
 
int main(){
    int r,c,sum,total_sum = 0;
    scanf("%d %d",&r,&c);
    int table[r+1][c+1];
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            table[i][j] = 0;
        }
    }
 
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            scanf("%d",&table[i][j]);
            sum += table[i][j];
            table[r][j] += table[i][j];
        }
        table[i][c] = sum;
        total_sum += sum;
    }
    table[r][c] = total_sum;
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            printf("%d ",table[i][j]);
        }
        printf("%d\n",table[i][c]);
    }
}


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

int main(){
    ll n, m; cin >> n >> m;
    vector<vector<ll>> g(n+1);
    rep(i,m){
        ll a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for(auto x:g[1]){
        for(auto y:g[x]){
            if(y == n){
                put("POSSIBLE");
                return 0;
            }
        }
    }
    put("IMPOSSIBLE");
}

Measured memory_bytes: 15756
from heapq import heappush, heappop

def get_par(x, par_lst):
  if x == par_lst[x]:
    return x
  p = get_par(par_lst[x], par_lst)
  par_lst[x] = p
  return p

while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  que = []
  for _ in range(m):
    a, b, c = map(int, input().split())
    heappush(que, (c, a, b))
  
  par_lst = [i for i in range(n)]
  ans = 0
  while que:
    c, a, b = heappop(que)
    pa, pb = get_par(a, par_lst), get_par(b, par_lst)
    if pa != pb:
      par_lst[pa] = pb
      ans += c
  print(ans)


Measured memory_bytes: 5660
graph=[[False for i in range(8)]for j in range(8)]
def dfs(x,N,visted):
 all=True
 for i in range(N):
  if(visted[i]==False):
    all=False
 if all==True:
  return 1

 ret=0
 for i in range(N):
   if graph[x][i]==False:
    continue
   if visted[i]==True:
    continue
   visted[i]=True
   ret=ret+dfs(i,N,visted)
   visted[i]=False
  
 return ret

N,M=map(int,input().split())
for i in range(M):   
  x,y=map(int,input().split())
  graph[x-1][y-1]=True
  graph[y-1][x-1]=True
visted=[False for i in range(N)]
visted[0]=True
print(dfs(0,N,visted))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    double ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += (double)1 / a[i];
    }
    ans = (double)1 / ans;
    cout << fixed;
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll R=2e5+69, INF=2e9+6969;

int n,r,ans;
string S;

int main()
{
	cin >> n >> S;
	S = " " + S;
	for(int i=1;i<=n;++i)
	{
		if(S[i] == 'R') ++r;
	}
	for(int i=1;i<=r;++i) if(S[i] == 'W') ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3856
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 200002;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()
#define biton(x, y) (((x>>y)&1ll) == 1)
#define bitoff(x, y) (((x>>y)&1ll) == 0)
int32_t main()
{ 
   IOS

  string s;
  cin >> s;
  int n = s.size();
  int pref = 0;
  int a[n];
  for(int i = 0;i<n;i++){
    pref^=(1ll<<(s[i]-'a'));
    a[i] = pref;
  }
  map<int,int> dp;
  dp[0] = 0;
  for(int i = 0;i<n;i++){
    int x = 0;
    int mini = 1e18;
    for(int j = 0;j<=26;j++){
      if(dp.find(a[i]^x) != dp.end()){
        mini = min(mini, dp[a[i]^x] +1);
      }
      x = (1ll<<j);
    }
    if(dp.find(a[i]) == dp.end()) dp[a[i]] = mini;
    else dp[a[i]] = min(dp[a[i]], mini);
  }
  cout << max(dp[a[n-1]],1ll )<< endl;
    
  

    


  
  
  


    


  
  

 
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	i64 N;
	cin >> N;

	if (N % 4 == 0)
	{
		cout << "Yes" << endl;
		return 0;
	}
	else if (N % 7 == 0)
	{
		cout << "Yes" << endl;
		return 0;
	}

	int div = N / 7;
	if (div > 0)
	{
		FOR(i, 1, div + 1)
		{
			if ((N - 7 * i) % 4 == 0)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	div = N / 4;
	if (div > 0)
	{
		FOR(i, 1, div + 1)
		{
			if ((N - 4 * i) % 7 == 0)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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


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

int main(){
    int n;
    while(cin >>n){
        if(n == 0) break;

        vector< vector<int> > cardset(2, vector<int>());
        set<int> s;
        for(int i = 0; i < n; i++){
            int tmp;
            cin >>tmp;
            s.insert(tmp);
        }
        for(int i = 1; i <= 2 * n; i++){
            if(s.find(i) != s.end()) cardset[0].push_back(i);
            else cardset[1].push_back(i);
        }

        sort(cardset[0].begin(), cardset[0].end());
        sort(cardset[1].begin(), cardset[1].end());

        int nowturn = 0;

        while(cardset[0].size() != 0 && cardset[1].size() != 0){
            int now = cardset[nowturn][0] - 1;
            while(cardset[0].size() != 0 && cardset[1].size() != 0){
                vector<int>::iterator it = cardset[nowturn].begin();
                for( ; it != cardset[nowturn].end(); it++){
                    if((*it) > now){
                        now = (*it);
                        cardset[nowturn].erase(it);
                        nowturn = (nowturn + 1) % 2;
                        break;
                    }
                }
                if(it == cardset[nowturn].end()){
                    nowturn = (nowturn + 1) % 2;
                    break;
                }
            }
        }
        cout <<cardset[1].size() <<endl <<cardset[0].size() <<endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    long long a,b,c;
    cin>>a>>b>>c;
    long long n;
    cin>>n;
    long long res = 0;

    long long z = min(n,a);
    res+=z;
    n-=z;

    z = min(n,b);
    n-=z;

    z = min(n,c);
    res-=z;
    n-=z;
    cout<<res;


}


Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

/* template end */

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

    int a, b;
    cin >> a >> b;

#if DEBUG
    cout << "** RESULT **" << endl; // debug
#endif
    cout << (((a * b) % 2) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
l = [format(i, 'b').zfill(10) for i in range(1, 2 ** 10)]
ans = []

for i in l:
    c = [0] * N
    for j in range(10):
        if i[j] == '1':
            for k in range(N):
                if F[k][j] == 1:
                    c[k] += 1
                else:
                    continue
        else:
            continue
    temp = 0
    for j in range(N):
        temp += P[j][c[j]]
    ans.append(temp)

print(max(ans))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int n,k;
int x[200002],y[200002];
int main() {
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&k);
        x[i] = k;
        y[i] = k;
    }
    sort(&x[0],&x[n]);
    int a[2] = {x[(n/2)-1],x[n/2]};
    if (a[0]==a[1]) {
        for (int i=0; i<n; i++) {
            printf("%d\n", a[0]);
        }
    }
    else {
        for (int i=0; i<n; i++) {
            if (y[i]<=a[0]) printf("%d\n",a[1]);
            else printf("%d\n",a[0]);
        }
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > v;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,ga,sa,ba,gb,sb,bb;
	cin>>n;
	int m=n;
	cin>>ga>>sa>>ba>>gb>>sb>>bb;
	for(int i=0;i<=n;i+=ga)
		for(int j=0;j<=n;j+=sa){
			int k=n-i-j;
			if(k<0) continue;
			m=max(m,max(i,i%ga+i/ga*gb)+max(j,j%sa+j/sa*sb)+max(k,k%ba+k/ba*bb));
		}
	long long int ans=m;
	if(ans!=n){
		if(gb<ga)
			v.push_back(make_pair(gb,ga));
		if(sb<sa)
			v.push_back(make_pair(sb,sa));
		if(bb<ba)
			v.push_back(make_pair(bb,ba));
		if(v.size()==1){
			ans=ans%v[0].first+ans/v[0].first*v[0].second;
		}
		else if(v.size()==2){
			for(long long int i=0;i<=m;i+=v[0].first)
				ans=max(ans,i/v[0].first*v[0].second+(m-i)%v[1].first+(m-i)/v[1].first*v[1].second);
		}
		cout<<ans<<endl;
		return 0;
	}
	for(long long int i=0;i<=m;i+=gb)
		for(long long int j=0;j<=m;j+=sb){
			long long int k=m-i-j;
			if(k<0)	continue;
			ans=max(ans,max(i,i%gb+i/gb*ga)+max(j,j%sb+j/sb*sa)+max(k,k%bb+k/bb*ba));
		}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb push_back
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    if(k>=n)
        cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string> 

using namespace std;

bool check(vector<string> &A, vector<string> &B, int px, int py) {
	for (int y = 0; y < B.size(); y++) {
		for (int x = 0; x < B.size(); x++) {
			if (A[y + py][x + px] != B[y][x]) return false;
		}
	}
	return true;
}

int main(int argc, char *argv[]) {
	int N, M;
	cin >> N >> M;

	vector<string> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector<string> B(M);
	for (int i = 0; i < M; i++) cin >> B[i];

	for (int py = 0; py <= N - M; py++) {
		for (int px = 0; px <= N - M; px++) {
			if (check(A, B, px, py)) {
				printf("Yes\n");
				return 0;
			}
		}
	}

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
 
class MainClass
{
  static public void Main(string[] args)
  {
    var N = Convert.ToInt64(Console.ReadLine());
    long res = 0;
    for (long i = 1; i <= N; i++) {
      var n = N / i;
      res += (i * n * (n + 1)) / 2;
    }
    Console.WriteLine(res);
  }
}

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

vector<ll> par;
vector<ll> ran;
vector<ll> siz;

vector<pair<ll,ll> > brid;

void init(ll n)
{
  for (ll i = 0; i < n; i++)
  {
    par.push_back(i);
    ran.push_back(0);
    siz.push_back(1);
  }
}

ll root(ll x)
{
  if(par[x]==x){
    return x;
  } else {
    par[x] = root(par[x]);
    return par[x];
  }
}

bool same(ll x, ll y)
{
  return root(x)==root(y);
}

void unite(ll x, ll y)
{
  x = root(x);
  y = root(y);
  if(ran[x]>ran[y]){
    par[y]=x; // rank of x does not change
    siz[x] += siz[y];
  } else {
    par[x]=y;
    if(ran[x]==ran[y]) ran[y]++;
    siz[y] += siz[x];
  }
}

ll size_query(ll x)
{
  return siz[root(x)];
}

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

  for (ll i = 0; i < m; i++)
  {
    ll a,b;
    cin >> a >> b;
    brid.push_back(make_pair(a,b));
  }
  
  vector<ll> ans(m);
  ans[m-1] = n*(n-1)/2;

  for (ll i = m-2; i >= 0; i--)
  {
    ll a,b;
    a = brid[i+1].first-1;
    b = brid[i+1].second-1;
    if(same(a,b)){
      ans[i] = ans[i+1]; 
    } else {
      ans[i] = ans[i+1] - size_query(a) * size_query(b);
      unite(a,b);
    }
  }
  
  for (ll i = 0; i < m; i++)
  {
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 5980
#include <iostream>
#include <iomanip>

using namespace std;

double r;

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

	cout << fixed << setprecision(5) << r*r*3.141592653589 << " "  << fixed << setprecision(5) << 2*r*3.141592653589 << "\n";

	return 0;
}

Measured memory_bytes: 3296
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    b=[0]*n

    s_xor=0
    i_1=0
    i_2=0
    for j in range(n):
        if j==0:
            for _ in range(n-1):
                s_xor^=a[i_1]
                i_1+=1
            b[i_1]=s_xor
        else:
            s_xor^=a[i_2]
            i_2+=1
            i_2%=n

            s_xor^=a[i_1]
            i_1+=1
            i_1%=n
            b[i_1]=s_xor

    print(*b)

if __name__=="__main__":
    main()

Measured memory_bytes: 31608
// Author: pankaj_m05 
// Problem: C
//Created: 17.05.2020 17:39:13

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
#define PI 3.1415926535897932384626

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;

int main(void) { 
	fast
	int a, b, h, m;
	cout.precision(15); cout << fixed;
	cin >> a >> b >> h >> m;
	double hourAngle = 0.5 * (h * 60 + m);
	double minuteAngle = 6 * m;
	double angle = abs(hourAngle - minuteAngle);
	angle = min(360.0 - angle, angle);
	double ans = (double) ((a * a) + (b * b) - (2 * a * b * cos(angle * PI / 180.0)));
	ans  = sqrt(ans);
	cout << ans << '\n';
	return 0;
}                                          

Measured memory_bytes: 4240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp111 {
    class Program {
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            String[] inputArr = input.Split(' ');

            int[] inputInt = StringToInteger(inputArr);

            int ans = inputInt[0] - (inputInt[1] - 1);
            Console.WriteLine(ans);
        }

        static int[] StringToInteger(string[] input)
        {
            int[] inputInt = new int[2];
            int i = 0;

            foreach(string n in input)
            {
                inputInt[i] = int.Parse(n);
                i++;
            }

            return inputInt;
        }
    }
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define mod (ll)1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, y;
  cin >> n >> y;

  rep(i, 0, n + 1) {
    rep(j, 0, n - i + 1) {
      if((i * 10000 + j * 5000 + (n - i - j) * 1000) == y) {
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


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

signed main()
{
  string s;
  cin>>s;
  int r=1,p=0,sum=0;

  for(int i=1;i<s.length();i++)
  {
    if(s[i]=='g'){
      if(p<r){
       p++;
       sum++;
      }
      else{
      r++;
     }
    }
    else if(s[i]=='p'){
      if(p<r){
        p++;
      }
      else{
        r++;
        sum--;
      }
    }
  }  
  cout<<sum;
  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if (flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
string s1, s2;
string wa(string S1, string S2) {

}
int main() {
    cin >> h >> n;
    inputv(A, n);
    rep(i, n) {
        h -= A[i];
    }
    if (h <= 0)cout << "Yes";
    else cout << "No" << endl;
}

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

void solve(){
	
	int a,b,c ;
	cin>>a>>b>>c ;
	set<int> st ;
	st.insert(a) ;
	st.insert(b) ;
	st.insert(c) ;
	
	if(st.size()==2)
		cout<<"Yes" ;
	else
		cout<<"No" ;

}



int main(){


	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<queue>

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

using namespace std;

typedef pair<int,int> pii;

int main(){
	int a,b[2]={0};
	rep(i,2)rep(j,4){
	    scanf("%d",&a);
	    b[i]+=a;
    }
	printf("%d\n",max(b[0],b[1]));
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int status[1005][1005];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int h, w;
/*
void f() {
   rep(i, 0, h) {
      rep(j, 0, w) printf("%d ", status[i][j]);
      printf("\n");
   }
   printf("=======================\n");
}
*/
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   cin >> h >> w;
   P s, g;
   cin >> s.first >> s.second;
   s.first--, s.second--;
   cin >> g.first >> g.second;
   g.first--, g.second--;
   vector<string> maze(h);
   rep(i, 0, h) cin >> maze[i];

   rep(i, 0, h) rep(j, 0, w) status[i][j] = INF;

   deque<P> deq;
   deq.push_front(s);
   status[s.first][s.second] = 0;
   while (!deq.empty()) {
      P p = deq.front();
      deq.pop_front();
      int cx = p.first, cy = p.second;
      rep(i, 0, 4) {
         int nx = cx + dx[i], ny = cy + dy[i];
         if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
         if (maze[nx][ny] == '#') continue;
         if (status[nx][ny] > status[cx][cy]) {
            status[nx][ny] = status[cx][cy];
            deq.push_front(P(nx, ny));
            // f();
         }
      }
      rep(i, -2, 3) {
         rep(j, -2, 3) {
            int nx = cx + i, ny = cy + j;
            if (nx == cx && ny == cy) continue;
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (maze[nx][ny] == '#') continue;
            if (status[nx][ny] > status[cx][cy] + 1) {
               status[nx][ny] = status[cx][cy] + 1;
               deq.emplace_back(nx, ny);
               // f();
            }
         }
      }
   }
   int ans = status[g.first][g.second];
   if (status[g.first][g.second] == INF) ans = -1;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 8612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
//Range Sum Query
class Lz_segtree{
public:
    int n;
    ll e=0;
    //ll init=0;
    vector<ll> dat,lz;
    Lz_segtree(int n_):n(n_){
        n=1;
        while(n<n_) n*=2;
        dat.resize(n*2,e);
        lz.resize(n*2,e);
    }
    void update_f(ll& d,ll x){
        d+=x;
    }
    ll dat_propergate(ll l,ll r){
        return l+r;
    }
    void lz_propergatef(ll& l,ll& r,ll x){
        l+=x,r+=x;
    }
    void eval(int len,int k){
        if(lz[k]!=e) update_f(dat[k],lz[k]);
        if(len>1){
            lz_propergatef(lz[k*2+1],lz[k*2+2],lz[k]/2);
        }
        lz[k]=e;
    }
    //range [a,b)
    void update(int a,int b,int k,int l,int r,ll x){
        eval(r-l,k);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            update_f(lz[k],(r-l)*x);
            eval(r-l,k);
        }
        else{
            update(a,b,k*2+1,l,(l+r)/2,x);
            update(a,b,k*2+2,(l+r)/2,r,x);
            dat[k]=dat_propergate(dat[2*k+1],dat[2*k+2]);
        }
    }
    //range [a,b)
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return e;
        if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return dat_propergate(vl,vr);
        }
    }
    void update(int a,int b,ll x){
        return update(a,b,0,0,n,x);
    }
    ll query(int a,int b){
        return query(a,b,0,0,n);
    }
};

int main(){
    int n,q,c,s,t,x;
    cin>>n>>q;
    Lz_segtree seg(n);
    rep(i,q){
        cin>>c;
        if(c==0){
            cin>>s>>t>>x;
            seg.update(s-1,t,x);
        }
        else{
            cin>>s>>t;
            ll ans=seg.query(s-1,t);
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

int main() {
  int n,m;
  cin >>n >>m;
  
  vector<int>broken(n+1);
  
  for(int i=0; i<m; i++){
    int a;
    cin >>a;
    broken[a]=1;
  }
  
  vector<int>dp(n+2);
  dp[n]=1;
  
  int x=1000000007;
  
  for(int i=n-1; i>=0; i--){
    if(broken[i]==1){
      dp[i]=0;
      continue;
    }
    dp[i]=(dp[i+1]+dp[i+2])%x;
  }
  cout <<dp[0] <<endl;
}
    

Measured memory_bytes: 1024
N,K = map(int,input().split()) 

coin_num = [0]*(max(N,K)+1) 

cursor = K
count = 0
for i in range(len(coin_num)-1,0,-1):
    if i>=cursor:
        coin_num[i] = count
    else:
        while(i<cursor):
            cursor = (cursor+1)//2 
            count += 1
        coin_num[i] = count
        
ans = 0 
for i in range(1,N+1):
    ans += (1/N)*((1/2)**coin_num[i]) 
    
print(ans)


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(num) scanf("%d",&num)
#define sff(num1,num2) scanf("%d %d",&num1,&num2)
#define sfff(num1,num2,num3) scanf("%d %d %d",&num1,&num2,&num3)
#define sl(num) scanf("%lld",&num)
#define sll(num1,num2) scanf("%lld %lld",&num1,&num2)
#define slll(num1,num2,num3) scanf("%lld %lld %lld",&num1,&num2,&num3)
#define rep(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define pb push_back
#define mpp make_pair
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
#define TIME cerr<<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<"s\n";
typedef long long int ll;
using namespace std;
int n,dp[N][3],ara[N][3];
int func(int cur,int last)
{
    if(cur>n)
        return 0;
    if(dp[cur][last]!=-1)
        return dp[cur][last];
    int i,j,ans=-1;
    rep0(i,3)
    {
        if(i!=last)
            ans=max(ans,func(cur+1,i)+ara[cur][i]);
    }
    return dp[cur][last]=ans;
}
int main()
{
    sf(n);
    int i,j;
    rep0(i,n)
    {
        rep0(j,3)
            sf(ara[i][j]);
    }
    mem(dp,-1);
    int res=-1;
    rep0(i,3)
       res=max(res,func(1,i)+ara[0][i]);
    pf("%d",res);
}


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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m;
    a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2, HELL)

vector<int> getFactors(int n) {
    vector<int> factors;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            factors.push_back(i);
            if (i * i != n) {
                factors.push_back(n / i);
            }
        }
    }
    factors.push_back(n);
    return factors;
}

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

    if (n == 2) {
    	cout << 1 << endl;
    	return 0;
	}

	if (n == 3) {
		cout << 2 << endl;
		return 0;
	}

	int res = getFactors(n - 1).size();
	vector<int> factors = getFactors(n);
	for (auto i : factors) {
		int x = n;
    	while (x >= i) {
    		if (x % i == 0) {
    			x /= i;
    		} else {
    			x = x % i;
    		}
    	}
    	if (x == 1) {
    		res++;
    	}
	}
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M, n, m;
    cin >> N >> M >> n >> m;
    cout << (N-n)*(M-m) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

ll dp[100001][101];

int main(){
  fastread;

  int n,w;
  cin >> n >> w;

  ll a,b;
  vector<pair<ll,ll>> values;
  rep(i,0,n){
    cin >> a >> b;
    values.pb(mp(a,b));
  }

  memset(dp,0,sizeof(dp));

  rep(i,1,w+1){
    rep(j,0,n){
      if(j==0 && values[j].ff<=i)
        dp[i][j]=values[j].ss;
      else
        dp[i][j]=max(dp[i][j-1], (i-values[j].ff>=0)?values[j].ss+dp[i-values[j].ff][j-1]:0);
    }
  }

  ll ma=0;
  rep(i,0,n)
    ma=max(ma, dp[w][i]);

  cout << ma << nl;
  return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  vector<vector<pair<ll, ll>>> edge(n);
  for (int i = 0; i < m; i++){
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    edge[a].emplace_back(make_pair(b, c));
  }

  vector<ll> dist(n, -INF);
  dist[0] = 0;
  vector<bool> isinf(n, false);
  for (int i = 0; i < n + 1; i++){
    for (int j = 0; j < n; j++){
      for (int k = 0; k < edge[j].size(); k++){
        if (dist[j] + edge[j][k].second > dist[edge[j][k].first]){
          if (i == n - 1){
            isinf[j] = true;
          }
          dist[edge[j][k].first] = dist[j] + edge[j][k].second;
        }
        if (isinf[j]){
          isinf[edge[j][k].first] = true;
        }
      }
    }
  }

  if (isinf[n-1]){
    cout << "inf" << endl;
  }
  else 
    cout << dist[n-1] << endl;

  return 0;
}


Measured memory_bytes: 384
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n, m;
    cin >> n >> m;
    char mat[n][m];
    forn(i, n) {
        string s;
        cin >> s;
        forn(j, m) {
            mat[i][j] = s[j];
        }
    }
    vector<int> cntr(m, 0), cntc(n, 0);
    forn(i, n) {
        forn(j, m) {
            cntc[i] += mat[i][j] == '.';
            cntr[j] += mat[i][j] == '.';
        }
    }
    forn(i, n) {
        if (!(cntc[i] == m)) {
            bool ok = 0;
            forn(j, m) {
                if (!(cntr[j] == n)) {
                    ok = 1;
                    cout << mat[i][j];
                }
            }
            if (ok)
                cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;

using pii = pair<int, int>;

map<pii, int> mp;

bool check(vector<int>& h, vector<int>& w, int a)
{
    if (a == 1) {
        if (mp[pii(h[0], w[0])] == 4) {
            swap(h[0], h[1]);
            swap(w[0], w[1]);
        }
        if (h[1] == h[0] && h[1] == w[0]) return true;
        if (w[1] == h[0] && w[1] == w[0]) return true;
    } else {
        map<int, int> mp2;
        for (int i = 0; i < 3; i++) {
            if (h[i] == w[i]) return false;
            mp2[h[i]]++;
            mp2[w[i]]++;
        }
        return (mp2.size() == 3);
    }
    return false;
}

int main()
{
    int h, w;
    vector<int> nh, nw;
    map<int, int> mp2;
    for (int i = 0; i < 6; i++) {
        cin >> h >> w;
        mp2[h]++; mp2[w]++;
        if (h > w) swap(h, w);
        if (++mp[pii(h, w)] == 1) {
            nh.emplace_back(h);
            nw.emplace_back(w);
        }
    }
    int a = 0, b = 0, c = 0;
    for(auto& it : mp) {
        if (it.second == 2) a++;
        if (it.second == 4) b++;
        if (it.second == 6) c++;
    }
    if (a == 3 || (a == 1 && b == 1)){
        cout << (check(nh, nw, a) ? "yes" : "no") << endl;
    } else if (c == 1 && mp2[nh[0]] == 12) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define int 		  	long long
#define f(i,n)        	for(int i=0;i<(n);++i)
#define fa(i,a,n)     	for(int i=a;i<=(n);++i)
#define fd(i,a,n)     	for(int i=a;i>=(n);--i)
#define tc 			  	int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
#define allx 			x.begin(),x.end()
#define tr(c,i) 		for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x) 	(c.find(x) != c.end())
#define cpresent(c,x) 	(find(allc,x) != c.end())
#define	PI 3.1415926535897932
void c_p_c() {

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

}
void solve() {
	int n;
	cin >> n;
	bool ans = 0;
	int cnt = 0;
	f(i, n) {
		int x, y;
		cin >> x >> y;
		if (x == y) {
			cnt++;
		}
		else {
			if (cnt >= 3) {
				ans = 1;
			}
			cnt = 0;
		}
	}
	if (cnt >= 3)
		ans = 1;
	if (ans)
		cout << "Yes";
	else
		cout << "No";
}

int32_t main() {

	c_p_c();
	//tc
	solve();
	return 0;
}



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

int main(){
    int64_t n,a,b;
    cin>>n>>a>>b;
    int64_t p,q;
    p=n/(a+b);
    q=n%(a+b);
    if(q>a) q=a;
    cout<<a*p+q;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int m;
vector<bool> v;
int a[10];

int dfs(int now, int x) {
  if (now == v.size()) {
    return x % 10 == 0;
  }
  int res = 0;
  REP(i,m) {
    int t = a[i];
    if (v[now]) t*=2;
    res += dfs(now+1, x+t/10+t%10);
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool f = 0;
  int x = 0;
  v.clear();
  for (int i=s.size()-1; i>=0; --i) {
    if (s[i] != '*') {
      int a = s[i]-'0';
      if (f) a*=2;
      x += a / 10 + a % 10;
    } else {
      v.push_back(f);
    }
    f = !f;
  }
  cin >> m;
  REP(i,m) {
    cin >> a[i];
  }
  cout << dfs(0,x) << endl;
}

Measured memory_bytes: 1336
n = int(input())
abc = [list(map(int,input().split())) for _ in range(n)]

dp = [[0 for _ in range(3)] for _ in range(n+1)]

for i in range(1,n+1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][k] = max(dp[i][k],dp[i-1][j] + abc[i-1][k])

ans = max(dp[-1])
print(ans)

Measured memory_bytes: 74840
package main

import (
	"fmt"
)

type dice struct {
	t, s, e, w, n, b int
}

func (d *dice) rotate(s string) {
	switch s {
	case "E":
		d.t, d.e, d.w, d.b = d.w, d.t, d.b, d.e
	case "W":
		d.t, d.e, d.w, d.b = d.e, d.b, d.t, d.w
	case "S":
		d.t, d.s, d.b, d.n = d.n, d.t, d.s, d.b
	case "N":
		d.t, d.s, d.b, d.n = d.s, d.b, d.n, d.t
	}
}

func (d *dice) equal(t dice) bool {
	return d.t == t.t && d.s == t.s && d.e == t.e && d.w == t.w && d.n == t.n && d.b == t.b
}

// サイコロ4
func main() {
	var n int
	fmt.Scan(&n)
	dices := make([]dice, n)
	for i := 0; i < n; i++ {
		var t, s, e, w, n, b int
		fmt.Scan(&t, &s, &e, &w, &n, &b)
		dices[i] = dice{t: t, s: s, e: e, w: w, n: n, b: b}
	}

	same := false
	base := dices[0]
	for i := 1; i < n; i++ {
		if same {
			break
		}
		for _, v := range "EEENEEENEEESEEESEEENEEEN" {
			if base.equal(dices[i]) {
				same = true
				break
			}
			dices[i].rotate(string(v))
		}
	}

	if same {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}



Measured memory_bytes: 1176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<int>card[2];
      for(int i=1;i<=2*n;i++)
    {
      card[1].push_back(i);
    }
      for(int i=0;i<n;i++)
    {
      int tmp;
      cin>>tmp;
      card[1].erase(remove(card[1].begin(),card[1].end(),tmp),card[1].end());
      card[0].push_back(tmp);
    }
      sort(card[0].begin(),card[0].end());
      int cnt=0;
      int fi=0;
      while(card[0].size()!=0&&card[1].size()!=0)
    {
      int tmp_fi=0;
      for(int i=0;i<card[cnt].size();i++)
        {
          if(card[cnt][i]>fi)
        {
          tmp_fi=card[cnt][i];
          card[cnt].erase(card[cnt].begin()+i);
          break;
        }
        }
      fi=tmp_fi;        
      if(cnt==0)
        cnt=1;
      else
        cnt=0;
    }
      cout<<card[1].size()<<endl;
      cout<<card[0].size()<<endl;
 
    }
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define ll long long 

ll n,m,k,a[N],b[N],sa[N],sb[N];

int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
	for(int i=1;i<=n;i++)sa[i]=sa[i-1]+a[i];
	for(int i=1;i<=m;i++)sb[i]=sb[i-1]+b[i];
	ll ans=0;
	for(int i=0;i<=n;i++)if(sa[i]<=k){
		ll t=k-sa[i];
		ll pos=upper_bound(sb+1,sb+1+m,t)-sb;
		ans=max(ans,i+pos-1);
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 9828