akhauriyash/Code-Regression huggingface dataset:
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
int n, go[63][200005];
ll x;
int main(){
ios::sync_with_stdio(false);
	cin>>n>>x;
	rep(i, n) {cin >> go[0][i];go[0][i]--;}
	rep(j, 61){
		rep(i, n){
			go[j+1][i] = go[j][go[j][i]];
		}
	}
	int cur = 0;
	rep(j, 62){
		if( ((x>>j)&1LL) == 0 ) continue;
		cur = go[j][cur];
	}
	cout<<++cur<<endl;
}

Measured memory_bytes: 52108
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
using namespace std;
string s;
int ans; 
int main()
{
	cin>>s;
	for(int i=0; i<s.length()-1; i++)
	{
		if(s[i]!=s[i+1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define N 100010
vector<ll> g[N]; ll n,c[N],nz[N],ans[N];
int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
      ll a,b;cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
  }
  for(int i=0;i<n;i++)cin>>c[i]; sort(c,c+n);
  if(n==1){
      cout<<c[0]<<endl;
      cout<<c[0]<<endl;
      return 0;
  }
  for(int i=1;i<=n;i++)nz[i]=g[i].size();
  queue<ll> Q;
  for(int i=1;i<=n;i++){
      if(nz[i]==1)Q.push(i);
  }
  ll t=0;
  while(!Q.empty()){
      ll x=Q.front(); Q.pop();
      ans[x]=c[t]; t++;
      for(auto y:g[x]){
	  nz[y]--;
	  if(nz[y]==1)Q.push(y);
      }
  }
  ll res=0;
  for(int i=1;i<=n;i++)for(auto y:g[i]){
      res+=min(ans[i],ans[y]);
  }
  res/=2; cout<<res<<endl;
  for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
  return 0;
}


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

static const int MAX = 200000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];
int rsl = 0;

void dfs(int r, int c){
    int cnt = 0;
    stack<int> S;
    S.push(r);
    color[r] = c;
    cnt += 1;
    while(!S.empty()){
        int u = S.top(); S.pop();
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            if(color[v]==NIL){
                color[v] = c;
                cnt += 1;
                S.push(v);
            }
        }
    }
    rsl = max(rsl,cnt);
}

void assignColor(){
    int id = 1;
    for(int i=0;i<n;i++) color[i]=NIL;
    for(int u=0;u<n;u++){
        if(color[u]==NIL) dfs(u, id++);
    }
}

int main(void){
    // Your code here!
    int s,t,m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> s >> t;
        s -= 1;t -= 1;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();
    cout << rsl << endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

const int limit = 100010;
ll a[limit];

int main(void) {
	int k;
	cin >> k;
	rep(i, k) cin >> a[i];

	ll amin = 2LL, amax = 2LL;
	rrep(i, k) {
		ll coef_min = (amin + a[i] - 1LL) / a[i];
		ll coef_max = amax / a[i];
		amin = a[i] * coef_min;
		amax = a[i] * coef_max + (a[i] - 1);
		//cerr << amin << " " << amax << endl;
	}

	if(amin <= amax)
		cout << amin << " " << amax << endl;
	else
		cout << -1 << endl;

	return 0;
}

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, ans;
  cin >> n >> ans;
  while (--n) {
    long long a;
    cin >> a;
    ans = lcm(ans, a);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;

vector<int> v;

int main(int argc, char const *argv[])
{
  int N, K;
  cin >> N >> K;

  int Joutmax = min(N, K);
  long long ans = 0;

  for (int i = 0; i < N; i++)
  {
    int temp;
    cin >> temp;
    v.push_back(temp);
  }
  // 取り出す個数
  for (int k = 1; k <= Joutmax; k++)
  {
    for (int left = 0; left <= k; left++)
    {
      int right = k - left;
      long long sum = 0;
      int diff = K - k;
      vector<int> vecJ;
      for (int index = 0; index < left; index++)
      {
        sum += v[index];
        vecJ.push_back(v[index]);
      }
      for (int index = 0; index < right; index++)
      {
        sum += v[N - index - 1];
        vecJ.push_back(v[N - index - 1]);
      }
      sort(vecJ.begin(),vecJ.end());
      for (int index = 0; index < min(diff,k); index++)
      {
        sum -= min(0,vecJ[index]);
      }
      //cout << sum << endl;
      ans = max(sum, ans);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
#n = int(input())
x, k, d = map(int, sys.stdin.readline().split())
#s = input()
#l = list(map(int, sys.stdin.readline().split()))

a = (abs(x)//d) + 1

if a >= k:
    if x >= 0:
        ans = (x - k * d)
    else:
        ans = (x + k * d)
else:
    if x >= 0:
        if (k - a) % 2 == 0:
            ans = (x - a * d)
        else:
            ans = ((x - a * d) + d)
    else:
        if (k - a) % 2 == 0:
            ans = (x + a * d)
        else:
            ans = ((x + a * d) - d)

print(abs(ans))
    




Measured memory_bytes: 10124
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		char[][] map = new char[h][w];
		for (int i = 0; i < h; i++) {
			String dot = sc.next();
			for (int j = 0; j < w; j++) {
				map[i][j] = dot.charAt(j);
			}
		}
		int result = 0;
		for (int i = 0; i < (1 << h); i++) {
			for (int j = 0; j < (1 << w); j++) {
				int count = 0;
				for (int l = 0; l < h; l++) {
					for (int m = 0; m < w; m++) {
						if ((((i >> l) & 1)== 1)) {
							continue;
						}
						if ((((j >> m) & 1)== 1)) {
							continue;
						}
						if (map[l][m] == '#') {
							count++;
						}
					}
				}
				if (count == k) {
					result++;
				}
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 35632
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n, w;
ll a[mnx];
ll b[mnx];
ll dp[mnx];

int main(){
    cin >> n >> w;

    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }

    fill(dp, dp + mnx, mod);

    dp[0] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 200000; j >= 0; j--) {
            if(dp[j] != mod)
                dp[j + b[i]] = min(dp[j + b[i]], dp[j] + a[i]);
        }
    }

    ll ans = 0;

    for (int i = 0; i <= 200000; i++) {
        if(dp[i] <= w) ans = i;
    }

    cout << ans << '\n';

    return 0;
}

/*
3
10 40 70
20 50 80
30 60 90

10  40  70
90  120 120
150 180 210
*/


















Measured memory_bytes: 10496
#include <stdio.h>
 
long long int gcd( long long int a , long long int b ){
    long long int r;
    while((r = a % b)!=0){
        a = b;
        b = r;
    }
    return b;
}
 
long long int lcm( long long int a , long long int b){
    return a/gcd(a,b)*b;
}
 
int main(void){
    long long int a , b;
    while(scanf("%lld %lld" , &a , &b)!=EOF){
        printf("%lld %lld\n" , gcd(a,b) , lcm(a,b));
    }
    return 0;
}

Measured memory_bytes: 596
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    lli ans = 0;
    if((x/d)>k)
    {
        ans = x - d * k;
    }
    else
    {
        lli tmp = x % d;
        k -= (x - tmp) / d;
        (k % 2 == 0 ? ans = tmp : ans = min(abs(tmp - d), tmp + d));
    }
    out(ans);
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
	
	static int time(String s) {
		String[] t=s.split(":");
		return Integer.parseInt(t[0])*3600+Integer.parseInt(t[1])*60+Integer.parseInt(t[2]);
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				int[] start=new int[86401];
				int[] end=new int[86401];
				for(int i=0; i<n; i++) {
					int s=time(sc.next());
					int e=time(sc.next());
					start[s]+=1;
					end[e]+=-1;
				}
				int count=0, max=0;
				for(int i=0; i<=86400; i++) {
					count+=start[i]+end[i];
					max=Math.max(count, max);
				}
				System.out.println(max);
			}
			
		}
	}
}


Measured memory_bytes: 105040
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        long[] x = new long[n];
        long[] y = new long[n];
        for(int i=0; i<n; i++){
            x[i] = stdIn.nextInt();
            y[i] = stdIn.nextInt();
        }
        
        long max_x_minus_y = Long.MIN_VALUE;
        long min_x_minus_y = Long.MAX_VALUE;
        for(int i=0; i<n; i++){
            long x_minus_y = x[i] - y[i];
            if(max_x_minus_y < x_minus_y)
                max_x_minus_y = x_minus_y;
            if(x_minus_y < min_x_minus_y)
                min_x_minus_y = x_minus_y;
        }

        long max_x_plus_y = Long.MIN_VALUE;
        long min_x_plus_y = Long.MAX_VALUE;
        for(int i=0; i<n; i++){
            long x_plus_y = x[i] + y[i];
            if(max_x_plus_y < x_plus_y)
                max_x_plus_y = x_plus_y;
            if(x_plus_y < min_x_plus_y)
                min_x_plus_y = x_plus_y;
        }

        long ans = Math.max(max_x_minus_y - min_x_minus_y, max_x_plus_y - min_x_plus_y);
        System.out.println(ans);
    }
}

Measured memory_bytes: 61268
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin>>n;
    long long sum=0;
    for(int i=1;i<=n;++i){
        if(i%3==0||i%5==0)
            continue;
        sum+=i;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   while (true) {
      int h, w;
      cin >> h >> w;
      if (h == 0 && w == 0)
         break;
      rep(i, h) {
         rep(j, w) {
            if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
               cout << '#';
            else
               cout << '.';
         }
         cout << endl;
      }
      cout << endl;
   }
   return 0;
}


Measured memory_bytes: 3072
import math

def is_prime(N :int) -> bool:
    if N < 2:
        return False

    if N == 2:
        return True
    
    if N == 3:
        return True
    
    sqrt_n = int(math.sqrt(N)) + 1
    for i in range(2, sqrt_n):
        if N % i == 0:
            return False

    return True

if __name__ == "__main__":
    N = int(input())
    
    ans = 0
    for i in range(N):
        num = int(input())
        if is_prime(num):
            ans += 1

    print(ans)


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Returns Run Length Enconding of an input vector.
// Verified: AGC040A
template<typename T> vector<pair<T, int>> RLE(vector<T> xs) {
  vector<pair<T, int>> es;

  T current = xs[0];
  int current_count = 1;
  for (int i = 1; i < xs.size(); i++) {
    if (xs[i] == current) {
      current_count++;
    } else {
      es.push_back(make_pair(current, current_count));
      current = xs[i];
      current_count = 1;
    }
  }
  es.push_back(make_pair(current, current_count));
  return es;
}

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

  string s;
  cin >> s;
  vector<char> cs(s.begin(), s.end());
  auto rle = RLE(cs);
  cout << rle.size() - 1 << endl;
}

Measured memory_bytes: 1736
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a,b,i,j;
int main()
{
	scanf("%lld%lld",&a,&b);
	if(a==b)
	{
		printf("1");
		return 0;
	}
	for(i=60;(a>>i&1)==(b>>i&1);--i);
	a&=(1ll<<i)-1,b&=(1ll<<i)-1;
	for(j=60;j>=0&&!(b>>j&1);--j);
	if(a>=(1ll<<(j+1)))
		printf("%lld",2*((1ll<<i)-a)+(1ll<<(j+1)));
	else
		printf("%lld",2*(1ll<<i)-a);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  string s, t;
  cin >> s >> t;

  int ans = 0;
  rep(i, s.length()) ans += (s[i] != t[i]);
  cout << ans << '\n';

  




  
  return 0;
}

Measured memory_bytes: 3844
<?php
  fscanf(STDIN,"%d%d%d", $n,$m,$x);

  for($i=0; $i<$n; $i++){
    $ca[$i] = explode(" ",trim(fgets(STDIN)));
  }
  $f = false;
  $mon = 99999999999;
  for($i=0; $i< 1<<$n; $i++){
    $skill = array_fill(0, $m+1, 0);
    for($j=0; $j<$n; $j++){
      if($i & (1<<$j)){
        foreach($ca[$j] as $key => $data){
          $skill[$key] += $data;
        }
      }
      $flag = true;
      //print_r($skill);
      for($k=1; $k<=$m; $k++){
        if($skill[$k] < $x){
          $flag = false;
        }
      }
      
      if($flag){
        $f = true;
        $mon = min($mon,$skill[0]);
      }
    }
  }

  echo $f ? $mon : "-1";

Measured memory_bytes: 16288
#include <stdio.h>

int main() {
 const int num[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
 int k=1;
 scanf("%d", &k);
 printf("%d", num[k-1]);
 return 0;
}

Measured memory_bytes: 128
import math
from bisect import bisect_left
x = int(input())
def primes(x):
    if x < 2: return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0
    return [prime for prime in primes if prime != 0]

L = primes(10**5 + 20)
if x in L:
    print(x)
else:
    print(L[bisect_left(L, x)])

Measured memory_bytes: 7064
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n), 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a) - 1; (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll H, W;
  cin >> H >> W;
  vector<vector<ll>> A(H, vector<ll>(W));
  rep (i, H) {
    rep (j, W) {
      cin >> A[i][j];
    }
  }
  vector<vector<ll>> B(H, vector<ll>(W));
  rep (i, H) {
    rep (j, W) {
      cin >> B[i][j];
    }
  }

  vector<vector<ll>> grid;
  rep (i, H) {
    vector<ll> row(W);
    rep (j, W) {
      row[j] = A[i][j] - B[i][j];
    }
    grid.push_back(row);
  }

  ll limit = 80 * 80;
  vector<vector<vector<int>>> dp(H, vector<vector<int>>(W, vector<int>(limit + 1)));
  dp[0][0][abs(grid[0][0])] = 1;
  rep (h, H) {
    rep (w, W) {
      ll g = grid[h][w];
      if (h - 1 >= 0) {
        rep (c, limit + 1) {
          if (abs(c + g) <= limit) {
            dp[h][w][abs(c + g)] |= dp[h - 1][w][c];
          }
          if (abs(c - g) <= limit) {
            dp[h][w][abs(c - g)] |= dp[h - 1][w][c];
          }
        }
      }
      if (w - 1 >= 0) {
        rep (c, limit + 1) {
          if (abs(c + g) <= limit) {
            dp[h][w][abs(c + g)] |= dp[h][w - 1][c];
          }
          if (abs(c - g) <= limit) {
            dp[h][w][abs(c - g)] |= dp[h][w - 1][c];
          }
        }
      }
    }
  }

  rep (i, 81) {
    if (dp[H - 1][W - 1][i]) {
      cout << i << "\n";
      break;
    }
  }
}

Measured memory_bytes: 162816
a,b=[int(i) for i in input().split()]
s=0

a= 100000 if a==3 else 200000 if a==2 else 300000 if a==1 else 0
b= 100000 if b==3 else 200000 if b==2 else 300000 if b==1 else 0

s=a+b
if a+b==600000:
    s=1000000
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    in(n);
    vector<int> vec(n);
    set<int> kind;
    map<int,int> memo;
    rep(i,n){
        in(vec[i]);
        if(kind.count(vec[i])){
            memo[vec[i]]++;
        }else{
            kind.insert(vec[i]);
            memo[vec[i]]=1;
        }
    }
    if(kind.size()>=4){
        out("No");
    }else if(kind.size()==3){
        vector<int> vec(3);
        int i=0;
        for(auto value:kind){
            vec[i]=value;
            i++;
        }
        bitset<32> abit(vec[0]),bbit(vec[1]),cbit(vec[2]);
        abit=(abit^bbit);
        abit=(abit^cbit);
        yn(abit.to_ullong()==0&&memo[vec[0]]==memo[vec[1]]
        &&memo[vec[1]]==memo[vec[2]]);
    }else if(kind.size()==2){
        vector<int> vec(2);
        int i=0;
        for(auto value:kind){
            vec[i]=value;
            i++;
        }
        sort(all(vec));
        yn(vec[0]==0&&2*memo[vec[0]]==memo[vec[1]]);
    }else{
        yn(*begin(kind)==0);
    }
}

Measured memory_bytes: 10800
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    int l,r,d;
    cin>>l>>r>>d;
    int ans;
    ans=(r/d)-(l/d);
    if (l%d==0) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3576
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=1; cin>>n;
    vector<ll> a(n,0),c(3,-1);
    rep(i,n) cin>>a[i];
    rep(i,n){
        int cnt=0;
        rep(j,3)if(a[i]==c[j]+1) cnt++;
        ans=(ans*cnt)%MOD;
        rep(j,3){
            if(a[i]==c[2-j]+1){
                c[2-j]=a[i];
                break;
            }
        }
    }
    cout<<(MOD+ans)%MOD<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

const int MAX = 510000;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    int n,p; cin >> n >> p;
    ll g = 0, k = 0;
    rep(i,n) {
        int a; cin >> a;
        if(a%2==0) g++;
        else k++;
    }
    COMinit();
    ll two_g,ans = 0;
    two_g = 1ll<<g;

    if(p==1){
        for(int i = 1; i <= k; i+=2){
            ans += COM(k,i);
        }
        ans *= two_g;
    }else{
        for(int i = 0; i <= k; i+=2){
            ans += COM(k,i);
        }
        ans *= two_g;
    }
    cout << ans << endl;
}




Measured memory_bytes: 15536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int x,a,b;cin>>x>>a>>b;
  int c=b-a;
  string ans;
  if(c<=0){
    ans="delicious";
  }else if(c<=x){
    ans="safe";
  }else{
    ans="dangerous";
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;
const int MAXN = 100010;
int nowarn;

int n, cnt[MAXN] = {0};

int main() {
	nowarn = scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) {
		int a;
		nowarn = scanf( "%d", &a );
		++cnt[a], ++cnt[a+1], ++cnt[a+2];
	}
	int ans = 0;
	for( int i = 0; i < MAXN; ++i )
		ans = max( ans, cnt[i] );
	printf( "%d\n", ans );
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    int n,k;
    cin>>n>>k;
    ll ans = 0;
    REP(i,k,n+1) {
        ans += ((ll)i*n-(ll)(i-1)*i+1);
    }
    cout<<ans%mod;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	if(s==t) {
		printf("Yes");return 0;
	}
	string a,b;
	int len=s.length();
	for(int i=1;i<len;i++){
		a=s.substr(0,i);
		b=s.substr(i);
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		a=a+b;
		reverse(a.begin(),a.end());
		if(a==t) {
			printf("Yes");return 0;
		}
	}
	printf("No");
	
	return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define mp make_pair
const int maxn=2e5;
string S,T,U;
int a,b;
int main()
{

    ios::sync_with_stdio(false);cin.tie(0);
    cin>>S>>T;
    cin>>a>>b;
    cin>>U;
    if(U==S) --a;else --b;
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
s = list(input())
count = 0

for i, char in enumerate(s):
    if (i+1)%2 == 0:
        if char == 'R':
            count = count + 1
    elif (i+1)%2 == 1:
        if char == 'L':
            count = count + 1

if count == 0:
    print('Yes')
else:
    print('No')


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

int main() {
    map<int,int> m;
    int n;
    cin >> n;
    rep(i,n){
        int l;
        cin >> l;
        m[l]++;
        if(m[l]>=2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9600
N = int(input())
L = list(map(int, input().split()))

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
                    cnt += 1

print(cnt)

Measured memory_bytes: 68136
import std.stdio;
import std.string;
import std.algorithm;
import std.array;
import std.conv;

void main() {
  int[int] data;
  int[int] res;
  bool second_time = false;
  while(true) {
    string line = readln.chomp;
    if (stdin.eof) break;
    if (line.length == 0) {second_time = true; continue;}
    auto i = line.split(",").map!(to!(int)).array;
    if (second_time) {
      if (i[0] in data) res[i[0]] = ++data[i[0]];
    }
    else {      
      if (i[0] in data) ++data[i[0]];
      else data[i[0]] = 1;
    }
  }
  foreach(k; res.keys.sort) {
    writeln(k, " ", res[k]);
  }
}

Measured memory_bytes: 1064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long ;
int main()
{
    int n;
    cin>>n;
    ll ans=0;
    vector<int> a(n+1),b(n);
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n){
        if(a[i]>=b[i]){
            ans+=b[i];
            b[i]=0;
            continue;
        }
        else{
            ans+=a[i];
            b[i]-=a[i];
            if(a[i+1]>=b[i]){
                ans+=b[i];
                a[i+1]-=b[i];
                b[i]=0;
            }
            else{
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 4016
# cf16-finalC - Interpretation
class UnionFind:  # O(α(N))
    def __init__(self, size):  # construct a Union-Find tree (1-idx)
        self.parent = [i for i in range(size + 1)]
        self.rank = [0] * (size + 1)

    def find(self, x):  # find the group (root) of a vertex
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):  # unite two groups
        x, y = self.find(x), self.find(y)
        if x == y:  # in the same group
            return
        # unite a small one to a bigger one to balance trees
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    # Union-Find on spoken languages -> check all langs are in the same group?
    N, M = map(int, input().split())
    A = tuple(tuple(map(int, input().split())) for _ in range(N))
    uf, spoken = UnionFind(M), set()
    for _, *langs in A:
        spoken.update(langs)
        primary = langs[0]
        for l in langs[1:]:
            uf.unite(primary, l)
    cur = uf.find(spoken.pop())  # group of one of spoken languages
    flg = all(uf.find(lang) == cur for lang in spoken)
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 18116
import numpy as np
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
from operator import itemgetter
def resolve():
    N = int(input())
    XY = [[i] + [int(x) for x in input().split()] for i in range(N)]

    G = set()
    for key in [itemgetter(1), itemgetter(2)]:
        XY.sort(key=key)
        for i in range(N - 1):
            i1, x1, y1 = XY[i]
            i2, x2, y2 = XY[i + 1]
            d = min(abs(x1 - x2), abs(y1 - y2))
            G.add((i1, i2, d))    

    A, B, W = zip(*G)
    csr = csr_matrix((W, (A, B)), shape=(N, N))
    mst = minimum_spanning_tree(csr).astype(int)
    print(mst.sum())

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 81228
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	v.push_back(0);
	long long x;
	for(int i=1;i<=n;++i)
	{
		cin>>x;
		v.push_back(x);
		if(i>k)
		{
			if(v[i]>v[i-k])
				cout<<"Yes"<<endl;
			else
				cout<<"No"<<endl;
		}
	}
	return 0;
}

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

int main() {
	int a = 0;
	char s[11];

	cin >> a >> s;

	if (2800 <= a && a < 3200) {
		cout << "red" << endl;
	}
	else if(3200 <= a && a <5000){
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

int main() {
#ifdef WYXLOCAL
	freopen("tmp.in", "r", stdin);
	freopen("tmp.out", "w", stdout);
#endif // WYXLOCAL
	int n, t;
	scanf("%d%d", &n, &t);
	int ans = 0x3f3f3f3f;
	for (int i = 1, x, y; i <= n; ++i) {
		scanf("%d%d", &x, &y);
		if (y <= t && x <= ans) ans = x;
	}	
	if (ans == 0x3f3f3f3f) printf("TLE\n");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, G;
  
  G = 0;
  
  cin >> N;
  
  vector<int> Kazu(N);
  
  for(int i = 0; i < N; i++){
    
    cin >> Kazu.at(i);
    
    if((i + 1) % 2 == 1){
      
      if(Kazu.at(i) % 2 == 1)G++;
        
    }
  }
  
  cout << G << endl;
  
}

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

using namespace std;

int main(){
	char s[105];
	scanf("%s",&s);
	
	
	
	int ans=0;
    for(int i=0;i<105;i++){
		if(s[i]=='C'){
			for(int j=i+1;j<105;j++){
				if(s[j]=='F'){
					ans=1;
				}
			}
		}
	}
	if(ans==0)printf("No\n");
	if(ans==1)printf("Yes\n");
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,c,k = na()
t = []

for i in range(n):
    u = ni()
    t.append(u)

t.sort()

now = t[0]
p = 1
ans = 1

for i in t:
    if i-now > k or p > c:
        p = 2
        now = i
        ans += 1
    else:
        p += 1

print(ans)

Measured memory_bytes: 7384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    int ans=0;
    for(int i=0;i<n;i++){
        int a;scanf("%d",&a);
        while(a%2==0){
            a/=2;
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
using pii = pair<int,int>;

int main() {
    int n,m,a,b,c,scan,cnt=0;
    long long ans=0LL;
	scan=scanf("%d %d",&n,&m);

    auto comp = [](pii x,pii y){
        return x.second < y.second;
    };
    priority_queue<
        pii,vector<pii>,decltype(comp)
    > que(comp);

	for(int i=0; i<n;i++){
		scan=scanf("%d",&a);
        que.push({1,a});
	}
    for(int i=0; i<m;i++){
		scan=scanf("%d %d",&b, &c);
        que.push({b,c});
	}

    while(cnt<n){
        pii tmp = que.top();
        que.pop();
        for(int i=0; i<tmp.first&&cnt!=n; i++){
            ans += tmp.second;
            cnt++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;


using ull = unsigned long long;
int main() {
    ull n, city[5];
    cin>>n;
    for(int i = 0; i < 5; i++) {
        cin>>city[i];
    }
    ull min = *min_element(city, city+5);
    ull res = (n + min - 1) / min + 4;
    cout<<res<<endl;
    return 0;
}

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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;
using ii = pair<int,ll>;

void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}




const int dx[] = {0, -1,1,0,1,-1, 1,-1};
const int dy[] = {1 , 0, 0, -1,1,-1,-1, 1};

const double EPS = 1e-9;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int N = 5e5 + 5;
const ll CONSTANT = 9e18 + 7;





int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // TLE

    int n , w = 0, r = 0;
    string s;
    cin >> n;
    cin >> s;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'W')w++;
        else r++;
    }
    int ans = min(w,r);
    string a = "";
    for(int i = 0; i < r; ++i)
        a += 'R';
    for(int i = 0; i < w; ++i)
        a += 'W';
    int cnt = 0;
    for(int i = 0; i < r; ++i){
        cnt += (s[i] != a[i]);
    }
    ans = min(ans,cnt);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int a; string str;
	cin >> a >> str;
	if( a >= 3200 ) cout << str;
	else cout << "red";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,i,j,k,x,a[100005],f[100005][2];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",a+i);
	sort(a+1,a+1+n);
	i=n,j=1;
	while(1)
	{
		if(j+1>a[i-1])
		{
			k=0;
			for(x=i;j<=a[x];--x)
				++k;
			if(k%2==0||(a[i]-j)%2==1)
				printf("First");
			else
				printf("Second");
			return 0;
		}
		--i,++j;
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if(a1 + a2 + a3 >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9
const int mx = 1e5;
int main(){
  int N, C;
  cin >> N >> C;
  vector<vector<int>> sum(C, vector<int>(mx+5, 0));
  REP(i, N){
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    sum[c][s]++;
    sum[c][t+1]--;
  }
  REP(i, C){
    REP(j, mx+4){
      sum[i][j+1] += sum[i][j];
    }
  }
  int ans = 0;
  REP(i, mx+1){
    int cnt = 0;
    REP(j, C){
      if(sum[j][i]){
        cnt++;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12416
// #pragma warning(disable:4996)
#include <memory.h>
#include <stdio.h>
#include <assert.h>

#include <list>
#include <bitset>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long int64;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int > vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#define ALL(x) (x).begin(), (x).end()
#define CLEAR(x) (x).clear()
#define RESET(x) memset((x), 0, sizeof (x))
#define MP(X,Y) make_pair(X,Y)//NOTES:MP(

#define FOR(i, b, e) for ( int i = (b); i < (e); ++i)
#define RE(i, n) FOR(i, 0, (n))
#define FOREACH(i, x, y) for ( int i = (x); i <= (y); ++i)

const ll maxn = (ll)77777;
const ll maxm = (ll)1e6 + 10;
const ll MOD = 786433;
const ll INF = 1e15;

int fast_read(){ int input; char c=0; while(c<33)c= getchar(); input=0; while(c>33){ input=input*10+c-'0'; c=getchar(); } return input; }

int main() {


	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	string s;
	while (cin >> s) {
		auto p = s.find('C');
		if (p == string::npos) {
			cout << "No" << endl;
			continue;
		}
		if (s.find('F', p) == string::npos) {
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
	}

	// cout << (float)(clock() - start_time)/CLOCKS_PER_SEC << "s" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;

void solve()
{
	int n;
	cin >> n;

	map<string, int> m;
	for(int i = 0; i < n; ++i)
	{
		string s = "";
		cin >> s;
		m[s] = 1;
	}

	cout << m.size() << endl;

}

int main()
{
	solve();

	return 0;
}

Measured memory_bytes: 19260
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		String s=scan.next();
		
		if(n==1) {
			System.out.println(0);
			return;
		}
		//how many west from 0...i
		//how many east from i...n-1
		int[] west=new int[n];
		int[] east=new int[n];
		
		if(s.charAt(0)=='W') west[0]++;
		if(s.charAt(n-1)=='E') east[n-1]++;
		
		for(int i=1;i<n;i++) {
			west[i]=west[i-1];
			if(s.charAt(i)=='W') west[i]++;
		}
		
		for(int i=n-2;i>=0;i--) {
			east[i]=east[i+1];
			if(s.charAt(i)=='E') east[i]++;
		}
//		System.out.println(Arrays.toString(west));
//		System.out.println(Arrays.toString(east));
		
		int res=west[n-1];
		if(n>1) res=Math.min(res,east[1]);
		
		for(int i=1;i<n-1;i++) {
			res=Math.min(res,west[i-1]+east[i+1]);
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 30872
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < ll , ll > ii;

ll n, der[N], mxd[N], mx, x[N], y[N];
vector < ll > g[N];
ii mn = mp(inf, inf);

void dfs(ll node, ll par, ll dr){
	ll of = 0;
	for(ll i = 0; i < g[node].size(); i++)
		if(coc != par){
			dfs(coc, node, dr + 1);
			of++;
		}
	mxd[dr] = max(mxd[dr], of);
	mx = max(mx, dr);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld",&n);
	for(ll i = 1; i < n; i++){
		scanf("%lld %lld",x + i ,y + i);
		g[x[i]].pb(y[i]);
		g[y[i]].pb(x[i]);
	}

	for(ll i = 1; i <= n; i++){
		mx = 0;
		dfs(i, 0, 1);
		// cout << i << " " << mx << endl;
		ll ans = 1;
		for(ll i = 1; i < mx; i++){
			ans *= mxd[i];
			mxd[i] = 0;
		}
		mn = min(mn, mp(mx, ans));
	}
	for(ll i = 1; i < n; i++){
		mx = 0;
		dfs(x[i], y[i], 1);
		dfs(y[i], x[i], 1);
		ll ans = 2;
		// cout << x[i] << " "<< y[i] << " = \n";
		for(ll i = 1; i < mx; i++){
			// cout << i << " " << mxd[i] << endl;
			ans *= mxd[i];
			mxd[i] = 0;
		}
		mn = min(mn, mp(mx, ans));
	}
	printf("%lld %lld\n", mn.st ,mn.nd);
	
	return 0;
}

Measured memory_bytes: 28928
import numpy as np
import itertools

H, W = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in range(H)]
B = [tuple(map(int, input().split())) for _ in range(H)]

D = [[abs(A[h][w] - B[h][w]) for w in range(W)] for h in range(H)]
max_num = 80 * (H + W)
table = np.zeros((H, W, max_num), dtype='bool')
table[0][0][D[0][0]] = True

it = itertools.product(range(H), range(W))
next(it)  # h=w=0 捨てる
for h, w in it:
    d = D[h][w]
    table[h][w][d:] += table[h - 1][w][:max_num - d] + table[h][w - 1][:max_num - d]
    table[h][w][:max_num - d] += table[h - 1][w][d:] + table[h][w - 1][d:]
    table[h][w][d:0:-1] += table[h - 1][w][:d] + table[h][w - 1][:d]

print(np.amin(*np.where(table[H - 1][W - 1])))


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

int main(){
    int N;
    cin >> N;
    int ans = N;
    for(int i = 0; i <= N; ++i){
        int count = 0;
        int tmp = i;
        while(tmp > 0){
            count += tmp % 6;
            tmp /= 6;
        }
        tmp = N - i;
        while(tmp > 0){
            count += tmp % 9;
            tmp /= 9;
        }
        if(ans > count) ans = count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256