akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// 別の書き方を使ってみる

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n, q;
int cnts[max_n];

int hd[max_n]; // n : 頂点数
int nxt[2*max_n], to[2*max_n]; // 2*(n-1)+1 : 辺の個数+1
int edge_cnt;
inline void add_edge(const int u, const int v) { // u to v
    edge_cnt++; // 辺が1つ増える
    to[edge_cnt] = v; // edge_cnt本目の辺の行き先はv
    nxt[edge_cnt] = hd[u]; // edge_cnt本目の辺の次に見る(uから出る)辺は、はじめに見ていた(uから出る)辺であるhd[u]本目の辺
    hd[u] = edge_cnt; // 新しくはじめに見る(uから出る)辺はedge_cnt本目の辺
}

void dfs(const int cur = 0, const int parent = -1, const int cnt = 0)
{
    cnts[cur] += cnt;
    for (int e = hd[cur]; e > 0; e = nxt[e]) {
       const int child = to[e];
       if (child == parent) { continue; }
       dfs(child, cur, cnts[cur]);
   }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(a,b);
        add_edge(b,a);
    }
    rep(j, q)
    {
        int p,x;
        cin >> p >> x;
        p--;
        cnts[p] += x;
    }

    // 集計
    dfs();

    rep(i, n)
    {
        cout << cnts[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 23840
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;
 
#ifdef ONLINE_JUDGE
#define whatis(x) ;
#endif
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b;
    sc(a,b);
    cout << max(0,a-2*b);
}



Measured memory_bytes: 764
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

int main() {
    string S, T;//Sの中にT
    cin >> S >> T;
    bool ans = false;
    ll n = 0;
    ll s = S.size(), t = T.size();
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());
    if (s < t)ans = false;
    else {
        rep(i, s - t + 1) {
            bool ok = true;
            rep(j, t) {
                if (S[i + j] != '?') {
                    if (T[j] != S[i + j]) {
                        ok = false;
                    }
                                            
                }
            }
            if (ok) {
                rep(k, t) {
                    S[i + k] = T[k];
                }
                ans = true;
                break;
            }
        }
        rep(i, s) {
            if (S[i] == '?')S[i] = 'a';
        }
        reverse(all(S));
    }
    if (ans)cout << S << endl;
    else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    n = int(stdin.readline().rstrip())
    ps = [int(x) for x in stdin.readline().rstrip().split()]
    x = [(p1, p2, p3) for p1, p2, p3 in [ps[i: i + 3] for i in range(n - 2)] if p1 < p2 <= p3 or p3 < p2 <= p1]
    print(len(x))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
require 'set'; require 'prime'
INF=Float::INFINITY
n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)

mini = INF
ans = []
n.times do |i|
  if p[i] <= mini
    ans.push(i + 1)
    mini= p[i]
  end
end

puts ans.count





Measured memory_bytes: 18496
N = int(input())
s = input()

def next(previous, myself, ans):
    if myself == "S":
        if previous == "S":
            if ans == "o":
                return "S"
            else:
                return "W"
        else:
            if ans == "o":
                return "W"
            else:
                return "S"
    else:
        if previous == "S":
            if ans == "o":
                return "W"
            else:
                return "S"
        else:
            if ans == "o":
                return "S"
            else:
                return "W"


ret = "SS"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0] and next(ret[-1], ret[0], s[0]) == ret[1]:
    print(ret)
    quit()

ret = "SW"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0] and next(ret[-1], ret[0], s[0]) == ret[1]:
    print(ret)
    quit()

ret = "WS"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0] and next(ret[-1], ret[0], s[0]) == ret[1]:
    print(ret)
    quit()

ret = "WW"
for i in range(len(s))[1:-1]:
    ret += next(ret[i - 1], ret[i], s[i])
if next(ret[-2], ret[-1], s[-1]) == ret[0] and next(ret[-1], ret[0], s[0]) == ret[1]:
    print(ret)
    quit()

print(-1)

Measured memory_bytes: 3572
/*****************************************
Author: lizi
Email: lzy960601@outlook.com
*****************************************/
  
#include<bits/stdc++.h>
  
using namespace std;
  
const double eps=1e-10;
const double pi=3.1415926535897932384626433832795;
const double eln=2.718281828459045235360287471352;
  
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr(x) printf("Case %d: ",x)
#define prn(x) printf("Case %d:\n",x)
#define prr(x) printf("Case #%d: ",x)
#define prrn(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))
#define fi first
#define se second
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int maxn=100005;
LL a[maxn],ans1,ans2,b[maxn];
int n;

bool cmp1(LL x, LL y){return x<y;}
bool cmp2(LL x, LL y){return x>y;}

int main()
{
    scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    int bg,ed,pos,cnt;
    sort(a+1,a+n+1,cmp1);
    bg=2;ed=n;pos=(n+1)>>1;b[pos]=a[1];cnt=0;
    while(bg<=ed)
    {
        cnt ++;
        if(cnt&1)b[pos+cnt]=a[ed--];else b[pos+cnt]=a[bg++];
        if(bg>ed)break;
        if(cnt&1)b[pos-cnt]=a[ed--];else b[pos-cnt]=a[bg++];
    }
    for(int i=2;i<=n;i++)ans1+=abs(b[i]-b[i-1]);
    sort(a+1,a+n+1,cmp2);
    bg=2;ed=n;pos=(n+1)>>1;b[pos]=a[1];cnt=0;
    while(bg<=ed)
    {
        cnt ++;
        if(cnt&1)b[pos+cnt]=a[ed--];else b[pos+cnt]=a[bg++];
        if(bg>ed)break;
        if(cnt&1)b[pos-cnt]=a[ed--];else b[pos-cnt]=a[bg++];
    }
    for(int i=2;i<=n;i++)ans2+=abs(b[i]-b[i-1]);
    printf("%lld\n",max(ans1,ans2));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define mll map<ll,ll>
#define vli vector<pair<ll,int>>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

vector<ll> parent, rak;

void make_set(int f){
    fo(i,f+1)parent.pb(i);
    rak.assign(f+1,1);
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

ll union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rak[a]+=rak[b];
        return (rak[a]-rak[b])*(rak[b]);
    }
    return 0;
}

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ld kv;
ll t,n,x,y,h,k,z,p,q,w;
string s;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n;
    fo(i,n){
        cin>>x;
        h=__gcd(h,x);
    }
    cout<<h;
    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  string ans = "WA";
  if (s.front() == 'A' && islower(s[1]) && islower(s.back())) {
    auto t = s.substr(2, s.size() - 3);
    auto pos = t.find('C');
    if (pos != string::npos && t.find('C', pos + 1) == string::npos) {
      ans = "AC";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){
  int x,y;
  tie(x,y) = frm;
  set<pii> se;
  if(x-1 >= 0)se.insert(pii(x-1,y));
  if(x+1 < n)se.insert(pii(x+1,y));
  if(y-1 >= 0)se.insert(pii(x,y-1));
  if(y+1 < m)se.insert(pii(x,y+1));
  for(auto t:se){
    int tx,ty;
    tie(tx,ty) = t;
    if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){
      table.at(tx).at(ty) = table.at(x).at(y) + 1;
      ans = max(ans,table.at(tx).at(ty));
      hukasa(s,table,ans,t,n,m);
      table.at(tx).at(ty) = -1;
    }
  }
}
void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(pii(cost.at(frm),frm));
  vector<bool> kakutei(n,false);
  while(!q.empty()){
    pii now = q.top();
    q.pop();
    int n1,n2;
    tie(n1,n2) = now;
    if(kakutei.at(n2))continue;
    kakutei.at(n2) = true;
    for(auto t:g.at(n2)){
      int tx,ty;
      tie(tx,ty) = t;
      if(cost.at(tx) > n1 + ty){
        cost.at(tx) = n1 + ty;
        q.push(pii(cost.at(tx),tx));
      }
    }
  }
}
int main(){
  char c;
  cin >> c;
  if(c - 'a' >= 0)cout << 'a' << endl;
  else cout << 'A' << endl;
}

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

typedef long long ll;
typedef pair <int, int> pii;

const int N = 2e5 + 5, mod = 998244353;

int fact[N], rev[N];

int mult(int a, int b) {
	return (1LL * a * b) % mod;
}

int pw(int a, int b) {
	if(!b)
		return 1;
	int ans = pw(a, b / 2);
	ans = mult(ans, ans);
	if(b & 1)
		ans = mult(ans, a);
	return ans;
}

void prep() {
	fact[0] = 1;
	for (int i = 1; i < N; i++)
		fact[i] = mult(fact[i - 1], i);
	rev[N - 1] = pw(fact[N - 1], mod - 2);
	for (int i = N - 2; ~i; i--)
		rev[i] = mult(rev[i + 1], i + 1);
}

int sum(int a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
	if(a < 0)
		a += mod;
	return a;
}

int c(int n, int k) {
	if(k > n)
		return 0;
	return mult(fact[n], mult(rev[k], rev[n - k]));
}

int n, m, k;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	prep();
	cin >> n >> m >> k;
	int ans = 0;
	for (int i = 0; i <= k; i++)
		ans = sum(ans, mult(m, mult(pw(m - 1, n - 1 - i), c(n - 1, i))));
	cout << ans << "\n";
}


Measured memory_bytes: 5164
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String  N = sc.next();

	boolean ch =false;
		for(int i=0; i<3; i++){
		if(N.charAt(i)== '7'){
			ch=true;
			break;
    }
    }
	if(ch){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
}
}

Measured memory_bytes: 35564
use std::io;

fn main() {
    loop {
        let (m, f, r) = input();
        if (m, f, r) == (-1, -1, -1){
            break;
        }
        if m == -1 || f == -1{
            println!("F");
        }
        else if m + f >= 80{
            println!("A");
        }
        else if m + f >= 65 && m + f < 80{
            println!("B");
        }
        else if m + f >= 50 && m + f < 65{
            println!("C");
        }
        else if m + f >= 30 && m + f < 50{
            if r >= 50{
                println!("C");
            }
            else {
                println!("D");
            }
        }
        else if m + f < 30{
            println!("F");
        }
    }
}

fn input() -> (i64, i64, i64) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();

    let m: i64 = iter.next().unwrap().parse().unwrap();
    let f: i64 = iter.next().unwrap().parse().unwrap();
    let r: i64 = iter.next().unwrap().parse().unwrap();

    (m, f, r)
}


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

int main() {
  int w,h,n;
  cin>>w>>h>>n;
  int a=0;
  int b=w;
  int c=0;
  int d=w;
  std::vector<int> x(n),y(n),j(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>j[i];
    if(j[i]==1)a=max(x[i],a);
    if(j[i]==2)b=min(x[i],b);
    if(j[i]==3)c=max(y[i],c);
    if(j[i]==4)d=min(y[i],d);
  }
  cout<<max(b-a,0)*max(d-c,0)<<endl;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

vector<ll> convertBase(ll n, ll b) {
  vector<ll> res;
  ll _b = abs(b);

  while (n != 0) {
    ll x = n % _b;
    if (x < 0) x += _b;
    res.eb(x);
    n = (n - x) / b;
  }
  if (res.size() == 0) res.eb(0);
  reverse(all(res));

  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> res = convertBase(n, -2);

  rep(i, res.size()) cout << res[i];
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long n=Long.parseLong(scan.next());
		long min=Long.MAX_VALUE;
		for (int i=0;i<5;++i) {
			min=Math.min(min, Long.parseLong(scan.next()));
		}
		System.out.print((long)Math.ceil((double)n/min)+4);
	
}
}
//end


Measured memory_bytes: 21844
import Control.Monad
import Control.Applicative
import Data.List

data Dice = Dice{tp::Int, fr::Int, rt::Int, lt::Int, bk::Int, bm::Int} deriving (Show, Eq)

roll :: Dice -> Char -> Dice
roll (Dice tp fr rt lt bk bm) dir
  | dir == 'N' = Dice fr bm rt lt tp bk
  | dir == 'S' = Dice bk tp rt lt bm fr
  | dir == 'E' = Dice lt fr tp bm bk rt
  | dir == 'W' = Dice rt fr bm tp bk lt
  | otherwise = Dice tp fr rt lt bk bm

rolls :: Dice -> String -> Dice
rolls d s = foldl roll d s

initDice :: [Int] -> Dice
initDice (tp:fr:rt:lt:bk:bm:_) = Dice tp fr rt lt bk bm

setDice :: Dice -> Int -> Int -> [Dice]
setDice d t f = d2s
  where
    d1s = filter (\x -> tp x == t) $ scanl roll d "NENEN"
    d2s = (nub . concat) $ do
      d1 <- d1s
      return (filter (\x -> fr x == f) $ scanl rolls d1 ["NES","NES","NES"])

main = do
  xs <- map read . words <$> getLine :: IO [Int]
  ys <- map read . words <$> getLine :: IO [Int]
  putStrLn $ solve xs ys

solve :: [Int] -> [Int] -> String
solve xs ys
  | d1 `elem` d2s = "Yes"
  | otherwise = "No"
  where d1 = initDice xs
        d2s = setDice (initDice ys) (tp d1) (fr d1)

Measured memory_bytes: 3740
/**
 * @param input string[]
 */
function Main(input) {
  const line0 = input[0].split(' ').map(Number);
  const line1 = input[1].split(' ').map(Number);

  const N = line0[0];
  const K = line0[1];

  // 相手の手に応じた勝ったときのスコア
  const scores = {
    r: line1[2], // パーで勝つ
    s: line1[0], // グーで勝つ
    p: line1[1], // チョキで勝つ
  };

  const T = input[2];

  var i, j, equals, current, maxScore = 0;
  for (i = 0; i < K; i++) {
    equals = 1;
    for (j = i; j < N; j += K) {
      current = T[j];
      // 同じ手が連続する場合
      if (current === T[j + K]) {
        equals++;
      } else {
        maxScore += scores[current] * Math.ceil(equals / 2);
        equals = 1;
      }
    }
  }

  console.log(maxScore);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n'));

Measured memory_bytes: 21192
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;


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

    vector<int> p(N);

    int counter = 0;
    for (int i = 1; i <= N; ++i) {
        int num;
        cin >> num;
        if (i != num) {
            ++counter;
        }
    }

    if (counter > 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool X[100001];
long ans[100001];
void Calc(){
	int N = rei();
	int M = rei();
	for(int i=0;i<M;i++){
		int x = rei();
		X[x] = true;
	}
	ans[0] = 1;
	if(X[1]){
		ans[1] = 0;
	}
	else{
		ans[1] = 1;
	}
	for(int i=2;i<=N;i++){
		if(X[i]){
			ans[i] = 0;
		}
		else{
			ans[i] = ans[i-1] + ans[i-2];
			ans[i] %= mod;
		}
	}
	cout << ans[N] << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

int N;
string S,T;

int main(void){
    cin >> N >> S>>T;
    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    vll A(N+1);
    vll B(M+1);
    A[0]=0;
    B[0]=0;
    for(int i=1;i<N+1;i++){
        cin>>A[i];
    }
    for(int i=1;i<M+1;i++){
        cin>>B[i];
    }
    for(int i=1;i<N+1;i++){
        A[i]=A[i-1]+A[i];
    }
    for(int i=1;i<M+1;i++){
        B[i]=B[i-1]+B[i];
    }
    ll ans=0;
    for(int i=0;i<N+1;i++){
        ll r=K-A[i];
        if(r<0)continue;
        ll x=upper_bound(ALL(B),r)-B.begin();
        x--;
        ans=max(ans,i+x);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6352
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 3005;
const int mod = 1e9+7;

int n,m,a[maxn],dp[maxn][maxn];
char str[maxn];int s[maxn];
int main()
{
	#ifdef Amberframe
		freopen("arc065f.in","r",stdin);
		freopen("arc065f.out","w",stdout);
	#endif
	scanf("%d %d %s",&n,&m,str+1);
	for (int i=1;i<=n;i++)
		s[i]=s[i-1]+(str[i]=='1'),a[i]=i;
	for (int l,r,i=1;i<=m;i++)
		scanf("%d %d",&l,&r),a[l]=max(a[l],r);
	for (int i=1;i<=n;i++)
		a[i]=max(a[i-1],a[i]);
		
	dp[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		int o=s[a[i]]-s[a[i-1]];
		for (int j=0;j<=s[a[i]];j++)
		if (dp[i-1][j]) {
			if (a[i]-i>=j+o) (dp[i][j+o]+=dp[i-1][j])%=mod;
			if (a[i]-i>=j+o-1) (dp[i][j+o-1]+=dp[i-1][j])%=mod;
		}
	}
	printf("%d",dp[n][0]);
	return 0;
}

Measured memory_bytes: 33920
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    ll a,b;
    ll v,w;
    cin>>a>>v;
    cin>>b>>w;
    ll t;
    cin>>t;
    if(v<=w){
        cout<<"NO"<<endl;
    }
    else{
        ll turn = (abs(b-a)+v-w-1)/(v-w);
        if(turn<=t){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }
    
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main() {
    string o,e;
    cin>>o>>e;
    string ans;
    rep(i,e.size()){
        ans+=o.at(i);
        ans+=e.at(i);
    }
    if(o.size()>e.size()) ans+=o.at(o.size()-1);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
// #define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

int main(){
  cin >> s >> n;
  map<char,vi > mp;
  map<string,int> test;
  vs vec;
  rep(i,0,s.sz)mp[s[i]].pb(i);
  int p = 0;
  rep(i,0,mp.sz){
    if(p > 5)break;
    rep(j,0,mp[char(i+'a')].sz){
      t = "";
      rep(k,mp[char(i+'a')][j],s.sz){
        t += s[k];
        if(t.sz > 5)break;
        if(test[t] != 0)continue;
        test[t]++;
        vec.pb(t);
      }
      p++;
    }
  }
  sort(all(vec));
  print(vec[n-1]);
  return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
sort_A=sorted(A)
max_A=sort_A[-1]
answer=[]
half_A=max_A//2
number=pow(10,9)
answer=0
for n in range(N-1):
    if number>=abs(sort_A[n]-half_A):
        answer=n
        number=abs(sort_A[n]-half_A)
print(max_A,sort_A[answer])


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

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


int main() {
  ll N;
  ll K;
  cin >> N >> K;
  vector<int> A(N),memo(N,-1);
  rep(i,N) {
    cin >> A[i];
    A[i]--;
    }
  memo[0]=0;
  ll now = 0,d;
  rep2(i,1,N+10) {
    now = A[now];
    if (i==K) {
      cout << now+1 << endl;
      return 0;
      }
    if (memo[now]==-1) memo[now]=i;
    else {
      d = i-memo[now];
      break;
    }
  }
  K = (K-memo[now])%d+memo[now];
  rep(i,N) {
    if (memo[i]==K) {
      cout << i+1 << endl;
      return 0;
    }
  }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[3030];
vector<int> E[3030];

int dfs(int cur,int pre) {
	
	int mi=1<<30;
	FORR(e,E[cur]) if(e!=pre) mi=min(mi,dfs(e,cur));
	
	if(mi<A[cur]) return 1<<30;
	return A[cur];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	vector<int> R;
	FOR(i,N) if(dfs(i,-1)==1<<30) R.push_back(i+1);
	FOR(i,R.size()) _P("%d%c", R[i],(i==R.size()-1)?'\n':' ');
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int K, N, X, Y;
	cin >> K >> N >> X >> Y;

	if (K <= N)
	{
		cout << X * K << endl;
	}
	else
	{
		cout << X * N + (K - N) * Y << endl;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

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

	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
// by syu
package main

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

var in = NewScanner(os.Stdin, 0)

func main() {
	N, X := in.Int(), in.Int()
	x := in.ArrayInt(N)
	x = append(x, X)
	sort.Ints(x)
	ans := x[1] - x[0]
	for i := 0; i < len(x)-1; i++ {
		gcd := Gcd(ans, x[i+1]-x[i])
		if gcd < ans {
			ans = gcd
		}
	}
	Pln(ans)
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func (s *Scanner) ArrayInt(n int) (r []int) {
	for i := 0; i < n; i++ {
		r = append(r, s.Int())
	}
	return
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}
func Gcd(a, b int) int {
	t := 0
	for b != 0 {
		t = a % b
		a = b
		b = t
	}
	return a
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}
int fac(int n){
	int x = 1;
	for(int i = 1; i <= n; i++){
		x *= i;
	}

	return x;
}

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

	vector<int> p;
	int p_num = 1;
	vector<int> q;
	int q_num = 1;
	vector<bool> p_pool;
	vector<bool> q_pool;

	rep(i, n){
		int a;
		cin >> a;
		p.push_back(a);
		p_pool.push_back(true);
	}
	rep(i, n){
		int a;
		cin >> a;
		q.push_back(a);
		q_pool.push_back(true);
	}

	for(int i = 0; i + 2 < n; i++){
		int x_p = 0;
		int x_q = 0;

		p_pool[p[i] - 1] = false;
		q_pool[q[i] - 1] = false;

		rep(j, p[i] - 1){
			if(p_pool[j]) x_p++;
		}
		rep(j, q[i] - 1){
			if (q_pool[j]) x_q++;
		}

		p_num += x_p * fac(n - i - 1);
		q_num += x_q * fac(n - i - 1);
	}
	if (p[n - 2] > p[n - 1]) p_num++;
	if (q[n - 2] > q[n - 1]) q_num++;
	
	cout << abs(p_num - q_num);

	return 0;
}

Measured memory_bytes: 256
n,T = map(int,input().split())
t = list(map(int,input().split()))
pushtime = 0
ans = 0
for i in range(n):
    if n== 0:continue
    if pushtime+T > t[i]:
        ans+=t[i] - pushtime
        pushtime = t[i]
        
    
    else:
        ans +=T
        pushtime = t[i]
ans+=T
print(ans)


Measured memory_bytes: 85840
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int INF = 1e13;

class Dinic {
private:
  struct edge {
    int to, cap, rev;
  };

  const int INF = 1e18;

  vector<vector<edge>> G;
  vector<int> level, iter;

  void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0LL, (int)G[from].size() - 1LL});
  }

  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> que;
    que.push(s);
    level[s] = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int f) {
    if (v == t)
      return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int getMaxFlow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0)
        return flow;
      fill(iter.begin(), iter.end(), 0);
      int f;
      while ((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
  }

public:
  Dinic(int N) : G(N, vector<edge>()) {
    level.resize(N);
    iter.resize(N);
  }

  void addEdge(int from, int to, int cap) { add_edge(from, to, cap); }
  int maxFlow(int s, int t) { return getMaxFlow(s, t); }
};

signed main() {
  int H, W;
  cin >> H >> W;

  const int S = 30303, T = 40404, N = 10000;
  int si, sj, ti, tj;

  Dinic d(50505);

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char a;
      cin >> a;
      if (a == 'S') {
        d.addEdge(S, i + N, INF);
        d.addEdge(S, j, INF);
        si = i, sj = j;
      } else if (a == 'T') {
        d.addEdge(i + N, T, INF);
        d.addEdge(j, T, INF);
        ti = i, tj = j;
      } else if (a == 'o') {
        d.addEdge(i + N, j, 1);
        d.addEdge(j, i + N, 1);
      }
    }
  }

  if (si == ti || sj == tj) {
    cout << -1 << endl;
    return 0;
  }

  cout << d.maxFlow(S, T) << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
const int p=31;
const int m=1e9+7;
typedef long long ll;
typedef int in;
// #define ll int64_t 
ll mod=1e9+7;
   
int main (){
    int x=0,n=0,k=0,ps=0,ng=0,ze=0;
    cin>>n>>k;
    vector<ll>v(n);
    for(int i=0;i<n;++i){
    	cin>>x;
    	v[i]=x;
    	if(v[i]>0)ps++;
    	else if(v[i]==0)ze++;
    	else ng++;
    }
         // cout<<ng<<" "<<ps<<" "<<ze<<"\n";

    if(ze!=0 && k>(ps+ng-(ng%2)) ){
    	cout<<0;
    	return(0);
    }

    sort(v.begin(),v.end());
    ll ans=1LL;
    if((ng==n && k%2)){	
    	// cout<<(ll)-999999999 * (ll)999999999<<" "<<(ll)999999999 *(ll)999999999<<" ";
    	for(int i=n-1;i>=n-k;i--){
    		ans=((ll)ans*(ll)((v[i])%mod+mod)%mod);
    		ans=((ans)%mod+mod)%mod;
    	}
    	// cout<<"yo "<<ans<<"  ";
    	cout<<(mod+ans)%mod;
    	return(0);
    }
    // if((ng==n && k%2)){
    // 	if(k==n ){
    // 		if(ze!=0){
    // 			cout<<0;
    // 			return(0);
    // 		}
    // 	}	
    // 	// cout<<(ll)-999999999 * (ll)999999999<<" "<<(ll)999999999 *(ll)999999999<<" ";
    // 	for(int i=n-1;i>=n-k;i--){
    // 		ans=((ll)ans*(ll)((v[i])%mod+mod)%mod);
    // 		ans=((ans)%mod+mod)%mod;
    // 	}
    // 	// cout<<"yo "<<ans<<"  ";
    // 	cout<<(mod+ans)%mod;
    // 	return(0);
    // }
    	ll i=0;
    while(k>0){
    	if(ng>=2 && k>=2){
    		ll _n=v[i]*v[i+1];
    		ll _p=v[n-1]*v[n-2];
    		if(_n>_p) {
    			_n=(_n)%mod;
    			ans=(ans*_n)%mod;
    			ans=((ans)%mod+mod)%mod;
    			i+=2;
    			k-=2;
    			ng-=2;
    		}
    		else{
    			ans=(ll)ans*(ll)v[n-1];
    			ans=((ans)%mod+mod)%mod;
    			if(v[n-1]<0)ng--;
    			n--;
    			k--;
    		}

    	}
    	else{
    			ans=ans*v[n-1]%mod;
    			ans=(ans%mod+mod)%mod;
    			if(v[n-1]<0)ng--;
    		n--;
    		k--;
    	}
    }


    cout<<(((ll)ans)%mod+mod)%mod;
  //  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time
    return(0);
	
}	

   


Measured memory_bytes: 4796
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

// 二分探索


int main() {

	long long N;
	cin >> N;

	long long min = N;
	long long val = 0;
	for (long long j = 1; j <= (long)sqrt((double)N) + 1; j++) {
		if (N % j == 0) {
			val = N / j;
			if (j <= val) {
				val += j - 2;
				if (val < min) {
					min = val;
				}
			}
			else {
				break;
			}
		}
	}

	cout << min << 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>
#include <chrono>

    #pragma GCC optimize("O3")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    /*#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC target ("avx2")*/

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

ll MAX = 1e15;
double PI = 3.141592653589793238463;
//double PI = acos(-1);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void fac(ll x, vector<ll> &divs){
    for(ll i=2; i*i<=x; i++){
        if(x%i==0){
            divs.push_back(i);
            if(i*i!=x){
                divs.push_back(x/i);
            }
        }
    }
}

void solve(){
    ll n;
    cin >> n;
    if(n==2){
        cout << 1;
        return;
    }
    ll m =n-1;
    vector<ll> divofn, divofm;
    set<ll> ans;
    fac(n, divofn); fac(m, divofm);
    divofm.push_back(m);
    divofn.push_back(n);
    for(auto k : divofn){
        ll cur=n;
        while(cur%k==0){
            cur/=k;
        }
        if(cur%k==1){
            ans.insert(k);
        }
    }
    for(auto k : divofm){
        ans.insert(k);
    }
    cout << ans.size();
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif


    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }


    return 0;
}


Measured memory_bytes: 3704
a = list(map(int, input().split()))
L = []
for i in range(a[0]):
    L.append(list(map(int, input().split())))

L = sorted(L)

res = 0
tmp = a[1]
for i in range(a[0]):
    if L[i][1] < tmp:
        res = res + L[i][0] * L[i][1]
        tmp = tmp - L[i][1]
    elif L[i][1] == tmp:
        res = res + L[i][0] * L[i][1]
        break
    else:
        res = res + L[i][0] * tmp
        break

print(res)


Measured memory_bytes: 28656
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    while (1){
    
    int n,x;
    scanf("%d %d",&n,&x);
    
        if(n==0 && x==0){
            break;
        }
    
        int count = 0;
        int i,j,k;
    for(i=1;i<=n-2;i++){
        for(j=i+1;j<=n-1;j++){
            for(k=j+1;k<=n;k++){
                if(i+j+k ==x){
                    count++;
                }
            }
        }
    }
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int N,M;
int C[20];
int X[20004];
const long long INF = 1000000000000;
long long dp[20004][260];
long long dfs(int i_,int y_) {
    if(i_ == N) return dp[i_][y_] = 0;
    if(dp[i_][y_]!=INF) return dp[i_][y_];

    long long ret = INF;

    rep(i,M) {
        int y = y_ + C[i];
        y = max(y,0);
        y = min(y,255);
        //cout<<y<<","<<X[i_]<<endl;
        ret = min(ret,dfs(i_+1,y)+(X[i_]-y)*(X[i_]-y));

    }
    //cout<<i_<<","<<y_<<","<<ret<<endl;
    return dp[i_][y_] = ret;

}
void solve() {
    rep(i,20004) rep(j,260) dp[i][j] = INF;
    rep(i,M) cin>>C[i];
    rep(i,N) cin>>X[i];
    long long ans = INF;
    ans = min(ans,dfs(0,128));
    rep(j,260) {
        ans = min(ans,dp[0][j]);
    }
    cout<<ans<<endl;
    rep(i,M) C[i] = 0;
    rep(i,N) X[i] = 0;

}
int main() {
    while(cin>>N>>M) {
        if(N+M==0) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 43428
object Main {
  def main(args:Array[String]):Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val list = List.fill(n)(sc.nextLong)
    println(list.reduceLeft(gcd))
  }

  def gcd(a:Long,b:Long):Long = {
    if(b > a) gcd(b,a) else if(b == 0) a else gcd(b, a%b)
  }
}

Measured memory_bytes: 62836
#!/usr/bin/php
<?php
$n=fgets(STDIN)+0;
for($i=0;$i<$n;$i++){
	list($y,$m,$d)=split(" ",fgets(STDIN));
	$y-=1;$m-=1;
	echo 196471-$y*195-floor($y/3)*5-$m*20+($y%3!=2?floor($m/2):0)-$d,"\n";
}
?>

Measured memory_bytes: 6624
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int h,w;
	cin >> h >> w;
	char a[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a[i][j];
		}
	}

	for(int i=0; i<h+2; i++){
		for(int j=0; j<w+2; j++){
			if(i==0 || i==h+1){
				cout << "#";
			}else{
				if(j==0 || j==w+1){
					cout << "#";
				}else{
					cout << a[i-1][j-1];
				}
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int n;

    cin >> n;
    vi v1(n), v2(n), v(n);

    for(auto &z : v1)cin >> z;
    for(auto &z : v2)cin >> z;
    for(int i = 1; i <= n; i++)v[i - 1] = i;

    int a = -1, b = -1;

    int brojac = 1;

    do
    {
        if(v1 == v)
        {
            a = brojac;
        }

        if(v2 == v)
        {
            b = brojac;
        }

        if(a != -1 && b != -1)break;

        brojac++;
    }while(next_permutation(all(v)));

    cout << abs(a - b) << '\n';

    return 0;
}


Measured memory_bytes: 256