akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int x[n], y[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; i++) mp[make_pair(x[i], y[i])] = i;
    int ans = n;
    for (int i = 0; i < n; i++)
        for (int j = i+1; j < n; j++) {
            int p = x[j] - x[i], q = y[j] - y[i];
            bool b[n] = {};
            int cnt = 0;
            for (int k = 0; k < n; k++) {
                if (!b[k]) {
                    cnt++;
                    b[k] = true;
                    for (int d = 1; ; d++)
                        if (mp.find({x[k] + p*d, y[k] + q*d}) != mp.end()) {
                            b[mp[{x[k] + p*d, y[k] + q*d}]] = true;
                        } else break;
                    for (int d = -1; ; d--)
                        if (mp.find({x[k] + p*d, y[k] + q*d}) != mp.end()) {
                            b[mp[{x[k] + p*d, y[k] + q*d}]] = true;
                        } else break;
                }
                //     for (int l = 0; l < n; l++) {
                //         if ((p == 0 && x[l] == x[k] && (y[l] - y[k]) % q == 0) ||
                //             (q == 0 && y[l] == y[k] && (x[l] - x[k]) % p == 0) ||
                //             (p != 0 && q != 0 && (x[l] - x[k]) % p == 0 &&
                //              (y[l] - y[k]) % q == 0 && (x[l] - x[k]) / p == (y[l] - y[k]) / q))
                //             b[l] = true;
                //     }
                // }
            }
            ans = min(cnt, ans);
        }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int x,i,f;
    scanf("%d",&x);
    while(1){
        f=0;
        for(i=2;i<sqrt(x);i++){
            if(x%i==0) f++;
        }
        if(f==0) break;
        x++;
    }
    printf("%d\n",x);
}

Measured memory_bytes: 128
#include<stdio.h>
int prev[200001],next[200001];
int main(){
	int n,m,q,i,a,p=0,j,r;
	scanf("%d %d %d",&n,&m,&q);
	for(i=0;i<n;i++){
		prev[i]=(i-1+n)%n;
		next[i]=(i+1)%n;
	}
	for(i=0;i<m;i++){
		scanf("%d",&a);
		for(j=0;j<a;j++){
			p=a%2==0?next[p]:prev[p];
		}
		r=p;
		prev[next[p]]=prev[p];
		next[prev[p]]=next[p];
		p=next[p];
		prev[r]=-1;
		next[r]=-1;
	}
	for(i=0;i<q;i++){
		scanf("%d",&a);
		if(prev[a]==-1){
			printf("0\n");
		}
		else{
			printf("1\n");
		}
	}
	return 0;
}

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

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

namespace Comb{
const int N = 10 + 5;
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int main() {
    int n;
    cin >> n;
    printf("%d\n", n / 3);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    //write code  here
    int A,B,K;
    cin >> A >> B >> K;
    for (int i = 0; i < K/2; ++i) {
        if (A%2) A--;
        A /= 2;
        B += A;

        if (B%2) B--;
        B /= 2;
        A += B;
    }
    if (K%2 == 1){
        if (A%2) A--;
        A /= 2;
        B += A;
    }

    cout << A << " " << B << endl;
    return 0;
}

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

const int MAX=100005;
vector<int> Sa(MAX,1000000005),Sb(MAX,1000000005),Sc(MAX,1000000005),A(MAX),B(MAX),C(MAX);
int N;

void DP(int u){
    for(int i=1;i<=u;i++){
        Sa[i]=max(Sb[i-1],Sc[i-1])+A[i];
        Sb[i]=max(Sa[i-1],Sc[i-1])+B[i];
        Sc[i]=max(Sa[i-1],Sb[i-1])+C[i];
    }
    cout<<max(Sa[u],max(Sb[u],Sc[u]))<<endl;
}

int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i+1]>>B[i+1]>>C[i+1];
    }
    Sa[0]=0;Sb[0]=0;Sc[0]=0;
    DP(N);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	string n;
	cin >> n;
	int64_t sum = 0;
	for (char c : n) {
		sum += (c - '0');
	}
	string ans = "Yes";
	if (sum % 9 != 0) {
		ans = "No";
	}

	cout << ans << '\n';
	return 0;
}


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

int main() {
	long long int n, a[100005], b[100005], cnt=0;
	cin >> n;
	for(int i =0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int j=n-1; j>=0;j--){
		if(cnt != 0){
			a[j] += cnt;
		}
		long long ans = a[j] / b[j];
		if(a[j] % b[j] != 0){
			cnt += b[j] * (ans + 1) - a[j];
		}
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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 int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int n;
vector<int> a, pos;
vector<bool> visited;
int mx = 1;

void dfs(int x, int k) {
    if(x!=n-1&&pos[x+1]>pos[x]) {
        visited[x+1] = true;
        dfs(x+1, k+1);
    }else{
        chmax(mx, k);
        return;
    }
}

int main(){
    cin >> n;
    a.resize(n);
    pos.resize(n);
    visited.assign(n, false);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        pos[a[i]] = i;
    }
    for(int i = 0; i < n; i++) {
        if(!visited[i]) {
            visited[i] = true;
            dfs(i, 1);
        }
    }
    int ans = n-mx;
    cout << ans << endl;
}

Measured memory_bytes: 1792
from collections import Counter


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[y] = x
        self.size[x] += self.size[y]
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)

ans = max(uf.size)

print(ans)

Measured memory_bytes: 26380
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    cin>>a>>b;
    if(a+b<10)cout<<a+b<<endl;
    else cout<<"error"<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
  char S[10];
  cin>>S;

  int ans = 0;
  for (int i = 0; i < 4; ++i)
  {
  	if (S[i] == '+') ++ans;
  	
    else
    	--ans;
  	

  }
  cout<<ans;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())
A = map(int, raw_input().split())
S = 0
for i in xrange(n-1):
    S += (m + A[i+1] - A[i]) % m

T = 2*m
D = [0]*(T+10)
data = [0]*(T+1)
def get(i):
    s = 0
    while i:
        s += data[i]
        i -= i & -i
    return s
def add(i, x):
    while i <= T:
        data[i] += x
        i += i & -i

for i in xrange(n-1):
    x = A[i]; y = A[i+1]
    if y < x:
        y += m
    k = y-x
    if k > 1:
        D[x+2] += 1
        D[y+1] -= k
        D[y+2] += k-1
for i in xrange(1, 2*m+5):
    D[i] += D[i-1]
    add(i, D[i])
res = min(S - (get(a) + get(a+m)) for a in A)
print res


Measured memory_bytes: 42808
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;
	cin >> h >> w;
	vector<vector<int> > c(10,vector<int>(10));
	rep(i,10){
		rep(j,10){
			cin >> c[i][j];
		}
	}
	int sum = 0;
	rep(i,h){
		rep(j,w){
			int a;
			cin >> a;
			if(a == 1 || a == -1) continue;
			vector<int> cost(10,INF);
			queue<int> que;
			que.emplace(a);
			cost[a] = 0;
			while(!que.empty()){
				int now = que.front();
				que.pop();
				rep(k,10){
					if(cost[now] + c[now][k] < cost[k]){
						cost[k] = cost[now] + c[now][k];
						que.emplace(k);
					}
				}
			}
			sum += cost[1];
		}
	}
			
	cout << sum << '\n';

	return 0;
}


Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z, k, n;
	string s;
	cin >> n >> s;
	z = 0;

	debug(s);


	while (s.size() and s.back() == 'W')	s.pop_back();
	n = s.size();

	j = n - 1;

	std::vector<pair<char, ll>> v;

	rep(i, 0, n, 1) {
		if (v.size() and v.back().ff == s[i])	v.back().ss++;
		else v.push_back({s[i], 1});
	}


	j = v.size() - 1;
	rep(i, 0, v.size(), 1) {
		// debug(v, j);
		if (v[i].ff == 'W' and i + 1 < v.size() and v[i + 1].ff == 'R'  and v[i + 1].ss) {
			while (1) {
				while (j > i and v[j].ff != 'R') {
					j--;
				}
				if (i == 2) {
					// debug(j);
				}
				if (j > i and v[j].ff == 'R') {
					// if (v[j].ss == 0)	j--;
					// else {
					if (v[j].ss > v[i].ss) {
						z += v[i].ss;
						v[j].ss -= v[i].ss;
						v[i].ss = 0;
						break;
					} else {
						z += v[j].ss;
						v[i].ss -= v[j].ss;
						v[j].ss = 0;
						j--;
					}
					// }
					// }
				}

				else {
					if (v[i + 1].ss < v[i].ss) {
						z += v[i + 1].ss;
					}
					else
						z += v[i].ss;
					break;
				}
			}
		}
	}

	debug(z, s, v);
	ce(z);
}



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;

ll ans = 0;

int main(void) {
  // Here your code !
  cin >> s;

  for (int i = 0; i < 1 << s.size() - 1; ++i) {

    ll tmpsum = 0;
    string tmpstr = "";
    for (int j = 0; j < s.size() - 1; ++j) {
      tmpstr += s[j];
      if (i >> j & 1) {
        tmpsum += stoll(tmpstr);
        tmpstr = "";
      }
    }
    tmpstr += s.back();
    tmpsum += stoll(tmpstr);
    ans += tmpsum;

  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int N;
  int AC=0,WA=0,TLE=0,RE=0;
  string str;
  cin >> N;
  for (int i=0;i<N;i++) {
    cin >> str;
    if (str == "AC") AC++;
    else if (str == "WA") WA++;
    else if (str == "TLE") TLE++;
    else if (str == "RE") RE++;
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

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

namespace ABC_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long N = long.Parse(s[0]);
            long M = long.Parse(s[1]);
            long X;

            if (N * 2 >= M)
            {
                X = M / 2;
            }
            else
            {
                X = N + (M - 2 * N) / 4;
            }

            Console.WriteLine(X.ToString());

        }
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll mod = 1000000007;

    int N,M;
    cin >> N >> M;

    vector<bool> isBroken(N+1,false);

    rep(i,M){
        int tmp;
        cin >> tmp;

        isBroken[tmp] = true;
    }

    vector<ll> sum(N+1,0);
    sum[0] = 1;

    for(int i = 0;i < N;i++){
        if(!isBroken[i+1]){
            sum[i+1] += sum[i];
            sum[i+1] %= mod; 
        }

        if(!isBroken[i+2] && i != N-1){
            sum[i+2] += sum[i];
            sum[i+2] %= mod; 
        }
    }


    // rep(i,N+1){
    //     cout << sum[i] << " ";
    // }
    // cout << endl;

    cout << sum[N] << endl;
}

Measured memory_bytes: 1024
a, b, c, d, e, f = map(int, input().split())

sug = 0
sugwat = 100 * a
for h in range(0,f + 1,100 * a):
    if h > f:
        break
    for i in range(0, f + 1, 100 * b):
        if h + i > f:
            break
        for j in range(0, f + 1, c):
            if h + i + j <= f:
                if h + i + j > 0:
                    if 100 * (j / (h + i + j)) > 100 * (e / (100 + e)):
                        break
            else:
                break
            for k in range(0, f + 1, d):
                if h + i + j + k <= f:
                    if h + i + j + k > 0:
                        if 100 * ((j + k) / (h + i + j + k)) <= 100 * (e / (100 + e)):
                            if 100 * (sug / sugwat) <= 100 * ((j + k) / (h + i + j + k)):
                                sugwat = h + i + j + k
                                sug = j + k
                else:
                    break

print(sugwat, sug)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  string s;
  cin >> s;
  int N = s.size();
  int cnt = 0;
  bool flag = 1;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if (s[i] == s[j]) {
        cnt++;
      }
    }
    if (cnt-1 != 0) {
      flag = 0;
      break;
    }
    else {
      cnt = 0;
    }
  }
  if (flag) {
    cout << "yes" << endl;
  }
  else cout << "no" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x;
	int i = 1;
	scanf("%d", &x);
	// ??\?????¨???????????°?????????
	while(x != 0){
		printf("Case %d: %d\n",i, x);
		i++;
		scanf("%d", &x);
	}


	return 0;
}

Measured memory_bytes: 2588
import java.util.Scanner;
class Main
 {
   public static void main(String[] args)
      {
      Scanner S = new Scanner(System.in);
      int W = S.nextInt();
      int H = S.nextInt();
      int x = S.nextInt();
      int y = S.nextInt();
      int r = S.nextInt();
      if(W>x && H>y && x>0 && y>0 && W-2*r>=0 && H-2*r>=0){
      System.out.println("Yes");
      }
      else{
      System.out.println("No");
      }
}
}


Measured memory_bytes: 26316
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    string S[1010];
    rep(i,0,H) cin >> S[i];
    ll dp[1010][1010] = {};
    dp[0][0] = 1;
    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j] == '#') continue;
            if(i+1 < H && S[i+1][j] == '.'){
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
            if(j+1 < W && S[i][j+1] == '.'){
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= MOD;
            }
        }
    }
    print(dp[H-1][W-1]);
    

}

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

int main() {
  vector<int> abc(3);
  for (int i=0; i<3; i++) cin >> abc.at(i);
  sort(abc.begin(), abc.end(), greater<int>());
  cout << abc.at(0)*10 + abc.at(1) + abc.at(2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)

typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;



int main() {

  ll n;
  cin >> n;
  ll sum=0;
  REP1(i,n){
    bool flag = true;
    if(i%3==0||i%5==0){
      flag = false;
    }
    if(flag){
      sum += i;
    }
  }
  cout << sum << endl;
}

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

const int N = 1e5 + 10;
int n, p, x, m, tmp;
int a[N], b[N];
string s;

int main() 
{
	cin >> s;
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
		cout << 3;
	else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
		cout << 2;
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
		cout << 1;
	else
		cout << 0;
		
	return 0; 
}

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

int main() {
  int a,b,k;
  scanf("%d %d %d", &a,&b,&k);
  set<int> s;
  for ( int i=a; i<min(a+k,b+1); i++ ) {
    s.insert(i);
  }
  for ( int i=b; i>max(a,b-k); i-- ) {
    s.insert(i);
  }
  for ( auto &i:s ) {
    printf("%d\n", i);
  }
  return 0;
}

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

int main()
{
    int ma = 0, sum = 0;
    for(int i = 0;i < 5;i++){
        int v;
        cin >> v;
        int x = (v + 9) / 10 * 10;
        sum += x;
        ma = max(ma, x - v);
    }
    cout << sum - ma << endl;
    return 0;
}


Measured memory_bytes: 256
#Small and Large Integers
A,B,K = map(int,input().split())
L = []
for i in range(K):
    if A+i <= B: 
        L.append(A+i)
    if A <= B-i:
        L.append(B-i)

S = set(L)
L = list(S)
L.sort()
for i in range(len(L)):
    print(L[i])

Measured memory_bytes: 3060
a, b, c, d = map(int, input().split())
if b <= c or d <= a:
	print(0)
elif b <= d:
	if a <= c:
		print(b - c)
	else:
		print(b - a)
	
else:
	if a <= c:
		print(d - c)
	else:
		print(d - a)


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

int A[] = { 1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049, 0 };
int X[ 100010 ];

int main()
{
int i;
int j;
int a;
int N;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;

	for( j = 0; A[ j ] > 0; j++ )
	{
		if( A[ j ] > N ) continue;
		if( A[ j ] == N )
		{
			cout << 1 << endl;

			return 0;
		}

		X[ A[ j ] ] = 1;
	}

	for( i = 1; i < N; i++ )
	{
		for( j = 0; A[ j ] > 0; j++ )
		{
			a = i + A[ j ];
			if( a > N ) continue;

			if( X[ a ] == 0 || X[ a ] > X[ i ] + 1 )
				X[ a ] = X[ i ] + 1;
		}
	}

	cout << X[ N ] << endl;

	return 0;
}


Measured memory_bytes: 640
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//THE BEST PROBLEM EVER
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 2 * (int)1e5 + 10;
vector < int > g[maxN];
int m;
int gr[maxN];
const int mod = 998244353;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
const int T = pw(10, 18);
int f[3][maxN];
const int LOG = 17;
void go(int v) {
    for (int i = 1; i <= n; i++) {
        g[i].clear();
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        g[a].emplace_back(b);
    }
    for (int i = n; i >= 1; i--) {
        gr[i] = 0;
        set < int > s;
        for (int p : g[i]) {
            s.insert(gr[p]);
        }
        while (s.count(gr[i])) gr[i]++;
    }
    for (int i = 1; i <= n; i++) {
        f[v][gr[i]] = sum(f[v][gr[i]], pw(T, i));
    }
    for (int bit = 0; bit < LOG; bit++) {
        for (int i = 0; i < (1 << LOG); i++) {
            if (i & (1 << bit)) {
                int a = f[v][i ^ (1 << bit)];
                int b = f[v][i];
                f[v][i ^ (1 << bit)] = sum(a, b);
                f[v][i] = sub(a, b);
            }
        }
    }
}
int tot[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < 3; i++) {
        go(i);
    }
    for (int i = 0; i < (1 << LOG); i++) {
        tot[i] = 1;
        for (int j = 0; j < 3; j++) {
            tot[i] = mult(tot[i], f[j][i]);
        }
    }
    for (int bit = 0; bit < LOG; bit++) {
        for (int i = 0; i < (1 << LOG); i++) {
            if (i & (1 << bit)) {
                int a = tot[i ^ (1 << bit)];
                int b = tot[i];
                tot[i ^ (1 << bit)] = sum(a, b);
                tot[i] = sub(a, b);
            }
        }
    }
    cout << mult(tot[0], pw((mod + 1) / 2, LOG));
    return 0;
}

Measured memory_bytes: 11008
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int[] weights = new int[n];
        int[] value = new int[n];
        for (int i=0; i<n; i++) {
            weights[i] = sc.nextInt();
            value[i] = sc.nextInt();
        }
        long[][] dp = new long[n+1][w+1];
        for (int i=0; i<=n; i++) {
            for (int j=0; j<=w; j++) {
                if (i == 0 || j == 0) {
                    dp[i][j] = 0;
                } else if (weights[i-1] > j) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = Math.max(dp[i-1][j], value[i-1] + dp[i-1][j-weights[i-1]]);
                }
            }
        }
        System.out.println(dp[n][w]);
    }
}

Measured memory_bytes: 124884
import bisect

n = int(input())
l = list(map(int,input().split()))

l.sort()
ans = 0

for b in range(n - 2):
    for c in range(b + 1,n - 1):
        left = bisect.bisect_left(l,l[c] + l[b])
        ans+=left - c - 1

print(ans)

Measured memory_bytes: 44708
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
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 powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int m;
char s[maxn];
set<int> st[1000];
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    n = readint();
    scanf("%s", s + 1);
    repd(i, 1, n)
    {
        st[s[i]].insert(i);
    }
    m = readint();
    int op, l, r;
    int x;
    char c;
    repd(q, 1, m)
    {
        op = readint();
        if (op == 1)
        {
            x = readint();
            scanf("%c", &c);
            auto it = st[s[x]].lower_bound(x);
            st[s[x]].erase(it);
            s[x] = c;
            st[c].insert(x);
        } else
        {
            l = readint();
            r = readint();
            int ans = 0;
            repd(i, 'a', 'z')
            {
                auto it = st[i].lower_bound(l);
                x = *it;
                if (x>=l&&x <= r)
                {
                    ans++;
                }
            }
            printf("%d\n", ans );
        }
    }
    return 0;
}




Measured memory_bytes: 24320
#include<cstdio>
#include<iostream>
using namespace std;
int f[20005], power[1005], cost[1005];
int main() {
	int H,N,Max=-1,Min=999999999;
	scanf("%d%d",&H,&N);
	for(int i=1;i<=N;i++) {
		scanf("%d%d",&power[i],&cost[i]);
		if(power[i]>Max)
			Max=power[i];
	}
	for(int i=1;i<=N;i++)
		if(f[power[i]]==0 || cost[i]<f[power[i]])
			f[power[i]]=cost[i];
	for(int i=1;i<H+Max;i++) {
		for(int j=1;j<=N;j++) {
			if(i-power[j]>0 && f[i-power[j]]) {
				if(f[i]==0) 
					f[i]=f[i-power[j]]+cost[j];
				else
					f[i]=min(f[i],f[i-power[j]]+cost[j]);
			}
		}
	}
	for(int i=H;i<H+Max;i++) 
		if(f[i] && f[i]<Min) Min=f[i];
	printf("%d\n",Min);
return 0;
} 

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n;
    cin >> n;
    if(n/100 == n%10)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
#include<stdio.h>//头文件

int a,b;

int main(void){
    scanf("%*d%d%d",&a,&b);//不读入n
    if((b-a-1)&1)//如果(b-a-1)为奇数
        puts("Alice");//Alice赢
    else//如果(b-a-1)为偶数
        puts("Borys");//Borys赢
    return 0;//结束
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <bitset>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <deque>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef pair<long long, long long> P;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	int from, to;
	ll cost;
};

int n, m, k, s;
ll pn, qn;
int c[100005] = { 0 };
vector<int> es[100005];
int city[100005] = { 0 };
vector<P>ne[100005];
ll d2[100005] = { 0 };
int main() {
	cin >> n >> m >> k >> s;
	cin >> pn >> qn;
	for (int i = 0; i < k; i++) {
		cin >> c[i];
		c[i]--;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		es[a].pb(b);
		es[b].pb(a);
	}
	for (int i = 0; i < k; i++) {
		int d[100005] = { 0 };
		rep(i, n) d[i] = INF;
		queue<int>que;
		que.push(c[i]);
		d[c[i]] = 0;
		while (!que.empty()) {
			int now = que.front();
			que.pop();
			if (d[now] >= s) break;
			for (int u = 0; u < es[now].size(); u++) {
				if (d[es[now][u]] == INF) {
					d[es[now][u]] = d[now] + 1;
					que.push(es[now][u]);
				}
			}
		}
		for (int j = 0; j < n; j++) {
			if (d[j] <= s&&city[j]==0) {
				city[j] = 1;
			}
		}
		city[c[i]] = 2;
	}
	/*rep(i, n) {
	if (city[i]==1) cout << i << endl;
	}*/
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < es[i].size(); j++) {
			int to = es[i][j];
			if (city[to] == 0) {
				ne[i].pb(P(to, pn));
			}
			if (city[to] == 1) {
				ne[i].pb(P(to, qn));
			}
		}
	}

	rep(i, n) d2[i] = LLINF;
	d2[0] = 0;
	priority_queue<P, vector<P>, greater<P>>que;
	que.push(P(0, 0));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		ll v = p.second;
		if (d2[v] < p.first) continue;
		for (int u = 0; u < ne[v].size(); u++) {
			ll to = ne[v][u].first;
			ll cost = ne[v][u].second;
			if (d2[to] > d2[v] + cost) {
				d2[to] = d2[v] + cost;
				que.push(P(d2[to], to));
			}
		}
	}
	if (city[n - 1] == 0) cout << d2[n - 1] - pn << endl;
	else cout << d2[n - 1] - qn << endl;
	return 0;
}



Measured memory_bytes: 23112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main (){
ll n,a[100009],b[100009],c[100009];
cin>>n;
for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
for(int i=1;i<n;i++)
a[i]=max(b[i-1]+a[i],c[i-1]+a[i]),
b[i]=max(c[i-1]+b[i],a[i-1]+b[i]),
c[i]=max(b[i-1]+c[i],a[i-1]+c[i]);
 
cout<<max(max(a[n-1],b[n-1]),c[n-1])<<endl;
 
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define vecin(vec) rep(i, vec.size()) cin >> vec.at(i)
using namespace std;

int main(){
  int a;
  cin >> a;
  vector<int> nums(a);
  vecin(nums);
  int ans = 0;
  rep(i, a){
    rep(j, a){
      ans = max(ans, abs(nums.at(i) - nums.at(j)));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter
from math import ceil
n = int(input())
s = input()

if n <= 2:
    ans = 0
else:
    c = list(Counter(s).values())
    if len(c) <= 2:
        ans = 0
    else:
        ans = 1
        for i in c:
            ans *= i
            
        for i in range(ceil(n/2)-1):
            for j in range(n-(i+1)*2):
                if s[j] != s[j+i+1] and s[j] != s[j+(i+1)*2] and s[j+(i+1)*2] != s[j+i+1]:
                    ans -= 1
            
print(ans)

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

int n;
ll a[100005][5];
ll memo[100005][5];

ll dp(int pos, int last){
	if(pos >= n) return 0;
	if(memo[pos][last] != -1)	return memo[pos][last];
	
	ll mmax = -1;
	for(int i = 0; i < 3; i++){
		if(i == last)	continue;
		mmax = max(mmax, a[pos][i] + dp(pos+1, i));
	}
	return memo[pos][last] = mmax;
}

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

	memset(memo, -1, sizeof(memo));

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

	cout << dp(0, 4);

	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
int N;
string S;
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int count = 0;
    cin >> N >> S;
    int counter = 0, idx = 0;
    for (char i : S) {
        if (counter == 0 || S[idx] != S[idx-1]) {
            counter++;
        }
        idx++;
    }
    cout << counter << "\n";
}

Measured memory_bytes: 512
#include <stdio.h>

int main() {
	
	int N;
	scanf("%d",&N);
	
	int p[N];
	for( int i = 0; i < N; i++ ){
		scanf("%d",&p[i]);
	}
	
	//maxの算出
	int max = 0, max_num = 0;
	for( int j = 0; j < N; j++ ){
		if( j == 0 ){
			max = p[0];
			max_num = 0;
		}
		else{
			if( max < p[j] ){
				max = p[j];
				max_num = j;
			}
		}
	}
	
	//resの算出
	int res = 0;
	for( int k = 0; k < N; k++ ){
		if ( k != max_num ){
			res = res + p[k];
		}
	}
	res = res + (p[max_num] / 2);
	
	printf("%d",res);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cstddef>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
//add #define GRAPH for graph theory problems
#define mp make_pair
#define pb push_back
#ifdef GRAPH
typedef pair <int, int> Edge;
#define v first
#define w second
#endif
#ifdef GEOMETRY
typedef pair <int, int> Point;
#define x first
#define y second
#endif
#ifdef FILEIO
#define FILEOPEN(in, out) freopen(in, "r", stdin);freopen(out, "w", stdout);
#endif
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
#define int long long
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
const int MAXN = 100010;
const int MOD = 1000000007;
vector <int> G[MAXN];
int vis[MAXN];
int dp[MAXN][2];
void DP(int u) {
	vis[u] = true;
	for (auto v: G[u]) {
		if (vis[v])continue;
		DP(v);
		dp[u][1] = (dp[u][1] * dp[v][0]) % MOD;
		dp[u][0] = (dp[u][0] * ((dp[v][0] + dp[v][1]) % MOD)) % MOD;
	}
}
int n;
signed main()
{
	cin >> n;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 0; i <= n + 5; i++)dp[i][0] = dp[i][1] = 1;
	DP(1);
	cout << (dp[1][1] + dp[1][0] + MOD) % MOD << endl;
	return 0;
}


Measured memory_bytes: 12288
# D - Line++
def main():
    N, X, Y = map(int, input().split())
    dist_cnt = [0] * N
    calc_min_dist = lambda x, y: min(y - x, abs(X - x) + abs(y - Y) + 1)  # assume x < y
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            dist_cnt[calc_min_dist(i, j)] += 1
    print("\n".join(map(str, dist_cnt[1:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int Q;
long a,b,c,d;
long T[31];
main()
{
	cin>>Q;
	T[0]=1;
	for(int i=1;i<=30;i++)T[i]=T[i-1]*3;
	for(;Q--;)
	{
		cin>>a>>b>>c>>d;
		a--,b--,c--,d--;
		long ans=abs(a-c)+abs(b-d);
		long plus=0;
		for(int i=30;i>=1;i--)
		{
			if(a/T[i-1]==c/T[i-1]&&a/T[i-1]%3==1)
			{
				long B=b/T[i-1],D=d/T[i-1];
				if(B>D)swap(B,D);
				while(B%3!=1)B++;
				while(D>=0&&D%3!=1)D--;
				if(B<=D)
				{
					a%=T[i];
					c%=T[i];
					plus=min(min(a,c)+1-T[i-1],2*T[i-1]-max(a,c));
					break;
				}
			}
			if(b/T[i-1]==d/T[i-1]&&b/T[i-1]%3==1)
			{
				long A=a/T[i-1],C=c/T[i-1];
				if(A>C)swap(A,C);
				while(A%3!=1)A++;
				while(C>=0&&C%3!=1)C--;
				if(A<=C)
				{
					b%=T[i];
					d%=T[i];
					plus=min(min(b,d)+1-T[i-1],2*T[i-1]-max(b,d));
					break;
				}
			}
		}
		cout<<ans+plus*2<<endl;
	}
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>

using namespace std;
#define MOD 998244353
#define LL long long


int main()
{
	  double a,h,b;
	  cin>>a>>b>>h;
	  
	  cout<<(a+b)*h/2.0<<endl;
	  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define For(i,n) for(ll i = 1 ; i < n ; i++)

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  string s,beg = "",en = "";cin>>s;
  ll t,f,q;
  char c;
  cin>>q;
  ll tog = 0;
  while(q--){
    cin>>t;
    if(t == 1)tog ^= 1;
    else{
      cin>>f>>c;
      if(f == 1){
        if(!tog)beg = c + beg;
        else en += c;
      }else{
        if(!tog)en += c;
        else beg = c +beg;
      }
    }
  }
  s += en;
  s = beg + s;
  if(tog)reverse(s.begin(),s.end());
  cout<<s<<'\n';
}

Measured memory_bytes: 1300
def main():
    """
    0 <= c <= 100
    c(i,j) = a(i) + b(j)
    a: 整数 -> 負もあるのでc特定の数不明

    c1,1 = a1 + b1
    c1,2 = a1 + b2
    c1,3 = a1 + b3

    c2,1 = a2 + b1
    c2,2 = a2 + b2
    c2,3 = a2 + b3

    c3,1 = a3 + b1
    c3,2 = a3 + b2
    c3,3 = a3 + b3

    a or b だけの式にできる
    →等しいか試す
    """
    N = 3
    C = [
        tuple(map(int, input().split()))
        for _ in range(N)
    ]

    a = is_valid_a(C, N)
    if not a:
        print("No")
        return

    b = is_valid_b(C, N)
    if not b:
        print("No")
        return

    print("Yes")


def is_valid_a(C, N):
    """
    c1,1 - c2,1: a1 - a2
    c1,2 - c2,2: a1 - a2
    c1,3 - c2,3: a1 - a2
    --------------
    ci,1 - c(i+1),1: ai - a(i+1)
    ci,2 - c(i+1),2: ai - a(i+1)
    ci,3 - c(i+1),3: ai - a(i+1)
    """
    from itertools import combinations
    for x, y in combinations([0, 1, 2], 2):
        valid = C[x][0] - C[y][0] == C[x][1] - C[y][1] == C[x][2] - C[y][2]
        if not valid:
            return False

    return True


def is_valid_b(C, N):
    """
    c1,1 - c1,2: b1 - b2
    c1,2 - c1,3: b2 - b3
    c1,3 - c1,1: b3 - b1
    --------------
    ci,1 - ci,2: b1 - b2
    ci,2 - ci,3: b2 - b3
    ci,3 - ci,1: b3 - b1
    """
    b1_m_b2 = set()
    b2_m_b3 = set()
    b3_m_b1 = set()
    for i in range(N):
        b1_m_b2.add(C[i][0] - C[i][1])
        b2_m_b3.add(C[i][1] - C[i][2])
        b3_m_b1.add(C[i][2] - C[i][0])

    return len(b1_m_b2) == 1 and len(b2_m_b3) == 1 and len(b3_m_b1) == 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			n = scanner.nextInt();
			k = scanner.nextInt();
			d = scanner.nextInt();
			if ((m | n | k | d) == 0)
				break;
			int[] cake = new int[m];
			for (int i = 0; i < m; i++) {
				cake[i] = scanner.nextInt();
			}
			int N = m + n + 2;
			List<Pair>[] lists = new ArrayList[N];
			for (int i = 0; i < N; i++) {
				lists[i] = new ArrayList<Pair>();
			}
			while (d-- > 0) {
				int s = get(scanner.next());
				int t = get(scanner.next());
				int cost = scanner.nextInt() * k;
				lists[s].add(new Pair(t, cost));
				lists[t].add(new Pair(s, cost));
			}
			int[][] dist = new int[1 << m][N];
			for (int[] a : dist)
				Arrays.fill(a, 1 << 28);
			boolean[][] u = new boolean[1 << m][N];
			dist[0][n + m] = 0;
			u[0][n + m] = true;
			PriorityQueue<Pair> deque = new PriorityQueue<Pair>();
			deque.add(new Pair(n + m, 0, 0));
			while (!deque.isEmpty()) {
				Pair pair = deque.poll();
				int s = pair.first;
				int cost = pair.second;
				int bit = pair.bit;
				for (Pair p : lists[s]) {
					if (m <= p.first) {
						int v = cost + p.second;
						if (v < dist[bit][p.first]) {
							dist[bit][p.first] = v;
							deque.offer(new Pair(p.first, v, bit));
						}
					} else {
						int aa = (bit >> p.first) & 1;
						if (aa == 1 )
							continue;
						int v = cost + p.second - cake[p.first];
						int newbit = bit | 1 << p.first;
						if (dist[newbit][p.first] > v) {
							dist[newbit][p.first] = v;
							deque.offer(new Pair(p.first, v, newbit));
						}
					}
				}
			}

			int min = 1 << 28;
			for (int j = 0; j < 1 << m; j++) {
				min = Math.min(min, dist[j][n + m + 1]);
			}
			System.out.println(min);
		}
	}

	private int get(String s) {
		if (s.charAt(0) == 'H')
			return n + m;
		if (s.charAt(0) == 'D')
			return n + m + 1;
		int x = Integer.parseInt(s.substring(1)) - 1;
		return s.charAt(0) == 'C' ? x : x + m;
	}

	int m, n, k, d;

	class Pair implements Comparable<Pair>{
		int first;
		int second;
		int bit;

		public Pair(int first, int second) {
			super();
			this.first = first;
			this.second = second;
		}

		public Pair(int first, int second, int bit) {
			super();
			this.first = first;
			this.second = second;
			this.bit = bit;
		}

		@Override
		public String toString() {
			return "Pair [first=" + first + ", second=" + second + ", bit="
					+ bit + "]";
		}

		@Override
		public int compareTo(Pair o) {
			return this.second-o.second;
		}

	}
}

Measured memory_bytes: 67588
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tmp;
        while(true){
        int x = sc.nextInt();
        int y = sc.nextInt();
            if ( x == 0 && y == 0) break;
            if(x > y){
            tmp = x;
            x = y;
            y = tmp;
            }
            System.out.println(x + " " + y);
        }
}

}




Measured memory_bytes: 36008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	long A[N];
	rep(i,0,N) cin>>A[i];
	long dp[N][N];
	rep(i,0,N) dp[i][i] = A[i];
	rep(i,1,N){
		rep(j,0,N-i){
			dp[j][j+i] = max(A[j] - dp[j+1][j+i], A[j+i] - dp[j][j+i-1]);
		}
	}cout<<dp[0][N-1]<<endl;
}

Measured memory_bytes: 70272
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;

int main(){
	ll n, m; cin >> n >> m;
	ll mod = 1e+9 + 7;
	ll ans = 1;
	ll root_n = n, root_m = m;
	if (abs(m - n) > 1){
		cout << 0 << endl;
		return 0;
	}ll dai = max(n, m);
	ll syou = min(n, m);
	while (1){
		ans *= dai;
		ans %= mod;
		ans *= syou;
		ans %= mod;
		if (syou == 1) break;
		dai--; syou--;
	}if (dai == syou){
		ans *= 2;
		ans %= mod;
	}cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] towns = new int[n];

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            towns[a - 1]++;
            towns[b - 1]++;
        }

        for (int i : towns) {
            System.out.println(i);
        }
    }
}


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

int main(){
  int N;
  cin >> N;
  int ans=0;
  vector<int> A(N);
  vector< vector< pair<int,int> > > xy(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    xy.at(i).resize(A.at(i));
    for(int j=0;j<A.at(i);j++){
      cin >> xy.at(i).at(j).first >> xy.at(i).at(j).second;
    }
  }

  for(int i=0;i<(1<<N);i++){
    bitset<15> bit(i);
    bool flag=true;
    for(int j=0;j<N;j++){
      if(bit.test(j)){
        for(int k=0;k<A.at(j);k++){
          auto p=xy.at(j).at(k);
          if(p.second==1){
            if(!bit.test(p.first-1)){
              flag=false;
              break;
            }
          }else{
            if(bit.test(p.first-1)){
              flag=false;
              break;
            }
          }
        }
      }
      if(!flag){
        break;
      }
    }
    if(flag){
      ans=max(ans,static_cast<int>(bit.count()));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256