akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
const ll L = 1e5 + 5;
vector<ll>ad[L];
ll dp[L][3];
ll vis[L];
void rec(ll ind)
{
	vis[ind] = 1;
	ll i;
	if(sz(ad[ind]) == 1 && ind != 1)
	{
		dp[ind][0] = 1;
		dp[ind][1] = 1;
		return;
	}
	for(i=0;i<sz(ad[ind]);i++)
	{
		ll v = ad[ind][i];
		if(!vis[v])
		{
			rec(v);
			dp[ind][0] = (dp[ind][0] * ((dp[v][0] + dp[v][1]) % mod)) % mod;
			dp[ind][1] = (dp[ind][1] * dp[v][0]) % mod;
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll i,n,x,y;
 	cin >> n;
 	for(i=0;i<n-1;i++)
 	{
 		cin >> x >> y;
 		ad[x].pb(y);
 		ad[y].pb(x);
 	}
 	for(i=1;i<=n;i++)
 		dp[i][0] = 1, dp[i][1] = 1;
 	rec(1);
 	cout << (dp[1][0] + dp[1][1]) % mod << endl;
	return 0;
}

Measured memory_bytes: 13056
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 12, maxM = 1e3; int n, m;
const lli inf = 1e15;
struct Key
{
  lli a; int b, canUnlock;
  void read()
  {
    scanf("%lld %d", &a, &b);
    canUnlock = 0;
    for (int i = 0; i < b; i ++)
    {
      int c; scanf("%d", &c); c --;
      canUnlock |= 1 << c;
    }
  };
};
Key keys[maxM];

lli memo[maxM][1 << maxN];
lli solve(int i = 0, int done = 0)
{
  if (done == (1 << n) - 1) return 0;
  if (i == m) return inf;
  if (memo[i][done] == -1)
  {
    lli ans = min(solve(i + 1, done), solve(i + 1, done | keys[i].canUnlock) + keys[i].a);
    memo[i][done] = ans;
  }
  return memo[i][done];
}

int main()
{
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i ++)
    keys[i].read();

  memset(memo, -1, sizeof(memo));
  lli ans = solve();
  printf("%lld\n", ans >= inf ? -1 : ans);

  return 0;
}

Measured memory_bytes: 32256
N,*P = `dd`.split.map(&:to_i)

ain  = Array.new(N+1, 0)
aout = Array.new(N+1, 0)
bin  = Array.new(N+1, 0)
bout = Array.new(N+1, 0)

P.each_with_index{ |q,k|
  bin[0]   += k+1
  bout[q]  += k+1
  ain[q-1] += k+1
  aout[N]  += k+1
}

x = 0
puts (0...N).map{ |i| x = x - aout[i] + ain[i] }.join(" ")
puts (0...N).map{ |i| x = x - bout[i] + bin[i] }.join(" ")


Measured memory_bytes: 5756
import itertools
import math
N = int(input())
city_list = []
for i in range(N):
    x, y = map(lambda z: int(z), input().split())
    city_list.append((x, y))
root_list = list(itertools.permutations(city_list, N))
ave = 0
for root in root_list:
    length = 0
    while len(root) > 1:
        x1, y1, x2, y2 = root[0][0], root[0][1], root[1][0], root[1][1]
        length += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        root = root[1:]
    ave += (length / len(root_list))
print(ave)


Measured memory_bytes: 7972
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	if((a<=0)&&(b>=0)){
		cout<<"Zero"<<endl;
	}
	if(a>0){
		cout<<"Positive"<<endl;
	}
	if(b<0){
		if((b-a)%2==1){
			cout<<"Positive"<<endl;
		}
		else{
			cout<<"Negative"<<endl;
		}
	}
}

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

long long mod(long long a, long long m) {
	a %= m;
	return a >= 0 ? a : a+m;
}

int main() {
	long long n, k;
	cin >> n >> k;
	long long ans = 0, S[n+1], x[n+1];
	map<long long, int> mp;
	S[0] = 0, x[0] = 0;
	mp[0]++;
	for (int i = 1; i <= n; i++) {
		long long a;
		cin >> a;
		S[i] = mod(S[i-1] + a, k);
		x[i] = mod(S[i] - i, k);
		if (i-k >= 0) mp[x[i-k]]--;
		ans += mp[x[i]];
		mp[x[i]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
const ll PSIZE = 10000000;

int ans;
void dfs(int s, ll mark[], ll a[], ll k, ll step, ll n)
{
    if (step  == k)
    {
        ans = s;
        return;
    }

    if (mark[s] != 0 || (s == 1 && step != 0))
    {
        ll cir = step - mark[s];
        ll path = (k - mark[s]) % cir;
        ll mark2[n + 1];
        memset(mark2,0,sizeof(mark2));
        dfs(s, mark2, a, path, 0, n);
        return;
    }

    mark[s] += step;
    dfs(a[s], mark, a, k, step + 1, n);
}

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, 1, n + 1)
    {
        cin >> a[i];
    }
    ll mark[n + 1];
    memset(mark,0,sizeof(mark));
    dfs(1, mark, a, k, 0, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8272
#include <cstdio>

using namespace std;

int gcd(int a,int b) {
	if(!(a%b)) return b;
	else return gcd(b,a%b);
}

int main() {
	int K;
	scanf("%d",&K);
	long long ans = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				ans += gcd(i,gcd(j,k));
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1732
from itertools import permutations
n = int(input())
p1 = tuple(map(int, input().split()))
p2 = tuple(map(int, input().split()))

l = list(range(1, n+1))

a = list(permutations(l))
# print(a)
print(abs(a.index(p1) - a.index(p2)))

Measured memory_bytes: 69660
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int n, a, b;
ll h[100000], h2[100000], hmax = 0;

int main() {
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		hmax = max(h[i], hmax);
	}

	ll left = 1, right = hmax, mid;
	while (right - left > 1) {
		mid = (left + right) / 2;
		for (int i = 0; i < n; i++)h2[i] = h[i] - mid*b;

		//cout << "mid:" << mid << endl;
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			if (h2[i] > 0) {
				sum += (ll)ceil(h2[i] / (double)(a - b));
			}
		}

		if (sum > mid) {
			left = mid;
		}
		else {
			
			right = mid;
		}
	}

	cout << right << endl;
}

Measured memory_bytes: 1792
/**
*    author:  Dooloper
*    created: 03.05.2020 21:01:01
**/

#include <bits/stdc++.h>

using namespace std;

int n,k,d[105],a;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
  int t;
	for(int i = 0; i < k; i++){
		cin >> t;
		for(int j = 0; j < t; j++){
			cin >> a;
			d[a] = 1;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(d[i]!=1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
n=len(s)
ans=0
for i in range(n//2):
    if s[i]!=s[-1-i]:
        ans+=1
print(ans)

Measured memory_bytes: 5324
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

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

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

int main(){
  while(true){
    int cnt[3] = {0, 0, 0};
    int t[5];

    for(int i = 0; i < 5; i++){
      cin >> t[i];
      if(t[i] == 0) return 0;
      t[i]--;
      cnt[t[i]]++;
    }

    if(cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5 ||
       0 < cnt[0] && 0 < cnt[1] && 0 < cnt[2]){
      for(int i = 0; i < 5; i++){
        cout << 3 << endl;
      }
    }
    else{
      for(int i = 0; i < 5; i++){
        if(cnt[(t[i] + 1) % 3] > 0){
          cout << 1 << endl;
        }
        else{
          cout << 2 << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

map<pair<int, int>, int> cells;

int main() {
  int i;
  long long H, W, N;
  long long ans[10] = {};
  scanf("%lld %lld %lld", &H, &W, &N);
  int a[100010], b[100010];
  for (i = 0; i < N; i++) {
    scanf("%d %d", &a[i], &b[i]);
    a[i] -= 1;
    b[i] -= 1;
  }
  long long not_white = 0;
  for (i = 0; i < N; i++) {
    for (int dx = -1; dx <= 1; dx++) {
      for (int dy = -1; dy <= 1; dy++) {
	int X = a[i] + dx;
	int Y = b[i] + dy;
	if (X <= 0 || Y <= 0 || X >= H-1 || Y >= W-1) {
	  continue;
	}
	pair<int, int> P;
	P = make_pair(X, Y);
	if (cells.find(P) != cells.end()) {
	  cells[P] += 1;
	} else {
	  cells[P] = 1;
	  not_white += 1;
	}
      }
    }
  }

  ans[0] = (H-2)*(W-2) - not_white;
  for (auto x : cells) {
    int num = x.second;
    ans[num] += 1;
  }
  for (i = 0; i < 10; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
  


Measured memory_bytes: 57216
N = int(input())

lst = []
for i in range(N):
    s, p = input().split()
    town = [s, int(p), i + 1]
    lst.append(town)
# print(lst)

lst.sort(key=lambda x: (x[0],-x[1]))
# print(lst)

for a in lst:
    print(a[2])

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{

  int n, i;

  scanf("%d",&n);
  int a[n];

  a[0] = a[1] = 1;

  for(i=2;i<=n;i++){
    a[i] = a[i-1] + a[i-2];
  }

  printf("%d\n",a[n]);

  return 0;

}




Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int> 
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << " - " << x << endl;
const ll MOD = 1e9 + 7;
const ll INF = 1<<29;
const ll MAX_N = 1e6 + 7;
using namespace std;

int main(){
    IOS;
    string s; cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A == B && A == 5 && C == 7)
    cout << "YES";
  else if(B == C && B == 5 && A == 7)
    cout << "YES";
  else if(C == A && C == 5 && B == 7)
    cout << "YES";
  else
    cout << "NO";
}

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

int main(){
    int a , b , c , Ans;
    scanf( "%d%d%d" , &a , &b , &c );
    Ans = b / a;
    Ans = min( Ans , c );
    printf( "%d\n" , Ans );
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
const ll md = 1000000007;

ll add(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod)%mod;
}

ll mul(ll a, ll b, ll mod = md) {
    return (a%mod * b%mod + mod)%mod;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n) {  
        if (n & 1) res = (res*x);
        n = n/2;
        x = (x*x);
    }  
    return res;
}

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // int t;
    // cin >> t;
    // while(t--) {
    // 	int count = 0;
    // int n,k;
    // cin >> n >> k;
   	// for(ll i = pow(10, n-1); i <= pow(10, n) - 1; i++) {
   	// 	ll x = i;
   	// 	string s = "";
   	// 	while(x) {
   	// 		s += (x%10 + '0');
   	// 		x /= 10;
   	// 	}
   	// 	bool bad = false;
   	// 	vector<int> f(100, 0);
   	// 	for(int i = 0; i < s.size(); i++) {
   	// 		f[s[i]]++;
   	// 		if(f[s[i]] > k) {
   	// 			bad = true;
   	// 			break;
   	// 		}
   	// 	}
   	// 	if(bad) {
   	// 		count++;
   	// 		cout << count << ". " << i << "\n";
   	// 	}
   	// }
   	// cout << count << "\n";
    // // }
	ll n, m;
	cin >> n >> m;
	vector<ll> dp(n+1, -1);
	dp[0] = 1;
	for(int i = 0, x; i < m; i++) {
		cin >> x;
		dp[x] = 0;
	}
	for(int i = 1; i <= n; i++) {
		if(dp[i] == -1) {
			dp[i] = (i-1 >= 0 ? dp[i-1] : 0) + (i-2 >= 0 ? dp[i-2] : 0);
			dp[i] %= md;
		}
	}
	cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    ll n;cin>>n;
    ll s;
    s=0;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
        s+=a[i];
    }
    ll sef,seb,sof,sob;
    sef=sof=seb=sob=0;
    for(int i=1;i*2<n;i++){
        seb+=a[i*2];
        sob+=a[i*2-1];
    }
    rep(i,n){
        if(i%2==0){
            cout<<(s/2-(sef+sob))*2<<" ";
            sef+=a[i];
            if(i!=n-1)sob-=a[i+1];
            }
        if(i%2==1){
            cout<<(s/2-(sof+seb))*2<<" ";
            sof+=a[i];
            if(i!=n-1)seb-=a[i+1];
            }
        }
    
}

Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;

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

  cin >> n;
  int mi = INF;
  int ans = 0;

  REP(i, n) {
    int a;
    cin >> a;

    if(a < mi) {
      ans++;
      mi = a;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
A = []
B = []
for i in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
count = 0
for j in range(n-1,-1,-1):
  mod = (A[j]+count)%B[j]
  if mod > 0 :
    count += B[j] - mod
print(count)

Measured memory_bytes: 11036
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

string replaceR(string str)
{
	int len = str.size();
	for(int i=0;i<len;i++)
	{
		for(int j=0;j<i;j++)
		{
			if(str[i]>str[j])
			{
				char tmp = str[j];
				str[j] = str[i];
				str[i] = tmp;
			}
		}
	}
	return str;
}

string replaceF(string str)
{
	int len = str.size();
	for(int i=0;i<len;i++)
	{
		for(int j=0;j<i;j++)
		{
			if(str[i]<str[j])
			{
				char tmp = str[j];
				str[j] = str[i];
				str[i] = tmp;
			}
		}
	}

	return str;
}

int main()
{
	string s,t;

	cin >> s >> t;

	s = replaceF(s);
	t = replaceR(t);

	int len = min(s.size(),t.size());

	for(int i=0;i<len;i++)
	{
		if(s[i]<t[i])
		{
			cout << "Yes" << endl;
			return 0;
		}
		else if(s[i] > t[i])
		{
			cout << "No" << endl;
			return 0;
		}
	}
	if(s.size() < t.size())
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
//using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n;
	ll ans;

	cin >> n;

	int a;
	unordered_map<int, int> m;
	rep(i, n) {
		cin >> a;
		++m[a];
	}

	ans = 0;
	for (auto itr:m) {
		ans += itr.second % 2;
	}

	cout << ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 4388
#include <iostream>
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m, top = 0;
LL s[N], w[N], st[N];
int main() {
	scanf("%d%d",&n,&m);
	st[top = 1] = n;
	rep(i,1,m) {
		LL x; scanf("%lld",&x);
		while (top && st[top] >= x) top--;
		st[++top] = x;
	}
	w[top] = 1;
	dep(i,top,1) {
		int x = i - 1; LL l = st[i];
		while (x) {
			w[x] += w[i] * (l / st[x]);
			l %= st[x];
			x = upper_bound(st + 1, st + top + 1, l) - st - 1;
		}
		s[l] += w[i];
	}
	dep(i,n,1) s[i] += s[i + 1];
	rep(i,1,n) printf("%lld ",s[i]); printf("\n");
	return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef string ST;
 
 
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
 
 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}

vector<vector<LL>> make_dp(vector<LL> A,vector<LL> B,LL T)
{
  LL N= A.size();
  vector<vector<LL>> dp(N,vector<LL>(T,0)); // N*T
  REP(n,N){
    REP(t,T){
      if(t >= A[n]){
        if(n==0){
          dp[n][t] =  B[n] ;
        }
        else{
          dp[n][t] = max(dp[n-1][t], dp[n-1][t-A[n]] + B[n] );
        }
      }
      else{
        if(n==0){
          dp[n][t] =  0;
        }
        else{
          dp[n][t] =  dp[n-1][t];
        }
      }
    }
  }

  return dp; 
}

void func() {
  LL N,T;
  cin >> N>>T;
  vector<LL> A(N);
  vector<LL> B(N);
  vector<LL> rA(N);
  vector<LL> rB(N);
  REP(i,N){
    cin >> A[i];
    cin >> B[i];
  }
  REP(i,N){
    rA[N-i-1] = A[i];
    rB[N-i-1] = B[i];
  }
  vector<vector<LL>> dp1  = make_dp(A,B,T);
  vector<vector<LL>> dp2  = make_dp(rA,rB,T);
  LL max_manzok=0;
  REP(n,N){
    REP(t,T){
      LL manzok=0;
      if (n==0){
        manzok  = dp2[N-n-1-1][T-t-1] + B[n];
        //cerr << n <<" "<< t <<" "<< dp2[N-n-1-1][T-t-1] + B[n] << endl;
      }
      else if(n==N-1){
        manzok  = dp1[n-1][t] + B[n];
        //cerr << n <<" "<< t <<" "<< dp1[n][t] + B[n] << endl;
      }
      else{
        manzok  = dp1[n-1][t] + dp2[N-n-1-1][T-t-1] + B[n];
        //cerr << n <<" "<< t <<" "<< dp1[n][t] + dp2[N-n-1-1][T-t-1] + B[n] << endl;
      }
      //cerr << manzok << " ";
      max_manzok= max(max_manzok, manzok);
    }
      //cerr << endl;
    
  }
/*
  REP(n,N){
     PRINTSP(dp1[n]);
  }
  REP(n,N){
    PRINTSP(dp2[n]);
  }
*/
  cout << max_manzok;
  // vector<vector<LL>> dp(N,vector<LL>(T,0)); // N*T
  // REP(n,N){
  //   REP(t,T){
  //     if(t >= A[n]){
  //       if(n==0){
  //         dp[n][t] =  B[n] ;
  //       }
  //       else{
  //         dp[n][t] = max(dp[n-1][t], dp[n-1][t-A[n]] + B[n] );
  //       }
  //     }
  //     else{
  //       if(n==0){
  //         dp[n][t] =  0;
  //       }
  //       else{
  //         dp[n][t] =  dp[n-1][t];
  //       }
  //     }
  //   }
  // }
  return;
}

int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 141312
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

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

fn main() {
  input! {
  a: i64,
  b: i64,
  }

  let mut ans = 0;
  if a < b {
    ans = b + b - 1;
  } else if a > b {
    ans = a + a - 1;
  } else {
    ans = a * 2;
  }

  println!("{}", ans);
}


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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int h,w;
vector<vector<int> > v(60, vector<int>(60, 0));
vector<vector<bool> > visited(60, vector<bool>(60,false));

int dfs(int i, int j){
  if(visited[i][j])return 0;

  visited[i][j] = true;
  rep(x,8){
    rep(y,8){
      int posx = j + ddx[x];
      int posy = i + ddy[y];
      if(0 <= posx && posx < w && 0 <= posy && posy < h){
        if(!visited[posy][posx] and v[posy][posx]){
          dfs(posy,posx);
        }
      }
    }
  }
  return 1;
}

int main(){

   while(cin >> w >> h, w and h){
    int ans = 0;
    rep(i,60){
      rep(j,60){
         visited[i][j] = false;
      }
    }

    rep(i,h){
      rep(j,w){
        cin >> v[i][j];
      }
    }

    rep(i,h){
      rep(j,w){
        if( !visited[i][j] && v[i][j])ans += dfs(i,j);
      }
    }
   cout << ans << endl;
   }

  return 0;

}


Measured memory_bytes: 3244
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
long long mod=1000000007;
long long min(long long a,long long b){
    if(a>b)return b;
    else return a;

}
int main(){
    int A,B;
    cin>>A>>B;
    cout<<A*B<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
    VECCIN(head);
    VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
    seco[head]=IN();
    VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
int main(){
    CIN(a,b);
    int diff = b - a;
    V v(1000,0);
    REP(i,1000)v[i+1]=v[i]+i+1;
    COUT(v[diff] - b);
 
    return 0;
}

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

#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pp pop_back
#define scan(t) scanf("%d",&t)
#define sscan(t) scanf("%lld",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define LL long long
#define ull unsigned long long
#define rock(cont) cont.begin(), cont.end()
#define roll(a,n) arr,arr+n
#define rep(i,n) for(int i=0 ; i<n ; i++)
#define repp(i, n) for(int i=1 ; i<=n ; i++)
#define print(t) printf("%d",t)
#define pprint(t) printf("%lld",t)
#define co(x) cout<<x
#define nl printf("\n")
#define el cout<<endl
#define INF (int)1e9

const int RT = 10000000;

vector<int>prime;
vector<LL>factor;
bitset<10000003> status;



int gcd(LL a,LL b){ return b==0 ? a: gcd(b,a%b);}
int lcm(LL a,LL b) { return a* (b/gcd(a,b));}

vector<int> Divisors(int n)
{
    vector<int> v;
    int limit=sqrt(n);
    for (int i=1; i<=limit; i++)
    {
        if (n%i==0)
        {
            if (n/i == i)
                v.push_back(i);
            else
            {
                v.push_back(i);
                v.push_back(n/i);
            }
        }
    }
    return v;
}

void sieve()
{
    int rt = sqrt(RT);
    //for(int i = 4; i <= rt; i+=2) status[i]=true;
    for(int i = 3; i <= rt; i+=2)
        if(!status[i])
            for(int j = i*i; j < RT; j+=(i<<1))
                status[j] = true;

    prime.push_back(2);

    for(int i = 3; i <= RT; i+=2)
        if(!status[i])
            prime.push_back(i);
}

LL primefac(LL n)
{
    int pf_idx=0,pf=prime[pf_idx],SIZE=prime.size();
    LL ANS=1,step=0;
    while(pf*pf<=n&&pf<SIZE)
    {
        if(n%pf==0)
        {
            while(n%pf==0) {n/=pf;}
            ANS=pf;
            step++;
        }
        pf=prime[++pf_idx];
        //cout<<pf<<" "<<n<<" "<<ANS<<endl;
    }
    if(n!=1) { ANS=max(ANS,n); step++; }
    if(step>1)
    {
      return ANS;
    }
    else
    {
        return -1;
    }
}

int main()
{
    fast;
    int a,b;
    cin>>a>>b;
    if(a<=b)
    {
        cout<<"unsafe"<<endl;
    }
    else
    {
        cout<<"safe"<<endl;
    }
}


Measured memory_bytes: 3676
ans=['A','B','C','D','E','F','G']
def sol(x):
    for i in range(8):
        for j in range(8):
            if i<7 and j<7:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i][j+1]=='1' and x[i+1][j+1]=='1':
                    return 0
            if i<5:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+2][j]=='1' and x[i+3][j]=='1':
                    return 1
            if j<5:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i][j+2]=='1' and x[i][j+3]=='1':
                    return 2
            if i<6 and 0<j:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+1][j-1]=='1' and x[i+2][j-1]=='1':
                    return 3
            if i<7 and j<6:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i+1][j+1]=='1' and x[i+1][j+2]=='1':
                    return 4
            if i<6 and j<7:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+1][j+1]=='1' and x[i+2][j+1]=='1':
                    return 5
            if i<7 and 0<j<7:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i+1][j]=='1' and x[i+1][j-1]=='1':
                    return 6


while 1:
    l=[]
    try:
        for i in range(8):
            l.append(raw_input())
        print ans[sol(l)]
        raw_input()
    except:
        break

Measured memory_bytes: 6416
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
   int n;
   int p[100];
   cin >> n;
   for(int i = 0; i < n; i++) cin >> p[i];
   int count = 0;
   for(int i = 0; i < n; i++){
       if(i+1 != p[i]) count++;
   }
   if(count <= 2) cout << "YES" << endl;
   else cout << "NO" << endl;
   //cout << count << endl;
}


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

int main(){
  string n;  cin >> n;
  
  // atoi function
  int sum = 0;
  for(int i = 0; i < n.size(); i++){
    if (n.at(i) == '1')
      sum += 1;
    else if (n.at(i) == '2')
      sum += 2;
    else if (n.at(i) == '3')
      sum += 3;
    else if (n.at(i) == '4')
      sum += 4;
    else if (n.at(i) == '5')
      sum += 5;
    else if (n.at(i) == '6')
      sum += 6;
    else if (n.at(i) == '7')
      sum += 7;
    else if (n.at(i) == '8')
      sum += 8;
    else if (n.at(i) == '9')
      sum += 9;
    else
      ;
  }
  
  //cout << sum << endl;
  
  int num = atoi( n.c_str() );
  //cout << num%sum << endl;
  if(num%sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;

bool BirthAscendingSort(const pair<int, int> &a, const pair<int, int> &b) {
	return a.second < b.second;
}

int P[100000];
int Y[100000];
int CityCount[100001];
char ans[100000][13];

int main(void) {
	unsigned int N, M;
	cin >> N >> M;

	vector <pair <int, int>> CityOrder;
	for (unsigned int i = 0; i < M; i++) {
		int year;
		cin >> P[i] >> year;
		CityOrder.push_back(make_pair(i, year));
	}

	for (unsigned int i = 1; i <= N; i++) {
		CityCount[i] = 0;
	}

	std::sort(CityOrder.begin(), CityOrder.end(), BirthAscendingSort);

	for (unsigned int i = 0; i < CityOrder.size(); i++) {
		int PrefectureNumber = P[CityOrder[i].first];
		CityCount[PrefectureNumber]++;
		sprintf(ans[CityOrder[i].first], "%06d%06d", PrefectureNumber, CityCount[PrefectureNumber]);

	}

	for (unsigned int i = 0; i < M; i++) {
		printf("%s\n", ans[i]);
	}

	return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
#define push_back pb;
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  (a.begin(),a.end())
#define RALL(a) (a.begin(),a.end(),greater<int>())


/*--------------------------------------------*/
/*
int dx[4]={-1,0,1,0};//四方に移動
int dy[4]={0,-1,0,1};
*/
/*--------------------------------------------*/
/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a=A;
    ll b=B;
    if (a==0 || b==0) {return 0;}
    if (a<0) {a=-a;}
    if (b<0) {b=-b;}
    while(b>0) {
        ll c=a%b;
        a=b;
        b=c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while(b!=0) {
        int t=b;
        b=a%b;
        a=t;
    }
    return a;
}

//入力はすべて正とする
bool is_prime(int n) {//素数判定o(√n)
    for (int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return n!=1;//1の場合は例外
}

vector<ll> divisor(ll n){//約数の列挙o(√n)
    vector<ll> res;
    for(ll i=1;i*i<=n;i++) {
        if(n%i == 0){
        res.push_back(i);
        if(i!=n/i)res.push_back(n/i);
        }
    }
    return res;
}//vector<ll>k=divisor(n);rep(i,k.size())cout<<k[i]<<endl;//のように使う

map<ll,ll> prime_factor(ll n){//素因数分解o(√n)
    map<ll,ll>res;    
    for(ll i=2;i*i<=n;i++) {
        while (n%i==0) { 
            ++res[i];
            n/=i;
        }
    }
    if (n!=1)res[n]=1;
    return res;
}//map<ll,ll> k=prime_factor(n);for(auto i=k.begin();i!=k.end();i++){cout<<i->first<<" "<<i->second<<endl;}//みたいに使う

vector<ll> prime_list(ll n){//n以下の素数を全て見つける
    vector<ll> is_prime(n);//is_prime[i]が1ならiは素数
    for(ll i=2;i<=n;i++)is_prime[i]=1;//最初はみんな素数かも
    for(ll i=2;i*i<=n;i++){//素数の整数倍を消していく(√nまで)
        if(is_prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    is_prime[j]=0;                
                }
            }
        }
    }return is_prime;
}vector<ll>k=prime_list(n);REP(i,n){if(k[i])cout<<i<<endl;}のように使う
*/
/*--------------------------------------------*/


int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    int v1=c-a;int v2=d-b;
    cout<<c-v2<<" "<<d+v1<<" "<<a-v2<<" "<<b+v1<<" "<<endl;
}




Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
if(N == 1):
    print(1)
    exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
    if(cur == A[i]): continue
    if(flag == -1):
        if(A[i] > cur): flag = 1
        elif(A[i] < cur): flag = 0
        cur = A[i]
        continue
    if(flag == 1 and A[i] < cur):
        cur, flag = A[i], -1
        ans += 1
        continue
    if(flag == 1 and A[i] > cur):
        cur = A[i]
        continue
    if(flag == 0 and A[i] > cur):
        cur, flag = A[i], -1
        ans += 1
        continue
    if(flag == 0 and A[i] < cur):
        cur = A[i]
        continue
print(ans)


Measured memory_bytes: 14480
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,l; cin >> n >> l;
  vector<int> v(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    v[i] = l + i;
    sum += v[i];
  }
  sort(v.begin(),v.end());

  int res = 1 << 30;
  int idx = -1;
  for(int i = 0; i < n; i++){
    if(res > abs(sum - (sum - v[i]))){
      res = abs(sum - (sum - v[i]));
      idx = i;
    }
  }
  cout << sum - v[idx] << endl;

  return 0;
}


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

int main(){
  int D;
  cin >> D;

  string s = "Christmas";
  if(D <= 24){
    s += " Eve";
    if(D <= 23){
      s += " Eve";
      if(D == 22){
        s += " Eve";
      }
    }
  }
  
  cout << s << endl;
  
  return 0;

}

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

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)

#define pr(x) cout << #x << " = " << x << endl;

using namespace std;

const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
int a[N];
int main() {
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	int n;
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, 1, n - 1) {
		if(a[i] == i) {
			swap(a[i], a[i + 1]);
			ans++;
		}
	}
	if(a[n] == n) {
		ans++;
	}
	cout << ans << "\n";
}



Measured memory_bytes: 640
import sys
readline = sys.stdin.buffer.readline

S = readline().strip().decode('utf-8')
N = len(S)
ans = 'No'
if N%2 == 0:
    for i in range(N//2):
        if S[2*i] != 'h' or S[2*i+1] != 'i':
            break
        
    else:
        ans = 'Yes'

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int ans = 0;
    string S,T;
    cin >> S >> T;
    for(int i = 0;i < 3;i++)
    {
        if(S[i] == T[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import math
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)

Measured memory_bytes: 68200
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B = map(int, readline().split())
S = readline().decode('utf8').rstrip()
T=S[:A]+S[A+1:]
bl = S[A] == '-' and not('-' in T)

print('Yes' if bl else 'No')


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  vector<int> a(3);
  int n;
  for (int i = 0; i < 3; ++i) cin >> a[i];
  cin >> n;
  vector<int> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < 3; ++i) {
    for (int j = n; j >= a[i]; --j) {
      for (int k = 1; k * a[i] <= j; ++k) {
        dp[j] += dp[j - k * a[i]];
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int N = 0;
    int L = 0;
    int tasteA = 0;
    int tasteB = 0;
    int result = 0;
    
    scanf("%d",&N);
    scanf("%d",&L);
    
    for (int i=1; i<=N; i++) {
        tasteA = tasteA + (L + i - 1);
    }
    
    for (int i=1; i<=N; i++) {
        tasteB = 0;
        for (int j=1; j<=N; j++) {
            if (i==j) {
                continue;
            }
            tasteB = tasteB + (L + j - 1);
        }
        int valueA = tasteA-tasteB;
        int valueB = tasteA-result;
        if (valueA < 0) {
            valueA = valueA * -1;
        }
        if (valueB < 0) {
            valueB = valueB * -1;
        }
        if (valueA < valueB) {
            result = tasteB;
        }
    }
    printf("%d",result);
}


Measured memory_bytes: 128
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int dp[1 << 17][26][26];
int nxt[1 << 19][26];
int sum[1 << 19];
int name[1 << 19];
int cur = 0;
void add(string s,int N)
{
    int cnt = 0;
    for (auto it : s)
    {
        const int w = it - 'a';
        if (!nxt[cnt][w]) nxt[cnt][w] = ++cur;
        cnt = nxt[cnt][w];
        ++sum[cnt];
    }
    name[cnt] = N;
}
int C[55][55];
int W[1 << 20];
void dfs(int node = 0,int add = 0)
{
    for (int i = 0;i < 26;++i)
        if (nxt[node][i])
        {
            for (int j = 0;j < 26;++j)
                if (nxt[node][j] && i != j)
                    C[i][j] += sum[nxt[node][j]];
            dfs(nxt[node][i],(name[node] != 0) + add);
            for (int j = 0;j < 26;++j)
                if (nxt[node][j] && i != j)
                    C[i][j] -= sum[nxt[node][j]];
        }
    if (name[node])
    {
        for (int i = 0;i < 26;++i)
            for (int j = 0;j < 26;++j)
                dp[name[node]][i][j] = C[i][j];
        W[name[node]] = add;
    }
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    for (int i = 1;i <= n;++i)
    {
        string s;
        fi>>s;
        add(s,i);
    }
    int m;
    dfs();
    fi>>m;
    for (int i = 1;i <= m;++i)
    {
        int k;
        fi>>k;
        string s;
        fi>>s;
        int ans = W[k] + 1;
        for (int i = 0;i < 26;++i)
            for (int j = i + 1;j < 26;++j)
                ans += dp[k][s[j] - 'a'][s[i] - 'a'];
        fo << ans << '\n';
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 275328
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
const int mod=998244353;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
inline LL read(){LL x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;}
inline LL qpow(LL x,LL k=mod-2,LL m=mod){LL res=1;while(k){if(k&1) res=res*x%m;x=x*x%m;k>>=1;}return res;}
/*=================================================================================================================*/
LL f[N],sum[N],n,k,l[N],r[N];

int main(){
    cin>>n>>k;
    for(int i=1;i<=k;i++) cin>>l[i]>>r[i];
    f[1]=sum[1]=1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            int ll=max(1ll,i-r[j]),rr=i-l[j];
            if(rr<1) continue;
            f[i]=(f[i]+sum[rr]-sum[ll-1]+mod)%mod;
        }
        sum[i]=(sum[i-1]+f[i])%mod;
    }
    cout<<f[n]<<endl;
    return 0;
}


Measured memory_bytes: 6700
#include<iostream>
using namespace std;
int main()
{
	int a;
	int b,c,d;
	int p;
	
	int x_moni;
	int y_moni;
	
	int moni;
	
	cin >> a >> b >> c >> d >> p;
	
	x_moni=p*a;
	
	y_moni=b;
	if(p>c)
	{
		p-=c;
		y_moni+=d*p;
	}
	
	moni=min( x_moni , y_moni );
	
	cout << moni << endl;
	
	return 0;
}

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

int main() {
    string S;
    cin >> S;

    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll a, b, c;
	cin >> a >> b >> c;
	ll num = a*100+b*10+c;
	if(!(num%4)) puts("YES");
	else puts("NO");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <cmath>
#include <stdlib.h>
#include <math.h>
using namespace std;

void printa(int a[], int n) {
  for (int i=0;i<n;i++) {
    if (i!=(n-1)) {
      cout << a[i] << " ";
    } else {
      cout << a[i] <<endl;
    }
  }
}

int stack[200];
int sp = 0;
void push(int a) {
  stack[sp++] = a;
}
int pop() {
  return stack[--sp];
}

int main(){
  int t,a,b;
  char str[10];
  for (int i=0;scanf("%s",str)!=EOF;i++) {
    switch (str[0])
    {
    case '+':
      t = pop() + pop();
      push(t);
      break;
    case '-':
      a = pop();
      b = pop();
      t = b - a;
      push(t);
      break;
    case '*':
      t = pop() * pop();
      push(t);
      break;
    case '/':
      a = pop();
      b = pop();
      t = b / a;
      push(t);
      break;
    default:
      push(atoi(str));
    }
  }
  cout << pop() << endl;
}



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

typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

ll L[100];
ll lucas(){
    REAP(i,2,99){
        L[i]=L[i-1]+L[i-2];
    }
}

int main(){
    L[0]=2;
    L[1]=1;
    int n;
    cin >> n;
    lucas();
    cout << L[n] << endl;
}


Measured memory_bytes: 256