akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define INF 987654321

using namespace std;
using llong = long long;
using VI = vector<int>;
using PII = pair<int, int>;

int n;
VI a;
VI dp;

int dfs(int k) // k번째 돌에 있을 때(0-n-1) 최솟값
{
	if (k == n - 1) return 0;
	if (dp[k] != -1) return dp[k];
	int dfs1=INF, dfs2=INF;
	if (k + 1 <= n - 1) dfs1 = dfs(k + 1) + abs(a[k] - a[k + 1]);
	if (k + 2 <= n - 1) dfs2 = dfs(k + 2) + abs(a[k] - a[k + 2]);
	return dp[k] = min(dfs1, dfs2);
}

int main()
{
	IOS;
	cin >> n;
	a.resize(n);
	dp.resize(n);
	fill(all(dp), -1);
	rep(i, 0, n) cin >> a[i];
	cout << dfs(0);

	return 0;
}



Measured memory_bytes: 8748
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}
ll n, k;
ll h[maxN];
ll dp[maxN];

ll solve(ll pos) { // pos will be 0 indexing based
	if (pos <= 0) {
		return 0;
	}
	if (pos <= k) {
		if (dp[pos] == -1)
			return dp[pos] = abs(h[0] - h[pos]);
		else
			return dp[pos];
	}
	if (dp[pos] != -1)
		return dp[pos];
	ll a = INT_MAX;
	for (ll j = 1; j <= k; j++) {
		a = min(a, abs(h[pos] - h[pos - j]) + ( dp[pos - j] == -1 ? dp[pos - j] = solve(pos - j) : dp[pos - j]));
	}
	return dp[pos] = a;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	cin >> n >> k;
	FOR(i, n) cin >> h[i];
	FOR(i, maxN) dp[i] = -1;
	dp[0] = 0;
	cout << solve(n - 1);
	return 0;
}


Measured memory_bytes: 11384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int a[200010];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[x]++;
    }
    for(int i = 1; i < n; i++) {
        printf("%d\n", a[i]);
    }
    printf("%d\n", a[n]);

    return 0;
}


Measured memory_bytes: 2512
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,t,minx=2147483647,x,y,flag=0;
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		if(y<=t)
			minx=min(minx,x),flag=1;
	}
	if(!flag)
		printf("TLE"),exit(0);
	printf("%d",minx);
	return 0;
}

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

int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> grid(h);
  for (auto& row: grid) {
    std::cin >> row;
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '.') {
        continue;
      }
      bool adjacent = false;
      adjacent |= i > 0 && grid[i - 1][j] == '#';
      adjacent |= i < h - 1 && grid[i + 1][j] == '#';
      adjacent |= 0 < j && grid[i][j - 1] == '#';
      adjacent |= j < w - 1 && grid[i][j + 1] == '#';
      if (!adjacent) {
        std::cout << "No" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll mod = 1e9+7;
const int len=1005;


ll suan(ll x)
{
    if (x&1)
    {
        x=(x+1)/2;
        x&=1;
    }
    else 
    {
        ll t=x+1;
        x++;
        x=(x+1)/2;
        x&=1;
        x^=t;
    }

    return x;
}

int main()
{
    ll a,b;

    cin>>a>>b;
    a--;

    if (a==-1)
    {
        cout<<suan(b)<<endl;
    }
    else
    {
        cout<<(suan(b)^suan(a))<<endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,used[100009];
main(){
	for(int i=0;i<100009;i++)used[i]=1e9;
	cin>>n;
	deque<int>q;
	q.push_back(1);
	used[1]=1;
	while(!q.empty()){
		int x=q.front();q.pop_front();
		int a=(x*10)%n,b=(x+1)%n;
		if(used[a]>used[x]){
			used[a]=used[x];
			q.push_front(a);
		}
		if(used[b]>used[x]+1){
			used[b]=used[x]+1;
			q.push_back(b);
		}
	}
	cout<<used[0]<<endl;
}

Measured memory_bytes: 896
n, k = map(int, input().split())
N = [i for i in range(1, n+1)]
ans = []
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        ans.append(j)
count = 0
for x in N:
    if x not in ans:
        count += 1
print(count)

Measured memory_bytes: 68148
#include <iostream>
using namespace std;
#define  M 1000000007
typedef long long ll;

ll factorial(int n) {
  ll sum = 1;
  for (int i = 1; i <= n; i++) {
    sum *= i;
    sum %= M;
  }
  return sum;
}

template< typename T, typename U>
T mod_pow(T x, U n, const U &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


int main() {
  int X, Y;
  cin >> X >> Y;
  if ((X + Y) % 3  != 0)
    cout << '0' << endl;
  else {
    int n = (X+Y)/3;
    int r = X - n;
    if (r < 0 || r > n)
      cout << '0' << endl;
    else {
      ll s = factorial(n);
      ll t = factorial(r);
      ll u = factorial(n-r);
      t = mod_pow(t, M-2, M);
      u = mod_pow(u, M-2, M);
      cout << ((s*t)%M)*u%M << endl;
    }
  }
}


Measured memory_bytes: 256
package main

import "fmt"

func maxInt(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func reversed(n []int) {
	for i, j := 0, len(n)-1; i < j; i, j = i+1, j-1 {
		n[i], n[j] = n[j], n[i]
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	var nums []int

	nums = append(nums, n%10)
	for n/10 != 0 {
		n = n / 10
		nums = append(nums, n%10)
	}
	reversed(nums)
	var ans, tempAns, temp int
	for i := 0; i < (1 << uint(len(nums)-1)); i++ {
		temp = nums[0]
		tempAns = 0
		for j := 0; j < len(nums)-1; j++ {
			if (i>>uint(j))&1 == 1 {
				tempAns = tempAns + temp
				if j+1 < len(nums) {
					temp = nums[j+1]
				} else {
					temp = 0
				}
			} else {
				temp = temp*10 + nums[j+1]
			}
		}
		tempAns += temp
		ans += tempAns
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> B){
  vector<ll> A;
  REP(N){
    if(i==0){
      A.push_back(B[0]);
    }else if(i==N-1){
      A.push_back(B[i-1]);
    }
    else{
      A.push_back(min(B[i],B[i-1]));
    }
  }
  cout<<accumulate(A.begin(),A.end(),0LL)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(B));
    return 0;
}


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

int main() {
    int n;
    long long k;
    cin >> n >> k;
    long long a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    vector<long long> arrive;
    arrive.push_back(0);
    vector<long long>::iterator p;
    long long P;

    set<long long >s;
    s.insert(0);

    // https://teramonagi.hatenablog.com/entry/20130225/1361793892
    for(int i = 0; i < n; i++) {
        long long next = a[arrive[i]];
        s.insert(next);
        if(s.size() == i + 2) {
            arrive.push_back(next);
            continue;
        }

        p = find(arrive.begin(), arrive.end(), next);
        P = (long long) distance(arrive.begin(), p);

        if(p != arrive.end()) {
            // cout << "found " << next << " at " << P << endl;
            break;
        }
    }

    int size = arrive.size();
    int period = size - P;

    // cout << "period: " << period << endl;

    // cout << "iterator: " << *p << endl;

    /*
    for(int i = 0; i < size; i++) cout << arrive[i] << ' ';
    cout << endl;
     */
    
    long long index;
    if(k <= P) index = k;
    else index = P + (k - P) % period;

    // cout << "index: " << index << endl;

    cout << arrive[index] + 1 << endl;





    return 0;
}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n; cin >> n;
	vi a(n); cin >> a;
	multiset<int> ms;
	for (int x : a) ms.insert(x);
	vi ans;
	ans.push_back(*ms.begin()); ms.erase(ms.begin());
	ans.push_back(*(--ms.end())); ms.erase(--ms.end());
	for (int i=0;i+2<n;i++) {
		int tar = ans[i] ^ ans[i + 1];
		// cerr << tar << ": " << ans;
		auto it = ms.find(tar);
		if (it == ms.end()) return cout << "No" << endl, 0;
		ms.erase(it);
		ans.push_back(tar);
	}
	for (int i=0;i<n;i++) {
		if ((ans[i] ^ ans[(i + 2) % n]) != ans[(i + 1) % n])
			return cout << "No" << endl, 0;
	}
	cout << "Yes" << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 5504
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define debug(x) cout<<#x<<": "<<x<<endl
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rfor(i, st, en) for(ll i=st; i>=en; i--)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define printv(x) For(i, 0, x.size()){cout<<x[i]<<" ";} cout<<endl;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vpi;
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007


signed main(){
	fast
	string a, b;
	cin>>a>>b;
	vi mp[30];

	int n = a.size();
	For(i, 0, n){
		int val = a[i]-'a';
		mp[val].pb(i+1);
	}

	int count=0;
	int m= b.size();
	For(i, i, m){
		int val = b[i]-'a';
		if(!mp[val].size()){
			cout<<-1<<endl;
			return 0;
		}
	}
	int val = b[0]-'a';
	int temp = mp[val][0];
	int ch;
	For(i, 1, m){
		val = b[i]-'a';
		if(temp>=mp[val].back()){
			count++;
			temp=mp[val][0];
		}else{
			ch = *upper_bound(all(mp[val]), temp);
			temp=ch;
		}
	}
	int ans = count*n + temp;
	cout<<ans<<endl;
    return 0;
}
    



Measured memory_bytes: 1736
from collections import deque

def is_equal(dice1, dice2):

    equal = "No"

    if dice1.min != dice2.min or dice1.max != dice2.max:
        return "No"

    top0 = dice1.disp_top_face()
    front0 = dice1.disp_front_face()

    flag = 1

    for _ in range(100):

        if dice2.disp_top_face() == top0:
            flag = 0
            break

        for _ in range(4):
            dice2.lotate("S")

            if dice2.disp_top_face() == top0:
                flag = 0
                break

        if flag :
            dice2.lotate("E")
        else:
            break

    for _ in range(4):

        if dice2.disp_front_face() == front0:
            break

        dice2.lotate("E")
        dice2.lotate("S")
        dice2.lotate("W")

    if dice1.disp_top_face() == dice2.disp_top_face() and \
       dice1.disp_bottom_face() == dice2.disp_bottom_face() and \
       dice1.disp_front_face() == dice2.disp_front_face() and \
       dice1.disp_left_face() == dice2.disp_left_face() and \
       dice1.disp_right_face() == dice2.disp_right_face() and \
       dice1.disp_back_face() == dice2.disp_back_face():

       equal = "Yes"

    return equal

class Dice():
    def __init__(self, seq):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

        self.max = max(seq)
        self.min = min(seq)

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

    def disp_back_face(self):
        return self.v[1]

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input()
    n = int(param)

    dices = list()

    for _ in range(n):
        param = input().split(" ")
        seq = [int(a) for a in param]
        d = Dice(seq)
        dices.append(d)

    different = "Yes"

    for i in range(len(dices)-1):

        if len(dices) - 1 < 2:
            if is_equal(dices[i], dices[i+1]) == "Yes":
                different = "No"
        else:
            for j in range( i + 1, len(dices) - 1 ):
                if is_equal(dices[i], dices[j]) == "Yes":
                    different = "No"

    print(different)



Measured memory_bytes: 6112
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

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

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  bool c = false;
  bool f = false;
  REP(i,0,s.size()) {
    if(!c && s[i] == 'C') {
      c = true;
    } else if(c && s[i] == 'F') {
      f = true;
    }
  }
  cout << (f ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll a, b;
	while (cin >> a >> b) {
		if (!a && !b)break;
		cout << min(a, b) << ' ' << max(a, b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3044
#include <stdio.h>
#include <stdlib.h>
int main()
{
        int i,j,a;
        int b = 0;
        int c = 0;
 
    // 整数の入力
    scanf("%d", &a);
    // スペース区切りの整数の入力
    //scanf("%d %d",&b,&c);
    // 文字列の入力
    //scanf("%s",s);
    // 出力
    int c_ = 0;
    char y[2];
    int s[a];
    char ss[a];
    gets(ss);
   // printf("%d\n",a);
for(i=0;i<a*2-1;i++){
  scanf("%d",&s[c_]);
  //printf("%d ",s[c_]);
  c_++;
  if(c_==a){ 
    //printf("%d\n\n",c_);
    break;}
  getc(stdin);
}

for(i=0;i<a;i++){
  //printf("%d ",s[i]);
}

    for(i=0;i<a;i++){
      if(i==0){
        b=s[0];
      }else if(i == 1){
        if(b<s[1]){
          c=s[1];
        }else{
          c=b;
          b=s[1];
        }
      }else{
      if(s[i]<b){
        b=s[i];
      }else if(s[i]>c){
        c=s[i];
      }
    }
    }
    
    printf("%d",c-b);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int K = 3005;
const int MOD = 998244353;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int dp[K][K];

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

	int n, S;
	cin >> n >> S;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= S; j++) {
			if (j + a[i] <= S) {
				dp[i + 1][j + a[i]] = add(dp[i + 1][j + a[i]], divv(dp[i][j], 2)); 
			}
			dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
		}
	}	
	// cerr << dp[n][S] << endl;
	// cerr << add(divv(1, 2), divv(1, 4)) << endl;
	int ans = mul(binpow(2, n), dp[n][S]);
	cout << ans << endl;
}

Measured memory_bytes: 73636
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int n;
  cin >> n;
  cout << n * n << endl;
  return 0;
}

Measured memory_bytes: 256
#include<set>
#include<cstdio>
#include<vector>

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

using namespace std;

int to[9][5]; // to[i] : 雲が位置 i から移動できる位置

int n;
int sun[366][16]; // sun[t][j]==1 <=> t 日目にマス j は晴れていないといけない
int rain[9][16]; // rain[i][j]==1 <=> 雲が位置 i にいるとき, マス j は雨

set< vector<char> > vis[366][9];
bool dfs(int t,int i,vector<char> last){
	if(t%2==0){ // MLE したので半分だけメモ化
		if(vis[t][i].count(last)==1) return false;
		vis[t][i].insert(last);
	}

	rep(j,16){
		if(rain[i][j]==1){
			last[j]=0;
			if(sun[t][j]==1) return false;
		}
		else{
			last[j]++;
			if(last[j]>=7) return false;
		}
	}

	if(t==n) return true;

	rep(j,5) if(dfs(t+1,to[i][j],last)) return true;
	return false;
}

int main(){
	to[0][0]=0;
	to[0][1]=1;
	to[0][2]=2;
	to[0][3]=3;
	to[0][4]=6;
	to[1][0]=1;
	to[1][1]=0;
	to[1][2]=2;
	to[1][3]=4;
	to[1][4]=7;
	to[2][0]=2;
	to[2][1]=0;
	to[2][2]=1;
	to[2][3]=5;
	to[2][4]=8;
	to[3][0]=3;
	to[3][1]=0;
	to[3][2]=4;
	to[3][3]=5;
	to[3][4]=6;
	to[4][0]=4;
	to[4][1]=1;
	to[4][2]=3;
	to[4][3]=5;
	to[4][4]=7;
	to[5][0]=5;
	to[5][1]=2;
	to[5][2]=3;
	to[5][3]=4;
	to[5][4]=8;
	to[6][0]=6;
	to[6][1]=0;
	to[6][2]=3;
	to[6][3]=7;
	to[6][4]=8;
	to[7][0]=7;
	to[7][1]=1;
	to[7][2]=4;
	to[7][3]=6;
	to[7][4]=8;
	to[8][0]=8;
	to[8][1]=2;
	to[8][2]=5;
	to[8][3]=6;
	to[8][4]=7;
	rain[0][ 0]=rain[0][ 1]=rain[0][ 4]=rain[0][ 5]=1;
	rain[1][ 1]=rain[1][ 2]=rain[1][ 5]=rain[1][ 6]=1;
	rain[2][ 2]=rain[2][ 3]=rain[2][ 6]=rain[2][ 7]=1;
	rain[3][ 4]=rain[3][ 5]=rain[3][ 8]=rain[3][ 9]=1;
	rain[4][ 5]=rain[4][ 6]=rain[4][ 9]=rain[4][10]=1;
	rain[5][ 6]=rain[5][ 7]=rain[5][10]=rain[5][11]=1;
	rain[6][ 8]=rain[6][ 9]=rain[6][12]=rain[6][13]=1;
	rain[7][ 9]=rain[7][10]=rain[7][13]=rain[7][14]=1;
	rain[8][10]=rain[8][11]=rain[8][14]=rain[8][15]=1;

	while(scanf("%d",&n),n){
		rep(t,n) rep(j,16) scanf("%d",sun[t]+j);
		rep(t,n+1) rep(i,9) vis[t][i].clear();

		vector<char> last(16); // 最後に雨が降ったのは何日前か ( int だと MLE した )
		puts(dfs(0,4,last)?"1":"0");
	}

	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int H,W,h,w;

int main(){
	scanf("%d%d%d%d" , &H , &W , &h , &w);
	int q = (H%h) * W + (W%w) * H;
	if(q == 0) return []{printf("No\n");return 0;}();
	printf("Yes\n");
	if(H%h != 0 && W%w != 0) --q;
	int x = (H/h)*(W/w) / q + 1;
	int y = -x*(h*w-1)-1;
	repm(i,H,0){
		repm(j,W,0){
			printf("%d%c" , i%h==0 && j%w==0 ? y : x , j == 1 ? '\n' : ' ');
		}
	}
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x % 2 == 0) v.push_back(x);
    }
    int ans = 0;
    for (auto &&x : v)
    {
        while (x % 2 == 0)
        {
            ans++;
            x /= 2;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

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

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 3e18;
const double eps = 1e-9;

int X[100010];
int Y[100010];
pii pos[100010];
int v[100010];

signed main()
{ // #define int long long ?????????????????§scanf???????????¨???????????????????????\?????????????????????
    int W, H; cin >> W >> H;

    int N; cin >> N;

    rep(i, N) {
        cin >> X[i];
        cin >> Y[i];
        pos[i] = pii(X[i], Y[i]);
    }

    sort(X, X + N);
    sort(Y, Y + N);

    int x, y;
    
    if (N % 2 == 0) {
        int ans = inf;
        int ansx = -1, ansy = -1;

        rep(i, 2) {
            rep(j, 2) {
                int x = X[N / 2 - i], y = Y[N / 2 - j];
                
                int sum = 0;
                int ma = 0;
                rep(k, N) {
                    int a = abs(x - pos[k].fst) + abs(y - pos[k].scd);
                    sum += a * 2;
                    chmax(ma, a);
                }
                sum -= ma;

                if (ans >= sum) {
                    ans = sum;
                    ansx = x;
                    ansy = y;
                }
            }
        }

        cout << ans << endl;
        cout << ansx << ' ' << ansy << endl;
    } else {
        x = X[N / 2], y = Y[N / 2];

        int ma = 0;
        int v = 0;

        rep(i, N) {
            int a = abs(x - pos[i].fst) + abs(y - pos[i].scd);
            v += a * 2;
            ma = max(ma, a);
        }
        v -= ma;

        cout << v << endl;
        cout << x << ' ' << y << endl;
    }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    {
      x=x->left;
    }
  return x;
}

Node treeSearch(Node u, int k){
  if(u->key>k)
    {
      if(u->left==NIL)
	{
	  return NIL;
	}
      return treeSearch(u->left,k);
    }
  if(u->key<k)
    {
      if(u->right==NIL)
	{
	  return NIL;
	}
      return treeSearch(u->right,k);
    }

  return u;

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    {
      return treeMinimum(x->right);
    }
  y=x->parent;
  while(y!=NIL&&x==y->right)
    {
      x=y;
      y=y->parent;
    }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)
    {
      y=z;
    }
  else
    {
      y=treeSuccessor(z);
    }

  if(y->left!=NIL)
    {
      x=y->left;
    }
  else
    {
      x=y->right;
    }

  if(x!=NIL)
    {
      x->parent=y->parent;
    }

  if(y->parent==NIL)
    {
      root=x;
    }
  else if(y==y->parent->left)
    {
      y->parent->left=x;
    }
  else
    {
      y->parent->right=x;
    }

  if(y!=z)
    {
      z->key=y->key;
    }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL)
    {
      y=x;
      if(z->key<x->key)
	{
	  x=x->left;
	}
      else
	{
	  x=x->right;
	}
    }
  z->parent=y;
  if(y==NIL)
    {
      root=z;
    }
  else if(z->key<y->key)
    {
      y->left=z;
    }
  else
    {
      y->right=z;
    }
}





void inorder(Node u){
  if(u->left!=NIL)
    {
      inorder(u->left);
    }
  printf(" %d",u->key);
  if(u->right!=NIL)
    {
      inorder(u->right);
    }
}
void preorder(Node u){
  printf(" %d",u->key);
   if(u->left!=NIL)
    {
      preorder(u->left);
    }
  if(u->right!=NIL)
    {
     preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <stdio.h>

void class_judge(int math, int en, int ja);

int main(void)
{
	int set, math, en, ja;
	while (1) {
		scanf("%d", &set);
		if (set == 0) {
			break;
		} else {
			for (int i = 0; i < set; i++) {
				scanf("%d %d %d", &math, &en, &ja);
				class_judge(math ,en ,ja);
			}
		}
	}
	return 0;
}

void class_judge(int math, int en, int ja)
{
	if (math == 100 || en == 100 || ja == 100) {
		printf("A\n");
	} else if ((math + en) / 2 >= 90) {
		printf("A\n");
	} else if ((math + en + ja) / 3 >= 80) {
		printf("A\n");
	} else if ((math + en + ja) / 3 >= 70) {
		printf("B\n");
	} else if ((math + en + ja) / 3 >= 50 && (math >= 80 || en >= 80)){
		printf("B\n");
	} else {
		printf("C\n");
	}
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int N, M; cin >> N >> M;
  int ans[N] = {0};
  rep(i, 2 * M) {
    int c; cin >> c;
    ans[c-1]++;
  }
  rep(i, N) {
    cout << ans[i] << endl;
  }
}

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

int main(){
	using namespace std;

	vector<string> c;
	int H,W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		string tmp;
		cin >> tmp;
		c.push_back(tmp);
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(c[i][j] == '#'){
				bool flag1 = true;
				bool flag2 = true;
				bool flag3 = true;
				bool flag4 = true;
				if(i != 0){
					if(c[i-1][j] != c[i][j]){
						flag1 = false;
					}else{
						flag1 = true;
					}
				}
				if(j != 0){
					if(c[i][j-1] != c[i][j]){
						flag2 = false;
					}else{
						flag2 = true;
					}
				}
				if(i != H-1){
					if(c[i+1][j] != c[i][j]){
						flag3 = false;
					}else{
						flag3 = true;
					}
				}
				if(j != W-2){
					if(c[i][j+1] != c[i][j]){
						flag4 = false;
					}else{
						flag4 = true;
					}
				}
				if(!flag1 && !flag2 && !flag3 && !flag4){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string r[] = {"maerd", "remaerd", "esare", "resare"};
    string s;
    cin >> s;
    
    reverse(s.begin(),s.end());    

    int itr=0;
    bool ans = true;
    while(1){
        bool ok = false;
        rep(i, 4){
            //cout << s[itr] << r[i][0] << endl;
            if (memcmp(&s[itr], &r[i][0], strlen(&r[i][0]))==0){
                //cout << itr << r[i] << endl;
                ok = true; 
                itr += strlen(&r[i][0]);
                break;
            }
        }
        if (!ok){
            ans = false;
            break;
        }

        if (itr >= s.size()) break;
    }

    if (ans) cout << "YES" << endl;
    else cout << "NO" << endl;

}



Measured memory_bytes: 512
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

class SplitStream {
	typedef basic_ostream<char, char_traits<char> > BaseOst;
	std::ostream& ost_m;
	bool line_is_empty_m;
public:
	SplitStream(std::ostream& ost);
	template <typename T>
	SplitStream& operator<<(T right);
	SplitStream& operator<<(BaseOst& (*right)(BaseOst&));
};
SplitStream::SplitStream(std::ostream& ost) : ost_m(ost), line_is_empty_m(true) {}
template <typename T>
SplitStream& SplitStream::operator<<(T right) {
	if (!line_is_empty_m) ost_m << ' ';
	line_is_empty_m = false;
	ost_m << right;
	return *this;
}
/* std::endl のみ */
SplitStream& SplitStream::operator<<(BaseOst& (*right)(BaseOst&)) {
	ost_m << '\n';
	ost_m.flush();
	line_is_empty_m = true;
	return *this;
}
SplitStream Scout(cout);

template <typename T, int Begin, int End>
class OffsetArray {
	T arr_m[End - Begin];
public:
	OffsetArray();

	T& operator[](int index);
	T operator[](int index) const;
};
template<typename T, int Begin, int End>
OffsetArray<T, Begin, End>::OffsetArray() : arr_m() {}
template<typename T, int Begin, int End>
T& OffsetArray<T, Begin, End>::operator[](int index) {
	return arr_m[index - Begin];
}
template<typename T, int Begin, int End>
T OffsetArray<T, Begin, End>::operator[](int index) const {
	return arr_m[index - Begin];
}

template<typename T, int N>
void Fill(T(&arr)[N], T val) {
	for (int i = 0; i < N; ++i) {
		Fill(arr[i], val);
	}
}
template<typename T, int M, int N>
void Fill2D(T(&arr)[M][N], T val) {
	for (int i = 0; i < M; ++i) {
		Fill(arr[i], val);
	}
}

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#endif
int N;
int A[100002];
int IN[100002];
vector<int> T[100002];
vector<PP> S;
int L[100002];

int Rec(int i) {
	vector<int> next;
	REP(k, 0, T[i].size()) {
		next.push_back(Rec(T[i][k]));
	}
	sort(next.begin(), next.end(), greater<int>());
	int M = 0;
	REP(k, 0, T[i].size()) {
		M = max(M, next[k] + k + 1);
	}
	return M;
}

int main() {
	cin >> N;
	REP(i, 2, N + 1) {
		cin >> A[i];
		T[A[i]].push_back(i);
		++IN[i];
	}
	queue<int> Q;
	Q.push(1);
	while(!Q.empty()) {
		int P = Q.front();  Q.pop();
		REP(i, 0, T[P].size()) {
			--IN[T[P][i]];
			if(IN[T[P][i]] == 0){
				Q.push(T[P][i]);
				S.push_back(PP(P, T[P][i]));
			}
		}
	}
	cout << Rec(1) << endl;
	return 0;
}



Measured memory_bytes: 17520
using System;
using System.Linq;

namespace _1072
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                if (x[0] * x[1] % 2 == 0)
                {
                    Console.WriteLine("yes");
                }
                else
                {
                    Console.WriteLine("no");
                }
            }
        }
    }
}

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

int main(void){
	int n,m;
  cin>>n>>m;
  int B[m]={},A[n][m]={};
  
  
  for (int i=0;i<n;i++){
    for (int j=0;j<m;j++){
      cin>>A[i][j];
    }
  }
  for (int j=0;j<m;j++){
    cin>>B[j];
    }

  for (int i=0;i<n;i++){
    int sum=0;
      for (int j=0;j<m;j++){
        sum+=A[i][j]*B[j];
      }
	cout<<sum<<endl;
  } 
  	return 0;
}


Measured memory_bytes: 3128
using System;
using System.Collections.Generic;

namespace ABC173
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int m = N % 1000;
            if (m == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1000 - (N % 1000));
            }
        }
    }
}


Measured memory_bytes: 27528
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

res = 0
tmp = n
for i in range(n):
    a_ = a[i]
    res += b[a_ - 1]
    if a_ == tmp + 1:
        res += c[tmp - 1]
    tmp = a_

print(res)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

// var sc = bufio.NewScanner(os.Stdin)

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

// var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

// func readLine() string {
// 	buf := make([]byte, 0, 1000000)
// 	for {
// 		l, p, e := rdr.ReadLine()
// 		if e != nil {
// 			panic(e)
// 		}
// 		buf = append(buf, l...)
// 		if !p {
// 			break
// 		}
// 	}
// 	return string(buf)
// }

func main() {
	// sc.Split(bufio.ScanWords)
	// in := strings.Split(readLine(), " ")
	// nstr, qstr := in[0], in[1]
	// n, _ := strconv.Atoi(nstr)
	// q, _ := strconv.Atoi(qstr)
	// s := readLine()
	// n := nextInt()
	// q := nextInt()
	var n, q int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&q)
	fmt.Scan(&s)

	var numAry = make([]int, n)
	ret := 0
	for i := 1; i < n; i++ {
		get := s[i-1 : i+1]
		if get == "AC" {
			ret++
		}
		numAry[i] = ret
	}

	l := make([]int, q)
	r := make([]int, q)
	for i := 0; i < q; i++ {
		// in := strings.Split(readLine(), " ")
		// lstr, rstr := in[0], in[1]
		// lq, _ := strconv.Atoi(lstr)
		// rq, _ := strconv.Atoi(rstr)
		// l[i] = nextInt()
		// r[i] = nextInt()
		fmt.Scan(&l[i])
		fmt.Scan(&r[i])
		fmt.Println(numAry[r[i]-1] - numAry[l[i]-1])
	}
}


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

using namespace std;

//int main() {
//	string t, p;
//	int tl, pl;
//	cin >> t >> p;
//	tl = t.size();
//	pl = p.size();
//	for (int i = 0; i <= tl - pl; ++i) {
//		for (int j = 0; j < pl; ++j) {
//			if (t[i + j] != p[j])
//				break;
//			if (j == pl - 1)
//				cout << i << endl;
//		}
//	}
//
//	return 0;
//}
int main() {
	string t, p;
	cin >> t >> p;
	int s = 0;
	while (1) {
		if ((s = t.find(p, s)) == string::npos)
			break;
		cout << s++ << endl;
	}

	return 0;
}


Measured memory_bytes: 3184
N = int(input())
A = list(map(int, input().split()))
for h in range(len(A)):
    if h == len(A)-1:
        print(A[h])
    else:
        print(A[h], "", end="")
def insertionSort(A, N):
    for i in range(1, N):
        temp = A[i]
        j = i -1
        while j >= 0 and temp < A[j]:
            A[j+1] = A[j]
            j -= 1
        A[j + 1] = temp
        for k in range(len(A)):
            if k == len(A)-1:
                print(A[k])
            else:
                print(A[k], "", end="")

insertionSort(A, N)


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())


template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

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

const int N = 200005;
int nxt[N];
int A[N];
int lst[N];
int fst[N];
int done[N];
int tour[N];
int nxt2[N];
int main(){
	ll k;
	int n; sd(n); scanf("%lld", &k);
	nxt[n + 1] = 1;
	for(int i = 1; i <= n; i++){
		sd(A[i]);
		if(!fst[A[i]]) fst[A[i]] = i;
	}

	for(int i = n; i >= 1; i--){
		nxt[i] = lst[A[i]] ? nxt[lst[A[i]] + 1] : fst[A[i]] + 1;
		nxt2[i] = lst[A[i]];
		lst[A[i]] = i;
	}

	int curr = 1;
	int sz = 0;
	int cyc = -1;
	while(1){
		if(!done[curr]){
			tour[++sz] = curr;
			done[curr] = sz;
		} else{
			cyc = done[curr];
			break;
		}
		curr = nxt[curr];
	}
	// trace(sz, cyc);
	// for(int j = 1; j <= sz; j++) cerr << tour[j] << " ";
	// cerr << endl;
	int pos = k <= sz ? tour[k] : tour[cyc + ((k - cyc) % (sz - cyc + 1))];
	vector<int> ele;
	int ans = 0;
	while(pos <= n){
		if(!nxt2[pos]){
			ele.push_back(A[pos]);
			pos ++;
		} else{
			pos = nxt2[pos] + 1;
		}
	}
	for(auto it : ele) printf("%d ", it);
}

Measured memory_bytes: 7924
#include<iostream>
using namespace std;
static const int MAX = 200000;
int max(int a,int b)
{
    if(a > b)
        return a;
    else
        return b;
}
int min(int a,int b)
{
    if(a > b)
        return b;
    else
        return a;
}
int main(){
    int R[MAX], n;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> R[i];
    int maxv = -2000000000;
    int minv = R[0];
    for(int i=1;i<n;i++)
    {
        maxv = max(maxv,R[i]-minv);
        minv = min(minv,R[i]);
    }
    
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3872
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: i,j,x,y,h,w
    integer(int32):: d,nx,ny,ans=0
    integer(int32), allocatable:: a(:,:),ax1(:),ay1(:),ax2(:),ay2(:)
    logical,allocatable:: pass(:,:)


    read*, h,w
    allocate(a(w,h))
    allocate(ax1(w*h), ay1(w*h), ax2(w*h), ay2(w*h))
    allocate(pass(0:w+1,0:h+1), source=.false.)
    pass(:,0) = .true.
    pass(:,h+1) = .true.
    pass(0,:) = .true.
    pass(w+1,:) = .true.

    do i=1,h
        read*, a(:,i)
    end do

    x=1; y=1; d=0

    do while(.true.)
        pass(x,y) = .true.
        if(.not. next_xy(x,y,d,nx,ny)) exit
        if (mod(a(x,y),2) == 1) then
            ans=ans+1
            ax1(ans)=x; ay1(ans)=y; ax2(ans)=nx; ay2(ans)=ny
            a(x,y)=a(x,y)-1
            a(nx,ny)=a(nx,ny)+1
        end if
        x=nx; y=ny
    end do
    print'(i0)', ans
    do i=1,ans
        print'(*(i0,1x))', ay1(i), ax1(i), ay2(i), ax2(i)
    end do

contains
    function next_xy(x,y,d,nx,ny) result(ret)
        integer(int32),intent(in):: x,y
        integer(int32),intent(out):: nx,ny
        integer(int32),intent(inout):: d
        integer(int32):: dx(0:3) = [1,0,-1,0]
        integer(int32):: dy(0:3) = [0,1,0,-1]
        integer(int32):: nd
        logical:: ret
        ret = .true.
        nd = d
        nx = x+dx(nd); ny = y+dy(nd)
        do while(pass(nx,ny))
            nd=mod(nd+1,4)
            nx=x+dx(nd); ny=y+dy(nd)
            if (nd == d) then
                ret = .false.
                return
            end if
        end do
    end function
end program main

Measured memory_bytes: 6796
#include <iostream>

using namespace std;

int main()
{
    int N, i;
    int min=0, max=0;
    int rate[100] = {0};
    int color[9] = {0};


    cin >> N;
    for(i=0; i<N; i++)
        cin >> rate[i];
    
    for(i=0; i<N; i++)
    {
        if( rate[i] >= 1 && rate[i] <= 399 )
            color[0]++; //灰色
        else if( rate[i] >= 400 && rate[i] <= 799 )
            color[1]++; //茶色
        else if( rate[i] >= 800 && rate[i] <= 1199 )
            color[2]++; //緑色
        else if( rate[i] >= 1200 && rate[i] <= 1599 )
            color[3]++; //水色
        else if( rate[i] >= 1600 && rate[i] <= 1999 )
            color[4]++; //青色
        else if( rate[i] >= 2000 && rate[i] <= 2399 )
            color[5]++; //黄色
        else if( rate[i] >= 2400 && rate[i] <= 2799 )
            color[6]++; //橙色
        else if( rate[i] >= 2800 && rate[i] <= 3199 )
            color[7]++; //赤色
        else
            color[8]++; //その他
    }

    for(i=0; i<8; i++)
    {
        if(color[i] != 0)
            min++;
    }

    if( min == 0 ) //3200未満が0人の場合
    {
        min = 1;   //3200以上が必ず1人はいる
        max = color[8];
    }
    else
    {
        if(color[8] != 0)
            max = min + color[8];
        else
            max = min;
    }

    cout << min << " " << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int f(int a, int b){
  int x;
  if (a>b) x=a-b;
  else x=b-a;
  return x;
}
int main(void) {
    int N, h[100006], i, c[100006];
    scanf("%d", &N);
    for (i=1; i<=N; i++) {
        scanf("%d", &h[i]);
    }
    h[N+1]=h[N];
    h[N+2]=h[N];
    c[1]=0;
    c[2]=f(h[1], h[2]);
    for (i=3; i<=N; i++) {
        if (c[i-1]+f(h[i], h[i-1]) <= c[i-2]+f(h[i], h[i-2])) {
          c[i]=c[i-1]+f(h[i], h[i-1]);
        }
        else {
          c[i]=c[i-2]+f(h[i], h[i-2]);
        }
    }
        printf("%d\n", c[N]);
    return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in).useDelimiter("[ .,]+");
		boolean first = true;
		while (sc.hasNext())
		{
			String str = sc.next();
			if (2 < str.length() && str.length() < 7)
			{
				if (first)
				{
					first = false;
				}
				else
				{
					System.out.print(" ");
				}
				System.out.print(str);
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 12000