akhauriyash/Code-Regression huggingface dataset:
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;
int main(){
  string s;
  cin>>s;
  int flag=0;
  rep(i,s.size())rep(j,s.size()){
    if(s[i]==s[j]){
      flag++;
    }
  }
  cout<<(flag==s.size()?"yes":"no")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define deb(x) cerr<<#x<<" : "<<x<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int,int>
#define PI   3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i=n-1;i>=x;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
#define INF 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
const int N=2e5+5;
signed main()
{
	fast
	string s;
	cin>>s;
	if(s[s.length()-1]!='s') s+="s";
	else s+="es";
	cout<<s;
	return 0;
}



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

int main() {
	long long n, m;
	cin >> n >> m;
	if (m / 2 <= n) {
		cout << m/2 << endl;
	}
	else {
		cout << n + (m - n * 2) / 4 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,x;
    cin>>n>>x;
    vector<string>v;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    sort(all(v));
    for(auto i:v)
        cout<<i;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

	scanf("%d %d %d", &a, &b, &c);

	if (a < b + c)
		printf("%d\n", c - (a - b));
	else
		printf("%d\n", 0);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
    ll n;
    cin >> n;
    vector<ll> a,b,c;
    for (ll i=0;i<n;i++){
        ll m;
        cin >> m;
        a.push_back(m);
    }
    for (ll i=0;i<n;i++){
        ll m;
        cin >> m;
        b.push_back(m);
    }
    for (ll i=0;i<n;i++){
        ll m;
        cin >> m;
        c.push_back(m);
    }
    ll ans=0;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for (ll i=0;i<n;i++){
        ll p=b[i];
        auto x=lower_bound(c.begin(),c.end(),p+1),y=upper_bound(a.begin(),a.end(),p-1);
        ll X=c.end()-x;
        ll Y=y-a.begin();
        ans+=X*Y;
    }
    cout << ans << endl;
    return 0;
}    


Measured memory_bytes: 6384
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    t, x, y = map(int, input().split())
    if x > pre_x:
        a = x - pre_x
        b = 0
    else:
        b = pre_x - x
        a = 0
    if y > pre_y:
        c = y - pre_y
        d = 0
    else:
        d = pre_y - y
        c = 0
    total = a+b+c+d
    if t - pre_t >= total and (t - pre_t - total) % 2 == 0:
        count += 1
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define lt(a,b) (a-b < -EPS)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
  bool operator < (const Point &p)const{ return x != p.x ? x < p.x : y < p.y; }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a,b) > EPS){ return COUNTER_CLOCKWISE; }
  if(cross(a,b) < -EPS){ return CLOCKWISE; }
  if(dot(a,b) < -EPS){ return ONLINE_BACK; }
  if(norm(a) < norm(b)){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}

struct Segment{
  Point s,t;
  Segment(){}
  Segment(Point s,Point t) : s(s),t(t) {}
};

typedef Segment Line;

Point crosspointLL(const Line &a,const Line &b){
  Vector va = a.t-a.s, vb = b.t-b.s;
  double d = cross(vb,va);
  if(abs(d) < EPS){ return b.s; }
  return a.s+va*cross(vb,b.t-a.s)*(1.0/d);
}

#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])
typedef vector<Point> Polygon;

Polygon convex_cut(const Polygon &pg,const Line &l){
  Polygon res;
  for(int i = 0 ; i < (int)pg.size() ; i++){
    Point cp = curr(pg,i), np = next(pg,i);
    if(ccw(l.s,l.t,cp) != -1){ res.push_back(cp); }
    if(ccw(l.s,l.t,cp)*ccw(l.s,l.t,np) < 0){
      res.push_back(crosspointLL(Line(cp,np),l));
    }
  }
  return res;
}

int main(){
  int N;
  while(cin >> N, N){
    Polygon pg(N);
    for(int i = 0 ; i < N ; i++){
      cin >> pg[i].x >> pg[i].y;
    }
    Polygon pg2;
    pg2.push_back(Point(0,0));
    pg2.push_back(Point(10000,0));
    pg2.push_back(Point(10000,10000));
    pg2.push_back(Point(0,10000));
    for(int i = 0 ; i < N ; i++){
      Line l = Line(curr(pg,i),next(pg,i));
      pg2 = convex_cut(pg2,l);
    }
    cout << (pg2.size() > 0 ? 1 : 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
int n,a,b,c,d;
int main(){
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);n--;b-=a;
	rep(i,0,n){
		ll now=1ll*(n-2*i)*c;
		ll L=now - 1ll*i*(d-c);
		ll R=now + 1ll*(n-i)*(d-c);
		if(b>=L && b<=R){
			//printf("%d %I64d %I64d %I64d\n",i,L,R,now);
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        String s = scanner.next();
        String[] pass = s.split("");
        boolean flg = true;

        for(int i=1;i<pass.length;i++) {
        	if(pass[i].equals(pass[i-1])) {
        		System.out.println("Bad");
        		flg = false;
        		break;
        	}
        }
        if(flg) {
        	System.out.println("Good");
        }
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, k) for (int i = (s); i < (int)(k); i++)

int main(){
    string o,e,ans="";
    cin >> o >> e;
    int O = o.size();
    int E = e.size();

    int size = max(O,E);
    rep(i,0,size-1){
        ans += o.at(i);
        ans += e.at(i);
    }
    if(O==E){
        ans += o.at(size-1);
        ans += e.at(size-1);
    }
    if(O>E) ans += o.at(size-1);
    if(O<E) ans += e.at(size-1);
    cout << ans << endl;

}

Measured memory_bytes: 3596
program main
  implicit none
integer :: a, b, c = 0, d = 0, e = 0, f = 0, g = 0

read *, a, b


d = a + b
e = a - b
f = a * b

if (d <= e) then
   g = e
else
   g = d
end if

if (g <= f) then
   g = f
else
   continue
end if

print *, g

end program main

Measured memory_bytes: 256
'use strict';
function Main(input) {

	let input1 = input.trim();
  	let input2 = input.trim().split("")
	//console.log(input1,input2)
	//var a = parseInt(input[0], 10);//文字列から10進数に変換するときはparseIntを使います

	if(input2[input2.length - 1]==='s'){
      console.log('%s',`${input1}es`);
    }else{
      console.log('%s',`${input1}s`);
    }
}



//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const int INF = 1001001001;

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

  int n, W;
  cin >> n >> W;

  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }

  vector<vector<int>> dp(n + 1, vector<int>(200000, INF));
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    for (int sumV = 0; sumV <= 100100; sumV++) {
      if (sumV - v[i] >= 0) {
        dp[i + 1][sumV] = min(dp[i + 1][sumV], dp[i][sumV - v[i]] + w[i]);
      }

      dp[i + 1][sumV] = min(dp[i + 1][sumV], dp[i][sumV]);
    }
  }

  ll ans = 0;
  for (int sumV = 0; sumV < 100100; sumV++) {
    if (dp[n][sumV] <= W) ans = sumV;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
unsigned int fact(unsigned int n)
{
    if (n == 0)
    return 1;
    return n * fact(n - 1);
}

int main()
{

    long long int a,b,c,d,i,j,k,l;
    string s;
    cin>>a;
   long long int a1[a][2];
   for(i=0;i<a;i++)
   {
       cin>>a1[i][0]>>a1[i][1];

   }
   long double dist=0.0,cur;
   b=fact(a)*(a-1)*2;
   c=(a*(a-1));
   long long int times=b/c;
  // cout<<times<<endl;

   for(i=0;i<a;i++)
   {
       for(j=i+1;j<a;j++)
       {
           cur=sqrt((a1[i][0]-a1[j][0])*(a1[i][0]-a1[j][0])+(a1[i][1]-a1[j][1])*(a1[i][1]-a1[j][1]));

           dist+=cur*times;
           //cout<<i<<j<<" "<<dist<<endl;
       }
   }
   cout<<fixed<<setprecision(10)<<dist/fact(a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
    fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;


int main()
{
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n,vector<ll>(3));
    REP(i, n)REP(j,3)cin >> a[i][j];
    ll ans = 0;
    REP(i, 1 << 3){
        vector<ll> v(n,0);
        ll tmp = 0;
        REP(j, n){
            REP(k, 3){
                if(i & (1 << k))v[j] += a[j][k];
                else v[j] -=a[j][k];
            }
        }
        sort(ALL(v),greater<ll>());
        REP(i,m){
            tmp += v[i];
        }
        ans = max(ans,tmp);
    }
    dump(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(m[a] == b) {
    cout << 1 << endl;
  }
  else cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String []args) {
	Scanner tc = new Scanner (System.in);
	int a,b;
	a = tc.nextInt();
	b = tc.nextInt();
	
	if(b%2==0) {
if(a<=5) {
	System.out.println(b*0);
			
		}
if(a>=6 && a<=12) {
	System.out.println(b/2);
	
}
		if(a>=13) {
			System.out.println(b);
		}
		
	}
}
}

Measured memory_bytes: 21844
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int wh = a*b;
        int cir = (a+b)*2;
        System.out.printf("%d %d\n",wh,cir);
    }
}


Measured memory_bytes: 26192
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

class Demand {
  public:
    Demand() = default;
    Demand(int _a, int _b) { a = _a; b = _b; }
    int a;
    int b;
};

bool a_smallest_first(const Demand& d1, const Demand& d2)
{
  return d1.a < d2.a;
}

bool b_smallest_first(const Demand& d1, const Demand& d2)
{
  return d1.b < d2.b;
}

void print_demand(const vector<Demand>& demand)
{
  for(const auto& d : demand) {
    printf("%d %d\n", d.a, d.b);
  }
}

int count_bridge(const vector<Demand>& demand)
{
  int range_a = 0;
  int range_b = INT_MAX;
  int cnt = 1;
  for(size_t i = 0; i < demand.size(); i++) {
    if(range_b <= demand[i].a) {
      cnt++;
      range_a = demand[i].a;
      range_b = demand[i].b;
    } else {
      range_a = min(range_a, demand[i].a);
      range_b = min(range_b, demand[i].b);
    }
  }
  return cnt;
}

int main()
{
  int n, ndemand;
  scanf("%d%d", &n, &ndemand);
  vector<Demand> demand(ndemand);
  for(int i = 0; i < ndemand; i++) {
    int a,b;
    scanf("%d%d", &a, &b);
    demand[i].a = a;
    demand[i].b = b;
  }
  std::sort(demand.begin(), demand.end(), b_smallest_first);
  std::stable_sort(demand.begin(), demand.end(), a_smallest_first);
  //print_demand(demand);
  printf("%d\n", count_bridge(demand));
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#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 endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
using ll = long long;
const int maxn = 105;
const int maxm = 1e5+5;
const int us = 1e5+4;
int n,w;
int arr[maxn][2];
ll dp[maxm];
const ll inf = 0x3f3f3f3f3f3f3f3f;
int32_t main(){
    IOS;
    cin>>n>>w;
    rep(i,maxm)
        dp[i]=inf;
    dp[0]=0;
    rep1(i,n)
        rep(j,2)
            cin>>arr[i][j];
    rep1(i,n){
        for(int j=us;j>=arr[i][1];j--)
            dp[j]=min(dp[j],dp[j-arr[i][1]]+arr[i][0]);
        // for(int j=us-1;j>=0;j--)
        //     dp[j]=min(dp[j],dp[j+1]);
    }
    ll ans=0;
    for(int i=us;i>=0;i--){
        if(dp[i]<=w&&dp[i]!=inf){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}
/*
3 8
3 3
4 5
5 6
*/

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=100;
const int M=20;

int main(){
    ll dp[N-1][M+1];
    int n,num[N];

    cin>>n;

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

    for(int i=0;i<N-1;i++){
        for(int j=0;j<=M;j++){
            dp[i][j]=0;
        }
    }

    dp[0][num[0]]=1;

    for(int i=1;i<n-1;i++){
        for(int j=0;j<=M;j++){
            if(j-num[i]>=0){
                dp[i][j]+=dp[i-1][j-num[i]];
            }
            if(j+num[i]<=M){
                dp[i][j]+=dp[i-1][j+num[i]];
            }
        }
    }

    cout<<dp[n-2][num[n-1]]<<endl;

    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n;
    while(cin>>n,n){
        vint a(n);
        rep(i,n)cin>>a[i];
        sort(all(a));
        int mi=LLONG_MAX;
        rep(i,n-1)chmin(mi,a[i+1]-a[i]);
        cout<<mi<<endl;
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int absmax=-1;
	int midx=-1;
	int sign;
	for(int i=1; i<=n; i++){
		int a;
		cin >> a;
		if(abs(a) > absmax){
			absmax = abs(a);
			midx = i;
			if(a>0) sign = 1;
			else sign = -1;
		}
	}
	
	cout << 2*n << endl;
	if(sign>0){
		cout << midx << " " << 1 << endl;
		cout << midx << " " << 1 << endl;
		for(int i=1; i<n; i++){
			cout << i << " " << i+1 << endl;
			cout << i << " " << i+1 << endl;
		}
	}else{
		cout << midx << " " << n << endl;
		cout << midx << " " << n << endl;
		for(int i=n; i>1; i--){
			cout << i << " " << i-1 << endl;
			cout << i << " " << i-1 << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;



int main(void) {
	int n,p[10000],y=0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> p[i];
	}
	for (int i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1])|| (p[i - 1] > p[i] && p[i] > p[i + 1])){
			y++;
		}
	}
	cout << y << endl;
	return 0;
}

Measured memory_bytes: 256
"""
Writer: SPD_9X2
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_B&lang=ja

各セルに対して、上にいくつ0が連続しているか数えれば、
ヒストグラム上での最大長方形問題になる
"""


def Largest_rectangle_in_histgram(lis):

    stk = []

    ans = 0
    N = len(lis)

    for i in range(N):

        if len(stk) == 0:
            stk.append((lis[i],i))

        elif stk[-1][0] < lis[i]:
            stk.append((lis[i],i))

        elif stk[-1][0] == lis[i]:
            pass

        else:
            lastpos = None
            while len(stk) > 0 and stk[-1][0] > lis[i]:

                nh,np = stk[-1]
                lastpos = np
                del stk[-1]

                ans = max(ans , nh*(i-np))

            stk.append((lis[i] , lastpos))

    return ans

H,W = map(int,input().split())

c = []
for i in range(H):
    C = list(map(int,input().split()))
    c.append(C)

zlis = [ [0] * (W+1) for i in range(H) ]
for i in range(H):
    for j in range(W):

        if c[i][j] == 1:
            continue
        elif i == 0:
            zlis[i][j] = 1
        else:
            zlis[i][j] = zlis[i-1][j] + 1

#print (zlis)
ans = 0
for i in range(H):
    ans = max(ans , Largest_rectangle_in_histgram(zlis[i]))

print (ans)



Measured memory_bytes: 63244
s = input()
t = input()
n = len(s)
m = len(t)
ans = []
for i in range(n-m+1):
    c = 0
    for j in range(m):
        if s[i+j] == '?' or s[i+j] == t[j]:
            c += 1
    if c == m:
        s_ = s[0:i] + t + s[i+m:]
        s_ = s_.replace('?', 'a')
        ans.append(s_)
if len(ans)>0:
    print(sorted(ans)[0])
else:
    print('UNRESTORABLE')
 

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    int A, B, T; cin >> A >> B >> T;
    int ans = T / A * B;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#define ll long long

using namespace std;

vector<int> t(55001,0);
int main(){
  int n;
  cin >> n;
  
  for( int i = 0 ; i <= 50000 ; i ++ ){
    int af = 1.08 * i;
    t[af] = i;
  
  }
  if( t[n] == 0 ) cout << ":(" << endl;
  else cout << t[n] << endl;
  return 0;

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
 
int main(){
  ll N, R, ans;
  cin >> N >> R;
  
  ans = R;
  
  if(N < 10){
    ans += (10 - N)*100;
  }
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#coding:utf-8
 
import sys
import copy
 
def main():
    line = sys.stdin.readline()
    #case
    while line.split() != ["0","0"]:
        analy(line)
        line = sys.stdin.readline()
    return
 
def analy(line):
    #整列
    field = [int(n) for n in line.split()]
    # 横、縦
    num = int(sys.stdin.readline())
    data = []
    for i in range(num):
        a = sys.stdin.readline()
        b = [int(n) for n in a.split()]
        #横、縦
        data.append(b)
    print (compute(field, data))
 
def compute(field, ng):
    list = []
    for i in range(field[1]):
        for j in range(field[0]):
            #横→縦に移動していく
                if i == 0 :
                    #一番下
                    if [j+1,i+1] in ng:
                        list.append(0)
                    elif j == 0:
                        #左がない
                        list.append(1)
                    else:
                        list.append(list[j-1])
                else:
                    if [j+1,i+1] in ng:
                        list[j] = 0
                    elif j != 0:
                    #no left >> the same.
                        list[j] = list[j-1] + list[j]
    return list[len(list)-1]
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 4300
N,K,Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
from collections import Counter
R = [K-Q]*N
c = Counter(A)
for i in c.items():
    R[i[0]-1] += i[1]
    
for j in R:
    if j<=0:
        print('No')
    else:
        print('Yes')

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c, d; cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes\n";
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3564
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n=scanner.nextInt();
		int m=scanner.nextInt();
		String s=scanner.next();
		String t=scanner.next();
		long l=lcm(n,m);
		Map<Long,String>map=new HashMap<>();
		for(int i=0;i<n;i++) {
			Long indn=(Long) (i*l/n+1);
			String tmps=String.valueOf(s.charAt(i));
			map.put(indn, tmps);
		}
		for(int i=0;i<m;i++) {
			Long indm=(Long) (i*l/m+1);
			String tmpt=String.valueOf(t.charAt(i));
			if (map.containsKey(indm)) {
				if(map.get(indm).equals(tmpt)) {
					
				}
				else {
					System.out.println(-1);
					return;
				}
			} 
			map.put(indm, tmpt);
		}
		System.out.println(l);
	}
	
	/*******************************************************************
	最大公約数
	*******************************************************************/

	static long gcd(long a, long b) {
			long temp;
			while ((temp = a % b) != 0) {
				a = b;
				b = temp;
			}
			return b;
		}


	/*******************************************************************
	最小公倍数
	*******************************************************************/

		 static long lcm(long m, long n) {
			return m / gcd(m, n) * n;
		}

}

Measured memory_bytes: 55268
#include<stdio.h>
#include<stdlib.h>

int p,q,a,n;

int dfs(int b,int s,int c,int now)
{
	int i,r=0;
	if(b*p==q*s)
		return 1;
	if(c==n)
		return 0;
	if(b*p<q*s)
		return 0;
	for(i=now;i*b<=a;i++)
		r+=dfs(b*i,(s*i)+b,c+1,i);
	return r;
}

int main()
{
	for(;scanf("%d%d%d%d",&p,&q,&a,&n),q;)
		printf("%d\n",dfs(1,0,0,0));
}

Measured memory_bytes: 600
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let S = read string
    let T = "CODEFESTIVAL2016"

    seq {
        for i in 0..S.Length - 1 do
            if S.[i] <> T.[i] then
                yield ()
    }
    |> Seq.length
    |> printfn "%d"
    0 // return an integer exit code


Measured memory_bytes: 14044
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    std::string S, T;
    std::cin >> S >> T;

    int64_t ans = INT64_MAX;

    if (S == T)
    {
        std::cout << 0 << std::endl;
        return;
    }

    if (S.size() == T.size())
    {
        int64_t ans = 0;
        for (int64_t i = 0; i < S.size(); i++)
        {
            if (S[i] != T[i]) ans++;
        }
        std::cout << ans << std::endl;
        return;
    }

    for (int64_t i = 0; i < S.size() - T.size(); i++)
    {
        int64_t diff = 0;
        for (int64_t j = 0; j < T.size(); j++)
        {
            if (S[i + j] != T[j]) diff++;
        }
        ans = std::min(ans, diff);
    }

    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mod = 1000000007;

int main(){
    int N;
    cin >> N;
    string S1, S2;
    cin >> S1 >> S2;
    vector<bool> rule;
    
    int index = 0;
    while(index < N){
        if(S1[index] == S2[index]){
            rule.push_back(true);
            index++;
        }
        else{
            rule.push_back(false);
            index += 2;
        }
    }
    
    ll ans = 1;
    
    bool previous = rule[0];
    if(previous){
        ans *= 3;
    }
    else{
        ans *= 6;
    }
    for(int i = 1; i < rule.size(); ++i){
        if(previous){
            if(rule[i]){
                ans *= 2;
                ans %= mod;
            }
            else{
                ans *= 2;
                ans %= mod;
            }
        }
        else{
            if(rule[i])         ;       // ans *= 1;
            else{
                ans *= 3;
                ans %= mod;
            }
        }
        
        previous = rule[i];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, x, ans;

int main() {
    n = read();
    for (int i = 1; i <= n; i++) { x = read(); ans += x - 1; }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
import math
n, m = map(int, input().split())

if abs(n-m)>1:
  print(0)
elif n-m==1:
  print(int((math.factorial(n)*math.factorial(m))%(10**9+7)))
elif m-n==1:
  print(int((math.factorial(m)*math.factorial(n))%(10**9+7)))
elif n==m:
  print(int((math.factorial(n)*math.factorial(m)*2)%(10**9+7)))

Measured memory_bytes: 10976
#include <stdio.h>

//void make_prime();

//int max=100000000;
//int prime[100000010];

int prime00(int n);

int main()
{
	int n,i,x;
	int count=0;
	//make_prime();
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &x);
		if(prime00(x)){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}
/*
void make_prime()
{
	int i,k;
	for(i=0; i<=max; i++){
		prime[i]=1;
	}
	prime[0]=0;
	prime[1]=0;
	for(i=2; i<=max; i++){
		if(prime[i]){
			for(k=i+i; k<=max; k+=i){
				prime[k]=0;
			}
		}
	}
	return;
}
*/

int prime00(int n)
{
	int i;
	if(n<2){
		return 0;
	}
	else if(n==2){
		return 1;
	}
	else if(n%2==0){
		return 0;
	}
	else{
		for(i=3; i*i<=n; i+=2){
			if(n%i==0){
				return 0;
			}
		}
	}
	return 1;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int MAX_V=1020;

vvin g(MAX_V);//グラフの隣接リスト表現
vin match(MAX_V);//マッチングのペア
vbo used(MAX_V);

void add_edge(int u,int v){
    g[u].push_back(v);
    g[v].push_back(u);
}

//増加パスをdfsで探す
bool dfs(int v){
    used[v]=true;
    for(auto u:g[v]){
        int w=match[u];
        if(w<0||(!used[w]&&dfs(w))){
            match[v]=u;
            match[u]=v;
            return true;
        }
    }
    return false;
}

//二部グラフの最大マッチングを求める
int max_matching(int v){//vは頂点数
    int res=0;
    fill(all(match),-1);
    rep(i,v){
        if(match[i]<0){
            fill(all(used),false);
            if(dfs(i))res++;
        }
    }
    return res;
}

vin b(510),r(510);

int solve(int m,int n){
    rep(i,MAX_V)g[i].clear();
    rep(i,m)cin>>b[i];
    rep(i,n)cin>>r[i];
    rep(i,m)rep(j,n){
        if(__gcd(b[i],r[j])!=1)add_edge(i,j+m);
    }
    return max_matching(m+n);
}

int main(){
    vin ans;
    while(1){
        int m,n;cin>>m>>n;
        if(m==0)break;
        ans.push_back(solve(m,n));
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
}


Measured memory_bytes: 5060
x=3
A,B,C=(int(x) for x in input().split())
K=int(input())
j=0
if A>=(2**K)*B :
    print('No')
else :
    while A>=(2**j)*B :
        j+=1
    if (2**j)*B>=(2**(K-j))*C :
        print('No')
    else:
        print('Yes')

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

using namespace std;

const int N = 100005;

vector<int> adj[N];
int visit[N], ans = 0;

int dfs(int u) {
  int c = 0;
  for (auto v : adj[u]) {
    if (visit[v] == -1) {
      c = max(c, 1 + dfs(v));
    } else {
      c = max(c, 1 + visit[v]);
    }
  }
  return visit[u] = c;
}

int main() {
  int n, m, u, v;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
  }
  memset(visit, -1, sizeof visit);
  for (int i = 1; i <= n; i++) {
    if (visit[i] == -1) {
      ans = max(ans, dfs(i));
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <queue>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

void solve();

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

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

int N, M;
bool con[8][8];

void solve() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)con[i][j] = false;
	}
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		con[--a][--b] = true;
		con[b][a] = true;
	}
	vector<int> v(N);
	iota(v.begin(),v.end(),0);
	int sum = 0;
	do {
		if (v[0] != 0)continue;
		bool flag = true;
		for (int i = 0; i < v.size() - 1; i++) {
			if (!con[v[i]][v[i + 1]]) {
				flag = false;
				break;
			}
		}
		if (flag)sum++;
	} while (next_permutation(v.begin(),v.end()));
	cout << sum;
	cin >> N;
	return;
}

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

int main()
{
    std::string s;
    int k;
    std::cin >> s >> k;
    std::vector<std::string> can;
    for (int i = 0; i < static_cast<int>(s.size()); ++ i) {
        for (int j = 1; j <= k && i + j <= (int)(s.size()); ++ j) {
            can.push_back(s.substr(i, j));
        }
    }
    std::sort(can.begin(), can.end());
    can.erase(std::unique(can.begin(), can.end()), can.end());
    printf("%s\n", can[k - 1].c_str());
}

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

using namespace std;

const int INF = 1 << 30;


struct SegmentTree
{
  vector< int > seg;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, INF);
  }

  int rmq(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (INF);
    if(a <= l && r <= b) return (seg[k]);
    return (min(rmq(a, b, 2 * k + 1, l, (l + r) >> 1),
                rmq(a, b, 2 * k + 2, (l + r) >> 1, r)));
  }

  int rmq(int a, int b)
  {
    return (rmq(a, b, 0, 0, sz));
  }

  void update(int k, int x)
  {
    k += sz - 1;
    seg[k] = x;
    while(k > 0) {
      k = (k - 1) >> 1;
      seg[k] = min(seg[2 * k + 1], seg[2 * k + 2]);
    }
  }
};

int main()
{
  int W, N, x[50001] = {};

  while(scanf("%d %d", &W, &N), W) {
    for(int i = 1; i <= N; i++) {
      scanf("%d", x + i);
      x[i] += x[i - 1];
    }

    auto getSpace = [&](int l, int r)
    {
      if(l + 1 >= r) {
        cout << l << " " << r << endl;

        puts("foo");
        return (114514);
      }
      if(x[r] - x[l] + r - l - 1 > W) return (INF);
      return ((W + x[l] + r - x[r] - l - 2) / (r - l - 1));
    };

    int low = 1, high = W;
    while(high - low > 0) {
      int limit = (low + high) >> 1;

      int left = 0, right = 0;
      SegmentTree dp(N);
      dp.update(0, limit);
      for(int i = 2; i < N; i++) {
        while(i - left >= 2 && getSpace(left, i) == INF) ++left;
        while(i - right >= 2 && (getSpace(right, i) == INF || getSpace(right, i) <= limit))++right;
        dp.update(i, dp.rmq(left, right));
      }
      int tail = N - 2;
      bool flag = dp.rmq(N - 1, N) <= limit;
      while(tail >= 0 && getSpace(tail, N) != INF) {
        flag |= dp.rmq(tail, tail + 1) <= limit;
        --tail;
      }
      if(flag)high = limit;
      else low = limit + 1;
    }
    printf("%d\n", low);
  }
}

Measured memory_bytes: 3908
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12668
#include <stdio.h>

int main(void) {
	char ok[2][256] = {
		{['R'] = 1, ['U'] = 1, ['D'] = 1},
		{['L'] = 1, ['U'] = 1, ['D'] = 1}
	};
	char S[128];
	int i;
	if (scanf("%127s", S) != 1) return 1;
	for (i = 0; S[i] != '\0'; i++) {
		if (!ok[i % 2][(unsigned char)S[i]]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 128
// A - Irreversible operation

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

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

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

	ll ans = 0;
	ll cnt = 0;
	for (int i=0; i<S.size(); i++) {
		if (S[i] == 'B') cnt++;
		else ans += cnt;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	string s;
	cin>>s;
	getchar();
	int tmp=1;
	for(int i=0;i<s.length()-1;i++){
		if(s[i]!=s[i+1]){
			tmp++;
			continue;
		}
		else{
			if(i==s.length()-3){
				tmp++;
				break;
			}
			if(i==s.length()-2){
				break;
			}
			tmp+=2;
			i+=2;
		}
	}
	cout <<tmp<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
using namespace std;
char str[MAXN+5],ans[MAXN+5];
char inv[200];
int N,K,seq[MAXN+5];
int main()
{
	inv['A']='B',inv['B']='A';
	scanf("%d %d",&N,&K);
	scanf("%s",str+1);
	for(int i=1;i<=N;i++)
		seq[i]=str[i]-'A';
	int mv=0,turn=0;
	while(mv<N)
	{
		K--;
		if((seq[mv+1]^turn)==0)
		{
			seq[mv+1]^=1;
		}
		else
		{
			mv++;
			turn^=1;
		}
		if(K==0)
			break;
	}
	int len=0;
	for(int i=mv+1;i<=N;i++)
	{
		if(seq[i]^turn)
			ans[++len]='B';
		else
			ans[++len]='A';
	}
	if(K==0||N%2==0)
	{
		for(int i=1;i<=mv;i++)
			if((i%2)^(turn))
				ans[++len]='B';
			else
				ans[++len]='A';
		printf("%s\n",ans+1);
		return 0;
	}
	for(int i=1;i<=N;i++)
		if(i%2)
			ans[++len]='A';
		else
			ans[++len]='B';
	if(K%2==1)
		ans[1]='B';
	printf("%s\n",ans+1);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int N, a[100001], b[100001], c[100001], dpa[100001], dpb[100001], dpc[100001];

int main(){
  cin >> N;
  for(int i = 1; i <= N; i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  dpa[1] = a[1];
  dpb[1] = b[1];
  dpc[1] = c[1];
  for(int i = 2; i <= N; i++){
    dpa[i] = max(dpb[i-1],dpc[i-1])+a[i];
    dpb[i] = max(dpa[i-1],dpc[i-1])+b[i];
    dpc[i] = max(dpb[i-1],dpa[i-1])+c[i];
  }
  cout << max(dpa[N], max(dpb[N], dpc[N])) << endl;
}

Measured memory_bytes: 2560
#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>;
using namespace std;

int main()
{
    int x;
    cin >> x;
    while(true) {
        bool ok = true;
        for (int i = 2; i < x; ++i) {
            if (x%i == 0) {
                ok = false;
                break;
            }
        }
        if (ok) break;
        ++x;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
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; }



void solve() {
    ll n;
    ll a[200010];
    cin>>n;
    rep(i,n) cin>>a[i];
    ll ans=0;
    rep2(i,1,n){
        if(a[i-1] > a[i]){
            ans += a[i-1] - a[i];
            a[i] += (a[i-1] - a[i]);
        }
    }
    cout<<ans<<endl;
    

}







signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    rep(i,t){
        solve(); 
    }


    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	multiset<int,greater<int> > M;
	for(int i=1,x;i<=n;i++)
		cin>>x,M.insert(x);
	int ans = 0;
	while(M.size()){
		int x = *M.begin();
		M.erase(M.begin());
		int y = (1<<(32-__builtin_clz(x)))-x;
		if(M.count(y)){
			ans++;
			M.erase(M.find(y));
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  bool flag=false;
  int sum=1;
  int count=0;
  while(flag==false){
    if(sum>=B){
      cout<<count<<endl;
      flag=true;
      break;
    }
    else{
      sum=sum+A-1;
      count=count+1;
    }
  }
}
    
    


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    private static IO io = new IO();
    public static void main(String[] args) {
        while (io.hasNext()) {

            int n = io.nextInt();
            int ans = 0;
            for (int a = 0; a < 10; a++) {
                for (int b = 0; b < 10; b++) {
                    for (int c = 0; c < 10; c++) {
                        int d = n - (a+b+c);
                        if (0<=d && d<10) ans++;
                    }
                }
            }
            System.out.println(ans);

        }
    }

    static class IO extends PrintWriter {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        IO() {
            this(System.in);
        }

        IO(InputStream source) {
            super(System.out);
            this.in = source;
        }

        boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }
        int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }
        boolean isPrintableChar(int c) {return 33<=c &&c <=126;}
        void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;}
        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }

        int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public void close() {
            super.close();
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }
}

Measured memory_bytes: 24176
import java.util.*;

public class Main {
    public static void main(String[] aregs) {
        Scanner sc = new Scanner(System.in);
        int[] imput = new int[4];

        for (int i = 0; i <= 3; i++) {
            imput[i] = sc.nextInt();;
        }

        int left_sum = imput[0] + imput[1];
        int right_sum = imput[2] + imput[3];

        if (left_sum > right_sum) {
            System.out.println("Left");
        } else if (left_sum == right_sum) {
            System.out.println("Balanced");
        } else {
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 21716