akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,d;
cin>>n>>d;
ll arr[n][d];
rep(i,0,n)
rep(j,0,d)
cin>>arr[i][j];
ll ans=0;
rep(i,0,n)
{
	rep(j,i+1,n)
	{
		ll x=0;
		rep(k,0,d)
		x+=(arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
			ll y=sqrt(x);
	if(y*y==x)
	ans++;
	}

}
cout<<ans;
}






Measured memory_bytes: 256
using System;

namespace rensyuu1
{
    class Program
    {
        static void Main(string[] args)
        {
            string qq = Console.ReadLine();
            string[] aa = qq.Split(new char[] { ' ' });
            int a = int.Parse(aa[0]);
            int b = int.Parse(aa[1]);
            int d = a / b;
            int r = a % b;
            double f = 1.00000 * a / b;
            string text = f.ToString("F5");
            Console.WriteLine("{0} {1} {2}", d, r, text);
        }
    }
}


Measured memory_bytes: 17972
import java.io.Console;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.function.IntToDoubleFunction;

public class Main {
    static int A;
    static int B;
    static int[] a;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        A = scanner.nextInt();
        B = scanner.nextInt();
        scanner.close();
    }

    public static void main(String[] args) {
        init();
        // logic
        logic();
    }

    static void logic() {
        int distance = Math.max(A - B * 2, 0);
        System.out.println(distance);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

string s;
ll K;
set<string> cands;

void showcands() {
  for (auto it = cands.begin(); it != cands.end(); it++) {
    cerr << *it << "\n";
  }
}

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> s >> K;
  for (int i = 0; i < (int)s.size(); i++) {
    for (int j = 1; j <= K; j++) {
      if (i + j <= (int)s.size()) {
	cands.insert(s.substr(i, j));
      }
    }
  }
  DCALL(showcands);
  auto it = cands.begin();
  for (int i = 0; i < K-1; i++) it++;
  cout << *it << endl;
  
  return 0;
}



Measured memory_bytes: 1664
#include<stdio.h>
int main(void) {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
 
	if(A+B>C+D) printf("Left\n");
	else if(A+B<C+D) printf("Right\n");
	else printf("Balanced\n");
 
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

int N, A, B, C, INF = 1e9;
int l[10];

int solve(int i, int a, int b, int c)
{
    if (i == N)
    {
        if (min({a, b, c}) == 0)
            return INF;
        else
            return abs(a - A) + abs(b - B) + abs(c - C);
    }
    else
    {
        int res0 = solve(i + 1, a, b, c);
        int res1 = solve(i + 1, a + l[i], b, c) + (a == 0 ? 0 : 10);
        int res2 = solve(i + 1, a, b + l[i], c) + (b == 0 ? 0 : 10);
        int res3 = solve(i + 1, a, b, c + l[i]) + (c == 0 ? 0 : 10);
        return min({res0, res1, res2, res3});
    }
}

int main()
{
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++)
    {
        cin >> l[i];
    }
    cout << solve(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
H, W=map(int, input().split())
S=[input() for _ in range(H)]

tate=[[0]*W for _ in range(H)]
yoko=[[0]*W for _ in range(H)]

for i in range(W):
  j=0
  while j<H:
    x=0
    while j+x<H and S[j+x][i]=='.':
      x+=1
    if x==0:
      tate[j][i]=0
      j+=1
    else:
      for t in range(x):
        tate[j+t][i]=x
      j+=x

for i in range(H):
  j=0
  while j<W:
    x=0
    while j+x<W and S[i][j+x]=='.':
      x+=1
    if x==0:
      yoko[i][j]=0
      j+=1
    else:
      for t in range(x):
        yoko[i][j+t]=x
      j+=x
      
print(max([max([tate[i][j]+yoko[i][j]-1 for j in range(W)]) for i in range(H)]))

Measured memory_bytes: 123480
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

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

int main(){
	int n;
	cin>>n;
	
	
	rep(i,n){
		string str;
		cin>>str;
		map<string,int> hoge;
		
		reps(j,1,str.size()){
			string s1 = str.substr(0,j);
			string s2 = str.substr(j,str.size()-j);
			string s3 = s1;
			string s4 = s2;
			reverse(s3.begin(),s3.end());
			reverse(s4.begin(),s4.end());
			
			hoge[s1+s4]=1;
			hoge[s4+s1]=1;
			
			hoge[s2+s3]=1;
			hoge[s3+s2]=1;
			
			hoge[s1+s2]=1;
			hoge[s2+s1]=1;
			
			hoge[s3+s4]=1;
			hoge[s4+s3]=1;
			/*
			cout<<" "<<s1<<s4<<endl;
			cout<<" "<<s4<<s1<<endl;
			cout<<" "<<s2<<s3<<endl;
			cout<<" "<<s3<<s2<<endl;
			cout<<" "<<s1<<s3<<endl;
			cout<<" "<<s3<<s1<<endl;
			cout<<" "<<s2<<s4<<endl;
			cout<<" "<<s4<<s2<<endl;*/
		}
		
		printf("%d\n",hoge.size());
	}
}

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

#define pb push_back
#define fi first
#define se second
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353

int lowbit(int x) {return x&(-x);}

int n,m;
vector <pii> p[200010];
long long tree[800040];
long long tag[800040];

void update(int cur,int l,int r,int ll,int rr,long long c) {
	if (ll<=l&&rr>=r) {
		tree[cur]+=c;
		tag[cur]+=c;
		return; 
	}
	int mid=(l+r)>>1;
	if (ll<=mid) update(cur*2,l,mid,ll,rr,c);
	if (rr>mid) update(cur*2+1,mid+1,r,ll,rr,c);
	tree[cur]=max(tree[cur*2],tree[cur*2+1])+tag[cur];
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;i++) {
		int l,r,a;
		scanf("%d%d%d",&l,&r,&a);
		p[r].pb(mp(l,a));
	}
	for (int i=1;i<=n;i++) {
		update(1,1,n,i,i,tree[1]);
		for (int j=0;j<p[i].size();j++)
			update(1,1,n,p[i][j].fi,i,p[i][j].se);
	}
	cout<<max(0ll,tree[1]);
	return 0;
}


Measured memory_bytes: 22656
N, K = map(int, input().split())
D = []
A = [[] for i in range(200)]
for i in range(K):
    d = int(input())
    D.append(d)
    a = list(map(int, input().split()))
    A[i] = a

ans = 0
for i in range(1, N+1):
    num = 0
    for j in range(K):
        for k in range(D[j]):
            if A[j][k] == i:
                num = 1
    if num == 0:
        ans += 1
print(ans)


Measured memory_bytes: 68004
n,m=map(int,input().split())
student=[list(map(int,input().split())) for _ in range(n)]
checkpoint=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
    distance=[]
    for j in range(m):
        calc=0
        calc=abs(student[i][0]-checkpoint[j][0])+abs(student[i][1]-checkpoint[j][1])
        distance.append(calc)
    print(distance.index(min(distance))+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	bool flag = 0;
	REP(i, n){
		int a;
		cin >> a;
		if (a % 2 == 1) flag = 1;
	}

	if (flag) cout << "first" << endl;
	else cout << "second" << endl;
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    ans = (N - 2) * 180
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10116
n=int(input())
S=list(input())
W=[0]*(n+1)
E=[0]*(n+1)
for i in range(n):
  W[i]=W[i-1]+S[i].count("W")
  E[n-i-1]=E[n-i]+S[n-i-1].count("E")
W = W[:n]
E = E[:n]
ans = 1000000
for i in range(n):
  ans = min(ans,W[i]+E[i]-1)
print(ans)


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

int main() {
    long n, ans = 1, temp;
    const long MOD = 1000000007;
    cin >> n;
    map<long, long> mp;
    for(long i = 2; i <= n; i++) {
        temp = i;
        for(long j = 2; j * j <= n; j++) {
            while(temp % j == 0) {
                mp[j]++;
                temp /= j;
            }
        }
        if(temp > 1) mp[temp]++;
    }
    for(pair<long, long> p : mp) {
        ans = ans * (p.second + 1) % MOD;
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

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

int64 modinv(int64 a, int64 m) {
    int64 b = m, u = 1, v = 0;
    while (b) {
        int64 t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    int N;
    cin >> N;
    
    string S;
    cin >> S;
    map<char, int> M;
    rep(i, S.size()) M[S[i]]++;
    cout << (M['B'] < M['R'] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())

if a >= b and a >= c:
    if b<=c:
        print(b,c,a)
    else:
        print(c,b,a)
elif a>=b or a>=c:
    if b<=c:
        print(b,a,c)
    else:
        print(c,a,b)
else:
    if b<=c:
        print(a,b,c)
    else:
        print(a,c,b)


Measured memory_bytes: 5592
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		Map<Integer, Integer> map = new TreeMap<>();
		int xy[] = new int[2];

		map.put(x, a);
		map.put(y, b);

		int i = 0;
		for (int k : map.keySet()) {
			xy[i] = k;
			i++;
		}

		int ans = 0;
		ans = Math.min(a * xy[0] + b * xy[0], c * xy[0] * 2);

		if (x != y) {
			int t = xy[1] - xy[0];
			ans += Math.min(map.get(xy[1]) * t, c * t * 2);
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define LL long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pii pair < int , int >

LL n;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	cout << 1LL * n * (n-1) / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ALL(a)  (a).begin(),(a).end()
 
int main(){
  int n, x;
  cin >> n >> x;
  vector<int> l(n+1, 0);
  for (int i=0; i<n; ++i){
    int a; cin >> a;
    l[i+1] = l[i] + a;
    if(l[i+1]>x){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << n+1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer t = new StringTokenizer(br.readLine());
		int[] h = new int[n];
		for(int i = 0 ; i < n ; i++) h[i] = Integer.parseInt(t.nextToken());
		int[] dp = new int[n];
		dp[n-1] = 0;
		dp[n-2] = Math.abs(h[n-1] - h[n-2]);
		for(int i = n-3 ; i >= 0 ; i--)
		      dp[i] = Math.min(Math.abs(h[i]-h[i+1])+dp[i+1],Math.abs(h[i]-h[i+2])+dp[i+2]);
		System.out.println(dp[0]);
	}
}

Measured memory_bytes: 31448
import java.util.Scanner;


public class Main {
	
	private static int[][] cache;
	private static int[] r;
	private static int[] c;
	

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

		int n = sc.nextInt();
		cache = new int[n][n];
		r = new int[n];
		c = new int[n];

		for (int i = 0; i < n; i++) {
			r[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		for (int j = 0; j < n; j++) {
			for (int i = 1; i <= n && i + j <= n; i++) {
				cache[i-1][i+j-1] = mcm(i, i + j);
//				System.out.println(i + " " + (i + j));
			}
		}

		System.out.println(cache[1 - 1][n - 1]);
		
		sc.close();
	}
	
	private static int mcm(int i, int j) {
		if (i == j) {
			return 0;
		} else {
			int min = Integer.MAX_VALUE;
			for (int k = 0; k < j - i; k++) {
				assert c[i+k-1] == r[i+k+1-1] : i + k + ":" + c[i+k-1] + "," + r[i+k+1-1];
				int result = cache[i-1][i+k-1] + r[i-1] * r[i+k+1-1] * c[j-1] + cache[i+k+1-1][j-1];
				if (result < min) {
					min = result;
				}
			}
			
			return min;
		}
	}
}

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

using namespace std;

#define Q int t, q; scanf("%d", &t); for(q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pli;

int main()
{
    int n, i, m, x;
    string s;
    cin >> n >> m;
    bool is[n+1] = {0};
    map<int, int> mp;
    while(m--){
        cin >> x >> s;
        if(s == "AC"){
            is[x] = 1;
            if(mp[x] == 0){
                mp[x] = 0;
            }
        }
        else{
            if(!is[x]){
                mp[x]++;
            }
        }
    }
    int a=0, b=0;
    for(auto it=mp.begin(); it!=mp.end(); it++){
        if(is[it->first]){
            a++;
            b += it->second;
        }
    }
    cout << a << " " << b << "\n";

    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;	
	
int main(){
	int n,m,k;cin>>n>>m>>k;

	for(int i=0;i<=n;i++){
	for(int j=0;j<=m;j++){
		if(m*i+n*j-i*j*2 == k){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w, i,j,q,r,l;
ll k;
ll ans;
ll x[500005], y[200005], z[200005];
char s[500005], t[500005];
bool used[3005][3004];
P table[500005];

int main(){
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    */
    ll s;
    cin >> n >> k >> s;
    if(s != 1000000000ll){
        for(ll i=0;i<k;i++){
            pe(s);
        }
        for(ll i=k;i<n;i++){
            pe(s + 1);
        }
        el;
        return 0;
    }else{
        for(ll i=0;i<k;i++){
            pe(s);
        }
        for(ll i=k;i<n;i++){
            pe(1);
        }
        el;
        return 0;
    }
    return 0;
}
 
 











Measured memory_bytes: 1280
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    string s; cin >> s;

    A--; B--; C--; D--;
    bool ok = true;
    {
        // A -> C
        int cons = 0, max_cons = 0;
        for(int i=A; i<=C; i++) {
            if(s[i] == '.') {
                max_cons = max(max_cons, cons);
                cons = 0;
            }
            else {
                cons++;
            }
        }

        ok &= (max_cons < 2);
        fprintf(stderr, "ok1 = %d\n", max_cons < 2);
    }
    {
        // B -> D
        int cons = 0, max_cons = 0;
        for(int i=B; i<=D; i++) {
            if(s[i] == '.') {
                max_cons = max(max_cons, cons);
                cons = 0;
            }
            else cons++;
        }
        ok &= (max_cons < 2);
        fprintf(stderr, "ok2 = %d\n", max_cons < 2);
    }

    if(C > D) {
        bool can = false;
        can |= (0 < B and B < N - 1 and s[B-1] == '.' and s[B+1] == '.');
        can |= (0 < D and D < N - 1 and s[D-1] == '.' and s[D+1] == '.');
        
        // 追い越す場合は 3 マス以上の空きがどこかに必要
        int cons = 0, max_cons = 0;
        for(int i=B-1; i<=D+1; i++) {
            if(s[i] == '#') {
                max_cons = max(max_cons, cons);
                cons = 0;
            }
            else cons++;
        }
        can |= (max_cons >= 3);
        // fprintf(stderr, "max_cons = %lld, can = %d\n", max_cons, can);

        ok &= can;
    }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int cntw[4001][4001], cntb[4001][4001];
int dp[2001][2001];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vector<pi> in;
	vi pos(2 * n);
	rep(i, 2 * n){
		char c; int p; cin >> c >> p; p--;
		in.emplace_back(c == 'B', p);
		pos[p + (c == 'B' ? n : 0)] = i;
		
		if(i){
			rep(j, 2 * n) cntw[i][j] = cntw[i - 1][j];
			rep(j, 2 * n) cntb[i][j] = cntb[i - 1][j];
		}
		if(c == 'B') for(int j = p; j < 2 * n; j++) cntb[i][j]++;
		if(c == 'W') for(int j = p; j < 2 * n; j++) cntw[i][j]++;
	}
	
	//rep(i, 2 * n) rep(j, 2 * n) cerr<<cntw[i][j]<<(j==2*n-1?"\n":" ");
	
	
	rep(i, n + 1) rep(j, n + 1) dp[i][j] = inf;
	dp[0][0] = 0;
	rep(i, n + 1) rep(j, n + 1){
		if(i < n){
			int p = pos[i], w = cntw[p][2 * n - 1] - cntw[p][i], b = cntb[p][2 * n - 1] - (j ? cntb[p][j - 1] : 0);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + w + b);
		}
		if(j < n){
			int p = pos[j + n], w = cntw[p][2 * n - 1] - (i ? cntw[p][i - 1] : 0), b = cntb[p][2 * n - 1] - cntb[p][j];
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + w + b);
		}
	}
	//dbg(pos[0], cntw[pos[0]][2 * n - 1]);
	//rep(i, n + 1) rep(j, n + 1) cerr<<dp[i][j]<<(j==n?"\n":" ");
	cout << dp[n][n] << endl;
	
	return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int32_t main() {
    Fast_IO
#ifdef __WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    for (auto &it : a) {
        for (auto &i : it)
            cin >> i;
    }
    vector < vector<int>> dp(n + 1, vector<int>(3, 0));
    for (int day = 1; day <= n; day++) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i != j) {
                    dp[day][j] = max(dp[day][j], dp[day - 1][i] + a[day - 1][j]);
                }
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}

Measured memory_bytes: 11264
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t N, A, B;

    std::cin >> N >> A >> B;

    int64_t sum = A + B;
    int64_t count = (N/sum) * A;
    int64_t mod = N % sum;

    if (mod <= A) {
        count += mod;
    } else {
        count += A;
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

// add :: T -> T -> T
//     {v1,v2,...,vm}+vm+1
// bundle :: T -> T
//     u->{v1,v2,v3,...,vm} 
template<class T, class F1, class F2>
vector<T> freeTreeDP(const vector<vector<int>> &g, F1 add, F2 bundle) {
	const int n = g.size();
	vector<T> dp(n);
	function<void(int, int)> dfs = [&](int u, int p) {
		for (int v : g[u]) {
			if (v != p) {
				dfs(v, u);
				dp[u] = add(dp[u], dp[v]);
			}
		}
		dp[u] = bundle(dp[u]);
	};
	dfs(0, -1);
	function<void(int, int)> dfs2 = [&](int u, int p) {
		const int m = g[u].size();
		T l;
		vector<T> r(m);
		for (int i = m - 2; i >= 0; i--) {
			r[i] = add(dp[g[u][i + 1]], r[i + 1]);
		}
		for (int i = 0; i < m; i++) {
			const int v = g[u][i];
			dp[u] = bundle(add(l, r[i]));
			l = add(l, dp[v]);
			if (v != p) {
				dfs2(v, u);
			}
		}
		dp[u] = bundle(l);
	};
	dfs2(0, -1);
	return dp;
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	struct foo {
		double sum;
		int cnt;
		foo(double sum = 0, int cnt = 0) : sum(sum), cnt(cnt) {}
	};
	auto add = [&](const foo &a, const foo &b) {
		foo c;
		c.sum = a.sum + b.sum;
		c.cnt = a.cnt + b.cnt;
		return c;
	};
	auto bundle = [&](const foo &a) {
		foo c;
		if (a.cnt == 0) {
			c.sum = 0;
		} else {
			c.sum = 1.0 / a.cnt * a.sum + 1;
		}
		c.cnt = 1;
		return c;
	};
	auto dp = freeTreeDP<foo>(g, add, bundle);
	for (int i = 0; i < n; i++) {
		printf("%.20f\n", dp[i].sum);
	}
}


Measured memory_bytes: 28160
n = gets.to_i
a = gets.split("\s").map(&:to_i)
count = 0
i = 1

a.each do |a_i|
  if a_i == i
    i += 1
    next
  end
  
  count += 1
end

if i == 1 || count == n
  p -1
else
  p count
end

Measured memory_bytes: 15364
import sys

n,m = map(int,input().split())
s = [] ; c = []
for i in range(m) :
  st,ct = map(int,input().split())
  s.append(st) ; c.append(ct)

ans = [[0,0] for i in range(n)]  
for i in range(m) :
  if s[i] == 1 and c[i] == 0 and n >= 2 :
    print(-1)
    sys.exit()
  if ans[s[i]-1][1] == 0 :
    ans[s[i]-1][0] = c[i] 
    ans[s[i]-1][1] = 1
  else :
    if ans[s[i]-1][0] != c[i] :
      print(-1)
      sys.exit()

if ans[0][0] == 0 and n >= 2 :
  ans[0][0] = 1

ansn = 0
for i in range(n) :
  ansn += ans[i][0]*10**(n-1-i)
  
print(ansn)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll h,w;
ll a[e3][e3];
ll x[e5],y[e5],z[e5],ww[e5];
ll n = 0;
ll flag = false;

int main(){
  cin >> h >> w;
  for(ll i = 1;i <= h;i++){
    for(ll j = 1;j <= w;j++){
      cin >> a[i][j];
    }
  }
  for(ll i = 1;i <= h;i++){
    for(ll j = 1;j < w;j++){
      if(a[i][j] % 2){
        x[n] = j;
        y[n] = i;
        z[n] = j+1;
        ww[n] = i;
        n++;
        a[i][j]--;
        a[i][j+1]++;
      }
    }
  }
  for(ll i = 1;i < h;i++){
    if(a[i][w] % 2){
      x[n] = w;
      y[n] = i;
      z[n] = w;
      ww[n] = i+1;
      n++;
      a[i][w]--;
      a[i+1][w]++;
    }
  }
  cout << n << endl;
  for(ll i = 0;i < n;i++){
    cout << y[i] << " " << x[i] << " " << ww[i] << " " << z[i] << endl;
  }
}


Measured memory_bytes: 41984
N = gets.to_i
as = gets.split.map(&:to_i).sort.reverse + [0]

i, j = 0, 1
while as[i+1] >= j+1
    i += 1
    j += 1
end

ans = (as[i] - j) % 2
if as[i+1] == j
    num = 0
    ((i+1)...N).each do |k|
        num += 1 if as[k] == j
    end
    ans = 1 if num % 2 == 1
end

puts ["Second", "First"][ans]

Measured memory_bytes: 10880
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

D, N = map(int, input().split())

if N == 100:
    print(100 ** D * (N + 1))
else:
    print(100 ** D * N)

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

typedef struct node{
  int key;
  int priority;
  struct node *left;
  struct node *right;
}node;

node * Delete(node **, int);
node * _delete(node **, int);

int find(node *p, int x){
  while(p != NULL){
    if(p->key == x) return 1;
    else if(p->key > x) p = p->left;
    else p = p->right;
  }
  return 0;
}

void inorder(node *p){
  if(p->left != NULL) inorder(p->left);

  cout  << " " << p->key;

  if(p->right != NULL) inorder(p->right);

  return;
}

void preorder(node *p){
  cout << " " << p->key;

  if(p->left != NULL) preorder(p->left);

  if(p->right != NULL) preorder(p->right);

  return;
}

void print(node *p){
  inorder(p);
  cout << endl;

  preorder(p);
  cout << endl;

  return;
}

node * makenode(int x, int y){
  node *n = new node;
  n->key = x;
  n->priority = y;
  n->left = NULL;
  n->right = NULL;
  return n;
}

node *rightRotate(node *p){
  node *q = p->left;
  p->left = q->right;
  q->right = p;
  return q;
}

node *leftRotate(node *p){
  node *q = p->right;
  p->right = q->left;
  q->left = p;
  return q;
}

node *insert(node **t, int key, int priority){
  node *n;

  if((*t) == NULL) return n = makenode(key, priority);

  if((*t)->key == key) return *t;

  if(key < (*t)->key){
    (*t)->left = insert(&(*t)->left, key, priority);
    if((*t)->priority < (*t)->left->priority)
      (*t) = rightRotate((*t));
  }

  else {
    (*t)->right = insert(&(*t)->right, key, priority);
    if((*t)->priority < (*t)->right->priority)
      (*t) = leftRotate((*t));
  }

  return *t;
}

node * Delete(node **t, int key){
  if((*t) == NULL) return NULL;

  if(key < (*t)->key)
    (*t)->left = Delete(&((*t)->left), key);

  else if(key > (*t)->key)
    (*t)->right = Delete(&((*t)->right), key);

  else return _delete(t, key);

  return *t;
}

node * _delete(node **t, int key){
  if((*t)->left == NULL && (*t)->right == NULL)
    return NULL;

  else if((*t)->left == NULL)
    (*t)=leftRotate(*t);

  else if((*t)->right == NULL)
    (*t)=rightRotate(*t);

  else {
    if((*t)->left->priority > (*t)->right->priority)
      (*t) = rightRotate(*t);
    else
      (*t) = leftRotate(*t);
  }
  return Delete(t, key);
}

int main(){
  int n, x, y;
  char com[8];
  node *root = NULL;

  cin >> n;

  for(int i = 0; i < n; ++i){
    cin >> com;

    switch(com[0]){

      case 'i': cin >> x >> y;
        root = insert(&root, x, y);
        break;

      case 'd': cin >> x;
        root = Delete(&root, x);
        break;

      case 'f': cin >> x;
        if(find(root, x)) cout << "yes" << endl;
        else cout << "no" << endl;
        break;

      case 'p': print(root);
        break;
    }
  }

  return 0;
}



Measured memory_bytes: 9372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int H;
	static int W;
	static int[][]memo;
	static int dp(char[][] grid, int i, int j) {
		if(memo[i][j]!=-1)
			return memo[i][j];
		if (i == H - 1 && j == W - 1) {
			return 1;
		}
		if(grid[i][j]=='#')
			return 0;
		if (i == H - 1)
			if (grid[i][j + 1] == '#')
				return memo[i][j] = 0;
			else
				return memo[i][j] = (int)((dp(grid, i, j + 1))%(Math.pow(10,9)+7));
		if (j == W - 1)
			if (grid[i + 1][j] == '#')
				return memo[i][j] = 0;
			else
				return memo[i][j] = (int)((dp(grid, i + 1, j))%(Math.pow(10,9)+7));
		if (grid[i + 1][j] == '#' && grid[i][j + 1] == '#')
			return 0;
		return memo[i][j] = (int)((dp(grid, i + 1, j))%(Math.pow(10,9)+7) + (dp(grid, i, j + 1))%(Math.pow(10,9)+7));

	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		char[][] grid = new char[H][W];
		memo = new int[H][W];
		for(int[]arr : memo)
			Arrays.fill(arr, -1);
		for (int i = 0; i < H; i++) {
			String str = sc.next();
			for (int j = 0; j < W; j++) {
				grid[i][j] = str.charAt(j);
			}
		}
		System.out.println((int)((dp(grid, 0, 0))%(Math.pow(10,9)+7)));
	}
}





class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++)
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

}


Measured memory_bytes: 32352
def p_c():
    n, m = map(int, input().split())
    _min = n
    _max = 0
    for _ in range(m):
        l, r = map(int, input().split())
        _min = min(_min, r)
        _max = max(_max, l)
    print(max(_min - _max + 1, 0))

p_c()

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int c,n;
    int fun(int);
    while(cin >> n){
    c=fun(n);
    cout << c << endl;
    }
return 0;
}

    int fun(int n){

        int sum1=0;
        int temp,sum2=1;

        int j;
        for(int i=2;i<=n;i++){
            int j=i;
            int cou=0;
            if(j%2!=0)
                continue;
            else{
            while(j%2==0){
            cou++;
            j=j/2;
            }
            }
            if(cou>sum1){
                sum1=cou;
                sum2=i;
            }
        }
     return sum2;
    }


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

c = 0
add = 0
xor = 0
r = 0
for l in range(N):
    # print(l, r, bin(add)[2:], bin(xor)[2:])
    while r < N and add+A[r] == xor^A[r]:
        add += A[r]
        xor ^= A[r]
        r += 1
        # print(l, r, add, xor)
    # l <= i < r までの add と xor が等しい
    c += r - l
    if l == r:
        r += 1
    else:
        add -= A[l]
        xor ^= A[l]
    # print(add, xor, c)

print(c)
    

Measured memory_bytes: 23560
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	long int n;
	cin >> n;
	long long int ans = 0;
	int roop = n / 15;
	int roopP = n % 15;
	for (int i = 0; i < roop; i++) {
		ans += 60 + 8*15*i;
	}
	for (int i = 15*roop + 1; i < n + 1; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String[] hiki = scan.nextLine().split(" ");
    int N = Integer.parseInt(hiki[0]);
    int M = Integer.parseInt(hiki[1]);
    int C = Integer.parseInt(hiki[2]);
    hiki = scan.nextLine().split(" ");
    int[] B = new int[M];
    for(int i = 0;i < M;i ++){
      B[i] = Integer.parseInt(hiki[i]);
    }
    int count = 0;
    for(int i = 0;i < N;i ++){
      int tmp = 0;
      hiki = scan.nextLine().split(" ");
      for(int j = 0;j < M;j ++){
        tmp += Integer.parseInt(hiki[j]) * B[j];
      }
      tmp += C;
      if(tmp > 0){
        count ++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21840
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,a,b,h,ans;
    cin>>a>>b>>h;
    ans=(a+b)*h/2;
    cout<<ans<<endl;


    return 0;
}





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

template<typename T>
class late_update {
  vector<T>& v;
  vector<pair<int, T>> u;
public:
  late_update(vector<T>& a) : v(a)
  {
  }
  void upd(int i, T by) {
    u.push_back({i, by});
  }
  ~late_update() {
    for(auto x : u) {
      v[x.first] = max(v[x.first], x.second);
    }
  }
};

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    vector<ll> dp(W + 1);
    for(int j = 0; j < N; ++j) {
        cin >> w[j] >> v[j];
        late_update<ll> lu(dp);
        for(int i = 0; i <= W - w[j]; ++i) {
          lu.upd(i + w[j], dp[i] + v[j]);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 10000

struct state {
    int v, l, c;
};

bool operator<(const state &a, const state &b) {
    if (a.l != b.l) return a.l > b.l;
    return a.c > b.c;
}

int main(){
    cin.sync_with_stdio(false);
    int n, m;
    int cost[MAX_N];
    vector<state> r[MAX_N];
    while(cin >> n >> m, n | m) {
        fill(cost, cost + n, INF);
        fill(r, r + n, vector<state>());

        rep(i, m) {
            int u, v, l, c;
            cin >> u >> v >> l >> c; u--, v--;
            r[u].pb((state{v, l, c})), r[v].pb((state{u, l, c}));
        }

        priority_queue<state> q;
        q.push(state{0, 0, 0});
        while(!q.empty()) {
            state s = q.top(); q.pop();

            if (cost[s.v] < INF) continue;
            else cost[s.v] = s.c;
            bool ok = true;
            rep(i, n) if (cost[i] == INF) ok = false;
            if (ok) break;

            rep(i, r[s.v].size()) {
                state tmp = r[s.v][i];
                if (tmp.c < cost[tmp.v]) {
                    q.push(state{tmp.v, s.l + tmp.l, tmp.c});
                }
            }
        }

        int ans = 0;
        repl(i, 1, n) ans += cost[i];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5688
from itertools import accumulate

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]

ans = [0] * n
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ans[i + 1] = 1
        
ans = list(accumulate(ans))
for i in lr:
    print(ans[i[1]-1]-ans[i[0]-1])

Measured memory_bytes: 69336
import java.util.Scanner;



public class Main {
	static long count;

	public static void merge(int[] arr, int right, int mid, int left) {
		int n1 = mid - left, n2 = right - mid;
		int[] l = new int[n1 + 1], r = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			l[i] = arr[left + i];
		}
		for (int i = 0; i < n2; i++) {
			r[i] = arr[mid + i];
		}
		l[n1] = Integer.MAX_VALUE;
		r[n2] = Integer.MAX_VALUE;
		int i = 0, j = 0;
		for (int k = left; k < right; k++) {
			if (l[i] <= r[j]) {
				arr[k] = l[i++];
			} else {
				arr[k] = r[j++];
				count += n1 - i;
			}
		}
	}
	public static void mergeSort(int[] arr, int left, int right) {
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(arr, left, mid);
			mergeSort(arr, mid, right);
			merge(arr, right, mid, left);
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		mergeSort(arr, 0, n);
		System.out.println(count);
	}
}


Measured memory_bytes: 102464
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

int main(){
	ll a,b,x,ans;
    cin >> a >> b >> x;
    ans= b/x -a/x;
    if(a%x==0) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
 * test1.cpp
 */

//include files
#include <bits/stdc++.h>

using namespace std;

//DEFINE MACROS

//DEFINE CONSTANT
long long int A,B,C;
int arA[10000];
int acount=0;



//DEFINE PROTOTYPE
bool checkpri(){
  if((A%2==1)||(B%2==1)||(C%2==1)) return true;
  for (int i = 0; i < acount; ++i){
	if(arA[i] == A){
	  acount = -1;
	  return true;
	}
  }
  arA[acount] = A;
  return false;
}

int main(){
  cin >> A;
  cin >> B;
  cin >> C;
  int preA,preB,preC;
  while(1){
	if(checkpri()) break;
	preA = A;
	preB = B;
	preC = C;
	A = preB/2 + preC/2;
	B = preC/2 + preA/2;
	C = preA/2 + preB/2;
	acount++;
  }
  cout << acount << "\n";
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int r,D,newx,x;
    cin >> r >> D >> x;
    newx =x*r-D;
    for(int i=1;i<=10;++i){
       cout << newx <<endl;
        newx = newx*r-D;
       
        
         }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int N;
int H[100];
int X;
int i;
int max=0;

  
  scanf("%d",&N);
for(i=1;i<=N;i++){
scanf("%d",&H[i]);
}
for(i=1;i<=N;i++){
if(max<=H[i]){
  max=H[i];
  X++;
}
}

  printf("%d",X);
return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(float, input().split()))
ans=0
dp=[[0]*(n+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n+1):
    for j in range(1,n+1):
        if i==0:
            dp[i][j]=dp[i][j-1]*(1-p[j-1])
        else:
            dp[i][j]=p[j-1]*dp[i-1][j-1]+(1-p[j-1])*dp[i][j-1]

for i in range(n//2+1,n+1):
    ans+=dp[i][n]
print(ans)

Measured memory_bytes: 259720
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint N,K;
    cin >> N >> K;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint dp[N+1][N+1][3000]={};
    lint ans=0;
    dp[0][0][0]=1;
    rep(i,N) rep(j,N) rep(k,2501){
        dp[i+1][j+1][k+A[i]]+=dp[i][j][k];
        dp[i+1][j][k]+=dp[i][j][k];
    }
    for(int i=1;i<=N;i++) ans+=dp[N][i][i*K];
    cout << ans << endl;
}

Measured memory_bytes: 61184
#include <algorithm>
#include <cmath>
#include <iostream>

#define MAX_N 100000

using namespace std;

struct Test
{
    long long score, upper, lower;

    long long sum();
};

Test tests[MAX_N];
long long cum[MAX_N + 1];
long long N, X;
long long aokiScore;

bool cmp( Test u, Test v ) { return u.sum() > v.sum(); }

long long Test::sum() { return upper * ( X - score ) + lower * score; }

bool isok( long long k )
{
    long long q = k / X;
    long long r = k % X;

    if ( q == N ) return true;

    long long total = cum[q];

    for ( int i = 0; i < N; ++i )
    {
        long long tmp = total;

        if ( i < q )
        {
            tmp -= tests[i].sum();
            tmp += tests[q].sum();
        }

        tmp += min( r, tests[i].score ) * tests[i].lower;
        tmp += max( 0LL, r - tests[i].score ) * tests[i].upper;

        if ( tmp >= aokiScore ) return true;
    }

    return false;
}

int main()
{
    N = 0;
    aokiScore = 0;
    cin >> N >> X;

    for ( int i = 0; i < N; ++i )
    {
        cin >> tests[i].score >> tests[i].lower >> tests[i].upper;
        aokiScore += tests[i].score * tests[i].lower;
    }

    sort( tests, tests + N, cmp );

    for ( int i = 0; i < N; ++i ) cum[i + 1] = cum[i] + tests[i].sum();

    long long l = 0;
    long long r = N * X;

    while ( l < r )
    {
        long long mid = ( l + r ) / 2;

        if ( isok( mid ) )
            r = mid;
        else
            l = mid + 1;
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 3328
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int k,a,b;
  cin >> k >> a >> b;
  if(b/k!=(a-1)/k) {
    cout << "OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3648
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Set<Integer> num=new HashSet<>();
int a=Integer.parseInt(sc.next());
int b=Integer.parseInt(sc.next());
int k=Integer.parseInt(sc.next());
for(int i=a;i<a+k&&i<=b;i++){
num.add(i);
}
for(int i=b;i>b-k&&i>=a;i--){
num.add(i);
}
int[] m=new int[num.size()];
int l=0;
for(int i:num){
m[l]=i;
l++;
}
Arrays.sort(m);
for(int i:m){
System.out.println(i);
}
}}

Measured memory_bytes: 23760
#include <stdio.h>
#include <math.h>

int answer(int);

int main(void)
{
    int n,i,x,ans=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&x);
        ans+=answer(x);
    }
    printf("%d\n",ans);
    
    return 0;
}


int answer(int x)
{
    int i;
    
    if(4>x){
        return 1;
    }else if(x%2==0){
        return 0;
    }else{
        for(i=3;i<=sqrt(x);i+=2){
            if(x%i==0)return 0;
        }
        return 1;
    }
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= (n + a - 1) / a; b++) {
      if (a * b >= n * 2) break;
      int c = n - (a * b);
      if (c > 0) ans++;
      // dump(a, b, c);
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3636