akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>

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

using namespace std;

int main(){
	for(int n;scanf("%d ",&n),n;){
		map<string,int> f[128];
		rep(_,n){
			char s[2048]; fgets(s,2048,stdin);
			int len=strlen(s);
			s[--len]='\0';

			int p=0;
			rep(i,len+1) if(i==len || s[i]==' ') {
				s[i]='\0';
				++f[s[p]][s+p];
				p=i+1;
			}
		}

		char c; scanf("%c",&c);
		vector< pair<int,string> > ans;
		map<string,int>::iterator it;
		for(it=f[c].begin();it!=f[c].end();++it){
			ans.push_back(make_pair(-it->second,it->first));
		}
		sort(ans.begin(),ans.end());

		if(ans.empty()) puts("NA");
		else{
			rep(i,min((int)ans.size(),5)){
				if(i>0) putchar(' ');
				printf("%s",ans[i].second.c_str());
			}
			puts("");
		}
	}

	return 0;
}

Measured memory_bytes: 0
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <numeric>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, k, a, b, c, d, e, H, W,X;
long long A[200000] = {};
long long B[365][365] = {};
bool f;
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <long long>vl;

struct ST
{
	long long total;
	long long aki;
	long long itta;
};

vector <ST> vst;
ST st;

int main() {

	cin >> a>>b>>c>>N;
	d = 0;

	for (int i = 0; i*a <= N; i++) {
		for (int j = 0; i*a + j*b <= N; j++) {
			if ((N - i*a - j*b) % c == 0) {
				d++;
			}
		}

	}

	cout << d<<endl;

	return 0;
}

Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int x;
    cin>>x;
    cout<<(x>=30?"Yes":"No");
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(all(a)), sort(all(b)), sort(all(c));
    ll num[n], sum[n] = {};
    rep(i, n) {
        auto j = upper_bound(all(c), b[i]) - c.begin();
        num[i] = n - j;
    }
    rep(i, n) {
        if (i == 0) sum[i] = num[i];
        else sum[i] = sum[i - 1] + num[i];
    }
    ll ans = 0;
    rep(i, n) {
        auto j = upper_bound(all(b), a[i]) - b.begin();
        if (j == 0) ans += sum[n - 1];
        else ans += (sum[n - 1] - sum[j - 1]);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    string n;
    cin >> n;
    int i = 3;
    while(i) {
        if(n[i-1] == '1') n[i-1] = '9';
        else n[i-1] = '1';
        i--;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define int long long
using namespace std;
const int N=2e5+10;
int x[N],tmp[N],d1[N],d2[N];
int L,n,ans;
int D1(int l,int r) {return r<l?0:(d1[r]-d1[l-1]);}
int D2(int l,int r) {return r<l?0:(d2[r]-d2[l-1]);}
void Calc()
{
	for(int i=1;i<=n;i++) d1[i]=d1[i-1]+x[i];
	for(int i=1;i<=n;i++) d2[i]=d2[i-1]+L-x[i];
	for(int i=1,ps;i<=n/2;i++)
	{
		ps=n-i*2;
		ans=max(ans,D1(ps,ps+i-1)*2+x[ps+i]+D2(ps+i+1,n)*2);
		ans=max(ans,D1(ps+1,ps+i)*2+D2(ps+i+2,n)*2+L-x[ps+i+1]);
	}
}
signed main()
{
	cin>>L>>n;
	for(int i=1;i<=n;i++) cin>>x[i];
	ans=max(ans,max(x[n],L-x[1]));
	Calc();
	for(int i=1;i<=n;i++) tmp[i]=L-x[n-i+1];
	for(int i=1;i<=n;i++) x[i]=tmp[i];
	Calc();
	cout<<ans<<endl;
}

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

int n, cnt, ans;
bool c[8];

bool ir(int n, int a, int b) {
	if (n >= a && n <= b) return 1;
	return 0;
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	int a[n];
	REP(i, 0, n) {
		cin >> a[i];
		if (ir(a[i], 1, 399)) c[0] = 1;
		else if (ir(a[i], 400, 799)) c[1] = 1;
		else if (ir(a[i], 800, 1199)) c[2] = 1;
		else if (ir(a[i], 1200, 1599)) c[3] = 1;
		else if (ir(a[i], 1600, 1999)) c[4] = 1;
		else if (ir(a[i], 2000, 2399)) c[5] = 1;
		else if (ir(a[i], 2400, 2799)) c[6] = 1;
		else if (ir(a[i], 2800, 3199)) c[7] = 1;
		else cnt++;
	}
	for (auto x : c) ans += x;
	cout << max(ans, 1) << " " << ans + cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, W; cin >> n >> W;
  int m = 0;
  V<> v, w;
  for (int i = 0; i < n; ++i) {
    int _v, _w, k; cin >> _v >> _w >> k;
    int s = 0;
    for (int j = 1; j <= k >> 1; j <<= 1) {
      v.push_back(_v * j);
      w.push_back(_w * j);
      ++m;
      s += j;
    }
    v.push_back(_v * (k - s));
    w.push_back(_w * (k - s));
    ++m;
  }
  V<> dp(W + 1);
  for (int i = 0; i < m; ++i) for (int j = W; j >= w[i]; --j) dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
  cout << dp[W] << '\n';
}


Measured memory_bytes: 3292
#include<iostream>
#include<cstdio>
using namespace std;
const int L=128,N=65;
const char ch[]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"};
int len;
int cnt[N];
int query(const string &s)
{
	cout<<"? "<<s<<endl; 
	int ans;
	cin>>ans;
	return ans;
}
bool check(const string &s)
{
	return query(s)==len-s.size();
}
string merge(int l,int r)
{
	if(l==r) return string(cnt[l],ch[l]);
	int mid=(l+r)/2;
	string a=merge(l,mid),b=merge(mid+1,r);
	string t;
	int i=0,j=0;
	while(i<a.size()&&j<b.size())
	{
		if(check(t+a[i]+b.substr(j))) t+=a[i],i++;
		else t+=b[j],j++;
	}
	while(i<a.size())
		t+=a[i],i++;
	while(j<b.size())
		t+=b[j],j++;
	return t;
}
int main()
{
	for(int i=0;i<62;i++)
		cnt[i]=L-query(string(L,ch[i])),len+=cnt[i];
	string ans=merge(0,62);
	cout<<"! "<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  std::vector<int > dp(N, -1);
  for (int i=0; i<N;i++){
    scanf("%d", &A[i]);
  }
  for (int i=0; i<N; i++){
    //printf("i=%d\n", i);
    auto itr = std::lower_bound(dp.rbegin(), dp.rend(), A[i]);
    if (itr==dp.rbegin()){
      dp.push_back(A[i]);
    } else {
      itr--;
      *itr = A[i];
    }
  }
  int counter=0;
  while (counter<N){
    //printf("dp[%d]=%d\n", counter, dp[counter]);
    if (dp[counter]==-1){
      break;
    }
    counter++;
  }
  std::cout << counter << std::endl;
  return 0;
}

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

int main()
{
    size_t N;
    std::cin >> N;
    size_t z = 0, m = 0;;
    for (size_t n = 0; n < N; ++n)
    {
        int64_t a, b;
        std::cin >> a >> b;
        if (a == b) {
            ++z;
        }
        else {
            z = 0;
        }
        m = std::max(m, z);
    }
    if (m >= 3) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, x;

int main() {
    cin >> N >> x;
    if(x > 1 && x < 2 * N - 1) {
        cout << "Yes"
             << "\n";
    } else {
        cout << "No"
             << "\n";
        return 0;
    }
    if(x != 2) {
        REP(i, N - 1) {
            cout << (x - 2 * (N - 2 - i) - 2 + 2 * N - 1) % (2 * N - 1) + 1 << "\n";
        }
        cout << x << "\n" << x + 1 << "\n";
        FOR(i, N + 1, 2 * N - 1) {
            cout << (x - 2 * (i - N - 1) - 3 + 2 * N - 1) % (2 * N - 1) + 1 << "\n";
        }
    } else {
        REP(i, N - 1) { cout << (x + i) % (2 * N - 1) + 1 << "\n"; }
        cout << x << "\n" << x - 1 << "\n";
        FOR(i, N + 1, 2 * N - 1) {
            cout << (x - 2 + i) % (2 * N - 1) + 1 << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 1536
import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    input_q = list(map(int, input().split()))
    B.append(input_q[0])
    C.append(input_q[1])
    
A_sum = sum(A)
CONST_MAX = 100001
count_list = [0] * CONST_MAX

c = collections.Counter(A)
for k, v in c.items():
    # print(k, v)
    count_list[k] = v


for i in range(Q):
    count_list[C[i]] += count_list[B[i]]
    A_sum += (C[i] - B[i]) * count_list[B[i]]
    count_list[B[i]] = 0
    # print(count_list)

    print(A_sum)


Measured memory_bytes: 26884
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, K;
ll calc(ll k, vector<pll>& num) {
  ll res = 0;
  for (ll i = 0; i < N; ++i) {
    if ((num.at(i).first | k) == k) {
      res += num.at(i).second;
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  vector<pll> num(N);
  for (ll i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    num.at(i) = {a, b};
  }
  ll ans = calc(K, num);
  for (ll i = 0; i < 30; ++i) {
    ll temp = pow(2, i);
    if ((temp & K) != 0) {
      ll k = K;
      k = k / temp * temp - 1;
      ans = max(ans, calc(k, num));
    }
  }
  cout << ans << "\n";
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << 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;
}

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

vector<int>A(M);
REP(i,M) cin >> A[i];

int left = 0, right = 0;
REP(i,M){
    if(X > A[i]) left++;
    if(X < A[i]) right++;

}

int ans = min(right, left);
print(ans);

}

Measured memory_bytes: 256
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let a: Vec<i32> = read_vec();
    let ans = a.iter().sum::<i32>() - a.len() as i32;
    println!("{}", ans);
}


Measured memory_bytes: 4352
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        _n: usize,
        s: chars,
    }
    let res = s.iter().scan(0, |a, &v| {
        if v == 'I' { *a += 1; Some(*a) }
        else { *a -= 1; Some(*a) }
    }).max().unwrap();
    println!("{}", std::cmp::max(res,0));
}


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

int n, k;

int main () {
    while (scanf("%d %d", &n, &k) == 2) {
        vector<int> a(n);
        for (auto &x : a) scanf("%d", &x);

        vector<bool> res;
        for (int i = k; i < n; i++) res.push_back(a[i] > a[i - k]);

        for (bool x : res)
            printf(x ? "Yes\n" : "No\n");
    }
}



Measured memory_bytes: 4376
'''ABC172 C'''
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i + n-1, ans)
print(ans)

Measured memory_bytes: 53232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;


int main()
{
	string s;
	cin>>s;
	int cnt[26]={0};
	for(int i=0;i<s.length();i++){
		cnt[s[i]-'a']=1;
	}
	for(int i=0;i<26;i++){
		if(!cnt[i]){
			printf("%c",'a'+i);
			return 0;
		}
	}
	printf("None");
	return 0;
}


Measured memory_bytes: 512
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(K):
        if dp[i]:
            continue
        for a in A:
            if i + a > K:
                break
            dp[i + a] = 1
    print("First" if dp[-1] else "Second")
if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>

using namespace std;

int main(void){
    stack<int> s;
    int tmp;
    char input[80];
    char *endptr;
    
    while(cin >> input){
        tmp = strtol(input , &endptr,10);
        
        switch(*endptr){
            case '+':
                tmp = s.top(); s.pop();
                tmp += s.top(); s.pop();
                s.push(tmp);
                break;
            case '-':
                tmp = s.top(); s.pop();
                tmp = s.top() - tmp; s.pop();
                s.push(tmp);
                break;
            case '*':
                tmp = s.top(); s.pop();
                tmp *= s.top(); s.pop();
                s.push(tmp);
                break;
            default:
                s.push(tmp);
                break;
        }
    }
    cout << s.top() << endl;
    
    return 0;
}

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

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

using namespace std;

typedef long long ll;

#define MAX 100010

int N;
ll A,B,X[MAX], dp[MAX];

void compute() {
  rep(i,N+1) dp[i] = LLONG_MAX;
  dp[0] = 0;
  REP(i,1,N) {
    dp[i] = min(dp[i],dp[i-1] + B);
    dp[i] = min(dp[i],dp[i-1] + (X[i]-X[i-1])*A);
    /*
    dp[i] = min(dp[i],dp[i-1] + B);
    rep(j,i) {//愚直にやるとこうなる TLE
      dp[i] = min(dp[i],
                  dp[j]+(X[i]-X[j])*A);
    }
    */
  }
  cout << dp[N-1] << endl;
}

int main() {
  if( 0 ) {
    srand((unsigned int)time(NULL));
    N = 10000;
    A = rand() % 1000 + 1;
    B = A + rand() % 100;
    cout << N << " " << A << " " << B << endl;
    ll cur = 1;
    rep(i,N) {
      if( i ) cout << " ";
      cout << cur;
      cur += ( rand() % 1000 + 1 );
    } puts("");
    return 0;
  }
  cin >> N >> A >> B;
  rep(i,N) cin >> X[i];
  compute();
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>

using namespace std;

int main (){
  int N;
  int A[200001];
  int flag[200001];
  int loop[200001];
  long long int K;
  long long int loop_len=0;

  cin >> N >> K;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    A[i] --;
    flag[i] = -1;
    loop[i] = 0;
  }

  // check loop
  int p = 0;
  while (1) {
    if (flag[p]>=0) {
      break;
    } else {
      flag[p] = loop_len;
      p = A[p];
      loop_len++;
    }
    if (loop_len == K) {
      K=0;
      break;
    }
  }

  if (K) {
    // printf("K: %lld loop_len: %lld p: %d flag[p]: %d\n", K, loop_len, p, flag[p]);
    K -= loop_len;
    loop_len -= flag[p];
    K %= loop_len;
    for (int i=0; i<K; i++) {
      p = A[p];
    }
  }
  cout << p+1 << endl;

}

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

signed main(){
    int a[5];
    int N;
    cin >> N;
    rep(i,5) cin >> a[i];

    sort(a,a+5);
    int ans = N/a[0] + 5;
    if(a[0] == 1) ans--;

    put(ans); 
    
}


Measured memory_bytes: 256
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 3e3 + 5;
const int MOD = 1e9 + 7;

int N, M;

void solve()
{
    static int dp[MAXN][MAXN][2];

    dp[0][0][1] = 1;
    for (int i = 1; i <= N; ++i) {
        dp[0][i][0] = 1;
    }
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j <= N; ++j) {
            for (int k = 0; k <= 1; ++k) {
                if (j) (dp[i + 1][j][k | (j - 1 == 0)] += dp[i][j][k]) %= MOD;
                if (j) (dp[i + 1][j - 1][k | (j - 1 == 0)] += dp[i][j][k]) %= MOD;
                if (N - j) (dp[i + 1][j][k] += dp[i][j][k]) %= MOD;
                if (N - j) (dp[i + 1][j + 1][k] += dp[i][j][k]) %= MOD;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= N; ++i) {
        (ans += dp[M][i][1]) %= MOD;
    }

    printf("%d\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    read(N); read(M);
    solve();

    return 0;
}

// 万壑树参天，千山响杜鹃。
//     -- 王维《送梓州李使君》


Measured memory_bytes: 70656
///
// File:  dpl_1_a.cpp
// Author: ymiyamoto
//
// Created on Wed Nov  1 01:41:22 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
#define MAX_N 50001
static vector<int32_t> coins;
static uint32_t dp[MAX_N];

int32_t main()
{
  int32_t n, m;
  cin >> n >> m;
  for (int32_t i = 0; i < m; i++) {
    int32_t c;
    cin >> c;
    coins.push_back(c);
  }

  for (int32_t i = 0; i <= n; i++) {
    dp[i] = UINT32_MAX;
    dp[0] = 0;
    for (int32_t j = 0; j < (int32_t)coins.size(); j++) {
      if (i - coins[j] >= 0) {
        dp[i] = min(dp[i], 1 + dp[i - coins[j]]);
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;
  for (int i = 0; i < N; i++) {
    if (i == K - 1) {
      if (S[i] == 'A') cout << 'a';
      else if (S[i] == 'B') cout << 'b';
      else cout << 'c';
    } else {
      cout << S[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
using System;

namespace abc136_d
{
    static class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var boxes = new int[s.Length];
            for (int i = 0; i < boxes.Length; i++)
            {
                boxes[i] = 1;
            }

            // RLのRにいる子→偶数回でR/奇数回でL
            // RLのLにいる子→偶数回でL/奇数回でR
            // →つまり、RLは無視していい
            // RRのR1にいる子→Lが来るまで右に移動する。Lが来たら、RLに移行
            // LLのL2にいる子→Rが来るまで左に移動する。Rが来たら、RLに移行
            // LRのRにいる子→右がRRかRLかによる
            // LRのLにいる子→左がLLかRLかによる
            // →つまり、すべての子がRLに溜まる

            // 10^100は偶数。

            // まずはRを確認。RLのLに溜まる子を計算
            // RLまでにRが続いた個数
            var r = 0;
            for (int i = 0; i < boxes.Length; i++)
            {
                if (s[i] == 'R')
                {
                    if (s[i + 1] == 'L')
                    {
                        // RLから奇数個離れてる
                        boxes[i] += r / 2;
                        // RLから偶数個離れてる
                        boxes[i + 1] += r / 2 + r % 2;
                        r = 0;
                    }
                    else
                    {
                        boxes[i] = 0;
                        r++;
                    }
                }
                else
                {
                    // Lの時は何もしない
                }
            }

            // 次にLを確認。RLのRに溜まる子を計算
            // RLまでにLが続いた個数
            var l = 0;
            for (int i = boxes.Length - 1; i >= 0; i--)
            {
                if (s[i] == 'L')
                {
                    if (s[i - 1] == 'R')
                    {
                        // RLから奇数個離れてる
                        boxes[i - 1] += l / 2 + l % 2;
                        // RLから偶数個離れてる
                        boxes[i] += l / 2;
                        l = 0;
                    }
                    else
                    {
                        boxes[i] = 0;
                        l++;
                    }
                }
                else
                {
                    // Rの時は何もしない
                }
            }

            Console.WriteLine($"{string.Join(" ", boxes)}");
        }
    }
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  for (int x = 0; x <= 1000; x++) {
    for (int y = 0; y <= 1000; y++) {
      if (x + y == X && x * 2 + y * 4 == Y) return cout << "Yes" << "\n", 0;
    }
  }
  cout << "No" << "\n";
}

Measured memory_bytes: 3592
/* Author : Pranav Deshmukh
            PICT,Pune
   Purpose: Atcoder Practice
   Stay Focused!
*/

#include<bits/stdc++.h>
using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define int             long long
#define dip(type,var)   type var; cin>>var;
#define dipi(x)         int x; cin>>x;
#define dipi2(x,y)       int x,y; cin>>x>>y;
#define w(x)            int x; cin>>x; while(x--)
#define mka(arr,n,type) type *arr=new type[n];
#define fo(i,n)        for(int i=0;i<n;i++)
#define mod             pow(10,9)+7
#define inf             1e18
#define endl            "\n"
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
    c_p_c();
    int ac = 0, wa = 0, tle = 0, re = 0;
    w(t) {
        string s;
        cin >> s;
        if (s[0] == 'A') {
            ac++;
        }
        else if (s[0] == 'W') {
            wa++;
        }
        else if (s[0] == 'T') {
            tle++;
        }
        else
            re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

int main(){
    int h,a;
    cin >>h>>a;
    cout << (h+a-1)/a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

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

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}


Measured memory_bytes: 892
N,T=map(int,input().split())
li=[list(map(int,input().split())) for i in range(N)]
li2=[]
for i in range(N):
  if li[i][1]<=T:
    li2.append(li[i])
li2.sort()
if len(li2)==0:
  print('TLE')
  exit()
print(li2[0][0])

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    cin>>n;
    ll i=1;
    ll sum=0;
   while(i<=n)
   {
       if(i%3!=0&&i%5!=0)
       {
           sum+=i;
          // cout<<i<<" ";
       }
       i++;
 
 
   }
   cout<<sum<<endl;
 
}

Measured memory_bytes: 3624
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int main(){
  int Lj4PdHRW, i;
  long long res=0;
  map<int,int> mp;
  rd(N);
  rd(M);
  mp[0]++;
  i = 0;
  for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
    i = (i + rd_int()) % M;
    res += (mp[i]++);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int N, M;
// {
//   int i;
//   map<int,int> mp;
//   ll res = 0;
// 
//   rd(N,M);
//   mp[0]++;
//   i = 0;
//   rep(N){
//     i = (i + rd_int()) % M;
//     res += (mp[i]++);
//   }
//   wt(res);
// }


Measured memory_bytes: 3200
n,m=map(int,input().split())
s_list=[0]+list(map(int,input().split()))
t_list=[0]+list(map(int,input().split()))
dp=[]
for i in range(n+1):
    sub_list=[0]*(m+1)
    dp.append(sub_list)
for j in range(m+1):
    dp[0][j]=1
for i in range(n+1):
    dp[i][0]=1
Mod=10**9+7
for i in range(1,n+1):
    for j in range(1,m+1):
        if s_list[i]==t_list[j]:
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%Mod
        else:
            dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%Mod
print(dp[n][m])





Measured memory_bytes: 72668
import sys


def solve(inp):
    C = inp.readline().strip()

    if C[0] != 'z':
        next = chr(ord(C[0]) + 1)
    else:
        next = 'a'
    return next


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
def main28():
    num = int(input())
    st = []
    for i in range(num):
        st.append(input())
    for i in range(1,num,1):
        if st[i-1][-1] != st[i][0]:
            print("No")
            return
        for j in range(i):
            if st[j] == st[i]:
                print("No")
                return
    print("Yes")

if __name__ == "__main__":
    main28()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,k;
	scanf("%lld %lld %lld",&a,&b,&k);
	if(a<k)	{
		k=k-a;		
		a=0;	
//		printf("%lld %lld %lld\n",a,b,k);		
		b=b-k;

		if(b<0)	b=0;
	}
	else {
		a=a-k;
	}
	printf("%lld %lld\n",a,b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N;
  cin >> A;
 
  int x = N % 500;
  
  if (x <= A) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define rep(i,n) for(int i = 1; i <= n; ++i)
#define boost ios::sync_with_stdio(0)
#define ms0(s) memset((s), 0, sizeof(s))
#define INF 0x3f3f3f3f
#define ABS(x) ((x)<0 ? (-(x)) : (x))
#define forvec(it,v) for(vector<int>::iterator it = v.begin(); it != v.end(); ++it)

#ifdef LOCAL
#define DEBUG 1
#else
#define DEBUG 0
#endif
#define $ if(DEBUG)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

//quick I/O
ostream& operator << (ostream& out, const pii& p){
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}
template <typename T>
inline void read(T& x){
	int w = 1; T data = 0;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') w = -1, ch = getchar();
	while(isdigit(ch))
		data = 10 * data + ch - '0', ch = getchar();
	x = data * w;
}
template <typename T>
void write(T x){
	 if (x < 0) putchar('-'),x = ~x + 1;
	 if (x > 9) write(x / 10);
	 putchar( x % 10 + '0');
}

//debug
template<typename T>
void printvec(vector<T> vec){
	for(T v : vec) cout << ' ' << v;
	cout << '\n';
}
template<typename T>
void printset(set<T> s){
	for(auto it = s.begin(); it != s.end(); ++it)
		cout << ' ' << *it;
	cout << '\n';
}
template<typename T>
void printarray(T* p,int n){
	cout << '{';
	REP (i,n) cout << ' ' << p[i];
	cout << "}\n";
}

int main()
{
 	#ifdef FREOPEN
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
 		clock_t starttime = clock();
	#endif
int n; read(n);
if(n < 1200) puts("ABC");
else if(n < 2800) puts("ARC");
else puts("AGC");


	#ifdef FREOPEN
		freopen("CON", "w", stdout);
		printf( "\n\n-----------------\n%ld ms are used.\n", clock() - starttime );
	#endif
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
const ll INF=1e18+5;
int main()
{
    IO;
    int n ;
    cin>>n;
    double arr[n+2];
    for(int i = 0; i< n ; i ++) cin>>arr[i];
    double dp[n+2][n+2];
    for(int i = 0 ; i< n ; i ++)
    {
        for(int j = 0 ; j <=i+1 ; j ++)
        {
                if(i==0 && j==0)
                    dp[i][j]=1-arr[i];
                else if(j==0)
                    dp[i][j]=(1-arr[i])*dp[i-1][j];
                else if(i==0 &&j==1)
                    dp[i][j]=arr[i];
                else if(j==i+1)
                    dp[i][j]=arr[i]*dp[i-1][j-1];
                else
                    dp[i][j]=(1-arr[i])*dp[i-1][j]+(arr[i]*dp[i-1][j-1]);
        }
    }
    double ans=0;
    for(int i = n; i>n/2;i--){
        ans+=dp[n-1][i];
    }
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 70144
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

class Point{
public:
  int n;
  double sa;
  Point (int n = 0, double sa = 0):n(n),sa(sa){}
  bool operator < (const Point &p) const{
    return sa < p.sa;
  }
};

main(){
  int i,j,n;
  Point p[1000000];
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++){
      double h,w;
      cin >> p[i].n >> h >> w;
      p[i].sa = w / pow(h/100,2) - 22.0;
      if(p[i].sa < 0.0) p[i].sa *= -1.0;
    }
    sort(p,p+n);

    cout << p[0].n << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  int x = s1.size()-1;
  int y = s2.size()-1;
  int z = s3.size()-1;
  if(s1[x]==s2[0]&&s2[y]==s3[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,k;
  int *array=new int[200005];
  int *imos=new int[200005];
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  
  for(int i=0;i<k;i++){
    for(int j=0;j<n;j++){
      imos[j]=0;
    }
    for(int j=0;j<n;j++){
      int left=max(j-array[j],0);
      int right=min(j+array[j]+1,n);
      imos[left]++;
      imos[right]--;
    }
    bool is_full=(imos[0]==n);
    for(int j=1;j<n;j++){
      imos[j]+=imos[j-1];
      if(imos[j]!=n){
	is_full=false;
      }
    }
    if(is_full){
      for(int j=0;j<n;j++){
	cout<<n<<' ';
      }
      cout<<endl;
      return(0);
    }
    int *temp=array;
    array=imos;
    imos=temp;
  }
  
  for(int i=0;i<n;i++){
    cout<<array[i]<<' ';
  }
  cout<<endl;
  return(0);
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

struct UnionFind{
	vector<int> par,rank;
	UnionFind(int n) :par(n + 1),rank(n + 1,1){
		for(int i = 1;i <= n;i++) par [i] = i;
	}
	int find(int x){
		return par [x] == x ? x : par [x] = find(par [x]);
	}
	bool unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(rank [x] < rank [y]) swap(x,y);
		rank [x] += rank [x] == rank [y];
		par [y] = x;
		return true;
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
};

int N,M;

int main()
{
	scanf("%d%d",&N,&M);
	UnionFind uf(N * 2);
	FOR(i,0,M){
		int a,b;
		scanf("%d%d",&a,&b);
		uf.unite(a,b + N);
		uf.unite(a + N,b);
	}

	if(uf.same(1,1 + N)){
		printf("%lld\n",(ll) N * (N - 1) / 2 - M);
	}
	else{
		ll x = 0,y = 0;
		FOR(i,1,N + 1){
			if(uf.same(1,i)){
				x++;
			}
			else{
				y++;
			}
		}
		printf("%lld\n",x * y - M);
	}

	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
 public static void main(String args[]) {
	 Scanner sc =new Scanner(System.in);
	 int N = sc.nextInt();
	 int data[]=new int[N];
	 int max1=0;
	 int max2=0;
	 int t1=0;
	 int t2=0;
	 
	 for(int i=0;i<N;i++) {
		 data[i]=sc.nextInt();
		 if(max1 <=data[i]) {
			 
	
			 max2=max1;
			 max1=data[i];
			
			 t2  = t1;
			 t1  = i;
			 
		 }else if(max2<=data[i]){

			 max2= data[i];
			 t2  = i;
		
	 }
	 }
	 for(int i=0;i<N;i++) {
		if(i==t1) {
			System.out.println(max2);
		}else {
			System.out.println(max1);
		}
		 
	 }
	 

	 
 }
}



Measured memory_bytes: 84412
#!/usr/bin/env python3

import functools


def restore_array(bs):
    all_xor = functools.reduce(lambda x, y: x ^ y, bs)
    res = [all_xor ^ b for b in bs]
    return res


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    print(*restore_array(bs))


if __name__ == '__main__':
    main()

Measured memory_bytes: 31832
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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;}

int n;
ll a[16][16];
ll dp[65540];
bool used[65540];

ll calc(int s){
  if(s == 0)return 0;
  if(used[s])return dp[s];
  used[s] = true;
  ll res = 0;
  rep(i, n){
    FOR(j, i+1, n){
      if((s >> i) % 2 == 1 && (s >> j) % 2 == 1)res += a[i][j];
    }
  }
  for(int t = s; t > 0; t = (t-1) & s){
    res = max(res, calc(t) + calc(s & ~t));
  }
  return dp[s] = res;
}

int main(int argc, char const* argv[])
{
  cin >> n;
  rep(i, n){
    rep(j, n){
      cin >> a[i][j];
    }
  }
  fill(used, used + (1LL << n), false);
  cout << calc((1LL << n) - 1) << endl;
	return 0;
}


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

int A[3002];
int B[3002];

int DP1[3002][3002];
int DP2[3002][3002];

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

    for (int i = 1; i <= N; ++i) cin >> A[i] >> B[i];

    A[0] = B[0] = 0;
    A[N + 1] = B[N + 1] = 0;

    DP1[0][0] = 0;

    for (int i = 1; i <= N; ++i) {
        DP1[i][0] = 0;
    }

    for (int j = 1; j <= T - 1; ++j) {
        DP1[0][j] = 0;
    }

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= T - 1; ++j) {
            int a = A[i - 1];
            int b = B[i - 1];
            DP1[i][j] = max(DP1[i - 1][j], j - a >= 0 ? DP1[i - 1][j - a] + b : 0);
        }
    }

    DP2[N + 1][0] = 0;

    for (int i = N; i >= 1; --i) {
        DP2[i][0] = 0;
    }

    for (int j = 1; j <= T - 1; ++j) {
        DP2[N + 1][j] = 0;
    }

    for (int i = N; i >= 1; --i) {
        for (int j = 1; j <= T - 1; ++j) {
            int a = A[i + 1];
            int b = B[i + 1];
            DP2[i][j] = max(DP2[i + 1][j], j - a >= 0 ? DP2[i + 1][j - a] + b : 0);
        }
    }

    int ans = 0;

    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= T - 1; ++j) {
            int q = DP1[i][j] + DP2[i][T - 1 - j] + B[i];
            if (ans < q) ans = q;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 70656
num = int(input())
list = [i ** 5 for i in range(1000)]
ans = []
for a in range(1000):
    for b in range(1000):
        if list[a] - list[b] == num: 
            ans = [a, b]
            break
        if list[a] + list[b] == num:
            ans = [a, b * (-1)]
            break
print(' '.join(map(str, ans)))

Measured memory_bytes: 9228
#include "bits/stdc++.h"

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

using namespace std;

namespace Kyopro {

    using ll = long long;

    const double PI = acos(-1);

    const ll MOD = 998244353LL;

    const int MAX = 210000;

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

    // テーブルを作る前処理
    void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    // 二項係数計算
    long long COM(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

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

    ll f(size_t m, size_t n) {
        ll ret = (m * modpow(m - 1, n - 1, MOD)) % MOD;
        return ret;
    }

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

    ll combinations2(size_t n, size_t k) {
        ll r = 1;
        for (ll d = 1; d <= k; ++d) {
            r *= n--;
            r = r % MOD;
            r = r * modinv(d, MOD);
            r = r % MOD;
        }
        if (r > MOD / 2) {
            r -= MOD;
        }
        return r;
    }
}

using namespace Kyopro;

void solve() {
    size_t ans = 1;
    while (true) {
        ll t;
        cin >> t;
        if (t == 0) {
            break;
        }
        ++ans;
    }
    cout << ans << endl;
}

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

    COMinit();

    solve();

    return 0;
}

Measured memory_bytes: 8532
import sys
readline = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, readline().rstrip().split()))
    x = 0
    y = sum(A)
    ans = 10 ** 10
    for i in range(N-1):
        x += A[i]
        y -= A[i]
        ans = min(ans, abs(x-y))
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 23792