akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab_s = sorted(ab, key=lambda x: x[1])
ab_r = list(reversed(ab_s))

t = [x[0] for x in ab_r]
d = [x[1] for x in ab_r]        

t_set = len(set(t[:k]))
d_sum = sum(d[:k])

res = [t_set**2 + d_sum]

from collections import Counter
t_cou = Counter(t[:k])

dp =[0]*(n+1)
j_old = k-1

for i in t_cou:
    dp[i] = t_cou[i]

for i in range(k,n):
    t_new = ab_r[i][0]
    if dp[t_new] ==0:
        for j in range(j_old,-1,-1):
            t_old = ab_r[j][0]
            if dp[t_old] <=1:
                pass
            else:
                dp[t_new] =1
                dp[t_old] -=1
                t_set +=1
                d_sum = d_sum - ab_r[j][1] + ab_r[i][1]
                res.append(t_set**2 + d_sum)
                j_old = j-1
                break
            j_old = 0

print(max(res))

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

int main()
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  if (s[0] == '1') k++;
  int l(0), r(0);
  int ans = r - l;
  while (r < n) {
    while (k > 0) {
      while (r < n && s[r] == '0') r++;
      while (r < n && s[r] == '1') r++;
      k--;
    }
    ans = max(ans, r - l);
    while (l < n && s[l] == '1') l++;
    while (l < n && s[l] == '0') l++;
    k++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a ; cin >> a ;
  rep(i,a+10){
    if(pow((i+1),2) > a) {
      ll ret = pow(i,2);
      cout << ret  << endl;
      return 0;
    }
  }
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main(){
    IOS;
    int a,b,c,k,x=0;
    cin>>a>>b>>c>>k;
    while(b<=a)
        b*=2,x++;
    while(c<=b)
        c*=2,x++;
    if(x>k)
        cout<<"No";
    else
        cout<<"Yes";
}
/*

*/


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

int rec_amari[100];
int rec_shou[100];

int main() {
  int p;
  int q;

  while(scanf("%d %d", &p, &q) != EOF) {
    int restart = 0;
    int stoped = 0;
    bool looped = false;
    int first_p = p;
    
    for (int i=0; 1; i++) {
      p *= 10;
      int shou = p / q;
      int amari = p % q;

      // printf("shou %d amari %d\n",shou,amari);
      
      rec_amari[i] = amari;
      rec_shou[i] = shou;

      // 
      if (amari == first_p) {
	  restart = 0;
	  stoped = i;
	  looped = true;
	  goto END_LOOP;
      }
      
      // ???????????????
      for (int j=0; j<i; j++) {
	if (amari == rec_amari[j]) {
	  restart = j+1;
	  stoped = i;
	  looped = true;
	  goto END_LOOP;
	}
      }

      // ???????????????
      if (amari == 0) {
	stoped = i;
	break;
      }
      
      p = amari;
    }
  END_LOOP:

    // ????????????
    for (int i=0; i<=stoped; i++) {
      printf("%d", rec_shou[i]);
    }
    puts("");
    // ???????????¨???
    if (looped) {
      for (int i=0; i<=stoped; i++) {
	if (i >= restart) {
	  printf("^");
	} else {
	  printf(" ");
	}
      }
      puts("");
    }
    
  }
}

Measured memory_bytes: 3100
def main():
    data0 = input()
    data1 = input()

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while True:
        if data0 == "":
            break

        data0 = data0.replace(data0[0], "")
        data1 = data1.replace(data1[0], "")

        if len(data0) != len(data1):
            print('No')
            exit()

    print('Yes')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3760
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <unordered_map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
typedef long int l;
#define f(i,a,b) for(l i=(l)a;i<(l)b;i+=1)
#define rf(i,a,b) for(l i=(l)a;i>=(l)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0)
using namespace std;
#define MAX 1000001 
l spf[MAX];
void precompute()
{
	spf[1] = 1;
	for (l i = 2; i < MAX; i++)
		spf[i] = i;

	for (l i = 4; i < MAX; i += 2)
		spf[i] = 2;

	for (l i = 3; i * i < MAX; i++)
	{
		if (spf[i] == i)
		{
			for (l j = i * i; j < MAX; j += i)
				if (spf[j] == j)
					spf[j] = i;
		}
	}
}

int main()
{
	FAST;
	ll n;
	cin >> n;
	string s;
	cin >> s;
	f(i, 0, s.length())
	{
		ll temp = s[i];
		n %= 26;
		temp += n;
		if (temp > 90)
			temp -= 91 - 65;
		s[i] = temp;
	}
	cout << s;
	// 65 and 90
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str=input.readLine();
	int m=0,n=str.length()-1;
	char ch[]=str.toCharArray();
	for(int i=n;i>=0;i--)
	    {
		System.out.print(ch[i]);
	    }
	System.out.println();
	    
    }
}

Measured memory_bytes: 16860
#coding utf-8
X = input() 
n = 8
op =[0 for i in range(3)]
for i in range(n):
  p = bin(i)[2:]
  p = "0"*(3-len(p))+p
  Y =""
  for j,k in enumerate(X):
    Y +=k
    if j < 3:
      if p[j:j+1] =="0":
        Y +="+"
      else:
        Y +="-"
  ans = eval(Y)
  if ans ==7:
    print(Y+"=7")
    break




Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
ll gcd2(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {   x = 1;  y = 0;  return a;   }
    ll xx, yy;
    ll res = gcd2(b, a%b, xx, yy);
    x = yy;     y = xx - yy * (a / b);
    return res;
}

// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 1e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        ll d, t, s;
        cin >> d >> t >> s;
        if (d > t*s)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int n=read(),k=read(),a[999];
int main(){
int ans=0;
for (re0 i=1;i<=n;++i){
  int x=read();
  ans+=min(x,k-x)*2;
  }
write(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<vector>
#define N 210000
#define ll long long
#define ls (now<<1)
#define rs ((now<<1)|1)
#define RG register
using namespace std;
inline int read(){
    RG int x=0,o=1; RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=((x<<3)+(x<<1))+ch-'0',ch=getchar();
    return x*o;
}

int main(){
	int a=read(),b=read();
	for(RG int i=1;i<=3;++i)
		if(((i*a*b)&1)) {puts("Yes"); return 0 ;}
	puts("No");
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S;
  cin >> S;
  if (S.back() == 's') S += "es";
  else S += "s";
  cout << S;
}
#endif


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

void main_()
{
    ll N;
    cin >> N;
    vector<ll> as;
    as.reserve(N);
    copy_n(istream_iterator<ll>(cin), N, back_inserter(as));

    vector<ll> sums;
    sums.reserve(N);
    partial_sum(begin(as), end(as), back_inserter(sums));

    vector<ll> abss;
    abss.reserve(N);
    transform(begin(sums), end(sums) - 1, back_inserter(abss),
        [total = sums.back()](auto x) {
            auto y = total - x;
            return abs(x - y);
        });

    cout << *min_element(begin(abss), end(abss)) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 4992
n, x = (int(i) for i in input().split())

a, p = [1], [1]
for i in range(n):
    a.append(a[-1]*2+3)
    p.append(p[-1]*2+1)

def f(n, x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif 1 < x <= a[n-1]+1:
        return f(n-1, x-1)
    elif x == a[n-1]+2:
        return p[n-1] + 1
    elif a[n-1] + 2 < x <= a[n-1]*2 + 2:
        return p[n-1] + f(n-1, x-a[n-1]-2) + 1
    elif x == a[n-1]*2 + 3:
        return p[n-1]*2 + 1

print(f(n,x))

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

int main(){
 int a/*一人目の距離*/,b/*二人目の距離*/,c/*三人目の距離*/,d/*トランシーバーが届く範囲*/;
 cin>>a>>b>>c>>d;
 if(abs(a-c) <= d){
  cout<<"Yes\n";
 }
else if(abs(b-a) <= d && abs(b-c) <= d){
            cout<<"Yes\n";
}
else{
    cout<<"No\n";
}

  return 0;
}

Measured memory_bytes: 256
//R<3S
#include <bits/stdc++.h>
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define ll long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


using namespace std;

void solve()
  {

    string s;
    cin>>s;
    int len=sz(s);
    rep(i,len-1)
    {
      if((s[i+1]=='A'&&s[i]=='B')||(s[i+1]=='B'&&s[i]=='A')){cout<<"Yes";return;}
    }
    cout<<"No";
  }



int main()
{
   FAST
   
   int t;
   t=1;
   //cin>>t;
   while(t--)
  {
      solve();
  }


   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<ll> arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int slow = 0;
    while(arr.size() < n) {
        ll cur = arr[slow++];
        ll last = cur % 10;
        if (last - 1 >= 0)
            arr.push_back(cur*10+(last-1));
        arr.push_back(cur*10+last);
        if (last +1 <= 9)
            arr.push_back(cur*10+(last+1));
    }
    cout << arr[n-1] << endl;
    return 0;
}




Measured memory_bytes: 1592
K = gets.to_i

edges = Array.new(K)
K.times do |i|
    edges[i] = [
        [(i + 1) % K, 1],
        [(i * 10) % K, 0]
    ]
end

dist = Array.new(K, 100)
dist[1] = 1

deque = [1]

while deque.length > 0 do
    v = deque.shift
    edges[v].each do |dst, cost|
        if dist[dst] > dist[v] + cost
            dist[dst] = dist[v] + cost
            if cost == 1
                deque.push(dst)
            else
                deque.unshift(dst)
            end
        end
    end
end

print dist[0]

Measured memory_bytes: 16220
using System;
using System.Collections.Generic;

class p
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        long N = long.Parse(input[0]);
        long C = long.Parse(input[1]);
        long K = long.Parse(input[2]);
        long[] T = new long[N];

        long Index = 0;//先頭の客
        long count = 1;//乗ってる人数
        long ans = 1;

        for(int i = 0; i < N; i++)
        {
            T[i] = long.Parse(Console.ReadLine());
        }

        Array.Sort(T);

        for(int i = 1; i < N; i++)
        {
            if (count == C || T[Index] + K < T[i])
            {
                ans++;
                Index = i;
                count = 1;
            }
            else
            {
                if(Index!=i) count++;
            }
        }

        Console.WriteLine(ans);

    }   
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/

vector<ll> bit;

ll sum(ll i){
	ll s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x){
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}
}

int solve() {
	cin >> n;
	a.resize(n);
	vl b(n);
	bit.resize(n+1, 0);
	REP(i, n){
		cin >> a[i];
	}
	map<ll, ll> m;
	REP(i, n){
		b[i] = a[i];
	}
	sort(ALL(b));
	REP(i, n){
		m[b[i]] = i + 1;
	}
	ll ans = 0;
	for(ll j = 0; j < n; j++){
		ans += j - sum(m[a[j]]);
		add(m[a[j]], 1);
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}



Measured memory_bytes: 20108
#include <iostream>
#include <string.h>
using namespace std;
int main(int argc, char* argv[])
{

	int N,i;
	cin>>N;
	int Sum=0;
	for (i=1;i<=N;i++){
		if (i<10){
			Sum++;
		}else if (i>=100 && i<=999){
			Sum++;
		}else if (i>=10000 && i<=99999){
			Sum++;
		}else if (i>=10000000 && i<=9999999){
			Sum++;
		}
	}
	cout<<Sum<<endl;
	return 0;
}

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

int main()
{
  long long N,A,B;
  
  cin >> N>>A>>B;
  
  if(A+B==0){cout << 0 <<endl;return 0;}
  
  long long Mult=N/(A+B),Remain=min(A,N%(A+B));
  
  cout << Mult*A+Remain <<endl;
  
}

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

int main(){
    int A,B;
    cin >> A >> B;
    int c;
    c = A - 2 * B;
    if( c <= 0) cout << 0 << endl;
    else cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N];
  int B[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    B[i]=A[i];
  }
  sort(B,B+N);
  for(int i=0;i<N;i++){
    if(A[i]==B[N-1]){
      cout << B[N-2] << endl;
    }
    else{
      cout << B[N-1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    long ans = 1000000000;
    for(int i=0; i<=X; i++){
        int k = (X-i)*2;
        int j = max(Y - k/2, 0);
        long t = A*i + B*j + C*k;
        if(t < ans) ans = t;
    }
    for(int j=0; j<=Y; j++){
        int k = (Y-j)*2;
        int i = max(X - k/2, 0);
        long t = A*i + B*j + C*k;
        if(t < ans) ans = t;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
using ll = long long;
using namespace std;

int N, a[301];
double dp[301][301][301];

double rec(int i, int j, int k)
{
    if (dp[i][j][k] >= 0.0){ return dp[i][j][k]; }
    double ret = 0.0;
    if (i != 0) { ret += rec(i - 1, j, k) * i; }
    if (j != 0) { ret += rec(i + 1, j - 1, k) * j; }
    if (k != 0) { ret += rec(i, j + 1, k - 1) * k; }
    ret += N;
    ret *= 1.0 / (i + j + k);
    return dp[i][j][k] = ret;
}

int main()
{
    cin >> N;
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        if (a[i] == 1) one++;
        if (a[i] == 2) two++;
        if (a[i] == 3) three++;
    }
    MEMSET(dp, -1);
    dp[0][0][0] = 0.0;
    cout << fixed << setprecision(10) << rec(one, two, three) << endl;
    return 0;
}

Measured memory_bytes: 213376
string = input()
q = int(input())

for i in range(q):
    cmdln = [i for i in input().split()]
    cmd = cmdln[0]
    a, b = (int(i) for i in cmdln[1:3])
    if cmd == "print":
        print(string[a:b+1])
    elif cmd == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif cmd == "replace":
        p = cmdln[3]
        string = string[:a] + p + string[b+1:]



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

int main(){

	int x, a, b;
	cin >> x >> a >> b;
	if(b-a <= 0){
		cout << "delicious\n";
	}
	else if(b-a <= x){
		cout << "safe\n";
	}
	else if(b-a > x){
		cout << "dangerous\n";
	}

	return 0;

}

Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int X; cin >> X;
	int ans = 0;
	REP(i, 1, 1001) {
		REP(j, 2, 1001) {
			int a = pow(i, j) + 0.0001;
			if (a <= X) {
				ans = max(ans, a);
			}
			else {
				break;
			}
		}
	}
	cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
Q = []
B = [0] * N
C = [0] * (M + 1)
flag = True
MIN = -1
for i in range(N):
  Q.append(list(map(int, input().split())))
  
for i in range(2 ** N):
  C = [0] * (M + 1)
  flag = True
  for j in range(N):
    B[j] = (i >> j) & 1
    
  for j in range(N):
    if B[j] == 1:
      for k in range(M + 1):
        C[k] += Q[j][k]
  for j in range(1, M + 1):
    if C[j] < X:
      flag = False
  if flag == True and (MIN == -1 or MIN > C[0]):
    MIN = C[0]
print(MIN)    

Measured memory_bytes: 9248
n = int(input())

x =[]
y =[]
for i in range(n):
    x1, y1 = [i for i in input().split()]
    x.append(x1)
    y.append(y1)


ans = 0
for i in range(n):
    if y[i] == "JPY":
        ans += int(x[i])
    else:
        ans+= float(x[i])*380000

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

/////////////         UnionFind
//    バラバラの要素を結合してグループにまとめる際に使える構造。
//    グループ番号、要素数の取得が可能だが、グループに属する要素の列挙はO(N)かかる。

class UnionFindClass {
public:
	UnionFindClass() {
		N = 0;
		parent = NULL;
		size = NULL;
	}
	~UnionFindClass() {
		if (parent != NULL) {
			delete[] parent;
		}
		if (size != NULL) {
			delete[] size;
		}
	}

	void activate(int n) {// 要素の数N
		N = n;
		parent = new int[N];
		size = new int[N];
		for (int i = 0; i < N; i++) {
			parent[i] = -1;
			size[i] = 1;
		}
	}

	int getParent(int x) {// グループの親の番号を得る
		if (parent[x] == -1) {
			return x;
		}
		else {
			int y = getParent(parent[x]);
			parent[x] = y;
			return y;
		}
	}
	int getSize(int x) {// 自分が属するグループのサイズを得る
		x = getParent(x);
		return size[x];
	}
	bool connect(int x, int y) {// 二つの要素を結ぶ。２グループ間を繋いだ場合trueを返す
		x = getParent(x);
		y = getParent(y);
		if (x == y) { return false; }
		int xsize = getSize(x), ysize = getSize(y);
		if (xsize < ysize) {
			parent[x] = y;
			size[y] += size[x];
			size[x] = 0;
		}
		else {
			parent[y] = x;
			size[x] += size[y];
			size[y] = 0;
		}
		return true;
	}

	//データ
	int N;// 個数
	int* parent;// 親の番号。自分自身が親なら-1。
	int* size;// 親のみ有効。自分のグループのサイズ。
};

ll getHash(ll r, ll t) {
	return r * 1000000L + t;
}

int main() {
	ll N, K, L; cin >> N >> K >> L;

	UnionFindClass R, T;

	R.activate(N);
	T.activate(N);

	for (int i = 0; i < K; i++) {
		int x, y; cin >> x >> y;
		R.connect(x - 1, y - 1);
	}
	for (int i = 0; i < L; i++) {
		int x, y; cin >> x >> y;
		T.connect(x - 1, y - 1);
	}

	map<ll, int> mp;
	for (int i = 0; i < N; i++) {
		ll h = getHash(R.getParent(i), T.getParent(i));
		if (mp.find(h) == mp.end()) {
			mp.insert({ h, 1 });
		}
		else {
			mp[h]++;
		}
	}

	for (int i = 0; i < N; i++) {
		ll h = getHash(R.getParent(i), T.getParent(i));
		cout << mp[h] << " ";
	}

	return 0;
}

Measured memory_bytes: 15104
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
    int a , b ,x  ;
    scanf("%d%d%d",&x,&a,&b);

    int ab = abs(b-a) ;
    if(a>=b){
        printf("delicious");
    }else{
        if(ab<=x){
            printf("safe");
        }else{
            printf("dangerous");
        }
    }

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N, i, j, k, answer = 0;
	vector<int> L;
	cin >> N;
	for(int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		L.push_back(tmp);
	}
	sort(L.begin(), L.end());
	for(i = 0; i < N; i++){
		for(j = i + 1; j < N; j++){
			for(k = j + 1; k < N; k++){
				if(L[j] < L[i] + L[k] && L[k] < L[i] + L[j]){
					answer++;
				}else{
					break;
				}
			}
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
N=int(input())
*A,=map(int, input().split())
*B,=map(int, input().split())

ans=0
for i in range(N):
    a0 = min(A[i], B[i])
    B[i] -= a0
    a1 = min(A[i+1], B[i])
    ans += a0 + a1
    A[i+1] -= a1
print(ans)

Measured memory_bytes: 87908
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    for (int i=0;i<6;i++){
        cin >> S[i];
    }
    for (int i=0;i<6;i++){
        if(S[2]==S[3] && S[4] == S[5]){
            cout <<"Yes" << endl;
            break;
        }
        else {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3612
M, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
accum = [0]
d = {0 : 1}

for i, a in enumerate(A):
  accum.append((accum[-1] + a - 1)%K)
  if i >= K - 1:
    d[accum[i-K+1]] -= 1
  
  if accum[-1] in d:
    ans += d[accum[-1]]
    d[accum[-1]] += 1
  
  else:
    d[accum[-1]] = 1

print(ans)

Measured memory_bytes: 38820
#include<iostream>

using namespace std;

int main(){
  int i,j,n,a;
  
  cin>>n;
  a=n;
  
  while(n!=0){
    i=n%10;
    j+=i;
    n=n/10;
  }
  cout<<(a%j==0?"Yes":"No")<<endl;
  
  return 0;
}
  

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }

typedef long long ll;



int main() {
    int N;
    cin >> N;
    string ans = "No";
    FOR(i,1,10) {
        FOR(j,1,10) {
            if (i*j == N) ans = "Yes";
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j;
	int n,ca[10],ba=0,temp;
	char c;
	scanf("%d",&n);
	while(n!=0){
		for(j=0;j<n;j++){
			ca[j]=0;
		}
		j=0;
		for(i=0;i<100;i++){
			scanf(" %c",&c);
			if(c=='M'){
				ca[j]=ca[j]+1;
			}
			else if(c=='S'){
				ba=ba+1+ca[j];
				ca[j]=ca[j]-ca[j];
			}
			else if(c=='L'){
				ca[j]=ca[j]+ba+1;
				ba=ba-ba;
			}
			j++;
			if(j==n){
				j=0;
			}
		}
		for(i=0;i<n;i++){
			for(j=n-1;j>0;j--){
				
				if(ca[j]<ca[j-1]){
					temp=ca[j];
					ca[j]=ca[j-1];
					ca[j-1]=temp;
				}
			}
		}
		for(j=0;j<n;j++){
			printf("%d ",ca[j]);
		}
		printf("%d\n",ba);
		j=0;
		ba=0;
		scanf("%d",&n);
	}
	return 0;
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
map<ll, ll> mp;

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    ll ans = 0;
    REP(i, n) {
        cin >> a[i];
        a[i] %= m;
    }
    int wa = 0;
    REP(i, n) {
        wa += a[i];
        wa %= m;
        a[i] = wa;
    }

    mp[0] = 1;

    REP(i, n) {
        ans += mp[a[i]];
        mp[a[i]]++;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int n;
  string s;
  cin>>n>>s;
  for (int i;i<s.length();i++){
    int c = s[i]-'A';
    s[i] = 'A'+(n+c)%26;
  }
  cout << s << endl;
  return 0;
}


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

int main(){
  int N;
  string S,T;
  cin >> N >> S >> T;
  bool a=false;
  for(int i=0;i<N;i++){
    if(S.substr(i,N-i)==T.substr(0,N-i)){
      a=true;
      cout << N+i << endl;
      break;
    }
  }
  if(!a){
    cout << 2*N << endl;
  }
} 

Measured memory_bytes: 3556
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N;
	long long K;
	cin >> N >> K;
	vector<int>A(N);
	for (int n1 = 0; n1 < N; ++n1) {
		cin >> A[n1];
	}

	//ついた町リスト
	vector<int>B; 
	vector<int>C(N+1);
	map<int, int> map;

	int nNow = 1;
	int  a = 0;
	int b = 0;
	for (int n2 = 0; n2 < N; ++n2) {
		B.push_back(nNow);
		C[nNow] = 1;
		map[nNow] = n2;
		nNow = A[nNow - 1];

		if (1 == C[nNow]) {
			a = map[nNow];
			break;
		}
	}
	//abcd(b)
	//a= 1

	b = B.size() - a;

	int nRet = -1;
	if (K < (long long)B.size()) {
		nRet = B[K];
	}
	else {
		long long c = (K - a) % (b)+a;
			nRet = B[c];
	}

	cout << nRet << endl;
	return 0;
}

Measured memory_bytes: 14632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int x1 = in.nextInt();
		int x2 = in.nextInt();
		int x3 = in.nextInt();
		int x4 = in.nextInt();
		int x5 = in.nextInt();
		
		if(x1 == 0) {
			System.out.println(1);
		}
		if(x2 == 0) {
			System.out.println(2);
		}
		if(x3 == 0) {
			System.out.println(3);
		}
		if(x4 == 0) {
			System.out.println(4);
		}
		if(x5 == 0) {
			System.out.println(5);
		}
	}
}

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

int main (void){
  int a,d,n,k,ans = 0;
  int have[110] = {};

  cin >> n >> k;

  for(int i = 0;i < k;i++){
    cin >> d;
    for(int j = 0;j < d;j++){
      cin >> a;
      a--;
      have[a]++;
    }
  }

  for(int i = 0;i < n;i++){
    if(have[i] == 0){
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;

}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		String[] tmpArray = br.readLine().split(" ");
		int input[] = new int[n];
		
		int negative = 0;
		int positive = 0;
		
		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
			if(input[i] > 0){
				positive++;
			}
			else if(input[i] < 0){
				negative++;
			}
		}
		
		if((positive > 0 && negative == 0) || (positive == 0 && negative > 0)){
			System.out.println("0");
			return;
		}
		else if(positive == 0 && negative == 0){
			System.out.println((long)n*(n+1)/2);
			return;
		}
		
		long result = 0;
		
//		for(int i = 0; i < n; i++){
//			long tmp = 0;
//			for(int j = i; j < n; j++){
//				tmp += input[j];
//				
////				System.out.print(tmp +" ");
//				if(tmp == 0){
//					result++;
//				}
//			}
//		}
		
//		System.out.println(result);
		System.out.println(solve(input, 0, n));
	}
	
	static long solve(int[] input, int left, int right){
//		System.out.println("left "+left+" right "+right);
		if(right - left <= 1){
			if(input[left] == 0){
				return 1;
			}
			else {
				return 0;
			}
		}
		
		int mid = (left+right)/2;
		
		long result = 0;
		
//		System.out.println("left "+left+" right "+right+ " mid "+mid);
		
		result += solve(input, left, mid);
		result += solve(input, mid, right);
		
//		long rightSum = 0;
		long[] rightSum = new long[right - mid];
		long[] leftSum = new long[mid - left];
		
		long tmpSum = 0;
		for(int i = mid; i < right ; i++){
			tmpSum += input[i];
			
			rightSum[i - mid] = tmpSum;
		}

		tmpSum = 0;
		for(int i = mid - 1; i >= left ; i--){
			tmpSum += input[i];
			
			leftSum[mid - 1 - i] = tmpSum;
		}
		
//		Arrays.sort(leftSum);
		//debug
//		for(int i = 0; i < leftSum.length ; i++){
////			System.out.print(leftSum[i]);
//		}
//		System.out.println();
		Arrays.sort(rightSum);
		
		for(int i = 0; i < leftSum.length ; i++){
			int index = Arrays.binarySearch(rightSum, -leftSum[i]);
			
			if(index >= 0){
				result++;
//				System.out.println("left "+left+" right "+right+" mid "+mid+ "hit "+leftSum[i]);
				
				for(int j = index - 1; j >= 0; j--){
					if(rightSum[j] != -leftSum[i]){
						break;
					}
					result++;
				}
				
				for(int j = index + 1; j < rightSum.length; j++){
					if(rightSum[j] != -leftSum[i]){
						break;
					}
					result++;
				}
			}
		}
		
		
		return result;
	}

}



Measured memory_bytes: 64084
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define mod 1000000007

vector<int> v[100001];

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int n, k; cin >> n>> k;
        lp(i, n) { int a, b; cin >> a>> b; v[a].push_back(b); }
        lp(i, 100001) if (sz(v[i])) sort(all(v[i]));
        int cur = k - 1, pos = 1, an = 0;
        priority_queue <int> pq;
        while ( cur-- >= 0 ) {
                lp(i, sz(v[pos])) { pq.push(v[pos][i]); }
                if (sz(pq)) { an += pq.top(); pq.pop(); }
                pos++;
        }
        cout << an;
return 0;
}


Measured memory_bytes: 5632
#include <cassert>
#include <cstdlib>
#include <iostream>
using namespace std;

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

int correct(int pos, int limit) {
	return pos > limit ? limit : pos < 1 ? 1 : pos;
}

void update(int &x, int &y, int dir, int amount, int w, int h) {
	x = correct(x + dx[dir] * amount, w);
	y = correct(y + dy[dir] * amount, h);
}

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

	for(int w, h; cin >> w >> h && w;) {
		int x = 1, y = 1;
		int dir = 0;

		while(true) {
			string instruction;
			cin >> instruction;

			switch(instruction[0]) {
			case 'F': // forward
			{
				int k;
				cin >> k;
				update(x, y, dir, k, w, h);
				break;
			}
			case 'B': // backward
			{
				int k;
				cin >> k;
				update(x, y, dir ^ 2, k, w, h);
				break;
			}
			case 'R': // right
			{
				dir = (dir + 1) % 4;
				break;
			}
			case 'L': // left
			{
				dir = (dir + 3) % 4;
				break;
			}
			case 'S': // stop
			{
				goto finish;
			}
			default:
			{
				assert(false);
			}
			}
		}

	finish:;
		cout << x << " " << y << endl;
	}

	return EXIT_SUCCESS;
}

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

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, u, w, N, M, S, T;
	scanf("%d %d", &N, &M);
	list **adj = (list**)malloc(sizeof(list*) * (N + 1) * 3), *d = (list*)malloc(sizeof(list) * M * 3);
	for (i = 1; i <= N * 3; i++) adj[i] = NULL;
	for (i = 0; i < M; i++) {
		scanf("%d %d", &u, &w);
		d[i*3].v = w + N;
		d[i*3].next = adj[u];
		adj[u] = &(d[i*3]);
		d[i*3+1].v = w + N * 2;
		d[i*3+1].next = adj[u+N];
		adj[u+N] = &(d[i*3+1]);
		d[i*3+2].v = w;
		d[i*3+2].next = adj[u+N*2];
		adj[u+N*2] = &(d[i*3+2]);
	}
	scanf("%d %d", &S, &T);
	
	int dist[300001] = {}, q[300001], head, tail;
	list *p;
	dist[S] = 1;
	q[0] = S;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			if (dist[p->v] == 0) {
				dist[p->v] = dist[u] + 1;
				q[tail++] = p->v;
			}
		}
	}
	
	printf("%d\n", (dist[T] + 2) / 3 - 1);
	fflush(stdout);
	return 0;
}

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

int main(){
    int N,M;
    cin>>N>>M;
    bool ship_from_1[200010]={false};
    bool ship_from_N[200010]={false};
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        if(a==1||b==1){
            int target_island=a==1?b:a;
            ship_from_1[target_island]=true;
        }
        if(a==N||b==N){
            int target_island=a==N?b:a;
            ship_from_N[target_island]=true;
        }
    }
    string ans="IMPOSSIBLE";
    for(int i=1;i<N;i++){
        if(ship_from_1[i]&&ship_from_N[i]){
            ans="POSSIBLE";
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define vi vector<int>
#define mod 100000007
const int N=1e5+2;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int arr[n][3];int dp[n+1][4];
    memset(dp,-1,(n+1)*4);
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>arr[i][j];
        }
    }
  
      dp[0][0]=arr[0][0];
      dp[0][1]=arr[0][1];
      dp[0][2]=arr[0][2];
      
    
      for(int i=1;i<n;i++){
          
        dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
      
      }
       int ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
      cout<<ans<<endl;
  
}

Measured memory_bytes: 2944
#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-1; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin >>s;
    if(s[0]==s[1]&&s[1]==s[2])cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll x;
int main(){FAST;
cin>>x;
ll ans = x/500*1000;
ll rem = x%500;
ans+=rem/5*5;
cout<<ans;
return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

char_map = {}
char_map_t = {}

result = 'Yes'

for s, t in zip(S, T):
    if s in char_map:
        if t == char_map[s]:
            continue
        else:
            result = 'No'
            break
    else:
        char_map[s] = t

    if t in char_map_t:
        if s == char_map_t[t]:
            continue
        else:
            result = 'No'
            break
    else:
        char_map_t[t] = s

print(result)


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/29  Problem: 077_arc_c / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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


	deque<int>dq;
	cin >> N;
	FOR(i, 0, N) {
		int a; cin >> a;
		if (SZ(dq) % 2 == N%2) { dq.push_back(a); }
		else { dq.push_front(a); }
	}
	FOR(i, 0, N) {
		cout << dq.front() << (i != N - 1 ? ' ' : '\n');
		dq.pop_front();
	}

	return 0;
}


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

using namespace std;

int main()
{ 
	string a,b,c;
	cin>>a>>b>>c;
	int d=a.length();
	int e=b.length();
	if(a[d-1]==b[0]&&b[e-1]==c[0]){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int c[3][3];

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            scanf("%d", &c[i][j]);
        }
    }

    int f = 1;

    for(int x = 0; x <= 100; x++){
        if(f == 0){
            break;
        }
        for(int y = 0; y <= 100; y++){
            if(f == 0){
                break;
            }
            for(int z = 0; z <= 100; z++){
                if(c[0][0] - x == c[1][0] - y && c[1][0] - y == c[2][0] - z){
                    if(c[0][1] - x == c[1][1] - y && c[1][1] - y == c[2][1] - z){
                        if(c[0][2] - x == c[1][2] - y && c[1][2] - y == c[2][2] - z){
                            f = 0;
                            break;
                        }
                    }
                }
            }
        }
    }

    if(f == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1640
#coding: utf-8

while True:
    h, w = map(int, input().split())
    if h + w == 0:
        break
    line0 = '#' * w
    line1 = '#' + '.' * (w - 2) + '#'
    print(line0)
    for i in range(h - 2):
        print(line1)
    print(line0)
    print('')


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
const int N = 1e5 + 5;
int height[N];
int dp[N];
int k;

int solve (int n) {

	dp[1] = 0;
	f(i, 2, n + 1) {
		int ming = INT_MAX;
		f(j, 1, min(i, k + 1)) ming = min(ming, abs(height[i] - height[i - j]) + dp[i - j]);
		dp[i] = ming;
	}
	return dp[n];
}

int32_t main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;

	int n;
	cin >> n >> k;
	f(i, 1, n + 1) cin >> height[i];
	cout << solve(n) << nl;
}


Measured memory_bytes: 5172
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

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

  P(n / 3);
  return 0;
}



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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    bool judge;
    while (true) {
        C -= B;
        if (C <= 0) {
            judge = true;
            break;
        }

        A -= D;

        if (A <= 0) {
            judge = false;
            break;
        }
    }

    if (judge)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592