akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b;
	while (cin >> a >> b, a)
	{
		int c = b - a;
		int x, y, z;
		x = c / 1000;
		c %= 1000;
		y = c / 500;
		c %= 500;
		z = c / 100;
		cout << z << " " << y << " " << x << endl;
	}
	return 0;
}

Measured memory_bytes: 3128
/*input
4
aaaa
a
aaa
aa
*/

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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n;
	cin>>n;
	string s[n];
	rep(i,0,n)cin>>s[i];
	sort(s,s+n);
	ll ans=1;
	rep(i,1,n)if(s[i]!=s[i-1])++ans;
	cout<<ans<<endl;
	return 0;
}




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

A, B, C, X, Y = map(int, input().split())

if X > Y:
  print(min(A * X + B * Y, 2 * C * Y + (X - Y) * A, 2 * C * X))
else:
  print(min(A * X + B * Y, 2 * C * X + (Y - X) * B, 2 * C * Y))

Measured memory_bytes: 3060
# include <iostream>
# include <vector>
# include <queue>
# include <cstring>
# include <cstdio>
# include <algorithm>
# include <cmath>
# include <cstdlib>
# include <map>
# include <set>
# define eps 1e-15
# define inf 2000000000
# define MAXN 100010
# define MOD 1000000007
using namespace std;
int main()
{
	string s;
	cin>>s;
	cout<<"ABC"+s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int maxn = 1e6+5;

struct Node {
	int to, next;
	ll w;
}edge[maxn<<1];
int head[maxn], cnt;
ll dis[maxn];
ll dist[maxn];
bool vis[maxn];

void init(int n) {
	cnt = 0;
	memset(dis, INF, sizeof(dis));
	memset(head, -1, sizeof(head));
}

void addEdge(int from, int to, ll w) {
	edge[cnt].to = to;
	edge[cnt].w = w;
	edge[cnt].next = head[from];
	head[from] = cnt++;
}

void spfa(int s) {
    dis[s] = 0;
    queue<int> q;
    q.push(s);
	vis[s] = 1;
	while (!q.empty()) {
		
		int num = q.front(); q.pop();
		vis[num] = 0;
		for (int i = head[num]; i != -1; i = edge[i].next) {
			Node e = edge[i];
		//	cout << e.w << "  --  ";
			if (dis[e.to] > dis[num] + e.w) {
				dis[e.to] = dis[num] + e.w;
				if (!vis[e.to]) {
					vis[e.to] = 1;
					q.push(e.to);
				}
			}
		}
	}
}


void dij(int s, int e, int n) {
    memset(vis, 0, sizeof(vis));
    int mina, k;
    memset(dist, INF, sizeof(dist));
    for (int i = 0, j = 0; ~i; i = edge[i].next, j++) {
        dist[j] = edge[i].w;
    }
    
    for (int i = 1; i < n; i++) {
        mina = INF, k =0;
        for (int j = 0; j < n; j++) {
            if (!vis[j] && dist[j] < mina) {
                mina = dist[j];
                k = j;
            }
        }
        vis[k] = 1;
        for (int j = 0, s = 0; ~j; j = edge[j].next, s++) {
            if (!vis[s] && dist[s] > edge[j].w + dist[k]) {
                dist[s] = edge[j].w + dist[k];
            }
        }
    }
    
}


int main(void) {
    int t;
    scanf("%d", &t);
    init(t);
    for (int i = 0; i < t-1; i++) {
        int v, u, w;
        scanf("%d %d %d", &u, &v, &w);
        addEdge(u, v, w);
        addEdge(v, u, w);
    }
    
    int q, k;
    scanf("%d %d", &q, &k);
    spfa(k);
    for (int i = 1; i <= t; i++) {
       // cout << dis[i] << "  **  " ;
    }
    for (int i = 0; i < q; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        //dij(u, k, t);
        printf("%lld\n", dis[u]+dis[v]);
    }
    
}

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

int main(){
int a, b;
cin >> a >> b;
int cnt = 0;
for(int i = 1; i <= a; i++){ 
     for(int j = 1; j <= 12; j++){ 
          if(i == a && j > b) break;
          if(i == j) cnt++;
     }
}
cout << cnt << endl; 
}

Measured memory_bytes: 256
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/16 18:38:57
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e5 + 5;

int n;
int c[N], cnt[N];
vector <int> G[N];

int sz[N], sum[N];
ll ans[N];

ll f(int x) {
    return 1ll * x * (x + 1) / 2;   
}

void dfs(int u, int fa) {
    sz[u] = 1;
    int t = sum[c[u]];
    for (auto v : G[u]) if (v != fa) {
        sum[c[u]] = 0;
        dfs(v, u);
        sz[u] += sz[v];
        ans[c[u]] -= f(sz[v] - sum[c[u]]);
    }
    sum[c[u]] = t + sz[u];
}

void run() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
        ++cnt[c[i]];
    }
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        ans[i] += f(n) - f(n - sum[i]);
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

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

int main(){
  while(true){
    int n, a[100100] = {}, sum = 0, count = 0, N;
    cin>>N;
    if(!N) break;
    for(int i = 1; i <= N; i++){
      cin>>a[i];
      sum += a[i];
    }
    for(int i = 1; i <= N; i++){
      if(a[i]*N <= sum)count++;
    }
    cout<<count<<endl;
  }
  return 0;
}



Measured memory_bytes: 3480
(* O(|s|) *)
let s = read_line ()
let i = ref @@ String.length s - 1
let ws = [|"dream"; "dreamer"; "erase"; "eraser"|]
let _ =
  while !i >= 0 do
    let j = ref 0 in
    let is_ok = ref false in
    while !j < 4 && not !is_ok do
      let m = String.length ws.(!j) in
      if String.sub s (max 0 @@ !i - m + 1) @@ m = ws.(!j) then (i := !i - m; is_ok := true);
      incr j done;
    if not !is_ok then (print_endline "NO"; exit 0) done;
  print_endline "YES"

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int A,B,Q;
  cin >> A >> B >> Q;
  VLL s(A), t(B), x(Q);
  rep(i,A) cin >> s[i];
  rep(i,B) cin >> t[i];
  rep(i,Q) cin >> x[i];

  rep(i,Q){
    vector<long long>::iterator it_s = lower_bound(all(s),x[i]);
    vector<long long>::iterator it_t = lower_bound(all(t),x[i]);
    VLL target_s, target_t;
    if(it_s != s.end())   target_s.push_back(*it_s);
    if(it_t != t.end())   target_t.push_back(*it_t);
    if(it_s != s.begin()) {
      --it_s;
      target_s.push_back(*it_s);
    }
    if(it_t != t.begin()){
      --it_t;
      target_t.push_back(*it_t);
    }


    ll min_cost = 1e15;
    //cout << i <<"-----------------" << endl;
    rep(j,target_s.size()) rep(k,target_t.size()){
      //cout << x[i] << " -> " << << " -> " <<
      min_cost = min(min_cost, abs(x[i] - target_s[j]) + abs(target_t[k] - target_s[j]));
      min_cost = min(min_cost, abs(x[i] - target_t[k]) + abs(target_t[k] - target_s[j]));
    }
    cout << min_cost << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int a, b;
    cin >> a >> b;

    cout << (a + b) % 24 << endl;

    return 0;
}



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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	int res = 300;
	for (int i = 0; i <= 100; i++) {
		int a = A >= i ? A - i : abs(A - i) / 2 + abs(A - i) % 2 * 2;
		int b = B >= i ? B - i : abs(B - i) / 2 + abs(B - i) % 2 * 2;
		int c = C >= i ? C - i : abs(C - i) / 2 + abs(C - i) % 2 * 2;
		res = min(res, a + b + c);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

template <typename T> using order_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll         long long int
#define endl       '\n'
#define pii        pair <int, int>
#define mk         make_pair

static const int maxn = 3e5 + 5;
static const int logn = 19;
static const ll mod = 1e9 + 7;

vector < vector <int> > graph;
int n;
int k;

ll solve(int u, int p, int lvl) {
      ll res = 1;
      int len = graph[u].size();
      int child = 0;
      for (int i = 0; i < len; i++) {
            int v = graph[u][i];
            if (v == p) {
                  continue;
            }
            int bad = child + 1 + (lvl > 0);
            ++child;
            res = (res * (k - bad)) % mod;
            res = (res * solve(v, u, lvl + 1)) % mod;
      }
      return res;
}

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);

      cin >> n >> k;
      graph.resize(n + 1);
      for (int e = 1; e < n; e++) {
            int u, v;
            cin >> u >> v;
            graph[u].push_back(v);
            graph[v].push_back(u);
      }
      ll ans = solve(1, -1, 0);
      cout << (ans * k) % mod << endl;
}


Measured memory_bytes: 11520
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

#define drobucs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main() {
	drobucs;

	int n, d;
	cin >> n >> d;

	vector<vector<int>> v(n, vector<int>(d));

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < d; ++j) {
			cin >> v[i][j];
		}
	}
	int cnt = 0;
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int dist, sum = 0;
			for (int k = 0; k < d; ++k) {
				sum += pow((v[i][k] - v[j][k]), 2);
			}
			dist = sqrt(sum);
			if (dist * dist == sum) {
				cnt++;
			}
		}
	}

	cout << cnt;

	return 0;
}

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

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

    int counter = 0;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= i; j++){
            if(i % j == 0 && i % 2 == 1)
                counter++;
        }
        if(counter == 8)
            ans++;

        counter = 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

// ll n;
// ll dp[(ll)pow(2,21)];
// ll a[21][21];

// ll f(ll mask){
//     // print("call "<<" "<<mask);
//     ll cnt=0, cnt0=0;
//     for(ll j=0; j<n; j++){
//         if((mask & (1<<j)) == 0) cnt0++;
//     }
//     for(ll j=0; j<n; j++){
//         cnt += (ll)(((mask & (1<<j)) != 0) && a[cnt0][j]);
//     }
//     // print(cnt);
//     // print(cnt0);
//     // if(cnt == 0) ret0;
//     if(cnt0==n-1) {
//         ret cnt;
//     }
//     else if(dp[mask]!=-1) {
//         // print("case 2");
//         ret dp[mask];
//     }
//     else {
//         // print("case 3");
//         ll ans = 0;
//         for(ll j=0; j<n; j++){
//             if((mask & (1<<j)) != 0 && a[cnt0][j] == 1){
//                 ans = (ans%mod + f(mask ^ (1<<j))%mod)%mod;
//             }
//         }
//         return dp[mask] = ans%mod;
//     }
// }

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/

    ll n;
    cin>>n;
    ll a[n][n];
    loop(i,0,n){
        loop(j,0,n) cin>>a[i][j];
    }
    ll dp[1<<n] = {0};

    dp[(1<<n) - 1] = 1;
    for(ll i = (1<<n)-2; i>=0; i--){
        // print(i<<" tree");
        ll k = __builtin_popcount(i);
        // print(k);
        for(ll j = 0; j<n; j++){
            // cout<<(i&(1<<j))<<endl;;
            // print(a[k][j]);
            ll x = (i&(1<<j));
            if((x == 0) && (a[k][j] == 1)){
                // cout<<" as "<< (i|(1<<j)) <<endl;;
                dp[i] = (dp[i]%mod + (dp[i|(1<<j)])%mod)%mod;
            }
        }
        // print(i<<" val: "<<dp[i]);
    }

    print(dp[0]);

    /*#ifndef ONLINE_JUDGE
        end_routine();
    #endif*/
}



Measured memory_bytes: 16768
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

struct DP{
  int cost;
  int next;
  DP(){
    cost = INF;
    next = -1;
  }
};

int main(){
  int total_hotels;
  int total_days;
  while(~scanf("%d %d",
	       &total_hotels,
	       &total_days)){
    int price_table[55][55];
    memset(price_table,0,sizeof(price_table));

    for(int hotel_idx=1;hotel_idx<=total_hotels;hotel_idx++){
      for(int day=1;day<=total_days;day++){
	int price;
	scanf("%d",&price);
	price_table[day][hotel_idx] = price;
      }
    }

    DP dp[55][55][55]; //dp[day][current_hotel][current_move_count] = cost
    for(int day=0;day<=total_days;day++){   
      for(int hotel_idx=1;hotel_idx<=total_hotels;hotel_idx++){
      	  for(int move_count=0;move_count<=total_days;move_count++){
	    dp[day][hotel_idx][move_count].cost = INF;
	    dp[day][hotel_idx][move_count].next = -1;
	  }
      }
    }

    for(int hotel_idx=1;hotel_idx<=total_hotels;hotel_idx++){
      dp[total_days+1][hotel_idx][0].cost = 0;
      dp[total_days+1][hotel_idx][0].next = hotel_idx;
    }

    for(int day=total_days;day>=1;day--){   
	for(int next_hotel_idx=1;next_hotel_idx<=total_hotels;next_hotel_idx++){
	  for(int hotel_idx=1;hotel_idx<=total_hotels;hotel_idx++){
	    for(int next_move_count=0;next_move_count<=total_days;next_move_count++){
	    
	    int move_count
	      = next_move_count + (next_hotel_idx == hotel_idx ? 0 : 1);

	    if(dp[day][hotel_idx][move_count].cost
	       > dp[day+1][next_hotel_idx][next_move_count].cost + price_table[day][hotel_idx]){
	      
	      dp[day][hotel_idx][move_count].cost
		= dp[day+1][next_hotel_idx][next_move_count].cost + price_table[day][hotel_idx];
	      dp[day][hotel_idx][move_count].next = next_hotel_idx;
	    }
	  }
	}
      }
    }
    
    int next_hotel;
    int current_move_count = 0;
    int min_cost = INF;
    int min_move_count = INF;

    for(int move_count=0;move_count<=total_days;move_count++){
      for(int hotel_idx=1;hotel_idx<=total_hotels;hotel_idx++){
	if(dp[1][hotel_idx][move_count].cost < min_cost){
	  min_cost = dp[1][hotel_idx][move_count].cost;
	  min_move_count = move_count;
	  next_hotel = hotel_idx;
	  current_move_count = move_count;
	}
      }
    }

    printf("%d %d\n",min_cost,min_move_count);
    for(int day=1;day<=total_days;day++){
      printf("%d\n",next_hotel);
      int tmp_hotel = dp[day][next_hotel][current_move_count].next;
      if(tmp_hotel != next_hotel) current_move_count--;
      next_hotel = tmp_hotel;
    }
  }
  return 0;
}

Measured memory_bytes: 2508
#include <stdio.h>

int main(void){
	int N, ans=0,i,x;
	scanf("%ld",&N);
	int a[100001] = {0};
	for(i = 0; i < N; i++){
		scanf("%ld",&x);
		a[x]=1;
	}
	for(i = 0; i < 100001; i++){
		if(a[i] == 1) ans++;
	}
	printf("%ld",ans - 1 + ans % 2);
	return 0;
}


Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        n:usize,
        q:usize,
        s:chars,
        lrn:[(usize,usize);q],
    };
    let mut ans:Vec<i64> = vec![0];
    let mut count = 0;
    for i in 0..n-1
     {
        if s[i] == 'A' && s[i + 1] == 'C' {
            count += 1;
        }
         ans.push(count);
    }
    for &(k,v) in &lrn {
        println!("{}",(ans[k-1]-ans[v-1]).abs());
    }
}

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

const int mxN = 1e5;
int h[mxN], dp[mxN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> h[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <= k && i+j<n; j++) {
			dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
		}
	}

	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll K;
    cin >> K;
    vector<ll> A(K);
    rep(i,K){
        cin >> A[i];
    }
    if(A[K-1] != 2){
        cout << -1 << endl;
        return 0;
    }
    //ll cur = 2;
    ll M = 2;
    ll m = 2;
    ll MM;
    ll mm;
    rep(i,K){
        if(m % A[K-1-i] == 0){
            mm = m/A[K-1-i];
        }else{
            mm = m/A[K-1-i];
            mm++;
        }
        MM = M/A[K-1-i];

        //M = M/A[K-1-i];
        /*if(M < 1){
            cout << -1 << endl;
            return 0;
        }*/
        /*if(m > M){
            m = M;
        }*/
        mm = A[K-1-i] * mm;
        MM = A[K-1-i] * MM + A[K-1-i] - 1;
        if(MM < m || mm > M){
            cout << -1 << endl;
            return 0;
        }
        M = MM;
        m = mm;
        //cout << m << " a " << M << endl;
        //cur = A[K-2-i];
        //M = M*2-1;
        //m = max(m, A[K-2-i]);
    }
    cout << m << " " << M << endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int n;
    cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    map<int, int> odd, even;
    REP(i, n) (i % 2 ? odd : even)[a[i]]++;
    int ans = n;
    map<int, VI> revEven;
    FORE(e, even) revEven[e.second].EB(e.first);
    FORE(e, odd) {
        int foo = e.second;
        if (revEven.rbegin()->second.size() == 1 && revEven.rbegin()->second[0] == e.first) {
            if (revEven.size() == 1) {
                chmin(ans, n - foo);
            } else {
                auto it = revEven.rbegin();
                it++;
                chmin(ans, n - foo - it->first);
            }
        } else {
            chmin(ans, n - foo - revEven.rbegin()->first);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll X, Y;
    cin >> X >> Y;
    if(abs(X - Y) <= 1) PRINT("Brown");
    else PRINT("Alice");
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int[] ans = {Math.abs(a - b), Math.abs(b - c), Math.abs(c - a)};
        Arrays.sort(ans);

        System.out.println(ans[0] + ans[1]);
   }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  string S; cin >> S;
  string p = S.substr(0,1);
  //cout << p << endl;
  int ans = 1;
  for(int i=1; i<S.size();) {
    int r = 1;
    while(1) {
      if(p == S.substr(i,r)){
        ++r;
        if(i+r > S.size()) {
          --ans;
          break;
        }
      } else {
        p = S.substr(i,r);
        break;
      }
    }
    ++ans;
    //cout << p << endl;
    i = i+r;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
N,M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]

tmp = []
for i in range(M):
    tmp.append(A[i][0])
    tmp.append(A[i][1])

for i in range(1, N+1):
    print(tmp.count(i)) 


Measured memory_bytes: 2940
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 2000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

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

    ll ans = 0LL;
    rep(n){
        reppp(j, i+1, n-1){
            ll min_distance = MAX;
            int min_k = -1;
            repp(k, n){
                if(k == i || k == j) continue;
                if(min_distance > a[k][i]+a[k][j]){
                    min_distance = a[k][i]+a[k][j];
                    min_k = k;
                }

            }
            if(min_distance < a[i][j]){
                cout << -1;
                return 0;
            }else if(min_distance > a[i][j]){
                ans += a[i][j];
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>

int t,n,m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string x,y;
	int ans=1001;
	cin >> x >> y;
	for (int i=0, last=x.length()-y.length(); i<=last; i++){
		int tans=0;
		for (int j=0; j<y.length(); j++){
			if (x[i+j] != y[j]) ++tans;
		}
		ans = min(ans,tans);
	}
	
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<ll> h(N);
    rep(i, N) cin >> h[i];

    vector<ll> dp(N, INF);
    dp[0] = 0;
    rep(i, N) {
        if (i - 2 >= 0) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        if (i - 1 >= 0) chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    agc011a()
}

fun agc011a() {
    val (n, c, k) = readLine()!!.split(' ').map { it.toInt() }
    val tList = (1..n).map { readLine()!!.toInt() }
        .sorted()

    var left = 0
    var right = 0
    var answer = 0
    while (left <= tList.lastIndex) {
        while (right <= tList.lastIndex && right - left + 1 <= c && tList[right] - tList[left] <= k) right++
        answer++
        left = right
    }

    println(answer)
}


Measured memory_bytes: 47652
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <fstream>

using namespace std;


bool t[101][101],p[101][101];
int a[101][101];
int main()
{
	int n,mh,mc;
	while(cin>>n)
	{
		if(n==0)break;
		else{
		for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
		cin>>a[i][j];
		t[i][j]=0;
		p[i][j]=0;
		}
		for(int i=0;i<n;i++)
		{	mh=0;
			for(int j=1;j<n;j++)
			{
				if(a[i][j]<a[i][mh])mh=j;
			}
			for(int j=0;j<n;j++)
			{
				if(a[i][j]==a[i][mh])t[i][j]=1;
			}
		}
		for(int i=0;i<n;i++)
		{	mc=0;
			for(int j=1;j<n;j++)
			{
				if(a[j][i]>a[mc][i])mc=j;
			}
			for(int j=0;j<n;j++)
			{
				if(a[j][i]==a[mc][i])p[j][i]=1;
			}
		}
		int kt=0;
		for(int i=0;i<n;i++)
		{
		if(kt==1)break;
		for(int j=0;j<n;j++)
		{
			if(t[i][j]==1&&p[i][j]==1){
			cout<<a[i][j]<<endl;
			kt=1;
			break;
			}
			//cout<<t[i][j]<<"  ";
		}
		//cout<<endl;
		}
		if(kt==0)cout<<0<<endl;
//		for(int i=0;i<n;i++)
//		{
//		for(int j=0;j<n;j++)
//		{
//			if(t[i][j]==1&&p[i][j]==1)cout<<a[i][j]<<endl;
//			cout<<p[i][j]<<"  ";
//		}
//		cout<<endl;
//		}
	}}
}

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

int main(){
	ios::sync_with_stdio(false);
    cin.tie();
    
    signed long long x,k,d;
    cin>>x>>k>>d;
    if(x==0){
        if(k%2==0)cout<<0<<endl;
        else cout<<d<<endl;
        return 0;
	}
	if(abs(x)/d>k){
		cout<<abs(x)-d*k<<endl;
		return 0;
	}
	unsigned long long re=k-x/d;
	signed long long z1,z2;
	signed long long ans;
	z1=x%d;
	if(x<0)z2=z1+d;
	else if(x>0)z2=z1-d;
	if(re%2==1) ans=z2;
	if(re%2==0) ans=z1;
	cout<<abs(ans)<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int n,m,R,dist[300][300],r[10];

int main()
{
	memset(dist,0x3f,sizeof dist);
	int Min,ans;
	cin>>n>>m>>R;
	for(int i=0;i<R;i++)
		cin>>r[i];
	for(int i=0;i<m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		dist[x][y]=dist[y][x]=z;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(dist[i][k]+dist[k][j]<dist[i][j])
					dist[i][j]=dist[i][k]+dist[k][j];
	sort(r,r+R);
	ans=0x3f3f3f3f;
	do
	{
		Min=0;
		for(int i=0;i<R-1;i++)
			Min+=dist[r[i]][r[i+1]];
		ans=min(Min,ans);
	}while(next_permutation(r,r+R));
	cout<<ans;
}

Measured memory_bytes: 640
def digSum(i):
    dig = str(i)
    array = list(map(int, list(dig)))
    return sum(array)

N = int(input())
minSum = float("inf")

for a in range(1, (N//2) + 1):
    b = N-a
    sumAB = digSum(a) + digSum(b)
    if sumAB < minSum:
        minSum = sumAB

print(minSum)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		rep(i, 10)rep(j, 10)rep(k, 10)rep(l, 10) {
			if (i + j + k + l == n) {
				ans++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, o;
    cin>>n>>m>>o;
    if(n==m && n!=o)
        cout<<"Yes";
    else if(n==o && n!=m)
        cout<<"Yes";
    else if(m==o && m!=n)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3572
// hare krishna
# include <iostream>
using namespace std;
int main()
{
	int l,r,d,p;
	p=0;
	cin>>l>>r>>d;
	for(int i=0; i<i+1; i++)
	{
		if(d*(i+1)>=l && d*(i+1)<=r)
		{
			p=p+1;
		}
		if(d*(i+1)>r)
		{
			break;
		}
	}
	cout<<p;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define X first
#define Y second
#define mp(x, y) make_pair(x, y)
#define pb(e) push_back(e)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define iter(c) __typeof((c).begin())
#define each(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)

using namespace std;

typedef long long LINT;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = 1 << 29;

int main ( void )
{
	int n;
	while ( cin >> n, n ) {
		VI p( n + 1 ), t( n + 1 );
		p[0] = t[0] = 0;
		for ( int i = 1; i <= n; ++i ) {
			cin >> p[i] >> t[i];
		}
		
		int k_th = 0;
		VVI m( n+1, VI( 4, INF ) );

		m[0][0] = m[0][1] = 0;
		for ( int i = 1; i <= n; ++i ) {
			bool change = false;
			for ( int j = 2; j <= 3; ++j ) {
				if ( m[i - 1][j - 1] != INF ) {
					if ( t[i] >= t[i - 1] + abs( p[i] - p[i - 1] ) * j ) {
						m[i][j] = m[i - 1][j - 1] + abs( p[i] - p[i - 1] );
						m[i][0] = min( m[i][0], m[i][j] + p[i] );
						change = true;
					}
				}
			}
			for ( int j = 1; j <= 3; ++j ) {
				if ( m[i - 1][j] != INF ) {
					if ( t[i] >= t[i - 1] + p[i - 1] * (j + 1) + p[i] ) {
						m[i][1] = min( m[i][1], m[i - 1][j] + p[i - 1] + p[i] );
						m[i][0] = min( m[i][0], m[i][1] + p[i] );
						change = true;
					}
				}
			}
			if ( !change ) {
				k_th = i;
				break;
			}
		}
		if ( m[n][0] == INF ) {
			cout << "NG " << k_th << endl;
		}
		else {
			cout << "OK " << m[n][0] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static class R {
        public int inputNum;
        public String name;
        public int point;
        public int rank;
    }

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        int n = Integer.parseInt( in.nextLine() );
        List<String> rows = new ArrayList<>();
        for( int i = 0 ; i < n ; i++ ){
            rows.add( in.nextLine() );
        }

        List<R> rs = new ArrayList<>();
        for( int i = 0 ; i < n ; i++ ){
            String[] row = rows.get(i).split(" ");
            R r = new R();
            r.inputNum = i + 1;
            r.name = row[0];
            r.point = Integer.parseInt( row[1] );
            r.rank = 0;
            rs.add( r );
        }

        rs.sort(new Comparator<R>() {
            @Override
            public int compare(R o1, R o2) {
                int comp = o1.name.compareTo(o2.name);
                if( comp == 0 ){
                    return o2.point - o1.point;
                }
                else return comp;
            }
        });

        for( int i = 0 ; i < n ; i++ ){
            R r = rs.get(i);
            System.out.println(r.inputNum);
        }

    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   ll a,b,k;
   cin >> a >> b >> k;
   cout<<max(0LL,a-k)<<' '<<max(b-max(k-a,0LL),0LL)<<endl;
   return 0;
}

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

int main()
{
  vector<int> vec(3);
  int  k;
  cin >> vec[0], cin >> vec[1], cin >> vec[2], cin >> k;

  sort(vec.begin(), vec.end());
  for (int i = 0; i < k; i++) {
    vec[2] *= 2;
  }

  cout << accumulate(vec.begin(), vec.end(), 0) << endl;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque, defaultdict

N, M = map(int, input().split())
ins = [0]*N
outs = defaultdict(list)

for _ in range(N+M-1):
    Ai, Bi = map(int, input().split())
    ins[Bi-1] += 1
    outs[Ai-1].append(Bi-1)

ans = [-1]*N
q = deque([i for i in range(N) if ins[i]==0])

while q:
    v = q.popleft()
    
    for nv in outs[v]:
        ins[nv] -= 1
        
        if ins[nv]==0:
            ans[nv] = v
            q.append(nv)

for ans_i in ans:
    print(ans_i+1)

Measured memory_bytes: 67800
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
long long a[10005],n,m,k,ans=0,i,r,l,j,p=0,b[10005];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=4&&i<=n;i++)
	{
		for(l=1;l<=n-i+1;l++)
		{
			if(a[l]!=0||i==1)
			{
				for(j=l;j<=l+i-1;j++)
					p=p*10+a[j];
				b[p]=1;
				p=0;
			}
		}
	}
	for(i=0;i<=10000;i++)
		if(b[i]==0)
		{
			cout<<i<<endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 3180
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

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

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 100005;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}
ll dp[2002][2002];
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n],b[m];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int j=0;j<m;j++) cin>>b[j];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(!i||!j) dp[i][j]=0;
            else
            {
                if(a[i-1]==b[j-1]) dp[i][j]=(1+dp[i][j-1]+dp[i-1][j])%mod;
                else dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+mod)%mod;
            }
        }
    }
    cout<<(dp[n][m]+1)%mod<<endl;
}


Measured memory_bytes: 34880
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

class Node{
    public:
        Node* prev;
        Node* next;
        int data;
        Node(){prev = 0; next = 0; data = 0;}
};

class List{
    private:
        Node head;
    public:
        List(){head.prev = &head; head.next = &head;}
        int insert(int x);
        int del(int x);
        int deleteFirst();
        int deleteLast();
        void print();
};

int List::insert(int x){
    Node* p = new Node();

    if(p == 0) 
        return -1;

    Node* q = &head;
    Node* r = head.next;

    p->prev = q;
    p->next = r;
    p->data = x;

    q->next = p;
    r->prev = p;

    return 0;
}

int List::del(int x){
    Node* p;

    for(p=head.next; p!=&head; p=p->next){ 
        if(p->data==x) break;
    }
    if(p==&head) return -2;

    Node* q = p->prev;
    Node* r = p->next;
    
    q->next = r;
    r->prev = q;
    
    delete p;
    
    return 0;
}

int List::deleteFirst(){
    Node* p = head.next;

    if(p == &head) 
        return -2;

    Node* q = p->prev;
    Node* r = p->next;

    q->next = r;
    r->prev = q;

    delete p;
    
    return 0;
}

int List::deleteLast(){
    Node* p = head.prev;

    if(p == &head) 
        return -2;

    Node* q = p->prev;
    Node* r = p->next;

    q->next = r;
    r->prev = q;

    delete p;

    return 0;
}

void List::print(){
    for(Node* p = head.next; p != &head; p = p->next){
        cout << p->data;

        if(p->next != &head){
            cout << ' ';
        }else{
            cout << endl;
        }
    }
}

int main(){
    List L;

    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        char com[20];
        cin >> com;

        if(com[0] == 'i'){
            int x;
            cin >> x;

            L.insert(x);
        }else if(com[6] == 'F'){
            L.deleteFirst();
        }else if(com[6] == 'L'){
            L.deleteLast();
        }else{
            int x;
            cin >> x;
            L.del(x);
        }
    }
    L.print();
    return 0;
}


Measured memory_bytes: 34228
#include <stdio.h>
#include <math.h>
#define N 10000

int main() {
  int i,a,A[N],cnt=0,b=0,c,flag=0;
  scanf("%d",&a);
  for(i=0;i<a;i++)scanf("%d",&A[i]);
  for(i=0;i<a;i++){
    if(A[i]==2 || A[i]==3){
      cnt++;
      continue;
  }
    if(A[i]<2 || A[i]%2==0)continue;
    c=3;
    flag=0;
    while(c<=sqrt(A[i])){
      if(A[i]%c==0){
	flag=1;
	break;
      }
      c+=2;
    }
    if(flag==0)cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  int N, A, B;
  cin >> N >> A >> B;
  
  //main
  
  // output
  cout << min(A*N,B);
  
  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,d,l,r;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	l=a+b;
	r=c+d;
	if(l>r)
	{
		printf("Left");
	}
	else if(l==r)
	{
		printf("Balanced");
	}
	else
	{
		printf("Right");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cassert>
using namespace std; typedef long long ll; const int MINF=-1e9; typedef pair<int,int> P;

int main() {
  int n,k; cin>>n>>k;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll b1[n], b2[n]; b1[0]=max(0LL,a[0]); b2[n-1]=max(0LL,a[n-1]); 
  for(int i=1;i<n;i++) b1[i]=b1[i-1]+max(0LL,a[i]);
  for(int i=n-2;i>=0;i--) b2[i]=b2[i+1]+max(0LL,a[i]);
  ll nkb[n-k+1]; fill(nkb,nkb+n-k+1,0); // nkw[i]=0
  for(int i=0;i<k;i++) nkb[0]+=a[i];
  for(int i=k,j=0;i<n;i++,j++) nkb[j+1]=nkb[j]+a[i]-a[j];

  //for(int i=0;i<n;i++) cout<<b1[i]<<" "; cout<<endl;
  //for(int i=0;i<n;i++) cout<<b2[i]<<" "; cout<<endl;
  //for(int i=0;i<n-k+1;i++) cout<<nkb[i]<<" "; cout<<endl;

  ll an=-1e16;
  for(int i=0;i<n-k+1;i++) {
    ll sm=0;
    if (i-1 >= 0) sm+=b1[i-1];
    if (i+k < n) sm+=b2[i+k];
    sm += max(nkb[i], 0LL);
    an=max(an,sm);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  string S; cin >> S;
  if(S[2]==S[3] && S[4]==S[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256