akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<vector<int>> vec(n);
    for(int i=0;i<m;++i)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    vector<int> ans(n,0);
    queue<int> q;
    q.push(0);
    vector<int> visited(n,0);
    visited[0]=1;
    while(!q.empty())
    {
        int temp=q.front();
        q.pop();
        for(int i=0;i<vec[temp].size();++i)
        {
            if(!visited[vec[temp][i]])
            {
                visited[vec[temp][i]]=1;
                ans[vec[temp][i]]=temp;
                q.push(vec[temp][i]);
            }
        }
    }
    int flag=0;
    for(int i=0;i<n;++i)
    {
        if(visited[i]==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"No"<<"\n";
    else
    {
        cout<<"Yes"<<"\n";
    
    for(int i=1;i<n;++i)
    {
        cout<<ans[i]+1<<"\n";
    }
    }

}


Measured memory_bytes: 10528
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

int n, x[110], y[110], ans[110];
double PI = acos(-1.0);

signed main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < n; i++){
        vector<double> d;
        double ret = 0.0;
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            d.push_back(atan2(y[i] - y[j], x[i] - x[j]));
        }
        sort(d.begin(), d.end());
        d.push_back(d[0] + 2 * PI);
        for(int j = 0; j < d.size() - 1; j++){
            if(d[j + 1] - d[j] >= PI) ret = d[j + 1] - d[j] - PI;
        }
        printf("%.10f\n", ret / (2.0 * PI));
    }
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll n;cin>>n;ll t;cin>>t;
  vector<vvl> dp (3100,vvl(3100,vl(2)));
  for(ll i=1;i<=n;i++){
    ll a,b;cin>>a>>b;
    rep(j,t){
      dp[i][j][0]=dp[i-1][j][0];
      dp[i][j][1]=dp[i-1][j][1];
      if(j>=a){
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j-a][0]+b);
        dp[i][j][1]=max(dp[i][j][1],dp[i-1][j-a][1]+b);
      }
      dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][0]+b);
    }
  }
  ll ans=0;
  rep(j,t){
    rep(k,2)ans=max(ans,dp[n][j][k]);
  }
  cout<<ans<<endl;
  /*rep(i,n+1){
    rep(j,t){
      rep(k,2)cout<<dp[i][j][k]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;*/
}

Measured memory_bytes: 526080
s=input()
n=len(s)
ans=[0]*n
p='R'
c=1
for i in range(1,n):
    if s[i]==p:
        c+=1
    elif s[i]=='L':
        ans[i-1]+=c-c//2
        ans[i]+=c//2
        c=1
        p=s[i]
    elif s[i]=='R':
        ans[i-c-1]+=c//2
        ans[i-c]+=c-c//2
        c=1
        p=s[i]
ans[n-c-1]+=c//2
ans[n-c]+=c-c//2
print(' '.join(map(str,ans)))


Measured memory_bytes: 10484
n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
k-=q
list=[k]*n
for i in range(q):
    list[a[i]-1]+=1
for i in range(n):
    if list[i]>0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 10472
a, b = map(int, input().split())
if (a % 3 ==0) | (b % 3 ==0):
    ans = 0
else:
    anss = []
    s1 = (b // 3 + 1) * a
    s2 = (b - (b // 3 + 1)) * (a // 2)
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3) * a
    s2 = (b - (b // 3)) * (a // 2)
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3 - 1) * a
    s2 = (b - (b // 3) + 1) * (a // 2)
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3) * a
    s2 = (b // 3) * a
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3) * a
    s2 = (b // 3 + 1) * a
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    # b a
    t = a
    a = b
    b = t
    s1 = (b // 3 + 1) * a
    s2 = (b - (b // 3 + 1)) * (a // 2)
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3) * a
    s2 = (b - (b // 3)) * (a // 2)
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3 - 1) * a
    s2 = (b - (b // 3) + 1) * (a // 2)
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3) * a
    s2 = (b // 3) * a
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    s1 = (b // 3) * a
    s2 = (b // 3 + 1) * a
    s3 = a * b - s1 - s2
    anss.append(max(s1, s2, s3) - min(s1, s2, s3))

    ans = min(anss)

print(ans)

Measured memory_bytes: 3192
#include <stdio.h>

int main(void){
    unsigned long long int a[100001] = {0},b[100001],c[100001];
    unsigned long long int aa[100001];
    unsigned long long int buf;
    unsigned long long int n,q;
    unsigned long long int sum = 0;
    
    scanf("%llu",&n);
    for(int i= 0;i < n;i++){
        scanf("%llu",&buf);
        a[buf] ++;
        aa[i] = buf;
    }
    
    scanf("%llu",&q);
    for(int i = 0;i<q;i ++)scanf("%llu %llu",&b[i],&c[i]);
    for(int i = 0;i<n;i++)sum += aa[i];

    for(int j = 0;j<q;j++){
        sum = sum + a[b[j]] * (c[j] - b[j]);

        a[c[j]] += a[b[j]];
        a[b[j]] = 0;

        printf("%llu\n",sum);
    }
    return 0;
}

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

int main() {
  int X,A,B;
  cin >> X >> A >> B;
  if(B-A<=0){
    cout << "delicious" << endl;
  }else if(B-A<=X){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
}


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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    vector<ll> Aa(N + 1);
    Aa[0]               = 0;
    rep(i, N) Aa[i + 1] = A[i] + Aa[i];

    ll l = 0, r = 1e10;
    ll ans = 0;

    while (r - l > 1) {
        ll c = (l + r) / 2;
        ll m = 0;
        ans  = 0;
        rep(i, N) {
            int index = lower_bound(all(A), c - A[i]) - A.begin();
            ans += (Aa[N] - Aa[index] + A[i] * (N - index));
            m += (N - index);
        }
        M >= m ? (r = c) : (l = c);
        ans += l * (M - m);
    }
    cout << ans << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  map<ll, ll> m;
  rep(i, 0, n) {
    cin >> a[i];
    m[a[i]]++;
  }
  
  if(m.size() <= k) {
    cout << 0 << "\n";
    return 0;
  }
  
  vector<ll> v;
  for(const auto& e : m)
    v.push_back(e.second);
  sort(all(v));
  ll lim = m.size()-k;
  ll ans = 0;
  rep(i, 0, lim) ans += v[i];
  
  cout << ans << "\n";
}

Measured memory_bytes: 16500
n, k = map(int,input().split())
if n%2 == 0:
  n_h = n / 2
  if n_h >= k:
    print('YES')
  else:
    print('NO')
else:
  n_h = (n+1) / 2
  if n_h >= k:
    print('YES')
  else:
    print('NO')

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

int b[50][50];
bool used[50];
int main() {
	int s, d;
	while (scanf("%d%d", &s, &d), s) {
		priority_queue<P, vector<P>, greater<P>>que;
		rep(i, s)rep(j, d) {
			int a; scanf("%d", &a);
			if(a)que.push(P(a, j));
		}
		rep(i, d)rep(j, d - i - 1) {
			scanf("%d", &b[i][i + j + 1]);
			if (!b[i][i + j + 1])b[i][i + j + 1] = INF;
			b[i + j + 1][i] = b[i][i + j + 1];
		}
		memset(used, 0, sizeof(used));
		int ans = 0;
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (used[p.second])continue;
			used[p.second] = true;
			ans += p.first;
			rep(i, d) {
				if (!used[i])que.push(P(b[p.second][i], i));
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3136
// In the name of Allah the Lord of the Worlds.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n , k;
vector<ll>v1 , v2;

bool possible(ll mid)
{
    ll tot = 0;
    for(int i=0;i<n;i++){
        ll temp = (mid)/v2[i];
        //if(v2[i]*v1[i]<=mid)continue;
        //cout << temp << " " << temp-v1[i] << endl;
        tot+=max(0LL , v1[i]-temp);
    }
    if(tot>k)return false;
    return true;
}

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

    cin >> n >> k;
    for(int i=0;i<n;i++){
        ll in;
        cin >> in;
        v1.push_back(in);
    }
    for(int i=0;i<n;i++){
        ll in;
        cin >> in;
        v2.push_back(in);
    }
    sort(v1.begin() , v1.end());
    sort(v2.begin() , v2.end());
    reverse(v2.begin() , v2.end());
    ll hi = 1e14 , low = 0 , mid , ans = -1 , t = 70;
    while(t--){
        mid = (hi+low)/2;
        //mid = 0;
        if(possible(mid)){
            ans = mid;
            hi = mid-1;
        }
        else{
            low = mid+1;
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef pair<int, int> P;

int main() {
  int n, x, l;
  cin >> n;
  vector<P> xl;
  for (int i = 0; i < n; i++) {
    cin >> x >> l;
    xl.emplace_back(x + l, x - l);
  }
  sort(xl.begin(), xl.end());

  int cur = -1e9, ans = 0;
  for (auto &v : xl) {
    if (cur <= v.second) {
      ans++;
      cur = v.first;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int X = sc.nextInt();
    for(int i=0; i<K-1; i++){
      System.out.print(X-K+1+i +" ");
    }
    for(int i=0; i<K-1; i++){
      System.out.print(X+i +" ");
    }
    System.out.println(X+K-1);
  }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  int arr[n];
  for(int i=0;i<n;i++)
  {
    scanf("%d",&arr[i]);
  }
 int max=arr[0];
  long long int sum=0;
  for(int i=1;i<n;i++)
  {
    if(max>arr[i])
    {
      sum=sum+(max-arr[i]);
    }else{
      max=arr[i];
    }  
  }
  printf("%lld",sum);
  return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int h,w; cin >>h >>w;
	vector<string> a(h);
    cinf(h,a);
	for(int i=0;i<h+2;i++){
		if(i==0 || i==h+1){
			for(int j=0;j<w+2;j++)
				cout <<"#";
			cout << endl;
		}
		else{cout <<"#"<<a[i-1]<<"#"<<endl;}
	}

}


Measured memory_bytes: 256
s = input()
t = input()

def comp(a, b, n):
	for i in range(n):
		if a[i] != '?' and a[i] != b[i]:
			return False
	return True 

def change(a):
	b = ""
	for i in range(len(a)):
		c = a[i]
		if a[i] == '?':
			c = 'a'
		b += c
	return b

t_len = len(t)
bad = "UNRESTORABLE"

n = len(t)
if len(t) > len(s):
	print(bad)
else:
	found = 0
	for i in range(n, len(s)):
		if comp(s[-i:-(i-n+1)]+s[-(i-n+1)], t, t_len):
			s = change(s)
			if i > n:
				print(s[:-i]+t+s[-(i-n):])
			else:
				print(s[:-i]+t)
			found = 1
			break
	if found == 0:
		if len(s) == len(t):
			if comp(s, t, n):
				print(t)
				found = 1
	if found == 0:
		print(bad)

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

struct Dice {
  int f[6];

  void roll(char ch) {
    if (ch == 'N') {
      int t = f[0];
      f[0] = f[1];
      f[1] = f[5];
      f[5] = f[4];
      f[4] = t;
    } else if (ch == 'E') {
      int t = f[0];
      f[0] = f[3];
      f[3] = f[5];
      f[5] = f[2];
      f[2] = t;
    } else if (ch == 'W') {
      int t = f[0];
      f[0] = f[2];
      f[2] = f[5];
      f[5] = f[3];
      f[3] = t;
    } else if (ch == 'S') {
      int t = f[0];
      f[0] = f[4];
      f[4] = f[5];
      f[5] = f[1];
      f[1] = t;
    }
  }

  void spin() {
    int t = f[1];
    f[1] = f[2];
    f[2] = f[4];
    f[4] = f[3];
    f[3] = t;
  }

  int top() {
    return f[0];
  }

  int left() {
    return f[3];
  }

  int right() {
    return f[2];
  }

  int front() {
    return f[1];
  }

  bool equal(Dice d) {
    return f[0] == d.f[0] &&
      f[1] == d.f[1] &&
      f[2] == d.f[2] &&
      f[3] == d.f[3] &&
      f[4] == d.f[4] &&
      f[5] == d.f[5];
  }
};

bool check_equal(Dice d1, Dice d2) {
  bool flag = 0;

  for (int i = 0; i < 4; i++) {
    d1.spin();

    for (int j = 0; j < 4; j++) {
      if (flag) break;
      d2.roll('N');
      flag = d1.equal(d2);
    }
  }

  d1.roll('E');
  for (int j = 0; j < 4; j++) {
    if (flag) break;
    d2.roll('N');
    flag = d1.equal(d2);
  }

  d1.roll('W');
  d1.roll('W');
  for (int j = 0; j < 4; j++) {
    if (flag) break;
    d2.roll('N');
    flag = d1.equal(d2);
  }

  return flag;
}

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

  Dice dices[n] = {};
  bool flag = 0;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++)
      cin >> dices[i].f[j];

  for (int i = 0; i < n - 1; i++) {
    if (flag) break;
    Dice d1 = dices[i];
    for (int j = i + 1; j < n; j++) {
      if (flag) break;
      Dice d2 = dices[j];
      flag = check_equal(d1, d2);
    }
  }

  cout << (flag ? "No" : "Yes") << endl;

  return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,k;
  int count,x=0,y[105];
  cin>>a>>b>>k;
  count=min(a,b);
  for(int i=1;i<=count;i++){
    if(a%i==0 && b%i==0){
      y[x]=i;
      x++;
    }
  }
  sort(y,y+x,greater<int>());
  cout<<y[k-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    int n;
    cin >> n;
    unordered_map<string ,int>mp;
    string s;
    for(int i=0;i<n;i++) {
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << nl;
    
}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 17748
#include<stdio.h>
int main(void)
{
  int i,t,n,k;
  for(i=0;i<4;i++){
    scanf("%d %d",&t,&n);
    if(t==1){
      k=6000;
    } else{
      k=(6-t)*1000;
    }
    k*=n;
    printf("%d\n",k);
  }
  return(0);
}

Measured memory_bytes: 600
#include <stdio.h>
#include <iostream>
#include <queue>
using namespace std;

typedef long long ll;

// Self settings
// clang-format off
#define MAX_N 10000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N, K;
int V[MAX_N];

int main(void)
{
  deque<int> dqe;
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> V[i];
    dqe.push_back(V[i]);
  }

  ll ans = 0;

  for (int a = 0; a <= min(N, K); a++) {
    deque<int> dq = dqe;
    priority_queue<int, vector<int>, greater<int>> que;
    int aa = a;
    while (aa > 0 && !dq.empty()) {
      que.push(dq.front());
      dq.pop_front();
      aa--;
    }

    for (int b = 0; b <= min(N, K) - a; b++) {
      deque<int> dqq = dq;
      priority_queue<int, vector<int>, greater<int>> qu = que;
      int bb = b;
      while (bb > 0 && !dqq.empty()) {
        qu.push(dqq.back());
        dqq.pop_back();
        bb--;
      }

      for (int k = 0; k <= K - (a + b); k++) {
        int kk = k;
        priority_queue<int, vector<int>, greater<int>> q = qu;
        while (kk > 0) {
          if (!q.empty() && q.top() < 0) {
            q.pop();
          }
          kk--;
        }
        ll sum = 0;
        while (!q.empty()) {
          sum += q.top();
          q.pop();
        }
        ans = max(ans, sum);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 504
class Vector:
    __slots__ = ['x', 'y']

    def __init__(self, x, y):
        self.x, self.y = x, y

    def __add__(self, other):
        return self.__class__(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return self.__class__(self.x - other.x, self.y - other.y)

    def __mul__(self, x):
        return self.__class__(self.x * x, self.y * x)

    def __truediv__(self, x):
        return self.__class__(self.x / x, self.y / x)

    def norm(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5


def dot(u, v):
    return u.x * v.x + u.y * v.y


x1, y1, x2, y2 = map(float, input().split())
p1, p2 = Vector(x1, y1), Vector(x2, y2)
n = (p2 - p1) / (p2 - p1).norm()

q = int(input())

for _ in range(q):
    p = Vector(*map(float, input().split()))
    p_prj = p1 + n * dot(p - p1, n)
    p_ref = p_prj * 2 - p
    print('{:.10f} {:.10f}'.format(p_ref.x, p_ref.y))



Measured memory_bytes: 5676
# 2019-11-20 23:47:42(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    H, W, n, *a = [int(x) for x in sys.stdin.read().split()]
    color_count = [None] + a 
    
    canvas = [[None for _ in range(W)] for _ in range(H)]
    
    h, w = 0, 0
    for i in range(1, n+1):
        while color_count[i] > 0:
            canvas[h][w] = i
            color_count[i] -= 1

            if h % 2 == 0:
                w += 1
                if w == W:
                    h += 1
                    w = W - 1
            else:
                w -= 1
                if w == -1:
                    h += 1
                    w = 0

    for h in range(H):
        print(' '.join(map(str, canvas[h])))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define prllDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

vector<vector<int>> product(vector<vector<int>> A, vector<vector<int>> B)
{
    vector<vector<int>> C(A.size(), vector<int>(A[0].size()));
    for(int i = 0; i < C.size(); i++)
    {
        for(int j = 0; j < C[0].size(); j++)
        {
            for(int k = 0; k < A.size(); k++)
            {
                C[i][j] += (1LL * A[i][k]*B[k][j]) % mod;
                C[i][j] %= mod;
            }
        }
    }
    return C;
}

vector<vector<int>> power(vector<vector<int>> A, ll k)
{
    if(k == 1)
            return A;

    vector<vector<int>> res = power(A, k/2);

    if(k & 1)
        return product(product(res, res), A);
    else return product(res, res);
}

int solve(vector<vector<int>>& adjMat, ll k)
{
    adjMat = power(adjMat, k);
    ll ans = 0;
    for(int i = 0; i < adjMat.size(); i++)
    {
        for(int j = 0; j < adjMat[0].size(); j++)
        {
            ans = (ans + adjMat[i][j]) % mod;
        }
    }
    return ans;
}

int main(){
    ll i,j,t,n,m,x,p,k;
    fast_io;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n>>k;
        vector<vector<int>> graph(n, vector<int>(n));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >> graph[i][j];
        cout << solve(graph, k);
    }
    return 0;
}


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

bool solve(vector<int> a, int sum) {
    int N = a.size();
    vector< vector<int> > dp(N + 10, vector<int>(sum + 10));
    dp[0][0] = 1;

    for(int i=0; i<N; i++) {
        for(int j=0; j<=sum; j++) {
            dp[i+1][j] |= dp[i][j];
            if(j - a[i] < 0) continue;
            dp[i+1][j] |= dp[i][j-a[i]];
        }
    }
    return dp[N][sum];
}

int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;

    s += "T";
    int mode = 0, cnt = 0;
    int sum_x = x, sum_y = y;
    vector<int> move_x, move_y;
    for(size_t i=0; i<s.length(); i++) {
        if(s[i] == 'F') cnt++;
        else {
            if(mode == 0) {
                sum_x -= cnt;
            }
            else {
                (mode % 2 ? move_y : move_x).push_back(cnt);
                (mode % 2 ? sum_y : sum_x) += cnt;
            }
            cnt = 0;
            mode++;
        }
    }

    x = abs(x), y = abs(y);
    move_x.push_back(x);
    move_y.push_back(y);

    fprintf(stderr, "sum_x = %d, sum_y = %d\n", sum_x, sum_y);
    if(sum_x % 2 || sum_y % 2 || sum_x < 0 || sum_y < 0) {
        cout << "No" << endl;
        return 0;
    }

    sum_x /= 2;
    sum_y /= 2;

    bool ok = true;
    ok &= solve(move_x, sum_x);
    ok &= solve(move_y, sum_y);
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 32896
<?php
$input = trim(fgets(STDIN));
$max = 0;
$cnt = 0;
foreach(str_split($input) as $e) {
  $max = ($cnt > $max) ? $cnt : $max; 
  $cnt = ($e === "R") ? ($cnt + 1) : 0;
}
$max = ($cnt > $max) ? $cnt : $max; 
echo $max . PHP_EOL;


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

int main(int argc, char const *argv[])
{
	string s;
	int m, h;
	while(cin >> s) {
	    if(s.compare("-") == 0) break;
	    cin >> m;
	    for (int i = 0; i < m; ++i)
	    {
	    	cin >> h;
	    	string left = s.substr(0,h);
	    	string right = s.substr(h, s.length()-h);
	    	s = right + left;
	    }
	    cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include<vector>
#include<iostream>
using namespace std;
#include<stdio.h>

int cnt;
vector<int> G;
int n;
int m;
int A[1000000];
void insertionSort(int* A,int n,int g)
{
    for(int i = g;i <= n-1;i++)
    {
        int v = A[i];
        int j = i-g;
        for(;j >= 0 && A[j] > v;)
        {
            A[j+g] = A[j];
            cnt++;
            j = j - g;
        }
        A[j+g] = v;

    }
}

void shellSort(int* A,int n)
{
    cnt = 0;
    m = 0;
    int h = 1;
    G.push_back(h);
    m++;
    while(h*3+1 < n)
    {
        h = h*3 + 1;
        G.push_back(h);
        m++;
    }

    for(int i = m-1;i >= 0;i--)
    {
        insertionSort(A,n,G[i]);
    }


}


int main()
{
    cin >> n;
    for(int i = 0;i < n;i++)
        scanf("%d",&A[i]);
    cnt = 0;

    shellSort(A,n);

    cout << G.size() << endl;
    for ( int i = G.size() - 1;i >= 0;i-- ) {
        printf("%d",G[i]);
        if ( i ) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
    for ( int i = 0; i < n;i++) printf("%d\n",A[i]);

    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

int n;
vector<vector<int>> a(305, vector<int>(305)), b(305, vector<int>(305));


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n)rep(j, n) cin >> a[i][j];
    b = a;
    rep(k, n)rep(i, n)rep(j, n) b[i][j] = min(b[i][j], a[i][k] + a[k][j]);
    bool ok = true;
    rep(i, n){
        rep(j, n) {
            if (a[i][j] != b[i][j]) {
                ok = false;
                break;
            }
        }
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    rep(i, n)rep(j, n) ans += a[i][j];
    rep(i, n)rep(j, n){
        rep(k, n) {
            if (i == k || j == k) continue;
            if (b[i][j] == b[i][k] + b[k][j]) {
                ans -= b[i][j];
                break;
            }
        }
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 1024
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

p = int(sum(x)/n)
q = p+1

a = sum([(i-p)**2 for i in x])
b = sum([(i-q)**2 for i in x])

print(min([a,b]))


Measured memory_bytes: 9540
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    string s;
    getline(cin, s);
    int n = sz(s);
    rep(i, n) {
        if (isalpha(s[i])) {
            if (isupper(s[i])) s[i] = tolower(s[i]);
            else s[i] = toupper(s[i]);
        }
        cout << s[i];
    }
    cout << endl;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> b(n - 1);
	rep(i, n - 1) cin >> b[i];
	int ans = 0;
	ans += b.front();
	b.push_back(inf);
	rep(i, n - 1) {
		ans += min(b[i], b[i + 1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    arr = [a, b, a - 1, b - 1]
    arr.sort()
    print(arr[2] + arr[3])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();

        s[3] = '8';

        String output = new String(s);
        System.out.println(s);
        sc.close();
    }
}


Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
typedef struct{
	int data,num;
}Data;
int comp(const void* a,const void* b){
	return ((Data*)a)->data - ((Data*)b)->data;
}
Data a[100000];
int main(void)
{
	int n,res=0,i;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a[i].data);
		a[i].num=i;
	}
	qsort(a,n,sizeof(Data),comp);
	for(i=0;i<n;i+=2){
		if(a[i].num%2) res++;
	}
	printf("%d\n",res);
	return 0;
}

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int b=0;
  int c=0; 
  while(b<N-1){
    c++;
    b+=K-1;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3664
fn main() {
    let s : String = readln();
    let ans = format!("{}8{}", &s[0..3], &s[4..]);
    println!("{}", ans);
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 4352
void main()
{
    long a, b;
    rdVals(a, b);

    writeln(calc(b) ^ calc(a-1));
}

long calc(long x)
{
    long r = x % 4, y = (r >> 1) & 1;
    if (r & 1)
    {
        return !y;
    }
    else
    {
        return x + y;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
n,m=map(int,input().split())
k=[[0]*m for i in range(n)]
for i in range(n):
    k[i]=list(map(int,input().split()))
ans=1000
for i in range(m-1):
    ma=[0]*m
    mi=-1
    for j in range(n):
        ma[k[j][0]-1]+=1
    if ans>max(ma):
        ans=max(ma)
    mi=ma.index(max(ma))+1
    for j in range(n):
        k[j].remove(mi)
if m==1:
    print(n)
else:
    print(ans)
        


Measured memory_bytes: 4332
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>



using namespace std;

static const int N = 100;
int A[N+1][N+1];

int main(){
    
    for (int i=0;i<=N;i++){
        A[i][0] = 0;
    }
    for (int j = 0;j<=N;j++){
        A[0][j] = 0;
    }
    int n;
    cin >> n;
    for (int i=1;i<=n;i++){
        int p,k;
        cin >> p >> k;
        for (int j=0;j<k;j++){
            int a;
            cin >> a;
            A[i][a] = 1;
           
        }
    }

    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++){
            if(j-1){
                cout << " ";
            }
            cout << A[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3164
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int>pli;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string impossible;

mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int N=6;
const int N=5e2+5;
const int M=1e4+5;
const int L=41;
int MOD=1e9+7;
// ll n,m,k,i,j,d;
bool f0,f1,f2;
const int MAXN=2e3;
ll dp[3000][3000][4];
int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
    cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    for(int te=1;te<=tests;te++){
        ll r,c,items;  cin>>r>>c>>items;
        int v[r][c]; mem(v,0);
        for(int i=0;i<items;i++){
            int x,y,val;    cin>>x>>y>>val;
            v[x-1][y-1]=val;
        }
        
        mem(dp,0LL);
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                for(int k=0;k<4;k++){
                    if(i-1>=0)  dp[i][j][k]=max(dp[i-1][j][3],dp[i][j][k]);
                    if(j-1>=0)  dp[i][j][k]=max(dp[i][j-1][k],dp[i][j][k]);
                    if(k>0){
                        if(i-1>=0)  dp[i][j][k]=max(v[i][j]+dp[i-1][j][3],dp[i][j][k]);
                        if(j-1>=0)  dp[i][j][k]=max(v[i][j]+dp[i][j-1][k-1],dp[i][j][k]);
                        dp[i][j][k]=max(dp[i][j][k],v[i][j]*1LL);
                    }
                    // cout<<dp[i][j][k]<<" ";
                }
                // cout<<"|\t|";
            }
            // cout<<"\n";
        }
        cout<<dp[r-1][c-1][3];
    }
    return 0;
}





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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    char c;
    for (int i = 0; i < n; i++) {
        cin >> c;
        if (c == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl; 
}


Measured memory_bytes: 256
// Sum of gcd of Tuples (Easy)
func gcd(_ a:Int, _ b:Int) -> Int {
  if a == 1 || b == 1 {
    return 1
  }
  if a == b {
    return a
  }
  return gcd(min(a, b), abs(b-a))
}


func main() {
  let n = Int(readLine()!)!
  var sum = 0
  for a in 1...n {
    for b in 1...n {
      for c in 1...n {
        sum += gcd(gcd(a,b), c)
      }
    }
  }
  print(sum)
}

main()

Measured memory_bytes: 7692
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
vector<vector<int>> G;
using P = pair<int, int>;
vector<P> d;
vector<bool> visit;

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    d.assign(N, make_pair(1 << 30, -1));
    d[0].first = 0, d[0].second = 0;
    visit.assign(N, false);
    queue<int> q;
    q.push(0);
    visit[0] = true;
    int count = 0;
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        visit[v] = true;
        ++count;
        for (int nv : G[v])
        {
            if (visit[nv]) continue;
            if (count < d[nv].first)
            {
                d[nv].first = count;
                d[nv].second = v;
                q.push(nv);
            }
        }
    }
    for (int i = 1; i < N; ++i)
    {
        if (!visit[i])
        {
            std::cout << "No" << endl;
            return 0;
        }
    }
    std::cout << "Yes" << endl;
    for (int i = 1; i < N; ++i)
    {
        std::cout << d[i].second + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n,h,w;
  cin>>w>>h>>n;
  int maxx=w,maxy=h,minx=0,miny=0;
  rep(i,0,n){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1){
      minx=max(minx,x);
    }
    else if(a==2){
      maxx=min(maxx,x);
    }
    else if(a==3){
      miny=max(miny,y);
    }
    else if(a==4){
      maxy=min(maxy,y);
    }
  }
  if(maxx-minx<0 || maxy-miny<0)cout<<0<<endl;
  else cout<<(maxx-minx)*(maxy-miny)<<endl;
}

Measured memory_bytes: 256
let s = stdin.ReadLine()

let ans =
  let rIntervals, lIntervals =
    let rIntervals = ResizeArray<int * int> []
    let lIntervals = ResizeArray<int * int> []

    let mutable left = ('R', 0)
    for i in 1 .. s.Length - 1 do
      if fst left = 'R' && s.[i] = 'L' then
        rIntervals.Add((snd left, i - 1))
        left <- ('L', i)
        if i = s.Length - 1 then
          lIntervals.Add((i, i))
      elif fst left = 'L' then
        if s.[i] = 'R' then
          lIntervals.Add((snd left, i - 1))
          left <- ('R', i)
        elif i = s.Length - 1 then
          lIntervals.Add((snd left, i))

    [ for i in rIntervals -> i ], [ for i in lIntervals -> i ]

  List.zip rIntervals lIntervals
  |> List.collect (
    fun ((rl, rr), (ll, lr)) ->
      [rl .. lr]
      |> List.map (
        fun i ->
          if i = rr then
            ([rl .. rr].Length + 1) / 2 + [ll .. lr].Length / 2
          elif i = ll then
            ([rl .. rr].Length) / 2 + ([ll .. lr].Length + 1) / 2
          else
            0
        )
      )

ans
|> List.map string
|> List.toSeq
|> String.concat " "
|> stdout.WriteLine

Measured memory_bytes: 38460
//  Twitter@KonoLv1 2020年春からエンジニア見習いデビュー！
 
//  標準入出力を扱うヘッダーファイルの読み込み
#include <stdio.h>
//  "atoi" "atof"などのキャスト、"rand" 疑似乱数を発生させるヘッダーファイルの読み込み
#include <stdlib.h>
//  "strcpy" "strcat"などの文字列操作や"strlen"文字列長さ取得などを行うヘッダーファイルの読み込み
#include <string.h>
//  "sqrtl" "fmax"などの数値操作を行うヘッダーファイルの読み込み
#include <math.h>
 
int main(void){
 
    int x,y,z;
    int i,j,k;
    int count = 0;
    int flg = 0;
    char s[200000] = {};
    int box[200000] = {};
 
    //scanf("%s %d",&s,&box[0]);
    scanf("%d %d",&x,&y);
    // HP x
    // DM y
    while(1){
        if (x <= 0){
            break;
        }
        count++;
        x = x - y;
    }
    
    //printf("%s \n%d",s,box[0]);
    printf("%d",count);
  
 
}

Measured memory_bytes: 128
N,W=map(int,input().split())

def solve_knapsack(capacity):
    # basic checks
 
    dp = [0]*(capacity + 1)
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    for i in range(0, N):
        weights,profits = map(int,input().split())
        for c in range(capacity, weights-1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]: dp[c] = tmp
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

Measured memory_bytes: 7668
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int nLines;
  std::cin >> nLines;
  
  // Loop through prices and append the results to a vector
  std::vector<int> prices;
  for(int i = 0; i < nLines; i++) {
    int price;
    std::cin >> price;
    prices.push_back(price);
  }
  
   if(prices.empty()) {
    std::cout << "0" << std::endl;
    return 0;
  }
 
  // Sort vector
  std::sort(prices.begin(), prices.end());
  int pos = prices.size() - 1;
  int acc = prices[pos--]/2;

  while(pos >= 0) {
    acc += prices[pos--];
  }

  std::cout << acc << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
char str[200005];
int main() {
	int n;
	scanf("%d%s", &n, str);
	int l = 0;
	const ll MOD = 1e9 + 7;
	ll ans = 1;
	for (int i = 0; i < 2 * n; ++i) {
		int col = (str[i] == 'W');
		col ^= (l & 1);
		if (col == 1) {
			if (!l) {
				printf("0\n");
				return 0;
			}
			ans = ans * l % MOD;
			--l;
		} else {
			++l;
		}
	}
	if (l > 0) ans = 0;
	for (int i = 1; i <= n; ++i) ans = ans * i % MOD;
	printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
 
int main(){
    LL a,b,x;
    cin >> a >> b >> x;
    if(a%x==0) cout << b/x-a/x+1 << endl;
    else cout << b/x-a/x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	string s;
	ll memo[26],ans=1,n;
	fill(memo, memo + 26, 1);
	cin >> n>>s;
	for (int i = 0; i < n; i++) {
		memo[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		ans = ans * memo[i] % mod;
	}
	cout << (ans + mod - 1) % mod << endl;

}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, s, t) for(int i = (s); i < (t); i++)

int N;
ll A[405], DP[405][405];
ll sum[405];
// 0 - Taro's turn
// 1 - Jiro's turn

ll rek(int l, int r) {
    if(l>=r) return 0;
    if(DP[l][r] != -1) return DP[l][r];
    ll sol = 1LL<<60;
    for(int i = l; i < r; i++) {
        ll a = rek(l, i);
        ll b = rek(i + 1, r);
//        printf("interval %lld; %d-%d\n", sum[r]-sum[l-1], l, r);
        sol = min(sol, a+b+sum[r]-sum[l-1]);
    }
    DP[l][r] = sol;
    return DP[l][r];
}

int main()
{
    scanf("%d", &N);
    REP(i, 0, N) {
        scanf("%lld", &A[i]);
        sum[i] = A[i] + (i==0?0:sum[i-1]);
    }

    memset(DP, -1, sizeof(DP));
    ll x = rek(0, N-1);
    printf("%lld", x);

    return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] inputPrices = br.readLine().split(" ");

            List<Integer> bellPrices = new ArrayList<>();

            for (int i = 0; i < inputPrices.length; i++) {
                bellPrices.add(Integer.parseInt(inputPrices[i]));
            }

            int minPrice = 0;
            bellPrices.sort((i1, i2) -> i1 - i2);
            for (int bellPrice : bellPrices.subList(0, 2)) {
                minPrice += bellPrice;
            }

            System.out.println(minPrice);

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 26836