akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
ll A;
string B;

int main() {
  INCANT;
  cin >> A >> B;
  ll b1 = B[0]-'0';
  ll b2 = B[2]-'0';
  ll b3 = B[3]-'0';

  cout << (A*b1*100+A*b2*10+A*b3)/100 << "\n";
  return 0;
}

Measured memory_bytes: 3652
n,m = map(int,input().split())

A = [list(map(int,input().split())) for _ in range(n)]

b = [[int(input())] for _ in range(m)]

c = [0]*n
for i in range(n):
    for j in range(m):
        c[i] += A[i][j]*b[j][0]

for k in range(n):
    print(c[k])



Measured memory_bytes: 6028
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        StringBuilder sb = new StringBuilder(s);
        int cnt = 0;
      
        for (int i=0; i<sb.length()-1; i++) {
          if (sb.charAt(i) != sb.charAt(sb.length()-1-i)) {
             sb.replace(i, i+1, String.valueOf(sb.charAt(sb.length()-1-i)));
             cnt++;
          }
        }
      System.out.println(cnt);
      
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;

  if (k % 2 == 0) {
    cout << a-b << endl;
  } else {
    cout << b-a << endl;
  }
}


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

int main() {
    int n,m,c; cin >> n >> m >> c;

    int b[m];
    rep(i,m)cin >> b[i];

    int a[n][m];
    rep(i,n)rep(j,m) cin >> a[i][j];

    int sum[n];
    int count = 0;

    for (int i = 0; i < n; ++i) {
        sum[i] = 0;
        for (int j = 0; j < m; ++j) {
            sum[i] += a[i][j] * b[j];
        }
        if(sum[i] + c > 0)count++;
    }
    print(count);
}


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

public class Main {


    public static void main(String[] args) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int N = Integer.parseInt(s[0]);
        int K = Integer.parseInt(s[1]);
        HashSet<Integer> set = new HashSet<>();
        for(int i = 0; i < K; i++) {
            int d = Integer.parseInt(in.readLine());
            s = in.readLine().split(" ");
            for(int j = 0; j < s.length; j++) {
                set.add(Integer.parseInt(s[j]));
            }
        }
        System.out.println(N - set.size());
    }

}


Measured memory_bytes: 27112
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
const LL MOD = (LL)1e9 + 7;
int A[MAXN];
int cnt[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    LL ans = 1;
    cnt[0] = 3;
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        ans = (ans * cnt[A[i]]) % MOD;
        cnt[A[i]]--;
        cnt[A[i] + 1]++;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define Endl endl
#define mod  1000000007
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)

ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
ll intpoint(ll x1, ll y1, ll x2, ll y2) { return ( __gcd(abs(x1-x2),abs(y1-y2))+1); }
bool isvalid(ll x,ll y,ll n,ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int pp = uniform_int_distribution<int>(0, kk-1)(rng);
// ---------------------///////////////---------------------------------
// ---------------------///////////////----------------------------------
// -------------/////////////////---------------------------------///////
ll dp[100011],ap[100011],n;

ll get_ans(ll st,ll k){
  if(st == n){
    return 0;
  }
  if(dp[st]!=-1){
    return dp[st];
  }
  ll ans = mod;
  for(ll i=1;i<=k;i++){
    if(st+i>n){
      break;
    }
    ans = min(ans,abs(ap[st]-ap[st+i]) + get_ans(st+i,k));
  }
  dp[st] = ans;
  return dp[st];
}

int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t,i,j,l,r,q,k,kk,x,p,m;
    cin>>n>>k;
    for(i=1;i<=n;i++){
      cin>>ap[i];
      dp[i] = -1;
    }
    get_ans(1,k);
    // for(i=1;i<=n;i++){
    //   cout<<dp[i]<<" ";
    // }
    cout<<dp[1]<<" ";
return 0;
}

Measured memory_bytes: 8064
#include <cstdlib>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

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

int N;
const long long INF = 1LL << 60;
long long h[100010];
long long dp[100010];

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

	// 初期化 (最小化問題なので INF に初期化)
	for (int i = 0; i < 100010; ++i) dp[i] = INF;

	// 初期条件
	dp[0] = 0;

	dp[0] = 0;
	for (int i = 1; i < N; ++i) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 5032
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <numeric>

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

int mind[22][110][110];
ll cost[22][22000];

ll gr[110][110];

int main() {
	while(1) {
		fill_n(mind[0][0], 22*110*110, 1000000);
		for (int i = 0; i < 22; i++) {
			for (int j = 0; j < 110; j++) {
				mind[i][j][j] = 0;
			}
		}
		int n, m, c, s, g;
		cin >> n >> m >> c >> s >> g; s--; g--;
		if (!n) break;
		for (int i = 0; i < m; i++) {
			int x, y, d, c;
			cin >> x >> y >> d >> c; x--; y--; c--;
			mind[c][x][y] = min(mind[c][x][y], d);
			mind[c][y][x] = min(mind[c][y][x], d);
		}
		int pnum[22];
		for (int i = 0; i < c; i++) {
			cin >> pnum[i];
		}
		for (int i = 0; i < c; i++) {
			cost[i][0] = 0;
			int qq[55], rr[55];
			qq[0] = 0;
			for (int j = 0; j < pnum[i]-1; j++) {
				cin >> qq[j+1];
			}
			qq[pnum[i]] = 21000;
			for (int j = 0; j < pnum[i]; j++) {
				cin >> rr[j];
			}
			for (int j = 0; j < pnum[i]; j++) {
				for (int k = qq[j]; k < qq[j+1]; k++) {
					cost[i][k+1] = cost[i][k]+rr[j];
				}
			}
		}
//		cout << cost[1][1] << endl;
//		cout << mind[1][2][1] << endl;
		for (int r = 0; r < c; r++) {
			for (int k = 0; k < 110; k++) {
				for (int i = 0; i < 110; i++) {
					for (int j = 0; j < 110; j++) {
						mind[r][i][j] = min(mind[r][i][j], mind[r][i][k]+mind[r][k][j]);
					}
				}
			}
		}
//		cout << mind[1][2][1] << endl;
		for (int i = 0; i < 110; i++) {
			for (int j = 0; j < 110; j++) {
				gr[i][j] = 1LL<<55;
			}
		}

		for (int i = 0; i < 110; i++) {
			for (int j = 0; j < 110; j++) {
				for (int r = 0; r < c; r++) {
					if (mind[r][i][j] < 20100) {
						gr[i][j] = min(gr[i][j], cost[r][mind[r][i][j]]);
					}
				}
			}
		}
//		cout << gr[2][1] << endl;
		ll dist[110];
		fill_n(dist, 110, 1LL<<55);
		dist[s] = 0;
		bool used[110] = {};
		while (true) {
			int u = -1;

			for (int v = 0; v < 110; v++) {
				if (used[v]) continue;
				if (u == -1 || dist[v] < dist[u]) {
					u = v;
				}
			}
			if (u == -1) break;
			used[u] = true;
			for (int v = 0; v < 110; v++) {
				dist[v] = min(dist[v], dist[u]+gr[u][v]);
			}
		}
		if (dist[g] > 1LL<<50) {
			cout << -1 << endl;
		} else {
			cout << dist[g] << endl;
		}
	}
	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

template<class T>
class Dinic {
private:
    const T INF;

    struct edge {
        T to, cap, rev;
        edge(T to, T cap, T rev) :to(to), cap(cap), rev(rev) {}
    };

    T V;
    vector<vector<edge>> g;
    vector<T> level;      // sourceからの距離
    vector<T> itr;       // どこまで調べ終わったか

public:
    Dinic(T V) :INF(1e9+7), V(V), g(V, vector<edge>()) {}

    void add_edge(T from, T to, T cap) {
        g[from].emplace_back(to, cap, g[to].size());
        g[to].emplace_back(from, 0, g[from].size()-1);
    }

    // sourceからの最短路を幅優先で探索
    void bfs(T s) {
        level = vector<T>(V, -1);
        queue<T> que;
        que.push(s);
        level[s] = 0;
        while (que.size()) {
            int v = que.front(); que.pop();
            for (edge &e : g[v]) {
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    // v->tの増加路を探す
    T dfs(T v, T t, T f) {
        if (v == t) return f;
        for (T& i = itr[v]; i < g[v].size(); ++i) {
            edge& e = g[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T max_flow(T s, T t) {
        T flow = 0, f;
        while (true) {
            bfs(s);
            if (level[t] < 0) return flow;
            itr = vector<T>(V, 0);
            while ((f = dfs(s, t, numeric_limits<T>::max())) > 0) {
                flow += f;
            }
        }
    }
};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A
int main() {
    int V, E;
    cin >> V >> E;
    //Ford_Fulkerson flow;
    Dinic<ll> flow(V);
    rep(i, E) {
        int from, to, cap;
        cin >> from >> to >> cap;
        flow.add_edge(from, to, cap);
    }
    cout << flow.max_flow(0, V-1) << endl;
    return 0;
}


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    multiset<int> Set;
    Set.insert(-1);
    int ai;
    rep(i,n) {
        ai = a[i];
        auto itr1 = Set.lower_bound(ai);
        if (itr1 == Set.begin()) Set.insert(ai);
        else {
            itr1--;
            Set.erase(itr1);
            Set.insert(ai);
        }
    }
    cout << Set.size() << endl;
    return 0;
}

Measured memory_bytes: 8556
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};


int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    map<int,int> num;
    for(int i=0;i<N;i++){
        num[a[i]]++;
    }
    //cout<<num.size()<<endl;
    if(num.size()!=3&&num[0]==0){
        cout<<"No"<<endl;
        return 0;
    }
    if(num.size()==1&&num[0]>0){
        cout<<"Yes"<<endl;
        return 0;
    }

    if(num.size()==3){
        int vals[3];
        int kosu[3];
        int cnt=0;
        for(auto itr =num.begin(); itr != num.end(); ++itr) {
            vals[cnt]=itr->first;
            kosu[cnt]=itr->second;
            //cout<<vals[cnt]<<endl;
            cnt++;
        }
        if((vals[0]^vals[1])==vals[2]&&(vals[1]^vals[2])==vals[0]&&kosu[0]==kosu[1]&&kosu[1]==kosu[2]){
            cout<<"Yes"<<endl;
            return 0;
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }

    if(num.size()==2){
        int vals[3];
        int kosu[3];
        int cnt=0;
        for(auto itr =num.begin(); itr != num.end(); ++itr) {
            vals[cnt]=itr->first;
            kosu[cnt]=itr->second;
            cnt++;
        }
        int dai,syo;
        if(kosu[0]>kosu[1]){
            dai=vals[0];
            syo=vals[1];
        }else{
            dai=vals[1];
            syo=vals[0];
        }

        if(syo==0&&num[dai]==num[syo]*2){
            cout<<"Yes"<<endl;
            return 0;
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 4224
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    count = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            count += 1
    print(min(count + K * 2, N-1))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


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

d = dict()
array = 'MARCH'
for i in array:
    d[i] = 0

for i in range(N):
    s = input()
    if s[0] in array:
        d[s[0]] += 1

ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += d[array[i]] * d[array[j]] * d[array[k]]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;

const int N = 3000005;
const int mod = 1e9 + 7;

int n , a[N];
map <int,int> freq;

vector< pii > v[2];

int main(){
	cin >> n;
	for (int i = 0; i < n; ++i){
		scanf("%d",&a[i]);
	}
	int ans = 0;
	for(int it = 0 ; it <= 1 ;++it){
		freq.clear();
		for(int j = it ; j < n ; j += 2){
			freq[a[j]]++;
		}
		for(auto x : freq){
			v[it].pb(make_pair(x.second,x.first));
		}
		sort(v[it].begin(),v[it].end());
		reverse(v[it].begin(),v[it].end());	
	}
	int mn = n;
	for(int i = 0 ; i < min((int)v[0].size(),2);++i){
		for(int j = 0 ; j < min((int)v[1].size(),2);++j){
			if(v[0][i].second != v[1][j].second){
				mn = min(mn,n-v[0][i].first-v[1][j].first);
			}

			mn = min(mn,n/2-v[0][i].first+n/2);
			mn = min(mn,n/2-v[1][j].first+n/2);
		}
	}

	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int N;
    cin >> N;
    map<string, int> count;
    for (int i = 0; i < N; i++) {
        string temp;
        cin >> temp;
        count[temp]++;
    }
    vector<string> temp = {"AC", "WA", "TLE", "RE"};
    for (auto a : temp) {
        cout << a << " x " << count[a] << endl;
    }
}


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

int main() {
int N,D,X;
cin >> N >> D>>X;
int sum=0;
vector<int> A(N);
for (int i = 0; i < N; i++)
{
 cin>>A[i]; 
}

for (int i = 0; i < N; i++)
{
  int date=0;
  for (int j = 0; j < 101; j++)
  {
    date=j*A[i]+1;
    if(date>D) break;
    sum++;
  }
}
cout << X+sum << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, X, Y;
    cin >> N >> X >> Y;
    --X; --Y;

    mat G(N);
    REP(i,0,N-1) {
        G[i].pb(i+1);
        G[i+1].pb(i);
    }
    G[X].pb(Y);
    G[Y].pb(X);

    vec C(N+1, 0);
    REP(i,0,N) {
        queue<ll> Q;
        vec D(N, INF);
        Q.push(i);
        D[i] = 0;
        while(!Q.empty()) {
            ll v = Q.front(); Q.pop();
            FORR(nv,G[v]) {
                if(D[nv] == INF) {
                    D[nv] = MIN(D[nv],D[v]+1);
                    Q.push(nv);
                }
            }
        }
        REP(j,0,N) {
            if(D[j] < INF) ++C[D[j]];
        }
    }

    REP(i,1,N) PR(C[i]/2);

    return 0;
}

/*



*/

Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
int dx[]={0,1,0,-1},dy[]={-1,0,1,0},w,h,x,y,d;
string s[51];
bool b[51][51][4];
main(){
  while(cin>>h>>w,h&&(d=1)){
    vector<P>v;
    memset(b,0,sizeof(b));
    int a[3]={};
    r(i,h)cin>>s[i];
    y=0,x=0;
    while(1){
      v.push_back(P(y,x));
      if(b[y][x][d])break;
      b[y][x][d]=1;
      if(y==h-1&&x==w-1){
        a[0]++;
        r(i,v.size()-1)s[v[i].fi][v[i].se]='#';
        v.clear();
      }
      if(y==h-1&&x==0){
        a[1]++;
        r(i,v.size()-1)s[v[i].fi][v[i].se]='#';
        v.clear();
      }
      if(y==0&&x==w-1){
        a[2]++;
        r(i,v.size()-1)s[v[i].fi][v[i].se]='#';
        v.clear();
      }
      int yy=y+dy[d],xx=x+dx[d];
      if(yy<0||yy>=h||xx<0||xx>=w)d=(d+1)%4;
      else if(s[yy][xx]=='#'&&yy+xx)d=(d+1)%4;
      else{
        int ya=yy+dy[(d+3)%4];
        int xa=xx+dx[(d+3)%4];
        if(ya>=0&&ya<h&&xa>=0&&xa<w&&s[ya][xa]=='.')d=(d+3)%4;
        y=yy,x=xx;
      }
    }
    if(!(y+x)&&a[0]&&a[1]&&a[2])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3192
def pat1(H,W):
    if H % 3 == 0:
        return 0
    else:
        return W

def pat2(H,W):
    if W % 3 == 0:
        return 0
    else:
        return H

def pat3(H,W):
    h1 = H // 2
    h2 = H - h1
    ans = 10**15 
    for w in range(1,W//2+1):
        s1 = h1 * (W-w)
        s2 = h2 * (W-w)
        s3 = H*w
        min1 = min(s1,s2,s3)
        max1 = max(s1,s2,s3)
        ans = min(ans,max1-min1)
    return ans

def pat4(H,W):
    w1 = W // 2
    w2 = W - w1
    ans = 10**15
    for h in range(1,H//2+1):
        s1 = w1*(H-h)
        s2 = w2*(H-h)
        s3 = W*h
        min1 = min(s1,s2,s3)
        max1 = max(s1,s2,s3)
        ans = min(ans,max1-min1)
    return ans

H,W = map(int,input().split())
ans = 10**15
ans = min(ans,pat1(H,W))
ans = min(ans,pat2(H,W))
ans = min(ans,pat3(H,W))
ans = min(ans,pat4(H,W))

print(ans)


Measured memory_bytes: 3064
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	pp := make([]int, n)
	aa := make([]int, n)
	bb := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner) - 1
	}

	for i := 0; i < n; i++ {
		aa[pp[i]] = i + 1
		bb[pp[i]] = i + 1
	}

	minus := 0
	for i := 1; i < n; i++ {
		if aa[i] <= aa[i-1] {
			bb[i] -= aa[i-1] - aa[i] + 1
			aa[i] += aa[i-1] - aa[i] + 1
		}
		if bb[i-1] <= bb[i] {
			aa[i] += bb[i] - bb[i-1] + 1
			bb[i] -= bb[i] - bb[i-1] + 1
		}
		if minus > bb[i] {
			minus = bb[i]
		}
	}
	for i := 0; i < n; i++ {
		aa[i] -= minus - 1
		bb[i] -= minus - 1
	}
	for i := 0; i < n; i++ {
		fmt.Fprint(writer, aa[i])
		if i == n-1 {
			continue
		}
		fmt.Fprint(writer, " ")
	}
	fmt.Fprintln(writer, "")
	for i := 0; i < n; i++ {
		fmt.Fprint(writer, bb[i])
		if i == n-1 {
			continue
		}
		fmt.Fprint(writer, " ")
	}
	fmt.Fprintln(writer, "")
	writer.Flush()
}


Measured memory_bytes: 2688
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll k,a,b,sum;
  cin >> k >> a >> b;
  if(b-a<=2||k<=a){
    cout << k+1<<endl;
    return 0;
  }
  k -= a-1;
  ll v = a+(k/2)*(b-a);
  cout << v+(k%2)<<endl;
}


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

cumsum = [0]

for i in a:
  cumsum.append(cumsum[-1]+i)

d = dict()

for i in cumsum:
  d[i] = d.get(i, 0) + 1


ans = 0
for v in d.values():
  ans += (v * (v-1)) / 2

print(int(ans))

Measured memory_bytes: 41228
# -*- coding: utf-8 -*-
"""
B - Palindrome-phobia
https://atcoder.jp/contests/cf17-final/tasks/cf17_final_b

"""
import sys


from collections import Counter

def solve(S):
    cnt = Counter(S)
    res = sorted([[v, k] for k, v in cnt.items()], reverse=True)

    ch = res[0][1]
    prev = None
    cnt[ch] -= 1
    if cnt[ch] == 0:
        del cnt[ch]

    d = {'ab': 'c', 'ac': 'b', 'ba': 'c', 'bc': 'a', 'ca': 'b', 'cb': 'a'}

    while cnt:
        if prev is None:
            if len(res) < 2:
                return 'NO'
            else:
                prev = ch
                ch = res[1][1]
                cnt[ch] -= 1
                if cnt[ch] == 0:
                    del cnt[ch]
        else:
            n_ch = d[prev+ch]
            if cnt[n_ch] > 0:
                prev, ch = ch, n_ch
                cnt[n_ch] -= 1
                if cnt[n_ch] == 0:
                    del cnt[n_ch]
            else:
                return 'NO'
    return 'YES'


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
	return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int> &vec)
{
	for (auto &e : vec)
	{
		cout << e << " ";
	}
	cout << endl;
}

int main()
{
	string a;
	string b;
	cin >> a >> b;
	string tempA;
	string tempB;
	rep(i, stoi(b))
	{
		tempA += a;
	}
	rep(i, stoi(a))
	{
		tempB += b;
	}

	if (a > b)
	{
		cout << tempB << endl;
	}
	else if (a <= b)
	{
		cout << tempA << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;

const ll INF = 1e15;
const ld eps = 1e-15;

int main() {
	ll N;
	cin >> N;
	string s;
	cin >> s;
	ll ans = 0;
	for (ll i = 0;i < 1LL << N;i++) {
		string target = "";
		ll A = 0;
		ll B = 0;
		for (ll k = 0;k < N;k++)
			if ((1LL << k) & i) {
				target.push_back(s[k]);
				A++;
			}
		for (ll k = N - 1;k >= 0;k--)
			if ((1LL << k) & ~i) {
				target.push_back(s[k]);
				B++;
			}
		vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));
		dp[A][B] = 1;
		for (int k = 0;k < N;k++) {
			for (int a = max(A, k+B-N);a <= min(N, A+k);a++) {
				ll b = B + k - (a - A);
				if (b < B || b > N)
					continue;
				if (a < N && target[a] == s[N + k])
					dp[a + 1][b] += dp[a][b];
				if (N-b-1 >= 0 && target[N - b - 1] == s[N + k])
					dp[a][b + 1] += dp[a][b];
			}
		}
		ans += dp[N][N];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int a,b,i,cnt,f=0;
	while (scanf("%d %d", &a, &b) != EOF) {
	i=1;
	cnt=0;
	while((a+b)/i>0){
		cnt+=1;
		i=i*10;
	}
	printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

bool dp[2][701];
bool connected[700][700];
bool vis[700];
int color[700];
int N, M;

void get_component(int v, vector<int> &comp) {
	comp.push_back(v);
	vis[v] = 1;
	for (int i = 0; i < N; i++) {
		if (connected[v][i] && !vis[i]) get_component(i, comp);
	}
}
bool dfs(int v, int c) {
	color[v] = c;
	for (int i = 0; i < N; i++) {
		if (!connected[v][i]) continue;
		if (color[i] == c) return false;
		if (!color[i] && !dfs(i, -c)) return false;
	}
	return true;
}
int main() {
	cin >> N >> M;
	memset(connected, -1, sizeof(connected));
	for (int i = 0; i < N; i++) connected[i][i] = 0;
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		connected[A][B] = connected[B][A] = 0;
	}
	vector<int> X, Y;
	for (int i = 0; i < N; i++) {
		if (vis[i]) continue;
		vector<int> comp;
		get_component(i, comp);
		if (!dfs(i, 1)) {
			cout << -1 << endl;
			return 0;
		}
		int A = 0, B = 0;
		for (int v : comp) {
			if (color[v] == 1) A++;
			else B++;
		}
		X.push_back(A);
		Y.push_back(B);
	}
	dp[0][0] = 1;
	for (int i = 0; i < X.size(); i++) {
		for (int j = 0; j <= N; j++) {
			if (j + X[i] <= N) dp[(i + 1) & 1][j + X[i]] |= dp[i & 1][j];
			if (j + Y[i] <= N) dp[(i + 1) & 1][j + Y[i]] |= dp[i & 1][j];
		}
		for (int j = 0; j <= N; j++) dp[i & 1][j] = 0;
	}
	int ans = 1 << 30;
	for (int i = 0; i <= N; i++) {
		if (dp[X.size() & 1][i]) {
			int sum = i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2;
			ans = min(ans, sum);
		}
	}
	cout << ans << endl;
}


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

int main() {
  long long n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e;
  cout << max({ (n - 1) / a, (n - 1) / b, (n - 1) / c, (n - 1) / d, (n - 1) / e }) + 5 << "\n";
}

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

int n;
vector<pair<int,int> > arr[20];

int main() {
    scanf("%d",&n);
	int a,x,y;
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		for(int j=0;j<a;j++){
			scanf("%d%d",&x,&y);x--;
			arr[i].push_back(make_pair(x,y));
		}
	}
	int ans=0;
	int N=(1<<n);
	int stat[20];
	for(int i=0;i<N;i++){
		bool poss=1;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				for(int k=0;k<(int)arr[j].size();k++){
					x=arr[j][k].first;y=arr[j][k].second;
					if(y==1){
						if((i&(1<<x))==0){
							poss=0;
							break;
						}else{
							stat[x]=1;
						}
					}else if(y==0){
						if((i&(1<<x))>0){
							poss=0;
							break;
						}else{
							stat[x]=0;
						}
					}
				}
			}
			if(!poss)break;
		}
		if(poss){
			int k=0;
			int bm=i;
			while(bm&(-bm)){
				k++;
				bm-=(bm&(-bm));
			}
			ans=max(ans,k);
		}
	}
	printf("%d",ans);
}

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

int main(){
    int d,g; cin>>d>>g;
    pair<int,int> a[11];
    for(int i=0;i<d;i++){
        int p,c; cin>>p>>c;
        a[i]=make_pair(p,c);
    }

    int ans=1e9;
    for(int i=0;i<(1<<d);i++){
        int cnt=0,n=0,r=-1;
        for(int j=0;j<d;j++){
            if(i&(1<<j)){
                cnt+=100*(j+1)*a[j].first+a[j].second;
                n+=a[j].first;
            }else{
                r=j;
            }
        }
        if(cnt<g){
            int b=100*(r+1);
            int e=(g-cnt+b-1)/b;
            if(e>=a[r].first) continue;
            n+=e;
        }
        ans=min(ans,n);
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int h[n];
	for(int i=0;i<n;i++)
		cin >> h[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout << dp[n-1] << "\n";
	return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int length = Integer.parseInt(reader.readLine());
    
    String[] intAryStr = reader.readLine().split(" ");
    int[] intAry = new int[intAryStr.length];
    for (int i = 0; i < intAry.length; i++)
      intAry[i] = Integer.parseInt(intAryStr[i]);
    
    reverse(intAry);

    for (int i = 0; i < intAry.length; i++)
      if (i == intAry.length-1)
        System.out.println(intAry[i]);
      else
        System.out.print(intAry[i] + " ");
  }

  public static void reverse(int[] array) {
    for (int i = 0; i < array.length / 2; i++) {
      int tmp = array[i];
      array[i] = array[array.length-1-i];
      array[array.length-1-i] = tmp;
    }
  }
  
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = 0;
    ll num = n / (a+b);
    if((n - num * (a+b)) < a)
        ans = a * num + (n - num * (a+b));
    else
    {
        ans = a * (num+1);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "1000 8", "1 3 4 5 6 7 8 9" ].parse.expand.solve == 2000 );
	assert( [ "9999 1", "0" ].parse.expand.solve == 9999 );
	
	assert( [ "1112 9", "0 2 3 4 5 6 7 8 9" ].parse.expand.solve == 11111 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto ds = input.front.split.map!( to!char ).array;
	return tuple( nk[ 0 ], ds );
}

auto solve( long n, char[] ds )
{
	for( ;; n++ )
	{
		if( memoize!f( n.to!string, ds ) ) break;
	}
	return n;
}

bool f( string cs, char[] ds )
{
	if( cs.empty ) return true;
	foreach( d; ds )
	{
		if( cs[ 0 ] == d ) return false;
	}
	return memoize!f( cs[ 1 .. $ ], ds );
}


Measured memory_bytes: 12156
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "b.cpp"

int main() {
  string s, t;
  cin >> s >> t;
  ll ans = 0;
  ll n = s.size();
  rep(i, n) {
    ans += s[i] != t[i];
  }
  cout << ans << el;
}


Measured memory_bytes: 3788
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
#define arr(u) (str[u] == 'A' ? rem_a : rem_b)
typedef long long ll;
int rem_a[200005], rem_b[200005], que[200005];
bool vis[200005], cyc[200005];
std::vector<int> adj[200005];
char str[200005];
int main()
{
	// freopen("AGC027-C.in", "r", stdin);
	int n, m, he = 0, ta = 0;
	scanf("%d%d%s", &n, &m, str);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		if (--u == --v)
			cyc[u] = true;
		else
		{
			adj[u].pb(v);
			adj[v].pb(u);
			arr(u)[v]++;
			arr(v)[u]++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (cyc[i])
			arr(i)[i] = 1e9;
	}
	for (int i = 0; i < n; i++)
	{
		if (!rem_a[i] || !rem_b[i])
		{
			que[ta++] = i;
			vis[i] = true;
		}
	}
	while (he < ta)
	{
		int u = que[he++];
		for (int v : adj[u])
		{
			if (vis[v])
				continue;
			if (!--arr(u)[v])
			{
				que[ta++] = v;
				vis[v] = true;
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (!vis[i])
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 13056
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[11];
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	if(s[1]!='A') printf("WA");
	else{
		int anum=0,cnum=0,cnt=0,sum=0;
		for(int i=1;i<=len;++i){
			if(s[i]=='A') ++anum;
			if(s[i]=='C'){
				++cnum;
				if(i>=3&&i<len) ++cnt;
			}
			if(s[i]>='A'&&s[i]<='Z') ++sum;
		}
		if(anum==1&&cnum==1&&cnt==1&&sum==2) printf("AC");
		else printf("WA");
	}
	return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
seats = [None] * (N + 1)


def main():
    print(0)
    answer = input()
    if answer == "Vacant":
        return
    seats[0] = answer == "Male"
    l, r = 0, N
    while r - l > 1:
        # Vacant must be in [l, r).
        assert seats[l] is not None
        q = (l + r) // 2
        #sys.stderr.write(f"l={l} r={r} q={q}\n")
        print(q)
        answer = input()
        if answer == "Vacant":
            return
        seats[q] = answer == "Male"
        if ((q - l) % 2 == 0) ^ (seats[l] == seats[q]):
            r = q
        else:
            l = q
    raise ValueError("something went wrong")


if __name__ == "__main__":
    main()


Measured memory_bytes: 4424
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for i in range(m)]
 
for i in range(10**n):
  ans = str(i)
  if len(ans) != n:
    continue
  if all([ans[s-1] == str(c) for s, c in sc]):
    print(ans)
    break
else:
  print(-1)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char s;
    cin >> s;
    if (s == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }

  cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
import qualified Data.Array.IO as A
import Data.Array.IO
import Control.Monad
import Data.Maybe

type Array = IOArray Int

main :: IO ()
main = do
    n <- read <$> getLine :: IO Int
    ts <- A.newListArray (1,n-1) =<<
        replicateM (n-1) ((\[c,s,f]->(c,s,f)) . map read . words <$> getLine) :: IO (Array (Int, Int, Int))
    forM_ [1..n] $ \i -> do
        print =<< sim ts i 0 n

sim :: Array (Int, Int, Int) 
    -> Int -- current point
    -> Int -- time
    -> Int -- gool
    -> IO Int
sim arr pos time goal = do
    (c, s, f) <- fromMaybe (0, 0, 0) <$> (arr!?pos)
    case (pos==goal, s<=time, mod time f) of
        (True, _, _) -> return time
        (_, True, 0) -> sim arr (pos+1) (time+c) goal 
        (_, True, n) -> sim arr (pos+1) (time+(f-n)+c) goal 
        (_, False,_) -> sim arr (pos+1) (s+c) goal

(!) :: (A.Ix x) => A.IOArray x y -> x -> IO y
arr ! n = A.readArray arr n
{-# INLINE (!) #-}
 
(!?) :: (A.Ix x) => A.IOArray x y -> x -> IO (Maybe y)
arr !? n = do
    (start, last) <- A.getBounds arr
    if n >= start && last >= n 
        then Just <$> A.readArray arr n 
        else return Nothing
{-# INLINE (!?) #-}
 
(<<-) :: (A.Ix x) => (A.IOArray x y, x) -> y -> IO ()
(arr, i) <<- v = A.writeArray arr i v
{-# INLINE (<<-) #-}

Measured memory_bytes: 1404
lst = [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(lst[int(input())-1])

Measured memory_bytes: 2940
#include<iostream>
#include<math.h>
#include<algorithm>
 
#define long long long
 
using namespace std;
 
long n;
long a[100001], dp[100001];
 
long cal(int idx) {
    if (idx >= n) return 0;
    if (dp[idx] != -1) return dp[idx];
    dp[idx] = 0;
    
    if (idx + 2 <= n) dp[idx] = min(cal(idx + 1) + abs(a[idx + 1] - a[idx]), cal(idx + 2) + abs(a[idx + 2] - a[idx]));
    else dp[idx] += abs(a[idx + 1] - a[idx]);
    return dp[idx];
}
 
void FastInput()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    for (int i = 1; i <= n; i ++)
        dp[i] = -1;
}
 
void Solve()
{
    cout << cal(1);
}
 
int main()
{
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 7456
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


int n;
string s, t;

signed main() {

    cin >> n;
    cin >> s >> t;
    s[n] = '0';
    t[n] = '1';
    ll ans = (s[0]==t[0]?3:6);
    
    for(int i = 0; i < n; i++) {
        if(i + 1 + (s[i]!=t[i]) == n) break;
        if(s[i]==t[i]) {
            ans *= 2;
        }
        else {
            if(s[i+2]!=t[i+2]) {
                ans *= 3;                
            }
            i++;            
        }

        ans %= SMOD;
    }
    
    cout << ans << endl;

  
    return 0;
}



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

#define sd(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define N 100010
#define INF 1000000000000000000ll

ll dp[5][N],sub[N];
vector<pair<int,ll> > v[N];
int n;

void sub_dfs(int cur, pair<int,ll> par)
{
	sub[cur]=1;
	for(auto p:v[cur])
		if(p.F!=par.F)
		{
			sub_dfs(p.F,MP(cur,p.S));
			sub[cur]+=sub[p.F];
		}
}

void dfs(int cur,pair<int,ll> par)
{
	for(auto p:v[cur])
		if(p.F!=par.F)
			dfs(p.F,MP(cur,p.S));
	for(int i=0;i<=2;i++)
	{
		if(sub[cur]<i || n-sub[cur]<2-i)
		{
			dp[i][cur]=-INF;
			continue;
		}
		ll cnt1=2*sub[cur],cnt2=2*(n-sub[cur]);
		cnt1-=i;
		cnt2-=(2-i);
		dp[i][cur]=min(cnt1,cnt2)*par.S;
		ll max11=-INF,max12=-INF,max2=-INF,Sum=0;

		for(auto p:v[cur])
			if(p.F!=par.F)
			{
				max2=max(max2,dp[2][p.F]-dp[0][p.F]);
				if(dp[1][p.F]-dp[0][p.F]>max11)
				{
					max12=max11;
					max11=dp[1][p.F]-dp[0][p.F];
				}
				else if(dp[1][p.F]-dp[0][p.F]>max12)
					max12=dp[1][p.F]-dp[0][p.F];
				Sum+=dp[0][p.F];
			}
		ll val=-INF;
		if(i==0 || i==1)
		{
			val=max(val,Sum);
		}
		if(i==1||i==2)
		{
			val=max(val,Sum+max11);
		}
		if(i==2)
		{
			val=max(val,Sum+max11+max12);
			val=max(val,Sum+max2);
		}
		dp[i][cur]+=val;
	}
}
int main()
{
	int i;
	sd(n);
	for(i=0;i<n-1;i++)
	{
		int x,y,z;
		sd(x);sd(y);sd(z);
		v[x].PB(MP(y,z));
		v[y].PB(MP(x,z));
	}
	sub_dfs(1,MP(1,0));
	dfs(1,MP(1,0));
	printf("%lld\n",dp[2][1]);
}

Measured memory_bytes: 20992
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    #print(a)
    if a in ctr:
        answer += ctr[a]
    ctr[a] += 1
print(answer)

Measured memory_bytes: 25300
/* beginner 81 */
/* Shubham Jain */

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll c=0,i;
    string s;
    cin>>s;
    for(i=0;i<s.length();i++)
        if(s[i]=='1')
        c++;
    cout<<c<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001],d[100001],n;
int main() {
	cin>>n;
	for(int i=1; i<=n; i++)cin>>a[i];
	int l=1;
	d[1]=a[1];
	for(int i=2; i<=n; i++) {
		if(d[l]>=a[i])d[++l]=a[i];
		else {
			int p=upper_bound(d+1,d+1+l,a[i],greater<int>())-d;
			d[p]=a[i];
		}
	}
	cout<<l;
	return 0; 
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(N):
    for j in range(N):
        B=A[i]*A[j]
        count=count+B
for k in range(N):
    C=A[k]*A[k]
    count=count-C
print(int(count/2))

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
int cand1[10] = {'M', 'M', 'M', 'M', 'M', 'M', 'A', 'A', 'A', 'R'};
int cand2[10] = {'A', 'A', 'A', 'R', 'R', 'C', 'R', 'R', 'C', 'C'};
int cand3[10] = {'R', 'C', 'H', 'C', 'H', 'H', 'C', 'H', 'H', 'H'};

int main() {
  ll N;
  cin >> N;
  string s;
  map<char, ll> march_cnt;
  march_cnt['M'] = 0;
  march_cnt['A'] = 0;
  march_cnt['R'] = 0;
  march_cnt['C'] = 0;
  march_cnt['H'] = 0;
  for (size_t i = 0; i < N; i++) {
    cin >> s;
    if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'R' ||
        s[0] == 'C' || s[0] == 'H') {
      march_cnt[s[0]]++;
    }
  }
  ll ans = 0;
  ll n = march_cnt.size();
  if (n >= 3) {
    for (int i = 0; i < 10; i++) {
      ans += march_cnt[cand1[i]] * march_cnt[cand2[i]] * march_cnt[cand3[i]];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  vector<int> pre(3);
  cin>>pre[0]>>pre[1]>>pre[2];
  sort(pre.begin(),pre.end());
  int x = pre[2] - pre[1];
  int y = pre[2] - pre[0];
  int ans = x/2 + y/2;
  if(x&1 && y&1)ans+=1;
  else if(x&1 || y&1)ans+=2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル(n_max×w_max:110×100100)
// 要素には価値の和が入る
long long dp[110][100100] = {0};


int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    // 全てのマスを埋めるようにループする
    // ある１行(i番目の品物)に対して、全てのそれぞれの重さに対応する価値を考える。
    // dp[i+1][w]:=dp[i][]+v[]
  
    // 一つの品物ごとに回す(縦の列)
    for (int i = 0; i < N; ++i) {
        // 重さごとに回す(横の行)
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            // if (sum_w - weight[i] >= 0) {
            if (sum_w + weight[i] <= W) {
                // dp[i][sum_w - weight[i]]はdp[i+1][sum_w]を更新する時に必要。
                // 例えば、dp[i][5-2]だったら合計の重さ5を考えている時に、i番目の品物の重さが２である。
                // この時dp[i+1][5]を更新するためには、i番目の品物の重さを足した時に5になる必要があるためdp[i][5-2]。
                // chmax(dp[i+1][考えている重さ], dp[i][合計-重さ]+v[i]) 

                // 貰うver
                // chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);

                // 配るver
                chmax(dp[i+1][sum_w+weight[i]], dp[i][sum_w] + value[i]);
            }

            // i 番目の品物を選ばない場合(単純な入れ替え)
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81744
Option Strict On
Module Module1

    Sub Main()
        Dim n As Integer = Convert.ToInt32(Console.ReadLine())
        Dim S As String = Console.ReadLine()
        Dim k As Integer = Convert.ToInt32(Console.ReadLine())
        Dim moji As String = Mid(S, k, 1)
        For i As Integer = 1 To n
            If Mid(S, i, 1) <> moji Then
                Mid(S, i, 1) = "*"
            End If
        Next
        Console.WriteLine(S)
        Console.ReadLine()
    End Sub

End Module

Measured memory_bytes: 20560