akhauriyash/Code-Regression huggingface dataset:
using System;

namespace _0031
{
    class Program
    {
        readonly static int[] weights = {512,256,128,64,32,16,8,4,2,1 };
        readonly static int MAX_NUMBER = 10;

        static void Main(string[] args)
        {
            while (true)
            {
                var input = Console.ReadLine();
                int[] isUsedWeights = new int[MAX_NUMBER];

                if (string.IsNullOrEmpty(input))
                {
                    break;
                }

                var Inputweight = int.Parse(input);

                for (int i = 0; i < MAX_NUMBER; i++)
                {
                       if((Inputweight / weights[i]) == 1 )
                       {
                            isUsedWeights[i] = weights[i];
                       }else
                       {
                            isUsedWeights[i] = 0;
                       }
                       Inputweight = Inputweight % weights[i];
                }
                 Array.Reverse(isUsedWeights);


                 string answer = "";
                for (int i = 0; i < isUsedWeights.Length; i++)
                {
                    if (isUsedWeights[i] != 0)
                    {
                        if (answer == "")
                        {
                            answer += isUsedWeights[i];
                        }
                        else
                        {
                            answer += " " + isUsedWeights[i];
                        }
                    }
                }
                Console.WriteLine(answer);
            }
        }
    }
}

Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

class Combi {
private:
  v(ll) fac, inv, finv;
  void init(int N) {
    fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1;
    for (int i = 2; i < N; 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;
    }
  }
public:
  Combi(int N) : fac(N + 1), inv(N + 1), finv(N + 1) { init(N + 1); }
  ll Cmod(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;
  }
  ll Pmod(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
  }
};

struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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^(int b) {mint res = 1;while(b > 0) {if(b&1) {res = (res*(*this));}*this=(*this)*(*this);b>>=1;} return res;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
typedef vector<mint> vm;
typedef vector<vm> vvm;
  
int main() {
  int N,K;
  cin >> N >> K;
  if(K+1>=N) {
    Combi c(2*N);
    cout << c.Cmod(2*N-1,N-1) << endl;
    return 0;
  }
  Combi c(2*N);
  mint ans = c.Cmod(2*N-1,N-1);
  srep(k,K+1,N) {
    mint x =  c.Cmod(N,k);
    x *= c.Cmod(N-k-1+k,k);
    ans -= x;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 9600
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int maxn = 55;

int c[maxn],d[maxn];
int a[maxn],b[maxn];
int n,m;

int dis(int x,int y){
  return abs(c[x]-a[y])+abs(d[x]-b[y]);
}

int main() {
  //freopen("in.cpp","r",stdin);
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
  for(int i=1;i<=m;i++)cin>>c[i]>>d[i];
  for(int i=1;i<=n;i++){
    int ret=1,d=dis(1,i);
    for(int j=2;j<=m;j++){
      int tmp=dis(j,i);
      if(tmp<d){
        d=tmp,ret=j;
      }
    }
    cout<<ret<<endl;
  }
  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int x,y;
  int ans = 0;
  x = max(a,b);
  y = min(a,b);
  ans += x;
  --x;
  ans += max(x,y);
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n)  for(int i = 0; i < (int)(n); i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; ll K; std::cin >> N >> K;
  std::vector<ll> A(N); 
  rep(i,N) std::cin >> A[i];

  ll l = 0., r = 1e9;
  while( r - l > 1 ) {
    ll mid = (l+r)/2.;
    int cnt = 0;
    rep(i,N) cnt += std::ceil((double)A[i]/mid)-1;
    if ( cnt > K ) l = mid;
    else r = mid;
  }
  std::cout << r << std::endl;
  return 0;
}



Measured memory_bytes: 4688
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll N;

  cin >> N;

  ll ans = N * (N - 1) / 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> a(N);
    cin >> a;
    map<int, int> check;
    for (int i = 0; i < N; i++) check[a[i]]++;
    if (check.size() == 1 && check.begin()->first == 0) {
        cout << "Yes" << endl;
        return 0;
    } else if (N % 3 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (check.size() == 2 && check.begin()->first == 0 && check.begin()->second == N / 3) {
        cout << "Yes" << endl;
        return 0;
    } else if (check.size() == 3 && check.begin()->second == N / 3 && check.rbegin()->second == N / 3) {
        if ((check.begin()->first xor next(check.begin(), 1)->first xor check.rbegin()->first) == 0LL) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 5632
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    ld n;
    cin >> n;
    cout << fixed << setprecision(10) << (n * n * n) / 27.0;
}
/*

*/


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

int main(){
    ll n;
    ll m = pow(10, 16);
    ll tmp;
    cin >> n;
    for(int i=0; i < 5; i++){
        cin >> tmp;
        m = min(m, tmp);
    }
    ll ans = ceil(n / double(m)) + 4;
    cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;

  if (s.size() == 1) {
    cout << 0 << endl;
    return 0;
  }

  // 分割後リバースして比較
  // 100以下なので間に合う
  string s1 = s.substr(0, s.size()/2);
  string s2 = s.substr((s.size() + 1)/2, s.size());
  reverse(s2.begin(), s2.end());

  int count = 0;
  rep(i, s1.size()) {
    if (s1[i] != s2[i]) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let mut a = get!(usize; 5);
    let mut mn = 10;
    let mut mi = 0;
    for i in 0..5 {
        if a[i]%10 != 0 {
            if mn > a[i]%10 {
                mn = a[i]%10;
                mi = i;
            }
        }
    }
    let mut res = 0;
    for i in 0..5 {
        if i == mi {
            res += a[i];
        } else {
            res += if a[i] %10 == 0 {
                a[i]
            } else {
                (a[i]/10+1)*10
            };
        }
    }
    println!("{}", res);

}


Measured memory_bytes: 8572
from collections import deque,defaultdict
import copy

def main():
    from collections import defaultdict
    import copy 
    n,u,v = map(int,input().split())
    u -= 1
    v -= 1
    graph = defaultdict(deque)
    for _ in range(n-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    depth = dfs(graph,u,n)
    # print(depth)
    depth2 = dfs(graph,v,n)
    # print(depth2)
    ans = 0
    ans2 = 10**6
    for i,j in zip(depth,depth2):
        if i < j:
            ans = max(j,ans)
        # elif i == j:
        #     ans2 = min(j,ans2)

    print(ans-1)

def dfs(G,s,n):
    stack = deque([s])
    graph = copy.deepcopy(G)
    depth = [None] * n
    depth[s] = 0
    while stack:
        u = stack[-1]
        if graph[u]:
            v = graph[u].popleft()
            if depth[v] == None:
                depth[v] = depth[u] + 1
                stack.append(v)

        else:
            stack.pop()

    return depth
    

main()

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

class Mondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var list = new List<int>();
        var sum = 0;
        for (int i = 0; i < N; ++i)
        {
            var score = Int32.Parse(Console.ReadLine());
            if (score % 10 != 0) list.Add(score);
            sum += score;
        }
        list = list.OrderBy(x => x).ToList();
        var ans = 0;
        if (sum % 10 != 0) ans = sum;
        else
        {
            if (0<list.Count()) ans = sum - list[0];
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include<stdio.h>

struct Card{
  char suit;
  char value;
  int x;
};

void Bubble(struct Card* , int );
void Selection(struct Card*, int );
void Print(struct Card* , int );

int main(){
  struct Card C1[100], C2[100];
  int n, i;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i ++){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
    C1[i].x = i;
    C2[i] = C1[i];
  }

  Bubble(C1, n);
  Print(C1, n);
  
  Selection(C2, n);
  Print(C2, n);

  return 0;
}

void Bubble(struct Card* A, int n){
  int i, j;
  struct Card tmp;
  for( i = 0; i < n; i++ ){
    for( j = n-1; j > i; j-- ){
      if( A[j-1].value > A[j].value ){
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1]= tmp;
      }
    }
  }
  return;
}

void Selection(struct Card* B, int n){
  int i, j, min;
  struct Card tmp;
  for(i = 0; i < n; i++){
    min = i;
    for(j = i; j < n; j++){
      if(B[j].value < B[min].value){
	min = j;
      }
    }
    if(min != i){
      tmp = B[i];
      B[i] = B[min];
      B[min] = tmp;
    }
  }
  return;
}

void Print(struct Card* array, int n){
  int i, flg=1;
  for(i = 0; i < n; i++){
    if(i > 0) printf(" ");
    printf("%c%c", array[i].suit, array[i].value);
  }
  printf("\n");
  
  for(i = 0; i < n; i++){
    if((array[i].value == array[i+1].value) && (array[i].x > array[i+1].x)){
      flg = 0;
      break;
    }
  }

  if(flg == 1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }
  return;
}

Measured memory_bytes: 612
n = int(input())
raw_a = list(map(int,input().split()))
a = [0] + raw_a + [0]

total = 0
for i in range(n+1):
    total += abs(a[i+1] - a[i])

for i in range(1, n+1):
    print(total - (abs(a[i]-a[i-1]) + abs(a[i+1]-a[i]) - abs(a[i+1]-a[i-1])))

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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 100500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

int dp[2][N], a[N];

void add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
	FREOPEN();
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) scanf("%d ", &a[i]);
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) add(dp[(i - 1) & 1][j], dp[(i - 1) & 1][j - 1]);
		for (int j = 0; j <= k; j++) {
			dp[i & 1][j] = dp[(i - 1) & 1][j];
			if (j - a[i] > 0) dp[i & 1][j] -= dp[(i - 1) & 1][j - a[i] - 1];
			if (dp[i & 1][j] < 0) dp[i & 1][j] += MOD;
		}
	}
	printf("%d", dp[n & 1][k]);
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=1e5+5;
int f[N];
void work()
{
	int n,x;scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(x)f[x-1]++;
		f[x]++;f[x+1]++;
	}
	int ans=0;
	for(int i=0;i<N;i++){
		if(f[i]>ans)ans=f[i];
	}
	printf("%d\n",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int N=1e4+5;

int h,n,a[N],b[N],mem[N];

int dp(int val)
{
    if (val>=h)
    {
        return 0;
    }
    if (mem[val]!=-1)return mem[val];
    int ans=1e9;
    for (int i=0;i<n;i++)
    {
        ans=min(ans,b[i]+dp(val+a[i]));
    }
    return mem[val]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin >> h >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
    }
    cout << dp(0) << endl;
    return 0;
}



Measured memory_bytes: 768
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] astr = str.split(""); //状況に合わせて
        Boolean flag = true;
        int[] in_data = Stream.of(astr).mapToInt(x -> {
            try {
                return Integer.parseInt(x);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();

        int tmp = in_data[0] * in_data[0] * in_data[0];
        System.out.println(tmp);
    }
}

Measured memory_bytes: 28756
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int x,y,z; cin >> x >> y >> z;
  int remain_x = x - z;
  int ans = remain_x / (y + z);
  cout << ans << endl;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
now=0
# alst=[]

arui=ruiseki(a)
brui=ruiseki(b)
# print(brui)
for i in range(len(arui)):
    if arui[i]<=k:
        # print(k-arui[i])
        tmp=bisect.bisect_right(brui,k-arui[i])
        # print(tmp)
        ans=max(ans,i+tmp-1)
print(ans)

Measured memory_bytes: 123036
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n;
    cin>>n;
    vector<PLL> a(n),b(n),c(n); // index -> {value, num of combination}
    rep(i,0,n) cin>>a[i].first;
    rep(i,0,n) cin>>b[i].first;
    rep(i,0,n) cin>>c[i].first;

    sort(begin(a),end(a),greater<PLL>());
    sort(begin(b),end(b),greater<PLL>());
    sort(begin(c),end(c),greater<PLL>());

    rep(i,0,n)
        c[i].second = 1;

    ll k=0;
    rep(i,0,n){
        if(i>0)
           b[i].second = b[i-1].second; 
        while(c[k].first > b[i].first){
            b[i].second += c[k].second;
            k++;
        }
        // printf("b[%d] -> %d\n", i, b[i].second);
    }

    k=0;
    rep(i,0,n){
        if(i>0)
           a[i].second = a[i-1].second; 
        while(b[k].first > a[i].first){
            a[i].second += b[k].second;
            k++;
        }
        // printf("a[%d] -> %d\n", i, a[i].second);
    }

    ll ans=0;
    rep(i,0,n){ ans+= a[i].second;}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5500
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

const int MAXN = 1001024;

vector<ll> prime_factors(ll n) {
    map<ll, ll> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return vector<ll>();
    }
    for(ll i = 2, _n = n; i*i <= _n; ++i) {
        // cerr << "i: " << i << " n: " << n << endl; 
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    vector<ll> ans;
    for(auto x: res) ans.push_back(x.first);
    return ans;
}

int main() {
    ll A, B;
    cin >> A >> B;
    vector<ll> set_a = prime_factors(A);
    set<ll> result;

    sort(set_a.begin(), set_a.end());
    // for(auto x: set_a) cerr << x << " "; cout << endl;
    // sort(set_b.begin(), set_b.end());

    ll ans = 1;
    for(auto x: set_a) {
        if(x > B) break;
        if(B%x==0){
            ans++;
            B /= x;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def mi(): return map(int, input().split())


def li(): return list(mi())


def li_(): return [int(x) - 1 for x in input().split()]


def lin(n: int): return [input() for _ in range(n)]


def llin(n: int): return [li() for _ in range(n)]


def llin_(n: int): return [li_() for _ in range(n)]


def lli(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def f(): return float(input())


def s(): return input().replace('\n', '')


def main():
    N, K = mi()
    h = li()
    dp = [0] * N
    dp[1] = abs(h[0]-h[1])
    for i in range(2, N):
        dp[i] = min((dp[i-j]+abs(h[i-j]-h[i])
                     for j in range(1, min(K+1, i+1))))
    print(dp[N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 53136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int ti = clock();
    int D; cin >> D;
    vector<ll> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(i, D)rep(j, 26) cin >> s[i][j];
    vector<ll> t(D);
    rep(i, D) t[i] = 26-i%26;
    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t_ans(ALL(t));
    for (int d = 1; d <= D; d++) {
        for (int i = 1; i <= 26; i++) {
            if (t[d-1] == i) {
                ans += s[d-1][i-1];
                last[i-1] = d;
            }
            else {
                ans -= c[i-1]*(d-last[i-1]);
            }
        }
    }
    ll tmp;
    while ((double)(clock() - ti)/CLOCKS_PER_SEC <= 1.9) {
        t[rand()%365] = rand()%26 + 1;
        last.clear();
        last.resize(26);
        tmp = 0;
        for (int d = 1; d <= D; d++) {
            for (int i = 1; i <= 26; i++) {
                if (t[d-1] == i) {
                    tmp += s[d-1][i-1];
                    last[i-1] = d;
                }
                else {
                    tmp -= c[i-1]*(d-last[i-1]);
                }
            }
        }
        if (tmp > ans) {
            ans = tmp;
            swap(t_ans, t);
            t.clear();
            t.resize(D);
            rep(i, D) t[i] = t_ans[i];
        }
    }
    rep(i, D) cout << t_ans[i] << endl;
}

Measured memory_bytes: 3736
while 1:
	(a,b,c) = map(int,raw_input().split())
	if a == -1 and b == -1 and c == -1:
		break
	if a == -1 or b == -1:
		print 'F'
	elif a+b >= 80:
		print 'A'
	elif a+b >= 65:
		print 'B'
	elif a+b >= 50:
		print 'C'
	elif a+b >= 30:
		if c >= 50:
			print 'C'
		else:
			print 'D'
	else:
		print 'F'

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

int main(){
    int n,A[21],B[21],C[21],ans=0,p;
    cin>>n;
    REP(i,n) cin>>A[i];
    REP(i,n) cin>>B[i];
    REP(i,n-1) cin>>C[i];
    REP(i,n){
        p=A[i]-1;
        ans+=B[p];
        if(i>0 && A[i]-A[i-1]==1) ans+=C[p-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            long N = long.Parse (Console.ReadLine ());
            var p = PrimeFactors (N);

            int ans = 0;
            for (int i = 0; i < p.Count; i++)
            {
                int temp = p[i].Item2;

                for (int j = 1; true; j++)
                {
                    temp -= j;
                    if (temp < 0) break;
                    ans += 1;
                }
            }

            Console.WriteLine (ans);
        }

    }

    class MyLibrary
    {

        // 自作の関数

        public static List<Tuple<long, int>> PrimeFactors (long n)
        {
            var res = new List<Tuple<long, int>> ();
            var count = 0;
            for (long x = 2; x * x <= n; x++)
            {
                count = 0;
                while (n % x == 0)
                {
                    n /= x;
                    count++;
                }
                if (count > 0) res.Add (Tuple.Create (x, count));
            }
            if (n != 1) res.Add (Tuple.Create (n, 1));
            return res;
        }
    }
}

Measured memory_bytes: 27836
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
    int N, T;
    double A;
    cin >> N >> T >> A;
    vector<pair<double, int>> H(N);
    for (int i = 0; i < N; i++)
    {
        double tmp;
        cin >> tmp;
        double n = (T - tmp * 0.006) - A;
        H[i].first = abs(n);
        H[i].second = i;
    }
    sort(H.begin(), H.end());
    cout << H.front().second + 1 << endl;
    return 0;
}

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

#define int long long
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; }

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

	int p[200010];
	for(int i = 0;i < n;i++) cin >> p[i];

	int ma = INT_MAX;
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(p[i] < ma){
			ma = p[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	string s;
	cin >> s;
	int n = s.size();

	int ones = 0;
	rep(i, n) {
		if (s[i] == '1') ones++;
	}
	int mn = min(ones, n - ones);
	cout << mn * 2 << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int dp[3001][3001];

string common(string &str1,string &str2,int l)
{
    string str;
    // ye common subsequence hoga....
    // aur isse hame print karana hai..
    int i,j;
    i=j=0;
    while(l)
    {
        if(str1[i]==str2[j])
        {
            str.pb(str1[i]);
            i++;
            j++;
            l--;
        }
        else
        {
            int option1=dp[i][j+1];
            int option2=dp[i+1][j];
            if(option1>=option2)
            {
                j++;
            }
            else
            {
                i++;
            }
        }
    }
    return str;
}

int length(int i,int j,string &str1,string &str2)
{
    if(i>=str1.length() || j>=str2.length())
    {
        return 0;
    }
    else
    {
        if(dp[i][j]!=-1)
        {
            return dp[i][j];
        }
        
        if(str1[i]==str2[j])
        {
            return dp[i][j]=1+length(i+1,j+1,str1,str2);
        }
        else
        {
            int option1=length(i,j+1,str1,str2);
            int option2=length(i+1,j,str1,str2);
            
            return dp[i][j]=max(option1,option2);
        }
    }
}

string solve(string &str1,string &str2)
{
    memset(dp,-1,sizeof(dp));
    int l=length(0,0,str1,str2); // ye function lcs ki length ko return kr dega...
    return common(str1,str2,l);
}

int main()
{
    string str1,str2;
    cin>>str1>>str2;
    cout<<solve(str1,str2);
    return 0;
}

Measured memory_bytes: 35968
w, h, n = gets.split.map(&:to_i)

ary = h.times.map { [false] * w }

n.times do |i|
  x, y, a = gets.split.map(&:to_i)
  if a == 1
    0.upto(h - 1) do |i|
      0.upto(x - 1) do |j|
        ary[i][j] = true
      end
    end
  elsif a == 2
    0.upto(h - 1) do |i|
      x.upto(w - 1) do |j|
        ary[i][j] = true
      end
    end
  elsif a == 3
    0.upto(y - 1) do |i|
      0.upto(w - 1) do |j|
        ary[i][j] = true
      end
    end
  elsif a == 4
    y.upto(h - 1) do |i|
      0.upto(w - 1) do |j|
        ary[i][j] = true
      end
    end
  else
    raise "Invalid a = " + a
  end
end

count = 0
h.times do |i|
  w.times do |j|
    count += 1 if ary[i][j] == false
  end
end

puts count


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mem(x,n) memset(x,n,sizeof(x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=(l).begin();it!=(l).end();it++)
#define pnl printf("\n")
#define endl '\n'
#define len(x) (x).length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
const double EPS=1e-10;
//const double PI=acos(-1.0);
const int INF=1<<30;
const LL LLINF=1ll<<60;
const int MOD=1e9+7;
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};

void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }

/***********************************\
     _____ _             _
    /  __ \ |           (_)
    | /  \/ | __ _ _ __  _  ___
    | |   | |/ _` | '_ \| |/ _ \
    | \__/\ | (_| | |_) | |  __/
     \____/_|\__,_| .__/|_|\___|
                  | |
                  |_|
\***********************************/

int main(){
	string str;
	cin>>str;
	str[0]='2';
	str[1]='0';
	str[2]='1';
	str[3]='8';
	cout<<str<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, a, b = list(map(int, readline().split()))
    if b - a <= 0:
        print("delicious")
    elif 0 < b - a <= x:
        print("safe")
    else:
        print("dangerous")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main implements Comparator<Main> {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.nextLine()) ;

		for(int i = 0;i < count ;i++){

			String[] nums = sc.nextLine().split(" ");
			String[] colors = sc.nextLine().split(" ");

			ArrayList<Main> tehuda = new ArrayList<Main>();

			for(int j = 0;j < nums.length; j++ ) {
				Main card = new Main(Integer.parseInt(nums[j]), colors[j]);
				tehuda.add(card);
			}
			Collections.sort(tehuda, new Main());


			ArrayList<Integer> cardSet = new ArrayList<Integer>();
			ArrayList<ArrayList<Integer>> cSetList = new ArrayList<ArrayList<Integer>>();


			String checkColor = tehuda.get(0).getColor();
			cardSet.add(tehuda.get(0).getNum());
			
			for(int j = 1;j < tehuda.size();j++) {
				if(!(tehuda.get(j).getColor().equals(checkColor))) {
					cSetList.add(cardSet);
					cardSet = new ArrayList<Integer>();
					checkColor = tehuda.get(j).getColor();
				}

				cardSet.add(tehuda.get(j).getNum());
				if(j == tehuda.size() - 1) {
					cSetList.add(cardSet);
				}


			}

			int point = 0;


			for(int j = 0;j < cSetList.size(); j++) {
				

				//???????????????
				if(cSetList.get(j).size() >= 6) {
					if(cSetList.get(j).get(0)  == cSetList.get(j).get(1) && cSetList.get(j).get(2) == cSetList.get(j).get(3) && cSetList.get(j).get(4) == cSetList.get(j).get(5) ){
						point += 2;
					}
				}
				if(cSetList.get(j).size() == 9) {
					if(cSetList.get(j).get(3)  == cSetList.get(j).get(4) && cSetList.get(j).get(5) == cSetList.get(j).get(6) && cSetList.get(j).get(7) == cSetList.get(j).get(8) ){
						point += 2;
					}
				}

				for(int y = 0;y < cSetList.get(j).size() -2;y++){
					int num1 = cSetList.get(j).get(y);
					int num2 = cSetList.get(j).get(y + 1);
					int num3 = cSetList.get(j).get(y + 2);
					if((num1 + 1 == num2 && num1 + 2 == num3 ) || (num1 == num2 && num1 == num3)) {
						point++;
						y += 2;
					}
				}


			}
			if(point == 3) {
				System.out.println("1");
			} else {
				System.out.println("0");
			}
		}
		sc.close();

	}

	private int num;
	private String color;

	//??????????????????????????????
	Main (int num, String color) {
		this.num = num;
		this.color = color;
	}

	Main() {
	}

	public int getNum() {
		return this.num;
	}

	public String getColor () {
		return this.color;
	}

	@Override
	public  int compare(Main card1 ,Main card2) {
		int num1 = card1.getNum();
		int num2 = card2.getNum();
		String color1 = card1.getColor();
		String color2 = card2.getColor();

		if(color1.compareTo(color2) > 0 && num1 > num2) {
			return 2;
		} else if (color1.compareTo(color2) > 0) {
			return 1;
		} else if (color1.compareTo(color2) == 0 && num1 > num2) {
			return 0;
		} else if (color1.compareTo(color2) == 0 ) {
			return -1;
		} else if (color1.compareTo(color2) < 0 && num1 > num2) {
			return -2;
		} else {
			return -3;
		}

	}


}

Measured memory_bytes: 26492
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

#define INF (1<<31-1)
#define ll long long


int main(){

	int H, W, h, w;

	cin >> H >> W >> h >> w;

	if (W%w == 0 && H%h == 0){ cout << "No" << endl; return 0; }


	cout << "Yes" << endl;
	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			if (j%w != 0 || i%h != 0) cout << "1000 ";
			else cout << (-(h*w - 1) * 1000 - 1) << " ";
		}
		cout << endl;
	}


	return 0;
}


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

int main(){

    ll x,y;
    cin >> x >> y;

    int ans=1;
    while(1){
        if(y/2<x){
            break;
        }
        if(x*2<=y){
            x*=2;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const int INF=1e9+7;
int main(){
    LLI m[2000][2000]={};
    LLI n,x; cin>>n>>x;
    FOR(i,0,n) cin>>m[0][i];
    LLI ans=1e18;
    FOR(i,0,n){
        LLI sum=0;
        FOR(j,0,n){
            if(i) m[i][j]=min(m[i-1][j],m[0][(i+j)%n]);
            sum+=m[i][j];
        }
        ans=min(ans,sum+i*x);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
ll abs(ll a,ll b){
    return(a>b?a-b:b-a);
}

int main(){
    int n;
    cin >> n;
    if(n<1200){
        cout << "ABC" << endl;
    }else if(n>=1200&&n<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}


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

using namespace std;

int main(){

int s;

cin>>s;

string str =to_string(s);

if(str[0]=='7'||str[1]=='7'||str[2]=='7'){

 cout<<"Yes"<<endl;

}

else cout<<"No"<<endl;

return 0;

}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// 復習場所

const int MAX = 300000;
ll 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;
    }
}

// 二項計算 nCk
ll 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 h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    COMinit();
    rep(i, w-b){
        ans = (ans + COM(h+b-a-1+i, b+i) * COM(a+w-b-2-i, a-1)) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
 
 char S[3];
 int b;

 int main(){ 

  cin >> S[1] >> S[2] >> S[3];


 b=0;

 for (int i=1; i<=3; i++){
 if (S[i] == '1') b++;
 } 

  cout << b <<endl;


 return 0;
}


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

using namespace std;

template<typename Weight>
struct Dinic {
    struct Edge {
        int src, dst, rev;
        Weight weight;
        Edge(int f, int t, Weight cap, int rev = 0) :
            src(f), dst(t), rev(rev), weight(cap) {}
    };

    int n;
    vector<vector<Edge>> adj;
    const Weight INF;

    Dinic(int _n, Weight inf = numeric_limits<Weight>::max() / 10)
        : n(_n), adj(n), INF(inf) {}

    void add_edge(const int src, const int dst, const Weight cap) {
        adj[src].emplace_back(Edge(src, dst, cap, adj[dst].size()));
        adj[dst].emplace_back(Edge(dst, src, 0, adj[src].size() - 1));
    }

    Weight MaximumFlow(const int s, const int t) {
        Weight flow = 0;
        vector<int> level(n);
        vector<size_t> iter(n);
        while(true) {
            fill(level.begin(), level.end(), -1);
            fill(iter.begin(), iter.end(), 0);
            Bfs(s, level);
            if(level[t] == -1) break;
            for (Weight f = 0; (f = Dfs(s, t, INF, level, iter)) > 0; )
                flow += f;
        }
        return flow;
    }

    void Bfs(const int s, vector<int> &level){
        queue<int> que;
        for (level[s] = 0, que.push(s); !que.empty(); ) {
            const int v = que.front(); que.pop();
            for (const auto &e : adj[v])
                if(0 < e.weight && level[e.dst] == -1){
                    level[e.dst] = level[v] + 1;
                    que.push(e.dst);
                }
        }
    }

    Weight Dfs(int v, int t, Weight flow, vector<int> &level, vector<size_t> &iter) {
        if(v == t) return flow;
        for ( ; iter[v] < adj[v].size(); ++iter[v]) {
            Edge &e = adj[v][iter[v]];

            if(0 < e.weight && level[v] < level[e.dst]){
                Weight d = Dfs(e.dst, t, min(flow, e.weight), level, iter);
                if(0 < d){
                    e.weight -= d;
                    adj[e.dst][e.rev].weight += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

int Solve() {
    int h, w;
    cin >> h >> w;

    vector<string> hasu(h);
    for (auto &&x : hasu) cin >> x;

    const int s = h + w, t = h + w + 1;
    Dinic<int> g(h + w + 2);

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (hasu[i][j] == 'o') {
                g.add_edge(i, j + h, 1);
                g.add_edge(j + h, i, 1);
            }
            else if (hasu[i][j] == 'S') {
                g.add_edge(s, i, g.INF);
                g.add_edge(s, j + h, g.INF);
            }
            else if (hasu[i][j] == 'T') {
                g.add_edge(i, t, g.INF);
                g.add_edge(j + h, t, g.INF);
            }
        }
    }

    int res = g.MaximumFlow(s, t);
    return (res < g.INF ? res : -1);
}

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

    cout << Solve() << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
ll INF = (1LL << 62);

bool can(ll bit) { return bit < INF; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  set<int> s;
  for (int i = 0; i < 50; i++)
    s.insert(i + 1);
  ll ans = INF;
  for (int loop = 50; loop >= 0; loop--) {
    ll p[51][51];
    for (int i = 0; i <= 50; i++)
      for (int j = 0; j <= 50; j++)
        p[i][j] = INF;
    for (int i = 0; i <= 50; i++) {
      for (int j = 0; j < i; j++)
        for (auto &k : s) {
          if (i % k == j)
            p[i][j] = min(p[i][j], 1LL << k);
        }
      p[i][i] = 0;
    }
    for (int k = 0; k <= 50; k++) {
      for (int i = 0; i <= 50; i++) {
        for (int j = 0; j <= 50; j++) {
          p[i][j] = min(p[i][j], p[i][k] | p[k][j]);
        }
      }
    }
    ll subans = 0;
    for (int i = 0; i < n; i++)
      subans |= p[a[i]][b[i]];
    if (!can(subans)) {
      if (loop == 50) {
        cout << -1 << endl;
        return 0;
      } else {
        s.insert(loop + 1);
      }
    }
    ans = min(ans, subans);

    s.erase(loop);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384