akhauriyash/Code-Regression huggingface dataset:
import sys
H,W=map(int,input().split())
smap=[input() for i in range(H)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]

for i in range(H):
    for j in range(W):
        if(smap[i][j]=='#'):
            t=True
            for k in range(4):
                ni=i+dx[k]
                nj=j+dy[k]
                if(ni<0 or ni>=H or nj<0 or nj>=W):
                    continue
                if(smap[ni][nj]=='#'):
                    t=False
            if(t):
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 3064
use proconio::input;
use std::cmp::max;
use std::collections::HashMap;
#[allow(unused_mut)]
fn main() {
    input! {
        n: usize,
        s: [String; n]
    }
    let s: Vec<String> = s;
    let mut maxi = 0;
    let mut map = HashMap::new();
    for i in s.iter() {
        let count = map.entry(i).or_insert(0);
        *count += 1;
        maxi = max(maxi, *count);
    }
    let mut res = Vec::new();
    for (i, j) in map.iter() {
        if maxi == *j {
            res.push(i);
        }
    }
    res.sort();
    res.iter().for_each(|i| println!("{}", i));
}


Measured memory_bytes: 21436
import itertools
n = int(input())
dic = {"M":0, "A":0, "R":0, "C":0, "H": 0}
R = ["M", "A", "R", "C", "H"]
for i in range(n):
    s = input()
    if s[0] in R:
        dic[s[0]] += 1

num = 0
for i, j, k in itertools.combinations(R, 3):
    num += dic[i]* dic[j] * dic[k]

print(num)

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

#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second

ll n;

int main()
{
    boost;
    if(fopen("inp.txt", "r")) {
      freopen("inp.txt", "r", stdin);
      freopen("outp.txt", "w", stdout);
    }

    cin>>n;

    ll i,j,k,a[n+1][n+1],dist[n+1][n+1];
    bool indirect[n+1][n+1];

    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++) {
            cin>>a[i][j];
            dist[i][j]=a[i][j];
            indirect[i][j]=false;
        }

    ll ans=0;

    for (k=1;k<=n;k++) {
        for (i=1;i<=n;i++) {
            for (j=1;j<=n;j++) {
                if (k==i || k==j)
                    continue;

                if (dist[i][k]+dist[k][j]<dist[i][j]) {
                    cout<<"-1\n";
                    return 0;
                }

                else if (dist[i][k]+dist[k][j]==dist[i][j]) {
                    indirect[i][j]=true;
                }
            }
        }
    }

    for (i=1;i<=n;i++)
        for (j=i+1;j<=n;j++)
            if (!indirect[i][j])
                ans+=dist[i][j];

    cout<<ans;

}

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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    string s;
    cin >> s;

    int ans=0;

    FOR(i,1,s.length()){
        if(s[i]!=s[i-1]){
            ans++;
        }
    }

    cout << ans << ENDL;
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int a[4], n;
int main(){
  cin >> n;
  for(int i=0; i<4; i++){
  a[i] = n%10;
  n /= 10;
    }
  if((a[0] == a[1]) && (a[1] == a[2]) || (a[1] == a[2]) && (a[2] == a[3])) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
  }

Measured memory_bytes: 256
import sys
N=int(input())
lst=[]
for i in range(N):
  if i==0:
    lst.append(list(str(input())))
  else:
    s=list(str(input()))
    if s not in lst and lst[-1][-1]==s[0]:
      lst.append(s)
    else:
      print('No')
      sys.exit()
print('Yes')

Measured memory_bytes: 3060
n=int(input())
add=list(map(int,input().split()))
add.insert(0,0)
add.append(0)
count=0
for i in range(n+1):
    count +=abs(add[i]-add[i+1])
for i in range(1,n+1):
    print(count-(abs(add[i-1]-add[i])+abs(add[i]-add[i+1]))+(abs(add[i-1]-add[i+1])))

Measured memory_bytes: 63980
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int dp[105][105];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	rep(i, 105) rep(j, 105) dp[i][j] = 1e9;
	dp[0][0] = (s[0][0] == '#');
	rep(i, h) rep(j, w){
		if(!i && !j) continue;
		if(i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (s[i][j] == '#'));
		if(j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (s[i][j] == '#'));
		for(int i1 = i - 1; i1 >= 0; i1--){
			if(s[i1][j] == '#') dp[i][j] = min(dp[i][j], dp[i1][j]);
			else break;
		}
		for(int j1 = j - 1; j1 >= 0; j1--){
			if(s[i][j1] == '#') dp[i][j] = min(dp[i][j], dp[i][j1]);
			else break;
		}
	}
	int ans = dp[h - 1][w - 1];
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 384
n,m,x=gets.chomp.split(" ").map(&:to_i)
a_arr=gets.chomp.split(" ").map(&:to_i)

l_count = 0
r_count = 0
a_arr.each do |a|
  if a < x then
    l_count += 1
  else
    r_count += 1
  end
end

if l_count > r_count then
  puts r_count
else
  puts l_count
end






Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int n, ar[200001] = {}, x = 0;
int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {cin >> ar[i]; x ^= ar[i];}
	for (int i = 0; i < n; i++)
	{
		cout << (x ^ ar[i]);
		if (i < n - 1) cout << " ";
	}
	cout << "\n";
	return 0;
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;
const ll MOD = 1e9+7;
int n, k;
ll dp[101][MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
//    cout<< setprecision(2)<< fixed;
    cin>> n>> k;
    int arr[n];
    forn(i,n){
        cin>> arr[i];
    }
    sort(arr, arr+n);
    forn(i,arr[0]+1){
        dp[1][i]=1;
    }
    fore(i,2,n){
        forn(j, k+1){
            if(j==0){
                dp[i][j]= 1;
            }else if(j<=arr[i-1] ){
                dp[i][j]= (dp[i-1][j] + dp[i][j-1])%MOD;
            }else{
                dp[i][j]= (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-arr[i-1]-1] +MOD)%MOD;
            }
        }
    }
//    for(int j=k; j>=0 ; --j){
//        for(int i=0; i<=n; ++i){
//            cout<< dp[i][j]<< " ";
//        }
//        cout<<el;
//    }
    cout<< dp[n][k] <<el;
}


Measured memory_bytes: 78464
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    X, K, D = map(int, input().split())
    divD = abs(X)//D
    if K <= divD:
        ans = abs(X) - D*K
    elif X%D != 0:
        if (K - divD)%2 == 0:
            ans = abs(X)%D
        else:
            ans = -abs(X)%D
    else:
        if (K - divD)%2 == 0:
            ans = abs(X)%D
        else:
            ans = D
    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	cout << (n+2*k)/(2*k+1) << endl;

}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
while(true){
int H=sc.nextInt();
int W=sc.nextInt();
if(H==0 && W==0){
break;
}
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
if(j%2==1){
if(i%2==1){
System.out.printf("#");
}else{
System.out.printf(".");
}
}else{
if(i%2==1){
System.out.printf(".");
}else{
System.out.printf("#");
}}}
System.out.printf("\n");
}
System.out.printf("\n");
}
sc.close();
}}


Measured memory_bytes: 64904
/*input
8
1 2 1 4 2 1 4 1
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

ll func(ll n)
{
  return (n * (n - 1)) / 2;
}

int main()
{
  ifalse;
  int n;
  cin >> n;
  map < int, int > mp;
  vector < int > v(n);
  for(auto &x: v) {
    cin >> x;
    mp[x] ++;
  }

  ll ans = 0;
  for(auto x: mp) {
    if(x.second <= 1) continue;
    ans += func(x.second); 
  }

  for(auto x: v) {
    if(mp[x] <= 1) {
      cout << ans, nl;
    } else if(mp[x] == 2) {
      cout << ans - 1, nl;
    } else {
      cout << ans - func(mp[x]) + func(mp[x] - 1), nl;
    }
    
  }
  return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    string a[3];
    rep(i, 0, 3) cin >> a[i];
    string ans = "";
    rep(i, 0, 3) ans += (a[i][0] - 'a' + 'A');
    cout << ans << "\n";
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            long H = in.nextInt();
            long W = in.nextInt();

            long min = (long) 1e18;
            for (long h1 = 1; h1 < H; h1++) {
                long area1 = h1 * W;
                {
                    long h2 = (H - h1) / 2;
                    long area2 = h2 * W;
                    long h3 = H - (h1 + h2);
                    long area3 = h3 * W;
                    long maxArea = Math.max(area1, Math.max(area2, area3));
                    long minArea = Math.min(area1, Math.min(area2, area3));
                    min = Math.min(min, maxArea - minArea);
                }
                {
                    long w2 = W / 2;
                    long area2 = (H - h1) * w2;
                    long w3 = W - w2;
                    long area3 = (H - h1) * w3;
                    long maxArea = Math.max(area1, Math.max(area2, area3));
                    long minArea = Math.min(area1, Math.min(area2, area3));
                    min = Math.min(min, maxArea - minArea);
                }
            }
            for (long w1 = 1; w1 < W; w1++) {
                long area1 = H * w1;
                {
                    long w2 = (W - w1) / 2;
                    long area2 = H * w2;
                    long w3 = W - (w1 + w2);
                    long area3 = H * w3;
                    long maxArea = Math.max(area1, Math.max(area2, area3));
                    long minArea = Math.min(area1, Math.min(area2, area3));
                    min = Math.min(min, maxArea - minArea);
                }
                {
                    long h2 = H / 2;
                    long area2 = h2 * (W - w1);
                    long h3 = H - h2;
                    long area3 = h3 * (W - w1);
                    long maxArea = Math.max(area1, Math.max(area2, area3));
                    long minArea = Math.min(area1, Math.min(area2, area3));
                    min = Math.min(min, maxArea - minArea);
                }
            }

            System.out.println(min);
        }
    }
}


Measured memory_bytes: 27736
a=[0]*4
for i in range(3):
	x,y=map(int,input().split())
	a[x-1]+=1
	a[y-1]+=1
c=0
for i in range(4):
	if a[i]%2!=0:
		c+=1
if c==0 or c==2:
	print("YES")
else:
	print("NO")

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

int main(){
	int i, n, x;
	cin >> n;
	for(i = 1; i <= n; i++){
		x = i;
		if(i % 3 == 0) cout << " " << i;
		else{
			while(x != 0){
				if(x % 10 == 3){
					cout << " " << i;
					break;
				} 				
				x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}


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

int main(){
    int N,M;
    int a[100001];
    long long mem[100001] = {};
    mem[0]=1;//bengi
    mem[1]=1;
    mem[2]=2;
    for(int i=3;i<100001;i++){
        mem[i] = (mem[i-1] + mem[i-2]) % 1000000007;
    }

    cin >> N >> M;
    cin >> a[0];
    for(int i=1; i<M; i++){
        cin >> a[i];
        if(a[i] - a[i-1] == 1){
            cout << 0 << endl;
            return 0;
        } 
    }
    long long ans = 1;
    int start = 0, goal = a[0]-1;
    for(int i=0; i<M; i++){
        ans *= mem[goal - start];
        ans = ans % 1000000007;
        start = a[i]+1;
        goal = a[i+1]-1;
    }
    goal = N;
    ans *= mem[goal -start];
    ans = ans % 1000000007;
    
    cout << ans << endl;
}


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

long long ar[3000000]={0};
   long long ae[3000000]={0};
int main()
{
 
ar[0]=0;
 long long a,b,c,d, i,j,k=0,l=0;
  char s;string h;
cin>>a;
for(i=1;i<=a;i++)
{
  cin>>s;h+=s;
     if(s=='W')l++;
      
    ar[i]=l;
  
}
for(i=a-1;i>=0;i--)
 {
  if(h[i]=='E')k++;
  ae[i+1]=k;
  }
for(i=0;i<=a;i++)
{
        
    // cout<<ar[i]<<" "<<ae[i]<<endl;
  if(i==1)
  {
       d=ar[i-1]+ae[i+1];
  }
    else d=min(d,ar[i-1]+ae[i+1]);
}
cout<<d<<endl;
}

Measured memory_bytes: 8836
#include<map>
#include<cstdio>
#include<algorithm>
using namespace std;

map<long long,int> m;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	long long l,r;
	scanf("%lld %lld",&l,&r);
	if(r/2019-(l-1)/2019>0) {
		puts("0");
		return 0;
	}
	long long ans=0x3f3f3f3f;
	for(long long i=l;i<=r;i++)
		for(long long j=i+1;j<=r;j++)
			ans=min(ans,i*j%2019);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,r=0,b=0;
    cin >> n;
    string s;
    cin >> s;
    for(i=0;i<n;i++){
        if(s.at(i)=='R') r++;
        else b++;
    }
    if(r>b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<vector<pair<int,bool>>>XY(N);
  for(int i=0;i<N;i++){
    int A;cin>>A;
    for(int j=0;j<A;j++){
      int x;bool y;cin>>x>>y;
      XY[i].push_back(pair<int,bool>(x-1,y));
    }
  }
  long p=1;for(int i=0;i<N;i++)p*=2;
  //全探索で
  int ans=0;
  for(int i=0;i<p;i++){
    int tmp=i;
    int h_num=0;
    vector<bool>honest(N);
    for(int j=0;j<N;j++){honest[j]=tmp%2;tmp/=2;}
    

    
    bool contra=false;
    for(int j=0;j<N;j++){
      if(honest[j]){
        h_num++;
        for(auto xy:XY[j]){
          if(honest[xy.first]!=xy.second){contra=true;break;}
        }
      }
    }
    if(contra==false){
      ans=max(ans,h_num);
    }else{
      contra=false;
    }
    
    
  }
  cout<<ans;
  
}




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

#define      ll     long long int

const int N = 100005;

int main()
{
    int n, i, j, k, x, d, t, lt = 0, y, x0, y0, fl = 1;
    cin >> n;
    x0 = 0;
    y0 = 0;
    lt = 0;
    while (n--) {
        cin >> t >> x >> y;
        d = abs(x - x0) + abs(y - y0);
        if ( !(d <= (t - lt) && d % 2 == (t - lt) % 2) ) {
            fl = 0;
        }
        lt = t;
        x0 = x;
        y0 = y;
    }
    if (fl) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter
    N = int(input())
    A = sorted(list(map(int, input().split())))
    C = Counter(A)
    dp = [False] * 1100000
    ans = 0
    for a, cnt in C.items():
        if dp[a]:
            continue
        for i in range(2*a, 1100000, a):
            dp[i] = True
        if cnt == 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 136300
import sys
from itertools import groupby
from itertools import accumulate

input = sys.stdin.readline

N, K = map(int, input().rstrip().split())
S = list(map(int, list(input().rstrip())))

sakadati = []

sakadati.append(0)
if S[0] == 0:
    sakadati.append(0)

for key, value in groupby(S):
    sakadati.append(len(list(value)))

sakadati.append(0)

rui = list(accumulate(sakadati))

max = 0
for i in range(len(rui) - 2 * K - 1):
    if i % 2 == 1:
        continue
    cur = rui[i + 2 * K + 1] - rui[i]
    if max < cur:
        max = cur

if len(rui) <= 2*K+1:
    print(len(S))
else:
    print(max)


Measured memory_bytes: 9116
n = int(input())
s = [list(map(int,input().split())) for i in range(3)]
# print(s)
a=s[0]
b=s[1]
c=s[2]
# print(a,b,c)

score = 0
for i in range(len(a)):
    score+=b[a[i]-1]
    # print(b[a[i]-1])
    if i == len(a)-1:
        pass
    else:
        if a[i]+1 == a[i+1]:
            score+=c[a[i]-1]
            # print("c:"+str(c[a[i]-1]))
print(score)




Measured memory_bytes: 38384
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn is_agc(x: usize) -> bool {
    let x1 = x / 64;
    let x2 = (x / 16) % 4;
    let x3 = (x /4) % 4;
    let x4 = x % 4;

    (x1 == 0 && x2 == 2 && x3 == 1) ||
     (x1 == 0 && x2 == 1 && x3 == 2) ||
     (x1 == 2 && x2 == 0 && x3 == 1) ||
     (x2 == 0 && x3 == 2 && x4 == 1) ||
     (x2 == 0 && x3 == 1 && x4 == 2) ||
     (x2 == 2 && x3 == 0 && x4 == 1) ||
     (x1 == 0 && x3 == 2 && x4 == 1) ||
     (x1 == 0 && x2 == 2 && x4 == 1)
}


fn main() {
    let n: usize = read_line().trim().parse().unwrap();

    if n == 3 {
        println!("61");
    } else {
        let MOD: u64 = 1_000_000_007;
        let mut memo = vec![vec![0u64; 256]; n + 10];
        for i in 0..256 {
            if is_agc(i) {
                memo[3][i] = 0;
            } else {
                memo[3][i] = 1;
            }
        }
        for i in 4..n {
            for j in 0..256 {
                if is_agc(j) {
                    memo[i][j] = 0;
                } else {
                    memo[i][j] = (memo[i-1][j/4] + memo[i-1][j/4 + 64] + memo[i-1][j/4 + 128] + memo[i-1][j/4 + 192]) % MOD;
                }
            }
        }
        let ans = memo[n-1].iter().fold(0u64, |acc, val| (acc + val) % MOD);
        println!("{}", ans);
    }
}


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

const int MAXN = 1e5+5;

int n, m;
int x[MAXN], y[MAXN];
int ch[405][MAXN];
bool dead[405];
bool ok[405]; //if ok[i] = 1 then i can never be kept alive
bitset<405> b[405];
bitset<405> b1[100005], b2[100005];

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}

	for (int i = 0; i < n; ++i) {
		memset(dead, 0, sizeof(dead));
		dead[i] = 1;
		for (int j = m-1; j >= 0; --j) {
			if (dead[x[j]] && dead[y[j]]) {
				ok[i] = 1;
				break;
			}
			if (dead[x[j]]) {
				dead[y[j]] = 1;
				ch[i][j] = 2;
			} else if (dead[y[j]]) {
				dead[x[j]] = 1;
				ch[i][j] = 1;
			}
		}
	}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			b[i][j] = 1;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			if (ch[i][j] == 1)
				b1[j][i] = 1;
			if (ch[i][j] == 2)
				b2[j][i] = 1;
			if (ch[i][j] == 0)
				b1[j][i] = b2[j][i] = 1;
		}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			if (ch[i][j] == 1)
				b[i] &= b1[j];
			if (ch[i][j] == 2)
				b[i] &= b2[j];
		}

	int ct = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i+1; j < n; ++j) {
			if (ok[i] || ok[j])
				continue;
			ct += b[i][j];
		}

	cout << ct << endl;
	//count compatible pairs

}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("pot");
            WillReturn.Add("top");
            //YES
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("tab");
            WillReturn.Add("bet");
            //NO
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("eye");
            WillReturn.Add("eel");
            //NO
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        string CStr1 = InputList[0];
        string CStr2 = InputList[1];

        bool IsOK = true;
        if (CStr1[0] != CStr2[2]) IsOK = false;
        if (CStr1[1] != CStr2[1]) IsOK = false;
        if (CStr1[2] != CStr2[0]) IsOK = false;
        Console.WriteLine(IsOK ? "YES" : "NO");
    }
}


Measured memory_bytes: 11092
use proconio::{input,fastout};
use std::cmp;

#[fastout]
fn main() {
  input! {
    n: usize,
    h: [u64; n],
  }
  
  let mut v: Vec<usize> = vec![0; n];
  for i in 1..n {
    if h[n-i-1] >= h[n-i] {
      v[n-i-1] = v[n-i] + 1;
    }
    else {
      v[n-i-1] = 0;
    }
  }
  
  let mut ans: usize = 0;
  for i in 0..n {
    ans = cmp::max(ans, v[i]);
  }
  
  println!("{}", ans);
}


Measured memory_bytes: 4512
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

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

    // code here
    int n = input<int>();
    string s = input<string>();

    vector<int> state;
    for (int i = 1; i < SZ(s); ++i)
        state.push_back(abs(s[i] - s[i - 1]));

    n = SZ(state);
    if (std::find(ALL(state), 1) == state.end()) {
        int result = 0;

        for (int i = 0; i < n; ++i)
            if (state[i] == 2)
                result ^= ((i & (n - 1 - i)) == 0);

        result *= 2;
        cout << result << "\n";
    } else {
        int result = 0;

        for (int i = 0; i < n; ++i)
            if (state[i] == 1)
                result ^= ((i & (n - 1 - i)) == 0);

        result *= 1;
        cout << result << "\n";
    }

    return 0;
}


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

int main() {
	
	int n;
	cin >> n;
	
	int points[n+1][3];
	
	memset(points,0,sizeof points);
	
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin >> points[i][j];
		}
	}
	
	
	int dp[n+1][3];
	memset(dp,0,sizeof dp);
	
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[i][j]=points[i][j];
			if(1)
			{
				dp[i][j]+=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
			}
		}
	}
	
	cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
	
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<bitset>
#define ll long long
using namespace std;
inline ll read() {
	ll ans=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') {f=-1;}ch=getchar();}
	while(ch>='0'&&ch<='9') {ans=ans*10+ch-48;ch=getchar();}
	return ans*f;
}
bitset<4000032> b;
int n,sum;
int main() {
	n=read();
	b[0]=1;
	for (int i=1;i<=n;i++){
		int x=read();
		b|=b<<x;
		sum+=x;
	}
	for (int i=(sum+1)>>1;i<=sum;i++){
		if(b[i]){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

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

string s = "BRYG";
    
int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20);    
    int h, w, d;
    cin >> h >> w >> d;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int v1 = ((i + j) % (2 * d)) < d;
            int v2 = ((i - j + w * 2 * d) % (2 * d)) < d;
            cout << s[v1 * 2 + v2];
        }
        cout << "\n";
    }
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}

#define int ll

void _main() {
        int n, a, b; cin >> n >> a >> b;
        vector<int> H(n); cin >> H;

        auto can = [&](int x, vector<int> h) -> bool {
                for (int i = 0; i < n; i++) {
                        h[i] -= x * b;
                }

                int cnt = 0;
                for (int i = 0; i < n; i++) {
                        if (h[i] <= 0) continue;
                        cnt += (h[i] + a - b - 1) / (a - b);
                }

                return cnt <= x;
        };


        int l = 1, r = 1e9, ans = 1e9;
        while (l <= r) {
                int mid = (l + r) / 2;
                if (can(mid, H)) {
                        r = mid - 1;
                        ans = mid;
                } else {
                        l = mid + 1;
                }
        }

        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

#define int ll
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<vector>
struct P{int x,y;}p;
int r;
typedef std::vector<P>V;
V v[252][252];
int S(int s){return s*s;}
int F(const V&v,P p)
{
	int i,a;
	for(a=i=0;i<v.size();++i)
		if(S(v[i].x-p.x)+S(v[i].y-p.y)<=16*r*r)
			++a;
	return a;
}
int main()
{
	int n,m,i,j,x,y,a;
	while(scanf("%d%d%d",&n,&m,&r),r)
	{
		for(a=i=0;i<252;++i)for(j=0;j<252;++j)v[i][j].clear();
		while(n--)
		{
			scanf("%d%d",&p.x,&p.y);
			v[p.y/40+1][p.x/40+1].push_back(p);
		}
		while(m--)
		{
			scanf("%d%d",&p.x,&p.y);
			x=p.x/40+1,y=p.y/40+1;
			for(i=-1;i<2;++i)for(j=-1;j<2;++j)a+=F(v[y+i][x+j],p);
		}
		printf("%d\n",a);
	}
	return 0;
}

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

int main(){
  long N; cin >> N;
  
  int ans = 11;
  int count2 = 100;
  for(long i = 1; i < sqrt(N)+5; i++){
    if(N % i == 0){
      long count = 0;
      long n = N / i;
      while(n > 0){
        n /= 10;
        count++;
      }
      count2 = count;
    }
    ans = min(ans,count2);
    count2 = 100;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int main()
{
    int n;
    si(n);
    int a[n];
    for(int i=0;i<n;i++)
        si(a[i]);
    int dp[n];
    for(int i=0;i<n;i++)
        dp[i] = mod;
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
        if(i+1<n)
            dp[i+1] = min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
        if(i+2<n)
            dp[i+2] = min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
    }
    pfi(dp[n-1]);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   /*
           a>0 b>0  a>b ->   a<a+b
           a<0,b<0  a>b ->   a+b<b
           a>0 b<0  a>b ->   ?? 
           最初にabsが最大のものをn-1個に足しておけば、符号が揃うのでは？？
           */
           int n;
           cin>>n;
           int mx=0; 
           int x=-1;
           vin a(n);
           vector<pair<int,int>> ans(0);
           rep(i,0,n){
             cin>>a[i];
             if(abs(a[i])>=abs(mx)){
               x=i;
               mx=a[i];
             }
           }
           int m=0;
           rep(i,0,n){
            if(i==x)continue;
             if(a[x]==0)break;
             a[i]+=a[x];
             m++;
             ans.pb(mp(x+1,i+1));
           }
           if(a[x]>=0){
             rep(i,0,n-1){
               if(a[i]>a[i+1]){
                 m++;
                 ans.pb(mp(i+1,i+2));
                 a[i+1]+=a[i];
               }
             }
           }
           else{
              for(int i=n-2;i>=0;i--){
               if(a[i]>a[i+1]){
                 m++;
                 ans.pb(mp(i+2,i+1));
                 a[i]+=a[i+1];
               }
             }
           }
           cout<<m<<endl;
           rep(i,0,m){
            cout<<ans[i].first<<" "<<ans[i].second<<endl;
           }
           
}

Measured memory_bytes: 3636
while 1:
    n = int(raw_input())
    if n == 0:
        break
    ownlist = [1] * (2 * n + 1)
    for i in range(n):
        ownlist[int(raw_input())] = 0
    cntlist = [n] * 2
    pos = 1
    turn = 0
    while cntlist[0] > 0 and cntlist[1] > 0:
        try:
            pos = ownlist.index(turn, pos)
            ownlist[pos] = -1
            cntlist[turn] -= 1
            pos += 1
        except ValueError:
            pos = 1
        turn ^= 1
    print cntlist[1]
    print cntlist[0]

Measured memory_bytes: 4244
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
     	var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var X = retreiveStringArray()[0];

			//扱いやすいように1の桁から並べる
			var Xrev = X.Reverse().ToArray();

			var popCount = Xrev.Where(x => x == '1').Count();
			
			//popCount の+-1を格納
			var popS = new long[2];
			popS[0] = popCount + 1;
			popS[1] = popCount - 1 <=0 ? 1 : popCount - 1;

			//N...2のN乗  2...pop+-　それぞれの余り
			var TwoMods = new long[N, 2];
			TwoMods[0,0] = 1 % popS[0];
			TwoMods[0,1] = 1 % popS[1];

			for (int p = 0; p < 2; p++) {
				for (int i = 1; i < N; i++) {
					TwoMods[i, p] = (TwoMods[i - 1, p] * 2) % popS[p];
				}
			}

			//Xをpop+-1で割ったあまり
			var Fx = new long[2];

			
			for (int i = 0; i < N; i++) {
				var c = Xrev[i];
				for (int p = 0; p < 2; p++) {
					if (c == '1') {
						Fx[p] += TwoMods[i, p];
						Fx[p] %= popS[p];
					}

				}
			}

			//i番目をひっくり返す　降順になる
			for (var i = N-1; i >= 0; i--) {
				var c = Xrev[i];
				var first = 0L;
				if (c=='1') {

					//1つしかない1を反転させると、操作0回になる
					if (popCount==1) {
						Console.WriteLine(0);
						continue;
					}

					var p = 1;
					first = Fx[p] - TwoMods[i, p];
					if (first < 0) {
						first += popS[p];
					}
				}
				else {
					var p = 0;
					first = Fx[p] + TwoMods[i, p];
					first %= popS[p];
				}

				var ans = 1 + function(first);
				Console.WriteLine(ans);
			}

		}


		/// <summary>
		/// 問題文のfunctionを実装した関数
		/// </summary>
		/// <param name="n"></param>
		/// <returns></returns>
		private static long function(long n) {

			var count = 0;

			while (n >0) {
				//1が何個あるか求める
				var OneCount = 0L;
				for (int i = 0; i < 32; i++) {
					if ((n >> i & 1) == 1) {
						OneCount++;
					}
				}

				//nを割ってあまりを求める
				n %= OneCount;
				count++;
			}
			return count;


		}



		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}



Measured memory_bytes: 33164
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
int n,p[MAXN],re;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,1,n)cin>>p[i];
    rep(i,1,n)
    {
        if(i==p[i])
        {
            if(i!=n)swap(p[i],p[i+1]);
            else swap(p[i],p[i-1]);
            re++;
        }
    }
    cout<<re;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <stdio.h>

typedef long long ll;

using namespace std;

int V[3];

int main() {
  for (int i = 0; i < 3; ++i) {
    cin >> V[i];
  }
  sort(V, V + 3);
  ll L = (ll)(V[2] / 2);
  printf("%lld\n", V[0] * V[1] * (V[2] - L - L));
}

Measured memory_bytes: 3168
N,M,X = map(int,input().split())
data = []
minval = -1
for n in range(N):
    data.append(list(map(int,input().split())))
for ptn in range(2**N):
    sumchk = [0]*(M)
    sumpri = 0
    for bit in range(N):
        if ptn & (1 << bit) != 0:
            sumpri += data[bit][0]
            for x in range(M):
                sumchk[x] += data[bit][x+1]
    flag = True
    for x in range(M):
        if sumchk[x] < X:
            flag = False
            break
    if flag:
        if minval == -1:
            minval = sumpri
        else:
            if minval > sumpri:
                minval = sumpri
print(minval)


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;

const int inf =1 << 18;

const int cmax=250010;
int w,h;
ll d[cmax];
ll e[cmax];

struct state{
	int d,e;
	bool operator<(const state &arg)const{
		return (d-e) >  (arg.d-arg.e);
	}
};

string table[510];

int n=0;
state ex[cmax];

void dijkstra(char s,char o,ll* dist){
	rep(i,cmax) dist[i]=inf;
	queue<pii> q;
	rep(i,h)rep(j,w){
		if(table[i][j]==s){
			int idx=w*i+j;
			dist[idx]=0;
			pii in=mp(idx,0);
			q.push(in);
		}
	}
	while(!q.empty()){
		pii cur=q.front();q.pop();
		if(dist[cur.first]<cur.second)
			continue;
		int dir[4]={-w,-1,1,w};
		rep(i,4){
			pii next=cur;
			next.first+=dir[i];
			next.second++;
			int cw=next.first%w;
			int ch=next.first/w;
			if(table[ch][cw]=='#'||table[ch][cw]==o)
				continue;
			if(dist[next.first]>next.second){
				dist[next.first]=next.second;
				q.push(next);
			}
		}
	}
	return;
}

int main(void){
	cin >> w >> h;
	rep(i,h) cin >> table[i];
	dijkstra('g','*',d);
	dijkstra('*','#',e);

	int sidx;
	ll dsum=0;
	ll esum=0;
	rep(i,h)rep(j,w) {
		int idx=i*w+j;
		if(table[i][j]=='.'||table[i][j]=='s'){
			if(d[idx]!=inf){
				ex[n].d=d[idx];
				ex[n++].e=e[idx];
			}else
				esum+=e[idx];
		}
		if(table[i][j]=='s')
			sidx=idx;
	}
	sort(ex,ex+n);
	rep(i,n) dsum+=ex[i].d;
	double ans=(1.0*(dsum+esum)/n+e[sidx]);
	for(int i=n;i>=1;--i){
		ans=min(ans,1.0*(dsum+esum)/i+e[sidx]);
		int cur=n-i;
		dsum-=ex[cur].d;
		dsum+=ex[cur].e;
	}
	if(d[sidx]!=inf)
		ans=min(ans,1.0*d[sidx]);
	cout.precision(16);
	cout << fixed << ans << endl;
	return 0;
}

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

int N,M,Q;
vector<int> v,a,b,c,d;
int64_t ans=0;

void dfs(int x,int m){
  if(x==N){
    int64_t sum=0;
    for(int i=0;i<Q;i++){
      if(v.at(b.at(i))-v.at(a.at(i))==c.at(i)){
        sum+=d.at(i);
      }
    }
    if(ans<sum){
      ans=sum;
    }
  }else{
    for(int i=m;i<=M;i++){
      v.at(x)=i;
      dfs(x+1,i);
    }
  }
}

int main(){
  cin >> N >> M >> Q;
  v.resize(N);
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for(int i=0;i<Q;i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  v.at(0)=1;
  dfs(1,1);
  cout << ans << endl;
}


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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  int mid = N / 2;

  cout << d[mid] - d[mid - 1] << endl;

  return 0;
}


Measured memory_bytes: 3752
while(True):
    n = int(input())
    if not n: break
    for _ in range(n):
        m,e,j = map(int, input().split())
        if 100 in [m,e,j]: print("A"); continue
        elif (m+e)/2 >= 90: print("A"); continue
        elif (m+e+j)/3 >= 80: print("A"); continue
        elif (m+e+j)/3 >= 70: print("B"); continue
        elif (m+e+j)/3 >= 50 and (m>=80 or e>=80): print("B"); continue
        else: print("C"); continue


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

long long n, q, t;

int d[100000];
long long a[100000], v[1000];

int main()
{
	cin >> n >> t >> q;

	for (long long i = 0; i < n; i++)
		cin >> a[i] >> d[i];

	for (long long i = 0; i < q; i++)
		cin >> v[i];

	for (long long i = 0; i < n - 1; i++) {
		if (d[i] == 1 && d[i + 1] == 2) {
			if (a[i + 1] - a[i] <= t * 2) {
				a[i] = a[i] / 2 + a[i + 1] / 2;
				a[i + 1] = a[i];
			}
			else {
				a[i] += t;
				a[i + 1] -= t;
			}
		}
	}

	long long i = 0;
	while (d[i] == 2) {
		a[i] -= t;
		i++;
	}

	while (i < n - 1) {
		long long j = i;
		while (d[j] == 2 && d[j + 1] == 2) {
			if (a[j + 1] - a[i] <= t)
				a[j + 1] = a[i - 1];
			else
				a[j + 1] -= t;
			j++;
		}
		i = j + 1;
	}

	i = n - 1;
	while (d[i] == 1) {
		a[i] += t;
		i--;
	}

	while (i > -1) {
		long long j = i;
		while (d[j] == 1 && d[j - 1] == 1) {
			if (a[i + 1] - a[j - 1] <= t)
				a[j - 1] = a[i + 1];
			else
				a[j - 1] += t;
			j--;
		}
		i = j - 1;
	}

	for (long i = 0; i < q; i++)
		cout << a[v[i] - 1] << endl;

	return 0;
}


Measured memory_bytes: 4264
#include <bits/stdc++.h>
#define MAXN 210
#define INF 0x3f3f3f3f
using namespace std;

char s[MAXN];
int d[MAXN][MAXN], vis[MAXN];
int n, ans = 0;
bool flag = true;
void dfs(int now, int dep, int fa){
    if(vis[now]){
        if((dep - vis[now]) & 1)
            flag = false;
        return;
    }
    vis[now] = dep;
    for(int i = 1; i <= n; i++) {
        if(d[now][i] == 0 || i == fa) continue;
        dfs(i, dep + 1, now);
    }
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%s", s + 1);
        for(int j = 1; j <= n; j++) d[i][j] = s[j] - '0';
    }
    dfs(1, 1, 0);
    if(!flag) ans = -1;
    else{
        for(int k = 1; k <= n; k++){
            for(int i = 1; i <= n; i++){
                for(int j = 1; j <= n; j++){
                    if(i == j) continue;
                    if(d[i][k] && d[k][j]) {
                        d[i][j] = min(d[i][j] == 0 ? INF : d[i][j], d[i][k] + d[k][j]);
                    }
                }
            }
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                ans = max(ans, d[i][j]);
            }
        }
        ++ans;
    }
    printf("%d", ans);
}

Measured memory_bytes: 384