akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
#include <unordered_map>
using namespace std;
ifstream fi("zinput.txt");
ofstream fo("output.txt");
#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define ll long long
#define For(i,n) for (int(i) = 0; (i)< (int)(n); (i)++)
#define For1(i,n) for (int(i) = 1; (i) <= (int)(n); (i)++)
#define Forlr(i,l,r) for (int(i) = (int)(l); (i) <= (int)(r); (i)++)
#define Forrl(i,r,l) for (int(i) = (int)(r); (i) >= (int)(l); (i)--)
#define all(a) a.begin(), a.end() 
#define pb push_back
#define pp pop_back
#define mp make_pair
#define PI 3.14159265
#define putno return cout <<"NO", 0;
#define putyes return cout <<"YES", 0;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef map<int, int> mii;
//const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
//DSU
/*
int p[ N], r[N];
void init(int n) {
	For(i, n) {
		p[i] = i;
	}
}
int get(int x) {
	if (p[x] != x) {
		p[x] = get(p[x]);
	}
	return p[x];
}
bool uni(int x, int y) {
	x = get(x); y = get(y);
	if (x == y) {
		return false;
	}
	if (r[x] >= r[y]) {
		p[y] = x;
	}
	else {
		p[x] = y;
	}
	if (r[x] == r[y]) {
		r[x]++;
	}
	return true;
}
*/

// So mu
/*
int power(int x, unsigned int y, int p)
{
	int res = 1; // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
*/

// ReadHexa
/*
bitset<16400> b[4101];
void readHexa()
{
	For(i, n)
	{
		string st;
		cin>> st;
		For(j, m/4)
		{
			int x;
			if (st[j] >= 'A' && st[j] <= 'F')
				x = st[j] - 'A' + 10;
			else x = st[j] - '0';
			for (int k = 4; k; --k, x >>= 1)
				b[i][j * 4 + k] = x & 1;
		}
	}
}
*/

// nChoosek
/*
ll nChoosek(ll n, ll k)
{
	if (k > n) return 0;
	if (k * 2 > n) k = n - k;
	if (k == 0) return 1;

	ll result = n;
	for (ll i = 2; i <= k; ++i) {
		result *= (n - i + 1);
		result /= i;
	}
	return result;
}
*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
MIKUNO - 15/02/1999
*/
int n, m, k, cnt, rs, q;
int x, y;
//	priority_queue <ll, vector<ll>, greater<ll> > q;
//ll n, m, q, k, pos, t, cnt, rs1, check;
ll maxx = -1e9, minn = 1e9;
int ma = -1e9, mi = 1e9;
const int maxn = 2*N;
const ll MOD = 1e9 + 7;
string s;
int t1, t0;
int main()
{
	fast_input();
	cin >> s;
	For(i, s.length())
	{
		if (i & 1)
		{
			if (s[i] == '1') t1++;
			else t0++;
		}
		else
		{
			if (s[i] == '0') t1++;
			else
				t0++;
		}
	}
	cout << min(t1, t0);

}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        int N,M; cin >> N >> M;
        if (N == 0 && M == 0) break;
        vector<bool> A(101),B(101);
        int sumA = 0;
        int sumB = 0;
        rep(i,N) {
            int x; cin >> x;
            A[x] = true;
            sumA += x;
        }
        rep(i,M) {
            int x; cin >> x;
            B[x] = true;
            sumB += x;
        }
        int ans = -1;
        int anso = -1;
        if (abs(sumA-sumB)%2 != 0) {
            cout << ans << endl;
            continue;
        }
        int k = (sumA-sumB)/2;
        rep(i,101) {
            if (!A[i]) continue;
            if (i-k >= 0 && B[i-k]) {
                ans = i;
                anso = i-k;
                break;
            }
        }
        if (ans == -1) cout << ans << endl;
        else cout << ans << " " << anso << endl;
    }
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b<c+d){
		cout<<"Right";
	}else if(a+b>c+d){
		cout<<"Left";
	}else{
		cout<<"Balanced";
	}
}

Measured memory_bytes: 256
mo = 1000000007
n = int(input())
A = [int(s) for s in input().split()]
maxLen = 0
for a in A:
    if a > maxLen:
        maxLen = a
maxLen += 1
memo = [[]for i in range(maxLen)]
for index,a in enumerate(A):
    memo[a].append(index)

def calc(cur,last):
    # ele in cur can choose ele in last which is smaller than it
    # person says i can choose person says i-1 who is in front of him
    # cur and last are naturally increase order
    ans = 1
    minus = 0
    for i in cur:
        count = 0
        for j in last:
            if j < i:
                count += 1
        ans *= count-minus
        minus += 1
    return ans
    # j = 0
    # ans = 1
    # for i in range(len(cur)):
    #     while j < len(last):
    #         if last[j] < cur[i]:
    #             j += 1
    #         else:
    #             break
    #     ans *= (j-i)
    # return ans

memo.append([-1,-1,-1]) # for convenience
ans = 1
for i in range(maxLen):
    ans *= calc(memo[i],memo[i-1])
    ans %= mo
    # if len(memo[i]) == 1:
    #     break

print(ans)

Measured memory_bytes: 21928
a=int(input())
A=list(map(int,input().split()))
ans=1
if A.count(0)==0:
    for x in A:
      ans*=x
      if ans>10**18:
        break


    if ans>10**18:
      print(-1)
    else:
      print(ans)
else:
  print(0)
  

Measured memory_bytes: 21636
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, M = LI()
    A = [0] * (N + 1)
    for _ in range(M):
        A[II()] = 1
    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(1, N + 1):
        if A[i] == 1:
            dp[i] = 0
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD
    ans = dp[N]
    return ans

print(main())

Measured memory_bytes: 7796
# -*- coding: utf-8 -*-
n = int(input())
h = list(reversed(list(map(int, input().split()))))

cnt = 0
for i in range(n-1):
    if h[i+1] - h[i] > 1:
        print('No')
        exit(0)
    elif h[i+1] - h[i] == 1:
        h[i+1] -= 1

print('Yes')


Measured memory_bytes: 20624
#include <stdio.h>

int main(void) {
	char C[2][4];
	if (scanf("%4s", C[0]) != 1) return 1;
	if (scanf("%4s", C[1]) != 1) return 1;
	puts(C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0] ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    if (i != 0) os << ' ';
    os << V[i];
  }
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    is >> V[i];
  }
  return is;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> V(n);
  cin >> V;
  for (int i = 1; i < n; ++i) {
    if (V[i] > V[i - 1]) --V[i];
  }
  for (int i = 1; i < n; ++i) {
    if (V[i] < V[i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
} 


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(it,beg,end) for(__typeof(beg) X=beg,Y=end,it=(X>Y?X-1:X);it!=(X>Y?Y-1:Y);it+=(X>Y?-1:1))
using namespace std;
#define ll long long
#define pb emplace_back
#define mp make_pair
inline void read1(ll &n) {
	char c;n=0;ll x=1;
	while (!isdigit(c=fgetc(stdin))&&c!='-');
	if (c=='-') x=-1, c=fgetc(stdin);
	while (isdigit(c)) n=n*10+c-'0',c=fgetc(stdin);
	n*=x;
}
inline void read1(int &n) {ll x;read1(x);n=x;}
#define read2(a,b) {read1(a);read1(b);}
#define read3(a,b,c) {read1(a);read1(b);read1(c);}
#define read4(a,b,c,d) {read1(a);read1(b);read1(c);read1(d);}
// -------------------- Standard Template --------------------
int n,m,k;
int main() {
	read3(n,m,k);
	rep(i,0,n+1) rep(j,0,m+1) if (i*j+(n-i)*(m-j)==k) {
		printf("Yes");return 0;
	}
	printf("No");
	return 0;
}


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

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

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> f(N+1, 0);
  for(int x = 1; x * x <= N; x++){
    int x2 = x*x;
    for(int y = 1; y * y+x2 <= N; y++){
      int y2 = y*y;
      for(int z = 1; x2 + y2 + z*z <= N; z++){
        int z2 = z * z;
        int sum = x2 + y2 + z2 + x*y + y*z + z*x;
        if(sum > N) continue;
        f[sum]++;
      }
    }
  }
  FOR(i, 1, N+1){
    cout << f[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3592
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    int tc;
    ll now;
    cin >> now;
    set<ll> s;
    s.insert(now);
    if(now == 2) {
        cout << "1" << endl;
        return 0;
    }
    ll chaeng = now - 1;
    ll akar = sqrt(chaeng);
    for(ll a = 2; a <= akar; a++)
    {
        if(chaeng % a == 0)
        {
            s.insert(a);
            s.insert(chaeng/a);
        }
    }
    s.insert(chaeng);
    akar = sqrt(now);
    for(ll a = 2; a <= akar; a++)
    {
        ll tes = now;
        while(tes % a == 0) {
            tes /= a;
        }
        tes--;
        if(tes % a == 0) {
            s.insert(a);
        }
    }
    ans = s.size();
    cout << ans << endl;
    return 0;
}


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

int main () {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  int counta = 0;
  int countb = 0;
  for (int i = 0; i < M; i++) {
    if (A.at(i) < X) counta++;
    else countb++;
  }
  cout << min(counta,countb) << endl;
}

  

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

a,b,c,x,y = [int(i) for i in input().split()]
cost = x * a
while y != 0:
    if x > 0:
        if c * 2 < a + b:
            cost += -a + c*2
            y -= 1
            x -= 1
        else:
            cost += b
            y -= 1
    else:
        if b < c * 2:
            cost += b
            y -= 1
        else:
            cost += c*2
            y -= 1
print(cost)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> row1(n);
  vector<int> row2(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> row1.at(i);
    sum+=row1.at(i);
  }
  for(int i=0;i<n;i++) cin >> row2.at(i);
  sum += row2.at(n-1);
  int tmp = sum;
  for(int j=n-1; j>0; j--){
    tmp=tmp-row1[j]+row2[j-1];
    sum = tmp>sum?tmp:sum;
  }
  cout<<sum<<endl;
}

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

ll dp[1000005][2];

int main() {
  string S;
  cin >> S;
  int slen = S.length();
  dp[slen][1] = 10000000;
  for ( int i=slen-1; i>=0; --i) {
    ll n = S[i] - '0';
    // i桁目は自分が出す場合
    dp[i][0] = min(dp[i+1][0]+n, dp[i+1][1]+n+1);
    // i桁目は自分が出さずお釣りをもらう場合
    dp[i][1] = min(dp[i+1][0]+((10-n)%10), dp[i+1][1]+9-n + ((S[i+1]=='0')?1:0));
  }
  ll ans = min(dp[0][0], dp[0][1]+1);
  cout << ans << endl;

//  REP(i,3) cout << " " << dp[i][0] ;
//  cout << endl;
//  REP(i,3) cout << " " << dp[i][1];
//  cout << endl;
}


Measured memory_bytes: 17028
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#define MX 200005
#define MOD 1000000007

using namespace std;

typedef long long ll;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

ll qpow(ll x, ll t)
{
	ll ans = 1;
	while(t)
	{
		if(t & 1) ans = ans * x % MOD;
		x = x * x % MOD;
		t >>= 1;
	}
	return ans;
}

ll inv(ll x)
{
	return qpow(x, MOD-2);
}

ll fac[MX], faci[MX];

void init()
{
	fac[0] = 1;
	for(int i=1; i<MX; i++) fac[i] = fac[i-1] * i % MOD;
	faci[MX-1] = inv(fac[MX-1]);
	for(int i=MX-1; i>=1; i--) faci[i-1] = faci[i] * i % MOD;
}

ll C(int x, int y)
{
	return fac[x] * faci[y] % MOD * faci[x-y] % MOD;
}

int main()
{
	init();
	ll n, a, b, c;
	ll ans = 0;
	cin >> n >> a >> b >> c;
	c = c * inv(100) % MOD;
	ll pa = a * inv(a+b) % MOD, pb = b * inv(a+b) % MOD;
	for(int i=n; i<n*2; i++)
	{
		ans = (ans + qpow(pa, n) * qpow(pb, i-n) % MOD * C(i-1, n-1) % MOD * inv(MOD+1-c) % MOD * i % MOD) % MOD;
		ans = (ans + qpow(pb, n) * qpow(pa, i-n) % MOD * C(i-1, n-1) % MOD * inv(MOD+1-c) % MOD * i % MOD) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ll h,w;
  cin >> h >> w;
  if(h%3==0 || w%3==0){
    cout << 0 << endl;
    return 0;
  }
  ll ans = h*w;
  ll s1,s2,s3;
  ll a=h/2;
  ll b=h-a;
  rep1(i,w-1){
    s1=a*i;
    s2=b*i;
    s3=(w-i)*h;
    ll t=max(max(abs(s1-s2),abs(s2-s3)),abs(s3-s1));
    ans = min(t,ans);
  }
  swap(h,w);
  a=h/2;
  b=h-a;
  rep1(i,w-1){
    s1=a*i;
    s2=b*i;
    s3=(w-i)*h;
    ll t=max(max(abs(s1-s2),abs(s2-s3)),abs(s3-s1));
    ans = min(t,ans);
  }
  a=h/3;b=(h-a)/2;
  ll c=h-a-b;
  ans=min((c-a)*w,ans);
  swap(h,w);
  a=h/3;b=(h-a)/2;
  c=h-a-b;
  ans=min((c-a)*w,ans);

  
  cout << ans << endl;
  


  

  return 0;

}


Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
Ts = list(set([int(input()) for _ in range(N)]))

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

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

res = Ts[0]
for T in Ts:
    res = lcm(res, T)
print(int(res))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
     string A="ABC";
     string B="ARC";
     string C="AGC";
     int R;
     cin>>R;
     if(R>=0&&R<1200)
        cout<<A;
     else if(R>=1200&&R<2800)
        cout<<B;
     else if(R>=2800&&R<=4208)
        cout<<C;
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (d == 1) cout << "1\n";
	else cout << "0\n";



	return 0;
}


Measured memory_bytes: 888
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long x = 0;
      for(long i = (long)Math.sqrt(n);i > 0;i--){
      	if(n%i==0){
        	x = n/i;
          break;
        }
      }
      System.out.println(String.valueOf(x).length());
    }
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n;

int main(){
	cin >> n;
	cout << 48-n << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef double db;
const int N=1e5+10;
int n,m,tot,st,d[N],x,id[N],nt[N],K,ans[N],q[N],cnt,vs[N],p[N];
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)scanf("%lld",&p[i]);
	for (int i=2;i<=n;i++)d[i]=p[i]-p[i-1],id[i]=i;
	scanf("%lld%lld",&m,&K);
	for (int i=1;i<=m;i++){
		scanf("%lld",&x);
		swap(id[x],id[x+1]);
	}
	for (int i=2;i<=n;i++) nt[id[i]]=i;
	for (int i=2;i<=n;i++)
		if (!vs[i]){
			int cnt=0;
			for (int j=i;!vs[j];j=nt[j]){
				q[++cnt]=j;
				vs[j]=1;
			}
			x=K%cnt;int k=x%cnt+1;
			for (int j=1;j<=cnt;j++){
				ans[q[k]]=d[q[j]];
				k=k==cnt?1:(k+1);
			}
		}
	double pos=p[1];
	for (int i=1;i<=n;i++){
		pos+=ans[i];
		printf("%.10lf\n",(db)pos);
	}
	return 0;
}

Measured memory_bytes: 7808
h, w = map(int, input().split())
As = [input() for _ in range(h)]

Bs = []
for a in As:
    if "#" in a:
        Bs.append(a)

Cs = list(map(list, zip(*Bs)))
Ds = []
for c in Cs:
    if "#" in c:
        Ds.append(c)

ret = list(map(list, zip(*Ds)))
for x in ret:
    print(*x, sep="")

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

using namespace std;

using ll = long long;

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

    int a, b, c, x, y;

    cin >> a >> b >> c >> x >> y;
    if (a + b <= 2 * c)
        cout << a * x + b * y << endl;
    else {
        int n = min(x, y), m = max(x, y);
        cout << min(2 * n * c + a * (x - n) + b * (y - n), 2 * m * c) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))
Graph=[[] for i in range(N)]
isGood = [1]*N
for i in range(M):
  a,b=map(int,input().split())
  Graph[a-1].append(b)
  Graph[b-1].append(a)
# print(Graph)
for i in range(N):
  for j in Graph[i]:
    if H[i]<=H[j-1]:
      isGood[i]=0
# print(H)
print(sum(isGood))

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

using namespace std;

int frog1dp(int h[], int n){
    int mindp[n + 1];
    mindp[0] = 0;
    mindp[1] = 0;
    mindp[2] = abs(h[2]-h[1]);
    for(int i = 3; i <= n; i++){
        mindp[i] = min(mindp[i-1] + abs(h[i] - h[i-1]), mindp[i-2] + abs(h[i] - h[i - 2]));
    }
    return mindp[n];
}


int main(){
    int n;
    scanf("%d\n", &n);
    int h[n+1];
    h[0] = 0;
    for(int i = 1; i <= n; i++){
        scanf("%d", &h[i]);
    }
    printf("%d", frog1dp(h, n));
}


Measured memory_bytes: 4620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int dp[3010][6010];

int main(){
    int n,t; cin >> n >> t;
    vector<Pi> ab(n);
    rep(i,n) cin >> ab[i].first >> ab[i].second;
    sort(ab.begin(),ab.end());
    rep(i,n)rep(j,t){
        dp[i+1][j+ab[i].first] = max(dp[i+1][j+ab[i].first],dp[i][j]+ab[i].second);
        dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans,dp[i][t-1]+ab[i].second);
    }
    cout << ans << endl;
}


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

using namespace std;

int main()

{
    long long int n,i,ara[105]={0},coun[105]={0},j,k,ans=0;
    vector<long long int>v;
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&ara[i]);
    }
    sort(ara,ara+n);
    v.push_back(ara[0]);
    coun[0]=1;
    for(i=1;i<n;i++){
        if(ara[i]!=ara[i-1]){
            v.push_back(ara[i]);
            coun[v.size()-1]=1;
        }
        else{
             coun[v.size()-1]++;
        }
    }
    /*
     for(i=0;i<v.size();i++){
        cout<<coun[i]<<" "<<v[i]<<endl;
    }
    */
    if(v.size()<3){
        ans=0;
    }
    else{
    for(i=0;i<v.size()-2;i++){
        for(j=i+1;j<v.size()-1;j++){
            for(k=j+1;k<v.size();k++){
                    if(v[i]+v[j]>v[k])
                ans+=coun[i]*coun[j]*coun[k];
            }
        }
    }

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

Measured memory_bytes: 3692
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    h = tuple(geta(int))

    ans = 0

    cur = 0
    for i in range(n - 1):
        if h[i] >= h[i + 1]:
            cur += 1
            if cur > ans:
                ans = cur
        else:
            cur = 0

    print(ans)


if __name__ == "__main__":
    main()

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

const string vowels = "aoeiu";

int main() {
    int n;
    string name[100];
    string code[100];
    while (true) {
        cin >> n;
        if (n == 0) { break; }
        for (int j = 0; j < n; ++j) {
            cin >> name[j];
        }
        int lim = 0;
        for (int j = 0; j < n; ++j) {
            code[j] = name[j].substr(0,1);
            for (int k = 0; k < name[j].size()-1; ++k) {
                if (vowels.find(name[j].substr(k,1)) != -1) {
                    code[j].push_back(name[j][k+1]);
                }
            }
            lim = max(lim, (int)code[j].size());
        }
        int val = -1;
        for (int k = 1; k <= lim; ++k) {
            bool success = true;
            for (int x = 0; x < n; ++x) {
                for (int y = 0; y < n; ++y) {
                    if (x == y) { continue; }
                    if (code[x].substr(0,k) == code[y].substr(0,k)) {
                        success = false;
                        break;
                    }
                }
                if (!success) { break; }
            }
            if (success) {
                val = k;
                break;
            }
        }
        cout << val << endl;
    }
    return 0;
}

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

int n;
long long int a[5] = {0, 0, 0, 0, 0};

int main(){
  cin >> n;
  rep(i, n){
    string s;
    cin >> s;
    char c = s.at(0);
    if(c == 'M'){
      a[0]++;
    }else if(c == 'A'){
      a[1]++;
    }else if(c == 'R'){
      a[2]++;
    }else if(c == 'C'){
      a[3]++;
    }else if(c == 'H'){
      a[4]++;
    }
  }
  long long int ans = 0;
  ans += a[0] * a[1] * a[2];
  ans += a[0] * a[1] * a[3];
  ans += a[0] * a[1] * a[4];
  ans += a[0] * a[2] * a[3];
  ans += a[0] * a[2] * a[4];
  ans += a[0] * a[3] * a[4];
  ans += a[1] * a[2] * a[3];
  ans += a[1] * a[2] * a[4];
  ans += a[1] * a[3] * a[4];
  ans += a[2] * a[3] * a[4];
  
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const ll MOD = 1e9+7;

bool check(string last, char c){
    bool ret = true;
    if(c == 'T') ret = true;
    else if(c == 'C'){
        if(last[1] == 'G' && last[2] == 'A') ret = false;
        if(last[1] == 'A' && last[2] == 'G') ret = false;
        if(last[0] == 'A' && last[1] == 'G') ret = false;
        if(last[0] == 'A' && last[2] == 'G') ret = false;
    }
    else if(c == 'G'){
        if(last[1] == 'A' && last[2] == 'C') ret = false;
    }
    //else if(c == 'A'){
    //    if(last[1] == 'C' && last[2] == 'G') ret = false;
    //}
    return ret;
}

int N;
map<pair<int, string>, ll> memo;

void dfs(int v, string last){
    if(v == N){
        memo[make_pair(v, last)] = 1;    
        return;
    }
    ll ret = 0;
    if(check(last, 'A')){
        string next = last;
        next.erase(next.begin());
        next += 'A';
        auto p = make_pair(v+1, next);
        if(memo[p] == 0)
            dfs(v+1, next);
        ret += memo[p];
        ret %= MOD;
    }
    if(check(last, 'G')){
        string next = last;
        next.erase(next.begin());
        next += 'G';
        auto p = make_pair(v+1, next);
        if(memo[p] == 0)
            dfs(v+1, next);
        ret += memo[p];
        ret %= MOD;
    }
    if(check(last, 'C')){
        string next = last;
        next.erase(next.begin());
        next += 'C';
        auto p = make_pair(v+1, next);
        if(memo[p] == 0)
            dfs(v+1, next);
        ret += memo[p];
        ret %= MOD;
    }
    if(check(last, 'T')){
        string next = last;
        next.erase(next.begin());
        next += 'T';
        auto p = make_pair(v+1, next);
        if(memo[p] == 0)
            dfs(v+1, next);
        ret += memo[p];
        ret %= MOD;
    }

    memo[make_pair(v, last)] = ret;
}

int main(){
    cin >> N;
    dfs(0, "TTT");
    ll ans = memo[make_pair(0, "TTT")];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    string s;
    cin>>s;
    if(s[s.size()-1]=='s')cout<<s+"es"<<endl;
    else cout<<s+"s"<<endl;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	ll ne = 0;
	ll no = 0;
	ll n;
	cin >> n;
	rep(i, n){
		int d;
		cin >> d;
		if(d&1)++no;
		else ++ne;

	}

	if(ne*no==0){
		cout << 0 << endl;
		return 0;
	}

	int ans = 0;
	
	bool flag = true;
	while(flag){
		flag = false;
		if(ne>=2){
			++ans;
			--ne;
			flag = true;
		}
		if(no>=3){
			++ans;
			++ne;
			no -= 2;
			flag = true;
		}
	}

	cout << ans + 1 << endl;


	return 0;
}



Measured memory_bytes: 3096
<?php


  $s = trim(fgets(STDIN));
  $s = str_replace(array("\r\n","\r","\n"), '', $s);
  $s = explode(" ", $s);
  
  $answer = '';

for ($i = 0; $i <= $s[0]; $i++) {
    for ($j = 0; $i + $j <= $s[0]; $j++){
        $k = $s[0] - $i - $j;
        if ($s[1] == $i * 10000 + $j * 5000 + $k * 1000) {
            $answer = $i . ' ' . $j . ' ' . $k;
            break;
        }
    }
    if ($answer != '') {
        break;
    }
}

if ($answer == ''){
    echo '-1 -1 -1';
} else {
    echo $answer;
}


Measured memory_bytes: 16264
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second

/* STL */
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a)   reverse(a.begin(),a.end())
/* loops */
#define fa(i, a, b) for (auto (i) = (a); (i) < (b); ++(i))
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n) i=1;i<=(n);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";
vector<ll>v;
bool checker(ll n){
  while(n){
    for(auto i:v){
      if(i==n%10)
        return true;
    }
    n/=10;
  }

  return false;
}
int main()
{

   Ezio
   ll t,m,n,x,a,b;
   string s;

   cin>>m>>n;
   v.resize(n);
   fr(i,n)cin>>v[i];

   while(checker(m)) m++;
   cout<<m<<endl;
   return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <iomanip>
#define fi(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define imax INT_MAX
#define imin INT_MIN
#define lmin LONG_LONG_MIN
#define lmax LONG_LONG_MAX
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define st first
#define nd second

using namespace std;
typedef long long ll;
int f(int n){
    int k = 0;
    while(n > 0){
        k += n%10;
        n /= 10;
    }
    return k;
}
int main()
{
    int n;
    cin >> n;
    if(n % f(n) == 0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;

  vector<ll> s(A), t(B);
  rep (i, A) cin >> s[i];
  rep (i, B) cin >> t[i];

  sort(all(s));
  sort(all(t));

  rep (i, Q) {
    ll x;
    cin >> x;

    vector<ll> ss, tt;
    int p;
    p = lower_bound(all(s), x) - s.begin();
    if (p != sz(s)) ss.eb(s[p]);
    if (p != 0) ss.eb(s[p - 1]);
    p = lower_bound(all(t), x) - t.begin();
    if (p != sz(t)) tt.eb(t[p]);
    if (p != 0) tt.eb(t[p - 1]);

    ll ans = INF;
    rep (i, sz(ss)) rep (j, sz(tt)) {
      if (ss[i] <= x && tt[j] <= x) ans = min(ans, max(x - ss[i], x - tt[j]));
      else if (x <= ss[i] && x <= tt[j]) ans = min(ans, max(ss[i] - x, tt[j] - x));
      else ans = min(ans, min(2 * abs(ss[i] - x) + abs(tt[j] - x), abs(ss[i] - x) + 2 * abs(tt[j] - x)));
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

int main(){
    ll N;
    cin >> N;
    ll a[N];
    cin >> a[0];
    for(int i = 1; i < N; i++){
        ll b;
        cin >> b;
        a[i] = a[i-1] + b;
    } 
    ll ans = INF;
    for(int x = 1; x <= N-1; x++){
        ans = min(ans,abs(a[x-1]-(a[N-1]-a[x-1])));
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353

int lowbit(int x) {return x&(-x);}

int n,m;
vector <int> edge[100010];
bool vis[100010];
vector <int> node;
int f[100010];

void dfs(int x) {
	if (vis[x]) return;
	for (int i=0;i<edge[x].size();i++) dfs(edge[x][i]);
	vis[x]=true;
	node.pb(x);
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		edge[x].pb(y);
	}
	for (int i=0;i<n;i++) dfs(i);
	reverse(node.begin(),node.end());
	int ans=0;
	for (int i=0;i<n;i++) 
		for (int j=0;j<edge[node[i]].size();j++) {
			int to=edge[node[i]][j];
			f[to]=max(f[to],f[node[i]]+1);
			ans=max(ans,f[to]);
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8056
#include <iostream>
using namespace std;
int main(void)
{
  int route[4];
  int minute=0, second=0;

  for(int i = 0 ; i < 4 ; i++) {
    cin >> route[i];
    second += route[i];
  }
  while(second >= 60) {
    minute += 1;
    second -= 60;
  }
  cout << minute << endl << second << endl;
  return 0;
}

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

typedef long long ll;

int main () {
    string a,b,c;
    cin >> a >> b >> c;
    if( a[a.size()-1] == b[0] and b[b.size()-1] == c[0] )
	cout << "YES" << endl;
    else
	cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");

inline ll ceil(ll a,ll b)
{
  return (a+b-1)/b;
}

const ll N=2e5+5;

list<ll>adj[N];
ll p=1e9+7;
ll n,sz[N],in[N],out[N],fac[N];


ll pow_mod_p(ll a,ll b)
{
  a=a%p;
  ll res=1;
  while(b>0)
  {
    if(b&1) res=(res*a)%p;
    b=b>>1;
    a=(a*a)%p;
  }
  return res;
}


ll ext_gcd(ll a,ll b,ll &x,ll &y)
{
  if(b==0)
  {
    x=1;
    y=0;
    return a;
  }
  ll x1,y1;
  ll d=ext_gcd(b,a%b,x1,y1);
  x=y1;
  y=x1-(a/b)*y1;
  return d;
}


// when a and m are co-prime
ll mod_inv(ll a,ll m=p)
{
  ll x,y;
  ext_gcd(a,m,x,y);
  x=(x%m + m) % m;
  return x;
}

ll nCr(ll x,ll y)
{
  ll res=1;
  ll z=(mod_inv(fac[y]) * mod_inv(fac[x-y]) )%p;
  res=(fac[x]*z)%p;
  return res;
}



ll dfs1(ll v,ll pv)
{
  sz[v]++;
  for(auto i:adj[v])
  {
    if(i==pv) continue;
    dfs1(i,v);
    sz[v]+=sz[i];
  }
  if(sz[v]==1) return in[v]=1;
  
  ll x=sz[v]-1,res=1;
  for(auto i:adj[v])
  {
    if(i==pv) continue;
    ll y=sz[i];
    ll temp=(nCr(x,y)*in[i])%p;
    res=(res*temp)%p;
    x-=y;
  }
  return in[v]=res;
}


void dfs2(ll v,ll pv)
{
  for(auto i:adj[v])
  {
    if(i==pv) continue;
    ll res=1;

    ll y=(nCr(sz[v]-1,sz[i])*in[i])%p;
    y=mod_inv(y);
    y=(in[v]*y)%p;

    ll z=nCr(n-1-sz[i],sz[v]-1-sz[i]);
    z=(z*out[v])%p;
    res=(z*y)%p;
    out[i]=res;
    dfs2(i,v);
  }
}

void func()
{ 
  fac[0]=1;
  f(i,1,N) fac[i]=(fac[i-1]*i)%p;
  out[1]=1;
  cin>>n;
  f(i,0,n-1)
  {
    ll u,v;
    cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
  }

  ll ans=0;
  dfs1(1,0);
  dfs2(1,0);
  f(i,1,n+1)
  {
    ll x=(nCr(n-1,sz[i]-1)*in[i])%p;
    x=(x*out[i])%p;
    cout<<x<<endl;
  }
} 

int main() 
{
    //fast
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/
    
    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
 
    return 0;
}

Measured memory_bytes: 25728
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N,T,sum=0;
        N=sc.nextInt();
        T=sc.nextInt();
        int [] list = new int[N];
        for(int a=0;a<N;a++){
            list[a] = sc.nextInt();
            }
            for(int a=1;a<N;a++){
            if(list[a]-list[a-1]<=T)sum+=list[a]-list[a-1];
            else sum+=T;
            }
    sum+=T;
        System.out.println(sum);
         }
}

Measured memory_bytes: 64060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    int N;
    scanf("%d", &N);
    long *H;
    H = (long *)calloc(N, sizeof(long));
    for(int i=0; i<N; i++)
        scanf("%ld", &H[i]);
    int *ans;
    ans = (int*)calloc(N, sizeof(int));
    int j=0;
    for(int i=0; i<N;){
        i=j;
        int count=0;
        while(H[j]>=H[j+1]){
            if(j==N-1)break;
            j++;
            count++;
        }
        ans[i]=count;
        if(count>=N-i)break;
        j+=1;
    }
    int max=ans[0];
    for(int i=0; i<N; i++){
        if(ans[i]>max)
            max = ans[i];
    }
    printf("%d\n", max);
    free(ans);
    free(H);
    return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
 
 
using namespace std;
 
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
 
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
#define int long long
#define left left228
#define right right228
#define prev prev228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second

const int N = 505;

char a[N][N], blue[N][N], red[N][N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> a[i][j];
            red[i][j] = blue[i][j] = '.';
        }
    }
    for (int i = 1; i <= n; ++i) {
        red[i][m] = '#';
        blue[i][1] = '#';
    }
    for (int j = 2; j <= m - 1; ++j) {
        for (int i = 2; i <= n - 1; ++i) {
            if (i & 1) {
                red[i][j] = '#';
                if (a[i][j] == '#') {
                    blue[i][j] = '#';
                }
            } else {
                blue[i][j] = '#';
                if (a[i][j] == '#') {
                    red[i][j] = '#';
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << red[i][j];
        }
        cout << '\n';
    }
    cout << '\n';
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << blue[i][j];
        }
        cout << '\n';
    }
    return 0;
}

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

int main(){
    ll N;cin>>N;
    ll info[N];
    rep(i,N){
        cin>>info[i];
        info[i]-=i;
    }
    sort(info,info+N);
    ll a=info[N/2];
    ll ans;
    rep(i,N)ans+=abs(a-info[i]);
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
const int N = 100000 + 10, inf = 0x3f3f3f3f;
typedef long long ll;
int a[N];
int ans[110][110];
int main()
{
    int n, h, w;
    cin>>h>>w>>n;
    for(int i = 1; i<=n; i++)
        scanf("%d", &a[i]);
        int l = 1, r = 1;
    int flag = 1;
    for(int i = 1; i<=n; i++)
    {
        for(int j = 1; j<=a[i]; j++){
            ans[l][r] = i, r += flag;
            if(r > w || r < 1){
                l++,flag = -flag;
                r+=flag;
            }
        }
    }
    for(int i = 1; i<=h; i++)
    {
        for(int j = 1; j<=w; j++){
            printf("%d", ans[i][j]);
            if(j==w)
                puts("");
            else printf(" ");
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
int main(){
    int n,d[2];
    cin >> n;
    int zoro=0,zoromax=0;
    rep(i, n){
        cin >> d[0] >> d[1];
        if(d[0]==d[1]){
            zoro++;
            zoromax=max(zoromax,zoro);
        } else {
            zoro=0;
        }
    }
    if(zoromax>=3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
// #pragma GCC optimization ("O3,unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
using namespace std;

int N, K; 
vector<int> p, c;
vector<bool> vis;
vector<int64_t> found;

void dfs(int s, int64_t count = 0) {
    if (vis[s] == 1) return;
    vis[s] = 1;
    count += c[s];
    found.emplace_back(count);
    dfs(p[s], count);
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> K;
    p.resize(N);
    c.resize(N);
    vis.resize(N);
    for (auto &it : p) cin >> it, it--;
    for (auto &it : c) cin >> it;
    int64_t ans = INT64_MIN;
    for (int i = 0; i < N; i++) {
        fill(vis.begin(), vis.end(), 0);
        dfs(i);
        int nodes = found.size();
        int64_t cycles = K / nodes, rem = K % nodes, sum = 0, mxe = 0;
        if (found.back() > 0 && K > nodes) {
            sum = cycles * found.back();
            if (rem > 0) mxe = *max_element(found.begin(), found.begin() + rem);
            if (mxe > 0) sum += mxe;
            mxe = *max_element(found.begin(), found.end());
            sum = max(sum, (cycles - 1) * found.back() + mxe);
        } else {
            sum = *max_element(found.begin(), found.begin() + min(K, nodes));
        }
        ans = max(ans, sum);
        found.clear();
    }
    cout << ans;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    int x;
    cin >> x;
    a[x-1]++;
  }
  sort(a.begin(),a.end());
  vector<int> s(n+1); // sum of [0,i)
  rep(i,n) s[i+1] = s[i]+a[i];
  for (int k = 1; k <= n; ++k) {
    int l = 0, r = n/k+1; // l:OK, r:NG
    while (l+1 < r) {
      int c = (l+r)/2;
      bool ok = [&](int c) {
        int i = lower_bound(a.begin(), a.end(), c) - a.begin();
        int sum = c*(n-i) + s[i];
        return (sum >= c*k);
      }(c);
      if (ok) l = c; else r = c;
    }
    printf("%d\n", l);
  }
  return 0;
}


Measured memory_bytes: 3200
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] chars = S.toCharArray();
        int zeroNum = 0;
        int oneNum = 0;
        for (char ch : chars) {
            if (ch == '0') {
                zeroNum++;
            }
            else {
                oneNum++;
            }
        }
        int min = Math.min(zeroNum, oneNum);
        int ans = min * 2;
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

}

Measured memory_bytes: 26312
#include<iostream>
using namespace std;
int main()
{
    int n, a, b, c, d, i, j, team[100], score[100];
    cin >> n;
    for (i = 1; i <= n; i++) {
        team[i] = 0;
    }
    for (i = 0; i < n*(n - 1) / 2; i++) {
        cin >> a >> b >> c >> d;
        if (c > d)
            team[a] += 3;
        else if (c < d)
            team[b] += 3;
        else {
            team[a]++;
            team[b]++;
        }
    }
    for(i=1;i<=n;i++){
        score[i] = 1;
        for (j = 1; j <= n; j++) {
            if (team[i] < team[j]) 
                score[i]++;
        }
    }
    for (i = 1; i <= n; i++) {
        cout << score[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include <cstdio>

int main() {
    int N, p, sum=0, max=0;
    scanf("%d",&N);
    for (int i=0; i<N; i++) {
        scanf("%d", &p);
        sum += p;
        if (p > max) max = p;
    }
    printf("%d\n",sum-max/2);
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll d ; cin >> d ;
	vll c(26) ;
	for(auto &i:c) cin >> i ;
	vvll di(d,vll(26)) ;
	for(int i=0;i<d;i++) for(int j=0;j<26;j++) cin >> di.at(i).at(j) ;
	vll last(26,-1) ;
	for(int i=0;i<d;i++) cout << 1 << "\n" ;
}




Measured memory_bytes: 3720
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

map<int, int> gMap;
const int mod = 1000000007;

long long calcPattern(int max, int current, vector<int>& vBreak)
{
	if (gMap.find(current) != gMap.end())
	{
		return gMap[current];
	}

	if (find(vBreak.begin(), vBreak.end(), current) != vBreak.end())
	{
		// 踏み抜いた
		return 0;
	}
	if (max <= current)
	{
		if (max < current)
		{
			// 行き過ぎ
			return 0;
		}
		// たどり着けた
		return 1;
	}

	long long num = calcPattern(max, current + 1, vBreak) + calcPattern(max, current + 2, vBreak);
	gMap.insert(make_pair(current, num % mod));
	return gMap[current];
}

int main() {

	int N, M;
	cin >> N >> M;
	vector<int> vBreak(M, 0);
	for (int i = 0; i < M; i++)
	{
		cin >> vBreak[i];
	}

	long long result = calcPattern(N, 0, vBreak);

	cout << result << endl;
	
	return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
int main(void)
{
	int N,X=0,Y=0;
	int V[101];
	int C[101];

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &V[i]);
	}

	for (int i = 0; i < N; i++) {
		scanf("%d", &C[i]);
	}

	for (int i = 0; i < N; i++) {
		if (V[i] > C[i]) {
			X += V[i];
			Y += C[i];
		}
	}
	printf("%d", X - Y);

	return 0;

}

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

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


int N, X;
int L[110];

int main(){

    cin >> N >> X;
    for(int i = 0; i < N; i++) cin >> L[i];
    int l = 0;
    int cnt = 1;
    for(int i = 0; i < N; i++){
        l += L[i];
        if(l <= X) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


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

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
    
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin >> k;
  cout << a[k-1] << '\n';

  return 0;
}


Measured memory_bytes: 256