akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B)cout<<C<<endl;
  else if(B==C)cout<<A<<endl;
  else cout<<B<<endl;
  return 0;
}


Measured memory_bytes: 256
a, b = gets.chomp.split(" ").map(&:to_i)
if a == 1 && b == 1
  puts 1
elsif a == 1 || b == 1 then
  puts a * b - 2
else
  puts a * b - ((a - 2 + b - 2) * 2 + 4)
end

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

using namespace std;

int main()
{
    int n, k, h[200007];
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> h[i];
    sort(h+1, h+n+1);
    long long ans = 0;
    for (int i = 1; i <= n-k; ++i) ans += h[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

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

  cout << S[0] << S[1] << S[2]<<endl;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<String, List<Integer>> restaurants = new TreeMap<>();
        Map<String, Integer> order = new HashMap<>();
        for (int i = 0; i < N; ++i) {
            String S = sc.next();
            int P = sc.nextInt();
            order.put(S + " " + P, i + 1);
            if (restaurants.containsKey(S)) {
                restaurants.get(S).add(P);
            } else {
                List<Integer> points = new ArrayList<>();
                points.add(P);
                restaurants.put(S, points);
            }
        }
        for (Map.Entry<String, List<Integer>> e: restaurants.entrySet()) {
            e.getValue().sort(Comparator.reverseOrder());
            for (int p: e.getValue()) System.out.println(order.get(e.getKey() + " " + p));
        }
    }
}


Measured memory_bytes: 21712
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
  // INFILE();
  auto b = scan('W');
	int s = b.size();

	int count = 0;
	REP(i, 1, s) {
		if (b[i] == b[i - 1]) {
			continue;
		}
		count++;
	}

	cout << count << endl;
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  map<type_index, const char *const> m = {{typeid(int), "%d"},
                                          {typeid(ll), "%lld"},
                                          {typeid(double), "%lf"},
                                          {typeid(char), "%c"}};

  auto tFormat = m[typeid(T)];

  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;

int main() {
    ll N,ans=0,x=0; cin>>N;
    vech S(N);
    rep0(i,N){
        cin>>S[i];
        if(S[i]=='I'){x++;ans=max(ans,x);}
        else if(S[i]=='D'){x--;ans=max(ans,x);}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, k, q; cin >> n >> k >> q; vi p(n, 0);
    rep(i, q){ lli ans; cin >> ans; ans--; p[ans]++; }
    rep(i, n) (k <= (q-p[i])) ? No() : Yes();
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    int sum = 0;
    rep(0, i, 26)
    {
        rep(0, j, 15)
        {
            sum = 4 * i + 7 * j;
            if (sum == N)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

void insetrtionsort(int a[], int n)
{
    int j, v;
    for (int i = 1; i < n; i++)
    {
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (int i = 0; i < n; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

int gcd(int a, int b)
{
    if (a < b)
    {
        int t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << endl;
    if (b == 0) return a;
    else return gcd(b, b%a);
}

int main()
{
    int n, a, b;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (a == 0){
            cin >> b;
            v.push_back(b);
        }
        else if (a == 1){
          	cin >> b;
            cout << v[b] << endl;
        }
        else v.pop_back();
    }
    return 0;
}



Measured memory_bytes: 3920
n = int(input())
xy = []
for i in range(n):
    a = int(input())
    temp = []
    for j in range(a):
        x, y = map(int, input().split())
        temp.append([x, y])
    xy.append(temp)

max_honesty = 0
for i in range(2 ** n):
    num = bin(i + 2 ** n)[3:]
    honest = 0
    flag = True
    for j in range(len(num)):
        if num[j] == "0":
            continue
        else:
            for k in range(len(xy[j])):
                if int(num[xy[j][k][0] - 1]) == xy[j][k][1]:
                    continue
                else:
                    flag = False
                    break
            if flag == True:
                honest += 1
    if flag == True:
        max_honesty = max(max_honesty, honest)
print(max_honesty)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
bool n, w, s, e;

int main()
{
    string S;
    getline(cin, S);
    for (int i = 0; i < S.size(); i++)
        if (S[i] == 'N') n = 1;
        else if (S[i] == 'W') w = 1;
        else if (S[i] == 'S') s = 1;
        else e = 1;
    if ((n ^ s) || (w ^ e)) printf("No");
    else printf("Yes");
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int maxv = -1e5;
int dp[105][105];

int main()
{

    rep(i, 105) rep(j, 105) dp[i][j] = -1e5;

    vector<int> k(100);
    iota(ALL(k), 1);
    string s;
    int i = 0, b;
    while (cin >> s)
    {
        rep(j, s.size()) if (s[j] == ',') s[j] = ' ';
        stringstream ss(s);
        vector<int> t;
        while (ss >> s)
            t.push_back(stoi(s));
        if (i < t.size())
            b = i + 1;

        for (int j = 1; j <= t.size(); j++)
        {
            i < t.size() ? dp[i][j] = t[j - 1] : dp[i][j + k[i - b]] = t[j - 1];
        }
        i++;
    }

    for (int k = 1; k < i; k++)
    {
        for (int j = 1; j < i; j++)
        {
            dp[k][j] += max(dp[k - 1][j], dp[k - 1][j - 1]);
        }
    }
    OP(dp[i - 1][b]);

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,a,b,c,d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  int nb = 0;
  for(int i = b; i < d; ++i){
    if(s[i] == '.') nb = 0;
    else{
      ++nb;
      if(nb > 1){
      cout << "No";
        return 0;
      }
    }
  }
  nb = 0;
  for(int i = a; i < c; ++i){
    if(s[i] == '.') nb = 0;
    else{
      ++nb;
      if(nb > 1){
        cout << "No";
        return 0;
      }
    }
  }
  if(d < c){
    bool ok = false;
    nb = 0;
    for(int i = b-2; i <= d; ++i){
      if(s[i] != '.') nb = 0;
      else{
        ++nb;
        if(nb >= 3){
          ok = true;
          break;
        }
      }
    }
    if(!ok){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 892
list = []
gets.to_i.times{
	command, x = gets.split
	case command
	when 'insert'
		list.unshift x
	when 'delete'
		index = list.index(x)
		list.delete_at index if index
	when 'deleteFirst'
		list.shift
	when 'deleteLast'
		list.pop
	end
}
puts list * ' '

Measured memory_bytes: 97760
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m,a,b;
	cin>>n>>m;
	int box[n],vis[n]={0};
	for(int i=0;i<n;i++)
	box[i]=1;
	vis[0]=1;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		--a,--b;
		--box[a],++box[b];
		if(vis[a])
		{
			if(box[a])vis[b]=1;
			else vis[a]=0,vis[b]=1;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)
	if(vis[i])ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int A, P; cin >> A >> P;
  cout << (3*A+P) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (auto& c : s) {
        if (c == '7') {
            Yes();
            return 0;
        }
    }
    No();


    solve();
    return 0;
}


Measured memory_bytes: 3652
def resolve():
    import math
    from math import gcd
    MOD=10**9+7
    n=int(input())
    zero=0
    cnt={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0 and b==0:
            zero+=1
            continue
        g=gcd(a,b)
        a//=g
        b//=g
        if b<0:
            a*=-1
            b*=-1
        if b==0 and a<0:
            a*=-1
        if a<=0:
            a,b=b,-a
            if (a,b) in cnt:
                cnt[(a,b)][0]+=1
            else:
                cnt[(a,b)]=[1,0]
        else:
            if (a,b) in cnt:
                cnt[(a,b)][1]+=1
            else:
                cnt[(a,b)]=[0,1]
    ans=1
    for i,v in cnt.items():
        ans*=pow(2,v[0],MOD)+pow(2,v[1],MOD)-1
        ans%=MOD
    print((zero-1+ans)%MOD)    

if __name__ == '__main__':
    resolve()

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

int d,ans[365],c[26],s[365][26],last[26],tlast[26],S[365][26];
const int INF=1e9;

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

void FIN(int a){
  if(a){
    ofstream fout("output.txt");
    REP(i,d)fout<<ans[i]<<"\n";
    fout.close();
    return;
  }
  REP(i,d)cout<<ans[i]<<"\n";
  return;
}

int score(){
  int res=0;
  memset(tlast,-1,sizeof(tlast));
  REP(day,d){
    res+=S[day][ans[day]-1];
    tlast[ans[day]-1]=day;
    REP(i,26)res-=c[i]*(day-tlast[i]);
  }
  return res;
}

signed main(){
  memset(last,-1,sizeof(last));
  cin>>d;
  REP(i,26)cin>>c[i];
  REP(i,d)REP(j,26)cin>>s[i][j];
  REP(i,d)REP(j,26)S[i][j]=s[i][j];
  REP(j,26){
    int now=-INF;
    for(int i=364;i>=0;i--){
      if(now>15000)s[i][j]-=(now-15000)/10;
      if(now<s[i][j])now=s[i][j];
      now-=c[j];
    }
  }
  REP(day,d){
    int Sc=-INF,now;
    if(day<d-1){
      REP(i,26){
        REP(j,26){
          if(i==j)continue;
          int tmp=s[day][i]+s[day+1][j];
          REP(k,26){
            if(i!=k&&j!=k)tmp-=c[k]*(day-last[k]+day+1-last[k]);
            if(i==k)tmp-=c[k];
            if(j==k)tmp-=c[k]*(day-last[k]);
          }
          if(Sc<tmp)Sc=tmp,now=i;
        }
      }
      ans[day]=now+1;
      last[now]=day;
    }
    else{
      REP(i,26){
        ans[day]=i+1;
        int R=score();
        if(Sc<R)Sc=R,now=i+1;
        else ans[day]=now;
      }
    }
  }/*
  REP(day,d){
    vector<int> minus(26);
    REP(j,26)minus[j]=c[j]*(day-last[j]);
    int A=-INF,idx=0;
    REP(j,26){
      int tmp=s[day][j]+minus[j];
      if(A<tmp)A=tmp,idx=j;
    }
    ans[day]=idx+1;
    last[idx]=day;
  }
  */
  /*
  REP(_,480){
    int day1=rand()%365,day2=rand()%365;
    if(day1==day2)day2++;if(day2==365)day2=0;
    int Sc=-INF,now1=ans[day1],now2=ans[day2];
    REP(i,26){
      REP(j,26){
        ans[day1]=i+1;
        ans[day2]=j+1;
        int R=score();
        if(Sc<R)Sc=R,now1=i+1,now2=j+1;
        else ans[day1]=now1,ans[day2]=now2;
      }
    }
  }
  */
  /*
  REP(_,1000){
    int day1=_%360;
    int now[5],Sc=-INF;
    vector<int> v(5);
    REP(i,5)v[i]=ans[day1+i];
    sort(v.begin(),v.end());
    do{
      REP(i,5)ans[day1+i]=v[i];
      int R=score();
      if(Sc<R){
        REP(i,5)now[i]=v[i];
        Sc=R;
      }
      else REP(i,5)ans[day1+i]=now[i];
    }while(next_permutation(v.begin(),v.end()));
  }
  */
  REP(__,11){
    REP(_,1000){
      int day=rand()%365,Sc=-INF,now=ans[day];
      REP(i,26){
        ans[day]=i+1;
        int R=score();
        if(Sc<R)now=i+1,Sc=R;
        else ans[day]=now;
      }
    }
    REP(_,1000){
      int day1=rand()%360;
      int day2=day1+rand()%4+1;
      int R=score();
      swap(ans[day1],ans[day2]);
      if(R>score())swap(ans[day1],ans[day2]);
    }
  }

  FIN(0);
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
int a[999][8],n,t,d[99];char s[999];main(){scanf("%d%s",&n,s);a[0][1]=d[79]=1;d[73]=2;r(i,n)r(j,8)r(k,8)if(j&k&&k>>d[s[i]]&1)(a[i+1][k]+=a[i][j])%=10007;r(i,8)t+=a[n][i];printf("%d\n",t%10007);}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; ++i)  cin >> h[i];
    if(n == 1){
        cout << h[0] << endl;
        return 0;
    }
    int low = 0;
    int res = 0;
    bool flag = true;
    for(int i = 0; i < n-1; ++i){
        if(flag){
            if(h[i+1] >= h[i]){
                if(i == n - 2){
                    res += h[n-1] - low;
                }
                continue;
            }
            else{
                res += h[i] - low;
                flag = false;
            }
        }
        else{
            if(h[i+1] > h[i]){
                if(i == n-2){
                    res += h[n-1] - h[n-2];
                }
                else{
                    low = h[i];
                    flag = true;
                }    
            }
        }
    }
    cout << res << endl;
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

char s[10];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%s", s);
	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i+1]) {
			return printf("Bad"), 0;
		}
	}
	printf("Good");
    return 0;
}


Measured memory_bytes: 3724
#coding: UTF-8

def Sort(a,b,c):
    box = 0
    if a > b:
        box = b
        b = a
        a = box
    if b > c:
        box = c
        c = b
        b = box
    if a > b:
        box = b
        b = a
        a = box
    return a,b,c

if __name__=="__main__":
    a = input().split(" ")
    a,b,c = Sort(int(a[0]),int(a[1]),int(a[2]))
    print(str(a)+" "+str(b)+" "+str(c))

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a(N);
    rep(i, N) cin >> a[i];
    ll mo = 1000;
    ll ka = 0;
    rep(i, N-1){
        if(a[i] < a[i+1]){
            ka += mo/a[i];
            mo -= mo/a[i]*a[i];
        }else if(a[i] > a[i-1]){
            mo += ka*a[i];
            ka = 0;
        }
    }
    mo += ka*a.back();
    cout << mo << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;
int main() {
  int x, t;
  cin >> x >> t;
  for (int i = 0; i < t; i++) {
    if (x > 0)
      x--;
    else
      break;
  }
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define llt long long int

using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s < t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 504
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    map<int, int> m;
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        m[a] ^= 1;
    }
    int ans = 0;
    for (auto v : m) {
        ans += v.second;
    }
    cout << ans << endl;
    return 0;
}

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

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

    int d1 = s[0] - '0';
    int d2 = s[1] - '0';
    int d3 = s[2] - '0';
    int d4 = s[3] - '0';

    for(int a = 0; a < 2; a++)
    for(int b = 0; b < 2; b++)
    for(int c = 0; c < 2; c++)
    {
        int sum = 0;

        string ops;

        if(a) sum = d1 + d2, ops += '+';
        else sum = d1 - d2, ops += '-';

        if(b) sum += d3, ops += '+';
        else sum -= d3, ops += '-';

        if(c) sum += d4, ops += '+';
        else sum -= d4, ops += '-';

        if(sum == 7)
        {
            cout << d1 << ops[0] << d2 << ops[1] << d3 << ops[2] << d4 << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

#define MAX_N 100005
int parent[MAX_N];
int rank[MAX_N];
int mark[MAX_N];

void init(int n) {
    for (int i = 0; i < n; ++i) {
        parent[i] = i;
        rank[i] = 0;
    }
}

// find a root of tree
int find(int x) {
    if (parent[x] == x) return x;
    if (mark[x]) return x;
    return parent[x] = find(parent[x]);
}

// unite a group which includes x and a group which includes y
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) {
            ++rank[x];
        }
    }
}

// check if x and y belong to the same group
bool same(int x, int y) {
    return find(x) == find(y);
}

typedef pair<char, int> p;

int n, q;
vector<p> qs;

int main(int argc, char *argv[]) {
    char buf[1024];
    while (true) {
        fgets(buf, 1024, stdin);
        sscanf(buf, "%d%d", &n, &q);
        //cout << n << ", " << q << endl;
        if (n == 0) break;
        init(n);
        memset(mark, 0, sizeof(mark));
        qs.clear();
        for (int i = 1; i < n; ++i) {
            int par;
            fgets(buf, 1024, stdin);
            sscanf(buf, "%d", &par); --par;
            //cout << i << ", " << par << endl;
            parent[i] = par;
        }
        for (int i = 0; i < q; ++i) {
            fgets(buf, 1024, stdin);
            char c;
            int a;
            sscanf(buf, "%c %d", &c, &a); --a;
            //cout << c << ", " << a << endl;
            if (c == 'M') {
                if (!mark[a])
                {
                    qs.push_back(p(c, a));
                    mark[a] = 1;
                }
            } else {
                qs.push_back(p(c, a));
            }
        }
        long long int sum = 0;
        for (int i = qs.size()-1; i >= 0; --i)
        {
            //cout << qs[i].first << ", " << qs[i].second << endl;
            if (qs[i].first == 'M') {
                mark[qs[i].second] = 0;
            } else {
                int t = find(qs[i].second);
                //cout << t << endl;
                sum += t + 1;
            }
        }
        printf("%lld\n", sum);
    }
    return 0;
}



Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<map<char, vector<int>>> RGB_num;
string s;
ll cnt(int i,char c1,char c2){
    ll num = 0;
   
    for(auto j:RGB_num[i][c1]){
            int k = j + j - i;
            ll sub = 0;
            if(k<s.size()){
                if(s[k]==c2){
                    sub--;
                }
            }
            num += RGB_num[j][c2].size()+sub;
        }
        return num;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n >> s;
RGB_num.resize(n);
vector<int> r,g,b;

rrep(i,n){
    if(s[i]=='R'){
        r.pb(i);
    }
    else if(s[i]=='G'){
        g.pb(i);
    }
    else if(s[i]=='B'){
        b.pb(i);
    }
    RGB_num[i]['R'] = r;
    RGB_num[i]['G'] = g;
    RGB_num[i]['B'] = b;
}
ll ans = 0;
rep(i,n){
    if(s[i]=='R'){
        ans+=cnt(i, 'G', 'B');
        ans+=cnt(i, 'B', 'G');
    }
    else if(s[i]=='G'){
        ans+=cnt(i, 'R', 'B');
        ans+=cnt(i, 'B', 'R');
    }
    else if(s[i]=='B'){
        ans+=cnt(i, 'G', 'R');
        ans+=cnt(i, 'R', 'G');
    }
}
cout << ans << endl;
//system("pause");
return 0;
}

Measured memory_bytes: 35968
using System;
class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            
            for (var i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int t = int.Parse(input[0]);
                int x = int.Parse(input[1]);
                int y = int.Parse(input[2]);

                if (x + y > t)
                {
                    Console.WriteLine("No");
                    Environment.Exit(0);
                }
                else if ((t % 2) != ((x + y) % 2))
                {
                    Console.WriteLine("No");
                    Environment.Exit(0);
                }
            }
            
            Console.WriteLine("Yes");
        }
    }

Measured memory_bytes: 15184
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;


int main() {
  int a,b;cin >> a >> b;
  cout << max(a-2*b,0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    vvi dist(h, vi(w, INF));
    
    int white_count = 0;
    rep(i, h)rep(j, w){
        if(s[i][j]=='.'){
            white_count++;
        }
    }
    
    queue<P> q;

    auto update = [&](int i, int j, int x){
        if(dist[i][j]!=INF) return;
        dist[i][j] = x;
        q.push(P(i, j));
    };

    update(0, 0, 0);

    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        rep(dir, 4){
            int ni = i + di[dir];
            int nj = j + dj[dir];

            if(ni<0||ni>=h||nj<0||nj>=w) continue;
            if(s[ni][nj]=='#') continue;
            update(ni, nj, dist[i][j]+1);
        }
    }

    /*
    rep(i, h){
        rep(j, w){
            if(dist[i][j]==INF) cout << "x ";
            else cout << dist[i][j] << "\t";
        }
        cout << endl;
    }
    */

    int ans = white_count - dist[h-1][w-1] - 1;
    if(ans < 0) cout << "-1" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s=list(input().split())
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
tyoku=abs(c-a)

if tyoku<=d or (abs(b-a)<=d and abs(c-b)<=d):
  print('Yes')
else:
  print('No')

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

using namespace std;

long long n, sum, a[100001];

int main () {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i], sum += a[i];
	if (sum % (n * (n + 1) / 2) != 0) cout << "NO", exit (0);
	sum /= (n * (n + 1) / 2);
	a[n + 1] = a[1];
	for (int i = 1; i <= n; i ++) {
		if (a[i + 1] - a[i] - sum > 0 || (a[i + 1] - a[i] - sum) % n != 0) cout << "NO", exit (0);
	}
	cout << "YES";
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 32);
double EPS = 1e-4;

int main() {
  ll H, W;
  cin >> H >> W;
  vvi M(H, vi(W));
  for (ll i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < W; j++) {
      if (s[j] == '.') {
        M[i][j] = 1;
      }
    }
  }
  vvi dist(H, vi(W, INF));
  dist[0][0] = 0;
  for (ll k = 0; k < H * W; k++) {
    for (ll i = 0; i < H; i++) {
      for (ll j = 0; j < W; j++) {
        if (i > 0 && M[i][j] && M[i - 1][j]) dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1);
        if (i < H - 1 && M[i][j] && M[i + 1][j]) dist[i][j] = min(dist[i][j], dist[i + 1][j] + 1);
        if (j > 0 && M[i][j] && M[i][j - 1]) dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1);
        if (j < W - 1 && M[i][j] && M[i][j + 1]) dist[i][j] = min(dist[i][j], dist[i][j + 1] + 1);
      }
    }
  }

  if (dist[H - 1][W - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      if (M[i][j]) {
        ans += 1;
      }
    }
  }
  cout << ans - (dist[H - 1][W - 1] + 1) << endl;
}


Measured memory_bytes: 256
#Coins
A=int(input())
B=int(input())
C=int(input())
X=int(input())

i=0
#j=0 ここに入れるとだめ
ans=0
while i <=A:
    X_aftera=X-500*i
    if X_aftera<0:
        break
    j=0
    while j<=B:
        X_afterb=X_aftera-100*j
        if X_afterb<0:
            break
        if X_afterb//50<=C:
            ans +=1
        j+=1
    i+=1
print(ans)

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int dp_eq[101][5];
int dp_lo[101][5];

int main() {
  CIN(string, N);
  CIN(int, K);
  dp_eq[0][0] = 1;
  REP(i, N.size()) {
    for (int z = 0; z <= 3; ++z) {
      int d = N[i] - '0';
      // Equal to d
      dp_eq[i + 1][z + (d != 0)] += dp_eq[i][z];
      dp_lo[i + 1][z + (d != 0)] += dp_lo[i][z];
      // Lower than d (zero)
      if (d > 0) dp_lo[i + 1][z] += dp_eq[i][z] + dp_lo[i][z];
      // Lower than d (non-zero)
      if (d > 1) dp_lo[i + 1][z + 1] += (dp_eq[i][z] + dp_lo[i][z]) * (d - 1);
      // Highe than d
      dp_lo[i + 1][z + 1] += dp_lo[i][z] * (9 - d);
    }
  }
  COUT(dp_eq[N.size()][K] + dp_lo[N.size()][K])
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//debug
#define dump(x)  cout << #x << = << (x) << endl;

int main(){
 int a,b,n;
 cin >> n;
 vi d(n);
 REP(i,n) cin >> d.at(i);
 
 REP(i,n){
     FOR(j,i+1,n){
         a = d.at(i) * d.at(j);
         b += a;
     }
 }

 cout << b << endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,ans = 0,cnta = 0,cntb = 0,cntab = 0;
    cin >> n;
    rep0(i, n){
        string s;
        cin >> s;
        if(s[0] == 'B' && s[s.size() - 1] == 'A')++cntab;
        else if(s[s.size() - 1] == 'A')++cnta;
        else if(s[0] == 'B')++cntb;
        rep0(j, s.size() - 1)if(s[j] == 'A' && s[j + 1] == 'B')++ans;
    }
    if(cntab){
        if(cnta && cntb){
            ans += cntab + 1;
            --cnta;
            --cntb;
        }else if(cnta || cntb){
            ans += cntab;
            if(cnta < cntb)--cntb;
            else --cnta;
        }else ans += cntab - 1;
    }
    ans += min(cnta,cntb);
    pf(ans);
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
ca = Counter(a)
cb = Counter(b)
for k,v in cb.items():
  if ca[k]<v:
    print("NO")
    break
else:
  print("YES")

Measured memory_bytes: 57048
import java.util.*;
	public class Main {
		public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
        if((a-b)%2==0){
         System.out.println((a+b)/2);
        }
        else{
          System.out.println("IMPOSSIBLE");
        }
	}
}

Measured memory_bytes: 21332
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [6,2,5,5,4,5,6,3,7,6] # B[i]がiを作るのに必要なマッチ棒の数

# dp[i]: i本マッチ使って作れるMAX桁数。。
dp = [-1 for _ in range(N+10)]
dp[0] = 0
A.sort()
visited = [False for _ in range(N+10)]
h = []
heapq.heappush(h, (0,0))

while h:
  now_n, keta = heapq.heappop(h)
  if visited[now_n]:
    continue
  visited[now_n] = True
  for a in A:
    nxt_n = now_n + B[a]
    if nxt_n >= N + 10:
      continue
    dp[nxt_n] = max(dp[nxt_n], dp[now_n] + 1)
    heapq.heappush(h, (nxt_n, dp[now_n] + 1))
    
#print(dp)

A.sort(reverse=True)
# 上の桁から決めていく。dp[N]
ANS = []
zan = N
for i in range(dp[N],0,-1):
  bugf = True
  # sorted(a) 大きい方から試す
  for a in A:
    if dp[zan-B[a]] == dp[zan] - 1:
      ANS.append(str(a))
      zan = zan - B[a]
      bugf = False
      break
  if bugf:
    # Aが構成できない、と言うことなのでここは通らないはず
    print("bug...")
  
print("".join(ANS))

Measured memory_bytes: 9684
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;

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

	cout << n*(n-1)/2 << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    int n; cin >> n;
    vector<ll> x(n);
    for(int i = 0; i < n; ++i) cin >> x[i];

    Sort(x);

    vector<ll> ssum(n+1);
    for(int i = 0; i < n; ++i) ssum[i+1] = ssum[i] + x[i];

    // 1体は生き残る
    int ans = 1;
    for(int i = n-1; i >= 0; --i) {
        int sum = 0;
        for(int j = 0; j < i; ++j) sum += x[j];

        if(2*ssum[i] >= x[i]) ans++;
        else              break;
    }

    cout << ans << endl;

    return 0;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    int n;
    cin >> n;
    map<int, int> cnt;
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (cnt.count(i - a) > 0) {
            res += cnt[i - a];
        }
        ++cnt[i + a];
    }

    cout << res << "\n";
}

int main() {
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--) {
       one_case();
    }

    return 0;
}


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

int main() {
  int N; cin >> N;
  long long sum = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    else sum += i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
import sys


def solve(inp):
    A = [list(map(int, inp.readline().split(' '))) for i in range(3)]

    m = list(map(min, A))
    for a1 in range(m[0] + 1):
        c1 = [A[0][0] - a1, A[0][1] - a1, A[0][2] - a1]
        for a2 in range(m[1] + 1):
            c2 = [A[1][0] - a2, A[1][1] - a2, A[1][2] - a2]
            for a3 in range(m[2] + 1):
                c3 = [A[2][0] - a3, A[2][1] - a3, A[2][2] - a3]
                if c1 == c2 == c3:
                    return "Yes"

    return "No"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N, K, A[60];
	for (int i = 0; i < 60; i++) {
		A[i] = 0;
	}
	cin >> N >> K;
	for (int i = 0; i < N; i ++ ) {
		cin >> A[i];

	}
	sort(A, A + N, greater<int>());
	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += A[i];
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
def main():
    from bisect import bisect_left
    import sys
    input = sys.stdin.buffer.readline
    def near(A, x):
        return [A[(i:=bisect_left(A, x)) - 1], A[i]]
    a, b, q = map(int, input().split())
    INF = 10 ** 15
    S = [-INF] + [int(input()) for _ in range(a)] + [INF]
    T = [-INF] + [int(input()) for _ in range(b)] + [INF]
    for _ in range(q):
        x = int(input())
        print(min([min(abs(s - x) + abs(t - s), abs(t - x) + abs(s - t)) for s in near(S, x) for t in near(T, x)]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 17756
#include<stdio.h>

int main(){
    
    int a, b, c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a < b){
    	if(b < c) {
	    	printf("Yes\n"); 
    	} else {
	    	printf("No\n");
    	}
    } else {
    	printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<set>
using namespace std;
set<int>prime;
int main(){
	prime.insert(2);
	for(int i=3;i<15000;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0)goto fail;
		}
		prime.insert(i);
		fail:;
	}
	int x;
	while(cin>>x && x){
		set<int>::iterator itr=--prime.upper_bound(x);
		while(*itr-*--itr!=2);
		cout<<*--itr<<" "<<*++itr<<endl;
	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s;
	int ans=0;
	for(int i=0;i<n;i++){
		int cnt=0;
		for(int j=0;j<n-i;j++){
			if(s[j]==s[i+j]){
				cnt++;
			}
			else{
				cnt=0;
			}
			ans=max(ans,min(i,cnt));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384