akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SUM(x) ((x)*(x+1)/2)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++)
        cin >> c[i];
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++)
        for (int j = 0; j < 26; j++)
            cin >> s[i][j];
    vector<int> t(D);
    for (int i = 0; i < D; i++)
        cin >> t[i];
    
    int score = 0;
    vector<int> last(26, 0);
    for (int i = 1; i <= D; i++) {
        score += s[i-1][t[i-1]-1];
        last[t[i-1]-1] = i;
        for (int j = 0; j < 26; j++)
            score -= c[j] * (i - last[j]);
    }
    
    int m;
    cin >> m;   
    vector<int> ans;
    for (int i = 0; i < m; i++) {
        int d, q;
        cin >> d >> q;
        int p = t[d-1];
        t[d-1] = q;
        int diff = 0;
        diff -= s[d-1][p-1];
        diff += s[d-1][q-1];
        int lp = 0, rp = D+1, lq = 0, rq = D+1;
        for (int i = 1; i <= D; i++) {
            if (i < d) {
                if (t[i-1] == p)
                    lp = i;
                if (t[i-1] == q)
                    lq = i;
            }
            if (d < i) {
                if (rp == D+1 && t[i-1] == p)
                    rp = i;
                if (rq == D+1 && t[i-1] == q)
                    rq = i;
            }
        }
        int cp = c[p-1] * (d-lp) * (rp-d);
        int cq = c[q-1] * (d-lq) * (rq-d);
        diff -= cp;
        diff += cq;
        score += diff;
        ans.push_back(score);
    }
    for (int z : ans)
        cout << z << endl;
    
    return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <stack>
#include <list>
using namespace std;

int calcP(vector<int> *w, int k, int p){
  int nimotu = 0;			// 積めた荷物の数
  int w_n = 1;
  int w_size = w->size();
  int p_tmp = 0;
  for (int i = 0; i < k; i++) {
    p_tmp = p;

    if (nimotu == w_size) {
      break;
    }
    // cout << w->at(w_n-1) << " " << p_tmp << "\n";
    while ((w_n != w_size+1)&&(w->at(w_n-1) <= p_tmp )) {
      p_tmp = p_tmp - w->at((w_n)-1);
      w_n++;
      nimotu++;
      // cout << p_tmp << "\n";
    }
  }
  return w_n-1;
}



int main(int argc, char *argv[])
{
  int n;			// 荷物の数
  int k;			// トラックの数
  vector<int> W;		// 荷物の中身
  int w;
  long long unsigned int start = 0;
  long long unsigned int end = 100000*10000;
  cin >> n;
  cin >> k;
  for (int i = 0; i < n; i++) {
    cin >> w;
    W.push_back(w);
  
  }
  while ((end - start)> 1) {
    long long unsigned int mid = (long long unsigned int)(start + end)/2;
    // cout << calcP(&W,k,mid) << " "<< n <<" "<< mid<< "\n";
    if (calcP(&W,k,mid) >= n) {
      end = mid;
    }else {
      start = mid;
    }
  }
  cout << end << "\n";    
  
  return 0;
}




Measured memory_bytes: 3532
import Control.Applicative
import Control.Monad

main = do
    n <- fmap (read :: String -> Int) . words <$> getLine
    let a = n !! 0
        b = n !! 1
    as <- getAs a
    bs <- getBs b
    let anses = foldr (calc bs) [] as
    mapM_ (\x -> putStrLn $ show x) anses

getAs :: Int -> IO [[Int]]
getAs n = do
    forM [1..n] $ \_ -> do
        fmap (read :: String -> Int) . words <$> getLine

getBs :: Int -> IO [Int]
getBs n = do
    forM [1..n] $ \_ -> do
        readLn :: IO Int

calc :: [Int] -> [Int] -> [Int] -> [Int]
calc _ [] acc = acc
calc bs as acc = (mul bs as) : acc

mul :: [Int] -> [Int] -> Int
mul [] [] = 0
mul (b:bs) (a:as) = (a * b) + mul bs as

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

const int N = (int) 1e5;
int a[N], b[N], n;

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b + n);
    for (int i = 0; i < n; ++i) a[i] = lower_bound(b, b + n, a[i]) - b;
    int res = 0;
    for (int i = 0; i < n; ++i) if (a[i] % 2 != i % 2) ++res;
    cout << res / 2 << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){ 
	string s;
	cin>>s;
	int K;
	cin>>K;
	int a[s.size()];
	for(int i=0;i<s.size();i++){
		a[i]=0;
	}
	for(int i=0;i<s.size();i++){
		a[i]=((int)'z'-(int)s[i]+1)%26;
	}
	for(int i=0;i<s.size();i++){
		if(K>=a[i]){
			K-=a[i];
			a[i]=0;
		}else if(i==s.size()-1){
			a[i]-=K;
			a[i]=((a[i]%26)+26)%26;
			K=0;


		}else{

		}

	}
	if(K>0){
		a[s.size()-1]-=K;
		a[s.size()-1]=((a[s.size()-1]%26)+26)%26;


	}
	string ans="";
	for(int i=0;i<s.size();i++){
		if(i==s.size()-1){
			a[i]%=26;
			//a[i]=a[i]+97;
		}
		else if(a[i]==0){
			//a[i]=97;
		}else{
			//a[i]=97+(26-a[i]);
		}
		assert(a[i]>=0);
		a[i]%=26;
		char c='a'+(26-a[i])%26;
		ans+=c;
		//ans+=(char)(a[i]);
	}
	cout<<ans<<endl;
	}
	

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

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

    vector<string> s(L * N);

    for (int i = 0; i < L * N;i++) {
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());

    for (int i = 0; i < L * N; i++) {
        cout << s.at(i);
    }
    
        return 0;
}

Measured memory_bytes: 384
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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 MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  REP(i,n){
    while(A[i]%2==0){
      A[i] /= 2;
      z++;
    }
  }
  OUT(z);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define vi vector<int>
#define vvi vector<vector<int>>

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a,b,k = 0;
    cin>>n;

    vector<P>vp;
    map<P,int>eds;
    queue<int>q;
    vi c(n,0),used(n,0);
    vvi G(n);
    rep(i,0,n-1){
        cin>>a>>b;
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a,b);
    }
    
    q.push(0);
    used[0]=1;
    while(!q.empty()){
        int s = q.front();q.pop();
        if((int)G[s].size() > k){k = (int)G[s].size();}
        int now = 1;
        for(auto x:G[s]){
            if(used[x]){continue;}
            if(now == c[s]){now++;}
            c[x] = now;
            eds[{s,x}] = now;
            eds[{x,s}] = now;
            now++;
            used[x] = 1;
            q.push(x);
        }
    }

    cout<<k<<endl;
    for(auto p:vp){
        cout<<eds[p]<<endl;
    }
    return 0;
}

Measured memory_bytes: 20088
using System;
using System.Text;

class p
{
    static void Main()
    {
        int n = scan()[0];
        var a = new int[n+1,n+1];
        for(int i =0;i<n;i++)
        {
            var t = scan();
            for(int j=0;j<t[1];j++)
            {
                a[t[0],t[2+j]]++;
            }
        }
        var sb = new StringBuilder();
        for(int i = 1; i <=n; i++)
        {
            for(int j =1; j<=n; j++)
            {
                sb.Append(a[i,j]);
                if(j==n)sb.AppendLine();
                else sb.Append(" ");
            }
        }
        Console.Write(sb);
    }
    static int[] scan()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    }
}

Measured memory_bytes: 9428
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


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

  vector <ll> A(N), F(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());

  for (int i = 0; i < N; i++) cin >> F[i];
  sort(F.begin(), F.end(), greater<ll>());

  ll M = 0;
  for (int i = 0; i < N; i++){
    M = max(M, A[i] * F[i]);
  }
  
  bool flag = false;
  ll L = 0, R = M;

  vector < pair <ll, bool> > ans;  
  ans.push_back(make_pair(R, true));
  
  while (flag == false){
    ll now = (L + R) / 2;
    ll cnt = 0;
    for (int i = 0; i < N; i++){
      if (A[i] * F[i] > now){
        cnt += (A[i] * F[i] - now) / F[i];
        if ((A[i] * F[i] - now) % F[i] != 0){
          cnt++;
        }
      }
    }
    
    if (cnt <= K){
      ans.push_back(make_pair(now, true));
      R = now;
    }else{
      ans.push_back(make_pair(now, false));
      L = now;
    }
    
    if (now == (L + R) / 2){
      flag = true;
    }
  }
  
  for (int i = 0; i < ans.size(); i++){
    if (ans[i].second == true){
      M = min(M, ans[i].first);
    }
  }
  cout << M << endl;
  


  return 0;
}


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

#define ll long long
#define p_b push_back
#define pl pair<ll,ll>

ll modo = 1000000007;
ll MOD = modo;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t = 1;
	//cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		ll i;
		ll arr[n];
		ll sum = 0;
		for(i=0;i<n;i++)
		{
			cin >> arr[i];
			sum +=arr[i];
		}
		ll pre = 0;
		ll mini = MOD*MOD;

		for(i=0;i<n;i++)
		{
			pre +=arr[i];
			ll temp = sum - pre;
			ll diff = abs(temp - pre);
			mini = min(mini,diff);


		}
		cout << mini << endl;

		


	}	
	
	return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::tuple<int,int,int> T;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N;
int times[100];
int chairs[17];
std::priority_queue<T,std::vector<T>,std::greater<T>> queue1, queue2; // queue1: 入っている人, queue2: 待っている人

// (1) 入れる
// (2) 次の人が入るように追い出す

int position(const T& tuple){
    for(int i=0;i+std::get<1>(tuple)<=17;i++){
        bool can = true;
        REP(j, std::get<1>(tuple)){
            if(chairs[i+j] != -1){can = false; break;}
        }
        if(can){return i;}
    }
    return -1;
}

void enter(const T& tuple, const int& pos, const int& t){
    int index = std::get<2>(tuple);
    REP(i, std::get<1>(tuple)){
        chairs[pos+i] = index;
    }
    queue1.push(std::make_tuple(t+17*(index%2)+3*(index%3)+19, std::get<1>(tuple), index));
}

void leave(const T& tuple){
    REP(i, 17){
        if(chairs[i] == std::get<2>(tuple)){chairs[i] = -1;}
    }
}

void simulate(){
    std::fill(chairs, chairs+17, -1);

    REP(i, 100){
        queue2.push(std::make_tuple(5*i, i%5==1?5:2, i));
    }

    int t = 0;
    while(!queue2.empty()){
        while(!queue1.empty()){
            T tuple = queue1.top();
            if(std::get<0>(tuple) == t){
                // printf("Exit %d %d\n", std::get<2>(tuple), t);
                queue1.pop();
                leave(tuple);
            }else{break;}
        }

        while(!queue2.empty()){
            T tuple = queue2.top();
        
            int pos = position(tuple);
            if(pos != -1 && std::get<0>(tuple) <= t){
                // printf("Enter %d %d\n", std::get<2>(tuple), t);
                queue2.pop();
                enter(tuple, pos, t);
                times[std::get<2>(tuple)] = t - std::get<0>(tuple);
            }else{
                break;
            }
        }

        t += 1;
    }
}

int main(){
    simulate();
    
    while(std::cin >> N, !std::cin.eof()){
        std::cout << times[N] << std::endl;
    }
}

Measured memory_bytes: 1200
n, m = map(int, input().split())
p_y = []
for i in range(m):
    p, y = map(int, input().split())
    p_y.append([p, y, i])

p_y_sorted = sorted(p_y)
li_id = []
prev_p = -1
cnt = 1

for i in p_y_sorted:
    if(prev_p != i[0]):
        prev_p = i[0]
        cnt = 1
    id = str(i[0]).zfill(6) + str(cnt).zfill(6)
    li_id.append([i[2], id])
    cnt += 1

li_id_sorted = sorted(li_id)

for i in li_id_sorted:
    print(i[1])



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

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

  int a = 0, b = 0, c = 0;
  for (int i = 0; i < N.size(); i++) {
    if (N.at(i) == 'a')
      a++;
    else if (N.at(i) == 'b')
      b++;
    else
      c++;
  }

  int minv = N.size() / 3;
  if (a != minv && a != minv + 1)
    cout << "NO" << endl;
  else if (b != minv && b != minv + 1)
    cout << "NO" << endl;
  else if (c != minv && c != minv + 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <iostream>

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; ; i++) {
        if (n < 7 * i) {
            std::cout << "No" << std::endl;
            return 0;
        }
        if ((n - 7 * i) % 4 == 0) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    return 0;
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>


using namespace std;
const ll maxn=2e3+100,inf=1e9,LOG=23,mod=1e9+7;
int block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
#define int ll

int n, dp[maxn][maxn], ans;
pii a[maxn];

main()
{
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i].f;
		a[i].s = i;
	}
	sort(a + 1, a + 1 + n);
	nfor(1, len, n)
	{
		forn(1, l, n - len + 1)
		{
			int r = l + len - 1;
			dp[l+1][r] = max(dp[l][r] + a[r-l+1].f * abs(a[r-l+1].s-l), dp[l+1][r]);
			dp[l][r-1] = max(dp[l][r] + a[r-l+1].f * abs(a[r-l+1].s-r), dp[l][r-1]);
		}
	}
	forn(0, i, n)
	{
		ans = max(ans, dp[i + 1][i]);
	}
	cout << ans;
}

Measured memory_bytes: 26660
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans,x;
int n,num[15];
void dfs(int pos,ll sum)
{
	if(pos==n+1) {ans+=sum;return;}
	ll tmp=0;
	for(int i=pos;i<=n;i++)
	    tmp=tmp*10+num[i],dfs(i+1,sum+tmp);
}
int main(){
	cin>>x;
	while(x) num[++n]=x%10,x/=10;
	reverse(num+1,num+n+1);
	dfs(1,0);
	cout<<ans;
	return 0;         
}

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

int main(void){
    int D, cbuf, sbuf, tbuf;
    vector<int> c;
    cin >> D;
    vector<vector<int>> s(D, vector<int>(26, 0));
    vector<int> t;
    for(int i=0; i<26; i++){
        cin >> cbuf;
        c.push_back(cbuf);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            cin >> sbuf;
            s[i][j] = sbuf;
        }
    }
    for(int i=0; i<D; i++){
        cin >> tbuf;
        tbuf--;
        t.push_back(tbuf);
    }
    int satisfaction = 0;
    vector<vector<int>> last(D, vector<int>(26, -1));
    for(int i=0; i<D; i++){
        satisfaction += s[i][t[i]];
        for(int j=0; j<26; j++){
            if(j == t[i]){
                last[i][j] = i;
            }else{
                if(i > 0)last[i][j] = last[i-1][j];
            }
        }
        for(int j=0; j<26; j++){
            satisfaction -= c[j]*(i-last[i][j]);
        }
    }
    int M, dbuf, qbuf;
    cin >> M;
    for(int i=0; i<M; i++){
        cin >> dbuf >> qbuf;
        dbuf--;
        qbuf--;
        int oldtest = t[dbuf];
        t[dbuf] = qbuf;
        int j=dbuf;
        int oldlast = -1;
        if(dbuf > 0)oldlast = last[dbuf-1][oldtest];
        int lastdiff = dbuf - oldlast;
        while(j < D){
            if(last[j][oldtest] != dbuf)break;
            if(j <= 0){
                last[j][oldtest] = -1;
            }else last[j][oldtest] = last[j-1][oldtest];
            j++;
        }
        satisfaction -= c[oldtest]*(j-dbuf)*lastdiff;
        j=dbuf;
        oldlast = -1;
        if(dbuf > 0)oldlast = last[dbuf-1][qbuf];
        while(j < D){
            if(last[j][qbuf] != oldlast)break;
            last[j][qbuf] = dbuf;
            j++;
        }
        lastdiff = dbuf - oldlast;
        satisfaction += c[qbuf]*(j-dbuf)*lastdiff;
        satisfaction += s[dbuf][qbuf] - s[dbuf][oldtest];
        cout << satisfaction << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		//??????
		int tbl[] = new int[10];
		//
		int c = 9;
		int tmp;
		
		Scanner sc = new Scanner(System.in);
		
		//????????????????´?
		for(int i = 0; i < 10; i++) {
			tbl[i] = sc.nextInt();
		}
		
		//??´???(??????)
		while(c > 0) {
			int i = 0;
			while(i < c) {
				if(tbl[i] < tbl[i+1]) {
					tmp = tbl[i];
					tbl[i] = tbl[i+1];
					tbl[i+1] = tmp;
				}
				i++;
			}
			c--;
		}
		
		//??????
		for(int i = 0; i < 3; i++) {
			System.out.println(tbl[i]);
		}
	}
}

Measured memory_bytes: 26324
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int nex[2][6][2] = {
	{{1,0},{0,1},{-1,0},{0,-1},{-1,-1},{1,-1}},
	{{1,0},{0,1},{-1,0},{0,-1},{-1,1},{1,1}}
};

int a[110][110];
void dfs(int x,int y){
	if(a[x][y] == 0){
		a[x][y] = -1;
		rep(i,6){
			dfs(x + nex[x%2][i][0],y + nex[x%2][i][1]);
		}
	}
}

int main(){
	rep(i,110){
		rep(j,110){
			if(i == 0 || i == 109 || j == 0 || j == 109)a[i][j] = -2;
			else a[i][j] = 0;
		}
	}
	
	int w,h;
	
	scanf("%d%d",&w,&h);
	rep(i,h){
		rep(j,w){
			scanf("%d",&a[i+3][j+3]);
		}
	}
	
	dfs(1,1);
	
	int ret = 0;
	
	rep1(i,108){
		rep1(j,108){
			rep(k,6){
				if(a[i][j]*a[i+nex[i%2][k][0]][j+nex[i%2][k][1]] < 0)ret ++;
			}
		}
	}
	
	printf("%d\n",ret/2);
}

Measured memory_bytes: 1756
import sys
s = sys.stdin.read()
ans = [0 for i in range(26)]
s = s.lower()
for i in range(len(s)):
    if s[i]>='a' and s[i]<='z':
        ans[ord(s[i])-ord('a')] += 1

for i in range(25):
    print('%s : %d'%(chr(ord('a')+i),ans[i]))
print('z : %d'%(ans[25]))


Measured memory_bytes: 5568
#include <iostream>
#include <cstring>
#include <algorithm>
#define INF (2 << 28)
using namespace std;

int N, M, d[1000], c[1001], dp[1001][1001];

int rec(int now, int day) {
    
    if(now == N) return 0;
    if(day > M) return INF;
    if(~dp[now][day]) return dp[now][day];
     
    return dp[now][day] = min(rec(now, day + 1), rec(now + 1, day + 1) + d[now] * c[day]);
 }

int main() {
    
    cin >> N >> M;
    for(int i = 0; i < N; i++) cin >> d[i];
    for(int i = 0; i < M; i++) cin >> c[i + 1];
    
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 1) << endl;
}

Measured memory_bytes: 5132
// https://atcoder.jp/contests/abc074/tasks/abc074_b
#include <bits/stdc++.h>
using namespace std;

int main(void)
{
  int N, K;
  cin >> N >> K;

  int sum = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    
    if (x < K/2.0)
      sum += x * 2;
    else{
      if (x < K)
        sum += (K - x) * 2;
      else
        sum += (x - K) * 2;
    }
  }

  cout << sum << endl;
}

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

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader d=new BufferedReader(new InputStreamReader(System.in));
		String line;
		double x,y;
		while((line=d.readLine())!=null){
			String sp[] = line.split(" ");
			double[] var=new double[6];
			for(int i=0;i<sp.length;i++){
				var[i]=Double.valueOf(sp[i]);
			}
//[0]x + [1]y = [2]
//[3]x + [4]y = [5]
			var[1]/=var[0];// b/a
			var[2]/=var[0];// c/a
			var[0]=1;// a/a


			var[1]*=-1;

			//x=-by+c;
			//x=[1]y+[2];

			var[4]+=(var[3]*var[1]);
			var[5]-=(var[3]*var[2]);
			//[3]([1]y+[2])+[4]y=[5]
			//([4]+[3][1])y=[5]-[3][2]
			//[4]y=[5];

			y=var[5]/var[4];
			x=var[1]*y+var[2];
			System.out.println( String.format("%.3f", x)+" "+ String.format("%.3f", y));
		}
	}
}

Measured memory_bytes: 12000
from sys import stdin
import numpy as np
from numba import njit

H,N = map(int, input().split())
M = [list(map(int, stdin.readline().split())) for i in [0]*N]
M = np.array(M)

@njit
def main(h,n,m):
    dp = [10**8+1]*(10**4+1)
    dp = np.array(dp)
    dp[0] = 0

    for i in range(1,10**4+1):
        for j in range(n):
            a = m[j][0]
            b = m[j][1]
            if a>i:
                dp[i] = min(dp[i],b)
            else:
                dp[i] = min(dp[i],dp[i-a]+b)

    print(dp[h])

if __name__=="__main__":
    main(H,N,M)

Measured memory_bytes: 111736
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  string S,T; cin>>S>>T;
  int cnt=0;
  rep(i,0,S.size()){
    if(S[i]!=T[i]) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3852
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }
signed main() {
	int W, H, N; cin >> W >> H >> N;
	vector<vector<int>> v(W, vector<int>(H, 1));
	rep(i, N) {
		int x, y, a; cin >> x >> y >> a;
		if (a == 1) {
			for (int i = 0; i < x; i++) rep(j, H) v[i][j] = 0;
		}
		if (a == 2) {
			for (int i = x; i < W; i++) rep(j, H) v[i][j] = 0;
		}
		if (a == 3) {
			for (int i = 0; i < y; i++) rep(j, W) v[j][i] = 0;
		}
		if (a == 4) {
			for (int i = y; i < H; i++) rep(j, W) v[j][i] = 0;
		}
	}
	int ans = 0;
	rep(i, W) rep(j, H) ans += v[i][j];
	cout << ans << endl;
	system("pause");
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		String s = scan.next();

		if(a >= 3200) {
			System.out.println(s);
		}else {
			System.out.println("red");
		}
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>

int main()
{
    std::string str;
    std::cin >> str;
    
    for(u_int i = 0; i < str.size(); ++i)
        std::cout << str.at(str.size() - i - 1);
    std::cout << std::endl;
    
    return 0;
}

Measured memory_bytes: 1176
using System;
class Program
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        long a, b, x;
        a = long.Parse(s[0]);
        b = long.Parse(s[1]);
        x = long.Parse(s[2]);
        long ans;
        if (a != 0)
            ans = b / x - (a - 1) / x;
        else
            ans = b / x + 1;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;
int main(void){
string s;
while(1){
	cin>>s;
	if(s=="#")break;
	//now -1 l 1 r
	int r=-1,l=-1,ans=0,now=0;
for(int i=0;i<s.size();i++){
	if(s[i]=='1'||s[i]=='4'||s[i]=='7'){
		if(now==0){
			if(l==0){
				r=0;
			//	cout<<ans<<' '<<now<<' '<<l<<' '<<r<<endl;
				continue;
			}
		l=0;
		if(r!=-1&&r!=0){
			now=-1;
		}

		}else{
			if(now==1){
				now=-1;
				l=0;
			}else if(l>0){
				now=-1;
				l=0;
				ans++;
			}else{
				now=1;
				r=0;
			}
		}

		}else if(s[i]=='2'||s[i]=='8'){
	if(now!=0){
		if(now==-1){
			if(l==2){
				l=1;
				ans++;
			}else{
				now=1;
				r=1;
			}
		}else{
			if(now==1){
				if(r==0){
					r=1;
					ans++;
				}else{
					now=-1;
					l=1;
				}
			}
		}

	}else{
		if(l==0){
			r=1;
			now=1;
		}else if(r==2){
			l=1;
			now=-1;
		}else{
			r=1;
			l=1;
		}
	}

		}else{
			if(now==0){
				if(r==2){
					l=2;
//cout<<ans<<' '<<now<<' '<<l<<' '<<r<<endl;
					continue;
				}
				r=2;
				if(l!=-1&&l!=2){
					now=1;
				}
			}else{
				if(now==-1){
					now=1;
					r=2;
				}else{
					if(r!=2){
						ans++;
						r=2;
					}else{
						l=2;
						now=-1;
					}
				}

			}

}
//cout<<ans<<' '<<now<<' '<<l<<' '<<r<<endl;
}
cout<<ans<<endl;

}

	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
#define MAX 55555
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    vector<ll> P(MAX+1,-1);
    vector<int> R;
    for(int i = 2; i <= MAX; i++){
        if(P.at(i)!=-1)continue;
        else R.push_back(i);
        for(int j = 1; j*i <= MAX; j++){
            P.at(j*i) = i;
        }
    }
    vector<set<int>> res(5);
    for(auto i:R){
        int m = i%5;
        res.at(m).insert(i);
    }
    auto iter = res.at(1).begin();
    rep(i,N){
        cout<<*iter<<endl;
        iter++;
    }
}


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

int main() {
	int n, l;
	string S;
	vector<string> v;
	
	cin >> n >> l;
	for(int i = 0; i < n; i++) {
		cin >> S;
		v.push_back(S);
	}
	
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++) {
		cout << v[i];
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int N,D;
	cin>>N>>D;
	double x[N],y[N];
	double ans[N]={0};
	int anss=0;
	for(int i=0;i<N;i++)
	{
		cin>>x[i]>>y[i];
		ans[i]=sqrt(x[i]*x[i]+y[i]*y[i]);
		if(ans[i]<=D)
		anss++;
	}
	cout<<anss<<endl;
} 

Measured memory_bytes: 8436
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 



int main() {
  ll n,x;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  ll i=0,j=n-1,p=0,q=0;
  bool visited[n];
  memset(visited,0,sizeof(visited));
  while(i<=j)
  {
    if(p<=q)
    {
        if(visited[i]==0)
        {    p+=a[i];
        visited[i]=1;
        }
        i++;
    }
    else
    {
      if(visited[j]==0)
    {
      q+=a[j];
      visited[j]=1;
    }
      j--;
    }

  }
  cout<<abs(p-q)<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll N, A, B;
ll h[100005]; 

bool can(ll x) {
    ll add = 0LL;
    ll sub = A - B;
    rep(i,N) {
        ll hi = h[i] - B * x;
        if(hi > 0) add += ( hi - 1 + sub ) / sub;
        else continue;
    } 
    if( add <= x ) return true;
    else return false;
}

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

    cin >> N >> A >> B;
    rep(i,N) cin >> h[i];

    ll ma = INF;
    ll mi = 0LL;
    while(ma - mi > 1LL) {
        ll mid = (ma + mi) / 2;
        if(can(mid)) ma = mid;
        else mi = mid;
    }
    if(!can(ma)) ma = mi;
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n,m;
	cin>>n>>m;
	vvi g(n,vi(n,INT_MAX/10));
	REP(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		g[a][b]=-c;
	}
	REP(k,n){
		REP(i,n){
			REP(j,n){
				g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
			}
		}
	}
	cout<<-g[0][n-1]<<endl;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define MAXN 1000001

int arr[MAXN];
unordered_set<int> factors;

int gcd(int a, int b) { 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

int spf[MAXN]; 
   
void sieve() { 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) spf[i] = i; 
  
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) {  
        if (spf[i] == i) { 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
int getFactorization(int x) { 
    unordered_set<int> currFact;
    while (x != 1) { 
        if(currFact.find(spf[x]) == currFact.end()) {
            if(factors.find(spf[x]) != factors.end()) return 0;
            
            factors.insert(spf[x]);
            currFact.insert(spf[x]);
        }

        x = x / spf[x]; 
    } 
    return 1;   // all ok till this point
}

int main() {
    int n; scanf("%d", &n);
    for(int i=0 ;i<n; i++) scanf("%d", &arr[i]);

    int GCD = arr[0];
    for(int i=1; i<n && GCD != 1; i++) GCD = gcd(GCD, arr[i]);

    sieve();

    int pairCoprime = 1, setWiseCoprime = (GCD == 1);
    for(int i=n-1; i>=0; i--) {
        if(arr[i] == 1) continue;

        pairCoprime = getFactorization(arr[i]);

        if(!pairCoprime) break;
    }

    if(pairCoprime) printf("pairwise coprime\n");
    else if(setWiseCoprime) printf("setwise coprime\n");
    else printf("not coprime\n");

    return 0;
}

Measured memory_bytes: 11476
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  vector<long long>v;
  int i,j,k=0,l;
  for(i=0;i<n-1;i++)
  {
     cin>>l;
    v.push_back(l);
  }
  for(i=0;i<n-2;i++)
    k=k+min(v[i],v[i+1]);
  k=k+v[0]+v[n-2];
  cout<<k;
}

Measured memory_bytes: 256
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][idx]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)

    random.seed(20)
    while time.time() - start < 1.9:
        idx = random.randint(0,25)
        d = random.randint(0,D-1)
        if c[idx] == 0 or ans[d-1] == idx:
            continue
        tmp = ans[d]
        ans[d] = idx
        last_d = [0 for i in range(26)]
        score2 = 0    
        for i in range(D):
            score2 += s[i][ans[i]]
            last_d[ans[i]] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d] = tmp
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


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

int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

void err() {
	puts("No");
	exit(0);
}

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

	int N;
	cin >> N;
	vector<int>S(1<<N);
	for (int i = 0; i < (1<<N); i++)cin >> S[i];
	sort(all(S));
	reverse(all(S));

	multiset<int>rem;
	for (int i = 0; i < (1 << N); i++)rem.insert(S[i]);
	rem.erase(--rem.end());

	priority_queue<int>q1, q2;
	q1.push(S[0]);
	while (q1.size() < 1 << N) {
		while (q1.size()) {
			int tp = q1.top();
			q1.pop();
			q2.push(tp);
			auto itr = rem.lower_bound(tp);
			if (itr == rem.begin())err();
			--itr;
			q2.push(*itr);
			rem.erase(itr);
		}
		swap(q1, q2);
	}
	puts("Yes");

	return 0;
}

Measured memory_bytes: 13568
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 1010;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

LL dp[MAX][MAX];
void solve() {

	LL result = 0;
	int h,w;

	cin >> h>>w;
	vector<string> zm(h);
	for (int i = 0; i < h; ++i) {
		cin >> zm[i];
	}
	dp[0][0] = 1;
	for (int x = 0; x < h; ++x) {
		for (int y = 0; y < w; ++y) {
			if (zm[x][y] == '#') continue;
			if (x > 0) {
				dp[x][y] += dp[x - 1][y];
			}
			if (y > 0) {
				dp[x][y] += dp[x][y - 1];
			}
			dp[x][y] %= base;
		}
	}
	result = dp[h - 1][w - 1];

	cout << result << endl;

}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define N_MAX 100000
#define A_MAX 100000

int main(void)
{
  int n, a[N_MAX], b[A_MAX + 1][2] = {}, k = -1;
  int max = 0;
  std::cin >> n;
  for(int i = 0; i != n; i++) std::cin >> a[i];
  std::sort(a, a + n);
  for(int i = 0; i != n; i++){
    if(a[i] != k){
      b[a[i]][0] = i + 1;
      if(k != -1) b[k][1] = i + 1;
    }
    k = a[i];
  }
  b[a[n - 1]][1] = n + 1;
  for(int i = 0; i <= a[n - 1]; i++){
    int k;
    if(i > 1 && b[i - 2][0] != 0) k = b[i - 2][0];
    else if(i > 0 && b[i - 1][0] != 0) k = b[i - 1][0];
    else k = b[i][0];
    max = std::max(max, b[i][1] - k);
  }
  std::cout << max << std::endl;
  return 0;
}

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

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n;
	cin >> n;
	vi a(n);
	map<int, int> mp;
	rep(i, n) {
		cin >> a.at(i);
		if (a.at(i) % 4 == 0) {
			mp[4]++;
		}
		else if (a.at(i) % 2 == 0) {
			mp[2]++;
		}
		else {
			mp[1]++;
		}
	}
	if (mp[2] > 0) {
		mp[1]++;
	}
	if (mp[4] + 1 >= mp[1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 768
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int h, w;
    cin >> h >> w;
    vvi dist(10, vi(10, INF));
    rep(i, 10) {
        rep(j, 10) {
            int c;
            cin >> c;
            if(c != -1) {
                dist[i][j] = c;
            }
        }
    }
    vvi a(h, vi(w));
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }
    }

    rep(k, 10) {
        rep(i, 10) {
            rep(j, 10) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            if(a[i][j] != -1) {
                ans += dist[a[i][j]][1];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)
#define size size()

int main(){
    int n,m;
    cin >> n >> m;
    if(m%3==0||n%3==0||(m+n)%3==0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}





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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int, int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int w;
    cin >> w;

    cout << w * 32 << '\n';

    return (0);
}



Measured memory_bytes: 3216
using System;
using System.Linq;

namespace abc085c
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = inputs[0];
            var y = inputs[1];

            for (int i = 0; (10000 * i) <= y; i++)
            {
                for (int j = 0; (10000 * i + 5000 * j) <= y; j++)
                {
                    if (y - (10000 * i + 5000 * j + 1000 * (n - i - j)) == 0)
                    {
                        Console.WriteLine($"{i} {j} {n - i - j}");
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");

        }
    }
}


Measured memory_bytes: 13268
var
	N,i,ans,A:Longint;
	cnt:Array[1..100000]of Longint;
begin
	read(N);
	for i:=1 to N do begin
		read(A);
		inc(ans);
		if A<=N then begin
			inc(cnt[A]);
			if cnt[A]=A then dec(ans,A);
		end;
	end;
	writeln(ans);
end.


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

int main(){
    int ans=0;
    int n,k;
    cin >> n >> k;
    int x[110];
    rep(i,n){
        cin >> x[i];
    }
    rep(i,n){
        int ido=min(abs(x[i]),abs(x[i]-k));
        ans += ido * 2;
    }
    cout << ans << endl;
    
    return 0;
}

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

int main() {
  long long N,sum=0;
  cin >> N;

  for(long long i=1;i<N+1;i++){
    if(i%3 != 0 && i%5 != 0){
      sum += i;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3624