akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
const ll INF = 1001001000100010;
const ld PI = 3.14159265358979323846;


int main() {
ll N,min_num=INF,i=1;
string a,b;
cin>>N;
while(i<=sqrt(N)){
    if(N%i==0){
        a=to_string(i);
        b=to_string(N/i);
        if(min_num>max(a.size(),b.size()))

        min_num=max(a.size(),b.size());
    }
    i++;
}
cout<<min_num<<endl;

return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(V) V.begin(),V.end()
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;
using PLL = pair<ll, ll>;
using TLL = tuple<ll, ll, ll>;

const ll inf = 5e15;

void sort_and_unique(V<ll> &v) {
    sort(ALL(v));
    auto ite = unique(ALL(v));
    v.erase(ite, v.end());
}

map<ll, V<PLL>> create_map(const V<PLL> &shape) {
    ll N = shape.size();
    map<ll, V<PLL>> ret;
    for(ll i = 0; i < N; i++) {
        PLL p1 = shape[i], p2 = shape[(i + 1) % N];
        ll x1, y1, x2, y2;
        tie(x1, y1) = p1;
        tie(x2, y2) = p2;
        if(x1 != x2) continue;
        ret[x1].emplace_back(min(y1, y2), max(y1, y2));
    }

    for(auto &ele : ret) {
        ele.second.emplace_back(inf, inf);
        ele.second.emplace_back(-inf, -inf);
        sort(ALL(ele.second));
    }

    return move(ret);
}

bool check_inside(map<ll, V<PLL>> &mp, ll x, ll y1, ll y2, const V<ll> &xlis) {
    auto ite = lower_bound(ALL(xlis), x);
    if(*ite != x) return false;
    const auto &v = mp[x];
    PLL yline = *(upper_bound(ALL(v), PLL(y1, inf)) - 1);
    return yline.first <= y1 && y2 <= yline.second;
}

bool solve() {
    ll N;
    cin >> N;

    if(!N) return false;

    V<PLL> window, curtain;
    V<ll> xlis, ylis;
    V<ll> wxlis, cxlis;
    map<ll, V<PLL>> mp;

    for(ll i = 0; i < N + 4; i++) {
        ll x, y;
        cin >> x >> y;
        (i < N ? window : curtain).emplace_back(x, y);
        (i < N ? wxlis : cxlis).push_back(x);
        xlis.push_back(x);
        ylis.push_back(y);
    }

    wxlis.push_back(inf);
    cxlis.push_back(inf);

    sort_and_unique(xlis);
    sort_and_unique(wxlis);
    sort_and_unique(cxlis);
    sort_and_unique(ylis);

    auto window_mp = create_map(window);
    auto curtain_mp = create_map(curtain);

    ll ans = 0;
    bool inside_window = false, inside_curtain = false;

    ll px = -inf;
    for(ll yi = 0; yi < ylis.size() - 1; yi++) {
        for(ll xi = 0; xi < xlis.size(); xi++) {
            ll x = xlis[xi];
            ll y1 = ylis[yi], y2 = ylis[yi + 1];
            if(inside_window && !inside_curtain) {
                ans += (y2 - y1) * (x - px);
            }
            px = x;
            if(check_inside(window_mp, x, y1, y2, wxlis)) inside_window = !inside_window;
            if(check_inside(curtain_mp, x, y1, y2, cxlis)) inside_curtain = !inside_curtain;
        }
    }

    cout << ans << endl;
    return true;
}

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



Measured memory_bytes: 3120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Echizen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int[] arr = new int[3];
            arr[0] = a;
            arr[1] = b;
            arr[2] = c;
            Arrays.sort(arr);
            out.println(arr[0] + arr[1]);
        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  if (a < k && b > a+1) {
    ll ans = a, time = k-a+1;
    if (time/2 > 0)
      ans += (b-a)*(time/2);
    ans += time%2;
    cout << ans << endl;
  } else
    cout << k+1 << endl;
  return 0;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int k = 1;
  string prev = "";
  prev += s[0];
  for (int i = 1; i < sz(s);) {
    if (s[i] != prev[0] or sz(prev) > 1) {
      string cur = "";
      cur += s[i];
      prev = cur;
      k++;
      i++;
    } else {
      string cur = "";
      cur += s[i];
      i++;
      if (i == sz(s)) break;
      cur += s[i];
      prev = cur;
      k++;
      i++;
    }
  }
  cout << k << '\n';
  return (0);
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100000+5;
const string v[] = {"dream", "dreamer", "erase", "eraser"};

int n;
string s;
bool memo[N];

int main(){
	cin >> s;
	n = s.size();
	memo[0] = true;
	for(int i=1; i<=n; i++){
		memo[i] = false;
		for(int j=0; j<4; j++){
			int len = v[j].size();
			if(i < len) continue;
			if(s.substr(i-len,len) == v[j]){
				memo[i] |= memo[i-len];
			}
		}
	}
	puts(memo[n]?"YES":"NO");
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,m,i=0,j=0;cin>>n>>m;
if(n>1)
i=((n*(n-1))/2);
if(m>1)
j=((m*(m-1))/2);
cout<<i+j;
    return 0;
  
}


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

const long long MOD = 1000000007;
long long cnt[63];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n; cin >> n;
    memset(cnt, 0, sizeof(cnt));
    long long a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        for(int j = 0; j < 63; j++){
            if(a[i] >> j & 1) cnt[j]++;
        }
    }
    long long ans = 0LL;
    long long tmp = 1LL;
    for(int i = 0; i < 63; i++){
        if(cnt[i] == 0){
            tmp = (tmp * 2) % MOD;
            continue;
        }
        long long p = ((n-cnt[i])*cnt[i])%MOD;
        p = (tmp * p) % MOD;
        ans = (ans + p) % MOD;
        tmp = (tmp * 2) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

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

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

    }
}

LL comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int maxx = -1000;
    int miny = 1000;
    for( int i = 0; i < n; ++i ) {
        int a;
        cin >> a;
        maxx = max(maxx, a);

    }

    for( int i = 0; i < m; ++i ) {
        int a;
        cin >> a;
        miny = min(miny, a);

    }

    bool flg = false;
    for( int i = maxx + 1; i <= miny; ++i ) {
        if( x < i && i <= y ) flg = true;

    }
    if( flg ) cout << "No War";
    else cout << "War";
    cout << endl;
    return 0;
}



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

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int ans = 1e9;
    for(int i=0; i<=H; i++) for(int j=0; j<=W; j++){
        int res = i*W + j*H - i*j;
        if(res >= N) ans = min(ans, i+j);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long int
# define ld long double
# define pb push_back
# define mp make_pair
# define mod 1000000007
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#else
// online submission
	#endif
	IOS
	int r,c,k;
	cin >> r >> c >> k;
	char arr[r+1][c+1] = {'a'};
	int row[r][c+1] = {0}, col[r+1][c] = {0};
	int tot = 0;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> arr[i][j];
			if(arr[i][j] == '#')
				tot++;
		}
	}
	for(int i = 0; i < r; i++){
		row[i][0] = (arr[i][0] == '#');
		for(int j = 1; j <= c; j++){
			row[i][j] = row[i][j - 1] + (arr[i][j] == '#');
		}
	}
	for(int j = 0; j < c; j++){
		col[0][j] = (arr[0][j] == '#');
		for(int i = 1; i <= r; i++){
			col[i][j] = col[i - 1][j] + (arr[i][j] == '#');
		}
	}
	int ways = 0;
	for(int i = 0; i < (1 << r + 1); i++){
		int x = 0;
		vector<int> tempx;
		for(int j = 0; j < r; j++){
			if((i & (1 << j))){
				tempx.pb(j);
				x += row[j][c];
			}
		}
		for(int j = 0; j < (1 << c + 1); j++){
			int y = 0;
			vector<int> tempy;	
			for(int t = 0; t < c; t++){
				if((j & (1 << t))){
					y += col[r][t];
					tempy.pb(t);
				}
			}
			if(tempx.size() > 0 && tempy.size() > 0){
				for(int a : tempx){
					for(int b : tempy){
						y -= (arr[a][b] == '#');
					}
				}
			}
			if(tot - x - y == k){
				ways++;
			}
		}
	}
	cout << ways/4;
	return 0;
}

Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: int, B: int, C: int, s: "List[str]"):
    ans = []
    str2idx = {"AB": (0, 1), "BC": (1, 2), "AC": (0, 2)}
    abc = [A, B, C]
    for i, c in enumerate(s[:-1]):
        p, q = str2idx[c]
        np, nq = str2idx[s[i + 1]]
        if (abc[p] == abc[q] and (p == np or p == nq)) or abc[p] < abc[q]:
            abc[p] += 1
            abc[q] -= 1
            ans.append("ABC"[p])
        else:
            abc[q] += 1
            abc[p] -= 1
            ans.append("ABC"[q])
        if abc[0] < 0 or abc[1] < 0 or abc[2] < 0:
            print("No")
            return
    lp, lq = str2idx[s[-1]]
    if abc[lp] == abc[lq] == 0:
        print("No")
        return
    elif abc[lp] > abc[lq]:
        ans.append("ABC"[lq])
    else:
        ans.append("ABC"[lp])
    print("Yes")
    print("\n".join(ans))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, A, B, C, s)


if __name__ == "__main__":
    main()


Measured memory_bytes: 17700
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	string W, T;
	string::size_type W_size,T_size;
	int ans=0;
	
	cin>>W;
	transform(W.begin(),W.end(), W.begin(), ::toupper);
	W_size = W.size();
	
	for(;;){
	cin>>T;
	T_size = T.size();
	if(T != "END_OF_TEXT"){
		std::transform(T.begin(), T.end(), T.begin(), ::toupper);
		if(T.find(W) != string::npos){
			if(T_size == W_size)
			ans++;
		}
	}
	else
		break;
	}
	cout<<ans<<endl;
	
	return 0;
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int k;
int a[N];
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        /// freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1, [](int x, int y){
        return (x > y);
    });
    long long res = 0;
    for(int i = k + 1; i <= n; i ++){
        res += a[i];
    }
    cout << res << "\n";
}




Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a+n);
	int s = 0;
	for (int i = 0; i < n - 1; i++) {
		s += a[i];
	}
	printf("%d\n", s + (a[n - 1] / 2));
	return 0;
}

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

using namespace std;

vector<int> pri;
int isprime(int x){
  for(int i=0;i<pri.size();i++){
    if(x == pri[i])return 1;
    if(!(x % pri[i]))return 0;
  }
  return 1;
} 

void primecal(int x){
  bool ip;

  for(int i=2;i<=floor(sqrt(x));i++){
    ip = true;
    for(int j=0;j<pri.size();j++){
      if(!i%pri[j]){
	ip = false;
	break;
      }
    }
    if(ip)pri.push_back(i);
  }
}

int  main(){
  
    cin.tie(0);
    ios::sync_with_stdio(false);
  int mx,N,tmp;
  vector<int> a;
  cin >> N;
  mx = 0;
  for(int i=0;i<N;i++){
    cin >> tmp;
    a.push_back(tmp);
    mx = max(mx,tmp);
  }
  primecal(mx);
  int c=0;
  for(int i=0;i<N;i++)
    c += isprime(a[i]);

  cout << c << endl;
  
  return 0;
}

Measured memory_bytes: 3220
import heapq
from sys import stdin
input = stdin.readline

#入力
s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]


# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    if len(s)==2:
        print(s)
    else:
        print(s[::-1])
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N,M,cnt;
vector<int>mp[111111];
set<int>st;
int main(){
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        int a,b;
        cin>>a>>b;
        mp[a].push_back(i);
        mp[b].push_back(-i);
    }
    for(int i=1;i<=N;i++){
        sort(mp[i].begin(),mp[i].end());
        for(int j:mp[i]){
            if(j>0){
                st.insert(j);
            }
            else{
                if(st.find(-j)!=st.end()){
                    cnt++;
                    st.clear();
                }
            }
        }
    }
    cout<<cnt<<'\n';
    return 0;
}


Measured memory_bytes: 7676
#include<stdio.h>
int a[1000001],b[1000001];
int main(void)
{
	int i,j=1,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++) b[i]=0;
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	if(n%2==0){
		for(i=n;i>=1;i-=2){
			b[j]=a[i];
			j++;
		}
		for(i=1;i<=n;i+=2){
			b[j]=a[i];
			j++;
		}
	}
	if(n%2!=0){
		for(i=n;i>=1;i-=2){
			b[j]=a[i];
			j++;
		}
		for(i=2;i<=n;i+=2){
			b[j]=a[i];
			j++;
		}
	}
	for(i=1;i<=n;i++){
		printf("%d",b[i]);
		if(i==n) printf("\n");
		else  printf(" ");
	}
	return 0;
}

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

using namespace std;

int main() {
    int s;
    cin >> s;
    int a=s/100, b=s%100;
    if(a>0 && a<=12 && b>0 && b<=12) cout << "AMBIGUOUS" << endl;
    else if(a>0 && a<=12) cout << "MMYY" << endl;
    else if(b>0 && b<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;

    return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int feeA = A * N;
  int answer;
  if ( feeA < B ) {
    answer = feeA;
  }
  else {
    answer = B;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fly ios::sync_with_stdio(false); cin.tie(nullptr); 
using namespace std;
typedef long long ll;

int main() {
    fly;
    ll n;  cin >>n;
    ll arr[n][3];
    for(ll i=0;i<n;i++){
        cin >>arr[i][0] >>arr[i][1] >>arr[i][2];
    }
    ll dp[n][3];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    
    for(ll i=1;i<n;i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+arr[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+arr[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+arr[i][2];
    }
    
    ll answer = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
    
    cout<<answer;
    
    return 0;
}


Measured memory_bytes: 8216
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int N;
multiset<double> v;
int main()
{
   cout << fixed << setprecision(10);
   cin >> N;
   int value;
   REP(i, N) {
      cin >> value;
      v.insert(double(value));
   }
   double prev;
   while (SZ(v)!=1) {
      auto itr = v.begin();
      double a = *itr;
      itr++;
      double b = *itr;
      v.erase(itr);
      itr--;
      itr = v.begin();
      v.erase(itr);
      v.insert(a/2+b/2);
   }
   auto itr = v.begin();
   cout << *itr << endl;
   return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N; cin >> N;
  unordered_map<string, int> ans;
  REP(n,N) {
    string s; cin >> s;
    ans[s]++;
  }

  printf("AC x %lld\n", ans["AC"]);
  printf("WA x %lld\n", ans["WA"]);
  printf("TLE x %lld\n", ans["TLE"]);
  printf("RE x %lld\n", ans["RE"]);

  return 0;
}


Measured memory_bytes: 3724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			ConversionMap cmap = new ConversionMap();
			int num = Integer.parseInt(br.readLine());

			if(num == 0){
				break;
			}

			for(int i = 0; i < num; i++){
				String[] tmpStr = br.readLine().split(" ");
				cmap.setConversion(tmpStr[0].charAt(0), tmpStr[1].charAt(0));
			}

			int strLength = Integer.parseInt(br.readLine());

			for(int i = 0; i < strLength; i++){
				System.out.print(cmap.getConversion(br.readLine().charAt(0)));
			}
			System.out.println();
		}

	}

}

class ConversionMap {
	private char[] map;

	public ConversionMap(){
		map = new char[128];
		//init
		for(int i = 0; i < map.length; i++){
			map[i] = (char)(i);
		}
	}

	public void setConversion(char a, char b){
		map[(int)a] = b;
	}

	public char getConversion(char a){
		return map[(int)a];
	}
}

Measured memory_bytes: 48396
S=input()
s=list()
a=['k','e','y','e','n','c','e']
j,p=1,1
for i in S:
	s.append(i)
c,t=len(s),len(a)
if s[0]!=a[0]:
	if s[-t:c]!=a:
		p=0
else:
	for i in range(6):
		if (s[0:j]!=a[0:j]) & (s[(-t):c]!=a[(-t):7]):
			p=0
		t=t-1
		j=j+1
if p==1:
	print('YES')
elif p==0:
	print('NO')

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

int main(){
    long int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    int count;
    int ans=0;
    for(int i=0;i<n-1;i++){
        count=0;
        for(int h=i;h<n-1;h++){
            if(a.at(h+1)<=a.at(h))count+=1;
            else break;
        }
    

        ans=max(count,ans);
        if(ans>n-i)break;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll A,B,C;cin >> A >> B >> C;
  cout << min(C,A+B+1) + B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lll;
vector<lll> v;
lll ss(lll x)
{
    lll ret=0;
    for(; x; x/=10) ret+=x%10;
    return ret;
}
lll nx(lll x)
{
    if(x<999) return x+1;
    lll n=x+1,d=0;
    for(; n; n/=10) ++d;
    for(d-=3,n=1; d--;) n*=10;
    return x+n;
}
int main()
{
    lll i=1,k;
    for(scanf("%lld",&k); i<10; ++i) v.push_back(i);
    for(i=10; i<1000000000000000LL; v.push_back(i),i=nx(i)) while(i*ss(v.back())<v.back()*ss(i)) v.pop_back();
    for(i=0; i<k; ++i) printf("%lld\n",v[i]);
    exit(0);
}

Measured memory_bytes: 256
#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)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n; cin >> n;
    if(n == 22) cout <<"Christmas Eve Eve Eve" << endl;
    if(n == 23) cout <<"Christmas Eve Eve" << endl;
    if(n == 24) cout <<"Christmas Eve" << endl;
    if(n == 25) cout <<"Christmas" << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
   int N,R;
   int nai;
   scanf("%d %d",&N,&R);
   if(N>=10){
      nai=R;
   }else if(N<10){
      nai=R+100*(10-N);
   }
   printf("%d",nai);
   return 0;
}


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

int main() {
  int n, a[110], ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, greater<int>());
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      ans -= a[i];
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int  a;
long long f1,f2,k;


int main(void) {
  f1=1;
  f2=1;
  scanf("%d",&a);
  if(a==0 || a==1){
  printf("1\n");
}
 else{

   for(int i=0;i<=a-2;i++){
     k=f1;
     f1 = f1+f2;
     f2=k;
   }

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

 }
      	return 0;

}



Measured memory_bytes: 2144
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i = 0;i < n;i++){
			double x1 = in.nextDouble();
			double y1 = in.nextDouble();
			double x2 = in.nextDouble();
			double y2 = in.nextDouble();
			double x3 = in.nextDouble();
			double y3 = in.nextDouble();
			double A2 = Math.pow((x1-x2),2.0)+Math.pow((y1-y2),2.0); 
			double B2 = Math.pow((x2-x3),2.0)+Math.pow((y2-y3),2.0); 
			double C2 = Math.pow((x3-x1),2.0)+Math.pow((y3-y1),2.0); 
			double A = Math.pow(A2,0.5); 
			double B = Math.pow(B2,0.5);  
			double C = Math.pow(C2,0.5); 
			double sinA = (Math.pow((4*B2*C2)-Math.pow((C2+B2-A2),2.0),0.5))/(2*B*C);
			double R = A/(2*sinA);
			double xen = ((y1-y3)*(Math.pow(y1,2.0)-Math.pow(y2,2.0)+Math.pow(x1,2.0)-Math.pow(x2,2.0))
					-(y1-y2)*(Math.pow(y1,2.0)-Math.pow(y3,2.0)+Math.pow(x1,2.0)-Math.pow(x3,2.0)))/
					(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
			double yen = ((x1-x3)*(Math.pow(x1,2.0)-Math.pow(x2,2.0)+Math.pow(y1,2.0)-Math.pow(y2,2.0))
					-(x1-x2)*(Math.pow(x1,2.0)-Math.pow(x3,2.0)+Math.pow(y1,2.0)-Math.pow(y3,2.0)))/
					(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
			System.out.printf("%1.3f %1.3f %1.3f\n",xen,yen,R);
		}
	}
}

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

int main(){
	int n;
	string s;
	cin >>n >> s;
	string a = s.substr(0, n/2);
	string b = s.substr(n/2);
	if(a == b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;
	
const int maxn=1e5;
int b[maxn];

int main()
{
	int a,c,d=0;
	cin >> a >> c;
	string s[a];
	for(int i=0;i<a;i++)
	{
		cin >> s[i];
		for(int j=0;j<c;j++)
			if(s[i][j] == '#')
				d++;
	}
	if(d==a+c-1)
		cout << "Possible";
	else cout << "Impossible";
}

 



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x0123456789) cerr<<#x0123456789<<':'<<x0123456789<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x0123456789:v)cerr<<x0123456789<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;
typedef long double ld;

ll func(string s){
    ll ans = 0;
    string num = "123456789";
    FOR(i,1,10){
        if(s[0]==num[i-1])ans += 100*i;
        if(s[1]==num[i-1])ans += 10*i;
        if(s[2]==num[i-1])ans += 1*i;
    }
    return ans;
}

signed main(){
    ll ans = INF;
    string S;
    cin >> S;
    FOR(i,0,S.size()-2){
        string s = S.substr(i,3);
        ans = min(ans,(ll)abs(func(s)-753));
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {
    int n;  cin >> n;
    vector<int> vc;

    bool evenState = true;
    int ret = 0;
    for (int i = 0; i < n; i++) {
        int a;  cin >> a;
        if (a % 2 == 1) {
            evenState = false;
            break;
        }
        vc.push_back(a);
    }

    while(evenState) {
        ret++;
        for (auto &e: vc) {
            e /= 2;
            if (e % 2 == 1) evenState = false;
       }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int int64_t
#define fi first
#define se second
signed main(){
  string s,c,e;
  int ans=0,m=0,sum;
  map<char,int> d;
  vector<char> v;
  cin>>s;
  for(int i=0;i<s.size();i++){
    d[s[i]]++;
    if(d[s[i]]==1) v.push_back(s[i]);
  }
  e=s;
  for(int j=0;j<v.size();j++){
    sum=0;
    s=e;
    while(true){
      string q;
      m=0;
      for(int i=0;i<s.size();i++){
	if(s[i]==v[j]) m++;
      }
      if(m==s.size()) break;
      for(int i=0;i<s.size()-1;i++){
	if(s[i]==v[j]||s[i+1]==v[j]){
	  q+=v[j];
	}
	else{
	  q+=s[i];
	}
      }
      swap(s,q);
      sum++;
    }
    if(j==0) ans=sum;
    ans=min(ans,sum);
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline


def main():
    _, K = map(int, input().split())
    X = [int(c) for c in input().split()]

    def fullsearch():
        for l, r in zip(X, X[K-1:]):
            distance = abs(r - l)
            yield distance + abs(r)
            yield distance + abs(l)

    print(min(fullsearch()))

main()

Measured memory_bytes: 14172
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                cnt += 1

print(cnt)


Measured memory_bytes: 9108
#include <stdio.h>
#include <string.h>
void swap_int(int* x, int* y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void swap_char(char* x, char* y) {
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

void asc_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] > array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

void dec_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] < array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

int max(int x, int y) {
    if (x > y) {
        return x;
    } else {
        return y;
    }
}

int min(int x, int y) {
    if (x > y) {
        return y;
    } else {
        return x;
    }
}
typedef struct {
    char str[20];
    int num;
    int order;
} group;

int main(void) {
    int n;
    int i, j, k;
    group gp[200], tmp;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %d", gp[i].str, &gp[i].num);
        gp[i].order = i + 1;
    }

    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (!strcmp(gp[i].str, gp[j].str)) {
                if (gp[i].num < gp[j].num) {
                    tmp = gp[i];
                    gp[i] = gp[j];
                    gp[j] = tmp;
                }
            } else if (strcmp(gp[i].str, gp[j].str) > 0) {
                tmp = gp[i];
                gp[i] = gp[j];
                gp[j] = tmp;
            }
        }
    }
    for (i = 0; i < n; i++) {
        printf("%d\n", gp[i].order);
    }
    return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    T = input().strip()

    if S == T[:len(S)] and len(T) - len(S) == 1:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 累乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
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;
}
 
//int dx[4] = {1, 0, 0, -1}, dy[4] = {0, 1, -1 ,0};
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
 
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
ll N;
cin >> N;
map<ll, ll>mp;
vector<ll>a(N);
REP(i, N){
    cin >> a[i];
    mp[a[i]]++;
}

ll sum = 0;
for(auto x : mp){
    sum += x.second * (x.second - 1) / 2;
}

for(auto x : a){
    cout << sum - (mp[x] - 1) << endl;
}

return 0;
}


Measured memory_bytes: 11008
import math
from datetime import date

def main():
		
	line = input().split()
	n = int(line[0])
	k = int(line[1])


	a = []
	for i in range(n):
		s = input()
		a.append(s)

	ans = "";
	for x in sorted(a):
		ans += x

	print(ans)
	
main()


Measured memory_bytes: 9404
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c,dp[3]={0},i,f=1,k1,k2,k3;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a>>b>>c;
        if(f==1)
        {
            dp[0]=a;
            dp[1]=b;
            dp[2]=c;
            f=0;
        }
        else
        { //cout<<"hi ";
        k1=max(a+dp[1],a+dp[2]);
        k2=max(b+dp[0],b+dp[2]);
        k3=max(c+dp[0],c+dp[1]);
        dp[0]=k1;
        dp[1]=k2;
        dp[2]=k3;
        }
       
            }
   
    cout<<max(dp[0],max(dp[1],dp[2]));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 101

void Depth(int);

int G[MAX][MAX],D[MAX],d[MAX],f[MAX];
int n,count=1;

int main( ){
  int i,j,k,l,v,u;

  scanf("%d",&n);
  D[0] = 0;
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  for(i=0;i<n;i++){
    if(D[i]==0){
      Depth(i);
    }
  }
  
  for(i=0;i<n-1;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  printf("%d %d %d\n",i+1,d[i],f[i]);
  
  return 0;
}

  
void Depth(int a) {
  int b;

  d[a] = count++;
  D[a] = 1;
  
  for(b = 0 ; b < n ; b++) {
    if(G[a][b] == 1 && D[b] == 0) {
      Depth(b);
    }
  }
  
  f[a] = count++;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
using namespace std;
ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x);
        x=(x*x);
        y=y/2;
    }
    return res;
}
int main()
{
    ll n,p;
    cin>>n;
    vector<ll>v,dp(n+1);
    dp[0]=0;//if one stone then cost incurred=0
    for(ll i=0;i<n;i++)
    {
        cin>>p;
        v.pb(p);
    }
    if(n>1)
        dp[1]=abs(v[0]-v[1]);
    for(ll i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    cout<<dp[n-1];
}

Measured memory_bytes: 2168
#include <iostream>;
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=2;i<=n;i++)
        cin>>a[i];
   
    int b[n+1];
    for(int i=0;i<=n;i++)
        b[i]=0;
    for(int i=2;i<=n;i++)
    {b[a[i]]++;

    }
    for(int i=1;i<=n;i++)
    {cout<<b[i]<<endl;

    }

}


Measured memory_bytes: 5224
from itertools import cycle, chain, repeat

# 入力
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

# (1, 1), (1, 2), ..., (1, W), (2, W), (2, W - 1), ..., (2, 2), (2, 1),
# (3, 1), (3, 2), ... の順で色1(1マス目), 色1(2マス目), ..., 色1(a_1マス目),
# 色2(1マス目), ..., 色2(a_2マス目), 色3(1マス目), ... と塗る
c = {
    (i, j): k
    for k, i, j in zip(
        chain(
            *(
                repeat(k, m)
                for k, m in enumerate(a, 1)
            )
        ),
        chain(
            *(
                repeat(r, W)
                for r in range(H)
            )
        ),
        cycle(
            chain(
                range(W),
                reversed(range(W)),
            )
        )
    )
}
ans = '\n'.join(
    ' '.join(
        str(c[(i, j)])
        for j in range(W)
    )
    for i in range(H)
)

# 出力
print(ans)


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

using namespace std;

int main() {
    int N, X, Y;
    int res[2000] = {};
    cin >> N >> X >> Y;

    for (int i = 1; i <= N; ++i) {
        for (int j = i; j <= N; ++j) {
            res[min((j - i), abs(X - i) + 1 + abs(Y - j))]++;
        }
    }

    for (int k = 1; k < N; ++k) {
        cout << res[k] << endl;
    }
    return 0;
}


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

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

map<string, int> mp;
int ans;

int main(){
    int n, m;
    string str[n + m];

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> str[i];
        mp[str[i]]++;
    }
    cin >> m;
    for (int i = n; i < n + m; i++){
        cin >> str[i];
        mp[str[i]]--;
    }

    for (int i = 0; i < n + m; i++){
        ans = max(ans, mp[str[i]]);
    }

    cout << max(ans, 0) << endl;

    return 0;
}

Measured memory_bytes: 33024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        var sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        var a = new int[n];
        Arrays.setAll(a, $ -> Integer.parseInt(sc.next()));
        var b = new int[n];
        Arrays.setAll(b, $ -> Integer.parseInt(sc.next()));
        sc.close();

        var x = new int[n];
        int inf = 1000000000;
        int min = inf;
        for (int k = 0; k < 1 << n; k++) {
            for (int i = 0; i < n; i++) {
                if ((k & (1 << i)) == 0) { // Front
                    x[i] = a[i];
                } else {                   // Back
                    x[i] = ~b[i];
                }
            }
            // Normal Bubblesort. 
            // The variable c means the inversion number (= the number of swap-and-flip operations) of the array x.
            int c = bubblesort(x, n);
            // Adjusting Front/Back.
            for (int i = 0; i < n - 1; i++) {
                if (x[i] < 0) {
                    // ~2, 2, 2, ~2 => ~2, ~2, ~2, ~2
                    if (x[i + 1] >= 0 && i + 2 < n) {
                        swapAndFlip(x, i + 1, i + 2);
                        c++;
                    }
                    // ~2, ~2, ~2, ~2 => 2, 2, ~2, ~2
                    swapAndFlip(x, i, i + 1);
                    c++;
                }
            }
            // Making sure the array x is correctly sorted
            if (allPositive(x, n) && isAscending(x, n)) {
                min = Math.min(min, c);
            }
        }
        System.out.println(min == inf ? -1 : min);
    }

    public static int bubblesort(int[] x, int n) {
        int c = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = n - 1; j > i; j--) {
                int u = x[j - 1] < 0 ? ~x[j - 1] : x[j - 1];
                int v = x[j]     < 0 ? ~x[j]     : x[j]    ;
                if (u > v) {
                    swapAndFlip(x, j - 1, j);
                    c++;
                }
            }
        }
        return c;
    }

    public static void swapAndFlip(int[] x, int i, int j) {
        int tmp = x[i];
        x[i] = ~x[j];
        x[j] = ~tmp;
    }

    public static boolean allPositive(int[] x, int n) {
        for (int i = 0; i < n; i++) {
            if (x[i] < 0) {
                return false;
            }
        }
        return true;
    }

    public static boolean isAscending(int[] x, int n) {
        for (int i = 0; i < n - 1; i++) {
            if (x[i] > x[i + 1]) {
                return false;
            }
        }
        return true;
    }
}


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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5;
int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
ll infll = 1e18 + 7;

int f(int x){
    int ans = 0;
    Ford(i, 50, 0){
        int t = x / (1ll << i);
        if (t % 2 == 0) continue;
        int kek = x % (1ll << i);
        if (kek % 2 == 0) ans ^= (1ll << i);
    }
    if (x % 4 == 1 || x % 4 == 2) ans++;
    return ans;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int x, y; cin >> x >> y;
    cout << (f(x - 1) ^ f(y));
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256