akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

vector<int> foo(int n, const vector<vector<int> > & g) {
    // construct the tree with non-leaf vertices
    int m = 0;
    vector<vector<int> > h(n);
    REP (i, n) if (g[i].size() != 1) {
        ++ m;
        for (int j : g[i]) if (g[j].size() != 1) {
            h[i].push_back(j);
        }
    }

    // the tree must be a path graph
    REP (i, n) {
        if (h[i].size() >= 3) {
            return vector<int>();
        }
    }

    // reconstruct chains
    if (m == 0) {
        assert (n == 2);
        return vector<int>({ 0, 0 });

    } else {
        vector<int> a;
        a.push_back(0);
        int i = 0;
        while (g[i].size() == 1 or h[i].size() == 2) {
            ++ i;
        }
        int parent = -1;
        while (true) {
            a.push_back(g[i].size() - h[i].size());
            bool found = false;
            for (int j : h[i]) if (j != parent) {
                parent = i;
                i = j;
                found = true;
                break;
            }
            if (not found) {
                break;
            }
        }
        -- a[1];
        -- a[a.size() - 1];
        a.push_back(0);
        assert (*min_element(ALL(a)) >= 0);
        return a;
    }
}

vector<int> bar(int n, const vector<int> & a) {
    vector<int> p(n, -1);
    int i = 0;
    for (int a_i : a) {
        p[i + a_i] = i;
        REP (j, a_i) {
            p[i + j] = i + j + 1;
        }
        i += a_i + 1;
    }
    return p;
}

vector<int> solve(int n, const vector<vector<int> > & g) {
    auto a = foo(n, g);
    if (a.empty()) return vector<int>({ -1 });
    auto p = bar(n, a);
    reverse(ALL(a));
    auto q = bar(n, a);
    return min(p, q);
}

int main() {
    int n; cin >> n;
    vector<vector<int> > g(n);
    REP (i, n - 1) {
        int v, w; cin >> v >> w;
        -- v;
        -- w;
        g[v].push_back(w);
        g[w].push_back(v);
    }
    auto p = solve(n, g);
    for (int p_i : p) {
        cout << (p_i == -1 ? -1 : p_i + 1) << ' ';
    }
    cout << endl;
    return 0;
}


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

int main(){
   int a,b,c;
   cin >> a >> b;
   if (b < 10) c = 10*a+b;
   else if(b < 100) c = 100*a+b;
   else c = 1000*a+b;
   int n=sqrt(c);
   if (c == n*n){
      cout << "Yes" << endl;
   }
   else
      cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split()))

bad = 0
for n in nums: bad ^= n

BASIS_LENGTH = 61

def reduce(num):
    total = 0
    power = 0
    for i in range(BASIS_LENGTH):
        if bad & (1 << i): continue
        total += ((num & (1 << i)) >> i) * pow(2, power)
        power += 1
    return total
    
def expand(num):
    total = 0
    power = 0
    for i in range(BASIS_LENGTH):
        if bad & (1 << i):
            continue
        total += ((num & (1 << power)) >> power) * pow(2, i)
        power += 1
    return total

BASIS = [0 for i in range(BASIS_LENGTH)]
numsPrime = [reduce(n) for n in nums]

f = lambda x : max(range(BASIS_LENGTH), key=lambda n: (x & (1 << n), n))

def insertVector(x):
    for i in range(BASIS_LENGTH -1, -1, -1):
        if x & (1 << i) == 0: continue
        if BASIS[i] == 0: BASIS[i] = x; return
        x ^= BASIS[i]
        
for x in numsPrime:
    insertVector(x)

def getSum():
    total = 0
    for el in reversed(BASIS):
        if el == 0: continue
        if el ^ total > total:
            total = el ^ total
    return total

print(2*expand(getSum()) + bad)


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

using namespace std;

typedef pair<int, int> P;
const int INF = 1e9;

int n, m, s, t;
vector<vector<int>> g;
int dist[101010][3];

int main() {
  cin >> n >> m;
  g.assign(n, vector<int>());
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].emplace_back(v);
  }
  cin >> s >> t;
  s--, t--;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      dist[i][j] = INF;
    }
  }
  queue<P> q;
  q.push(P(s, 0));
  dist[s][0] = 0;
  while (!q.empty()) {
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for (auto nv : g[v]) {
      int nl = (l + 1) % 3;
      if (dist[nv][nl] != INF) continue;
      dist[nv][nl] = dist[v][l] + 1;
      q.push(P(nv, nl));
    }
  }
  int ans = dist[t][0];
  if (ans == INF)
    ans = -1;
  else
    ans /= 3;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6912
n = int(input())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
if sum(alst) - sum(blst) < 0:
    print(-1)
    exit()


ans = 0
res = []
plus = 0
for a, b in zip(alst, blst):
    if a < b:
        ans += 1
        plus += b - a
    else:
        res.append(a - b)
res.sort(reverse = True)
pos = 0
while plus > 0:
    plus -= res[pos]
    ans += 1
    pos += 1
print(ans)

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

const int MOD = 1000000007;
const int MAX = 60;
char S[MAX];

int main() {
    int N;
    vector<int> a;
    scanf("%d", &N);
    scanf("%s", S);
    S[N] = '0';
    for (int i = 0; i < N; i++) {
        if (S[i] == S[i+1]) {
            a.push_back(2);
            i++;
        } else {
            a.push_back(1);
        }
    }
    long long ans;
    if (a[0] == 1) ans = 3;
    else ans = 6;
    for (int i = 1; i < N; i++) {
        if (a[i] == 1 && a[i-1] == 1) ans = ans * 2 % MOD;
        else if (a[i] == 2 && a[i-1] == 1) ans = ans * 2 % MOD;
        else if (a[i] == 2 && a[i-1] == 2) ans = ans * 3 % MOD; 
    }
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;
unsigned long long n;
char key[26]={'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'};
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n;
    string s;
    while(n){
        s+=key[n%26];
        if(n%26 == 0 ){
            n/=26;
            n--;
        }
        else n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<'\n';
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<string, int>> sp(n), nsp;
  for (int i = 0; i < n; i ++) {
    string s;
    int t;
    cin >> s >> t;
    t *= -1;
    sp[i] = make_pair(s, t);
  }

  nsp = sp;
  sort(nsp.begin(), nsp.end());
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < n; j ++) {
      if (sp[j] == nsp[i]) {
        cout << j + 1 << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,a[3][105],dp[3][105];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=1;i<=2;i++)for(ll j=1;j<=n;j++)cin>>x,dp[i][j] = x + max(dp[i-1][j] , dp[i][j-1]);
    cout<<dp[2][n];
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main ()
{
	int a, b, result, max;
	cin>>a>>b;
	for (int i=0; i<3; i++)
	{
		if (i==0)
		{
			result=a+b;
			max=result;	
		}
		else if (i==1) result=a-b;
		else result=a*b;
		if (max<result) max=result;
	}
	cout<<max;
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
ll _abs (ll x ) { return (x>0?x:-x); }
const int K = 105 ; 
int n , k , a[55]; 
ll ans , res , p , s ; 
int main(){
cin >> n >> k ; 
for(int i = 1 ; i <= n ; i++ ) cin >> a[i] ; 
for(int l = 0 ; l <= n && l <= k; l++ ){  
	for(int r = 0 ; r+l <= n && r + l <= k ; r ++ ) {
		int left = k - l - r ;  
		res =0 ; 
		vector<int> v; 
		for(int i = 0 ; i <= l ; i++ )v.pb(a[i]) ; 
		for(int j = 0 ; j <= r ; j++ )v.pb(a[n-j+1]) ;
		sort(all(v)) ; 
		auto it = v.begin() ; 

		for(int w : v )
			res += w ; 
		while( left && *it < 0 ){
			res -= *it , it ++ , left -- ;  
		}

		ans = max (ans , res ) ;

	}
}
cout<<ans<<endl; 
}


Measured memory_bytes: 256
n,m=gets.split(' ').map(&:to_i)
a=m.times.map{gets.to_i}
dp=Array.new(n+1).fill(0)
a.each{|i|dp[i]=-1}
dp[0]=1
dp[1]=1 if dp[1]!=-1
mod=1000000007
2.upto(n) do |i|
  next if dp[i]==-1
  dp[i]=(dp[i]+dp[i-2])%mod if dp[i-2]!=-1
  dp[i]=(dp[i]+dp[i-1])%mod if dp[i-1]!=-1
end
puts dp[n]

Measured memory_bytes: 3764
N, M = map(int,input().split())
L = sorted(list(map(int,input().split())))
distance = []
for i in range(len(L)-1):
    distance.append(abs(L[i]-L[i+1]))
distance = sorted(distance)
for _ in range(N-1):
    if len(distance) > 0:
        del distance[-1]
    else:
        print(0)
        quit()
print(sum(distance))


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


// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3") 
// #pragma GCC optimization ("unroll-loops")
 
#define ll  long long int
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
#define MD          1000000007
#define M           100011

long long  md=MD;
ll dp[M][2];
vector<int> v;
ll f(ll n,ll m){
	if(n<0)return 1;
	if(dp[n][m]!=-1)return dp[n][m];
	ll ans=0;
	for(int a=0;a<=1;++a){
		for(int b=0;b<=1;++b){
			if(a+b<=1&&(m==0||(m&&((a+b)<=v[n])))){
				if(m==0){
					ans=ans+f(n-1,m);

				}
				else{
					ans=ans+f(n-1,(a+b==v[n]));
				}
				if(ans>md)ans-=md;
			}
		}
	}
	dp[n][m]=ans;
	return ans;



}

int solve(){
	int n,i,j,k,m;
	string s;
	cin>>s;
	for(char x:s)v.pb(x-'0');
		reverse(all(v));
	memset(dp,-1,sizeof(dp));
	ll p=f(v.size()-1,1);
	cout<<p<<"\n";

}


int main(){

 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;

    t=1;
    // cin>>t;

    while(t--){
    	solve();
    }



    

}



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

using namespace std;

void solve()
{
    int k, t;
    cin >> k >> t;
    vector<int> as(k);
    for (int i = 0; i < k; i++)
    {
        cin >> as[i];
    }
    cout << max(*max_element(as.begin(), as.end()) * 2 - k - 1, 0) << endl;
}

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


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

int loop(int n, int y){
    for (int yukichi=0; yukichi <= n; yukichi++){
        for (int noguchi=0; noguchi <= n-yukichi; noguchi++){
            int natsume = n - noguchi - yukichi;
            if (yukichi*10000+noguchi*5000+natsume*1000==y){
                cout << yukichi << " " <<noguchi << " " << natsume << endl;
                return 0;
            }
        }
    }
    return 1;
}

int main() {
    int n, y;
    cin >> n >> y;
    int done = loop(n, y);
    if (done){
        cout << "-1 -1 -1" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
X = int(input())
plus = [i**5 for i in range(1000)]

for num in plus:
  if abs(X - num) in plus:
    break
    
if (X - num) in plus:
  print(plus.index(num), -1*plus.index(X-num))
else:
  print(plus.index(num), plus.index(num-X))

Measured memory_bytes: 9200
use std::io;
use std::cmp;
use std::collections::HashMap;


fn main() {
    let (n, k) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let an = read::<usize>();
    let mut s = vec![0; n + 1];
    s[1] = an[0];
    for i in 2..n + 1 {
        s[i] = s[i - 1] + an[i - 1];
    }

    let mut si = Vec::new();
    for i in 0..n + 1 {
        si.push((s[i] - i) % k);
    }

    let mut cnt = HashMap::new();
    for i in 0..cmp::min(n + 1, k - 1) {
        *cnt.entry(si[i]).or_insert(0) += 1;
    }

    let mut ans: usize = 0;
    for i in 0..n + 1 {
        *cnt.entry(si[i]).or_insert(0) -= 1;
        if i + k <= n + 1 {
            *cnt.entry(si[i + k - 1]).or_insert(0) += 1;
        }
        ans += cmp::max(*cnt.get(&si[i]).unwrap_or(&0), 0);
    }

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 22544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    int N, T;
    cin >> N >> T;
    
    ll p;
    cin >> p;
    int s = p, t = p + T;
    ll ans = 0;
    rep(i, N - 1) {
        cin >> p;
        if (p <= t) {
            chmax(t, p + T);
        } else {
            ans += t - s;
            s = p;
            t = p + T;
        }
    }
    ans += t - s;
    cout << ans << endl;
}


Measured memory_bytes: 256
// abc158_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, a, b, res, ans;
  cin >> n >> a >> b;
  ans = n / (a + b) * a;
  res = n % (a + b);
  ans += min(res, a);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
int N,X;
int m[1005];
int ans;

int main(){
    cin >> N >> X;
    rep(i,N) cin >> m[i];
    sort(m,m+N);
    ans = accumulate(m,m+N,0);
    cout << N + (X-ans)/m[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

template<typename T> class edge{
    public:
        int from, to;
        T cost;

        edge(){}
        edge(int t, T c){
            this->to = t;
            this->cost = c;
        }
        edge(int f, int t, T c){
            this->from = f;
            this->to = t;
            this->cost = c;
        }
};

template<typename T> class Graph_list{
    public:
        vector<vector<edge<T>>> list;
        vector<edge<T>> edges;

        Graph_list(int n);
        void add(int f, int t, T c);
        void add(int f, int t);
        int size(){ return (int)list.size();}
        vector<edge<T>> operator[](int i){ return list[i];}
        bool negative();
};

template<typename T> Graph_list<T>::Graph_list(int n){
    list = vector<vector<edge<T>>>(n + 1, vector<edge<T>>());
    edges.clear();
}

template<typename T> void Graph_list<T>::add(int f, int t, T c){
    list[f].push_back(edge<T>(t, c));
    edges.push_back(edge<T>(f, t, c));
}
template<typename T> void Graph_list<T>::add(int f, int t){
    list[f].push_back(edge<T>(t, 1));
    edges.push_back(edge<T>(f, t, 1));
}
template<typename T> bool Graph_list<T>::negative(){
    int V = this->size();
    vector<T> dist(V, 0);
    REP(i,0,V){
        for (auto e : this->edges){
            if (dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if (i == V - 1) return true;
            }
        }
    }
    return false;
}

template<typename T>
vector<T> BellmanFord(Graph_list<T>& g, int s){
    const auto INF = numeric_limits<T>::max();
    int V = g.size();
    vector<T> dist(V, INF);
    dist[s] = 0;
    REP(i,0,V - 1){
        for (auto e : g.edges){
            if (dist[e.from] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
        }
    }

    return dist;
}


int main(){
    int n, m;
    cin >> n >> m;
    Graph_list<ll> g(n);
    REP(i,0,m){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        g.add(a, b, -c);
    }

    vector<ll> dist = BellmanFord(g, 1);
    ll ans = dist[n];

    for (auto e : g.edges){
        if (dist[e.from] == numeric_limits<ll>::max()) continue;
        dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
    }
    
    if (dist[n] < ans) cout << "inf" << endl;
    else cout << -ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
N   = int(input())
*A, = map(int, input().split())

rate = {}
for i in range(9):
    rate[i] = 0

for i in range(N):
    a = A[i]
    if 1<=a and a<=399:
        rate[0] += 1
        continue
    if 400<=a and a<=799:
        rate[1] += 1
        continue
    if 800<=a and a<=1199:
        rate[2] += 1
        continue
    if 1200<=a and a<=1599:
        rate[3] += 1
        continue
    if 1600<=a and a<=1999:
        rate[4] += 1
        continue
    if 2000<=a and a<=2399:
        rate[5] += 1
        continue
    if 2400<=a and a<=2799:
        rate[6] += 1
        continue
    if 2800<=a and a<=3199:
        rate[7] += 1
        continue
    if 3200<=a:
        rate[8] += 1
        continue

ans_min = 0
ans_max = 0
count_zero = 0
count_3200over = rate[8]

for i in range(8):
    if rate[i]>=1:
        ans_min = ans_min + 1
    else:
        count_zero = count_zero + 1
ans_max = ans_min

if count_zero==8:
    print(1, max(count_3200over, 1))
    exit()

print(ans_min, ans_max+count_3200over)


Measured memory_bytes: 3064
#include <stdlib.h>
#include <stdio.h>

int main(){
	int a, b;
	int x, y;	

	while(1){
		scanf("%d %d", &a, &b);
		if((a == 0) && (b == 0)){
			break;
		}
		else{
			for(y=0;y<a; y++){
				for(x=0;x<b;x++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}

	}
	
	return 0;

}


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

int main() {
   
    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
        
    }
    sort(a,a+3);
    cout<<a[0]+a[1];
    
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
 
int main(void){
 int flag = 1;
int i,j,N,v,a[10000]; 
int c =0;
 
    scanf("%d", &N);
     for ( i = 0; i < N; i++ ){ 
scanf("%d", &a[i]);
}
  
 while ( flag ) {
        flag = 0;
        for ( j = N - 1; j >0; j-- ) {
            if ( a[j] < a[j - 1] ) {
                v = a[j];
                a[j] = a[j - 1];
                a[j - 1] = v;
                 
                flag = 1;
c++;
            }
        }
    }
 
    
    for ( i = 0; i < N; i++ ) {
if(i>0){
printf(" ");
}
 
        printf("%d", a[i]);
}
printf("\n");
   
     
 
    printf("%d\n",c);
 
    return 0;
}

Measured memory_bytes: 1804
var
  a,b,c,kkk:int64;
begin
  readln(a,b,c);
  if b>=a then begin writeln(1);exit;end;
  if c>=b then begin writeln(-1);exit;end;
  if (a-b) mod (b-c)>=1 then kkk:=1;
  writeln(((a-b) div (b-c)+kkk)*2+1);
end.

Measured memory_bytes: 128
#include<cstdio>
using namespace std;
int main()
{
    int k,a,b;
    int flag=0;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    for(int t=a;t<=b;t++)
    {
        if(t%k==0)
        {
            printf("OK");
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        printf("NG");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1724
import numpy as np
n = int(input())
a = [0] * n
b = [0] * n
c = [0] * n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
dp = np.zeros((3, n+1), dtype=np.int)
for i in range(1, n+1):
    dp[0, i] = max(dp[1,i-1]+b[i-1], dp[2,i-1]+c[i-1])
    dp[1, i] = max(dp[0,i-1]+a[i-1], dp[2,i-1]+c[i-1])
    dp[2, i] = max(dp[0,i-1]+a[i-1], dp[1,i-1]+b[i-1])
print(max(dp[:, n]))

Measured memory_bytes: 40568
#include<bits/stdc++.h>
using namespace std;
const int N=5005,p=1000000007;
struct A{
	int a;
	A(){a=0;}
	A(int b){a=b;}
	void operator+=(A b){a+=b.a;if(p<=a)a-=p;}
	void operator-=(A b){a-=b.a;if(a<0)a+=p;}
	A operator*(int b){return (long long)a*b%p;}
	A operator*(A b){return (long long)a*b.a%p;}
};
int n,sz[N];
vector<int>e[N];
A f[N][N],a[N],g[N];
void dfs(int v,int fa){
	f[v][1]=A(1);
	int size=1;
	for(int it=0;it<(int)e[v].size();it++){
		int u=e[v][it];
		if(u!=fa){
			dfs(u,v);
			for(int i=1;i<=size;i++)g[i]=f[v][i],f[v][i]=A(0);
			for(int i=1;i<=size;i++)for(int j=1;j<=sz[u];j++){
				f[v][i+j]+=g[i]*f[u][j];
				f[v][i]-=g[i]*f[u][j]*a[j];
			}
			size+=sz[u];
		}
	}
	sz[v]=size;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	a[0]=A(1);
	for(int i=2;i<=n;i+=2)a[i]=a[i-2]*(i-1);
	dfs(1,0);
	A ans=0;
	for(int i=2;i<=n;i+=2)ans+=f[1][i]*a[i];
	printf("%d",ans.a);
	return 0;
}

Measured memory_bytes: 98944
#include <iostream>
#include <vector>
#include <string>
#include <math.h>

using namespace std;


vector<long> ans;



int main()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	long answer;
	long cnt = 0;


	for (long i = 0; i < s.length() - 1; i++) {
		if (s.substr(i, 1) == "A") {
			if (s.substr(i + 1, 1) == "C") {
				cnt++;
			}
		}
		ans.push_back(cnt);
	}
	ans.push_back(cnt);
	ans.push_back(cnt);

	for (long i = 0; i < q; i++) {
		long x, y;
		cin >> x >> y;
		x--; y--;
		if(x==0) cout << ans[y - 1] << endl;
		else cout << ans[y - 1] - ans[x - 1] << endl;
	}

	return 0;
}

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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)
#define EREP(t,i,a,b) for(t i = a; i <= b; ++i)
#define REPR(t,i,a,b) for(t i = a; i > b; --i)
#define EREPR(t,i,a,b) for(t i = a; i >= b; --i)

typedef long long ll;

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;

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

    int n, k, q;
    cin >> n >> k >> q;
    vector<int> c(n+1,0);

    REP(int, i, 0, q) {
        int a;
        cin >> a;
        c[a] += 1;
    }

    EREP(int, i, 1, n) {
        int score = k + c[i] - q;
        if (score > 0) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}


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

int main(){
    long long a,b,c,newa=1;
    cin >> a >> b >> c;
    if(a==1){cout << "YES"; return 0;}
    for(int i = 1;i<20000;i++){
		newa=a*i;
		if(newa%b==c) {cout << "YES"; return 0;}
	}
	cout << "NO";
}


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

using namespace std;

int main(){
    long long H, N;
    while(cin >> H >> N){
        vector<long long> A(N);
        for(auto& t : A) cin >> t;
        cout << (H <= accumulate(A.begin(), A.end(), 0LL) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1024
n = int(input())
p = [int(input()) for i in range(n)]
pos = [-1 for i in range(n + 1)]
best = [1 for i in range(n)]
for i in range(n):
    pos[p[i]] = i
for i in range(n):
    if p[i] == 1:
        continue
    j = pos[p[i] - 1]
    if j < i:
        best[i] = best[j] + 1
print(n - max(best))


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

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

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
	ll K;
	scanf("%lld", &K);
	printf("50\n");
	rep(i, 50) {
		if(i != 0) printf(" ");
		printf("%lld", 49 - i + (K + 49 - i) / 50);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))

b = []
c = 0
b.append(0)
for i in range(n):
    c += a[i]
    c = c % m
    b.append(c)

b.sort()

count = 0
i = 0
j = 1
d = []

while j < n+1:
    if b[i] == b[j]:
        count += 1
        j += 1
    else:
        d.append(count+1)
        count = 0
        i = j
        j += 1
if count > 0:
    d.append(count+1)

ans = 0
for i in d:
    if i > 1:
        ans += i * (i-1) // 2

print(ans)


Measured memory_bytes: 14568
#include <iostream>

int main () {
    using namespace std;
    long int a,b,k;
    cin >> a >> b >> k;
    if (a >= k) cout << a-k << " " << b;
    else if (a+b < k) cout << "0 0";
    else cout << 0 << " " << b - (k - a);
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=1e6+69;
const int INF = 1e10;
const int mod = 1e9+7;
struct vl{
    int x,y;
    bool operator<(vl t)const{
        if(x==t.x)return y<t.y;
        return x<t.x;
    }
};
int luythua(int x, int y){
    if(y==0)return 1;
    if(y==1)return x%mod;
    int k = luythua(x,y/2);
    if(y%2==0)return k*k%mod;
    return k*k%mod*x%mod;
}
int m,n,q,k,l,x,y,z;
int a[MAXN];
int dp[MAXN];
string s,t,r;
signed main(){                                                                                                                                                                                                                                                                                                  ios_base::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);
    cin>>s>>t;
    cin>>m>>n;
    cin>>r;
    if(r==s)m--;
    if(r==t)n--;
    cout<<m<<' '<<n;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int dp[66666][17][17],n,m,mp[17][17],xx,yy,zz,k,sum;
int main()
{
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		cin>>xx>>yy>>zz;
		xx--;yy--;
		mp[xx][yy]=zz;
		mp[yy][xx]=zz;
	}
	for (int i=0;i<(1<<n);i++)
	{
		for (int j=0;j<n;j++)
		{
			for (int k=0;k<n;k++)
			dp[i][j][k]=1e9;
		}
		for (int j=0;j<n;j++) dp[i][j][j]=0;
	}
	for (int i=1;i<(1<<n);i++)
	{
		for (int j=i;j;j=(j-1)&i)
		{
			if (!(j&1)) continue;
			k=i^j;
			sum=0;
			for (int x=0;x<n;x++)
			{
				if (j&(1<<x)) 
				{
					for (int y=0;y<n;y++)
					{
						if (k&(1<<y)) sum+=mp[x][y]; 
					}
				}
			}
			int x=0;
			for (int y=0;y<n;y++)
			{
				if (k&(1<<y))
				{
					for (int z=0;z<n;z++)
					{
						if (j&(1<<z) && mp[y][z]) 
						{
							dp[i][x][y]=min(dp[i][x][y],dp[j][x][z]+sum-mp[y][z]);
						}
					}
				}
			}
		}
	}
	cout<<dp[(1<<n)-1][0][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 39168
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int sunuke[n]={0};
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int a;
            cin>>a;
            sunuke[a-1]=1;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
        if(sunuke[i]==0)
            ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void) {
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll h,n;
    cin>>h>>n;
    ll temp;

    ll sum =0;
    for(ll i=0;i<n;i++){
        cin>>temp;
        sum+=temp;
        if(sum>=h){
            cout<<"Yes";
            return 0;
        }
    }

    cout<<"No";

    return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
  if a==b:
    return a 
  elif a<b:
    a,b=b,a
    while a%b!=0:
      a,b=b,a%b
    return b
  else:
    while a%b!=0:
      a,b=b,a%b
    return b
 

N=int(input())
A=list(map(int,input().split()))

data_ans=[]
data1=[A[0]]
data2=[A[N-1]]
l=A[0]
m=A[N-1]
for i in range(1,N-2):
  l=gcd(l,A[i])
  m=gcd(m,A[N-i-1])
  data1.append(l)
  data2.append(m)
l=gcd(l,A[N-2])
m=gcd(m,A[1])
data_ans.append(l)
data_ans.append(m)
for i in range(0,N-2):
  data_ans.append(gcd(data1[i],data2[N-3-i]))
print(max(data_ans))


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

int main()
{
    int a, b, k, j=0, res[1001];
    cin>>a>>b>>k;
    for(int i=1; i<=min(a, b); i++)
    {
        if(a%i==0 && b%i==0)
        {
            j++;
            res[j]=i;
        }
    }
    cout<<res[j-k+1]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 60;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, p;
  cin >> n >> p;
  ll ec = 0, oc = 0;
  rep(i, n) {
    ll x;
    cin >> x;
    if (x % 2 == 0)
      ec++;
    else
      oc++;
  }

  ll ans = 1LL << ec;
  if (oc > 0) ans <<= (oc - 1);
  if (p == 1 && oc == 0) ans = 0;

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
N,K=map(int, sys.stdin.readline().split())
A=[None]+map(int, sys.stdin.readline().split())
visit=[ 0 for _ in range(N+1) ]

L=[]    #閉路になった町番号を順番に記録する

def func(fro):
    global K
    to=A[fro]
    visit[fro]+=1
    if visit[fro]==2:
        L.append(fro)
    if visit[to]<=1:    #閉路ループは2回まで許可する
        K-=1        #操作回数を減らす
        if K==0:    #Kが途中でゼロになれば、その時に移動しようとしていたtoが答え
            print to
            quit()
        func(to)

func(1)
K-=1
l=len(L)
print L[K%l]


Measured memory_bytes: 307524
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

using namespace atcoder;

int main(){
    int n,m;
    cin >> n >> m;
    vector<string> grid(n);
    rep(i,n){
        cin >> grid[i];
    }
    int S=n*m,T=n*m+1;
    mf_graph<int> mf(n*m+2);
    rep(i,n){
        rep(j,m){
            if(i && grid[i][j]=='.' && grid[i-1][j]=='.'){
                if((i+j)%2){
                    mf.add_edge(i*m+j,(i-1)*m+j,1);
                }
                else{
                    mf.add_edge((i-1)*m+j,i*m+j,1);
                }
            }
            if(j && grid[i][j]=='.' && grid[i][j-1]=='.'){
                if((i+j)%2){
                    mf.add_edge(i*m+j,i*m+j-1,1);
                }
                else{
                    mf.add_edge(i*m+j-1,i*m+j,1);
                }
            }
            if((i+j)%2){
                mf.add_edge(S,i*m+j,1);
            }
            else{
                mf.add_edge(i*m+j,T,1);
            }
        }
    }
    int mx=mf.flow(S,T);
    for(auto e:mf.edges()){
        if(e.from!=S && e.to!=T && e.flow==1){
            int fi=e.from/m,fj=e.from%m;
            int ti=e.to/m,tj=e.to%m;
            if(fi==ti){
                grid[fi][min(fj,tj)]='>';
                grid[fi][max(fj,tj)]='<';
            }
            else{
                grid[min(fi,ti)][fj]='v';
                grid[max(fi,ti)][fj]='^';
            }
        }
    }
    cout << mx << endl;
    rep(i,n){
        rep(j,m){
            cout << grid[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 5580
N, K, Q = gets.chomp.split().map(&:to_i)
    points = Array.new(N, K - Q)
     
    Q.times do
        winner = gets.chomp.to_i - 1
        points[winner] += 1
    end
    points.each do |point|
        if point > 0
            puts "Yes"
        else
            puts "No"
        end
    end

Measured memory_bytes: 3196
loop do
    a, op, b = gets.chomp.split
    a = a.to_i
    b = b.to_i
        case op
        when "?"
            break
        when "+"
            puts "#{a + b}"
        when "-"
            puts "#{a - b}"
        when "*"
            puts "#{a * b}"
        when "/"
            puts "#{a / b}"
        end
end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define int long long


class APair {
public:
    void solve(std::istream &in, std::ostream &out) {
      int k;
      in >> k;
      int a = k / 2;//偶数
      int b = k - a;//奇数
      out << a * b << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  APair solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

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

    char che[3] = {'A', 'B', 'C'};
    int ans = 0;
    int flag = 0;

    for(int i = 0; i < n - 2; i++){
        flag = 0;
        for(int j = 0; j < 3; j++){
            if(s[i + j] != che[j]){
                flag = 1;
                break;
            }
        }
        if(flag == 0){
            ans++;
        }
    }

    cout << ans << endl;
}

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





int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！
    int N;
    string s;
    cin>>N>>s;
    int count=0;
    int min=N;
    int i,j;
    //リーダーはどちらの方向を向いていても構いません。


    //0番目の範囲を求める
    for(i=1;i<N;++i){
    	if(s[i]=='E'){
    		count++;
    	}
    }

    min = count;
    //cout << count<<endl;
    for(i=1;i<N;++i){
    	if(s[i]=='E'&&i<N){//左側
    			count--;
    		}
    	if(s[i-1]=='W'){//左側
    			count++;
    		}

    	if(count<min){
    		min=count;
    	}
    	//cout << count << endl;

    }

    // for(i=0;i<N;i++){//i番目がリーだー
    // 	for(j=0;j<i;++j){//左側Eにならなきゃ
    // 		if(s[j]=='W'){
    // 			count++;
    // 		}
    // 	}
    // 	for(j=i+1;j<N;j++){//右側
    // 		if(s[j]=='E'){
    // 			count++;
    // 		}	
    // 	}

    // 	if(count<min){
    // 		min=count;
    // 	}

    // 	count=0;


    // }

    cout<<min << endl;
    return 0;
}


//X と Y のどちらにも含まれている文字

Measured memory_bytes: 900
#include <iostream>
using namespace std;
bool chk(int n){
  return (n % 4 == 0) - (n%100 == 0) + (n%400 ==0);
}

int main(void){
  int a,b,res = 0;
  bool first = false;
  while(cin>>a>>b,a+b){
    bool used = false;
    if(first)cout<<endl;
    first = true;

    for(int i = a ; i <= b ; i ++)
      if(chk(i)){
	cout<<i<<endl;
	used = true;
      }
    if(!used)cout<<"NA"<<endl;
  }
}

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

int main(){
    int s;
    cin >> s; //sは初項
    set<int>st;
    while(st.count(s) == 0){
        st.insert(s);
        if(s % 2 == 0){
            s /= 2;
        }
        else{
            s = (s * 3) + 1;
        }
    }
    cout << st.size() + 1 << endl;
}

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

using ll = long long;

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

    int n,h;cin>>n>>h;

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

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    int l=-1,r=n;
    for(int m=l+(r-l)/2;m!=l;m=l+(r-l)/2)
    {
        if(a[n-1]<b[m])r=m;
        else l=m;
    }

    int ans=0;
    for(int i=n-1;i>l&&h>0;i--,ans++)h-=b[i];

    if(h>0)ans+=(h-1)/a[n-1]+1;

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	int cnt = 0;
	FOR(i, n) {
		int x;
		cin >> x;
		if (x & 1) cnt++;
	}
	cout << (cnt & 1 ? "NO" : "YES") << endl;
	return 0;
}

Measured memory_bytes: 384
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t={}
p={}
d={}
for _ in[0]*int(input()):
 e=input().split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):i=str(i);print('node',i+':','parent =',p[i]+',','depth =',d[i]+',','root,'if'-1'==p[i]else'internal node,'if t[i]else'leaf,',list(map(int,t[i])))


Measured memory_bytes: 55844
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N;
	cin >> N;
	vector<string>ans(N);

	REP(i, N) {
		vector<int>vec(3);
		REP(j, 3) cin >> vec[j];
		SORT(vec);

		int a = vec[0] * vec[0];
		int b = vec[1] * vec[1];
		int c = vec[2] * vec[2];

		if (a + b == c) ans[i] = "YES";
		else ans[i] = "NO";
	}

	REP(i, N) cout << ans[i] << "\n";
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
int num[1000010];int dif[1000010];
int a[1000010];int b[1000010];

int main(){
	int n;read(n);
	rep(i,1,n){char ch;cin>>ch;num[i]=ch-'0';}
	rep(i,1,n-1)dif[i]=abs(num[i+1]-num[i]);
	rep(i,1,1000000)b[i]=((i%2==1)?0:(b[i/2]+1));
	
	if(n==1){write(num[n]);}
	else{
		rep(i,1,n)a[i]=num[i]%2;
		int ret=0;int ans=0;
		rep(i,1,n){ans+=(!ret)*a[i];ans%=2;ret+=b[n-i]-b[i];}
		if(ans%2==1){write(1);return 0;}
		
		int tmp=0;
		rep(i,1,n-1)tmp+=(dif[i]==1);
		if(tmp){write(0);return 0;}
		
		rep(i,1,n-1)a[i]=dif[i]/2;
		ret=0;ans=0;
		rep(i,1,n-1){ans+=(!ret)*a[i];ans%=2;ret+=b[n-1-i]-b[i];}
		write(2*(ans%2));
	}
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	long long n, a[5001], rui[5002] = { 0 }, ans[5002], cnt = 0;
	while (1) {
		cnt++;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			rui[i+1] = rui[i] + a[i];
		}
		int max;
		max = -100001;
		for (int i = 0; i <= n; ++i) {
			for (int j = i+1; j <= n; ++j) {
				if (rui[j] - rui[i] > max) {
					max = rui[j] - rui[i];
				}
			}
		}
		ans[cnt] = max;
	}
	for (int i = 1; i < cnt; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	while (1) {
		int x, y, s; cin >> x >> y >> s;
		if (!x)break;
		int ans=0;
		for (int i = 1; i<= s - 1; ++i) {
			int a = int(double(i)*(1. + double(x) / 100.)+1e-4);
			for (int j = i; j <= s - 1; ++j) {
				int b = int(double(j)*(1. + double(x) / 100.) + 1e-4);
				if (a + b == s) {
					ans = max(ans, int(double(i)*(1. + double(y) / 100.) + 1e-4)+ int(double(j)*(1. + double(y) / 100.) + 1e-4));
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2988
#include <cstdio>
#include <algorithm>

const int MN = 100005;

int N, A[MN];
int que[MN], l, r;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	std::sort(A + 1, A + N + 1);
	l = 1, r = 0;
	int lstc = 0;
	for (int i = 2; i <= N; ++i) {
		if (A[i] == A[i - 1]) lstc ^= 1;
		else {
			int c = ~(A[i] - A[i - 1]) & 1;
			if (c != lstc) que[++r] = A[i - 1] - lstc + i;
			lstc = 0;
		}
		while (l <= r && que[l] <= i) ++l;
	}
	puts(lstc ^ (A[N] & 1) ^ ((r - l) & 1) ? "First" : "Second");
	return 0;
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> aa(n);
	int x=0;
	for(int i=0;i<n;++i) {
		int a; cin >> a;
		x^=a;
		aa[i]=a^(a-1);
	}
	sort(aa.begin(),aa.end(),greater<>());
	int cnt=0,t=0;
	for(int i=(1<<30);i>1;i>>=1) {
		if(!((i>>1)&x)) continue;
		while(t<n&&(i-1)!=aa[t]) ++t;
		if(t==n) break;
		x^=aa[t];
		++cnt;
	}
	cout << (x?-1:cnt) << endl;
	
	return 0;
}


Measured memory_bytes: 640
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    # 同じ数字を取った場合を考慮してleftでなくright
    b_idx = bisect.bisect_right(sum_b_list,time_rest) - 1
    
    ans = max(ans, a_idx + b_idx)
        
print(ans)

Measured memory_bytes: 49252
#include <iostream>
#include <string>
#include <cstdlib>
#include <stack>
using namespace std;

int main()
{
    stack<int> st;
    string s;
    while(cin >> s){
        if(s == "+" || s == "-" || s == "*"){
            int x = st.top(); st.pop();
            int y = st.top(); st.pop();
            
            switch(s[0]){
                case '+':
                    st.push(y + x);
                    break;
                case '-':
                    st.push(y - x);
                    break;
                case '*':
                    st.push(y * x);
                    break;
            }
        }
        else {
            st.push(atoi(s.c_str()));
        }
    }
    cout << st.top() << endl;
}

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

int main(){
  int n;
  cin>>n;
  cout<<n*n*n;

}

Measured memory_bytes: 3556
def findSumDigit(num):
    global total
    total = ""
    while num > 0:
        total += str(num % 10)
        num //= 10
    return total

def main():
    a,b = map(int, input().split())
    ans = 0
    for i in range(a,b+1):
        tmp = str(findSumDigit(i))
        if tmp == str(i):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
ll max(ll a,ll b){
	if(a>b) return a;
	else return b;
}
ll min(ll a,ll b){
	if(a<=b) return a;
	else return b;
}
int n,a,b,c,d;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> algo(n,vector<int>(m+1));
    for(int i=0; i<n;  i++){
    	for(int j=0; j<=m; j++) cin>>algo[i][j];
	}
	int ans =1e9;
	for(int i=0; i<1<<n; i++){
		vector<int> tmp(m,0);
		int tans=0;
		for(int j=0; j<n; j++){
          int t2=pow(2,j);
			if(i&t2){
				for(int k=1; k<=m; k++){
					tmp[k-1]+=algo[j][k];
				}
				tans+=algo[j][0];
			}
		}
		int cond=1;
		for(int j=0; j<m; j++){
			if(tmp[j]<x){
				cond=0;
				break;
			}
		}
		if(cond) ans=min(ans,tans);
	}
  if(ans!=1e9)
	cout<<ans;
  else cout<<-1;
	return 0;
}

Measured memory_bytes: 4068
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
ll f;
string s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    f=0;
    for(int i=0;i<s.size();i++) if(s[i]=='7') f=1;
    if(f==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3608