akhauriyash/Code-Regression huggingface dataset:
/*input
5 9
4 4 2 3 2
5
1 4 2 3 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 5e5+2;
int a[N];
int b[N];
int d[N];
int n,q;

void solve(){
  	cin >> n >> a[0];
  	RE(i,n)cin >> d[i];
  	RE(i,n){
  		a[i] = min(a[i-1],abs(a[i-1]-d[i]));
  	}
  	REP(i,n+1){
  //		cout << i << " " << a[i] << endl;
  	}
  	b[n+1] = 1;
  	for(int i= n;i > 0;i--){
  		if(2*b[i+1] > d[i]){
  			b[i] = b[i+1]+d[i];
  		}
  		else b[i] = b[i+1];
  	}
  //	RE(i,n)cout << b[i] << " ";cout << endl;
  	cin >> q;
  	while(q--){
  		int ind;cin >> ind;
  		if(a[ind-1] >= b[ind+1]){
  			cout << "YES";
  		}
  		else cout << "NO";
  		cout << endl;
  	}
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 13696
#include<stdio.h>
#define int long long

main()
{
  int a,b,c,d;
  int count,r,tmp,x,y,z;
  
  scanf("%ld %ld %ld %ld",&a,&b,&c,&d);  
  
  x=c;
  y=d;
  z=x*y;
  
  if(x<y){
    tmp = x;
    x = y;
    y = tmp;
  }
 
  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }
  
  z=z/y;
  count=b-a+1;
  r=b/z-(a-1)/z;
  a=(a-1)/c+(a-1)/d;
  b=(b/c)+(b/d);
  
  count=count-(b-a-r);
  
  printf("%ld",count);
  
  return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  bool bl;
  bl = false;
  for (int i=0; i<b; i++){
    if(a*i % b == c){
      bl = true;
    }
  }
  
  if(bl){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) std::cout << (x) << std::endl
typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;
    char s[h][w];
    REP(i, h) {
        REP(j, w)
        cin >> s[i][j];
    }
    int ans = 0;
    vector<int> dx = {0, 1, 0, -1};
    vector<int> dy = {1, 0, -1, 0};
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            //cout << "start: " << i << "," << j << endl;
            if (s[j][i] == '#')
                continue;
            pair<int, int> start = {i, j};
            for (int k = 0; k < w; k++) {
                for (int l = 0; l < h; l++) {
                    //cout << "goal: " << k << "," << l << endl;
                    if (s[l][k] == '#')
                        continue;
                    pair<int, int> goal = {k, l};
                    vector<vector<bool>> flag(h, vector<bool>(w, false));
                    queue<pair<pair<int, int>, int>> que;
                    que.push({start, 0});
                    while (!que.empty()) {
                        auto tmp = que.front();
                        que.pop();
                        auto corr = tmp.first;
                        int depth = tmp.second;
                        if (corr.first == goal.first && corr.second == goal.second) {
                            ans = max(ans, tmp.second);
                            break;
                        }
                        for (int t = 0; t < 4; t++) {
                            int nextX = corr.first + dx[t], nextY = corr.second + dy[t];
                            if (nextX < 0 || nextX >= w)
                                continue;
                            if (nextY < 0 || nextY >= h)
                                continue;
                            if (s[nextY][nextX] == '#')
                                continue;
                            if (flag[nextY][nextX])
                                continue;
                            flag[nextY][nextX] = true;
                            que.push({{nextX, nextY}, depth + 1});
                        }
                    }
                }
            }
        }
    }
    OUT(ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	static Map<Integer, Long> factMap = new HashMap<>();
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++)
        	p[i] = sc.nextInt();
        int[] q = new int[n];
        for(int i = 0; i < n; i++)
        	q[i] = sc.nextInt();

        int[] cntP = new int[n];
        for(int i = 0; i < n; i++) {
        	int cnt = 0;
        	for(int j = 0; j < i; j++) {
        		if(p[j] < p[i])
        			cnt++;
        	}
        	cntP[i] = cnt;
        }

        int[] cntQ = new int[n];
        for(int i = 0; i < n; i++) {
        	int cnt = 0;
        	for(int j = 0; j < i; j++) {
        		if(q[j] < q[i])
        			cnt++;
        	}
        	cntQ[i] = cnt;
        }

        long numP = calPosition(p, cntP);
        long numQ = calPosition(q, cntQ);
        System.out.println(Math.abs(numP - numQ));
    }

    private static long calPosition(int[] p, int[] cntP) {
    	long res = 0;
    	int n = p.length;
    	for(int i = 0; i < n; i++) {
    		int rightCnt = n - i - 1;
    		int smallCnt = p[i] - 1 - cntP[i];
    		res += smallCnt * factorial(rightCnt);
    	}
    	return res;
    }

    private static long factorial(int n) {
    	if(factMap.containsKey(n))
    		return factMap.get(n);
    	if(n == 1) 
    		return 1;
    	if(n == 0)
    	    return 0;
    	long res = n * factorial(n-1);
    	factMap.put(n, res);
    	return res;
    }
}


Measured memory_bytes: 24020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long x = Long.parseLong(sc.next());
        long[] ary = new long[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Long.parseLong(sc.next());
        }
        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (ary[i] + ary[i + 1] > x) {
                long temp = ary[i] + ary[i + 1] - x;
                ans += temp;
                if (ary[i + 1] < temp) {
                    ary[i + 1] = 0;
                } else {
                    ary[i + 1] -= temp;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 47308
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

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

    vector<int> v(n);
    rep(i,n){
        cin >> v[i];
    }

    sort(v.begin(), v.end());

    rep(i, m){
        auto itr = lower_bound(v.begin(), v.end(), v[n-1]/2);
        v.insert(itr, v[n-1]/2);
        v.pop_back();
    }

    cout << accumulate(v.begin(), v.end(), 0LL);
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	vector<int> v(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> v[i + 1];
	}
	vector<int> ball(N + 1, 0);
	vector<bool> ans(N + 1, false);
	int counter = 0;
	for (int i = N; i > 0; i--) {
		if (ball[i] % 2 != v[i]) {
			ball[i]++;
			ans[i] = true;
			counter++;
			for (int j = 1; j * j <= i; j++) {
				if (i % j == 0) {
					ball[j]++;
					if (j != 1 && j * j != i) {
						ball[i / j]++;
					}
				}
			}
		}
	}
	cout << counter << endl;
	for (int i = 1; i <= N; i++) {
		if (ans[i]) {
			cout << i;
			counter--;
			if (counter == 0) {
				cout << endl;
				break;
			}
			else {
				cout << " ";
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2560
def solve(N):
    if len(N) > 1:
        tmp = N[0] + '9' * (len(N) - 1)
    else:
        print(int(N))
        exit()

    if int(tmp) > int(N):
        tmp = str(int(N[0]) - 1) + '9' * (len(N) - 1)

    ans = 0
    for s in tmp:
        ans += int(s)

    return ans


if __name__ == "__main__":
    N = input()
    print(solve(N))


Measured memory_bytes: 9124
#include <iostream>

using namespace std;

int main (){

    int N0,Y;

    cin >> N0 >> Y;

    for(int i = 0; i <= N0; i++){
        int N1 = N0 - i;
        for(int j = 0; j <= N1; j++){
            int N2 = N1 - j;
            if(Y == i*10000 + j*5000 + N2*1000){
                cout << i << " " << j << " " << N2 << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;

}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int k, t; cin >> k >> t;
  int maxT = -1;
  int sum = 0;
  vector<int> a(t);
  for(int i = 0; i < t; i++) {
    cin >> a[i];
    maxT = max(maxT, a[i]);
    sum += a[i];
  }
  cout << max(maxT - (sum-maxT+1), 0) << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    if d:
        d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    if e:
        e.sort()
    if d and e:
        print(max(d[-1] * d[-2], e[-1]*e[-1]))
    elif d:
        print(d[-1] * d[-2])
    else:
        print(e[-1]*e[-1])


if __name__ == '__main__':
    main()


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

int main(void) {

	//char S[10];
	int A=0,B=0,C=0;

	scanf("%d %d %d" ,&A,&B,&C);


	if(A-B>=C){

	printf("%d", 0);

	}

	else{
		printf("%d",C-A+B );
	}

	return 0;
}



Measured memory_bytes: 128
#define DEBUG 0
#define L -1
#define B -1
#define R 1
#define T 1

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

struct sq_data{
	int no;
	int x;
	int y;
};



int main(){
	int N;
	
	while(1){
		if(DEBUG)printf("input N:");
		
		scanf("%d",&N);
		if(N == 0){
			break;
		}
		struct sq_data sq[N];
		sq[0].no = 0;
		sq[0].x = 0;
		sq[0].y = 0;
		
		int i;
		int n,d;
		for(i = 1;i < N;i++){
			scanf("%d%d",&n,&d);
			if(d == 0){//左
				sq[i].x = sq[n].x + L;
				sq[i].y = sq[n].y;
			}
			else if(d == 1){//下
				sq[i].x = sq[n].x;
				sq[i].y = sq[n].y + B;
			}
			else if(d == 2){//右
				sq[i].x = sq[n].x + R;
				sq[i].y = sq[n].y;
			}
			else if(d == 3){//上
				sq[i].x = sq[n].x;
				sq[i].y = sq[n].y + T;
			}
		}
		
		int buf_min_x=0;
		int buf_max_x=0;
		int buf_min_y=0;
		int buf_max_y=0;
		for(i = 0;i < N;i++){
			if(i == 0){
				buf_min_x = 0;
				buf_max_x = 0;
			}
			if(sq[i].x<buf_min_x){
				buf_min_x = sq[i].x;
			}
			else if(sq[i].x>buf_max_x){
				buf_max_x = sq[i].x;
			}
			
			if(sq[i].y<buf_min_y){
				buf_min_y = sq[i].y;
			}
			else if(sq[i].y>buf_max_y){
				buf_max_y = sq[i].y;
			}
		}
	
		
		printf("%d %d\n",buf_max_x-buf_min_x+1,buf_max_y-buf_min_y+1);
	}
	
	
	return 0;
}

// vim: se noet ts=4 sw=4 sts=0 ft=c :

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {
	fix;
	int r;
	cin >> r;
	cout << M_PI * 2 * r << "\n";
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int main(){
  int n[4],n2[4],hit,blow;
  while(cin>>n[0]>>n[1]>>n[2]>>n[3]>>n2[0]>>n2[1]>>n2[2]>>n2[3]){
    hit = 0;
    blow = 0;
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
      if(n[i]==n2[j]&&i==j) hit++;
      else if(n[i]==n2[j]) blow++;
      }
    }
    cout << hit << ' ' << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define mod 1000000007
#define rep(i,n)    for(ll i=0;i<n;++i)
#define forup(i,a,b)    for(ll i=a;i<=b;++i)
#define all(v)    v.begin(),v.end()
#define inf 1000000010
#define pii pair<ll,ll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MAXN 110
#define bsize 555
#define sz(v) v.size()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll y, ll md){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

vector<ll> v[100010];
vector<ll> dp(100010,0);
vector<bool> visit(100010,false);

void dfs(ll x){
    if(visit[x])    return;
    visit[x] = true;
    for(ll i=0;i<sz(v[x]);++i){
        dfs(v[x][i]);
    }
    ll mx=0;
    for(ll i=0;i<sz(v[x]);++i){
        mx = max(mx,dp[v[x][i]]);
    }
    dp[x]=mx+1;
}
int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        v[x].pb(y);
    }
    forup(i,1,n){
        if(!visit[i])
            dfs(i);
    }
    cout<<*max_element(all(dp))-1;
}

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

typedef map<int, int> mii;
typedef vector<int> vi;
typedef multiset<int> msi;

const int MAXI = 1000000000;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m ,i, j, k, e, ans = 1;
	cin >> n;
	m = pow(2, n);
	mii ns;
	msi ms;
	bool is = true;
	for (i = 0; i < m; i++) {
		cin >> e;
		ns[MAXI - e]++;
	}
	
	ms.insert(ns.begin()->first);
	(ns.begin()->second)--;
	if (ns.begin()->second == 0)
		ns.erase(ns.begin());

	for (i = 0; i < n; i++) { 
		vi elem;
		for (auto it = ms.begin(); it != ms.end(); it++) {
			auto jt = ns.upper_bound(*it);
			if (jt == ns.end()) {
				is = false;
				break;
			}
			elem.push_back(jt->first);
			jt->second--;
			if (jt->second == 0)
				ns.erase(jt);
		}
		if (!is)
			break;
		for (j = 0; j < elem.size(); j++)
			ms.insert(elem[j]);
	}

	cout << (is ? "Yes" : "No") << "\n";
	return 0;
}

Measured memory_bytes: 13304
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    if(a>=1 && a<=100 && b>=1 && b<=100)
    {
      String temp=""+a+""+b;
      int c=Integer.parseInt(temp);
      Double d=Math.sqrt(c);
      int e = d.intValue();
      if(d==e)
      {
        System.out.println("Yes");
      }else
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22484
import math

S = list(input())

t = 0

res = 0

for i in range(len(S)):
    if S[i] == "W":
        res += i - t
        t += 1

if len(S) == 1:
    print(0)

elif S.count("B") == 1 and S[-1] == "B":
    print(0)

else:
    print(res)

Measured memory_bytes: 10520
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=0;i<n-1;i++)
	{
		while(a[i]>0)
		{
			if(a[i+1]>=a[i])a[i+1]=a[i+1]%a[i];
			if(a[i]>a[i+1])swap(a[i],a[i+1]);
		}
	}
	cout<<a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var M = int.Parse(inputs[1]);
        var X = new int[M];
        inputs = Console.ReadLine().Split(' ');
        for (int i = 0; i < M; i++)
        {
            X[i] = int.Parse(inputs[i]);
        }
        // 座標の昇順
        X = X.OrderBy((x) => x).ToArray();
        // 次の地点までの距離
        var d = new int[M - 1];
        var sum = 0;
        for (int i = 0; i < d.Length; i++)
        {
            d[i] = X[i + 1] - X[i];
            sum += d[i];
        }

        d = d.OrderByDescending((v) => v).ToArray();
        // 大きい距離から順番に除いていく
        // N個のコマがある場合、区切りはN-1個であることに注意する
        int maxNum = Math.Min(d.Length, N - 1);
        for (int i = 0; i < maxNum; i++)
        {
            sum -= d[i];
        }

        Console.WriteLine(sum);
    }
}



Measured memory_bytes: 23008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
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 main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -INF;
    chmax(ans, a*c);
    chmax(ans, a*d);
    chmax(ans, b*c);
    chmax(ans, b*d);
    cout << ans << endl;
    return 0;
}

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

int main() {
long int n,a,b;
cin >> n;
cin >> a;
cin >> b;

long int grp=n/(a+b);
long int amari = n%(a+b);
long int x;
if(amari>=a){
x=a;
} else {
x=amari;
}
long int sum = grp*a+x;
cout << sum << endl;
        return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
int main(){
  int a,b,x,y;
  cin>>a>>b>>x>>y;
  fr(i,x-a) cout<<"R";
  fr(i,y-b) cout<<"U";
  fr(i,x-a) cout<<"L";
  fr(i,y-b+1) cout<<"D";
  fr(i,x-a+1) cout<<"R";
  fr(i,y-b+1) cout<<"U";
  cout<<"LU";
  fr(i,x-a+1) cout<<"L";
  fr(i,y-b+1) cout<<"D";
  cout<<"R"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int mod=1000000007;
    int mc=0,ml=0;
    map<string, int> m;
    string s,a,b;
    while(cin>>s){
        m[s]++;
        if (mc<m[s]) {
            mc=m[s];
            a=s;
        }
        if (ml<s.length()){
            ml=s.length();
            b=s;
        }

    }
    cout<<a<<" "<<b<<"\n";
    return 0;
}

Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
string S;
int main() {
	cin >> S; int cnt = 0;
	for (int i = 0; i < (S.size() + 1) / 2; i++) { if (S[i] == 'p')cnt--; }
	for (int i = (S.size() + 1) / 2; i < S.size(); i++) { if (S[i] == 'g')cnt++; }
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    if N % 2 == 0:
        A = [a * 2 for a in A]
        B = [b * 2 for b in B]

    A.sort()
    B.sort()

    medA = (A[(N - 1) // 2] + A[N // 2]) // 2
    medB = (B[(N - 1) // 2] + B[N // 2]) // 2

    ans = medB - medA + 1
    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 144824
def max_minus_min(areas):
    # print("areas", areas)
    return max(areas) - min(areas)
 
def solve2(h, w):
    area1 = h * (w // 2)
    area2 = h * w - area1
    return [area1, area2]
 
def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h
        ans = min(ans, max_minus_min([area1] + solve2(h, w - w2)))
        ans = min(ans, max_minus_min([area1] + solve2(w - w2, h)))
    return ans
 
H, W = map(int, input().split())
print(min(solve(H,W), solve(W,H)))


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

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        if ans <= 10**18:
            ans = ans * i
        else:
            break

if ans > 10**18:
    print(-1)
else:
    print(ans)

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000000 + 7)

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

u64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}
u32 A[12][12];
int main() {
  cout << setprecision(18);

  u32 N, M, X;
  cin >> N >> M >> X;
  vector<u32> C(N);
  vector<u32> Skill(M, 0);
  for (u32 i = 0; i < N; ++i) {
    cin >> C[i];
    for (u32 j = 0; j < M; ++j) {
      cin >> A[i][j];
      Skill[j] += A[i][j];
    }
  }
  bool flag = false;
  for (u32 j = 0; j < M; ++j) {
    if (Skill[j] < X) {
      flag = true;
      break;
    }
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  u32 max_num = My_Pow(2, N, MAX_NUM);
  u32 res = MAX_NUM;
  for (u32 i = 1; i < max_num; ++i) {
    u32 cost = 0;
    vector<u32> Index;
    for (u32 j = 0; j < N; ++j) {
      if ((i >> j) & 0x01) {
        Index.push_back(j);
      }
    }
    vector<u32> Aquire(M, 0);
    for (auto itr = Index.begin(); itr != Index.end(); ++itr) {
      for (u32 j = 0; j < M; ++j) {
        Aquire[j] += A[*itr][j];
      }
      cost += C[*itr];
    }
    flag = false;
    for (u32 j = 0; j < M; ++j) {
      if (Aquire[j] < X) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      res = min(res, cost);
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<int,int> P;
struct edge{ int to,cost; };
#define VMAX 100000
//bool cmp(P a,P b){ return a.second < b.second;}

ll N,M,X,ans=0;
ll Lay[52],Py[52];

ll DP(ll n,ll x){
	if(n==0){
		if(x<=0) return 0;
		else return 1;
	}else if(x<=Lay[n-1]+1){
		return DP(n-1,x-1);
	}else{
		return Py[n-1]+1+DP(n-1,x-2-Lay[n-1]);
	}

}

int main(){
	std::ios_base::sync_with_stdio(false);
	cin>>N>>X;
	Lay[0]=Py[0]=1;
	REP(i,N){
		Lay[i+1]=2*Lay[i]+3;
		Py [i+1]=2*Py [i]+1;
		DEB(Lay[i+1])DEB(Py[i+1])END
	}
	ans=DP(N,X);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N = 200010;
const int MOD = 1000000007;
const int oo = 1e9;


int  n , k , p[N],idx = 0;

int dv(int n , int k){
	return n/k + (n%k != 0);
}
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; ++i){
		scanf("%d",&p[i]);
		if(p[i]==1)
			idx = i;
	}
	int res = 1e9;
	for(int i = idx ; i >= max(1,idx-k+1);i--){
		res = min(dv(i-1,k-1)+dv(n-i,k-1),res);
	}
	cout << res << endl;


	return 0;
}

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

int main()
{
    long long int n;
    cin>>n;
    int t;
    string ans="";
    while(n>26)
    {
      	n--;
      	t=n%26;
        n=n/26;
        ans+=('a'+t);
    }
    n--;
    ans+=('a'+n);
    long long int len=ans.length();
    string res;
    for(long long int i=len-1;i>=0;i--)
    {
        res.push_back(ans[i]);
    }
    cout<<res;
    return 0;
}


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

int a[100010];
int k;

long long ans(long long q)
{
    for (int i(1); i <= k; i++)
        q -= q % a[i];
    return q;
}

int main()
{
    cin >> k;
    for (int i(1); i <= k; i++)
        cin >> a[i];

    long long p(0), q(1ll << 60);
    while (q) {
        if (ans(p + q) < 2)
            p += q;
        q /= 2;
    }
    p++;
    if (ans(p) == 2)
        cout << p << ' ';
    else {
        cout << -1;
        return 0;
    }

    p = 0, q = 1ll << 60;

    while (q) {
        if (ans(p + q) <= 2)
            p += q;
        q /= 2;
    }

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


Measured memory_bytes: 640
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;
const ll inf = (1LL << 60);

int n;
ll p[MAXN], p1[MAXN], dp[MAXN][4];

ll rek(int a, int t) {
	if (a == n) return 0;
	if (t == 4) return -(1LL << 54);
	if (dp[a][t] != -1) return dp[a][t];

	ll ret = -inf;
	
	if (t) ret = max(ret, rek(a, t - 1));
	int b = t % 2;
	
	if (!(b ^ p1[a])) ret = max(ret, rek(a + 1, t) + p[a]);
	else ret = max(ret, rek(a + 1, t) - p[a]);
	
	if (p1[a]) {
		int B = !b;
		if (!B) ret = max(ret, rek(a + 1, t + 1) + p[a]);
		if (B) ret = max(ret, rek(a + 1, t + 1) - p[a]);
	}

	return dp[a][t] = ret;
}

int main() {
	scanf("%d",&n);
	scanf("%lld",&p[0]);
	REP(i, n - 1) {
		char s[2];
		scanf("%s %lld",s,&p[i + 1]);
		if (s[0] == '-') p1[i + 1] = 1;
	}

	memset(dp, -1, sizeof dp);
	printf("%lld\n",rek(0, 0));
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl;
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 itoc(const char c){
  return (c+'0');
}

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int P[M],Y[M];
    vector<char> ans[100100];
  	vector<char> tai[100100],kei[100100];
    vector<pair<int,int>> V[100100];
    REPP(i,1,M+1){
        cin >> P[i] >> Y[i];
        V[P[i]].pb({Y[i],i});
   	   	int num = to_string(P[i]).size();
        REP(j,6 - num){
            ans[i].pb('0');
        }
        REP(j,num){
            int A = P[i] % 10;
            P[i] /= 10;
            tai[i].pb(itoc(A));
        }
        for(int j = num-1; j >= 0;j--){
            ans[i].pb(tai[i][j]);
        }
    }
    REPP(i,1,N+1){
        if(V[i].size() >= 1) sort ALL(V[i]);
    }
    REPP(i,1,N+1){
        REP(j,V[i].size()){
            string B;
          	int C = j+1;
          	int nam = to_string(C).size();
            REP(k,6 - nam){
                ans[V[i][j].second].pb('0');
            }
            REP(k,nam){
               int B = C % 10;
               C /= 10;
               kei[V[i][j].second].pb(itoc(B));
            }
            for(int k = nam-1; k >= 0;k--){
                ans[V[i][j].second].pb(kei[V[i][j].second][k]);
            }
        }
    }
    REPP(i,1,M+1){
        REP(j,12){
            cout << ans[i][j];
        }
      	cout << endl;
    }
}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

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

    if (K <= (N - 1) * (N - 2) / 2) {
        K = (N - 1) * (N - 2) / 2 - K;

        cout << K + N - 1 << "\n";
        rep(i, N - 1) cout << 1 << " " << i + 2 << "\n";

        for (int i = 2; i <= N; ++i) {
            for (int j = i + 1; j <= N; ++j) {
                if (K != 0) {
                    cout << i << " " << j << "\n";
                    --K;
                }
            }
        }
    } else {
        cout << -1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long   ll;
typedef  long double ld;
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
string a, b;
int n, m;
vector<vector<int>> dp;
int solve(int idx1, int idx2) {
	if (idx1 > n || idx2 > m)
		return -1e9;
	if (idx1 == n || idx2 == m)
		return 0;
	int& ret = dp[idx1][idx2];
	if (~ret)
		return ret;
	int p1 = solve(idx1 + 1, idx2);
	int p2 = solve(idx1, idx2 + 1);
	int p3 = 0;
	if (a[idx1] == b[idx2])
		p3 = 1 + solve(idx1 + 1, idx2 + 1);
	return ret = max({ p1, p2, p3 });
}

void build(int idx1, int idx2) {
	if (idx1 > n || idx2 > m)
		return;
	if (idx1 == n || idx2 == m)
		return;
	int p1 = solve(idx1 + 1, idx2);
	int p2 = solve(idx1, idx2 + 1);
	int p3 = 0;
	if (a[idx1] == b[idx2]) 
		p3 = 1 + solve(idx1 + 1, idx2 + 1);
	int opt = solve(idx1, idx2);
	if (p1 == opt) 	
		build(idx1 + 1, idx2);	
	else if (p2 == opt) 	
		build(idx1 , idx2  + 1);
	else if (p3 == opt) {
		cout << a[idx1];
		build(idx1 + 1, idx2 + 1);
	}
	
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	cin >> a >> b;
	n = a.size(), m = b.size();
	dp = vector<vector<int>>(n, vector<int>(m, -1));
	solve(0, 0);
	build(0, 0);
	
	


}


Measured memory_bytes: 38756
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int h,w;
    cin>>h>>w;

    char a[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    vvi dp(h, vi(w));
    dp[0][0]=1;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0;
                continue;
            }
            if(i>0) dp[i][j]+=dp[i-1][j];
            if(j>0) dp[i][j]+=dp[i][j-1];
            if(dp[i][j]>=mod) dp[i][j]-=mod;
        }
    }

    cout<<dp[h-1][w-1]<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


Measured memory_bytes: 12172
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			string s = cin.Next();
			int n = s.Length;
			if (n % 2 != 0) {
				Console.WriteLine("No");
				return;
			}

			for (int i = 0; i < n; i += 2) {
				if (s[i] != 'h' || s[i + 1] != 'i') {
					Console.WriteLine("No");
					return;
				}
			}

			Console.WriteLine("Yes");
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13140
// $%U%$
// $%D%$/$%M%$/$%Y%$
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}

int main(){
    string s;
    cin >> s;
    if(s[s.length()-1] == 's') s += "es";
    else s += "s";
    cout << s;
    return 0;
}




Measured memory_bytes: 3572
N = int(input())
L = input().split(" ")
for i in range(0, len(L)):
  L[i] = int(L[i])
L.sort()

ans = 0
for i in range(0, len(L), 2):
  tmp = L[i]
  if tmp > L[i+1]:
    tmp = L[i+1]
  ans += tmp
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

long long n;
string s;

signed main()
{
    srand(time(NULL));
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cout << n * n << endl;
}


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

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int) (x).size())
#define ALL(x) x.begin(), x.end()
#define debug(x) cerr << #x" = " << x << endl

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long u64;
typedef vector<int> VI;

template <typename T, typename TT> ostream & operator << (ostream &out, pair<T, TT> t) { return out << "(" << t.X << "," << t.Y << ")";}
template <typename T> ostream & operator << (ostream &out,vector<T> t) { out << "["; for (auto x:t) out << x << " "; out << "]"; return out;}
template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
template <typename T> void read(T & x) 
{
	int f = 1; char ch; x = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x *= f;
}

const int N = 1 << 19, NX = N << 1, mod = 924844033, G = 5;

int n, siz[NX], da[NX], db[NX]; vector<int> edge[NX];
 
void dfs(int x, int fa = 0) 
{
	siz[x] = 1;
	for (int y : edge[x]) 
	{
		if(y != fa)
		{
			dfs(y, x);
			siz[x] += siz[y];
		}
	}
	if(x != 1) 
	{
		++da[siz[x]];
		++da[n - siz[x]];
	}
}

int exp(int a, int n)
{
	int res = 1;
	for (; n; n >>= 1)
	{
		if(n & 1)
			res = (LL) res * a % mod;
		a = (LL) a * a % mod;
	}
	return res;
}

namespace ntt 
{
	int eps[NX];
	void preprocess()
	{
		int g = exp(G, (mod - 1) / N);
		eps[0] = 1; 
		for (int i = 1; i < N; i++)
			eps[i] = (LL) eps[i - 1] * g % mod;
	}
	
	void dft(int n, int x[])
	{
		for (int i = 0, j = 0; i < n; i++)
		{
			if(i > j) swap(x[i], x[j]);
			for (int l = n >> 1; (j ^= l) < l; l >>= 1);
		}
		
		for (int i = 2; i <= n; i <<= 1)
		{
			int l = i >> 1, d = N / i;
			for (int j = 0; j < n; j += i) 
				for (int k = 0; k < l; k++)
				{
					int t = (LL) eps[d * k] * x[j + k + l] % mod;
					x[j + k + l] = (x[j + k] + mod - t) % mod;
					x[j + k] = (x[j + k] + t) % mod;
				}
		}
	}
	
	void idft(int n, int x[]) 
	{
		dft(n, x);
		reverse(x + 1, x + n);
		int inv = exp(n, mod - 2);
		for (int i = 0; i < n; i++)
			x[i] = (LL) x[i] * inv % mod;
	}
}
using ntt::dft;
using ntt::idft;

int fac[NX], rfac[NX];
int main() 
{
	ntt::preprocess();
	
	read(n);
	for (int i = 1, u, v; i < n; i++) 
	{
		read(u); read(v);
		edge[u].pb(v);
		edge[v].pb(u);
	}	
	dfs(1, 0);

	fac[0] = 1;
	for (int i = 1; i < N; i++)	
		fac[i] = (LL) fac[i - 1] * i % mod;
	rfac[N - 1] = exp(fac[N - 1], mod - 2);
	for (int i = N - 1; i; i--)
		rfac[i - 1] = (LL) rfac[i] * i % mod;
	
			
	for (int i = 0; i <= n; i++)
	{
		da[i] = (LL) da[i] * fac[i] % mod;
		db[i] = rfac[i];
	}
	
	reverse(da, da + n + 1);
	dft(N, da);
	dft(N, db);
	for (int i = 0; i < N; i++)
		da[i] = (LL) da[i] * db[i] % mod;
	idft(N, da);
	
	for (int i = 1; i <= n; i++)
	{
		int ans = (LL) n * fac[n] % mod * rfac[i] % mod * rfac[n - i] % mod;
		ans = (ans + mod - (LL) da[n - i] * rfac[i] % mod) % mod;
		printf("%d\n", ans);	
	}
	return 0;
}





Measured memory_bytes: 66176
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=map(int,input().split())
# print(0)
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 5204
a,b=map(int,input().split())
one_num=0
if(a%2==0 and b%2==0):
    one_num=(((b-1)-a)+1)//2
    one_num=0 if one_num%2==0 else 1
    print(one_num^b)
elif(a%2==0):
    one_num=((b-a)+1)//2
    one_num=0 if one_num%2==0 else 1
    print(one_num)
elif(b%2==0):
    one_num=(((b-1)-(a+1))+1)//2
    one_num=0 if one_num%2==0 else 1
    print(one_num^a^b)
else:
    one_num=((b-(a+1))+1)//2
    one_num=0 if one_num%2==0 else 1
    print(one_num^a)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
	#define int long long
	int n;
	cin >> n;
	int d[n];
	for(int i = 0; i < n; i++)
	cin >> d[i];
	sort(d,d+n);
	int ans = d[n/2]-d[n/2-1];
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	string s, t;
	cin >> s >> t;
	int ss = s.size();
	int tt = t.size();
	//int cnt(0);
	int ans(0);
	rep(i, ss) {
		int cnt(0);
		if (i + tt-1 >= ss)break;
		rep(j, tt) {
			int k = i + j;
			//cout << k << " " << j << endl;
			if (s[k] == t[j]) {
				cnt++;
			}
		}
		ans = max(ans,cnt);
	}
	cout << tt - ans;
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int count = 0;
        for (int i = 1; i <= n; i++) {
            int s = scan.nextInt();
            if(i != s){
                count+=1;
            }
        }

        System.out.println(count>2?"NO":"YES");
    }
}


Measured memory_bytes: 22740