akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e3+10;
ll dp[N][N][4];
ll a[N][N];
int main(){
    int R,C,k;scanf("%d %d %d",&R,&C,&k);
    for(int i=1;i<=k;i++){
        int r,c,v;scanf("%d %d %d",&r,&c,&v);a[r][c]=v;
    }
    for(int i=1;i<=R;i++)
        for(int j=1;j<=C;j++){

            dp[i][j][0]=dp[i][j-1][0];
            for(int p=0;p<=3;p++)
            dp[i][j][0]=max(dp[i-1][j][p],dp[i][j][0]);

            dp[i][j][1]=dp[i][j-1][1];
            if(a[i][j]>0)
            dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]+a[i][j]);

            dp[i][j][2]=dp[i][j-1][2];
            if(a[i][j]>0)
            dp[i][j][2]=max(dp[i][j][2],dp[i][j-1][1]+a[i][j]);

            dp[i][j][3]=dp[i][j-1][3];
            if(a[i][j]>0)
            dp[i][j][3]=max(dp[i][j][3],dp[i][j-1][2]+a[i][j]);
        }
    ll ans=0;
    for(int i=0;i<=3;i++)ans=max(ans,dp[R][C][i]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 356060
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
mini = max(x)
maxi = min(y)
al = [i for i in range(X+1,Y+1)]
ol = [i for i in range(mini+1,maxi+1)]
for i in ol:
    if i in al:
        print("No War")
        exit()
print("War")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define MOD 1000000007
ll check(ll x,ll l,ll r)
{
	if(x>=l && x<=r)
	{
		return 1;
	}
	else
	return 0;
}
ll mod(ll x,ll h)
{
	return (x+h)%h;
}
int main()
{
 ll n,m;
 cin>>n>>m;
 ll answer=0;
 answer=(n*n + m*m - n - m)/2;
 cout<<answer<<endl;
}


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

using namespace std;

int main(){
  string s;
  int a=0;
  cin >> s;
  for(int i=0;i<4;i++){
    if(s[i]=='+'){
      a++;
    }else{
      a--;
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(1, N+1):
    ans.append([i, A[i-1]])
ans.sort(key=itemgetter(1))
for i in range(0, N-1):
    print(str(ans[i][0]), end=" ")
print(str(ans[N-1][0]))


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


int main(){

    ll F[45];
    F[0]=1; F[1]=1;
    int n;
    cin >> n;
    for(int i=2;i<=n;i++) {
        F[i] = F[i-1] + F[i-2];
    }
    cout << F[n] << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define endl "\n"
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};


template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}


extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<> void print<string>(const string& container)
{
	cout<<container<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}


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

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}

template<typename Head, typename... Tail>
struct vector_demensions
{
	using type=vector<typename vector_demensions<Tail...>::type>;
};

template<typename Head>
struct vector_demensions<Head> { using type=Head; };

template<typename T>
vector<T> make_vectors(int size, T val)
{
	return vector<T>(size, val);
}

template<typename T=int, typename... Args>
auto make_vectors(int size, Args... tail)
	-> typename vector_demensions<Args..., T>::type
{
	auto val=make_vectors<T>(forward<Args>(tail)...);
	return vector<decltype(val)>(size, val);
}



int main()
{
	int n;
	cin>>n;
	auto p(read<int>(n));
	VI q(n);
	REP(i,n)
	{
		p[i]--;
		q[p[i]]=i;
	}
	int seq=1, ans=1;
	//print(q);
	REP(i,n-1)
	{
		if(q[i]<q[i+1])
		{
			seq++;
		}
		else
		{
			seq=1;
		}
		//print(seq);
		chmax(ans, seq);
	}
	print(n-ans);
}


Measured memory_bytes: 1792
puts $<.map {|l|
  ('%05d' % l.chomp.to_i).each_char.map(&:to_i).each_with_object([]) {|x, cs|
    cs << (x / 5 == 0 ? [?*, ?\ , ?=] : [?\ , ?*, ?=]) + [?*] * (x % 5) + [?\ ] + [?*] * (4 - x % 5)
  }.transpose.map(&:join).join ?\n
}.join "\n\n"

Measured memory_bytes: 9308
#include <bits/stdc++.h>
using namespace std;
int n,l;
int main(){
	scanf("%d%d",&n,&l);
	int ans=(n-1)*n/2+n*l;
	int mi=999;
	for(int i=0;i<n;i++){
		if(abs(i+l)<abs(mi)){
			mi=i+l;
		}
	}
	ans-=mi;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll m[1234567]={0ll},c[1234567]={0ll},mc[1234567]={0ll},ans,tmp;

int main(void){
	int n,i,q,k,t;
	string s;
	cin >> n;
	cin >> s;
	for(i=0; i<n; ++i){
		m[i+1] = m[i];
		if(s[i]=='M'){
			++m[i+1];
		}
		c[i+1] = c[i];
		if(s[i]=='C'){
			++c[i+1];
		}
	}
	for(i=0; i<n; ++i){
		if(s[i]=='C'){
			mc[i+1] = mc[i]+m[i];
		}else{
			mc[i+1] = mc[i];
		}
	}
	cin >> q;
	for(t=0; t<q; ++t){
		cin >> k;
		ans = 0ll;
		for(i=0; i<n; ++i){
			if(s[i]=='D'){
				tmp = mc[min(i+k,n)]-mc[i];
				tmp -= m[i]*(c[min(i+k,n)]-c[i]);
				ans += tmp;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 29956
#include <bits/stdc++.h> 
using namespace std; 
#define int long long
int32_t main() 
{ 
	int n,k;
	cin>>n>>k;
	int ar[n];
	for(int i=0;i<n;++i)
		cin>>ar[i];
	sort(ar,ar+n);
	int s=0;
	for(int i=n-1;i>=0;--i){
		if(k>0)
			k--;
		else s+=ar[i];
	}
	cout<<s;
} 


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

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

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

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

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

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 1e5 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int a[N];

int main () {
    to_pray();

    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++ i) {
    	cin >> a[i];
    }
    
    int mx = 0;
    for (int i = 1; i <= n; ++ i) {
    	mx = max(mx, a[i]);
    	if (abs(mx - a[i]) >= 2)
    		return cout << "No", 0;
    }
    
    cout << "Yes";
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}


Measured memory_bytes: 640
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const ll LIM = (ll)1e18;

ll a, b, c, k;

void solve() {                   
    scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
    ll ans = ((k & 1) ? b - a : a - b);

    if (ans > LIM) {
        printf("Unfair\n");
        return;
    }

    printf("%lld\n", ans);
}

int main() {    
    int tt = 1;

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

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        double[] dp = new double[n + 1];
        dp[0] = 1;
        for (int i = 0; i < n; i++)
        {
            double p = scan.nextDouble();
            for (int j = n; j >= 0; j--)
            {
                if (j == 0)
                    dp[j] *= (1 - p);
                else
                    dp[j] = dp[j - 1] * p + dp[j] * (1 - p);
            }
        }
        double sum = 0;
        for (int j = (int) ((n + 1) / 2); j <= n; j++)
            sum += dp[j];
        System.out.println(sum);
        
        // double[] arr = new double[n];
        // for (int i = 0; i < n; i++)
        //     arr[i] = scan.nextDouble();

        // double[][] dp = new double[n + 1][n + 1];
        // dp[0][0] = 1;
        // for (int i = 1; i <= n; i++)
        //     dp[i][0] = dp[i - 1][0] * (1 - arr[i - 1]);
        // for (int i = 1; i <= n; i++)
        //     for (int j = 1; j <= n; j++)
        //         dp[i][j] = dp[i - 1][j - 1] * arr[i - 1] + dp[i - 1][j] * (1 - arr[i - 1]);
        // double sum = 0;
        // for (int j = (int) ((n + 1) / 2); j <= n; j++)
        //     sum += dp[n][j];
        // System.out.println(sum);
    }
}

Measured memory_bytes: 37604
n,m=[int(s)for s in input().split(" ")]
a=[int(input().split(" ")[0])for i in range(m)]
a.sort()
if a[1]>=n:print(0)
else:
    cost=0
    ac=a[1:]
    for i in ac:
        if i<n:cost+=n-i
        else:
            print(cost)
            break

Measured memory_bytes: 7788
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
 int main(void){
     int N,K;
     cin >> N >> K;
     bool ok[10]={};
     rep(i,K){
         int D;
         cin >> D;
         ok[D]=1;
     }
     int ans=N;
     while(true){
         int digit=1+floor(log10(ans)),check=0;
         int value=ans;
         for(int i=digit-1;i>=0;i--){
             int mono=value/pow(10,i);
             if(ok[mono]==1) check=1;
             value-=mono*pow(10,i);
         }
         if(check==0){
             cout << ans << endl;
             break;
         }
         else ans++;
     }
 }

Measured memory_bytes: 512
l = [int(x) for x in input().split()]

l.sort(reverse=True)


if len([x for x in l if x % 2 == 0]) > 0:
    print(0)
else:
    ans = min(l[1]*l[2], l[0]*l[1], l[0]*l[2])
    print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n;
	if (!scanf( "%d", &n ))
		return 0;
	std::vector <int> input( n, 0 );
	rep( i, 0, n ){
		if (!scanf( "%d", &( input[ i ] )))
			return 0;
	}
	std::sort( input.begin(), input.end());
	int count = 0;
	for(int i = n - 1; i > 1; i--){
		for(int j = i - 1; j > 0; j--){
			int d = input[ i ] - input[ j ];
			for(int k = j - 1; k > -1; k--){
				if (d < input[ k ])
					count++;
				else
					break;
			}
			if (d > input[ j - 1 ])
				break;
		}
	}
	printf( "%d\n", count );
	return 0;
}


Measured memory_bytes: 256
//2017-like Number

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

bool IsPrime(int num){
    if(num<2)return false;
    else if(num==2)return true;
    else if(num%2==0)return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)return false;
    }
    return true;
}

signed main (){
    vector<int>t(100010,false);
    rep(i,1,100010)if(IsPrime(i))if(IsPrime((i+1)/2))t[i]=true;
    vector<int>s(100010,0);
    rep(i,1,100010){
        if(t[i]){
            s[i]=s[i-1]+1;
        }
        else s[i]=s[i-1];
    }
    int q;cin>>q;
    rep(i,0,q){
        int l,r;cin>>l>>r;
        cout<<s[r]-s[l-1]<<nnn;
    }
    return 0;
}

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

using namespace std;

int main() {

	long n;
	cin >> n;

	string s;
	cin >> s;
	
	for (long i = 0; i < s.size(); i++) {
		s[i] = s[i]+n;
		if (s[i] > 90) { s[i] -= 26; }
	}


	cout << s << endl;
}

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


int main(){
    int n,k;
    cin >> n >> k;
    long double ans = 0;
    long double subans = 0;
    for(int i = 1; i <= n and i < k; ++i){
        int cnt = 0;
        int base = i;
        while(base  < k) ++cnt, base *= 2;
        long double hoge = 0.5;
        for(int i = 0; i < cnt-1; ++i)hoge *= 0.5;
        subans += (long double)hoge;
    }
    if(n >= k) {
        ans = (long double)(n - k + 1+ subans) / n;
    } else {
        ans = subans /n;
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#C問題になると、正攻法ではTLEになる気がするが、ダメもとで出してみるか…
#更新してから足しちゃうと、答え変わるから注意。(書きかけの時）
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
beat = []
remain = []

for i in range(n+1):
  if i==0:
    if a[i]<=b[i]:
      beat.append(a[i])
      remain.append(0)
      b[i]-=a[i]
    else:
      beat.append(b[i])
      remain.append(a[i]-b[i])
      b[i] = 0
  elif i==n:
    if a[i]<=b[i-1]:
      beat.append(a[i])
      remain.append(0)
      b[i-1]-=a[i]
    else:
      beat.append(b[i-1])
      remain.append(a[i]-b[i-1])
      b[i-1] = 0
  elif a[i]<=b[i-1]:
    b[i-1] -= a[i]
    beat.append(a[i])
    remain.append(0)
  elif a[i] > b[i-1] and a[i]<=b[i]+b[i-1]:
    b[i] -= a[i]-b[i-1]
    b[i-1] = 0
    beat.append(a[i])
    remain.append(0)
  else:
    beat.append(b[i-1]+b[i])
    remain.append(a[i]-b[i-1]-b[i]) 
    b[i]=0
    b[i-1]=0

print(sum(beat))

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

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

    if(N%10==9 || N/10==9){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back

using namespace std;

class cond{
public:
	cond(int x, int y, int z, int t){a=x;b=y;c=z;r=t;chked=false;}
	int a,b,c,r;
	bool chked;
};

int main(void){
	int a,b,c;

	while(cin >> a >> b >> c){
		if((a|b|c) == 0) break;
		vector<cond> v;
		bool changed = true;
		int state[a+b+c+1];
		int x,y,z,r;

		//at first, every state are unknown
		fill(state,state+a+b+c+1,2);

		//read data
		int n; //# of conditions
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> x >> y >> z >> r;
			v.PB(cond(x,y,z,r));
		}
		while(changed){
			changed = false;
			//for all conditions
			for(int i=0;i<n;i++){
				if(v[i].chked) continue; //do not check which is determined
				if(v[i].r == 1){          //in case work well
					state[v[i].a] = 1;
					state[v[i].b] = 1;
					state[v[i].c] = 1;
					v[i].chked = true;
					changed = true;
				}else{
					if(state[v[i].a] == 1 && state[v[i].b] == 1){
						state[v[i].c] = 0;
						changed = true;
						v[i].chked = true;
					}else if(state[v[i].a] == 1 && state[v[i].c] == 1){
						state[v[i].b] = 0;
						changed = true;
						v[i].chked = true;
					}else if(state[v[i].b] == 1 && state[v[i].c] == 1){
						state[v[i].a] = 0;
						changed = true;
						v[i].chked = true;
					}
				}
			}
		}
		for(int i=1;i<=a+b+c;i++){
			cout << state[i] << endl;
		}
	}
}

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


class Main{
  public static void main(String[] args)throws IOException{
     
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
 
        int x=Integer.parseInt(str);
        int h=x/3600;
        int m=x%3600/60;
        int s=x%3600%60;
 
    System.out.println(h+":"+m+":"+s);
  }
}

Measured memory_bytes: 24156
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=20000+20;
int a,b,c,d;
int main()
{
    //freopen("out.txt","w",stdout);
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        printf("%d\n",min(a,b)+min(c,d));
    }


    return 0;
}


Measured memory_bytes: 256
use std::collections::BinaryHeap;
use std::cmp;

fn main(){
    let mut sc = Scanner::new();
    let n = sc.next();
    let x : i64 = sc.next();
    let mut a = vec![0i64; n];
    for e in a.iter_mut() { *e = sc.next(); }
    let mut ans = a.iter().fold(0, |x, y| x + y);
    a.resize(n*2, 0);
    for i in 0..n { a[i+n] = a[i]; }

    let mut del = vec![false; n*2];
    let mut s:BinaryHeap<(i64, usize)> = BinaryHeap::new();
    for mg in 1..n {
        s.clear();
        s = (n-mg..n).map(|i| (-a[i], i)).collect();
        for i in 0..n*2 { del[i] = false; }
        let mut cand = x*mg as i64;
        for j in n..n+n {
            while del[s.peek().unwrap().1] {
                s.pop();
            }
            let min = *s.peek().unwrap();
            cand += cmp::min(-min.0 as i64, a[j]);
            del[j-mg] = true;
            s.push((-a[j], j));
        }
        ans = cmp::min(ans, cand);
    }
    println!("{}", ans);
}

// Scanner

#[allow(dead_code)]
struct Scanner {
    token_buffer : Vec<String>,
    index : usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner{
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn wrapped<T>(& mut self) -> Result<T,&str> where T: std::str::FromStr {
        let s = try!(self.fetch_token());
        let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
        Ok(t)
    }
    fn next<T>(& mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }

    fn fetch_token(&mut self) -> Result<&String,&str> {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    Ok(_)  => return Err("End of file"),
                    Err(_) => return Err("Failed to read line"),
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }

        self.index += 1;
        Ok(&self.token_buffer[self.index - 1])
    }
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n, k;
  scanf("%d %d", &n, &k);

  vector<LL> x(n);
  REP (i, n) {
    scanf("%lld", &x[i]);
  }

  int zp = distance(x.begin(), lower_bound(x.begin(), x.end(), 0));

  LL ans = pow(10, 18);
  FOR (i, max(0, zp - k), min(zp + 1, n - k + 1)) {
    LL t;
    if (x[i + k - 1] * x[i] < 0)
      t = x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i]));
    else
      t = max(abs(x[i + k - 1]), abs(x[i]));
    ans = min(ans, t);
  }
  cout << ans << endl;
}


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

const int N_MX = 1e6;
int a[N_MX];
const long long int MOD = 1e9 + 7;
long long int n;
long long int all, have0, have9, have_0or9, ans, tmp;

int main() {
    cin >> n;
    //全体
    all = 1;
    for (int i = 0; i < n; i++) {
        all = all * 10 % MOD;
    }
    // 0を持つ、9を持つ
    tmp = 1;
    for (int i = 0; i < n; i++) {
        tmp = tmp * 9 % MOD;
    }
    have0 = have9 = (all - tmp) % MOD;
    if (have0 < 0 & have9 < 0) {
        have0 = MOD + have0;
        have9 = MOD + have9;
    }

    // 0または9を持つ
    tmp = 1;
    for (int i = 0; i < n; i++) {
        tmp = tmp * 8 % MOD;
    }
    have_0or9 = (all - tmp) % MOD;
    if (have_0or9) have_0or9 = MOD + have_0or9;

    ans = ((have0 + have9) % MOD - have_0or9) % MOD;
    if (ans < 0) ans = MOD + ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){

  string S, ans;
  cin >> S;

  if( S == "Sunny"){
    ans = "Cloudy";
  }
  if( S == "Cloudy"){
    ans = "Rainy";
  }
  if( S == "Rainy"){
    ans = "Sunny";
  }

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 1<<31-1


int n;
vector<int> G[100000];
vector<int> depth,vs;
int id[100000]={};
//pii dat[4*100000];

template<class T>
class segtree{
private:
    vector<T> dat;
    int _size;
    T _init;
    
public:
    segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init) , dat(4*__size,init){
        if(__size==0)return ;
        int x=1;
        while(x<_size)x*=2;
        _size = x;
    }
    
    int size(){
        return _size;
    }
    
    void update(int m,T x){
        int i = m+_size;
        dat[i] = x;
        while(i!=1){
            dat[i/2] = min(dat[i],dat[i^1]);
            i/=2;
        }
    }
    
    // call find(s,t)
    T find(int s,int t,int num=1,int a=0,int b=-1){
        if(b==-1)b=_size-1; //I couldn't "int b=_size".
        if(b<s||t<a)return _init;
        if(s<=a&&b<=t)return dat[num];
        return min( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );
    }
    
    void print(){
        rep(i,_size*2)cout<<dat[i].first<<" "<<dat[i].second<<endl;
    }
};


void dfs(int d,int num){
    depth.pb(d);
    vs.pb(num);
    rep(i,G[num].size()){
        dfs(d+1,G[num][i]);
        depth.pb(d);
        vs.pb(num);
    }
    return ;
}

void init(){
    dfs(1,0);
    rep(i,vs.size()){
        if(id[ vs[i] ]==0)id[ vs[i] ]=i;
    }
}

int main(){
    cin>>n;
    rep(i,n){
        int k;
        cin>>k;
        rep(j,k){
            int a;
            cin>>a;
            G[i].pb(a);
        }
    }
    
    init();
    segtree<pii> st(depth.size(),pii(INF,INF));
    rep(i,depth.size()){
        st.update(i,pii(depth[i],vs[i]));
    }
    int q;
    cin>>q;
    rep(i,q){
        int a,b;
        cin>>a>>b;
        cout<<st.find(min(id[a],id[b]),max(id[a],id[b])).second<<endl;
    }
}

Measured memory_bytes: 19604
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b;

int x(int n) {
	int res = (n%2==0 ? n : 0);
	int t = (n+1)/2;
	if (t%2) res ^= 1;
	return res;
}

signed main() {
	cin >> a >> b;
	a--, chmax(a, 0ll);
	cout << (x(a) ^ x(b)) << endl;
}

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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

inline void chkmin( int &a, int b ) { if(a > b) a = b; }

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

const int N = 1e5 + 5;
char s[N];
int n, m, f[N], g[N], top, st[N];
deque<int> q;

int main()
{
	n = _; m = _;
	scanf("%s", s);
	if(s[n] == '1')
		return puts("-1"), 0;
	int flag = 0;
	while(1)
	{
		flag = 0;
		int r = max(0, n - m);
		for( int i = r; i < n; i++ ) 
			if(s[i] == '0')
			{
				st[++top] = n - i;
				n = i;
				flag = 1;
				break;
			}
		if(!n || !flag)
			break;
	}
	// cout << n << ln;
	// puts("===qwq===");
	if(!flag)
		return puts("-1"), 0;
	while(top)
		cout << st[top--] << " ";

}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std; 
int main(){
	// freopen("input.txt","r",stdin);
	int n; cin>>n; 
	
	// double x[n];
	double s=0; 
	for(int i=0;i<n;i++){
		double x; cin>>x;
		s+=1.0/x;  
	}	

	cout<<1.0/s<<endl; 

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
//ll t,n,a[100005];
ll a,b,c,d;
int main()
{
    //IOS;
    /*cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
    }*/
    cin>>a>>b>>c>>d;
    if(b>=c)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    while(1)
    {
        c-=b;
        if(c<=0)
        {
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0)
        {
            cout<<"No"<<endl;
            break;
        }
    }
    return 0;
}
/*

*/


Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
int main(){
    string str;
    cin>>str;
    int Jcou=0,Ocou=0,Icou=0;
    int ans=0;
    for(int i=0;i<str.size();i++){
        if(Ocou==0&&Icou==0&&str[i]=='J')Jcou++;
        else if(Jcou!=0&&Icou==0&&str[i]=='O')Ocou++;
        else if(Jcou!=0&&Ocou!=0&&str[i]=='I')Icou++;
        else{
            if(Jcou<Ocou||Ocou>Icou)Ocou=0;
            ans=max(ans,min(Jcou,min(Ocou,Icou)));
            Jcou=0,Ocou=0,Icou=0;
            if(str[i]=='J')Jcou++;
        }
        //printf("[%d][%d][%d][%d]\n",Jcou,Ocou,Icou,ans);
    }
    if(Jcou<Ocou||Ocou>Icou)Ocou=0;
    ans=max(ans,min(Jcou,min(Ocou,Icou)));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2052
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void solve() throws IOException {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int n1 = 0;
		int n2 = 0;

		if (a >= b) {
			n1 = b;
			if (a >= c) {
				n2 = c;
			} else {
				n2 = a;
			}
		} else {
			n1 = a;
			if (b >= c) {
				n2 = c;
			} else {
				n2 = b;
			}
		}

		System.out.println(n1 + n2);

		sc.close();
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 19668
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>

using namespace std;

int h, w;
int colornum;
int colorval;

int ccounter = 1;

int answer[10100];

int main() {
	scanf("%d %d", &h, &w);
	scanf("%d", &colornum);
	for (int c = 1; c <= colornum; c++) {
		scanf("%d", &colorval);
		for (int i = 0; i < colorval; i++) {
			answer[ccounter] = c;
			ccounter++;
		}
	}
	for (int i = 0; i < h; i++) {
		int s = i * w + 1;
		int e = w * (i + 1);
		if (i % 2 == 1) {
			for (int j = e; j >= s; j--)printf("%d ", answer[j]);
		}
		else {
			for (int j = s; j <= e; j++)printf("%d ", answer[j]);
		}
		printf("\n");
	}
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double ans = 0;
	int n; cin >> n;
	REP(i, n) {
		double d;
		cin >> d;
		string s;
		cin >> s;
		if (s == "JPY") {
			ans += d;
		}
		else {
			ans += 380000 * d;
		}
	}
	cout << fixed << setprecision(100) << ans << endl;
}

Measured memory_bytes: 256
s = gets.chomp.split("")
long = s.size
i = 0
arr = []
ookisa = []
aa = 0
while true
    if arr != []
        arr << s[i]
    end
    if s[i] == "A" && aa == 0
        arr << s[i]
        aa += 1
    end
    if s[i] == "Z" && arr != []
        ookisa << arr.size
    end
    if i == long-1
        break
    end
    i += 1
end
puts ookisa.sort.pop

Measured memory_bytes: 34744
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		
		if((existChar(str, 'N') == existChar(str, 'S')) && (existChar(str, 'W') == existChar(str, 'E'))){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	
	static boolean existChar(String str, char ch){
		for(char c : str.toCharArray()){
			if(c == ch){
				return true;
			}
		}
		return false;
	}
}


Measured memory_bytes: 21844
function Main(input) {
	input = input.split("\n");
	const N = parseInt(input[0])
	const ps = input[1].split(" ").map(x => parseInt(x))

	var count = 0
	for(i=0; i < N; i++){
		if(ps[i] != i+1) count++
	}
	if(count == 2 || count == 0){
		console.log("YES")
	}else{
		console.log("NO")
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[100010];
int B[100010];
int C[100010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		cin>>B[i];
	}
	REP(i,N){
		cin>>C[i];
	}
	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);
	int ans=0;
	REP(i,N){
		int res=1;
		if(A[0]>=B[i]){
			continue;
		}
		int ok=0,ng=N;
		while(abs(ok-ng)>1){
			int mid=(ok+ng)/2;
			if(A[mid]<B[i]){
				ok=mid;
			}
			else{
				ng=mid;
			}
		}
		ok++;
		res*=ok;
		ok=N-1,ng=-1;
		if(C[N-1]<=B[i]){
			continue;
		}
		while(abs(ok-ng)>1){
			int mid=(ok+ng)/2;
			if(B[i]<C[mid]){
				ok=mid;
			}
			else{
				ng=mid;
			}
		}
		res*=N-ok;
		ans+=res;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

string s;

int main()

{

cin >> s;

if ( s == "SUN")	{	cout << 7;

}

else if (s == "MON"){

	cout << 6;

}

else if (s == "TUE"){

	cout << 5;

}

else if(s == "WED"){

	cout << 4;

}

else if (s == "THU"){

	cout << 3;

}

else if (s == "FRI"){

	cout << 2;

}

else if (s == "SAT"){

	cout << 1;

}

}

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

int main() {

  int a, b;
  
  for(;;) {
    scanf("%d %d", &a, &b);
    if( a == 0 && b == 0 ) break;
    if( a > b ) {
      std::swap(a, b);
    }
    printf("%d %d\n", a, b);
  }
  
  
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a,b,c) for(b=(c);b<(a);b++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline long kaizyo(long);
int main() {
	string S;
	cin >> S;
	bool b = true;
	int check = 0;
	if (S[0] == 'A') {
		if (!('A' <= S[1] && 'Z' >= S[1])) {
			for (int i = 2; i < (S.size() - 1);i++) {
				if (S[i] == 'C') {
					check++;
				}
				else if ('A' <= S[i] && 'Z' >= S[i]) {
					b = false;
					break;
				}
			}
			if ('A' <= S[S.size() - 1]&&'Z'>=S[S.size()-1]) {
				b = false;
			}
		}
		else {
			b = false;
		}
	}
	else {
		b = false;
	}
	if (check != 1) {
		b = false;
	}
	if (b) {
		cout << "AC";
	}
	else {
		cout << "WA";
	}
	return 0;
}

inline long kaizyo(long x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 998244353
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,s;cin>>n>>s;
    ll a[n];
    rep(i,n) cin>>a[i];

    ll dp[3][n+1][s+1];
    rep(i,3)rep(j,n+1)rep(k,s+1) dp[i][j][k]=0;

    // 0 not in not use, 1 in not use, 2 in use
    dp[0][0][0]=1;

    rep(i,n){
        for(int j=0;j<=s;j++){
            // use
            if(j-a[i]>=0){
                dp[2][i+1][j]=(dp[2][i+1][j]+dp[0][i][j-a[i]]+dp[1][i][j-a[i]]+dp[2][i][j-a[i]])%mod;
            }
            // not in not use
            dp[0][i+1][j]=(dp[0][i+1][j]+dp[0][i][j]+dp[1][i][j]+dp[2][i][j])%mod;
            dp[1][i+1][j]=(dp[1][i+1][j]+dp[0][i][j]+dp[1][i][j]+dp[2][i][j])%mod;
            
        }
    }

    // cout<<"0"<<endl;
    // rep(j,s+1){
    //     rep(i,n+1){
    //         cout<<dp[0][i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    // cout<<"1 -- "<<endl;
    // rep(j,s+1){
    //     rep(i,n+1){
    //         cout<<dp[1][i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<"2 --- "<<endl;
    // rep(j,s+1){
    //     rep(i,n+1){
    //         cout<<dp[2][i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    ll ans=0;
    rep(i,3){
        ans+=dp[i][n][s];
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 214688
#include<bits/stdc++.h>
using namespace std;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#define ll long long int
#define md 1000000007
#define pb emplace_back
#define all(s) s.begin(),s.end()
typedef vector<int>vi;
typedef vector<bool>vb;
void solve(){
	int n=0,k=0;
	cin>>n>>k;
	vi st(n+1);
	for(int i=1;i<=n;i++){
		cin>>st[i];
	}
	vi dp(n+1);
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(st[2]-st[1]);
	if(n==2)
	{
		cout<<dp[2]<<"\n";
		return;
	}
	for(int i=3;i<=n;i++){
		dp[i]=dp[i-1]+abs(st[i-1]-st[i]);
	for(int j=1;j<=k;j++){
		if(i-j>=1){
         int a= dp[i-j]+abs(st[i]-st[i-j]);
		dp[i]=min(a,dp[i]);
	} 
}
}
     cout<<dp[n]<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); 
 int t=1;
 //cin>>t; 
   while(t--){
   	solve();
   }
     return 0;
}  

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define rep( i, n ) for (ll i = 0; i < ( ll )(n); i++)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;

int main(){
    int d,t,s;

    cin>>d>>t>>s;

    if(d<=t*s) cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

bool flag[100];

void printPairVector(vector<pair<int,int> > &vect){
	for(auto x:vect){
		cout << x.first << " " << x.second << endl;
	}
}
 
int main(){
    int N;
    vector<pair<int,int> > red, blue;

    cin >> N;
    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        red.push_back( make_pair(x, y) );
    }

    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        blue.push_back( make_pair(x, y) );
    }


    sort(red.begin(), red.end() );
    sort(blue.begin(), blue.end() );

    //printPairVector(red);
    //printPairVector(blue);

    int ans = 0;
    for(int i = 0; i < N; i++){
        vector<pair<int,int> > maxr;
        
        for(int j = 0; j < N; j++){
            
            if(blue[i].first < red[j].first) continue;

            if(blue[i].second < red[j].second) continue;

            maxr.push_back( make_pair(red[j].second, j) );

            

        }
        
        sort(maxr.begin(), maxr.end(), greater<pair<int,int> >());
        //cout << "---maxr---" << endl;
        //printPairVector(maxr);
        for(int j = 0; j < maxr.size(); j++){
            pair<int, int> r = maxr[j];
            if(flag[r.second] == false){
                ans++;
                flag[r.second] = true;
                break;
            }
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <iostream>


using namespace std;


int main()
{

    int s,w;
cin>>s>>w;
if(s<=w)
{

    cout<<"unsafe";

}
else
    cout<<"safe";

return 0;
}


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

struct p2 {
    int x, y;
};

const int INF = 2e9 + 7;

int main() {
    int n;
    cin >> n;
    int mxplus = -INF, mnplus = INF, mxminus = -INF, mnminus = INF;
    for (int i = 0; i < n; i++) { int x, y; cin >> x >> y, mxplus = max(mxplus, x + y), mnplus = min(mnplus, x + y), mxminus = max(mxminus, x - y), mnminus = min(mnminus, x - y); }
    cout << max(mxplus - mnplus, mxminus - mnminus);
}

Measured memory_bytes: 3552
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == -1)
				break;
			Deque<Integer> deque = new ArrayDeque<Integer>();
			while (true) {
				int a = n % 4;
				deque.push(a);
				n /= 4;
				if (n == 0)
					break;
			}
			for (int t : deque)
				System.out.print(t);
			System.out.println();
		}
	}
}

Measured memory_bytes: 23432
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int res=1e9;
    int n;cin>>n;
    int a,b,c;cin>>a>>b>>c;
    vector<int> t(n);
    rep(i,n) cin>>t[i];
    for(int i=0;i<(1<<16);i++){
        int A=0,B=0,C=0,tmp=i;
        int buf=0;
        rep(j,n){
            if(tmp%4==0){
                A+=t[j];
                tmp/=4;buf+=10;
            }else if(tmp%4==1){
                B+=t[j];
                tmp/=4;buf+=10;
            }else if(tmp%4==2){
                C+=t[j];
                tmp/=4;buf+=10;
            }else{
                tmp/=4;
            }
        }
        if(A==0||B==0||C==0)continue;
        buf+=abs(a-A)+abs(b-B)+abs(c-C)-30;
        chmin(res,buf);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
ld n,ans,a,rans,s[200001];
int k;
vector<ld> v;
int main(void){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        s[i]++;
    }
    for(int i=1;i<=n;i++){
        s[i]+=s[i-1];
    }
    for(int i=0;i<=n-k;i++){
        ans=s[k+i]-s[i];
        rans=max(rans,ans);
    }
    cout<<setprecision(15)<<rans/2<<endl;
}


Measured memory_bytes: 3328
import sys
input = sys.stdin.readline

s=input().strip()
n=len(s)
s+="###################################"
i=0
while n-i>=1:
    """print(n-i)
    print(s[i:i+5])"""

    if s[i:i+5]=="dream":
        if s[i+5:i+7]=="er":
            #print(s[i+7:i+11])
            if s[i+7:i+10]=="ase":
                if s[i+10]=="r":
                    i+=11
                else:
                    i+=10    
            else:
                i+=7
        else:
            i+=5

    elif s[i:i+5]=="erase":
        #print(8)
        if s[i+5]=="r":
            i+=6
        else:
            i+=5
    else:
        print("NO")
        exit()
print("YES")


Measured memory_bytes: 40432
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	int cnt = 0;
	char prev = ' ';
	for (int i = 0; i < 4; i++) {
		char c;
		cin >> c;
		if (c != prev)cnt = 0;
		cnt++;
		prev = c;
		if (cnt > 2)break;
	}

	if (cnt > 2)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256