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

constexpr int inf = 1e9;

int main() {
    int w, h;
    while(cin >> w >> h, w) {
        vector<vector<char>> s(h, vector<char>(w));
        vector<vector<vector<int>>> d(h, vector<vector<int>>(w, vector<int>(2, inf)));
        using state = tuple<int, int, int, int>;
        priority_queue<state, vector<state>, greater<state>> que;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> s[i][j];
                if(s[i][j] == 'S') {
                    d[h - i - 1][j][0] = d[h - i - 1][j][1] = 0;
                    que.emplace(0, h - i - 1, j, 0);
                    que.emplace(0, h - i - 1, j, 1);
                }
            }
        }
        reverse(begin(s), end(s));
        while(!que.empty()) {
            int cur_d, y, x, step;
            tie(cur_d, y, x, step) = que.top();
            que.pop();
            if(cur_d > d[y][x][step]) continue;
            int inc = step == 0 ? 1 : -1;
            for(int i = 1; i <= 3; ++i) {
                for(int dy = -3 + i; dy <= 3 - i; ++dy) {
                    int ny = y + dy, nx = x + inc * i;
                    if(ny < 0 || h <= ny || nx < 0 || w <= nx || s[ny][nx] == 'X') continue;
                    int nxt_d = cur_d + (isalpha(s[ny][nx]) ? 0 : s[ny][nx] - '0');
                    if(d[ny][nx][!step] > nxt_d) {
                        que.emplace(nxt_d, ny, nx, !step);
                        d[ny][nx][!step] = nxt_d;
                    }
                }
            }
        }

        int ans = inf;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                if(s[i][j] == 'T') {
                    ans = min({ans, d[i][j][0], d[i][j][1]});
                }
            }
        }
        cout << (ans == inf ? -1 : ans) << endl;
    }
}



Measured memory_bytes: 3232
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <vector>
using namespace std;
int n;
int main ()
{
	scanf("%d",&n);
	while(n){
		if(n%10==9) {
			printf("Yes\n");
			return 0;
		}
		n/=10;
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::{HashSet, HashMap, BinaryHeap};

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(x: usize, y: usize)->usize{
    if y == 0{
        return x
    }
    gcd(y, x % y)
}

fn main() {
    input! {
        n: usize,
    }
    let mut t = (n as f64).sqrt().floor() as usize;
    let mut ans = 0;
    while t > 0{
        if n % t == 0{
            ans = n / t + t - 2;
            break;
        }
        t -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
int N, a[300001];
long long O;
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= 3 * N; i++)
		scanf("%d", a + i);
	std::sort(a + 1, a + 3 * N + 1);
	std::reverse(a + 1, a + 3 * N + 1);
	for (int i = 1; i <= N; i++)
		O += a[2 * i];
	printf("%lld\n", O);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){
  int n;
  cin >> n;
  int nums[n];
  for(int i=0;i<n;i++){
    cin >> nums[i];
  }
  int flag =0;
  int even =0;
  for(int i=0; i<n; i++){
    if(nums[i]%2 == 0){
      even++;
    }
  }
  for(int i=0;i<n;i++){
    if(nums[i]%2 == 0){
      if((nums[i]%3 == 0) || (nums[i]%5==0)){
        even--;
      }
    }
  }
  if(even == 0)
    cout << "APPROVED" << endl;
  else
  	cout << "DENIED" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

constexpr int INF = 1 << 30;
constexpr int BASE = 4000;

inline bool match(char c1, char c2) {
    return (c1 == c2 || c1 == '?' || c2 == '?');
}

// t を s から見て相対位置 i-BASE に置くことができるか
inline bool can_place(string &s, string &t, int ns, int nt, int i) {
    for(int j=0;j<nt;++j) {
        if(i+j-BASE < 0 || ns <= i+j-BASE) continue;
        if(!match(s[i+j-BASE], t[j])) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string a[3];
    cin >> a[0] >> a[1] >> a[2];
    int n[3] = {int(a[0].length()), int(a[1].length()), int(a[2].length())};

    // a (位置: 2000) に対する c の位置を i にしてよいか
    vector<bool> ac(2*BASE+1, true);
    for(int i=0;i<=2*BASE;++i) {
        ac[i] = can_place(a[0], a[2], n[0], n[2], i);
    }

    //  // b (位置: 2000) に対する c の位置を i にしてよいか
    vector<bool> bc(2*BASE+1, true);
    for(int i=0;i<=2*BASE;++i) {
        bc[i] = can_place(a[1], a[2], n[1], n[2], i);
    }


    int ans = INF;
    for(int bi=0;bi<=2*BASE;++bi) {
        if(!can_place(a[0], a[1], n[0], n[1], bi)) continue;
        for(int ci=0;ci<=2*BASE;++ci) {
            if(0 <= BASE+(ci-bi) && BASE+(ci-bi) <= 2*BASE && !bc[BASE+(ci-bi)]) continue;
            if(!ac[ci]) continue;
            ans = min(ans, max({BASE+n[0], bi+n[1], ci+n[2]}) - min({BASE, bi, ci}));
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
int cnt[7];
int main(){
    long n;
    cin>>n;
    if(n%2) cout<<2*n<<endl;
    else cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k1,l,sum=0,ans=0,var,a[100005]={0},x,y,z,k2;
int main()
{
    ios
    float p,q;
    cin>>p>>q;
    cout<<(2*q)-p;
 	return 0;
}


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

using namespace std;

int main() {
    int men[6];
    
    for(int i=0;i<6;i++){
        cin >> men[i];
    }

    string str;

    cin >> str;

    int len=str.size();

    int box;
    for(int j=0;j<len;j++){
        if(str[j]=='S'){
            box=men[0];
            men[0]=men[4];
            men[4]=men[5];
            men[5]=men[1];
            men[1]=box;
        }
        else if(str[j]=='N'){
            box=men[0];
            men[0]=men[1];
            men[1]=men[5];
            men[5]=men[4];
            men[4]=box;
        }
        else if(str[j]=='W'){
            box=men[0];
            men[0]=men[2];
            men[2]=men[5];
            men[5]=men[3];
            men[3]=box;
        }
        else if(str[j]=='E'){
            box=men[0];
            men[0]=men[3];
            men[3]=men[5];
            men[5]=men[2];
            men[2]=box;
        }
    }

    cout << men[0] << endl;

    return 0;
}

Measured memory_bytes: 1204
N = int(input())
A = list(map(int, input().split()))
ans=0

for i in range(1, len(A)):
    if A[i-1] >= A[i]:
        ans = ans + A[i-1] - A[i]
        A[i] = A[i] + (A[i-1] - A[i])

print(ans)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main()
{
    int N, T;
    cin >> N >> T;

    vector<P> CT(N);
    rep(i, N) cin >> CT[i].first >> CT[i].second;

    int min = CT[0].second;
    int cost = CT[0].first;
    repd(i, 1, N) {
        if (CT[i].second <= T) {
            if (cost > CT[i].first) {
                cost = CT[i].first;
                min = CT[i].second;
            }
        }
    }

    if (min <= T) cout << cost << endl;
    else cout << "TLE" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<pair<string, int>> vp;
	for (int i = 0; i < n; i++) {
		string s;
		int t;
		cin >> s >> t;
		vp.push_back(make_pair(s, t));
	}
	string x;
	cin >> x;
	int res = 0;
	int flag = 0;
	for (int i = 0; i < n; i++) {
		res += flag * vp[i].second;
		if (x == vp[i].first) flag = 1;
	}
	cout << res << endl;
}









Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> V;
int main(){
	LL sum=0,tot,n;
	cin>>n;
	tot=n;
	if(n==3){
		cout<<"2 5 63"<<endl;;
		return 0;
	}
	rb(i,1,30000){
		if(i%2==0||i%3==0){
			tot--;
			
			sum+=i;
			V.PB(i);
			if(!tot) break;
		}
	}
//	cout<<sum<<" "<<V[n-1]<<endl;
	if(sum%6==1){
		if(V[n-1]%2==0)V[n-1]+=6;
		int OK1=0,OK2=0;
		rl(i,n-1,0){
			if(!OK1&&V[i]%2==0){
				OK1=1;
				V[i]+=2; 
			}
			else
			if(!OK2&&V[i]%3==0){
				OK2=1;
				V[i]+=3;
			}
		}
	}
	else
	if(sum%6==2){
		rl(i,n-1,0){
			if(V[i]%2==0){
				V[i]+=4;
				break;
			}
		}
	}
	else
	if(sum%6==3){
		rl(i,n-1,0){
			if(V[i]%3==0){
				V[i]+=3;
				break;
			}
		}
	}
	else 
	if(sum%6==4){
		rl(i,n-1,0){
			if(V[i]%2==0){
				V[i]+=2;
				break;
			}
		}
	}
	else
	if(sum%6==5){
		if(V[n-1]%3==0)V[n-1]+=6;
		int OK1=0,OK2=0;
		rl(i,n-1,0){
			if(!OK1&&V[i]%2==0){
				OK1=1;
				V[i]+=4; 
			}
			else
			if(!OK2&&V[i]%3==0){
				OK2=1;
				V[i]+=3;
			}
		}
	}
	rb(i,1,n) cout<<V[i-1]<<" ";
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long rui(int n) {
	if (n == 0) {
		return 1;
	}
	else {
		long long x = rui(n - 1);
		return 2 * x;
	}
}
int main() {
	int n, m,yo;
	cin >> n >> m;
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i]>>yo;
	}
	sort(a.begin(), a.end());
	yo = 0;
	for (int i = 1; i < m; i++) {
		yo += n - min(n, a[i]);
	}
	cout << yo << endl;
}


Measured memory_bytes: 3168
def func():
    global n,m,k
    for i in range(n+1):
        for j in range(m+1):
            tmp = i*m + j*n -(j*i)*2
            if tmp == k:
                return "Yes"
    return "No"
n,m,k = map(int,input().split())
ans = func()
print(ans)


Measured memory_bytes: 38768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ShekharN
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            out.println(n / 3);
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21460
#include<cstdio>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

const int CMax = 100002;

int N, Q, H, S, D, min2, min1;

int main(){
    scanf("%d %d %d %d", &Q, &H, &S, &D);
    scanf("%d", &N);
    min2 = min(min(min(8*Q, 4*H), 2*S), D);
    min1 = min(min(4*Q, 2*H), S);
    cout << ((long long)N / 2) * (long long)min2 + ((long long)N % 2) * (long long)min1 << endl;
}


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

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int) (v).size())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;



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

	// h: nr rows
	// w: nr cols
	int h,w,n;
	cin >> h >> w >> n;

	vi frow(h, w + 1);

	REP(i, n) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		frow[x] = min(frow[x], y);
	}
	assert(frow[0] > 0);

	int r = 0, maxc = 0;
	while (++r < h) {
		int lst = frow[r];
		if (lst <= maxc) {
			// is blocked!
			break;
		} else if (lst == maxc + 1) {

		} else {
			maxc++;
		}
	}

	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin>>s;
  bool ok=true;
  int itr=s.length()-1;
  while(ok&&s.length()>0){
    itr=s.length()-1;
    if(s[itr]=='r'){//rだったら
      if(s.length()<6){//6以下で無理
        ok=false;
        break;
      }else{//6以上
        if(s.length()==6){
          string pre=s.substr(itr-5,6);
          if(pre=="eraser"){
            s=s.substr(0,s.length()-6);
            continue;
          }else{
            ok=false;
            break;
          }
        }
        if(s.substr(itr-5,6)=="eraser"){
          s=s.substr(0,s.length()-6);
          continue;
        }else if(s.substr(itr-6,7)=="dreamer"){
          s=s.substr(0,s.length()-7);
          continue;
        }else{
          ok=false;
          break;
        }
      }
    }else if(s[itr]=='e'){//eだったら
      if(s.length()<5){
        ok=false;
        break;
      }
      if(s.substr(itr-4,5)=="erase"){
        s=s.substr(0,s.length()-5);
        continue;
      }else{
        ok=false;
        break;
      }
    }else if(s[itr]=='m'){
      if(s.length()<5){
        ok=false;
        break;
      }
      if(s.substr(itr-4,5)=="dream"){
        s=s.substr(0,s.length()-5);
        continue;
      }else{
        ok=false;
        break;
      }
    }else{
      ok=false;
      break;
    }
  }
  if(ok){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c;
    char d,e;
  	string s;
  	cin>>s;
  for(int i=0;i<3;i++){
  if(s.at(i)=='1')
    s.at(i) = '9';
  else if(s.at(i)=='9') 
    s.at(i) = '1';
  }
 /* else if(a==23)
    cout<<"Christmas Eve Eve"<<endl;
  else
    cout<<"Christmas Eve Eve Eve"<<endl;
  */
  cout<<s<<endl;
  return 0;
}

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

bool is_reap(int i){
	if(!(i%100) && (i%400)) return false;
	if(!(i%4)) return true;
	return false;
}

int main()
{
	int a, b;
	bool flag = false;
	while(cin >> a >> b){
		if(!a && !b) break;
		if(flag)cout << endl;
		flag = true;
		bool flag = false;
		for(int i=a; i<=b; i++){
			if(is_reap(i)){ cout << i << endl; flag = true;}
		}
		if(!flag) cout << "NA" << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin>>N;
  map<int,int> mp;
  rep(i,N){
    int A; cin>>A;
    if(mp[A]){
      cout<<"NO\n";
      return 0;
    }
    mp[A]++;
  }
  cout<<"YES\n";
  return 0;
}

Measured memory_bytes: 9600
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
    	int K = sc.nextInt();

    	int q = K;
    	int count = 1;

    	while(q<=N) {
    		q *=K;
    		count++;
    	}
    	System.out.println(count);

    }

}

Measured memory_bytes: 23252
n=int(input())
a,b,c=map(int,input().split())
dp=[[a,b,c] for i in range(n)]
for i in range(1,n):
  a,b,c=map(int,input().split())
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[n-1]))

Measured memory_bytes: 22772
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
  cin>>n;
  long long int tm=7,f=-1;
  for(int i=1;i<10000000;i++){
   if(tm%n==0)
    {
        f=i;
    	break;
    }
    tm*=10;
    tm+=7;
    tm%=n;
  }
  cout<<f;
}


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

using namespace std;
#define pb push_back

typedef long long ll;

int n;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  cout << (((a1+a2+a3)>=22)?"bust":"win") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ii pair<ll,pair<int,int>>
#define ll long long
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define orta ((bas+son)>>1)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define inf 2000000000
#define N 100005
#define MOD 1000000007
using namespace std;
 
int main() {
 
	int n;

	scanf("%d",&n);

	vector<int> a(n);

	for(int i=0;i<n;i++) scanf("%d",&a[i]);

	int df=0;

	for(int i=0;i<n;i++) {
		df+=(a[i]!=i+1);


	}
	
	printf(df<=2?"YES":"NO");

}

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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main() {
	vector<int> a(3);
	REP(i, 3) {
		cin >> a[i];
	}

	SORT(a);

	int x = a[2] - a[0];
	int y = a[2] - a[1];

	if (x % 2 == 1 && y % 2 == 1) {
		cout << y + abs(x - y) / 2 << endl;
	}
	else if (x % 2 == 0 && y % 2 == 0) {
		cout << x / 2 + y / 2 << endl;
	}
	else {
		cout << min(x, y) + abs(x - y) / 2 + 2 << endl;
	}

	

	
	

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010,maxm=400010;
int n,m,cnt,head[maxn];
struct edge{
    int from,to,next;
}edges[maxm];
char c[maxn];
bool sz[maxn];
inline bool check(int p){
    char hd;
    if(head[p]<0) return false;
    register int j;
    for(j=head[p];!sz[edges[j].to];j=edges[j].next);
    if(j>=0) hd=c[edges[j].to];
    for(;j>=0;j=edges[j].next) if(sz[edges[j].to]){
        if(c[edges[j].to]!=hd) return true;
    }
    return false;
}
inline void dfs(int p){
    sz[p]=false;
    for(register int j=head[p];j>=0;j=edges[j].next) if(sz[edges[j].to]&&(!check(edges[j].to))) dfs(edges[j].to);
}
int main(){
    scanf("%d%d",&n,&m);getchar();
    scanf("%s",c+1);int xx,yy;memset(head,-1,sizeof(head));
    for(register int i=1;i<=m;i++){
        scanf("%d%d",&xx,&yy);
        edges[cnt]=(edge){xx,yy,head[xx]};
        head[xx]=cnt++;
        edges[cnt]=(edge){yy,xx,head[yy]};
        head[yy]=cnt++;
    }
    bool flag;memset(sz,1,sizeof(sz));
    while(true){
        flag=true;
        for(register int i=1;i<=n;i++) if(sz[i]&&(!check(i))){
            flag=false;dfs(i);
        }
        if(flag) break;
    }
    for(register int i=1;i<=n;i++) if(sz[i]){
        printf("Yes\n");return 0;
    }
    printf("No\n");
    return 0;
}

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

int main(){
    int a, b; cin >> a >> b;
    if ((a>b && b!=1) || (a==1 && b!=1)){
        cout << "Alice" << endl;
    } else if (a==b){
        cout << "Draw" << endl;
    } else {
        cout << "Bob" << endl;
    }
    return 0;
}

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

bool is[150];
int n, a[4][4], temp;

int main()
{
	for(int i = 1; i <= 3; ++i)
	{
		for(int j = 1; j <= 3; ++j)
			cin >> a[i][j];
	}
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> temp;
		is[temp] = true;
	}
	for(int i = 1; i <= 3; ++i)
	{
		for(int j = 1; j <= 3; ++j)
		{
			if(is[a[i][j]])
				a[i][j] = 1;
			else 
				a[i][j] = 0;
		}
	}
	for(int i = 1; i <= 3; ++i)
	{
		if(a[i][1] && a[i][2] && a[i][3])
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	for(int i = 1; i <= 3; ++i)
	{
		if(a[1][i] && a[2][i] && a[3][i])
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	if(a[1][1] && a[2][2] && a[3][3])
	{
		cout << "Yes" << endl;
		return 0;
	}
	if(a[1][3] && a[2][2] && a[3][1])
	{
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
long double f[200005],tmp=0,ans=0,s[200005];
inline double cs(double x){
	return x*(x+1)/2;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>f[i],s[i]=cs(f[i])/f[i];
	for(int i=0;i<=n-k+1;i++){
		if(i==0)
			for(int j=0;j<k;j++) 
				tmp+=s[j];
		ans=fmax(ans,tmp);
		if(i==0) continue;
		tmp-=s[i-1],tmp+=s[i+k-1];
	}
	cout<<setprecision(7)<<fixed<<ans;
	return 0;
}
/*
5 5
1 2 2 4 5
*/


Measured memory_bytes: 6528
def check_stable(before_sort_list, after_sort_list):
    N = len(before_sort_list)
    for i in range(0, N, 1):
        for j in range(i+1, N, 1):
            for a in range(0, N, 1):
                for b in range(a+1, N, 1):
                    if before_sort_list[i][1] == before_sort_list[j][1] and before_sort_list[i] == after_sort_list[b] and before_sort_list[j] == after_sort_list[a]:
                        return False
    return True

def bubble_sort(cards_list, N):
    for i in range(0, N, 1):
        for j in range(N-1, i, -1):
            if cards_list[j][1] < cards_list[j-1][1]:
                cards_list[j], cards_list[j-1] = (cards_list[j-1], cards_list[j])
    return cards_list


def selection_sort(cards_list, N):
    for i in range(0, N, 1):
        minj = i
        for j in range(i, N, 1):
            if cards_list[j][1] < cards_list[minj][1]:
                minj = j
        cards_list[i], cards_list[minj] = (cards_list[minj], cards_list[i])
    return cards_list


num_cards = int(input())
cards = input().split(' ')

sorted_cards1 = bubble_sort(cards.copy(), num_cards)
sorted_cards2 = selection_sort(cards.copy(), num_cards)

print(' '.join(sorted_cards1))
print('Stable' if check_stable(cards, sorted_cards1) else 'Not stable')
print(' '.join(sorted_cards2))
print('Stable' if check_stable(cards, sorted_cards2) else 'Not stable')


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

int main(){
	int n=1, y=1, m=1, d=1;
	cin >> n;
	vector<int> ans(n);
	for(int i=0; i<n; i++){
		cin >> y >> m >> d;
		for(int j=y; j<1000; j++){
			for(int k=m; k<=10; k++){
				if(j%3==0 || k%2==1) for(int l=d-1; l<20; l++) ans[i]++;
				else if(k%2==0) for(int l=d-1; l<19; l++) ans[i]++;
				else cout << "OUT" << endl;
				d=1;
			}
			m=1;
			d=1;
		}
	}
	for(int i=0; i<n; i++) cout << ans[i] << endl;
}

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

bool vis[1000000];
int main(){
	int n;
	cin>>n;

	int res = 0;
	while(!vis[n]){
		vis[n] = 1;
		n = n%2 ? 3*n+1 : n/2;
		res++;
	}
	cout<<res+1;
}

Measured memory_bytes: 256
#import<iostream>
#define l long
l N,M,c,n=1,i,o=1e9+7;l m(l a){l g=1,h=2*o-4;while(h/=2){h&1?g=g*a%o:0;a=a*a%o;}return g;}l C(l b){l r=1,d=1;for(;b;--b)r=r*(N-1+b)%o,d=d*b%o;return r*m(d)%o;}main(){std::cin>>N>>M;for(i=2;i*i<=M;++i){c=0;while(M%i<1)++c,M/=i;n=n*C(c)%o;}std::cout<<n*(M^1?N:1)%o<<std::endl;}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    cout << ((x-r < 0 || W < x+r || y-r < 0 || H < y+r) ? "No" : "Yes") << endl;
    return 0;
}

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

bool is_prime(int n){
	for(int i=2; i*i <= n; i++){
		if(n % i== 0)return false;
	}
	return n != 1;
}


int main(){
	int x;
	cin >> x;
	int i=x;

	while(!(is_prime(i))){
		i++;
	}
	cout << i << endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 3000009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n;
ll a[maxn],sum[maxn];

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        sum[i]+=sum[i-1]+a[i];
    }
    ll ans=2e18+999;
    for(int i=1;i<n;i++)
        ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
    printf("%lld\n",ans);
    return 0;
}



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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end() å
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n, x;
vector<int> l;

signed main()
{
    cin >> n >> x;
    l.resize(n);
    rep(i, n)
    {
        cin >> l[i];
    }

    int ans = 1;
    int d = 0;

    rep(i, n)
    {
        d += l[i];
        if (d <= x)
        {
            ans++;
        }
        else
        {
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"


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

	string a,b;
	cin>>a>>b;
	int c=0;
	rep(i,a.size())if(a[i]-b[i])c++;
	cout<<c<<endl;
}


Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long k = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        long biscuits = a;
        long time = k - a + 1;

        if (a + 2 >= b || time < 0) {
            System.out.println(k + 1);
        } else if (time % 2 == 0) {
            biscuits += ((b - a) * (time / 2));
            System.out.println(biscuits);
        } else {
            biscuits += ((b - a) * (time / 2)) + 1;
            System.out.println(biscuits);

        }
    }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int e[n+1],w[n+1];
    e[0] = w[0] = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'W'){
            w[i+1] = 1 + w[i];
            e[i+1] = e[i];
        }else{
            w[i+1] = w[i];
            e[i+1] = 1 + e[i];
        }
    }
    int ans = INT_MAX;
    for(int i=0;i<s.size();i++){
        ans = min(ans,w[i]+e[n]-e[i+1]);
    }
    cout<<ans<<"\n";
    return 0;
}




Measured memory_bytes: 3092
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
using namespace std;

int N, M, path;

void f(vector<vector<int>> &v, vector<int> p) {
    if(p.size() < N) {
        REP(i, N) {
            bool g = true;
            REP(j, p.size()) {
                if(p[j] == i + 1) {
                    g = false;
                    break;
                }
            }
            if(g) {
                vector<int> np(p.size() + 1);
                REP(k, p.size()) {
                    np[k] = p[k];
                }
                np[p.size()] = i + 1;
                f(v, np);
            }
        }
    }
    if(p.size() == N) {
        bool h = true;
        REP(i, N - 1) {
            if(v[p[i] - 1][p[i + 1] - 1] == 0) {
                h = false;
                break;
            }
        }
        if(h) ++path;
    }
    
}

int main(){
    cin >> N >> M;
    vector<vector<int>> v(N);
    REP(i, N) {
        v[i].resize(N);
        REP(j, N) {
            v[i][j] = 0;
        }
    }
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        v[a - 1][b - 1] = v[b - 1][a - 1] = 1;
    }
    vector<int> p(1);
    p[0] = 1;
    f(v, p);
    cout << path << endl;

}


Measured memory_bytes: 256
var print= function(elem){
    console.log(elem);
};

var toInt = function(elem) {
    return parseInt(elem, 10);
};
var toIntArr = function(line) {
    var intArray = line.split(' ').map(toInt);
    if(intArray.length === 1) {
        return intArray[0];
    } else {
        return intArray;
    }
};
var inputs = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

//end of template

var N = toInt(inputs[0]);
var a= toIntArr(inputs[1]);


var sum_array=Array([0]);
var _sum = 0;
for(var i=0;i<N;i++){
    _sum +=a[i];
    sum_array.push(_sum)
}

max_sum = sum_array[sum_array.length-1];
var diff =9999999999999

for(var i=1;i<N;i++){
    diff = Math.min( diff, Math.abs(max_sum - 2*sum_array[i])   )
}


print(diff);

Measured memory_bytes: 38200
#include <iostream>

int calc(int n, int nset, int fee) {
  return ((n / nset) + (n % nset > 0)) * fee;
}

int main() {
  int n, a, b, c, d;
  std::cin >> n >> a >> b >> c >> d;
  std::cout << std::min(calc(n, a, b), calc(n, c, d)) << std::endl;
}



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



int main(){

	int n;
	string a;	
	cin>>n;

	string ans="Yes";
	
	set<string>s;
	std::vector<string> v(n);

	for(int i=0;i<n;i++){
		cin>>a;
		s.insert(a);
		v[i]=a;
	}

	if(s.size()==n){
		for(int i=1;i<n;i++){
			if(v[i-1].at(v[i-1].size()-1) != v[i].at(0)){
				ans="No";
				break;
			}
		}
	}else{
		ans="No";
	}

	cout<<ans;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a<b) {
    for (int i=0; i<b; i++) {
      cout << a;
    }
    cout << endl;
  }
  else {
    for (int i=0; i<a; i++) {
      cout << b;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(b-a) <= d && abs(c-b) <= d) cout << "Yes" << endl;
    else if(abs(a-c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from copy import copy

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(float, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    p = in_nl()

    dp = [0] * (N + 1)
    dp[0] = 1 - p[0]
    dp[1] = p[0]

    for i in range(1, N):
        next_dp = copy(dp)
        for j in range(i + 2):
            next_dp[j] = dp[j] * (1 - p[i])
            if j - 1 >= 0:
                next_dp[j] += dp[j - 1] * p[i]
        dp = next_dp

    print(sum(dp[N // 2 + 1:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 69428
a = [chr(ord('a') + i) for i in range(26)] #a-zまでのリストを作るやつなんでそうなるのか後で聞く
import sys
b = str.lower(sys.stdin.read())
for i in a:
    x = 0
    for j in range(len(b)):
        if b[j] == i:
            x = x + 1
    print(i + ' : ' + str(x))


Measured memory_bytes: 5560
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

	ll dp[51][51][50*50+1] = {0};

	for(int i = 0; i <= n; i++){
		dp[i][0][0]=1;
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 0; k <=50*50; k++){
				if(k-x[i] >= 0){
					dp[i][j][k] = dp[i-1][j-1][k-x[i]] + dp[i-1][j][k];
				}else{
					dp[i][j][k] = dp[i-1][j][k];
				}
			}
		}
	}


	ll ans = 0;

	for(int j = 1; j <= n; j++){
		//cout << ans << endl;
		ans += dp[n][j][j*a];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 51072
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    int a = 0,b = 0;
    rep(i,0,S.size()){
        string str = "01";
        if(S[i] != str[i%2])a++;
    }
    rep(i,0,S.size()){
        string str = "10";
        if(S[i] != str[i%2])b++;
    }
    cout << min(a,b) << endl;
}

Measured memory_bytes: 512
wt,ht,n=map(int,input().split())
# XYA=[list(map(int,input().split())) for i in range(n)]

w=[1]*wt
h=[1]*ht
for i in range(n):
  W,Y,A=map(int,input().split())
  if A==1:
    w=[0]*(W)+w[W:]
  elif A==2:
    w=w[:W]+[0]*(wt-W)
  elif A==3:
    h=h[:ht-(Y+1)+1]+[0]*(Y)
  elif A==4:
    h=[0]*(ht-Y)+h[ht-Y:]

print(sum(w)*sum(h))



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    vector<int> array(N);

    REP(i, N)
        cin >> array[i];

    sort(ALL(array));

    int prev_key = -1;
    int prev_n = 0;

    int pprev_key = -1;
    int pprev_n = 0;

    int current_key = array[0];
    int current_n = 0;

    int max_n = 0;

    REP(i, N)
    {
        if( current_key == array[i] )
            current_n++;

        int current = current_n;
        if( pprev_key == array[i-1] - 2 )
            current += pprev_n;
        if( prev_key == array[i-1] - 1 )
            current += prev_n;

        max_n = max(max_n, current);

        if( current_key != array[i] ) {
            pprev_key = prev_key;
            pprev_n = prev_n;

            prev_key = current_key;
            prev_n = current_n;

            current_key = array[i];
            current_n = 1;
        }
    }

    cout << max_n << endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input())
happy_mat = []
for _ in range(n):
    happy_mat.append(list(map(int, input().split())))

# max happiness after i days doing (a, b, c) on that day is in dp[i][0/1/2]
dp = [[0]*3 for _ in range(n+1)]

dp[1][0] = happy_mat[0][0]
dp[1][1] = happy_mat[0][1]
dp[1][2] = happy_mat[0][2]

for day in range(2, n+1):
    for activity in range(3):
        dp[day][activity] = max(dp[day-1][(activity+1)%3], dp[day-1][(activity+2)%3]) + happy_mat[day-1][activity]

print(max(dp[n]))

Measured memory_bytes: 50164
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

typedef long long ll;

ll X, K, D;

int main() {
  std::cin >> X >> K >> D;
  if (X < 0)  X *= -1;

  ll Xt = X;
  if (K & 1) {
    Xt = X - D;
    K--;
    if (Xt < 0) Xt *= -1;
  }

  ll steps = std::min(K, Xt / (2*D) * 2);
  Xt -= steps * D;
  K  -= steps;

  while (std::abs(Xt - 2*D) < std::abs(Xt) and K >= 2) {
    Xt -= 2*D;
    K -= 2;
  }

  std::cout << std::abs(Xt) << "\n";

  return 0;
}


Measured memory_bytes: 3672
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>

#define SIZE 100000

long int N,C;
long int XV[2][SIZE];
long int gainmax[2][SIZE];
long int gain[2][SIZE];
long int gaintotal=0;
long int reversemax;
long int max=0;

int main(){
#ifdef DEBUG
	printf("DEBUGGING ON\n");
#endif
	scanf("%ld %ld",&N,&C);
	for (int i=0;i<N;++i){
		scanf("%ld %ld",&XV[0][i],&XV[1][i]);
		gaintotal+=XV[1][i];
	}
	gaintotal-=C;
	gain[0][0]=XV[1][0]-XV[0][0];
	gain[1][0]=gaintotal-gain[0][0]+XV[1][0];
	gainmax[0][0]=0;
	if(gainmax[0][0]<gain[0][0])gainmax[0][0]=gain[0][0];
	for (long int i=1;i<N;++i){
		gain[0][i]=gain[0][i-1]+XV[1][i]-XV[0][i]+XV[0][i-1];
		gain[1][i]=gaintotal-gain[0][i]+XV[1][i];
		gainmax[0][i]=gainmax[0][i-1];
		if(gainmax[0][i]<gain[0][i]) gainmax[0][i]=gain[0][i];
	}
	gainmax[1][N-1]=0;
	if(gainmax[1][N-1]<gain[1][N-1])gainmax[1][N-1]=gain[1][N-1];
	for (long int i=N-2;i>=0;--i){
		gainmax[1][i]=gainmax[1][i+1];
		if(gainmax[1][i]<gain[1][i]) gainmax[1][i]=gain[1][i];
	}
	max=gainmax[0][N-1];
	if(max<gainmax[1][0])max=gainmax[1][0];
	for(int i=0;i<N-1;++i){
		if(max<gain[0][i]-XV[0][i]+gainmax[1][i+1])max=gain[0][i]-XV[0][i]+gainmax[1][i+1];
		if(max<gain[1][i+1]-C+XV[0][i+1]+gainmax[0][i])max=gain[1][i+1]-C+XV[0][i+1]+gainmax[0][i];
	}
	printf("%ld\n",max);


	return (0);
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int ab,bc,ca;
    cin >> ab >> bc >> ca;
    cout << ab * bc / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++; 
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
int M, D;
int solve() {
	int cnt = 0;
	for(int i = 2; i <= 9; ++i) {
		for(int j = 2; j <= 9; ++j) {
			if(i * 10 + j > D) continue;
			if(i * j <= M) {
//				debug("%d %d\n", i, j); 
				++cnt;
			} 
		}
	}
	return cnt;
}
int main() {
	read(M), read(D);
	printf("%d\n", solve());
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main() {
    ll h;
    cin >> h;
    if(h == 1) {
        cout << 1 << endl;
        return 0;
    }
    int p = 0;
    ll ans = 0;
    while(h > 0) {
        ans += (1LL << p);
        h /= 2;
        ++p;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

		int a = Integer.parseInt(scanner.next());
		int b = Integer.parseInt(scanner.next());
		int c = Integer.parseInt(scanner.next());
		
		if(a == b && b == c)
			System.out.println("Yes");
		else 
			System.out.println("No");
	}
}


Measured memory_bytes: 21716
import java.io.*;
import java.util.*;


public class Main{
    static HashSet<Integer> set;

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        long MOD = 1000000007;
        //int t = sc.nextInt();
        int t = 1;

        while(t -- > 0)
        {
            int n = sc.nextInt();
            long [] a = new long[n + 1];
            long [] presum = new long[n + 1];
            long [][]dp = new long[n + 1][n + 1];
            for(int i = 1; i <= n; i++) {
                a[i] = sc.nextInt();
                presum[i] = presum[i - 1] + a[i];
            }
            for(int i = 1; i <= n; i++) dp[i][i] = a[i];
            for(int k = 1; k <= n; k ++){
                for(int i = 1; i + k <= n; i++) {
                    dp[i][i + k] = Math.max(a[i] + presum[i + k] - presum[i] - dp[i + 1][i + k],
                            a[i + k] + presum[i + k - 1] - presum[i - 1] - dp[i][i + k - 1]);
                }
            }
            out.println(2 * dp[1][n] - presum[n]);
            //for(int ii = 0; ii <= n; ii++) System.out.println(Arrays.toString(dp[ii]));
        }
        out.close();

        /*
        int n      = sc.nextInt();        // read input as integer
        long k     = sc.nextLong();       // read input as long
        double d   = sc.nextDouble();     // read input as double
        String str = sc.next();           // read input as String
        String s   = sc.nextLine();       // read whole line as String

        int result = 3*n;
        out.println(result);                    // print via PrintWriter
        */
        // Stop writing your solution here. -------------------------------------
        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 128980