akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 A, B;
	cin >> A >> B;
	int64 K = (A+B)/2;
	if ((A+B) % 2) {
	    cout << "IMPOSSIBLE" << endl;
	} else {
	    cout << K << endl;
	    
	}
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        s: Chars,
    }

    let mut s_1: Vec<char> = s.clone();
    let l = s_1.len();
    for i in 1..l/2 {
        for j in 0..2 {
            s_1.pop();
        }
        let mut ok = true;
        for j in 0..s_1.len()/2 {
            if s_1[j]==s_1[s_1.len()/2+j] {
                continue;
            } else {
                ok = false;
                break;
            }
        }
        if ok==true {
            println!("{}", s_1.len());
            return;
        }
        debug!(s_1);
    }
}


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

using namespace std;

vector <int> g[200000 + 5];
int a[200000 + 5];

int f(int u, int p, int sum) {
  a[u] += sum;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p) continue;
    f(v, u, a[u]);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    a[x-1] += y;
  }
  f(0, -1, 0);
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 26624
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N=200005;
vector<int>vis(N);
vector<vector<int>>adj(N);
void dfs(int v){vis[v]=1;for(auto i:adj[v]){if(!vis[i]){dfs(i);}}return;}
bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
int root(int a[],int i){while(a[i]!=i){a[i]=a[a[i]];i=a[i];}return i;}
void unionn(int a[],int i,int j){int root_i=root(a,i);int root_j=root(a,j);a[root_i]=root_j;return;}
void fun()
{
    #ifndef ONLINE_JUDGE
    freopen("infile.txt", "r", stdin);
    freopen("oufile.txt", "w", stdout);
    #endif
}

int nCr(int n, int r, int p) 
{ 
    // The array C is going to store last row of 
    // pascal triangle at the end. And last entry 
    // of last row is nCr 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; // Top row of Pascal Triangle 
  
    // One by constructs remaining rows of Pascal 
    // Triangle from top to bottom 
    for (int i = 1; i <= n; i++) 
    { 
        // Fill entries of current row using previous 
        // row values 
        for (int j = min(i, r); j > 0; j--) 
  
            // nCj = (n-1)Cj + (n-1)C(j-1); 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
  
// Lucas Theorem based function that returns nCr % p 
// This function works like decimal to binary conversion 
// recursive function.  First we compute last digits of 
// n and r in base p, then recur for remaining digits 
int nCrModpLucas(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
   // Compute last digits of n and r in base p 
   int ni = n%p, ri = r%p; 
  
   // Compute result for last digits computed above, and 
   // for remaining digits.  Multiply the two results and 
   // compute the result of multiplication in modulo p. 
   return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r 
           nCr(ni, ri, p)) % p;  // Remaining digits 
} 

signed main()
{
    flash;
    //fun();
    int t=1;
    //cin>>t;
    while(t--)
    {
    	int n,m;
    	cin>>n>>m;
    	int s=0;
    	if(n>=2)
    		s=s+nCr(n,2,mod);
    	if(m>=2)
    		s=s+nCr(m,2,mod);
    	cout<<s;
    }
    return 0;
}

Measured memory_bytes: 6528
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100;
const int MAX_L = 100;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N][MAX_M], bs[MAX_M][MAX_L];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> as[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++) cin >> bs[i][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      ll ci = 0;
      for (int k = 0; k < m; k++) ci += as[i][k] * bs[k][j];

      if (j) putchar(' ');
      printf("%lld", ci);
    }
    putchar('\n');
  }
  
  return 0;
}

Measured memory_bytes: 1312
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;


int main(){
	string str;
	cin>>str;
	int num1=0;
	int num0=0;
	for(int i=0;i<str.length();i++){
		if(str[i]=='0')
			num0++;
		else
			num1++;
	}
	cout<<2*(min(num1,num0));
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x-a)%b << endl;
	//printf((a<=c&&c<=b) ? "Yes\n" : "No\n");
}

Measured memory_bytes: 384
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()
a,b = LIR(M,2)

count = [0]*(N+1)
for i in range(M):
    count[a[i]] += 1
    count[b[i]] += 1

for i in range(1,N+1):
    if count[i]%2 == 1:
        print('NO')
        exit()

print('YES')

Measured memory_bytes: 96812
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<'\n'
using namespace std;
 

int main() {
	SPEED;
	//freopen("in.txt", "r", stdin);
	string a, b; cin >> a >> b;
	int n = len(a), ok = 0;
	REP(i, 1, n){
		char tmp = a[n - 1];
		FORD(j, n - 1, 1) a[j] = a[j - 1];
		a[0] = tmp;
		if(a == b){
			ok = 1;
			break;
		}
	}
	print(ok ? "Yes" : "No");
	return 0;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
#define mod2 998244353

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
P mx1[1<<18],mx2[1<<18];
signed main(){
    cin>>N;
    rep(i,1<<N){
        cin>>mx1[i].first;
        mx1[i].second=i;
        mx2[i].second=-1;
    }
    int ans=0;
    rep(i,1<<N){
        chmax(ans,mx1[i].first+mx2[i].first);
        if(i)cout<<ans<<endl;
        rep(j,N){
            if(i>>j&1)continue;
            int k=i|(1<<j);
            if(mx1[k].first<=mx1[i].first&&mx1[k].second!=mx1[i].second&&mx2[k].second!=mx1[i].second){
                mx2[k]=mx1[k];
                mx1[k]=mx1[i];
            }else if(mx2[k].first<=mx1[i].first&&mx2[k].second!=mx1[i].second&&mx1[k].second!=mx1[i].second){
                mx2[k]=mx1[i];
            }
            if(mx2[k].first<=mx2[i].first&&mx2[k].second!=mx2[i].second&&mx1[k].second!=mx2[i].second){
                mx2[k]=mx2[i];
            }
        }
    }
}

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

using namespace std;

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

    if (a >= 6 and a <= 12) {
        b /= 2;
    } else if (a <= 5) {
        b = 0;
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 384
from itertools import combinations_with_replacement, combinations

n, m, q = map(int, input().split())

abcd = [tuple(map(int, input().split())) for _ in range(q)]

l = {(a-1, b-1, c): d for a, b, c, d in abcd}

r = 0
for poses in combinations_with_replacement(range(m), n):
    s = 0
    for pos in combinations(enumerate(poses), 2):
        k = (pos[0][0], pos[1][0], pos[1][1]-pos[0][1])
        if k in l:
            s = s + l[k]
    if s > r:
        r = s

print(r)


Measured memory_bytes: 9068
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        string s = Console.ReadLine();
        int N = s.Length;
        int canbattle = 15 - N;
        int win = 0;
        int lose = 0;
        for (int i = 0; i < N; i++)
        {
            if (s[i] == 'x') lose++;
            else win++;
        }
        win += canbattle;
        string output = "";
        if (win >= 8) output = "YES";
        else output = "NO";
        Console.WriteLine(output);
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


int n, m, ans;
int k[20];
int s[20][20];
int p[20], f[20];

void dfs(int x) {
	if (x == n) {
		int total = 0;
		rep (i, m) {
			int cnt = 0;
			rep(j, k[i]) {
				if (f[s[i][j] - 1]) {
					cnt++;
				}
			}
			if (cnt % 2 == p[i]) total++;
		}
		if (total == m)ans++;
		return;
	}
	f[x] = 1;
	dfs(x + 1);
	f[x] = 0;
	dfs(x + 1);
	return;
}

int main() {

	cin >> n >> m;
	rep(i, m) {
		cin >> k[i];
		rep(j, k[i])cin >> s[i][j];
	}
	rep(i, m)cin >> p[i];

	dfs(0);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define PQ priority_queue
#define mx(a) *max_element(a)
#define mn(a) *min_element(a) 
#define LB lower_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE 
#define UB upper_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE 

#define fr first
#define sc second

#define MAXN 10000010
#define INF 9223372036854775807
int spf[MAXN+5];
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
        spf[i] = i; 
  
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) 
  
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
 
int generatePrimeFactors(int N) 
{ 
    vector<int> vec;
    int curr = spf[N];   
    int cnt = 1;   
  
  
    while (N > 1) 
    { 
        N /= spf[N]; 
 
        if (curr == spf[N]) 
        { 
            cnt++; 
            continue; 
        } 
  
		vec.push_back(cnt); 
		
        curr = spf[N]; 
        cnt = 1; 
    } 
    int res=1;
    for(auto i:vec){
    	res*=(i+1);
	}
	return res;
} 
signed main(){
    fastio
    sieve();
    int n,ans=0;
    cin>>n;
    f(i,1,n+1)
    	ans+=i*generatePrimeFactors(i);
	cout<<ans;
    
}

Measured memory_bytes: 81700
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp_e, mp_o;
  REP(i, n) {
    ll v;
    cin >> v;
    if (i % 2 == 0) {
      mp_e[v]++;
    } else {
      mp_o[v]++;
    }
  }
  ll e1 = 0, e2 = 0, o1 = 0, o2 = 0;
  ll e, o;
  for (auto x : mp_e) {
    if (x.second > e1) {
      e1 = x.second;
      e = x.first;
    }
  }
  for (auto x : mp_o) {
    if (x.second > o1) {
      o1 = x.second;
      o = x.first;
    }
  }
  for (auto x : mp_e) {
    if (x.second > e2 && x.first != e) {
      e2 = x.second;
    }
  }
  for (auto x : mp_o) {
    if (x.second > o2 && x.first != o) {
      o2 = x.second;
    }
  }
  ll ans;
  if (e == o) {
    ans = min(n - e1 - o2, n - e2 - o1);
  } else {
    ans = n - e1 - o1;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;




int main(){
	int n,l,i;
	cin>>n>>l;
	int arr[n],m=INT_MAX,totalsum(0),choosedapple(0);
	for(i=0;i<n;i++){
		arr[i]=l+i;
		totalsum+=arr[i];
		if(abs(arr[i])<m){
			m=abs(arr[i]);
			choosedapple=arr[i];
		}
	}
	cout<<totalsum-choosedapple;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
	int n,x,date[100],i=0;
	
	scanf("%d",&n);
	
	while(i != n){
		scanf("%d",&date[i]);
		++i;
	}
	
	i = 0;
	
	while(i != n/2){
		x = date[i];
		date[i] = date[n-i-1];
		date[n-i-1] = x;
		++i;
	}
	
	i = 0;
	
	while(1){
		printf("%d",date[i]);
		if(i == n-1){break;}
		printf(" ");
		++i;
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main()
{
	long long n,m,k,a[200011]={},b[200011]={},t=0,i;

	scanf("%lld%lld%lld",&n,&m,&k);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]+=a[i-1];
	}
	for(i=1;i<=m;i++){
		scanf("%lld",&b[i]);
		b[i]+=b[i-1];
	}

	for(i=0;i<=n;i++){
		while(m>0&&a[i]+b[m]>k)
			m--;
		if(a[i]+b[m]<=k)
			t=i+m>t?i+m:t;
	}
	printf("%lld",t);
	return 0;
}

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

using namespace std;
using int64 = long long;

int64 gcd(int64 a, int64 b) { return b? gcd(b,a%b) : a;}

int main() {
    int64 n,x;
    cin >> n >> x;
    vector<int64> a(n);
    for (int i=0; i<n; i++) cin >> a[i];


    int64 ans = abs(a[0] - x);
    for (int i=0; i<n; i++) {
        ans = gcd(ans, abs(a[i] - x));
        x = a[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x,l;cin>>n>>x;
  lvector L(n+1,0);rep(i,n) {cin>>l;L[i+1]+=L[i]+l;}
  ll ans=n+1;
  rep(i,n+1) if(L[i]>x) {ans=i;break;}
  print(ans);
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll,ll> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

int main() {
   ll n,q; cin >> n >> q;
   string s; cin >> s;
   vector<ll> sum(n);
   rep(i,n){
      if(s[i]=='A' && s[i+1]=='C') sum[i+1]=sum[i]+1;
      else sum[i+1]=sum[i];
   }
   rep(i,q){
      ll l,r; cin >> l >> r;
      l--; r--;
      cout << sum[r]-sum[l] << endl;
   }
}



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

int main(){
    int n;
    cin >> n;
    int flag = 0;
    int tmp = 0;
    for(int i = 0; i < 3; i++){
        tmp = n % 10;
        n = n / 10;
        if(tmp == 7){
            flag = 1;
        }
    }
    if(flag == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
# include <bits/stdc++.h>
// #define INF 9223372036854775807
# define INF 1e9
using namespace std;

int main(){

  int N, M;
  cin >> N >> M;
  long int X[M];
  for(int i=0; i< M; i++){
    cin >> X[i];
  }

  long int ans = 0;
  if(M == 1){
    ans = 0;
  } else{
    sort(X, X+M);
    vector<long int> dist;
    for(int i=0; i< M-1;i++){
      dist.push_back(X[i+1] - X[i]);
    }
    sort(dist.begin(), dist.end());

    for(int i=0; i< N-1; i++){
      dist.pop_back();
      if(dist.size() == 0){
        break;
      }
    }

    for(int i=0; i< dist.size();i++){
      ans += dist[i];
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
struct __test {} test;
using namespace std;
template <typename T>const __test &operator<<(const __test& d,
const T& v) {return cerr << "\033[31m" << v << "\033[0m",d;}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;



int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int a,b;
	cin >> a >> b;
	if(a <= 0 && b >= 0) cout << "Zero\n";
	else if(1 <= a || (min(-1,b)-1+a)%2==0) cout << "Positive\n";
	else cout << "Negative\n";
	
	
	return 0;
}

Measured memory_bytes: 256
r, g, b = map(int, input().split())
k = int(input())

def e(r, g, b):
    return g > r and b > g

from itertools import product
for pp in product([0, 1, 2], repeat=k):
    rr = r
    gg = g
    bb = b
    for p in pp:
        if p == 0:
            rr *= 2
        elif p == 1:
            gg *= 2
        else:
            bb *= 2
    if e(rr, gg, bb):
        print('Yes')
        break
else:
    print('No')


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

using namespace std;


int main(void){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> l = vector<int>();
  l.reserve(n);
  l.push_back(0);
  for(int i = 0; i < n-1; ++i){
    l.push_back(l[i]);
    if (s[i] == 'W')
      l[i+1]++;
  }
  vector<int> r = vector<int>();
  r.reserve(n);
  r.push_back(0);
  for(int i = 0; i < n-1; ++i){
    r.push_back(r[i]);
    if (s[n-1-i] == 'E')
      r[i+1]++;
  }
  int min = n;
  for(int i = 0; i < n; ++i){
    int var = r[n-1-i] + l[i];
    if (min > var)
      min = var;
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 3076
#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<char> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

vector<string> v;

int main(){
  cin.sync_with_stdio(false);
  string s, tmp, check;
  while(cin >> s, s[0] != '#') {
    v.clear();
    set<string> set;
    rep(i, 1 << s.length()) {
      tmp = s;
      rep(j, s.length()) {
        if (((1 << j) & i) && tmp[j] < 'z') tmp[j] = (char)(tmp[j] + 1);
      }

      check = tmp;
      bool alphabet[26] = {};
      rep(i, check.length()) {
        if (check[i] > 'a' && !alphabet[check[i] - 'a']) {
          alphabet[check[i] - 'a'] = true;
          check[i] = (char)(check[i] - 1);
        }
      }

      if (check == s) set.insert(tmp);
    }

    each(itr, set) v.pb(itr);
    sort(all(v));

    cout << v.size() << endl;
    if (v.size() > 10) {
      rep(i, 5) cout << v[i] << endl;
      repr(i, 5) cout << v[v.size() - i - 1] << endl;
    } else {
      rep(i, v.size()) cout << v[i] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 5196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#define N 601000
typedef long long ll; 
template<typename T> inline void read(T &x) { 
  x = 0; char  c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
}
using namespace std;
const int P = 924844033;
const int G = 5;
int Gi; 
inline ll quickpow(ll x, int k) {
  ll res = 1;
  while (k) {
    if (k & 1)  res = res * x % P;  
    x = x *x  % P;
    k >>= 1;
  }
  return res;
}
int n;
struct edge{
  int nxt, to; 
}e[N << 1]; 
int head[N], ecnt;
inline void addedge(int from, int to) {
  e[++ecnt] = (edge){head[from], to};
  head[from] = ecnt;
}

int siz[N], dep[N], fa[N];
void dfs_son(int cur, int faa) {
  siz[cur] = 1, fa[cur] = faa;
  for (int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to; if (to == faa)  continue;
    dfs_son(to, cur);
    siz[cur] += siz[to];
  }
}

int cnt[N];
ll f[N], g[N], A[N], ans[N];
int limi, L, r[N];
inline void ntt(ll *a, int type) {
  for (int i = 1; i < limi; ++i)
    if (i < r[i]) swap(a[i], a[r[i]]);
  for (int i = 1; i < limi; i <<= 1) {
    ll T = quickpow(type == 1 ? G : Gi, (P - 1) / (i << 1));
    for (int j = 0; j < limi; j += (i << 1)) {
      ll t = 1;
      for (int k = 0; k < i; ++k, t = t * T % P) {
        ll nx = a[j + k], ny = t * a[j + k + i] % P;
        a[j + k] = (nx + ny) % P;
        a[j + k + i] = (nx - ny + P) % P;
      }   
    }   
  }
  if (type == -1) {
    ll inv = quickpow(limi, P - 2); 
    for (int i = 0; i < limi; ++i)  a[i] = a[i] * inv % P;
  }
}

ll jie[N], jieni[N];
inline ll get_c(int n, int m) {
  if (n < 0 || m < 0 || n - m < 0)  return 0;
  return jie[n] * jieni[m] % P * jieni[n - m] % P;
}
inline void work() {
  limi = 1;
  while (limi <= n + n + 2) limi <<= 1, ++L;
  for (int i = 0; i <= limi; ++i)
    r[i] = (r[i >> 1] >> 1) | ((i & 1) << (L - 1));
  ntt(f, 1), ntt(g, 1); 
  for (int i = 0; i < limi; ++i)  A[i] = f[i] * g[i] % P;
  ntt(A, -1);
//  for (int i= 0; i <= n; ++i)	printf("A(yuan)[%d] = %lld\n", i, A[n - i]);
  for (int k = 1; k <= n; ++k) {
    ll ans = (1ll * n * get_c(n, k) % P - jieni[k] * A[n - k] % P) % P;
//    printf("%d * %lld - %lld * %lld = \n", n, get_c(n, k), jie[k], A[n - k]);
    printf("%lld\n", (ans % P + P) % P); 
  }
}

inline void init() {
  jie[0] = jieni[0] = 1;
  int up = n + 10; 
  for (int i = 1; i <= up; ++i) jie[i] = jie[i - 1] * i % P;
  jieni[up] = quickpow(jie[up], P - 2); 
  for (int i = up - 1; i; --i)  jieni[i] = jieni[i + 1] * (i + 1) % P;
  Gi = quickpow(G, P - 2); 
}

int main() {
  read(n); init();
  for (int i = 1; i < n; ++i) {
    int u, v; read(u), read(v); addedge(u, v), addedge(v, u); 
  }
  dfs_son(1, 0); 
  for (int i = 2; i <= n; ++i) {
    ++cnt[siz[i]], ++cnt[n - siz[i]];
  }
  for (int i = 0; i <= n; ++i)  f[i] = 1ll * cnt[n - i] * jie[n - i] % P;
  for (int i = 0; i <= n; ++i)  g[i] = jieni[i];
//  for (int i = 0; i <= n; ++i)	printf("f[%d] = %lld, g = %lld\n", i, f[i], g[i]);
  work();
  return 0;
}

/*
3
1 2
2 3
//3 7 3
*/

Measured memory_bytes: 34880
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    ll n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector <ll> v;
    ll now = 0;
    for(ll i=0;i<n;i++){
        if(i!=0 and s[i] == 'C' and s[i-1] == 'A'){
            now++;
        }
        v.push_back(now);
    }
    for(ll i=0;i<q;i++){
        ll l,r;
        cin >> l >> r;
        cout << v[r-1] - v[l-1] << endl;
    }


}



Measured memory_bytes: 1908
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define For(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define repd(i,j) for(int (i)=(j);(i)>=0;(i)--)
#define Ford(i,j,k) for(int (i)=(j);i>=(k);i--)
#define vfor(c,v) for(auto (c): v)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using pii = std::pair<int,int>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 10241024;
const ll INFL = (1ll << 62) - 1;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
//_____________________　following sorce code_________________________//
int n,m,k;
//vvll dp(400, vll(400));
string S;
vll cost(1 << 16);
int a,b,c;
int h,w;
vvi v;
vll u;

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  IN(S);
  reverse(All(S));
  S += '0';
  int n = sz(S);
  vvi dp(n+4,vi(2, INF));
  dp[0][0] = 0;
  rep(i,n)rep(j,2){
    int x = S[i] - '0';
    if(j == 1)x++;
    rep(k,10){
      int ni = i+1, nj = 0;
      int a = k - x;
      if(a < 0){
        a += 10;
        nj = 1;
      }
      chmin(dp[ni][nj] , dp[i][j] + a + k);
    }
  }
  OUT(dp[n][0]);
  //cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 56476
#include<bits/stdc++.h>
using namespace std;
int f(int x,int y,int z){
    return (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
}
int a[100007];
int main()
{
    int n;
    cin>>n;
    int n1=sqrt(n);
    for(int i=1;i<=n1;i++){
        for(int j=1;j<=n1;j++){
            for(int k=1;k<=n1;k++){
                int x=f(i,j,k);
                if(x<=n) a[x]++;
            }
        }
    }
    for(int i=1;i<=n;i++) cout<<a[i]<<endl;
    return 0;
}


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

using namespace std;

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

    int n;
    cin >> n;
    vector<pair<string, int> > v;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        int q;
        cin >> s >> q;
        v.push_back({s,q});
    }
    string x;
    cin >> x;
    bool seen = false;
    for (int i = 0; i < n; i++) {
        if (seen) ans += v[i].second;
        if (v[i].first == x) seen = true;
    }


    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int c=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(a[i]==a[j])
			continue;
			for(int k=j+1;k<n;k++)
			{
				if(a[i]==a[k])continue;
				if(a[j]==a[k])continue;
				if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
				c++;
			}
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 3552
#include<stdio.h>
#include<stdlib.h>
#define N 100

int p[N],m[N][N];
 int n;
void matrixChain();

int main(){

  int i;

  scanf("%d",&n);
  for(i=1; i <=n; i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
 
  //fprintf(stderr,"err\n");
  matrixChain();
printf("%d\n",m[1][n]);
  return 0;
}

void matrixChain(){
  int t,k;
  int i,j;
  int l;

  for(i=1; i < n; i++){
    m[i][j]=0;
  }

  for(l=2; l <= n; l++){
    for(i=1; i <= n-l+1; i++){
      j=i+l-1;
      m[i][j]=1000000;
    for(k=i; k < j; k++){
      t=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      if(t < m[i][j]) m[i][j]=t;
    }
  }
  }
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    int a,b;
    while(cin>>a){
        cin>>b;
        cout<<a+b<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3072
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, M) = nextIntList()
    val A = PriorityQueue<Long>(N) { o1, o2 -> o2.compareTo(o1) }
    A.addAll(nextLongList())
    repeat(M) {
        val max = A.poll()
        A.add(max / 2)
    }
    println(A.sum())
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans;
    if (a >= 13) {
        ans = b;
    } else if (a >= 6) {
        ans = b / 2;
    } else {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

ll dp[1005][1005];

int main()
{
    ll q;
    cin >> q;
    rep(w,q){
        string s,t;
        cin >> s >> t;
        ll n=s.length();
        ll m=t.length();
        rep(i,n+5){
            rep(j,m+5){
                dp[i][j]=0;
            }
        }
        rep(i,n){
            rep(j,m){
                if(s[i]==t[j]){
                    dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
                }
                else{
                    dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
                }
            }
        }
        cout << dp[n][m] << endl;
        
    }
    
    return 0;
} 


Measured memory_bytes: 11048
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
B=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
U=[0]*N

for c,d in B:
  i,mv,mi=0,-1,0
  for a,b in R:
    if a<c:
      if b<d and U[i]==0:
        if mv<b:
          mv,mi=b,i
      i+=1
    else:
      break

  if mv!=-1:
    U[mi]=1

print(sum(U))


Measured memory_bytes: 3064
#include <cstdio>
#include <utility>
#include <cmath>

using namespace std;

void rec(pair<double,double> x,pair<double,double> y,int n){
  if(n<=0) return;
  pair<double,double> t=make_pair((2*y.first+x.first)/3,(2*y.second+x.second)/3);
  pair<double,double> s=make_pair((y.first+2*x.first)/3,(y.second+2*x.second)/3);
  double u_1=(s.first+t.first)/2+sqrt(3)*(s.second-t.second)/2;
  double u_2=(s.second+t.second)/2+sqrt(3)*(t.first-s.first)/2;
  pair<double,double> u=make_pair(u_1,u_2);
  rec(x,s,n-1);
  printf("%lf %lf\n",s.first,s.second);
  rec(s,u,n-1);
  printf("%lf %lf\n",u.first,u.second);
  rec(u,t,n-1);
  printf("%lf %lf\n",t.first,t.second);
  rec(t,y,n-1);
}

int main(){
  int n; scanf("%d",&n);
  const pair<double,double> p_1=make_pair(0,0);
  const pair<double,double> p_2=make_pair(100,0);
  printf("%lf %lf\n",p_1.first,p_1.second);
  rec(p_1,p_2,n);
  printf("%lf %lf\n",p_2.first,p_2.second);
}

Measured memory_bytes: 2736
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int main()
{
    int n;
    cin >> n;
    printf("%.20f\n", 2*n*PI);
    
}

Measured memory_bytes: 3780
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    for(;;){
        int n, m, c;
        cin >> n >> m >> c;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(n*n);
        for(int i=0; i<m; ++i){
            int f, t, ci;
            cin >> f >> t >> ci;
            -- f;
            -- t;
            for(int j=0; j<n; ++j)
                edges[f+j*n].push_back(Edge(t+j*n, ci));
            for(int j=0; j<n-1; ++j)
                edges[f+j*n].push_back(Edge(t+(j+1)*n, 0));
        }

        vector<int> dist;
        shortestPath(edges, 0, dist);
        int i = 0;
        while(dist[n-1+n*i] > c)
            ++ i;
        cout << i << endl;
    }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5 + 7;
int n, m, a[MAXN], ans;
int check(int x)
{
    ans = 0;
    for (int i = 1, sum; i <= x; i++) 
    {
        if (a[i] + a[2 * x + 1 - i] >= m) return 1;
        sum = a[i] + a[2 * x + 1 - i];
        ans = max(ans, sum >= m ? sum - m : sum);
    }
    for (int i = 2 * x + 1, sum; i <= 2 * n; i++)
    {
        if (a[i] + a[2 * (n + x) + 1 - i] < m) return 2;
        sum = a[i] + a[2 * (n + x) + 1 - i];
        ans = max(ans, sum >= m ? sum - m : sum);
    }
    return 0;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + 2 * n);
    int l = 0, r = n; 
    while (l < r)
    {
        int mid = (l + r) >> 1;
        int ck = check(mid);
        if (ck == 0 || ck == 1) r = mid;
        else l = mid + 1;
    }
    check(l);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	int m, f, b;
	cin >> m >> f >> b;
	if (m >= b) cout << 0 << endl;
	else if (m + f >= b) cout << b - m << endl;
	else cout << "NA" << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

const int inf=1<<28;

int dp[1010];
bool can[1010][1010];
int w[1010],c[1010];

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> c[i] >> w[i];
	rep(i,n) w[i+1]+=w[i],can[i][i+1]=true;
	for(int d=2;d<=n;++d){
		for(int i=0;i+d<=n;++i){
			if(can[i+1][i+d]){
				int cur=w[i+d-1]-w[i];
				if(c[i]>=cur) can[i][i+d]=true;
			}
			if(can[i][i+d-1]){
				int cur=w[i+d-2];
				if(i-1>=0) cur-=w[i-1];
				if(c[i+d-1]>=cur) can[i][i+d]=true;
			}
		}
	}
	rep(i,n+1) dp[i]=inf;
	dp[0]=0;
	rep(i,n)rep(j,n) if(can[i][j+1]) dp[j+1]=min(dp[j+1],dp[i]+1);
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 2160
from itertools import accumulate

N = int(input())
A = list(accumulate([int(i) for i in input().split()]))
B = list(accumulate([int(i) for i in input().split()][::-1]))[::-1]

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

print(ans)


Measured memory_bytes: 9100
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vl = vector<ll>;
    using vvl = vector<vl>;
    using pll = pair<ll,ll>;
    using vb = vector<bool>;
    const ll oo = 0x3f3f3f3f3f3f3f3fLL;
    const double eps = 1e-9;
    #define sz(c) ll((c).size())
    #define all(c) begin(c),end(c)
    #define mp make_pair
    #define mt make_tuple
    #define pb push_back
    #define eb emplace_back
    #define xx first
    #define yy second
    #define has(c,i) ((c).find(i) != end(c))
    #define FOR(i,a,b) for (int i=(a); i<(b); i++)
    #define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

    vl lis;
    ll LIS(vl & v) {
        lis.assign(sz(v), 0);
        vl minval(1);
        ll maxlen = 0;
        minval[0] = LLONG_MIN;
        FOR (i, 0, sz(v)) {
            lis[i] = lower_bound(all(minval), v[i]) - minval.begin();
            if (lis[i] > maxlen) {
                maxlen = lis[i];
                minval.push_back(v[i]);
            } else {
                minval[lis[i]] = min(minval[lis[i]], v[i]);
            }
        }
        return maxlen;
    }


    int main() {
    	const long double ARC = atan(1) * 4 * 5;

    	ll x1, y1, x2, y2, NN;
    	cin >> x1 >> y1 >> x2 >> y2 >> NN;
    	vector<pll> v(NN);
    	FOR(i,0,NN) cin >>v[i].first >> v[i].second;


    	if (x1 > x2) {
    		swap(x1, x2);
    		swap(y1, y2);
    	}
    	if (y1 > y2) {
    		y2 = y1 - y2;
    		FOR(i,0,NN) v[i].second = y1 - v[i].second;
    		y1 = 0;
    	}

    	if (x1 == x2) {
    		long double doof = 0;
    		FOR(i,0,NN) if (v[i].first == x1 && v[i].second > y1 && v[i].second < y2) doof = 2 * ARC  - 20;
    		printf("%.*Lf\n", 18, 100 * (y2 - y1) + doof);
    		return 0;
    	}
    	if (y1 == y2) {
    		long double doof = 0;
    		FOR(i,0,NN) if (v[i].second == y1 && v[i].first > x1 && v[i].first < x2) doof = 2 * ARC  - 20;
    		printf("%.*Lf\n", 18, 100 * (x2 - x1) + doof);
    		return 0;
    	}
    	sort(all(v));

    	vector<ll> choose;
    	int idx = 0;

    	while (idx < NN && v[idx].first < x1) idx++;
    	int smallest = idx;
    	while (idx < NN && v[idx].first <= x2) {
    		if (v[idx].second >= y1 && v[idx].second <= y2) {
    			choose.pb(v[idx].second);
    		}
    		idx++;
    	}
    	ll N = choose.size();
    	ll best = LIS(choose);


    	long double kack = 0;
    	if (best == min(x2-x1+1, y2-y1+1)) {
    		kack = ARC;
    	}
    	printf("%.*Lf\n", 18, 100 * (x2 - x1 + y2 - y1) + best * (atan(1) * 20 - 20) + kack);

   }

Measured memory_bytes: 9584
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define range(x,l,r) (l<=x && x<r)
#define chmax(a,b) (a = max(a,b))
using namespace std;

const int dy[] = {0,1,0,-1}, dx[] = {1,0,-1,0};
int dp[50][50][4][1<<12];
int vis[1<<12];

inline int visit(int bit){
  if(vis[bit]>=0)return vis[bit];

  int y=0, x=0, b=bit;
  rep(i,6){
    y += dy[b&3], x += dx[b&3]; b>>=2;
    if(y==0 && x==0)return vis[bit] = 1;
  }
  return vis[bit] = 0;
}

int main(){
  int h,w,k;
  string g[50];
  cin >> h >> w >> k;
  rep(i,h)cin >> g[i];

  memset(vis,-1,sizeof(vis));
  memset(dp,-1,sizeof(dp));
  dp[0][0][0][0] = isdigit(g[0][0])?(int)(g[0][0]-'0'):0;

  rep(rev,k+1){
    rep(y,h)rep(x,w){
      if(g[y][x] == '#')continue;
      rep(bit,1<<12){
	if(dp[y][x][rev][bit]<0)continue;

	rep(d,4){
	  if(rev==k && d>1)break;
	  int ny = y+dy[d], nx = x+dx[d];
	  if(!range(ny,0,h) || !range(nx,0,w))continue;
	  if(g[ny][nx] == '#')continue;

	  int nbit = ((bit<<2)|d) & ((1<<12)-1);
	  int item = isdigit(g[ny][nx])?(int)(g[ny][nx]-'0'):0;
	  if(visit(nbit))item = 0;

	  if(d<2){
	    chmax(dp[ny][nx][rev][nbit], dp[y][x][rev][bit] + item);
	  }else{
	    chmax(dp[ny][nx][rev+1][nbit], dp[y][x][rev][bit] + item);
	  }
	}
      }
    }
  }

  int res = 0;
  rep(bit,1<<12)chmax(res, dp[h-1][w-1][k][bit]);
  cout << res << endl;
}

Measured memory_bytes: 161240