akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define SZ(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back
char ta[10][10];
int main(){
	while(cin>>ta[1][1]){
		for(int i=1;i<=8;i++)for(int j=(i==1)+1;j<=8;j++)cin>>ta[i][j];
	
		for(int i=1;i<=8;i++){
			for(int j=1;j<=8;j++){
				char ans='?';
				if(ta[i][j]=='1'){
				if(ta[i+1][j]=='1'&&ta[i][j+1]=='1'&&ta[i+1][j+1]=='1')ans='A';
				
				else if(ta[i+1][j]=='1'&&ta[i+1][j]=='1'&&ta[i+3][j]=='1')ans='B';
				
				else if(ta[i][j+1]=='1'&&ta[i][j+2]=='1'&&ta[i][j+3]=='1')ans='C';
				
				else if(ta[i+1][j]=='1'&&ta[i+1][j-1]=='1'&&ta[i+2][j-1]=='1')ans='D';
				
				else if(ta[i][j+1]=='1'&&ta[i+1][j+1]=='1'&&ta[i+1][j+2]=='1')ans='E';
				
				else if(ta[i+1][j]=='1'&&ta[i+1][j+1]=='1'&&ta[i+2][j+1]=='1')ans='F';
				
				else if(ta[i][j+1]=='1'&&ta[i+1][j]=='1'&&ta[i+1][j-1]=='1')ans='G';
				}
				if(ans!='?'){cout<<ans<<endl;goto next;}
			}
		}
	
	next:;
	}
	return 0;
}

Measured memory_bytes: 1132
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
        int c = sc.nextInt();
		int d = sc.nextInt();
        int k = sc.nextInt();
       
		System.out.println((60*c+d)-(60*a+b)-k);
	}
}


Measured memory_bytes: 35704
import math
import fractions

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0

    minX = (A - 1) // X
    maxX = B // X

    return maxX - minX

A , B , C , D = map(int,input().split())

ans = B - A + 1

# 最小公倍数
Z = int(C * D / fractions.gcd(C,D))

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))



Measured memory_bytes: 5176
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

signed main (){
    int a,b;
    int k;
    cin>>a>>b>>k;
    int ct=0;
    vector<int> v;
    rep(i,1,max(a,b)+1){
        if(a%i==0&&b%i==0)v.push_back(i);
    }
    reverse(all(v));
    cout<<v[k-1]<<endl;

    

    

    
}  
/*
100 50 4
1 2 5 10
*/


Measured memory_bytes: 256
n=int(input())
s=['M','A','R','C','H']
for i in range(n):
    i=input()
    s.append(i[0])

import collections
c = collections.Counter(s)
d=['M','A','R','C','H']
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=(c[d[i]]-1)*(c[d[j]]-1)*(c[d[k]]-1)
print(ans)
            


Measured memory_bytes: 4244
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int ans[55];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);

    for (int i=0;i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        ans[a]++;
        ans[b]++;
    }
    for (int i=1; i<=n; i++)
    {
        cout<<ans[i]<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
def main():
    domain, num_sum = map(int, input().split())
    answer = 0
    for i in range(domain + 1):
        for j in range(domain + 1):
            if 0 <= num_sum - i - j <= domain:
                answer += 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <stdio.h>
int main (void)
{
  int A,B,C,X;
  	scanf("%d%d%d",&A,&B,&C);
  X = B / A;
  if(X<=C){
  	printf("%d",X);
  }
  else{
    printf("%d",C);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

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

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

    for(int i = k; i < n; i++){
        if(a[i - k] < a[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }





}

Measured memory_bytes: 4040
n = int(input())
a = [i for i in map(int, input().split())]
q = int(input())
m = [i for i in map(int, input().split())]

def solve(i, m):
    global a
    if m == 0:
        return True
    if i >= n:
        return False
    return solve(i+1, m) or solve(i+1, m - a[i])

for target in m:
    if sum(a) < target:
        print('no')
    elif solve(0, target):
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5624
n = gets.strip.split.map{|i| i.to_i}
a = gets.strip.split.map{|i| i.to_i}
counter=0

isBreak = false

while true
  for i in 0..a.length-1 do
    if (a[i]%2==0) then
      a[i] /= 2
    else
      isBreak = true
      break
    end
  end
  break if isBreak
  counter += 1
end

puts counter

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=998244353;


ll sm[MX+5];

int main()
{
    FasterIO;

    for(int i=1; i<=MX; i++)
    {
        if(i%3==0 || i%5==0) sm[i]=sm[i-1];
        else  sm[i]=sm[i-1]+i;
    }
    int n;
    cin>>n;
    cout<<sm[n]<<endl;
    return 0;
}


Measured memory_bytes: 11452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int n, k;cin >> n >> k;
    cout << n-k+1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
void b()
{
    int n;
    cin >>n;
    for(int i=1;i<10;i++)
    {
        if(n%i ==0)
     if(n/i<10)
     {
     cout<< "Yes";
     return;
     }

    }
    cout<<"No";
    return;
    


}
void a()
{
    int a,b;
    cin >>a>>b;
    if(a<10 && b<10)
    cout << a*b;
    else cout << -1;
    return;

}
int main(void){
    //a();
    b();
    //c();
    //d();
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

vector<long long int> prime_factor(long long int n){
    vector<long long int> res;
    for(int i=2; i*i<=n; ++i){
        while(n%i==0){
            res.push_back(i);
            n/=i;
        }
    }
    if(n!=1) res.push_back(n);
    return res;
};

class segtree{
public:
    i64 n,size_;
    vector<vector<pair<int,int>>> segs;
    segtree()=default;
    segtree(i64 size){ init(size); }
    void init(i64 size){
        size_=size;
        n=1;
        while(n<size) n*=2;
        segs.resize(n*2-1);
    }
    void insert(int l_,int r_){ insert(0,n,0,l_,r_); }
    void insert(int a,int b,int index,int l_,int r_){
        if(b<=l_ or r_<=a) return;
        if(l_<=a and b<=r_){
            segs[index].push_back(make_pair(l_,r_));
            return;
        }
        insert(a,(a+b)/2,2*index+1,l_,r_);
        insert((a+b)/2,b,2*index+2,l_,r_);
    }
    int query(int lb,int x){ return query(0,n,0,lb,x); }
    int query(int a,int b,int index,int lb,int x){
        if(/*b<=lb or*/ x<a or b<=x) return 0;
        int res=0;
        if(lb<a and a<=x and x<b) res+=segs[index].end()-upper_bound(segs[index].begin(),segs[index].end(),make_pair(lb,inf));
        if((a+b)/2<b) res+=query(a,(a+b)/2,index*2+1,lb,x);
        if(a<(a+b)/2) res+=query((a+b)/2,b,index*2+2,lb,x);
        return res;
    }
};

void solve(){
    int N,M;
    cin >> N >> M;

    vector<pair<int,int>> LR;
    rep(i,0,N){
        int L,R;
        cin >> L >> R;
        ++R;
        LR.push_back(make_pair(L,R));
    }
    sort(LR.begin(),LR.end());
    segtree seg(M+1);
    rep(i,0,N) seg.insert(LR[i].first,LR[i].second);

    rep(i,1,M+1){
        int ans=0;
        rep(j,1,M/i+1){
            int tmp=seg.query(i*(j-1),i*j);
            ans+=seg.query(i*(j-1),i*j);
        }
        cout << ans << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(m + 2, 0L);
    int64_t t = 0;
    int64_t i = 1;
    for (auto j : irange(0L, m)) {
        if (s[j] == '0') {
            a[i++] = t;
        } else {
            ++t;
        }
    }
    a[i++] = t;
    a.resize(i);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(2, vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t h = 0;
    dp[h][0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        auto&& prev = dp[h];
        auto&& next = dp[!h];
        h = !h;

        for (auto j : irange(0L, k + 1) | reversed) {
            int64_t ss = 0;
            for (auto c : irange(a[i + 1], a.back() + 1)) {
                next[j][c] = ss + prev[j][a[i] + (c - a[i + 1])];
                ss += prev[j][a[i] + (c - a[i + 1])];
                next[j][c] %= M;
            }

            for (auto c : irange(a[i + 1], a.back() + 1)) {
                for (auto b : irange(a[i] + (c - a[i + 1]) + 1, c + 1)) {
                    auto w = j + b - (a[i] + (c - a[i + 1]));
                    if (w > k) {
                        break;
                    }
                    next[w][c] += prev[j][b];
                    next[w][c] %= M;
                }
            }
        }
    }

    int64_t ans = 0;
    for (auto i : irange(0L, k + 1)) {
        ans += dp[h][i][a.back()];
        ans %= M;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5296
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1<<30] * n
dp[0] = 0
for i in range(n):
    for j in range(min(k, n) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])


Measured memory_bytes: 52448
#include<stdio.h>
#define N 100000
#define NIL -1
void depth(int,int);
int height(int);
int info_sibling(int);
void print(int);

typedef struct{
    int parent;
    int left;
    int right;
} Node;

Node node_all[N];
int n;
int node_depth[N],node_height[N];

int main(){
    int i,id,l,r,root;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        node_all[i].parent = NIL;
    }
    for(i=0;i<n;i++){
        scanf("%d%d%d",&id,&l,&r);
        node_all[id].left = l;
        node_all[id].right = r;
        if(l != NIL) node_all[l].parent = id;
        if(r != NIL) node_all[r].parent = id;
    }
    for(i=0;i<n;i++){
        if(node_all[i].parent == NIL){
            root = i;
        }
    }
    depth(root,0);
    height(root);
    for(i=0;i<n;i++){
        print(i);
    }
    return 0;
}

void depth(int k,int dn){
    if(k == NIL) return;
    node_depth[k] = dn;
    depth(node_all[k].left,dn+1);
    depth(node_all[k].right,dn+1);
}

int height(int k){
    int a = 0,b = 0,max;
    if(node_all[k].left != NIL){
        a = height(node_all[k].left) + 1;
    }
    if(node_all[k].right != NIL){
        b = height(node_all[k].right) + 1;
    }
    max = a;
    if(b > max){
        max = b;
    }
    node_height[k] = max;
    return node_height[k];
}

int info_sibling(int k){
    if(node_all[k].parent == NIL){
        return NIL;
    }
    if(node_all[node_all[k].parent].left != k && node_all[node_all[k].parent].left != NIL){
        return node_all[node_all[k].parent].left;
    }
    if(node_all[node_all[k].parent].right != k && node_all[node_all[k].parent].right != NIL){
        return node_all[node_all[k].parent].right;
    }
    return NIL;
}

void print(int k){
    int count = 0;
    printf("node %d: ",k);
    printf("parent = %d, ",node_all[k].parent);
    printf("sibling = %d, ",info_sibling(k));
    if(node_all[k].left != NIL){
        count++;
    }
    if(node_all[k].right != NIL){
        count++;
    }
    printf("degree = %d, ",count);
    printf("depth = %d, ",node_depth[k]);
    printf("height = %d, ",node_height[k]);

    if(node_all[k].parent == NIL){
        printf("root\n");
    }
    else if(node_all[k].left == NIL && node_all[k].right == NIL){
        printf("leaf\n");
    }
    else printf("internal node\n");
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

vector<P> factorize(ll N){
    vector<P> res;
    ll tmp = N;
    for(ll i=2; i*i<=tmp; i++) {
        if(tmp%i == 0) {
            ll cnt = 0;
            while(tmp%i == 0) {
                cnt++;
                tmp /= i;
            }
            res.emplace_back(P(i, cnt));
        }
    }
    if(tmp > 1) {
        res.emplace_back(P(tmp, 1));
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    vector<P> facts = factorize(N);
    stringstream ss;
    ss << N << ":";
    sort(facts.begin(), facts.end());
    for(auto &fact: facts){
        for(int i=0; i<fact.second; i++){
            ss << " " << fact.first;
        }
    }
    cout << ss.str() << endl;
}


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

int main(){
  int D;
  cin>>D;
  if(D==25)cout<<"Christmas"<<endl;
  if(D==24)cout<<"Christmas Eve"<<endl;
  if(D==23)cout<<"Christmas Eve Eve"<<endl;
  if(D==22)cout<<"Christmas Eve Eve Eve"<<endl;
  
}

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

string divv[4]={"dream", "dreamer", "erase", "eraser"};

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

  reverse(S.begin(), S.end());
  for(int i=0; i<4; i++) reverse(divv[i].begin(), divv[i].end());

  bool can = true;
  for(int i=0; i<S.size();){
    bool can2 = false;
    for(int j=0; j<4; j++){
      string d = divv[j];
      if(S.substr(i, d.size())==d){
        can2 = true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }

  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long a[301][301];
    long flag[301][301]={0};

    long i,j;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            scanf("%ld", &a[i][j]);
        }
    }

    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            if(i==j) {
                if(a[i][j]!=0) {
                    printf("-1\n"); return 0;
                }
            }
            else {
                if(a[i][j]!=a[j][i]) {
                    printf("-1\n"); return 0;
                }
            }
        }
    }

    {
        for (long k = 0; k <n; k++) {
          for (long i = 0; i <n; i++) {
            for (long j = 0; j <n; j++) {
              if (a[i][j] > a[i][k] + a[k][j]) {
                  printf("-1\n"); return 0;
              }
              else if (a[i][j] == a[i][k] + a[k][j] && a[i][k]>0 && a[k][j]>0) {
                  flag[i][j] = 1;
              }
            }
          }
        }
    }

    ll sum=0;            
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            if(flag[i][j]==0) sum+= a[i][j];
        }
    }


    printf("%lld\n", sum/2);
  
    return 0;
}


Measured memory_bytes: 1536
<?php
  list($n,$m) = explode(" ", trim(fgets(STDIN)));

  $ac = [];
  $ac_cnt=0;
  $wa_cnt=0;
  for($i=0;$i<$m;$i++){
    list($p, $S) = explode(" ", trim(fgets(STDIN)));
    if(!isset($ac[$p])){
      $ac[$p]=[];
      $ac[$p][0]=false;
      $ac[$p][1]=0;
    }
    if($ac[$p][0]){
      continue;
    }
    if($S=="WA"){
      $ac[$p][1]++;
    }else{
      $ac[$p][0]=true;
    }
  }
  foreach($ac as $key => $value){
    if(!$value[0]){
      continue;
    }
    $ac_cnt++;
    $wa_cnt+=$value[1];
  }
  echo $ac_cnt." ".$wa_cnt;

Measured memory_bytes: 45944
import java.util.Scanner;

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

		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();

		int n = a * b;
		int m = c * d;

		if (n >= m) {
			System.out.println(n);
		} else if (m >= n) {
			System.out.println(m);
		} else if (n == m) {
			System.out.println(n);

		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;

int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    int ans;
    if(b > a)
        ans = b-a-w;
    else
        ans = a-b-w;

    if(ans < 0) cout << 0;
    else  cout << ans;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



int main() {
	int n, m;
	cin >> n >> m;
	vector<int> even, odd;
	while(m--) {
		int x;
		cin >> x;
		if(x % 2 == 0) even.push_back(x);
		else odd.push_back(x);
	}
	if((int) odd.size() > 2) {
		puts("Impossible");
		return 0;
	}
	vector<int> w;
	if(!odd.empty()) w.push_back(odd[0]);
	for(int x : even) w.push_back(x);
	if((int) odd.size() == 2)
		w.push_back(odd.back());
	for(int x : w) printf("%d ", x); puts("");
	vector<int> b;
	if(w[0] > 1) b.push_back(w[0] - 1);
	for(int i = 1; i < (int) w.size() - 1; ++i)
		b.push_back(w[i]);
	b.push_back(w.back() + 1);
	if((int) w.size() == 1) {
		if(w[0] == 1) b = w;
		else b = {w[0] - 1, 1};
	}
	printf("%d\n", (int) b.size());
	for(int x : b) printf("%d ", x);
	puts("");
}


Measured memory_bytes: 256
S=input()
t=set()
for i in range(len(S)):
    t.add(S[i])
if len(t)==4:
    print('Yes')
elif len(t)==3:
    print('No')
elif len(t)==2:
    if 'N' in t and 'S' in t:
        print('Yes')
    elif 'W' in t and 'E' in t:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

namespace ProblemE
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var M = read[1];

            var half = M / 2;
            var endFirst = M%2 == 0 ? M + 1 : M;
            var startSecond = endFirst + 1;
            var endSecond = 2 * M + 1;
            for (int i = 0; i < half; i++)
            {
                Console.WriteLine((i + 1) + " " + (endFirst - i));
            }
            for (int i = 0; i < M - half; i++)
            {
                Console.WriteLine((startSecond + i) + " " + (endSecond - i));
            }
        }

        static int CalcDist(int a, int b, int N)
        {
            return Math.Min(b - a, a + N - b);
        }

        
//            #region odd case
//            if (N % 2 != 0)
//            {
//                for (int i = 0; i<M; i++)
//                {
//                    Console.WriteLine((i + 1) + " " + (N - i));
//                }
//}
//            #endregion 
//            else
//            {
//                for(int i=0;i<M;)
//                {
//                    var dists = new int[M];
//                    for (int j = 0; j<M; j++)
//                    {
//                        var dist = CalcDist(i + 1, N - i - j, N);
//                        if (!(N - j - 2 * i - 1 == N / 2) && !dists.Contains(dist))
//                        {
//                            Console.WriteLine((i + 1) + " " + (N - i - j));
//                            dists[i] = dist;
//                            i++;
//                            break;
//                        }
//                    }
//                }
//            }
    }
}


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

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

int l[maxn];

int main()
{

  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for(int i = 0 ; i < n; i++)
  {
    cin >> l[i];
  }

  sort(l, l + n);

  ll ans = 0;

  for(int i = 0; i < n; i++)
  {
    int k = i + 2;
    for(int j = i+1; j < n; j++)
    {
      while( k < n && l[i] + l[j] > l[k])
        k++;
      if(k > j)
      ans += k - j - 1;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val bList = readLine()!!.split(" ").map(String::toInt)

    var count = bList[0]
    for (i in 1 until n-1) {
        count += Math.min(bList[i-1], bList[i])
    }
    println(count + bList.last())
}

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

char flag[1024][1024];

int main(){
	int m,n;
	cin>>m>>n;
	
	for(int i=0;i<=n+5;i++){
		flag[0][i]='X';
		flag[m+1][i]='X';
		}
		
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++)cin>>flag[i+1][j+1];
			}
			
		string mon[2];
		cin>>mon[0]>>mon[1];
			
		int sum=0;
		
		for(int i=0;i<=m;i++){
			for(int j=0;j<=n;j++){
				if(flag[i][j]==mon[0][0]&&flag[i][j+1]==mon[0][1]&&flag[i+1][j]==mon[1][0]&&flag[i+1][j+1]==mon[1][1]){
					sum++;
					}
				}
			}
			
		int ans=0;	
		string joi="JOI";
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				for(int k=0;k<=2;k++){
					int a=0;
					if(flag[i][j]==mon[0][0]&&flag[i][j+1]==mon[0][1]&&flag[i+1][j]==mon[1][0]&&flag[i+1][j+1]==mon[1][1]){
						a--;
						}
					if(flag[i-1][j-1]==mon[0][0]&&flag[i-1][j]==mon[0][1]&&flag[i][j-1]==mon[1][0]&&flag[i][j]==mon[1][1]){
						a--;
						}	
					if(flag[i-1][j]==mon[0][0]&&flag[i-1][j+1]==mon[0][1]&&flag[i][j]==mon[1][0]&&flag[i][j+1]==mon[1][1]){
						a--;
						}
					if(flag[i][j-1]==mon[0][0]&&flag[i][j]==mon[0][1]&&flag[i+1][j-1]==mon[1][0]&&flag[i+1][j]==mon[1][1]){
						a--;
						}		
						
					if(joi[k]==mon[0][0]&&flag[i][j+1]==mon[0][1]&&flag[i+1][j]==mon[1][0]&&flag[i+1][j+1]==mon[1][1]){
						a++;
						}
					if(flag[i-1][j-1]==mon[0][0]&&flag[i-1][j]==mon[0][1]&&flag[i][j-1]==mon[1][0]&&joi[k]==mon[1][1]){
						a++;
						}	
					if(flag[i-1][j]==mon[0][0]&&flag[i-1][j+1]==mon[0][1]&&joi[k]==mon[1][0]&&flag[i][j+1]==mon[1][1]){
						a++;
						}
					if(flag[i][j-1]==mon[0][0]&&joi[k]==mon[0][1]&&flag[i+1][j-1]==mon[1][0]&&flag[i+1][j]==mon[1][1]){
						a++;
						}
						ans=max(ans,sum+a);	
					}
				}
			}
		cout<<ans<<endl;
		return 0;			
	}

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

int main() {
    ll n,k,a,b;
    cin>>n>>k;
    map<int,ll> c;
    while (n--) {
        cin>>a>>b;
        c[a]+=b;
    }
    ll sm=0;
    for (auto p:c) {
        sm+=p.second;
        if (k<=sm) {
            cout<<p.first<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 101001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．

// Main program
void solve(){
  ll A,B,K;
  cin >> A ;
  cin >> B ;
  cin >> K ;

  
  ll div,outA,outB;
  if(A-K<=0){
    outA = 0;
    outB = B-(K-A);
  }
  else{
    outA = A-K;
    outB = B;
  }

 if(outA<=0){
    outA=0;
  }
  if(outB<=0){
    outB=0;
  }
  
  cout << outA;
  cout << " ";
  cout << outB;

  return;

}

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






Measured memory_bytes: 256
s = gets.gsub("BC", "D")
ai = nil
di = nil
f = false
ans = 0

s.size.times do |i|
    if s[i] == "A"
        ai = i if ai.nil?
    elsif s[i] == "D" && ai
        ans += i - ai
        ai += 1
    else
        ai = nil
    end
end

puts ans

Measured memory_bytes: 2172
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = list(readline().rstrip().decode('utf-8'))

bl = S[0] == 'A'
bl &= ('C' in S[2:-1])

if bl:
    S.remove('A'); S.remove('C')

bl &= all('a'<=x<='z' for x in S)

answer = 'AC' if bl else 'WA'
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
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 long long INF = 1LL << 60;

int main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int> > a(n, vector<int>(m));
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = 1001001001;
  rep(tmp, (1<<n)){
    bitset<12> s(tmp);
    int sum = 0;
    vector<int> b(m, 0);
    rep(i, n){
      if(s.test(i)){
        sum += c[i];
        rep(j, m) b[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j, m){
      if(b[j] < x) ok = false;
    }
    if(ok) chmin(ans, sum);
  }

  if(ans == 1001001001){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
    string s,t; cin >> s >> t;
    vector<vector<int> > ord(26);
    int sl=s.length();
    int tl=t.length();
    rep(i,sl) ord[s[i]-'a'].push_back(i+1);
    rep(i,sl) ord[s[i]-'a'].push_back(i+1+sl);
    ll ans=0;
    int p=0;
    rep(i,tl){
        if(ord[t[i]-'a'].empty()){
            cout << -1 << endl;
            return 0;
        }
        else{
            p=*upper_bound(ord[t[i]-'a'].begin(),ord[t[i]-'a'].end(),p);
            if(p>sl){
                p-=sl;
                ans+=sl;
            }
        }
    }
    ans+=p;
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 1724
#include <stdio.h>

int gcd(int x, int y)
{
	if(y==0)
		return x;
	else
	return gcd(y, x%y);
}

int main()
{
	int x,y;
	scanf("%d %d", &x, &y);
	
	printf("%d\n", gcd(x,y));
	
	return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

string S;
int N;

int main(){
    cin>>S;
    N=S.size();

    rep(i,N){
        rep(j,N){
            string s=S;
            s.erase(i,j);
            if(s=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }

    cout<<"NO"<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7;
const ld error = 1e-5;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 80+5;
///===========================================  template  =======================================================

ll sum(ll a, ll n){
    ll b = a+n-1;
    ll ans = (a+b)*(b-a+1);
    return ans/2;
}

int main(){
    FASTIO;

    ll n, x, d;
    cin>>n>>x>>d;

    if(d == 0){
        if(x == 0) cout<<1;
        else cout<<n+1;
        cout<<"\n";
        return 0;
    }


    if(d < 0){
        x = x + (n-1)*d;
        d = -d;
    }

    map<ll, int> rem;

    vector<vector<pair<ll, ll> > > ranges;      /// 0 begin, 1 end
    for(int i = 0; i<=n; i++){
        ll sum_x = x*i;
        ll r = MOD(sum_x, d);

        if(rem.find(r) == rem.end()) {
            rem[r] = ranges.size();
            ranges.emplace_back();
        }
        r = rem[r];

        ll sum_d_first = sum(0, i);
        ll sum_d_second = sum(n-i, i);

//        debug(i);
//        debug(sum_x);
//        debug(sum_d_first);
//        debug(sum_d_second);

        ranges[r].emplace_back(sum_x + sum_d_first*d, 0);
        ranges[r].emplace_back(sum_x + sum_d_second*d, 1);
////
//        debug(sum_x + sum_d_first*d);
//        debug(sum_x + sum_d_second*d);
    }

    for(int i = 0; i<ranges.size(); i++)
        sort(ranges[i].begin(), ranges[i].end());


    ll ans = 0;
    for(int r = 0; r <ranges.size(); r++){
        ll last = 0;
        int cnt = 0;
        for(auto p: ranges[r]){
//            cout<<p.first<<" "<<p.second<<"\n";
            if(cnt == 0) last = p.first;
            cnt += (p.second == 0)? 1 : -1;
            if(cnt == 0) ans += ((p.first - last)/d + 1);
        }
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 28204
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<algorithm>

using namespace std;

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

    vector<pair<int, int> > dt(n);
    for (int i = 0; i < n; i++) {
        int ti, di;
        cin >> ti >> di;
        dt[i] = make_pair(di, ti);
    }

    sort(dt.begin(), dt.end(), greater<pair<int, int> >());

    stack<int> stack_d;
    set<int> set_type;
    long long now = 0;
    long long ans = 0;

    for (int i = 0; i < k; i++) {
        if (set_type.count(dt[i].second)) {
            stack_d.push(dt[i].first);
        }
        set_type.insert(dt[i].second);
        now += dt[i].first;
    }

    ans = now + (set_type.size() * set_type.size());

    for (int i = k; i < n; i++) {
        if (stack_d.empty()) {
            break;
        }
        if (set_type.count(dt[i].second)) {
            continue;
        }
        set_type.insert(dt[i].second);
        now = now - stack_d.top() + dt[i].first;
        stack_d.pop();

        long long ans_tmp = now + set_type.size() * set_type.size();
        ans = max(ans, ans_tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4096
n=int(input())
s=[0 for _ in range(52)]
M=["S","H","C","D"]
for _ in range(n):
    a,b=map(str,input().split())
    if a==M[0]:
        a=0
    elif a==M[1]:
        a=1
    elif a==M[2]:
        a=2
    else:
        a=3
    s[13*a+int(b)-1]=1

for i in range(len(s)):
    if s[i]==0:
        print("{} {}".format(M[i//13],i%13+1))



Measured memory_bytes: 5608
#include <iostream>
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int main(){
    int k;
    cin >> k;
    int tmp = 0;
    int cnt = 0;
    for(int x=1;x<=k;x++){
        for(int y=1;y<=k;y++){
            tmp = gcd(x,y);
            for(int z=1;z<=k;z++){
                cnt+=gcd(tmp,z);
            }
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3188
#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 ll inf=1e9+7;
const ll INF=1e18;

vll divide;

void divisor(ll x){
    for(ll i=1;i*i<=x;i++){
        if(x%i==0){
            divide.push_back(i);
            if(i*i!=x)divide.push_back(x/i);
        }
    }
    return;
}

int main(){
    int n,k;cin>>n>>k;
    vin a(n);
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    divisor(sum);
    sort(all(divide));reverse(all(divide));
    int tmp;
    rep(i,divide.size()){
        tmp=divide[i];
        vin r(n);
        rep(i,n)r[i]=a[i]%tmp;
        sort(all(r));
        rep(i,n-1)r[i+1]+=r[i];
        rep(j,n){
            if(tmp*(n-j-1)==r[n-1]&&r[j]<=k){//r[i]==d*(n-i-1)-(r[n]-r[i])
                cout<<divide[i]<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3644
n=int(input())
i=1
num=0
suml=[0]
while num<=10**7+1000:
    num+=i
    suml.append(num)
    i+=1

j=1
while n>suml[j]:
    j+=1
k=suml[j]-n
for ii in range(1,j+1):
    if ii!=k:
        print(ii)

Measured memory_bytes: 3572
import math
N = int(input())
n = round(math.sqrt(N))
counter = 0
for i in range(n):
		if N%(n-i) == 0 and counter == 0:
			counter+=1
			var1=(n-i)
			var2=N/(n-i)
            
print(int(var1+var2-2)) 

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define tc int t;cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff(i,a,b) for(i=a;i<b;i++)
#define fb(i,b,a) for(i=b;i>a;i--)
#define ffi(i,a,b,c) for(i=a;i<b;i+=c)
#define fbi(i,b,a,c) for(i=b;i>a;i-=c)
#define clin(s) getline(cin,s)
#define MOD 1e9+7
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ub upper_bound
#define lb lower_bound
int main() {
	fio;
	//tc{
		int n,i;
		cin>>n;
		int h[n][3];
		ff(i,0,n){
			cin>>h[i][0]>>h[i][1]>>h[i][2];
		}
		int dp[n][3];
		dp[0][0] = h[0][0];
		dp[0][1] = h[0][1];
		dp[0][2] = h[0][2];

		ff(i,1,n){
			dp[i][0]=h[i][0]+max(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=h[i][1]+max(dp[i-1][0],dp[i-1][2]);
			dp[i][2]=h[i][2]+max(dp[i-1][0],dp[i-1][1]);
		}

		cout<<max( dp[n-1][0] , max( dp[n-1][1] , dp[n-1][2] ) );
	//}
	return 0;
}


Measured memory_bytes: 2560
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	string s;
	cin>>s;
	if(s[1]==s[2]&&(s[0]==s[1]||s[2]==s[3])){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int n;
vector<vector<int>> G;

int main(void) {

    cin >> n;
    G.push_back(vector<int>(0));

    for (int i = 1; i <= n; ++i) {
        int u, k;
        cin >> u >> k;
        G.push_back(vector<int>());
        for (int m = 0; m < k; ++m) {
            int v;
            cin >> v;
            G[u].push_back(v);
        }
    }

    queue<int> Q;
    vector<int> color(n + 1, 0);
    vector<int> d(n + 1, -1);
    Q.push(1);
    color[1] = 1;
    d[1] = 0;

    while(!Q.empty()) {
        int idx = Q.front();

        for (int v : G[idx]) {
            // 未訪問
            if (color[v] == 0) {
                d[v] = d[idx] + 1;
                Q.push(v);
                color[v] = 1;
            }
        }

        color[idx] = 2;
        Q.pop();
    }

    for (int i = 1; i <= n; ++i) {
        cout << i << " " << d[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int max = Integer.parseInt(sc.next());
    long ans = 0;
    for (int i = 1; i < n; i++) {
      int a = Integer.parseInt(sc.next());
      if (max <= a) {
        max = a;
      } else {
        ans += max - a;
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 58532
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()

    print((n-1)*(m-1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 77064
#include <bits/stdc++.h>
using namespace std;
int a,b,c,flag,ans,maxx;
int main()
{
	cin>>a>>b>>c;
	if(a%2==b%2&&b%2==c%2){
		maxx=max(a,max(b,c));
		ans+=(maxx*3-a-b-c)/2;
	} else {
		maxx=max(a,max(b,c));
		flag=(a%2+b%2+c%2);
		maxx+=(maxx%2==(flag==2));
		ans+=(maxx*3-a-b-c-2)/2;
		ans+=1;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a , b;
	while(1){
		cin>> a >> b;
		if(a==0)break;
		for (int i = 0; i < a ; i++){
			for (int j = 0; j < b; j++){
				cout << "#" ;
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;
 
int main() {
int n,x,y;
  cin>>n>>x>>y;
  x--; y--;
  vector<int> ans(n);
  rep(sv,n){
  vector<int> dist(n,INF);
  queue<int> q;
  auto push=[&](int v,int d){
 if(dist[v]!=INF) return;
    dist[v]=d;
    q.push(v);
  };
    push(sv,0);
    while(!q.empty()){
    int v =q.front();q.pop();
      int d =dist[v];
      if(v-1>=0) push(v-1,d+1);
      if(v+1<n) push(v+1,d+1);
      if(v==x) push(y,d+1);
      if(v==y) push(x,d+1);
    }
    rep(i,n) ans[dist[i]]++;
  }
    rep(i,n) ans[i]/=2;
    for(int i=1;i<=n-1;i++){
    cout<<ans[i]<<endl;
    }
  } 

Measured memory_bytes: 256
n, K = [int(a) for a in input().split()]
s = [[int(a) for a in input().split()] for _ in range(K)]

MOD = 998244353

dp = [0] * (n + 1)
dp_sum = [0] * (n + 1)
dp[1] = 1

for i in range(1, n+1):
    for l, r in s:
        dp[i] += dp_sum[i-l if (i-l) > 0 else 0] - dp_sum[(i-r-1) if (i-r-1) > 0 else 0]
        dp_sum[i] = (dp[i] + dp_sum[i-1]) % MOD

print(dp[n] % MOD)

Measured memory_bytes: 76828
# -*- coding: utf-8 -*-
import heapq

# N: 買う品物の個数
# M: 持っている割引券の数
N, M = list(map(int, input().split()))

# X 円の品物を買う際に Y 枚の割引券を使った場合、その品物を (X/2^Y) 円(小数点以下切り捨て)で買うことができます。
# 最小で何円あれば全ての品物を買うことができるのか?

# アイディア
# 単に高い商品から順に割引券を使えればよい...
# プライオリティキューを使って最大のものから順次割引していけばよさそう
# Python のプライオリティキューは最小値しか取れないため、すべての値を (* -1) して考える (出力時にまた (* -1) して戻す)
A = [-x for x in map(int, input().split())]
heapq.heapify(A)


for i in range(M):
    # M 回割引券を適用する
    minimal = heapq.heappop(A)
    heapq.heappush(A, minimal / 2)

print(sum([int(x) for x in A]) * -1)


Measured memory_bytes: 98616