akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353

    """
    aiが300以下なのが嬉しい，総和でなんかできる．
    dp[i][j]でi番目まで見て合計がj，j<=N*max(a)なので合計O(N^2 max(a))，これでRの通り数が求まるがGB用に何が残っているのかわからん-
    余事象，R>=sum(a)/2 ならダメなわけで
    
    """
    N=I()
    A=[0]*N
    for i in range(N):
        A[i]=I()
    
    S=sum(A)
    
    dp=[[0]*(S+1) for _ in range(N+1)]
    # i番目まで見て，Rの総和がjの通り数
    dp[0][0]=1
    
    for i in range(N):
        a=A[i]
        for j in range(S+1):
            dp[i+1][j]=(dp[i+1][j] + dp[i][j]*2)%mod#g,b
            if j+a<=S:
                dp[i+1][j+a]=(dp[i+1][j+a] + dp[i][j])%mod#r
    
    rem=0
    for j in range((S+1)//2,S+1):
        rem=(rem+dp[-1][j])%mod#RがS/2以上なら基本的に被りを考慮する必要はない
    ans=pow(3,N,mod)-rem*3#r,g,b3色分
    ans%=mod#負数防止
        
    if S%2==0:
        # 0,S/2,S/2は被って数えている，bを使わないバージョン
        dp2=[[0]*(S+1) for _ in range(N+1)]
        # i番目まで見て，Rの総和がjの通り数
        dp2[0][0]=1
        
        for i in range(N):
            a=A[i]
            for j in range(S+1):
                dp2[i+1][j]=(dp2[i+1][j] + dp2[i][j])%mod#g
                if j+a<=S:
                    dp2[i+1][j+a]=(dp2[i+1][j+a] + dp2[i][j])%mod#r
                    
        temp=dp2[-1][S//2]
        ans+=temp*3
        
    
    print(ans%mod)
    
    # for i in range(N+1):
    #     print(dp[i])
            

main()


Measured memory_bytes: 489408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
#define mod 1000000007
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}

int main()
{
    int n;
    cin>>n;
    vi a(n);
    int ans=0;
    rep(i,0,n)
    {
        cin>>a[i];
        if(i%2==0&&a[i]%2!=0)ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define loop(i,n) for(int i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fileread freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb push_back
#define mp make_pair
#define itr iterator
#define fi first
#define se second
#define pii pair<int,int>
#define pci pair<char,int>
#define u_map unordered_map
#define u_set unordered_set
#define u_mmap unordered_multimap
#define u_mset unordered_multiset
# define pi 3.14159265358979323846
using namespace std;

signed main() {
	/*
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	*/
    
    int n,a;
    cin>>n>>a;
    n%=500;
    if(n<=a) cout<<"Yes";
    else cout<<"No";
    
    
    
    
    
    
    
   
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define P(x) cout << (x) << "\n"
#define D(x) cerr << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

using i64=long long int; // 10^18
i64 INF = 1e+18;
int n;
const int SIZE = 100005;
i64 h[SIZE],dp[SIZE];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    REP(i,n)cin>>h[i];
    REP(i,n)dp[i]=INF;
    dp[0]=0;
    dp[1]=abs(h[1] - h[0]);
    for(int i=2;i<=n-1;++i){
        dp[i]=min(min(dp[i], dp[i-1]+abs(h[i] - h[i-1])), dp[i-2]+abs(h[i-2] - h[i]));
    }
    P(dp[n-1]);
    return 0;
}

Measured memory_bytes: 1792
#define DEBUG 0

/**
 * File    : D2.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-26 00:08:10
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
ll A[100010];
ll B[100010];
ll C[100010];
typedef tuple<ll, ll> T;
vector<T> V;

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  for (auto i = 0; i < M; i++)
  {
    cin >> B[i] >> C[i];
  }
  for (auto i = 0; i < N; i++)
  {
    V.push_back(T(A[i], 1));
  }
  for (auto i = 0; i < M; i++)
  {
    V.push_back(T(C[i], B[i]));
  }
  ll cnt = N;
  ll ans = 0;
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  for (auto x : V)
  {
    ll val = get<0>(x);
    ll c = get<1>(x);
    ans += val * min(c, cnt);
    cnt -= min(c, cnt);
    if (cnt == 0)
    {
      break;
    }
  }
  cout << ans << endl;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

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

signed main()
{
    int a[3] = {};
    string s;
    cin >> s;

    a[s[0] - 'a']++;
    a[s[1] - 'a']++;
    a[s[2] - 'a']++;

    if (a[0] && a[1] && a[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
import itertools

grid = []
for i in range(2*k):
    array = list(map(int, input().split()))
    grid.append(array)

l = []
for j in range (k):
    l.append(grid[0+2*j+1])

lis = list(itertools.chain.from_iterable(l))

count = 0
for m in range(n):
    if m+1 in lis:
        count = count +1
print(n - count)

Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define MAX 100001
#define MOD 1000000007
using namespace std;

int sum[401][401],cost[401][401];

void min_cost (int s,int e, int*a )
{
    if(cost[s][e] != -1)
        return;
    if(s==e)
    {
        sum[s][e] = a[s];
        cost[s][e] = 0;
        return;
    }
    int minn = LLONG_MAX;
    for (int i = s; i < e ; ++i)
    {
        min_cost (s,i,a);
        min_cost (i+1,e,a);

        sum[s][e] = sum[s][i] + sum[i+1][e];
        minn = min ( minn , cost[s][i] + cost[i+1][e] + sum[s][e]);
    } 
    cost[s][e] = minn;
}

 
int32_t main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
            cin>>a[i];

    memset(cost,-1, sizeof(cost));

    min_cost (0,n-1,a);

    cout<< cost [0][n-1] << endl;


    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a-c)/(b+c)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string name = "E869120";
    int ans = 0;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        ans += s==name;
    }
    cout << ans << endl;
}


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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define sort_unique(x) sort(ALL(x)); x.resize(distance(x.begin(), unique(ALL(x))))
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(15);
    cout << fixed;

	int n = 0, ans = 0;
    cin >> n;

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

        st.insert(x);

        if (*st.begin() == x) {
            ans++;
        }
    }

    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

int main()
{
  int n, q;
  std::cin >> n >> q;
  std::vector<std::vector<int>> adj_list(n);
  for(int i = 0; i < n-1; i++)
  {
    int p, c;
    std::cin >> p>>c;
    int p_i = p - 1;
    int c_i = c - 1;
    adj_list[p_i].push_back(c_i);
    adj_list[c_i].push_back(p_i);
  }
  
  std::vector<int> p_vec(q);
  std::vector<int> x_vec(q);
  std::vector<int> scores(n,0);
  for (int i = 0; i < q; i++)
  {
    int p, x;
    std::cin >> p >> x;
    scores[--p] += x;
  }
  
  std::queue<int> queue;
  std::vector<bool> closed_nodes(n, false);
  queue.push(0);
  while(!queue.empty())
  {
    int ind = queue.front(); queue.pop();
    std::vector<int> child = adj_list[ind];
    closed_nodes[ind] = true;
    for(auto i: child)
    {
      if(closed_nodes[i])
      {
        continue;
      }
      scores[i] += scores[ind];
      queue.push(i);
    }
  }
  
  for (int i = 0; i < scores.size(); i++)
  {
    std::cout << scores[i] << std::endl;
  }
  
  return 0;
}

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


int main()
{
    float a, b;

    cin >> a;
    cin >> b;

    int i;
    int a_t;
    int b_t;

    int ans = -1;
    for(i=0;i<10000;i++){
        a_t = float(i) / 12.5;
        b_t = float(i) / 10;
        if(a_t == a && b_t == b){
            ans = i;
            break;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<int> days(n);
  for (int i = n-1; i >= 0; i--) {
    if (i+c+1 < n)
      days[i] = days[i+c+1];
    if (s[i] == 'o')
      days[i]++;
    if (i < n-1)
      chmax(days[i], days[i+1]);
  }
  int cnt = 0, last = -c-1;
  rep(i, n) {
    int num = cnt;
    int next = max(i+1, last+c+1);
    if (next < n)
      num += days[next];
    if (num < k)
      cout << i+1 << '\n';
    if (i > last+c && s[i] == 'o') {
      cnt++;
      last = i;
    }
  }
  return 0;
}

Measured memory_bytes: 2580
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    VII arr(n);
    for(auto &x:arr)
        cin>>x;
    ll ans=0;
    sort(all(arr),greater<int>());
    if(arr.size()>=2)
        ans+=arr[0];
    int j=1,c=0;
    for(int i=2;i<arr.size();++i)
    {
        if(c==2)
        {
            c=0,j++;
        }
        ans+=arr[j];
        c++;
    }

    cout<<ans;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

string str;
int ans;
int x;
int main()
{
    int n; 
    cin >> n >> str;
    for (auto it:str)
    {
        if (it=='I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans;
}

Measured memory_bytes: 256
n, k = map(int,input().split())
A = []
N = []

N = list(range(1,n+1))

for i in range(1,k+1):
    d = int(input())
    a=set(map(int,input().split()))
    A += a

ans = list(set(N)-set(A))

print(len(ans))

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
     int a,b;
     cin>>a>>b;
     if(a<=5)
        b=0;
     else if(a<=12)
        b/=2;
     cout<<b<<endl;

    return 0;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n,x,m;
  cin >> n >> x >> m;
  
  map<ll,ll> next;
  ll a = x;
  ll total = a;
  ll i = 0;
  for(i=0;i<n-1;i++){
    if(next.count(a)!=0){
      break;
    }
    ll b = (a*a)%m;
    total += b;
    next[a] = b;
    a = b;
  }

  ll rest = (n-1)-i;
  if(rest==0){
    cout << total << endl;
    return 0;
  }
  
  ll p = a;
  ll count = 0;
  ll loopTotal = 0;
  while(true){
    p = next[p];
    loopTotal += p;
    count++;
    if(p==a){
      break;
    }
  }
  
  total += (rest/count)*loopTotal;
  rest = rest%count;
  while(rest>0){
    p = next[p];
    total += p;
    rest--;
  }

  cout << total << endl;
  
  return 0;
}



Measured memory_bytes: 6708
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String n = sc.next();
		String s = n.substring(0,n.length() - 8);
		System.out.println(s);
		
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 2001;

ll mn[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll x;
    cin >> n >> x;
    vl vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    ll ans = (1LL << 62);
    rep(i,n){
        ll sm = 0;
        if(i == 0){
            rep(j,n){
                mn[i][j] = vec[j];
                sm += mn[i][j];
            }
        }else{
            rep(j,n){
                mn[i][j] = min(mn[i-1][j],vec[(j+n-i)%n]);
                sm += mn[i][j];
            }
        }
        ans = min(ans,sm+i*x);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

ll mod = 1000000007;

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

  vector<vector<ll>> vec(1000, vector<ll>(2000));
  for (int i = 1; i < 1000; ++i) {
    for (int j = 1; j < 2000; ++j) {
      if (i == 1)
        vec[i][j] = 1;
      else if (j == 1)
        vec[i][j] = 1;
      else
        vec[i][j] = (vec[i-1][j] + vec[i][j-1]) % mod;
    }
  }

  ll ans = 0;
  for (int i = 1; i < 1000; ++i) {
    if (n < 3 * i)
      continue;
    ans = (ans + vec[i][n - i * 3 + 1]) % mod;
  }

  cout << ans << endl;

}


Measured memory_bytes: 18836
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> low(n), high(n);
        for(int i=0; i<n; ++i)
            cin >> low[i] >> high[i];

        map<pair<int, int>, long long> m;
        m[make_pair(0, 1)] = 1;
        long long ans = 0;
        while(!m.empty()){
            map<pair<int, int>, long long> m2;
            for(const auto& p : m){
                int prev = p.first.first;
                bitset<32> bs = p.first.second;

                for(int a=0; a<=9; ++a){
                    bitset<32> bs2;
                    for(int i=0; i<n; ++i){
                        if(bs[2*i]){
                            if(0 < a)
                                bs2[2*i+1] = true;
                            if(low[i] <= a && a <= high[i])
                                bs2[2*(i+1)] = true;
                        }
                        if(bs[2*i+1]){
                            int x = prev * 10 + a;
                            if(low[i] <= x && x <= high[i])
                                bs2[2*(i+1)] = true;
                        }
                    }
                    if(bs2[2*n]){
                        ans += p.second;
                        bs2[2*n] = false;
                    }

                    if(bs2.any())
                        m2[make_pair(a, bs2.to_ulong())] += p.second;
                }
            }
            m.swap(m2);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1212
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,y) for(int i=(x);i<=(y);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    int cnt=0,nt=0,k=inf;
    rep(i,n){
        int x;
        cin>>x;
        cnt+=x;
        if(x%10){
            nt++;
            k=min(k,x);
        }
    }

    if(nt==0){
        cout<<0;
        return 0;
    }
    if(cnt%10){
        cout<<cnt;
        return 0;
    }
    cout<<cnt-k<<'\n';

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
 
 
}
 
Node treeSearch(Node u, int k){
  while(u !=NIL){
    if(u->key == k)break;
    else if(u->key < k)u = u->right;
    else u = u->left;
  }
  return u;
}
 
Node treeSuccessor(Node x){
 
 
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
 
 
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x != NIL){
    y=x;
    if(z->key < x->key)x = x->left;
    else x = x->right;
  }
  z->parent = y;
   if(y == NIL)
      root = z;
    else if(z->key < y->key)
        y->left = z;
    else
      y->right = z;
 
   
}
void inorder(Node u){
if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);  
    inorder(u->right);
      }
}
void preorder(Node u){
 if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
      }
}
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}

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

int main() {
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<char> a(h*w);
  
  for (int i = 0; i < h*w; i = i + 1) {
    cin >> a.at(i);
  }
  
  for (int i = 0; i < w + 2; i = i + 1) {
    cout << '#';
  }
  
  cout << endl;
  
  for (int i = 0; i < h*w; i = i + 1) {
    if (i % w == 0) {
      cout << '#';
    }
    cout << a.at(i);
    if ((i + 1) % w == 0) {
      cout << '#' << endl;
    }
  }
  
  for (int i = 0; i < w + 2; i = i + 1) {
    cout << '#';
  }
  
  cout << endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] odd = new int[100001]; // iが奇数であるviからなる数列Oについて、1-100000までのそれぞれの数が存在する個数
		int[] even = new int[100001];
		Arrays.fill(odd, 0);
		Arrays.fill(even, 0);
		for (int i = 1; i <= n; i++) {
			int v = sc.nextInt();
			if (i%2 != 0) {
				odd[v]++;
			} else {
				even[v]++;
			}
		}

		int odd_max1 = 0;
		int odd_max2 = 0;
		for (int i = 1; i < 100000; i++) {
			if (odd[i] > odd[odd_max1]) {
				odd_max2 = odd_max1;
				odd_max1 = i;
			} else if (odd[i] > odd[odd_max2]) {
				odd_max2 = i;
			}
		}
		int even_max1 = 0;
		int even_max2 = 0;
		for (int i = 2; i < 100001; i++) {
			if (even[i] > even[even_max1]) {
				even_max2 = even_max1;
				even_max1 = i;
			} else if (even[i] > even[even_max2]) {
				even_max2 = i;
			}
		}
		int not_rewrited = 0;
		if (odd_max1 == even_max1) {
			not_rewrited = Math.max(odd[odd_max1] + even[even_max2], odd[odd_max2] + even[even_max1]);
		} else {
			not_rewrited = odd[odd_max1] + even[even_max1];
		}
		System.out.println(n - not_rewrited);
	}
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int x;
    cin >> x;

    int b, max_pow = 1;
    for (int i = 2; i <= x; i++) {
        b = 2;
        while (pow(i, b) <= x) {
            max_pow = max(max_pow, int(pow(i, b)));
            b++;
        }
    }

    cout << max_pow << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 512
h,w=map(int, input().split())
l=[list(list(input())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if i==0:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i][j+1]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
        elif i==h-1:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='#' or l[i-1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i-1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i][j+1]=='#' or l[i-1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
        else:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='#' or l[i-1][j]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i-1][j]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i][j+1]=='#' or l[i-1][j]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()

print('Yes')

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

int main(){
 	int n,m;
	cin >>n;
  	vector<string> a(n);
  	for(int i = 0; i < n;i++)
      	cin >> a[i];
  
  	cin >>m;
  	vector<string> b(m);
  	for(int i = 0; i < m;i++)
      	cin >> b[i];
  	int max = 0;
  	for(int i = 0; i < n;i++) {
      	int tmp = 1;
    	for(int j = i+1; j < n+m;j++) {
      			if(j<n && a[i] == a[j])
                   		tmp++;
 				else if(j>=n && a[i] ==b[j-n]) 
          				tmp--;
        }
      	if(max < tmp)	
         	max = tmp;
    }    	
	cout << max<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int findans(vector<int>&arr,vector<int>&brr,vector<int>&crr,int pos,int parent,map<pair<int,int>,int> &mp)
{
    if(pos==arr.size())
    {
        return 0;
    }
    if(mp.find({pos,parent})!=mp.end())
    {
        return mp[{pos,parent}];
    }
    if(parent==1)
    {
        return mp[{pos,parent}]=max(brr[pos]+findans(arr,brr,crr,pos+1,2,mp),crr[pos]+findans(arr,brr,crr,pos+1,3,mp));
    }
    else if(parent==2)
    {
        return mp[{pos,parent}]=max(arr[pos]+findans(arr,brr,crr,pos+1,1,mp),crr[pos]+findans(arr,brr,crr,pos+1,3,mp));
    }
    else
    {
        return mp[{pos,parent}]=max(brr[pos]+findans(arr,brr,crr,pos+1,2,mp),arr[pos]+findans(arr,brr,crr,pos+1,1,mp));
    }
}
int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    vector<int> brr;
    vector<int> crr;
    for(int i=0;i<n;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        arr.push_back(a);
        brr.push_back(b);
        crr.push_back(c);
    }
    map<pair<int,int>,int> mp;
    cout<<max(max(arr[0]+findans(arr,brr,crr,1,1,mp),brr[0]+findans(arr,brr,crr,1,2,mp)),crr[0]+findans(arr,brr,crr,1,3,mp));
}

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

const int MAXN = 2005;

int a[MAXN][MAXN], c[MAXN][MAXN], d[MAXN][MAXN];
char str[MAXN][MAXN];
int n, m, q;

inline int read()
{
	int a = 0, c;
	do c = getchar(); while (!isdigit(c));
	while (isdigit(c)) {
		a = a*10+c-'0';
		c = getchar();
	}
	return a;
}

int main()
{
	n = read(), m = read(), q = read();
	for (int i = 1; i <= n; i++) 
		scanf("%s", str[i]+1);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			a[i][j] = str[i][j]-'0';
			if (j < m) c[i][j] = (str[i][j]==str[i][j+1]&&str[i][j]=='1');
			if (i < n) d[i][j] = (str[i][j]==str[i+1][j]&&str[i][j]=='1');
			a[i][j] += a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			c[i][j] += c[i-1][j]+c[i][j-1]-c[i-1][j-1];
			d[i][j] += d[i-1][j]+d[i][j-1]-d[i-1][j-1];
		}
	}
	for (int i = 1; i <= q; i++) {
		int x1 = read(), y1 = read(), x2 = read(), y2 = read();
		int tot = a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
		int link_lr = c[x2][y2-1]-c[x1-1][y2-1]-c[x2][y1-1]+c[x1-1][y1-1];
		int link_ud = d[x2-1][y2]-d[x1-1][y2]-d[x2-1][y1-1]+d[x1-1][y1-1];
		printf("%d\n", tot-link_lr-link_ud);
	}
	return 0;
}


Measured memory_bytes: 52864
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    static class Reader {
        private BufferedReader br;
        private StringTokenizer token;

        protected Reader(InputStream obj) {
            br = new BufferedReader(new InputStreamReader(obj));
            token = null;
        }
        protected String next() {
            while (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {e.printStackTrace();}
            }
            return token.nextToken();
        }
        protected int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int i=0; i<n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
        protected int nextInt() {return Integer.parseInt(next());}
    }


    public static void main(String[] args) throws IOException {
        Reader in = new Reader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = in.nextInt(), b = in.nextInt();
        if (((a*b)&1) == 0) out.printf("%s\n", "Even");
        else out.printf("%s\n", "Odd");
        out.close();
    }
}

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

int main() 
{
    string s;
    int n,q;
    cin>>n>>q;
    cin>>s;
    int arr[n+1]={0};
    if(s[0]=='A' && s[1]=='C')
    {
        arr[2]++;
    }
    for(int i=2;i<n;i++)
    {
        if(s[i-1]=='A' && s[i]=='C')
        {
            arr[i+1]+=arr[i]+1;
        }
        else
        {
            arr[i+1]=arr[i];
        }
    }
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        cout<<arr[y]-arr[x]<<"\n";
    }
   
    
}


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

int main(void){
    string s;
    cin >> s;
    if(s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;

class Main {
    public static void main(String args[])
    {
     String s;int a=0;
     Scanner sc=new Scanner(System.in);
     s=sc.next();
     if(s.equals("MON"))
     {
         a=6;
     }
     else if(s.equals("TUE"))
     {
         a=5;
     }
     else if(s.equals("WED"))
     {
         a=4;
     }
     else if(s.equals("THU"))
     {
         a=3;
     }
     else if(s.equals("FRI"))
     {
         a=2;
     }
     else if(s.equals("SAT"))
     {
         a=1;
     }
     else if(s.equals("SUN"))
     {
         a=7;
     }
     System.out.println(a);
    }
}



Measured memory_bytes: 21844
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	lines := n * (n - 1) / 2
	max := (n - 1) * (n - 2) / 2
	if k < 0 || k > max {
		fmt.Println(-1)
	} else {
		count := 0
		fmt.Println(lines - k)
		for i := 1; i < n; i++ {
			for j := i + 1; j < n+1; j++ {
				fmt.Println(i, j)
				count += 1
				if count == lines-k {
					return
				}
			}
		}
	}
}


Measured memory_bytes: 640
const makeOdd = (l, isFirstZero) => {
  var isZero = !isFirstZero
  return Array.from({ length: l }).map(i => {
    isZero = !isZero
    return isZero ? "0" : "1"
  })
}

function main(input) {
  const inp = input.trim()
  const gt1 = makeOdd(inp.length, true)
  const gt2 = makeOdd(inp.length, false)
  var a1 = inp.split("").filter((char, c) => gt1[c] !== char).length
  var a2 = inp.split("").filter((char, c) => gt2[c] !== char).length
  console.log(a1 < a2 ? a1.toString() : a2.toString())
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 26832
#include <iostream>
using namespace std;
struct point
{
    int tan;
    int sum;
}ans1,ans2;
int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int tang=-1;
    int sum=1;
    //double C=(100*e)/(100+e);
    for(int a1=0;a1*a*100<=f;a1++)
        for(int b1=0;b1*b*100<=f-a1*a*100;b1++)
            for(int c1=0;c1*c<=f-a1*a*100-b1*b*100;c1++)
                for(int d1=0;d1*d<=f-a1*a*100-b1*b*100-c1*c;d1++)
                {
                    int suger=c1*c+d1*d;
					if(suger>(a1*a+b1*b)*e) continue;
					int all=suger+a1*100*a+b1*100*b;
					if(suger*sum>tang*all){
						tang=suger;
						sum=all;
					} 
                }
    cout<<sum<<" "<<tang<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

struct UnionFind
{
    vector<int> par, rank;

    UnionFind(int N) : par(N), rank(N)
    {
        rep(i, N) par[i] = i, rank[i] = 0;
    }

    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (rank[rx] < rank[ry])
        {
            par[rx] = ry;
        }
        else
        {
            par[ry] = rx;
            if (rank[rx] == rank[ry])
                rank[rx]++;
        }
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    UnionFind tree(N);

    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        tree.unite(A, B);
    }

    set<int> st;
    rep(i, N) {
        st.insert(tree.root(i));
    }

    int len = (int)st.size();
    cout << len - 1 << endl;
    return 0;
}

Measured memory_bytes: 7788
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def M(n): return ModInt(n)
def MI(): return M(I())


def main():
    n = I()
    a = LI()
    r = inf
    for c in a:
        tr = 0
        while c%2 == 0:
            c/=2
            tr+=1
        if tr < r:
            r = tr
    return r



print(main())




Measured memory_bytes: 67052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  cout << 360/gcd(n,360) << endl;

}


Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    int n, i, max = 0, min = 1000;
    scanf("%d\n", &n);
    for (i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (tmp > max)
            max = tmp;
        if (tmp < min)
            min = tmp;
    }
    printf("%d\n", max - min);
    return 0;
}


Measured memory_bytes: 128
N = int(input())
happy = [tuple(map(int, input().split())) for _ in range(N)]
happy.sort(key=lambda x: x[0] + x[1])
result = [0, 0]
for i, x in enumerate(reversed(happy)):
    result[i % 2] += x[i % 2]
print(result[0] - result[1])


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

int main(){
    int n;
    cin>>n;
    vector<int> num(100000);
    rep(i,n){
        int a;
        cin>>a;
        num[a]++;
    }
    int ans=0;
    rep(i,num.size()-1){
        int tmp=num[i]+num[i+1]+num[i+2];
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
N = int(input())
Data = list(map(int,input().split()))
Acc  = [0]*(N+1)
for i in range(N):
    Acc[i+1] = Acc[i]+Data[i]
dict = {}
for acc in Acc:
    if not acc in dict.keys():
        dict[acc] = 0
    dict[acc]+=1
ans = 0
for v in dict.values():
    ans += (v * (v-1) // 2)
print(ans)


Measured memory_bytes: 41144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()


int main() {
    int n;
    cin >> n;
    vector<ii> a(n);
    REP(i, n) {
        int x, y;
        cin >> x >> y;
        a[i] = make_pair(x, y);
    }
    sort(ALL(a), [](const ii &a, const ii &b) {
        return a.second < b.second;
    });

    int now = 0;
    REP(i, n) {
        now += a[i].first;
        if (now > a[i].second) {
            std::cout << "No" << '\n';
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    int N,K; cin>>N>>K;
    vector<ll> a(N,0);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }

    vector<ll> subtotal;
    for (int i = 0; i < N; ++i) {
        ll tmp=a[i];
        subtotal.push_back(tmp);
        for (int j = i+1; j < N; ++j) {
            tmp+=a[j];
            subtotal.push_back(tmp);
        }
    }
    ll ans=0ll;
    for (int i = 39; i >= 0; --i) {
        int cnt=0;
        ll cmp=ans|(1ll<<i);
        for(ll s:subtotal){
            if((s&cmp)==cmp) ++cnt;
        }
        if(cnt>=K) ans=cmp;
    }
    cout<<ans<<endl;
    return 0;
}


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

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

        String[] markArr = {"S", "H", "C", "D"};
        HashMap<String, Integer> markMap = new HashMap<>();
        for(int i = 0; i < 4; i++) markMap.put(markArr[i], i);

        //input
        int n = in.nextInt();

        for(int i = 0; i < n; i++){
            String mark = in.next();
            int num = Integer.parseInt(in.next());

            card[markMap.get(mark)][num] = true;
        }

        //search missing card
        PrintWriter out = new PrintWriter(System.out);
        for(int i = 0; i < 4; i++){
            for(int j = 1; j <= 13; j++){
                if(!card[i][j]) out.printf("%s %d\n", markArr[i], j);
            }
        }

        out.flush();
    }
}


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



Measured memory_bytes: 2052