akhauriyash/Code-Regression huggingface dataset:
//Coded by not_surrender
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

#define MAXN 300003
#define MOD 1000000007
#define oo (1<<20)
#define mid ((a+b)/2)
#define pb push_back
#define sz size()
#define fastCpp() ios_base::sync_with_stdio( false ), cin.tie( NULL ), cout.tie( NULL )

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;

struct Data{
	int n1, n2;
	Data(int n1 = 0, int n2 = 0):n1(n1),n2(n2){}
}dp[MAXN];

int N, M, ans;
 
int main(){

    #ifndef ONLINE_JUDGE
		//~ freopen( "a.txt", "r", stdin );
    #endif // ONLINE_JUDGE
    
    fastCpp();
    
    scanf( "%d", &N );
    
    M = (1<<N);
    
    for ( int i = 0; i < M; ++i )
		scanf( "%d", &dp[i].n1 );
    
    for ( int i = N-1; i >= 0; --i ){
		for ( int j = M-1, nxt; j > 0; --j ){
			nxt = j-(j&(1<<i));
			if ( nxt < j ){
				if ( dp[nxt].n1 > dp[j].n1 )
					dp[j].n2 = dp[j].n1, dp[j].n1 = dp[nxt].n1;
				else
					dp[j].n2 = max( dp[j].n2, dp[nxt].n1 );
			}
		}
	}
	
	for ( int i = 1, ans = 0; i < M; ++i ){
		ans = max( ans, dp[i].n1+dp[i].n2 );
		printf( "%d\n", ans );
	}
	
return 0;
}


Measured memory_bytes: 5376
N = int(input())
b = list(map(int,input().split()))
flag = 0
for i in range(N):
    if b[i] > i+1:
        flag = 1
ans = [0 for i in range(N)]
if flag == 1:
    print(-1)
if flag == 0:
    for i in range(N):
        for j in range(N-1,b[i]-1,-1):
            ans[j] = ans[j-1]
        ans[b[i]-1] = b[i]
    for i in range(N):
        print(ans[i])

Measured memory_bytes: 3064
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int W = Integer.parseInt(S[0]);
    int H = Integer.parseInt(S[1]);
    int N = Integer.parseInt(S[2]);
    
    int ax = 0;
    int ay = 0;
    int bx = W;
    int by = H;
    
    for(int i = 0; i < N; i++){
      String[] T = sc.nextLine().split(" ");
      int x = Integer.parseInt(T[0]);
      int y = Integer.parseInt(T[1]);
      int order = Integer.parseInt(T[2]);
      
      if(order == 1 && x > ax){
        ax = x;
      }else if(order == 2 && x < bx){
        bx = x;
      }else if(order == 3 && y > ay){
        ay = y;
      }else if(order == 4 && y < by){
        by = y;
      }
    }
    int ans = Math.max(0, (bx - ax)) * Math.max(0, (by - ay));
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int N=1000;
 
 
int lcs(string X,string Y){
    int c[N+1][N+1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for(int i=0;i<=m;i++) c[i][0]=0;
    for(int j=1;j<=n;j++) c[0][j]=0;
     
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(X[i]==Y[j]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i-1][j],c[i][j-1]);
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}
int main(){
    string s1,s2;
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
bool g[10][10];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int a,b;
    scanf("%d%d",&a,&b);
    --a;--b;
    g[a][b]=g[b][a]=true;
  }
  vi v(n);
  REP(i,n)v[i]=i;
  int ans = 0;
  do{
    bool ok = true;
    REP(i,n-1){
      if(!g[v[i]][v[i+1]])ok=false;
    }
    if(ok)ans++;
  }while(next_permutation(v.begin()+1,v.end()));
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;

int main()
{
	int L;
	while(cin >> L && L)
	{
		int n,m;
		int flag=0;
		for(int i=0;i<12;i++)
		{
			cin >> n >> m;
			L-=(n-m);
			if(L<=0 && !flag)
			{
				flag=1;
				cout << i+1 << endl;
			}
		}
		if(L>0)cout << "NA" << endl;
	}

    return 0;
}

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

typedef long long ll;

/* メモリ食い過ぎ注意 */
#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
const ll MAX = 1e6;
/* end defineing */

signed main()
{
    string s;
    cin >> s;
    if (s.length() > 9)
    {
        cout << "NO" << endl;
        return 0;
    }

    vector<string> v;
    v.push_back("KIHBR");
    v.push_back("AKIHBR");
    v.push_back("KIHABR");
    v.push_back("KIHBAR");
    v.push_back("KIHBRA");
    v.push_back("AKIHABR");
    v.push_back("AKIHBAR");
    v.push_back("AKIHBRA");
    v.push_back("KIHABAR");
    v.push_back("KIHABRA");
    v.push_back("KIHBARA");
    v.push_back("AKIHABAR");
    v.push_back("AKIHABRA");
    v.push_back("AKIHBARA");
    v.push_back("KIHABARA");
    v.push_back("AKIHABARA");

    for (int i = 0; i < v.size(); i++)
        if (v[i] == s)
        {
            cout << "YES" << endl;
            return 0;
        }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int arr[10],x,i;

    for(i=1;i<=5;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            x=i;
        }
    }

    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n,i,j,p,q,t;
	while(cin>>n)
	{
		if(n<1||n>100)
		break;
		if(n<4){
			cout<<"No"<<endl;
			break;
		}
		p=n/4;
		q=n/7;
		t=0;
		for(i=0;i<=p;i++){
			for(j=0;j<=q;j++){
				if((4*i+7*j)==n)
				{
					t++;
				} 
			}
		}
		if(t==0)cout<<"No"<<endl;
		else  cout<<"Yes"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int L[250010];
int R[250010];
int cnt = 0;

void merge(int A[], int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;

  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] = 2000000000;
  int i = 0;
  int j = 0;

  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] < R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  if (left+1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main () {
  int n;
  cin >> n;
  int A[500010];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  mergeSort(A, n, 0, n);

  // 出力
  // 数列
  for (int i = 0; i < n; i++) {
    if (i) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;

  // 比較回数
  cout << cnt << endl;

}



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

using namespace std;

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


int main() {

	int N;
	cin >> N;

	int res,minres;
	res = 0;
	minres = 999999;

	REP3(i, N-1) {
		res = 0;
		int a, b;
		a = i;
		b = N - i;
		while (a > 0) {
			res += a % 10;
			a /= 10;
		}
		while (b > 0) {
			res += b % 10;
			b /= 10;
		}
		minres = min(minres, res);
	}

	cout << minres << endl;

	int end;
	cin >> end;

	return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = sorted([int(x) for x in input().split()])
ans = 0
for i in range(N):
    if x < a[i]:
        break
    ans += 1
    x -= a[i]
    if i == N - 1 and x != 0:
        ans -= 1
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <stack>
#include <vector>

typedef long long ll;
using namespace std;



int main()
{
	char c;
	scanf("%c", &c);

	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		printf("vowel\n");
	}
	else {
		printf("consonant\n");
	}
	
	return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
    int x;  cin >> x;
    int v[] = {100, 101, 102, 103, 104, 105};
    bool *dp = new bool[x+1];
    for (int i = 0; i <= x; i++)
        dp[i] = false;
    dp[0] = true;
    for (int i = 99; i < x; i++) { //dp[i+1]を更新する
        for (int j = 0; j < 6; j++) {
            if (v[j] <= i+1) {
                if (dp[i+1-v[j]] == true)
                    dp[i+1] = true;
            }
        }
    }

    if (dp[x])
        cout << 1 << endl;
    else 
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
  int N,K; cin>>N>>K;
  cout<<(N+K-3)/(K-1)<<endl;
}

Measured memory_bytes: 3640
n = int(input())
a_list = [int(s) for s in input().strip().split()]
q = int(input())

b_list = [0] * q
c_list = [0] * q
for i in range(q):
    b, c = [int(s) for s in input().strip().split()]
    b_list[i] = b
    c_list[i] = c

num_list = [0] * (10**5 + 1)
for i in a_list:
    num_list[i] += 1
num_sum = sum([i * n for i, n in enumerate(num_list)])

for b, c in zip(b_list, c_list):
    num_sum += (c - b) * num_list[b]
    num_list[c] += num_list[b]
    num_list[b] = 0
    print(num_sum)


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

int main()
{
	string s;
	cin >> s;

	if (*s.rbegin() != 's')
	{
		s += 's';
	}
	else
	{
		s += "es";
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

void solve (int n)
{
    int m;
    cin >> m;
    vi a(m);
    for (int i = 0; i < m; i++)
        cin >> a[i];

    if (m == 1)
    {
        if (a[0] == 1)
            cout << a[0] << endl << "1" << endl << "1" << endl;
        else
            cout << a[0] << endl << "2" << endl << a[0] - 1 << " 1" << endl;
        return;
    }

    int cnt = 0;
    for (int x : a)
        cnt += x % 2;

    sort(ALL(a), [] (int x, int y) {return x % 2 > y % 2;});
    sort(a.begin() + 1, a.end(), [] (int x, int y) {return x % 2 < y % 2;});
    if (cnt > 2)
    {
        cout << "Impossible" << endl;
        return;
    }

    for (int i = 0; i < sz(a); i++)
        cout << a[i] << " \n"[i + 1 == sz(a)];

    vi res;
    for (int i = 0; i < sz(a); i++)
    {
        res.pb(a[i]);
        if (i == 0)
            res.back()--;
        if (i + 1 == sz(a))
            res.back()++;
        if (res.back() == 0)
            res.pop_back();
    }

    cout << sz(res) << endl;
    for (int i = 0; i < sz(res); i++)
        cout << res[i] << " \n"[i + 1 == sz(res)];
};

int main()
{
    #ifndef ONLINE_JUDGE
   // freopen("input.txt", "rt", stdin);
   // freopen("output.txt", "w", stdout);
    #endif

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 256
#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; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}


int main(){

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	vector<int> cnt(10, 0);
	vector<vector<int>> suff(n);
	set<int> st;
	vector<int> sux(n);
	for(int i = n - 1; i >= 0; --i){
		cnt[s[i] - '0']++;
		suff[i] = cnt;
		st.insert(s[i]);
		sux[i] = st.size();
	}

	vector<int> pin(100);
	for(int i = 0; i + 2 < n; ++i){
		int num = (s[i] - '0') * 10;
		for(int j = i + 1; j + 1 < n; ++j){
			int tmp = num + (s[j] - '0');
			pin[tmp] = max(pin[tmp], sux[j + 1]);
		}
	}

	ll res = 0;
	for(auto &p : pin){
		// res += p.Y;
		// cout << p.X << endl;
		// debug() << imie(p);
		res += p;
	}
	cout << res << endl;

	
	return 0;
} 

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VI P(N);
    REP(i, N) {
        cin >> P[i];
    }

    int cnt = 0;
    int mi = INF;
    REP(i, N) {
        if (mi == P[i] || chmin(mi, P[i])) {
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 1024
n, m = map(int,input().split())
ans = 0
count  = 0

import math

not_c = 1-(1/2)**m
c = (1/ 2) ** m
s = 1900

#k-1 回目まで不正解かつ k回目で終わる確率は
# (not_c ** (k-1)) * c 199
# k回目までに(s * k)が重み付け

ans = s * c /((1-not_c) ** 2)
x = 1900 * m + 100*(n-m)
print(int(x / c))

Measured memory_bytes: 3060
import fractions
N = int(input())
A = list(map(int, input().split()))
find = 0
broken = 0

for i in range(N):
  if A[i] == find + 1:
    find = find + 1
  else:
    broken = broken + 1

if find == 0:
  print(-1)
else:
  print(broken)

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

#define ll long long
#define ull unsigned long long
#define LL long long
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define sch(n) scanf(" %c", &n)
#define ss(n) scanf("%s", n)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define plp pair <int, pll >
#define pb push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define Unique(a)  sort(all(a)),a.erase(unique(all(a)),a.end())

#define inf (1LL<<50)
#define eps 1e-9

ll Set(ll n, ll pos)
{
    return n|(1LL<<pos);
}

bool Check(ll n, ll pos)
{
    return (bool) (n&(1LL<<pos));
}

ll h[100010];
ll dp[100010];

int main ()
{
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    //  ios_base::sync_with_stdio(0); // no printf/scanf must be present
    ll cs, ts, i, j, k, x, y, z, q, m, n, v;

    while(sl(n) != EOF)
    {
        sl(k);
        for (i = 1; i <= n; i++)
        {
            sl(h[i]);
        }

        dp[1] = 0;
        for (i = 2; i <= n; i++)
        {
            dp[i] = inf;
            for (j = 1; j <= k; j++)
            {
                if (i-j >= 1)
                    dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
            }
        }

        printf("%lld\n", dp[n]);
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 String result = sc.nextLine();
		 sc.close();
		 if(result.equals("ARC")) {
			 result = "ABC";
		 }
		 else {
			 result = "ARC";
		 }
		 System.out.println(result);
		 
	}
 
}

Measured memory_bytes: 35624
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

int main(){
	ll n,k,ans;
    
    cin >> n >> k;
    ans = n;
    if(n>k){
    	n=n%k;
    }
    for(int i=0;i<10000000;i++){
    	n=abs(n-k);
      	if(n<ans) ans=n;
    }
    cout << ans;
}

Measured memory_bytes: 256
<?php

$str = trim(fgets(STDIN));


for($i =floor(strlen($str)/2);0 < $i;$i--){
    if(substr($str,0,$i) == substr($str,$i,$i)){
        if(strlen($str)!=strlen(substr($str,0,$i*2))){
        echo strlen(substr($str,0,$i*2)).PHP_EOL;
        break;
        }
    }
}


Measured memory_bytes: 4728
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      if(A == B && B!= C){
      	System.out.println("Yes");
      }else if(A == C && C!= B){
      	System.out.println("Yes");
      }else if(C == B && B!= A){
      	System.out.println("Yes");
      }else{
        System.out.println("No");
      }

    }
}

Measured memory_bytes: 21588
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var n = parseInt(input[0], 10);
	var ax = input[1].split(" ");

	var nums = {};
	ax.forEach(function(element){
		if(nums[element]) {
			nums[element]++;
		} else {
			nums[element] = 1;
		}
	});
	var ans = 0;
	for(var num in nums) {
		num = parseInt(num);
		var tmp = nums[num];
		if(nums[num - 1]) {
			tmp += nums[num - 1];
		}
		if(nums[num + 1]) {
			tmp += nums[num + 1];
		}
		if(ans < tmp) {
			ans = tmp;
		}
	}

	console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int [] B = new int [A];
		int ans = 0;
		
		for(int i = 1; i<A;i++){
			B[i-1] = i;
		}
		B[A-1] = A;
	
		if(Arrays.binarySearch(B, 64) >= 0){
			ans = 64;
		} else if (Arrays.binarySearch(B, 32) >= 0){ 
			ans = 32;
		} else if (Arrays.binarySearch(B, 16) >= 0){ 
			ans = 16;
		} else if (Arrays.binarySearch(B, 8) >= 0){ 
			ans = 8;
		} else if (Arrays.binarySearch(B, 4) >= 0){ 
			ans = 4;
		} else if (Arrays.binarySearch(B, 2) >= 0){ 
			ans = 2;
		} else if (Arrays.binarySearch(B, 1) >= 0){ 
			ans = 1;;
		}
		
		System.out.println(ans);
		//System.out.println(Arrays.toString(B));
		
	}
	
	
}

Measured memory_bytes: 25684
package main

import (
	"fmt"
)

func main() {
	const MOD = 1000000007
	var s string
	fmt.Scan(&s)

	n := len(s)
	var new, old [13]int

	if s[n-1] == '?' {
		for i := 0; i < 13; i++ {
			if i < 10 {
				old[i] = 1
			} else {
				old[i] = 0
			}
		}
	} else {
		c := int(s[n-1] - '0')
		for i := 0; i < 13; i++ {
			if i == c {
				old[i] = 1
			} else {
				old[i] = 0
			}
		}
	}

	digit := 10
	for i := n - 2; i >= 0; i-- {
		for j := 0; j < 13; j++ {
			new[j] = 0
		}
		if s[i] == '?' {
			for m := 0; m < 10; m++ {
				for mod, cnt := range old {
					shifted := (mod + m*digit) % 13
					new[shifted] += cnt
				}
			}
		} else {
			m := int(s[i] - '0')
			for mod, cnt := range old {
				shifted := (mod + m*digit) % 13
				new[shifted] += cnt
			}
		}

		for j := 0; j < 13; j++ {
			new[j] %= MOD
		}
		digit = (digit * 10) % 13
		new, old = old, new
	}

	fmt.Println(old[5])
}


Measured memory_bytes: 1280
package main

import "fmt"

func main() {
	// Code for A - HEX
	var X, Y string
	fmt.Scanf("%s %s", &X, &Y)

	if X > Y {
		fmt.Println(">")
	} else if X == Y {
		fmt.Println("=")
	} else {
		fmt.Println("<")
	}
}


Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  string s;  
  cin >> s; 
  int L = s.size(), a = 0, z = 0;

  for (int i = 0; i < L; i++) {
    if (s[i] == 'A') {
      a = i;
      for (int j = i; j < L; j++) if (s[j] == 'Z') z = j;
      if (z != 0) break;
    }   
  }
  
  cout << z-a+1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

int kare(int x){
	return x*x;
}

double fact[13];

pair<int,int> arr[13];

double sum;

int main(){
	//fri("a.gir");
	//fro("a.cik");
	int n;
	cin>>n;
	fact[1]=1;
	for(int i=2;i<=8;i++){
		fact[i]=i*fact[i-1];
	}
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		arr[i]=mp(x,y);
	}
	for(int i=1;i<=n-1;i++){
		for(int j=i+1;j<=n;j++){
			sum+=sqrt(kare(arr[i].first-arr[j].first)+kare(arr[i].second-arr[j].second));
		}
	}
	int k=fact[n-1]*2;
	sum*=k;
	sum/=fact[n];
	cout<<setprecision(12)<<sum;


 
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<double>x(n);
    vector<double>y(n);
    for(double &a : x){
        cin >> a;
    }
    for(double &a : y){
        cin >> a;
    }
    double M=0, U=0, T=0, C=0;
    for(int i=0; i<n; i++){
        double A = abs(x.at(i)-y.at(i));
        M += A;
        U += (A*A);
        T += (A*A*A);
        if(A > C) C=A;
        //printf("%d %d %d %d", M, U, T, C);
    }
    printf("%.6lf\n%.6lf\n%.6lf\n%.6lf\n", M, sqrt(U), cbrt(T), C);

    return 0;
}




Measured memory_bytes: 3412
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 1;
  int sum[n];
  sum[0] = a[0];
  for (int i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    if (sum[i] * 2 >= a[i + 1]) {
      ans++;
    } else {
      break;
    }
  }
  cout << ans << "\n";
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

const int alp = 'z' - 'a' + 1;

void solve(string s, long long K){
	ll size = s.size();
	
	REP(i,size) {
		int cost = ('z' + 1 - s[i] ) % alp;
		if (K >= cost) {
			K -= cost;
			s[i] = 'a';
		}
	}

	if (K) {
		char buf = s[size - 1] - 'a';
		s[size - 1] = ((buf + (K % alp)) % 26) + 'a';
	}

	cout << s << endl;
}



int main(){	
	ios::sync_with_stdio(false);
	string s;
	long long K;
	cin >> s;
	cin >> K;
	solve(s, K);
	return 0;
}


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

int main() {
  int N, k=1;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++) {
    cin >> d.at(i);
  }

  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  
  for(int i=0;i<N-1;i++) {
    if(d.at(i+1)!=d.at(i)) k++;
  }
 
  cout << k << endl;
  
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

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

  double x[101], y[101];
  for(int i=0; i<n; ++i){
    std::cin >> x[i];
  }
  for(int i=0; i<n; ++i){
    std::cin >> y[i];
  }

  double dist = 0;
  /*----------------- Manhattan distance -------------------*/
  // p = 1
  for(int i=0; i<n; ++i){
    dist += abs(x[i]-y[i]);
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(6) << dist << std::endl;


  dist = 0;
  /*----------------- Euclidean distance -------------------*/
  // p = 2
  for(int i=0; i<n; ++i){
  dist += abs(x[i]-y[i])*abs(x[i]-y[i]);
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(6) << sqrt(dist) << std::endl;


  dist = 0;
  /*----------------- Minkowski distance -------------------*/
  // p = 3
  for(int i=0; i<n; ++i){
    dist += abs(x[i]-y[i])*abs(x[i]-y[i])*abs(x[i]-y[i]);
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(6) << pow(dist, 1.0/3.0) << std::endl;


  dist = 0;
  /*----------------- Chebyshev distance -------------------*/
  // p = ∞
  for(int i=0; i<n; ++i){
    dist = max(dist, abs(x[i]-y[i]));
  }

  std::cout << std::fixed;
  std::cout << std::setprecision(6) << dist << std::endl;;


  return 0;
}



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

using namespace std;

const long long MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> iii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef priority_queue<pii, vector<pii>, greater<pii>> fila_prioridade;
typedef priority_queue<iii, vector<iii>, greater<iii>> fila_prioridade_grids;

#define nl '\n'
#define INF 1000000000
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int n,k,x;
int total = 0;

int main() {
        NeedForSpeed

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> x;

		if (x >= abs(k - x)) {
			total += abs(k - x) * 2;
		}else {
			total += x * 2;
		}
	}

	cout << total << nl;



        return 0;
}



Measured memory_bytes: 3628
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	S[K - 1] -= 'A';
	S[K - 1] += 'a';
	cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    char c;
    cin >> c;
    if('a' <= c && c <= 'z')cout << "a" << endl;
    else cout << "A" << endl;
    return 0;
}

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

vector<int>to[2505];
vector<int>rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v){
  if(reachableFrom1[v])return;
  reachableFrom1[v]=true;
  for(int u:to[v]){
    dfs(u);
  }
}
void rdfs(int v){
  if(reachableToN[v])return;
  reachableToN[v]=true;
  for(int u:rto[v]){
    rdfs(u);
  }
}

int main(){
  int n,m,p;
  cin>>n>>m>>p;
  vector<tuple<int,int,int>>edges;
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    --a;--b;
    c-=p;
    c=-c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n)ok[i]=reachableFrom1[i]&reachableToN[i];
  {//bellman-ford
    vector<int>d(n,INF);
    d[0]=0;
    bool upd=true;
    int step=0;
    while (upd){
      upd=false;
      rep(i,m){
        int a,b,c;
        tie(a,b,c)=edges[i];
        if(!ok[a])continue;
        if(!ok[b])continue;
        int newD=d[a]+c;
        if (newD<d[b]){
          upd=true;
          d[b]=newD;
        }
      }
      step++;
      if (step>n){
        puts("-1");
        return 0;
      }
    }
    int ans=-d[n-1];
    ans=max(ans,0);    
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    if( n == m ){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
# F - Unfair Nim

N = int(input())
A = list(int(a) for a in input().split())

a = A[0]
b = A[1]
S = a + b
X = 0
for i in range(2, N):
    X ^= A[i]

dp = [[[-1] * 2 for i in range(2)] for j in range(50)]
dp[0][0][0] = 0

for i in range(49):
    cur_s = S>>i&1
    cur_x = X>>i&1
    cur_a = a>>i&1
    for j, k in ((0, 0), (0, 1), (1, 0), (1, 1)):
        if dp[i][j][k] == -1:
            continue
        for p, q in ((0, 0), (0, 1), (1, 0), (1, 1)):
            if p ^ q != cur_x:
                continue
            if (p + q + j)&1 != cur_s:
                continue
            ni = i + 1
            nj = 0
            if (p + q + j) >= 2:
                nj = 1
            if cur_a < p:
                nk = 1
            elif cur_a > p:
                nk = 0
            else:
                nk = k
            dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k]|(1<<i)*p)

tmp = dp[49][0][0]
if tmp == 0 or tmp == -1:
    print(-1)
else:
    print(a - tmp)

Measured memory_bytes: 9240
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;


int main(void){
    int n, m; cin >> n >> m;
    ll ans = 0;
    priority_queue<ll> que;
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        que.push(a);
        ans += a;
    }
    for (int i = 0; i < m; i++)
    {
        ll a;
        a = que.top();
        ans = ans - (a+1)/2;
        que.pop();
        que.push(a/2);
    }
    
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 1400
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String goal = br.readLine();
		generate("SS", goal);
		generate("WS", goal);
		generate("SW", goal);
		generate("WW", goal);
		System.out.println(-1);
	}
	
	public static void generate(String prefix, String goal) {
		char[] ret = new char[goal.length()];
		ret[0] = prefix.charAt(0);
		ret[1] = prefix.charAt(1);
		for(int i = 2; i < ret.length; i++) {
			if(ret[i-1] == 'S') {
				if(goal.charAt(i-1) == 'o') {
					ret[i] = ret[i-2];
				}
				else {
					ret[i] = (char)('S' + (int)'W' - ret[i-2]);
				}
			}
			else {
				if(goal.charAt(i-1) == 'x') {
					ret[i] = ret[i-2];
				}
				else {
					ret[i] = (char)('S' + (int)'W' - ret[i-2]);
				}
			}
		}
		if(isConsistent(ret, goal)) {
			System.out.println(new String(ret));
			System.exit(0);
		}
	}
	
	public static boolean isConsistent(char[] l, String s) {
		for(int i = 0; i < l.length; i++) {
			int lhs = (i+l.length-1)%l.length;
			int rhs = (i+1)%l.length;
			if(l[i] == 'S') {
				if(s.charAt(i) == 'o' && l[lhs] != l[rhs]) return false;
				if(s.charAt(i) == 'x' && l[lhs] == l[rhs]) return false;
			}
			else {
				if(s.charAt(i) == 'o' && l[lhs] == l[rhs]) return false;
				if(s.charAt(i) == 'x' && l[lhs] != l[rhs]) return false;
			}
		}
		return true;
	}
	
}

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

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> a(A), b(B), c(C);
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < B; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < C; i++) {
    cin >> c.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  int Xc = X, Yc = Y;
  for (int i = 0; i < C; i++) {
    if (Xc == 0) {
      if (b.at(Yc - 1) < c.at(i)) {
        b.at(Yc - 1) = c.at(i);
        Yc--;
        if (Yc <= 0) {
          break;
        }
      }
      else {
        break;
      }
    }
    else if (Yc == 0) {
      if (a.at(Xc - 1) < c.at(i)) {
        a.at(Xc - 1) = c.at(i);
        Xc--;
        if (Xc <= 0) {
          break;
        }
      }
      else {
        break;
      }
    }
    else if (min(a.at(Xc - 1), b.at(Yc - 1)) < c.at(i)) {
      if (a.at(Xc - 1) < b.at(Yc - 1)) {
        a.at(Xc - 1) = c.at(i);
        Xc--;
      }
      else {
        b.at(Yc - 1) = c.at(i);
        Yc--;
      }
    }
    else {
      break;
    }
  }
  unsigned long long ans = 0;
  for (int i = 0; i < X; i++) {
    ans += a.at(i);
  }
  for (int i = 0; i < Y; i++) {
    ans += b.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
H,W = [int(i) for i in input().split()]
li = ['0'] * H
for i in range(H) :
    li[i] = list(input())
for i in range(H) :
    for j in range(W) :
        if li[i][j] == "." :
            count = 0
            a = i -1
            b = i + 1
            c = j - 1
            d = j + 1
            if a >= 0 :
                if li[a][j] == "#" :
                    count+=1
            if b <= H-1 :
                if li[b][j] == "#" :
                    count+=1
            if c >= 0 :
                if li[i][c] == "#" :
                    count+=1
            if d <= W-1 :
                if li[i][d] == "#" :
                    count+=1
            if a >= 0 and c >= 0 :
                if li[a][c] == "#" :
                    count+=1
            if a >= 0 and d <= W-1 :
                if li[a][d] == "#":
                    count+=1
            if b <= H-1 and c >= 0 :
                if li[b][c] == "#" :
                    count+=1
            if b <= H-1 and d <= W - 1 :
                if li[b][d] == "#" :
                    count+=1
            li[i][j] = str(count)
for i in range(H) :
    a = ''.join(li[i])
    print(a)

Measured memory_bytes: 3444
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

int N, T;
vector<pii> p;
i64 dp[3005][3005];

i64 slv(int elapsed, int i)
{
    if (elapsed >= T) { return 0; }
    if (i >= N) { return 0; }

    auto &ret = dp[elapsed][i];
    if (~ret) return ret;

    ret = 0;
    chmax(ret, slv(elapsed, i + 1));
    chmax(ret, slv(elapsed + p[i].first, i + 1) + p[i].second);

    return ret;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    input(N, T);
    p.resize(N);

    rep(i, N) {
        var(int, a, b);
        p[i] = pii(a, b);
    }

    sort(all(p));

    memset(dp, -1, sizeof(dp));
    print(slv(0, 0));

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++) cin >> H.at(i);
  
  int cnt = 0;
  int highest = 0;
  
  for(int i = 0; i < N; i++){
    highest = max(highest, H.at(i));
    if(H.at(i) >= highest) cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

s = input()
s = s.replace("BC", "D")

cnt = 0
ans = 0
for x in s:
	if x == "A":
		cnt += 1
	elif x == "D":
		ans += cnt
	else:
		cnt = 0

print(ans)


Measured memory_bytes: 10808
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }


int main() {   
    string s, t; cin >> s >> t;
    s.push_back(t.back());
    if(s==t) cout << "Yes" << ln;
    else cout << "No" << ln;
}

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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	ll n; cin >> n;
	ll sum_v = 0;
	for (int i = 0; i < n; ++i) {
		ll v; cin >> v;
		sum_v += v;
	}
	cout << (sum_v - (n * (n + 1) / 2)) << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
int main(void)
{
int a,b;
char t;
for(;;){
scanf("%d %c %d", &a, &t, &b);
if (t=='?') break;
if (t=='+') a+=b;
if (t=='-' ) a-=b;
if (t=='*') a*=b;
if (t=='/') a/=b;
printf("%d\n", a);
}

return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll mod = 1e9 + 7;

  ll incnt = 0;
  rep(l, n){
    for(ll r = l+1; r < n; r++){
      if(a[r] < a[l]) incnt++, incnt %= mod;
    }
  }

  ll outcnt = 0;
  rep(l, n){
    rep(r, n){
      if(a[r] < a[l]) outcnt++, outcnt %= mod;
    }
  }

  ll res = (k*incnt)%mod + (k*(k-1)/2)%mod * outcnt;
  cout << res%mod << endl;

  return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
n = I()
a = LI()
b = [None for i in range(n-1)]
for i in range(n-1):
    a[i+1] += a[i]
for i in range(n-1):
    b[i] = abs(2*a[i]-a[n-1])
print(min(b))
"""

#D
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b = LI()
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
d_f = [-1 for i in range(n)]
q = deque()
q.append(0)
d_f[0] = 0
while q:
    x = q.pop()
    for y in v[x]:
        if d_f[y] == -1:
            d_f[y] = d_f[x] + 1
            q.append(y)
d_s = [-1 for i in range(n)]
q.append(n-1)
d_s[n-1] = 0
while q:
    x = q.pop()
    for y in v[x]:
        if d_s[y] == -1:
            d_s[y] = d_s[x] + 1
            q.append(y)
f = 0
s = 0
for i in range(n):
    if d_f[i] <= d_s[i]:
        f += 1
    else:
        s += 1
if f > s:
    print("Fennec")
else:
    print("Snuke")
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

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

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

  string s, t;
  for (int i = 0; i < b; ++i) s += to_string(a);
  for (int i = 0; i < a; ++i) t += to_string(b);

  cout << min(s, t) << '\n';

  return (0);
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(true){
    int people[5];
    int kind[3] = {0};

    REP(i,5){
      if((people[i] = getInt()) == 0) return 0;
      kind[people[i]-1]++;
    }

    bool aiko = false;

    if(kind[0] > 0 && kind[1] > 0 && kind[2] > 0)
      aiko = true;
    if(kind[0] == 5 || kind[1] == 5 || kind[2] == 5)
      aiko = true;

    if(aiko){
      REP(i,5) print(3);
    }else{
      int kati;
      if(kind[0] == 0) kati = 2;
      if(kind[1] == 0) kati = 3;
      if(kind[2] == 0) kati = 1;

      REP(i,5) if(people[i] == kati)
        print(1);
      else
        print(2);
    }
  }
}

Measured memory_bytes: 0