akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

int main(){

    ll h, w, k; cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    rep(i, h){
        rep(j, w){
            cin >> c[i][j];
        }
    }

    ll cnt, ans = 0;
    vector<vector<char>> c_cp(h, vector<char>(w));
    rep(i, 1<<h){
        rep(j, 1<<w){
            bitset<6> bs_h(i);
            bitset<6> bs_w(j);
            rep(ii, h){
                rep(jj, w){
                    c_cp[ii][jj] = c[ii][jj];
                }
            }

            rep(ii, h){
                if(bs_h.test(ii)){
                    rep(jj, w){
                        c_cp[ii][jj] = '.';
                    }
                }
            }
            rep(jj, w){
                if(bs_w.test(jj)){
                    rep(ii, h){
                        c_cp[ii][jj] = '.';
                    }
                }
            }

            cnt = 0;
            rep(ii, h){
                rep(jj, w){
                    if(c_cp[ii][jj] == '#') cnt++;
                }
            }
            if(cnt==k) ans++;
        }
    }

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

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

int main(){

    int N;
    cin >> N;

    vector<long long> a(N);
    int count = 0;
    long long sum = 0;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] < 0){
            count++;
            a[i] = -a[i];
        }
        sum += a[i];
    }

    if(count % 2 == 0){
        cout << sum << endl;
    }else{
        int min_v = *min_element(a.begin(), a.end());
        cout << sum - min_v*2 << endl;
    }

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

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

const int SZ=50000;
bool isPrime[SZ];
vector<int> primes;

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

    for(int i=2;i<SZ;i++) isPrime[i]=true;
    for(int i=2;i<SZ;i++){
        if(!isPrime[i]) continue;
        for(int j=i*2;j<SZ;j+=i) isPrime[j]=false;
    }
    REP(i,SZ) if(isPrime[i]) primes.push_back(i);

    int m,a,b;
    while(cin>>m>>a>>b,m)
    {   
        int maxp=0,s,t;
        REP(i,primes.size()){
            for(int j=i;j<primes.size();j++){
                int p=primes[i],q=primes[j];
                if(p*q>m || a*q>b*p) break;
                if(p*q>maxp){ 
                    maxp=p*q; s=p,t=q;
                }
            }
        }
        cout<<s<<" "<<t<<endl;
    }
}


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

using namespace std;
using ll = long long;

int main() {
	int k;
	scanf("%d", &k);
	vector<int> vis(k);

	int ans = 1;
	int val = 7 % k;
	while(val != 0 and !vis[val]) {
		vis[val] = 1;
		val = (val * 10 + 7) % k;
		ans++;
	}

	if(val == 0) printf("%d\n", ans);
	else printf("-1\n");
}


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

int main() {
	int n;
	cin >> n;
	vector<char> str(n);
	for(int i=0; i<n; i++){
		cin >> str.at(i);
	}
	int ans = 0; 
	for(int i=0; i<n-2; i++){
		if(str.at(i) == 'A' && str.at(i+1) == 'B' && str.at(i+2) == 'C'){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *      ABC 64 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-06 20:18:40
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[N] = {};
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int distribution[8] = {};
    int target = 0;

    for (int i = 0; i < N; ++i) {
        if (1 <= a[i] && a[i] <= 399){
            distribution[0] = 1;
        }
        else if (400 <= a[i] && a[i] <= 799){
            distribution[1] = 1;
        }
        else if (800 <= a[i] && a[i] <= 1199){
            distribution[2] = 1;
        }
        else if (1200 <= a[i] && a[i] <= 1599){
            distribution[3] = 1;
        }
        else if (1600 <= a[i] && a[i] <= 1999){
            distribution[4] = 1;
        }
        else if (2000 <= a[i] && a[i] <= 2399){
            distribution[5] = 1;
        }
        else if (2400 <= a[i] && a[i] <= 2799){
            distribution[6] = 1;
        }
        else if (2800 <= a[i] && a[i] <= 3199){
            distribution[7] = 1;
        }
        else {
            ++target;
        }
    }
    int minimum, maximum;
    int sum = 0;
    for (int i = 0; i < 8; ++i) {
        sum += distribution[i];
    }
    minimum = max(sum, 1);
    maximum = sum + target;
    cout << minimum << " " << maximum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    vector<pair<int, int>> ind(h * w);
    for(size_t i = 0; i < h; i++) {
        for(size_t j = 0; j < w; j++) {
            int a;
            cin >> a;
            a--;
            ind[a] = make_pair(i, j);
        }
    }
    vector<vector<int>> mp(d, vector<int>(1, 0));
    for(int i = 0; i < d; i++) {
        int x = i;
        while(x + d < h * w) {
            mp[i].push_back(mp[i].back() +
                            abs(ind[x + d].first - ind[x].first) +
                            abs(ind[x + d].second - ind[x].second));
            x += d;
            // cout << i << ":" << x << ":" << mp[i].back() << endl;
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        // cout << mp[l % d].size() << endl;
        cout << mp[l % d][r / d] - mp[l % d][l / d] << endl;
    }
}


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

double pi = 3.141592653589793238;

int main(){
    int r;
    cin >> r;
    double ans = 2*r*pi;
    cout << fixed << setprecision(10) << ans << endl;
}


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

// INT VS LL

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

    vector<int> cnt(10);
    for (int i = 0; i < 3; ++i) {
    	int foo;
    	cin >> foo;
    	cnt[foo]++;
    }
    if (cnt[5] == 2 && cnt[7] == 1) {
    	cout << "YES";
    }
    else {
    	cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int a,b,c;cin>>a>>b>>c;
  int k;cin>>k;
  int res=0;
  if(a>=k)res=k;
  else if(a+b>=k){
    res=a;
  }
  else{
    res=a-(k-(a+b));
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
int main(){
  int s1, s2, s3, s4, x, y;
  scanf("%d %d %d %d",&s1, &s2, &s3, &s4);
  x=(s1+s2+s3+s4)/60;
  y=(s1+s2+s3+s4)%60;
  printf("%d\n",x);
  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 592
n = int(input())
s, t = [], []
for i in range(n):
  a, b = list(map(int, input().split()))
  s.append((a, b))
for i in range(n):
  c, d = list(map(int, input().split()))
  t.append((c, d))
s.sort(key=lambda x:x[1])
t.sort()

ans = 0
for i in range(n):
  for j in range(n-1, -1, -1):
    if s[j]==None:
      continue
    if s[j][0]<t[i][0] and s[j][1]<t[i][1]:
      ans+=1
      s[j] = None
      break
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
    long N, M;
    cin >> N >> M;
    if(N > M) swap(N, M);
    if(N == 1 && M == 1){
        cout << 1 << endl;
    }else if(N == 1){
        cout << M-2 << endl;
    }else{
        cout << (M-2)*(N-2) << endl;
    }
}

Measured memory_bytes: 256
a,b,m=[int(i) for i in input().split(" ")]
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]

min=min(a)+min(b)

for i in range(m):
    x,y,c=[int(i) for i in input().split(" ")]
    val=a[x-1]+b[y-1]-c
    if val<min:
        min=val

print(min)


Measured memory_bytes: 18488
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

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

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

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

inline void print() { cout << "\n"; }

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

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

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

i64 N;
vector<i64> C;
i64 memo[30][100010];

i64 dp(int idx, int rem) {
    if (rem < 0) return INF;
    if (idx >= C.size()) {
        return (rem == 0) ? 0 : INF;
    }

    auto &ret = memo[idx][rem];
    if (~ret) return ret;

    ret = INF;
    chmin(ret, dp(idx + 1, rem));
    chmin(ret, dp(idx, rem - C[idx]) + 1);

    return ret;
}

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

    read(N);
    {
        C.push_back(1);
        i64 a = 6;
        i64 b = 9;
        while (true) {
            C.push_back(a);
            C.push_back(b);
            a *= 6;
            b *= 9;
            if (a > 1000000 && b > 1000000) break;
        }
    }
    dump(C);

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

    print(dp(0, N));


    return 0;
}


Measured memory_bytes: 28416
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b; cin >> a>>b;
	int m = max(a + b, a - b);
	cout << max(m, a * b);

	cout << endl;
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
//#define ll __int128
//#define int ll
//#define int ll
//#define char ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(4) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

void smain() {

    string s;
    cin >> s;
    int n = s.size();
    if (SZ(s) & 1) {
        cout << "No\n";
        return;
    }
    for (int i = 0; i < SZ(s); i += 2) {
        if (s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
x_dif = []
for i in range(m-1):
    x_dif.append(x[i+1] - x[i])
x_dif.sort(reverse=True)
ans = sum(x_dif[n-1:])
print(ans)

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

int DP(int n,int k,int s){

  int dp[156][12];
  
  for(int i=0 ; i <= 155  ; i++){
    for(int j=0 ; j <= 11 ; j++){
      dp[i][j]=0;
    }
  }
  
  dp[0][0]=1;

  for(int i=1 ; i <= n ; i++){
    for(int K=k ; K >= 0 ; K--){
      for(int j=0 ; j <= s ; j++){
	if(dp[j][K] != 0 && i+j <= s && K+1 <= k){
	  dp[i+j][K+1]+=dp[j][K];
	}
      }
    }
  }
  
  return dp[s][k]; 
}
int main(){
  
  int n,k,s;

  while(1){
    cin >>n>>k>>s;
    if(n==0 && k==0 && s==0)break;
    cout <<DP(n,k,s)<<endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N, M;

    scanf("%d%d", &N, &M);

    char A[N][N+1], B[M][M+1];

    for(int i = 0; i < N; i++){
        scanf("%s", A[i]);
    }
    for(int i = 0; i < M; i++){
        scanf("%s", B[i]);
    }

    int t = 0;

    for(int i = 0; i <= N-M; i++){
        if(t == 1){
            break;
        }
        for(int j = 0; j <= N-M; j++){
            if(t == 1){
                break;
            }
            int f = 0;
            for(int k = 0; k < M; k++){
                if(t == 1){
                    break;
                }
                for(int l = 0; l < M; l++){
                    if(B[k][l] != A[i+k][j+l]){
                        f = 1;
                        break;
                    }
                }
            }
            if(f == 0){
                t = 1;
            }
        }
    }

    if(t == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
    size_t n, m;
    cin >> n >> m;
    vector<vector<size_t>> c(m);
    for (size_t i = 0; i < n; ++i) {
        size_t a, b;
        cin >> a >> b;
        if (a <= m)
            c[a - 1].emplace_back(b);
    }
    priority_queue<size_t> pq{};
    size_t d = 0;
    for (size_t i = 0; i < m; ++i) {
        for (auto e : c[i])
            pq.emplace(e);
        if (!pq.empty()) {
            d += pq.top();
            pq.pop();
        }
    }
    cout << d << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans = -1;
    rep(i, SZ(s)) {
        int cnt = 0;
        int j = i;
        while(j < SZ(s)) {
            if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') j++,cnt++;
            else                                                          break;
        }
        if (ans < cnt) {
            ans = cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

n = int(input())
aa = inpl_int()

b = []

if n%2 == 0:
	for i in range(n-1,0,-2):
		b.append(aa[i])
	for i in range(0,n,2):
		b.append(aa[i])
else:
	for i in range(n-1,-1,-2):
		b.append(aa[i])
	for i in range(1,n-1,2):
		b.append(aa[i])

print (' '.join(map(str,b)))


Measured memory_bytes: 30584
parseInt(x) = parse(Int32, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,ma,mb = readline() |> split |> parseMap
	a = Tuple{Int32,Int32,Int32}[(0,0,0) for i in 1:n]
	for i in 1:n
		p,q,r = readline() |> split |> parseMap
		a[i] = (p,q,r)
	end
	dp = 4001*ones(Int32,n+1,401,401)
	dp[1,1,1] = 0
	for i in 1:n
		for x in 1:401
			for y in 1:401
				dp[i+1,x,y] = min(dp[i+1,x,y],dp[i,x,y])
				if x+a[i][1]<=401&&y+a[i][2]<=401
					dp[i+1,x+a[i][1],y+a[i][2]] = min(dp[i+1,x+a[i][1],y+a[i][2]],dp[i,x+a[i][1],y+a[i][2]],dp[i,x,y]+a[i][3])
				end
			end
		end
	end
	minim = 4001
	k = min(div(400,ma),div(400,mb))
	for i in 1:k
		minim = min(minim,dp[n+1,ma*i+1,mb*i+1])
	end
	println(minim<4001?minim:-1)
end

main()

Measured memory_bytes: 170144
n=int(input())
s=input()

r=s.count('R')
g=s.count('G')
b=s.count('B')

ans=r*g*b

for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>=n: break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans-=1

print(ans)


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) cout << k << '\n';
    else if (k <= a + b) cout << a << '\n';
    else cout << a - (k - (a + b)) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3640
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n, a[110], b[110];

vector< Array > edges;
bool visit[110];

int rec(int v) {
	int res = 1;
	
	visit[v] = 1;
	
	int e_size = size_of(edges[v]);
	for_(i,0,e_size) {
		int u = edges[v][i];
		if (visit[u]) continue;
		maxUpdate(res, rec(u) + 1);
	}
	
	visit[v] = 0;
	
	return res;
}

void solve() {
	edges.assign(101, Array());
	
	for_(i,0,n) {
		edges[ a[i] ].push_back(b[i]);
		edges[ b[i] ].push_back(a[i]);
	}
	
	minit(visit, 0);
	int ans = 0;
	for_(i,1,101) maxUpdate(ans, rec(i));
	cout << ans << endl;
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> a[i] >> b[i];
		solve();
	}
	return 0;
}

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

int main()
{
   int N; cin>>N;
   int ans=0;
   for(int i=0;i<N;i++){
      string s; cin>>s;
      if(s=="E869120") ans++;
   }
   cout<<ans<<endl;
   return 0;
}




Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;




int main() {
  int i,N,K,top=1000,second=1000,third=1000;
  cin>>N>>K;
  vi p(N);
  for(i=0;i<N;i++)cin>>p[i];
  sort(p.begin(),p.end());
  int count=0;
  for(i=0;i<K;i++)count+=p[i];
  cout<<count<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end(), [](int x, int y){return (x > y);});
  long long ans = 0;
  priority_queue<int> q;
  q.push(a.at(0));
  for (int i = 1; i < n; ++i) {
    ans += q.top();
    q.pop();
    q.push(a.at(i));
    q.push(a.at(i));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	string s; cin>>s;
	if (n%2) {
		cout<<"No\n";
		return 0;
	}
	string t=s.substr(0,n/2);
	cout<<(s==t+t?"Yes":"No")<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
string s;
cin >> s;
if(s=="Sunny"){
	cout << "Cloudy" << endl;
}
else if(s=="Rainy")
	cout << "Sunny" << endl;
else{
	 cout << "Rainy" << endl;
}
}



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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  for (int i = 0;i < n;i++){
    cin >> w[i];
  }
  
  int ans = 1000000000;
  for (int t = 1;t < n;t++){
    int s1 = 0,s2 = 0;
    for (int i = 0;i < n;i++){
      if (i < t){
        s1 += w[i];
      }
      else{
        s2 += w[i];
      }
    }
    ans = min(ans,abs(s1-s2));
  }

  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

bool isNumber(char c){
	if( c >= '0' && c <= '9' ) return true;
	return false;
}

int main(){
	string s;
	while( getline(cin,s) ){
	 	int minusFlag = 1;
		double n = 0.0;
		stack<double> st;
		s += " ";

		for(int i=0 ; i < s.size() ; i++ ){
			char c = s[i];
			if( c == '-' && isNumber(s[i+1]) ){
				minusFlag = -1;
			}else if( isNumber(c) ){
				n *= 10.0;
				n += c - '0';
			}else  if( c == ' ' ){
				if( isNumber(s[i-1]) ){
					n = n * minusFlag;
					st.push( n );
					n = 0.0;
					minusFlag = 1;
				}
			}else if( c == '+' || c == '-' || c == '*' || c == '/' ){
				double a = st.top();
				st.pop();
				double b = st.top();
				st.pop();
				if( c == '+' ) st.push( b + a );
				if( c == '-' ) st.push( b - a );
				if( c == '*' ) st.push( b * a );
				if( c == '/' ) st.push( b / a );
			}
		}
		//cout << st.top() << endl;
		printf("%.8f\n", st.top() );
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#pragma GCC optimize ("O3")

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

inline static void pl(unsigned int s){
    char str[9];
    int pos=9;
    if(s==0){
        putchar_unlocked('0');
        return;
    }
    do{
        pos--;
        str[pos]=s%10+48;
        s/=10;
    }while(s!=0);
    for(; pos<9; pos++){
        putchar_unlocked(str[pos]);
    }
}

char a[501];
unsigned short out[4*500*500];

int main(void){
    int h=gl(), w=gl(), pos=0;
    char haveCoin = 0;
    short old_y, old_x;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            int t = getchar_unlocked() - 48;
            getchar_unlocked();
            a[j] = t;
        }
        if(i%2==1){
            for(int j=1; j<=w; j++){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }else{
            for(int j=w; j>0; j--){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }
    }
    printf("%d\n", pos);
    for(int i=0; i<pos; i++){
        pl(out[4*i+0]); putchar_unlocked(' ');
        pl(out[4*i+1]); putchar_unlocked(' ');
        pl(out[4*i+2]); putchar_unlocked(' ');
        pl(out[4*i+3]); putchar_unlocked('\n');
    }
    return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();

		int[][] a = new int[n][m];
		int[][] b = new int[m][l];

		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				a[i][j] = scan.nextInt();
		for (int i = 0; i < m; i++)
			for (int j = 0; j < l; j++)
				b[i][j] = scan.nextInt();

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < l; j++) {
				if (j > 0)
					System.out.print(" ");
				long ans = 0;
				for (int w = 0; w < m; w++)
					ans += (a[i][w] * b[w][j]);
				System.out.print(ans);
			}
			System.out.println();

		}
		System.exit(0);
	}

}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true) {
		int n;
		vector<int> w;
		vector<vector<int>> dp;
		
		cin >> n;
		
		if(!n) break;
		
		w.resize(n);
		dp.resize(n+1, vector<int>(n+1, 0));
		
		for(int i = 0; i < n; i++){
			cin >> w[i];
		}
		
		
		for(int k = 2; k <= n; k++){
			for(int i = 0; i < n && i + k <= n; i++){
				int j = i + k;
				
				if(abs(w[i] - w[j-1]) <= 1 && dp[i+1][j-1] == k - 2){
					dp[i][j] = k;
				}
				
				for(int l = i + 1; l < j; l++){
					dp[i][j] = max(dp[i][j], dp[i][l] + dp[l][j]);
				}
			}
		}
		
		cout<<dp[0][n]<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>

#define INF (1<<21)
#define swap(a,b) {a=a+b; b=a-b; a=a-b;}
#define min(a,b) {a > b ? b:a}
#define max(a,b) {a > b ? a:b}
using namespace std;

//300*300??§???????????§??¨??¢?´¢
#define MAX_N 10
#define MAX_D 30
bool t[MAX_N - 1][MAX_D];
int n, m, goal, d;

bool checkAmida() {
	int amida[] = {0,1,2,3,4,5,6,7,8,9};
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < n - 1; j++) {
			if (t[j][i]) swap(amida[j], amida[j + 1])
		}
	}
	return amida[goal - 1] == m-1;
}

pair<int,int> addOneLine() {
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < n - 1; j++) {
			if ((j - 1 >= 0) && t[j - 1][i]) continue;
			if (t[j][i]) continue;
			if ((j + 1 < n - 1) && t[j + 1][i]) continue;
			t[j][i] = true;
			if (checkAmida()) return make_pair(i,j);
			t[j][i] = false;
		}
	}
	return make_pair(-1, -1);
}
void q69() {
	for (; ;) {
		scanf("%d\n", &n);
		if (!n) break;
		scanf("%d\n%d\n%d\n", &m,&goal, &d);
		for (int i = 0; i < d; i++) {
			char tmp;
			for (int j = 0; j < n - 1; j++) {
				scanf("%c", &tmp);
				t[j][i] = tmp == '0' ? false : true;
			}
			scanf("%c", &tmp);
		}
		if (checkAmida()) {
			cout << "0" << endl;
			continue;
		}
		
		pair<int, int> point = addOneLine();
		if (point.first != -1) {
			cout << point.first+1 << " " << point.second+1 << endl;
		}
		else {
			cout << "1" << endl;
		}

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

Measured memory_bytes: 3120
n = int(input())
h = list(map(int, input().split()))
temp = 0
i = 0
while i<n:
    a = 0
    while i+a+1 < n and h[i+a]>=h[i+a+1]:
        a += 1
        temp = max(temp, a)
    if a == 0: i+=1
    else: i+=a
print(temp)

Measured memory_bytes: 14252
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
//#define INF 1145141919
//#define INF (1LL<<63)
#define INF 9223372036854775807LL
#define MOD 1000000007

int N;
vector<int> G[100];
int R[100];
int prod(int a, int b) {
  __int128 ret = (__int128)a*(__int128)b;
  if (ret > INF) ret = INF;
  return ret;
}
int dfs(int x, int p, int r) {
  int m = r;
  int deg = 0;
  for (int t : G[x]) if (t != p) {
    deg++;
    m = max(m, dfs(t, x, r+1));
  }
  R[r] = max(R[r], deg);
  return m;
}
P solveV(int v) {
  rep(i, N) R[i] = 1;
  int level = dfs(v, -1, 0);
  assert(level < N);
  int ret = 1;
  for (int k=0; k<=level; k++) ret = prod(ret, R[k]);
  //cout<<"v="<<v<<", ("<<level+1<<"/"<<ret<<")\n";
  //for (int k=0; k<=level; k++) cout<<"R["<<k<<"]="<<R[k]<<"\n";
  return P(level+1, ret);
}
P solveE(int a, int b) {
  rep(i, N) R[i] = 1;
  int level = 0;
  level = max(level, dfs(a, b, 0));
  level = max(level, dfs(b, a, 0));
  int ret = 2;
  for (int k=0; k<=level; k++) ret = prod(ret, R[k]);
  return P(level+1, ret);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P> edges;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
    edges.pb(P(a, b));
  }
  P ans = P(INF, INF);
  rep(i, N) ans = min(ans, solveV(i));
  for (P p : edges) ans = min(ans, solveE(p._1, p._2));
  cout << ans._1 << " " << ans._2 << "\n";
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/abc146/tasks/abc146_a

now_yobi = input()

if now_yobi == 'SUN':
    print(7)
elif now_yobi == 'MON':
    print(6)
elif now_yobi == 'TUE':
    print(5)
elif now_yobi == 'WED':
    print(4)
elif now_yobi =='THU':
    print(3)
elif now_yobi == 'FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 2940
h,w = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())
ans = [[0 for _ in range(w)] for _ in range(h)]
ans[0][0] = 1
mod = 7+10**9
for i in range(h):
    for j in range(w):
        if ans[i][j] == 0 or l[i][j] == "#":
            continue
        if i+1 < h:
            ans[i+1][j] += ans[i][j]
            ans[i+1][j] %= mod
        if j+1 < w:
            ans[i][j+1] += ans[i][j]
            ans[i][j+1] %= mod
print(ans[-1][-1])

Measured memory_bytes: 92124
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define VE vector<int>
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  LL N,X;
  LL A[2000];
  LL M[2000];
  cin>>N>>X;
  FOR(i,0,N){
    cin>>A[i];
    M[i]=A[i];
  }
  LL ans=1e15+7;
  FOR(i,0,N){
    LL sum=X*i;
    FOR(j,0,N){
      M[j]=min(M[j],A[((j-i)<0?j-i+N:j-i)]);
      sum+=M[j];
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける

int main(){
  int N, D, count=0;
  cin >> N >> D;
  for (int i = 0; i < N; i++)
  {
    if ((2*D+1)*i < N)
    {
      count ++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInt()
    val A = readIntList()

//    val map = A
//        .groupingBy { it }
//        .eachCount()
//        .mapValues { (k,v)-> v*(v-1)/2 to (v-1)*(v-2)/2 }
    val tmpmap = mutableMapOf<Int, Int>()
    A.forEach{tmpmap[it] = (tmpmap[it]?:0) + 1 }
    val map = tmpmap
        .map { 
            it.key to (it.value.toLong()*(it.value-1)/2 to (it.value.toLong()-1)*(it.value-2)/2) }
        .toMap()
    val sum = map.values.map { it.first }.sum()

    repeat(N) {
        println(sum - map[A[it]]!!.first + map[A[it]]!!.second)
    }
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 108520
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, B;

  std::cin >> A >> B;

  std::vector<std::string> board(100, std::string(100, '.'));

  for (int i = 0; i < 100; i ++)
    for (int j = 0; j < 50; j ++)
      board[i][j] = '#';

  A --;
  B --;

  for (int t = 0; t < A; t ++)
    for (int i = 0; ; i += 2)
      for (int j = 0; j < 50; j += 2) {
        board[i][j] = '.';

        if (-- A == 0)
          goto endloop1;
      }

endloop1:
  
  for (int t = 0; t < B; t ++)
    for (int i = 0; ; i += 2)
      for (int j = 0; j < 50; j += 2) {
        board[i][j + 51] = '#';

        if (-- B == 0)
          goto endloop2;
      }

endloop2:
  
  std::cout << board[0].size() << ' ' << board.size() << std::endl;

  for (const auto& s : board)
    std::cout << s << std::endl;
    
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>
const int MAX = 1000000;

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

// テーブルを作る前処理

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
using ll=long long int;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main(){
    COMinit();
    int n;
    cin >> n;
    vector<int> vec(n+1);
    for(int i=0;i<n+1;i++){
        cin >> vec[i];
    }
    vector<int> vec_c(n+1);
    vec_c=vec;
    int keep=-1;
    sort(vec_c.begin(),vec_c.end());
    for(int i=0;i<n+1;i++){
        if(vec_c[i]==vec_c[i+1]){
            keep = vec_c[i];
            break;
        }
    }
    int right=-1,left=-1;
    for(int i=0;i<n+1;i++){
        if(keep==vec[i]&&left==-1){
            left = i+1;
        }
        else if(keep==vec[i]&&left!=-1){
            right = i+1;
            break;
        }
    }
    ll ans;
    for(int i=1;i<=n+1;i++){
        //cout << left << " " << right << " " << COM(n+1,i) << " " << COM(left-1+n+1-right,i-1) << endl;
        ans = (COM(n+1,i)-COM(left-1+n+1-right,i-1)+MOD)%MOD;
        cout << ans << endl;
    }
    return 0;
}
//2 3 1 4 5 1 6 7


Measured memory_bytes: 25472
from collections import defaultdict
import heapq as hq
from itertools import permutations
def dijkstra(E, D, start,W):
    q = []
    V = [-1]*N
    V[start] = 0
    # for i in range(start):
    #     V[i] = W[i][start]
    #     for e in E[i]:
    #         if e > start:
    #             hq.heappush(q, (V[i] + D[(i,e)], e))
    for e in E[start]:
        if V[e] == -1:
            hq.heappush(q, (D[start, e],e))
    # print(V, q)
    while q:
        d, v = hq.heappop(q)
        if V[v] >= 0:
            continue
        V[v] = d
        for e in E[v]:
            if V[e] == -1:
                hq.heappush(q, (D[v,e]+d, e))
    return V
N, M, r = map( int, input().split())
R = list( map( int, input().split()))
d = defaultdict( int)
E = [ [] for _ in range(N)]
for _ in range(M):
    a, b, c = map( int, input().split())
    a, b = a-1, b-1
    d[(a,b)] = d[(b,a)] = c
    E[a].append(b)
    E[b].append(a)
W = [ [-1]*N for i in range(N)]
# for i in range(N):
#     W[i] = dijkstra(E,d,i,W)
    # print(W)
for i in range(r):
    W[R[i]-1] = dijkstra(E,d,R[i]-1,W)

ans = 10**9
for P in permutations( range(r)):
    now = R[P[0]]-1
    cans = 0
    for i in range(1,r):
        cans += W[now][R[P[i]]-1]
        now = R[P[i]]-1
    if cans < ans:
        ans = cans
print( ans)


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

#define LL long long
#define lowbit(x) ((x) & -(x))

const int maxn = (int) 1e5 + 20;
const int MOD = 998244353;

LL fp(LL a, LL n, LL m = MOD)
{
    LL res = 1;
    for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m;
    return res;
}

void work()
{
    int x, y;
    int px, py;
    cin >>x >>y;
    cin >>px >>py;

    int ck = (x % 2 == 0 && y % 2 == 0) && (x / 2 == px && y / 2 == py);
    printf("%.10lf %d", (double) x * y / 2, ck);
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 256
/*
* @Author: hannibal_lecter
* @Date:   2018-09-24 13:51:57
* @Last Modified by:   hannibal_lecter
* @Last Modified time: 2018-09-24 14:04:48
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
int Case = 1, n, m;
int mul(int a, int b) {
	return 1ll*a*b%mod;
}
int power(int a, int b) {
	int res = 1;
	while(b) {
		if(b&1) res = mul(res, a);
		a = mul(a, a);
		b = b>>1;
	}
	return res;
}
int res = 1;
void C(int a, int b) {
	for(int i = 1; i <= b; i++) {
		res = mul(res, a+i);
		res = mul(res, power(i, mod-2));
	}
}
void solve(){
    scanf("%d%d", &n, &m);
    for(int i = 2; i <= sqrt(m); i++) {
    	int cnt = 0;
    	while(m%i == 0) ++cnt, m/=i;
    	C(n-1, cnt);
    }
    if(m!=1) C(n-1, 1);
    printf("%d\n", res);
    return;
}

int main() {
    //ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    //freopen("/Users/hannibal_lecter/Desktop/code/in.txt", "r", stdin);
    //freopen("/Users/hannibal_lecter/Desktop/code/out.txt","w",stdout);
#endif
    while(Case--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter as cntr

n = int(input())
*a, = map(lambda x: x % 4, map(int, input().split()))
d = cntr(a)
c0, c1, c2 = d[1]+d[3], d[2], d[0]
if c1:
    print("Yes" if c2 >= c0 else "No")
else:
    print("Yes" if c2 >= c0-1 else "No")


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

struct Edge {
  int from;
  int to;
  int length;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<Edge> edges;
  for (int i = 0; i < M; ++i) {
    int f, t, l;
    cin >> f >> t >> l;
    edges.emplace_back(Edge {f - 1, t - 1, l});
  }

  const int kUnconnected = 100000000;
  vector<vector<int>> dists(N, vector<int>(N, kUnconnected));
  for (auto& e : edges) {
    dists[e.from][e.to] = e.length;
    dists[e.to][e.from] = e.length;
  }
  for (int i = 0; i < N; ++i) {
    dists[i][i] = 0;
  }

  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        dists[i][j] = min(dists[i][j], dists[i][k] + dists[k][j]);
      }
    }
  }

  int ret = 0;
  for (auto& e : edges) {
    bool used = false;
    for (int i = 0; i < N && !used; ++i) {
      if (dists[i][e.from] + e.length == dists[i][e.to])
        used = true;
    }
    if (!used)
      ++ret;
  }
  cout << ret << "\n";

  return 0;
}


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int L = A + B, R = C + D;
	if (L > R) {
		cout << "Left" << endl;
	}
	if (L == R) {
		cout << "Balanced" << endl;
	}
	if(L <R){
		cout << "Right" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v1;
int main(){
	int n;
	int i,j,k;
	int a,b,c;
	int s[2]={0};
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		v1.push_back(a);
	}
	sort(v1.rbegin(),v1.rend());
	for(i=0,j=0;i<n;i++){
		s[j]+=v1[i];
		j=1-j;
	}
	cout<<s[0]-s[1]<<endl;
	return 0;
}


Measured memory_bytes: 256
def main():
  N, Q = map(int, input().split())
  #graph = [[] for i in range(200010)]
  #ans = [0 for i in range(200010)]
  graph = [[] for i in range(N)]
  ans = [0 for i in range(N)]
  import sys
  #sys.setrecursionlimit(100000)
  sys.setrecursionlimit(10**7)
  #
  readline = sys.stdin.readline


  for _ in range(N - 1):
      #a, b = map(int, input().split())
      a, b = map(int, readline().split())
      a -= 1
      b -= 1

      graph[a].append(b)
      graph[b].append(a)

  for _ in range(Q):
      #p, x = map(int, input().split())
      p, x = map(int, readline().split())
      p -= 1

      ans[p] += x

  def dfs(node, frm=-1):
      for to in graph[node]:
          if to == frm:
              continue
          ans[to] += ans[node]
          dfs(to, node)
  dfs(0)

  #print(*ans[:N])
  print(*ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 268440