akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

inline int64_t /* greatest common divisor - Euclid's algo. */
gcd(const int64_t a, const int64_t b){ return !b ? a : gcd(b, a % b); }

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  size_t n;
  int64_t k;
  cin >> n >> k;
  vector<int64_t> a(n);
  cin >> a;

  if(find(begin(a), end(a), k) != end(a))
  {
    cout << "POSSIBLE";
    return 0;
  }

  if(*max_element(begin(a), end(a)) < k)
  {
    cout << "IMPOSSIBLE";
    return 0;
  }

  int64_t x = a.front();
  for(const auto v: a)
  {
    x = gcd(x, v);
    if(x == 1) break;
  }

  if(k % x)
  {
    cout << "IMPOSSIBLE";
    return 0;
  }

  cout << "POSSIBLE";
  return EXIT_SUCCESS;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;

int main(){
    string s;
    cin>>s;
    int l=s.length();
    int count=0,max=0;
    rep(i,l){
        if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C'){
            count++;
        }else{
            if(count>max){
                max=count;
            }
            count=0;
        }
    }
    if(count>max)max=count;
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ifnot(x) if(not(x))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int X;

void solve() {
  cin >> X;
  int i = 0;
  int sum = 0;
  for(i = 1; ; i++) {
    sum += i;
    if(sum >= X) {
      break;
    }
  }
  cout << i << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	long long int a[10000], min, max, sum;
	int i;
	scanf("%d", &n);
	scanf("%lld", &a[0]);
	min=max=sum=a[0];
	for(i=1; i<n; i++) {
		scanf("%lld", &a[i]);
		if(a[i]<min) min=a[i];
		if(a[i]>max) max=a[i];
		sum+=a[i];
	}
	printf("%lld %lld %lld\n", min, max, sum);
	
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}
bool bitcheck(ll x, ll y) { return (x >> y) & 1; }

template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    ll q;
    cin >> q;
    set<ll> s;
    REP(i, q) {
        ll a, b;
        cin >> a >> b;
        if (a == 0) {
            s.insert(b);
            cout << s.size() << endl;
        } else if (a == 1) {
            cout << s.count(b) << endl;
        } else {
            s.erase(b);
        }
    }
}


Measured memory_bytes: 12464
from collections import Counter

n = int(input())
d_input=list(map(int,input().split()))
m=int(input())
t_input=list(map(int,input().split()))

d_count = Counter(d_input)
t_count = Counter(t_input)

for key,value in t_count.items():
    if key not in d_count:
        print('NO');exit()
    if d_count[key]<value:
        print('NO');exit()
print('YES')


Measured memory_bytes: 57028
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string str;
    int q;
    cin >> str;
    cin >> q;
    string cmd, p;
    int a, b;
    for (int i = 0; i < q; i++) {
        cin >> cmd;
        if (cmd == "print") {
            cin >> a >> b;
            cout << str.substr(a, (b-a+1)) << "\n";
        }
        else if (cmd == "reverse") {
            cin >> a >> b;
            string sub = str.substr(a, (b-a+1));
            reverse(sub.begin(), sub.end());
            str = str.substr(0, a) + sub + str.substr(b+1);
        }
        else if (cmd == "replace") {
            cin >> a >> b >> p;
            str = str.substr(0, a) + p + str.substr(b+1);
        }
    }
}

Measured memory_bytes: 3196
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()

for i in range(50000):
    if N == int(i * 1.08):
        print i
        exit()
print ":("

Measured memory_bytes: 5804
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1010,mod=1e9+7;
int n,ans=1,x,y,high[N];
int power(int p)
{
	int ans=1,v=2;
	for(;p;p>>=1,v=1ll*v*v%mod)
	 if(p&1)ans=1ll*ans*v%mod;
	return ans;
}
void slove(int l,int r,int h,int &a,int &b)
{
	int minf=0x7fffffff,cnt=0;
	for(int i=l;i<=r;i++)
	 if(high[i]<minf)minf=high[i],cnt=1;
	 else if(high[i]==minf)cnt++;
	if(cnt==r-l+1)
	{
		a=power(r-l+1)-2;if(a<0)a+=mod;
		b=power(minf-h);
		return;
	}
	int x,y,last=0,v1=1,v2=1;
	for(int i=l;i<=r+1;i++)
	{
		if(!last&&high[i]>minf)last=i;
		else if(last&&(high[i]<=minf||i==r+1))
		{
			slove(last,i-1,minf,x,y);
			v1=1ll*v1*(x+y*2%mod)%mod;
			v2=1ll*v2*y%mod;last=0;
		}
	}
	a=1ll*v1*power(cnt)%mod;
	a=(a-v2*2)%mod;if(a<0)a+=mod;
	b=1ll*v2*power(minf-h)%mod;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	 scanf("%d",&high[i]);
	for(int i=1;i<=n;i++)
	 if(high[i]>high[i-1]&&high[i]>high[i+1])
	 {
	    ans=1ll*ans*power(high[i]-max(high[i-1],high[i+1]))%mod;
	    high[i]=max(high[i-1],high[i+1]);
	 }
	slove(1,n,0,x,y);
	ans=1ll*ans*(x+y)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  rep(u,m){
    int x,y,z;
    cin >> x >> y >> z;
    tree.unite(x-1,y-1);
  }
  int ans = 0;
  for(auto e:tree.data){
    if(e<0)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
n, a = input(), [0] + map(int, raw_input().split()) + [0]
r = [abs(a[i] - a[i + 1]) for i in xrange(n + 1)]
f, b, s = [], [], 0
for i in xrange(n + 1):
    f.append(s)
    s += r[i]
s = 0
for i in xrange(n, -1, -1):
    b.append(s)
    s += r[i]
b = b[::-1]
f, b = f[:-1], b[1:]
for i in xrange(n):
    print f[i] + b[i] + abs(a[i] - a[i + 2])


Measured memory_bytes: 18284
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

ll n, a[21][21], dp[21][1LL<<21];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) REP(j, n) cin >> a[i][j];

  vector<vector<ll>> g(n+1);
  REP(i, 1LL<<n) {
    ll m = __builtin_popcountll(i);
    // cerr << i << " " << m << endl;
    g[m].push_back(i);
  }

  REP(i, n) if(a[0][i]) dp[0][1<<i] = 1;
  FOR(i, 1, n) for(auto j: g[i]) {
    if(dp[i-1][j] == 0) continue;
    REP(k, n) {
      if(!a[i][k]) continue;
      (dp[i][j | 1<<k] += dp[i-1][j]) %= MOD;
    }
  }
  cout << dp[n-1][(1LL<<n)-1] << endl;

  return 0;
}


Measured memory_bytes: 342944
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int N, M;
  int G[50] = {};
 
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A]++;
    G[B]++;
  }
  for(int i = 0; i < N; i++) {
    cout << G[i] << endl;
  }
 
}

Measured memory_bytes: 256
// you**can**do**anything :~  
#include <bits/stdc++.h>
#define ll long long
#define read(i) scanf("%lli" , &i)
const int maxn=5e5+10;
using namespace std;
vector< pair< ll , ll > >abj[545445];
int main()
{
ll n ,y ,x;
cin>>n;
cin>>y>>x;
ll b=ceil((double)y/n);
//cout<<b<<endl;
b*=n;
//cout<<b<<endl;
if( b>=y and b<=x )
cout<<"OK";
else
cout<<"NG";

}


Measured memory_bytes: 16472
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int water(vector<int> h) {
  if (h.size() == 0) return 0;
  int mn = INF;
  for (int i : h) mn = min(mn, i);
  int res = mn;
  vector<int> watasu;
  REP(i, h.size()) {
    if (h[i] > mn) watasu.push_back(h[i] - mn);
    else {
      res += water(watasu);
      watasu.resize(0);
    }
  }
  res += water(watasu);
  return res;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> h(n); REP(i, n) cin >> h[i];
  cout << water(h) << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 1005
using namespace std;
int n,t;
void solve(){
	scanf("%d %d",&n,&t);
	int ans=0;
	int mi=0x3f3f3f3f;
	for(int i=0;i<n;i++){
		ans+=t+i;
		if(abs(t+i)<abs(mi))mi=t+i;
	}
	ans-=mi;
	printf("%d\n",ans);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[200000],i,n,b,c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(i>0){
      if(i==1)b=a[0];
      if(b<a[i])c++;
      else b=a[i];
    }
  }
  printf("%d",n-c);
  return 0;
}
  

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define taskname "A"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
const int logn = log2(maxn) + 1;
const int inf = 1e9 + 1;
struct seg{
    ll s[maxn * 4];
    void update(int x , int l , int r , int pos , ll val){
        if(l == r){
            s[x] = min(s[x] , val);
            return;
        }
        int mid = l + r >> 1;
        if(pos <= mid)update(x*2,l,mid,pos,val);
        else update(x*2+1,mid+1,r,pos,val);
        s[x] = min(s[x*2],s[x*2+1]);
    }
    ll query(int x , int l, int r , int L , int R){
        if(l > R || L > r)return 1e18;
        if(L <= l && r <= R)return s[x];
        int mid = l + r >> 1;
        return min(query(x*2,l,mid,L,R),query(x*2+1,mid+1,r,L,R));
    }
    seg(){fill_n(s,maxn*4,1e18);};
}s[2];
int n , q , A , B;
int a[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP" , "r")){
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    cin >> n >> q >> A >> B;
    s[0].update(1,1,n,B,B);
    s[1].update(1,1,n,B,-B);
    a[0] = A;
    ll sum = 0;
    //dp[i][j] -> process first i query with pos1 = a[i] , pos2 = j;
    //either dp[i + 1][j] = dp[i][j] + abs(a[i + 1] - a[i])
    //or dp[i + 1][a[i]] = dp[i][j] + abs(j - a[i + 1])
    for(int i = 1 ; i <= q ; ++i){
        cin >> a[i];
        //dp[i + 1][a[i]] = dp[i][j] + abs(j - a[i + 1])
        ll cal = min(-a[i] + s[0].query(1,1,n,a[i],n),
                     a[i] + s[1].query(1,1,n,1,a[i]));
        int tmp = abs(a[i] - a[i - 1]);
        sum += tmp;
        s[0].update(1,1,n,a[i-1],cal-tmp+a[i-1]);
        s[1].update(1,1,n,a[i-1],cal-tmp-a[i-1]);
    }
    ll res = 1e18;
    for(int i = 1 ; i <= n ; ++i){
        res = min(res, s[0].query(1,1,n,i,i)-i+sum);
        res = min(res, s[1].query(1,1,n,i,i)+i+sum);
    }
    cout << res;
}


Measured memory_bytes: 13568
import java.util.Scanner;

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

		int k = sc.nextInt();
		int x = sc.nextInt();

		if (k * 500 >= x) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 27012
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    // g++ -std=c++11 -o c.o c.cpp
    ll l, r;
    cin >> l >> r;
    int mod = 2019;
    int ans = 2019;

    if (r - l >= 2019)
    {
        cout << 0 << endl;
    }
    else
    {
        for (ll i = l; i < r; i++) // 2019の倍数が間に入っている場合
        {                          //たかだか2019回　... O(1)
            for (ll j = l + 1; j <= r; j++)
            {
                ll tmp = (i * j) % 2019;
                if (tmp == 0)
                {
                    ans = 0;
                    break;
                }
                if (tmp < ans)
                {
                    ans = tmp;
                }
            }
        }

        cout << ans % mod << endl;
    }
}

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

using namespace std;

int z_algorithm(string S){
  int A[S.size()];
  A[0] = S.size();
  int i = 1, j = 0;
  while (i < S.size()) {
    while (i+j < S.size() && S[j] == S[i+j]) ++j;
    A[i] = j;
    if (j == 0) { ++i; continue;}
    int k = 1;
    while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
    i += k; j -= k;
  }
  int mx=0;
  for(int i=1;i<S.length();i++){
    if(i>=A[i]&&A[i]>mx)mx=A[i];
  }
  return mx;
}

int main(){
  int n;
  string s;
  cin >> n >> s;
  int mx=0;
  for(int i=0;i<n;i++){
    mx=max(mx, z_algorithm(s.substr(i, s.length()-i)));
  }
  cout << mx << endl;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    uf.unite(a, b);
  }
  int max_size = 0;
  REP(i,n){
      max_size = max(uf.size(i),max_size);
  }
  cout << max_size << endl;
}

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

public class Main {
	static final int RED = 1;
	static final int BLACK = 2;
	static final int VISITED = 3;

	static final int UP = 1;
	static final int DOWN = 2;
	static final int RIGHT = 3;
	static final int LEFT = 4;
	static final int START = 0;

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String tmp = br.readLine();
			/*
			if(tmp == null){
				break;
			}*/

			String[] tmpArray = tmp.split(" ");

			int width = Integer.parseInt(tmpArray[0]);
			int height = Integer.parseInt(tmpArray[1]);

			if(width == 0 && height == 0){
				break;
			}
			int[][] tiles = new int[height][width];

			int currentX = 0;
			int currentY = 0;

			for(int i = 0; i < height; i++){
				String tmpStr = br.readLine();
				for(int j = 0; j < width ; j++){
					char tmpChar = tmpStr.charAt(j);
					if(tmpChar == '.' || tmpChar == '@'){
						tiles[i][j] = BLACK;
					}
					else {
						tiles[i][j] = RED;
					}

					if(tmpChar == '@'){
						currentX = j;
						currentY = i;
					}
				}
			}

			System.out.println(visit(tiles, currentX, currentY, START));
		}
	}

	static int visit(int[][] tiles, int curX, int curY, int dest){
		int result = 1;
		
		if(!available(tiles, curX, curY)){
			return 0;
		}
		tiles[curY][curX] = VISITED;
		
		result += visit(tiles, curX-1, curY, dest);
		result += visit(tiles, curX+1, curY, dest);
		result += visit(tiles, curX, curY-1, dest);
		result += visit(tiles, curX, curY+1, dest);
		
		return result;
	}

	private static boolean available(int[][] tiles, int curX, int curY) {
		// TODO ?????????????????????????????????????????????
		if(curX < 0 || curX >= tiles[0].length || curY < 0 || curY >= tiles.length || tiles[curY][curX] == RED || tiles[curY][curX] == VISITED){
			return false;
		}
		else{
			return true;
		}
	}

}

Measured memory_bytes: 27596
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
int x,n,i,y;
unordered_map<int,int> a;
cin>>x>>n;
for(i=0;i<n;i++)
{
cin>>y;
a[y]=i;
}
for(i=0;;i++)
{
int w=x-i,q=x+i;
if(a.find(w)==a.end())
{
cout<< w;
return 0;
}
if(a.find(q)==a.end())
{
cout<<q;
return 0;
}
}
return 0;
}
 

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int x, y, z, num;
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();
        y = sc.nextInt();
        z = sc.nextInt();
        
        num = (x - z) / (y + z);
        System.out.println(num);
    }
    
}

Measured memory_bytes: 22868
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		// スペース区切りの整数の入力
      int W[] = new int[N];
      int sum = 0;
      for(int i=0;i<N;i++){
        W[i] = sc.nextInt();
        sum = sum + W[i];
      }
      int sasum = 0;
      int sa =100000000;
      int san = 10000000;
      for(int i=0;i<N&&sa>san;i++){
        sasum = sasum + W[i];
        sa = san;
        san = Math.abs((sum-sasum)-sasum);
      }

      System.out.println(sa);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
using namespace std;
const int maxn = 2e5 + 5;
int n;
int p[maxn] , tree[maxn];
inline void update(int x) {
	for(register int i = x; i <= n; i += lowbit(i)) tree[i]++;
}
inline int query(int x) {
	int ret = 0;
	for(register int i = x; i; i -= lowbit(i)) ret += tree[i];
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(register int i = 1; i <= n; ++i)
		cin >> p[i];
	int ans = 0;
	for(register int i = 1; i <= n; ++i) {
		int cnt = query(p[i]);
		if(cnt == 0) ans++;
		update(p[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int n;
	std::vector<int> prime;
	std::vector<int> prime_count;
	scanf("%d", &n);
	for (int i = 2; i <= n; i++)
	{
		int i_cpy{i};
		for (unsigned int j = 0; j < prime.size(); j++)
		{
			while (!(i_cpy % prime[j]))
			{
				i_cpy /= prime[j];
				prime_count[j]++;
			}
		}
		if (i_cpy > 1)
		{
			prime.push_back(i_cpy);
			prime_count.push_back(1);
		}
	}
	long long ans{1};
	for (auto &e : prime_count)
	{
		ans = ans * (e + 1) % 1000000007;
	}
	printf("%lld\n", ans);

	return 0;
}

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

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

  std::set<char> s;

  for (int i = 0; i < N; i++) {
    char S;
    std::cin >> S;
    s.insert(S);
  }

  std::cout << (s.size() < 4 ? "Three" : "Four") << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    return 0;
}

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

int main(){
	string s;
	cin>>s;
	int n=s.size();
	int ans=0,num=0;
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll a, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 10000;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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


void solve(){
	int k, n; cin >> k >> n;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	a.push_back(a[0] + k);
	int ma = 0;
	rep(i, n)ma = max(ma, a[i + 1] - a[i]);
	cout << k - ma << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


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

#define endl "\n"

int a[N];

struct node{
	int b,c;
}x[N];

bool cmp(const node &i,const node &j){
	if(i.c==j.c) return i.b>j.b;
	return i.c>j.c;
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,m,l;
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<m;i++) cin>>x[i].b>>x[i].c;
	sort(a,a+n);
	sort(x,x+m,cmp);
	l=0;
	for(int i=0;i<m&&l<n;i++){
		if(x[i].c<=a[l]) break;
		int t=x[i].b;
		while(t--){
			if(x[i].c>a[l]) a[l++]=x[i].c;
			if(l==n) break;
		}
	}
	ll sum=0;
	for(int i=0;i<n;i++) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	double qwq;
	double ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%lf",&qwq);
		getchar();
		char c=getchar();
		getchar(); getchar(); getchar();
		if (c=='J')
		{
			ans+=qwq;
			continue;
		}
		qwq*=380000;
		ans+=qwq;
	}
	printf("%lf",ans);
	return 0;
}

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

int main(){
  int i,j;
  int n;
  int a[10];

  while(1){
    cin >> n;
    if(!n)break;

    j = 0;
    while(1){
      a[j] = n%8;
      n /= 8;
      if(!n)break;
      j++;
    }

    for(i=j;i>=0;i--){
      if(a[i]<4)cout << a[i];
      else if(a[i]<5)cout << a[i]+1;
      else cout << a[i]+2;
    }
    cout << endl;
  }
}

Measured memory_bytes: 868
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

    int a;
    cin>>a;

    cout<<3*a*a<<endl;

    return 0;
}


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

using namespace std;

long long a[100000];

bool memo[100000];
int c[100000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    memo[0] = true;
    for (int i = 0; i < n; i++) c[i] = 1;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        memo[y] |= memo[x];
        c[y]++;
        c[x]--;
        if (c[x] == 0) memo[x] = false;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (memo[i]) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
using node = tuple<ll, ll>;
const ll inf = numeric_limits<ll>::max();

int main(void) {
  int n,m;
  ll x;
  cin >> n >> m >> x;
  auto costs = vector<ll>(n);
  auto books = vector<vector<ll>>(n);
  for(int i = 0;i < n;++i) {
    cin >> costs[i];
    books[i].resize(m);
    for(int j = 0;j < m;++j) {
      cin >> books[i][j];
    }
  }

  ll res = inf;
  for(int comb = 0;comb < (1 << n);++comb){
    ll c = 0;
    auto skills = vector<ll>(m, 0LL);
    for(int book = 0;book < n;++book) {
      if((1 << book) & comb) {
        c += costs[book];
        for(int a = 0;a < m;++a) {
          skills[a] += books[book][a];
        }
      }
    }

    bool ok = true;
    for (int a = 0;a < m;++a) {
      if (skills[a] < x) {
        ok = false;
        break;
      }
    }
    if(ok) {
      res = min(res, c);
    }
  }
  if(res == inf) {
    cout << "-1" << endl;
  } else {
    cout << res << endl;
  }
  return 0;
}


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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve()
{
    int n, m; cin >> n >> m;
    int sx, sy, dx, dy; cin >> sx >> sy >> dx >> dy;
    --sx; --sy; --dx; --dy;
    vector<vector<bool>> v(n, vector<bool>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char c; cin >> c;
            v[i][j] = c == '.';
        }
    }
    deque<pair<pair<int, int>, int>> q;
    q.push_back({{sx, sy}, 0});

    while (!q.empty()) {
        int cx = q.front().first.first, cy = q.front().first.second, cw = q.front().second;
        q.pop_front();

        if (cx == dx && cy == dy) {
            cout << cw << NL;
            return;
        }

        if (cx < 0 || cy < 0 || cx >= n || cy >= m || !v[cx][cy]) continue;
        v[cx][cy] = false;

        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                int nx = cx + i, ny = cy + j;

                if (abs(i) + abs(j) != 1) {
                    q.push_back({{nx, ny}, cw + 1});
                } else {
                    q.push_front({{nx, ny}, cw});
                }
            }
        }
    }
    cout << -1 << NL;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 6572
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    if (n < 1000000) {
        for (ll i = 1; i <= n; ++i) {
            if (n / i == n % i) ans += i;
        }
    } else {
        for (ll i = 1; i <= 1000000; ++i) {
            if (n / i == n % i) ans += i;
        }
        for (ll q = n / 1000001; q >= 1; --q) {
            if ((n - q) % q == 0) ans += (n - q) / q;

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



Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int H, W;
	cin >> H >> W;

	map<char, int> cnt;

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			char c;
			cin >> c;
			cnt[c]++;
		}
	}

	vector<int> num;
	for (auto itr : cnt) {
		num.push_back(itr.second);
	}

	vector<int> req;
	if (H % 2 == 1 && W % 2 == 1) {
		req.push_back(1);
	}

	for (int i=0; i<H/2; i++) {
		for (int j=0; j<W/2; j++) {
			req.push_back(4);
		}
	}

	if (H % 2 == 1) {
		for (int i=0; i<W/2; i++) {
			req.push_back(2);
		}
	}

	if (W % 2 == 1) {
		for (int i=0; i<H/2; i++) {
			req.push_back(2);
		}
	}

	/*
	// **** debug ****
	int q = 0;
	for (int k : req) {
		cout << k << " ";
		q += k;
	}
	cout << endl << q << endl;

	q = 0;
	for (int k : num) {
		cout << k << " ";
		q += k;
	}
	cout << endl << q << endl;
	*/

	string ans = "Yes";

	for (int r : req) {
		if (r == 1) {
			for (int i=0; i<num.size(); i++) {
				ans = "No";
				if (num[i] % 2 == 1) {
					num[i]--;
					ans = "Yes";
					break;
				}
			}
		} else if (r == 4) {
			for (int i=0; i<num.size(); i++) {
				ans = "No";
				if (num[i] >= 4) {
					num[i] -= 4;
					ans = "Yes";
					break;
				}
			}
		} else {
			for (int i=0; i<num.size(); i++) {
				ans = "No";
				if (num[i] >= 2) {
					num[i] -= 2;
					ans = "Yes";
					break;
				}
			}
		}

		if (ans == "No") break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int vis[100009];
vector<int> adj[100005];
void dfs(int u)
{
	vis[u] = 1;
	for(int i=0;i<(int)adj[u].size();++i) {
		if(!vis[adj[u][i]])
		dfs(adj[u][i]);
	}
}
int main() {
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;++i) {
		int x,y,z;
		cin>>x>>y>>z;
		adj[x-1].push_back(y-1);
		adj[y-1].push_back(x-1);
	}
	int c = 0;
	for(int i=0;i<n;++i) {
		if(!vis[i]) {
			dfs(i);
			c++;
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 10752
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct FlowEdge {
    int to, cap, rev;
    FlowEdge(int to_, int cap_, int rev_) :to(to_), cap(cap_), rev(rev_) { }
};
class FordFulkerson {
public:
    FordFulkerson() {}

    FordFulkerson(int n) : G(n), used(n) {}

    void add(int from, int to, int cap) {
        G[from].emplace_back(to, cap, (int)G[to].size());
        G[to].emplace_back(from, 0, (int)G[from].size() - 1);
    }

    int get(int s, int t) {
        int f = 1, res = 0;
        while (f) {
            fill(begin(used), end(used), false);
            f = dfs(s, t, INT_MAX);
            res += f;
        }
        return res;
    }
private:

    vector<vector<FlowEdge>> G;
    vector<bool> used;

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = 1;
        for (auto &e : G[v]) {
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(e.cap, f));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

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

    int H, W, sy=-1, sx=-1, gy=-1, gx=-1;
    cin >> H >> W;
    vector<string> S(H);
    FordFulkerson ff(H + W + 2);
    rep(y, H) {
        cin >> S[y];
        rep(x, W) {
            if (S[y][x] == 'S') {
                sy = y;
                sx = x;
            }
            if (S[y][x] == 'T') {
                gy = y;
                gx = x;
            }
            if (S[y][x] != '.') {
                ff.add(y, x + H, 1);
                ff.add(x + H, y, 1);
            }
        }
    }
    if (sy == gy || sx == gx) {
        cout << -1 << endl;
        return 0;
    }
    int src = H + W, sink = src + 1;
    ff.add(src, sy, 10000);
    ff.add(src, sx + H, 10000);
    ff.add(gy, sink, 10000);
    ff.add(gx + H, sink, 10000);
    cout << ff.get(src, sink) << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll A,B,Q;
int main(){
    cin >> A >> B >> Q;
    vector<ll> s(A),t(B);
    rep(i,A) cin >> s[i];
    rep(i,B) cin >> t[i];
    
    ll x;
    rep(i,Q){
        cin >> x;
        auto itrA = lower_bound(ALL(s),x);
        auto itrB = lower_bound(ALL(t),x);
        vector<ll> S,T;
        if(itrA == s.begin()) S.pb(*itrA),S.pb(-1e11);
        else if(itrA == s.end()) S.pb(*(itrA-1)),S.pb(1e11);
        else S.pb(*itrA),S.pb(*(itrA-1));
        
        if(itrB == t.begin()) T.pb(*itrB),T.pb(-1e11);
        else if(itrB == t.end()) T.pb(*(itrB-1)),T.pb(1e11);
        else T.pb(*itrB),T.pb(*(itrB-1));
        
        ll ans = 1e13;
        rep(i,2) rep(j,2){
            if(S[i] > x && T[j] > x) ans = min(ans,max(S[i],T[j])-x);
            else if(S[i] < x && T[j] < x) ans = min(ans,x-min(S[i],T[j]));
            else ans = min(ans,min(abs(S[i]-x),abs(T[j]-x))+abs(S[i]-T[j]));
        }
        pr(ans);
    }
    
}

Measured memory_bytes: 2944
#include <map>
#include <ctime>
#ifdef WK
	#include <windows.h>
#endif
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define lowbit(x) (x&(-x))
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define drep(i,x,y) for(int i=x;i>=y;i--)
#define repg(i,x) for(int i=p[x];i;i=e[i].nt)  
using namespace std;
typedef long long LL;
LL read(){
	LL rtn=0;char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')rtn=(rtn<<3)+(rtn<<1)+ch-'0',ch=getchar();
	return rtn;
}
const int N=5010;
int n,m,k;
LL f[51][2];
int a[51]; 
int main(){
#ifdef WK
	freopen("in.txt","r",stdin);
	freopen("ou1.txt","w",stdout);
#endif
	n=read();k=read();k%=2;
	rep(i,1,n)a[i]=read(),a[i]%=2;
	f[0][0]=1;
	rep(i,1,n){
		if(a[i]){
			f[i][0]=f[i-1][0]+f[i-1][1];
			f[i][1]=f[i-1][1]+f[i-1][0];
		}else{
			f[i][0]=f[i-1][0]+f[i-1][0];
			f[i][1]=f[i-1][1]+f[i-1][1];
		}
	}
	printf("%lld\n",f[n][k]);
	return 0;
}

Measured memory_bytes: 256
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(b < a && c < a) a *= 10;
        else if(a <= b && c < b) b *= 10;
        else c *= 10;
        System.out.println(a + b + c);
        sc.close();

    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MaxN = 102;
const int MaxVal = 1e5+2;
const int INF = 1e9+7;
int profit[MaxN], weight[MaxN];
int dp[MaxN][MaxVal];
int N,W;

int rec(int pos, int rem){

    if(rem==0) return 0;
    if(rem<=0 || pos>=N) return INF;
    auto &ret = dp[pos][rem];
    if(ret!=-1) return ret;
    return ret = min( rec(pos+1,rem-profit[pos]) + weight[pos] ,rec(pos+1,rem) );


}

void read(){

    cin>>N>>W;
    memset(dp,-1,sizeof dp);
    for(int i=0; i<N; i++)
        cin>>weight[i]>>profit[i];
}


void solve(){

    read();
    int res = 0;
    for(int i=0; i<MaxVal; i++){
        int ret = rec(0,i);
        if(ret<=W) res = i;
    }

    cout<< res <<"\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 43480
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
 
 
def gcd_ab(a,b):
  a,b = sorted([a,b])
  if a == 0:
    return b
  return gcd_ab(b%a, a)
 
if __name__ == "__main__": 
  N = int(input())
  An = list(map(int, sys.stdin.readline().rstrip().split()))
  cum = [[0,0] for i in range(N+2)]
 
  for i in range(N):
    cum[i+1][0] = gcd_ab(cum[i][0], An[i])
    cum[N-i][1] = gcd_ab(cum[N-i+1][1], An[N-i-1])
 
  ans = [0 for i in range(N)]
  for i in range(1,N+1):
    ans[i-1] = gcd_ab(cum[i-1][0], cum[i+1][1])
  print(max(ans))
 

Measured memory_bytes: 18404
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 0
    mod = 10 ** 9 + 7
    for i in range(N):
        left = 0
        for j in range(i):
            if A[j] < A[i]:
                left += 1
        right = 0
        for j in range(i+1, N):
            if A[j] < A[i]:
                right += 1
        ans += (right * K * (K+1) + left * (K-1) * K) // 2
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 42348
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL LINF=1LL<<62;
const LL mod=1e9+7;


int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<LL> A;
    for(int i=0;i<N;i++){
        LL a;
        cin >> a;
        A.pb(a);
    }
    vector<LL> mini;
    for(int i=0;i+K<=N;i++){
        LL m=LINF;
        for(int j=0;j<K;j++){
            m=min(m,A[i+j]);
        }
        mini.pb(m);
    }
    sort(ALL(mini));
    mini.erase(unique(ALL(mini)),mini.end());
    LL ans=LINF;
    for(int i=0;i<mini.size();i++){
        vector<LL> t,p;
        for(int j=0;j<N;j++){
            if(A[j]>=mini[i]) t.pb(A[j]);
            if(A[j]<mini[i]||j==N-1){
                if(t.size()<K) t.clear();
                else{
                    sort(ALL(t));
                    for(int k=0;k<t.size()-K+1;k++){
                        p.pb(t[k]);
                    }
                    t.clear();
                }
            }
        }
        sort(ALL(p));
        if(p.size()<Q) continue; 
        ans=min(ans,p[Q-1]-p[0]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
# 解説放送の１つめ
N,M = map(int, input().split())
A = list(map(int, input().split()))
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の数(str)
dp = [None]*(N+1)
dp[0] = ""

# strの数の大きいほう
def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
    
for i in range(2, N+1):
    nxt = ""
    for aj in A:
        # 配列外参照と，i本ちょうどで作れないものはだめ
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
    if nxt!="":
        dp[i] = nxt
    #print(dp)
print(dp[N])


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

using namespace std;

int n,a[100005];

map <int,int > M;

int main()
{
	scanf("%d",&n);
	
	for (register int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		M[a[i]]++;
	}
	
	int ans=0;
	
	for (register int i=1;i<=n;++i)
	{
		if (M[a[i]]<a[i]) ans+=M[a[i]];
		if (M[a[i]]>a[i]) ans+=M[a[i]]-a[i];
		M[a[i]]=0;
	}
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 5120