akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 3e5;
const ll inf = 1e18;


int n;
ll a[maxn];
ll dp[maxn][4];


void relax(ll& x, ll y) {
    x = max(x, y);
}

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

    cin>>n;
    assert(n>=2);
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }

    for (int i=0; i<=n+1; i++) {
	for (int j=0; j<4; j++) {
	    dp[i][j] = -inf;
	}
    }

    dp[0][0] = 0;

    int parity = 1+(n%2);

    for (int i=0; i<n; i++) {
	for (int j=0; j<=parity; j++) {
	    relax(dp[i+1][j+1], dp[i][j]);
	    
	    ll cur = ((i+j)%2==0) ? a[i] : 0;
	    relax(dp[i+1][j], dp[i][j] + cur);
	}
    }

    ll ans = dp[n][parity];
    cout<<ans<<endl;
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  ll ans = 0;
  if (a.size()%2 == 0) {
    for (ll i = 0; i < (n-2)/2; ++i) {
      ans += a[i] * -2;
    }
    for (ll i = 0; i < (n-2)/2; ++i) {
      ans += a[n-i-1] * 2;
    }
    ans += a[n/2-1] * -1;
    ans += a[n/2];
  } else {
    vector<ll> p1 = {-1, -1};
    vector<ll> p2 = {1, 1};
    for (ll i = 0; i < (n-2+1)/2; ++i) {
      p1.push_back(2);
      p2.push_back(-2);
    }
    for (ll i = 0; i < (n-2)/2; ++i) {
      p1.push_back(-2);
      p2.push_back(2);
    }
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end());

    ll sum1 = 0, sum2 = 0;
    for (ll i = 0; i < n; ++i) {
      sum1 += a[i] * p1[i];
      sum2 += a[i] * p2[i];
    }
    ans = max(sum1, sum2);
  }

  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 2804
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  long long int min=(1<<29),d[100010],e[100010],a,b,m,i,x,y,c,sum=0;
  scanf("%lld %lld %lld\n",&a,&b,&m);
  for(i=0;i<a;i++){
    scanf("%lld",&d[i]);
    if(min>d[i]){
      min=d[i];
    }
  }
  sum+=min;
  min=(1<<29);
  scanf("\n");
  for(i=0;i<b;i++){
    scanf("%lld",&e[i]);
    if(min>e[i]){
      min=e[i];
    }
  }
  sum+=min;
  scanf("\n");
  for(i=0;i<m;i++){
    scanf("%lld %lld %lld\n",&x,&y,&c);
    x--,y--;
    if(sum>d[x]+e[y]-c){
      sum=d[x]+e[y]-c;
    }
  }
  printf("%lld\n",sum);
  return 0;
}

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

int main()
{
	int r, g, b;
	scanf("%d %d %d", &r, &g, &b);

	int sum = r * 100 + g * 10 + b;

	if (sum % 4 == 0)
		printf("YES\n");
	else
		printf("NO\n");

}

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

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

void solve(void){
  ll x, n; cin >> x >> n;

  if (n == 0) {
    cout << x << endl;
    return;
  }
  vector<ll> v(n, 0);
  rep(n, i) cin >> v[i];

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

  vector<ll> vb;
  vector<ll> vc;
  for (ll i = 0; i <= 1000; ++i) {
    bool flag = false;
    for (ll j = 0; j < n; ++j) {
      if (i == v[j]){
        flag = true;
        break;
      } 
    }
    if (flag == false) {
      ll temp = abs(x - i);
      vb.emplace_back(i);
      vc.emplace_back(temp);
    }
  }

  ll res = vb[(ll)vb.size() - 1];
  for (ll i = (ll)vb.size()-1; i-1 >= 0; --i) {
    if (vc[i-1] <= vc[i]) res = vb[i-1];
  }
  cout << res << endl;
}

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

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int N, A, B;
    cin >> N >> A >> B;
    string s;
    cin >> s;

    int a = 0;
    int b = 0;

    rep(i, N){

        if(s[i] == 'a'){
            if(a + b < A + B){
                cout << "Yes" << endl;
                a++;
            }else{
                cout << "No" << endl;
            }
        }else if(s[i] == 'b'){
            if(a + b < A + B && b < B){
                cout << "Yes" << endl;
                b++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 896
N = int(input())
S = input()

if N % 2 != 0:
    print('No')
else:
    S_1 = S[:int(N // 2)]
    S_2 = S[int(N // 2):]
    if S_1 == S_2:
        print('Yes')
    else:
        print('No')

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,a,b,c;
    t = 1;
    while(t--) {
     cin >> a >> b >> c;
     if(c <= a - b)
      cout << 0 << endl;
     else
      cout << c - a + b << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.Stream;

public class Main {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        func();
        pw.flush();
        return;
    }

    static void func() throws IOException {
        int[] input = arrayOfInt();
        int n = input[0];
        int m = input[1];

        // 1.N個の数が最大公約数Dを持つということから、
        // 　その合計値のMの約数にもDを含んでいることがわかる。
        // 2.MがDを約数としているとき、D×NがMを超えると成立しなくなるので、
        //   取りうるDの最大値はM/Nとなる
        // ex.) ・N = 3 M = 14のとき、Mの約数は 1 2 7となる
        //      ・最大公約数が7のとき、数列は全て7以上となるため、
        //      　最低値の7×3でも21となり成立しない。
        //      ・最大公約数が2のとき、数列は全て2以上となるため、
        //      　最低値の2×3は6となり、取りうる最大公約数となる。
        int MAX = (int)Math.floor(m/n);

        // 最大値を求める問題なので、取りうる最大値からマイナスして成立するものを探すほうが早い
        long ans = 1;
        for(int i = MAX;1 < i;i--){
            if (m%i == 0){
                ans = i;
                break;
            }
        }
        println(ans);
    }
    // 入力受け取り
    static String next() throws IOException {return br.readLine();}
    static int nextInt() throws IOException{return getInt(br.readLine());}
    static long nextLong() throws IOException{return getLong(br.readLine());}
    static String[] arrayOfString() throws IOException{return br.readLine().split(" ");}
    static int[] arrayOfInt() throws IOException{return toIntArray(arrayOfString());}
    // 変換
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {return Integer.parseInt(val);}
    static int[] toIntArray(String[] array) {return Stream.of(array.clone()).mapToInt(Integer::parseInt).toArray();}
    static String joinToString(String[] array) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < array.length;i++) sb.append(array[i]);
        return sb.toString();
    }

    // 出力
    static void println(Object val){pw.println(val);}
}


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

int *flag;

void prime(int num){
	int i,j;

	flag = (int *)calloc(sizeof(int),num+1);

	for(i = 2;i*i <= num;i++){
		if(flag[i] == 0){
			for(j = 2;i*j <= num;j++){
				flag[i*j] = 1;
			}
		}
	}
}

int main(){
	int n,i,cnt;

	prime(50000);

	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		i = 2;
		cnt = 0;
		while(i*2 <= n){
			if(!flag[i] && !flag[n-i]){
				cnt++;
			}
			i++;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 808
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)

#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld\n",a)

#define stll(a) stoll(a,nullptr,10)
#define PII pair<ll,ll>
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define EL printf("\n")
#define ff first
#define ss second


#define mem(ar,val) memset(ar,val,sizeof(ar))
#define ssort(ar) sort(ar.begin(),ar.end())
#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)

#define bug1(a) cout<<"test "<<a<<endl;
#define bug2(a,b) cout<<"test "<<a<<" "<<b<<endl;
#define bug3(a,b,c) cout<<"test "<<a<<" "<<b<<" "<<c<<endl;
#define bug4(a,b,c,d) cout<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define fout freopen("output.txt","w",stdout)
#define fin  freopen("input.txt","r",stdin)

/// unordered_map<int,int>mp;
/// mp.reserve(1024);
/// mp.max_load_factor(0.25);

/// pbds
/// *find_by_order(k) - return k th largest element.. 0 based
/// order_of_key(k) - number of items strictly smaller than k

/*
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
*/

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


int main()
{
    ll n;
    cin>>n;
    ll lcm = (360*n)/__gcd(360LL,n);
    ll ans = lcm/n;
    cout<<ans<<endl;

}




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

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

  int num = stoi(N);
  vector<int> v_x(N.size());

  rep(i, 0, N.size()) v_x.at(i) = int(N[i]-'0');

  int temp = 0;
  rep(i, 0, v_x.size()) temp += v_x.at(i);

  cout << ( num%temp ? "No" : "Yes" ) << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0

for i in range(N):
    if A[i] >= B[i]:
        count += B[i]
    else:
        count += A[i]
        B[i] -= A[i]
        if A[i+1] >= B[i]:
            count += B[i]
            A[i+1] -= B[i]
        else:
            count += A[i+1]
            A[i+1] = 0

print(count)

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

using namespace std;

typedef long long ll;
int n, a, b, c, d;
ll dyn[1100][1100], MOD = 1000000007;
ll fac[1100], fnv[1100], fnp[1100][1100];

ll power(ll a, ll n) {
    if (!n) return 1;
    ll tmp = power(a,n/2);
    return tmp*tmp%MOD*((n&1)?a:1)%MOD;
}

int main() {
    int i, j, k;

    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    dyn[0][a-1] = 1;
    fac[0] = fnv[0] = 1;
    for (i=1;i<=n;i++) {fac[i]=fac[i-1]*i%MOD; fnv[i] = power(fac[i],MOD-2);}
    for (i=0;i<=n;i++) for (j=0;j<=n;j++) fnp[i][j] = power(fnv[i],j);
    for (i=0;i<=n;i++) {
        for (j=a;j<=b;j++) {
            ll &res = dyn[i][j]; res = dyn[i][j-1];
            for (k=c;k<=d&&i-k*j>=0;k++) {
                res += dyn[i-j*k][j-1]*fac[i]%MOD*fnv[i-k*j]%MOD*fnp[j][k]%MOD*fnv[k]%MOD;
                res %= MOD;
            }
        }
    }
    printf("%lld\n",dyn[n][b]);

    return 0;
}


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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N, M, L;
int dp[6][300][41][1 << 9];

struct S {
  int a, k, t;
  S(int a_, int k_, int t_) {
    a = a_; k = k_; t = t_;
  }
};

vector<S> D[5];

int dfs(int d, int n, int l, int bit) {
  //cout << d << " " << n << " " << l << " " << bit << endl;;
  if ( d == 5 || l == 0 ) return 0;
  if ( D[d].size() == n ) return dfs(d+1, 0, l, 0);
  if ( dp[d][n][l][bit] ) return dp[d][n][l][bit];

  int ret = dfs(d, n+1, l, bit);
  int a = D[d][n].a, k = D[d][n].k, t = D[d][n].t;
  bool flag = true;
  for ( int i = a; i < a+k; i++ ) {
    if ( bit & (1 << i) ) {
      flag = false;
      break;
    }
  }
  
  if ( flag ) {
    int nbit = bit;
    for ( int i = a; i < a+k; i++ ) {
      nbit |= (1 << i);	
    }
    ret = max(ret, dfs(d, n+1, l-1, nbit) + t);
  }

  return dp[d][n][l][bit] = ret;
}


signed main() {
  cin >> N >> M >> L;

  Rep(i, M) {
    int d, a, k, t;
    cin >> d >> a >> k >> t;
    a--;
    D[d].pb(S(a, k, t));
  }
  //cout << endl;
  cout << dfs(0, 0, L, 0) << endl;
}

Measured memory_bytes: 28992
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;
 
int func(int ind, int flag) {
 
	if (ind == n) return 0;
 
	if (dp[ind][flag] != -1) return dp[ind][flag];
 
	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}
 
	return dp[ind][flag] = maxi;
}
 
int main() {
 
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
 
	memset(dp, -1, sizeof dp);
 
	cout << func(0, 0);
 
	return 0;
}

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

int main()
{
	int X, Y, R, W, H;
	cin >> W >> H >> X >> Y >> R;
	cout << ((0 <= X - R && X + R <= W && 0 <= Y - R && Y + R <= H) ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 3092
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
        int[] a = new int[100];
        int k = 0;
        while(sc.hasNext()){
        	a[k] = sc.nextInt();
        	k++;
        }
		
		int[] num = new int[100];
		
		for(int i=0; i<a.length; i++){
			if(a[i]==0){
				break;
			}else{
				num[a[i]-1] += 1;
			}
		}
		
		/*
		for(int i=0; i<10; i++){
				System.out.println(i+1 + ":" +num[i]);
		}
		*/
		
		int target = 0;
		int j = 0;
		int[] ans = new int[100];
		for(int i=0; i<num.length; i++){
			if(i==0 || target < num[i]){
				j = 0;
				target = num[i];
				ans = new int[100];
				ans[j] = i;
			}else if(target == num[i]){
				j += 1;
				ans[j] = i;
			}
		}
		
		for(int i=0; i<ans.length; i++){
			if(i>0 && ans[i]==0){
				break;
			}else{
				System.out.println(ans[i]+1);
			}
		}
		
	}
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  ll N,A,B;
  cin>>N>>A>>B;
  ll ans=A*(N/(A+B));
  ans+=min(A,N-(A+B)*(N/(A+B)));
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    ll n,a,b;
    std::cin >> n>>a>>b;
    ll res = (ll)1e18+10;
    res = min(n-a,b-1);
    
    if((b-a)%2==0){
        res = min(res,(b-a)/2);
    }else{
        res = min(res,(b-a-1)/2+a);
        res = min(res,(b-a-1)/2+n-b+1);
    }
    
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

//ミョ(-ω- ?)
int main() {
    long long a;
    string s;
    cin >> a >> s;
    s.erase(s.begin()+1);
    long long b = stoll(s);
    cout << fixed << setprecision(0) << a*b/100 << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++) {L[i] = A[left + i];}
	for(int i = 0; i < n2; i++) {R[i] = A[mid + i];}
	L[n1].value = R[n2].value = SENTINEL;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		if(L[i].value <= R[j].value){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(struct Card A[], int n, int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(struct Card A[], int n, int p, int r){
	int i,j;
	struct Card t, x;
	x = A[r];
	i = p-1;
	for(j = p; j < r; j++){
		if(A[j].value <= x.value){
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	t = A[i + 1];
	A[i + 1] = A[r];
	A[r] = t;
	return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
	int q;
	if(p < r){
		q = partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%s %d", S, &v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i = 0; i < n; i++){
		if(A[i].suit != B[i].suit){stable = 0;}
	}
	if(stable == 1){printf("Stable\n");}
	else {printf("Not stable\n");}
	for(i = 0; i < n; i++){
		printf("%c %d\n", B[i].suit, B[i].value);
	}
	
	return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int disum(int n) {
	int sum = 0;

	while (n) {

		sum += n % 10;
		// sum++;
		n /= 10;





	}
	return sum;

}


// #define maxa 1000000




int give(int m){


	if(m%2)
		return 3*m+1;
	return m/2;


}





int main() {
	int i, n, m, k, c1 = 0, sum = 0;
	c_p_c();
	cin>>m;
	set<int> st;
	st.insert(m);
	for (int i = 1; i < 1000000; ++i)
	{
		/* code */
		m=give(m);

		if(st.find(m)!=st.end()){
			cout<<i+1<<endl;
			break;
		}
		st.insert(m);
		// watch(m);


	}


}




Measured memory_bytes: 3592
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();

    if (d == 3 || d == 5 || d == 7) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


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

int BsearchQ(int A[],int n,int key){
	int l = 0;
	int r = n;
	while(l<r){
		int mid=(l+r)/2;
		if(A[mid]==key){
			return 1;
		}else if(A[mid]<key){
			l=mid+1; 		
		}else {
			r=mid;
		}
		
	}
	return 0;
}

int main() {
	int n,A[100000+5],q,key,sum=0;
	
	cin>>n;
	for(int i=0;i<n;i++) cin>>A[i];
	
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>key;
		sum+=BsearchQ(A,n,key);
	} 
	cout<<sum<<endl;
	return 0;
}

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

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

    vector<int> a(N);
    vector<int> b(N);

    long long suma=0;
    long long sumb=0;

    for(int i=0;i<N;++i)
    {
        cin >> a[i];
    }

    for(int i=0;i<N;++i)
    {
        cin >> b[i];
    }

    long long step = 0;
    for(int i=0;i<N;++i)
    {
        if (a[i]%2 != b[i]%2)
        {
            b[i]++;
            step++;
        }
        if (a[i]>b[i])
        {
            step += a[i]-b[i];
        }
        else
        {
            step -= (b[i]-a[i])/2;
        }
    }
  
    if (step > 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 384
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func solve(a, b, c int) {
	if a%2 == 1 || b%2 == 1 || c%2 == 1 {
		out(0)
		return
	}
	flg := true
	cnt := 0
	for i := 0; i < 10000; i++ {
		a, b, c = b+c, a+c, a+b
		if a%2 == 1 || b%2 == 1 || c%2 == 1 {
			flg = false
			break
		}
		cnt++
		a /= 2
		b /= 2
		c /= 2
	}
	if flg == false {
		out(cnt)
	} else {
		out(-1)
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	A, B, C := getInt(), getInt(), getInt()

	// a := PfsMap(A)
	// b := PfsMap(A)
	// c := PfsMap(A)

	// out(min(a[2], min(b[2], c[2])))
	solve(A, B, C)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	int N,E,limit,tmp,minimum;
	scanf("%d %d",&N,&E);

	int table[15] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384};

	limit = pow(2,N);

	int cost[N][N];

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)cost[i][k] = BIG_NUM;
	}

	int from,to,value;

	for(int i = 0; i < E; i++){
		scanf("%d %d %d",&from,&to,&value);
		cost[from][to] = value;
	}

	int** dp = new int*[N];
	for(int i = 0; i < N; i++){
		dp[i] = new int[limit];
		for(int k = 0; k < limit; k++){
			dp[i][k] = BIG_NUM;
		}
	}

	minimum = BIG_NUM;

	tmp = pow(2,0);

	dp[0][tmp] = 0;

	for(int state = 0; state <= limit-1; state++){
		for(int k = 0; k < N; k++){
			if(dp[k][state] == BIG_NUM)continue;
			for(int a = 0; a < N; a++){
				if(state & (1 << a)){
					if(state == limit-1 && a == 0){
						if(cost[k][0] != BIG_NUM)dp[0][limit-1] = min(dp[0][limit-1],dp[k][state]+cost[k][0]);
					}
				}else{
					if(cost[k][a] != BIG_NUM){
						tmp = state + table[a];
						dp[a][tmp] = min(dp[a][tmp],dp[k][state]+cost[k][a]);
					}
				}
			}
		}
	}

	minimum = min(minimum,dp[0][limit-1]);


	if(minimum == BIG_NUM){
		printf("-1\n");
	}else{
		printf("%d\n",minimum);
	}

}



Measured memory_bytes: 4776
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func score(scoreX, scoreY int) int {
	return abs(scoreX - scoreY)
}

const INF = 1000001000

// プレイヤーxがy枚目を引いた時のスコア
var memo [][]int

func dfs(scoreX, scoreY, n int, player int) int {

	if n == N {
		// fmt.Println(score(scoreX, scoreY))
		return score(scoreX, scoreY)
	}

	if memo[player][n] != -1 {
		return memo[player][n]
	}

	if player == 1 {
		ma := -1 * INF
		for i := n; i < N; i++ {
			ma = max(ma, dfs(a[i], scoreY, i+1, 0))
		}
		memo[player][n] = ma
		return memo[player][n]
	} else {
		mi := INF
		for i := n; i < N; i++ {
			mi = min(mi, dfs(scoreX, a[i], i+1, 1))
		}
		memo[player][n] = mi
		return memo[player][n]
	}

	// var res int

	// for i := n; i < N; i++ {
	// 	if player == 1 {
	// 		res = max(-1*INF, dfs(a[i], scoreY, i+1, 0))
	// 		memo[player][i] = res
	// 	} else {
	// 		res = min(INF, dfs(scoreX, a[i], i+1, 1))
	// 		memo[player][i] = res
	// 	}

	// }

	// ans := -1*INF
	// for i := 0; i

	// return memo[player][n]
}

var N, Z, W int
var a []int

func main() {
	sc.Split(bufio.ScanWords)
	N, Z, W = nextInt(), nextInt(), nextInt()

	memo = make([][]int, 2)
	for i := 0; i < 2; i++ {
		memo[i] = make([]int, 2020)
		for j := 0; j < 2020; j++ {
			memo[i][j] = -1
		}
	}

	a = make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}

	fmt.Println(dfs(Z, W, 0, 1))

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 1152
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    INF = 10**9
    H, W = input_nums()
    ss = [input() for _ in range(H)]
    dp = [[0]*W for _ in range(H)]
    if ss[0][0] == '#': dp[0][0] = 1
    for h in range(H):
        for w in range(W):
            if (h, w) == (0, 0): continue
            u = l = INF
            if h-1>=0:
                u = dp[h-1][w]
                if ss[h][w] == '#' and ss[h-1][w] == '.': u += 1
            if w-1>=0:
                l = dp[h][w-1]
                if ss[h][w] == '#' and ss[h][w-1] == '.': l += 1
            dp[h][w] = min(u, l)
    print(dp[H-1][W-1])

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
XYH.sort(key=lambda x:x[2])
X, Y, H = XYH[-1]
for cx in range(101):
    for cy in range(101):
        h = H + abs(cx-X) + abs(cy-Y)
        flag = False
        for xyh in XYH:
            if xyh[2] != max(h-abs(cx-xyh[0])-abs(cy-xyh[1]), 0):
                flag = True
        if flag: continue
        print(cx, cy, h)
        exit()

Measured memory_bytes: 3064
import math

A, B, H, M = map(int, input().split())
h = H * 30 + M / 2
m = M * 6
sita = min(abs(h - m), 360 - abs(h - m))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(sita))))


Measured memory_bytes: 62408
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200+10;
const int M=1e5+10;
const int MOD=1e9+7;
int n,x;
int a[N],f[N][M];

int main()
{
	scanf("%d%d",&n,&x);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	
	f[1][x]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=x;j++) {
			f[i+1][j%a[i]]=((LL)f[i+1][j%a[i]]+(LL)f[i][j])%MOD;
			f[i+1][j]=((LL)f[i+1][j]+(LL)f[i][j]*(n-i)%MOD)%MOD;
		}
	
	LL ans=0;
	for (int j=0;j<x;j++) ans=(ans+(LL)f[n+1][j]*j)%MOD;
	cout<<ans<<endl;	
	return 0;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  bool ok = true;
  rep(i, sz(s)){
    if(i % 2 == 0 && s[i] == 'L')ok = false;
    if(i % 2 == 1 && s[i] == 'R')ok = false;
  }
  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
/**
 * 
 */

/**
 * @author saiyo
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int men[] = new int[6];
		for(int i = 0; i < 6; i++){
			men[i] = scan.nextInt();
		}
		//String meirei = scan.next();
		// TODO 自動生成されたメソッド・スタブ
		
		
		Dice d1 = new Dice(men);
		int count = scan.nextInt();
		for(int i = 0; i < count; i++){
			int tp = scan.nextInt(), fr = scan.nextInt();
			d1.turnDice(tp, fr);
			//d1.turnDice(meirei);
			System.out.println(d1.getDiceMen(3));
		}
	}

}


class Dice{
	private int diceMen[] = new int[6];
	
	Dice(int men[]){
		for(int i = 0; i < 6; i++)
			this.diceMen[i] = men[i];
	}
	
	public int getDiceMen(int m){
		return this.diceMen[m - 1];
	}
	
	public void turnDice(int tp, int fr){
		int nullBox;
		while(this.diceMen[0] != tp){
			turnDice("S");
			if(this.diceMen[0] == tp){
				break;
			}
			turnDice("W");
		}
		while(this.diceMen[1] != fr){
			nullBox = diceMen[1];
			diceMen[1] = diceMen[2];
			diceMen[2] = diceMen[4];
			diceMen[4] = diceMen[3];
			diceMen[3] = nullBox;
			
		}
	}
	
	public void turnDice(String mei){
		int nullBox;
		char[] stWord = stlipWord(mei);
		for(char word: stWord){
			switch(word){
			case 'S':
				nullBox = this.diceMen[0];
				this.diceMen[0] = this.diceMen[4];
				this.diceMen[4] = this.diceMen[5];
				this.diceMen[5] = this.diceMen[1];
				this.diceMen[1] = nullBox;
				break;
			case 'E':
				nullBox = this.diceMen[0];
				this.diceMen[0] = this.diceMen[3];
				this.diceMen[3] = this.diceMen[5];
				this.diceMen[5] = this.diceMen[2];
				this.diceMen[2] = nullBox;
				break;
			case 'W':
				nullBox = this.diceMen[0];
				this.diceMen[0] = this.diceMen[2];
				this.diceMen[2] = this.diceMen[5];
				this.diceMen[5] = this.diceMen[3];
				this.diceMen[3] = nullBox;
				break;
			case 'N':
				nullBox = this.diceMen[0];
				this.diceMen[0] = this.diceMen[1];
				this.diceMen[1] = this.diceMen[5];
				this.diceMen[5] = this.diceMen[4];
				this.diceMen[4] = nullBox;
				break;
			}
		}
		
	}
	
	public char[] stlipWord(String mei){
		char[] stlipWord = new char[mei.length()];
		for(int i = 0; i < mei.length(); i++){
			stlipWord[i] = mei.charAt(i);
		}
		return stlipWord;
	}
	
}


Measured memory_bytes: 26156
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ar[n];
  for(int i=0;i<n;i++)
    cin>>ar[i];
  int dp[n];
  dp[1]=abs(ar[1]-ar[0]);
  dp[2]=min(abs(ar[2]-ar[0]),dp[1]+abs(ar[2]-ar[1]));
  for(int i=3;i<n;i++)
  {
    dp[i]=min(abs(ar[i]-ar[i-2])+dp[i-2],abs(ar[i]-ar[i-1])+dp[i-1]);
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    int expo[]={1000,512,343,243,216,128,125,32,27,8};
    cin>>x;
    int s=sqrt(x);
    int ans=s*s;
    for(int i=0;i<10;i++){
        if(x>=expo[i])ans=max(ans,expo[i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, K, C = in.next().toInt
  val S = in.next().toArray

  //
  val o = 'o'
  val x = 'x'

  var cnt = 0
  var i = 0

  val L = new Array[Int](K)
  val R = new Array[Int](K)

  while (i < N) {
    if (S(i) == o) {
      cnt += 1
      i += C+1
    }
    else {
      i += 1
    }
  }

  var ans = List[Int]()
  if (cnt == K) {
    cnt = 0
    i = 0
    while (i < N) {
      if (S(i) == o) {
        L(cnt) = i
        i += C+1
        cnt += 1
      }
      else {
        i += 1
      }
    }

    cnt = K-1
    i = N-1
    while (i >= 0) {
      if (S(i) == o) {
        R(cnt) = i
        i -= C+1
        cnt -= 1
      }
      else {
        i -= 1
      }
    }

    for (i <- 0 until K) {
      if (L(i) == R(i))
        ans = (L(i) + 1) :: ans
    }

    ans.reverse.foreach{pw.println}
    pw.flush()
  }
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 69872
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;


int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(a[i]+a[j]>a[k]){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,a,b = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)

ans = 0

def min(a,b)
  a < b ? a : b
end

(n-1).times do |i|
  ans += min((x[i+1]-x[i])*a,b)
end

puts ans

Measured memory_bytes: 9476
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

#define SZ(a) (int)(a).size()
typedef long long ll;

int main() {
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> t;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		t[x]++;
	}
	int mn = begin(t)->first;
	int mx = prev(end(t))->first;
	int m;
	if (mx > mn+1) {
		puts("No");
		return 0;
	}
	else if (mx == mn) {
		if (mx == n-1) {
			puts("Yes");
			return 0;
		}
		m = mx;
	}
	else {
		m = mx-t[mn];
		n -= t[mn];
	}
	puts(m <= n/2 && m >= 1 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 4992
n=int(input())
a=[]
for i in range(2):
    a.append(list(map(int,input().split())))

dp= [[-1 for i in range(n)] for j in range(2)]

dp[0][0]=a[0][0]
dp[1][0]=dp[0][0]+a[1][0]

for i in range(1,n):
    dp[0][i]=dp[0][i-1]+a[0][i]
    dp[1][i]=max(dp[1][i-1]+a[1][i],dp[0][i]+a[1][i])


#for i in range(2):
    #print(dp[i])
print(dp[-1][-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int lcm(int x, int y){
    return x/__gcd(x,y)*y;
}

int main(){
    set<int> bp;
    for(int i:{13,17,19,23}) bp.insert(i);

    int a = 1, b = 1;
    for(int i=1; i<=24; ++i){
        if(bp.count(i)) b = lcm(b,i);
        else a = lcm(a,i);
    }

    int n;
    while(cin >>n,n){
        vector<int> A(a), B(b);

        rep(i,n){
            int d,t;
            cin >>d >>t;

            vector<int> x(d);
            rep(j,d) cin >>x[j];

            if(bp.count(d)){
                rep(j,b) B[j] += x[(j+t)%d];
            }
            else{
                rep(j,a) A[j] += x[(j+t)%d];
            }
        }

        int maxA = 0, maxB = 0;
        rep(i,a) maxA = max(maxA, A[i]);
        rep(i,b) maxB = max(maxB, B[i]);
        cout << maxA+maxB << endl;
    }

    return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#define rg register
using namespace std;
signed main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(a-c)*(b-d)<<endl;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
m = 0
for i in range(n):
    if a[i]<m:
        print("No")
        break
    m = max(m, a[i]-1)
else:
    print("Yes")

Measured memory_bytes: 85488
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N;
vector<llong>A;
llong T;
llong ANS = 0;

int main() {
	cin >> N;
	cin >> T;
	for (int i = 0; i < N; i++) {
		llong a;
		cin >> a;
		A.push_back(a);
	}

	llong LowestPrice = 1000000007;
	llong HighestBenefit = 0;
	for (int i = 0; i < N; i++) {
		LowestPrice = min(LowestPrice, A[i]);
		HighestBenefit = max(HighestBenefit, A[i] - LowestPrice);
	}
	LowestPrice = 1000000007;
	for (int i = 0; i < N; i++) {
		LowestPrice = min(LowestPrice, A[i]);
		int Benefit = A[i] - LowestPrice;
		if (Benefit == HighestBenefit) {
			ANS++;
		}
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,ans,sum=0;
    cin>>n;
    for(int i=sqrt(n);i>=0;i--)
    {
        if(n%i==0)
        {
            ans=n/i;
            break;
        }
    }
    while(ans)
    {
        sum++;
        ans=ans/10;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.replaceAll("eraser", "").replaceAll("erase", "").replaceAll("dreamer", "").replaceAll("dream", "")
                .equals("")) {
            System.out.println("YES");
        
        } 

        else {
            System.out.println("NO");
        }
        
        sc.close();
    }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	string s;
	int cnt[255]={};

	cin >> s;
	for(auto c: s) cnt[c]++;

	int d = 0;
	chmax(d, abs(cnt['a'] - cnt['b']));
	chmax(d, abs(cnt['b'] - cnt['c']));
	chmax(d, abs(cnt['c'] - cnt['a']));

	bool ans = (d <= 1);

	cout << (ans?"YES":"NO") << endl;

	return 0;
}


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

int main(void) {

	int n;
	cin >> n;
	int i = 1;
	while (++i <= n) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
			continue;
		}
		while (x) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll fact[200000], invFact[200000], memo[1009];

long long power(long long x, long long c) {
    if(c==0) return 1;
    if(c==1) return x;
    if (c%2==1) return (power( (x*x)%MOD, c/2)*x)%MOD;
    else return power( (x*x)%MOD, c/2)%MOD;
}

void make_combT(ll n){
    fact[0]=1;
    rep1(i,n) fact[i]= fact[i-1]*i%MOD;
    
    invFact[n] = power(fact[n],MOD-2);
    rrep(i,n-1) invFact[i] = invFact[i+1] * (i+1) %MOD;
}

ll comb(ll n, ll m){
    if(n<m||n<0||m<0) return 0;
    return (fact[n] * invFact[m] %MOD) * invFact[n-m] %MOD;
}

ll inv(int k){
    if(memo[k]) return memo[k];
    return memo[k]=power(k,MOD-2);
}

ll dp[1009][1009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make_combT(1009);
    
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    
    rep(i,1009) dp[i][0]=1;
    for(int i=A;i<=B;i++){
        rep(j,N+1)if(dp[i][j]){
            if(j) (dp[i+1][j]+=dp[i][j])%=MOD;
            ll p=1;
            for(int k=1;k<=D&&j+i*k<=N;k++){
                p=(((p*comb(N-j-i*(k-1),i)%MOD)*inv(k))%MOD)%MOD;
                if(k>=C) (dp[i+1][j+i*k]+=(dp[i][j]*p)%MOD)%=MOD;
            }
        }
    }
    cout1(dp[B+1][N])
}

Measured memory_bytes: 10496
#include<stdio.h>

int main(void){
    char s[3];
    scanf("%s",s);

    if(s[0]==s[1] && s[2]==s[3] && s[1] != s[2] ||
       s[0]==s[3] && s[1]==s[2] && s[0] != s[1] ||
       s[0]==s[2] && s[1]==s[3] && s[0] != s[1]){
           printf("Yes\n");
       }else{
           printf("No\n");
       }

       return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N;
int ret;
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x>>y;
		ret+=y-x+1;
	}
	cout<<ret<<endl;
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 256
M = 6400
mid = M//2
INF = 10**18

H,W = map(int, input().split())
As = []
for i in range(H):
    As.append(list(map(int, input().split())))
diffs = []
for i in range(H):
    bs = list(map(int, input().split()))
    diffs.append([abs(a-b) for a,b in zip(As[i],bs)])

# bitset高速化
# 初期値
dp = [[0]*W for j in range(H)]
dp[0][0] = 1 << (mid+diffs[0][0]) #プラスマイナス考慮して、下駄をはかせる
for i in range(H):
    for j in range(W):
        # 行方向
        if i+1 < H:
            d = diffs[i+1][j]
            dp[i+1][j] |= dp[i][j] >> d  
            dp[i+1][j] |= dp[i][j] << d  
        # 列方向
        if j+1 < W:
            d = diffs[i][j+1]
            dp[i][j+1] |= dp[i][j] >> d
            dp[i][j+1] |= dp[i][j] << d

ans = INF
for i in range(M):
    if dp[H-1][W-1] >> i & 1:
        # print(i-mid)
        ans = min(ans, abs(i-mid))
print(ans)


Measured memory_bytes: 12788