akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		dPA();

	}

	private static void dPA() {
		Scanner scanner = null;
		int numDay = 0;

		try {
			scanner = new Scanner(System.in);
			numDay = scanner.nextInt();
			int[][] dayArray = new int[numDay][3];
			int[][] koufukuArray = new int[numDay][3];

			for (int i = 0; i < numDay; i++) {
				dayArray[i][0] = scanner.nextInt();
				dayArray[i][1] = scanner.nextInt();
				dayArray[i][2] = scanner.nextInt();
			}

			koufukuArray[0][0] = dayArray[0][0];
			koufukuArray[0][1] = dayArray[0][1];
			koufukuArray[0][2] = dayArray[0][2];
			for (int i = 1; i < dayArray.length; i++) {
				koufukuArray[i][0] = Math.max(dayArray[i][0] + koufukuArray[i - 1][1], dayArray[i][0] + koufukuArray[i - 1][2]);
				koufukuArray[i][1] = Math.max(dayArray[i][1] + koufukuArray[i - 1][0], dayArray[i][1] + koufukuArray[i - 1][2]);
				koufukuArray[i][2] = Math.max(dayArray[i][2] + koufukuArray[i - 1][0], dayArray[i][2] + koufukuArray[i - 1][1]);
			}

			int koufuku = 0;
			for (int i = 0; i < 3; i++) {
				koufuku = Math.max(koufukuArray[koufukuArray.length - 1][i], koufuku);
			}

			System.out.println(koufuku);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 101096
from collections import deque
import sys
sys.setrecursionlimit(300000)

N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  l,r,d = map(int, input().split())
  l,r = l-1,r-1
  E[l].append((r,d))
  E[r].append((l,-d)) 
  
#for e in E:
#  print(e)
  
# dfs
visited = [False] * N

INF = 10**16
A = [ INF ] * N

def dfs(now, prev, num):
  visited[now] = True
  if A[now] == INF:
    A[now] = num
  else:
    pass
  for nxt, dis in E[now]:
    if nxt == prev:
      continue
    if A[nxt] < INF and A[nxt] != num + dis:
      # ある点において2通りのnum設定の仕方がある
      print("No")
      exit(0)
    if visited[nxt]:
      continue
    dfs(nxt, now, num + dis)
  return 

for i in range(N):
  if visited[i]:
    continue
  dfs(i,-1,0)
  
print("Yes")

Measured memory_bytes: 135320
def main():
    n, c, k = map(int, input().split())
    customers = [int(input()) for i in range(n)]
    
    customers.sort()
    bus_count = 0
    in_bus = []

    for i in range(n):
        if len(in_bus) == 0:
            in_bus.append(customers[i])
        elif len(in_bus) < c and customers[i] <= in_bus[0] + k:
            in_bus.append(customers[i])
        else:
            bus_count += 1
            in_bus = []
            in_bus.append(customers[i])
    
    print(bus_count+1)

if __name__ == '__main__':
    main()

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

int main(){
    int A,B,C,D=0;
    cin >>A >>B >>C;
    if((A!=C)&&(A==B))D++;
    if((A!=B)&&(A==C))D++;
    if((B!=A)&&(B==C))D++;
    if(D>0){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

#if !ONLINE_JUDGE
#define debug
#endif

using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i,k) for(int i=k;i>=0;i--)
#define rep(i,k) for(int i=0;i<k;i++)
#define repn(i,k1,k2) for(ll i=k1;i<k2;i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001

#define trav(a, v) for(auto& a : v)

#define tt ll t;cin>>t; while(t--)
typedef long long int ll;
 
typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr>vvpr;
typedef vector<vi> vvi;

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;

#ifdef debug
#define dbg(...) { cerr<<"[ "; dump(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.ff<<","<<x.ss<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const unordered_map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
} 
 
template <typename Arg1>
void dump(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void dump(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    dump(names.substr(1+(int)name.size()), args...);
}
#else
    #define dbg(args...)
#endif
 
ll powmod(ll x, ll y) 
{ 
    ll res = 1;  
    x = x % MOD;
    while (y > 0) 
    { 
        if (y & 1) 
  	      res = (res*x) % MOD; 
        y = y>>1; // y = y/2 
        x = (x*x) % MOD;   
    } 
    return res; 
} 

int main()
{
	/*#if !ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);*/
	
	ll a,b,c;cin>>a>>b>>c;
	if(a%2 and b%2 and c%2){
		cout<<min(a*b,min(b*c,a*c));
	}	
	else cout<<"0";  	
}

Measured memory_bytes: 256
import Control.Monad

main = do
    a <- map read . words <$> getLine :: IO [Int]
    let isAllIn = 1 `elem` a && 7 `elem` a && 9 `elem` a && 4 `elem` a
    --let ans = filter (/=1) $ filter (/=7) $ filter (/=9) $ filter (/=4) a
    --if length ans == 0 then putStrLn $ "YES" else putStrLn $ "NO"
    if isAllIn then putStrLn $ "YES" else putStrLn $ "NO"

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

int main() {
    int n;
    long long sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) if(!(i % 3 == 0 || i % 5 == 0)) sum += i;
    cout << sum << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        a[i] = 0;
    }
    int x=1,y=1,z=1;
    while(x<=sqrt(n))
    {
        y = 1;
        while(y<=sqrt(n))
        {
            z = 1;
            while(z<=sqrt(n))
            {
                int value = x*x + y*y + z*z + x*z + x*y + y*z;
                if(value <= n)
                {
                    value--;
                    a[value]++;
                }
                z++;
            }
            y++;
        }
        x++;
    }
    for(int i=0;i<n;i++)
    {
        cout << a[i] << endl;
    }
	return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;cin >> n;
    vector<int> p(n),q(n);
    REP(i,n){
        cin >> p[i];
        q[p[i]-1]=i;
    }
    int m=0,cnt=1;
    REP(i,n-1){
        if(q[i]<q[i+1]){
            cnt++;
        }
        else{
            chmax(m,cnt);
            cnt=1;
        }
    }
    chmax(m,cnt);
    cout << n-m << endl;
}

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

int main() {
	int A,B;
	cin >> A >> B;
  if(A>=13){
    cout << B << endl;
  } else if(A>=6){
    cout << B/2 << endl;
  } else if(A<=5){
    cout << 0 << endl;
  }
}

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

char s[1001];
int n;

bool judge(int l,int r)
{
	for(register int i=l,j=r;i<j;i++,j--)
		if(s[i]!=s[j]) return false;
	return true;
}

signed main()
{
	cin>>(s+1);
	n=strlen(s+1);
	if(judge(1,n)&&judge(1,(n-1)/2)&&judge((n+3)/2,n)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

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

    int res;
    while (1) {
        if (n % 111 == 0) {
            res = n;
            break;
        }
        n++;
    }

    cout << res << endl;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    ll n;
    cin>>n;
    ll a[n];
    ll ans=1LL,mx=1e18,z=0;
    for(ll i=0;i<n;i++)
    {
    	cin>>a[i];
    	if(!a[i])
    		z++;
    }

    if(z)
    {
    	cout<<0<<endl;
    	return 0;
    }

    for(int i=0;i<n;i++)
    {
    	if(a[i]<=mx/ans)
    		ans*=a[i];
    	else
    	{
    		cout<<-1<<endl;
    		return 0;
    	}
    }

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

Measured memory_bytes: 4400
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
ll n;
ll a[100010];

int main() {
    string s;
    cin >> s;
    int fr = stoi(s.substr(0, 2));
    int sc = stoi(s.substr(2, 4));
    if ((fr > 12 && sc > 12) || fr + sc == 0) {
        cout << "NA" << endl;
    } else if (fr > 12 && sc <= 12) {
        if (sc == 0) {
            cout << "NA" << endl;
        } else {
            cout << "YYMM" << endl;
        }
    } else if (fr <= 12 && sc > 12) {
        if (fr == 0) {
            cout << "NA" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        if (fr == 0) {
            cout << "YYMM" << endl;
        } else if (sc == 0) {
            cout << "MMYY" << endl;
        } else {
            cout << "AMBIGUOUS" << endl;
        }
    }
}



Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Edge{
        int cost, dest;
        Edge(int cost, int dest): cost(cost), dest(dest){ }
        ostream& operator >> (ostream& out){
            return out << '(' << cost << ':' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
        ll height = 0;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    // vector<Edge> edges;
    // Graph(int nn, int en = 10): nodes(nn){
    //     edges.reserve(en);
    // }
    // void addEdge(int from, int dest, ll cost = 1){
    //     nodes[from].outEdges.emplace_back(edges.size());
    //     edges.emplace_back(from, dest, limit);
    // }
    void addEdge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void addEdge2(int from, int dest, int cost = 1){
        addEdge(from, dest, cost);
        addEdge(dest, from, cost);
    }
    void dfs(int idx, ll height, int from = -1){
        nodes[idx].height = height;
        for(auto& e : nodes[idx].edges){
            if(e.dest == from){ continue; }
            dfs(e.dest, height + e.cost, idx);
        }
    }
};

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        // cin >> a >> b >> c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        g.addEdge2(a, b, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    g.dfs(k, 0);
    for(int i = 0; i < q; i++){
        int x, y;
        // cin >> x >> y;
        scanf("%d %d", &x, &y);
        x--; y--;
        cout << g.nodes[x].height + g.nodes[y].height << '\n';
    }
}


Measured memory_bytes: 11392
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
		ll l, k;
		cin >> l >> k;
		vector<vector<ll>> dp(l + 1, vector<ll>(l + 1, 0));
		ll ans = 0;
		dp[0][0] = 1;
		FOR(i,1,l+1) FOR(j,1,l+1) {
			dp[i][j] += dp[i - 1][j - 1];
			if(j >= k) dp[i][j] += dp[i - 1][j - k];
		}
		FOR(i,1,l + 1) FOR(j,1,l+1) {
			if(l - j >= i - 1) ans += dp[i][j];
		}
		cout << ans << endl;
	return 0;
}
/* --------------------------------------- */



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

int main() {
  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  for (int i=0; i<N; i++)
    cin >> a.at(i) >> b.at(i);
  int amax = 0;
  for (int i=0; i<a.size(); i++)
    if (amax < a.at(i))
      amax = a.at(i);
  sort(b.begin(), b.end(), greater<int>());
  
  int i=0;
  while (true) {
    if (H > 0 && i < b.size() && b.at(i) > amax) {
      H -= b.at(i);
      i++;
    } else {
      if (H < 0) {
        cout << i << endl;
        break;
      }
      i += H / amax;
      if (H % amax == 0) cout << i << endl;
      else cout << i + 1 << endl;
      break;
    }
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int n, ans = 0;
vector<PIB> stones;
int main()
{
  while(true){
    cin >> n;
    if(!n)
      break;

    stones.clear();
    ans = 0;
    for(int i = 1; i <= n; i++){
      bool stone;
      cin >> stone;
      
      if(i % 2){
	if(i == 1 || (stones.end() - 1)->second != stone)
	  stones.push_back(make_pair(1, stone));
	else
	  (stones.end() - 1)->first++;
      }
      
      else{
	if((stones.end() - 1)->second != stone){
	  (stones.end() - 1)->second = stone;
	  if(stones.end() - 1 != stones.begin()){
	    (stones.end() - 2)->first += (stones.end() - 1)->first;
	    stones.erase(stones.end() - 1);
	  }
	}
	(stones.end() - 1)->first++;
      }
    }

    for(int i = 0; i < stones.size(); i++)
      if(!stones[i].second)
	ans += stones[i].first;
    
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	//ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	ll l_ans = 0;
	string s_ans = "NG";
	ll l, r;

	cin >> a >> b;

	if (a > b) {
		l_ans += a;
		a--;
	}
	else {
		l_ans += b;
		b--;
	}

	if (a > b) {
		l_ans += a;
		a--;
	}
	else {
		l_ans += b;
		b--;
	}

	cout << l_ans << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}

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

int n,dp[100001];

int main(){
    scanf("%d",&n);
    dp[0]=0;
    for(int i=1;i<=n;i++){
        dp[i]=dp[i-1]+1;
        for(int j=6;j<=i;j*=6)dp[i]=min(dp[i],dp[i-j]+1);
        for(int j=9;j<=i;j*=9)dp[i]=min(dp[i],dp[i-j]+1);
    }
    printf("%d\n",dp[n]);
}

Measured memory_bytes: 512
// ~maqsat~
/*
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 2e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
    fre("");
    ACCELERATE;
	
	ll n;
	cin >> n;
	cout << n * (n - 1) / 2;

    return 0;
}
/*
 
*/


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>

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

using namespace std;

typedef	long long	ll;

int main(){
	ll order[9];
	rep(i,9)	order[i]=(i+1)*9*(ll)pow(10.,i);

	for(int n,k;scanf("%d%d",&n,&k),n;){
		int p;
		for(p=0;p<9;p++){
			if(n<=order[p])	break;
			n-=order[p];
		}

		int startnum=(int)pow(10.,p)+(n-1)/(p+1);
		int startdgt=(n-1)%(p+1);
		char ans[256]="",tmp[16];
		sprintf(tmp,"%d",startnum);
		strcat(ans,tmp+startdgt);
		for(int i=0,j=startnum+1;i<k;i+=p+1,j++){
			sprintf(tmp,"%d",j);
			strcat(ans,tmp);
		}
		ans[k]='\0';
		puts(ans);
	}

	return 0;
}

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

int main() {
	int x;
	int n;
	int p[128] = {0};
	
	scanf("%d", &x);
	scanf("%d", &n);
	for(int i=0; i<n; i++) {
	    int v;
	    scanf("%d", &v);
	    p[v] = 1;
	}
	int md = 1024;
	int sel = -1;
	for(int i=0; i<=101; i++) {
	    if(p[i]) {
	        continue;
	    }
	    int td = abs(x - i);
	    if(td < md) {
	        md = td;
	        sel = i;
	    }
	}
	printf("%d\n", sel);
	return 0;
}


Measured memory_bytes: 3720
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
    char ch;
    for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
    int x=ch-'0';
    for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x;
}

const int N=3*1e5+5;

int w,h,n,ta,tb,ans;
struct P{int x,y;}p[N],sta[N],stb[N];
bool cmp(P x,P y) {return x.x<y.x;}

int tr[N<<2],tag[N<<2];

void add(int v,int z) {tr[v]+=z;tag[v]+=z;}

void down(int v) {
    if (tag[v]) {
        add(v<<1,tag[v]);
        add(v<<1|1,tag[v]);
        tag[v]=0;
    }
}

void modify(int v,int l,int r,int x,int y,int z) {
    if (l==x&&r==y) {add(v,z);return;}
    int mid=l+r>>1;down(v);
    if (y<=mid) modify(v<<1,l,mid,x,y,z);
    else if (x>mid) modify(v<<1|1,mid+1,r,x,y,z);
    else modify(v<<1,l,mid,x,mid,z),modify(v<<1|1,mid+1,r,mid+1,y,z);
    tr[v]=max(tr[v<<1],tr[v<<1|1]);
}

void solve() {
    sort(p+1,p+n+1,cmp);
    fo(i,1,n<<2) tr[i]=tag[i]=0;
    ta=tb=0;
    fo(i,1,n) {
        ans=max(ans,tr[1]+p[i].x);
        if (p[i].y<=h/2) {
            int la=i-1;
            while (ta&&sta[ta].y<p[i].y) {
                modify(1,1,n,sta[ta].x,la,sta[ta].y-p[i].y);
                la=sta[ta--].x-1;
            }
            if (la!=i-1) sta[++ta].x=la+1,sta[ta].y=p[i].y;
        } else {
            int la=i-1;
            while (tb&&stb[tb].y>p[i].y) {
                modify(1,1,n,stb[tb].x,la,p[i].y-stb[tb].y);
                la=stb[tb--].x-1;
            }
            if (la!=i-1) stb[++tb].x=la+1,stb[tb].y=p[i].y;
        }
        sta[++ta].x=i;sta[ta].y=0;
        stb[++tb].x=i;stb[tb].y=h;
        modify(1,1,n,i,i,h-p[i].x);
    }
}

int main() {
    // freopen("paint.in","r",stdin);
    // freopen("paint.out","w",stdout);
    w=read();h=read();n=read();
    fo(i,1,n) {
        p[i].x=read();
        p[i].y=read();
    }
    p[++n].x=0;p[n].y=0;
    p[++n].x=w;p[n].y=h;
    solve();
    fo(i,1,n) swap(p[i].x,p[i].y);
    swap(w,h);
    solve();
    printf("%d\n",ans*2);
    return 0;
}

Measured memory_bytes: 16512
#include<stdio.h>


int main(void){
    int N,M;

    scanf("%d", &N);
    scanf("%d", &M);

    int A[M];
    int sum=0,ans;

    for(int i=0;i<M;i++){
        scanf("%d", &A[i]);
        sum += A[i];
    }

    ans = N-sum;

    if(ans<0){
        printf("-1");
    }
    else{
        printf("%d", ans);
    }

    return 0;
}

Measured memory_bytes: 1764
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<uint32_t> an(n);
    for(uint32_t& a : an){
        cin >> a;
    }

    sort(an.begin(), an.end());
    vector<uint32_t> unique;
    unique_copy(an.begin(), an.end(), back_inserter(unique));

    size_t count[unique.size()] = {};
    for(int i = 0; i < 3 ;i++){
        count[i] =  count_if(
                        an.begin(), 
                        an.end(), 
                        [unique, i](uint32_t a)->bool{
                            return a == unique[i];
                        }
                    );
    }

    bool exists = true;
    switch(unique.size()){
        case 3:
        {
            if (   (count[0] != (size_t) n / 3) 
                || (count[1] != (size_t) n / 3))
            {
                    exists = false;
            }

            if((unique[0] ^ unique[1]) != unique[2])
            {
                exists = false;
                break;
            }
        }
        break;
        case 2:
        {
            if (   (count[0] == (size_t) 2 * n / 3) 
                || (count[1] == (size_t) 2 * n / 3))
            {
                exists = true;
            }
            else
            {
                exists = false;
                break;
            }

            uint32_t major = count[0] > count[1] ? unique[0] : unique[1];
            uint32_t minor = count[0] > count[1] ? unique[1] : unique[0];

            if((major ^ major) != minor)
            {
                exists = false;
                break;
            }
        }
        break;
        case 1:
        {
            if(unique[0] != 0){
                exists = false;
            }
        }
        break;
        default:
            exists = false;
        break;
    }
    
    string result = exists ? "Yes" : "No"; 
    cout << result << endl;

    return 0;
}



Measured memory_bytes: 2808
def solve(string):
    n, m, *a = map(int, string.split())
    needs = {i + 1: n for i, n in enumerate(map(int, "2 5 5 4 5 6 3 7 6".split()))}
    if 2 in a and 5 in a or 2 in a and 3 in a:
        a.remove(2)
    if 3 in a and 5 in a:
        a.remove(3)
    if 6 in a and 9 in a:
        a.remove(6)
    a = sorted(a, key=lambda x: needs[x])
    index = 0
    base = str(a[0]) * (n // needs[a[0]])
    n %= needs[a[0]]
    while n > 0:
        use = [_b for _b in a if needs[_b] <= needs[a[0]] + n]
        if len(use) == 1:
            base = base[:-1]
            n += needs[a[0]]
            continue
        flag = max(use) == a[0]
        tmp_n = use[-1] if flag else max(use)
        diff = needs[tmp_n] - needs[a[0]]
        tmp_c = n // diff
        if flag:
            base = base[:-tmp_c] + str(tmp_n) * tmp_c
        else:
            base = base[:index] + str(tmp_n) * tmp_c + base[index + tmp_c:]
            index += tmp_c
        n -= diff * tmp_c
    return base


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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

N = input()
S = input()

s = set([""])
for n in S[::-1]:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))


Measured memory_bytes: 65496
function main(arg) {
	arg = arg.trim().split('\n');
  	var a = arg[1].split(' ').map(str => parseInt(str, 10)),
        n = arg[0], out = 0;
  	//逆数の総和
    for (var i = 0; i < n; i++) {
      out += 1.0 / a[i];
    }
  	//逆数
    out = 1.0 / out
  console.log(out)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
bool ifprime(ll x){
    if(x==1) return false;
    if(x==2) return true;
    for(ll i=2; i*i<=x; i++){
        if(x%i==0) return false;
    }
    return true;
}

int main(){
    ll q; cin>>q;
    vector<ll> memo(1e5+5,0);
    for(ll i=1; i<=1e5; i++){
        memo[i]=memo[i-1];
        if(i%2==0) continue;
        if(ifprime(i) && ifprime((i+1)/2)) memo[i]++;
    }
    rep(i,q){
        ll l,r; cin>>l>>r;
        cout<<memo[r]-memo[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        String s = r.s();
        for(int i = 0; i < s.length(); i+=2)
            print(s.charAt(i));
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 30532
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

constexpr int64_t MOD=1e9+7;

int main() {
    string s;
    cin>>s;
    int64_t next=1;
    int64_t pow3=1;
    for(int i=s.size()-1;i>=0;--i){
        next=s[i]=='1'?((next*2)%MOD+pow3)%MOD:next;
        pow3*=3;
        pow3%=MOD;
    }
    cout<<next<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int x;
  cin>>x;
  for(int i=400;i<=1800;i+=200){
    if(i<=x&&x<i+200){
      cout<<10-i/200<<endl;
      return(0);
    }
  }
}

Measured memory_bytes: 3628
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, ll k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}

const int maxn = 1e5 + 5;
int par[maxn], r[maxn];
int findp(int x)
{
    if (par[x] < 0) return x;
    else{
        int fx = findp(par[x]);
        r[x] = (r[x] + r[par[x]]) % 2;
        par[x] = fx;
    }
}
void unite(int x, int y)
{
    int fx = findp(x), fy = findp(y);
    if (fx != fy){
        r[x] = (r[x] - r[y] + 1) % 2;
        par[fy] = fx;
    }
}
bool same(int x, int y){return findp(x) == findp(y);}

int main()
{
    char s[15], ans[15], p = 0;
    scanf("%s", s);
    for (int i = 0; i < strlen(s); ++i){
        if (s[i] == '1') ans[++p] = '1';
        else if (s[i] == '0') ans[++p] = '0';
        else if (p > 0) --p;
    }
    ans[++p] = 0;
    printf("%s\n", ans + 1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

bool graph[10][10];
bool seen[10];

int N, M;

int dfs(int now){
    seen[now] = true;
    bool flg = true;
    for(int i=0; i<N; i++) if(!seen[i]) flg = false;
    if(flg) { seen[now] = false; return 1;} 

    int res = 0;
    for(int to=0; to<N; to++){
        if(graph[now][to] && seen[to] == false){
            res += dfs(to);
        }
    }

    seen[now] = false;
    return res;
}

int main(){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        graph[a][b] = graph[b][a] = true;
    }

    cout << dfs(0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	char s[1000000];
	char t[1000000];
	while(scanf("%s",s)!=EOF){
		int j;
		int i,num;
		num=strlen(s);
		for(i=0,j=0;i<=num;i+=2){
			
			t[j]=s[i];
			j++;
		}
		printf("%s",t);
	}
 } 

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var results string
	fmt.Scan(&results)

	wins := 0
	for _, s := range results {
		if s == 'o' {
			wins++
		}
	}

	wins += 15 - len(results)

	if wins >= 8 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>


int main() {

    char str[20];
    scanf("%s\0", str);
    int ans = 0;
    int memo = 0;
    int cnt = std::strlen(str);
    while(cnt){
        memo = 0;
        for (int i = 0; i < cnt; i++){
            memo += str[i] - '0';
        }
        for (int i = cnt; i < std::strlen(str); i++){
            memo += 9;
        }
        if( cnt != std::strlen(str) ) memo--;
        ans = std::max(ans, memo);
        cnt--;
    }

    printf ("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
kiarray=Array.new(n).map{Array.new(2).map{Array.new}}
(n-1+m).times{
    parent,child=gets.split.map(&:to_i)
    kiarray[parent-1][1].push(child)
    kiarray[child-1][0].push(parent)
}
 
root=0
n.times{|k|
    if kiarray[k][0]==[]
        root=k+1
        break
    end
}
 
nisecount=0
que=[root]
 
while nisecount<m
    shift = que.shift
   children=kiarray[shift-1][1]
 
   ll=children.length
   index=0
   ll.times{
        value=children[index]
        if !kiarray[value-1][0][1]
            que.push(value)
         else
            nisecount+=1
            kiarray[value-1][0].delete(shift)
        end
        index+=1
   }
end
 
kiarray.map.with_index{|value,index|
    if  index==root-1
        puts 0
    else
        puts value[0][0]
    end
}

Measured memory_bytes: 29052
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();
    let a: i64 = read();
    let b: i64 = read();
    println!("{}", min(n * a, b))
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		for (int i = 0; i < n; i++) {
			System.out.println(Yamada(1000, 1, 1)
					- Yamada(s.nextInt(), s.nextInt(), s.nextInt()));
		}
		s.close();
	}

	public static int Yamada(int y, int m, int d) {
		int ans = -1;

		ans += 19 * 10 * (y - 1);
		ans += 10 * ((y - 1) / 3) + 5 * ((y - 1) - (y - 1) / 3);

		if (y % 3 == 0) {
			ans += 20 * (m - 1);
		} else {
			ans += 19 * ((m - 1) / 2);
			ans += 20 * ((m - 1) - ((m - 1) / 2));
		}
		return ans += d;
	}
}

Measured memory_bytes: 20616
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N, W;
    cin >> N >> W;
    ll baseW = 0;
    vector<ll> weight[4];
    vector<ll> sum[4];
    weight[0] = vector<ll>(0);
    weight[1] = vector<ll>(0);
    weight[2] = vector<ll>(0);
    weight[3] = vector<ll>(0);

    for (int i = 0; i < N; i++) {
        ll w, v;
        cin >> w >> v;
        if (i == 0) {
            baseW = w;
        }
        w -= baseW;
        weight[w].push_back(v);
    }
    sort(weight[0].begin(), weight[0].end(), greater<ll>());
    sort(weight[1].begin(), weight[1].end(), greater<ll>());
    sort(weight[2].begin(), weight[2].end(), greater<ll>());
    sort(weight[3].begin(), weight[3].end(), greater<ll>());
    sum[0] = vector<ll>(weight[0].size() + 1);
    sum[1] = vector<ll>(weight[1].size() + 1);
    sum[2] = vector<ll>(weight[2].size() + 1);
    sum[3] = vector<ll>(weight[3].size() + 1);
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < weight[i].size() + 1; j++){
            if(j == 0){
                sum[i][j] = 0;
            }else{
                sum[i][j] = sum[i][j - 1] + weight[i][j - 1];
            }
        }
    }
    ll M = 0;
    for(int a = 0; a < weight[0].size() + 1; a++){
        for(int b = 0; b < weight[1].size() + 1; b++){
            for(int c = 0; c < weight[2].size() + 1; c++){
                for(int d = 0; d < weight[3].size() + 1; d++){
                    ll total = baseW * (a + b + c + d) + b + 2  * c + 3 * d;
                    if(total <= W){
                        ll val = sum[0][a] + sum[1][b] + sum[2][c] + sum[3][d];
                        M = max(M,val);
                    }
                }
            }
        }
    }
    cout << M << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100005;

int n;
LL C;
LL a[N];
int val[N];
LL pre[N];

int main(){
	n=get();
	scanf("%lld",&C);
	fo(i,1,n)scanf("%lld %d",&a[i],&val[i]);
	pre[0]=0;
	fo(i,1,n)pre[i]=pre[i-1]+val[i];
	LL ans=0;
	LL tmp;
	fo(i,1,n){
		tmp=pre[i]-a[i];
		if (tmp>ans)ans=tmp;
	}
	fo(i,1,n){
		tmp=pre[n]-pre[i-1]-(C-a[i]);
		if (tmp>ans)ans=tmp;
	}
	//pre[i]+pre[n]-pre[j-1]-(2*a[i]+C-a[j])
	LL pv=-1e16;
	fd(i,n,1){
		LL tmp=pre[i]-a[i]*2+pv;
		if (tmp>ans)ans=tmp;
		if (pre[n]-pre[i-1]-(C-a[i])>pv)pv=pre[n]-pre[i-1]-(C-a[i]);
	}
	pv=-1e16;
	fd(i,n,1){
		LL tmp=pre[i]-a[i]+pv;
		if (tmp>ans)ans=tmp;
		if (pre[n]-pre[i-1]-2ll*(C-a[i])>pv)pv=pre[n]-pre[i-1]-2ll*(C-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll arrVal[1000005], arrFreq[1000005], arr[1000005] ;
ll maxVal = 0, n ;

bool pairPrime()
{
    ll val = 0 ;
    for (int i = 2; i <= maxVal; i++) {
        for (int j = i; j <= maxVal; j += i) {
            arrFreq[i] += arrVal[j] ;
        }
    }

    for (int i = 1;  i <= maxVal; i++) {
        val = max(val, arrFreq[i]) ;
    }
    if (val > 1)    return false ;
    else    return true ;
}

bool setPrime()
{
    ll gcd = arr[0] ;

    for (int i = 1; i < n; i++) {
        gcd = __gcd(gcd, arr[i]) ;
    }

    if (gcd == 1)   return true ;
    else    return false ;
}

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

    for (int i = 0; i < n; i++) {
        cin >> arr[i] ;
        maxVal = max(maxVal, arr[i]) ;
        arrVal[arr[i]]++ ;
    }

    if (pairPrime()) {
        cout << "pairwise coprime\n" ;
    }
    else if (setPrime()) {
        cout << "setwise coprime\n" ;
    }
    else {
        cout << "not coprime\n" ;
    }

    return 0 ;
}


Measured memory_bytes: 26960
fun main(arr:Array<String>) {
    val num = readLine()!!.toLong()
    var cur = num
    var div = 1L
    val flags = mutableListOf<Boolean>()
    while (cur != 0L) {
        if(cur % (div*2) != 0L) {
            flags.add(true)
            cur -= div
        } else {
            flags.add(false)
        }
        div *= -2
    }
    if(flags.size == 0) {
        println(0)
    } else {
        println(flags.map { if(it) "1" else "0" }.reversed().joinToString(""))
    }
}

Measured memory_bytes: 31996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int sum = min(a, b) + min(c, d);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
lst = list(map(int, input().split()))

res = 0
max_num = min(n, k)
for i in range(max_num+1):
    for j in range(max_num+1 - i):
        my_lst = []
        my_lst += lst[:i]
        if j != 0:
            my_lst += lst[-j:]
        
        s = sum(my_lst)
        sorted_my_lst = sorted(my_lst)
        #print('my_lst :', my_lst)
        for l in range(k- i - j):
            if len(my_lst) > l:
                if sorted_my_lst[l] < 0:
                    s -= sorted_my_lst[l]
        res = max(res, s)

print(res)

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

#define MAX 1000001

int main(){
  bool p[MAX];
  memset(p, true, sizeof(p));
  p[1] = p[0] = 0;
  for(int i = 0 ; i < MAX ; i++){
    if(p[i]){
      for(int j = 2 * i ; j < MAX ; j += i){
	p[j] = 0;
      }
    }
  }
 
  int n;
  while(cin >> n, n){
    unsigned long long cnt = 0, ans = 0;
    for(int i = 0 ; ; i++){
      if(cnt == n) break;
      if(p[i] == true){
	ans += i;
	cnt++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int nijou(int a){
    int b = 1;
    rep(i,a-1) b *= 2;
    return b;
}

int main()
{
    int n, m, ans =0;
    cin>>n>>m;
    vector<vector<int>>a(m,vector<int>(n+1));
    vector<int>p(m);
    rep(i,m){
        cin>>a[i][0];
        rep(j,a[i][0]) cin>>a[i][j+1];
    }

    rep(i,m) cin>>p[i];

    rep(i,1<<n){
        vector<int>s(m);
        rep(j,n){
            int mask=1<<j;
            if(i&mask){
                rep(k,m){
                    rep(l,a[k][0]){
                        if(nijou(a[k][l+1]) == mask){
                            s[k]++;
                        }
                    }
                }
            }
        }
        bool ok = true;
        rep(j,m){
            if(s[j] % 2 != p[j]) ok = false;
        }
            if(ok) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio,
	   std.string,
	   std.conv,
	   std.algorithm,
	   std.range,
	   std.math;

void main()
{
	while(true){
		auto ip = readln.split.to!(int[]), h = ip[0], w = ip[1];
		if(h == 0 && w == 0) break;
		else{
			string W;
			foreach(j; 0..w){
					W ~= "#";
			}
			foreach(i; 0..h){
				W.writeln;
			}
			writeln;
		}
	}
}


Measured memory_bytes: 2488
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)

def unzip(strlist,a,b):
    ret = []
    for word in strlist:
        tmp = ""
        for i in range(len(word)):
            tmp += chr(((ord(word[i])-97)*a+b)%26+97)
        ret.append(tmp)
    return ret

n = int(input())
for _ in range(n):
    instr = input().split()
    flag = False
    for a in range(1,26):
        if gcd(1,26)!=1 : continue
        if flag: break
        for b in range(26):
            if "this" in unzip(instr, a, b):
                print(" ".join(unzip(instr, a, b)))
                flag = True
                break
            elif "that" in unzip(instr, a, b):
                print(" ".join(unzip(instr, a, b)))
                flag = True
                break

Measured memory_bytes: 7584
def main():
    a, b, c = list(map(int, input().split()))
    k = int(input())

    cnt = 0
    while True:
        if b > a:
            break
        cnt += 1
        b *= 2

    while True:
        if c > b:
            break
        cnt += 1
        c *= 2
    
    if cnt <= k:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()



Measured memory_bytes: 9168
def spliter(a):
    a = str(a)
    b = list()
    b = a.split(' ')
    for i in range(0,len(b)):
        b[i] = int(b[i])
    return b
s = spliter(str(input()))
goal = s[2]
counter = 0
while counter != goal:
    if s[0] % 2 == 0:
        s[1] += (s[0] / 2)
        s[0] -= (s[0] / 2)
        counter += 1
        if counter == goal:
            break
        else:
            if s[1] % 2 == 0:
                s[0] += (s[1] / 2)
                s[1] -= (s[1] / 2)
                counter += 1
                if counter == goal:
                    break
            else:
                s[1] -= 1
                s[0] += (s[1] / 2)
                s[1] -= (s[1] / 2)
                counter += 1
                if counter == goal:
                    break
    else:
        s[0] -= 1
        s[1] += (s[0] / 2)
        s[0] -= (s[0] / 2)
        counter += 1
        if counter == goal:
            break
        else:
            if s[1] % 2 == 0:
                s[0] += (s[1] / 2)
                s[1] -= (s[1] / 2)
                counter += 1
                if counter == goal:
                    break
            else:
                s[1] -= 1
                s[0] += (s[1] / 2)
                s[1] -= (s[1] / 2)
                counter += 1
                if counter == goal:
                    break
            
print(int(s[0]),int(s[1]))


Measured memory_bytes: 3064