akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

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

const long long INF = 1LL << 60;

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1

void print(const std::vector<ll>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main() {
    ll N,P[8]={},Q[8]={},p_index=0, q_index=0;
    vector<ll> v;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        v.push_back(i+1);
        cin>>P[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin>>Q[i];
    }
    
    // for (int i = 0; i < N; i++)
    // {
    //     cout << v[i] << endl;
    //     cout << "P[" << i << "]: " << P[i] << endl;
    //     cout << "Q[" << i << "]: " << Q[i] << endl;
    // }

    int index = 1;
    do {
        bool pflag = true;
        bool qflag = true;
        // print(v);
        for (int i = 0; i < N; i++)
        {
            if(P[i] != v[i]){
                pflag = false;
            }

            if(Q[i] != v[i]){
                qflag = false;
            }
        }
        if(pflag){
            p_index = index;
        }
        if(qflag){
            q_index = index;
        }
        index++;
    } while (std::next_permutation(v.begin(), v.end()));

    // cout << p_index << endl;
    // cout << q_index << endl;
    cout << abs(p_index - q_index) << endl;
}

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

int arr[10050];
int rans = 0;
const long long mod = 1e9+7;
const int N_MAX = 10005;
const int D_MAX = 100;
int dp[N_MAX][D_MAX][2];

long long d;

int go (int n, int pos , long long sum, bool flag){
    
    if(dp[pos][sum][flag] != -1){
        return dp[pos][sum][flag] % mod;
    }
    
    if( pos > n ){
        // cout<<sum<<endl;
        if(/*sum!=0 &&*/ sum % d == 0){
           return 1;
        }
        return 0;
    }
    
    int limit = 9;
    if(flag == false){
        limit = arr[pos];
    }
    
    long long ans = 0;
    
    for( int i = 0 ; i <= limit ; i++ ) {
        if(flag || i < limit)
        dp[pos][sum][flag] = ans = ( ans % mod +  (go (n, pos + 1, (sum + i) % d, true) % mod) ) % mod;
        else
        dp[pos][sum][flag] = ans = ( ans % mod +  (go (n, pos + 1, (sum + i) % d, false) % mod) ) % mod;

    }
    
    return dp[pos][sum][flag] = ans % mod;
    
}


int main() {
        string s;
        cin >> s >> d;
        memset(dp,-1,sizeof(dp));
        for(int i = 0; i < s.size() ; i++){
            arr [i + 1] = s.at(i) - '0';
        }
        cout << ( ( go(s.size(), 1, 0, 0) % mod  - 1 ) + mod ) % mod<<endl ;
        // cout<<rans;
    return 0;
}




Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;

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

ll leftgcd[100010];
ll rightgcd[100010];

int main(void) {
	ll n, ans = 1;
	cin >> n;
	vector<ll>a(n);
	for (ll i = 0;i < n;i++)cin >> a[i];
	leftgcd[0] = a[0];
	for (ll i = 0;i < n;i++)leftgcd[i + 1] = gcd(leftgcd[i], a[i]);
	rightgcd[0] = a[n - 1];
	for (ll i = 0;i < n;i++)rightgcd[i + 1] = gcd(rightgcd[i], a[n - i - 1]);
	for (ll i = 0;i < n;i++) {
		if (i == 0) ans = max(ans, rightgcd[n - 1]);
		else {
			if (i == n - 1)ans = max(ans, leftgcd[n - 1]);
			else {
				ll g = gcd(leftgcd[i], rightgcd[n - i - 1]);
				ans = max(ans, g);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}


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

    int R, G;
    cin >> R >> G;

    cout << 2*G - R << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include <string.h>

#include <algorithm>

#include <iostream>

#include <map>

#include <queue>

#include <set>

#include <string>

#include <vector>

#include <bits/stdc++.h>

using namespace std;

 

//priority_queue<long long, vector<long long>, greater<long long>> pq;



const double TL = 1.5 * CLOCKS_PER_SEC;

mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

#define clr(x, y) memset(x, y, sizeof(x))

#define forn(i, n) for (int i = 0; i < n; i++)

#define LL long long

const double pi = acos(-1.0);





LL n, a, b, c, d;

map<LL, LL> mp;



LL mul(LL x, LL y) {

  if (x > 1e16 / y) return 1e16;

  return x * y;

}

//LL mul(LL x, LL y) {

//  LL ret = x * y;

//  if (ret / y != x) return 1e16;

//  if (ret > 1e16) return 1e16;

//  return ret;

//}





LL dfs(LL x) {

  if (x == 0) {

    return 0;

  }

  if (x == 1) {

    return d;

  }

  if (mp.find(x) != mp.end()) {

    return mp[x];

  }

  //cout << x << endl;





  LL ans = 1e16;

  LL y = x % 2;

  LL z = (x - y) / 2;

  ans = min(ans, dfs(z) + min(d * y + a, mul(abs(z - x), d)));

  if (y != 0) {

    z += 1;

    ans = min(ans, dfs(z) + min(d * (2 - y) + a, mul(abs(z - x), d)));

  }





  y = x % 3;

  z = (x - y) / 3;

  ans = min(ans, dfs(z) + min(d * y + b, mul(abs(z - x), d)));

  if (y != 0) {

    z += 1;

    ans = min(ans, dfs(z) + min(d * (3 - y) + b, mul(abs(z - x), d)));

  }



  y = x % 5;

  z = (x - y) / 5;

  ans = min(ans, dfs(z) + min(d * y + c, mul(abs(z - x), d)));

  if (y != 0) {

    z += 1;

    ans = min(ans, dfs(z) + min(d * (5 - y) + c, mul(abs(z - x), d)));

  }



  mp[x] = ans;

  return ans;

}



int main() {

#ifdef LOCAL

  auto start_clock = clock();

  freopen("in", "r", stdin);

#endif

  int T;

  scanf("%d", &T);

  while (T--) { 

    mp.clear();

    cin >> n >> a >> b >> c >> d;

    cout << dfs(n) << endl;

  }



#ifdef LOCAL

 auto end_clock = clock();

 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;

#endif

  return 0;

}



Measured memory_bytes: 4524
# coding: utf-8
# Your code here!
N = int(input())
H = list(map(int,input().split()))
num = 0
S = [0] * N
for i in reversed(range(N)):
    
    if i == N - 1:
        
        continue
    if H[i] >= H[i + 1]:
        num += 1
        S[i] = num
    elif H[i] < H[i + 1]:
        num = 0
        S[i] = num
    
    
print(max(S))

Measured memory_bytes: 63856
N = gets.to_i
as = gets.split.map(&:to_i)

hash = Hash.new(0)
sum = 0
ans = 0

as.each do |a|
    sum += a
    if hash[sum] > 0
        ans += hash[sum]
    end
    if sum == 0
        ans += 1
    end
    hash[sum] += 1
end
puts ans

Measured memory_bytes: 29060
#include<stdio.h>
int main(void){
   int n, a, age[10], i, l;
   scanf("%d", &n);
   while ( n != 0 ) {
      l = 6;
      while( l >= 0 ) {
         age[l] = 0; l--;
      }
      for ( i = 1; i <= n; i++ ) {
         scanf("%d", &a);
         if ( a < 60 ) age[a / 10]++;
         else age[6]++;
      }
      for ( i = 0; i <= 6; i++ ) printf("%d\n", age[i]);
      scanf("%d", &n);
   }
   return 0;
}

Measured memory_bytes: 1784
def rsum(n):return (n+1)*(n//2)+((n+1)//2) if n%2 else (n+1)*(n//2)
N,K=map(int,input().split())
p=list(map(int,input().split()))
l=[0]*N
for i in range(N):l[i]=rsum(p[i])*(1/p[i])
s=sum(l[0:K])
ans=0
for i in range(N-K):
    ans=max(ans,s)
    s-=l[i]
    s+=l[i+K]
print(max(ans,s))

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

int main(){
  int n,l,r;
  cin>>n;
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/




void Calc() {

  int n = in;
  const int INF = 1e9 - 1;

  int mini = 0;
  ll x = 1, y = 1;
  rep(i, n) {
    int a, b;
    in, a, b;
    if (abs(a - b) == 0) {
      amax(x, y);
      amax(y, x);
    } else {
      ll aa = (ll) x / a;
      if (x % a != 0) aa++;
      ll bb = (ll) y / b;
      if (y % b != 0) bb++;
      ll i = max(aa, bb);
      x = i * a;
      y = i * b;
      err(aa, bb, x, y);
    }
  }
  cout << (x + y) << endl;



}


Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef std::pair<int, int> Par;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 2020;
int du[maxn];
int a[maxn];
bool link[maxn][maxn];
bool vis[maxn];
std::vector<int> G[maxn];

void dfs(int u, int n) {
	vis[u] = true;
	for(int v = 1; v <= n; v ++)
		if(not vis[v] and link[u][v] and u != v) {
			link[u][v] = link[v][u] = false;
			// debug("%d -> %d\n", u, v);
			G[u].push_back(v);
			du[v] ++;
			dfs(v, n);
		}
}

int main() {
	int n = input();
	for(int i = 1; i <= n; i ++)
		a[i] = input();
	std::sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if(std::__gcd(a[i], a[j]) > 1)
				link[i][j] = true;
	for(int i = 1; i <= n; i ++)
		if(not vis[i])
			dfs(i, n);
	std::priority_queue<Par> q;
	for(int i = 1; i <= n; i ++)
		q.push(Par(- du[i], i));
	while(not q.empty()) {
		int d = - q.top().first, u = q.top().second;
		q.pop();
		if(d != du[u]) continue;
		for(int v : G[u]) {
			du[v] --;
			q.push(Par(- du[v], v));
		}
		printf("%d ", a[u]);
	}
	puts("");
}

Measured memory_bytes: 4608
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

typedef struct Node {
    int id;
    int x;
} Node;

int main() {
    int N, Q;
    cin >> N; cin >> Q;
    vector <int> *adj = new vector <int>[N];
    int *cnt = new int[N]();
    int *x = new int[N]();
    char *visited = new char[N];

    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a; cin >> b; a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i = 0; i < Q; ++i) {
        int p, xi;
        cin >> p; cin >> xi; p--;
        x[p] += xi;
    }

    stack <Node> f;
    Node root;
    root.id = 0; root.x = 0;
    f.push(root);
    while (!f.empty()) {
        Node n = f.top();
        f.pop();
        if (visited[n.id] == 1) continue;
        visited[n.id] = 1;
        cnt[n.id] += n.x + x[n.id];
        for (auto j : adj[n.id]) {
            Node next;
            next.id = j;
            next.x = n.x + x[n.id];
            f.push(next);
        }
    }
    for (int i = 0; i < N; ++i) {
        cout << cnt[i] << " ";
    }
    delete[] cnt;
    delete[] adj;
    delete[] visited;
    delete[] x;

    return 0;
}

Measured memory_bytes: 17396
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector <int> g[110000];
int indeg[110000];
int len[110000];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		g[x].push_back(y);
		indeg[y]++;
	}
	stack <int> S;
	for(int i=0;i<n;i++)
	{
		if(indeg[i]==0)
			S.push(i);
	}
	while(S.size())
	{
		int p=S.top();
		S.pop();
		for(int l=0;l<g[p].size();l++)
		{
			int to=g[p][l];
			if(len[p]+1>len[to])
			{
				len[to]=len[p]+1;
			}
			indeg[to]--;
			if(!indeg[to])
				S.push(to);
		}
	}
	cout<<*max_element(len,len+n)<<"\n";
	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h> 
#include <algorithm>
#define ll  long long int
#define m 1000000007
using namespace std;
int c=0;
string s;
void pali(int f,int l)
{
	if(f>=l)
		return;
	if(s[f]!=s[l])
		c++;
	pali(f+1,l-1);
}
int main() 
{		
	
	cin>>s;
	pali(0,s.size()-1);
	cout<<c<<endl;
	
}



Measured memory_bytes: 256
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let a: Vec<i64> = sc.next_vec(n);
    let mut s: i64 = a.iter().sum();
    let mut t = a[0];
    s -= t;
    let mut ans = (s - t).abs();
    for i in 1..n-1 {
        t += a[i];
        s -= a[i];
        if (s - t).abs() < ans {
            ans = (s - t).abs();
        }
    }
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8444
n=int(input())
l=list(map(int , input().split()))
#尺取り法
l.sort()
s=0
for i in range(n):
  if i+2<n:
    k=i+2
  else:
    break
  for j in range(i+1,n):
    while (k<n and l[k]<l[i]+l[j]):
      k+=1
    s+=k-(j+1)
print(s)

Measured memory_bytes: 42604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
int n,i;
cin>>n;
vector<int>d(n);
for(i=0;i<n;i++)cin>>d[i];
sort(d.begin(),d.end());
cout<<d[n/2]-d[n/2-1]<<endl;
return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define Left second
#define Right first
class SEGMENTS{
private:
    
    map<int,int> dat;
    
    bool isInclude(int li, int ri, int L, int R){ return (L<=li && ri<=R); }
    
public:
    
    void erase(int l, int r){
        while(true){
            auto it = dat.upper_bound(l);
            if(it==dat.end() || r<=it->Left)break;
            
            int li = it->Left;
            int ri = it->Right;
            
            if( isInclude(li,ri,l,r) ) dat.erase(it);
            else{
                dat.erase(it);
                if( isInclude(l,r,li,ri) ){
                    if(li!=l) dat[l] = li;
                    if(r!=ri) dat[ri] = r;
                }else{
                    if(li<=l&&l<ri) ri = l;
                    if(l<=li&&li<r) li = r;
                    if(li!=ri) dat[ri] = li;
                }
            }
        }
    }
    
    void insert(int l, int r){
        while(true){
            auto it = dat.upper_bound(l);
            if(it==dat.end() || r<it->Left){
                if(dat.count(l)){
                    dat[r] = dat[l];
                    dat.erase(l);
                }
                else dat[r] = l;
                break;
            }
            
            if( isInclude(it->Left,it->Right,l,r) ) dat.erase(it);
            else{
                l = min(l,it->Left);
                r = max(r,it->Right);
            }
        }
    }
    
    int size(){ return dat.size(); }
    
    void output(){ for(auto e:dat)cout<<e.Left<<" "<<e.Right<<endl;cout<<endl; }
};

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    SEGMENTS st;
    
    for(int i=0;i<n;){
        if(s[i]=='0')i++;
        else{
            int l=i;
            while(i<n && s[i]=='1') i++;
            st.insert(l,i);
        }
    }
    
    int q;
    cin>>q;
    while(q--){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        
        if(b==0)    st.erase(l,r);
        else        st.insert(l,r);
        
        cout<<st.size()<<endl;
    }
}

Measured memory_bytes: 4144
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,m;
  int i,j,k;
  double dp[105][105];
  double grow[105][105];
  int maxi[105];//??????????????§???????????¨????????´????????\???

  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;

    rep(i,n)rep(j,n)
      cin>>grow[i][j];

    double temp;
    int tempi;
    rep(j,n){
      temp=0;
      rep(i,n)
        if(temp<grow[i][j]){
	  temp=grow[i][j];
	  tempi=i;
	}
      maxi[j]=tempi;
    }

    rep(j,n)
      dp[0][j]=1.0;

    for(i=1;i<m;i++)
      for(j=0;j<n;j++){
	temp=0;
	rep(k,n)
	  temp=max(temp,dp[i-1][k]*grow[k][j]);
	dp[i][j]=temp;
      }
      
    double sum=0;

    rep(j,n)
      sum=max(sum,dp[m-1][j]);
 
    printf("%.2f\n",sum);
  }

}

Measured memory_bytes: 1412
#include<iostream>

using std::cout;
using std::endl;
using std::cin;


void output(int h, int w) {
    for (int i = 0; i < h; i++) {
        if (w >= 1) {
            cout << "#";  
        }

        for (int j = 1; j < w - 1; j++) {
            if (i == 0 || i == h - 1) {
                cout << "#";  
            } else {
                cout << ".";  
            }
        }

        if (w > 1) {
            cout << "#";  
        }
        cout << endl;
    }
    cout << endl;
    return;
}

int main(void) {
    int h;
    int w;

    cin >> h >> w;

    while (h != 0 && w != 0) {
        output(h, w);
        cin >> h >> w;
    }

    return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> P(N);
  int cnt = 0;
  rep(i, N) {
    cin >> P[i];
    if(P[i] != i+1) cnt++;
  }
  cout << (cnt<=2 ? "YES" : "NO") << "\n";
  return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <queue>
#define F first
#define S second
#define PI pair<int, int>
using namespace std;
 
int n, v[100005];
deque<PI> qu;
int main()
{
        ios::sync_with_stdio(false);
	PI t;
	cin >> n;
	qu.push_front(PI(1,1));
	while (!qu.empty()) {
		t = qu.front(); qu.pop_front();
		if (v[t.S]) continue;
		v[t.S] =1;
		if (t.S == 0) {
			cout << t.F;
			return 0;
		}
		qu.push_front(PI(t.F, (t.S * 10) % n));
		qu.push_back(PI(t.F+1, (t.S + 1) % n));
	}
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main()  {
	long long int w, h;
	cin >> w >> h;
	vector<long long int> p(w);
	vector<long long int> q(h);

	for (long long int i = 0; i < w; i++) {
		cin >> p[i];
	}
	for (long long int i = 0; i < h; i++) {
		cin >> q[i];
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	long long int ww, hh;
	long long int pp, qq;
	pp = qq = 0;
	ww = w+1;
	hh = h+1;
	long long int cc = 0;
	while (true) {
		//cout << hh << ' ' << ww << endl;
		if (pp == p.size()) {
			if (qq == q.size()) {
				break;
			} else {
				cc += q[qq]*ww;
				qq++;
				hh--;
				//cout << 'c' << endl;
			}
		} else if (qq == q.size()) {
			cc += p[pp]*hh;
			pp++;
			ww--;
		} else {
			if (p[pp] < q[qq]) {
				cc += p[pp]*hh;
				pp++;
				ww--;
				//cout << 'a' << endl;
			} else {
				cc += q[qq]*ww;
				qq++;
				hh--;
				//cout << 'b' << endl;
			} 
		}
		//cout << cc << ' ' << hh << ' ' << ww <<endl;
	}
	cout << cc << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int val[5];
	for(int i=0;i<5;i++)
		cin >> val[i];

	sort(val,val+5);
	for(int i=5;--i;)
		cout << val[i] << " ";
	cout << val[0] << endl;

	return 0;
}

Measured memory_bytes: 1176
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0]+a+[0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])
 
    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()

Measured memory_bytes: 14048
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i] - i;
    }

    sort(b.begin(), b.end());
    int median = b[n / 2];

    int sum = 0;
    for(int i = 0; i < n; i++) {
        sum += abs(a[i] - (median + i));
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3328
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()

def num2alpha(num):
    if num<=26:
        return chr(96+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(122)
    else:
        return num2alpha(num//26)+chr(96+num%26)

print(num2alpha(N))

Measured memory_bytes: 83056
/*ex5_3
series2*/

# include <stdio.h>
int main(void){
    //各文字の箱を作って読み取り
    int height,width;
    scanf("%d %d", &height,&width);
    char cell[height][width];
    int sub_row[height];
    int sub_col[width];
    //初期化
    for(int i=0;i<height;i++){sub_row[i]=0;}
    for(int j=0;j<width;j++){sub_col[j]=0;}
    //マスを読み取りながら、横にそろっている列をチェック
    for(int i=0;i<height;i++){
        int row_check=0;
        for(int j=0;j<width;j++){
            scanf(" %c",&cell[i][j]);
            if(cell[i][j]=='.'){
                row_check++;
            }
        }
        if (row_check==width){
            sub_row[i]=1;
        }
    }
    //縦にそろっている列をチェック
    for(int j=0;j<width;j++){
        int col_check=0;
        for(int i=0;i<height;i++){
            if(cell[i][j]=='.'){
                col_check++;
            }
        }
        if (col_check==height){
            sub_col[j]=1;
        }
    }
    //そろっていないマスを一つずつ出力
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            if(sub_row[i]==0&&sub_col[j]==0){
                printf("%c",cell[i][j]);
            }
        }
        //今の横列が描画されたら、改行する
        if (sub_row[i]==0){
            printf("\n");
        }
    }
    return 0;
}




Measured memory_bytes: 128
#include<stdio.h>

int main(void){
    int n, m;
    scanf("%d %d",&n ,&m);
    int a[m];
    long long int b[n];
    int i, j, k=0;
    int flag;
    long long int ans;
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
    }

    // shokichi
    if(a[0] == 1 && a[1] == 2){
        printf("0");
        return 0;
    }
    if(a[0] == 2){
        b[0] = 1;
        b[1] = 0;
    }
    else if(a[0] == 1 && a[1] != 2){
        b[0] = 0;
        b[1] = 1;
    }
    else{
        b[0] = 1;
        b[1] = 2;
    }

    //keisan
    for(i=0;i<n-2;i++){
        b[i+2] = b[i+1] + b[i];
        for(j=k;j<m;j++){
            if(a[j] == i+3){
                flag++;
                k = j;
                break;
            }
        }
        if(flag == 1){
            b[i+2] = 0;
            flag--;
        }
        b[i+2] = b[i+2]%1000000007;
    }

    ans = b[n-1]%1000000007;
    printf("%lld\n",ans);
    return 0;
    
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    int n;
    cin >> n;

    vector<string> v;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        v.push_back(s);
    }

    sort(all(v));
    v.erase(unique(all(v)), v.end());

    cout << v.size() << "\n";

    return 0;
}

Measured memory_bytes: 11548
import math
 
K=int(input())
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
  
print(L[K-1])


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        int z=sc.nextInt();
        x-=z;
        System.out.println(x/((y+z)));
	
	}

}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#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()
{
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(a,b) << " " << max(0,a+b-n) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int cnt=0;
  const int p=100000;
  while(a%2==0 && b%2==0 && c%2==0 && cnt<p){
    int x=b/2+c/2;
    int y=a/2+c/2;
    int z=a/2+b/2;
    a=x;b=y;c=z;
    cnt++;
  }
  if(cnt>=100000) printf("-1\n");
  else printf("%d\n",cnt);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end


n = gi # 10**5
as = gsmi

as.map!.with_index{|a,i| a-i-1 }.sort!
if n.odd?
  b = as[n/2]
else
  begin
    b = as[n/2-1]+((as[n/2]-as[n/2-1])*(as[n/2-1]-as[0])/(as[n/2-1]-as[0]+as[-1]-as[n/2]))
  rescue ZeroDivisionError => ex
  	b = (as[n/2]+as[n/2-1])/2
  end
end
b = as[n/2]
puts as.each_with_index.inject(0){|r,(a,i)| r+(a-b).abs }


Measured memory_bytes: 35620
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,cnt=0;
	int a[60];
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=n;i>=n-m+1;i--) cnt+=a[i];
	cout<<cnt;
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int expr(const string &s, int &pos);
int term(const string &s, int &pos);
int factor(const string &s, int &pos);
int number(const string &s, int &pos);

int expr(const string &s, int &pos) {
  auto res = term(s, pos);
  while ((pos < s.size()) and (s[pos] == '+' or s[pos] == '-')) {
    auto op = s[pos++];
    if (op == '+') {
      res += term(s, pos);
    } else {
      res -= term(s, pos);
    }
  }
  return res;
}

int term(const string &s, int &pos) {
  auto res = factor(s, pos);
  while ((pos < s.size()) and (s[pos] == '*' or s[pos] == '/')) {
    auto op = s[pos++];
    if (op == '*') {
      res *= factor(s, pos);
    } else {
      res /= factor(s, pos);
    }
  }
  return res;
}

bool is_digit(char ch) {
  return '0' <= ch and ch <= '9';
}

int factor(const string &s, int &pos) {
  if (is_digit(s[pos])) {
    return number(s, pos);
  }
  assert(s[pos++] == '(');
  auto res = expr(s, pos);
  assert(s[pos++] == ')');
  return res;
}

int number(const string &s, int &pos) {
  int ret = 0;
  while (pos < s.size() and is_digit(s[pos])) {
    ret = ret * 10 + (s[pos++] - '0');
  }
  return ret;
}

int main() {

  int n;
  cin >> n;
  cin.ignore();
  
  while (n--) {
    string s;
    getline(cin, s);
    s.pop_back();
    // <expr> ::= <term> [('+'|'-') <term>]*
    // <term> ::= <factor> [('*'|'/') <factor>]*
    // <factor> ::= <number> | '(' <expr> ')'
    // <number> ::= 123 とか
    int pos = 0;
    auto res = expr(s, pos);
    cout << res << endl;
  }

  return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

void solve() {
	int n = fetch<int>() * 2;
	vector<int> a(n);

	for(auto& elem: a) {
		cin >> elem;
	}

	sort(a.begin(), a.end());
	int answ = 0;

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

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n,sum=0;cin>>n;
        string s;cin>>s;
        for(ll i=0;i<n;i++){
            if(s[i]=='R')sum++;
        }
        ll ans=0;
        for(ll i=0;i<sum;i++)
        if(s[i]=='W')
        ans++;
        cout<<ans<<endl;

}


Measured memory_bytes: 3760
#include <iostream>

using namespace std;

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

    string S;
    cin >> S;

    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    } 

    return 0;
}

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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;

int main(void)
{
    int N;

    cin >> N;

    mint ans = 10;
    mint b = 9;
    mint c = 8;

    for(int i = 1; i < N; ++i)
    {
        ans = ans * 10;
        b = b * 9;
        c = c * 8;
    }
    ans = ans - b - b + c; 

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3548
#include <iostream>
using namespace std;
int main() {
    long long H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    long long w0, w1, h0, h1, r;
    w0 = (W + 1) / 2;
    if (W % 2 == 0) {
        w1 = w0;
    }
    else {
        w1 = w0 - 1;
    }
    if (H % 2 == 0) {
        r = H / 2;
        cout << w0 * r + w1 * r << endl;
    }
    else {
        cout << w0 * (H / 2 + 1) + w1 * (H / 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> P(N), C(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for(int i = 0; i < N; i++) cin >> C[i];
    long long ans = -1e18;
    vector<int> used(N, 0);
    vector<vector<long long>> vec(N);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(used[i] == 1) continue;
        int flag = 0;
        int ind = i, ind2 = i;
        while(flag == 0 || ind != ind2){
            flag = 1;
            vec[cnt].push_back(C[ind]);
            used[ind] = 1;
            ind = P[ind];
        }
        cnt++;
    }
    vector<vector<long long>> memo(cnt, vector<long long>(N, -1e18));
    for(int i = 0; i < cnt; i++){
        long long siz = vec[i].size();
        long long temp = 0;
        long long res = 0;
        for(int j = 0; j < siz; j++){
            long long t = 0;
            for(int k = 0; k < siz; k++){
                t += vec[i][(j + k) % siz];
                memo[i][k] = max(memo[i][k], t);
            }
            temp += vec[i][j];
        }
        if(temp > 0) {
            res += K / siz * temp;
            long long temp2 = 0;
            if(K / siz > 0){
                temp2 = (K / siz - 1) * temp;
                long long m = 0;
                for(int j = 0; j < siz; j++) m= max(m, memo[i][j]);
                temp2 += m;
            }
            long long t = -1e18;
            int flag = 0;
            for(int j = 0; j < K % siz; j++){
                t = max(t, memo[i][j]);
                flag = 1;
            }
            if(flag == 1) res += t;
            ans = max(res, ans);
            ans = max(temp2, ans);
        }
        else{
            long long r = -1e18;
            int flag = 0;
            for(int j = 0; j < min(K, siz); j++){
                r = max(r, memo[i][j]);
                flag = 1;
            }
            if(flag == 1) res += r;
            ans = max(res, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 36628
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_V 15
#define INF INT_MAX / 2

int V;
int d[MAX_V][MAX_V];

int dp[1 << MAX_V][MAX_V];

int rec(int S, int v) {
	if (dp[S][v] >= 0) {
		return dp[S][v];
	}

	if (S == (1 << V) - 1 && v == 0) {
		return dp[S][v] = 0;
	}

	int res = INF;
	for (int u = 0; u < V; u++) {
		if (!(S >> u & 1)) {
			res = min(res, rec(S | 1 << u, u) + d[v][u]);
		}
	}
	return dp[S][v] = res;
}

void solve() {
	memset(dp, -1, sizeof(dp));
	int ans = rec(0, 0);
	if (ans == INF)
		cout << -1 << endl;
	else
		cout << ans << endl;
}

void solve2() {
	for (int S = 0; S < 1 << V; S++)
		fill_n(dp[S], V, INF);
	dp[(1 << V) - 1][0] = 0;

	for (int S = (1 << V) - 2; S >= 0; S--) {
		for (int v = 0; v < V; v++)
			for (int u = 0; u < V; u++)
				if (!(S >> u & 1))
					dp[S][v] = min(dp[S][v], dp[S | 1 << u][u] + d[v][u]);
	}
	cout << dp[0][0] << endl;
}

int main() {
	int E;
	cin >> V >> E;
	for (int i = 0; i < V; i++)
		for (int j = 0; j < V; j++)
			d[i][j] = d[j][i] = INF;
	for (int i = 0; i < E; i++) {
		int s, t, dd;
		cin >> s >> t >> dd;
		d[s][t] = dd;
	}
	solve();
//	solve2();
	return 0;
}

Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner in = new FastScanner();
		String s = in.next();
		String t = in.next();
		int dp[][] = lcs(s, t);
		int i = s.length();
		int j = t.length();
		StringBuilder sb = new StringBuilder();
		sb.append("");
		while (i > 0 && j > 0) {
			if (s.charAt(i - 1) == t.charAt(j - 1)) {
				sb.append(s.charAt(i - 1));
				i--;
				j--;
			} else {
				if (dp[i - 1][j] > dp[i][j - 1]) {
					i--;
				} else {
					j--;
				}
			}
		}
		sb.reverse();
		System.out.println(sb);
	}

	public static int[][] lcs(String s, String t) {
		int dp[][] = new int[s.length() + 1][t.length() + 1];
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[0].length; j++) {
				if (i == 0 || j == 0) {
					dp[i][j] = 0;
				}
			}
		}
		for (int i = 1; i < dp.length; i++) {
			for (int j = 1; j < dp[0].length; j++) {
				if (s.charAt(i - 1) == t.charAt(j - 1)) {
					dp[i][j] = 1 + dp[i - 1][j - 1];
				} else {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}
		return dp;
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

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

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		TreeSet<Long> shrines = new TreeSet<Long>(), temples = new TreeSet<Long>();
		int a = sc.nextInt(), b = sc.nextInt(), q = sc.nextInt();
		for (int i = 0; i < a; i++){
			shrines.add(sc.nextLong());
		}for (int i = 0; i < b; i++){
			temples.add(sc.nextLong());
		}for (int i = 0; i < q; i++){
			long x = sc.nextLong();
			Long lshrine = shrines.floor(x);
			lshrine = (lshrine == null?(1L<<60):x - lshrine);//if it is null, set to infinity
			Long rshrine = shrines.ceiling(x);
			rshrine = (rshrine == null?(1L<<60):rshrine - x);
			Long ltemple = temples.floor(x);
			ltemple = (ltemple == null?(1L<<60):x - ltemple);
			Long rtemple = temples.ceiling(x);
			rtemple = (rtemple == null?(1L<<60):rtemple - x);
			System.out.println(Math.min(Math.min(Math.max(lshrine, ltemple), Math.max(rshrine, rtemple)),
					Math.min(Math.min(lshrine*2+rtemple, ltemple*2+rshrine),
							Math.min(lshrine+2*rtemple, ltemple+2*rshrine))));
		}

	}
}

Measured memory_bytes: 109860
if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    n0 = a.count(0)
    b = [x for x in a if x!=0]
    ans = 'No'
    if n0==N:
        ans = 'Yes'
    elif n0 != 0 and a.count(b[0])==n0*2 and N==n0*3:
        ans = 'Yes'
    elif len(set(b))==3:
        b1,b2,b3 = list(set(b))
        n1 = b.count(b1)
        n2 = b.count(b2)
        n3 = b.count(b3)
        if b1^b2==b3 and n1==n2==n3:ans = 'Yes'
    print(ans)

Measured memory_bytes: 14116
#include <stdio.h>

int get_uint() {
  int n = 0;
  int c = getchar_unlocked();
  if(c < 48 || 57 < c) return c;
  while(47 < c && c < 58) {
    n = 10 * n + (c & 0xf);
    c = getchar_unlocked();
  }
  return n;
}
int loadable_num(const int cap, int qty, const int *arr, const int N) {
  int i = 0;
  // while truck exist
  while(qty--) {
    int now = 0;
    // while there is enough capacity for next package
    while(arr[i] + now <= cap) {
      now += arr[i];
      // N -> loaded all package
      if(++i == N) return N;
    }
  }
  return i;
}
int main(int argc, char **argv) {
  int n = get_uint();
  int k = get_uint();
  int w[100001];
  for(int i = 0; i < n; ++i) w[i] = get_uint();

  int left = 0;
  // MAX cap
  int right = 10000 * 100000;
  int mid;
  // binary search
  while(right - left > 1) {
    mid = left + (right - left) / 2;
    // couldn't load all
    if(n > loadable_num(mid, k, w, n)) left = mid;
    // enoght cap
    else right = mid;
  }
  printf("%d\n", right);
}



Measured memory_bytes: 2216
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int r,g,b,n;
    cin>>r>>g>>b>>n;

    int ans=0;
    for(int i=0;i*r<=n;i++){
        int u=i*r;
        int kn=n-u;
        for(int j=0;j*g<=kn;j++){
            int y=j*g;
            int kkn=kn-y;
            if(kkn%b==0)ans++;
        }

    }
    cout<<ans<<endl;


    return 0;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	
	int n;
	cin >> n;
	unordered_set<string> bag;
	string s;
	while(n--) {
		cin >> s;
		bag.insert(s);
	}
	cout << bag.size() << "\n";



	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

vector<vi> adj;

int dist[2001][2001];

void bfs(int node) {
	queue<int> q;
	q.push(node);
	dist[node][node] = 0;
	int i,j;
	while(!q.empty()){
		int bil = q.front(); q.pop();
		for(i=0;i<adj[bil].size();i++){
			int v = adj[bil][i];
			if(dist[node][v] == inf) {
				dist[node][v] = dist[node][bil] + 1;
				q.push(v);
			}
		}
	}
}

int main(){
	int n,x,y,i,j;
	scanf("%d %d %d",&n,&x,&y);
	adj.assign(n+1, vi());
	for(i=1;i<n;i++){
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[x].pb(y);
	adj[y].pb(x);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			dist[i][j] = inf;
		}
	}
	for(i=1;i<=n;i++){
		bfs(i);
	}
	int cnt[200001];
	memset(cnt, 0, sizeof cnt);
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			// printf("dist[%d][%d]: %d\n",i,j,dist[i][j]);
			cnt[dist[i][j]]++;
		}
	}
	for(i=1;i<n;i++){
		printf("%d\n",cnt[i]);
	}

	return 0;
};

Measured memory_bytes: 16896