akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> Pi(N);
	for(int i = 0; i < N; i++) {
		int p;
		cin >> p;
		Pi[--p] = i;
	}
	int ans = N, cur = 0;
	for(int i = 0; i < N; i++) {
		if(i == 0 || Pi[i-1] < Pi[i]) cur++;
		else cur = 1;
		ans = min(ans, N-cur);
	}
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[])
{
  string s;
  cin >> s;
  
  int cnt = 0;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - i - 1]) {
      cnt++;
    }
  }

  cout << cnt << "\n";
  return 0;
}

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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  long long ans = 1;
  for (int i = n; i > 0; i--)
    ans = ans * i % 1000000007;
  for (int i = m; i > 0; i--)
    ans = ans * i % 1000000007;
  if (abs(n - m) >= 2)
    cout << 0 << endl;
  else if (n == m)
    cout << ans * 2 % 1000000007 << endl;
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n;
		int p = 2000, j = 2000;
		
		for(int i = 0; i < 3; i++){
			n = scan.nextInt();
			if(n < p)p = n;
		}
		for(int i = 0; i < 2; i++){
			n = scan.nextInt();
			if(n < j)j = n;
		}
		
		System.out.println((p + j - 50));
	}
}

Measured memory_bytes: 26336
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  set<int> st;
  while(st.count(a) == 0){
    st.insert(a);
    if(a % 2 == 0)
      a /= 2;
    else{
      a = a*3 + 1;
    }
  }
    cout << st.size()+1 << endl;
}

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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   int a[n][2];
   for(int i = 0 ; i < n ; i++)
      cin >> a[i][0];
   for(int i = 0 ; i < n ; i++)
      cin >> a[i][1];
   int ans = mod;
   for(int i = 0 ; i < (1 << n) ; i++){
      if(__builtin_popcount(i) != (n + 1) / 2)
         continue;
      vector <pii> odd , even;
      for(int j = 0 ; j < n ; j++){
         if((1 << j) & i)
            odd.push_back({a[j][j & 1] , j});
         else
            even.push_back({a[j][1 - (j & 1)] , j});
      }
      sort(odd.begin() , odd.end());
      sort(even.begin() , even.end());
      vector <pii> v;
      for(int i = 0 ; i < odd.size() ; i++){
         v.push_back(odd[i]);
         if(i < even.size())
            v.push_back(even[i]);
      }
      int cur = 0;
      bool bad = false;
      for(int i = 0 ; i < v.size() ; i++){
         if(i && v[i].first < v[i - 1].first)
            bad = true;
         else{
            for(int j = i + 1 ; j < v.size() ; j++)
               if(v[i].second > v[j].second)
                  cur++;
         }
      }
      if(!bad)
         ans = min(ans , cur);
   }
   if(ans == mod)
      ans = -1;
   cout << ans;
   return 0;
}


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

int main(){
  string s,T;
  cin >> s >> T;
  reverse(s.begin(),s.end());
  reverse(T.begin(),T.end());

  bool anothor_flag = false;
  for(int i = 0;i < s.size();i++){

    bool flag = true;
    for(int j = i;j < T.size() + i;j++){
      if(j >= s.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
      }
      else if(!(s[j] == T[j - i] || s[j] == '?')){
        flag = false;
        break;
      }
    }
    if(!flag)continue;
    else{
      s.replace(i,T.size(),T);
      anothor_flag = true;
      break;
    }
  }


  for(int i = 0;i < s.size();i++)
    if(s[i] == '?')s[i] = 'a';

  reverse(s.begin(),s.end());
  if(anothor_flag)cout << s << endl;
  else cout << "UNRESTORABLE" << endl;
}


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

int main() {
  int a_1, a_2, a_3;
  
  cin >> a_1 >> a_2 >> a_3;
  
  if((a_1 + a_2 + a_3) >= 22 ){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int m[200010];

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

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

    map<int, int> mp;
    mp[0]++;
    for (int i = s.size() - 1; i >= 0; --i) {
        m[i] = ((s[i] - '0') * modpow(10, s.size() - 1 - i, 2019) + m[i+1]) % 2019;
        mp[m[i]]++;
    }

    ll res = 0;
    for (auto x : mp){
        res += x.second * (x.second - 1) / 2;
    }
    cout << res << endl;
}

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


int main(void){
    
    int L, c;
    int C[101] = {}, tunnel[1000] = {0}, put = 0;
    
    cin >> L;
    
    for(int i = 1; i <= L; i++){
        cin >> c;
        
        if(c > 0){
            
            // 判定：トンネルにネコが居ないか確認
            if(C[c] == 0){
                C[c] = 1;
                tunnel[ put ] = c;      // トンネルの先頭順番を決める（今回はスタックをイメージ）
                put++;                  // 次の先頭位置が変化するので １ プラスする
            } 
            
            else{
                cout << i << endl;
                return 0;
            }
        }
        
        if(c < 0){
            c *= -1;
            
            // 判定：トンネルにネコが居る　＋　トンネルの先頭は出口を出るネコか確認
            if(C[c] == 1 && tunnel[ put - 1] == c){
                C[c] = 0;
                put--;   
            }
            
            else{
                cout << i << endl;
                return 0;
            }
        }
    }
    
    cout << "OK" << endl;
    
}


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

int n;
string s;

inline string get(int l, int r) {
  string ret = "";
  if (s[l] == 'a') {
    for (int i = l, j = 0, k = 0, m = 0; i <= r; i++) {
      if (s[i] == 'a') {
        ++j;
        if (k <= m) {
          ret += "ab";
          k = j;
        }
      } else {
        ++m;
      }
    }
  } else {
    for (int t = 1; t <= r - l + 1 >> 1; t++) {
      string cur = "";
      for (int i = l, j = 0, k = 0; i <= r; i++) {
        if (++(s[i] == 'a' ? j : k) >= t) {
          cur += s[i];
        }
      }
      ret = max(ret, cur);
    }
  }
  return ret;
}

int main() {
  cin >> n >> s;
  vector<string> t, f;
  for (int i = 0, sum = 0, last = 0; i < n << 1; i++) {
    sum += s[i] == 'a' ? 1 : -1;
    if (sum == 0) {
      t.push_back(get(last, i));
      last = i + 1;
    }
  }
  f.resize(t.size());
  for (int i = (int) t.size() - 1; ~i; i--) {
    f[i] = i == (int) t.size() - 1 ? t[i] : max(f[i + 1], t[i] + f[i + 1]);
  }
  cout << f[0] << endl;
}


Measured memory_bytes: 10624
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	P := make([]int, N)
	for i := 0; i < N; i++ {
		P[i] = ReadInt() - 1
	}
	Q := make([]int, N)
	for i := 0; i < N; i++ {
		Q[P[i]] = i
	}
	max := 1
	v := 1
	for i := 1; i < N; i++ {
		if Q[i-1] < Q[i] {
			v++
			max = Max(max, v)
		} else {
			v = 1
		}
	}
	fmt.Println(N - max)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 7604
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long  n, m; cin >> n >> m;
	vector<pair<bool, long long >> v(n + 1, {false, 0});

	for (long long  i = 1; i <= m; i++) {
		long long  p; cin >> p;
		string s; cin >> s;

		if (s == "AC") {
			if (v[p].ff == false) v[p].ff = true;
		}
		else {
			if (v[p].ff == false) v[p].ss++;
		}
	}

	long long  q1 = 0, q2 = 0;
	for (long long  i = 1; i <= n; i++) {
		q1 += (v[i].ff == true);
		if (v[i].ff == true) q2 += (v[i].ss);
	}

	cout << q1 << " " << q2;

	return 0;
}

Measured memory_bytes: 4472
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define ll long long 
#define il inline
const int maxn=5010;
struct node{
    int sz; 
    vector<ll> a;
}tmpnode;
vector<node> bk;
int n,k;
int p[maxn];
ll c[maxn],vis[maxn];
ll ans=-50000000000000;
ll s[maxn<<1];
ll getmax(const node &u,int r,int len){
    ll mx=-50000000000000;
    deque<int> q; q.push_front(0);
    if (r){
        for (int i=1;i<=len;++i){
            while (!q.empty()&&i-q.back()>r) q.pop_back();
            mx=max(mx,s[i]-s[q.back()]);
            while (!q.empty()&&s[i]<=s[q.front()]) q.pop_front();
            q.push_front(i);
        }
    }
    return mx;
}
void updateans(const node &u){
    memset(s,0,sizeof(s)); int len=0;
    for (int i=0;i<u.a.size();++i){
        ++len;
        s[len]=s[len-1]+u.a[i];
    }
    if (u.sz>=k||s[u.sz]<=0){
        //cout<<"u.sz>=k||s[u.sx]<=0"<<endl;
        ans=max(ans,getmax(u,min(k,u.sz),len));
    }else{
        //cout<<"u.sz<k&&s[u.sz]>0"<<endl;
        if (k%u.sz) ans=max(ans,s[u.sz]*(k/u.sz)+getmax(u,k%u.sz,len));
        else ans=max(ans,s[u.sz]*(k/u.sz-1)+getmax(u,u.sz,len));
    }
}
int main(){
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;++i){
        scanf("%d",&p[i]);
    }
    for (int i=1;i<=n;++i){
        scanf("%lld",&c[i]);
    }
    for (int i=1;i<=n;++i){
        if (!vis[i]){
            int tmp=i; vis[tmp]=1;
            tmpnode.sz=1; 
            tmpnode.a.clear();
            tmpnode.a.push_back(c[tmp]);
            tmp=p[tmp];
            while (tmp!=i){
                vis[tmp]=1;
                tmpnode.sz++;
                tmpnode.a.push_back(c[tmp]);
                tmp=p[tmp];
            }
            tmp=tmpnode.a.size();
            for (int j=0;j<tmp;++j){
                tmpnode.a.push_back(tmpnode.a[j]);
            }
            bk.push_back(tmpnode);
        }
    }
    for (int i=0;i<bk.size();++i){
        updateans(bk[i]);
    }
    printf("%lld",ans);
}

Measured memory_bytes: 4136
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[][] a = new int[2][2];
		for(int i = 0 ; i < 2 ; i++){
			a[0][i] = Integer.parseInt(sc.next());
			a[1][i] = 0;
			if(a[0][i] == 2) a[1][i] = 2;
			else if(a[0][i] == 4 || a[0][i] == 9 || a[0][i] == 6 || a[0][i] == 11) a[1][i] = 1;
		}
		if(a[1][0] == a[1][1]) ou.println("Yes");
		else ou.println("No");
		ou.flush();
	}
}

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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...) 
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, b;
    cin >> n >> m >> b;
    vector<int> r(n), c(m);
    set<pair<int, int>> bombs;
    for (int i = 0; i < b; i++) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        bombs.emplace(x, y);
        r[x]++;
        c[y]++;
    }
    int maxr = *max_element(r.begin(), r.end());
    int maxc = *max_element(c.begin(), c.end());
    vector<int> cr, cc;
    for (int i = 0; i < n; i++) {
        if (r[i] == maxr)
            cr.push_back(i);
    }
    for (int i = 0; i < m; i++) {
        if (c[i] == maxc)
            cc.push_back(i);
    }
    bool f = 1;
    for (int x : cr) {
        for (int y : cc) {
            if (!bombs.count(make_pair(x, y))) {
                f = 0;
                break;
            }
        }
        if (!f)
            break;
    }
    cout << maxr + maxc - f << '\n';
    return 0;
}

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


if N == 3:

    ans = [".aa","b..","b.."]

    for i in ans:
        print (i)

elif N >= 4:

    four = ["abcc","abdd","hhfg","eefg"]
    five = ["ahhgg","ai..f","bi..f","b.jje","ccdde"]
    six = ["add.ff","a.ce..","bbce..",".ffadd","e..a.c","e..bbc"]
    seven = [".iijjkk","fadd...","fa.c...","gbbc...","g...add","h...a.c","h...bbc"]

    ans = [ ["."] * N for i in range(N) ]

    now = 0
    while N-now > 7:

        for i in range(4):
            for j in range(4):

                ans[i+now][j+now] = four[i][j]

        now += 4

    if N - now == 4:
        for i in range(4):
            for j in range(4):

                ans[i+now][j+now] = four[i][j]

    elif N - now == 5:
        for i in range(5):
            for j in range(5):

                ans[i+now][j+now] = five[i][j]

    elif N - now == 6:
        for i in range(6):
            for j in range(6):

                ans[i+now][j+now] = six[i][j]

    else:
        for i in range(7):
            for j in range(7):

                ans[i+now][j+now] = seven[i][j]

    for i in range(N):
        print ("".join(ans[i]))

else:
    print (-1)

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

int main(){

int H, W;
  cin >> H >> W;
bool a = false;  
  
char d[H + 2][W + 2];
  for(int i = 0; i < W + 2;i++) d[0][i] = '.';
  for(int i = 0; i < W + 2;i++) d[H + 1][i] = '.';
  for(int i = 1; i < H + 1;i++) d[i][0] = '.' ;
  for(int i = 1; i < H + 1;i++) d[i][W + 1] = '.';
  
  for(int i = 1;i < H + 1;i++){
    for(int j = 1;j < W + 1;j++){
    char s;
      cin >> s;
      d[i][j] = s;
    }    
  }
 
  for(int i = 1;i < H + 1;i++){
    for(int j = 1;j < W + 1;j++){
      if((d[i][j] == '#') && (d[i - 1][j] == '.') && (d[i + 1][j] == '.') && (d[i][j - 1] == '.') && (d[i][j + 1] == '.')){
      a = true;
        break;
      }
    }
  }
  
  if(a == true) cout << "No" << endl;
  else cout << "Yes" << endl;
       
return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}

int main()
{
    int a, b;
    cin >> a >> b;
    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
}

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

int main(){
    int N;
    cin >> N;
    vector<int> Ns(N);
    for(int i = 0;i < N;i++){
        cin >> Ns[i];
    }

    for(int i = N - 1;i >= 1;i--){
        if(Ns[i - 1] - 1 > Ns[i]){
            cout << "No" << endl;
            return 0;
        }
        else if(Ns[i - 1] - 1 == Ns[i]){
            Ns[i - 1]--;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 640
// finish date: 2018/01/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int fact(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans *= i;
    }
    return ans;
}

int main() {
    int H,W;
    cin>>H>>W;
    string S;
    rep(i,H){
        cin>>S;
        cout<<S<<endl;
        cout<<S<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1<<30
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M;
bool G[50][50];
bool used[50];

bool dfs(ll s) {
    ll i;
    ll cnt=0;
    queue<ll> q;
    for(i=0; i<N; i++)
        used[i]=0;
    
    used[s]=1;
    ll u;
    q.push(s);
    while(q.size()) {
        u=q.front(); q.pop();
        for(i=0; i<N; i++) {
            if(G[u][i] && !used[i]) {
                used[i]=1;
                q.push(i);
            }
        }
    }
    
    for(i=0; i<N; i++) {
        if(used[i]) cnt++;
    }
    
    return cnt==N;
}

int main() {
    ll i, j, a, b;
    cin >> N >> M;
    for(i=0; i<M; i++) {
        cin >> a >> b;
        a--; b--;
        G[a][b]=G[b][a]=1;
    }
    ll ans=0;
    for(i=0; i<N; i++) {
        for(j=i+1; j<N; j++) {
            if(G[i][j]) {
                G[i][j]=G[j][i]=0;
                if(!dfs(0)) ans++;
                G[i][j]=G[j][i]=1;
            }
        }
    }
    
    cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>p(n);
  int a=0;
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  for(int i=0; i<n; i++){
    if(p[i]!=i+1){
      a++;
    }
  }
  if(a==0 || a==2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int a[MAX], ans[MAX], lis[MAX];
int n;

void dfs(int source, int father, int best) {
    int pos = lower_bound(lis + 1, lis + n + 1, a[source]) - lis;
    int prv = lis[pos];
    lis[pos] = a[source];
    ans[source] = max(best, pos);
    for (auto &each : adj[source]) {
        if (each == father) continue;
        dfs(each, source, max(best, pos));
    }
    lis[pos] = prv;
}

void solve() {
    cin >> n;
    fori (i, 1, n + 1) cin >> a[i];
    fori (i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    memset(lis, 0x3F, sizeof lis);
    dfs(1, -1, 0);
    fori (i, 1, n + 1) cout << ans[i] << '\n';
}

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



Measured memory_bytes: 31232
module Main where
 
import           Debug.Trace
import qualified Data.Vector.Unboxed as VU
 
main :: IO ()
main = do
    [n, vertexX, vertexY] <- map read . words <$> getLine
 
    let shortestList = [((aaaa (i,j) vertexX vertexY) - 1,1) | i<-[1 .. n-1], j<-[i+1..n] ]

    let aaaList = 
                sumShortest shortestList n
    
    --mapM putStrLn (map  (\x->show (snd x))  aaaList)
    VU.mapM_ print (trace (show aaaList) aaaList)
 
aaaa :: (Int,Int) -> Int -> Int -> Int
aaaa x vertexX vertexY  =  min (abs (start-vertexX) + 1 + abs (end-vertexY)) (end - start)
  where
    start    = fst x :: Int
    end      = snd x :: Int
    smaller a b = if a < b then a else b
 
sumShortest :: [(Int,Int)] -> Int-> VU.Vector Int
sumShortest shortestList n =
    VU.accum (+) (VU.replicate (n-1) 0) shortestList

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

typedef long long int ll;
typedef unsigned long long int ull;

int main() {
  int n;

  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
    cout << "hon"
         << "\n";
  } else if (n == 3) {
    cout << "bon"
         << "\n";
  } else {
    cout << "pon"
         << "\n";
  }
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
int a[maxn], x[maxn];
int main(){
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k%2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int n,p,odd=0;
    cin>>n>>p;
    int v[n];
    for(int i=0;i<n;i++){
      cin>>v[i];
      if (v[i]%2) odd++;}
  if(odd==0)
  {if(p==1) cout << 0 << endl;
  else cout <<  (long long) pow(2,n)<< endl;
  }
  else  cout << (long long) pow(2,n-1)<< endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int A = ni();
        int B = ni();
        double T = ni() + 0.5;

        out.println((int) (T / A) * B);
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 22996
#include <iostream>
#define maxn 100005
using namespace std;
int n, pre[maxn];

int main()
{
	cin>>n;
	int ans = 0, cnt = 0;
	for(int i=1;i<=n;i++){
		cin>>pre[i];
		if(pre[i] > pre[i - 1]) cnt = 0;
		else{
			cnt ++;
			ans = max(ans, cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  for(int i=K;i<N;i++){
    if(A.at(i)>A.at(i-K)) cout << "Yes" << endl;
    else  cout << "No" << endl;
  }

  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=1000000007>struct fp {
   int v; static unsigned get_mod(){return mod;}
   int inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp():v(0){}
   fp(ll x):v(x>=0?x%mod:mod+(x%mod)){}
   fp operator-()const{return fp(-v);}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){if((v+=x.v)>=(int)mod)v-=mod; return *this;}
   fp& operator-=(const fp& x){if((v+=mod-x.v)>=(int)mod)v-=mod; return *this;}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
}; using Fp=fp<>;
template<typename T>struct factorial {
   vector<T> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1;
      rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv();
      for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];}
   }
   T fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   T inv(int n){return Inv[n];}
   T nPr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[n-r];}
   T nCr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

factorial<Fp> fact(501010);

int main(){
   int n,m; cin>>n>>m;
   Fp res;
   rep(i,0,n+1){
      Fp add=fact.nCr(m,i)*fact.nPr(n,i)*(fact.nPr(m-i,n-i)).pow(2);
      if(i&1)res-=add; else res+=add;
   }
   cout<<res.v<<endl;
   return 0;
}

Measured memory_bytes: 8844
# https://atcoder.jp/contests/abc153/tasks/abc153_f
# 座標圧縮、貪欲法、imos法


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


# まず、何回攻撃すればいいのかを計算する。これがとにかく必要だ(なくてもいいけど)。
#
# 素直な戦略として、左から倒せるギリギリの爆弾を投下して倒すのが最適
# だけどナイーブに実装すると、O(N^2)。だから体力を管理するのが重要。
# どこにどれだけダメージが蓄積したのかはimos法(デルタ関数をおいてから累積和)で管理できる。

from bisect import bisect_left


def main():
    N, D, A = read_ints()
    XH = read_tuple(N)
    XH.sort()  # 座標でソート

    n_atk = []  # 何回攻撃するのが必要か
    X = []  # 座標アクセス用配列
    for x, h in XH:
        n_atk.append((h - 1) // A + 1)
        X.append(x)

    damege = [0] * (N + 10)  # ダメージ管理用、配列外アクセスがめんどくさいので長めに取る
    ans = 0
    # j = 0  # 次のxが、今のx+2d以下でもっとも大きなidx
    for i, (x, n) in enumerate(zip(X, n_atk)):
        damege[i] += damege[i - 1]  # 積分して、現時点の蓄積回数を表示
        atk = max(0, n - damege[i])  # iには何回攻撃したか
        ans += atk
        # 攻撃下回数を記録
        damege[i] += atk
        # 効果が切れる点を予約 # 尺取ならO(1)で次に行けるけど二分探索でも間に合うか
        # while j < len(X) and X[j] < x + 2 * D + 1:  # あんま高速化しないね
        #     j += 1
        # damege[j] -= atk  # 効果切れを予約
        damege[bisect_left(X, x + 2 * D + 1, lo=i)] -= atk  # 二分探索で十分速い

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 48656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		//String g = sc.next();
		long n = sc.nextLong();
		long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		//long count=0;

		/*for(int i=1;i<=n;i++) {

		}*/
		if(n<=8 && m<=8) {
			System.out.println("Yay!");
		}else{
			System.out.println(":(");
		}
		//System.out.println((int)Math.ceil((n+m)/2.0));
		//System.out.println(s.substring(0,1)+t.substring(1,2)+g.substring(2,3));
	}
}




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

using namespace std;

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

ll cnt[10];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, N;
	cin >> H >> W >> N;
	map<P, int> mp;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		for (int j = a - 1; j <= a + 1; j++) {
			for (int k = b - 1; k <= b + 1; k++) {
				if (j <= 0 || j >= H - 1 || k <= 0 || k >= W - 1) continue;
				mp[P(j, k)]++;
			}
		}
	}

	cnt[0] = (ll)(H - 2) * (W - 2) - mp.size();
	for (auto p : mp) cnt[p.second]++;
	for (int i = 0; i < 10; i++) cout << cnt[i] << endl;
	return 0;
}

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

int main () {
      char a[200005];
      int sum = 0;
      cin >> a;
      int n = strlen (a);
      for (int i=0; i<n; i++) {
            sum += a[i] - 48;
      }
      if (sum%9==0) {
            cout << "Yes" << endl;
      }
      else {
            cout << "No" << endl;
      }
      return 0;
}


Measured memory_bytes: 3788
#include<cassert>
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const double eps = 1e-10;

class Point{
public:
  double x,y,z;
  double dist(){
    return sqrt(x*x+y*y+z*z);
  }
  Point operator+(Point a)const{
    return (Point){x+a.x,y+a.y,z+a.z};
  }
  Point operator-(Point a)const{
    return (Point){x-a.x,y-a.y,z-a.z};
  }
  Point operator*(double a)const{
    return (Point){a*x,a*y,a*z};
  }
  Point operator/(double a)const{
    return (Point){x/a,y/a,z/a};
  };
};

//Lib
double dot(Point A,Point B){
  return A.x*B.x + A.y*B.y + A.z*B.z;
}

//Lib
Point CircumCenter(Point A,Point B,Point C){
  Point ret;
  double a=(B-C).dist(),b=(C-A).dist(),c=(A-B).dist();
  double cosA=dot(B-A,C-A)/(b*c);
  double s=(c-b*cosA)/(2*c*(1-cosA*cosA));
  double t=(b-c*cosA)/(2*b*(1-cosA*cosA));
  ret=(B-A)*s+(C-A)*t+A;
  return ret;
}

//Lib
Point normal_vector(Point a,Point b){
  Point ret =(Point){a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x};
  double len=ret.dist();
  ret=ret/len;
  return ret;
}

double isp(Point a,Point b,Point c){
  return (a-c).dist()+(b-c).dist() < (a-b).dist() + eps;
}

bool is_contain_all(Point a,double r,vector<Point> &in){
  rep(i,in.size()){
    if ((in[i]-a).dist() <r+eps);
    else return false;
  }
  return true;
}

double solve(Point cir,Point norm,vector<Point> &in,Point check,
	     double d,double f){//d=(A+B)/2).dist(),f=(cir-(A+B)/2)/dist()
  double l = 0,r=50;
  double mid,ret=1e6;
  //  while(r-l >eps){
  rep(i,100){
    double mid = (l+r)/2;
    Point vec = cir+norm*mid;
    double radius = (vec-check).dist();

    if (is_contain_all(vec,radius,in))r=mid-eps,ret=min(ret,radius);
    else l=mid+eps;
  }
  return ret;
}

double solve(vector<Point> & in){
  double ret = 1e6;
  
  rep(i,in.size()){
    REP(j,i+1,in.size()){
      REP(k,j+1,in.size()){
	if (isp(in[i],in[j],in[k])||isp(in[i],in[k],in[j])
	    ||isp(in[j],in[k],in[i])){
	  continue;
	}
	Point cir = CircumCenter(in[i],in[j],in[k]);
	double r =(cir-in[i]).dist();

	if (is_contain_all(cir,r,in))ret=min(ret,r);
	
	Point norm= normal_vector(in[j]-in[i],in[k]-in[i]);
	Point tmp = (in[i]+in[j])/2-in[i];
	Point tmp2= (cir-(in[i]+in[j])/2);
	ret=min(ret,solve(cir,norm,in,in[i],tmp.dist(),tmp2.dist()));
	norm=norm*-1;
	ret=min(ret,solve(cir,norm,in,in[i],tmp.dist(),tmp2.dist()));
	
      }
    }
  }
  
  rep(i,in.size()){
    REP(j,i+1,in.size()){
      Point center=(in[i]+in[j])/2;
      double r = (center-in[i]).dist();
      if (is_contain_all(center,r,in))ret=min(ret,r);
    }
  }

  return ret;
}

main(){
  int n;
  while(cin>>n && n){
    vector<Point> in;
    rep(i,n){
      double x,y,z;
      cin>>x>>y>>z;
      in.push_back((Point){x,y,z});
    }

    printf("%.8lf\n",solve(in));
  }
}

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

int main(){
   int N;
   cin >> N;
   vector<int> p(N);
   for (int i=0; i<N; i++)
      cin >> p.at(i);

   vector<int> sortp(N);
   sortp = p;
   sort(sortp.begin(), sortp.end());
   bool flag;
   if (p == sortp)
      flag = true;
   else
      flag = false;

   vector<int> q(N);
   vector<int> sortq(N);

   for (int i=0; i<N-1; i++)
      for (int i2=i+1; i2<N; i2++){
         q = p;
         q.at(i) = p.at(i2);
         q.at(i2) = p.at(i);
         sortq = q;
         sort(sortq.begin(), sortq.end());
         if (q == sortq){
            flag = true;
            break;
         }
      }

   if (flag)
      cout << "YES" << endl;
   else
      cout << "NO" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<double > a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(),a.end());
	double ans = a.at(0);
	rep(i,n-1) ans = (ans + a.at(i+1)) / 2.0;
	cout << setprecision(20) << fixed << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

	int N, x[123], y[123], h[123], mh = 0;
	scanf("%d", &N);

	rep(i, N) {
		scanf("%d%d%d", &x[i], &y[i], &h[i]);
		mh = max(h[i], mh);
	}

	rep(Cx, 101) {
		rep(Cy, 101) {
			rep(H, 300) {
				bool f = true;
				rep(i, N) {
					if (max(H + mh - abs(x[i] - Cx) - abs(y[i] - Cy), 0ll) != h[i]) {
						f = false;
						//break;
					}
				}
				if (f) {
					printf("%lld %lld %lld\n", Cx, Cy, mh + H);
					return 0;
				}
			}
		}
	}

	return 0;
}


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

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> num(k,0);
  for(int i = 1; i<=n; i++) num[i%k]++;
  ll ans=0;
  rep(i,k){
    int a,b,c;
    a = i;
    b = (k-a) % k;
    c = (k-a) % k;
    if((b+c)%k!=0) continue;
    ans+=num[a]*num[b]*num[c];
  }
  cout<<ans<<endl;
}


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

template<typename T>
struct imos2d{
	int n,m;
	T mod;
	vector<vector<T>>sum;
	bool flag=false;

	imos2d(){}
	imos2d(int n,int m,T mod=-1)
		:n(n),m(m),mod(mod),sum(vector<vector<T>>(n+2,vector<T>(m+2))){}
	
	void add(int x1,int y1,int x2,int y2,T t){
		assert(!flag);
		x1++;y1++;x2++;y2++;
		sum[x1][y1]+=t;
		sum[x1][y2+1]-=t;
		sum[x2+1][y1]-=t;
		sum[x2+1][y2+1]+=t;
		if(mod!=-1){
			sum[x1][y1]%=mod;
			(sum[x1][y2+1]+=mod)%=mod;
			(sum[x2+1][y1]+=mod)%=mod;
			sum[x2+1][y2+1]%=mod;
		}
	}
	
	void calc(){
		flag=true;
		rep(i,n+1)for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i][j-1];
			if(mod!=-1)sum[i][j]%=mod;
		}
		rep(i,m+1)for(int j=1;j<=n;j++){
			sum[j][i]+=sum[j-1][i];
			if(mod!=-1)sum[j][i]%=mod;
		}
	}

	T get(int x,int y){
		if(!flag)calc();
		x++;y++;
		return sum[x][y];
	}
};

template<typename T>
struct sum1d{
	int n;
	T mod;
	vector<T>sum;
	bool flag=false;

	sum1d(){}
	sum1d(int n,T mod=-1):n(n),mod(mod),sum(vector<T>(n+2)){}

	void add(int x,T t){
		x++;
		sum[x]+=t;
		if(mod!=-1)sum[x]%=mod;
	}

	void calc(){
		flag=true;
		for(int i=1;i<=n;i++){
			sum[i]+=sum[i-1];
			if(mod!=-1)sum[i]%=mod;
		}
	}

	T get(int l,int r){//[l,r)
		T res=sum[r]-sum[l];
		if(mod!=-1){
			while(res<mod)res+=mod;
			res%=mod;
		}
		return res;
	}
};

P dat[20000];
int N;
void init(int n){
	N=1;while(N<n)N<<=1;
	for(int i=N;i<2*N;i++)dat[i].second=i-N;
}
void update(int k,int x){
	k+=N;
	dat[k].first=x;
	while(k>1){
		k=(k-1)/2;
		dat[k]=max(dat[k*2],dat[k*2+1]);
	}
}
P query(int l,int r){
	P res=P(0,0);
	for(l+=N,r+=N;l<r;l>>=1,r>>=1){
		if(l&1)res=max(res,dat[l++]);
		if(r&1)res=max(res,dat[--r]);
	}
	return res;
}

ll a[6000],b[6000][300];

imos2d<ll>sum;
sum1d<ll>asum;

void dfs(int l,int r){//[l,r]
	if(l>r)return;
	P p=query(l,r+1);
	sum.add(l,p.second,p.second,r,p.first);
	dfs(l,p.second-1);
	dfs(p.second+1,r);
}

int main(){
	int n,m;scanf("%d%d",&n,&m);
	asum=sum1d<ll>(n-1);
	rep(i,n-1){
		scanf("%lld",&a[i]);
		asum.add(i,a[i]);
	}
	rep(i,n)rep(j,m)scanf("%lld",&b[i][j]);
	sum=imos2d<ll>(n,n);
	init(n);
	rep(i,m){
		rep(j,n)update(j,b[j][i]);
		dfs(0,n-1);
	}
	asum.calc();
	ll Max=0;
	rep(i,n)for(int j=i;j<n;j++){
		Max=max(Max,sum.get(i,j)-asum.get(i,j));
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 208384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N; cin>>N;
  ll a[N]; CINA(a,N);
  ll M = N-1;
  ll d[M]; REP(i,M){ d[i] = a[i+1]-a[i];}
  ll mode = 0;
  ll r = 1;
  REP(i,M){
    if(mode==0){
      if(d[i]==0){mode=0; continue;}
      else{ mode = 2*(d[i]>0)-1; continue; }
    }
    if(d[i]>0 && mode<0){
      ++r; mode=0;
    }else if(d[i]<0 && mode>0){
      ++r; mode=0;
    }
  }
  cout << r <<"\n";
  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 1; i < n; i++) {
        vi find(26, 0);
        int save = 0;
        for(int j = 0; j < i; j++) {
            for(int k = i; k < n; k++) {
                if(s[j] == s[k]) {
                    if(find[s[j] - 'a'] == 0) {
                        save++;
                        find[s[j] - 'a']++;
                        break;
                    }
                    else {
                        break;
                    }
                }
            }
        }
        ans = max(ans, save);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(10)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main() {
	int n = in(), m = in(), X = in(), Y = in();
	vector<int>x(n + 1);
	x[0] = X;
	REP1(i, n) {
		x[i] = in();
	}
	sort(ALL(x));
	vector<int>y(m + 1);
	y[0] = Y;
	REP1(i, m) {
		y[i] = in();
	}
	sort(ALL(y));
	cout << (x.back() < y.front() ? "No War" : "War") << endl;
}

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

int main() {
  string A;
  cin >> A;
  char B = A[2];
  if (count(A.begin(),A.end(),A[2]) >= 3  && A[1] == A[2]) {
   	 cout << "Yes" << endl;
  } else {
   	cout << "No" << endl; 
  }
}

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

print(*A)
for i in range(1, n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(*A)


Measured memory_bytes: 5984
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> L(M), R(M), D(M);
	REP(i, M) scanf("%d %d %d", &L[i], &R[i], &D[i]), --L[i], --R[i];
	
	vector<vector<pii>> g(N);
	REP(i, M) {
		g[L[i]].emplace_back(R[i], D[i]);
		g[R[i]].emplace_back(L[i], -D[i]);
	}
	
	vector<int> x(N, -1), done(N, false);
	
	bool ok = true;
	
	REP(i, N) {
		if (done[i]) continue;
		queue<int> que;
		que.push(i);
		done[i] = true;
		x[i] = 0;
		while (!que.empty()) {
			int u = que.front(); que.pop();
			
			for (pii e : g[u]) {
				int v = e.fi, d = e.se;
				if (chmax(done[v], true)) {
					x[v] = x[u] + d;
					que.push(v);
				}
				else {
					ok &= x[v] == x[u] + d;
				}
			}
		}
	}
	
	puts([&] {
		return ok;
	}() ? "Yes": "No");
	
	return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5, mod = 1e9 + 7;
struct lpl{
	int dfn, low, num;
}node[maxn];
struct ld{
	int u, v;
}edge[maxn];
int N, M, K, br, cnt, ent, tot, bnt = -1;
int scc[maxn], b[maxn], d[maxn], w[maxn];
long long ans = 1, fac[maxn], inv[maxn];
bool vis[maxn];
vector<int> point[maxn];
stack<int> s;
set<int> st[maxn];

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

inline long long C(int n, int m){
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

inline long long fpow(int a, int b){
	long long ret = 1, tmp = a;
	while(b){
		if(b & 1) ret = ret * tmp % mod;
		tmp = tmp * tmp % mod; b >>= 1;
	}
	return ret;
}

inline long long polya(int t){
	long long ret = 0;
	for(int i = 1; i <= t; ++i) ret = (ret + fpow(K, gcd(i, t))) % mod;
	return ret * fpow(t, mod - 2) % mod;
}

inline void putit(){
	scanf("%d%d%d", &N, &M, &K);
	for(int u, v, i = 1; i <= M; ++i){
		scanf("%d%d", &u, &v);
		edge[++bnt] = (ld){u, v}; point[u].push_back(bnt);
		edge[++bnt] = (ld){v, u}; point[v].push_back(bnt);
	}
}

inline void tarjan(int t, int fa){
	node[t].dfn = node[t].low = ++cnt;
	for(int i = point[t].size() - 1; i >= 0; --i){
		int now = edge[point[t][i]].v;
		if(!node[now].dfn){
			s.push(point[t][i]); tarjan(now, t);
			node[t].low = min(node[t].low, node[now].low);
			if(node[now].low >= node[t].dfn){
				ent++; int lpd = 0;
				while(true){
					lpd++;
					int qwe = s.top(); s.pop();
					if(node[edge[qwe].u].num != ent){w[ent]++; node[edge[qwe].u].num = ent;}
					if(node[edge[qwe].v].num != ent){w[ent]++; node[edge[qwe].v].num = ent;}
					scc[qwe] = ent; scc[qwe ^ 1] = ent; if(qwe == point[t][i]) break;
				}
				if(lpd == w[ent]) ans = ans * polya(lpd) % mod;
				if(lpd < w[ent]) ans = ans * K % mod;
				if(lpd > w[ent]) ans = ans * C(lpd + K - 1, K - 1) % mod;
			}
		}
		else if(node[now].dfn < node[t].dfn && now != fa){
			s.push(point[t][i]); node[t].low = min(node[t].low, node[now].dfn);
		}
	}
}

inline void workk(){
	for(int i = 1; i <= N; ++i)
		if(!node[i].dfn) tarjan(i, 0);
	cout << ans;
}

inline void print(){

	for(int i = 1; i <= ent; ++i){
		if(d[i] < b[i]) ans = ans * C(b[i] + K - 1, K - 1) % mod;
		if(d[i] == b[i]) ans = ans * polya(b[i]) % mod;
		if(d[i] > b[i]) ans = ans * K % mod;
	}
	cout << ans % mod;
}

inline void prepare(){
	fac[0] = 1; inv[0] = 1; 
	for(int i = 1; i <= 3000; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[3000] = fpow(fac[3000], mod - 2); 
	for(int i = 2999; i >= 1; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}

int main()
{
	//freopen("lpl.in", "r", stdin);
	putit();
	prepare();
	workk();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <set>
#include <string.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    set<int>s;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(s.count(x))
        {
            s.erase(x);
        }
        else s.insert(x);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864