akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

struct E {
    int to, co;
    E(int to=0, int co=0) : to(to), co(co){}
};

string rev(string s){
    reverse(s.begin(), s.end());
    return s;
}

int main(){
    int m;
    cin >> m;
    vector<string> s(m);
    vector<int> c(m);
    for(int i=0; i<m; ++i){
        cin >> s[i] >> c[i];
    }
    //逆もオッケー
    //これで0-mは正方向
    //m+1 - 2mは逆
    for(int i=0; i<m; ++i){
        s.push_back(rev(s[i]));
        c.push_back(c[i]);
    }

    //頂点を作る(n頂点)
    int n =1;
    //空文字列を0をする
    //各文字にidを割り当てる
    vector<vector<int>> id(m*2);
    for(int i=0; i<m*2; ++i){
        int l = s[i].size();
        id[i].resize(l);
        for(int j=0; j<l; ++j){
            id[i][j] = n++;
        }
    }

    //グラフを作る
    vector<vector<E>> g(n);
    //各suffixから遷移
    for(int i=0; i<m*2; ++i){
        int l = s[i].size();
        for(int j=0; j<l; ++j){
            //ここから遷移. j文字目以降が余ってる。
            //j=0は全部余ってるときはj=0;

            int v = id[i][j];
            for(int ni=0; ni<m*2; ++ni){
                // i/mすると前半なら0,後半なら1になる,
                //この２つが一緒なら何もしない
                if(i/m == ni/m) continue;
                //何文字で共通する?
                int nl = s[ni].size();
                int w = min(nl, l-j);
                //そもそも一致してないといけないのでその判定
                if(s[i].substr(j,w) != s[ni].substr(0, w)) continue;

                int u =0;
                //　うしろが余る条件
                if( nl > w){
                    u = id[ni][w];
                }else if(l > j+w){
                    //先頭が余る条件
                    u = id[i][j+w];
                }else{
                    //あまりなしの空文字
                    u = 0;
                }
                g[v].emplace_back(u, c[ni]);
            }
        }
    }

    //ダイクストラ
    vector<long long> dist(n, INF);
    //先頭が距離、後ろが頂点番号
    using P = pair<long long, int>;
    priority_queue<P, vector<P>, greater<P>> q;
    auto push = [&](int v, long long x){
        if(dist[v] <= x) return;
        dist[v] = x;
        q.emplace(x, v);
    };

    for(int i=0; i<m; ++i){
        push(id[i][0], c[i]);
    }

    //内部のロジック
    while(!q.empty()){
        long long x = q.top().first;
        int v = q.top().second; 
        q.pop();
        if(dist[v] != x) continue;
        for(E e : g[v]){
            push(e.to, x+e.co);
        }
    }

    long long ans = dist[0];
    for(int i=0; i<m * 2; ++i){
        int l = s[i].size();
        for(int j=0; j<l; ++j){
            string t = s[i].substr(j);
            //回文ならオッケー
            if(t == rev(t)){
                ans = min(ans, dist[id[i][j]]);
            }
        }
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3744
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            String str=sc.nextLine();
            int sum=0;
            for(int i=0;i<str.length();i++){
                String data=String.valueOf(str.charAt(i));
                sum+=Integer.parseInt(data);
            }
            if(sum==0)break;
            else System.out.println(sum);
        }
    } 
}


Measured memory_bytes: 26804
n, x, y = map(int, input().split())

cnt = [0] * (n+1)

for i in range(1, n+1):
    for j in range(i+1, n+1):
        cnt[min(j-i, abs(x-i)+abs(y-j)+1)] += 1

for i in range(1, n):
    print(cnt[i])


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

int main(){
	int m1, d1;
	int m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(d2 == 1) cout << 1 << endl;
	else cout << 0 << endl;
}

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

using namespace std;
int main() {
	int N;
	cin >> N;
	set<int>S;
	for (int n = 0;n<N;++n) {
		int num;
		cin >> num;
		S.insert(num);
	}
	if (N == S.size()) {
		cout <<"YES"<<endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 12820
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    ll res = longinf;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res = min(res, i + n / i - 2);
        }
    }
    cout << res << "\n";
}

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

using namespace std;

typedef long long ll;
const int MAX = 100005;
const int MOD = 1000000007;

#define F first
#define S second

void solve()
{
	
	return;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	vector<ll> arr(n,0);
	if(n!=1)
		arr[0]=1;
	ll flag=1;
	map<ll,ll> mp;
	for(int i=0;i<m;i++)
	{
		ll s,c;
		cin>>s>>c;
		s--;
		arr[s]=c;
		if(!mp.count(s))
			mp[s]=c;
		else
		{
			if(mp[s]!=c)
				flag=0;
		}
	}	
	if(arr[0]==0&&n!=1)
		flag=0;
	if(flag==0)
		cout<<"-1\n";
	else
	{
		ll ans=0;
		for(int i=0;i<n;i++)
		{
			ans=ans*10+arr[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll K;
    cin>>K;
    string S;
    cin>>S;
    if(S.size()<=K) cout<<S<<endl;
    else{
        string ans="";
        rep(i, K) ans+=S[i];
        cout<<ans+"..."<<endl;
    }
    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int m;
    while(cin >> m){
        int n = m%39;
        if(n == 0) cout << "3C39" << endl;
        else if(0 < n && n <= 9) cout << "3C0" << n << endl;
        else cout << "3C" << n << endl;
    }
}

Measured memory_bytes: 1160
N = int(input())
W = []
head = ''
ans = "Yes"
for i in range(N):
    W.append(input())
while len(W) != 0:
    word = W[-1]
    W.pop()
    if word in W or (head != '' and word[-1] != head):
        ans = "No"
        break
    head = word[0]
print(ans)



Measured memory_bytes: 3060
#include<stdio.h>
int main (void){
  int n,k,i,j,c,ans=0;
  int  p[1000];
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){scanf("%d",&p[i]);}
  
  for(i=0;i<n;i++){
    for(j=0;j<n-i-1;j++){
      if(p[j]>p[j+1]){
        c=p[j];
        p[j]=p[j+1];
        p[j+1]=c;}
    }
  }
  for(i=0;i<k;i++){ans=ans+p[i];}
  
  printf("%d",ans);
  
}

Measured memory_bytes: 1712
n,k,*a=map(int,open(0).read().split())
l,r,*b=[[]for _ in range(10**6)]
for i,v in enumerate(a):
  b[v]+=i,
  l+=len(b[v]),
s=a[0]
i=c=0
while 1:
  j=l[i]%len(b[s])
  if(c>k-2)>j:
    r+=s,
    i+=1
  else:i=b[s][j]+1
  c+=j<1
  if i==n:
    if c>k-2:break
    k%=c+1
    i=c=0
  s=a[i]
print(*r)

Measured memory_bytes: 105764
fun main(args: Array<String>) {
	readLine()
	val a = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
	var flag = false
	var sum = 0L
	var min = Int.MAX_VALUE
	for (v in a) {
		sum += Math.abs(v)
		if (v < 0) flag = !flag
		if (Math.abs(v) < min) min = Math.abs(v)
	}
	if (flag) sum -= 2 * min
	println(sum)
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;
  int st, ed;
  rep (i, 0, s.size()) {
    if (s[i] == 'A') {
      st = i;
      break;
    }
  }

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

  string ans = "";
  rep(i, st, ed+1) {
    ans += s[i];
  }

  cout << ans.size() << endl;

  return 0;
};


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

using namespace std;

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

    int n, k;
    cin >> k >> n;
    int a[n];
    int m = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i > 0) {
            m = max(m, a[i] - a[i - 1]);
        }
    }
    m = max(m, a[0] + k - a[n - 1]);
    cout << k - m << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
    
int main(){
    int a,b,c;
    cin >> a >> b >> c;
      
    if (a > b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    
    if (b > c){
        int tmp = b;
        b = c;
        c = tmp;
    }
    
    if (a > b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll A[202020], B[202020];
ll xA[404040], xB[404040];
ll mk[404040], mk2[404040];
ll i, j, k, ans;

//Zアルゴリズム
void Zalgo(ll N,ll *S,ll *T,ll *ln1,ll *ln2){
    ll i = 1;
    ll j = 0;
    ll k = 0;
    while(i<N){
        //printf("%lld %lld\n", i, j);
        if(i+ln2[i-j]<j+ln1[j]){
            ln1[i] = ln2[i - j];
        }else{
            k = max(j + ln1[j] - i, 0ll);
            while (i + k < N && T[k] == S[i + k])
                k++;
            ln1[i] = k;
            j = i;
        }
        i++;
    }
    fornum(i,0,N){
        if(S[i]!=T[i])
            break;
    }
    ln1[0] = i;
}


int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,N){
        scanf("%lld", &B[i]);
    }
    fornum(i,0,N){
        xA[i + N] = xA[i] = A[(i + 1) % N] ^ A[i];
        xB[i + N] = xB[i] = B[(i + 1) % N] ^ B[i];
        //printf("%lld:%lld ", xA[i], xB[i]);
    }
    //printf("a\n");
    Zalgo(N * 2, xB, xB, mk, mk);
    //printf("b\n");
    Zalgo(N * 2, xA, xB, mk2, mk);
    /*
    fornum(i,0,N){
        printf("%lld,%lld ", mk[i], mk2[i]);
    }*/

    fornum(i,0,N){
        if(mk2[i]>=N){
            printf("%lld %lld\n", i, A[i] ^ B[0]);
        }
    }

    return 0;
}

Measured memory_bytes: 19200
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
const int MX=60;
int N, M, k, x;
int arr[MX];
char g[MX][MX];
int D[MX][MX];
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
bool ch(int x, int y)
{
    return min(x, y) >=0 && x < N && y < M;
}
void bfs(int x, int y)
{
    D[x][y]=0;
    multiset<pair<int, pair<int, int> > > ms;
    ms.insert(mp(0, mp(x, y)));
    while(ms.size())
    {
        pair<int, pair<int, int> > p=*ms.begin();
        int xx=p.S.F, yy=p.S.S;
        int w=p.F;
        ms.erase(ms.begin());
        if(D[xx][yy] < w) continue;
        for(int d=3;d>=0;d--)
        {
            int xc=dx[d]+xx;
            int yc=dy[d]+yy;
            if(ch(xc, yc) == 0) continue;
            if(g[xc][yc] == '#') continue;
            if(D[xx][yy] + 1 < D[xc][yc])
            {
                D[xc][yc]=D[xx][yy]+1;
                ms.insert(mp(D[xc][yc], mp(xc, yc)));
            }
        }
    }
}
int main()
{
    cin>>N>>M;
    int B=0;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            cin>>g[i][j];
            if(g[i][j] == '#') B++;
            D[i][j]=1e8;
        }
    }
    bfs(0, 0);
    if(D[N-1][M-1] != 1e8){
        cout<<N*M-B-D[N-1][M-1]-1<<"\n";
    }
    else{
        cout<<-1<<"\n";
    }
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, K, _Q = in.next().toInt
  val Q = _Q - 1
  val A = new Array[Int](N+1)

  for(i <- 1 to N)
    A(i) = in.next().toInt

  
  //
  def calc(min: Int, ind: Int): Option[Int] = {
    var acc: List[Int] = Nil

    var l = 1; var r = 1
    while(r <= N) {
      if(A(r) < min) {
        val range =
          if (l <= ind && ind <= r - 1) r - l - 1
          else r - l
        if(range >= K) {
          val tmp: Array[Int] = A.slice(l, r).sorted
          val hoge: List[Int] =
            if (l <= ind && ind <= r - 1)
              tmp.slice(1, Math.min(Q, range - (K-1)) + 1).toList
            else
              tmp.take(Math.min(Q, (r-l) - (K-1))).toList
          acc = hoge ++ acc
        }

        r += 1
        l = r
      }
      else {
        r += 1
      }
    }

    val range =
      if (l <= ind && ind <= r - 1) r - l - 1
      else r - l
    if(range >= K) {
      val tmp: Array[Int] = A.slice(l, r).sorted
      val hoge: List[Int] =
        if (l <= ind && ind <= r - 1)
          tmp.slice(1, Math.min(Q, range - (K-1)) + 1).toList
        else
          tmp.take(Math.min(Q, (r-l) - (K-1))).toList
      acc = hoge ++ acc
    }


    //
    if(acc.length >= Q) {
      val tmp = acc.sorted.apply(Q-1)
      // println(tmp, min)
      Some(tmp - min)
    }
    else {
      None
    }
  }


  var ans = Int.MaxValue
  for(i <- 1 to N) {
    val tmp =
      if (Q == 0)
        Some(0)
      else
        calc(A(i), i)

    tmp match {
      case Some(x) => ans = Math.min(ans, x)
      case None => ()
    }
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 106400
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int l,k; cin >> l >> k;
    vector<vector<ll>> dp(l+2,vector<ll>(2,0));
    dp[0][0] = 0;
    dp[0][1] = 1;
    for(int i=1;i<=l;i++){
        // black
        dp[i][0] += dp[i-1][1];
        if(i-k>=0) dp[i][0] += dp[i-k][1];

        // white
        dp[i][1] += dp[i-1][0];
    }

    ll ans = 0;
    for(int i=0;i<=l;i++) ans += dp[i][0];
    cout << ans << endl;
}



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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e8;

//---main---------------------------------------------
int main(){
    //main
    int N,K;
    cin >> N >> K;

    int ansmin=1,ansmax=1;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
        chmax(ansmax,A[i]);
    }

    int x;
    rep(i,1000){
        x = (ansmin+ansmax)/2;
        int cut=0;
        rep(i,N){
            cut += (A[i]-1)/x;
        }
        if(cut>K) ansmin = x+1;
        else ansmax = x;
    }
    
    cout << ansmin << endl;


    return 0;
}

Measured memory_bytes: 3964
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()

lis = [0]*N

for i in range(N-1):
	if S[i] == "A" and S[i+1] == "C":
		lis[i+1] = 1

lis_acc = list(accumulate(lis))

for _ in range(Q):
	l, r = MAP()
	print(lis_acc[r-1] - lis_acc[l-1])


Measured memory_bytes: 10976
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int t;
    int n;
    cin>>n;
    long long int ans=1;
    double a=0;
    for(int i=0;i<n;i++) cin>>t,ans=ans*t,a=a+(log(t)*1.0/log(10));
   // cout<<a;
    if(a>18 || ans>1000000000000000000ll) cout<<-1;
    else cout<<ans;
    cout<<endl;
    return 0;

}

Measured memory_bytes: 3876
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<tgmath.h>
#include<stdlib.h>
#include<assert.h>
#include<stdio.h>



#define ll long long


/*
_
_._ _..._ . - ',     _.._(`))
'-. `     ' / -._. - '    ', /
)         \            '.
/ _    _ | \
| a    a    /              |
\   . - .;
'-('' ).-', '       ;
'-;           |      .'
\           \    /
| 7.__  _. - \   \
| |  |  ``/ / `  /
/, _|  |   /, _/   /
/, _ / '`-'
*/
using namespace std;

int bin_search(int ele, vector<pair<int,int> > arr)
{
    int l = 0, r = arr.size()-1 , mid=0;
    while (l <= r) {
        mid = l + (r - l) / 2;
        if (arr[mid].first == ele) {
            return arr[mid].second;
        }
        else if (arr[mid].first > ele) {
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    return mid;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > arr(m);
    int i;
    vector<int> num(n,-1);
    bool flag = true;
    for (i = 0; i < m; ++i) {
        cin >> arr[i].first >> arr[i].second;
        if (arr[i].first > n) {
            flag = false;
        }
        if (arr[i].first == 1 && arr[i].second == 0 && n!=1) {
            flag = false;
        }
        if (arr[i].first <= n && num[arr[i].first - 1] == -1) {
            num[arr[i].first - 1] = arr[i].second;
        }
        else if (arr[i].first <= n && num[arr[i].first - 1] != arr[i].second) {
            flag = false;
        }
    }
    if (!flag) {
        cout << "-1";
        return 0;
    }
    if (n == 1 && m == 0) {
        cout << 0;
        return 0;
    }
    if (num[0] == -1) {
        num[0] = 1;
    }
    for (i = 1; i < n; ++i) {
        if (num[i] == -1) {
            num[i] = 0;
        }
    }
    for (i = 0; i < n; ++i) {
        cout << num[i];
    }
    
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int digits(ll n){
	int res = 0;
	while(n > 0){
		n /= 10;
		res++;
	}
	return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> comb(10, vector<int>(10, 0));
    for(int i = 1; i <= n; i++){
        int head = i;
        int tail = i%10;
        while(head >= 10){
            head /= 10;
        }
        ++comb[head][tail];
    }
    ll ans = 0;
    rep(i,10)rep(j,10){
        ans += comb[i][j] * comb[j][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
using namespace std;
int main(){
	double m,k;
	while(cin>>m>>k){
		if(m<35.5&&k<71.0)
			cout<<"AAA"<<endl;
		else if(m<37.5&&k<77.0)
			cout<<"AA"<<endl;
		else if(m<40.0&&k<83.0)
			cout<<"A"<<endl;
		else if(m<43.0&&k<89.0)
			cout<<"B"<<endl;
		else if(m<50.0&&k<105.0)
			cout<<"C"<<endl;
		else if(m<55.0&&k<116.0)
			cout<<"D"<<endl;
		else if(m<70.0&&k<148.0)
			cout<<"E"<<endl;
		else cout<<"NA"<<endl;
	}
}

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

int main() {
    int N; cin >> N;
    map<string,ll> ans;
    rep(i,N) {
        string S; cin >> S;
        sort(S.begin(),S.end());
        if(ans.count(S)) {
            ans[S]++;
        } else {
            ans[S] = 1;
        }
    }
    ll count = 0;
    for(auto res:ans) {
        //cout << res.first << " " << res.second << endl;
        if(res.second != 1)
            count += (res.second-1) * res.second/2;
    }
    cout << count << endl;
}

Measured memory_bytes: 11136
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
        int d = sc.nextInt();
        String ans = "";
        
        if (Math.abs(a - c) <= d) {
          ans = "Yes";
        } else {
          ans = Math.abs(a - b) <= d && Math.abs(b - c) <= d ? "Yes" : "No";
        }
    
		// 出力
		System.out.println(ans);
	}
}


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

string s;
int q;
vector<string> a = {"dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"};

void pei(int x){
  if(s.size() > x){
    for(int i = 0; i < 6; i++){
      int y = a[i].size();
      if(s.substr(x, y) == a[i]){
        pei(x + y);
        return;
      }else if(i == 5){
        q = 1;
        return;
      }
    }
  }else{
    if(s.size() != x){q = 1;}
    return;
  }
}

int main(){
  cin >> s;
  q = 0;
  pei(0);
  if(q == 0){cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  return 0;
}


Measured memory_bytes: 1920
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
v = 1

if min(a) == 0:
  print(0)
else:
  for i in a:
    v *= i
    if v > 1000000000000000000:
      print(-1)
      break
  else:
    print(v)

Measured memory_bytes: 20088
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double x1, y1, x2, y2, x3, y3, px, py, r;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    py = ((x3 - x1) * (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) - (x2 - x1) * (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3)) /
         (2 * (x3 - x1) * (y1 - y2) - 2 * (x2 - x1) * (y1 - y3));
    if (x2 - x1 != 0) {
      px = (2 * (y1 - y2) * py - x1 * x1 - y1 * y1 + x2 * x2 + y2 * y2) / (2 * (x2 - x1));
    } else {
      px = (2 * (y1 - y3) * py - x1 * x1 - y1 * y1 + x3 * x3 + y3 * y3) / (2 * (x3 - x1));
    }
    r = sqrt((px - x1) * (px - x1) + (py - y1) * (py - y1));
    cout << fixed << setprecision(3) << px << " " << py << " " << r << endl;
  }
  return 0;
}


Measured memory_bytes: 3208
H,W= map(int,input().split())
le = [input() for i in range(H)]
answer = [['0' for i in range(W)] for j in range(H)]

for i in range(0,H):
    for j in range(0,W):
        count=0

        if le[i][j]=='#':
            answer[i][j]='#'
            continue

        if (i!=H-1):
            if(le[i+1][j]=='#'):
                count+=1

            if (j!=W-1):
                if(le[i+1][j+1]=='#'):
                    count+=1

            if (j!=0):
                if(le[i+1][j-1]=='#'):
                    count+=1


        if (i!=0):
            if(le[i-1][j]=='#'):
                count+=1
            if (j!=W-1):
                if(le[i-1][j+1]=='#'):
                    count+=1

            if (j!=0):
                if(le[i-1][j-1]=='#'):
                    count+=1


        if (j!=W-1):
            if(le[i][j+1]=='#'):
                count+=1

        if (j!=0):
            if(le[i][j-1]=='#'):
                count+=1

        answer[i][j]=str(count)


for i in range(0,H):
    aaa=''
    for j in range(0,W):
        aaa+=answer[i][j]
    print(aaa)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
	int n;
	long long ans = 0, ret = 99999999999999999LL;
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	for(int i=-100; i<=100; i++)
	{
		ans = 0;
		for(int j=1; j<=n; j++)
			ans += (long long)(a[j]-i) * (long long)(a[j]-i);
		ret = min(ret, ans);
	}
	printf("%d", ret);
}

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

int main(){
        int n,a,b;
        int cnt=0;
        cin>>n;
        
        for(int i=0;i<n;i++){
                cin>>a>>b;
                if(a==b){
                        cnt++;
                }else{
                        cnt=0;
                }
                if(cnt==3){
                        cout<<"Yes"<<endl;
                        return 0;
                }
                
        }
        cout<<"No"<<endl;
        return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string N;
    cin >> N;
    ll S = 0;
    rep(i, N.size()) {
        S += N[i] - 0x30;
    }
    if (S % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(){
	int a[5];
	for(int i=0; i<5; ++i){
		cin >> a[i];
	}

	sort(a, a+5, greater<int>());

	for(int i=0; i<5; ++i){
		if(i == 4){
			cout << a[i] << endl;
			break;
		}
		cout << a[i] << " ";;
	}

    return 0;
}

Measured memory_bytes: 1176
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
int MOD = 1000000007;

using namespace std;

vector<vector<pair<int,int>>> P(100001);
int used[100001] = {0};
int d[100001];
int ans = 1;

int dfs(int now){
    if(used[now] == 1) return 0;

    used[now] = 1;
    for(auto x : P[now]){
        if(d[x.fi] == INF){
            d[x.fi] = d[now] + x.se; dfs(x.fi);
        }else if(d[x.fi] != d[now] + x.se){
                ans = 0;
        }     
    }

}

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

    REP(i,100001) d[i] = INF;

    REP(i,m){
        int a,b,c;
        cin >> a >> b >> c;

        P[a].pb(MP(b,c));
        P[b].pb(MP(a,-1*c));
    }

    for(int i = 1; i <= n;i++){
        if(used[i] == 1 || P[i].size() == 0){

        }else{
            d[i] = 0;
            dfs(i);
        }
    }

    if(ans == 1) cout << "Yes" << endl;
    else cout << "No" << endl;



    return 0;
}
//g++ -std=c++14 code1.cpp

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

int main(){
    int Q;
    cin >> Q;
    while(Q--){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x = (c+1)/2 - a/2;
        int y = d/2 - (b-1)/2;
        cout << (c-a+1)*(d-b+1) - x*y << endl;
    }
}



Measured memory_bytes: 3112
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = Integer.parseInt(in.next());
        int b = Integer.parseInt(in.next());
        if (a * b % 2 == 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc =new Scanner(System.in);
		String s = sc.nextLine();
		
		int l = s.length();
		char[] c= s.toCharArray();
		int[] num = new int[l];
		for(int i=0;i<l;i++) {
			if(c[i]!='?') {
				num[i]=(int)c[i]-48;
			}
			else {
				num[i]=-1;
			}
		}
		
		
		long dp[][]=new long[l+1][13];//dp[i][j]=下からi桁まで考えて、あまりがjの場合の数
		int tmp;
		int mod[]={4,1,10,9,12,3};
		if(num[l-1]!=-1) {
			dp[1][num[l-1]]=1;
		}
		else {
			for(int j=0;j<=9;j++) {
				dp[1][j]=1;
			}
		}
		
		for(int i=2;i<=l;i++) {
			if(num[l-i]!=-1) {
				tmp=(num[l-i]*mod[i%6])%13;
				for(int j=0;j<13;j++) {
					dp[i][(j+tmp)%13]=dp[i-1][j];
				}
			}
			else{
				tmp = mod[i%6]%13;
				for(int j=0;j<13;j++) {
					for(int k=0;k<=9;k++) {
						dp[i][(j+tmp*k)%13]+=dp[i-1][j];
					}
				}
				for(int j=0;j<13;j++) {
					dp[i][j]=dp[i][j]%((int)Math.pow(10, 9)+7);
				}
				
			}

			
		}
		
		
		System.out.println(dp[l][5]);


}
	
	
	
}





Measured memory_bytes: 38992
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    n <- readLn
    a <- readLn
    -- 出力
    putStrLn $ show $ n ^ 2 - a


Measured memory_bytes: 508
from collections import deque

S = input().split()
dq = deque()

for i in range(len(S)):
    if S[i] == '+':
        a = dq.pop()
        b = dq.pop()
        dq.append(b+a)
    elif S[i] == '-':
        a = dq.pop()
        b = dq.pop()
        dq.append(b-a)
    elif S[i] == '*':
        a = dq.pop()
        b = dq.pop()
        dq.append(b*a)
    else:
        dq.append(int(S[i]))

print(dq[0]) 

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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long x = Math.abs(in.nextLong());
        long k = in.nextLong();
        long d = in.nextLong();

        long ans;
        if (x / d >= k) {
            ans = x - k * d;
        }
        else {
            k -= x / d;
            if (k % 2 == 0) {
                ans = x % d;
            }
            else {
                ans = Math.abs(d - (x % d));
            }
        }

        out.println(ans);
        out.close();

    }


    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
            st = new StringTokenizer("");
        }
        public String next() throws IOException {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            else
                st = new StringTokenizer(br.readLine());
            return next();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public String nextLine() throws IOException {
            if (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
                return nextLine();
            }

            String ret = "";
            while (st.hasMoreTokens()) {
                ret += st.nextToken();
            }
            return ret;
        }
        public int[] nextIntArr(int size) throws IOException {
            int[] arr = new int[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
        public long[] nextLongArr(int size) throws IOException {
            long[] arr = new long[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
        public double[] nextDoubleArr(int size) throws IOException {
            double[] arr = new double[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 32916
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

int main() {
   int a[3],k;
   rep(i,3)
   cin >> a[i];
   cin >> k;
   sort(a,a+3,greater<int>());
   rep(i,k){
      a[0]*=2;
   }
   cout << a[0]+a[1]+a[2] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String[] LVstr = new String[N];
		Long ans = (long) 1;
		Long limit = (long) Math.pow(10,18);
      
      	for(int i=0; i<N; i++){
			LVstr[i] = sc.next();
          	if(LVstr[i].equals("0")){
             	System.out.println("0");
				return;
            }
		}

		for(int i=0; i<N; i++){
          	if(LVstr[i].length()>19){
             	System.out.println("-1");
				return;
            }
			try{
				Long tmp = Long.valueOf(LVstr[i]);
				Long tmpLimit = (long) Math.floor(limit/ans);
				if(tmp>tmpLimit){
					System.out.println("-1");
					return;
				}
				ans *= tmp;
			}catch(Exception e){
				ans = (long) -1;
			}finally{
				if(ans==-1){
					System.out.println("-1");
					return;
				}
			}
		}
		System.out.println(ans);
		return;
	}
}

Measured memory_bytes: 65080
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

long long maxv(long long t)
{
    if (t < 0)
    {
        return 0;
    }
    else
    {
        return t;
    }
}

int main(void)
{
    long long a, b, x;
    cin >> a >> b >> x;

    long long ans;
    ans = b / x - maxv(a - 1) / x;
    if (a == 0)
        ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s;
    cin >> s;
    bool flg = true;
    for( int i = 0; i < s.size(); ++i ) {
        if( i % 2 == 0 ) {
            if( s[i] == 'L' ) flg = false;

        } else {
            if( s[i] == 'R' ) flg = false;

        }
    }

    if( flg ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public 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 X = sc.nextInt();
		int ans = 0;

		for(int i = 0; i <= A; i++) {
			if(500 * i > X) {
				break;
			}
			for(int j = 0; j <= B; j++) {
				for(int k = 0; k <= C; k++) {
					if(500 * i + 100 * j + 50 * k == X) {
						ans++;
					}
				}
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

// int dp[110][5][5][5];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<vector<vector<vector<int>>>> dp(110,vector<vector<vector<int>>>(4,vector<vector<int>>(4,vector<int>(4))));
	dp[0][3][3][3]=1;
	rep(i,n){
		rep(j,4){
			rep(k,4){
				rep(l,4){
					if(dp[i][j][k][l]==0) continue;
					rep(a,4){
						if(a==2 && j==1 && k==0) continue;
						if(a==2 && j==0 && k==1) continue;
						if(a==1 && j==2 && k==0) continue;
						if(a==2 && j==1 && l==0) continue;
						if(a==2 && k==1 && l==0) continue;
						dp[i+1][a][j][k]+=dp[i][j][k][l];
						dp[i+1][a][j][k]%=mod;
					}
				}
			}
		}
	}
	ll ans=0;
	rep(i,4){
		rep(j,4){
			rep(k,4){
				ans+=dp[n][i][j][k];
				ans%=mod;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
N=int(input())
AB=[list(map(int, input().split())) for _ in range(N)]
time=0
AB.sort(key=lambda x:x[1])
ans="Yes"
for i in range(N):
  A, B=map(int, AB[i])
  if time+A>B:
    ans="No"
    break
  time+=A
print(ans)

Measured memory_bytes: 53660
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<21)
#define white 0
#define gray 1
#define black 2

int n;
int W[100][100];
int color[100],d[100],p[100];

int prim() {

  d[0] = 0;

  while(true) {
    int mini = INF,u;
    for(int i = 0;i < n;i++) {
      if(d[i] < mini && color[i] != black) {
        mini = d[i];
        u = i;
      }
    }

    

    if(mini == INF) break;
    color[u] = black;

    for(int i = 0;i < n;i++) {
      if(color[i] != black && W[u][i] != -1) {
        if(W[u][i] < d[i]) {
          d[i] = W[u][i];
          p[i] = u;
        }
      }
    }
  }

  int sum = 0;
  for(int i = 0;i < n;i++) {
    if(p[i] != -1) sum += W[i][p[i]];
  }
 
  return sum;

}


int main() {

  cin >> n;

  for(int i = 0;i < n;i++) {
    color[i] = white;
    d[i] = INF;
    p[i] = -1;
    for(int j = 0;j < n;j++) {
      int a;
      cin >> a;
      W[i][j] = a;
    }
  }

 
    cout << prim() << endl;

}




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

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()
#include <unordered_set>
/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */
constexpr ll MOD = ll(1e9 + 7);
int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll N, M; cin >> N >> M;
	unordered_set<ll> cannot;
	vector<ll> A(M); 
	FOR(i, M) {
		cin >> A[i];
		cannot.insert(A[i]);

	}

	
	vector<ll> dp(N + 1, 0);
	// 0, 1, 2, 3, .. N
	dp[0] = 1;
	FOR(_i, N) {
		auto i = _i + 1; // 1 ... Nまで
		if (i - 1 >= 0 && (!cannot.count(i-1)) )
			(dp[i] += dp[i - 1]) %= MOD;
		if (i - 2 >= 0 && (!cannot.count(i - 2)))
			(dp[i] += dp[i - 2]) %= MOD;
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 5924