akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct P{
  int h,p,q;
  P(){}
  P(int H,int P,int Q){ h=H; p=P; q=Q; }
  bool operator<(const P &p) const {
    return h<p.h;
  }
};

int main(){
  int n,m,a;
  int H,PP,Q;
  vector<P> v;

  while( cin>>n>>m>>a && (n|m|a) ){
    v.clear();
    for( int i=0;i<m;i++ ){
      cin >> H >> PP >> Q;
      v.push_back( P(H,PP,Q) );
    }
    sort( v.begin(),v.end() );

    for( int i=v.back().h;i>=0;i--){
      std::vector<P>::iterator pp
	= lower_bound(v.begin(),v.end(),P(i,0,0) );
     
      //      cout << "***** i="<<i << " a=" << a << " *****" << endl;

      while( pp!=v.end() && pp->h == i ){
	PP=pp->p; Q=pp->q;
	//	cout << pp->h << " " << PP << " " << Q << endl;
	if( a==PP )	  a = Q;
	else if( a==Q )	  a = PP;
	pp++;
      }
      //      if( pp!=v.end() )	cout << "while out " << pp->h << " " << pp->p << " " << pp->q << endl;
    }
    cout << a << endl;
  }

  return 0;
}

Measured memory_bytes: 936
//
//NOMURA 2020
//B - Postdocs
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    string t;

    cin >> t;

    t+='-';
    string ans = "";
    char bf = t[0];
    REP(i, t.size()-1){
        if (t[i] == '?') {
            if (bf=='P'){
                ans += 'D';
                bf = 'D';
            }else{
                if (t[i+1] == 'D' || t[i+1] == '?') {
                    ans += 'P';
                    bf = 'P';
                }else{
                    ans += 'D';
                    bf = 'D';
                }
            }
        }else{
            ans += t[i];
            bf = t[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3824
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

n = int(input())
s = input()

if n % 2 == 1:
  print('No')

else:
  for i in range(n // 2):
    # print('{} <--> {}'.format(s[i], s[n // 2 + i]))
    if not(s[i] == s[n // 2 + i]):
      print('No')
      exit(0)
  print('Yes')


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

using namespace std;
typedef long long int ll;


void pf(ll x, vector<ll> &a) {
    for(ll i=2; i*i<=x; ++i){
        if(x % i == 0){
            a.push_back(i);
            while(x % i == 0){
                x /= i;
            }
        }
    }
    if(x > 1){
        a.push_back(x);
    }
}



int main() {
    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    vector<ll> pa;
    pf(g, pa);
    cout<<pa.size() + 1;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
 
/*---------------------------------------------------------------------------------------------------*/
int n, W;
int dp[103][100005];
int w[103], v[103];

int knapsack(int curr, int rem)
{
    if (curr == n) return 0;

    int &ret = dp[curr][rem];
    if (ret != 0) return ret;

    ret = knapsack (curr + 1, rem);
    if (rem >= w[curr]) ret = max (ret, v[curr] + knapsack (curr + 1, rem - w[curr]));

    return ret;
}

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

    f (i, n) cin >> w[i] >> v[i];

    memset (dp, 0, sizeof(dp));

    cout << knapsack(0, W);
} 
 
signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--) solve();
  return 0;
}

Measured memory_bytes: 84124
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int N;
long long X;
vector<long long> x;

int main() {
    while (cin >> N >> X) {
        x.resize(N); for (int i = 0; i < N; ++i) cin >> x[i], x[i] -= X;
        long long g = abs(x[0]);
        for (int i = 0; i < N; ++i) g = GCD(g, abs(x[i]));
        cout << g << endl;
    }
}






















Measured memory_bytes: 1024
#include <iostream>
#include <string>

int main() {
	std::ios::sync_with_stdio(false);

	std::string input;
	int n;

	std::cin >> n >> input;

	long long i = 0;
	long long j = 0;
	long long k = 0;
	long long less = 0;

	for (int _ = 0; _ < n; _++) {
		char c = input[_];
		if (c == 'R') {
			i++;
		}
		else if (c == 'G') {
			j++;
		}
		else {
			k++;
		}
	}

	for (int dist = 1; 2 * dist < n; dist++) {
		for (int start = 0; start + 2 * dist < n; start++) {
			char s = input[start];
			char m = input[start + dist];
			char l = input[start + 2 * dist];
			if (s != m && s != l && m != l) {
				less++;
			}
		}
	}

	std::cout << i * j * k - less;
	
	return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int N = int.Parse(s.Split(' ')[0]);
            int K = int.Parse(s.Split(' ')[1]);

            string[] arr = Console.ReadLine().Split(' ');
            long[] Pattern = new long[N - K + 1];

            for(int i = 0; i < N - K + 1; i++)
            {
                long max = long.Parse(arr[K + i - 1]);
                long min = long.Parse(arr[i]);

                if(max <= 0)
                {
                    Pattern[i] = (-1) * min;
                    continue;
                }
                else if(0 <= min)
                {
                    Pattern[i] = max;
                    continue;
                }

                if(Math.Abs(min) < max)
                {
                    Pattern[i] = Math.Abs(min) * 2 + max;
                }
                else
                {
                    Pattern[i] = Math.Abs(min) + max * 2;
                }
            }

            Console.WriteLine(Pattern.Min());
        }
    }
}


Measured memory_bytes: 20448
n, m = map(int, input().split())
a_list = list(map(int, input().split()))


flg = 0

a_list.sort()
a_list.reverse()

all = 0

for i in range(n):
    all += a_list[i]

all = all*(1/(4*m))


for j in range(m):
    if a_list[j] < all:
        flg = 1

if flg == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;

int n, m;

int dist[1 << 20];
int cost[20][123456];
int nui[123456];
int ncount[20];

int memo[1 << 20];
int dp(int bit)
{
	if (bit == 0)return 0;
	if (memo[bit] >= 0)return memo[bit];
	int ans = 123456789;
	for (int i = 0; i < 20; ++i)
	{
		if (bit & (1 << i))
		{
			int lastbit = bit - (1 << i);
			ans = min(ans, dp(lastbit) + cost[i][dist[lastbit]]);
		}
	}
	return memo[bit] = ans;
}

int main(void)
{
	scanf("%d %d", &n, &m);
	memset(memo, 0xff, sizeof(memo));
	fill(ncount, ncount + 20, 0);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", nui + i);
		--nui[i];
		++ncount[nui[i]];
	}
	dist[0] = 0;
	for (int bit = 1; bit < (1 << m); ++bit)
	{
		int bigb = 0;
		for (int i = 0; i < 20; ++i)
		{
			if (bit & (1 << i))
			{
				bigb = i;
				break;
			}
		}
		dist[bit] = dist[bit - (1 << bigb)] + ncount[bigb];
	}
	for (int j = 0; j < m; ++j)
	{
		//cost
		int price = 0;
		for (int first = 0; first < ncount[j]; ++first)
		{
			if (nui[first] == j)
			{
				++price;
			}
		}
		for (int shack = 0; shack <= n - ncount[j]; ++shack)
		{
			cost[j][shack] = ncount[j] - price;
			if (nui[shack] == j)
			{
				--price;
			}
			if (shack != n - ncount[j] && nui[shack + ncount[j]] == j)
			{
				++price;
			}
		}
	}
	int ans = dp((1 << m) - 1);
	printf("%d\n", ans);
	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    string s;
    cin >> n >> s;
    REP(i, size(s)){
        char a = s[i] - 'A';
        s[i] = 'A' + (a + n) % 26;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
double INF = 1000000000000.0;

int main() {
  int n;
  cin >> n;
  vector<int> dist(n);
  vector<int> gold(n);
  vector<int> nums(n);
  for (int i = 0; i < n; ++i) {
    cin >> nums[i] >> dist[i] >> gold[i];
  }
  vector<vector<double>> dp(n,vector<double>(1<<n,INF));
  vector<vector<int>> path(n,vector<int>(1<<n));
  for (int i = 0; i < n; ++i) {
    dp[i][1<<i] = 0.0;
  }
  for (int i = 1; i < (1 << n); ++i) {
    bitset<16> bs(i);
    int weight = 0;
    for (int j = 0; j < n; ++j) {
      if(bs[j]) {
        weight += gold[j] * 20;
      }
    }
    for (int j = 0; j < n; ++j) {
      if(!bs[j]) {
        int k = i | (1 << j);
        for (int l = 0; l < n; ++l) {
          if(bs[l]){
            double d = abs(dist[l] - dist[j]);
            double s = 2000.0 / (70.0 + weight);
            double t = d / s;
            if (dp[j][k] > dp[l][i] + t){
              dp[j][k] = dp[l][i] + t;
              path[j][k] = l;
            }
          }
        }
      }
    }
  }
  vector<int> steps(n);
  int bitmask = (1<<n)-1;
  int mini = 0;
  double mint = INF;
  for (int i = 0; i < n; ++i) {
    if (mint > dp[i][bitmask]) {
      mint = dp[i][bitmask];
      mini = i;
    }
  }
  for (int i = 0; i < n; ++i) {
    steps[n-i-1] = mini;
    int oldmini = mini;
    mini = path[mini][bitmask];
    bitmask ^= 1 << oldmini;
  }
  for (int i = 0; i < n; ++i) {
    if(i) cout << ' ';
    cout << nums[steps[i]];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int lds(vector<int> &v){
    int n = v.size();
    vector<int> ans(n, -INF);
    REP(i, n) {
        *(upper_bound(ALL(ans), v[i]-1)-1) = v[i];
    }
    return ans.end() - upper_bound(ALL(ans), -INF);
}

int main(void)
{
    ll N;
    cin >> N;
    vector<int> A(N);
    REP(i, N){
        cin >> A[i];
    }
    pr(lds(A));
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N, x,t; cin>> N >> x >> t;
	cout << (N/x + (N % x != 0))*t << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

ll bfs(vector<string> S, ll si, ll sj)
{
    queue<pair<ll,ll>> Q;
    vector<vector<ll>> C(SZ(S), vector<ll>(SZ(S[0]), -1));
    ll pi, pj, di, dj;
    Q.push({si, sj});
    C[si][sj] = 0;
    
    while(!Q.empty()) {
        pair<ll,ll> p = Q.front(); Q.pop();
        pi = p.first; pj = p.second;
        if(S[pi][pj] == '#') continue;
        vector<pair<ll,ll>> D = {{pi-1, pj}, {pi, pj+1}, {pi+1, pj}, {pi, pj-1}};
        FORR(d,D) {
            di = d.first; dj = d.second;
            if(C[di][dj] == -1 && S[di][dj] == '.') {
                C[di][dj] = C[pi][pj] + 1;
                Q.push({di, dj});
            }
        }
    }
    
    ll m = 0;
    FORR(_c,C) {
        FORR(c,_c) m = MAX(m,c);
    }
    
    return m;
}


int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    string s;
    REP(i,0,W+2) S[0] += "#";
    REP(i,1,H+1) {
        cin >> s;
        S[i] = '#' + s + '#';
    }
    REP(i,0,W+2) S[H+1] += "#";

    ll m = 0, c;
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            c = bfs(S, i, j);
            m = MAX(m,c);
        }
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main () {
  long long input, ans=0;
  cin >> input;
  for (long long i=1;i<=input;i++) {
    if (i%3!=0&&i%5!=0) ans+=i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string c, left, right;
    int a,b;
    while(cin >> c){
        if(c == "-") break;
        cin >> a;
        for (int i = 0; i < a; ++i)
        {
            cin >> b;
            c += c.substr(0, b);
            c.erase(0,b);
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    ll ng = -(ll)(1e18) - 10, ok = (ll)1e18 + 10;
    int N;
    ll K;
    cin >> N >> K;
    vll A(N);
    rep(i, N) {
        cin >> A[i];
    }
    sort(all(A));
    vll pos, neg;
    ll zer = 0;
    each(a, A) {
        if (a > 0)pos.push_back(a);
        else if (a < 0)neg.push_back(a);
        else zer++;
    }
    reverse(all(neg));

    while (ok - ng > 1) {
        ll x = (ok + ng) / 2;
        ll num = 0;

        auto f = [&](vll &X) {
            for (int i = 0, j = sz(X) - 1; i < j; ++i) {
                while (j > i && X[i] * X[j] > x) {
                    j--;
                }
                num += j - i;
            }
        };
        f(pos);
        f(neg);

        for (int i = sz(pos) - 1, j = 0; i >= 0; --i) {
            while (j < sz(neg) && pos[i] * neg[j] > x) {
                j++;
            }
            num += sz(neg) - j;
        }

        if (x >= 0) {
            num += zer * (N - zer) + zer * (zer - 1) / 2;
        }
        
        (num >= K ? ok : ng) = x;
    }

    cout << ok << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 4084
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
  double a, b, c, d;
  cin >> a >> b >> c >> d;
  std::string result = std::ceil(c/b) <=  std::ceil(a/d) ? "Yes": "No" ;

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3752
w,h,n = gets.split.map(&:to_i)
xs,xe = 0,w
ys,ye = 0,h

n.times do
  x,y,a = gets.split.map(&:to_i)
  case a
  when 1
    xs = [xs, x].max
  when 2
    xe = [xe, x].min
  when 3
    ys = [ys, y].max
  when 4
    ye = [ye, y].min
  end
end

puts [xe-xs, 0].max * [ye-ys, 0].max

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



int main(){
	string s;
	cin >> s;
	int cnt = 0;
	rep(i,0,s.size()){
		if (s[i] == 'o')cnt++;
	}
	if ((15-s.size())+cnt >= 8)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class A {
	int a, b, tmp, ans{ -10000000 };
public:
	void solve()
	{
		cin >> a >> b;

		tmp = a + b;
		if (ans < tmp) ans = tmp;
		tmp = a - b;
		if (ans < tmp) ans = tmp;
		tmp = a * b;
		if (ans < tmp) ans = tmp;

		cout << ans << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	//static int Border = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		String oprand = sc.next();
		int B = sc.nextInt();
		
		if(oprand.equals("+")){
			System.out.println( A+B);
		}
		else if (oprand.equals("-")){
			System.out.println( A - B);
		}else if (oprand.equals("*")){
			System.out.println( A * B);
		}else if (oprand.equals("/")){
			System.out.println( A / B);
		}
		
		
		// 文字列の入力
		
	}
	
}

Measured memory_bytes: 9684
#include <iostream>
#include <vector>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
  double r;cin >> r;
  printf("%lf %lf\n",M_PI*r*r,2*M_PI*r);
}

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

#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x

void solve(ll a, ll b){
	bool ans = false;
	char buff[10];
	sprintf(buff, "%lld%lld", a, b);
	ll n = atoi(buff);
	rep(i, 1000){
		if(i * i == n){
			ans = true;
			break;
		}
	}
	printf("%s\n", ans ? "Yes" : "No");
}

int main(void){
	ll a;
	ll b;
	scanf("%lld", &a);
	scanf("%lld", &b);
	solve(a, b);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#define G(x,y,z,t) ((((LL)(x))<<30)+((y)<<20)+((z)<<10)+(t))
unordered_map<LL,int> number;
struct sqare{
	int x0,x1,x2,x3;
	LL key[5];
	void ini(int a,int b,int c,int d){
		x0=a,x1=b,x2=c,x3=d;
		key[1]=G(a,b,c,d);
		key[2]=G(b,c,d,a);
		key[3]=G(c,d,a,b);
		key[4]=G(d,a,b,c);
	}
	void add(){
		for(int i=1;i<=4;i++) number[key[i]]++;
	}
	void dec(){
		for(int i=1;i<=4;i++) number[key[i]]--;
	}
}p[505];
LL calc(sqare fr,sqare bk){
	fr.dec();bk.dec();
	LL ret=0;
	for(int i=1;i<=4;i++){
		int t=bk.x0;bk.x0=bk.x1;bk.x1=bk.x2;bk.x2=bk.x3;bk.x3=t;
		LL ans=1;sqare key[5];
		key[1].ini(fr.x1,fr.x0,bk.x1,bk.x0);
		ans*=number[key[1].key[1]];key[1].dec();
		key[2].ini(fr.x2,fr.x1,bk.x0,bk.x3);
		ans*=number[key[2].key[1]];key[2].dec();
		key[3].ini(fr.x3,fr.x2,bk.x3,bk.x2);
		ans*=number[key[3].key[1]];key[3].dec();
		key[4].ini(fr.x0,fr.x3,bk.x2,bk.x1);
		ans*=number[key[4].key[1]];key[4].dec();
		ret+=ans;
		for(int j=1;j<=4;j++) key[j].add();
	}
	fr.add();bk.add();
	return ret;
}
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		p[i].ini(a,b,c,d);
		p[i].add();
	}
	LL ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(i!=j)
				ans+=calc(p[i],p[j]);
	cout<<ans/3<<endl;
	return 0;
}

Measured memory_bytes: 239576
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  
  vector<int> vec(a*b);
  for ( int i = 0 ; i < a*b ; i++ ) {
    cin >> vec.at(i);
  }
  
  vector<int> vec2(a);
  
  for ( int i = 0 ; i < a ; i++ ) {
      int count = 0;
    
    for ( int j = 0 ; j < a*b ; j++ ) {
      
      if ( vec.at(j) == i+1 ) {
        count++;
      }
    }
    
    vec2.at(i) = count;
  }
  
  for ( int i = 0 ; i < a ; i++ ) {
    cout << vec2.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VVVVI = vector<VVVI>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    VVVVI dp(n, VVVI(m, VVI(n, VI(m))));
    for(int i = n-1; i >= 0; i--) for(int j = m-1; j >= 0; j--) {
        if (s[i][j] == '#') continue;
        dp[i][j][i][j] = 1;
        if (i + 1 < n) {
            rep(k, n) rep(l, m) dp[i][j][k][l] |= dp[i+1][j][k][l];
        }
        if (j + 1 < m) {
            rep(k, n) rep(l, m) dp[i][j][k][l] |= dp[i][j+1][k][l];
        }
    }
    int cnt = 0;
    int sv = 2 * n * m, tv = sv + 1;
    mcf_graph<ll, ll> g(tv + 1);
    rep(i, n) rep(j, m) if (s[i][j] == 'o') {
        cnt++;
        g.add_edge(sv, i * m + j, 1, 0);
        rep(k, n) rep(l, m) if (dp[i][j][k][l]) {
            if (s[k][l] == '#') continue;
            assert(i <= k && j <= l);
            assert(100 - (k - i + l - j) >= 0);
            g.add_edge(i * m + j, n * m + k * m + l, 1, 100 - (k - i + l - j));
        }
    }
    rep(i, n) rep(j, m) if (s[i][j] != '#') g.add_edge(n * m + i * m + j, tv, 1, 0);
    auto t = g.flow(sv, tv, cnt);
    assert(t.first == cnt);
    ll ans = -(t.second - 100 * cnt);
    cout << ans << endl;
}


Measured memory_bytes: 37424
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define exists(x,m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	vi A = vi();
	rep(i, n) {
		int x; cin >> x;
		A.pb(x);
	}
	ll ans = 0;
	vll psums = {A[0]};
	for (int i = 1; i < n; i++) {
		psums.pb(psums[i-1] + A[i]);
		psums[i] %= MOD;
	}
	for (int i = 1; i < n; i++) {
		ll x = (psums[i-1] * A[i]) % MOD;
		ans += x;
		ans %= MOD;
	}
	cout << ans;
}

Measured memory_bytes: 6064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int N=200050;
const int M=2*N;
char col[N];
vector<int> E[M];
int cyc[M];
bool cycle=0;
void DFS(int u)
{
	cyc[u]=1;
	for(int v:E[u])
	{
		if(!cyc[v]) DFS(v);
		else if(cyc[v]==1) cycle=1;
	}
	cyc[u]=2;
}
int main()
{
	int n,m,i,u,v;
	scanf("%i %i",&n,&m);
	scanf("%s",col+1);
	for(i=1;i<=m;i++)
	{
		scanf("%i %i",&u,&v);
		if(col[u]==col[v]) E[u].pb(v+n),E[v].pb(u+n);
		else E[u+n].pb(v),E[v+n].pb(u);
	}
	for(i=1;i<=n;i++) if(!cyc[i]) DFS(i);
	if(cycle) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
     
    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long
    #define ld long double
     
    #define vi vector<int>
    #define vl vector<long>
    #define vll vector<long long>
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    
    #define ff first
    #define ss second
   
    #define pll pair<ll,ll> 
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll  
     
  
     
     
    //const ll N=1e6+7;
    ll p=1e9+7;
    //ll fac[N];
     
// taking inpugt with help of string and " "
     /*   string s;
         getline(cin,s);
         vi a=init(s);
         if(a.size()==2)cout<<query_(a[0]+1,a[1]+1)<<endl;
         else update_(a[0]+1,a[1]+1,a[2]);
 
      */
 vi init(string s)
{
    istringstream sin(s);
    int n;
    vi arr;
    while(sin>>n)arr.push_back(n);
    return arr;
}

    ll gcd(ll a, ll b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
    
    ll pow_mod_p(ll a,ll b)
    {
      a=a%p;
      ll res=1;
      while(b>0)
      {
        if(b&1) res=(res*a)%p;
        b=b>>1;
        a=(a*a)%p;
      }
      return res;
    }
     
    inline ll mod_inv(ll x)
    {
      return pow_mod_p(x,p-2);
    }
     
   
     int main() 
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE
        
     
        ll ntc=1;
     //   cin>>ntc;
     
        f(i,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";
         
         string s; cin>>s;
         ll ans = 0;
         for(int i =0; i< s.size(); ++i){
             ans  += s[i] - '0';
         }
         if(ans%9 == 0) cout<<"Yes"<<endl;
         else cout<<"No"<<endl;
          
        }
     
        return 0;
    }

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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;


int main()
{
	LL n, k;
	cin >> n >> k;
	
	vector<LL> a(n);

	for (auto &e : a) {
		cin >> e; e--;
	}

	vector<LL> vis(n, 0);

	vis[0] = 1;
	LL sz = 0;

	LL nxt = 0;
	LL cycnode = 0;

	vector<LL> arr;
	while (true) {
		vis[nxt] = 1;
		arr.push_back(nxt);
		nxt = a[nxt];
		sz++;
		if (vis[nxt]) {
			cycnode = nxt;
			break;
		}
	}

	vis.assign(n, 0);
	LL cycsz = 0;

	nxt = cycnode;
	vector<LL> cyc;

	while (!vis[nxt]) {
		cyc.push_back(nxt);
		vis[nxt] = 1;
		nxt = a[nxt];
		cycsz++;
	}

	if (k < sz) {
		cout << arr[k]+1 << "\n";
	}
	else {
		k -= (sz - cycsz);
		k %= cycsz;
		cout << cyc[k]+1 << "\n";
	}


}

Measured memory_bytes: 10804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>m;
ll a[222222];
ll n,k;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)a[i]=(a[i-1]+a[i]-1)%k;
	ll ans=0;
	m[0]++;
	for(int l=0,r=1;r<=n;r++){
		if(r-l==k)m[a[l++]]--;
		ans+=m[a[r]];
		m[a[r]]++;
	}cout<<ans<<endl;
}

Measured memory_bytes: 14336
n, q = map(int, input().split())

# make a list whose length is 2^i - 1.
num = 1
max_v = 2147483647

while num < n:
    num *= 2

A = [max_v for i in range(2 * num - 1)]


def update(i, x):
    i += num - 1
    A[i] = x

    while i > 0:
        i = (i - 1) // 2
        A[i] = min(A[i * 2 + 1], A[i * 2 + 2])

def find(a, b, k, l, r):
    if r <= a or b <= l:
        return max_v
    if a <= l and r <= b:
        return A[k]
    else:
        vl = find(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = find(a, b, k * 2 + 2, (l + r) // 2, r)
        return min(vl, vr)


for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        update(x, y)
    else:
        ans = find(x, y + 1, 0, 0, num)
        print(ans)

Measured memory_bytes: 11116
#include <bits/stdc++.h>
    #define ll int
    #define N 100000
    #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
    #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
    #define po pop_back
    #define pb push_back
    #define lb lower_bound
    #define fi first
    #define se second
    #define debug(x) cout << #x << " = " << x << endl
    #define ub upper_bound
    #define ibs ios_base::sync_with_stdio(false)
    #define cti cin.tie(0)
    #define all(x) x.begin(),x.end()
    #define PI 3.14159265
    #define cot cout.tie(0)
    using namespace std;
      /**
        * @author :: Sawlani
        *
        */

       ll n,k;
       ll a[101];
       ll dp[N+1][3];
       int main()
      {
         cin >> n >> k;

        memset(dp,-1,sizeof(dp));
         f(i,1,n) cin >> a[i];


         f(i,0,a[1]-1)
            dp[i][1]=2,dp[i][2]=1;


         f(i,a[1],k)
         {
              f(j,1,n)
              {
                   if(i>=a[j])
                   {
                       if(dp[i-a[j]][2]==1)
                        dp[i][1]=1;
                       if(dp[i-a[j]][1]==2)
                        dp[i][2]=2;
                   }
              }
              if(dp[i][1]==-1)
                dp[i][1]=2;
              if(dp[i][2]==-1)
                dp[i][2]=1;

        }

 
          if(dp[k][1]==1)
            cout <<  "First";
          else
            cout << "Second" ;

      }


Measured memory_bytes: 1408
/*input
11 10 9
*/

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans;
  if (n < b) ans = (a*n)/b;
  else ans = a-(a+b-1)/b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    while(s.back() == '#')s.pop_back();
    while(s.front() == '.')s.erase(s.begin());
    ll wcnt = 0;
    rep(i, s.size())if(s[i] == '.')++wcnt;
    ll ans = s.size()-wcnt;
    ll bcnt = 0; 
    rep(i, s.size()){
        if(s[i] == '#')ans = min(ans, wcnt+bcnt), ++bcnt;
        else --wcnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

vector<pair<int,int>> convex_hull(vector<pair<int,int>> P){
    int N=P.size();
    if(N<=1){
        return P;
    }
    vector<pair<int,int>> LH[2],V[2];
    sort(P.begin(),P.end());
    LH[0].push_back(P[0]);
    for(int i=0;i<N;i++){
        if((P[N-1].first-P[0].first)*(P[i].second-P[0].second)>=(P[N-1].second-P[0].second)*(P[i].first-P[0].first)){
            LH[1].push_back(P[i]);
        }else{
            LH[0].push_back(P[i]);
        }
    }
    LH[0].push_back(P[N-1]);
    reverse(LH[1].begin(),LH[1].end());
    
    for(int k=0;k<2;k++){
        for(int i=0;i<LH[k].size();i++){
            if(V[k].size()<2){
                V[k].push_back(LH[k][i]);
            }else{
                int j=V[k].size();
                if((V[k][j-1].first-V[k][j-2].first)*(LH[k][i].second-V[k][j-2].second)>=(V[k][j-1].second-V[k][j-2].second)*(LH[k][i].first-V[k][j-2].first)){
                    V[k].push_back(LH[k][i]);
                }else{
                    while(V[k].size()>=2){
                        j=V[k].size();
                        if((V[k][j-1].first-V[k][j-2].first)*(LH[k][i].second-V[k][j-2].second)<(V[k][j-1].second-V[k][j-2].second)*(LH[k][i].first-V[k][j-2].first)){
                            V[k].pop_back();
                        }else{
                            break;
                        }
                    }
                    V[k].push_back(LH[k][i]);
                }
            }
        }
    }
    
    P.clear();
    for(int i=0;i<V[1].size();i++){
        P.push_back(V[1][i]);
    }
    for(int i=1;i<V[0].size()-1;i++){
        P.push_back(V[0][i]);
    }
    return P;
}


signed main(void){
    int N;
    vector<pair<int,int>> P;
    map<pair<int,int>,int> M;
    double Ans[114]={};
    int x,y;
    cin >> N;
    REP(i,N){
        cin >> x >> y;
        P.push_back({x,y});
        M[{x,y}]=i;
    }
    P=convex_hull(P);
    //REP(i,P.size()){cout << P[i].first MM P[i].second << endl;}
    P.push_back(P[0]);
    double angle[114]={};
    REP(i,P.size()-1){
        double t=atan2(-(P[i+1].first-P[i].first),(P[i+1].second-P[i].second));
        angle[i]=t;
    }
    angle[P.size()-1]=angle[0];
    REP(i,P.size()-1){
        double k=angle[i+1]-angle[i];
        if(k<-PI)k+=2*PI;
        Ans[M[P[i+1]]]+=k;
    }
    
    //REP(i,P.size()-1){printf("%.8f\n",angle[i]);}
    
    double sum=0;
    REP(i,N){
        sum+=Ans[i];
    }
    REP(i,N){
        Ans[i]/=sum;
    }
    //printf("%.8f\n\n\n\n",sum/PI);
    REP(i,N){
        printf("%.8f\n",Ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
vector<vector<int>> happy(100010, vector<int>(3,0));
vector<vector<int>> dp(100010, vector<int>(3, 0));

int rec(int x, int y){
    if(x == 0) return 0;
    if(dp[x][y] != 0) return dp[x][y];
    
    rep(i, 3){
        if(i == y) continue;
        chmax(dp[x][y], rec(x-1, i) + happy[x-1][i]);
    }
    return dp[x][y];
}

int main(){
    cin >> n;
    rep(i, n){
        rep(j, 3){
            cin >> happy[i][j];
        }
    }
    rep(i, 3) rec(n, i);

    int ans = max(max(dp[n][0], dp[n][1]), dp[n][2]);
    cout << ans << ln;
}
    

Measured memory_bytes: 15232
#include <iostream>
using namespace std;
int m,n,j,k,f,g;
char c[101];
void acta() {
	for (j=0;j<m;j++) if (c[j]=='#') { c[j]='A'; break;}
}

void actb() {
	f=m-1;
	for (j=m-1;j>=0;j--) {
		if (c[j]!='#') continue;
		f=j;
		if (j==m-1) {if (c[m-2]!='A') break; else continue;} 
		if (j==0) {if (c[1]!='A') break; else continue;}
		if (c[j-1]!='A' && c[j+1]!='A') break;
	}
	c[f]='B';
}

void actc() {
	if (g==0) {c[m/2]='C'; return;}
	for (j=0;j<m;j++) {
	 if (c[j]!='#') {
		 if (j<m-1) if (c[j+1]=='#') { c[j+1]='C'; break;}
		 if (j>0) if (c[j-1]=='#') { c[j-1]='C'; break;}
	 }   	
	}
}
void actd() {
	int l=0,sx=0,x=0;
	f=0;
	if (g==0) {c[0]='D';return;}
	for (j=0;j<m;j++) {
		if (c[j]!='#') {
			if (f==0) { x=0; l=j;} else { if ((j-sx)/2>l) { l=(j-sx)/2; x=sx+l;}}
			sx=j; f=1;
		} else if (j==m-1) if (j-sx>l) x=j;
	}
	c[x]='D';
}
int main() {
	int i;
	char a;
	while(cin >> m >> n) {
		if (m+n==0) break;
		for (i=0;i<m;i++) c[i]='#'; c[i]='\0'; g=0;
		for (i=0;i<n;i++) {
			cin >> a;
			switch(a) {
				case 'A': acta(); break;
				case 'B': actb(); break;
				case 'C': actc(); break;
				case 'D': actd(); break;
			}
			g=1;
		}
		cout << c << endl;
	}	 
			  			
	return 0;
}

Measured memory_bytes: 1156
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10 ** 9 + 7

Y = 0
for i in range(1, m + 1):
    Y += (i - 1) * y[i - 1] - (m - i) * y[i - 1]
    Y %= mod

X = 0
for i in range(1, n + 1):
    X += (i - 1) * x[i - 1] - (n - i) * x[i - 1]
    X %= mod

print(X * Y % mod)


Measured memory_bytes: 18624
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	static int Y_MIN = 0;
	static int X_MAX = 600;
	
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
			int X_TANI = sc.nextInt();
			int MENSEKI = 0;
			
			for(int i=X_TANI; i < X_MAX; i += X_TANI){
				MENSEKI += X_TANI * i * i;
			}
			
			System.out.println(MENSEKI);
        }
	}
}

Measured memory_bytes: 17180
#include<stdio.h>
int gcd(int x, int y){
  while(y!=0){
    int r=x%y;
    x=y;
    y=r;}
  return x;
}
int main(void){
  int K;
  int i,j,l;
  int wa=0;
  scanf("%d",&K);
  for(i=1;i<=K;i++){
    for(j=1;j<=K;j++){
      for(l=1;l<=K;l++){
        wa=wa+gcd(gcd(i,j),l);}
    }
  }
  printf("%d",wa);
  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
using namespace std;
int main() {
	int a,b,c,d,e;
	while(true){
		d=0;
		e=0;
		cin>>a;
		if(a==0){
			break;
		}
		for(int i=0;i<a;i++){
			cin>>b>>c;
			if(b>c)
				d=d+b+c;
			else if(c>b)
				e=e+b+c;
			else{
				e=e+c;
				d=d+c;
			}
		}
		cout<<d<<" "<<e<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n, k, sum=0;
	cin >> n >> k;
	vi v(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum += min(v[i], abs(v[i] - k));
	}
	cout << sum*2 << endl;
}


Measured memory_bytes: 256
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N];

void  solve(){

}
int32_t main()
{
    FIO
    int n;cin>>n;
    int xorval=0;
    fi(i,n) {
        cin>>a[i];
        xorval^=a[i];
    }
    fi(i,n) cout<<(xorval^a[i])<<" "; cout<<"\n"; 
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL x;
    cin >> x;

    LL n = x / 11;
    LL N = n * 11;

    n <<= 1;
    if(x - N > 0 && x - N < 7)
        n++;
    else if(x - N > 6)
        n += 2;

    cout << n << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  lint A, B; cin >> A >> B;
  V<> p(n); for (auto&& e : p) cin >> e, --e;
  V<lint> dp(n + 1);
  for (int x = 0; x < n; ++x) {
    int j = find(begin(p), end(p), x) - begin(p);
    int c = 0;
    for (int i = j + 1; ; ++i) {
      if (c) dp[i] += A;
      dp[i] = min(dp[i], B * c + dp[j]);
      if (i == n) break;
      c += p[i] < x;
    }
  }
  cout << dp.back() << '\n';
}

Measured memory_bytes: 384