akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,p,sum=0;
	cin>>n;
	p=n;
	while(p!=0)
	{
		sum+=p%10;
		p=p/10;
	}
	if(n%sum==0)
	   cout<<"Yes";
	else
	   cout<<"No";
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())

res = 10**10
cnt = 0
for mask in range(1<<2):
    _x = x
    _y = y
    if mask & 1:
        _x *= -1
        cnt +=1
    if (mask>>1) & 1:
        _y *= -1
        cnt += 1
    if _x <= _y:
        cnt += _y-_x
        res = min(res,cnt)
    cnt = 0
print(res)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; ll z, w; cin >> n >> z >> w;
    VL a(n); cin >> a;
    if (n == 1)cout << abs(w - a[0]) << "\n";
    else cout << max(abs(w - a[n - 1]), abs(a[n - 2] - a[n - 1])) << "\n";
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
int n, sqrtN;
long long ans, d;
char buf[8],out[20];
char k;
s;
size_t i;
int main() {
    s = read(0, buf, 8);
    for(;;) {
        k = buf[i++];
        if(k < '0') break;
        n = n * 10 + k - '0';
    }
    if(n == 1) {
        putchar(49);
    } else {
        const int sqrtN = sqrt(n);
        ans = -(long long)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
        for(int i = 1; i <= sqrtN; ++i) {
            const int a = n / i;
            ans += ((long long)i * (i + a) * (a + 1 - i));
        }
        i = 20;
        do{
            out[--i]=ans%10+'0';
            ans/=10;
        }while(ans);
        write(1,out+i,20-i);
    }
}


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

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  int n;cin >> n;
  vector<pair<int,int>> lr(n);
  ll ans = 0;
  rep(i,n){
    cin >> lr[i].first >> lr[i].second;
    ans+=(lr[i].second - lr[i].first + 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    string S;
    cin >> S;

    deque<char> T;
    rep(i, S.size()) T.push_back(S[i]);

    ll Q;
    cin >> Q;

    bool flip = false;
    rep (i, Q) {
        int flg;
        cin >> flg;
        if (flg == 1) {
            flip = !flip;
        }
        else if (flg == 2) {
            int f;
            char c;
            cin >> f >> c;
            if (flip) f = 3 - f;
            if (f == 1) {
                T.push_front(c);
            }
            else {
                T.push_back(c);
            }
        }
    }

    if (flip) reverse(all(T));

    rep(i, T.size()) cout << T[i];
    cout << endl;

}
signed main(){ Main();return 0;}

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

#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define ll long long

int main()
{
    ios;

    int n, q, op, t, x;
    scanf("%d %d", &n, &q);
    vector<int> v[n];
    while (q--)
    {
        scanf("%d %d", &op, &t);
        if (op == 0)
        {
            scanf("%d", &x);
            v[t].push_back(x);
        }
        else if (op == 1)
        {
            if (!v[t].empty())
                printf("%d", v[t][0]);
            for (int i = 1; i < v[t].size(); i++)
                printf(" %d", v[t][i]);
            printf("\n");
        }
        else
        {
            v[t].clear();
        }
    }
    return 0;

}




Measured memory_bytes: 6064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n;
  scanf("%d",&n);

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

  qsort(a,n,sizeof(int),sort);

  int ans = 0;
  int tmp = 0;
  if(n == 1){
    ans = 1;
  }else{
  for(int i = 0; i < n; ++i){
    if(a[i] == a[i+1]){
      ++ tmp;
    }
    if(a[i] != a[i+1]){
      if(tmp % 2 == 0){
        ans ++;
      }
      tmp = 0;
    }
  }
  }

  printf("%d",ans);

  return 0;

}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <typename T> bool is_square(T n){T rt = sqrt(n); return rt*rt == n;}

vector<LLI> divisor_list(LLI n){
  vector<LLI> temp, res;
  for(LLI i=1LL; i*i<n; ++i) if(n%i == 0) temp.push_back(i);
  for(auto i : temp) res.push_back(i);
  if(is_square(n)) res.push_back((LLI)sqrt(n));
  for(auto itr=temp.rbegin(); itr!=temp.rend(); ++itr) res.push_back(n/(*itr));
  return res;
}


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

  LLI N;
  while(cin >> N){
    auto divs = divisor_list(N);

    LLI ans = 0;

    for(auto d : divs){
      LLI m = N/d-1;
      if(d<m) ans += m;
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,arr[MAXN];
ll dp[MAXN];

ll solve(int idx){
    if(idx == 1) return 0;
    if(dp[idx] != -1) return dp[idx];
    if(idx == 2) return dp[2] = abs(arr[2]-arr[1]);
    return dp[idx] = min(abs(arr[idx]-arr[idx-1])+solve(idx-1),abs(arr[idx]-arr[idx-2])+solve(idx-2));
}

int main(){
    scanf("%d",&len);
    for(int i=1; i<=len; i++) scanf(" %d",&arr[i]);
    memset(dp,-1,sizeof dp);
    printf("%lld\n",solve(len));
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int t = (i >= b) ^ (j >= a);
            cout << t;
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 1280
def solve():
  ans = 0
  N = int(input())
  stacks = [list(map(lambda x:int(x)-1, input().split()))[::-1] for _ in range(N)]
  lis = [0]*N
  cnt = 0
  now = 0
  flag = 0
  while cnt<N*(N-1)//2:
    while not stacks[now]:
      now = (now+1)%N
    a = stacks[now][-1]
    while not stacks[a]:
      now = (now+1)%N
      a = stacks[now][-1]
    if stacks[a][-1] == now:
      lis[now] = max(lis[now],lis[a])+1
      lis[a] = lis[now]
      stacks[a].pop(-1)
      stacks[now].pop(-1)
      cnt += 1
      flag = 0
    else:
      now = a
      flag += 1
    if flag==N:
      return -1
  ans = max(lis)
  return ans
print(solve())

Measured memory_bytes: 84700
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

#define MAX 100000

vector<int> G[MAX];//??¢??????????±???????????????°??????
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;//dfs??§????¨?????????????

void dfs(int current, int prev) {
	//?????????current????¨????????????´????????????
	prenum[current] = lowest[current] = timer;
	timer++;

	visited[current] = true;

	int next;

	for (int i = 0; i < G[current].size(); i++) {
		next = G[current][i];

		if (visited[next] == false) {
			parent[next] = current;
			
			dfs(next, current);
			lowest[current] = min(lowest[current], lowest[next]);
		}
		else if (next != prev) {//?¬?????¨???????????¨????????????§?????§?????????????????????Back-edge?????´???
			lowest[current] = min(lowest[current], prenum[next]);
		}
	}
}

//??¢???????????¨?????????
void art_points()
{
	for (int i = 0; i < N; i++) {
		visited[i] = false;
	}


	dfs(0, -1);

	set<int> ap;
	int np = 0;
	for (int i = 1; i < N; i++) {
		int p = parent[i];
		if (p == 0) {
			np++;
		}
		else if(prenum[p] <= lowest[i]){
			ap.insert(p);
		}

	}

	if (np > 1) {
		ap.insert(0);
	}

	for (set<int>::iterator it = ap.begin(); it != ap.end(); it++) {
		cout << *it << endl;
	}

}

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

	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	art_points();
	
}

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

const int M=2e5+5;
char s[M];

char add[2][M];
int l[2];

char tmp[10];

int main()
{
	int rev=0;
	scanf("%s",s);
	int q; scanf("%d",&q);
	int t;
	while(q--)
	{
		scanf("%d",&t);
		if(t==1)
			rev^=1;
		else
		{
			scanf("%d%s",&t,tmp);
			t--;
			t^=rev;
			add[t][l[t]++]=tmp[0];
		}
	}
	if(rev)
	{
		for(int i=l[1]-1;i>=0;i--)
			putchar(add[1][i]);
		reverse(s,s+strlen(s));
		printf("%s",s);
		for(int i=0;i<l[0];i++)
			putchar(add[0][i]);
		putchar('\n');
	}
	else
	{
		for(int i=l[0]-1;i>=0;i--)
			putchar(add[0][i]);
		printf("%s",s);
		for(int i=0;i<l[1];i++)
			putchar(add[1][i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(y-r<0 || x-r<0 || x+r>W || y+r>H)
	printf("No\n");
	else 
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
string parts[4] = {"dream","dreamer", "erase", "eraser" };


int main() {
string input;
cin >> input;
//input = "dreameraser";

reverse(input.begin(), input.end());
rep(i,4){
  reverse(parts[i].begin(),parts[i].end());
}
bool can=true;
rep(i,input.size()){
  bool can2 = false;
  rep(j,4){
    if(input.substr(i,parts[j].size())==parts[j]){
      can2 = true;
      i+=parts[j].size()-1;
    }
  }
  if(can2==false){
    can = false;
    break;
  }
}


if(can) cout << "YES" << endl;
else cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

typedef short s;
int dp[41][451][451];
int main()
{
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    rep(i, N) {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }

    rep(i, N+1) {
        rep(j, 401) {
            rep(k, 401) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    rep(i, N) {
        rep(j, 401) {
            rep(k, 401) {
                if (dp[i][j][k] == INF) continue;
                dp[i+1][j][k] = min(dp[i][j][k], dp[i+1][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    int ans = INF;
    for(ll j = 1; j <=400; j++) {
        for(ll k = 1; k <=400; k++) {
            if (j*Mb == k * Ma) ans = min(ans, dp[N][j][k]);
        }
    }
    if (ans == INF) ans = -1;
    print(ans);
    return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long H, long long W, long long M, std::vector<long long> h, std::vector<long long> w){
    vector<int> rowCnt(H+1, 0), colCnt(W+1, 0), maxRows, maxCols;
    int maxRowCnt = 0, maxColCnt = 0;
    rep(i,0,M) {
        rowCnt[h[i]]++;
        colCnt[w[i]]++;
        maxRowCnt = max(maxRowCnt, rowCnt[h[i]]);
        maxColCnt = max(maxColCnt, colCnt[w[i]]);
    }
    rep(i,1,H+1) {
        if (maxRowCnt == rowCnt[i]) maxRows.push_back(i);
    }
    rep(i,1,W+1) {
        if (maxColCnt == colCnt[i]) maxCols.push_back(i);
    }
    bool minus = true;
    set<pair<int, int>> boms;
    rep(i,0,M) boms.insert({h[i], w[i]});
    for (const int r : maxRows) {
        for (const int c : maxCols) {
            if (boms.find({r, c}) == boms.end()) {
                minus = false;
                break;
            }
        }
        if (!minus) break;
    }
    int answer = maxRowCnt + maxColCnt;
    if (minus && answer > 0) answer--;
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> h(M);
    std::vector<long long> w(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&h[i]);
        scanf("%lld",&w[i]);
    }
    solve(H, W, M, std::move(h), std::move(w));
    return 0;
}


Measured memory_bytes: 26768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>                                                               
#include <stdio.h>   

#define LL long long
using namespace std;

int main(void){

    int n,d;

    cin >> n >> d;
    cout << ceil(n/((2 * d) + 1.0))<< endl;

    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int f=0;
	while(n)
	{
	    if(n%10==7)
	    {
	       f=1;
	       break;
	    }
	    n=n/10;
	}
	if(f)
	cout<<"Yes";
	else
	cout<<"No";
	
	
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#define ll long long
#define MOD 1000000007

using namespace std;
int main()
{
    int n;
    cin>>n;
    int **arr=new int*[n];
    for(int i=0;i<n;i++)
        arr[i]=new int[3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    int **dp=new int*[n];
    for(int i=0;i<n;i++)
        dp[i]=new int[3]();
    for(int i=0;i<3;i++)
        dp[0][i]=arr[0][i];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][2],dp[i-1][1])+arr[i][0];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
       
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 10928
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}


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

using namespace std;

int main()
{
	int n;
	int i=0;
	string s;
	string ans;
	int frcnt=0; //初めて(が出てくるまでの)の登場回数
	int flcnt=0; //初めて)が出てくるまでの(の登場回数
	int rcnt=0;
	int lcnt=0;
	int cnt;
	bool flag=false;
	cin>>n;
	cin>>s;
	ans=s;
	//全部チェック
	while(flag==false)
	{
		flag=true;
		for(int j=0;j<n-1;j++)
		{
			if(s[j]=='('&&s[j+1]==')')
			{
				s.erase(j,2);
				n -=2;
				flag=false;
			}
		}
	}
	for(int j=0;j<n;j++)
	{
		if(s[j]=='(')
		{
			lcnt++;
		}else if(s[j]==')'){
			rcnt++;
		}
	}
	//左から検査
	while(s[i]!='(' && i<n)
	{
		frcnt++;
		i++;
	}
	reverse(begin(s),end(s));
	i=0;
	//右から検査
	while(s[i]!=')' && i<n)
	{
		flcnt++;
		i++;
	}
	cerr<<flcnt<<" "<<frcnt<<endl;
	cerr<<lcnt<<" "<<rcnt<<endl;

	if(rcnt==0 || lcnt==0)
	{
		for(int j=0;j<rcnt;j++)
		{
			ans.insert(0,"(");
		}
		for(int j=0;j<lcnt;j++)
		{
			ans+=')';
		}
	}else{
		for(int j=0;j<frcnt;j++)
		{
			ans.insert(0,"(");
		}
		for(int j=0;j<flcnt;j++)
		{
			ans+=')';
		}
		if(frcnt+flcnt != rcnt+lcnt)
		{
			rcnt -= frcnt;
			lcnt -= flcnt;
			cnt=rcnt-lcnt;
			//(の方が多い
			if(cnt>0)
			{
				for(int j=0;j<cnt;j++)
				{
					ans.insert(0,"(");
				}
			}else if(cnt<0){
				cnt *= -1;
				for(int j=0;j<cnt;j++)
				{
					ans+=')';
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }

struct dat{
  string city;
  int score;
  int num;

  bool operator<(const dat& x) const {
    return city == x.city ? score > x.score : city < x.city;
  }
};

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

  int n; cin >> n;
  vector<dat> v;
  for (int i = 0; i < n; ++i) {
    string s; int score; cin >> s >> score;
    v.push_back({s, score, i + 1});
  }

  sort(all(v));
  for (int i = 0; i < n; ++i) {
    print(v[i].num);
  }

  return 0;
}

Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
      break
    elif m==-1 or f==-1:
      print("F")
    elif 80<=m+f:
      print("A")
    elif 65<=m+f:
      print("B")
    elif 50<=m+f:
      print("C")
    elif 30<=m+f:
      if r>=50:
        print("C")
      else:
        print("D")
    else:
      print("F")


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

using namespace std;

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

#define X first
#define Y second

const int M=6e4+10;
const int inf=1e9;
const int MOD=1e9+7;

struct maxflow{
    int m;
    int st,en;
    int v[M][2],flow[M][2],cap[M];

    int f[M],tr[M];
    vector <int> e[M];
    maxflow(){
        m=st=en=0;
    }
    void add_edge(int x,int y,int _cap){
//        cout<<x<<"->"<<y<<'\n';
        ++m;
        assert(m<M);
        v[m][0]=x;v[m][1]=y;
        e[x].push_back(m);
        e[y].push_back(m);
        cap[m]=_cap;
        flow[m][1]=_cap;
        flow[m][0]=0;
    }

    int q[M];
    bool BFS(int st){

        memset(tr,0,sizeof(tr));
        int top=1,bot=1;
        q[1]=st;
        while (top<=bot){
            int x=q[top++];

            if (x==en) return 1;
            for(auto i:e[x]){
                int dir=(x==v[i][1]);
                int y=v[i][dir^1];
                if (flow[i][dir]==cap[i]||tr[y]) continue;
                tr[y]=i;
                f[y]=min(f[x],cap[i]-flow[i][dir]);
                q[++bot]=y;
            }
        }
        return 0;
    }
    void inc_flow(){
        int cur=en;
        int ans=f[en];
        while (cur!=st){
            int use=tr[cur];
            int dir=(cur==v[use][0]);
            flow[use][dir]+=ans;
            flow[use][dir^1]-=ans;
            cur=v[use][dir];
        }
    }
    int answer(){
        int ans=0;
        f[st]=inf;
        while (BFS(st)){
            ans+=f[en];
            inc_flow();
        }
        return ans;
    }
}mflow;

int n,m;
string s[105];
void prepare(){
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>s[i];

    int sx,sy,ex,ey;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            if (s[i][j]=='S') mflow.st=n*m+i*m+j,sx=i,sy=j;
            if (s[i][j]=='T') mflow.en=i*m+j,ex=i,ey=j;
            if (s[i][j]!='.'){
                mflow.add_edge(i*m+j,i*m+j+n*m,1);
                mflow.add_edge(2*n*m+i,i*m+j,inf);
                mflow.add_edge(i*m+j+n*m,2*n*m+i,inf);
                mflow.add_edge(2*n*m+n+j,i*m+j,inf);
                mflow.add_edge(i*m+j+n*m,2*n*m+n+j,inf);
            }
        }
    if (sx==ex||sy==ey) {
        cout<<"-1";
        exit(0);
    }
}
int main(){
    prepare();
    cout<<mflow.answer();
}


Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	
	if(b-a <= 0)
	{
		cout << "delicious" << endl;
	}
	else if(a+x-b >= 0)
	{
		cout << "safe" << endl;
	}
	else
	{
		cout << "dangerous" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 
typedef long long ll;

using namespace std;

int main() {

	ll L, R; 
	cin >> L >> R;

	int mod_min = 2018;

	R = min(R, L + 2019);

	for (ll i = L; i < R; i++)
	{
		for (ll j = i + 1; j <= R; j++)
		{

			int mod = (i * j) % 2019;

			mod_min = min(mod_min, mod);
		}
	}

	cout << mod_min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[101],b[101];
bool mycmp(const char& a,const char& b)
{
	return a>b;
}
int main()
{
	scanf("%s",a);
	scanf("%s",b);
	sort(a,a+strlen(a));
	sort(b,b+strlen(b),mycmp);
	if(strcmp(a,b)<0)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=21;
vector<int> f[N][N];
int n,K; char s[1<<N];
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=0;i<=n;++i)
	{
		scanf("%s",s);
		for(int j=0;i+j<=n;++j) f[i][j].resize(1<<i+j);
		for(int j=0;s[j];++j) f[i][0][j]=(s[j]-'0');
	}
	for(int i=n;i;--i)
		for(int j=0;i+j<=n;++j)
			for(int k=0;k<(1<<i+j);++k) if(f[i][j][k])
			{
				int a=k>>j, b=(j?k&((1<<j)-1):0);
				f[0][j][b]+=f[i][j][k];
				if(a)
				{
					int p=32-__builtin_clz(a),nb=j?(b<<1|1):1;
					f[i-(i-p+1)][j+1][(a&((1<<p-1)-1))<<(j+1)|nb]+=f[i][j][k];
				}
				if(a!=(1<<i)-1)
				{
					unsigned tmp=(unsigned)a<<(32-i);
					int p=i-__builtin_clz(~tmp),nb=j?(b<<1):0;
					f[i-(i-p+1)][j+1][(a&((1<<p-1)-1))<<(j+1)|nb]+=f[i][j][k];
				}
			}
	for(int i=n;i;--i)
		for(int k=0;k<(1<<i);++k) if(f[0][i][k]>=K)
		{
			for(int j=i-1;~j;--j) putchar((k>>j&1)+'0');
			return 0;
		}
}


Measured memory_bytes: 165632
from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n = int(input())

clist = [''.join(sorted(input())) for _ in range(n)]

c = Counter(clist)

print(sum([v*(v-1)//2 for v in c.values()]))

Measured memory_bytes: 23892
n = int(input())
la = []
lb = []

for i in range(n):
    a, b = map(int, input().split())
    la.append(a)
    lb.append(b)

la.sort()
lb.sort()

if n % 2 == 1:
    lr = (n + 1) // 2
    ma = la[lr-1]
    mb = lb[lr-1]
    print(mb-ma+1)
else:
    l = n // 2
    r = n // 2 + 1
    ma = (la[l-1] + la[r-1]) / 2
    mb = (lb[l - 1] + lb[r - 1]) / 2
    print(int((mb-ma)*2+1))


Measured memory_bytes: 25476
s=input()
def comp():
    l=[]
    temp_S=s[0]
    cnt=1
    for i in range(1,len(s)):
        if s[i]==temp_S:cnt+=1
        else:
            l.append((temp_S,cnt))
            cnt=1
            temp_S=s[i]
    l.append((temp_S,cnt))
    return l
l=comp()
#print(l)
ans=[0]*len(s)

next_s='R'
cnt=0
for x,y in l:
    if cnt==0 and x=='L':
        ans[0]=y
        cnt+=y
    if x=='R':
        cnt+=y
        ans[cnt-1]+=(y+1)//2
        ans[cnt]+=y-(y+1)//2
    elif x=='L':
        ans[cnt]+=(y+1)//2
        ans[cnt-1]+=y-(y+1)//2
        cnt+=y
print(*ans)

Measured memory_bytes: 13432
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define int long long
/*#define endl "\n"*/
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22){
		cout<<"bust"<<endl;
	}
	else cout<<"win"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int K = scan.nextInt();
    int h[] = new int[N];
    int count = 0;
    for (int i = 0;i < N;i++) {
      h[i] = scan.nextInt();
      if (h[i] >= K) {
        count += 1;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 47612
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    ll a, b, c, k;

    cin >> a >> b >> c >> k;

    ll sum = 0;
    // a
    ll ap = min(a, k);
  	sum += ap;
  	k -= ap;
    // b
    ll bp = min (b, k);
    k -= bp;

    // c
    ll cp = min (c, k);
    sum -= cp;
    cout << sum;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;

const int nax = 2e5 + 5;
int height[nax];
int beauty[nax];
ll dp[nax];
const int MAX = 2e5;
int main()
{
    srand(time(NULL));
    int n;
    cin >> n;
    //n = MAX;

    int base = 1;
    while(base < n) {
        base *= 2;
    }
    vector<ll> tree(2*base);

    for(int i = 0; i < n; i++) {
        //height[i] = 1 + rand()%n;
        cin >> height[i];
        dp[i+1] = 0;
    }
    for(int i = 0; i < n; i++) {
        //beauty[i] = 1 + rand()%n;
        cin >> beauty[i];
    }

    for(int i = 0; i < n; i++) {
        dp[height[i]] = beauty[i];
        /*for(int h = 1; h < height[i]; h++) {
            dp[height[i]] = max(dp[height[i]], dp[h]+beauty[i]);
        }*/
        //find max from 1 to height[i]-1.
        int l = base+0, r = base+height[i]-2;
        ll maxval = 0;
        while(l <= r) {
            if(l%2) {
                maxval = max(maxval, tree[l]);
                l++;
            }
            if(r%2 == 0) {
                maxval = max(maxval, tree[r]);
                r--;
            }
            l /= 2;
            r /= 2;
        }
        //set dp[height[i]] to maxval.
        maxval = max(maxval+beauty[i], dp[height[i]]);
        int k = base+height[i]-1;
        tree[k] = maxval;
        while(k > 1) {
            tree[k/2] = max(tree[k/2], maxval);
            k /= 2;
        }
        dp[height[i]] = maxval;
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e5+10;

int main(){
	int N, M; cin>>N>>M;
	vector<int> P(MAX_N), Y(MAX_N);
	for(int i=0; i<M; i++) cin>>P[i]>>Y[i];
	map<int,vector<int>> v;
	for(int i=0; i<M; i++) v[P[i]].push_back(Y[i]);
	for(auto& p:v) sort(p.second.begin(), p.second.end());
	for(int i=0; i<M; i++){
		int j=lower_bound(v[P[i]].begin(), v[P[i]].end(), Y[i])-v[P[i]].begin();
		printf("%06d%06d\n", P[i], j+1);
	}
}

Measured memory_bytes: 14744
#include <bits/stdc++.h>
using namespace std;
#define N 201000

struct node {
	int num,d,id;
}a[N];
int n,x,y,cnt,v[N][2],v0[N][2],s[2],s0,s1;
long long ans,Ans,res;

bool cmp(node a,node b) {return a.num<b.num;}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d%d",&x,&y);
		a[++cnt].num=x; a[cnt].d=0; a[cnt].id=i;
		a[++cnt].num=y; a[cnt].d=1; a[cnt].id=i;
	}
	sort(a+1,a+cnt+1,cmp);
	for (int i=1;i<=n;i++) v[a[i].id][a[i].d]=1,ans+=a[i].num;
	for (int i=1;i<=n;i++)
		if (v[i][0]+v[i][1]==1) {
			if (v[i][0]) s[0]++;
			if (v[i][1]) s[1]++;
		}
	if (s[0] && s[1] && s[0]+s[1]==n); else return printf("%lld\n",ans),0;
	s0=s[0]; s1=s[1];
	memcpy(v0,v,sizeof(v));
	
	Ans=1e17;
	for (int st=1;st<=n;st++)
	{
		s[0]=s0; s[1]=s1;
		res=ans-a[st].num+a[n+1].num;
		v[a[st].id][a[st].d]=0,s[a[st].d]--;
		v[a[n+1].id][a[n+1].d]=1;
		if (v[a[n+1].id][0]+v[a[n+1].id][1]==1) s[a[n+1].d]++;
		else s[a[n+1].d^1]--;
		if (s[0] && s[1] && s[0]+s[1]==n); else {
			Ans=min(Ans,res);
			v[a[st].id][a[st].d]=1;
			v[a[n+1].id][a[n+1].d]=0;
			continue;
		}
		
		res=res-a[n+1].num+a[n+2].num;
		v[a[n+1].id][a[n+1].d]=0,s[a[n+1].d]--;
		v[a[n+2].id][a[n+2].d]=1;
		if (v[a[n+2].id][0]+v[a[n+2].id][1]==1) s[a[n+2].d]++;
		else s[a[n+2].d^1]--;
		if (s[0] && s[1] && s[0]+s[1]==n); else Ans=min(Ans,res);
		v[a[st].id][a[st].d]=1;
		v[a[n+1].id][a[n+1].d]=0;
		v[a[n+1].id][a[n+1].d]=1;
		v[a[n+2].id][a[n+2].d]=0;
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(void)
{
    int n,sumall;
    int i,j;
    while(1){
        scanf("%d",&n);
        if(n == 0) break;
        int a[n + 1][n + 1];
        for(i = 0; i <= n; i++){
            for(j = 0; j <= n; j++)
                a[i][j] = 0;
        }
        sumall = 0;
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                scanf("%d",&a[i][j]);
                a[i][n] += a[i][j];
                a[n][j] += a[i][j];
                sumall += a[i][j];
            }
        }
        for(i = 0; i <= n; i++){
            for(j = 0; j <= n; j++){
                if(i == n && j == n)
                    printf("%5d",sumall);
                else
                    printf("%5d",a[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 616
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	double p[n+1];
	for(int i=1; i<=n; i++) {
		scanf("%lf", &p[i]);
	}
	double dp[n+1][n+1];
	dp[1][0] = 1-p[1];
	dp[1][1] = p[1];
	for(int i=2; i<=n; i++) {
		dp[i][0] = dp[i-1][0]*(1-p[i]);
		for(int j=1; j<=i; j++) {
			dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
		}
	}
	double ans = 0.0;
	for(int i=n; i>n/2; i--) ans += dp[n][i];
	printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 69760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template< typename T >
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  Matrix<int> g(n, vector<int>(n));
  vector<vector<int>> g2(n);
  for(int i=0;i<n;++i) {
    for(int j=0;j<n;++j) {
      char tmp; cin >> tmp;
      g[i][j] = (int)(tmp - '0');
      if(g[i][j]) {
        g2[i].push_back(j);
        g2[j].push_back(i);
      }
      if(i != j && g[i][j] == 0) g[i][j] = INF;
    }
  }
  vector<int> col(n, -1);
  vector<bool> sel(n);
  queue<int> que;
  col[0] = 0;
  sel[0] = true;
  que.push(0);
  bool ok = true;
  while(!que.empty()) {
    if(!ok) break;
    int now = que.front(); que.pop();
    for(int i=0;i<(int)(g2[now].size());++i) {
      int next = g2[now][i];
      if(!sel[next]) {
        sel[next] = true;
        col[next] = !col[now];
        que.push(next);
      } else if(col[next] == col[now]) {
        ok = false;
        break;
      }
    }
  }
  if(!ok) {
    cout << -1 << endl;
    return 0;
  }
  warshall_floyd(g, INF);
  int ma = 0;
  for(int i=0;i<n;++i) {
    for(int j=0;j<n;++j) {
      ma = max(ma, g[i][j]);
    }
  }
  cout << ma + 1 << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    long long a,b,c,d,e,i,j;
    cin >> a;
    long long sum=0;
    map<long long,long long>mp;
    while(a--)
    {
        cin >> c;
        mp[c]++;
        sum+=c;
    }
    cin >> b;
    for(i=0;i<b;i++)
    {
        cin >> d >> e;
        sum=sum-mp[d]*d-mp[e]*e+(mp[d]+mp[e])*e;
        mp[e]+=mp[d];
        mp[d]=0;
        cout << sum << endl;






    }








}



Measured memory_bytes: 9464
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }


signed main()
{
	int R;
	cin >> R;
	cout << 2 * R * M_PI << endl;
}




Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll counter(ll x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}
int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  vector<vector<ll>> a(N,vector<ll>(N));
  for(ll i=0;i<N;i++){
    for(ll j=0;j<N;j++){
      a.at(i).at(j)=-1;
    }
  }
  for(ll i=0;i<N;i++){
    cin>>A.at(i);
    for(ll j=0;j<A.at(i);j++){
      ll m,n;
      cin>>m>>n;
      a.at(i).at(m-1)=n;
    }
  }
  ll ans=0;
  for(ll bit=1;bit<(ll)(1<<N);bit++){
    ll count=0;
    vector<ll> whether(1);
    for(ll i=0;i<1;i++){whether.at(i)=1;}
    for(ll i=0;i<N;i++){
      if((1<<i)&bit){
        count++;
        for(ll j=0;j<N;j++){
          if(a.at(i).at(j)!=-1){
            if(((bit>>j)&1)^a.at(i).at(j)){whether.at(0)=-1;}
          }
        }
      }
    }
    if(whether.at(0)==1){ans=max(ans,count);}
  }
  cout<<ans<<endl;
}

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

int main(void) {

	string num;
	while(true) {
		cin >> num;
		if(num == "0") {
			break;
		}

		int sum = 0;
		for(int i=0;i<num.size();i++) {
			sum += (int)(num[i] - '0');
		}

		cout << sum << endl;
	}

    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,cnt=0;
    cin >> n >> m;
    int swbin[m];//スイッチの条件を整数にして格納する配列
    int p[m];
    for(int i=0;i<m;i++){
        bitset<10> a;
        int k;
        cin >> k;
        int s[k];
        for(int j=0;j<k;j++){
            cin >> s[j];
            a.set(s[j]-1);
        }
        swbin[i]=a.to_ullong();
    }
    for(int i=0;i<m;i++) cin >> p[i];
    for(int i=0;i<(1<<n);i++){//点灯パターン
        bitset<10> s(i);
        bool c = 1;
        for(int j=0;j<m;j++){
            bitset<10> q(swbin[j]);//接続リスト
            if((s&q).count()%2!=p[j]) c=0;
        }
        if(c) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;
  string S;
  cin >> S;
  //より最初に左にあるほうをAとする
  if(A > B) {
    swap(A, B);
    swap(C, D);
  }
  // まずA~C、B~Dに(##)がないか確かめる
  // okがtrueなら答えはイエス
  bool ok = true;
  for(int i = A; i < C; i++) {
    if(S[i] == '#' && S[i + 1] == '#') {
      ok = false;
      break;
    }
  }
  for(int i = B; i < D; i++) {
    if(S[i] == '#' && S[i + 1] == '#') {
      ok = false;
      break;
    }
  }
  // ゴールがC, Dの順ならもうおわり
  if(C < D) {
    if(ok) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }
  //ゴールがD, Cの順のとき
  // 3マス空きがあるならgoodはtrue
  bool good = false;
  for(int i = B - 1; i <= D - 1; i++) {
    if(S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
      good = true;
      break;
    }
  }
  // okがtrueかつgoodがtrueならYES、それ以外はNO
  if(ok && good) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int A1, A2, A3;

int main(){
  cin >> A1 >> A2 >> A3;

  if(A1 + A2 + A3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;

  return 0;
}

Measured memory_bytes: 256
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N))
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            count = 0
            if a > max(useList):
                while not max(useList) > int(result[-1]):
                    count += 1
                    result = result[:-1]
                    if result == '':
                        break
                if result == '':
                    if useList[0] != 0:
                        result += str(useList[0])
                    else:
                        result += str(useList[1])
                    result += str(useList[0])*(len(N))
                    break
                count += 1
                sect = int(result[-1])
                result = result[:-1]
                result += str(useList[bisect.bisect_right(useList, sect)])
                result += str(useList[0])*(len(N)-len(result))
            else:
                result += str(useList[bisect.bisect_right(useList, a)])
                result += str(useList[0])*(len(N)-i-1)
            break
print(result)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int[] a = new int[4];
		int[] b = new int[4];
		
		while (sc.hasNext()) {
			for (int i = 0; i < 4; i++) {
				a[i] = sc.nextInt();
			}
			for (int i = 0; i < 4; i++) {
				b[i] = sc.nextInt();
			}
			
			int hit = 0;
			int blow = 0;
		
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					if (i == j && a[i] == b[j])
						hit++;
					if (i != j && a[i] == b[j])
						blow++;
				}
			}
			
			System.out.println(hit + " " + blow);
		}
	}

}

Measured memory_bytes: 26240
def run(d, n):
    if n == 100:
        return (n + 1) * (100 ** d)
    else:
        return n * (100 ** d)


def read_line():
    a, b = input().split()
    a = int(a)
    b = int(b)
    return (a, b)


def main():
    d, n = read_line()
    print(run(d, n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38424
#include <iostream>
#include <string>
using namespace std;
int main(){
    int N,K;
    cin >> N;
    string S;
    cin >> S;
    cin >> K;
    char T = S[K-1];
    for(int i=0;i<N;i++){
        if(S[i]!=S[K-1]){
            S.replace(i,1,"*");
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256