akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long N, K, V[100009]; cin >> N >> K;
	long item[100009] = {};
	for (int i = 0; i < N; i++) cin >> V[i];
	for (long myK = 0; myK <= K; myK++){
		for (int k = 0; k <= min(N, myK); k++){//合計k個取り出す。
			if (myK - k > k) continue; //(もどす > とりだす)

			for (int l = 0; l <= k; l++) {//左からl個取り出して、右からk - l個取り出す。
				for (int i = 0; i < l; i++) item[i] = V[i];
				for (int i = l; i < k; i++) item[i] = V[N - 1 + l - i];
				sort(item, item + k);
				for (int i = 0; i < myK - k; i++) item[i] = 0;
				res = max(res, accumulate(item, item + k, (long)0));
			}
		}
	}
	cout << res << endl;
}

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

int main(){
	int n, T, t0;
	scanf("%d%d%d", &n, &T, &t0);
	int an = T;
	f(i, 1, n){
		int t;
		scanf("%d", &t);
		an += min(T, t - t0);
		t0 = t;
	}
	printf("%d\n", an);
}

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

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    rep(i,n){
        if(((i+1)%5)==0) continue;
        if(((i+1)%3)==0) continue;
        //cout << i+1 << endl;
        sum+=i+1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main() {
    long long int n, m=1, c=0;
    cin >> n;
    while(true) {
        if(n==1) {
            c += m;
            break;
        } else {
            n /= 2;
            c += m;
            m *= 2;
        }
    }
    cout << c << endl;
}

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

int N,M,Q;
vector<int> a,b,c,d;
int ans=0;

void dp(vector<int> A)
{
    if(A.size()==N+1){
        int now=0;
        rep(i,Q){
            if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
        }
        ans=max(ans,now);
        return;
    }
    A.push_back(A.back());
    while(A.back()<=M){
        dp(A);
        A.back()++;
    }
}

int main()
{
    cin >> N >> M >> Q;
    a=b=c=d=vector<int>(Q);

    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dp(vector<int>(1,1));
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,K;
    cin>>N>>K;
    if(K==1) cout<<0<<endl;
    else cout<<N-K<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[10001],*p,*q;
	while(scanf("%s",s)>0)
	{
		int j=0,i=0,d;
		if(strlen(s)>2)for(p=s+1;*p;p=q+1)
		{
			if(!(q=strstr(p,"OI")))break;
			if(q)(q[-1]-'J'?(q[-1]-'I'?d:i):j)++;
		}
		printf("%d\n%d\n",j,i);
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque
h,w=(int(i) for i in input().split())
#print(h,w)

a=[[i for i in input()] for j in range(h)]
#print(a)

cnt=0
ans=0
black=deque([])
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            cnt+=1
            black.append((i,j))
dy=deque([1,0,-1,0])
dx=deque([0,1,0,-1])
#print(black)
#print(cnt)

while cnt<h*w:
    for i in range(len(black)):
        data=black.popleft()
        for j in range(4):
            if 0<=data[0]+dy[j]<h and 0<=data[1]+dx[j]<w:
                if a[data[0]+dy[j]][data[1]+dx[j]]=='.':
                    a[data[0]+dy[j]][data[1]+dx[j]]='#'
                    cnt+=1
                    black.append((data[0]+dy[j],data[1]+dx[j]))
    ans+=1
    
print(ans)

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

struct Edge{ int to, id;};

vector<vector<Edge> > g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1){
    int k = 1;
    rep(i,g[v].size()){
        int u = g[v][i].to, ei = g[v][i].id;
        if(u == p) continue;
        if(k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u, ans[ei], v);
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    ans = vector<int>(n-1);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i,n-1){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000007

int main() {
	string s;
	cin >> s;
	int ans = INF;
	vector<int>m;
	char a = s[0];
	for (int i = 1; i < s.size(); i++) {
		if (a != s[i]) {
			m.push_back(max(i, (int)s.size() - i));
			a = s[i];
		}
	}
	rep(i, m.size())
		ans = min(m[i], ans);
	if (ans == INF)
		ans = s.size();
	cout << ans;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n=s.size();
    int count=0;
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1]){count++;}
    };
    cout<< count;
    return 0;
}

Measured memory_bytes: 256
import sys
import re
N,K = map(int,input().split())
S = input()

if not ( 1 <= N <= 50 and 1 <= K <= N ): sys.exit()
if len(re.findall(r'[^(A|B|C)]',S)) != 0 : print("NG");sys.exit()

res = []
for I in range(len(list(S))):
    res.append(S[I]) if I + 1 != K else res.append(S[I].lower())
print(''.join(res))

Measured memory_bytes: 9824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

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

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

int main() {
    int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void B();

int main()
{
	B();
	fflush(stdout);
	return 0;
}

static void B()
{
	int A, B, C, K;
	get(A, B, C);
	get(K);

	while (K--) {
		if (B <= A) {
			B *= 2;
		}
		else if (C <= B) {
			C *= 2;
		}
	}
	if (B > A && C > B) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}


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

#define LLINF (1LL<<60)
typedef long long ll;

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

//C++14 (GCC 5.4.1)
int main() {
    int N,L;
    cin >>N>>L;

    //-----------------------------------
    bool is=false;
    int exiti,ans=0;

    if(0<L){
        exiti=0;
    }else if(L<=-N){
        exiti=N-1;
    }else{
        exiti=-L;
    }
    rep(i,N){
        if(i!=exiti) ans+=L+i;
    }

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

Measured memory_bytes: 256
from sys import stdin

def partition(A, p, r):
    val = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= val:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i+1], A[r] = A[r], A[i+1]
    return i+1

n = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
res = partition(A, 0, len(A)-1)
A[res] = [A[res]]
print(*A)


Measured memory_bytes: 16364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

void solve() {
  ll N;
  cin >> N;
  rep3(h, 1, 3501) rep3(n, 1, 3501) {
    ll bo = 4LL * h * n - N * (h + n);
    if (bo == 0) continue;
    ll si = N * h * n;
    if (si % bo != 0) continue;
    ll w = si / bo;
    if (w <= 0) continue;
    cout << h << " " << n << " " << w << endl;
    return;
  }
}


Measured memory_bytes: 256
def main():
    import numpy as np
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    b = np.array(a + [a[-1]+k-a[-1]+a[0]])
    c = np.diff(b)
    ans = sum(c) - max(c)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 34136
s = input()
S = s[2:-1]
if s[0]=='A' and S.count('C')==1 and s[1:s.index('C')].lower()==s[1:s.index('C')] and s[s.index('C')+1:].lower()==s[s.index('C')+1:]:
  print('AC')
else:
  print('WA')

Measured memory_bytes: 3060
N = int(input())

from collections import defaultdict
dic = defaultdict(int)

for i in range(1, N + 1):
  s = str(i)
  dic[(s[0], s[-1])] += 1

ans = 0
for key in dic.keys():
  a,b = key
  if (b,a) in dic:
    ans += dic[(a,b)] * dic[(b,a)]
  
print(ans)

Measured memory_bytes: 9452
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

long long modp(long long a, long long p) {
    long long res = a % p;
    if (res < 0) res += p;
    return res;
}

long long dif_modp(long long a, long long b, long long p){
    // a-b mod p
    return modp(a % p - b % p, p);
}

int main(void){
    int N,M;
    cin >> N >> M;
    ll x[N], y[M];
    REP(i,N) cin >> x[i];
    REP(i,M) cin >> y[i];

    ll Xsum = 0, Ysum = 0;
    REP(i,N) Xsum = (Xsum + dif_modp((i*x[i])%INF, ((N-1-i)*x[i])%INF, INF))%INF;
    REP(i,M) Ysum = (Ysum + dif_modp((i*y[i])%INF, ((M-1-i)*y[i])%INF, INF))%INF;
    cout << (Xsum*Ysum)%INF << endl;
    return 0;
}

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

using namespace std;

int main(){
	int n,k;
  	cin>>n>>k;
  	string s;
  	cin>>s;
  	for(int i=0;i<n;i++){
    	if(i==k-1){
        	cout<<(char)(s[i]+32);
          	continue;
        }	
      	cout<<s[i];
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,b;
  long long ans=0;
  cin>>N;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    B.at(i)=A.at(i)-(i+1);
  }
  sort(B.begin(),B.end());
  if(N%2==0)
    b=(B.at(N/2-1)+B.at(N/2))/2;
  else
    b=B.at(N/2);
  for(int i=0;i<N;i++){
    ans+=abs(B.at(i)-b);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  char ch;
  cin>>ch;
  if(ch>='a'&&ch<='z')
    cout<<'a';
  else
    cout<<'A';
  return 0;
}

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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=407;
const ll inf=0x3f3f3f3f3f3f3f;

int a[N];
ll dp[N][N],sum[N];

int main(){
	int n=input();
	for(int i=1;i<=n;i++){
		a[i]=input();
		sum[i]=sum[i-1]+a[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n-i;j++){
			int k=j+i;
			dp[j][k]=inf;
			ll tmp=sum[k]-sum[j-1];
			for(int o=j;o<=k;o++){
				dp[j][k]=min(dp[j][k],dp[j][o]+dp[o+1][k]+tmp);
			}
		}
	}

	printf("%lld\n",dp[1][n]);
}

Measured memory_bytes: 1536
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int N;
  cin >> N;
  for (int A = 1; A <= 9; A++)
  {
    for (int B = 1; B <= 9; B++)
    {
      if (A * B == N)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

#define ll long long int

int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll n,i,ans=0;
              cin>>n;
              vector<ll>A(n);
              for(i=0;i<n;i++)
              {
                  cin>>A[i];
              }
              for(i=1;i<n;i++)
              {
                  if(A[i]<A[i-1])
                  {
                      ans+=(A[i-1]-A[i]);
                      A[i]=A[i-1];
                  }
              }
              cout<<ans;
              return(0);
}


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

const ll MOD = 1000000007;

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

int main() {
  ll n;
  cin >> n;
  ll a, b, c;

  a = pow_mod(10, n);
  b = pow_mod(9, n);
  b *= 2;
  b %= MOD;
  c = pow_mod(8, n);

  ll ans = a - b;
  if (ans < 0) {
    ans += MOD;
  }
  ans %= MOD;
  ans += c;
  ans %= MOD;

  cout << ans << endl;
}

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    int k, a, b;
    cin >> k >> a >> b;

    rep(i, a, b + 1) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

            cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int main(){
    int n;
    cin>>n;
    n=n*2;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=1;i<=n;i+=2){
        sum+=a[i];
    }
    cout<<sum<<endl;
}

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

int main() {
  int a;
  cin >> a;
  int count = 0;
  if (a >= 100) {
    count++;
    a %= 100;
  }
  if (a >= 10) {
    count++;
    a %= 10;
  }
  if (a == 1) {
    count++;
  }
  cout << count << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int h, w, k;
  cin >> h >> w >> k;
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  sx--, sy--, tx--, ty--;
  vstr cell(h);
  cin >> cell;
  using T = tuple<int, int, int, int, int>;
  pqasc<T> q;
  q.emplace(0, k, sx, sy, 0);
  vector<vector<vi32>> dp(4, vector<vi32>(h, vi32(w, INF)));
  while (sz(q)) {
    int cost, cnt, x, y, dir;
    tie(cost, cnt, x, y, dir) = q.top();
    q.pop();
    if (dp[dir][x][y] != INF) continue;
    dp[dir][x][y] = cost;
    rep(i, 4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (cell[nx][ny] == '@') continue;
      if (i == dir && cnt < k) {
        q.emplace(cost, cnt + 1, nx, ny, i);
      } else {
        q.emplace(cost + 1, 1, nx, ny, i);
      }
    }
  }
  int ans = INF;
  rep(i, 4) amin(ans, dp[i][tx][ty]);
  if (ans == INF) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 44504
#include<iostream>
#include<cstdio>

using namespace std;

int main(int argc, char *argv[])
{
  int n;//カードの枚数
  int k;//シャッフルの方法
  int m;//操作回数
  int Card[202];//カードの状態
  int S[202];//カードの状態の退避場所
  scanf("%d",&n);
  getchar();
  scanf("%d",&m);
  getchar();
  for(int i = 1;i <= 2*n;i++){//初期化
    Card[i] = i;
  }
  for(int i = 0;i < m;i++){
    scanf("%d",&k);
    for(int j =1;j <=2*n;j++){
      S[j] = Card[j];
    }
    if(k ==0){//リフトシャッフル
      for(int l =1;l <=n;l++){
	Card[2*l-1] =S[l];
	Card[2*l] =S[n+l];
      }
      }else{
      for(int p = 1;p <=2*n-k;p++){//整数kカット
	Card[p] = S[k+p];
      }for(int p =1 ;p <= k;p++){
	Card[2*n-k+p] = S[p]; 
    }
  }
  }
  
  for(int i = 1;i <= 2*n;i++){
    cout <<Card[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)
	for i := 0; i*100 <= x; i++ {
		for j := 0; 100*i+j*101 <= x; j++ {
			for k := 0; 100*i+j*101+k*102 <= x; k++ {
				for l := 0; 100*i+j*101+k*102+l*103 <= x; l++ {
					for m := 0; 100*i+j*101+k*102+l*103+m*104 <= x; m++ {
						n := x - (100*i + j*101 + k*102 + l*103 + m*104)
						if n == 0 {
							fmt.Println(1)
							return
						} else if n%105 == 0 {
							fmt.Println(1)
							return
						}
					}
				}
			}
		}
	}
	fmt.Println(0)
}


Measured memory_bytes: 512
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

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

    vector<pair<ll,ll>> r(n);
    vector<pair<ll,ll>> lr(n);
    for(int i = 0; i < n; i++){
        pair<ll,ll> tmp;
        cin >> tmp.first >> tmp.second;

        lr[i].first = tmp.first + tmp.second;
        lr[i].second = tmp.first - tmp.second;

    }

    sort(lr.begin(), lr.end());

    ll cur = (ll)(-1e9) * 2LL - 100;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(cur <= lr[i].second){
            ans++;
            cur = lr[i].first;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

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

	cin >> N >> K;

	if(K*2-1 <= N){
		println("YES");
	}else{
		println("NO");
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
MAX = 10**18

ret = 1
for i in range(n):
	if(ret <= MAX):
		ret = ret*a[i]
	if(a[i] == 0):
		ret = 0
		break


if(ret > MAX):
	print(-1)
else:
	print(ret)


Measured memory_bytes: 84676
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            b[i] = sc.nextLong();
        }

        long ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            if ((a[i] + ans) % b[i] == 0) {
                continue;
            }
            ans += b[i] - (a[i] + ans) % b[i];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 88604
from heapq import heappush, heappop
def main():
    def dijkstra_search(s):
        d = [INF] * size
        searched = [False] * size
        d[s] = 0
        searched[s] = True
        edge_list = []
        count = 1
        for i in edge[s]:
            heappush(edge_list,i)
        while edge_list:
            min_d,min_v = heappop(edge_list)
            if searched[min_v] or min_d > d[min_v]:
                continue
            v = min_v
            d[v] = min_d
            searched[v] = True
            count += 1
            for i,j in edge[v]:
                next_d = i+d[v]
                if not searched[j]:
                    heappush(edge_list,(next_d,j))
            if count == size:
                break
        return d
    def judge(a,b):
        if a >= 0 and a < h and b >= 0 and b < w and s[a][b] == ".":
            return True
        else:
            return False
    h,w = map(int,input().split())
    s = [list(input()) for _ in range(h)]
    size = h*w
    INF = float('inf')
    edge = [[] for _ in range(size)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                if judge(i+1,j):
                    edge[i*w+j].append((1,((i+1)*w+j)))
                if judge(i-1,j):
                    edge[i*w+j].append((1,((i-1)*w+j)))
                if judge(i,j+1):
                    edge[i*w+j].append((1,(i*w+(j+1))))
                if judge(i,j-1):
                    edge[i*w+j].append((1,(i*w+(j-1))))
    ans = []
    for i in range(size):
        if s[i//w][i%w-1] == ".":
            d_list = dijkstra_search(i)
            for j in d_list:
                if not j == INF:
                    ans.append(j)
    print(max(ans))
    
if __name__ == '__main__':
    main()

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

using namespace std;

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

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    os << pai.first << ' ' << pai.second;
	return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    int a[4];

    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a, a+4);

    if (a[0] == 1 and a[1] == 4 and a[2] == 7 and a[3] == 9) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0&&w==0)break;
        int minlen=INF,mini=INF,minj=INF;
        for(int i=1;i<151;i++){//w
            for(int j=1;j<151;j++){//h
                if(i<=j)continue;
                if(h*h+w*w>i*i+j*j||(h*h+w*w==i*i+j*j&&h>j))continue;
                if(w==i&&h==j)continue;
                if(i*i+j*j<minlen){
                    minlen=i*i+j*j;
                    mini=i;
                    minj=j;
                }
                else if(i*i+j*j==minlen&&j<minj){
                    minlen=i*i+j*j;
                    mini=i;
                    minj=j;
                }
            }
        }
        cout<<minj<<" "<<mini<<endl;
    }
//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
long long int a=1000000007;
long long int adder(long long int x,long long int y)
{
    x+=y;
    if(x>a)
     x=x-a;

     return x;
}
int main()
{
    long long int n;
    cin>>n;
    long double dp[n+1];
    for(long long int i=0;i<n+1;i++)
    {
        dp[i]=0;
    }
    dp[0]=1;
    for(long long int i=0;i<n;i++)
    {
        double pheads;
        cin>>pheads;

       for(long long int j=i+1;j>=0;j--)
        { if(j)
          dp[j]=dp[j-1]*pheads+dp[j]*(1-pheads);
          else
           dp[j]=dp[j]*(1-pheads);
        }
    }

    double ans=0;
    for(long long int i=0;i<n+1;i++)
    { long long int t=n-i;
       if(i>t)
        ans+=dp[i];
    }
    cout<<setprecision(10)<<ans;
    return 0;
}


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

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


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

// gomennnasai hacchatta

class FenwickTree{
private:
    // Matrix to store the tree
    std::vector<std::vector<int>> ft;

public:
    // Function to get least significant bit
    int LSB(int x){
        return x & (-x);
    }

    int query(int x, int y){
        int sum = 0;
        for(int x_ = x; x_ > 0; x_ = x_ - LSB(x_)){
            for(int y_ = y; y_ > 0; y_ = y_ - LSB(y_)){
                sum = sum + ft[x_][y_];
            }
        }
        return sum;
    }

    int query(int x1, int y1, int x2, int y2){
        return (query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) + query(x1 - 1, y1 - 1));
    }

    void add(int x, int y, int value){
        // also update matrix[x][y] if needed.

        for(int x_ = x; x_ < ft.size(); x_ = x_ + LSB(x_)){
            for(int y_ = y; y_ < ft[0].size(); y_ = y_ + LSB(y_)){
                ft[x_][y_] += value;
            }
        }
    }

    FenwickTree(std::vector<std::vector<int>> matrix){
        int n = matrix.size();
        // matrix must not be empty.
        int m = matrix[0].size();
        // Initialize matrix ft
        ft.assign(n + 1, std::vector<int> (m + 1, 0));
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < m; ++j)
                add(i + 1, j + 1, matrix[i][j]);
        }
    }
};

struct cont{
    lint t,y,x;
};

int main(){
    lint H,W,T,q; cin>>H>>W>>T>>q; ++H,++W;
    FenwickTree mae(vector<vector<int>>(H,vector<int>(W))),ato(vector<vector<int>>(H,vector<int>(W)));
    queue<cont> que;
    rep(i,q){
        lint t,c,h,w,h2,w2; cin>>t>>c;

        while(que.size()){
            if(que.front().t<=t-T){
                auto e=que.front(); que.pop();
                mae.add(e.y,e.x,-1);
                ato.add(e.y,e.x,1);
            }
            else break;
        }

        if(c==0){
            cin>>h>>w;
            mae.add(h,w,1);
            que.push({t,h,w});
        }
        else if(c==1){
            cin>>h>>w;
            if(ato.query(h,w,h,w))ato.add(h,w,-1);
        }
        else{
            cin>>h>>w>>h2>>w2;
            cout<<ato.query(h,w,h2,w2)<<" "<<mae.query(h,w,h2,w2)<<endl;
        }
    }
}



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

const int INF = 0x3f3f3f3f;

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

    vector<vector<int>> dp(n, vector<int>(n, INF)), dp2(n, vector<int>(n, INF));
    for (int i = 0; i < m; i++){
        int s, t, c;
        cin >> s >> t >> c;
        s--; t--;
        dp[s][t] = c;
        dp[t][s] = c;
    }

    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                
                if (dp[i][j] <= l)
                    dp2[i][j] = 1;
            }
        }
    }

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

    int q;
    cin >> q;
    for (int i = 0; i < q; i++){
        int s, t;
        cin >> s >> t;
        s--; t--;

        if (dp2[s][t] == INF)
            cout << -1 << '\n';
        else
            cout << dp2[s][t] - 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 1280
#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;
  string s;
  cin >> s;
  rep(i,s.size()){
    s[i] += n;
    if(s[i]>'Z')s[i]=s[i]-'Z'+'A'-1;
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int upper = N/4;
        for(int i=0;i<=upper;i++){
            if((N-i*4)%7==0){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ans = (n / 500) * 1000;
  ans += ((n % 500) / 5) * 5;
  cout << ans << endl;
}


Measured memory_bytes: 256
import math
from collections import defaultdict

N = int(input())

rr = defaultdict(lambda: 0)
for i in range(1, N + 1):
    x = int(i / (10 ** int(math.log10(i))))
    y = i % 10
    rr[(x, y)] += 1

r = 0
for u in range(1, 10):
    for l in range(1, 10):
        r += rr[(u, l)] * rr[(l, u)]
print(r)



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

int main(){
  int A,B,K,j=0;
  cin>>A>>B>>K;
  int i=min(A,B);
  for(;j<K;i--)
    if(A%i==0 && B%i==0)
      j++;
  cout<<i+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int k;
void calc(deque<ll> q, vll& ans) {
    while (ans.size() <= k) {
        ll num = q.front();
        q.pop_front();
        int m = num%10;
        if (m != 0) q.push_back(num*10+(m-1));
        q.push_back(num*10+m);
        if (m != 9) q.push_back(num*10+(m+1));
        ans.push_back(num);
    }
}

int main() {
    cin >> k;

    vll ans;
    deque<ll> q;
    rep(i, 9) q.push_back(i+1);
    calc(q, ans);

    cout << ans[k-1] << endl;
    return 0;
}

Measured memory_bytes: 2548
f=[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]
k=int(input())
print(f[k-1])

Measured memory_bytes: 3060
#include <string.h>
#include <iostream>
#include <functional>
#include <algorithm>

using namespace std;
int main(){
    int N,sum=0;
    cin >> N;
    int L[N];
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    sort(L,L+N,greater<int>());
    for(int i=1;i<N;i++){
        sum=sum+L[i];
    }
    if(L[0]<sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/08  Problem: ABC 092 C / Link: http://abc092.contest.atcoder.jp/tasks/abc092_c  ----- */


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

	LL A, B, C, D; cin >> A >> B >> C >> D;

	LL ans = min(A,B) + min(C,D);
	
	
	cout << (ans) << "\n";

	return 0;
}


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

int main() {
    int S;
    cin >> S;
    int h = S / 3600;
    int m = S % 3600 / 60;
    int s = S % 60;
    printf("%d:%d:%d\n", h, m, s);
}

Measured memory_bytes: 1144
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func min(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a, b := nextInt(), nextInt()
	cnt := make([]int, 3)
	for i := 0; i < n; i++ {
		p := nextInt()
		if p <= a {
			cnt[0]++
		} else if p <= b {
			cnt[1]++
		} else {
			cnt[2]++
		}
	}
	fmt.Println(min(cnt))
}


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

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

  vector<int> A(N);
  rep(i, N) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  vector<ll> F(N);
  rep(i, N) {
    cin >> F.at(i);
  }
  sort(F.rbegin(), F.rend());

  ll l = 0;
  ll r = 1e12 + 1;
  ll ans = 0;

  while (l <= r) {
    ll mid = (l + r) / 2;
    ll sum = K;
    rep(i, N) {
      if (mid / F.at(i) < A.at(i)) {
        sum -= A.at(i) - mid / F.at(i);
      }
    }
    if (sum < 0) {
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    vector<int> a = {2,5,5,4,5,6,3,7,6};
    ll N, M;
    cin >> N >> M;
    vector<P> A(M);
    int argmin = 0;
    REP(i, M) {
        cin >> A[i].first;
        A[i].second = a[A[i].first - 1];
        if ((A[i].second == A[argmin].second && A[i].first > A[argmin].first) || A[i].second < A[argmin].second) argmin = i;
    }
    int std = A[argmin].first;
    int minc = A[argmin].second;

    sort(A.begin(), A.end(), [](P r, P l){
        return (r.first > l.first);
    });

    vector<ll> dp(N + 1, -1);
    dp[0] = 0;
    REP(i, N + 1){
        if (i == 0) continue;
        ll tmp1 = -1;
        for(auto tmp : A){
            if (i - tmp.second >= 0) if (dp[i - tmp.second] != -1) tmp1 = max(tmp1, dp[i - tmp.second] + 1);
        }
        dp[i] = tmp1;
    }
    //REP(i, N + 1)cout << dp[i] << endl;
    vector<int> s;
    ll red = N;
    REP(i, dp[N]){
        for(auto tmp : A){
            if (red - tmp.second >= 0) if (dp[red - tmp.second] == dp[red] - 1){
                s.push_back(tmp.first);
                red -= tmp.second;
                break;
            }
        }
    }

    REP(i, dp[N])cout << s[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
<?php
list ($H, $W) = fscanf(STDIN, "%d %d");
$a = explode("\n", fread(STDIN, 30000));

$white_row = array_pad(array(), $H, 0);
$white_col = array_pad(array(), $W, 0);
for ($r = 0; $r < $H; $r++) {
    $b = true;
    for ($c = 0; $c < $W; $c++) {
        if ($a[$r][$c] != ".") {
            $b = false;
            break;
        }
    }

    if ($b == true)
        $white_row[$r] = 1;
}

for ($c = 0; $c < $W; $c++) {
    $b = true;
    for ($r = 0; $r < $H; $r++) {
        if ($a[$r][$c] != ".") {
            $b = false;
            break;
        }
    }

    if ($b == true)
        $white_col[$c] = 1;
}

for ($r = 0; $r < $H; $r++) {
    if ($white_row[$r] == 1)
        continue;
    for ($c = 0; $c < $W; $c++) {
        if ($white_col[$c] == 0)
            print $a[$r][$c];
    }
    print "\n";
}
?>


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll,ll> T;

ll i,j,k;


int main(){
   ll N,A,B;
   cin>>N>>A>>B;
   string S;
   cin>>S;
   ll cnt=0;
   ll kaigai=0;
   rep(i,N){
       if(S[i]=='c')cout<<"No";
       else if(S[i]=='a'){
           if(cnt<A+B){
               cnt++;
               cout<<"Yes";
           }
           else cout<<"No";
       }
       else{
           if(cnt<A+B&&kaigai<B){
               cnt++;
               kaigai++;
               cout<<"Yes";
           }
           else cout<<"No";
       }
       cout<<endl;
   }
   
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int n,m,K;
char c[11][1003];
int wic[11],num[11],ans=1e9;
int main(){
	cin>>n>>m>>K;
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++) cin>>c[i][j];
	for (int i=0;i<(1<<(n-1));i++){
		int cnt=__builtin_popcount(i)+1;
		int res=cnt-1;
		memset (num,0,sizeof(num));
		int now=0;
		for (int j=1;j<n;j++){
			if ((1<<(j-1))&i)now++;
			wic[j]=now;
		}
		bool yes=1;
		for (int j=0;j<m;j++){
			for (int k=0;k<n;k++) if (c[k][j]=='1') num[wic[k]]++;
			bool ok=1;
			for (int k=0;k<cnt;k++) if (num[k]>K) ok=0;
			if (ok) continue;
			res++;
			memset (num,0,sizeof(num));
			for (int k=0;k<n;k++) if (c[k][j]=='1') num[wic[k]]++;
			ok=1;
			for (int k=0;k<cnt;k++) if (num[k]>K) ok=0;
			if (ok) continue;
			yes=0;break;
		}
		if (yes)
			ans=min(ans,res);
	}
	cout<<ans;
}

Measured memory_bytes: 256
n,k=map(int, input().split())
s=input()
b=[0]
for i in range(n-1):
    if s[i]!=s[i+1]:
        b.append(i+1)
b.append(len(s))
if s[0]=='0':
    b.insert(0,0)
if s[-1]=='0':
    b.append(len(s))
ans=0
stride=k*2+1
if len(b)-stride<1:
    stride=len(b)-1
for i in range(0,len(b)-stride,2):
    ans=max(ans,b[i+stride]-b[i])
print(ans)

Measured memory_bytes: 7160