akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
long long int gcd(long long int a, long long int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
int main()
{
	long long int A, B, C, D;
	scanf("%lld %lld %lld %lld", &A, &B, &C, &D);

	long long int numMultipleC;
	long long int numMultipleD;
	numMultipleC = (B / C) - ((A-1) / C);
	numMultipleD = (B / D) - ((A-1) / D);

	long long int numMultipleCD;
	long long int common_multiple;
	common_multiple = C * D / gcd(C, D);
	numMultipleCD = (B / common_multiple) - ((A-1) / common_multiple);

	printf("%lld\n", B - A + 1 - numMultipleC - numMultipleD + numMultipleCD);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

long long n, m;

signed main() {
	cin >> n >> m;
	if (m < n * 2)cout << m / 2 << endl;
	else cout << n + (m - n * 2) / 4 << endl;
	ggr
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
ll gcd(ll, ll);
//
int main(){
    int n;
    scanf("%d", &n);
    int target = 1;
    for(int i = 1; i <= n; i++){
        int a;
        scanf("%d", &a);
        if(a == target) target++;
    }
    if(target == 1) {cout <<- 1; return 0;}
    printf("%d", n - target + 1);
}

Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val (n, k) = get[Int, Int]
    val s = get[String].toCharArray

    s(k - 1) = (s(k - 1) - 'A' + 'a').toChar

    out.println(s.mkString(""))

    out.flush()
  }
}

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

using namespace std;

#define N 15

int n,m,swp[N];
bool used[N];
char s[N][N];

void dfs(int x){
	if (x>=n){
		memset(used,0,sizeof used);
		for (int i=1;i<=m;++i)
			if (!used[i]){
				for (int j=i+1;j<=m;++j)
					if (!used[j]){
						bool fl=1;
						for (int k=1;k<=n;++k)
							if (s[k][i]!=s[swp[k]][j]){
								fl=0; break;
							}
						if (fl){used[i]=used[j]=1; break;}
					}
			}
		int tmp=0;
		for (int i=1;i<=m;++i) if (!used[i]){if (tmp) return; tmp=i;}
		if (!tmp){puts("YES"); exit(0);}
		if (tmp&&(m&1)){
			for (int i=1;i<=n;++i)
				if (s[i][tmp]!=s[swp[i]][tmp]) return;
			puts("YES"); exit(0);
		}
		return;
	}
	if (n&1){
		bool fl=1;
		for (int i=1;i<=n;++i) if (swp[i]==i) fl=0;
		for (int i=1;i<=n;++i)
			if (!swp[i]){
				if (fl){swp[i]=i; dfs(x+1); swp[i]=0;}
				for (int j=i+1;j<=n;++j)
					if (!swp[j]){
						swp[i]=j; swp[j]=i;
						dfs(x+2);
						swp[i]=swp[j]=0;
					}
				break;
			}
	}
	else{
		for (int i=1;i<=n;++i)
			if (!swp[i]){
				for (int j=i+1;j<=n;++j)
					if (!swp[j]){
						swp[i]=j; swp[j]=i;
						dfs(x+2);
						swp[i]=swp[j]=0;
					}
			}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) scanf("%s",s[i]+1);
	dfs(0);
	puts("NO");
	
	return 0;
}
			

Measured memory_bytes: 256
def solution():
    while True:
        m, n = [int(val) for val in raw_input().split()]
        if (m, n) == (0, 0):
            break
        mat = []
        for _ in range(m):
            mat.append(list(raw_input()))

        def dfs(x, y):
            direct = [-1, 0, 1, 0, -1]
            stk = []
            c = mat[x][y]
            if mat[x][y] != '.':
                stk.append((x, y))
                mat[x][y] = '.'
            while len(stk):
                x, y = stk.pop(-1)
                for i in range(4):
                    xx = x + direct[i]
                    yy = y + direct[i + 1]
                    if 0 <= xx < m and 0 <= yy < n and mat[xx][yy] == c:
                        stk.append((xx, yy))
                        mat[xx][yy] = '.'

        def solve():
            ans = 0
            for i in range(m):
                for j in range(n):
                    if mat[i][j] != '.':
                        ans += 1
                        dfs(i, j)
            print ans

        solve()


solution()



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

#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

using namespace std;

using ll = long long;

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

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) cin >> S[i];

    ll result = 0;

    vector<ll> a(W, 0);

    REP(i, H) {
        int n_orbs = 0;
        RREP(j, W) {
            if (S[i][j] == 'J') {
                a[j] += n_orbs;
            } else if (S[i][j] == 'O') {
                ++n_orbs;
            } else if (S[i][j] == 'I') {
                result += a[j];
            }
        }

    }

    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 13508
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;++i)
#define repe(i,k,n) for(int i=k;i<=n;++i)

using namespace std;

int main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1);
    repe(i,1,n) cin >> a[i];

    int cnt=0;
    for (int i=1;i<=n;++i){
        int j = a[i];
        if (a[j]==i && a[i] ==j && a[j] !=0 && a[i] !=0) {


            a[j] = a[i] = 0;
            cnt +=1;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 3708
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
string trans(int N)
{
        string S;
        while (N != 0)
        {
                if (N % 2 == 1)
                {
                        N--;
                        S = '1' + S;
                }
                else
                {
                        S = '0' + S;
                }
                N /= 2;
        }
        return S;
}

bool binary(vector<int> vec, int key)
{
        int left = 0;
        int right = vec.size();

        while (left < right)
        {
                int mid = (left + right) / 2;
                if (vec[mid] == key)
                {
                        return true;
                }
                else if (vec[mid] > key)
                {
                        right = mid;
                }
                else
                {
                        left = mid + 1;
                }
        }
        return false;
}

int main() //input->compute->output
{
        int H, W;
        cin >> H >> W;
        vector<string> C(H);
        rep(i, H)
        {
                cin >> C[i];
        }
        rep(i, 2 * H)
        {
                cout << C[i / 2] << endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint m, n;
    cin >> m >> n;
    if (m == 1 and n == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (m == 1) {
        cout << n - 2 << endl;
        return 0;
    }
    if (n == 1) {
        cout << m - 2 << endl;
        return 0;
    }
    if (m == 2 or n == 2) {
        cout << 0 << endl;
        return 0;
    }
    lint a = (m-2)*(n-2);
    cout << a << endl;
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    str S; cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes";
    else cout << "No";
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


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

#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
pair<int,int> a[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n;
	cin>>n;
	rep(i,1,n)
	{
		scanf("%d",&a[i].first);
		a[i].second=i;
	}
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=n;i+=2)ans+=a[i].second%2==0;
	cout<<ans;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	if (a == 5)
		cnt++;
	if (b == 5)
		cnt++;
	if (c == 5)
		cnt++;
	if (cnt == 2) {
		if (a == 7 || b == 7 || c == 7)
			cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll unsigned long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N=1e3+10;
int h,w,ch,cw,dh,dw,head[N*N],cnt,dis[N*N],done[N*N];
char s[N][N];
int num(int x,int y){return (x-1)*w+y;}
struct Node{int nxt,to,w;}edges[N*N*25];
void addedge(int u,int v,int w){edges[++cnt]=Node{head[u],v,w},head[u]=cnt;}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d%d%d%d%d%d",&h,&w,&ch,&cw,&dh,&dw);
	for(int i=1;i<=h;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)
	{
		if(s[i][j]=='#')continue;
		if(s[i][j+1]=='.')addedge(num(i,j),num(i,j+1),0);
		if(s[i][j-1]=='.')addedge(num(i,j),num(i,j-1),0);
		if(s[i+1][j]=='.')addedge(num(i,j),num(i+1,j),0);
		if(s[i-1][j]=='.')addedge(num(i,j),num(i-1,j),0);
		for(int x=max(1,i-2);x<=min(i+2,h);x++)
		for(int y=max(1,j-2);y<=min(j+2,w);y++)
		if(s[x][y]=='.'&&abs(x-i)+abs(y-j)>1)addedge(num(i,j),num(x,y),1);
	}
	int st=num(ch,cw),ed=num(dh,dw);
	memset(dis,0x3f,sizeof(dis));
	priority_queue<pii,vector<pii>,greater<pii>>q;
	q.push(mp(0,st)),dis[st]=0;
	while(!q.empty())
	{
		int u=q.top().se;q.pop();
		if(done[u])continue;
		for(int i=head[u];~i;i=edges[i].nxt)
		{
			int v=edges[i].to;
			if(dis[v]>dis[u]+edges[i].w)dis[v]=dis[u]+edges[i].w,q.push(mp(dis[v],v));
		}
	}
	printf("%d\n",dis[ed]==0x3f3f3f3f?-1:dis[ed]);
	return 0;
}


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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define loop(i, s, n) for(int i = s; i < n; i++)
#define print_vec(X) loop(i, 0, X.size()) cout << X[i] << "\n"
#define nl "\n"
#define fat 1000000007

int main()
{
    boost;
    string s, t;
    cin >> s >> t;

    int count = 0;
    loop(i, 0, 3)
    {
        if(s[i] == t[i]) count++;
    }
    cout << count << nl;

    return 0;
}

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

int selectionSort(int a[],int n){
    int i,j,min_pos;
    int sw=0;
    for (i = 0; i < n-1; ++i) {
        min_pos=i;
        for (j = i; j < n; ++j) {
            if (a[j]<a[min_pos])
                min_pos=j;
        }
        swap(a[i],a[min_pos]);
        if (min_pos!=i)
            sw++;
    }
    return sw;
}

int main() {
    int n,i,j,sw;
    int a[150];
    cin>>n;
    for (i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sw=selectionSort(a,n);

    for (j = 0; j < n; ++j) {
        if (j>0)
            cout<<" ";
        cout<<a[j];
    }
    cout<<endl;
    cout<<sw<<endl;

    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin>>H>>W;
  for(int i=0;i<W+2;i++){
    cout<<"#";
  }
  cout<<endl;
  for(int i=0;i<H;i++){
    string s;
    cin>>s;
    cout<<"#"<<s<<"#"<<endl;
  }
  for(int i=0;i<W+2;i++){
    cout<<"#";
  }
  cout<<endl;
}

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

using namespace std;

struct Island {
	int value;
	int capacity;
};

bool operator<( const Island &a, const Island &b )
{
	return (a.capacity < b.capacity);
}

int main( void )
{
	int n;
	Island map[25];
	while(cin >> n, n) {
		for(int i=0; i < n; ++i)
			cin >> map[i].value >> map[i].capacity;
		sort(map, map+n);
		bool hit = true;
		int sum = 0;
		for(int i=0; i < n; ++i) {
			sum += map[i].value;
			if(sum > map[i].capacity) {
				hit = false;
				break;
			}
		}
		if(hit)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

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


int main() {
    ll n;
    std::cin >> n;

    for (int i = 1; i <= 3500; i++) {
        for (int j = 1; j <= 3500; j++) {
            if(4*i*j-n*i-n*j==0) continue;
            
            if(n*i*j%(4*i*j-n*i-n*j)==0){
                ll k = n*i*j/(4*i*j-n*i-n*j);
                if(k<=3500 && k>0){
                    std::cout << i<<" "<<j<<" "<<k << std::endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

char c;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> c;
	if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel\n";
	else cout << "consonant\n";
	return 0;
}

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

using namespace std;

string s;

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

	cin >> s;

	int x = 0;
	for (auto a : s)
    {
        if (a == 'A')
            x++;
    }

    if (x != 3 && x != 0)
        cout << "Yes";
    else
        cout << "No";

	return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
res = 0
for i in range(N - 1):
  if (X[i + 1] - X[i]) * A > B:
    res += B
  else:
    res += (X[i + 1] - X[i]) * A
print(res)

Measured memory_bytes: 62704
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 100000000

using namespace std;

int main() {
   int a,b,c,d;
   cin >> a >> b >> c >> d;
   cout << max(a*b,c*d) << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n ,k;
  cin >> n >> k;
  int ans =0;
  for(int i =0;i<n;i++){
    int x;
    cin >> x;
    ans += 2*(min(x,k-x));
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  string s[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string ss;
  cin>>ss;
  ll c = 0;
  rep(i,0,7){
    if(ss==s[i]){
      c = i;
    }
  }
  ll ans = 7-c;
  if(ans==0)ans+=7;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    string s, x;
    cin >> s;
    list<char> ans;
    int slen = s.size();
    rep(i, slen){
        ans.push_back(s[i]);
    }
    int q;
    bool rev=false;
    cin >> q;
    rep(i, q){
        int t;
        cin >> t;
        if(t==1){
            rev = !rev;
        }else{
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (f == 1)
            {
                if(!rev){
                    ans.push_front(c);
                }else{
                    ans.push_back(c);
                }
            }else{
                if (rev)
                {
                    ans.push_front(c);
                }
                else
                {
                    ans.push_back(c);
                }
            }
        }
        // for (list<char>::iterator it = ans.begin(); it != ans.end(); it++)
        // {
        //     cout << *it;
        // }
        // cout << endl;
    }

    if(!rev){
        for (list<char>::iterator it = ans.begin(); it != ans.end(); it++)
        {
            cout << *it;
        }
    }else{
        
        for (list<char>::iterator it = ans.begin(); it != ans.end(); it++)
        {
            x.push_back(*it);
        }
        int x_len = x.size();
        for(int i=x_len-1;i>=0;i--){
            cout << x[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 9984
k, n = map(int, input().split())
lis = []
for i in map(int, input().split()):
  lis.append(i)
  
max = k + lis[0] - lis[n-1]
for i in range(n-1):
  j = lis[i+1] - lis[i]
  if j > max:
    max = j

print(k-max)
  

Measured memory_bytes: 24948
#coding: utf-8
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
li = list(combinations_with_replacement([i for i in range(1, M+1)], N))
eq = []
for i in range(Q):
    eq.append(list(map(int, input().split())))
# print(list(combinations_with_replacement([i for i in range(1, M+1)], N)))
ans = 0
for l in li:
    tmp = 0
    for i in range(Q):
        a, b, c, d = eq[i]
        if l[b-1] - l[a-1] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 21412
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
list.sort(A,reverse=True)
count = 0
Sum = sum(A)
for i in range(M):
    if A[i] >= Sum/(4*M):
        count +=1

if M ==count:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <cstdio>
using namespace std;
int main(void){
    int n;
    long long r[200000], maxv, minv;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%ld", &r[i]);
    }
    maxv = r[1] - r[0];
    minv = r[0];
    for (int i = 1; i < n; i++){
        if (minv > r[i-1]) minv = r[i-1];
        if (maxv < r[i] - minv) maxv = r[i] - minv;
    }
    printf("%d\n", maxv);
    return 0;
}

Measured memory_bytes: 4220
#include <iostream>
#include <map>

using namespace std;
struct S
{
	int pos;
	int width;
};

void solve()
{
	int W, Q;
	while(cin >> W >> Q, W || Q)
	{
		map<int, S> Map;
		bool flag[101];
		for(int i = 0; i < 101; ++i)
		{
			flag[i] = false;
		}
		for(int i = 0; i < Q; ++i)
		{
			char c;
			cin >> c;
			if(c == 's')
			{
				int id, w;
				cin >> id >> w;
				int count = 0;
				bool OKflag = false;
				for(int j = 0; j < W; ++j)
				{
					if(!flag[j])
					{
						count++;
					}
					else
					{
						count = 0;
					}
					if(count >= w)
					{
						Map[id].pos = j - w + 1;
						Map[id].width = w;
						cout << j - w + 1 << endl;
						for(int k = j - w + 1; k <= j; ++k)
						{
							flag[k] = true;
						}
						OKflag = true;
						break;
					}
				}
				if(!OKflag)
				{
					cout << "impossible" << endl;
				}
			}
			else if(c == 'w')
			{
				int id;
				cin >> id;
				for(int j = Map[id].pos; j < Map[id].pos + Map[id].width; ++j)
				{
					flag[j] = false;
				}
			}
		}
		cout << "END" << endl;
	}
}

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

Measured memory_bytes: 0
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="?":
        break
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
  string N;
  cin>>N;
  if(N.at(0)==N.at(1)&&N.at(1)==N.at(2)){
    cout<<"Yes"<<endl;
  }
  else if(N.at(1)==N.at(2)&&N.at(2)==N.at(3)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

vector<pair<ll, ll> > ab;
ll N, M;

int main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    ll tmp, tmp2;
    cin >> tmp >> tmp2;
    ab.push_back(make_pair(tmp, tmp2));
  }
  sort(ab.begin(), ab.end());
  ll ans = 0;
  for(int i=0;i<N;i++){
    ll buy = min(M, ab[i].second);
    ans += ab[i].first * buy;
    M -= buy;
    if (M==0) break;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 2420
#include <bits/stdc++.h>
//#include <ext/numeric>
#define oo 0x3f3f3f3f
#define long long long

using namespace std;
//using namespace __gnu_cxx;

long calc(long n, long b) {
    long ret = 0;
    while (n) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    long s, n;
    cin >> n >> s;
    if (s > n) {
        cout << -1 << '\n';
        return 0;
    }
    if (s == n) {
        cout << n + 1 << '\n';
        return 0;
    }

    for (int b = 2; 1ll * b * b <= n; ++b) {
        long x = calc(n, b);
        if (x == s) {
            cout << b << '\n';
            return 0;
        }
    }

    long ans = LLONG_MAX;
    long m = n - s;
    for (int i = 1; 1ll * i * i <= m; ++i) {
        if (m % i == 0) {
            if (calc(n, i + 1) == s) {
                cout << i + 1 << '\n';
                return 0;
            } else if (calc(n, m / i + 1) == s) {
                ans = min(ans, m / i + 1);
            }
        }
    }


    if (ans == LLONG_MAX) {
        cout << -1 << '\n';
        return 0;
    }
    cout << ans << '\n';

    return 0;
}


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

using namespace std;

int main()
{   
    
    int x;
   string s;
   cin>>x>>s;
   int sum[x];
   int b=0;
   for(int i=0;i<x;i++)
   {
       if(s[i]=='I')
       {b+=1;sum[i]=b;}
       else if(s[i]=='D'){b-=1;sum[i]=b;}
   }
   int max=0;
   for(int i=0;i<x;i++)
   {if(sum[i]>max)max=sum[i];
       
   }
   cout<<max;


    return 0;
}


Measured memory_bytes: 256
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, m) = {
        let nm = get_line().split_whitespace()
            .map(|e| e.parse().unwrap())
            .collect::<Vec<usize>>();
        (nm[0], nm[1])
    };
    println!("{}", n * m);
}


Measured memory_bytes: 2156
import itertools

n = int(input())
j = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
j_i, q_i = None, None
for i, t in enumerate(itertools.permutations(range(1,n+1), n), start=1):
    if t == j:
        j_i = i
    if t == q:
        q_i = i
    if j_i and q_i:
        break
print(abs(j_i - q_i))


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

a = list(map(int, input().split()))

flag = True

for i in range(n):
  if a[i]%2 == 0:
    if a[i]%3 != 0 and a[i]%5 != 0:
      print('DENIED')
      flag = False
      break
      
if flag:
  print('APPROVED')

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

pub 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")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }

}

use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

}

use std::cmp::{max, min};
use std::collections::BinaryHeap;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = read_n(n);

    a.sort();
    let mut ans = 0;
    for (i, v1) in a.iter().enumerate() {
        for (j, v2) in a.iter().enumerate() {
            if i != j {

                // 一つ目の条件
                let fc = a.lower_bound(&(v1 + v2));

                // 2つ目の条件
                let sc = a.upper_bound(&(v1 - v2).abs());

                let mut cc = fc - sc;
                if i + 1 <= fc && sc < i + 1 {
                    cc -= 1;
                }
                if j + 1 <= fc && sc < j + 1 {
                    cc -= 1;
                }

                ans += cc

            }

        }
    }

    println!("{}", ans / 6)
}


Measured memory_bytes: 4860
fn main() {
    let n = read::<u32>();
    yn(n / 10 == 9 || n % 10 == 9);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;

const int N = 2e6+1;
int c[N];
int p[N];
int f[N];
int ans[N];
int lz[N];
vector<pair<int,int>> qr[N];

void push(int n) {
  lz[n+n] += lz[n];
  lz[n+n+1] += lz[n];
  lz[n] = 0;
}

void upd(int n, int s, int e, int l, int r, int v) {
  if(s > r or e < l) return;
  if(l <= s and e <= r) {
    lz[n] += v;
    return;
  }
  push(n);
  int mid = (s+e) >> 1;
  upd(n+n, s, mid, l, r, v);
  upd(n+n+1, mid+1, e, l, r, v);
}

int query(int n, int l, int r, int pp) {
  if(l == r) return lz[n];
  push(n);
  int mid = (l+r) >> 1;
  if(pp <= mid) 
    return query(n+n, l, mid, pp);
  else
    return query(n+n+1, mid+1, r, pp);
}

void solve() {
  int n, q;
  cin >> n >> q;
  for(int i = 1; i <= n; i++) {
    cin >> c[i];
    p[i] = f[c[i]];
    f[c[i]] = i;
  }
  for(int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    qr[r].push_back({l, i});
  }
  for(int i = 1; i <= n; i++) {
    upd(1, 1, n, p[i]+1, i, 1);
    for(auto cc : qr[i]) {
      ans[cc.second] = query(1, 1, n, cc.first);
    }
  }
  for(int i = 1; i <= q; i++)
    cout << ans[i] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(10);
  int t = 1;
  // cin >> t;
  for(int tt = 1; tt <= t; tt++) {
    //cout << "Case #" << tt << ": ";
    solve();
  }
  return 0;
}  

Measured memory_bytes: 72592
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> H = new ArrayList<>();

        for(int i=0;i<N; i++){
            H.add(scanner.nextInt());
        }
        List<Integer> step = new ArrayList<>();
        step.add(0);
        int currentH = H.get(N-1);
        int currentStep = 0;
        for(int i=N-2; i>=0; i--){
            int nextH = H.get(i);
            if(nextH >= currentH){
                currentStep++;
            }else{
                step.add(currentStep);
                currentStep = 0;
            }
            currentH = nextH;
        }
        step.add(currentStep);
        int answer = Collections.max(step);
        System.out.println(answer);
    }
}

Measured memory_bytes: 57428
X, Y = input().split()

l ={ "A":1, "B":2, "C":3, "D":4, "E":5, "F":6 }
res = ""
if l[X] == l[Y]:
    res = "="
elif l[X] > l[Y]:
    res = ">"
else:
    res = "<"
print(res)

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

int main(void){
	
	int a, b;

	std::cin >> a >> b;

	if (a <= 8 && b <= 8) {
		std::cout << "Yay!" << std::endl;
	}
	else {
		std::cout << ":(" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

int kaijou(int n){
    if(n==0) return 0;
    else{
        int a=1;
        for(int i=n;i>=2;i--) a*=i;
        return a;
    }

}

int main(){
    int A[10],B[10],n,ansa=0,ansb=0,k;
    bool a[10],b[10];
    cin>>n;
    REP(i,n){
        a[i]=b[i]=false;
    }
    REP(i,n){
        k=0;
        cin>>A[i];
        a[A[i]]=true;
        FOR(j,1,A[i]){
            if(a[j]==false) k++;
        }
        ansa+=k*kaijou(n-i-1);
    }
    REP(i,n){
        k=0;
        cin>>B[i];
        b[B[i]]=true;
        FOR(j,1,B[i]){
            if(b[j]==false) k++;
        }
        ansb+=kaijou(n-i-1)*k;
    }
    cout<<abs(ansa-ansb)<<endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

vector<P> vec;

struct edge{
    ll to,cost;  
};

void dijkstra(ll V,vector<vector<edge> > &G,vector<ll> &d,vector<ll> &d2,ll s){
    PQ que;
    fill(d.begin(),d.end(), LINF);
    fill(d2.begin(),d2.end(), -1);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if(d[v] < p.first) continue;

        rep(i,0,G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
                d2[e.to] = v;
            }
        }
    }
}

int main(){
    ll n,m;
    cin >> n >> m;
    ll a,b,c;
    vector<vector<edge>> G(n);

    rep(i,0,m){
        cin >> a >> b >> c;
        a--;b--;
        edge e; e.cost = c; e.to = b;
        G[a].push_back(e);
        e.to = a;
        G[b].push_back(e);
    }

    rep(i,0,n){
        vector<ll> d(n),d2(n);
        dijkstra(n,G,d,d2,i);
        rep(j,i+1,n){
            ll temp = j,pre = -1;
            for(;temp != -1;temp = d2[temp]){
                if(pre != -1) vec.push_back(P((ll)min(pre,temp),(ll)max(pre,temp)));
                pre = temp;
            }
        }
    }

    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());

    cout << m - sz(vec) << endl;


    return 0;
}



Measured memory_bytes: 7368
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

char otp[1000000];
int otp_p = 0;


inline void read(int &sum) {
    char ch=getchar();int _sum=0,tf;
    while ((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    tf=((ch=='-')&&(ch=getchar()));
    while (ch>='0'&&ch<='9') _sum=_sum*10+(ch-48),ch=getchar();
    sum=tf?-_sum:_sum;
}
inline void read(char *c) {
    char ch=getchar();int p=0;
    while (ch==' '||ch=='\n') ch=getchar();
    while (ch!=' '&&ch!='\n'&&ch!=-1) {*c=ch;ch=getchar();++c;}
    *c='\0';
}
inline void print(int k) {
    char num_s[16];int i = 0;
    if (k<0){*(otp+otp_p)='-';k=-k;++otp_p;}
    while (k) {*(num_s+i)='0'+k%10;k/= 10;++i;}
    while (i) {--i;*(otp+otp_p)=*(num_s+i);++otp_p;}
}
inline void print(string s){
    int j = s.size();otp_p += j;
    for(int i=0;i<j;){*(otp+otp_p-j)=s[i];++i;--j;*(otp+otp_p-i)=s[j];}
}
inline void print(char *c){while (*c!='\0'){*(otp+otp_p)=*c;++c;++otp_p;}}
inline void print() {*(otp+otp_p) = '\0';printf("%s", otp);}


int main() {
    //freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);

    int n,first,last;
    read(n);
    first = n/100;
    last = n%100;
    if (0<first && first<13){
        if (0<last && last<13){
            print("AMBIGUOUS\n");
        } else {
            print("MMYY\n");
        }
    } else {
        if (0<last && last<13){
            print("YYMM\n");
        } else {
            print("NA\n");
        }
    }

    print();
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    count = 0

    if a[0] > x:
        count += a[0] - x
        a[0] -= count

    for i in range(n - 1):
        diff = a[i] + a[i + 1] - x

        if diff > 0:
            count += diff
            a[i + 1] -= diff

    print(count)


Measured memory_bytes: 14068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  vector<int> seats(100000 + 10, 0);
  rep(i, N)
  {
    int l, r;
    cin >> l >> r;
    l;
    r;
    seats[l]++;
    seats[r + 1]--;
  }
  int ans = 0;
  rep(i, seats.size() - 1)
  {
    seats[i + 1] += seats[i];
    if (seats[i + 1] > 0)
      ans++;
  }

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

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
    int n, m, i, j, max, cnt;
    char s[101][11], t[101][11];

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s", s[i]);
    }

    scanf("%d", &m);

    for (i = 0; i < m; i++) {
        scanf("%s", t[i]);
    }

    for (i = 0; i < n; i++) {
        cnt = 0;

        for (j = i; j < n; j++) {
            if (strcmp(s[i], s[j]) == 0) {
                cnt++;
            }
        }

        for (j = 0; j < m; j++) {
            if (strcmp(s[i], t[j]) == 0) {
                cnt--;
            }
        }
        if (max < cnt) {
            max = cnt;
        }
    }

    printf("%d", max);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin>>n>>m;
  ll ans = pow(2,m)*(1900*m+(n-m)*100);
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  ll n;
  cin>>n;
  
  if(n==1){
    cout(0);
    return 0;
  }
  
  ll ans=(1+n)*((n+1)/2)-n;
  if(n%2){
    ans-=(1+n)/2;
  }
  
  cout(ans);
}

Measured memory_bytes: 256
// D - Ki
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

vi ans(200000);
vvi ab(200000);

void dfs(int p, int c){
	ans[c] += ans[p];
	for(int cc:ab[c]) if(cc!=p) dfs(c,cc);
}

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

	for(int i=0; i<n-1; i++){
		int a,b; cin>>a>>b;
		ab[--a].push_back(--b);
		ab[b].push_back(a);
	}

	for(int i=0; i<q; i++){
		int p,x; cin>>p>>x;
		ans[--p] += x;
	}

	for(int c:ab[0]) if(c) dfs(0,c);
	for(int i=0; i<n; i++) cout<< ans[i] <<(i<n-1?" ":"\n");
}

Measured memory_bytes: 23424
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

string read();
long think(string);
void write(long);

long calcSumWithSplitter(string, int);

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  auto input = read();
  auto output = think(input);
  write(output);

  return 0;
}

string read() {
  string buf;

  cin >> buf;
  return buf;
}

long think(string input) {
  long sum = 0;
  int signs = input.size() - 1;

  for (int bits = 0; bits < pow(2.0, signs); bits++) {
    sum += calcSumWithSplitter(input, bits);
  }

  return sum;
}

void write(long output) {
  cout << output << endl;
}

long calcSumWithSplitter(string input, int bits) {
  if (bits == 0) {
    return stol(input);
  }
  auto split = vector<bool> (input.size() - 1, false);
  auto splittedInput = vector<int>();

  for (int i = 0; i < split.size(); i++) {
    if (bits % 2 == 1) {
      split.at(i) = true;
    }
    bits /= 2;
  }

  int from = 0;
  while (from < input.size()) {
    int to = from;
    while (to < split.size() && !split.at(to)) {
      to++;
    }
    splittedInput.push_back(stol(input.substr(from, to - from + 1)));
    from = to + 1;
  }

  long sum = 0;
  for (auto e : splittedInput) {
    sum += e;
  }
  return sum;
}

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

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

	int i, j, k;
	int max = 1;
	for (i = 2; i < sqrt(X); i++) {
		for (j = 2; ; j++) {
			if (pow(i, j) > X)
				break;
		}
		if (max < pow(i, j-1))
			max = pow(i, j-1);
//		printf("%d\n", max);
	}

	printf("%d\n", max);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
const int MAXN=51;
int n,d[MAXN]; ll ans=0;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&d[i]);
    for(int i=1;i<n;++i)
        for(int j=i+1;j<=n;++j)
            ans+=1LL*d[i]*d[j];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int ans = 0;
  int N;
  cin >> N;
  ll A[N];
  map<ll,ll> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }
  sort(A,A+N);
  for (int bit = 32; bit >= 1; bit--) {
    for (int i = 0; i < N; i++) {
      if (lower_bound(A,A+N,(1LL << bit) - A[i]) == upper_bound(A,A+N,(1LL << bit) - A[i])) {
        continue;
      }
      ll& p = mp[A[i]];
      ll& q = mp[(1LL << bit) - A[i]];
      if ((1LL << (bit-1)) == A[i]) {
        ll s = p / 2;
        if (s > 0) {
          ans += s;
          p -= s*2;
        } 
      } else {
        ll s = min(p,q);
        if (s > 0) {
          ans += s;
          p -= s;
          q -= s;
        }
      }
    }
  }

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

Measured memory_bytes: 17648
a = []
S =''
try:
    while True:
        S += input()
except:
    pass

a.append(S)
a = ''.join(a)
a = ','.join(a)
x = a.lower()
    
b =[]
j = 1
y = len(x)
while j <= y:
    c = ord(x[j-1])
    b.append(c)
    j += 1
       
i = 1    
for i in range(97, 123):
    d = b.count(i)
    e = chr(i)
    print(f'{e} : {d}')
            
    i += 1


Measured memory_bytes: 5588
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

char ss[1024];
int n;

bool check()
{
	//the, this, that
	rep(i,n-4)
	{
		if(ss[i]=='t'&&ss[i+1]=='h'&&ss[i+2]=='i'&&ss[i+3]=='s') return true;
		if(ss[i]=='t'&&ss[i+1]=='h'&&ss[i+2]=='a'&&ss[i+3]=='t') return true;
		if(ss[i]=='t'&&ss[i+1]=='h'&&ss[i+2]=='e') return true;

	}
	return false;

}

void f()
{

	rep(i,n)
	{
		if(ss[i]=='\n') break;
		if(ss[i]==' '||ss[i]=='.') continue;
		char c=ss[i];
		c++;
		c-=19;
		c=c%26;
		ss[i]=(c+'a');
	}

}
int main()
{
	while(fgets(ss,sizeof(ss),stdin)!=NULL)
	{
		n=strlen(ss);
		//[97,122]
		//%97
	
		rep(i,26)
		{
			if(check())
			{
				printf("%s",ss);
				goto go;
			}
			f();
			//cout<<ss;
		}
go:;
	}
	
	return 0;
}

Measured memory_bytes: 1112