akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<queue>
#include<iostream>
#define REP(i, n) for(int i = 0, ed_##i = n; i < ed_##i; i++)
#define FOR(i, n) for(int i = 1, ed_##i = n; i <= ed_##i; i++)
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))  // Leading zeros
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))
 
#ifdef QWERTIER
#define err(x) cerr << #x << " : " << x << endl
#else
#define err(x)
#endif
 
typedef long long LL;
using namespace std;
 
typedef pair<int,int> pii;
#define MP make_pair
 
#define N 100010
int n, a[N], cnt[N];
 
int main(){
#ifdef QWERTIER
  freopen("in.txt","r",stdin);
#endif
  scanf("%d", &n);
  int dia = 0;
  FOR (i, n) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    dia = max(dia, a[i]);
  }
  FOR (i, n) {
    if (a[i] < (dia + 1) / 2) {
      puts("Impossible");
      return 0;
    } 
  }
  for (int i = dia; i >= (dia+1) / 2; i--) {
    if (i == dia && cnt[i] < 2) {
      puts("Impossible");
      return 0;
    }
    if (i != dia && i!= (dia+1)/2 && cnt[i]<2) {
      puts("Impossible");
      return 0;
    }
    if (i == (dia+1) / 2) {
      if ((dia % 2 == 0 && cnt[i] != 1) || (dia % 2 == 1 && cnt[i] != 2)) {
        puts("Impossible");
        return 0;
      }
    }
  }
  puts("Possible");
  return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long cnt = 0;
        for(int b = k+1; b <= n; b++) {
        	if(k == 0)
        		cnt += (b - k) * (n / b) + Math.max((n % b) - k, 0);
        	else
        	    cnt += (b - k) * (n / b) + Math.max((n % b) - k + 1, 0);
    	}
        System.out.println(cnt);

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(x) sort(x, x+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
#define pi 3.14159265358979323846
#define REP(i,j,n) for (int i = (int)j; i <=(int)n; i++)
#define REPD(i,n,j) for (int i = (int)n; i>=(int)j; i--)
#define all(vv) vv.begin(),vv.end()
//priority_queue <int, vector<int>, greater<int>> mnheap;

ll arr[200005],brr[200005];
ll ans=0;
int n;
void dfs(int id)
{
    ll val[3];
    REP(i,-1,1)
    {
        val[i+1]=brr[(id+i+n)%n];
    }
    ll used=val[1]/(val[0]+val[2]);
    used=min(used,(brr[id]-arr[id])/(val[0]+val[2]));
    if(used==0)
        return;
    ans+=used;
    brr[id]-=(used*(val[0]+val[2]));
    dfs((id-1+n)%n);
    dfs((id+1+n)%n);
}
int main()
{
    sync;
    cin>>n;
    REP(i,0,n-1)
        cin>>arr[i];
    REP(i,0,n-1)
        cin>>brr[i];
    for(int itr=0;itr<10;itr++)
    {
        REP(i,0,n-1)
            dfs(i);
    }
    REP(i,0,n-1)
    {
        if(arr[i]!=brr[i])
            ans=-1;
    }
    cout<<ans<<endl;
}
/*
3
RRRGGGBBB
*/

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long int N;
	cin >> N;
	for(int i = 2;true;i++){
		if(i * i > N){
			cout << (i - 1)*(i - 1) << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, k[200005], l[200005];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		l[i] = k[i];
	}
	sort(k, k + n);
	int med;
	for (int i = 0; i < n; ++i) {
		med = k[n / 2];
		if (l[i] <= k[(n - 1) / 2]) cout << k[n / 2] << endl;
		else cout << k[(n - 1) / 2] << endl;
	}
}

Measured memory_bytes: 3712
N = int(input())
S = input()
 
left_black=0
right_white=S.count(".")
ans=left_black+right_white

for i in S:
    if i==".":
        right_white-=1
        ans=min(ans,left_black+right_white)
    else:
        left_black+=1
        ans=min(ans,left_black+right_white)
print(ans)       

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

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

const ll MOD = 1e9+7;

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

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

    int now = 0;
    int cnt = 1;
    REP(i, n) {
        int l;
        cin >> l;
        now = now + l;
        if (now <= x) {
            cnt += 1;
        } else {
            break;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	if(x>y){
		printf("a > b\n",y,x);
}
	else if(x<y){
	printf("a < b\n");
}
	else if(x==y){
	printf("a == b\n");
}
return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<char> vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  bool A = false;
  for(int j = 0;j < N;j++) {
    if(vec.at(j) == 'Y') {
      A = true;
      break;
    }
  }
  if(A == false) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.string;
import std.conv;
import std.range;

void main() {
    while (true) {
        int c, r;
        readf("%d %d\n", &c, &r);
        if (r == 0 && c == 0) break;

        int[][] map = new int[][](r + 1, c + 1);
        map[1][1] = 1;
        bool[][] bad = new bool[][](r + 1, c + 1);
        int n = readln.chomp.to!int;
        foreach (i; 0..n) {
            int x, y;
            readf("%d %d\n", &x, &y);
            bad[y][x] = true;
        }

        int[][] q = [[2,1], [1,2]];
        while (!q.empty) {
            int[] p = q.front;
            q.popFront;
            int y = p[0], x = p[1];
            if (bad[y][x])
                continue;
            map[y][x] = map[y-1][x] + map[y][x-1];
            bad[y][x] = true;
            if (y + 1 <= r) q ~= [y+1, x];
            if (x + 1 <= c) q ~= [y, x+1];
        }

        map[r][c].writeln;
    }
}

Measured memory_bytes: 1076
import scala.annotation.tailrec
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"

  val input: Array[Array[Int]] = Array.ofDim(6, 6000000)
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
//  val a, b, k = sc.nextInt
  val o, e = sc.next
//  val d = List.fill(7)(sc.nextInt)

  val ans = o.zipAll(e, "", "").foldLeft(""){ case (acc, (op, ep)) =>
      acc + op + ep
    }

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }

  // https://stackoverflow.com/questions/10199171/matcherror-when-match-receives-an-indexedseq-but-not-a-linearseq/10199441#10199441
  object +: {
    def unapply[T](s: Seq[T]) =
      s.headOption.map(head => (head, s.tail))
  }

  @tailrec
  def foldLeftWithNext[A, B](seq: Seq[A])(z: B)(op: (B, A, A) => B)(tailOp: (B, A) => B): B = {
    seq match {
      case Nil => z
      case a +: Nil => tailOp(z, a)
      case a +: next +: tail => foldLeftWithNext(next +: tail)(op(z, a, next))(op)(tailOp)
    }
  }
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

const int INF = 1001001001;

int ck(int a)
{
    if (a == 1)
    {
        return 0;
    }
    for (int i = 2; i * i <= a; i++)
    {
        if (a % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

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

    vector<ll> su(n), cum(n + 1, 0);
    rep(i, n) cin >> su[i];
    rep(i, n) cum[i + 1] += su[i] + cum[i];

    // rep(i, n)
    // {
    //     cout << cum[i] << ' ';
    // }
    // cout << endl;

    map<ll, ll> mp;
    rep(i, n + 1)
    {
        mp[cum[i]]++;
    }

    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        ll n = itr->second;
        debug(n);
        ans += n * (n - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

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

const int N = 1e5+1;
string s[N];
int cnt[3], n;
vector <int> res;

bool Try(int u){
    if (cnt[0] < 0 || cnt[1] < 0 || cnt[2] < 0) return false;
    if (u == n + 1) return true;
    int x = s[u][0] - 'A';
    int y = s[u][1] - 'A';
    if (cnt[x] <= cnt[y]){
        cnt[x]++; cnt[y]--;
        res.push_back(x);
        if (Try(u + 1)) return true;
        res.pop_back();
        cnt[x] -= 2; cnt[y] += 2;
        res.push_back(y);
        if (Try(u + 1)) return true;
        res.pop_back();
        cnt[x]++; cnt[y]--;
    }
    else{
        cnt[x]--; cnt[y]++;
        res.push_back(y);
        if (Try(u + 1)) return true;
        res.pop_back();
        cnt[x] += 2; cnt[y] -= 2;
        res.push_back(x);
        if (Try(u + 1)) return true;
        res.pop_back();
        cnt[x]--; cnt[y]++;
    }
    return false;
}

int main()
{
    fastio;
    cin >> n >> cnt[0] >> cnt[1] >> cnt[2];
    for (int i = 1; i <= n; i++) cin >> s[i];
    if (Try(1)) {
        cout << "Yes\n";
        for (int x : res) cout << (char)(x + 'A') << '\n';
    }
    else cout << "No";
    return 0;
}


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

ll N;

vector<ll> primeFactorization(ll n) {
    vector<ll> ret;
    ll a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            ret.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    ret.push_back(n);
    return ret;
}

int main() {
    cin >> N;

    ll ans = 0;
    ll prime[100];
    memset(prime, 0, sizeof(prime));

    for (ll i = 2; i <= N; i++) {
        vector<ll> pf = primeFactorization(i);
        for (int j = 0; j < pf.size(); j++) {
            prime[pf[j]]++;
        }
    }

    int two = 0;
    int four = 0;
    int fourteen = 0;
    int twenty_four = 0;
    int seventy_four = 0;
    for (int i = 0; i < 100; i++) {
        //cout << i << ": " << prime[i] << endl;
        if (prime[i] >= 2) {
            two++;
        }
        if (prime[i] >= 4) {
            four++;
        }
        if (prime[i] >= 14) {
            fourteen++;
        }
        if (prime[i] >= 24) {
            twenty_four++;
        }
        if (prime[i] >= 74) {
            seventy_four++;
        }
    }

    ans += (two-four)*four*(four - 1)/2 + four*(four - 1)*(four - 2)/2;
    ans += (four - fourteen)*fourteen + fourteen*(fourteen - 1);
    ans += (two - twenty_four)*twenty_four + twenty_four*(twenty_four - 1);
    ans += seventy_four;

    cout << ans << endl;

    return 0;
}


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

int main(){
  unsigned long n,a,b; cin >> n >> a >> b;
  unsigned long x = n/(a+b);
  if(n-x*(a+b)<=a) cout << n-x*(a+b)+x*a << endl;
  else cout << (x+1)*a << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T>
T mypow(T x,ll n,function<T(T,T)> f,T init){
    T ret = init;
    while(n > 0){
        if(n&1){
            ret = f(ret,x);
        }
        x = f(x,x);
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll l,a,b,m;
    cin >> l >> a >> b >> m;

    MOD = m;

    vector<ll> idx(18,0);

    ll r = 1;

    for(int i = 0; i < 18; i++){
        r *= 10;
        ll ok = -1;
        ll ng = l;
        while(abs(ok - ng) > 1){
            ll middle = (ok + ng)/2;
            if(middle*b + a < r){
                ok = middle;
            }else{
                ng = middle;
            }
        }
        idx[i] = ok;
    }

    b %= MOD;
    a %= MOD;

    ll ans = 0;
    vector<ll> tmpans(18,0);

    r = 10;
    ll base = 1;
    
    vector<ll> ra(18,0);
    ra[0] = 10;
    for(int i = 1; i < 18; i++){
        ra[i] = (ra[i-1]*10)%MOD;
    }

    for(int i = 0; i < 18; i++){
        ll num = 0;
        vector<vector<ll>> arr = {{ra[i],1,b},{0,1,b},{0,0,1}};
        auto func = [](vector<vector<ll>> a,vector<vector<ll>> b)->vector<vector<ll>>{
            vector<vector<ll>> ret(a.size(),vector<ll>(a.size(),0));
            for(int i = 0; i < a.size(); i++){
                for(int j = 0; j < a.size(); j++){
                    for(int k = 0; k < a.size(); k++){
                        ret[i][j] += (a[i][k]*b[k][j])%MOD;
                    }
                    ret[i][j] %= MOD;
                }
            }
            return ret;
        };
        vector<vector<ll>> ia = {{1,0,0},{0,1,0},{0,0,1}};
        if(i > 0 && idx[i] != idx[i-1] && idx[i] >= 0){
            num = idx[i] - idx[i-1];
            auto ret = mypow<vector<vector<ll>>>(arr,num-1,func,ia);
            ll an = (a+(b*(idx[i-1]+1))%MOD)%MOD;
            ll s = ((an*ret[0][0])%MOD + (an*ret[0][1])%MOD + ret[0][2])%MOD;
            tmpans[i] = s;
        }else if(i == 0 && idx[i] >= 0){
            num = idx[i]+1;
            auto ret = mypow<vector<vector<ll>>>(arr,num-1,func,ia);
            ll s = ((a*ret[0][0])%MOD + (a*ret[0][1])%MOD + ret[0][2])%MOD;
            tmpans[i] = s;
        }
    }

    
    for(int i = 17; i >= 0; i--){
        ll num = 0;
        ans += (tmpans[i]*base)%MOD;
        ans %= MOD;
        if(i > 0 && idx[i] != idx[i-1] && idx[i] >= 0){
            num = idx[i] - idx[i-1];
        }else if(i == 0 && idx[i] >= 0){
            num = idx[i]+1;
        }
        base *= mypow(ra[i],num);
        base %= MOD;
    }

    cout << ans << endl;

    return 0;
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  ll N;
  cin >> N;

  vector<ll> A(N + 1);
  vector<ll> B(N);
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }

  ll ans = 0;

  for (int i = N - 1; i >= 0; i--) {
    ll temp;
    temp = min(A[i + 1], B[i]);
    ans += temp;
    B[i] = max(B[i]-temp, 0LL);

    temp = min(A[i], B[i]);
    ans += temp;
    A[i] = max(A[i] - temp, 0LL);
  }

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

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
  int H[251];
  int n,i;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&H[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,H[i]);
    if(i/2 >= 1 && i/2 <= n)printf("parent key = %d, ",H[i/2]);
    if(i*2 >= 1 && i*2 <= n)printf("left key = %d, ",H[i*2]);
    if(i*2+1 >= 1 && i*2+1 <= n)printf("right key = %d, ",H[i*2+1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  int a,b;
  int ans=0;
  cin>>a>>b;
  ans=max(a+b,a-b);
  ans=max(ans,a*b);
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;
string s;
map<string, int> num[19];

int main () {
	cin >> n >> s;
	for (int i = 0; i < (1 << n); i++) {
		string cur = "";
		int cnt = 0;
		for (int j = 0; j < n; j++)
			if (((i >> j) & 1) == 0) {
				cnt++;
				cur += s[j];
			}	
		for (int j = n - 1; j >= 0; j--)
			if (((i >> j) & 1) == 1)
				cur += s[j];
//		cout << cur << endl;
		num[cnt][cur]++;
	}
	reverse (all (s));
	ll ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		string cur = "";
		int cnt = 0;
		for (int j = 0; j < n; j++)
			if (((i >> j) & 1) == 0)
				cur += s[j];
		for (int j = n - 1; j >= 0; j--)
			if (((i >> j) & 1) == 1) {
				cnt++;
				cur += s[j];
			}	
		reverse (all (cur));
		ans += num[cnt][cur];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 69952
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;w] = reads int
    let wvs = Array.init n (fun _ -> reads int)

    let dp = Array2D.create (n + 1) (w + 1) 0L
    for i = 1 to n do
        let [iw;iv] = wvs.[i-1]
        for j = 0 to w do
            if j - iw >= 0 then
                dp.[i, j] <- max (dp.[i-1, j]) (dp.[i-1, j-iw] + int64 iv)
            else
                dp.[i, j] <- dp.[i-1, j]

    printfn "%i" dp.[n, w]
    0

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    ll asum = 0LL, bsum = 0LL;

    rep(i, n){
        cin >> a[i];
        asum += a[i];
    }
    rep(i, n){
        cin >> b[i];
        bsum += b[i];
    }

    if(asum < bsum){
        ppp(-1);
        return 0;
    }

    int ng = 0;
    vector<ll> diff(n);
    ll lack = 0LL;
    for(int i = 0; i < n; ++i){
        if(a[i] < b[i]) {
            ng++;
            lack += b[i] - a[i];
        }
        diff[i] = a[i] - b[i];
    }

    sort(diff.rbegin(), diff.rend());

    ll sum = 0LL;
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(sum >= lack)
            break;
        sum += diff[i];
        cnt++;
    }

    ppp(cnt + ng);

    return 0;
}


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

using namespace std;

int main(void){
    int N,T;
    cin>>N>>T;
    vector<int> c(N),t(N);
    for(int i=0;i<N;i++){
        cin>>c[i]>>t[i];
    }
    int ans=1001;
    for(int i=0;i<N;i++){
        if(t[i]<=T){
            ans=min(ans,c[i]);
        }
    }
    if(ans==1001) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, U: "List[int]", V: "List[int]", S: int, T: int):
    S -= 1
    T -= 1
    adj = [[] for i in range(N)]
    for u, v in zip(U, V):
        adj[u-1].append(v-1)
    color = [[0, 0, 0] for i in range(N)]
    color[S][0] = 1
    Q = [(0, S)]

    while len(Q) > 0:
        d, u = heapq.heappop(Q)
        if u == T and d % 3 == 0:
            print(d // 3)
            return
        for v in adj[u]:
            if color[v][(d+1) % 3] == 1:
                continue
            heapq.heappush(Q, (d+1, v))
            color[v][(d+1) % 3] = 1

    print(-1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]" 
    v = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, u, v, S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 78172
#include<bits/stdc++.h>
using namespace std;
int a[20][20],b[20],ma=0;
void sou(int n)
{
	bool y=true;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		if(b[i]==1)
		{
			sum++;
			for(int j=1;j<=n;j++)
			{
				if(a[i][j]!=-1&&a[i][j]!=b[j])
				{
					y=false;break;
				}
			}
		}
		if(y==false)
		break;
	}
	if(y)
	{
		if(ma<sum)
		ma=sum;
	}
}
void er(int n)
{
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				b[j+1]=1;
			}
		}
		sou(n);
		memset(b,0,sizeof(b));
	} 
}
int main()
{
	memset(a,-1,sizeof(a));
	int n,p=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int m;
		cin>>m;
		while(m--)
		{
			int h1,h2;
			cin>>h1>>h2;
			a[p][h1]=h2;
		}
		p++;
	}
	er(n);
	cout<<ma;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>s(N);
  int ans = 0;
  for(int i=0;i<N;i++){
    cin>>s.at(i);
    ans+=s.at(i);
  }
  sort(s.begin(),s.end());
  if(ans%10==0){
    for(int i=0;i<N;i++){
      if(s.at(i)%10!=0){
        ans-=s.at(i);
        cout<<ans<<endl;
        return 0;
      }
    }
    ans = 0;
  }

  cout<<ans<<endl;
}


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

int main() {
	int D, G; cin >> D >> G;
	int p[11], c[11]; for (int i = 0; i < D; i++) cin >> p[i] >> c[i];

	int ans = 1e9;
	for (int mask = 0; mask < (1 << D); mask++) {
		int s = 0, num = 0, rest_mask = -1;
		for (int i = 0; i < D; i++) {
			if (mask >> i & 1) {
				s += 100 * (i + 1) * p[i] + c[i];
				num += p[i];
			}
			else {
				rest_mask = i;
			}
		}
		if (s < G) {
			int s1 = 100 * (rest_mask + 1);
			int need = (G - s + s1 - 1) / s1;
			if (need >= p[rest_mask])	 continue;
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int  n; cin >> n;
    cout << 32*n << endl;
}





Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define int long long
using namespace std;

int spow(int i)
{
    return i * i * i * i * i;
}

signed main()
{
    int x;
    cin >> x;
    int a = -2e9, b = -2e9;
    for (int i = -1000; i <= 1000; i++) {
        int r = pow(x + spow(i), 0.2);
        if (spow(r) - spow(i) == x) {
            a = r, b = i;
            break;
        }
    }
    cout << a << " " << b << "\n";
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
//#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;


signed main() {

	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n,k;
	cin>>n>>k;
	queue<double> q;
	double ans=0;
	double res=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		x++;
		q.push(x);
		res+=x;
		if(q.size()>k)
			res-=q.front(),q.pop();
		ans=max(ans,res/2);
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;

	return 0;
}





Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

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

// const int MAX = 1010;

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

    // 0番目を確認する
    string zero;
    cout << 0 << endl;
    cin >> zero;

    int flag;
    if (zero == "Vacant")
    {
        return 0;
    }

    int left = 0;
    int right = n;
    while (right - left > 0)
    {
        int mid = (left + right) / 2;
        string resp;
        cout << mid << endl;
        cin >> resp;
        if (mid % 2 == 1)
        {
            if (resp == "Vacant")
            {
                return 0;
            }
            else if (resp == zero)
            {
                right = mid;
            }
            else
            {
                left = mid;
            }
        }
        else
        {
            if (resp == "Vacant")
            {
                return 0;
            }
            else if (resp == zero)
            {
                left = mid;
            }
            else
            {
                right = mid;
            }
        }
    }
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;



signed main(){
    ll n,m;
    cin>>n>>m;
    ll l=1,r=100000;
    for(int i=0;i < m;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x>l){
            l=x;
        }
        if(y<r){
            r=y;
        }
    }
    cout << max(r-l+1,0ll) << endl;
}



Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> c = new HashSet<>();
		for(int i=0;i<n;i++){
			c.add(sc.nextInt());
		}
		sc.close();
		if(n==c.size()){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 100576
N, A, B, C, D = map(int, input().split())
S = input()

def max_stone(a, b):
  m = 0
  for j in range(a, b-1):
    if S[j] == S[j+1] == '#':
      return False
  
  return True
  
def reachable(b, d):
  n_sharp = 0
  n_dot = 0
  for j in range(b-1, d+2):
    s = S[j]
    if s=='.':
      n_dot += 1
      n_sharp = 0
    else:
      n_sharp += 1
      n_dot = 0
      
    if n_dot == 3:
      return True
    elif n_sharp == 2:
      return False
    
  return False
  
if C < B:
  if max_stone(A-1, C) and max_stone(B-1, D):
    print('Yes')
  else:
    print('No')
elif B < C and C < D:
  if max_stone(A-1, C) and max_stone(B-1, D):
    print('Yes')
  else:
    print('No')
elif B < C and C > D:
  if reachable(B-1, D-1) and max_stone(A-1, C) and max_stone(B-1, D):
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 3572
#include<stdio.h>
#include<math.h>

int main()
{
    long long int N,i,a,b,c,m,sum;
    scanf("%lld\n", &N);
    m=N+1;
    a=sqrt(N);
    for(i=a;i>=1;i--){
        if(N%i==0){
            b=N/i;
            c=b+i;
            if(c<=m){
                m=c;
                sum=m-2;
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	string S;
	cin >> S;


	int s = S.back() - '0';
	if (s == 2 || s == 4 || s == 5 || s == 7 || s == 9) co("hon");
	else if (s == 3) co("bon");
	else co("pon");


	Would you please return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll visited[10001];
signed main()
{
    fast;
    ll n;
    cin>>n;
    vvi arr(n+1);
    ll i;
    ll val[n];
    for(i=0;i<n-1;i++)
    {
        ll x,y;
        cin>>x>>y;
        arr[x].pb(y);
        arr[y].pb(x);
    }
    ll ans = 0;
    for(i=0;i<n;i++)
        cin>>val[i],ans+=val[i];
    sort(val,val+n);
    reverse(val,val+n);
    ans-=val[0];
    mem(visited,-1);
    visited[1] = 0;
    queue < ll > q;
    q.push(1);
    ll cnt = 1;
    while(!q.empty())
    {
        ll u = q.front();
        q.pop();
        for(auto v:arr[u])
        {
            if(visited[v]==-1)
            {
                visited[v] = cnt++;
                q.push(v);
            }
        }
    }
    cout<<ans<<"\n";
    for(i=1;i<=n;i++)
    {
        cout<<val[visited[i]]<<" ";
    }
}


Measured memory_bytes: 1152
def memolize(f):
    cache = {}

    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper

@memolize
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))



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

using namespace std;

int main () {
    int a, b, sum=0;
    cin >> a >> b;
    if (a >= b) {
        sum += a;
        a--;
    } else {
        sum += b;
        b--;
    }
    if (a >= b) {
        sum += a;
        a--;
    } else {
        sum += b;
        b--;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};


int main() {
	ll N;
	cin >> N;
	char a = 'a';
	
		string ans;
		while (N != 0) {
			a = 'a';
			if (N % 26 == 0) {
				a = 'z';

			}
			else {
				a = a + N % 26 - 1;
			}

			ans = a + ans;
			if (N % 26 == 0) {
				N = N / 26 - 1;

			}
			else {
				N = N / 26;
			}
		}
		cout << ans<<endl;
	
}


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

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

    cout << A[2] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<int> arr(N);
  for(int i=0;i<N;++i) {
    cin>>arr[i];
  }
  int ans;
  while(arr.size()>1) {
    sort(arr.begin(), arr.end());
    ans = arr[0];
    vector<int> arr1;
    arr1.push_back(ans);
    for(int i=0;i<arr.size();++i) {
      if(arr[i]%ans!=0) arr1.push_back(arr[i]%ans);
    }
    arr.clear();
    for(int i=0;i<arr1.size();++i) {
      arr.push_back(arr1[i]);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4100
#include<cstdio>
#include<vector>
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(mat A, mat B, int M){
  if(A[0].size() != B.size())return mat();
  int n = A.size(), m = B[0].size();
  mat C(n,vec(m));

  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      for(int k=0;k<A[0].size();k++)
	C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
  return C;
}

mat pow(mat A,int n,int M){
  mat res(A.size(),vec(A[0].size()));
  for(int i=0;i<A.size();i++)res[i][i] = 1;
  while(n>0){
    if(n&1)res = mul(res,A,M);
    A = mul(A,A,M);
    n >>= 1;
  }
  return res;
}

int main(){
  int n,m,a,b,c,t;

  while(scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),(n||m||a||b||c||t)){
    mat s(n,vec(1)),r;
    for(int i=0;i<n;i++)scanf("%d",&s[i][0]);
    
    mat A(n,vec(n));
    for(int i=0;i<n;i++){
      if(i)A[i][i-1] = a;
      A[i][i] = b;
      if(i!=n-1)A[i][i+1] = c;
    }

    r = mul(pow(A,t,m),s,m);
    for(int i=0;i<n;i++)printf("%d%c",r[i][0],((i==n-1)?'\n':' '));
  }
}

Measured memory_bytes: 1188
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



signed main(){
	int N ,M;
	cin >> N >> M;
	cout << (N - 1) * N / 2 + (M - 1) * M / 2 << endl;
}

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

public class Main {
	public static int max(int[] array){
		int L = array.length;
		int m = array[0];
		for(int i=1;i<L;i++){
			if(array[i]>m) m=array[i];
		}
		return m;
	}
	public static int min(int[] array){
		int L = array.length;
		int m = array[0];
		for(int i=1;i<L;i++){
			if(array[i]<m) m=array[i];
		}
		return m;
	}
	public static int count(int[] array, int target){
		int c = 0;
		int L = array.length;
		for(int i=0;i<L;i++){
			if(array[i]==target)c++;
		}
		return c;
	}
	
	public static boolean solve(int[] hat){
		int M = max(hat);
		int m= min(hat);
		if(M-m>=2) return false;
		
		if(m==M){
			return (m==1 || hat.length==hat[0]+1 || hat.length/2>=m);
		}
		
		//if M==m+1
		//there are M colors
		//the cats who say "I see only m colors" are alone, and the others are not
		int possibleMin = count(hat,m);
		if(count(hat,M)>0)possibleMin++;
		
		int possibleMax = count(hat,m)+count(hat,M)/2;
		

		return (possibleMin<=M && possibleMax>=M);
	}
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] hat = new int[N];
        for(int n=0;n<N;n++)hat[n]=sc.nextInt();
        
        if(solve(hat))System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 52960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

ll dp[3010][3010][4];

int main(){
  ll R, C, K;
  cin>>R>>C>>K;
  vector<ll> RR(K), CC(K), VV(K);
  vector<vector<ll>> Check(R, vector<ll>(C, 0));
  rep(i, K){
    cin>>RR[i]>>CC[i]>>VV[i];
    RR[i]--; CC[i]--;
    Check[RR[i]][CC[i]]=VV[i];
  }
  rep(i, R+1){
    rep(j, C+1){
      rep(k, 4){
        dp[i][j][k]=-1*INF;
      }
    }
  }
/*  rep(i, R){
rep(j, C){
  cout<<Check[i][j]<<" ";
}
  cout<<endl;}*/
  
  dp[0][0][0]=0;
  if(Check[0][0]>0)dp[0][0][1]=Check[0][0];
  
  rep(i, R){
    rep(j, C){
      if(i>0){
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]);
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][1]);
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][2]);
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][3]);
        if(Check[i][j]>0){
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][0]+Check[i][j]);
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][1]+Check[i][j]);
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][2]+Check[i][j]);
          dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][3]+Check[i][j]);
        }
      }
      if(j>0){
        dp[i][j][0]=max(dp[i][j][0], dp[i][j-1][0]);
        dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][1]);
        dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][2]);
        dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][3]);
        if(Check[i][j]>0){
          dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][0]+Check[i][j]);
          dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][1]+Check[i][j]);
          dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][2]+Check[i][j]);
        }
      }
      //cout<<i<<" "<<j<<"   "<<dp[i][j][0]<<" "<<dp[i][j][1]<<" "<<dp[i][j][2]<<" "<<dp[i][j][3]<<endl;
    }
  }
  ll Ans=max(dp[R-1][C-1][0], dp[R-1][C-1][1]);
  ll Anss=max(dp[R-1][C-1][2], dp[R-1][C-1][3]);
  cout<<max(Ans, Anss)<<endl;
}

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

using i64 = int64_t;
constexpr const i64 INF = INT64_MAX / 2;

struct node {
    i64 min_dist;
    node() : min_dist(INF) {}
};

struct edge {
    int from;
    int to;
    i64 cost;
};

bool bellman_ford(vector<node> &nodes, vector<edge> const &edges) {
    int N = nodes.size();
    for (int i = 0; i < N-1; i++) {
        for (auto const &e: edges) {
            nodes[e.to].min_dist = min(nodes[e.to].min_dist, nodes[e.from].min_dist + e.cost);
        }
    }

    for (auto const &e: edges) {
        if (nodes[e.to].min_dist > nodes[e.from].min_dist + e.cost) {
            return true;
        }
    }

    return false;
}

bool mark_reachable_to_n(vector<vector<int>> const &graph, vector<bool> &unreachable, int from, unordered_set<int> &visited) {
    if (from == graph.size() - 1) return true;
    if (!unreachable[from]) return false;
    if (visited.count(from)) return false;
    visited.insert(from);
    bool res = false;
    for (auto to: graph[from]) {
        bool t = mark_reachable_to_n(graph, unreachable, to, visited);
        res = res || t;
    }
    visited.erase(from);
    if (res) unreachable[from] = false;
    return res;
}

void remove_edges_for_unreachable_vertices(vector<edge> &edges, vector<vector<int>> const &graph) {
    vector<bool> unreachable(graph.size(), true);
    unreachable[graph.size() - 1] = false;
    unordered_set<int> visited;
    assert(mark_reachable_to_n(graph, unreachable, 0, visited));
    assert(visited.size() == 0);

    for (int a = 0; a < graph.size(); a++) {
        if (!unreachable[a]) continue;
        cerr << a << " is unreachable!" << endl;
        for (auto it = edges.begin(); it != edges.end(); ++it) {
            if (it->from == a || it->to == a) {
                it = edges.erase(it);
            }
            if (it == edges.end()) break;
        }
    }
}

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

    vector<vector<int>> graph(N);
    vector<edge> edges;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges.push_back({a, b, -c});
        graph[a].push_back(b);
    }

    remove_edges_for_unreachable_vertices(edges, graph);
    vector<node> nodes(N);
    nodes[0].min_dist = 0;
    if (bellman_ford(nodes, edges)) {
        cout << "inf" << endl;
    } else {
        cout << -nodes[N-1].min_dist << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#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 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(){
  int A,B,C,D,E;
  cin>>A>>B>>C>>D>>E;
  cout<<(max(A,40)+max(B,40)+max(C,40)+max(D,40)+max(E,40))/5<<endl;
  return 0;
}


Measured memory_bytes: 3080