akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const ll mod=1e9+7;
ll dp[maxn];
ll vis[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    while(m--){
        int a;
        cin>>a;
        vis[a]=1;
    }
    dp[0]=1;
    dp[1]=!vis[1]?1:0;
    dp[2]=!vis[2]?(dp[1]+dp[0]):0;
    for(int i=3;i<=n;++i){
        dp[i]=!vis[i]?((dp[i-1]+dp[i-2])%mod):0;
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{

    int n,k,c=0,i;
    scanf("%d%d",&n,&k);
    int h[n];
    for(i=0;i<n;i++)
    {
    scanf("%d",&h[i]);
    if(h[i]>=k)
    {
        c++;
    }
    }printf("%d",c);
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x=0;
    if(n<=1000)
        x=1000;
    else if(n>1000 && n<=2000)
        x=2000;
    else if(n>2000 && n<=3000)
        x=3000;
    else if(n>3000 && n<=4000)
        x=4000;
    else if(n>4000 && n<=5000)
        x=5000;
    else if(n>5000 && n<=6000)
        x=6000;
    else if(n>6000 && n<=7000)
        x=7000;
    else if(n>7000 && n<=8000)
        x=8000;
    else if(n>8000 && n<=9000)
        x=9000;
    else if(n>9000)
    x=10000;
        cout<<x-n<<endl;
}

Measured memory_bytes: 3584
# coding: utf-8
# Your code here!
num = int(input())
grid = [int(item ) for item in input().split()]

cnt = 0


def chk(line, pos):
    if pos == num-1:
        return False
    elif line[pos] >= line[pos + 1]:
        return True
    else:
        return False


cnt = 0
cnt_list = [0]
for i, h in enumerate(grid):
    if i == num-1:
        cnt = 0   
    elif chk(grid, i):
        cnt +=1
        cnt_list.append(cnt)
    else:
        cnt = 0

print(max(cnt_list))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

int n;
double prob[3001];
double dp[3001][3001];

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> prob[i];
    }

    dp[0][0] = 1;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            if(j)
            {
                dp[i][j] = dp[i-1][j-1] * prob[i] + dp[i-1][j] * (1-prob[i]);
            }
            else
            {
                dp[i][j] = dp[i-1][j] * (1-prob[i]);
            }
        }
    }

    double ans = 0;
    for(int i = (n+1)/2; i <= n; i++)
    {
        ans += dp[n][i];
    }
    cout << setprecision(9);
    cout << ans << endl;
    return 0;
}

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


int main() 
{ 

	ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a,n;
    double ans;
    cin>>n;
    rep(i,1,n)
    {
    	cin>>a;
    	ans += (double)1/a;
    }
    ans=1/ans;
    cout << setprecision(16) << ans << endl;
} 


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

vector<int> primes;
bool used[(int)1e6+1];

void search() {
  used[0] = true;
  used[1] = true;
  for (int i=2; i<=1e6; i++) {
    if (used[i]) {
      continue;
    }
    primes.push_back(i);
    for (int j=i; j<=1e6; j+=i) {
      used[j] = true;
    }
  }
}
int main() {
  int x;
  cin>>x;
  search();
  auto it = lower_bound(primes.begin(), primes.end(), x);
  cout<<*it<<endl;
}

Measured memory_bytes: 1916
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();

	for(int cnt = 1; cnt <= n; ++cnt) {
		int rem = n - 100 * cnt;

		if(rem >= 0 && rem <= 5 * cnt) {
			cout << "1\n";
			return;
		}
	}

	cout << "0\n";
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;


typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


// ¹öª¢çÈ¢ê
vector<Weight> dijkstra2(const Graph &g, int s) {
  int n = g.size();
  vector<Weight> dist(n, INF);
  dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return dist;
}

int main() {
  int n, m;
  while(cin>>n>>m,n||m) {
    Graph g1(m), g2(m);
    REP(i,n) {
      int a, b, cost, time;
      cin >> a>> b >> cost >> time;
      a--;b--;
      g1[a].push_back(Edge(a,b,cost));
      g1[b].push_back(Edge(b,a,cost));
      g2[a].push_back(Edge(a,b,time));
      g2[b].push_back(Edge(b,a,time));
    }
    int k;
    cin >> k;
    REP(i,k) {
      int p,q,r;
      cin >> p >> q >> r;
      p--;q--;
      vector<Weight> dist;
      if (r == 0) {
        dist = dijkstra2(g1, p);
      } else {
        dist = dijkstra2(g2, p);
      }
      cout << dist[q] << endl;
    }
  }
}

Measured memory_bytes: 1088
import bisect,collections,copy,heapq,itertools,math,string
import sys
from decimal import Decimal
def S(): return sys.stdin.readline().rstrip()
def M(): return map(Decimal,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b = M()
ab = a*b
print(math.floor(ab))

Measured memory_bytes: 77460
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n];
    if(k>=n-1)
    {
        cout<<a[n-1] - a[0];
    }
    else
    {
        dp[0] = 0;
        for(int i=1;i<=k;i++)
        {
            int min_till = INT_MAX;
            for(int j=i-1;j>=0;j--)
            {
                int x = abs(a[i]-a[j]) + dp[j];
                min_till = min(min_till,x);
            }
            dp[i] = min_till;
        }
        for(int i=k+1;i<n;i++)
        {
            int min_till = INT_MAX;
            for(int j=i-1;j>=i-k;j--)
            {
                int x = abs(a[i]-a[j]) + dp[j];
                min_till = min(min_till,x);
            }
            dp[i] = min_till;
        }
        cout<<dp[n-1];
    }
    
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int md=1000000007;

int fac[8009],inv[8009];
int f[4005][4005];
int a[200005];
int b[200005];
int ans,n;

inline long long qpow(long long a,int b)
{
    long long ret=1;
    while(b)
    {
        if(b&1)
            ret=ret*a%md;
        a=a*a%md;
        b>>=1;
    }
    return ret;
}

inline int c(int n,int m)
{
    return 1ll*fac[n]*inv[m]%md*inv[n-m]%md;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",a+i,b+i);
        f[2001-a[i]][2001-b[i]]++;
    }

    for(int i=1;i<4002;i++)
        for(int j=1;j<4002;j++)
            f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%md;   

    fac[0]=1;
    for(int i=1;i<=8002;i++)
        fac[i]=1ll*fac[i-1]*i%md;
    inv[8002]=qpow(fac[8002],md-2);
    for(int i=8001;i>=0;i--)
        inv[i]=1ll*inv[i+1]*(i+1)%md;

    for(int i=0;i<n;i++)
        ans=(ans+f[2001+a[i]][2001+b[i]])%md;
    for(int i=0;i<n;i++)
        ans=((ans-c((a[i]+b[i])<<1,b[i]<<1))%md+md)%md;

    ans=(500000004ll*ans)%md;
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 64512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	D, _ := strconv.Atoi(sc.Text())

	X := make([][]int, N)
	for i := 0; i < N; i++ {
		X[i] = make([]int, D)
	}

	for i := 0; i < N; i++ {
		for j := 0; j < D; j++ {
			sc.Scan()
			X[i][j], _ = strconv.Atoi(sc.Text())
		}
	}

	pows := make([]int, 0)
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			var tmp int
			for d := 0; d < D; d++ {
				tmp += pow(X[i][d]-X[j][d], 2)
			}

			pows = append(pows, tmp)
		}
	}
	fmt.Println(powsNum(pows))
}

func pow(n, m int) (result int) {
	result = 1
	for i := 0; i < m; i++ {
		result *= n
	}
	return
}

func powsNum(x []int) int {
	sort.Ints(x)
	cur := 0
	count := 0
	now := 0
	for x[len(x)-1] >= cur*cur {
		pCur := cur * cur
		for i := now; i < len(x); i++ {
			if x[i] > pCur {
				now = i
				break
			} else if x[i] == pCur {
				count++
			}
		}
		cur++
	}
	return count
}


Measured memory_bytes: 640
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
r, d, x = map(int, input().split())
for i in range(10):
    x = r*x - d
    print(x)


Measured memory_bytes: 5048
# -*- coding: utf-8 -*-
import sys
import itertools
import math
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    L = list()
    for i in range(N):
        L.append(lmi())
    ans = 0.0
    for l in itertools.permutations(L, N):
        for i in range(N - 1):
            ans += math.sqrt((l[i + 1][0] - l[i][0])**2 + (l[i + 1][1] - l[i][1])**2)
    print(ans / math.factorial(N))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],dp[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],b[a[i]]=i,dp[i]=1;
    for(int i=1;i<=n;i++)
        if(b[a[i]-1]<i) dp[i]=dp[b[a[i]-1]]+1;
    int maxx=0;
    for(int i=1;i<=n;i++)
        maxx=max(maxx,dp[i]);
    cout<<n-maxx<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    int n,d;
    double x,y;
    int ans=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a,b,c;
  cin >>a>>b>>c;
  int t = b+c;
  int v = c-a-b;
  if(a+b<c){
    cout << t-v+1 << endl;
  }
  else{
    cout << t << endl;
  }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> s;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(s[0] == s[1] || s[2] == s[1] || s[2] == s[3]) anss = "Bad";
  else anss = "Good";

  cout << anss << endl;

}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  let n = lines[0] - 0;
  let ns = lines[1].split(" ").map(Number);
  let count = 0;
  let flag = true;
  while (flag) {
    flag = false;
    for (let j = n - 1; j >= 1; j--) {
      if (ns[j] < ns[j - 1]) {
        const t = ns[j];
        ns[j] = ns[j - 1];
        ns[j - 1] = t;
        count++;
        flag = true;
      }
    }
  }
  console.log(ns.join(" "));
  console.log(count);
});



Measured memory_bytes: 16532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int > pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 7;

ll fac[MAXN];
ll inv(ll x){
    return qpow(x, mod-2, mod);
}
ll cal(int n, int m){
    if(m > n)   return 0;
    return fac[n]*inv(fac[m])%mod*inv(fac[n-m])%mod;
}
int main(){
    fac[0] = 1;
    for(int i = 1; i <= 200000; ++i){
        fac[i] = fac[i-1] * i;
        fac[i] %= mod;
    }
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= k; ++i){
        ll res = 1;
        res *= cal(k-1, i-1);
        res %= mod;
        res *= cal(n-k+1, i);
        res %= mod;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k]) ** 2
        dis = dis ** (1/2)
        if dis.is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
   int n;
   cin>>n;
   int a[n+1],x[n+1],y[n+1];
   for(int i=1;i<n+1;i++){
       cin>>a[i]>>x[i]>>y[i];
   }
   a[0]=0,x[0]=0,y[0]=0;
   int b;
   for(int i=0;i<n;i++){
       b=abs(y[i+1]-y[i]+x[i+1]-x[i]);
       if(b>abs(a[i+1]-a[i])){
           cout<<"No"<<endl;
           return 0;
       }
       else{
           if((abs(a[i+1]-a[i])-b)%2==1){
               cout<<"No"<<endl;
               return 0;
           }
       }
   }
   cout<<"Yes"<<endl;
}


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

int main() {
	int n1, n2, n3, n4;
	cin >> n1 >> n2 >> n3 >> n4;
	string judge = "NO";

	if (n1 != n2 && n2 != n3 && n3 != n4) {
		if (n1 == 1 || n1 == 9 || n1 == 7 || n1 == 4) {
			if (n2 == 1 || n2 == 9 || n2 == 7 || n2 == 4) {
				if (n3 == 1 || n3 == 9 || n3 == 7 || n3 == 4) {
					if (n4 == 1 || n4 == 9 || n4 == 7 || n4 == 4) {
						judge = "YES";
					}
				}
			}
		}
	}
	
	cout << judge << endl;

	return 0;
}

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

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int h[100];
    for(int i=0;i<n;i++){
      cin>>h[i];
    }
    int m;
    cin>>m;
    vector<pair<int,int> > s[2];
    bool f=false;
    while(m--){
      int m,d;
      char t[7];
      cin.ignore(17,' ')>>m>>t>>d;
      s[t[0]=='S'].push_back(make_pair(m,d));
      f|=m==0&&d;
    }
    long long as[2][100001]={};
    for(int i=0;i<2;i++){
      for(int j=0;j<s[i].size();j++){
	for(int k=0;k+s[i][j].first<=100000;k++){
	  as[i][k+s[i][j].first]=max(as[i][k+s[i][j].first],as[i][k]+s[i][j].second);
	}
      }
    }
    long long mp=1LL<<62;
    for(int i=0;i<mp;i++){
      long long cm=i;
      for(int j=0;j<n;j++){
	cm+=lower_bound(as[1],as[2],h[j]-as[0][i])-as[1];
      }
      mp=min(mp,cm);
    }
    cout<<(f?0:mp)<<endl;
  }
  return 0;
}

Measured memory_bytes: 2768
char buf[1800000],f[5];
sz,osz;
#define rd(x)x=0;for(;;){k=buf[sz++];if(k<'0')break;x=x*10+k-'0';}
N,M,L,Q;
D[301][301];
i,j,k;
a,b,c;
main()
{
	read(0,buf,1800000);
	rd(N);rd(M);rd(L);
	for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=1000000001;
	for(i=0;i<M;i++)
	{
		rd(a);rd(b);rd(c);
		--a;
		--b;
		D[a][b]=D[b][a]=c;
	}
	for(k=0;k<N;++k)for(i=0;i<N;++i)for(j=0;j<N;++j)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	for(i=0;i<N;++i)for(j=0;j<N;++j)D[i][j]=D[i][j]>L?1000000000:1;
	for(k=0;k<N;++k)for(i=0;i<N;++i)for(j=0;j<N;++j)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	rd(Q);
	for(i=0;i<Q;++i)
	{
		rd(a);rd(b);
		--a;
		--b;
		if(D[a][b]<1000000000)
		{
			c=D[a][b]-1;
			k=0;
			do{
				f[k++]=c%10+'0';
				c/=10;
			}while(c);
			for(;k--;)buf[osz++]=f[k];
		}
		else buf[osz++]='-',buf[osz++]='1';
		buf[osz++]='\n';
	}
	write(1,buf,osz);
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[100010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    rep(i, N - 1) {
        if(S[i] == 'A' && S[i + 1] == 'C') sum[i + 1]++;
    }
    rep(i, N + 1) sum[i + 1] += sum[i];
    while(Q--) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << sum[r] - sum[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 1488
def cul(A,OP,B):
    A = int(A)
    B = int(B)
    if OP == '+':
        return A+B
    elif OP == '-':
        return A-B
    elif OP == '*':
        return A*B
    else:
        return A//B
a,op,b = input().split()
while op != '?':
    print(cul(a,op,b))
    a,op,b = input().split()



Measured memory_bytes: 5600
def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)
 
def lcm(a, b):
    return a // gcd(a, b) * b

a, b, c, d = list(map(int,input().split(" ")))

n = b - a + 1
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//lcm(c,d) - (a-1)//lcm(c,d)

print(n - n_c - n_d + n_cd)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://arc062.contest.atcoder.jp/tasks/arc062_a>
 問題文============================================================
 シカのAtCoDeerくんは選挙速報を見ています。選挙には二人の候補高橋くんと青木くんが出ています。
 速報では、現在の二人の得票数の比が表示されていますが、得票数そのものは表示されていません。
 AtCoDeerくんは N 回画面を見て、 i(1≦i≦N) 回目に見たときに表示されている比は Ti:Ai でした。
 ここで、
 AtCoDeerくんが選挙速報の画面を1回目に見た段階で既にどちらの候補にも少なくとも一票は入っていたことがわかっています。
 N 回目に画面を見たときの投票数(二人の得票数の和)として考えられるもののうち最小となるものを求めてください。
 ただし、得票数が途中で減ることはありません。
 =================================================================
 
 解説=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> T(N),A(N);
    ll t = 1, a = 1;
    for(int i = 0; i < N;i++) cin >> T[i] >> A[i];
    for(int i = 0; i < N;i++){
        ll mul = max((t+T[i]-1)/T[i],(a+A[i]-1)/A[i]);
        t = mul*T[i];
        a = mul*A[i];
    }
    cout << t + a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e17
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

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


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a,b,a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,n,m,m1,m2,n1,n2,o,p1,p2,p3,p4,
q1,q2,q3,q4,r,s,t,x,y,z,sum,mn,flg,flg1,flg2,id1,id2,id3,lim,cost;
void solve(){
    c=100;cost=0;
    while(c<n){
        c=c+(c/100);
        cost++;
    }
    printf("%lld\n",cost );
}
int main()
{
    scanf("%lld",&n);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3840
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            var s = Math.Sqrt(N);
            long minMove = long.MaxValue;

            for (long i = 1; i <= s; i++)
            {
                if (N % i == 0)
                {
                    var move = i + (N / i);
                    if (minMove > move)
                        minMove = move;
                }
            }
            Console.WriteLine(minMove-2);
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#define N 101
#define INF 2001
#define WHITE 0
#define BLACK -1

main(){
  int n, i, j, u, v, min, weight;
  int graph[N][N], color[N], d[N];
  
  scanf("%d", &n);
  
  for( i = 1; i <= n; i++){
    d[i] = INF;
    color[i] = WHITE;
    for( j = 1; j <= n; j++){
      scanf("%d", &graph[i][j]);
    }
  }
  
  weight = 0;
  d[1] = 0;
  while(1){
    min = INF;
    
    for( i = 1; i <= n; i++){
      if( color[i] != BLACK && d[i] < min ){
	min = d[i];
	u = i;
      }
    }
     
    if( min == INF )
      break;

    for( v = 1; v <= n; v++){
      if( graph[u][v] != -1 ){
	if( color[v] != BLACK && graph[u][v] < d[v] ){
	  d[v] = graph[u][v];
	}
      }
    }
    
    color[u] = BLACK;
    
  }
  
  for( i = 1; i <= n; i++){
    weight += d[i];
  }
  
  printf("%d\n", weight);
  
  return 0;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef complex<double> P;
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L() {}
};

// dp[S][i][j] = üªWSðÊÁÄ¨èA»ÝüªiÌj¤É¢éÆ«ÌÅ¬l
double dp[1<<14][14][2];
double dis[14][2][14][2];

int main() {
  int n;
  int T = 0;
  while(cin >>n, n) {
    L l[n];
    REP(i,n) {
      P p1,p2;
      cin >> p1.real()>>p1.imag()>>p2.real()>>p2.imag();
      l[i] = L(p1,p2);
    }
    REP(S,1<<n) REP(i,n) REP(j,2) dp[S][i][j] = INF;
    REP(i,n) REP(a,2) REP(j,n) REP(b,2) dis[i][a][j][b] = abs(l[i][a]-l[j][b]);
    double ans = INF;
    REP(i,n) REP(j,2) dp[1<<i][i][j] = dis[i][0][i][1];
    REP(S,1<<n) {
      REP(i,n) {
        if (!(S>>i&1)) continue;
        REP(j,2) {
          REP(k,n) {
            if (S>>k&1) continue;
            REP(p,2)
              dp[S|1<<k][k][p] = min(dp[S|1<<k][k][p], dp[S][i][j] + dis[i][j][k][!p] + dis[k][0][k][1]);
          }
          if (S==(1<<n)-1) 
            ans = min(ans, dp[S][i][j]);
        }
      }
    }
    printf("Case %d: %.10f\n",++T,ans); 
  }
}

Measured memory_bytes: 4592
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    bool ans = true;
    for(int i = 0; i < N/2; i++){
        if(s[i] != s[(N/2)+i])  ans = false;
    }
    if(ans && (N % 2 == 0)) cout << "Yes" << endl;
    else    cout << "No" << endl;
}

Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
A = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(list)


B = [0] * (N+1)
B[0] = 0 
for i in range(0,N):
    B[i+1] = A[i]
    B[i+1] += B[i]

for i in range(0,N+1):
    d[ B[i] % M] += [i]

from bisect import bisect_left

ans = 0
for i in range(0,N+1):
    m = B[i] % M 
    ans += bisect_left( d[m], i)

print(ans)
    
    


Measured memory_bytes: 62864
import copy

n = int(input())
v = list(map(int, input().split()))
# print(v)

la = [0 for i in range(5+10**5)]
lb = [0 for i in range(5+10**5)]

for i in range(0, n, 2):
    la[v[i]] += 1
for i in range(1, n, 2):
    lb[v[i]] += 1

# print(sum(la))
# print(sum(lb))
# print(max(la))
# print(max(lb))
# print(la.index(max(la)))
# print(lb.index(max(lb)))

sla = sum(la)
slb = sum(lb)
maxla = max(la)
maxlb = max(lb)
argmaxla = la.index(max(la))
argmaxlb = lb.index(max(lb))

if argmaxla != argmaxlb:
    if sla-maxla == 0 and slb-maxlb == 0:
        print(0)
    else:
        print(sla-maxla+slb-maxlb)
else:
    # laの2番目に大きい値を使う
    _la = copy.deepcopy(la)
    _la[argmaxla] = 0
    _maxla = max(_la)
    aa = sla-_maxla+slb-maxlb
    # lbの2番目に大きい値を使う
    _lb = copy.deepcopy(lb)
    _lb[argmaxlb] = 0
    _maxlb = max(_lb)
    bb = sla-maxla+slb-_maxlb
    if bb > aa:
        print(aa)
    else:
        print(bb)


Measured memory_bytes: 21228
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 60
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

int main() {
	optimizar_io
	int x, y; cin >> x >> y;
	bool flag = false;
	fore(i, 0, 200) {
		fore(j, 0, 200) {
			if(((2*i + 4*j) == y) && (i + j == x)) {
				flag = true;
				break;
			} 
		}
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3556
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a<b){
		cout << "a < b\n";
	}
	else if(a>b){
		cout << "a > b\n";
	}
	else{
		cout << "a == b\n";
	}
	return 0;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
 
#define mod             1000000007
#define rep(i,n)        for (int i = 0; i < n; ++i)
#define REP(i,k,n)      for (int i = k; i < n; ++i)
#define REPR(i,k,n)     for (int i = k; i >= n; --i)
#define w(x)            int x; cin>>x; while(x--)
#define mk(arr,n,type)  type *arr=new type[n];
#define pii             pair<int,int>
#define mp              make_pair
#define inrange(i, a, b) ((i >= min(a, b)) && (i <= max(a, b)))
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll              long long
#define w(x)            int x; cin>>x; while(x--)
#define mem(a, b)       memset(a, (b), sizeof(a))
#define setbits(x)      __builtin_popcountll(x)
  
void solve() {
   int n;
   cin>>n;
   int res1 = (int)ceil(n/1.08);
   int res2 = (int)floor(n/1.08);
   int temp1 = (int) floor(res1*1.08);
   int temp2 = (int)floor(res2*1.08);
   if(temp1==n) {
       cout<<res1<<endl;
       return;
   }
   if(temp2==n) {
       cout<<res2<<endl;
       return;
   }
   cout<<":("<<endl;
}
 
 
int main() {
    fast
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int main()
{
    int n;
    scanf("%d", &n);
    int x[2] = {100 * n / 108, 100 * n / 108 + 1};

    for (int i = 0; i < 2; ++i)
    {
        double c = x[i] * 1.08;
        if (c >= n && c < n + 1)
        {
            printf("%d\n", x[i]);
            return 0;
        }
    }
    printf(":(\n");
    return 0;
}


Measured memory_bytes: 128
N = int(input())
F = []
for n in range(N):
  F.append([k for k, x in enumerate(input().split()) if x=="1"])
P = []
for n in range(N):
  P.append([int(p) for p in input().split()])

PROFIT = []
for i in range(1, 2**10):
  i = format(i, "b")
  if len(i) < 10:
    i = "0"*(10-len(i)) + i
  OPEN_joisino = [k for k, x in enumerate(i) if x=="1"]
  profit = 0
  for n in range(N):
    together_time = 0
    for t in OPEN_joisino:
      if t in F[n]:
        together_time += 1
    profit += P[n][together_time]
  PROFIT.append(profit)
ans = max(PROFIT)
print(ans)

Measured memory_bytes: 3064
def main():
    N, K = [int(x) for x in input().split()]
    p = [int(x) for x in input().split()]
    e = [(x+1)/2 for x in p]

    s = sum(e[:K])
    ans = s
    for i in range(K, N):
        s = s - e[i-K] + e[i]
        ans = max(s, ans)
    print(ans)


if __name__ == '__main__':
    main()

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

  int N;
  std::string S;

  std::cin >> N >> S;

  if(N < 3200){
      std::cout << "red" << std::endl;
  }else{
      std::cout << S << std::endl;
  }
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define endl        '\n'
#define ll          long long int
#define pb          push_back
#define sz(x)       (int)(x).size()
const ll mod = 1e9 + 7;

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


ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}

//--------------------------------------------------------------------------------------------------------------------------//
const int N = 1e5 + 5;
int a[N] , b[N], c[N], dp[N][3];

int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];

	for (int i = 1; i <= n; i++) {
		if (i == 1) {
			dp[i][0] = a[i];
			dp[i][1] = b[i];
			dp[i][2] = c[i];
			continue;
		}

		dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1] , dp[i - 1][0]) + c[i];
	}

	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;;
	return 0;

}





Measured memory_bytes: 5976
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#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>
using namespace std;
#define int long long
#define float double
const int INF = 100000000000000000;


signed main(void){
  int h,w;
  cin >> h >> w;
  vector<string> a;

  for(int i = 0; i < h; i++){
    string a_;
    cin >> a_;
    a.push_back(a_);
  }

  for(int i = 0; i < w+2; i++)cout << "#";
  cout << "\r\n";

  for(int i = 0; i < h; i++){
    cout << "#";
    cout << a[i];
    cout << "#\r\n";
  }

  for(int i = 0; i < w+2; i++)cout << "#";
  cout << "\r\n";

  return 0;
}


Measured memory_bytes: 256
n,m,x = map(int,input().split())
c=[0 for _ in range(n)]
a=[[] for _ in range(n)]
for i in range(n):
    c[i],*a[i] = map(int,input().split())
ans=sum(c)+1
alg=[0 for i in range(m)]
for i in range(int(2**n)):
    cnt=0
    al=alg[:]
    ii=i
    for j in range(n):
        r=i%2
        i=i//2
        if r ==1:
            cnt+=c[j]
            k=0
            for v in a[j]:
                al[k]+=v
                k+=1
    ok = True
    for y in al:
        if y<x:
            ok=False
            break
    if ok:
        ans=min(ans,cnt)
    #print(ii,cnt,al)
if ans==sum(c)+1:
    print(-1)
else:
    print(ans)
    
    



Measured memory_bytes: 9240
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	H := ReadInts(N)
	c := make([]int, N)
	for i := N - 2; i >= 0; i-- {
		if H[i] >= H[i+1] {
			c[i] = c[i+1] + 1
		}
	}
	max := -1
	for i := 0; i < N; i++ {
		if max < c[i] {
			max = c[i]
		}
	}
	fmt.Println(max)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 5092
#include <iostream>
using namespace std;
int N, A, B, C, Y[110], i, n, X;

int ran(int x1, int i, int n){
    int x2;
    if(Y[i] == x1 && i==N)  return n;//0回を出すためのもの
    if(x1 == Y[i]){
        if(i==N)    return n;//最後止めるための条件
        else        i++;//整数と乱数の値が同じとき次の整数の検証に移る 
    }
    x2 = (A*x1+B)%C;//乱数を計算  
    n++;//リール数
    if(n > 10000)  return -1;//それ以外は－１

    return ran(x2, i, n);
}

int main(void){
    while(cin >> N >> A >> B >> C >> X){
        if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0)  break;
        for(int i= 1; i<= N; i++)
            cin >> Y[i];
            cout << ran(X, 1, 0) << endl;
    }
    return 0;
}


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

int main() {
  long long n, q;
  cin >> n >> q;
  vector<int> u(n-2, n-2), l(n-2, n-2);
  long long ans = 0;
  long long lmin = n-2, umin=n-2;
  long long lminv = n-2, uminv=n-2;
  for (int i = 0; i < q; i++) {
    int type, x;
    cin >> type >> x;
    x -= 2;
    if (type == 1) {
      //up
      if (lmin > x) {
        ans += uminv;
        for (int j = x; j < lmin; j++) {
          u[j] = uminv;
        }
      	lmin = x;
        lminv = x;
      } else {
        ans += u[x];
      }
    } else {
      //left
      if (umin > x) {
        ans += lminv;
        for (int j = x; j < umin; j++) {
          l[j] = lminv;
        }
        umin = x;
        uminv = x;
      } else {
      	ans += l[x];
      }
    }
  }
  cout << (n-2)*(n-2) - ans << endl;
}

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

public class Main{

    static int negativeInf = -Integer.MIN_VALUE;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.nextLine());
        String[] sElementArray=sc.nextLine().split(" ");
        //int[] array=Arrays.stream(sElementArray).mapToInt(Integer::parseInt).toArray();
        int[] array=new int[n+1];
        for(int i=0;i<n;i++){
            array[i+1]=Integer.parseInt(sElementArray[i]);
        }
        array[0]=negativeInf;
        sc.close();

        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //    try{
        //         int n= Integer.parseInt(br.readLine());
        //         int[] array = Arrays.stream(sElementArray).mapToInt(Integer::parseInt).toArray();
                
        //     }catch(IOException e){e.printStackTrace();}


        buildMaxHeap(array);

        for (int i=1;i<=n;i++){
            System.out.print(" "+array[i]);
        }
        System.out.print("\n");

    }

    static void buildMaxHeap(int[] array){
        for(int i=(array.length-1)/2;i>=1;i--){
            maxHeapify(i, array);
        }
    }
    
    //return index of each node
    static int parent(int h){return h/2;}
    static int left(int h){return 2*h;}
    static int right(int h){return 2*h+1;}

    static void maxHeapify(int k,int[] array){
        int indexOfLargestKey=k;
        int l=0;
        int r=0;
        if(2*k<array.length){
            l=left(k);
        }
        if(2*k+1<array.length){
            r=right(k);
        }
        
        if(array[indexOfLargestKey]<array[l]){
            indexOfLargestKey=l;
        }
        if(array[indexOfLargestKey]<array[r]){
            indexOfLargestKey=r;
        }

        if(array[indexOfLargestKey] != array[k]){
            swap(array,indexOfLargestKey,k);
            maxHeapify(indexOfLargestKey, array);
        }
    }

    static void swap(int[] array,int n,int m){
        int tmp=array[n];
        array[n]=array[m];
        array[m]=tmp;
    }
}
    


Measured memory_bytes: 123500
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int N;
ll a[112345][3];
ll dp[112345][3];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  repeat(i,N){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  repeat(i,N){
    repeat(j,3){
      dp[i+1][j] = max(dp[i][(j+1)%3],dp[i][(j+2)%3])+a[i][j];
    }
  }
  cout << max({dp[N][0],dp[N][1],dp[N][2]})<<endl;
  return 0;
}


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

int main() {
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int x=a*60+b;
    int y=c*60+d;
    int z=y-x;
    int r=z-e;
    cout<<r<<endl;
    
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int X,Y; cin >> X >> Y;
    int ans[3]={300000,200000,100000};
    if(X==1&&Y==1){
        cout << ans[X-1]+ans[Y-1]+400000 << endl;
    }else if(X<=3&&Y<=3){
        cout << ans[X-1]+ans[Y-1] << endl;
    }else if(X<=3){
        cout << ans[X-1] << endl;
    }else if(Y<=3){
        cout << ans[Y-1] << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
N,K = map(int,input().split())
r,s,p = map(int,input().split())
T = list(input())

def battle(i,b):
    st=['r','s','p']
    a = st[i]
    if a=='r':
        if b=='p':
            return p
        else:
            return 0
    elif a=='s':
        if b=='r':
            return r
        else:
            return 0
    elif a=='p':
        if b=='s':
            return s
        else:
            return 0
# dp = [[0]*3 for _ in range(N+1)]
# for i in range(K):
#     for j in range(3):
#         dp[i+1][j] = 
#%%
ans = 0
hand = ['n']*N
for i,t in enumerate(T):
    if i<K:
        if t=='r':
            ans += p
            hand[i] = 'p'
        elif t=='s':
            ans += r
            hand[i] = 'r'
        elif t=='p':
            ans += s
            hand[i] = 's'
    else:
        if t=='r' and hand[i-K]!='p':
                ans += p
                hand[i] = 'p'               
        elif t=='s' and hand[i-K]!='r':
            ans += r
            hand[i] = 'r'
        elif t=='p' and hand[i-K]!='s':
            ans += s
            hand[i] = 's'
print(ans)
        
    
        

Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,q;
	cin>>n;
	while(n--){
		cin>>q;
		int a[q],m1=0,m2=0;
		for(int i=0;i<q;i++){
			cin>>a[i];
			if(i){
				if(a[i-1]>a[i])m1=max(m1,a[i-1]-a[i]);
				if(a[i-1]<a[i])m2=max(m2,a[i]-a[i-1]);
			}
		}
		cout<<m2<<' '<<m1<<endl;
	}
}

Measured memory_bytes: 3072
n = int(input())
s = input()

from collections import Counter
left = Counter('')
right = Counter(s[1:])

ans = set()
for i in range(1, n-1):
    left[s[i-1]] += 1
    right[s[i]] -= 1
    # print(left, right)

    left_u = []
    for k in left.keys():
        if left[k] >= 1:
            left_u.append(k)
    right_u = []
    for k in right.keys():
        if right[k] >= 1:
            right_u.append(k)

    for l in left_u:
        for r in right_u:
            tmp = l + s[i] + r
            ans.add(tmp)

print(len(ans))


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main() {
	int w, h, n;
	int x, y, a;
	cin >> w >> h >> n;
	vector<vector<int>> v(w, vector<int>(h, 0));
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		if (a == 1) {
			for (int j = 0; j < x; j++) {
				for (int k = 0; k < h; k++) {
					v[j][k] = 1;
				}
			}
		}
		else if (a == 2) {
			for (int j = x; j < w; j++) {
				for (int k = 0; k < h; k++) {
					v[j][k] = 1;
				}
			}
		}
		else if (a == 3) {
			for (int j = 0; j < y; j++) {
				for (int k = 0; k < w; k++) {
					v[k][j] = 1;
				}
			}
		}
		else if (a == 4) {
			for (int j = y; j < h; j++) {
				for (int k = 0; k < w; k++) {
					v[k][j] = 1;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (v[i][j] == 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {
  int n, ans = 1;
  string s;
  vector<int> a(26);
  cin >> n >> s;
  for (char c : s) {
    ++a[c - 'a'];
  }
  for (int i = 0; i < 26; ++i) {
    ans = (long long)ans * (a[i] + 1) % MOD;
  }
  printf("%d\n", (ans - 1 + MOD) % MOD);
  
  return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,a[200001];
ll k;
int cur,cs;
int dist[200001];
void dfs(int x,ll kk){
	if(kk==0){
		cout<<x+1;
		re;
	}
	dfs(a[x],kk-1);
}
bool used[200001];
void dfs1(int x,int cnt){
	used[x]=true;
	dist[x]=cnt;
	if(used[a[x]]){
		cur=a[x];
		re;
	} 
	dfs1(a[x],cnt+1);
}
void dfs2(int x,int cnt){
	used[x]=true;
	cnt++;
	if(used[a[x]]){
		cs=cnt;
		re;
	}
	dfs2(a[x],cnt);
}
int main(){
	cin>>n>>k;
	rep(i,n){
		cin>>a[i];
		a[i]--;
	}
	if(k<n){
		dfs(0,k);
		re 0;
	}
	dfs1(0,0);
	k-=dist[cur];
	zero(used);
	dfs2(cur,0);
	k%=cs;
	dfs(cur,k);
	re 0;
}

Measured memory_bytes: 5340
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int j = i + 1;
        while (j < n && arr[j] <= arr[j - 1])
            ++j;
//        cout << j << endl;
        ans = max(ans, j - i);
        i = j - 1;
    }

    cout << ans - 1 << '\n';

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int,string>;
auto const INF = (ll)1e19;
int main(){
   int n,m;
   cin >> n >> m;
   auto a = priority_queue<ll,vector<ll> >();
   for(int i=0;i<n;i++){
      int t;
      cin >> t;
      a.push(t);
   }
   
   while(m!=0){
      ll t = a.top();
      a.pop();
      a.push(t/2);
      m--;
   }

   ll sum =0;
   while(!a.empty()){
      sum+=a.top();
      a.pop();
   }
   cout << sum << endl;

   return 0;
}

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

int main()
{
  int N;
  bool flag = true;
  int count = -1;

  cin >> N;

  vector<int> v(N);
  
  for (int i = 0; i < N; i++)
    cin >> v[i];
  while (flag)
  {
    count++;
    for (int i = 0; i < N; i++)
    {
      if (v[i] % 2 != 0)
      {
        flag = false;
        break;
      }
      else
      {
        v[i] /= 2;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256