akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int cmp(int a,int b){
    return a>b;
}
int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n,cmp);
    int sum=0;
    for(int i=0;i<m;i++) sum+=a[i];
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;



int main(int argc, char **argv) {
    i64 a, b, n;
    cin >> a >> b >> n;

    if (n < b)
        cout << floor((a*n)/b) - a*floor(n/b) << endl;
    else
        cout << floor((a*(b-1))/b) - a*floor((b-1)/b) << endl;

    return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INTXT std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
#define INF 1e9

using namespace std;
typedef long long ll;
static const ll MOD = 1000000007LL;

signed main() {
  IOS
  int n, m;
  cin >> n >> m;

  priority_queue<int> pq;
  REP(i, n){
    int tmp;
    cin >> tmp;
    pq.push(tmp);
  }
  
  vector<pair<int, int>> op;
  REP(i, m){
    int b, c;
    cin >> b >> c;
    op.push_back(make_pair(-c, b));
  }
  sort(op.begin(), op.end());
  
  int cnt = 0;
  for(auto x : op){
    REP(i, x.second){
      pq.push(-1 * x.first);
    }
    cnt += x.second;
    if (cnt > n) break;
  }
  
  ll sum = 0;
  REP(i, n){
    sum += pq.top();
    pq.pop();
  }
  cout << sum << endl;
}


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

int main() {
    // your code goes here
    ll a,b,i;
    cin >> a >> b;
    if(a>b) swap(a,b);
    for(i=0;i<b;i++) cout << a;
    cout << endl;
    return 0;
}

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

int n = 0 ;
char str[30] = {0} ;
char ring[120][30] = {0} ;

int solve()
{
  int ans = 0 ;
  for ( int i = 0 ; i < n ; i++ )
  {
    for ( int j = 0 ; j < 10 ; j++ )
    {
      if ( ring[i][j] == str[0] )
      {
        int flg = 1 ;
        for ( int k = 1 ; k < strlen(str) ; k++ )
        {
          if ( j+k < 10 )
          {
            if ( ring[i][ (j+k) ] == str[k] ) flg++ ;
            else break ;
          }
          else
          {
            if ( ring[i][ (j+k)-10 ] == str[k] ) flg++ ;
            else break ;
          }
        }
        if ( flg == strlen(str) )
        {
          ans++ ;
          break ;
        }
      }
    }
  }
  return ans ;
}

int main()
{
  cin >> str >> n ;
  for ( int i = 0 ; i < n ; i++ )
  {
    cin >> ring[i] ;
  }
  printf("%d\n", solve()) ;
  return 0 ;
}

Measured memory_bytes: 3204
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int total = 0;
	for (int i = 0; i < S.length(); i++) {
		total += S[i]-'0';
	}

	if (total % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3748
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    ll n;
    ll m;
    cin >> n >> m;
    rep(i, m) {
        ll a;
        cin >> a;
        n -= a;
    }

    if(n<0) {
        print(-1);
    } else {
        print(n);
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
#define ll long long int
#define F first
#define S second
#define INF (ll)1000000000
const int N = 1e5 + 5;
#define maax(a,b,c) max((int)a,max((int)b,(int)c))
#define miin(a,b,c) min((int)a,min((int)b,(int)c))
#define mp make_pair
#define in long long int
#define ep emplace_back
#define all(a) a.begin(),a.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf (long long) 1e18
#define vl vector<ll>
#define sz(a) (ll)a.size()
#define mem(a,b) memset(a,b,a.size())
#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
#define rall(x) (x).rbegin(), (x).rend()
typedef long long LL;
typedef pair<int, int> PII;	
int solve()
{
	
    return 0;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    int n;cin>>n;(n%2==0)?cout<<n/2:cout<<(n/2)+1;
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>

using namespace std;

const long MOD = 1000000007;

long dp[2000][2000];
long sum[2000][2000];

int main(){
    int N, M;
    cin >> N >> M;
    int S[2000], T[2000];
    long ans = 1;
    for(int i = 0; i < N; i++) cin >> S[i];
    for(int i = 0; i < M; i++) cin >> T[i];

    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(S[i] == T[j]){
                if(i == 0) dp[i][j] = 1;
                else if(j == 0) dp[i][j] = 1;
                else dp[i][j] = sum[i-1][j-1];
                dp[i][j] %= MOD;
            }else{
                dp[i][j] = 0;
            }
            if(i == 0 && j == 0) sum[i][j] = dp[i][j]+1;
            else if(i == 0) sum[i][j] = sum[i][j-1] + dp[i][j];
            else if(j == 0) sum[i][j] = sum[i-1][j] + dp[i][j];
            else sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j];
            sum[i][j] %= MOD;
            sum[i][j] += MOD;
            sum[i][j] %= MOD;
            ans += dp[i][j];
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 62720
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int n,pm,pe,pj;
	while(stdIn.hasNextInt()){
	    n = stdIn.nextInt();
	    for(int i = 0;i < n;i++){
		pm = stdIn.nextInt();
		pe = stdIn.nextInt();
		pj = stdIn.nextInt();
		if(pm == 100 || pe == 100 || pj == 100){
		    System.out.println("A");
		}else if((pm + pe) / 2 >= 90){
		    System.out.println("A");
		}else if((pm + pe + pj) / 3 >= 80){
		    System.out.println("A");
		}else if((pm + pe + pj) / 3 >= 70){
		    System.out.println("B");
		}else if((pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)){
		    System.out.println("B");
		}else System.out.println("C");
	    }
	}
    }
}

Measured memory_bytes: 28288
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k;
  cin >> k;
  
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  cout << a[k-1] << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct mint {
    ll x;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    ll value() const {
        return x;
    }
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (t == 0) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t % 2 == 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) {
            ifact[i - 1] = ifact[i] * i;
        }
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    mint h(int n, int k) {
        n += k - 1;
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(2002002);
int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    mint ans = 0;
    rep(i, n) {
        ans += comb(i, k - 1) * a[i];
        ans -= comb(n - i - 1, k - 1) * a[i];
    }
    cout << ans.value() << endl;
}


Measured memory_bytes: 32256
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

map<int, int>m;
pair<int, int>mm[100000];

int main() {
	int N;
	while (cin >> N, N) {
		for (int i = 0; i < N; i++) {
			int team;
			cin >> team;
			int m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			mm[i].first = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			mm[i].second = team;
		}
		sort(mm,mm+N);
		//for (int i = 0; i < N; i++) {
		//	cout << mm[i].second << endl;
		//}
		cout << mm[0].second << endl << mm[1].second << endl << mm[N-2].second << endl;
	}
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
// #define map unordered_map
// #define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll K;
  scanf("%lld", &K);

  ll A, B;
  scanf("%lld %lld", &A, &B);

  bool r = false;
  for (ll i = A; i <= B; i++) {
    if (i % K == 0) {
      r = true;
      break;
    }
  }

  if (r) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra
    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll a,b;
        cin>>a>>b;
        cout<<6-a-b<<endl;
    }

Measured memory_bytes: 256
#include<stdio.h>
#define M 200000
int main(){
  int i,j,t,r,s[10000],a,b,c,d;
  char p[M]={1,1};
  for(i=2;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  while(scanf("%d %d",&a,&b),a+1||b+1){
    r=c=0;
    for(i=a+1;c++<b;i++){//printf(" %d\n",c);
      while(p[i])i++;
      d=c-1;
      for(j=i;d++<b;j++){
	while(p[j])j++;
	s[r++]=i+j;//printf("%d\n",s[r-1]);
      }
    }
    for(i=0;i<b;i++){
      for(j=r-1;j>i;j--){
	if(s[j-1]>s[j]){
	  t=s[j-1];
	  s[j-1]=s[j];
	  s[j]=t;
	}
      }
    }
    printf("%d\n",s[b-1]);
  }
  return 0;
}

Measured memory_bytes: 820
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <math.h>

#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
#define ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

int main(){
    cin.tie();
    ios::sync_with_stdio(false);
    long int n,a;
    int ans=10;
    cin >> n;
    FOR(i,1,sqrt(n)+1){
        if(n%i==0){
            a = n/i;
            long int num = max(a,(long int)i);
            int digit=0;
            while(num!=0){
                num /= 10;
                digit++;
            }
            if(digit<ans) ans =digit;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
#define endl '\n'
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define _ <<' '<<
using ll = long long;


signed main(){
	FAST
	string A,B;
	cin>> A >> B;
	cout << B+A << endl;;
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int H,M,S,A;
    scanf("%d",&A);
    H=A/3600;
    M=(A-(3600*H))/60;
    S=(A-(3600*H)-(M*60));
    printf("%d:%d:%d\n",H,M,S);
    return 0;
    
}


Measured memory_bytes: 2712
a,b = map(int,input().split())
if a>0 and b>0 :
    print("Positive")
elif a<0 and b<0 :
    t = abs(a)-abs(b)+1 
    if t%2 == 0 :
        print("Positive")
    else :
        print("Negative")
else:
    print("Zero")

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int a,b,n;
	int p[80000];
	p[0]=2;
	n=1;
	for(a=3;a<60000;a++){
		for(b=0;b<n;b++){
			if(a%p[b]==0){break;}
			if(a/p[b]<p[b]){
				p[n]=a;
				n++;
				break;
			}
		}
	}
	p[n]=60000;
	for(;;){
		if(scanf("%d",&a)==EOF){break;}
		n=0;
		while(a>=p[n]){
			n++;
		}
		if(p[n-1] == a){printf("%d %d\n",p[n-2],p[n]);}
		else{printf("%d %d\n",p[n-1],p[n]);}
	}
	return 0;
}

Measured memory_bytes: 0
N,M,K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N+1):
    A[i] += A[i-1]
for i in range(1, M+1):
    B[i] += B[i-1]

ans = 0
j = M

for i in range(N+1):
    if A[i] > K:
        break
    while A[i] + B[j] > K:
        j -= 1
    ans = max(ans, i + j)

print(ans)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    std::cout << std::fixed;
    std::cout << std::setprecision(12);
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double deg = abs(2*M_PI*(h/12-11*m/720));//rad
    double ans = sqrt(pow(a*sin(deg),2)+pow(b-a*cos(deg),2));
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 4152
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C, K;
    cin >> N >> C >> K;
    int T[100010];
    rep(i, N) cin >> T[i];
    sort(T, T + N);
    int ans = 0;
    int a = 0, b = 0;
    while(a < N) {
        while(b + 1 < N && b + 1 - a  < C && T[b + 1] <= T[a] + K) {b++;}
        ans++;
        //cout << a << " " << b << " " << endl;
        a = b + 1;
        
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
int L,e,n,l;
struct as{
	int a,b,c;
}a[105];
int xx(int x){
	return -x&x;
}
int main(){
	scanf("%d",&L);
	for(int i=20;i>=0;i--){
		if(L&(1<<i)){
			n=i+1;
			break;
		}
	}	
	for(int i=1;i<n;i++){
		a[++e].a=i,a[e].b=i+1,a[e].c=1<<(n-i-1);
		a[++e].a=i,a[e].b=i+1,a[e].c=0;
	}
	if(L-xx(L)){
		for(int i=20;i>=0;i--){
			if((L-1)&(1<<i)){
				if(l)a[++e].a=1,a[e].b=n-i,a[e].c=l;
				l|=(1<<i);
			}
		}
		if(l)a[++e].a=1,a[e].b=n,a[e].c=l;
	}
	printf("%d %d\n",n,e);
	for(int i=1;i<=e;i++){
		printf("%d %d %d\n",a[i].a,a[i].b,a[i].c);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=k+1;i<=n;i++)
    {
        if(a[i]>a[i-k])
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}


Measured memory_bytes: 5204
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define INF 100000000000000
using namespace std;

typedef struct _CARD{
    unsigned char v[13];
}CARD;

typedef struct _DECK{
    CARD card_list[4];
}DECK;

int main() {
    long long n;
    char mark;
    long long number;
    DECK deck;
    cin >> n;
    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            deck.card_list[i].v[j] = 0;
        }
    }
    for(int i=0; i<n; i++){
        cin >> mark >> number;
        if(mark=='S'){
            deck.card_list[0].v[number-1] = 1;
        }
        if(mark=='H'){
            deck.card_list[1].v[number-1] = 1;
        }
        if(mark=='C'){
            deck.card_list[2].v[number-1] = 1;
        }
        if(mark=='D'){
            deck.card_list[3].v[number-1] = 1;
        }
    }

    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            if(deck.card_list[i].v[j]==0){
                if(i==0){
                    cout << "S " << j+1 << endl;
                }
                if(i==1){
                    cout << "H " << j+1 << endl;
                }
                if(i==2){
                    cout << "C " << j+1 << endl;
                }
                if(i==3){
                    cout << "D " << j+1 << endl;
                }
            }
        }
    }
}


Measured memory_bytes: 3108
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b=INTM()
    print(int((b-1+a-1.1)//(a-1)))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
           int n;
           cin >>n;

    vector<double> vec(n);
    for (int i = 0; i < n; i++) {
        cin>> vec.at(i);
    }
     
    double ave=0;
  for(int i=0;i<n;i++){
  ave += vec[i];
  }
  ave = ave / n;
  double k=10000;
  bool A=false;
  int c=0;
  for(int i=0;i<n;i++){
   
 if(k <= abs(ave - vec[i]) ){
    continue;
    }
    
    if(k >  abs(ave - vec[i])){
  k=min(abs(ave - vec [i]),k);
      c=i;
      
    }
  }
  cout <<c<<endl;
}

Measured memory_bytes: 3740
n = int(input())
A = [int(el) for el in input().split(' ')]
B = [int(el) for el in input().split(' ')]
C = [int(el) for el in input().split(' ')]

total = 0
last = 100
for a in A:
    total += B[a-1]
    if last == a - 1:
        total += C[last-1]
    last = a
print(total)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> arr(3);
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr.begin(), arr.end());
    cout << (arr[1] - arr[0]) + (arr[2] - arr[1]) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 301;
int mat[N][N],par[N][N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin>>n;
    memset(par, -1, sizeof(par));
    FOR(i, 0, n) {
    	FOR(j, 0, n) {
    		cin>>mat[i][j];
    	}
    }
    FOR(i, 0, n) {
    	FOR(j, 0, n) {
    		if(i == j) continue;
    		FOR(k, 0, n) {
    			if(k == i || k == j) continue;
    			if(mat[i][j] > mat[i][k] + mat[k][j]) {
    				cout<<-1;
    				return 0;
    			} else if (mat[i][j] == mat[i][k] + mat[k][j])
    			{
    				par[i][j] = k;
    			}
    		}
    	}
    }
    ll ans = 0;
    FOR(i, 0, n) {
    	FOR(j, 0, n) {
    		if(par[i][j] == -1) {
    			ans += (ll) mat[i][j];
    		}
    	}
    }
    cout<<ans/2;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
typedef long long ll;


using namespace std;

int count(vector<int>& h, int l, int r){
    if(l > r){return 0;}
    if(l == r){return h[l];}
    int minh=200;
    for(int i=l;i<=r;i++){
        minh = min(h[i],minh);
    }
    for(int i=l;i<=r;i++){
        h[i] -= minh;
    }
    int ret=minh;
    int now=l;
    for(int i=l;i<=r;i++){
        if(h[i] == 0){
            ret += count(h, now, i-1);
            now=i+1;
        }
    }
    ret += count(h, now, r);
    return ret;
}


int main(){
    int N;
    cin >> N;
    vector<int> h(N,0);
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    int ret=0;
    int now=0;
    for(int i=0;i<N;i++){
        if(h[i] == 0){
            ret += count(h, now, i-1);
            now = i+1;
        }
    }
    ret += count(h, now, N-1);

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  char a, b;
  cin >> a >> b;
  bool At_flag, To_flag;

  //At君の真偽性
  if(a == 'H')
    At_flag = true;
  else
    At_flag = false;

  //At君によるTop君の真偽性
  if(b == 'H')
    To_flag = true;
  else
    To_flag = false;

  //この2つのflagでXORをとり，否定をとれば答えが得られる
  bool ans = At_flag ^ To_flag;
  if(ans)
    cout << "D" << endl;
  else
    cout << "H" << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())

int main(void){
  int n,m;
  while(cin>>n>>m,n){
    vector<int> yen(n);
    REP(i,n)cin>>yen[i];
    sort(yen.begin(),yen.end());
    reverse(yen.begin(),yen.end());
    int ans = 0;
    REP(i,n)if((i+1)%m!=0)ans+=yen[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 1e6 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int mx;
int a[N];
int b[N];
int c[N];
long long get(long long x){
    return (x * (x - 1)) / 2;
}
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        b[a[i]] ++;
        c[a[i]] ++;
    }
    long long sum = 0;
    for(int i = 1; i <= n; i ++){
        sum += get(c[a[i]]);
        c[a[i]] = 0;
    }
    for(int i = 1; i <= n; i ++){
        cout << sum - get(b[a[i]]) + get(b[a[i]] - 1) << "\n";
    }
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define li long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))

ll n,W;
ll w[101],v[101];
ll dp[101][100010];
bool vis[101][100010];
ll totalV=0;

ll minWeight(ll end, ll Val)
{
  if(Val<=0)
  return 0;
  if(end==0)
  return INT_MAX;
  if(vis[end][Val])
  return dp[end][Val];
  vis[end][Val]=1;
  // if(v[end-1]>Val)
  // return dp[end][Val]=minWeight(end-1,Val);
  // else
  return dp[end][Val]=min(w[end-1]+minWeight(end-1,Val-v[end-1]), minWeight(end-1,Val));
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j;
    cin>>n>>W;
    for(i=0;i<n;i++)
    {
      cin>>w[i]>>v[i];
      totalV+=v[i];
    }
    mem(vis,0);
    for(i=0;i<=n;i++)
      for(j=0;j<=totalV;j++)
        dp[i][j]=INT_MAX;

    for(i=totalV;i>=1;i--)
    {
      if(minWeight(n,i)<=W)
      break;
    }
    cout<<i;
    return 0;
}

Measured memory_bytes: 92300
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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


	int N = getint();

	int A[1000001] = {};
	rep(i, N) A[getint()]++;

	if (A[1]) {
		if (A[1] == 1) co(1);
		else co(0);
		return 0;
	}
	if (A[2]) {
		int kotae = (A[2] == 1);
		for (int i = 3; i <= 500000; i += 2) {
			if (A[i]) {
				kotae += (A[i] == 1);
				for (int j = i + i; j <= 1000000; j += i) {
					A[j] = 0;
				}
			}
		}
		for (int i = 500001; i <= 1000000; i += 2) kotae += (A[i] == 1);
		co(kotae);
		return 0;
	}

	int kotae = 0;
	for (int i = 2; i <= 500000; i++) {
		if (A[i]) {
			kotae += (A[i] == 1);
			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}
		}
	}
	for (int i = 500001; i <= 1000000; i++) kotae += (A[i] == 1);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 7648
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, Q;
	cin >> N >> Q;
	long long xN = N - 3;
	long long yN = N - 3;
	vector<long long>A(N - 2, N - 2);
	vector<long long>B(N - 2, N - 2);
	if (false) {
		cout << xN << " " << yN << endl;
		cout << A[0] << A[1] << A[2] << endl;
		cout << B[0] << B[1] << B[2] << endl;
		cout << endl;
	}
	for (int i = 0; i < Q; ++i) {
		long long x, y;
		cin >> x >> y;
		y -= 2;
		if (1 == x) {
			A[y] = 0;
			if (y <= xN) {
				for (int j = y + 1; j <= xN; ++j) {
					A[j] = yN + 1;
				}
				xN = y - 1;
			}
		}
		else {
			B[y] = 0;
			if (y <= yN) {
				for (int j = y + 1; j <= yN; ++j) {
					B[j] = xN + 1;
				}
				yN = y - 1;
			}
		}
	}
	long long ans = (xN + 1)*(yN + 1);
	for (int i = xN + 1; i < N - 2; ++i) {
		ans += A[i];
	}
	for (int i = yN + 1; i < N - 2; ++i) {
		ans += B[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6388
#include<iostream>

using namespace std;

const int MAX = 1001;
int data[MAX];

void make(){
  for(int i = 1; i < MAX; i++)
    data[i] = data[i-1]+i;
}

int solve(int in){
  int ans = 0;
  for(int i = 0; i < MAX; i++)
    for(int j = i+2; j < MAX; j++)
      if(data[j]-data[i] == in) ans++;
  return ans;
}
int main(){
  make();
  int in;
  while(cin >> in && in) cout << solve(in) << endl;
  return 0;
}

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

int main() {
  int n;

  cin >> n;

  int flag = 0;

  vector<int> a(n+1);

  rep(i,n){
    cin >> a.at(i);
  }

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

  rep(i,n){
    if(a.at(i) == a.at(i+1))
    flag = 1;
  }

  if(flag == 1)
  cout << "NO";
  
  else
  {
    cout << "YES";
  }
  
  
}

Measured memory_bytes: 3996
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class A
{
	public static void Main()
	{
		int A = GetInt();
		int B = GetInt();
		Console.WriteLine((A + B) < 10 ? (A+B).ToString() : "error");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 != 0) {
        cout << "No" << endl;
        return 0;
    } else {
        int m = n / 2;
        for (int i = 0; i < m; i++) {
            if (s[i] != s[i + m]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		String s=in.next();
		if(s.charAt(0)=='S')
		{
			System.out.println("Cloudy");
		}
		else if(s.charAt(0)=='C')
		{
			System.out.println("Rainy");
		}
		else
		{
			System.out.println("Sunny");
		}
	}
}
	

Measured memory_bytes: 19156
/* 
 * Project: AtCoder Beginners Contest 085 A - Already 2018
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/3
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
using namespace std;

char s[10];

void solve() {

    printf("2018%.6s\n", s+4);

}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 256
from fractions import gcd

a, b, c, d = map(int, input().split())


def lcm(x, y):
    if gcd(x, y) == 0:
        return x * y
    return x * y // gcd(x, y)


def cantdiv(x):
    return x - x // c - x // d + x // lcm(c, d)


print(cantdiv(b) - cantdiv(a - 1))


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

int main(void) {

    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;

}


Measured memory_bytes: 3632
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>

using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;

    vector<int> cnt(m + 5, 0);

    
    for (int i = 0; i < n; i++) {
        int a,b;
        cin >> a;

        for(int i = 0; i < a; i++) {
            cin >> b;

            cnt[b]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        if (cnt[i] == n)ans++;
    }
    cout << ans << endl;

    return 0;

}



Measured memory_bytes: 3628
n, m = map(int, input().split())
q = []
s = []
for i in range(m):
    x = [int(i) for i in input().split()]
    q.append(x[0])
    s.append(x[1:])
p = list(map(int, input().split()))
ans = 0


for i in range(2**n):
    ok = True
    for j in range(m):
        on_cnt = 0
        for k in range(q[j]):
            for l in range(n):
                if i >> l & 1:
                    if l == s[j][k] - 1:
                        on_cnt += 1
        if on_cnt % 2 != p[j]:
            ok = False
    if ok:
        ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
s = input()
try:
  migi = s.count("(")
except:
  migi = 0
try:
  hidari = s.count(")")
except:
  hidari = 0
kasa = 0
ans = 0
for i in range(n):
  if s[i] == "(":
    kasa += 1
  else:
    if kasa >= 1:
      ans += 1
      kasa -= 1
migi -= ans
hidari -= ans
print("(" * hidari + s + ")"* migi)

Measured memory_bytes: 3064
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x  - a) % b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1e8;
int main(){
    int H, W;
    cin >> H >> W;
    int d[H][W];
    vector<vector<char>> s(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) {
            cin >> s[i][j];
            d[i][j] = INF;
        }
    }
    d[0][0] = 0;
    int dx[4] = {1, 0};
    int dy[4] = {0, 1};
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            for(int k = 0; k < 2; k++){
                int th = i + dy[k];
                int tw = j + dx[k];
                if(0 <= th && th < H && 0 <= tw && tw < W){
                    if(s[i][j] == '.' && s[th][tw] == '#') d[th][tw] = min(d[th][tw], d[i][j] + 1);
                    else d[th][tw] = min(d[th][tw], d[i][j]);
                }
            }
        }
    }
    if(s[0][0] == '#') cout << d[H - 1][W - 1] + 1 << endl;
    else cout << d[H - 1][W - 1] << endl;
}

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

int main()
{
 int n;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  int ans=1;
  for(int i=1;i<n;i++)
  {
    bool flag=true;
    for(int j=0;j<i;j++)
      if(v[j]>v[i])
        flag=false;
    if(flag)
      ans++;
  }
  cout<<ans<<"\n";
  
  
  return 0;
}


Measured memory_bytes: 256
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e4 + 10;

int a[N];
ll dp[N][N][2];

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int l = n; l >= 1; --l) {
		for (int r = 1; r <= n; ++r) {
			for (int take_max = 0; take_max <= 1; ++take_max) {
				if (l > r) {
					dp[l][r][take_max] = 0;
				} else if (take_max) {
					dp[l][r][take_max] = max(a[l] + (l + 1 <= n ? dp[l + 1][r][!take_max] : 0), a[r] + dp[l][r - 1][!take_max]);
				} else {
					dp[l][r][take_max] = min(-a[l] + (l + 1 <= n ? dp[l + 1][r][!take_max] : 0), -a[r] + dp[l][r - 1][!take_max]);
				}
			}
		}
	}
	cout << dp[1][n][1] << "\n";
}

Measured memory_bytes: 469888
h,w = list(map(int, input().split())) 
s=list([]) 
foot = list([False for i in range(w)] for j in range(h))

def is_new_white(i,j):
    global h,w, s, foot
    if ((i<0) or (j<0) or (i>=h) or(j>=w)):
        return False
    elif (not foot[i][j] and (s[i][j] == ".")):
        return True
    else:
        return False

def is_new_black(i,j):
    global h,w, s, foot
    if ((i<0) or (j<0) or (i>=h) or(j>=w)):
        return False
    elif (not foot[i][j] and (s[i][j] == "#")):
        return True
    else:
        return False

def check(i,j):
    global s, foot
    black = list([])
    white = list([])
    white_c = 0
    black_c = 0
    
    if foot[i][j] == True:
        return 0
    else:
        if s[i][j] == "#":
            black.append([i,j])
            foot[i][j] = True
            black_c += 1
        else:
            white.append([i,j])
            foot[i][j] = True
            white_c += 1

    while (bool(black) or bool(white)):
        while bool(black):
            pos = black.pop(0)
            tmp = [[pos[0]-1,pos[1]],[pos[0],pos[1]-1],[pos[0]+1,pos[1]],[pos[0],pos[1]+1]]
            for x in tmp:
                if is_new_white(x[0], x[1]):
                    white_c += 1
                    white.append([x[0],x[1]])
                    foot[x[0]][x[1]] = True

        while bool(white):
            pos = white.pop(0)
            tmp = [[pos[0]-1,pos[1]],[pos[0],pos[1]-1],[pos[0]+1,pos[1]],[pos[0],pos[1]+1]]
            for x in tmp:
                if is_new_black(x[0], x[1]):
                    black_c += 1
                    black.append([x[0],x[1]])
                    foot[x[0]][x[1]] = True
    return black_c * white_c


for i in range(h):
    s.append(input())

ans = 0
for i in range(h):
    for j in range(w):
        ans += check(i,j)

print(ans)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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() {
  ull X, Y; cin >> X >> Y;
  ull ans = 0;
  for(ull i=X, n=1; i<=Y; i=i*2) {
    ++ans;
    ++n;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int i=0;
  int x,a,b;
  int c=0;
  scanf("%d %d %d",&x,&a,&b);
  
  c=x-a;
  
  while(c>=b){
  c=c-b;
  }
  
  printf("%d",c);
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    
   int a,b,d,r;
   double f;
   
   scanf("%d %d",&a,&b);
   
   d=a/b;
   r=a%b;
   f=1.0*a/b;
   
   printf("%d %d %f\n",d,r,f);
   
    return 0;
    
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
int main(){
 long long int n,m;
 cin>>n>>m;
 long long int sum=0;
 for(long long int i=0;i<m;i++){
 	long long int x;
 	cin>>x;
 	sum+=x;
 }
 long long int ans;
 ans=n-sum;
 if(ans<0)
 ans=-1;
  cout<<ans<<"\n";
}

Measured memory_bytes: 3636
def check(h,m):
    if (h+m)%2 == 0:
        return '#'
    return '.'

while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for h in range(H):
        for w in range(W):
            print(check(h,w), end='')
        print()
    print()


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n&1) cout << b[n/2]-a[n/2]+1 << "\n";
    else cout << b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1 << "\n";
    return 0;
}


Measured memory_bytes: 6368
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 505;
const double PI = acos(-1.0);
const ll mod = 1e6 + 3;
ll po(ll a, ll b,ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}

ll n,s;
ll f(ll b,ll n)
{
	if(n<b)
	{
		return n;
	}
	else
	{
		return f(b,n/b) + n%b;
	}
}

void solve()
{
	scanf("%lld%lld",&n,&s);
	ll up = sqrt(1.0*n)+1;
	for(int i=2;i<=up;i++)
	{
		if(f(i,n)==s)
		{
			printf("%d",i);
			return;
		}
	}
	ll t = n-s;
	if(t < 0)
	{
		puts("-1");
		return;
	}
	if(t==0)
	{
		printf("%lld",n+1);
		return;
	}
	ll b = -1;
	for(int i=1;i<=up;i++)
	{
		if(t%i==0)
		{
			ll x = t/i+1;
			ll p = i;
			ll q = s-p;
			if(q >= x)continue;
			if(p >= x)continue;
			if(q < 0)continue;
			if(p*x+q == n)
			{
				b = x;
			}
		}
	}
	printf("%lld",b);
}

int main()
{

    solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int ans=1,mx=0,y;
    cin>>y;
    mx=y;
    for (int i=1;i<x;i++){
        cin>>y;
        if (y>=mx)
        {
            ans++;
            mx=y;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

long long gcd(long long m, long long n){
	//Euclid's algorithm
	if(m<n){ 
		swap(m, n);
	}

	do {
		if(n==0){
			return m;
		}
		
		int swap = m % n;
		m = n;
		n = swap;
	} while(1);
}

//1009
int main(){

	long long m, n;
	while(cin >> m >> n){
		long long  GCD;
		
		GCD = gcd(m, n);
		cout << GCD <<  endl;
	}

	return 0;
}

Measured memory_bytes: 0