akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextInt();
        long w = sc.nextInt();
        long a1 = calc(h, w);
        long a2 = calc(w, h);
        long ans = a1 > a2 ? a2 : a1;
        System.out.println(ans);
    }

    public static long calc(long i1, long i2) {
        long[] ss = new long[3];
        long ans = Long.MAX_VALUE;
        long sMax, sMin;
        for (int j = 1; j < i1; j++) {
            ss[0] = j * i2;
            for (int k = 0; k < 2; k++) {
                sMax = Long.MIN_VALUE;
                sMin = Long.MAX_VALUE;
                if (k == 0)
                    ss[1] = (i1 - j) * (i2 / 2);
                else
                    ss[1] = ((i1 - j) / 2) * i2;
                ss[2] = (i1 * i2) - (ss[0] + ss[1]);
                for (int i = 0; i < 3; i++) {
                    if (sMax < ss[i])
                        sMax = ss[i];
                    if (sMin > ss[i])
                        sMin = ss[i];
                }
                if (ans > (sMax - sMin))
                    ans = sMax - sMin;
            }
        }
        return ans;
    } 
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int need_a = ri();
	int need_b = ri();
	int n = ri();
	int m = ri();
	int k = ri();
	int a[n], b[m], c[k];
	for (auto &i : a) i = ri();
	for (auto &i : b) i = ri();
	for (auto &i : c) i = ri();
	
	std::sort(a, a + n, std::greater<>());
	std::sort(b, b + m, std::greater<>());
	std::sort(c, c + k, std::greater<>());
	
	int64_t all = 0;
	for (int i = 0; i < need_a; i++) all += a[i];
	for (int i = 0; i < need_b; i++) all += b[i];
	int a_head = need_a - 1;
	int b_head = need_b - 1;
	int64_t res = -1;
	for (int i = 0; i <= k; i++) {
		res = std::max(res, all);
		if (i < k) {
			if (a_head == -1 && b_head == -1) break;
			if (a_head != -1 && (b_head == -1 || a[a_head] < b[b_head])) all -= a[a_head--];
			else all -= b[b_head--];
			all += c[i];
		}
	}
	printf("%" PRId64 "\n", res);
	
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  ll ans=0;
  int r=0;
  int l=0;
  ll t=0;
  while(r < n){
    if( (t + a[r]) == (t ^ a[r])){
      t += a[r];
      ans += r-l+1;
      r++;
    }else{
      t -= a[l];
      l++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 1792
n=int(input())
A=list(map(int,input().split()))
B=[0]*n
cnt=0
for i in range(n):
    if A[i]<0:
        cnt+=1
    B[i]=abs(A[i])
B.sort()
if cnt%2==0:
    print(sum(B))
else:
    print(sum(B)-2*B[0])

Measured memory_bytes: 14412
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n , m;
    cin >> n >> m;
    vector<ll> v(m);
    vector<ll> l;
    rep(i, m) cin >> v[i];

    if(m == 1){
        cout << 0;
        return 0;
    }
    sort(all(v));

    rep(i, m-1) l.push_back(v[i+1] - v[i]);
    sort(all(l));

    ll f = l.size()-1;
    ll lim = min(m-1, n-1);
    ll cnt = 0;
    ll lsum = 0;
    while(cnt < lim){
        lsum += l[f];
        f--;
        cnt++;
    }
    ll ans = (v[m-1] - v[0]) - lsum;

    cout << ans;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
map<ll,vector<ll> >m;
map<ll,bool> vi;
ll dp[(ll)10e5+1];
ll dfs(ll n)
{
	if(vi[n])
		return dp[n];
	vi[n]=1;
	ll flag=0;
	for(auto x:m[n])
	{
		dp[n]=max(dp[n],1+dfs(x));
	}
	if(m[n].size()==0)
		return dp[n]=0;
	return dp[n];
}
int32_t main()
{
	ll n,q;
	cin>>n>>q;
	while(q--)
	{
		ll x,y;
		cin>>x>>y;
		m[x].pb(y);
		vi[x]=0;
		vi[y]=0;
	}
	ll mi=-1;
	for(auto x:m)
	{
		mi=max(mi,dfs(x.first));
	}
	cout<<mi;
}

Measured memory_bytes: 21632
#include <iostream>
#include <cstdlib>
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  ll a[200000];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ll sunuke = 0;
  ll answer = abs(sum - a[0] * 2);
  for (int i = 0; i < n - 1; i++) {
    sunuke += a[i];
    if (abs(sum - sunuke * 2) < answer) {
      answer = abs(sum - sunuke * 2);
    }
  }
  cout << answer << 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;

int main(void){
	int n;
	string s;
	cin >> n >> s;
	rep(i,s.size()){
		rep(j,n){
			if(s[i]=='Z') s[i] = 'A';
			else s[i] += 1;
		}
	}
	rep(i,s.size())cout << s[i];
	return 0;
}

Measured memory_bytes: 256
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}


ll take_gcd(ll a, ll b)
{
    // cout << a << ' ' << b << endl;
    if (a>b) swap(a, b);
    if (b%a == 0) return a;
    else return take_gcd(a, b%a);
}
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;

    if (d>0 and 4*a*b<d*d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int isprim();
int main()
{
  int a,b[10000],i,l,m=0;
  scanf("%d",&a);
  for(l=0;l<a;l++){
      scanf("%d",&b[l]);
    }
  for(i=0;i<a;i++){
    if(isprim(b[i])==1)m++;
  }
    printf("%d\n",m);
    return 0;
 }
int isprim(x){
    int i;
    if(x==2) return 1;
    else if(x<2||x%2==0) return 0;
    i=3;
    while(i<=sqrt(x)){
      if(x%i==0) return 0;
      i=i+2;
    }
    return 1;
} 

Measured memory_bytes: 632
#include<cstdio>
char s[1000005];
int main(){
    scanf("%s",s+1);
    for(int i=1;s[i+1];i++){
        if(s[i]==s[i+1])return !printf("%d %d\n",i,i+1);
        if(s[i]==s[i+2])return !printf("%d %d\n",i,i+2);
    }
    printf("-1 -1\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int main()
{
    int i,j;
    int h,a;

    scanf("%d %d", &h, &a);
    printf("%d\n", h/a + (h%a>0));

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define fori(i, n) for (int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    int mat[n][3];
    fori (i, n) fori (j, 3) cin >> mat[i][j];

    if (n == 1) {
        cout << max(max(mat[0][0], mat[0][1]), mat[0][2]);
        return 0;
    }

    int dp[2][3];
    dp[0][0] = mat[0][0], dp[0][1] = mat[0][1], dp[0][2] = mat[0][2];
    for (int i = 1; i < n; i++) {
        dp[1][0] = mat[i][0] + max(dp[0][1], dp[0][2]);
        dp[1][1] = mat[i][1] + max(dp[0][0], dp[0][2]);
        dp[1][2] = mat[i][2] + max(dp[0][0], dp[0][1]);
        dp[0][0] = dp[1][0], dp[0][1] = dp[1][1], dp[0][2] = dp[1][2];
    }
    cout << max(max(dp[1][0], dp[1][1]), dp[1][2]);
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int const N = 3e3+9;
int dp[N][N];
int main(){
    string s , t;
    cin>>s>>t;
    for(int i= 1;i<=s.size();i++){
        for(int j = 1;j<=t.size();j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int ptS = s.size();
    int ptT = t.size();
    string out;
    while(ptS && ptT){
        if(dp[ptS][ptT] == dp[ptS-1][ptT]){
            ptS--;

        }else if(dp[ptS][ptT] == dp[ptS][ptT-1]){
            ptT--;
        }else if(dp[ptS][ptT] == dp[ptS-1][ptT-1] +1){
            out+=s[ptS-1];
            ptS--;
            ptT--;
        }
    }
    reverse(out.begin(),out.end());
    cout<<out;
}






Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main() {
  #define int long long
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> graph(n+1);
  for(int i=0,x,y;i<n-1;i++) {
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  // 0 white, 1 black
  vector<array<int,2>> ans(n+1);
  function<void(int,int)> dfs = [&](int u,int v) {
    ans[u] = {1,1};
    // if (graph[u].size()==1)  
    for(auto e: graph[u]) {
      if (e==v) continue;
      dfs(e,u);
      ans[u][0] *= (ans[e][0]+ans[e][1]);
      ans[u][1] *= (ans[e][0]);
      ans[u][0] %= mod;
      ans[u][1] %= mod;
    }
  };
  dfs(1,0);
  cout << (ans[1][0] + ans[1][1])%mod << '\n';
  return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  a*=b;
  a/=2;
  cout<<a<<"\n";
  
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
    int a,b,k;
    cin >>a >> b >> k;
    if(b-a + 1 <= k*2){
        for(int i=a;i<=b;i++){
            cout << i << endl;
        }
    }else {
        for(int i=0; i<k; i ++){
            cout << a + i << endl;
        }
        for(int i=1; i<=k; i ++){
            cout << b - k + i << endl;
        }
    }
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
   int n, x[100000], i;
   x[0] = 1;
   n = 1;
   while(x[n-1] != 0){
      scanf("%d", &x[n]);
      n++;
   }

   for(i = 1; i < n-1; i++){
      printf("Case %d: %d\n", i, x[i]);
   }
   return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)

def find_loop(index, visited, cycle):
    visited[index] = True
    cycle.append(index)
    for i in edges[index]:
        if visited.get(i):
            return cycle[cycle.index(i):]
        ret = find_loop(i, visited, cycle)
        if ret:
            return ret
    visited[index] = False
    cycle.pop(-1)
    return None

def find_local_minimum(cycle):
    nxt = {i: j for (i, j) in zip(cycle, cycle[1:] + cycle[:1])}
    processed = set()
    i = cycle[0]
    while i not in processed:
        processed.add(i)
        for j in edges[i]:
            if j in nxt:
                k = i
                while k != j:
                    l = nxt[k]
                    del nxt[k]
                    k = l
                nxt[i] = j
        i = nxt[i]
    start = i
    ret = [i]
    i = nxt[i]
    while i != start:
        ret.append(i)
        i = nxt[i]
    return ret

cycle = None
visited = {}
for start in range(n):
    if start not in visited:
        cycle = find_loop(start, visited, [])
        if cycle:
            break

if cycle:
    ret = find_local_minimum(cycle)
    print(len(ret))
    for i in ret:
        print(i + 1)
else:
    print(-1)



Measured memory_bytes: 48360
from operator import itemgetter
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

ab.sort(key=itemgetter(1))
ans = [0]
for a, b in ab:
    if ans[-1] < a:
        ans.append(b-1)
print(len(ans) - 1)

Measured memory_bytes: 28580
#include <iostream>
#include <cctype>
#include <cassert>
using namespace std;

string S;
int cur;
int expression();
char readerchar()
{
    assert(cur < S.size());
    char ret = S[cur];
    cur += 1;
    return ret;
}
char peek()
{
    assert(cur < S.size());
    return S[cur];
}
int digit()
{
    assert(isdigit(peek()));
    int n = readerchar() - '0';
    return n;
}
int number()
{
    int n=digit();
    while(cur<S.size() && isdigit(peek()))
        n = n*10 + digit();
    return n;
}
int factor()
{
    if(peek()!='(')
        return number();
    cur += 1;
    int n = expression();
    assert(peek() == ')');
    cur += 1;
    return n;
}
int term()
{
    int a = factor();
    while(cur < S.size() && (peek()=='*' || peek()=='/'))
    {
        char op = readerchar();
        int b = factor();
        if(op == '*')
            a *= b;
        else    a /= b;
    }
    return a;
}
int expression()
{
    int a = term();
    while(cur < S.size() && (peek()=='+' || peek()=='-'))
    {
        char op = readerchar();
        int b = term();
        if(op == '+')
            a += b;
        else
            a -= b;
    }
    return a;
}


int main()
{
    int n,i;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cur = 0;
        cin >> S;
        S.resize(S.size()-1);
        cout << expression() << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  string S;
  int K;
  cin >> S >> K;

  set<string> Q;
  for (int i = 0; i < S.size(); ++i) {
    for (int l = 1; l <= 5 && i + l <= S.size(); ++l) {
      Q.insert(S.substr(i, l));
      if (Q.size() > K) {
        Q.erase(*Q.rbegin());
      }
    }
  }
  
  auto it = Q.begin();
  advance(it, K - 1);
  
  cout << *it << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	
	
	ll w,h;
	ll H,W;
	
	cin >> H >> W >> h >> w;
	
	cout << H*W - (h*W + w*H - w*h) << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const ll MOD = 1e9 + 7;
const int K = 60;

ll n;
vl a;

int main(void) {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    cin >> n;
    a.resize(n);
    rep(i,0,n) {
    	cin >> a[i];
    }

    ll ret = 0;
    ll d = 1;
    for(ll i = 0; i < K; ++i) {
    	ll x = 0;
    	rep(j,0,n) {
    		if(a[j] & 1) {
    			x++;
    		}
    		a[j] = a[j] >> 1;
    	}

    	ll loc = x * (n-x) % MOD;
    	loc *= d;
    	loc %= MOD;
    	ret += loc;
    	ret %= MOD;
    	d *= 2;
    	d %= MOD;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 2560
n=int(input())
X=[]
for i in range(n):
    x,l=[int(_) for _ in input().split()]
    X+=[(x-l,x+l)]
X.sort(key=lambda x:x[0])
ans=n
tmp=X[0][1]
for i in range(1,n):
    if tmp>X[i][0]:
        ans-=1
        tmp=min(tmp,X[i][1])
    else:
        tmp=X[i][1]
print(ans)

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

int main()
{
    int N;
    long A[200010];
    long d;
    long sum = 0;
    long max;

    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    max = A[0];
    for (int i = 0; i < N; ++i)
    {
        if (A[i] < max)
        {
            d = max - A[i];
            sum += d;
        }
        if (A[i] > max)
        {
            max = A[i];
            d = max - A[i];
            sum += d;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 4752
#n = int(input())
x,k,d = map(int,input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
v=abs(x)//d
if abs(x)>= d:
    if abs(x)//d >= k:
        if x >= 0:
            ans=abs(x-d*k)
        else:
            ans=abs(x+d*k)
    else:
        move=v*d
        dif=k-v
        if x >=0:
            #l=[]
            #l.append(x-v*d)
            x2=x-v*d
            #l.append(abs(x2-d))
            #ans=min(l)
            if dif%2==0:
                ans=abs(x-v*d)
            else:
                ans=abs(x2-d)
        else:
            x2=x+v*d
            if dif%2==0:
                ans=abs(x+v*d)
            else:
                ans=abs(x2+d)
else:
    if x>=0:
        x2=x-d
        dif=k-1
        if dif==0:
            ans=abs(x2)
        elif dif%2==0:
            ans=abs(x2)
        else:
            ans=abs(x2+d)
    else:
        x2=x+d
        dif=k-1
        if dif==0:
            ans=abs(x2)
        elif dif%2==0:
            ans=abs(x2)
        else:
            ans=abs(x2-d)
print(ans)


Measured memory_bytes: 9200
from math import sqrt
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in c.keys():
        tmp = a * 2
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

using namespace std;

const int N = 900100;
int n, k, m, a, b, use[N], now[N];
string s;
vector <int> v[N], c[N];

template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	out << v.size() << '\n';
	for(auto e : v) out << e << ' ';
	return out;
}

template<class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
	return out << '(' << p.st << ' ' << p.nd << ')';  
}


bool dfs(int node, int usg, int t) {
	now[node] = 1;
	use[node] = usg;
	for(auto i : v[node]) {
		if(use[i] == 0) {
			if(dfs(i, usg, node))
				return true;
		}
		else if(i != t && use[i] == usg && now[i])
			return true;
	}
	now[node] = 0;
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	cin >> s;
	s = " " + s;
	for(int i = 1; i <= m; i++) {
		cin >> a >> b;
		if(s[a] == 'A' && s[b] == 'A') {
			v[a].push_back(n + b);
			if(a != b)
				v[b].push_back(n + a);
		}
		if(s[a] == 'B' && s[b] == 'B') {
			v[2 * n + a].push_back(3 * n + b);
			if(a != b)
				v[2 * n + b].push_back(3 * n + a);
		}
		if(s[a] == 'A' && s[b] == 'B') {
			v[n + a].push_back(2 * n + b);
			v[3 * n + b].push_back(a);
		}
		if(s[a] == 'B' && s[b] == 'A') {
			v[n + b].push_back(2 * n + a);
			v[3 * n + a].push_back(b);
		}
	}

	dbg(v[3]);
	dbg(v[7]);
	dbg(v[8]);
	dbg(v[10]);
	dbg(v[13]);

	for(int i = 1; i <= n; i++) {
		dbg_ok;
		if(dfs(i, i, -1)) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}	

Measured memory_bytes: 67388
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const ll MIN = (1e+15) + 1;

int main(){
	static ll N, A[5], mi = MIN, ans = 4;
	cin >> N;
	for (int i = 0; i < 5; ++i){
		cin >> A[i];
		mi = min(mi, A[i]);
	}
	ans += ceil((double)N / mi);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

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

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


int main() {
	int a, b, c,x;
	cin >> a >> b >>c ;
	x = a * c;
	if (b < x) cout << b / a;
	else cout << c;
	return 0;
}










Measured memory_bytes: 256
#include<stdio.h>

int isPrime(int x){
  int i;
  if ( x == 2 ) return 1;
  else if ( x < 2 || (x % 2 == 0)) return 0;
  for ( i = 3; i*i <= x; i++){
    if ( x % i == 0 ) return 0;
  }
  return 1;
}

int main(){
  int x, t, status;
  int d = 0;
  while(1){
    status = scanf("%d", &x);
    if(status != 1) break;
    t = isPrime(x);
    d += t;
  }
  printf("%d\n", d);
  
  return 0;
}



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

int main() {
	int n, m, d;
	cin >> n >> m >> d;
	int num = d == 0 ? n : 2 * (n - d);
	cout << fixed << setprecision(10) << (double)num * (m - 1) / n / n;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

長さ2の数列を考えると
(1, 1) (1, 2)... (1, n)
(2, 1) (2, 2)... (2, n)
...
(n, 1) (n, 2)... (n, n)
となり、差は0がn個、差がx(0<x<n)のが2x+2(n-2x)=2(n-x)個ある
では、長さ3にすると？
2-3について同じように長さ2の数列で考えると、2(n-x)x2n倍になる
つまり、例えば差0については(x, x, y)はxy通り、つまりn^2通りあり、
また(x, y, y)も同様にn^2通りあるので
重複する(x, x, x)に関しては両方カウントしても無問題だからセーフ
つまり答えは(m-1)*2(n-d)*n^{m-2}
後はこれをn^mで割るだけ
よって答えは
d=0 : (m-1)n^{m-1}/(n^m)=(m-1)/n
d=x : 2(n-d)(m-1)n^{m-2}/(n^m)=2(n-d)(m-1)/(n^2)
*/

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#define maxK 1000
int pos[3 * maxK][2 * maxK];
int sum[3 * maxK + 1][2 * maxK + 1];

int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    int x, y;
    char c;
    cin >> x >> y >> c;
    if(c == 'W') y += K;
    //x,yを2k,kに集める
    y %= (2 * K);
    if(y >= K){
      y -= K;
      x += K;
    }
    x %= (2 * K);

    if(x < K){
      pos[x][y]++;
      pos[x + 2 * K][y]++;
      pos[x + K][y + K]++;
    } else {
      pos[x - K][y + K]++;
      pos[x][y]++;
      pos[x + K][y + K]++;
    }
  }

  //posの累積和
  for(int i = 0; i <= 3 * K; i++){
    for(int j = 0; j <= 2 * K; j++){
      if(i == 0 || j == 0) sum[i][j] = 0;
      else sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + pos[i-1][j-1];
    }
  }

  /*
  //debug↓
  cout << "pos" << endl;
  for(int i = 0; i < 3 * K; i++){
    for(int j = 0; j < 3 * K; j++){
      cout << pos[i][j] << " ";
    }
    cout << endl;
  }
  cout << "sum" << endl;
  for(int i = 0; i <= 3 * K; i++){
    for(int j = 0; j <= 3 * K; j++){
      cout << sum[i][j] << " ";
    }
    cout << endl;
  }
  //debug ↑
  */

  int ans = 0;
  for(int i = 0; i < 2 * K; i++){
    for(int j = 0; j < K; j++){
      int tmp = sum[i+K][j+K] - sum[i+K][j] - sum[i][j+K] + sum[i][j];
      ans = max(ans, tmp);
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 47104
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

int main(void)
{
    int N, M;
    std::cin >> N >> M;

    std::vector<int> P(M), Y(M);
    for (int i = 0; i < M; i++)
    {
        std::cin >> P[i] >> Y[i];
    }

    std::vector<std::pair<int, int>> x[N + 1];
    for (int i = 0; i < M; i++)
    {
        x[P[i]].emplace_back(Y[i], i);
    }

    int ans[M];
    for (int i = 1; i <= N; i++)
    {
        std::sort(x[i].begin(), x[i].end());

        for(int j = 0; j < x[i].size(); j++)
        {
            ans[x[i][j].second] = j + 1;
        }
    }

    for(int i = 0; i < M; i++)
    {
        std::cout << std::setw(6) << std::setfill('0') << P[i];
        std::cout << std::setw(6) << std::setfill('0') << ans[i] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 8192
def main():

    N, K, C = [int(i) for i in input().split()]
    S = input().rstrip()

    if all(s == "x" for s in S):
        return
    
    left = [0] * N
    day = 0
    work_cnt = 1
    while day < N:
        if S[day] == "o":
            left[day] = work_cnt
            work_cnt += 1
            day += C
        day += 1
    
    right = [0] * N
    day = N - 1
    work_cnt = K
    while 0 <= day:
        if S[day] == "o":
            right[day] = work_cnt
            work_cnt -= 1
            day -= C
        day -= 1
    
    for i in range(N):
        if left[i] == right[i] and left[i] != 0:
            print(i + 1)

main()


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

int main(){
    int n,m;cin>>n>>m;
    vector<string> image(n);for(int i=0;i<n;i++){cin>>image[i];}
    vector<string> temp(m);for (int i=0;i<m;i++){cin>>temp[i];}


    bool all_match = false;
    for (int h_init=0;h_init<=n-m;h_init++){
        for (int w_init=0;w_init<=n-m;w_init++){
            bool broke = false;

            for (int h=0;h<m;h++){
                if (image[h_init + h].substr(w_init, m) != temp[h]){
                    broke = true;
                    break;
                }
            }
            if (!broke){
                all_match = true;
            }

        }
    }
    if (all_match){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    map<int, int> cnt;
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        cnt[x]++;
    }
    int mx0=0, mx1=0;
    for (auto rit = cnt.rbegin(); rit != cnt.rend(); rit++) {
        if (rit->second < 2) continue;
        if (!mx0) mx0 = rit->first, rit->second-=2;
        if (rit->second < 2) continue;
        if (!mx1) {mx1 = rit->first; break;}
    }
    long long res = 1ll*mx0*mx1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 4992
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false); 
ll dsu[123456],dist[123456];
vector<vl> vec(123456);
ll par(ll cur){
	if(dsu[cur]<0) return cur;
	dsu[cur]=par(dsu[cur]);
	return dsu[cur];
}  
ll check(ll l,ll r,ll d){
	if(par(l)==par(r)){
		if(dist[r]-dist[l]!=d){
			cout<<"No"<<endl;
			exit(0);
		}
		return 0;
	}
	ll u=par(l);
	ll i,v=par(r),change;
	if(dsu[u]<dsu[v]){
		dsu[u]+=dsu[v];
		change=dist[r]-dist[l]-d;
		change*=-1;
		rep(i,vec[v].size()){
			dist[vec[v][i]]+=change;
			vec[u].pb(vec[v][i]);
			dsu[vec[v][i]]=u;
		}
		vec[v].clear();
	}
	else{

		dsu[v]+=dsu[u];
		change=dist[r]-dist[l]-d;
		//change*=-1;
		swap(u,v);
		rep(i,vec[v].size()){
			dist[vec[v][i]]+=change;
			vec[u].pb(vec[v][i]);
			dsu[vec[v][i]]=u;
		}
		vec[v].clear();
	}
	return 0;

}
int main(){
    std::ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll i,l,r,d;
    rep(i,n+10){
    	dsu[i]=-1;
    	dist[i]=0;
    	vec[i].pb(i);
    }
    rep(i,m){
    	cin>>l>>r>>d;
    	check(l,r,d);
    	
    }
    cout<<"Yes"<<endl;
    return 0;

    return 0;  
    
}



Measured memory_bytes: 15608
#include <iostream>
#include <string>
#include <sstream>

int main(){
    std::string r, g, b;
    std::cin >> r >> g >> b;

    std::stringstream ss;
    int rgb;
    std::string buf = r + g + b;
    ss << buf;
    ss >> rgb;

    if(0 == rgb%4){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<vector>
#define ll long long
#define MAX_N 10001
#define INF 1000001
#define MINF -1000001

using namespace std;

vector<int> a_n(MAX_N);

int min(int &n){
  int min = INF;
  for(int i=0;i < n;i++){
    if(min > a_n.at(i)) min = a_n.at(i);
  }
  return min;
}

int max(int &n){
  int max = MINF;
  for(int i=0;i < n;i++){
    if(max < a_n.at(i)) max = a_n.at(i);
  }
  return max;
}

ll sum(int &n){
  ll sum = 0;
  for(int i=0;i < n;i++){
    sum += a_n.at(i);
  }
  return sum;
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i < n;i++){
    cin >> a_n.at(i);
  }
  
  cout << min(n) << " " << max(n) << " " << sum(n) << endl;
  return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N + 1, 0);
  for (ll i = 1; i < N + 1; i++)
  {
    cin >> H.at(i);
  }

  // dp[i][j][k] := i 個目まで見た, j 回削除した, いちばん右が k 番目
  vector<vector<vector<ll>>> dp(N + 2, vector<vector<ll>>(K + 1, vector<ll>(N + 1, INF)));
  dp.at(0).at(0).at(0) = 0;
  for (ll i = 0; i < N + 1; i++)
  {
    for (ll j = 0; j <= K; j++)
    {
      for (ll k = 0; k < N; k++)
      {
        // 削除する
        if (j != K)
          chmin(dp.at(i + 1).at(j + 1).at(k), dp.at(i).at(j).at(k));

        // 削除しない
        chmin(dp.at(i + 1).at(j).at(i), dp.at(i).at(j).at(k) + max(0LL, H.at(i) - H.at(k)));
      }
    }
  }

  ll ans = *min_element(dp.at(N + 1).at(K).begin(), dp.at(N + 1).at(K).end());
  cout << ans << endl;
}

Measured memory_bytes: 217600
#include <iostream>
#include <vector>

int main(int argc, char const *argv[]) {

    int N;
    std::cin >> N;

    std::vector<int> buttons;
    for(int times = 0 ; times < N ; times++ )
    {
        int button_number;
        std::cin >> button_number;
        /** ボタンの数を0スタートにしている **/
        buttons.push_back(button_number - 1);
    }

    std::vector<bool> pushed_button(N);
    int button_index = 0;
    int push_times = 0;

    /** 既に通ったボタンにたどり着いたときに終了 **/
    while(pushed_button[button_index] == false)
    {
        /** 1番目のボタンは終了の合図なので脱出 **/
        if(button_index == 1)
        {
            break;
        }

        push_times++;

        pushed_button[button_index] = true;
        button_index = buttons[button_index];

    }

    std::cout << (button_index == 1 ? push_times : -1) << '\n';

    return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N;
    cin >> N;
    vector<int> H(N);
    REP(i, N) cin >> H[i];
    int mx  = H[0];
    int ans = 1;
    FOR(i, 1, N) {
        if (mx <= H[i]) {
            ans++;
            mx = H[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d %d" @@ fun n w ->
  let items = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
  let len = Array.fold_left (fun s (w,v) -> s+v) 1 items in
  let dp = Array.make len max_int in
  dp.(0) <- 0;
  for i = 0 to n-1 do
    let wi, vi = items.(i) in
    for j = len-1 downto vi do
      if dp.(j-vi) < max_int then
        dp.(j) <- min dp.(j) (dp.(j-vi) + wi)
    done;
  done;
  Array.mapi (fun i e -> i, e) dp
  |> Array.fold_left (fun a (v, wv) ->
      if wv <= w then v else a) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 5760
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    mat = [list(sys.stdin.readline()) for _ in range(n)]

    ans = 0
    for i in range(n):
        tmp = [[mati[(i + j) % n] for j in range(n)] for mati in mat]
        flg = True
        for y in range(n):
            for x in range(n):
                if tmp[y][x] != tmp[x][y]:
                    flg = False
        ans += flg * n
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 206416
H, W, K = map(int, input().split())
S = [list(input()) for _ in range(H)]

ans = 10 ** 6

def calc(lst): #lst: 区切りを与える
    n = sum(lst) + 1 #n+1個に縦を区切る
    tmp = [0] * n
    count = n - 1 #区切る本数
    for w in range(W):
        position = 0
        now = [0] * n
        for h in range(H):
            if S[h][w] == '1': #ホワイトチョコレートのとき
                now[position] += 1
            if lst[h] == 1:
                position += 1
        
        flag = True
        for i in range(n):
            if tmp[i] + now[i] > K:
                flag = False

        if flag:
            for i in range(n):
                tmp[i] += now[i]
        else:
            count += 1
            for i in range(n):
                tmp[i] = now[i]
    for i in range(n):
        if now[i] > K:
            count += 10 ** 6
            
    return count

for i in range(2 ** (H - 1)):
    lst = [0] * (H)
    for j in range(H - 1):
        if (i >> j) & 1:
            lst[j] = 1
    ans = min(calc(lst), ans)

print (ans)
        

Measured memory_bytes: 49244
import sys
N,k=map(int,input().split())
blist=[0]+list(map(int,input().split()))

checked_list=[-1]*(N+1)
pos=1
t=0
while True:
  if t==k:
    print(pos)
    sys.exit(0)
  elif checked_list[pos]!=-1:
    break
  
  checked_list[pos]=t
  pos=blist[pos]  
  t+=1
  
#print(checked_list,pos,t)
cycle=t-checked_list[pos]
#print(cycle)
pos_in_cycle=(k-checked_list[pos])%cycle
#print(pos_in_cycle)
k2=checked_list[pos]+pos_in_cycle
#print(k2)

print(checked_list.index(k2))

Measured memory_bytes: 32316
#!/usr/bin/env python3

from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -99999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = 0
        for t in range(10):
            if f[i][t] == 1 and open_at[t] == 1:
                cnt += 1
        res += p[i][cnt]
    return res

main()


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

int main() {
    int n;
    cin >> n;
    vector< vector<int> > G(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            G[u][v] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j > 0) cout << " ";
            cout << G[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define vpush(v,x) v.push_back(x);
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,w,h;
    string s;
    cin>>a>>b;
    cin>>s;
    if(s[b-1]=='A'){
        s[b-1]='a';
    }
    else if(s[b-1]=='B'){
        s[b-1]='b';
    }
    else{
        s[b-1]='c';
    }
    cout<<s;
    return(0);
}

Measured memory_bytes: 256
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, p = MII()
    s = list(map(int, IS()))
    if 10%p == 0: # pが2または5の場合
        cnt = 0
        for i, si in enumerate(s):
            if si%p == 0:
                cnt += i+1
        print(cnt)
        return None

    d = [0]*p
    d[0] = 1 # 0(mod p)はそれ単体で割り切れるため+1しておく
    ss = 0
    x = 1
    for si in s[::-1]:
        ss += x*si
        ss %= p
        d[ss] += 1
        x = (10*x)%p # %p無しだとTLE
    cnt = 0
    for di in d:
        cnt += di*(di-1)//2 # calc combination(n_C_2)
    print(cnt)


if __name__ == "__main__":
    main()

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

int main(){
	
	string s;
	cin >> s ;
	int cnt = 0;
	int red = 0;
	int blue = 0;
	for (int i = 0; i < s.length(); i++){
		if(s[i] == '0'){
			red++;
		}else{
			blue++;
		}
	}
	cout << min(red,blue) *2 <<endl;
	
}

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

int hp_sum(int live_coordinate[], int array_size, int P)
{
    int sum = 0;

    for (int i = 0; i < array_size; ++i){
        sum += pow(live_coordinate[i] - P, 2);
    }

    return sum;
}

void swap(int *x, int *y)
{
    int temp;

    temp = *x;
    *x = *y;
    *y = temp;
}

void bubble_sort(int array[], int array_size)
{
    for(int i = 0; i < array_size; ++i){
        for(int j = array_size - 1; j > i; --j){
            if (array[j] < array[j-1]) swap(&array[j], &array[j-1]);
        }
    }

}

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

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

    bubble_sort(live_coordinate, N);

    int min = live_coordinate[0];
    int max = live_coordinate[N - 1];

    int result_array[max - min + 1];
    int count = 0;

    for (int p = min; p <= max; ++p){
        result_array[count] = hp_sum(live_coordinate, N, p);
        ++count;
    }

    bubble_sort(result_array, max - min + 1);

    cout << result_array[0];

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,n,m;
	scanf("%d",&n);
	a=100000;
	for(m=0;m<n;m++)
	{
		a=a*1.05;
		if(a%1000!=0)
			a=a-a%1000+1000;

	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 592
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    var l = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    l.add(Long.MAX_VALUE)
    var a = 0L
    var current = 0L
    for(i in 0 until x){
        current = l[i]
        if(current + y > l[i + 1]){
            a += l[i + 1] - l[i]
        }
        else{
            a += y
        }
    }
    println(a)
}

Measured memory_bytes: 83024
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

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

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}


use input::*;

fn main() {
    let (a, b, c): (isize, String, isize);
    input!(a, b, c);
    if b == "+" {
        p(a + c);
    } else {
        p(a - c);
    }
}

Measured memory_bytes: 4352
n, m = map(int,input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]

pt_max = m * m

def b():
    for i in range(n-m+1):
        for j in range(n-m+1):
            pt = 0
            for k in range(m):
                for l in range(m):
                    if A[i+k][j+l] == B[k][l]:
                        pt += 1
            if pt == pt_max:
                return "Yes"
    return "No"

print(b())

Measured memory_bytes: 40176