akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
string S;

int main() {
   cin >> S;
   int N = S.size();
   for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
         string tmp = S.substr(0, i);
         tmp += S.substr(j);
         if (tmp == "keyence") {
            cout << "YES" << endl;
            return 0 ;
         }
         // cout << tmp << endl;
      }
   }
   cout << "NO" << endl;
   return 0;
}


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

int main(){
    int N ;
    string S ;
    cin >> N >> S ;
    int ans = 0; 
    for(int i=0; i < 1000; i++){
        vector<int> number = {i/100,(i%100 - i % 10)/10 ,i % 10};
        int k = 0, cnt = 0 ;
        while(1){
            if(k >= N || cnt == 3) break;
            else{
                if(number[cnt] + '0' == S[k]) {
                    cnt++ ;
                }
                k++ ;
            }
        }
        if(cnt==3) ans++;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
from math import gcd

k = int(input())

ans = 0
for a in range(1,k+1):
    for b in range(1,k+1): #k+1なのに注意
        t = gcd(a,b)
        for c in range(1,k+1):
            ans += gcd(t,c)

print(ans)



Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  
  int strsize = (int)S.size();
  //もし全部の文字が同じだったら
  if( S == string(strsize, S.at(0)) ){
    cout << ( strsize*K ) / 2 << endl;
    return 0;
  }
  
  
  int count = 0;
  int k = 1; //連続する文字の数
  int ans = 0;
  for( int i = 1; i < strsize; i++ ){
    if( S.at(i) == S.at(i-1) ){
      k++;
    }else{
      count += ( k/2 );
      k = 1;
    }
  }
  count += ( k/2 );
  ans = count*K;
  if( S.at(0) != S.back() ){
    cout << ans << endl;
    return 0;
  }else{
    int a = 1; //最初の部分の連続した文字の個数
    int b = 1; //最後の
    for( int i = 1; i < strsize; i++ ){
      if( S.at(i) == S.at(i-1) ){
        a++;
      }else{
        break;
      }
    }
    for( int i = strsize-1; i >= 0; i-- ){
      if( S.at(i) == S.at(i-1) ){
        b++;
      }else{
        break;
      }
    }
    ans = ans - ( (a/2) + (b/2) - ((a+b)/2) ) * (K-1);
    cout << ans << endl;
  }
  
  
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

ll a,b,x;

int main(){
  cin>>a>>b>>x;
  if(a+b>=x&&a<=x)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

int store[100007];
int n;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &store[i]);
    }

    sort(store, store+n);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int up = upper_bound(store+i, store+n, store[i]+2) - store - i;
        //cout << store[i] << ": " << up << endl;
        ans = max(up, ans);
    }

    cout << ans << endl;
}

/*
7
1 1 2 3 4 5 9

*/


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


int main(){
  int N,H,W;
  scanf("%d%d%d",&N,&H,&W);
  printf("%d\n",(N-H+1)*(N-W+1));
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
typedef pair<int,int> P;
int ceil(int a,int b){// a以上でbの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int main(){
    while(1){
    int n,m,a;
    cin>>n>>m>>a;
    if(n==0&& m==0 && a==0) break;
    vector<pair<int,P>> p(m);
    rep(i,m) cin>>p[i].first>>p[i].second.first>>p[i].second.second;
    int now=a;
    sort(p.rbegin(),p.rend());
    for(int i=0;i<m;i++){

        if(p[i].second.first==now){
            now=p[i].second.second;
        }

        else if(p[i].second.second==now){
            now=p[i].second.first;
        }
        
    }
    cout<<now<<endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int n, q;
string s ,t[MAX_N], d[MAX_N];

bool check(int k, bool f){
    int pos = k;
    char now = s[k];
    REP(i,q){
        if(now == t[i][0]){
            if(d[i]=="L"){
                now = s[pos-1];
                pos--;
            }
            else{
                now = s[pos+1];
                pos++;
            }
        }
    }
    if(f)return pos==0;
    else return pos==n+1;
}


int main() {
    cin >> n >> q >> s;
    s.insert(0, "#");
    s.push_back('#');
    REP(i,q){
        cin >> t[i] >> d[i];
    }
    int l, r;
    int ok = 0, ng = n+1;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(check(mid,true)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    l = ok;
    ok = n+1, ng = 0;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(check(mid,false)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    r = ok;
    cout << r-l-1 << endl;

    return 0;
}

Measured memory_bytes: 22276
s=input()

flag=True
for i in range(len(s)):
    if s[i]!=s[-i-1]:
        flag=False

if flag:
    for i in range((len(s)-1)//2):
        if s[i]!=s[(len(s)-1)//2-1-i]:
            flag=False

if flag:
    print('Yes')

else:
    print('No')

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

int N;
int d[500][500];
bool inai[500][500];

pair<int,int> fromP(int p) { return {(p-1)/N, (p-1)%N}; }
int toP(int i, int j) { return i*N + (j+1); }

bool update(int i, int j, int ii, int jj) {
  if(ii >= N || ii < 0 || jj>=N || jj < 0) return false;
  int f = inai[i][j] ? d[i][j] : d[i][j] + 1;
  bool ret = d[ii][jj] > f;
  if (ret) d[ii][jj] = f;
  return ret;
}

signed main() {
  cin >> N;

  for(int p=1; p<=N*N; p++) {
    auto [i, j] = fromP(p);
    d[i][j] = min(min(i, abs(N-1-i)), min(j, abs(N-1-j)));
  }

  int ans = 0;
  for(int t=0; t<N*N; t++) {
    int p; cin >> p;
    auto [i,j] = fromP(p);
    ans += d[i][j];
    inai[i][j] = true;
    queue<pair<int,int>> q;
    q.push({i,j});
    while(q.size()) {
      auto [ii, jj] = q.front(); q.pop();
      if(update(ii,jj,ii+1,jj)) q.push({ii+1,jj});
      if(update(ii,jj,ii-1,jj)) q.push({ii-1,jj});
      if(update(ii,jj,ii,jj+1)) q.push({ii,jj+1});
      if(update(ii,jj,ii,jj-1)) q.push({ii,jj-1});
    }
    //cerr << i << " " << j <<endl;
    //for(int ii=0; ii<N; ii++) {
    //  for(int jj=0; jj<N; jj++) cerr << d[ii][jj] << " ";
    //  cerr << "\t";
    //  for(int jj=0; jj<N; jj++) cerr << inai[ii][jj] << " ";
    //  cerr << endl;
    //}
    //cerr << "=================" << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4704
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

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

  if (S[1] == 'B') {
    S[1] = 'R';
  }
  else {
    S[1] = 'B';
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    string s;
    cin >> s;

    if (s.size() % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }

    string s1, s2;
    s1 = s.substr(0, s.size()/2);
    s2 = s.substr(s.size()/2);

    if (s1 == s2)
    {
        cout << "Yes" << endl;
        return 0;
    }

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

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

constexpr int INF = 1e9;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

int main() {
    int C, N, M, S, D;
    while(cin >> C >> N >> M >> S >> D, N) {
        S--; D--;
        graph g(N);
        for(int i=0; i<M; ++i) {
            int a, b, f;
            cin >> a >> b >> f;
            a--; b--;
            g[a].push_back((edge){b, f});
            g[b].push_back((edge){a, f});
        }

        int res = INF;
        using state = tuple<int, int, int>;
        vector<vector<int>> d(N, vector<int>(C+1, INF));
        d[S][C] = 0;
        priority_queue<state, vector<state>, greater<state>> que;
        que.push(make_tuple(0, S, C));
        while(!que.empty()) {
            int cur, v, c;
            tie(cur, v, c) = que.top();
            que.pop();
            if(d[v][c] < cur) {
                continue;
            }
            if(v == D) {
                res = min(res, d[v][c]);
            }
            for(auto& e : g[v]) {
                if(c > 0 && d[e.to][c-1] > d[v][c] + e.cost / 2) {
                    d[e.to][c-1] = d[v][c] + e.cost / 2;
                    que.push(make_tuple(d[e.to][c-1], e.to, c-1));
                }
                if(d[e.to][c] > d[v][c] + e.cost) {
                    d[e.to][c] = d[v][c] + e.cost;
                    que.push(make_tuple(d[e.to][c], e.to, c));
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3132
#include<iostream>
#include<string>

using namespace std;

int main(){

  int n=0, cnt=0;

  cin >> n;

  for(int i=1; i<=n; ++i){
    for(int i=1; i<=n; ++i){
      for(int i=1; i<=n; ++i){
        ++cnt;
      }
    }
  }


  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
ll ncd(ll n,ll d){
    ll x = 1,y=1;
    for(int i=0;i<d;i++){
        x = x*(n-i)%mod;
        y = y*(i+1)%mod;
    }
    return x*modpow(y,mod-2,mod)%mod;
}
int main() {    
    srand(time(NULL));
    ll d;
    cin >> d;
    d-=26;
    for(int i=0;i<26;i++){
        cout<<i+1<<endl;
    }
    for(int i=0;i<d;i++){

          cout<<rand()%26+1<<endl;  
    }
}
    



Measured memory_bytes: 3616
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int h[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  int current[n];
  for (int i = 0; i < n; i++) {
    current[i] = 0;
  }
  int count = 0;
  int flag;
  int prev;
  while (1) {
    flag = 1;
    prev = 0;
    for (int i = 0; i < n; i++) {
      if (current[i] < h[i]) {
        current[i]++;
        flag = 0;
        if (prev == 0) {
          count++;
        }
        prev = 1;
      } else {
        prev = 0;
      }
    }
    if (flag == 1) {
      break;
    }
  }
  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 128
def main():
    A, B, C, D, E, F = list(map(int, input().split(' ')))
    ans_total, ans_sugar = 100 * A, 0
    a = 0
    while 100 * A * a <= F:
        b = 0
        while 100 * (A * a + B * b) <= F:
            if a == b == 0:
                b += 1
                continue
            c = 0
            while 100 * (A * a + B * b) + C * c <= F:
                if E * (A * a + B * b) < C * c:
                    break
                d = 0
                while 100 * (A * a + B * b) + C * c + D * d <= F:
                    if E * (A * a + B * b) < C * c + D * d:
                        break
                    sugar, total = C * c + D * d, 100 * (A * a + B * b) + C * c + D * d
                    if sugar * ans_total > ans_sugar * total:
                        ans_sugar = sugar
                        ans_total = total
                    d += 1
                c += 1
            b += 1
        a += 1
    print('{} {}'.format(ans_total, ans_sugar))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
constexpr int f(int a){
	return a?a%10+f(a/10):0;
}
template<int N>struct ans{
	int a[37][N+1];
	constexpr ans(){
		for(int i=1;i<=N;i++){
			for(int j=1;j<=36;j++)a[j][i]=a[j][i-1];
			a[f(i)][i]+=i;
		}
		for(int i=1;i<=N;i++){
			for(int j=1;j<=36;j++)a[j][i]+=a[j-1][i];
		}
	}
};
void print(int a){
	a?print(a/10),putchar(a%10+48):0;
}
ans<10000>s;
int t,n,a,b,c;
main(){
	while((c=getchar())>47)n=n*10+c-48;
	while((c=getchar())>47)a=a*10+c-48;
	while((c=getchar())>47)b=b*10+c-48;
	t=s.a[b][n]-s.a[a-1][n];
	t?print(t),0:putchar(48);
}


Measured memory_bytes: 1664
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
 
 
public class Main {
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        final int m = sc.nextInt();
        
        for(int tt = 0; tt < m; tt++){
        	int[][] sum = new int[5][5];
        	
        	for(int i = 0; i < 5; i++){
        		for(int j = 0; j < 5; j++){
        			sum[i][j] = sc.nextInt();
        		}
        	}
        	/*
        	for(int i = 0; i < 5; i++){
        		for(int j = 1; j < 5; j++){
        			sum[i][j] += sum[i][j-1];
        		}
        	}
        	*/
        	for(int j = 0; j < 5; j++){
        		for(int i = 1; i < 5; i++){
        			if(sum[i][j] == 0){
        				continue;
        			}else{
        				sum[i][j] += sum[i-1][j];
        			}
        		}
        	}
        	/*
        	for(int i = 0; i < 5; i++){
        		for(int j = 0; j < 5; j++){
        			System.out.print(sum[i][j] + " ");
        		}
        		System.out.println();
        	}
        	*/
        	int max = Integer.MIN_VALUE;
        	Stack<Integer> stack = new Stack<Integer>();
        	Stack<Integer> number = new Stack<Integer>();
        	for(int i = 0; i < 5; i++){
        		stack.clear();
        		number.clear();
        		
        		for(int j = 0; j < 5; j++){
        			//System.out.println(i + " " + j + " " + stack);
        			//System.out.println(i + " " + j + " " + number);
        			
        			if(stack.isEmpty()){
        				stack.push(sum[i][j]);
        				number.push(j);
        			}else if(stack.peek() < sum[i][j]){
        				stack.push(sum[i][j]);
        				number.push(j);
        			}else{
        				int num = j;
        				
        				while(!stack.isEmpty() && stack.peek() > sum[i][j]){
        					final int high = stack.pop();
        					final int place = number.pop();
        					
        					num = Math.min(num, place);
        					
        					final int dist = j - place;
        					
        					//System.out.println("<" + dist + " " + high + ">");
        					
        					max = Math.max(max, high * dist);
        				}
        				
        				if(stack.isEmpty() || stack.peek() < sum[i][j]){
        					stack.push(sum[i][j]);
        					number.push(num);
        				}
        			}
        		}
        		
        		//System.out.println(i + " " + 5 + " " + stack);
    			//System.out.println(i + " " + 5 + " " + number);
        		
        		while(!stack.isEmpty()){
        			final int high = stack.pop();
        			final int dist = 5 - number.pop();
        			
        			//System.out.println("<" + dist + " " + high + ">");
        			
        			max = Math.max(max, high * dist);
        		}
        	}
        	
        	System.out.println(max);
        }
         
         
    }
 
}

Measured memory_bytes: 26324
n,m = map(int,input().split())
A = set([int(input()) for i in range(m)])
mod = 10**9+7

dp = [0]*(n+2)
dp[1]=1

for i in range(2,n+2):
    if i-1 not in A:
        dp[i]=dp[i-1]%mod+dp[i-2]%mod
print(dp[n+1]%mod)

Measured memory_bytes: 13168
import sys
s=input().split()
n=int(s[0]);m=int(s[1]);l=int(s[2])
a=[[0 for j in range(m)]for i in range(n)]
b=[[0 for j in range(l)]for i in range(m)]
c=[[0 for j in range(l)]for i in range(n)]
for i in range(n):
    t=input().split()
    for j in range(m):
        a[i][j]=int(t[j])
for i in range(m):
    t=input().split()
    for j in range(l):
        b[i][j]=int(t[j])
for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j]+=a[i][k]*b[k][j]
        sys.stdout.write("{0}".format(c[i][j]))
        if j==l-1:
            sys.stdout.write("\n")
        else:
            sys.stdout.write(" ")

Measured memory_bytes: 7028
# include <stdio.h>

int main(){
    int n, k;
    int total = 1;
    int inicio = 1;
    scanf("%d %d", &n, &k);

    for (int i = 0; i < n; ++i){
        if ((total * 2) >= (total + k))
            total += k;
        else
            total *= 2;
    }

    printf("%d\n", total);

    return 0;
}


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

using str = string;
using ss = stringstream;

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

    str s;
    cin>>s;

    int l=0,r=s.size()-1;

    for(int i=0;i<s.size();i++)if(s[i]=='A')
    {
        l=i;
        break;
    }

    for(int i=s.size()-1;i>=0;i--)if(s[i]=='Z')
    {
        r=i;
        break;
    }

    cout<<r-l+1<<"\n";

    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N; cin>>N;
  ll M = N*3;
  ll a[M]; CINA(a,M);
  sort(a,a+M);
  ll r = 0;
  for(ll i=0; i<N; i++){
    r += a[M-(i+1)*2];
  }
  cout << r <<"\n";
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
int n,high,maxn;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		char c;
		cin>>c;
		if(c=='I') high++;
		else high--;
		maxn=max(maxn,high);
	}
	cout<<maxn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vll p(a), q(b), r(c);
  for (ll i = 0; i < a; i++) cin >> p[i];
  for (ll i = 0; i < b; i++) cin >> q[i];
  for (ll i = 0; i < c; i++) cin >> r[i];
  sort(all(p));
  sort(all(q));
  sort(all(r));
  reverse(all(p));
  reverse(all(q));
  reverse(all(r));
  ll ans = 0, amin = x - 1, bmin = y - 1;
  for (ll i = 0; i < c; i++) {
    if (amin < 0 && bmin < 0) break;
    if (amin < 0) {
      if (r[i] <= q[bmin]) break;
      ans += r[i];
      bmin--;
    }
    else if (bmin < 0) {
      if (r[i] <= p[amin]) break;
      ans += r[i];
      amin--;
    }
    else {
      if (r[i] <= p[amin] && r[i] <= q[bmin]) break;
      if (p[amin] <= q[bmin]) amin--;
      else bmin--;
      ans += r[i];
    }
  }
  for (ll i = 0; i <= amin; i++) ans += p[i];
  for (ll i = 0; i <= bmin; i++) ans += q[i];
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

int n;
int m;
vector<int> lang[100000];

class UnionFind {
  int n;
  int cnt;   // number of connected component
  vector<int> par;
  vector<int> rank;
public:
  UnionFind(int n) : n(n), cnt(n), par(n), rank(n) {
    for (int i = 0; i < n; i++)
      par[i] = i;
  }
  
  int find(int x) {
    return par[x] == x ? x : par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    
    --cnt;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y])
        ++rank[x];
    }
    
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  
  int getCnt() {
    return cnt;
  }
};

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

  REP (i, n) {
    int k;
    scanf(" %d", &k);
    REP (j, k) {
      int tmp;
      scanf(" %d", &tmp);
      lang[--tmp].push_back(i);
    }
  }

  UnionFind uft(n);
  REP (i, m) {
    REP (j, lang[i].size()) {
      uft.unite(lang[i][0], lang[i][j]);
    }
  }

  if (uft.getCnt() == 1)
    puts("YES");
  else
    puts("NO");
  
  return 0;
}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int x,n;cin>>x>>n;
    set<int> s;
    int p;
    rep(i,n){
        cin>>p;
        s.insert(p);
    }
    int m=inf;int ans;
    rep(i,102){
        if(!s.count(i)){
            if(abs(x-i)<m){
                ans=i;
                m=abs(x-i);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;

int main(){
	int n;
	std::cin >> n;
	vector<vector<int>> f(n, vector<int>(10));
	vector<vector<int>> p(n, vector<int>(11));
	rep(i,n)rep(j,10)std::cin >> f[i][j];
	rep(i,n)rep(j,11)std::cin >> p[i][j];
	
	int maxv=-INF;
	int m = 10;// {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 1; bit < (1<<m); ++bit) {
    vector<int> S(10,0);
      for (int i = 0; i < m; ++i) {
      	
        if (bit & (1<<i)) { // i が bit に入るかどうか
          
          S[i]=1;
        }
      }
    int dum=0;
    std::vector<int> counter(n,0);
    rep(i,n)rep(j,10)if(S[j]&&f[i][j])counter[i]++;
    rep(i,n)dum+=p[i][counter[i]];
    if(dum>maxv)maxv=dum;
  }
  std::cout << maxv << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int K, S;
  cin >> K >> S;
  int counter = 0;
  
  for (int i = 0; i <= K; i++){
    for (int j = 0; j <= K; j++){
        if(0 <= S - i - j && S - i - j <= K)counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			char[] patten = { 'S', 'H', 'C', 'D' };
			var keyValuePairs = new Dictionary<string, bool>();
			foreach (char c in patten)
			{
				for (int i = 1; i <= 13; i++)
				{
					keyValuePairs.Add(c + " " + i.ToString(), false);
					//keyValuePairs.Add(c, new Dictionary<string, bool>() { {i.ToString(),false } });
				}
			}
			int n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				var input = Console.ReadLine().Split(' ');
				keyValuePairs[input[0] + " " + input[1]] = true;
			}
			foreach (var c in keyValuePairs)
			{
				if (!c.Value)
					Console.WriteLine(c.Key);
			}
		}
	}
}



Measured memory_bytes: 18008
#include<bits/stdc++.h>
using namespace std;
int a[105];
int n;
int sum;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%10!=0)
    {
    	cout<<sum<<endl;
    	return 0;
	}
    sort(a,a+n);
    int i;
    for(i=0;i<n;i++)
    {
    	 if(a[i]%10!=0)
    	break; 
    }
    if(i!=n)
    cout<<sum-a[i]<<endl;
    else
    cout<<0<<endl;
    return  0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>

typedef long long ll;
using namespace std;

struct Dijkstra{
  int n,i,done;
  vector<vector<pair<int,int> > > edge; //cost,to
  vector<int> distance;
  vector<bool> visited;
  vector<int> prev;

  void init(int v){
    n=v;
    edge.resize(n);
    distance.resize(n);
    visited.resize(n);
    prev.resize(n);
  }

  void input(int from,int to,int cost){
    edge[from].push_back({cost,to});
  }

  void calc(int start){
    for(i=0;i<n;i++){
      distance[i]=INT_MAX;
      visited[i]=0;
      prev[i]=-1;
    }
    distance[start]=0;
    done=0;

    priority_queue<pair<int,int> > q; //cost,to
    int from,to,tmp;
    q.push({0,start});

    while(!q.empty()){
      from=q.top().second;
      if(visited[from]){
        q.pop();
        continue;
      }
      visited[from]=1;
      done++;
      if(done==n){
        break;
      }
      q.pop();
      for(i=0;i<edge[from].size();i++){
        to=edge[from][i].second;
        tmp=distance[from]+edge[from][i].first;
        if(distance[to]>tmp){
          distance[to]=tmp;
          prev[to]=from;
          q.push({tmp*-1,to}); //greater
        }
      }
    }
  }
};

int main(void){
  int h,w,i,j,id,cnt=0;
  char S;
  int s[23][23];
  memset(s,-1,sizeof(s));
  Dijkstra graph;

  cin>>h>>w;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      cin>>S;
      if(S=='.'){
        s[i][j]=cnt;
        cnt++;
      }
    }
  }

  graph.init(cnt);

  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(s[i][j]!=-1){
        if(s[i+1][j]!=-1){
          graph.input(s[i][j],s[i+1][j],1);
          graph.input(s[i+1][j],s[i][j],1);
        }
        if(s[i][j+1]!=-1){
          graph.input(s[i][j],s[i][j+1],1);
          graph.input(s[i][j+1],s[i][j],1);
        }
      }     

    }
  }

  int ans=0;

  for(i=0;i<cnt;i++){
    graph.calc(i);
    for(j=i+1;j<cnt;j++){    
      if(graph.distance[j]>ans){
        ans=graph.distance[j];
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;

int n,m;
int r[51][51];
vector<pair<int,int>> t;

bool visited[51];
bool conn(int cur,int goal) {
	if(cur == goal) return true;
	for(int i = 1;i <= n;i++) {
		if(r[cur][i] && !visited[i]) {
			visited[i] = true;
			bool res = conn(i,goal);
			visited[i] = false;
			if(res) return true;
		}
	}
	return false;
}

int main(int argc,char** argv) {
	cin >> n >> m;
	for(int i = 0;i < m;i++) {
		int a,b;
		cin >> a >> b;
		t.push_back(make_pair(a,b));
		r[a][b]++;
		r[b][a]++;
	}
	for(int i = 0;i < 51;i++) visited[i] = false;
	int res = 0;
	for(auto& e:t) {
		r[e.first][e.second] = 0;
		r[e.second][e.first] = 0;
		visited[e.first] = true;
		if(!conn(e.first,e.second)) res++;
		visited[e.first] = false;
		r[e.first][e.second] = 1;
		r[e.second][e.first] = 1;
	}
	cout << res << endl;
}


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

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    map<int, int> A;
    int a;
    rep(i, Q) {
        cin >> a;
        A[a] += 1;
    }

    for (int i = 1; i < N+1; i++) {
        if (K - (Q - A[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 5376
N, M = map(int, input().split())
G = [[10000 for j in range(N)] for i in range(N)]
E = [(0, 0, 0)] * M
for i in range(N):
  G[i][i] = 0
for i in range(M):
  a, b, c = map(int, input().split())
  E[i] = (a - 1, b - 1, c)
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
def warshall_floyd(G):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        G[i][j] = min(G[i][k] + G[k][j], G[i][j])
  return G
G = warshall_floyd(G)
cnt = 0
for e in E:
  for s in range(N):
    if G[s][e[1]] == G[s][e[0]] + e[2]:
      break
  else:
    cnt += 1
print(cnt)

Measured memory_bytes: 3444
#include <iostream>
#include <unordered_map>
using namespace std;
int main(int argc, char const *argv[])
{
    int n,a;
    cin >> n;
    unordered_map<int,int> mp;
    int cnt =0;
    for(int i=0;i<n;++i){
        cin>>a;
        auto itr = mp.find(a);
        if(itr!=mp.end()){
            mp.erase(itr);
            cnt-=1;
        }
        else{
            mp[a]=1;
            cnt +=1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
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) << " "

int main(){
    int n,m;cin>>n>>m;
    int lmax=-1,rmin=1e5+1;
    rep(i,m){
        int l,r;cin>>l>>r;
        lmax = max(lmax, l);
        rmin = min(rmin, r);
    }
    co(max(0, rmin-lmax+1));
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<string.h>
using namespace std;
//const int sss[10] = { 0, 6, 5, 4, 3, 2, 1 };
struct DICE
{
    int f[8];
};
DICE dice[101];
DICE rin(DICE x,char a)
{
    int k[10];
    for (int i = 1; i < 7; i++)
    {
        k[i] = x.f[i];
    }
    switch (a)
    {
    case'N':
        x.f[1] = k[2];
        x.f[5] = k[1];
        x.f[6] = k[5];
        x.f[2] = k[6];
        break;
    case'E':
        x.f[3] = k[1];
        x.f[1] = k[4];
        x.f[4] = k[6];
        x.f[6] = k[3];
        break;
    case'S':
        x.f[2] = k[1];
        x.f[1] = k[5];
        x.f[5] = k[6];
        x.f[6] = k[2];
        break;
    case'W':
        x.f[1] = k[3];
        x.f[3] = k[6];
        x.f[6] = k[4];
        x.f[4] = k[1];
        break;
    }
    return x;
}
DICE yok(DICE x)
{
    DICE a = x;
    x.f[2] = a.f[3];
    x.f[3] = a.f[5];
    x.f[5] = a.f[4];
    x.f[4] = a.f[2];
    return x;
}
 
bool sen(DICE x, DICE y)
{
    for (int i = 1; i < 8; i++)
    {
        for (int q = 0; q < 4; q++)
        {
            for (int z = 0; z < 6; z++)
            {
                if (x.f[z + 1] != y.f[z + 1])break;
                if (z == 5)
                    return true;
            }
            y=yok(y);
        }
        if (i != 1&&i!=6)
        {
            y = rin(y, 'W');
        }
        else y = rin(y, 'N');
    }
    return false;
}
 
int main()
{
    int n;
    cin >> n;
    for (int s = 0; s < n; s++)
    {
        for (int i = 0; i < 6; i++)
        {
            cin >> dice[s].f[i + 1];
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int k = 0; k < n; k++)
        {
            if (k >= i)break;
            if (sen(dice[i], dice[k]))
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
 
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N = S.size();
  bool ans = true;
  rep(i,N)
  {
    if(S[i]!=S[N-i-1])
    {
      ans = false;
    }
  }
  int N1 = (N-1) / 2 ;
  rep(i,N1)
  {
    if(S[i]!=S[N1-i-1])
    {
      ans = false;
    }
  }
  for(int i=(N+3)/2;i<N;i++)
  {
    if(S[i]!=S[N-i-1])
    {
      ans = false;
    }
  }
  if(ans == true)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No"  << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3604
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int d[]=sc.nextIntArray(n);
        int c=0;
        for (int i = 0; i < d.length; i++) {
        	if(d[i]!=i+1)c++;
		}
        
        out.println(c<=2?"YES":"NO");        
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 23380
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: usize = iterator.next().unwrap().parse().unwrap();
    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    let ans = (x - a) % b;
    return ans.to_string();
}


Measured memory_bytes: 2100
#include <iostream>

using namespace std;
const int NMAX=200005;
long long v[NMAX];

int main()
{
    long long n,k,i,st;
    cin>>n>>k;
    for(i=1;i<=k;i++)
        cin>>v[i];
    st=1;
    for(;i<=n;i++){
        cin>>v[i];
        if(v[i]>v[st])
            cout<<"Yes\n";
        else
            cout<<"No\n";
        st++;
    }
    return 0;
}


Measured memory_bytes: 5184
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define s second
#define pb(x) push_back(x)
#define f first
using namespace std;
ll pw(ll a, ll n)
{
    ll ans=1;
    while(n>0)
    {
        if (n%2!=0)
        {
            ans=ans*a;
        }
        a=a*a;
        n=n/2;
    }
    return ans;
}

int main(){
       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(30);
        IOS;

  ll x;
  cin >> x;
  ll a=0;
  ll b=0;
  ll maxi=0;
  if(x==1)
    return cout << 1,0;
for(int i=2;i<=x;i++)
{
    for(int j=2;j<=10;j++)
    {
        if(pw(i,j)<=x)
            {
             maxi=max(pw(i,j),maxi);}

        else
            break;

    }
}

cout << maxi;




        return 0;
    }


Measured memory_bytes: 256
/////////////////////////////////////////////////
//                                             //
//                 _ooOoo_                     //
//                o8888888o                    //
//                88" . "88                    //
//                (| -_- |)                    //
//             ____/`---'\\____                //
//           .'  \|     |//  `.                //
//           /  \|||  :  |||// \               //
//          /  _||||| -:- |||||- \             //
//          |   | \\  -  /// |   |             //
//          | \_|  ''\---/''  |  |             //
//          \  .-\__  `-`  ___/-. /            //
//         ___`. .'  /--.--\  `. . __          //
//      ."" '<  `.___\_<|>_/___.'  >'"".       //
//     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     //
//     \  \ `-.   \_ __\ /__ _/   .-` /  /     //
//=====`-.____`-.___\_____/___.-`____.-'=======//
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
//.............................................//
/////////////////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll modn=1000000007;
const ll INF = 0x3f3f3f3f;
int n,t;
ll dp[10000][2];
int main(){
    scanf("%d%d",&n,&t);
    for(int i=0;i<n;i++){
        //cout<<i<<n<<endl;
        int a,b;
        scanf("%d%d",&a,&b);
        for(int j=t-a-1;j>=0;j--)
            dp[j+a][1]=max(dp[j+a][1],dp[j][1]+b);
        for(int j=t-1;j>=0;j--){
            dp[j][1]=max(dp[j][1],dp[j][0]+b);
        }
        for(int j=t-a-1;j>=0;j--){
            dp[j+a][0]=max(dp[j+a][0],dp[j][0]+b);
        }
    }

    ll ans = 0;
    for(int i=0;i<=3030;i++)ans=max(ans,dp[i][0]);
    for(int i=0;i<=3030;i++)ans=max(ans,dp[i][1]);
    printf("%lld\n",ans);
    return 0;
}
/*
5
1 2 3 4 5
5 3 2 1 4
*/


Measured memory_bytes: 256
#include <iostream>

int main(int argc, const char *argv[]) {
    std::string str;
    int m, h;
    for ( ; std::cin >> str && str != "-"; ) {
        std::cin >> m;
        for (int i = 0; i < m; i++) {
            std::cin >> h;
            str = str.substr(h) + str.substr(0, h);
        }
        std::cout << str << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/

ll V;
vector<vector<ll>> G;
vector<ll> match;
vector<int> used;

void add_edge(ll u, ll v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(ll v) {
    used[v] = 1;
    for (int i = 0; i < G[v].size(); i++) {
        ll u = G[v][i], w = match[u];
        if (w < 0 || ((used[w] == 0) && dfs(w))) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

ll bipartite_matching() {
    ll res = 0;
    for (int i = 0; i < (int)match.size();i++)match[i] = -1;
    for (int v = 0;v < V;v++) {
        if (match[v] < 0) {
            for (int i = 0; i < (int)used.size();i++)used[i] = 0;
            if (dfs(v))res++;
        }
    }
    return res;
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,A,B; cin >> N >> A >> B;
    vector<ll> a(N),b(N);
    for(int i = 0; i < N;i++) cin >> a[i] >>b[i];
    
    vector<int> f(N,0);
    for(int i = 0; i < N;i++){
        ll Abs = abs(a[i]-b[i]);
        if(Abs <= A || (B <= Abs && Abs <= 2*A)){
            f[i] = -1;
        }
    }
    ll cnt = -accumulate(f.begin(),f.end(),0LL);
    V = 0;
    for(int i = 0; i < N;i++){
        if(f[i] == 0){
            f[i] = V;
            V++;
        }
    }
    G.resize(V);
    match.resize(V);
    used.resize(V);
    
    for(int i = 0; i < N;i++){
        for(int j = 0; j < N;j++){
            if(f[i] == -1 || f[j] == -1) continue;
            ll Absdayo = abs(a[i]+a[j]-b[i]-b[j]);
            if(Absdayo <= A || (B <= Absdayo && Absdayo <= 2*A )){
                 add_edge(f[i],f[j]);
            }
        }
    }
//    cout << cnt << " " << bipartite_matching() << endl;
    cout << cnt + bipartite_matching() << endl;
	return 0;
}



Measured memory_bytes: 4480
#include<stdio.h>

int main(){

  int i,j,n,mini,si,a1[37],a2[37],count=1,f=0;
  char sc,c1[37],c2[37];

  //load N
  scanf("%d",&n);

  //load number
  for(i=1;i<=n;i++){
    scanf(" %c%d",&c1[i],&a1[i]);
    a2[i]=a1[i];
    c2[i]=c1[i];
  }



  //BubbleSort
  for(i=1;i<=n;i++){
    for(j=n;j>=i+1;j--){
      //swap
      if(a1[j]<a1[j-1]){
        si=a1[j];
        a1[j]=a1[j-1];
        a1[j-1]=si;
	sc=c1[j];
	c1[j]=c1[j-1];
	c1[j-1]=sc;

	}
    }
  }
  //print
  for(i=1;i<=n;i++){
    printf("%c%d",c1[i],a1[i]);
    if(i!=n){
      printf(" ");
    }
  }
    printf("\n");

    //stability
    printf("Stable\n");

  //SelectionSort
  for(i=1;i<=n;i++){
    mini=i;
    for(j=i;j<=n;j++){
      if(a2[j]<a2[mini]){
        mini=j;
      }
    }
      //swap
      si=a2[i];
      a2[i]=a2[mini];
      a2[mini]=si;
      sc=c2[i];
      c2[i]=c2[mini];
      c2[mini]=sc;
  }


  //print
  for(i=1;i<=n;i++){
    printf("%c%d",c2[i],a2[i]);
    if(i!=n){
      printf(" ");
    }
  }
  printf("\n");

  //stability
  f=0;
  for(i=1;i<=n;i++){
    if(c2[i]!=c1[i]){
      printf("Not stable\n");
      f=1;
      break;
    }
  }  
  if(f==0)printf("Stable\n");
  
  
  

  return 0;

}

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

int main() {
  int N;
  cin >> N;
  
  for (int i=0 ; i<N ; i++){
    string S;
    cin >> S;
    
    if (S=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if (i==N-1 && S!="Y"){
      cout << "Three" << endl;
    }
  }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if (c <= 0){
             cout << "Yes" << endl;
             return 0;
        }

        a -= d;
        if (a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	int w, h, n;
	cin >> w >> h >> n;
	int w1 = 0, h1 = 0;
	for(int i = 0; i < n; i++){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1 && w1 < x) w1 = x;
		if(a == 2 && w > x) w = x;
		if(a == 3 && h1 < y) h1 = y;
		if(a == 4 && h > y) h = y;
	}
	cout << max((w - w1), 0) * max((h - h1), 0) << endl;
	return 0;
}

Measured memory_bytes: 256