akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
//compiling code: g++ test.cpp(file) -o script(output) -std=c++11(version) -O2(make it 2x faster)
using namespace std;

int A, B;

int main(){
    cin >> A >> B;
    if (A >= 1 && A <= 9 && B >= 1 && B <= 9){
        cout << A*B << "\n";
    } else {
        cout << -1 << "\n";
    }

    return 0;
}

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

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	int H, W, N;
	cin >> H >> W >> N;

	int ans;
	int l = W;

	if (H > W)
	{
		l = H;
	}

	ans = N / l + (N % l == 0 ? 0 : 1);

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


Measured memory_bytes: 256
N = int(input())
hn = [int(i) for i in input().split()]



hi_2 = hn[0]
hi_1 = hn[1]
hi = -1

dp = [-1 for _ in range(N)]
dp_2 = dp[0] = 0
dp_1 = dp[1] = abs(hi_2 - hi_1)

for i in range(2, N):
    hi = hn[i]
    dp_i = dp[i] = min(abs(hi - hi_2) + dp_2, abs(hi - hi_1) + dp_1)

    hi_2 = hi_1
    hi_1 = hi
    dp_2 = dp_1
    dp_1 = dp_i

print(dp[N - 1])


Measured memory_bytes: 20528
package main

import "fmt"
import "sort"

var N, K int

func main() {
	fmt.Scan(&N, &K)
	var a, b int
	data := make(map[int]int)
	total := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&a, &b)
		data[a] += b
	}
	keys := make([]int, 0, 0)
	for key, _ := range data {
		keys = append(keys, key)
	}
	sort.Ints(keys)
	for _, num := range keys {
		total += data[num]
		if total >= K {
			fmt.Println(num)
			break
		}
	}
}


Measured memory_bytes: 8064
# include <iostream>
# include <cstring>
using namespace std;
int *b,n,*a;
void Count_Sort(int *a,int n)
{
	int c[10001];
	memset(c,0,sizeof(c));
	b = new int [n];
	for(int i = 0;i < n;i++) c[a[i]]++;
	for(int i = 1;i <= 10000;i++) c[i] += c[i-1];
	for(int i = n-1;i >= 0;i--)
	{
		b[c[a[i]]-1] = a[i];
		c[a[i]]--;
	}
}
int main(void)
{
	scanf("%d",&n); a = new int [n];
	for(int i = 0;i < n;i++) scanf("%d",&a[i]);
	Count_Sort(a,n);
	for(int i = 0;i < n;i++) printf("%d%c",b[i],(i == n-1)?'\n':' ');
	return 0;
} 


Measured memory_bytes: 18876
using System;
using System.Linq;

class Program {
  static int Hoge(int a, int d) {
    int res = 0;
    for (int i = 0; 1 + i * a <= d; i++) res++;
    return res;
  }

  static void Main() {
    int n = int.Parse(Console.ReadLine());
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int d = arr[0];
    int x = arr[1];
    var a = Enumerable.Repeat(0, n)
            .Select(_ => Console.ReadLine()).Select(int.Parse).Select(e => Hoge(e, d)).Sum();
    Console.WriteLine(a + x);
  }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;
const int MAX = 2e5+1;

vector<ll> dp(MAX,0);
vector<ll> f(MAX,1);
vector<ll> p(MAX,-1);
vector<int> g[MAX];

ll child(int u, int par) {
  for(auto k : g[u]) {
    if(k != par) {
      f[u] += child(k,u);
      p[k] = u;
    }
  }
  return f[u];
}

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;
}

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

int main(){
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  child(0,-1);
  ll ans = 0;
  rep(i,n) {
    ll c = n-1;
    for(auto k : g[i]) {
      if(p[i] != k) {
        (dp[i] -= Pow(2,f[k])-f[k]-1) %= mod;
        c -= f[k];
      }
    }
    (dp[i] -= Pow(2,c)-c-1) % mod;
    (dp[i] += Pow(2,n-1) - n) %= mod;
    (ans += dp[i]) %= mod;
  }
  ans = modinv(Pow(2,n),mod)*ans % mod;
  cout << (ans+mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 27008
class SWAG():
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        *_,=map(self.append,data[sep:])
        *_,=map(self.appendleft,data[sep-1::-1])
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__init__(self.unit,self.f,self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__init__(self.unit,self.f,self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

Measured memory_bytes: 26064
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int


using namespace std;

const int MAXN = 2005;

int dp[3 * MAXN + 1][6 * MAXN + 1];

inline int lgput(int a, int b, int md) {
	int ans = 1;
	while(b > 0) {
		if(b & 1) ans = (1LL * ans * a) % md;
		b >>= 1;
		a = (1LL * a * a) % md;
	}
	return ans;
}

int main() {
#ifdef HOME
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n, m;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    // daca iei un nr. a[i][j] se ia si a[i][j + 1], daca a[i][j + 1] < a[i][j]
    // impartim nr. in bucket-uri de 1, 2, 3 sortate dupa primul element (b[1] < b[2] < ... < b[k])
    // num[i] = nr. de bucket-uri de i elemente
    // num[1] >= num[2]
    // daca avem l[1], l[2], ..., l[k] lung. => nr. de permutari este: 
    // (3 * N)! / (l[1] * (l[1] + l[2]) * ... * (3 * N))
    
    cin >> n >> m;

    vector<int> inv(3 * n + 1, 1);
    for(i = 1; i <= 3 * n; i++) {
    	inv[i] = lgput(i, m - 2, m);
    }

    dp[0][3 * n] = 1;
    for(i = 0; i < 3 * n; i++) {
    	for(int bal = -3 * n; bal <= 3 * n; bal++) {
    		int cur = dp[i][bal + 3 * n];
    		if(cur == 0) continue;

    		for(int len = 1; len <= 3; len++) {
    			int d = 0;
    			if(len == 1) {
    				d++;
    			}
    			if(len == 2) {
    				d--;
    			}
    			dp[i + len][bal + d + 3 * n] = (dp[i + len][bal + d + 3 * n] + 1LL * cur * inv[i + len]) % m;
    		}
    	}
    }
    //cerr << dp[3 * n][3];
    int ans = 0;
    for(i = 0; i <= 3 * n; i++) {
    	ans = (ans + dp[3 * n][i + 3 * n]) % m;
    }
    for(i = 1; i <= 3 * n; i++) {
    	ans = (1LL * ans * i) % m;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 281088
#include <stdio.h>

int main(void)
{
  int N,i = 0,ans = 0,buf0 = 0,buf1 = 0,j = 0;
  scanf("%d",&N);
  int a[N],b[N];
  for(i = 0;i < N;i++) {
    scanf("%d",&b[i]);
  }

  while(j < N) {
    //printf("ans %d buf0 %d buf1 %d\n",ans,buf0,buf1);
    i = N - 1;
    ans = -1;
    buf0 = buf1 = 0;

    for(i = N - 1;i >= 0;i--) {
      //printf("b[%d] %d\n",i,b[i]);
      buf1 = b[i];

      if(b[i] == i + 1) {
        ans = b[i];
        a[j] = ans;
        b[i] = buf0;
        break;
      }
        //printf("a[%d] %d\n",i,a[i]);

      b[i] = buf0;
      buf0 = buf1;
    }

    if(ans == -1) break;

    j++;
  }

  if(ans == -1) {
    printf("-1\n");
  } else {
    i = N - 1;
    for(i = N - 1;i >= 0;i--) {
      printf("%d\n",a[i]);
    }
  }

  return 0;
}


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

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  const Int MOD = 1e9+7;
  Int n=s.size();
  Int x=0,y=0,z=0,r=1;
  Int inv=(1+MOD)/3;
  for(Int i=0;i<n;i++){
    if(s[i]=='C'||s[i]=='?') z+=y*(s[i]=='?'?inv:1);
    if(s[i]=='B'||s[i]=='?') y+=x*(s[i]=='?'?inv:1);
    if(s[i]=='A'||s[i]=='?') x+=1*(s[i]=='?'?inv:1);
    if(s[i]=='?') r*=3;
    x%=MOD;y%=MOD;z%=MOD;r%=MOD;
  }
  z*=r;
  z%=MOD;
  cout<<z<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  cin >>N;
  vector<int> V(N);
  rep(i,N) {
cin >>V.at(i);
  }
  vector<int> C(N);
  rep(i,N) {
cin >>C.at(i);
  }
  int ans=0;
  rep(i,N) {
if(V.at(i)>C.at(i)) {
ans +=V.at(i)-C.at(i);
}
  }
  cout << ans<< endl;
}
 

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 6e5 + 5;
const int mod = 1e9 + 7;

int dis[maxn];
int vis[maxn];

vector<ii> adj[maxn];
int n , m , n1;
map<ii,int> mmap;
int Add(int u , int c){
    if(mmap.count(mp(u , c)))return mmap[mp(u , c)];
    mmap[mp(u,c)] = ++n;
    adj[u].pb(mp(n , 1));
    adj[n].pb(mp(u , 0));
    return n;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    n1 = n;
    for(int i = 1 ; i <= m ; ++i){
        int u , v , c;cin >> u >> v >> c;
        u = Add(u , c);
        v = Add(v , c);
        adj[u].pb(mp(v , 0));
        adj[v].pb(mp(u , 0));
    }
    fill_n(dis,maxn,1e9);
    deque<int> q;
    dis[1] = 0;
    q.push_back(1);
    while(q.size()){
        int u = q.front();q.pop_front();
        vis[u] = 0;
        for(ii &c : adj[u]){
            if(dis[c.first] > dis[u] + c.second){
                dis[c.first] = dis[u] + c.second;
                if(vis[c.first] == 0){
                    if(c.second == 0)q.push_front(c.first);
                    else q.push_back(c.first);
                    vis[c.first] = 1;
                }
            }
        }
    }
    if(dis[n1] == (int)1e9)cout << -1;
    else cout << dis[n1];
}


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

int main() {
    int N; cin >> N;
    long long march[5] = {0};
    string MARCH = "MARCH";
    for(int i = 0; i < N; ++i) {
        string S; cin >> S;
        for(int j = 0; j < 5; ++j) {
            if(S[0] == MARCH[j]) ++march[j];
        }
    }
    
    long long res = 0;
    for(int i = 0; i < 3; ++i) {
        for(int j = i+1; j < 4; ++j) {
            for(int k = j+1; k < 5; ++k) {
                res += march[i] * march[j] * march[k];
            }
        }
    }
    
    cout << res << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;

int main() {
	int N;
	cin >> N;
	vector<LL> input;
	for(int i=0; i<N; i++)
	 {
	 int p;
	 cin >> p;
	 input.push_back(p);
	 }
	 
	 vector<LL> a,b;
	 
	 LL base = 30000;
	 for(int i=0; i<N; i++) {
	 	a.push_back(i * base+1);
	 	b.push_back((N-1-i) * base + 1);
	 }
	 
	 for(int i=0; i<N; i++) {
	 	a[input[i]-1] += i;
	 }
	 for(int i=0; i<N; i++) {
	 	cout << a[i];
	 	if(i<N-1) cout << " ";
	 	else cout << endl;
	 }
	 for(int i=0; i<N; i++) {
	 	cout << b[i];
	 	if(i<N-1) cout << " ";
	 	else cout << endl;
	 }
	 
	return 0;
}



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

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

    if (s == "Sunny") cout << "Cloudy" << endl;
    if (s == "Cloudy") cout << "Rainy" << endl;
    if (s == "Rainy") cout << "Sunny" << endl;
    
    return 0;
}

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

//1~nまでの要素をもつunionFind
class unionFind{
public:
  int *par, *rank;
  int n;

  unionFind(int n): n(n){
    par = new int[n+1];
    rank = new int[n+1];
    init();
  }

  ~unionFind(){
    delete [] par;
    delete [] rank;
  }

  int find(int x){
    if(par[x] == x){
      return x;
    }
    else {
      return par[x] = find(par[x]);
    }
  }

  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x==y) return ;

    if(rank[x] < rank[y]){
      par[x] = y;
    }
    else{
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }

  void solve(){
    map<pair<int, int>, int> mp;
    for(int i=1; i<=n/2; i++){
      mp[make_pair(find(i), find(n/2+i))]++;
    }

    for(int i=1; i<=n/2; i++){
      cout << mp[make_pair(find(i), find(n/2+i))] << " ";
    }
    cout << endl;
  }

  //デバッグ用
  void print(){
    for(int i=1; i<=n; i++){
      cout << "node: " << i << " parent: " << par[i] << endl;
    }
  }

private:
  void init(){
    for(int i=1; i<=n; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }
};

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

  unionFind uf(2*n);

  for(int i=1; i<=k; i++){
    int p, q; cin >> p >> q;
    uf.unite(p, q);
  }

  for(int i=1; i<=l; i++){
    int r, s; cin >> r >> s;
    uf.unite(n+r, n+s);
  }

  uf.solve();

  return 0;
}


Measured memory_bytes: 15104
L=input().split( )
n=int(L[0])
q=int(L[1])
Que=[0 for i in range(n)]

for i in range(n):
    Que[i]=input().split( )
    Que[i][1]=int(Que[i][1])
    Que[i].append(0)

head=0
Fin=[]
time=0
while Que!=[]:
    l=len(Que)
    if head>l-1:
        head=0
    else:
        if Que[head][1]>q:
            Que[head][1]-=q
            head+=1
            time+=q
        else:
            time+=Que[head][1]
            Que[head][2]+=time
            temp=Que.pop(head)
            Fin.append(temp)
for i in range(n):
    print(Fin[i][0],Fin[i][2])



Measured memory_bytes: 16268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M; cin >> N >> M;
  int k=0;
  vector<vector<int>> MY(N,vector<int>(M+1));
  for(int i=0;i<N;i++){
    cin >> MY.at(i).at(0);
    k=MY.at(i).at(0);
    for (int j=0;j<k;j++){
      cin >> MY.at(i).at(j+1);
    }
  }
  int check=0;
  int check2=0;
  int count=0;
  for(int i=1;i<M+1;i++){
    check2=0;
    for(int j=0;j<N;j++){
      check=0;
      for (int l=1;l<M+1;l++){
        if(MY.at(j).at(l)==i){
          check=1;
          break;
        }
      }
      if (check==1){
        check2++;
      }
      else break;
    }
    if(check2==N){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int Y,M,D;

  Y = stoi(S.substr(0, 4));
  M = stoi(S.substr(5, 2));
  D = stoi(S.substr(8, 2));

  if (Y < 2019) {
    cout << "Heisei" << endl;
    return 0;
  } else if (Y == 2019) {
    if (M < 4) {
      cout << "Heisei" << endl;
      return 0;
    } else if (M == 4) {
      if (D <= 30)
        cout << "Heisei" << endl;
      else
        cout << "TBD" << endl;
    } else
      cout << "TBD" << endl;
  } else
    cout << "TBD" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a,b,c,ans=0;
  cin>>a>>b>>c;
  if(a==b)ans++;
    if(b==c)ans++;
  if(a==c)ans++;
  if(ans<3)cout<<3-ans<<endl;
  else cout<<"1"<<endl;
}

Measured memory_bytes: 256
import sys
range = xrange
input = sys.stdin.readline

n = int(input())
coupl = [[] for _ in range(n)]
for _ in range(n-1):
    u,v = [int(x)-1 for x in input().split()]
    
    coupl[u].append(v)
    coupl[v].append(u)

root = 0
for _ in range(2):
    depth = [-1]*n
    depth[root] = 1
    Q = [root]
    for node in Q:
        d = depth[node]
        for nei in coupl[node]:
            if depth[nei]==-1:
                depth[nei] = d+1
                Q.append(nei)

    root = max(range(n), key = lambda i:depth[i])
dia = depth[root]
if dia%3!=2:
    print 'First'
else:
    print 'Second'

Measured memory_bytes: 82512
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100010
typedef long long ll;
const int mx=100000;
inline int read(){
	int 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<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,qwq,w[N<<2],v[N<<2],Q,lim;
ll dp[1025][N],d[N],sum[N];
void dfs(int u,int dep){
	if(u>n) return ;
	if(dep>qwq/2)return;
	lim=max(lim,u);
	for(int i=mx;i>=w[u];--i){
		dp[u][i]=max(dp[u>>1][i],dp[u>>1][i-w[u]]+v[u]);
	}
	for(int i=w[u]-1;i>=0;--i){
		dp[u][i]=dp[u>>1][i];
	}
	dfs(u<<1,dep+1);
	dfs(u<<1|1,dep+1);
	for(int i=1;i<=mx;++i){
		dp[u][i]=max(dp[u][i],dp[u][i-1]);
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		v[i]=read(),w[i]=read();
	}
	qwq=0;
	while((1<<qwq)<=n)qwq++;
	dfs(1,1);
	Q=read();
	while(Q--){
		int u=read(),L=read();
		if(u<=lim){
			printf("%lld\n",dp[u][L]);
			continue;
		}
		static int p[233],tot=0;
		tot=0;
		while(u>lim){
			p[++tot]=u;
			u>>=1;
		}
		ll ans=dp[u][L];
		d[0]=sum[0]=0;
		for(int i=1;i<(1<<tot);++i){
			int j=__builtin_ffs(i);
			d[i]=w[p[j]]+d[i^(1<<j-1)],sum[i]=v[p[j]]+sum[i^(1<<j-1)];
			if(d[i]>L)continue;
			ans=max(ans,dp[u][L-d[i]]+sum[i]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 405036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans,cnt = 0;
  for (int i=0; i<N; i++) {
    if (S[i]=='A' || S[i]=='T' || S[i]=='C' || S[i]=='G') {
      cnt++;
      
    }
    else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << endl;
}

Measured memory_bytes: 3624
n,m=map(int, input().split()) 
a=list(map(int, input().split()))
s=[list(map(int, input().split())) for i in range(m)]

ans=sum(a)
cnt=0

a.sort()
s=sorted(s, key=lambda x :x[1])
s.reverse()

for i in range(m):
    
        
        for j in range(cnt,s[i][0]+cnt):
            if s[i][1]>a[j]:
                ans+=s[i][1]-a[j]
                cnt+=1
                if j==n-1:
                    print(ans)
                    exit()
            else:
                break
                
print(ans)

Measured memory_bytes: 33732
import Control.Applicative
import Data.List

main = do
  _ <- getLine
  as <- sort . (map (read::String->Int)) . words <$> getLine

  print $ length (func as) - if even(length as - length (func as)) then 0 else 1

  where
    func [] = []
    func lst@(x:xs) = (x, len) : (func (drop len lst))
      where
        len = length (takeWhile (==x) lst)
  


Measured memory_bytes: 31996
k, n = map(int, input().split())
a = list(map(int, input().split()))
a_max = a[0] + (k - a[n-1])
for i in range(n-1):
  if (a[i+1] - a[i]) > a_max:
    a_max = a[i+1] - a[i]
print(k - a_max)

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

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__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_M = 575;
const int MAX_N = 77;

int dp[MAX_N][MAX_M][MAX_M];
// int dpB[MAX_N][MAX_N * MAX_C];

int N, A, B;

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

  cin >> N >> A >> B;
  vector< int > a(N), b(N), c(N);
  REP(i, N)
    cin >> a[i] >> b[i] >> c[i];

  REP(i, MAX_N) {
    REP(j, MAX_M) {
      REP(k, MAX_M) {
	dp[i][j][k] = INF;
      }
    }
  }

  REP(i, MAX_N) {
    dp[i][0][0] = 0;
  }
 
  REP(i, N) {
    REP(j, MAX_M) {
      REP(k, MAX_M) {
	// 入れる時
	dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]],
					    dp[i][j][k] + c[i]);
	// 入れない時
	dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
      }
    }
  }

  int ans = INF;

  FOR(i, 1, MAX_M) {
    int ai = A * i;
    int bi = B * i;
    if (max(ai, bi) >= MAX_M) break;
    ans = min(ans, dp[N][ai][bi]);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;

  
  
  return 0;
}



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

int main(){
    int n;
    cin >> n;
    vector<int> a(1<<n);
    for(int i=0;i<(1<<n);i++){
        cin >> a[i];
    }
    bool ok = true;
    if(a[0]==1) ok=false;
    if(a[(1<<n)-1]==0) ok=false;
    int ans = 0;
    for(int S=1;S<(1<<n);S++){
        bool f = true;
        for(int i=0;i<n;i++){
            if((S>>i)&1){
                int T = S^(1<<i);
                if(a[S]==0 && a[T]==1) ok = false;
                f &= a[T] == 0;
            }
        }
        if(f && a[S]==1) ans++;
    }
    cout << (ok ? ans : -1) << endl;
    return 0;
}


Measured memory_bytes: 7032
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100005;
int n,a[N];
LL f[N],sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]),sum+=abs(a[i]-a[i-1]);
	sum+=abs(a[n]-0);
	for(int i=1;i<=n;i++)
	  f[i]=(LL)abs(a[i]-a[i-1])+(LL)abs(a[i+1]-a[i])-(LL)abs(a[i+1]-a[i-1]);
	for(int i=1;i<=n;i++)
	  printf("%lld\n",sum-f[i]);
	return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int d[100];
int t[13];
int mo[25];
int dfs(int a){
    if(a==n){
        int pre=0,ans=24;
        for(int i=1;i<=24;i++){
            if(mo[i%24]){
                ans=min(i-pre,ans);
                pre=i;
            }
        }
        return ans;
    }
    int x=0,y=0;
    if(mo[d[a]]==0){
        mo[d[a]]=1;
        x=dfs(a+1);
        mo[d[a]]=0;
    }
    if(mo[24-d[a]]==0){
        mo[24-d[a]]=1;
        y=dfs(a+1);
        mo[24-d[a]]=0;
    }
    return max(x,y);
}
int main(void){
    cin>>n;
    t[0]=2;
    for(int i=0;i<n;i++){
        cin>>d[i];
        if(++t[d[i]]>2){
            cout<<0<<endl;
            return 0;
        }
    }
    mo[0]=1;
    cout<<dfs(0)<<endl;
}


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

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

    if (b <= a) {
        cout << "delicious" << endl;
    } else if (x >= b-a) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    V<ll> A(N);
    for(ll &e : A) cin >> e;

    ll sum1 = A[0], sum2 = -A[0];
    for(ll i = 1; i < N - 1; i++) {
        ll nsum1 = max(sum1 + A[i], sum2 - A[i]);
        ll nsum2 = max(sum1 - A[i], sum2 + A[i]);
        sum1 = nsum1;
        sum2 = nsum2;
    }
    cout << max(sum1 + A.back(), sum2 - A.back()) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define repf(i,s,e)  for(int i=s;i<e;i++)
#define repb(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve(){
	int r;
	cin>>r;

	const double pi=acos(-1);

	double ans=2*pi*r;
	cout<<fixed<<setprecision(10)<<ans<<endl;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	if(fopen("input.txt", "r")){
	    freopen("input.txt", "r", stdin),
	    freopen("output.txt", "w", stdout);
	}
	
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3832
n, yen = gets.split.map(&:to_i)

a = b = c = 0

k = yen / 1000

if k - n < 0
  puts Array.new(3, -1) * " "
  exit
end

tmp = k - n

(0..tmp/9).each do |i|
  
  tmp = k - n
  tmp -= 9 * i
  if tmp % 4 == 0
    a = i
    b = tmp / 4
    c = n - a - b
    
    if c >= 0
      puts [a, b, c] * " "
      # puts a + b + c
      exit
    end
  end
end

puts Array.new(3, -1) * " "
exit
  


mai0 = yen % 5000 / 1000
c += mai0 
n -= mai0
yen -= 1000 * mai0

mai1 = yen % 10000 / 5000
b += mai1
n -= mai1
yen -= 5000 * mai1

mai2 = yen / 10000 
a += mai2 
n -= mai2
yen -= 10000 * mai2

if n < 0
  puts Array.new(3, -1) * " "
  exit
end

n += mai2
yen += 10000 * mai2

k = yen / 1000

p [n, yen, a, b, c]
(0..(k-n)/9).each do |i|
  
  ans = ( k - n ) - 9 * i
  if ans % 4 == 0
    puts [a+i, ans/4, c] * " "
    p [n, yen]
  end
end
  

# p [n, yen]

# puts [a, b, c] * " "

Measured memory_bytes: 1788
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

int N, M;
int a[55], b[55];
int x[55], y[55];

int slv(int a, int b)
{
  auto dist = [](int sx, int sy, int gx, int gy){return abs(sx-gx) + abs(sy-gy); };

  int pos = 0;
  int d = dist(a,b, x[0], y[0]);

  for (int i = 1; i < M; ++i) {
    int tmp = dist(a,b, x[i], y[i]);
    if (chmin(d, tmp)) {
      pos = i;
    }
  }
  return pos;
}

signed main()
{

  cin >> N >> M;
  for (int i= 0; i < N; ++i) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> x[i] >> y[i];
  }

  for (int i = 0; i < N; ++i) {
    cout << slv(a[i], b[i])+1 << endl;
  }

  return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append([i, x, y])

X = sorted(X, key=lambda x: x[2])[::-1]

p = 0
L = [0] * (N + 1)
bonus = 0
for i in range(K):
    p += X[i][2]
    if L[X[i][1]] == 0:
        bonus += 1

    L[X[i][1]] += 1

p += bonus ** 2
ma = p
i = K - 1
j = K
while True:
    while j < N and L[X[j][1]]:
        j += 1
    if j == N:
        break
    else:
        while i >= 0 and L[X[i][1]] <= 1:
            i -= 1
        if i < 0:
            break
        else:
            L[X[i][1]] -= 1
            L[X[j][1]] += 1
            p -= X[i][2]
            p += X[j][2]
            p += bonus * 2 + 1
            bonus += 1
            ma = max(ma, p)
            i -= 1

    j += 1

print(ma)



Measured memory_bytes: 25276
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long int ll;
const int N=105;
ll n,k;
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n>>k;
    cout<<min((n%k),k-(n%k));
    return 0;
}


Measured memory_bytes: 256
_ = input()
S = list(input())

temp = 0
left = []
for s in S:
    left.append(temp)
    if s == 'W':
        temp += 1

temp = 0
right = []
for i, s in enumerate(S[::-1]):
    right.append(temp + left[-i-1])
    if s == 'E':
        temp += 1
print(min(right))     


Measured memory_bytes: 31716
#include <iostream>
#include <string>
#include <vector>
#include <functional>

using namespace std;

int main(){
    int N, Q;
    string S;
    vector<int> L;
    vector<int> R;
    int l, r;
    //input
    cin >> N >> Q;
    cin >> S;
    for(int i=0; i<Q; i++){
        cin >> l >> r;
        L.push_back(l);
        R.push_back(r);
    }

    //solve
    vector <int> count;
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(S[i-1] == 'A' && S[i] == 'C')cnt++;
        count.push_back(cnt);
    }


    //output
    for(int i=0; i<Q; i++){
        cout << count[R[i]-1] - count[L[i]-1] << endl;
    }

}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

ll N;
bitset<30> A[30];
ll dp[1<<22];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  for(ll i=0;i<N;i++){
    for(ll j=0;j<N;j++){
      ll a;cin>>a;
      A[i][j]=a&1;
    }
  }
  dp[0]=1;
  for(ll s=0;s<1<<N;s++){
    ll k = __builtin_popcountll(s);
    for(ll b=0;b<N;b++)if(A[k][b]&&!((s>>b)&1)){
      dp[s|(1<<b)] = (dp[s|(1<<b)]+dp[s])%MOD;
    }
  }
  cout<<dp[(1<<N)-1]<<endl;
  return 0;
}


Measured memory_bytes: 18688
#include<iostream>
using namespace std;
int main(){
	int time;
	cin>>time;
	int stone,people;
	for(int i=0;i<time;++i){
		cin>>stone>>people;
		if(stone%people==0){
			cout<<people<<endl;
		}else{
			cout<<stone%people<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;cin>>n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    int l=d[n/2-1],r=d[n/2];
    cout << r - l << endl;
}

Measured memory_bytes: 640
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/22/2019 11:08:25 PM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ostream& operator <<(ostream &out, pii &p){
	return out<<p.first<<" "<<p.second;
}
istream& operator >>(istream &in, pii &p){
	return in>>p.first>>p.second;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//ifstream cin("C:\\Users\\LENOVO\\Desktop\\in.txt");
	//ofstream cout("C:\\Users\\LENOVO\\Desktop\\out.txt");
	int a,b;cin>>a>>b;int cnt[3]={0};cnt[a-1]++;cnt[b-1]++;
	for(int i=0;i<3;i++) {
		if(!cnt[i]) cout<<i+1<<endl;
	}
	return 0;
}


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

int main(){
    ll n;
    cin>>n;
    vector<int>a(100020,0);
    
    rep(i,n){
        ll c;
        cin>>c;
        a[c]++;
    }
    int mx=0;
    rep(i,100020){
       int tmp=a[i]+a[i-1]+a[i+1];
       mx=max(mx,tmp);
    }
    cout<<mx<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int a[210][210];
char s[210];
int f[2][210][210][210];
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		for(int j=1;j<=m;++j){
			a[i][j]=s[j];
		}
	}
	//cerr<<233<<endl;
	for(int i=n;i>=1;--i){
		for(int j=i;j<=n;++j){
			for(int k=m;k>=1;--k){
				if(i==j){
					if(k==m)f[0][i][j][k]=m+1;
					if(a[i][k]==a[i][k+1]){
						f[0][i][j][k]=f[0][i][j][k+1];
					}
					else{
						f[0][i][j][k]=k+1;
					}
				}
				else{
					if(a[j-1][k]==a[j][k]){
						f[0][i][j][k]=min(f[0][i][j-1][k],f[0][j][j][k]);
					}
					else{
						f[0][i][j][k]=k;
					}
				}
			}
		}
	}
	int cur=0;
	for(int ans=0;;++ans){
		if(f[cur][1][n][1]==m+1){
			return printf("%d\n",ans),0;
		}
		int N=cur^1;
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				for(int k=m;k>=1;--k){
					if(f[cur][i][j][k]==m+1){
						f[N][i][j][k]=m+1;
						continue;
					}
					f[N][i][j][k]=f[cur][i][j][f[cur][i][j][k]];
					int l=i,r=j-1;
					while(l<=r){
						int mid=(l+r)/2;
						f[N][i][j][k]=max(f[N][i][j][k],min(f[cur][i][mid][k],f[cur][mid+1][j][k]));
						if(f[cur][i][mid][k]>f[cur][mid+1][j][k]){
							l=mid+1;
						}
						else r=mid-1;
					}
				}
			}
		}
		cur^=1;
	}
}

Measured memory_bytes: 67712
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, k;
  int v[50];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  int ans = 0;
  for (int i = 1; i <= min(k, n); i++) {
    int t = k - i;
    for (int l = 0; l <= i; l++) {
      int r = i - l;
      vector<int> a;
      for (int j = 0; j < l; j++) {
        a.push_back(v[j]);
      }
      for (int j = 0; j < r; j++) {
        a.push_back(v[n-1-j]);
      }
      sort(a.begin(), a.end());
      int sum = 0;
      int tt = t;
      for (int j = 0; j < a.size(); j++) {
        if (a[j] < 0 && tt > 0) {
          tt--;
          continue;
        } 
        sum += a[j];
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
void swap(int *p,int *q){
  int tmp=*p;
  *p = *q;
  *q = tmp;
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld",&n);
  rep(i,n) scanf("%d",&a[i]);
  rep(i,n){
    if(i<n-1&&a[i]==i+1){
      swap(&a[i],&a[i+1]);
      result++;
    }else if(a[i]==i+1){
      swap(&a[i-1],&a[i]);
      result++;
    }
  }
  //rep(i,n) printf("%d ",a[i]);
  //printf("\n");
  printf("%lld", result);
  
  return 0;
}



Measured memory_bytes: 2176
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = (0 until n).map {
        val (t, x, y) = readLine()!!.split(' ').map { it.toInt() }
        Triple(t, x, y)
    }
    var t = 0
    var x = 0
    var y = 0

    val ans = list.all {

        val d1 = (it.first - t)
        val d2 = (Math.abs(it.second - x) + Math.abs(it.third - y))

        t = it.first
        x = it.second
        y = it.third

        d1 >= d2 && (d1 % 2 == d2 % 2)
    }

    println(if (ans) "Yes" else "No")
}

Measured memory_bytes: 59108
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arr = new long[n + 1];
		for (int i = 1; i <= n; i++) {
		    arr[i] = sc.nextInt();
		    arr[i] += arr[i -1];
		}
		int left = 2;
		int right = 4;
		long min = Long.MAX_VALUE;
		for (int center = 3; center <= n - 1; center++) {
		    while (left < center && Math.abs(arr[center - 1] - 2 * arr[left - 1]) > Math.abs(arr[center - 1] - 2 * arr[left])) {
		        left++;
		    } 
		    while (center >= right) {
		        right++;
		    }
		    while (right < n && Math.abs(arr[n] - 2 * arr[right - 1] + arr[center - 1]) > Math.abs(arr[n] - 2 * arr[right] + arr[center - 1])) {
		        right++;
		    }
		    min = Math.min(min, getMax(arr[left - 1], arr[center - 1] - arr[left - 1], arr[right- 1] - arr[center - 1], arr[n] - arr[right - 1]));
		}
		System.out.println(min);
	}
	
	static long getMax(long a, long b, long c, long d) {
	    return Math.max(Math.max(a, b), Math.max(c, d)) - Math.min(Math.min(a, b), Math.min(c, d));
	}
}


Measured memory_bytes: 82144
/*...................bismillahir rahmanir rahim.....................*/
/*
  author :
    Muhammad Najmul hasan Nayeem
    Sust Math 17
*/
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
 
using namespace std;

#define m_p make_pair
#define PB push_back
#define eb emplace_back
#define FF first
#define SS second
#define MX5 100005
#define MX6 1000006
#define MOD 1000000007
#define in()({int a;scanf("%d",&a);a;})
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SC()({char a;scanf("%c",&a);a;})
#define SL()({long long a;scanf("%lld",&a);a;})
#define SD()({double a;scanf("%f",&a);a;})
#define nl '\n'
#define For(_,n) for(int i=_;i<=n;i++)
#define once "once upon a time\n"
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
 
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<string,string> PSS;
// typedef tree<PII,null_type,less<PII>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << "(" << a.FF << ", " << a.SS << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
    out << "[";
    for(int i=0;i<v.size();i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}
 
#define chk(a) cout<<(#a)<<" = "<<a<<endl;
#define chka(a,_) cout<<(#a)<<"["<<_<<"] = "<<a[_]<<"\n";

// int Set(int n,int pos){ return n | (1<<pos); }
// int Reset(int n,int pos){ return n=n & ~(1<<pos); }
// bool Check(int n,int pos){ return (bool)(n & (1<<pos)); }
 
/*............start.............*/
const int md=998244353;
int l[15],r[15];
LL dp[2*MX5],cum[2*MX5];
void solve()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;i++)
    {
        cin>>l[i]>>r[i];
    }
    dp[1]=1;
    cum[1]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<k;j++)
        {
            int x=max(1,i-r[j]);
            int y=max(0,i-l[j]);
            if(y>=x) dp[i]+=cum[y]-cum[x-1];
            if(dp[i]<0) dp[i]+=md;
            dp[i]%=md;
        }
        cum[i]+=cum[i-1]+dp[i];
        cum[i]%=md;
        // for(int i=0;i<=n;i++) cout<<dp[i]<<" \n"[i==n];
    }
    // for(int i=0;i<=n;i++) cout<<dp[i]<<" \n"[i==n];
    cout<<dp[n]<<nl;
}
int main()
{
    // clock_t time_start=clock();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int q=1;
    // cin>>q;
    // SI(q);
    for(int kase=1;kase<=q;kase++)
    {
        // cout<<"Case "<<kase<<": ";
        // printf("Case %d: ",kase );
        solve();
    }
    // clock_t time_end=clock();
    // cerr<<float((time_end-time_start)/CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 6784
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

s = input()
q = ni()
f = 0
top = ''
bot = ''
for _ in range(q):
    w = input().split()
    if w[0] == '1':
        f ^= 1
        top,bot = bot,top
    elif w[1] == '1':
        top += w[2]
    else:
        bot += w[2]
print(top[::-1] + s[::1-f*2] + bot)


Measured memory_bytes: 4408
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner ab = new Scanner(System.in);
 
        int a = ab.nextInt();
        int b = ab.nextInt();
 
        System.out.printf("%d %d\n",a*b,2*(a+b));
    }
}


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

int main()
{
    long long n,tmp, count=1;
    cin >> n;
    vector<long long> p(n);
    for (long long i = 0; i < n;i++){
        cin >> p.at(i);
    }
    tmp = p.at(0);
    for (long long i = 0; i < n; i++)
    {
        if(tmp>p.at(i)){
            count++;
            tmp = p.at(i);
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
char a;
int N,L;
string s[110];
//int cnt2=0;
int main(){
  cin >> N >> L;
  for(int i=0;i<N;i++){
    cin >> s[i];
  }
  sort(s,s+N);
  for(int i=0;i<N;i++){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


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

int main(int argc, const char * argv[]) {
    int A, B;
    cin >> A >> B;
    
    if(A+B >= A-B){
        if(A*B >= A+B){
            cout << A*B;
        } else{
            cout << A+B;
        }
    } else{
        if(A*B >= A-B){
            cout << A*B;
        } else{
            cout << A-B;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#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 Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int q;
  cin >> q;
  rep(qi, q)
  {
    int k;
    cin >> k;
    auto itr = lower_bound(all(a), k);
    cout << distance(a.begin(), itr) << endl;
  }
  return 0;
}



Measured memory_bytes: 3360
s = input('')
t = input('')

len_s=len(s)
len_t=len(t)

d=0
for j in range(len_t):
    if s[j]!=t[j]:
        d+=1
for i in range(len_s - len_t):
    s2 = s[i:i+len_t]
#    print(s2)
    d2=0
    for j in range(len_t):
        if s2[j]!=t[j]:
            d2+=1
#   print("{}/{}".format(s2,t))
    if d2<d:
        d=d2
print(d)



Measured memory_bytes: 9056
#include <stdio.h>
#include <string.h>
char t1[1510];
char t2[1510];
char t3[1510];
int main(){
	int n;
	int a,b;
	int i,j;
	char t;
	scanf("%s",&t1);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",&t3);
		if(strcmp(t3,"replace")==0){
			scanf("%d %d %s",&a,&b,&t2);
			for(j=0;j<b-a+1;j++){
				t1[a+j]=t2[j];
			}
		}
		else if(strcmp(t3,"reverse")==0){
			scanf("%d %d",&a,&b);
			while(a<b){
				t=t1[a];
				t1[a]=t1[b];
				t1[b]=t;
				a++;
				b--;
			}
		}
		else if(strcmp(t3,"print")==0){
			scanf("%d %d",&a,&b);
			for(j=a;j<b+1;j++){
				printf("%c",t1[j]);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 592