akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

// stackとかqueueうまく使うぽい

int par[30], ch[30][2];
vector<int> ans1,ans2,ans3;
int findGrandPar(int v){
  if(par[v] == v){
    return v;
  }
  return findGrandPar(par[v]);
}
// 先行順
void f1(int v){
  ans1.push_back(v);
  FOR(i,0,2){
    if(ch[v][i]!=-1){
      f1(ch[v][i]);
    }
  }
}
// 中間順
void f2(int v){
    if(ch[v][0]!=-1){
      f2(ch[v][0]);
    }
    ans2.push_back(v);
    if(ch[v][1]!=-1){
      f2(ch[v][1]);
    }
}
// 後行順
void f3(int v){
  FOR(i,0,2){
    if(ch[v][i]!=-1){
      f3(ch[v][i]);
    }
  }
  ans3.push_back(v);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  FOR(i,0,30) par[i] = i;
  FOR(i,0,n){
    int id,l,r;
    cin>>id>>l>>r;
    ch[id][0]=l;
    ch[id][1]=r;
    if(l!=-1)par[l]=id;
    if(r!=-1)par[r]=id;
  }
  int root = findGrandPar(0);
  f1(root);
  f2(root);
  f3(root);
  cout << "Preorder" << endl;
  FOR(i,0,n){
    cout << " ";
    cout << ans1[i];
  }
  cout << endl;
  cout << "Inorder" << endl;
FOR(i,0,n){
    cout << " ";
    cout << ans2[i];
  }
  cout << endl;
  cout << "Postorder" << endl;
  FOR(i,0,n){
    cout << " ";
    cout << ans3[i];
  }
  cout << endl;
}


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

using ll = long long;
const int INF = INT_MAX;//2147483647
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


int main() {

	int n;
	cin >> n;
	vector<vector<int>> a(n+1,vector<int>(3,0));
	repeq(i,n){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}

	//dp[i][j] i日にjを行なった場合の最大値
	vector<vector<int>> dp(n+1,vector<int>(3,0));
	
	for(int i=1;i<=n;i++){
		rep(j,3){
			int max=0;
			rep(k,3){
				if(j==k)continue;
				chmax(max,dp[i-1][k]+a[i][j]);
			}
			dp[i][j]=max;
		}
	}
	int max=*max_element(dp[n].begin(),dp[n].end());
	p(max);
	return 0;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int nums[3];
    for (int i=0; i<3; i++) cin >> nums[i];
    sort(nums, nums+3);
    cout << nums[2]*10 + nums[1] + nums[0] << endl;
    return 0;
}


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
from bisect import *

A, B, Q = map(int, input().split())
s = [-10**18]+[int(input()) for _ in range(A)]+[10**18]
t = [-10**18]+[int(input()) for _ in range(B)]+[10**18]

for _ in range(Q):
    x = int(input())
    idx1 = bisect_right(s, x)
    idx2 = bisect_right(t, x)
    ls, rs = s[idx1-1], s[idx1]
    lt, rt = t[idx2-1], t[idx2]
    ans = 10**18
    
    for p1, p2 in [(ls, lt), (ls, rt), (rs, lt), (rs, rt), (lt, ls), (lt, rs), (rt, ls), (rt, rs)]:
        ans = min(ans, abs(p1-x)+abs(p2-p1))
    
    print(ans)

Measured memory_bytes: 61788
N, M, X = map(int, input().split())
A = []
C = []
for i in range(N):
    tmp = list(map(int, input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])

INF = float('INF')
min_cost = INF


def dfs(i, cost, learn):
    if i == N:
        if min(learn) >= X:
            return cost
        else:
            return INF
    else:
        new_learn = [x + y for (x, y) in zip(A[i], learn)]
        cost = min(dfs(i + 1, cost, learn), dfs(i + 1, cost + C[i], new_learn))
        return cost


min_cost = dfs(0, 0, [0] * M)

if min_cost == INF:
    print(-1)
else:
    print(min_cost)

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

int main(){
	int w, h, x, y;
	cin >> w >> h >> x >> y;

	double ans = (double)w*h/2;
	int res = 0;
	if(w%2 != 0 || h%2 != 0) res = 0;
	else if(x == w/2 && y == h/2) res = 1;

	if(res) cout << fixed << setprecision(10) << ans << " " << res << endl;
	else cout << fixed << setprecision(10) << ans << " " << res << endl;

	return 0;
}

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

typedef long long ll;

ll n;
vector<long long> bit(200010,0);
void add(int a, int w) {
	for (int x = a;x <= 2*n+1;x += x&-x) bit[x] += w;
}
int sum(int a) {
	int ret = 0;
	for (int x = a;x > 0;x -= x&-x) ret += bit[x];
	return ret;
}

int main() {
    vector<int> a(100010,0);
    cin >> n;
    for (int i = 0;i < n;++i) cin >> a[i];

    int min = 0,max = 1000000010;
    ll m = n*(n+1)/2;
    m = (m+1)/2;
    while (1) {
        ll ret = 0;
        int mid = min+(max-min)/2;
        vector<int> b(n+1);
        for (int i = 1;i <= n;++i) {
            b[i] = ((a[i-1] < mid) ? -1 : 1);
        }
        for (int i = 1;i <= n;++i) b[i] += b[i-1];
        bit = vector<ll>(200010,0);
        for (int i = n;i >= 0;--i) {
            ret += n-i-sum(n+b[i]);
            add(n+1+b[i],1);
        }
        if (ret < m) max = mid;
        else if (min == mid) break;
        else min = mid;
    }
    cout << min << endl;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n;
  cin >> n;

  ll na = 2, nb = 1, nc;
  REP(i, n - 1) {
    nc = nb + na;
    na = nb;
    nb = nc;
  }

  if (n == 1) {
    cout << 1 << "\n";
  } else {
    cout << nc << "\n";
  }
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
ll A, B;
ll h[100000];

bool isOK(ll m){
	ll need = 0;
	rep(i, N){
		if(h[i]-B*m > 0){
			need += (h[i]-B*m + A-1) / A;
		}
	}
	return need <= m;
}

signed main(){
	cin >> N >> A >> B;
	A -= B;
	rep(i, N) cin >> h[i];
	sort(h, h+N);

	ll ok = 1'000'000'000;
	ll ng = 0;
	while(ok-ng > 1){
		ll m = (ok+ng) / 2;
		if(isOK(m)) ok = m;
		else ng = m;
	}
	cout << ok << endl;
}

Measured memory_bytes: 4384
def calc(pp,x,y):
    p = 0
    for i in range(1,1000):
        if i*(100+x)/100 == pp:
            p = i
            break
    return p*(100+y)/100

while True:
    max = 0
    x,y,s = map(int,raw_input().split())
    if x == 0 and y == 0 and s == 0:
        break
    for i in range(1,s):
        res = calc(i,x,y) + calc(s-i,x,y)
        if max < res:
            max = res
    print max

Measured memory_bytes: 4256
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int N, D, x[20][20];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> N >> D;
  rep(i, 0, N) rep(j, 0, D) 
    cin >> x[i][j];
    
  int ans = 0;
  rep(i, 0, N) {
    rep(j, i+1, N) {
      int powed = 0;
      rep(k, 0, D) {
        int t = abs(x[i][k] - x[j][k]);
        powed += t * t;
      }
      bool flag = false;
      erep(k, 0, powed) {
        if (k * k == powed) {
          flag = true;
          break;
        }    
      }
      if (flag) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int H, W;  cin >> H >> W;
	int N;  cin >> N;
	for(int i = 0 ; i <= min(H, W) ; i++){
		if(max(H, W) * i >= N){
				cout << i << endl;
				return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
//
void p(int x, int y) {
  printf("%d %d\n", x, y);
}
int main() {
  int n = getint();
  int bit = 0;
  while ((1 << bit) < n) ++bit;
  if ((1 << bit) == n) return !printf("No\n");
  printf("Yes\n");
  p(1, n + 2); p(n + 2, 3);
  p(3, n + 1); p(n + 1, 2); p(2, n + 3);
  for (int i = 4; i + 1 <= n; i += 2) {
    p(i, n + 1); p(i, n + i + 1);
    p(i + 1, n + 1); p(i + 1, n + i);
  }
  if (!(n & 1)) {
    for (int i = 2; i <= n - 1; i++) if ((n ^ 1 ^ i) < n) {
      p(i, n);
      p(n ^ 1 ^ i, 2 * n);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  vector<bool> v(250000,true);
  for(int i=2; i<250000; i++){
    if(!v[i]) continue;
    for(int j=i*2; j<250000; j+=i){
      v[j] = false;
    }
  }
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    int count = 0;
    for(int i=n+1; i<=2*n; i++){
      if(v[i]) count++;
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>

int top=0;
int stack[1000];

void push(int n){
  stack[++top]=n;
}

int pop(void){
  top--;
  return stack[top+1];
}

void calc(char op){
  int n1=pop(), n2=pop();
  if(op=='+') push(n1+n2);
  if(op=='-') push(n2-n1);
  if(op=='*') push(n2*n1);
}

int main(void){
  char a[1000];
  int t,s;
    while(scanf("%s",&a)!=EOF){
      if(a[0]=='+' || a[0]=='-' || a[0]=='*') calc(a[0]);
      else push(atoi(a));
    }
  printf("%d\n",pop());
  return 0;
}

Measured memory_bytes: 1852
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a!=b&&a!=c&&b!=c){cout<<3<<endl;}
  if(a==b&&a!=c&&b!=c||a==c&&a!=b&&c!=b||b==c&&b!=a&&c!=a){cout<<2<<endl;}
  if(a==b&&a==c&&b==c){cout<<1<<endl;}
  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  int sz = N * 2;
  vector<int> R(sz, -1);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    R[a] = b;
  }
  vector<int> B(sz, -1);
  for (int i = 0; i < N; i++) {
    int c, d;
    cin >> c >> d;
    B[c] = d;
  }
  int ans = 0;
  set<int> reds;
  for (int i = 0; i < sz; i++) {
    if (i > 0 and R[i - 1] != -1) reds.insert(R[i - 1]);
    if (B[i] == -1) continue;
    auto lb = reds.lower_bound(B[i]);
    if (lb == reds.begin()) continue;
    lb--;
    reds.erase(*lb);
    ans++;
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

int main(void){
    long long int n, ans = 1000;
    cin >> n;
    while(n >= 100){
        long long int tmp = n % 1000 - 753;
        if (tmp < 0) tmp *= -1;
        ans = min(ans, tmp);
        n /= 10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : Eaugene Thomas
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() {
faster;
int n=0;
cin>>n;
lli a,b;
cin>>a>>b;

lli x[n],y[n];

for(int i=0;i<n;i++)
{
	cin>>x[i]>>y[i];
}

int c=0;

for(int i=0;i<n;i++)
{
	if(x[i]>=a&&y[i]>=b)
		c++;
}
cout<<c<<"\n";
return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i + 1 < n; i++) {
    cin >> b[i];
  }
  int ans = b[0] + b.back();
  for (int i = 0; i + 2 < n; i++) {
    ans += min(b[i], b[i + 1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;

int main(){
	int h,w;
	cin>>h>>w;
	char c[h][w];
	for(ll i=0; i<h; i++){
		for(ll j=0; j<w; j++){
			cin>>c[i][j];
		}
	}
	for(ll i=0; i<h; i++){
		for(ll j=0; j<w; j++){
			if(c[i][j]=='.' || c[i][j]=='F'){
				bool ok=true;
				for(ll k=0; k<w; k++){
					if(c[i][k]=='#'){
						ok=false;
						break;
					}
				}
				if(ok==true){
					for(ll k=0; k<w; k++){
						c[i][k]='F';
					}
				}
				bool ok2=true;
				for(ll k=0; k<h; k++){
					if(c[k][j]=='#') {
						ok2=false;
						break;
					}
				}
				if(ok2==true){
					for(ll k=0; k<h; k++){
						c[k][j]='F';
					}
				}
			}
		}
	}
	for(ll i=0; i<h; i++){
		bool ok=true;
		for(ll j=0; j<w; j++){
			if(c[i][j]!='F'){
				cout<<c[i][j];
				ok=false;
			}
		}
		if(ok==false) cout<<endl;
	}
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.algorithm,
  std.array, std.conv, std.typecons;

alias Tuple!(ulong, "win", ulong, "lose") Record;

void main() {
  for(int n; readf("%d\n", &n), n != 0;) {
    Record[string] table;
    int[string] ids;
    for(int i = 0; i < n; i++) {
      string[] line = readln.chomp.split(" ");
      int[] data = line[1..$].map!(to!int).array;
      table[line[0]] = Record(data.filter!(x => x == 0).array.length,
                        data.filter!(x => x == 1).array.length);
      ids[line[0]] = i;
    }
    string[] keys = table.keys;
    sort!((x, y) {
        if (table[x].win != table[y].win) return table[x].win > table[y].win;
        else if (table[x].lose != table[y].lose) return table[x].lose < table[y].lose;
        else return ids[x] < ids[y];
      })(keys);
    foreach(k; keys) writeln(k);
  }
}

Measured memory_bytes: 1256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s1[64], s2[64];
	scanf("%s%s", s1, s2);
	long long int ans[64];
	long long int p = 1000000007;
	int i;
	if (n == 1)
	{
		printf("3\n");
		return 0;
	}
	if (n == 2)
	{
		printf("6\n");
		return 0;
	}
	ans[1] = 6;
	i = 2;
	if (s1[1] == s1[2])
	{
		ans[2] = ans[1];
		i = 3;
	}
	for (; i < n - 1; i++)
	{
		if (s1[i - 2] != s1[i - 1])
		{
			if (s1[i] != s1[i + 1])
				ans[i] = ans[i - 1] * 2;
			else
			{
				ans[i + 1] = ans[i] = ans[i - 1] * 2;
				i++;
			}
		}
		else
		{
			if (s1[i] != s1[i + 1])
				ans[i] = ans[i - 1];
			else
			{
				ans[i + 1] = ans[i] = ans[i - 1] * 3;
				i++;
			}
		}
		ans[i] %= p;
	}
	if (s1[n - 1] != s1[n - 2])
	{
		if (s1[n - 2] != s1[n - 3])
			ans[n - 1] = ans[n - 2] * 2;
		else
			ans[n - 1] = ans[n - 2];
	}
	printf("%lld\n", ans[n - 1] % p);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int[] dish = new int[5];
		for(int i = 0; i < 5; i++){
		    dish[i] = sc.nextInt();
		}
		
		// 計算
		int result = 0;
		int rest = 10;
		int index = 0;
		for(int i = 0; i < 5; i++){
		    if(rest > dish[i]%10 && dish[i]%10 > 0){
		        rest = dish[i]%10;
		        index = i;
		    }
		}
		for(int i = 0; i < 5; i++){
		    if(i != index) result += ((dish[i] + 9)/10)*10; 
		}
		result += dish[index];
		
		// 出力
		System.out.println(result);
        
	}
}

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

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N+1), B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll res = 0;
    rep (i, N) {
        if (A[i] >= B[i]) {
            res += B[i];
        }
        else {
            res += A[i];
            B[i] -= A[i];
            ll attack = min(B[i], A[i+1]);
            A[i+1] -= attack;
            res += attack;
        }
    }

    cout << res << endl;

    return 0;
}

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

vector<int> A;

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

    sort(A.rbegin(),A.rend());

    int m=A[0]*10+A[1]+A[2];

    cout << m << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s = buf.trim();
	let v: Vec<char> = s.chars().collect();
	let L = v.len();
	let mut cnt = 0;
	for n in 0..(L/2) {
		if v[n] != v[L - 1 - n] {
			cnt = cnt + 1;
		}
	}
	println!("{}", cnt);
}

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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

ll A,B,N;
void input()
{
    cin>>A>>B>>N;
}

void solve()
{
    if(B>N) cout<<(A*N)/B-(N/B)*A<<endl;
    else cout<<(A*(B-1))/B-((B-1)/B)*A<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

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

		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    if(a > b) {
		      System.out.println(a - 1);
		    }
		    else {
		      System.out.println(a);
		    }
		  }
		}

Measured memory_bytes: 21844
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
    char c;
    cin >> c;

    if (c == 'A')
        cout << "T" << endl;
    if (c == 'C')
        cout << "G" << endl;
    if (c == 'G')
        cout << "C" << endl;
    if (c == 'T')
        cout << "A" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cctype>
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vll;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define sortA(v) sort(v.begin(), v.end())
#define fill(a) memset(a, 0, sizeof(a))

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define FOR_REV(i, a ,b) for(int i = a; i >= b; i--)
#define REP(i, n) FOR(i, 0, n)


void test() {
    int n, x ,t;
    cin >> n >> x >> t;
    cout << (int) ceil((double) n / (double) x) * t;
}   
 
int main ()     
{
    // int t;
    // cin >> t;
    // while(t--) 
        test();
}


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  string s; cin >> s;
  if(s.back()=='s') s += "es";
  else  s += 's';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

#define rep(i, a, n) for(int i = a; i < (n); ++i)

int main()
{
  int n;
  cin >> n;
  
  int left = 0, right = 0;
  vector<int> w(n);
  rep(i, 0, n) {
    cin >> w[i];
    right += w[i];
  }
  
  int ans = 1e9+7;
  rep(i, 0, n)
  {
    left += w[i];
    right -= w[i];
    ans = min(ans, abs(right - left));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i+1];
  vector<int> b(n+1);
  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int j = i+i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum^a[i];
  }
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  rep(i,ans.size()) {
    printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
  }
  return 0;
}




Measured memory_bytes: 5340
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int array[] = new int[3];
		int number = 0;
		int max = 0;
		int exe1 = 0;
		int exe2 = 0;
		int answer = 0;
		//これから3つの数字の最大値を検索する関数を作る
		//1,配列作成、配列の初期化
		for(int i = 0;i < 3;i++){
			array[i] = sc.nextInt();
		}
		int a = sc.nextInt();
		//2,三つのうち最大の数字を取得
		kesu:for(int i = 0;i < 3;i++){
		number = 0;
		for(int n = 0;n < 3;n++){
			if(array[i] >= array[n]){
				number++;
				if(number == 3){
					max = array[i];
					if(i == 0){
						exe1 = array[1];
						exe2 = array[2];
					}else if(i == 1){
						exe1 = array[0];
						exe2 = array[2];
					}else if(i == 2){
						exe1 = array[0];
						exe2 = array[1];
					}


															break kesu;
				}
			}
		}

		}
		for(int i = 0;i < a;i++){
		max = max * 2;
		}
		answer = max + exe1 + exe2;


		System.out.println(answer);
		
		
	
	}
}


Measured memory_bytes: 22740
import java.util.Scanner;

class Main{

  private static int solve(int[][] play){
      int N = play.length;
      int K = play[0].length;

      //int max = Math.max(play[0][0], Math.max(play[0][1], play[0][2]));
      int[][] dp = new int[N][K];
      dp[0][0] = play[0][0]; dp[0][1] = play[0][1]; dp[0][2] = play[0][2];
      for(int i = 1; i < N; i++){
          dp[i][0] = play[i][0] + Math.max(dp[i-1][1], dp[i-1][2]);
          dp[i][1] = play[i][1] + Math.max(dp[i-1][0], dp[i-1][2]);
          dp[i][2] = play[i][2] + Math.max(dp[i-1][0], dp[i-1][1]);
      }
      return Math.max(dp[N-1][0], Math.max(dp[N-1][1], dp[N-1][2]));
  }


  public static void main(String... args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();

      int[][] play = new int[N][3];

      for(int i = 0; i< play.length; i++){
        for(int j = 0; j < play[0].length; j++){
            play[i][j] = sc.nextInt();
        }
      }

      System.out.println(solve(play));
      if(sc != null)
        sc.close();
  }
}

Measured memory_bytes: 98900
import java.util.Scanner;

public class Main {

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

    int h = sc.nextInt();
    int n = sc.nextInt();

    int sum = 0;

    for (int i = 0; i < n; i++) {
      sum += sc.nextInt();
    }

    if (h <= sum) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}


Measured memory_bytes: 48304
f = [0] * (10 ** 4 + 1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            w = x * x + y * y + z * z + x * y + y * z + z * x
            if w < len(f):
                f[w] += 1
n = int(input())
for i in range(1, n + 1):
    print(f[i])

Measured memory_bytes: 69176
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    a, b = map(int, input().split())
    if a >= 10 or b >= 10:
        print(-1)
    else:
        print(a*b)



    
            
    

    

    

if __name__ == '__main__':
    main()


Measured memory_bytes: 5984
main = do
  [n, m, _X, _Y] <- map read . words <$> getLine :: IO [Int]
  x <- map read . words <$> getLine :: IO [Int]
  y <- map read . words <$> getLine :: IO [Int]
  putStrLn $ if maximum (_X:x) < minimum (_Y:y) then "No War" else "War"

Measured memory_bytes: 1020
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll M, D;
    cin >> M >> D;
    ll ans = 0;
    for(ll m = 1; m <= M; m++){
        for(ll d = 1; d <= D; d++){
            ll d1 = d % 10;
            ll d10 = d / 10;
            if(d1 >= 2 && d10 >= 2 && d1 * d10 == m)ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define ull unsigned long long
const double EPS = 1e-10;

ull pow_ans(ull x, int n) {
    ull res = 1;
    while (n > 0) {
        if (n & 1) { res *= x; }
        x *= x;
        n >>= 1;
    }
    return res;
}


int main(){
  string t,p;
  cin>>t;
  cin>>p;
  ull b=1000000009;
  vector<ull> a;
  ull sum=0;
  ull ans=0;
  if(t.size()<p.size())return 0;
  for(int i=0;i<p.size();i++){
    ans+=p[i]*pow_ans(b,p.size()-1-i);
  }
  for(int i=0;i<p.size();i++){
    sum+=t[i]*pow_ans(b,p.size()-1-i);
  }
  if(ans==sum)cout<<0<<endl;
  a.push_back(sum);
  for(int i=0;i<(int)t.size()-(int)p.size();i++){
    sum-=t[i]*pow_ans(b,p.size()-1);
    sum*=b;
    sum+=t[i+p.size()];
    a.push_back(sum);
    if(ans==sum)cout<<i+1<<endl;
  }
}



Measured memory_bytes: 12724
from sys import stdin

def fun():
    s = input()
    s2 = s.split("/")
    year = int(s2[0])
    month =int(s2[1])
    day = int(s2[2])

    if year < 2018:
        print("Heisei")
    elif month < 5:
        print("Heisei")
    else:
        print("TBD")


if __name__ == '__main__':
    fun()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int a, b, c;
	cin >>a >> b >> c;
	bool ok = false;
	if (a == 1) ok = true;
	for (int i = 1; i < b; i++)
	{
		int p = i * a;
		if (p % b == c) ok = true; 
	}
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 11;
int N, D;
int X[MAX_N][MAX_N];

signed main()
{
  cin >> N >> D;
  REP(n,N) {
    REP(d,D) {
      cin >> X[n][d];
    }
  }

  int ans = 0;
  REP(n1,N) {
    FOR(n2,n1+1,N) {
      int k = 0;
      REP(d,D) {
        k += (X[n1][d] - X[n2][d]) * (X[n1][d] - X[n2][d]);
      }
      if((double)(sqrt(k)) == (int)sqrt(k)) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn*2];
int ans[maxn*2];
struct Node
{
    int x,y;
}s[maxn*2];
int maxpr[maxn*2];
int maxed[maxn*2];
int main()
{
    int r;
      cin>>r;
 cout<<ll(3*r*r)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AOneCardPoker {
public:
	void solve(istream& in, ostream& out) {
        int a, b;
        in >> a >> b;
        if(a == 1 && b != 1) out << "Alice" << endl;
        else if(b == 1 && a != 1) out << "Bob" << endl;
        else if(a == b) out << "Draw" << endl;
        else if(a > b) out << "Alice" << endl;
        else if(a < b) out << "Bob" << endl;
 	}
};

int main() {
	AOneCardPoker solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 384
from collections import Counter
import sys

mod = 998244353

n = int(input())
d = [int(v) for v in input().split()]

if d[0] != 0:
    print(0)
    sys.exit(0)

if len(d) == 1:
    print(1)
    sys.exit(0)

cnt = Counter(d[1:])
keys = sorted(cnt.keys())
for i in range(len(keys)):
    if keys[i] != i+1:
        print(0)
        sys.exit(0)

tree = [cnt[k] for k in sorted(cnt.keys())]

ans = 1
for i in range(len(tree) - 1):
    ans *= tree[i] ** tree[i+1]
    ans %= mod

print(ans)


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

int main() {
  std::string O, E;
  std::cin >> O;
  std::cin >> E;

  int i, j, k;
  i = j = k = 0;
  int n = O.length();
  int m = E.length();
  while (true) {
    if ( k % 2 == 0 ) {
      std::cout << O[i];
      ++i;
    } else {
      std::cout << E[j];
      ++j;
    }
    ++k;
    if ( n == i && m == j ) break;
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

if INT() >= 30:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27288
#include<iostream>
#include<queue>
using namespace std;
int main(){
  int n;
  int k;
  int maxim=0;
  priority_queue<int>pq;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int data;
    cin>>data;
    pq.push(data);
  }
  for(int i=0;i<k;i++){
    maxim+=pq.top();
    pq.pop();
  }
  cout<<maxim<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d});
}

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

int main() {

  int a, b;
  
  std::cin >> a >> b;
  if( a > b ) {
    std::swap(a, b);
  }
  while( a != 0 ) {
    b = b % a;
    std::swap(a, b);
  }

  std::cout << b << std::endl;
  
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a;
	cin>>a;
	int long long b=0;
	rep(i, a){
		if((i+1)%3!=0 && (i+1)%5!=0){
			b+=i+1;
		}
	}
	cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int> (3));
    rep(i,n) {
        rep(j,3) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(n, vector<int> (3)); // dp[i][j] := i日目に活動jを行う(i-1日目はj以外の活動を行った)
    dp[0] = a[0];
    rep(i,n) {
        if (i == 0) continue;
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + a[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + a[i][2];
    }
    int ans = max(dp[n-1][0],dp[n-1][1]);
    ans = max(ans, dp[n-1][2]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14304
import java.util.Scanner;
import java.lang.Math;
import java.math.BigDecimal;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = a + b;
    int num = Integer.parseInt(c);
    double k = Math.sqrt(num);
    BigDecimal bd = new BigDecimal(k);
    BigDecimal bd3 = bd.setScale(0, BigDecimal.ROUND_DOWN); 
    double x = bd3.doubleValue();
    if(k == x){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
def main():
    n = int(input())
    c = [i for i in input()]
    ans = 0
    cnt = 0
    cnt2 = 0
    for i in range(n):
        if c[i] =="R":
            cnt += 1
    for i in range(cnt):
        if c[i] == "R":
            cnt2 += 1
    ans = cnt - cnt2
    
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 10868
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

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

  int res = 0, mi = n+1;

  for(int i=0; i<n; ++i){
    int p;
    cin >> p;
    mi = min(mi, p);
    if(mi == p) res++;
  }
  cout << res;
}


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

int main(){
	int n,k;
	cin>>n>>k;
	
	int a[n];
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	int dp[n];
	memset(dp,1000000,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<n-1;i++){
		for(int j=1;j<=k;j++){
			if((i+j)<n)
			dp[i+j]=min((dp[i]+abs(a[i+j]-a[i])),dp[i+j]);
		}
	}
	cout<<dp[n-1];
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i > 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll N, M;
    cin >> N >> M;

    vector<ll> A(M);
    REP(i, M) cin >> A[i];
    ll sum = 0;
    REP(i, M) sum += A[i];
    PRINT(max(N-sum, -1LL));
    return 0;
}


Measured memory_bytes: 3688
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>
#pragma optimize("", off)
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {
    ll h, w;
    cin >> h >> w;
    vector<bool> v;
    v[0];
    vector<int> v2;
    v2[0];
    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = true;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = false;
    dp[0][0][-b[0][0] + a[0][0] + mid] = false;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if(i + 1 <= h - 1) {

                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] &= dp[i][j][l];
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] &= dp[i][j][l];
                }
                if(j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] &= dp[i][j][l];
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] &= dp[i][j][l];
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if(!dp[h - 1][w - 1][i])
            ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 160256
#include <bits/stdc++.h>
#include "atcoder/all"

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[100005];

struct UnionFind {
    UnionFind(int n) {
        rank.assign(n, 0);
        parent.resize(n);
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

    int find(int x) {
        if (x == parent[x])
            return x;
        return parent[x] = find(parent[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (rank[x] < rank[y]) {
            parent[x] = y;
        }
        else {
            parent[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }

    vector<int> rank;
    vector<int> parent;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i, M) {
        cin >> A[i].first >> A[i].second;
        uf.unit(A[i].first - 1, A[i].second - 1);
    }

    vector<ll> v;
    REP(i, N) {
        v.push_back(uf.find(i));
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 6664
N, M = map(int, input().split())
ans = 0
if N == M == 1:
	ans = 1
elif N == 1 and M >= 2:
	ans = M - 2
elif N >= 2 and M == 1:
	ans = N - 2
else:
	ans = (N - 2) * (M - 2)
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll tmp;
void swap(ll i,ll j){
  tmp=i;
  i=j;
  j=tmp;
}
int main(){
  int n,m,q;
  cin >> n >> m >> q;
  m++;
  int a[q],b[q],c[q],d[q];
  rep(i,q)cin >> a[i] >> b[i] >> c[i] >> d[i];
  vector<int> x(10);
  int ans=0;
  int r=0;
  for(x[0]=1;x[0]<m;x[0]++){
    for(x[1]=x[0];x[1]<m;x[1]++){
      for(x[2]=x[1];x[2]<m;x[2]++){
        for(x[3]=x[2];x[3]<m;x[3]++){
          for(x[4]=x[3];x[4]<m;x[4]++){
            for(x[5]=x[4];x[5]<m;x[5]++){
              for(x[6]=x[5];x[6]<m;x[6]++){
                for(x[7]=x[6];x[7]<m;x[7]++){
                  for(x[8]=x[7];x[8]<m;x[8]++){
                    for(x[9]=x[8];x[9]<m;x[9]++){
                      rep(i,q){
                        if(x[b[i]-1]-x[a[i]-1]==c[i])r+=d[i];
                      }
                      if(r>ans)ans=r;
                      r=0;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3632