akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

vector<set<int>> read_tree() {
    int h, w;
    if (!(cin >> h >> w, h)) return {};
    vector<string> s(h);
    for (auto &si: s) cin >> si;
    vector<string> field(h + 2, string(w + 2, '.'));    // .#
    for (int i = 0; i < h; i++) field[i + 1] = '.' + s[i] + '.';
    h += 2, w += 2;
    vector<vector<int>> visited(h, vector<int>(w, -1));
    vector<set<int>> g;
    auto dfs = [&](auto dfs, int i, int j, int id, int &cnt) {
        if (~visited[i][j]) return ;
        visited[i][j] = id, cnt++;
        for (int di: {-1, 0, 1}) for (int dj: {-1, 0, 1}) {
            if (abs(di) + abs(dj) > 1 + (field[i][j] == '#')) continue;
            int ni = i + di, nj = j + dj;
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (field[ni][nj] == field[i][j]) dfs(dfs, ni, nj, id, cnt);
            else if (~visited[ni][nj]) g[visited[ni][nj]].emplace(id);
        }
    };
    int id = 0;
    vector<int> num;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        if (visited[i][j] == -1) {
            int cnt = 0;
            dfs(dfs, i, j, id, cnt);
            num.emplace_back(cnt);
            g.resize(++id);
        }
    }
    return g;
}

string tree2str(vector<set<int>> &directed_tree, int u) {
    vector<string> s;
    for (int v: directed_tree[u]) s.emplace_back(tree2str(directed_tree, v));
    sort(begin(s), end(s));
    string res;
    for (string si: s) res += si;
    return '(' + res + ')';
}

bool is_isomorphic(vector<set<int>> &t1, vector<set<int>> &t2) {
    return tree2str(t1, 0) == tree2str(t2, 0);
}

int main() {
    while (true) {
        auto t1 = read_tree(); if (t1.empty()) return 0;
        auto t2 = read_tree();
        cout << (is_isomorphic(t1, t2) ? "yes" : "no") << endl;
    }
    return 0;
}



Measured memory_bytes: 3528
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define loop(n) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	while (n!=1) {
		cnt++;
		n = n / 2;
	}
	cout << (1<<cnt) << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu17e()

fun yorukatsu17e() {
    val (n, c) = readLine()!!.split(' ').map { it.toInt() }
    val changeCosts = (1..c).map { readLine()!!.split(' ').map { it.toLong() } }
    val grid = Array(n) { readLine()!!.split(' ').map { it.toInt() - 1 }.toIntArray() }

    val count = Array(3) { LongArray(c) }
    grid.mapIndexed { y, row -> row.forEachIndexed { x, i -> count[(y + x) % 3][i]++ } }

    fun colorToCost(i: Int, to: Int) = (0 until c)
        .map { count[i][it] * changeCosts[it][to] }.sum()

    var answer = Long.MAX_VALUE

    for (c1 in 0 until c) {
        for (c2 in 0 until c) {
            if (c2 == c1) continue
            for (c3 in 0 until c) {
                if (c3 == c1 || c3 == c2) continue
                val sum = colorToCost(0, c1) + colorToCost(1, c2) + colorToCost(2, c3)
                answer = Math.min(answer, sum)
            }
        }
    }

    println(answer)
}


Measured memory_bytes: 72276
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int minCost = Integer.MAX_VALUE;
        int[] costs = new int[n];
        int[][] knowledgeBooster = new int[n][m];
        int[] currentKnowledge = new int[m];
        int currentCost = 0;
        
        for(int i = 0; i < n; i++) {
        	costs[i] = sc.nextInt();
        	for(int j = 0; j < m; j++) {
        		knowledgeBooster[i][j] = sc.nextInt();
        	}
        }
        int maskLimit = 1 << n;
        for(int mask = 0; mask < maskLimit; mask++) {
        	currentCost = 0;
        	Arrays.fill(currentKnowledge, 0);
        	for(int i = 0; i < n; i++) {
        		if(((mask >> i) & 1) == 1) {
        			currentCost += costs[i];
        			for(int j = 0; j < m; j++) {
        				currentKnowledge[j] += knowledgeBooster[i][j];
        			}
        		}
        	}
        	boolean knowledgeSatisfied = true;
        	for(int i = 0; i < m; i++) {
        		if(currentKnowledge[i] < x) {
        			knowledgeSatisfied = false;
        			break;
        		}
        	}
        	if(knowledgeSatisfied)
        		minCost = Math.min(currentCost, minCost);
        }
        System.out.println(minCost == Integer.MAX_VALUE? "-1": minCost);

    }
    
}

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

struct Edge {
    int to;
    int use;
};

vector<map<int, Edge>> G;
vector<int> depth, odd, pa;

int main() {
    ll N, M;
    cin >> N >> M;
    G.resize(N);
    ll a, b;
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a][b] = Edge{b,1};
        G[b][a] = Edge{a,0};
    }
    depth.assign(N, -1);
    odd.assign(N, 0);
    pa.assign(N, -1);

    queue<int> q;
    q.push(0);
    depth[0] = 0;
    while ( !q.empty() ) {
        auto v = q.front();
        q.pop();

        int no = 0;
        for( auto ee : G[v] ) {
            auto e =  ee.second;
            if ( e.use == 1 ) no++;
            if ( depth[e.to] >= 0) continue;
            pa[e.to] = v;
            depth[e.to] = depth[v] + 1;
            q.push(e.to);
        }
        odd[v] = no % 2;
    }

    int oc = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( odd[i] == 1 ) oc++;
    }
    if ( oc % 2 == 1 )  {
        cout << -1 << "\n";
        return 0;
    }

    priority_queue<pair<int, int>> pq;
    for ( int i = 0; i < N; i++ ) {
        pq.push(make_pair(depth[i], i));
    }

    while ( !pq.empty() ) {
        auto x = pq.top();
        pq.pop();
        int v = x.second;
        if ( pa[v] == -1 ) {
            if ( odd[v] == 1 ) {
                cout << -1 << "\n";
                return 0;
            } else {
                break;
            }
        }

        if ( odd[v] == 1 ) {
            G[v][pa[v]].use = 1 - G[v][pa[v]].use;
            G[pa[v]][v].use = 1 - G[pa[v]][v].use;
            odd[v] = 1 - odd[v];
            odd[pa[v]] = 1 - odd[pa[v]];
        }
    }
    
    for ( int i = 0; i < N; i++ ) {
        for ( auto g : G[i] ) {
            auto e = g.second;
            if ( e.use == 1 ) {
                cout << i+1 << " " << e.to+1 << "\n";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 20724
n, m = map(int, input().split())
A = [[0 for _ in range(m)] for _ in range(n)]
b = [0 for _ in range(m)]
Ab = [0 for _ in range(n)]

for i in range(n):
    x = list(map(int, input().split()))
    for j in range(m):
        A[i][j] = x[j]

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

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

for i in range(n):
    print(Ab[i])


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

ll pow2( ll i ){
    return 1LL<<i;
}

int popn( ll b ){
    int cnt = 0;
    while( b ) cnt++, b -= (-b)&b;
    return cnt;
}


int N;
int M;
vector<vi> e;
map<pii,int> eid;
vii q;
vi tmp;
vl egn;

bool dfs1( int from, int goal, int pare = -1 ){
    for( int to : e[from] ){
        if( to == pare ) continue;
        tmp.push_back(to);
        if( to == goal ) return true;
        else if( dfs1(to,goal,from) ){
            return true;
        }else{
            tmp.pop_back();
        }
    }
    return false;
}

void search( int i, int u, int v ){
    tmp.clear();
    tmp.push_back(u);
    dfs1(u,v);
    Rep(j,(tmp.size()-1)){
        egn[i] |= (1LL<<eid[pii(tmp[j],tmp[j+1])]);
    }
}

set<int> amp( set<int>& a, set<int>& b ){
    set<int> c;
    for( int t : a ){
        c.insert(t);
    }
    for( int t : b ){
        c.insert(t);
    }
    return c;
}

int main() {

    Scd(N);

    e.resize(N);

    int u,v;
    Rep(i,N-1){
        Scd2(u,v);
        u--,v--;
        e[u].push_back(v);
        e[v].push_back(u);
        eid[pii(u,v)] = i;
        eid[pii(v,u)] = i;
    }

    int M;
    Scd(M);
    q.resize(M);
    egn.resize(M);
    Rep(i,M){
        Scd2(u,v);
        u--,v--;
        q[i] = pii(u,v);
        search(i,u,v);
    }

    ll ans = 0;
    int MM = 1<<M;
    Rep(bi,MM){
        int num = popn(bi);
        ll exs = 0;
        Rep(mi,M) {
            if( (1<<mi) & bi ) exs |= egn[mi];
        }
        ans -= (num%2?1:-1) * pow2( N-1-popn(exs) );
    }

    printf ("%lld\n", ans );

    return 0;
}




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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  ll res = 0LL;
  if(a[0] > x) {
    res = a[0] - x;
    a[0] = x;
  }
  for(int i = 1; i < N; ++i) {
    if(a[i] + a[i - 1] <= x) continue;
    res += a[i] + a[i - 1] - x;
    a[i] = x - a[i - 1];
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N=202020;
struct kek{
	int x,y,c;
}a[N];
int p[N],v[N],e[N];
int get(int x){
	if(x==p[x])return x;
	return p[x]=get(p[x]);
}
int32_t main(){
	int n,h,w;
	cin>>n>>h>>w;
	forn(i,n){
		cin>>a[i].x>>a[i].y>>a[i].c;
	}
	sort(a,a+n,[](const kek&p1,const kek&p2){return p1.c>p2.c;});
	for(int i=1;i<=h+w;++i){
		p[i]=i;v[i]=1;e[i]=0;
	}
	int ans=0;
	forn(i,n){
		int x=get(a[i].x),y=get(a[i].y+h);
		if(x==y){
			if(e[x]<v[x]){
				ans+=a[i].c;
				e[x]++;
			}
		}else{
			p[y]=x;
			v[x]+=v[y];
			e[x]+=e[y];
			if(e[x]<v[x]){
				ans+=a[i].c;
				e[x]++;
			}
		}
	}
	cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 12292
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e8 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, m, k;
int CASE;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};

int arr[MAXN];
vector<int> vec;
ll pref[MAXN];
int v, p;

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d%d%d%d", &n, &m, &v, &p);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
    }
    sort(arr + 1, arr + n + 1);
    reverse(arr + 1, arr + n + 1);
    for (int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1] + arr[i];
    }
    int ans = p;
    for (int i = p + 1; i <= n; i++) {
        if (arr[i] + m < arr[p]) continue;
        ll d = v - (n - (i - p));
        if (d <= 0) {
            ans++;
            continue;
        }
        if (d * m <= (ll)(i - p) * (arr[i] + m) - pref[i - 1] + pref[p - 1]) {
            ans++;
        }
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1408
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { A: number[] } => {
  const A = lines[1].split(' ').map(line => +line)
  const obj = { A }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { A } = parseLines(lines)
  const sum = A.reduce((prev, current) => prev += 1 / current, 0)
  return `${1 / sum}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N;
    cin >> N;
    vector<lli> A(N);
    lli mx = 0;
    REP(i, 0, N) {
        cin >> A[i];
        A[i] -= (i + 1);
        mx = max(abs(A[i]), mx);
    }
    lli l = -2 * mx, r = 2 * mx;
    lli ans = 1LL << 60;

    REP(i, 0, 500) {
        lli s1 = 0, s2 = 0;
        lli m1 = (2 * l + r) / 3, m2 = (l + 2 * r) / 3;
        REP(j, 0, N) {
            s1 += abs(A[j] - m1);
            s2 += abs(A[j] - m2);
        }
        ans = min({ans, s1, s2});
        if (s1 < s2) {
            r = m2;
        } else {
            l = m1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll dp1[30000000],dp2[30000000];
int main(){
	int n,a[3],b[3];
	cin>>n;
	rep(i,3)cin>>a[i];
	rep(i,3)cin>>b[i];
	int MAX=28000000;
	rep(i,MAX){
		dp1[i+1]=max(dp1[i+1],dp1[i]+1);
		rep(j,3)dp1[i+a[j]]=max(dp1[i+a[j]],dp1[i]+b[j]);
	}
	rep(i,MAX){
		dp2[i+1]=max(dp2[i+1],dp2[i]+1);
		rep(j,3)dp2[i+b[j]]=max(dp2[i+b[j]],dp2[i]+a[j]);
	}
	cout<<dp2[dp1[n]]<<endl;
}

Measured memory_bytes: 441172
import bisect
s = input().rstrip()
t = input().rstrip()

a_ord = ord("a")
ch_place = [[] for _ in range(26)]
for i, ch in enumerate(s):
    ch_place[ord(ch) - a_ord].append(i)

# print(ch_place)

count = 0
idx = -1 
for ch in t:
    ch_num = ord(ch) - a_ord
    if len(ch_place[ch_num]) == 0:
        print(-1)
        exit()
    place = bisect.bisect_right(ch_place[ch_num], idx)
    # print(ch_place[ch_num], idx, place)
    if place == len(ch_place[ch_num]):
        idx = ch_place[ch_num][0]
        count += 1
    else:
        idx = ch_place[ch_num][place]

# print(count, idx)
print(count * len(s) + idx + 1)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> xs(n);
    for (auto& x : xs) {
        cin >> x;
        sort(x.begin(), x.end());
    }
    sort(xs.begin(), xs.end());
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
        int j = i;
        while (j+1 < n && xs[j+1] == xs[i]) ++j;
        sum += ((long long) (j-i))*(j-i+1) / 2;
        i = j;
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

enum Face : int { Top, Front, Right, Left, Back, Bottom };
struct cube {
  int f[6];
  unordered_map<int, string> mp;
  cube(){}
  /*
            1(Top)
    4(Left) 2(Front) 3(Right) 5(Back)
            6(Bottom)
  */
  cube(vector<int> const& vs){ for(int i=0; i<6; i++) f[i] = vs[i]; }
  cube(vector<string> const& vs) { for(int i=0; i<6; i++) mp[i+1] = vs[i]; }
  void roll_z() { roll(1, 2, 4, 3); }
  void roll_y() { roll(0, 2, 5, 3); }
  void roll_x() { roll(0, 1, 5, 4); }
  void roll(int i, int j, int k, int l) {
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }

  void roll(int k) {
    if(k == 0) roll_y();
    if(k == 1) roll_x();
    if(k == 2) for(int i=0; i<3; i++) roll_y();
    if(k == 3) for(int i=0; i<3; i++) roll_x();
  }

  bool roll_top_front(int top, int front) {
    for(int k = 0; k < 6; (k & 1 ? roll_y() : roll_x()), k++)
      for(int i = 0; i < 4; roll_z(), ++i)
        if(top == f[Top] && front == f[Front]) return true;
    return false;
  }

  bool operator == (cube const& rhs) const {
    for(int i=0; i<6; i++)
      if(f[i] != rhs.f[i]) return false;
    return true;
  }

  bool isomorphic(cube rhs) const {
    for(int k = 0; k < 6; (k & 1 ? rhs.roll_y() : rhs.roll_x()), k++)
      for(int i = 0; i < 4; rhs.roll_z(), ++i)
        if(operator==(rhs)) return true;
    return false;
  }

};

int main() {

  cube cs[2]; rep(i, 2) rep(j, 6) cin >> cs[i].f[j];
  cout << (cs[0].isomorphic(cs[1]) ? "Yes\n" : "No\n");
  
  return 0;
}

Measured memory_bytes: 3076
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

// std::cmp::Reverse doesn't have Clone.
#[derive(Eq, PartialEq, Clone)]
struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let _n: usize = util::get();
    let a: Vec<usize> = util::gets();

    let mut map = HashMap::new();

    for &x in &a {
        *map.entry(x).or_insert(0) += 1;
    }

    let m = map.values().filter(|&v| v % 2 == 0).count();

    let ans = if m % 2 == 0 {
        map.keys().count()
    } else {
        map.keys().count() - 1
    };

    println!("{}", ans);
}


Measured memory_bytes: 12540
#include<stdio.h>
int main(){
  char a[1001]={0};
  int c[1001]={0};
  int b=0,d=0,i;
  while(1){
    scanf("%s",a);
    if(a[0]=='0'){
      break;
    }
    while(a[b]!=0){
      c[d]+=a[b]-'0';
      b++;
    }
    d++;
    b=0;
  }
  for(i=0;i<d;i++){
    printf("%d\n",c[i]);
  }
}
  

Measured memory_bytes: 2696
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main(){
    int n, q;
    while(cin >> n >> q, n+q){
        int quorum[110];
        memset(quorum, 0, sizeof(quorum));

        int ret = 0, maxQurourm = q-1;
        for(int j=0; j < n; j++){
            int m;
            cin >> m;
            for(int i=0; i < m; i++){
                int d;
                cin >> d;
                quorum[d]++;
                if(maxQurourm < quorum[d] || maxQurourm == quorum[d] && ret > d){
                    ret = d; maxQurourm = quorum[d];
                }
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1160
H = list(map(int, input().split()))
SX=H[0]
SY=H[1]
TX=H[2]
TY=H[3]
TX=TX-SX
TY=TY-SY

if((TX>=0)&(TY>=0)):
    U="U"
    R="R"
    D="D"
    L="L"

if((TX<0)&(TY>=0)):
    U="U"
    R="L"
    D="D"
    L="R"

if((TX>=0)&(TY<0)):
    U="D"
    R="R"
    D="U"
    L="L"

if((TX<0)&(TY<0)):
    U="D"
    R="L"
    D="U"
    L="R"

for i in range(abs(TY)):print(U,end="") 
for i in range(abs(TX)):print(R,end="") 

for i in range(abs(TY)):print(D,end="")
for i in range(abs(TX)):print(L,end="") 

print(L,end="") 
for i in range(abs(TY)+1):print(U,end="")
for i in range(abs(TX)+1):print(R,end="") 
print(D,end="")

print(R,end="") 
for i in range(abs(TY)+1):print(D,end="")
for i in range(abs(TX)+1):print(L,end="") 
print(U,end="")



Measured memory_bytes: 4468
package main

import (
	"fmt"
	"sort"
)

func ssort(s string) string {
	r0 := make([]string, 0)
	for i := 0; i < len(s); i++ {
		r0 = append(r0, string(s[i]))
	}
	sort.Strings(r0)
	r1 := ""
	for i := 0; i < len(s); i++ {
		r1 += string(r0[i])
	}
	return r1
}

func main() {
	var N int
	fmt.Scan(&N)
	m := make(map[string][]int)
	for i := 0; i < N; i++ {
		s0 := ""
		fmt.Scan(&s0)
		s1 := ssort(s0)
		m[s1] = append(m[s1], i)
	}
	// fmt.Println("N", N, "m", m)
	ans := 0
	for _, v := range m {
		vl := len(v)
		if vl >= 2 {
			ans += (vl - 1) * vl / 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 19584
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}

const int m=2019;
ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};
int main()
{
 ll n,k;
 cin>>n>>k;
 vector<ll>p(n);
 rep(i,n)cin>>p[i];
 vector<ll>c(n);
 rep(i,n)cin>>c[i];
 rep(i,n)p[i]--;    
 ll ans=-100000000000;
 rep(i,n){
     vector<ll>v;
     ll tot=0;
     ll now=i;
     ll tmp=k;
     while(0<tmp){
        now=p[now];
        tot+=c[now];
        v.push_back(c[now]);
        tmp--;
        if(now==i)break;
     }
     ll l=v.size();

     ll t;
     ll sum=0;
     rep(j,l+1){
      if(k<j+1)break;
      sum+=v[j];
      if(0<tot){
          ll e=(k-(j+1))/l;
          t=tot*e;
          ans=max(ans,sum+t);
      }
      ans=max(ans,sum);
     }
 }
 cout<<ans<<endl;
}
 




Measured memory_bytes: 3812
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# L = [int(v) * -1 for v in input().split()]

S = input().strip()

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] not in ["R", "U", "D"]:
            print("No")
            exit()
    else:
        if S[i] not in ["L", "U", "D"]:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 3316
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	string s;	cin >> s;
	int Won = 0, Loses = 0;
	Rep(i,0,s.size()){
		if(s[i] == 'o'){
			Won++;
		}else{
			Loses++;
		}
	}
	if(Won >= 8){
		cout << "YES" << endl;
	}else if(Won+(15 - s.size()) >= 8){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	Solve();
	return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli a[3] ;
    loopcin(3 , a) ;
    cout << (a[0] - a[1]) % a[2] ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string a,b;
    int gu,mut;
    double pisap;
    cin>>a>>b;
    a+=b;
    stringstream ss(a);
    ss>>gu;
    mut=sqrt(gu);
    pisap=sqrt(gu);
    if(mut==pisap)
    {
        cout<<"Yes"<<NL;
    }
    else
    {
        cout<<"No"<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
//package abc176;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static PrintWriter out;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		
		String string=sc.next();
		int sum=0;
		for(int i=0;i<string.length();i++) {
			sum+=string.charAt(i)-'0';
		}
		if(sum%9==0) {
			out.print("Yes");
		}
		else {
			out.print("No");
		}
		
		out.close();
		sc.close();
	}

}


Measured memory_bytes: 40144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC140B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] Ainput = Console.ReadLine().Split(' ');
            string[] Binput = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            int[] B = new int[N];
            int sum = 0;
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Ainput[i]);
                B[i] = int.Parse(Binput[i]);
                sum += B[i];
            }
            string[] Cinput = Console.ReadLine().Split(' ');
            int[] C = new int[N - 1];
            for (int i = 0; i < N-1; i++)
            {
                C[i] = int.Parse(Cinput[i]);
            }
            for(int i = 0; i < N-1; i++)
            {
                if (A[i] + 1 == A[i + 1])
                {
                    sum += C[A[i]-1];
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 27516
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////

int main() {
	ll r, D, a;
	ll x[12];
	cin >> r >> D >> a;
	x[0] = a;
	for (int i = 0; i <= 10; ++i) {
		x[i + 1] = r * x[i] - D;
	}
	for (int i = 1; i <= 10; ++i) {
		cout << x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = input()
for i in range(n):
    x, y, b, p = map(int, raw_input().strip().split(" "))
    if b >= 5 or p >= 2:
        if b < 5:
            print min(x * b + y * p, (x * 5 + y * p) * 4 / 5)
        elif p < 2:
            print min(x * b + y * p, (x * b + y * 2) * 4 / 5)
        else:
            print  (x * b + y * p) * 4 / 5
    else:
        print x * b + y * p 

Measured memory_bytes: 4228
from math import factorial

MOD = 10 ** 9 + 7
N, M, K = map(int, input().split(' '))

n, r = N * M - 2, K - 2
#P = factorial(n) // factorial(n-r) // factorial(r) % MOD
P = factorial(n) * pow(factorial(n-r) % MOD, MOD - 2, MOD) * pow(factorial(r) % MOD, MOD - 2, MOD)

ans = 0
for n in range(N) :
    for m in range(M) :
        if n == 0 and m == 0 :
            continue

        d = n + m
        cnt = (N - n) * (M - m) * (1 if n == 0 or m == 0 else 2)

        ans += d * cnt

ans = (ans * P) % MOD
print(ans)


Measured memory_bytes: 5872
W, H, N = map(int, input().split())
xya = []
l = 0
r = W
u = H
d = 0
for _ in range(N):
	x, y, a = map(int, input().split())
	if a == 1:
		l = max(l,x)
	elif a == 2:
		r = min(r,x)
	elif a == 3:
		d = max(d,y)
	else:
		u = min(u,y)
print(max(0,(u-d))*max(0,(r-l)))

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

int main() {
 int N;
 cin >> N;
 vector<int> a(N);
 for (int i = 0; i < N; i++) cin >> a.at(i);
 int num = 0; 
 int count = 0;
  
 for(int i = 0; i < a.size(); i++){
    if ( a.at(num) == 2 ){
      break;
     }
     else{
       num = a.at(num);
       num --;
         count++;
     }
    }
  
  if ( count >= a.size()){
    cout << -1 << endl;
  }
  else cout << count + 1 << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.buffer.readline

N = int(input())
X = list(map(int, input().split()))

answer = 10 ** 15
for p in range(min(X), max(X) + 1):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    answer = min(answer, tmp)

print(answer)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<char> t(Q), d(Q);
    for(int i=0; i<Q; i++) cin >> t[i] >> d[i];

    int l1 = -1, l2 = -1;
    int r1 = N, r2 = N;

    while(r1 - l1 > 1){
        int mid = (l1 + r1) / 2;
        int tmp = mid;
        bool isOK = false;
        for(int i=0; i<Q; i++){
            if(S[tmp] != t[i]) continue;
            if(d[i] == 'L') tmp--;
            else tmp++;
            if(tmp == -1) {isOK = true; break;}
            if(tmp == N) break;
        }
        if(isOK) l1 = mid;
        else r1 = mid;
    }

    while(r2 - l2 > 1){
        int mid = (l2 + r2) / 2;
        int tmp = mid;
        bool isOK = false;
        for(int i=0; i<Q; i++){
            if(S[tmp] != t[i]) continue;
            if(d[i] == 'L') tmp--;
            else tmp++;
            if(tmp == N) {isOK = true; break;}
            if(tmp == -1) break;
        }
        if(isOK) r2 = mid;
        else l2 = mid;
    }

    cout << l2 - r1 + 1 << endl;
    // printf("%d %d %d %d\n", l1, l2, r1, r2);
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int h = in.ni(), w = in.ni(), d = in.ni();
        HashMap<Integer, Pair> map = new HashMap<>();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int a = in.ni()-1;
                map.put(a,new Pair(i,j));
            }
        }
        int[] arr = new int[h*w];
        for (int i = d; i < h * w; i++) {
            arr[i] = arr[i-d]+Math.abs(map.get(i).x-map.get(i-d).x)+Math.abs(map.get(i).y-map.get(i-d).y);
        }
        long sum;
        int q = in.ni(), l , r;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            sum = 0;
            l = in.ni()-1;
            r = in.ni()-1;
            sum += arr[r]-arr[l];
            sb.append(sum);
            sb.append("\n");
        }
        out.print(sb);
    }
    public static class Pair{
        int x; int y;
        public Pair(int x, int y){
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

int main(){
long long int n,k, ans = 1145141919810931, keeper;
cin >> n >> k;
vector<long long int> v(n);
for(int i=0; i<n; i++){
cin >> v[i];
}
sort(v.begin(),v.end());
for(int i = 0; i <= n - k; i++){
keeper = abs(v[i]-v[i+k-1]);
ans = min(ans,keeper);
}
cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string s = Input.ScanStr();
          Console.WriteLine(s[0]==s[2] ? "Yes" : "No");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
import numpy as np

n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp  = np.zeros(W+1)

for i in range(1,n+1):
    w = weights[i-1]
    v = values[i-1]
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

print(int(dp[-1]))


Measured memory_bytes: 22136
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <stack>
#include <stack>
#include <list>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

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

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

int main(){
    
    int r, c;
    cin >> r >> c;
    int a[101][101] = {{}};
    rep(i, r){
        rep(j, c){
            cin >> a[i][j];
        }
    }
    rep(i, r){
        int sum = 0;
        rep(j, c){
            cout << a[i][j] <<" ";
            a[r][j] += a[i][j];
            sum += a[i][j];
        }
        cout << sum << endl;;
    }
    
    int sum = 0;
    
    rep(j, c){
        cout << a[r][j] << " ";
        sum += a[r][j];
    }
    
    cout << sum << endl;
    
    return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    ll N;
    cin >> N;
    for (ll h = 1; h <= 3500; h++) {
        for (ll n = 1; n <= 3500; n++) {
            ll z = 4*h*n - N*n - N*h;
            if (z > 0 && N*h*n % z == 0) {
                cout << h << " " << n << " " << N*h*n / z << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
#n,k = [int(i) for i in readline().split()]


a = ["Sunny", "Cloudy", "Rainy"] 

s = input()

if s[0] == "S":
    print("Cloudy")
elif s[0] == "C":
    print("Rainy")
else:
    print("Sunny")








Measured memory_bytes: 2940
import sys
from io import StringIO
import unittest
import copy

def resolve():
    n, m, x = map(int, input().split())

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

    ans = 99999999

    # bit全探索
    # 本の数だけパターンを作成
    for i in range(1 << n):

        price = 0
        rikais = [0 for i in range(m)]

        # 本の数だけループ
        for j in range(n):

            # 値が1(購入)の場合
            if i & 1 << j:
                # 価格を加算
                price += books[j][0]
                # 理解度を加算
                for k in range(1, m+1):
                    rikais[k-1] += books[j][k]

            # すべてのアルゴリズムの理解度をX以上にできた場合
            if min(rikais) >= x:
                # 価格の最適解を更新
                ans = min(price, ans)

    # 価格を出力
    if ans is 99999999:
        print(-1)
    else:
        print(ans)







class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
        output = """120"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2"""
        output = """1067"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    int n; cin >> n;ll a,ans=0;
    for (int i=0;i<n;i++)
    {
        cin >> a; ans=(ans^a);
    }
    if (ans==0) cout << "Yes\n" ;else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
	class Program
	{
		static void Main(string[] args)
		{
			var line1 = Console.ReadLine();
			var line1Splited = line1.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
			var N = int.Parse(line1Splited[0]);
			var K = int.Parse(line1Splited[1]);

			var H = new List<long>();
			for (int i = 0; i < N; i++) {
				H.Add(long.Parse(Console.ReadLine()));
			}

			H.Sort();
			H.Reverse();

			long min = long.MaxValue, diff = 0;
			for (int i = 0; i < N - K + 1; i++) {
				diff = H[i] - H[i + K - 1];
				if (min > diff)
					min = diff;
			}

			Console.WriteLine(min);
		}
	}
}

Measured memory_bytes: 17564
n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
    for j in range(i + 1, n):
        k = j - i + j
        if k < n:
            if {s[i], s[j], s[k]} == {"R", "G", "B"}:
                ans -= 1

print(ans)

Measured memory_bytes: 73816
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  final static Long MAX = 1000000000000000000L;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    sc.nextLine();
    List<Long> l = new ArrayList<Long>();
    for(int i = 0;i < n;i++) {
      l.add(sc.nextLong());
    }

    if(l.contains(0L)) {
      System.out.println(0);
    }else {

      Long sum = 1L;

      for(Long l2:l) {
        if(sum > MAX/l2) {
          System.out.println(-1);
          sum = 0L;
          return;
        }
        sum *= l2;
      }
      System.out.println(sum);
    }

    sc.close();
  }

}


Measured memory_bytes: 61088