akhauriyash/Code-Regression huggingface dataset:
n=int(input())
top=0
top_num=0
second_num=0
for i in range(n):
    a=int(input())
    if a>top_num:
        top=i
        top_num=a
    elif a>second_num:
        second_num=a

for i in range(n):
    if i==top:
        print(second_num)
    else:
        print(top_num)

Measured memory_bytes: 4540
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main()
{
    int A,B,M;
    cin >> A >> B >> M;
    vector <int> a(A);
    vector <int> b(B);
    int min_a = MOD;
    int min_b = MOD;

    REP(i,A)
    {
        cin >> a[i];
        min_a = min(min_a,a[i]);
    }
    REP(i,B)
    {
        cin >> b[i];
        min_b = min(min_b, b[i]);
    }

    int res = min_a + min_b;
    
    REP(i,M)
    {
        int x,y,c;
        cin >> x >> y >> c;
        --x;--y;

        res = min(res, a[x] + b[y] - c);
    }

    cout << res << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int no1,no2,i;
    scanf("%d%d",&no1,&no2);
    char s[no2];
    getchar();
    for(i=0; i<no1; i++)
    {
        scanf("%s",s);
        printf("%s\n",s);
        printf("%s\n",s);
    }
    return 0;
}


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

class Dice{
public:
	int num[6];

	Dice();
	Dice(int a, int b, int c, int d, int e, int f);
	void roll(char s);
	void mroll(string s);
	void chgnum(int a, int b, int c, int d, int e, int f);
	bool rolluf(int a, int b);
};

Dice::Dice(){
	for (int i = 0; i < 6; i++) num[i] = i;
}


Dice::Dice(int a, int b, int c, int d, int e, int f){
	num[0] = a;
	num[1] = b;
	num[2] = c;
	num[3] = d;
	num[4] = e;
	num[5] = f;
}

void Dice::chgnum(int a, int b, int c, int d, int e, int f){
	num[0] = a;
	num[1] = b;
	num[2] = c;
	num[3] = d;
	num[4] = e;
	num[5] = f;
}
void Dice::roll(char s){
	int dum;
	switch (s)
	{
		case 'N':
			dum = num[0];
			num[0] = num[1];
			num[1] = num[5];
			num[5] = num[4];
			num[4] = dum;
			break;
		case 'E':
			dum = num[0];
			num[0] = num[3];
			num[3] = num[5];
			num[5] = num[2];
			num[2] = dum;
			break;
		case 'W':
			dum = num[0];
			num[0] = num[2];
			num[2] = num[5];
			num[5] = num[3];
			num[3] = dum;
			break;
		case 'S':
			dum = num[0];
			num[0] = num[4];
			num[4] = num[5];
			num[5] = num[1];
			num[1] = dum;
			break;
		case 'R':
			dum = num[1];
			num[1] = num[2];
			num[2] = num[4];
			num[4] = num[3];
			num[3] = dum;
			break;
		case 'L':
			dum = num[1];
			num[1] = num[3];
			num[3] = num[4];
			num[4] = num[2];
			num[2] = dum;
			break;
		default:
			break;
	}
	return;
}

void Dice::mroll(string s){
	for (int i = 0; s[i] != '\0'; i++){
		roll(s[i]);
	}
	return;
}

bool Dice::rolluf(int a, int b){
	for (int j = 0; j < 3; j++){
		if (num[0] == a) break;
		roll('N');
		if (num[0] == a) break;
		roll('E');
	}
	if (num[0] != a) return false;
	for (int j = 0; j < 4; j++){
		if (num[1] == b) break;
		roll('L');
	}
	if (num[1] != b) return false;
	return true;
}

bool diceequal(Dice a, Dice b){
	return (a.num[0] == b.num[0] && a.num[1] == b.num[1] && a.num[2] == b.num[2] && a.num[3] == b.num[3] && a.num[4] == b.num[4] && a.num[5] == b.num[5]);
}

bool dicecmp(Dice a, Dice b){
	for (int i = 0; i < 6; i++){
		for (int j = 0; j < 4; j++){
			if (diceequal(a, b)) return true;
			b.roll('L');
		}
		b.roll(i % 2 == 0 ? 'N' : 'E');
	}
	return false;
}

int main(){
	int a, b, c, d, e, f, n;
	cin >> n;
	vector<Dice> dice(n);
	for (int i = 0; i < n; i++){
		cin >> a >> b >> c >> d >> e >> f;
		dice[i].chgnum(a,b,c,d,e,f);
	}
	int val = 1;
	for (int i = 0; i < n - 1; i++){
		for (int j = i + 1; j < n; j++){
			val *= (!dicecmp(dice[i], dice[j]));
		}
	}
	cout << (val == 0 ? "No" : "Yes") << endl;
}


Measured memory_bytes: 3116
#include <vector>
#include <iostream>
using namespace std;
vector<vector<char>> Sdata;
int H, W, K;

int MaxVerticalBar (int offset, vector<int> RegionEdge, int BarNumber)
{
	int MAX = offset;
	vector<int> Chocolates (BarNumber+1, 0);

	for (MAX = offset; MAX < W; MAX++)
	{
		for (int i = 0; i <= BarNumber; i++)
			for (int i2 = RegionEdge[i]; i2 < RegionEdge [i+1]; i2++)
			{	
				Chocolates [i] += (int) (Sdata [i2] [MAX] - '0');
				if (Chocolates [i] > K)
				{
					if (MAX != 0)
						return MAX-1;
					else
						return 0;
				}
			}
	}
	return MAX;
};

int main(void)
{
    cin >> H >> W >> K;
    Sdata.resize (H);
    for (auto& e: Sdata)
    {
    	e.resize (W);
    	for (auto& e2: e)
 			cin >> e2;
 	}

	int BarNumber = 0;
	vector<int> RegionEdge (H+1, 0);
	int WorldRecord = H + W;
	for (int UnderBar = 0; UnderBar < (1 << (H-1)); UnderBar++)
	{
		BarNumber = 0;
		for (int i = 0; i < H; i++)
		{
			if (((UnderBar >> i) & 1) != 0)
			{
				RegionEdge [BarNumber+1] = i+1;
				BarNumber++;
			}
		}
		RegionEdge [BarNumber+1] = H;

		if (BarNumber < WorldRecord)
        {
          int answer = BarNumber;
		  for (int offset = 0; offset < W; offset++)
		  {
			  int VerticalBar;
			  VerticalBar = MaxVerticalBar (offset, RegionEdge, BarNumber);
			  if (VerticalBar != W)
			    answer++;
			  if (WorldRecord <= answer)
			    break;
			  offset = VerticalBar;
		  }
		  WorldRecord = answer;
		}
	}
	
	cout << WorldRecord << endl;
}

Measured memory_bytes: 256
N = input()
H = map(int, input().split())
last_h = float('inf')
cnt = -1
ans = 0

for h in H:
    if h <= last_h:
        # count to move
        cnt += 1
    else:
        # update answer
        ans = max(ans, cnt)
        # reset
        cnt = 0
    # height completed to be passed
    last_h = h

# check the last cnt and update answer
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 11132
/*****TEMPLATE*****/
      

#include <algorithm>
#include <array>
#include <bitset>
#include <cctype> 
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cstring>
#include <cstdio>
#include <stdio.h>
//INCLUDES
using namespace std;

#define lld long long int
#define ulld unsigned long long int
#define mod 1000000007
#define pb push_back
#define umap unordered_map
#define mp make_pair
#define fi first
#define se second 
#define rep(n) for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//DEFINES

lld gcd(lld a,lld b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){lld r=a%b; a=b; b=r;} return a;}
lld bs(lld arr[], lld l, lld r, lld x) { if (r >= l) {  lld mid = l + (r - l) / 2;  if (arr[mid] == x)  return mid; if (arr[mid] > x)  return bs(arr, l, mid - 1, x);  return bs(arr, mid + 1, r, x);  }  return -1; }
lld mypower(lld x, lld n){	if (n == 0)	return 1;	if (n & 1) 	return (((x * mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod)%mod);return (((mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod))%mod;}
lld modinv(lld a) { lld g = gcd(a, mod); if (g != 1) return -1;else{  return mypower(a, mod-2)%mod; } } 

//FUNCTIONS
void solve()
{
    lld n,k;
    cin>>n>>k;
    lld h[n];
    rep(n)cin>>h[i];
    lld ans[n]={};
    ans[0]=0;
    for (int i = 1; i < n; i++) {
        lld val=1e15;
        for(lld j=1;j<=k && (i-j)>=0 ;j++)
        {
            val=min(val,(abs(h[i]-h[i-j])+ans[i-j]));
        }
        ans[i]=val;
    }
    cout<<ans[n-1]<<"\n";
    return;
}
int main() 
{
    fast
    // lld t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}



Measured memory_bytes: 5208
#include<stdio.h>
#include <math.h>
int main()
{
  int N,sum,min=1000000;
  scanf("%d", &N);
  int a[N];
  for(int i=0;i<N;i++) scanf("%d", &a[i]);  
  for(int p=-100;p<=100;p++){
    for(int i=0;i<N;i++) sum+=pow(p-a[i],2);
    if(min>sum) min=sum;
    sum=0;   
  } 
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Gluttony | diff Gluttony.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Gluttony.cpp && ./a.out

/*
 
 10/27/2019
 
 6:04-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N],F[MAX_N],K;
int N;

LL Inf=1e18;
bool ok(LL T) {
  LL cnt=0;
  REP(i,N) {
    LL a=A[i],f=F[i];
    LL x=max(0LL,a-T/f);
    cnt+=x;
  }
  return cnt<=K;
}
void solve() {
  sort(F,F+N),sort(A,A+N),reverse(F,F+N);
  LL good=Inf,bad=-1;
  while(abs(good-bad)>1) {
    LL mid=(good+bad)/2;
    bool res=ok(mid);
//    dump(mid,res);
    (res?good:bad)=mid;
  }
  cout<<good<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  REP(i,N) cin>>A[i];
  REP(i,N) cin>>F[i];
  solve();
  
  return 0;
}


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

using namespace std;

int N, M, S, T, ways[2][100009], x[200009], y[200009], z[200009];
long long dist[2][100009];
const int mod = 1e9 + 7;
vector < pair < int, int > > v[100009];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

priority_queue < pair < long long, int > > PQ;
void dijkstra (int lin, int source)
{
    for (int i=1; i<=N; i++)
        dist[lin][i] = -1;
    dist[lin][source] = 0, PQ.push ({0, source}), ways[lin][source] = 1;
    while (!PQ.empty ())
    {
        pair < long long, int > curr = PQ.top ();
        PQ.pop ();
        if (dist[lin][curr.second] != -curr.first) continue;
        int nod = curr.second;
        long long d = dist[lin][nod];
        for (auto it : v[nod])
            if (dist[lin][it.first] + it.second == d)
                adto (ways[lin][nod], ways[lin][it.first]);
        for (auto it : v[nod])
            if (dist[lin][it.first] == -1 || dist[lin][it.first] > d + it.second)
                dist[lin][it.first] = d + it.second, PQ.push ({-dist[lin][it.first], it.first});
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
scanf ("%d %d", &S, &T);
for (int i=1; i<=M; i++)
    scanf ("%d %d %d", &x[i], &y[i], &z[i]), v[x[i]].push_back ({y[i], z[i]}), v[y[i]].push_back ({x[i], z[i]});
dijkstra (0, S);
dijkstra (1, T);
long long minT = dist[0][T];
assert (dist[0][T] == dist[1][S] && ways[0][T] == ways[1][S]);
int ans = mul (ways[0][T], ways[0][T]);
for (int i=1; i<=N; i++)
    if (2LL * dist[0][i] == minT && dist[0][i] + dist[1][i] == minT)
    {
        int paths = mul (ways[0][i], ways[1][i]);
        ans = subtract (ans, mul (paths, paths));
    }
for (int i=1; i<=M; i++)
    for (int t = 0; t < 2; t ++, swap (x[i], y[i]))
        if (2 * dist[0][x[i]] < minT && minT < 2LL * (dist[0][x[i]] + z[i]) && dist[0][x[i]] + dist[1][y[i]] + z[i] == minT)
        {
            int paths = mul (ways[0][x[i]], ways[1][y[i]]);
            ans = subtract (ans, mul (paths, paths));
        }
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 14704
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    int k, x;
    
    cin >> k >> x;
    
    for (int i=-k+1; i<=k-1; i++)
    {
        cout << x+i << " ";
    }
    
    return 0;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
unordered_map<string, ll> memo;
string AND(string s, string t){
	string ret;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='1' && t[i]=='1') ret+='1';
		else ret+='0';
	}
	return ret;
}
ll solve(string s){
	int n=s.size();
	if(n==1){
		if(s[0]=='0') return 1;
		else return 2;
	}
	auto itr=memo.find(s);
	if(itr!=memo.end()) return itr->second;
	ll ans=solve(s.substr(1, n-1));
	if(s[0]=='1') ans=ans*2%MOD;
	string t=s;
	for(int i=1; i<=n; i++){
		string t=s.substr(0, i);
		for(int j=i; j+i<=n; j+=i){
			t=AND(t, s.substr(j, i));
			if(j+i<n) ans=(ans+solve(t)*solve(s.substr(j+i)))%MOD;
			else ans=(ans+solve(t))%MOD;
		}
	}
	return memo[s]=ans;
}

int main()
{
	string s;
	cin>>s;
	cout<<solve(s)<<endl;
	return 0;
}

Measured memory_bytes: 5388
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	ll k; cin >> k;
	vector<ll> a(n), f(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> f[i];
	sort(a.begin(), a.end());
	sort(f.rbegin(), f.rend());

	ll lo = -1, hi = 1'000'000'000'000'000'000LL;
	while (hi - lo > 1) {
		ll mid = lo + (hi - lo) / 2;
		ll s = 0;
		for (int i = 0; i < n; i++) {
			ll c = mid / f[i];
			s += max(0LL, a[i] - c);
		}
		if (s <= k) hi = mid;
		else lo = mid;
	}
	cout << hi << endl;
	return 0;
}


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

int N;
vector<int> A;
vector<vector<int>> x;
vector<vector<int>> y;

int counter(int x){
    if(x==0){
        return 0;
    }
    return counter(x >> 1)+(x & 1);
}

void input(){
    cin>>N;
    A.resize(N);
    x.resize(N);
    y.resize(N);
    for(int i=0; i<N; i++){
        
        cin>>A[i];


        for(int j=0; j<A[i]; j++){
            int x_in,y_in;
            
            cin>> x_in >> y_in;
        
            x_in--;

            x[i].push_back(x_in);
            y[i].push_back(y_in);
            
        }
    }

}

void solve(){
    int ans=0;
    for(int bits=1; bits<(1<<N); bits++){
        bool ok =true;

        for(int i=0; i<N; i++){
            if(!(bits & (1<<i))){
                continue;
            }
            for(int j=0; j<A[i]; j++){
                if(((bits >> x[i][j]) & 1) ^ y[i][j]){ // & 1　必要な理由?
                    ok = false;
                }
            }
        }
        if(ok){
            ans=max(ans, counter(bits));
        }
    }
    cout<< ans <<endl;
}

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

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


int main(){

    string S;
    cin >> S;

    int mid = S.size()/2;
    int mmid = mid/2;
    int size = S.size();

    //cout << S.length() << endl;
    for(size_t i=0;i<mid+1;i++){
        if(S[i]!=S[size-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    //cout << "done" << endl;
    for(size_t i=0;i<mmid+1;i++){
        if(S[i]!=S[mid-i-1]){
            cout << "No" << endl;
            return 0;
        }
        if(S[mid+i+1]!=S[size-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

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

  vector<int> join=a;
  sort(join.begin(),join.end());
  vector<int> leave=b;
  sort(leave.begin(),leave.end());
  int joinde=0;
  int leinde=0;
  int mem=1;
  int res=0;
  for(int i=2;i<=n+1;i++){
    
    while(joinde<n && join[joinde]==i){
      mem++;
      joinde++;
    }
    while(leinde<n && leave[leinde]<i){

      mem--;
      leinde++;
    }

    if(i<=mem){
      res=max(res,i-1);
    }
    
  }
  cout<<res<<endl;
  return 0;

}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vs s(b*2+1);
    rep(i, b*2+1) rep(j, a*2+1) {
        s[i].pb(((i+j)%2)+'0');
    }
    rep(i, b*2+1) for (int j=a*2+1; j<w; ++j) s[i].pb(s[i].back());
    for (int j=b*2+1; j<h; ++j) {
        s.pb(s.back());
    }
    if (w<=a*2) rep(i, h) s[i].pop_back();
    rep(i, h) cout << s[i] << endl;
    return 0;
}


Measured memory_bytes: 5468
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> v;
	for(int i=0;i<2*n;i++)
	{
		int a;
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	int brojac=0;
	for(int i=0;i<2*n;i+=2)
		brojac+=v[i];
	cout<<brojac<<endl;
	return 0;
}

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

int main() {
  int size; cin >> size;
  vector<int> A(size), B(size), C(size-1);

  for (auto &a : A) {
    cin >> a;
  }

  for (auto &b : B) {
    cin >> b;
  }

  for (auto &c : C) {
    cin >> c;
  } 

  int res = 0;

  for (int i = 0; i < size; i++) {
    res = res + B[i];
    if (i < size - 1) {
      if (A[i] + 1 == A[i+1]) {
        res = res + C[A[i]-1];
      }
    }
  }

  cout << res << endl;


}

Measured memory_bytes: 3192
s = input()
t = input()

ans = len(s)

for i in range(len(s)):
    if i + len(t) - 1 >= len(s):break
    dif = 0
    for j in range(len(t)):
        if s[i + j] != t[j]:
            dif += 1
    ans = min(ans, dif)

print(ans)

Measured memory_bytes: 8964
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 200005;
const int MM = 1000000007;

int cnt[MX];
int N, a;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &a), cnt[a]++;
	int mx = N, mn;
	while(cnt[mx] == 0) mx--;
	mn = (mx+1) / 2;
	if( mx%2 == 1 && cnt[mn] == 2 || mx%2 == 0 && cnt[mn] == 1);
	else return !printf("Impossible\n");

	for(int i = 1; i < mn; i++) if( cnt[i] ) return !printf("Impossible\n");
	for(int i = mn+1; i <= mx; i++) if(cnt[i] < 2 ) return !printf("Impossible\n");
	printf("Possible\n");
}



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

ac = 0
wa = 0
ac_status = [0 for i in range(N)]
wa_status = [0 for i in range(N)]

for _ in range(M):
    p_i, s_i = input().split()
    if s_i == "AC" and ac_status[int(p_i) - 1] == 0:
        ac += 1
        ac_status[int(p_i) - 1] += 1
        wa += wa_status[int(p_i) - 1]
    if s_i == "WA":
        wa_status[int(p_i) - 1] += 1

print(ac, wa)

Measured memory_bytes: 4760
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>

#define int64 long long int

using namespace std;
typedef pair<int, int> P;

int freq(int *, int);

int main()
{
    int n, S[12], buf, count;
    
    while(1){
        cin >> n;
        if(n == 0) break;
        
        for (int i=0; i<n; i++) {
            cin >> buf;
            S[i] = buf;
        }
        
        count = 0;
        while(freq(S, n)) count++;
        
        cout << count << endl;
        for(int i=0; i<n-1; i++) cout << S[i] << ' ';
        cout << S[n-1] << endl;
        
    }
    
    return 0;
}

int freq(int *S, int n){
    int C[12] = {0}, buf, flag = 0;
    for(int i=0; i<n; i++){
        buf = S[i];
        for(int j=0; j<n; j++){
            if(S[j] == buf) C[i]++;
        }
    }
    for(int i=0; i<n; i++){
        if(S[i] != C[i]){
            flag = 1;
            break;
        }
    }
    if(flag){
        for(int i=0; i<n; i++) S[i] = C[i];
        return 1;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int dab = abs(a-b);
    int dac = abs(a-c);
    int dbc = abs(b-c);
    
    if (dac <= d || (dab <= d && dbc <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int sum = 0;
    for (int i = 0; i < n; i++) {
        int l;
        int r;
        cin >> l;
        cin >> r;
        int num = r - l + 1;
        sum += num;
    }
    cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
//最大公約数　最小公倍数はa*b/GCD(a,b)
int64_t GCD(int64_t a,int64_t b){
    return b == 0 ? a : GCD(b, a % b);
}
int64_t LCM(int64_t a,int64_t b){
    if(a%b==0){
        return a;
    }
    if(b%a==0){
        return b;
    }
    return a/GCD(a,b)*b;
}
int main(){
    int n;
    cin>>n;
    vector<int64_t> t(n);
    rep(i,n){
        cin>>t[i];
    }
    if(n==1){
        cout<<t[0]<<endl;
        return 0;
    }
    int64_t sum=t[0];
    for(int i=1;i<n;i++){
        sum = LCM(sum,t[i]);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
/*
Just Constraints are different than the other version
rest logic is similar
Constraints:
1<=n<=100
1<=wt<=10^9
1<=w[i]<=wt
1<=v[i]<=10^3
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n , w;
    cin>>n >> w;
    ll wei[n],val[n];
    for(int i =0; i< n;++i) {
    	cin>>wei[i] >> val[i];
    }
    long long  dp[n+1][100005]; //n+1 weight and 1001 value
    for(int i = 0; i <= n; ++i){
    	for(int j = 0; j<= 100004; ++j){
    		if(j == 0 )
    			dp[i][j] = 0;
    		else if( i == 0)
    			dp[i][j] = INT_MAX;
    		else if(val[i-1] > j )
    			dp[i][j] = dp[i-1][j];
    			else //note the difference of using min here and max in other version
    			dp[i][j]  = min(dp[i-1][j] , wei[i-1] + dp[i-1][j - val[i-1]]);
    		}
    	}
    	ll ans =0 ;
    	for(int i = 0; i <= 100004; ++i){
    		if(dp[n][i] <= w && dp[n][i] != INT_MAX)
    		    ans = i;
    	}
    	cout<<ans<<endl;
}


Measured memory_bytes: 79104
// credit: fwho1150
program main;

type
    sample = array[1..8] of longint;

var
    n, order: longint;
    p, q: sample;

procedure input (var a: sample);
var
    i: longint;

begin
    for i := 1 to n do
        read(a[i]);
    readln;
end;

function code(var a: sample): sample;
var 
    i, j, c: longint;

begin
    for i := 1 to n do
        a[i] := a[i] - 1;
    for i := 1 to n do begin
        c := 0;
        for j := 1 to (i - 1) do
            if (a[j] < a[i]) then 
                inc(c);
        code[i] := a[i] - c;
    end;
end;

function fact(n: longint): longint;
begin
    if (n = 0) or (n = 1) then 
        fact := 1
    else 
        fact := n * fact(n - 1);
end;

function rank(a: sample): longint;
var
    i, tmp: longint;

begin
    tmp := 0;
    for i := 1 to n do 
        tmp := tmp + a[i] * fact(n - i);
    rank := tmp;
end;

begin
    readln(n);
    input(p);
    input(q);
    order := abs(rank(code(p)) - rank(code(q)));
    writeln(order);
end.

Measured memory_bytes: 1320
/// meowa 

#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define low lower_bound
#define upp upper_bound
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse((a).begin(), (a).end());
#define sz(x) (int) x.size()
 
using namespace std;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
  
//ll
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void stndrtn() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif        
}                   

const bool flag = 0;

void ma1n() {
    string s;
    cin >> s;
    int cnt = 1;
    int ans = (s[0] == 'R');
    for (int i = 1; i < sz(s); ++i) {
        if (s[i] == s[i-1]) {
            cnt++;
        } else {
            cnt = 1;
        }
        if (s[i] == 'R') {
            ans = max(ans, cnt);
        }
    }
    cout << ans;        
} 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n(); 
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int calsu(ll n)
{
	int res = 0;
	while(n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	cin>>n;
	set<ll> st;
	fore(i, 1, 10) st.insert(i);
	ll su = 9, nov = 9, mul = 10, ado;
	fore(i, 0, 16)
	{
		ado = 1;
		while(ado * mul + nov <= (su + calsu(ado)) * mul)
		{
			st.insert(nov + mul * ado);
			ado++;
		}
		mul *= 10;
		nov = nov * 10 + 9;
		su += 9;
	}
	//assert(n < 700);
	set<ll>::iterator it = st.begin();
	while(n--)
	{
		cout<<*it<<'\n';
		it++;
	}

	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 384
#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
	long long int n;
	cin>>n;
	long long int arr[n];
	unordered_map<long long int, long long int> u;
	//inserting in an array
	for(long long int i = 0; i < n; i++)
	{
		cin>>arr[i];
	}
	
	//inserting all elements of an array in unordered map
	for(long long int i = 0; i < n; i++)
	{
		if(u.find(arr[i]) != u.end())
		{
			auto it = u.find(arr[i]);
			u[arr[i]]++;
		}
		else
		{
			u.insert({arr[i], 1});
		}
	}
	
	long long int cnt = 0;
	
	for (auto it : u) 
    {
    	long long int data = it.first;
		long long int freq = it.second;
		
		// if condition like [5 5 5 3 3 3 2 2] :in this case 5 comes three times
		//so we need to count all 5 for making it good sequence.
		if(data > freq)
		{
			cnt += freq;	
		}
		else if(data < freq)
		{
			cnt += freq - data;	
		}	
    	
	}
	
	
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 5028
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
string l;
long long md=1000000007,ans=1,cnt=2;
int main()
{
	cin>>l;
	for(int i=0;i<l.size();i++)
	{
		ans*=3;
		ans%=md;
		if(l[i]=='0')
		{
			ans-=cnt;
			ans+=md;
			ans%=md;
		}
		else
		{
			cnt*=2;
			cnt%=md;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int ans=1;
  int N, K;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
  	if((ans*2)>(ans+K)){
      ans+=K;
    }else{
      ans*=2;
    }
  }
  cout << ans << endl;
}


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

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x,n) memset(x,n,sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=l.begin();it!=l.end();it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
const int inf=(1<<30);
const LL llinf=(1ll<<60);
const double eps=(1e-10);
//const double pi=2*acos(0.0);
//const double GOLD=((1+sqrt(5))/2);
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};

/* \( ·w·)~ Clapie ~(·w· )/ */

int n,k;
LL val[100005];
LL memo[100005];

LL dp(int idx){
	if(idx==n-1) return 0;
	if(idx>n) return inf;
	if(memo[idx]!=-1) return memo[idx];
	LL ret=inf;
	for(int i=1;i<=k;i++){
		ret=min(dp(idx+i)+abs(val[idx]-val[idx+i]),ret);
	}
	return memo[idx]=ret;
}

int main(){
	mem(memo,-1);
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&val[i]);
	}
	LL ans=dp(0);
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i) 
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s ;
  stringstream ss;
  ss << s;
  int i;
  ss >> i;
  int sum = 0;
  REP(i,SZ(s)){
    sum += s[i] - '0'; 
  }
  if(i % sum == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
base = long(1e9+7)
mod  = long(2**64-1)

# a x + b y = gcd(a, b)
def extgcd(a, b, x, y):
    g, x, y = a, 1, 0
    if b != 0:
        g, y, x = extgcd(b, a % b, y, x)
        y -= int(a / b) * x
    return [g, x, y];


def invMod(a, m=mod):
    g, x, y = 1, 1, 0
    g, x, y = extgcd(a, m, x, y)
    if g == 1:
        return (x + mod) % mod
    else:
        return 0 #unsolvable

if __name__ == '__main__':
    n, m = map(long, raw_input().split(' '))
    s = raw_input()
    r, l = 1, 0
    vb = [1]
    for i in xrange(n):
        vb.append(long(vb[i]*base)%mod)
        
    inv = invMod(base)
    val = long(ord(s[0]))
    bucket = set()
    for i in xrange(m):
        ss = raw_input()
        if ss == "R++":
            val = (val*base + ord(s[r]))%mod
            r+=1
        elif ss == "R--":
            val = (val + mod - ord(s[r - 1]))%mod
            val = val*inv%mod
            r-=1
        elif ss == "L++":
            val = (val + mod - ord(s[l])*vb[r - l - 1]%mod)%mod
            l+=1
        else:
            val = (val + ord(s[l - 1])*vb[r - l])%mod
            l-=1
        
        bucket.add(val);
        #print ss, s[l:r], val, len(bucket)
    print len(bucket)

Measured memory_bytes: 41172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define has(c,i) (c.find() != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

#define DBG 1
#define TR(X) ({ if(DBG) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;

	vl a(n);

	FOR(i,0,n){
		cin >> a[i];
	}

	sort(all(a));

	double val = a[0];
	FOR(i,1,n){
		val = (a[i] + val) / 2.0;
	}

	cout << val << endl;
}


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

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

int N;
int A[1000010];
int mem[1000010];
int mod = 1000000007;

signed main()
{
    cin >> N;

    mem[0] = 3;
    int ans = 1;
    rep(i, N)
    {
        int a;
        cin >> a;
        ans = ans * mem[a] % mod;
        mem[a]--;
        mem[a + 1]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4316
N,Q = list(map(int,input().split()))
 
e_list = [[] for i in range(N)]
 
for i in range(N-1):
        a,b = list(map(int,input().split()))
        a,b = a-1,b-1
        e_list[a].append(b)
        e_list[b].append(a)
 
add_list = [0]*N
 
for i in range(Q):
        p,x = list(map(int,input().split()))
        p = p-1
        add_list[p]+=x
 
count_list = [0]*N
count_list[0] = add_list[0]
 
vi = 0 #時と場合によってここを変える
from collections import deque
Q = deque([vi])
checked_list = [False for i in range(N)]
checked_list[vi]=True
while len(Q)>0:
    v = Q.pop()
    for v1 in e_list[v]:
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.appendleft(v1)
            count_list[v1] = count_list[v]+add_list[v1]
 
print(*count_list)

Measured memory_bytes: 109132
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
 ll x,y,ans=0;
 cin>>x>>y;
 if(x==1&&y==1)
 {
     ans+=400000;
 }
 if(x==1)
 {
     ans+=300000;
 }
 else if(x==2)
 {
     ans+=200000;
 }
 else if(x==3)
    ans+=100000;
 if(y==1)
 {
     ans+=300000;
 }
 else if(y==2)
 {
     ans+=200000;
 }
 else if(y==3)
    ans+=100000;
 cout<<ans<<endl;
return 0;
}



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

int func(int M, int K) {

  for ( int i = 0; i < K; i++ ) {
    M*=2;
  }
  return M;
}

int main() {
  int A,B,C,K; cin >> A >> B >> C >> K;
  int M = max(A,B);
  int ans;
  M = max(M,C);
  if ( M == A ) {
    ans = func(M,K);
    ans += B;
    ans += C;
  }
  if ( M == B ) {
    ans = func(M,K);
    ans += A;
    ans += C;
  }
  if ( M == C ) {
    ans = func(M,K);
    ans += B;
    ans += A;
  }

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here
	int n,x,i,a[100001],d;
	scanf("%d %d",&n,&x);
	scanf("%d",&a[1]);
	a[1]=a[1]-x;
	if(a[1]<0) a[1]=-a[1];
	for(i=1;i<n;i++) {
		scanf("%d",&a[i+1]);
		a[i+1]=a[i+1]-x;
		if(a[i+1]<0) a[i+1]=-a[i+1];
		while(1){
			if(a[i]%a[i+1]==0) break;
			if(a[i+1]%a[i]==0) {
				a[i+1]=a[i];
				break;
			}
			if(a[i]<a[i+1]){
				d=a[i];
				a[i]=a[i+1];
				a[i+1]=d;
			}
			a[i]=a[i]-a[i+1];
		}
	}
	printf("%d\n",a[n]);
	return 0;
}


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

int main(void){
	int n, k, q;
	scanf("%d %d %d", &n, &k, &q);
	int player[n];
  	int ans[n];
  	for(int i = 0; i < n; i++){
      player[i] = k;
      ans[i] = 0;
    }

	int answer;
	for(int i = 0; i < q; i++){
		scanf("%d", &answer);
        ans[answer-1]++;
    }
      	
    for(int i = 0; i < n; i++){
    	if((player[i] -1*(q-ans[i])) <= 0)
    		printf("No\n");
    	else
    		printf("Yes\n");
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1e9+7;
struct mint {
  typedef long long ll;
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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;
  }
  bool operator>(const mint a) const {
    mint res(*this);
    return res.x > a.x;
  }
  bool operator<(const mint a) const {
    mint res(*this);
    return res.x < a.x;
  }
  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;
  }
};


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

  int n, m; std::cin >> n >> m;
  std::vector<ll> x(n), y(m); 
  rep(i,n) std::cin >> x[i];
  rep(i,m) std::cin >> y[i];
  
  mint Sx = 0, Sy = 0;
  for(int k=0; k<n; k++) {
    mint a = k;     a *= x[k];
    mint b = n-k-1; b *= x[k];
    Sx += (a - b);
  }
  for(int k=0; k<m; k++) {
    mint a = k;     a *= y[k];
    mint b = m-k-1; b *= y[k];
    Sy += (a - b);
  }
  
  mint S = Sx * Sy;
  std::cout << S.x << std::endl;
  return 0;
}


Measured memory_bytes: 1792
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

unordered_map<int,int> ma;
void solve()
{
    int n; cin>>n;
    vector<int> a(n), b;
    rep(i,0,n)
    {
        cin>>a[i];
        b.pb(a[i]);
    }
    sort(all(b));
    rep(i,0,n)
    {
        ma[b[i]] = i;
    }
    int ans = 0;
    rep(i,0,n)
    {
        ans+=abs(i-ma[a[i]])%2;
    }
    ans/=2;
    cout<<ans;    
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5136
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] h = new int[N];
    for (int i = 0; i < N; i++) h[i] = scanner.nextInt();
    int max = 0;
    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      if (h[i] >= h[i + 1]) count++;
      else {
        max = Math.max(max, count);
        count = 0;
      }
    }
    max = Math.max(max, count);
    System.out.println(max);
  }
}


Measured memory_bytes: 50380
from operator import mul
from functools import reduce
import sys

def cmb(n,r):
    r=min(n-r,r)
    if r==0:
        return 1
    over=reduce(mul,range(n,n-r,-1))
    under=reduce(mul,range(1,r+1))
    return over//under

N,P=map(int,input().split())
S=list(map(int,list(input())))

if P==2:
    ans=0
    for i in range(N):
        if S[i]%2==0:
            ans+=i+1
    print(ans)
    sys.exit()

if P==5:
    ans=0
    for i in range(N):
        if S[i]==0 or S[i]==5:
            ans+=i+1
    print(ans)
    sys.exit()


data=[1]*N
for i in range(N-2,-1,-1):
    data[i]=data[i+1]*10%P

data[-1]=data[-1]*S[-1]%P

for i in range(N-2,-1,-1):
    data[i]=(data[i]*S[i]+data[i+1])%P

data.sort()
cnt=1
ans=data.count(0)
for i in range(1,N):
    if data[i]==data[i-1]:
        cnt+=1
    else:
        if cnt>=2:
            ans+=cmb(cnt,2)
        cnt=1
if cnt>=2:
    ans+=cmb(cnt,2)
    
print(ans)

Measured memory_bytes: 61680