akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define  MAX 100000000000

using namespace std;
typedef long long ll;

ll n,w,arrw[105],arrv[105],dp[105][100005];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>w;
    for(int i=1;i<=(int)n;i++)cin>>arrw[i]>>arrv[i];
    for(int i=0;i<=(int)n;i++)for(int j=0;j<=100000;j++)dp[i][j]=MAX;
    for(int i=1;i<=(int)n;i++){
        for(int j=1;j<=100000;j++){
            if(j<=arrv[i])dp[i][j]=min(arrw[i],dp[i-1][j]);
            else dp[i][j]=min(arrw[i]+dp[i-1][j-arrv[i]],dp[i-1][j]);
        }
    }
    /*for(int i=1;i<=n;i++){
        for(int j=1;j<10;j++)cout<<dp[i][j]<<' ';
        cout<<'\n';
    }*/
    for(int j=100000;j>=0;j--){
        if(dp[n][j]<=w){
            cout<<j;
            return 0;
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L.at(i);
    sort(all(L));

    int a, b, c, flag=0, ans=0;
    map<int, vector<int>> cont;
    vector<int> new_vec;

    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                a = L.at(i);
                b = L.at(j);
                c = L.at(k);
                if(c < a+b && a != b && b != c && a != c){
                    ans++;
                    /*
                    new_vec = {a, b, c};        
                    flag=0;
                    rep(tmp, cont.size()){
                        if(cont.at(tmp)==new_vec){
                            flag=1;
                        }
                    }
                    if(flag==0){
                        cont[cont.size()] = new_vec;
                    }
                    */
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/env python3


def g(x):
    if x % 2 == 1:
        return 1 if x % 4 == 1 else 0
    if x % 4 == 2:
        return x | 1
    return x


def solve(a, b):
    if a == 0:
        return g(b)
    else:
        return g(b) ^ g(a - 1)


def main():
    a, b = input().split()
    a = int(a)
    b = int(b)

    print(solve(a, b))


if __name__ == '__main__':
    main()



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

using namespace std;
const int INF = (1 << 30);
const int N = 100000 + 5;
const double eps = 1e-8;
const int M = 100 + 5;
const int MOD = 1e9;

char str[N];
int main(){
    int x, t;
    scanf("%d %d", &x, &t);
    printf("%d\n", max(x - t, 0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll n, m;
  cin >> n >> m;

  ll ans;
  if (n == 1 && m == 1) {
    ans = 1;
  } else if (n == 1) {
    ans = m - 2;
  } else if (m == 1) {
    ans = n - 2;
  } else {
    ans = (n - 2) * (m - 2);
  }

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


Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if ((x>=r && x <= W-r) && (y>=r && y <= H-r)){
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<fstream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	int n;
	string str;
	cin >> n >> str;
	int len = str.size();
	for( int i=0; i<len; i++ ) {
		str[i] = 'A' + (str[i]-'A'+n)%26;
	}
	cout << str;

	return 0;
}

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

int main(){
int n,k;
cin >> n >> k;
vector<int>a(n);

int ans =0;
for(int i=0;i<n;i++){
    int typeA =0;
    int typeB =0;
    cin >> a.at(i);
    typeB =abs(k-a.at(i))*2;
    typeA =a.at(i)*2;
    ans+=min(typeB, typeA );
    
}
cout << ans << endl;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> city(n ,0);
	for (int i = 0; i < m*2; i++)
	{
		int j;
		cin >> j;
		city.at(j - 1)++;
	}

	for (int i = 0; i < n; i++)
	{
		cout << city.at(i) << endl;
	}

}


Measured memory_bytes: 3644
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int count=0;
  cin>>s;
  rep(i,4){
    if(s[i]=='+'){
      count++;
    }
    else{
      count--;
    }
  }
  cout<<count<<'\n';
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>P;
const ll mod = ll(1e9 + 7);
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 1000001;
#define endl '\n'
#define ever ;;
#define F first
#define S second
#define pii pair<int,int>
#define sz(v) ((int)((v).size()))
#define pll pair<ll,ll>
void stop() {
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("pizza.in", "r", stdin);
	freopen("pizza.out", "w", stdout);
#endif
}
struct point {
	double x, y;
};
ull gcd(ull a, ull b) { return !b ? a : gcd(b, a % b); }
ll fixMod(ll a, ll b) { return ((a%b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
ll dis(point a, point b) {
	ll x = a.x - b.x, y = a.y - b.y;
	return x * x + y * y;
}
ull LCM(ull a, ull b) {
	return a / gcd(a, b)*b;
}
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
int main() {
	fast
		int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] + a[1];
	stop();
	return 0;
}

Measured memory_bytes: 504
#include<stdio.h>
int main(void){
	char S[4];
	int ans = 0,i;
	scanf("%s", &S);
	for (i = 0; i < 4; i++){
		if (S[i] == '+')ans++;
		else ans--;
	}
	printf("%d", ans);
	return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

template<class T> bool contain(const std::string& s, const T& v) {
    return s.find(v) != std::string::npos;
}

// GAC, ACG, A?GC, AG?C が含まれていればダメ
bool check(string last4) {
    if (contain(last4,"AGC") || contain(last4,"GAC") || contain(last4,"ACG")) {
        return false;
    }
    if (last4.size() == 4 && last4[0] == 'A' && last4[2] == 'G' && last4[3] == 'C') {
        return false;
    }
    if (last4.size() == 4 && last4[0] == 'A' && last4[1] == 'G' && last4[3] == 'C') {
        return false;
    }
    return true;
}

map<string, ll> dp[101]; // dp[i][last4]: i文字まで見て最後の4文字がlast4だったときの組み合わせ数

signed main() {
    dp[0]["A"] = 1; 
    dp[0]["T"] = 1; 
    dp[0]["C"] = 1; 
    dp[0]["G"] = 1; 

    ll N;
    cin>>N;
    rep(i, 1, N) for (auto it = begin(dp[i-1]); it != end(dp[i-1]); it++) {
        string last4 = it->first;
        for(char c : vector<char>{'A','T','C','G'}) {
            string new_last4 = last4 + c;
            if (new_last4.size() == 5) {
                new_last4 = new_last4.substr(1);
            }
            // cout<<"i="<<i<<" "<<last4<<" "<<new_last4<<endl;
            if (check(new_last4)) {
                dp[i][new_last4] += dp[i-1][last4];
                dp[i][new_last4] %= 1000000007;
            }
        }
    }
    ll ans = 0;
    for (auto it = begin(dp[N-1]); it != end(dp[N-1]); it++) {
        ans += it->second;
        ans %= 1000000007;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2688
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

void solve();

int a, b;

int main() {
  cin >> a >> b;

  solve();

  return 0;
}

void solve() {
  int n = b-a;

  for(int i=1; i<=999; ++i) {
    int sum = 0;
    for(int j=1; j<=i; ++j) {
      sum += j;
    }
    if(i==(n-1)) {
      cout << sum-a << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = (int)2e5 + 3;
const int infint = (int)1e9 + 3;
const int MOD = (int)998244353;
const ll inf = (ll)1e18 + 3;
string s;
unordered_map<string, int > M;
int dp[MAXN][3][3][3];
char nt(char a, char b)
{
	if(a != 'a' && b != 'a')
		return 'a';
	if(a != 'b' && b != 'b')
		return 'b';
	return 'c';
}
void generate(string s)
{
	M[s] = 1;
	for (int i = 0; i < s.size() - 1; i++)
		if(s[i] != s[i + 1])
		{
			string t = s;
			t[i] = t[i + 1] = nt(s[i], s[i + 1]);
			if(M.count(t) == 0)
				generate(t);
		}
}
int add(int a, int b)
{
	int c = a + b;
	if(c >= MOD)
		c -= MOD;
	if(c < 0)
		c += MOD;
	return c;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> s;

	if(s.size() <= 3)
	{
		generate(s);
		cout << M.size() << "\n";
		return 0;
	}
	bool diff = 0;
	for (int i = 1; i < s.size(); i++)
		if(s[i] != s[i - 1])
			diff = 1;
	if(!diff)
		return cout << 1, 0;
	int md = 0;
	for (int i = 0; i < s.size(); i++)
		if(s[i] == 'a')
			md += 0;
		else
		if(s[i] == 'b')
			md++;
		else
			md += 2;
	md %= 3;

	dp[1][0][0][0] = dp[1][1][1][0] = dp[1][2][2][0] = 1;
	for (int i = 2; i <= s.size(); i++)
		for (int md = 0; md < 3; md++)
			for (int last = 0; last < 3; last++)
			{
				for (int prev = 0; prev < 3; prev++)
				{
					if(prev != last)
						dp[i][md][last][0] = add(dp[i][md][last][0], dp[i - 1][(md - last + 3) % 3][prev][0]), dp[i][md][last][1] = add(dp[i - 1][(md - last + 3) % 3][prev][1], dp[i][md][last][1]);
					else
						dp[i][md][last][1] = add(add(dp[i][md][last][1], dp[i - 1][(md - last + 3) % 3][prev][0]), dp[i - 1][(md - last + 3) % 3][prev][1]);
				}
				//cerr << "# " << i << " " << md << " " << last << "-> " << dp[i][md][last][0] << " " << dp[i][md][last][1] << endl;
			}
	int ans = 0;
	for (int i = 0; i < 3; i++)
	{
		ans = add(ans, dp[s.size()][md][i][1]);
	}
	bool c = 0;
	for (int i = 1; i < s.size(); i++)
		if(s[i] == s[i - 1])
			c = 1;
	if(!c)
		ans = add(ans, 1);
	cout << ans;
}






Measured memory_bytes: 21652
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  
  int cnt=0;
  
  for(int i=n;i>0;i--){
   	string s=to_string(i);
   	
    if(s.size()%2==1){
     	cnt++; 
    }
  }
  
  cout << cnt << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

#define pb push_back
#define ll long long

using namespace std;

string y("Yes\n");

bool isPal(string& s) {
    int n = s.size(), l=n/2;
    for(int i=0;i<l;i++) {
        if (s.at(i)!=s.at(n-i-1)) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    bool ans = isPal(s);
    int n = s.size(), l=n/2;
    for(int i=0;i<l;i++) {
        if(s.at(i)!=s.at(l+1+i)) {
            ans = false;
            break;
        }
    }
    if(ans) {
        cout << y;
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
peaple = [0]*N
count = 0
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for j in A:
        peaple[j-1] += 1
for i in peaple:
    if i == 0:
        count += 1
print(count)

Measured memory_bytes: 9208
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

import java.util.Arrays;

public class Main {
  static int n;
  static int[] a;

  public static void main(String[] args){
    FastScanner sc = new FastScanner();

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int[] pos = new int[n + 1];
    for(int i = 0; i < n; i++){
      pos[a[i]] = i;
    }

    // left most right
    int[] lmr = new int[n];
    for(int i = 0; i < n; i++){
      int j = i - 1;
      while(j != -1 && a[j] > a[i]){
        j = lmr[j];
      }
      lmr[i] = j;
    }

    // right most left
    int[] rml = new int[n];
    for(int i = n - 1; i >= 0; i--){
      int j = i + 1;
      while(j != n && a[i] < a[j]){
        j = rml[j];
      }
      rml[i] = j;
    }

    int[] left = new int[n + 1];
    left[1] = pos[1];
    for(int i = 2; i <= n; i++){
      if(lmr[pos[i]] < pos[i]){
        left[i] = pos[i] - lmr[pos[i]] - 1;
      }
      else{
        left[i] = pos[i];
      }
    }

    int[] right = new int[n + 1];
    int ml = pos[1];
    right[1] = n - pos[1];
    for(int i = 2; i <= n; i++){
      if(pos[i] < rml[pos[i]]){
        right[i] = rml[pos[i]] - pos[i];
      }
      else{
        right[i] = n - pos[i];
      }
    }

    long sum = 0;
    for(int i = 1; i <= n; i++){
      sum += (long)i * ((long)right[i] * left[i] + right[i]);
    }

    System.out.println(sum);
  }
}

class FastScanner {
  private static final InputStream in = System.in;
  private static final PrintWriter out = new PrintWriter(System.out);
  private final byte[] buffer = new byte[2048];
  private int p = 0;
  private int buflen = 0;

  public FastScanner(){
  }

  private boolean hasNextByte() {
    if(p < buflen){
      return true;
    }
    p = 0;
    try{
      buflen = in.read(buffer);
    }catch (IOException e) {
      e.printStackTrace();
    }
    if(buflen <= 0){
      return false;
    }
    return true;
  }

  public boolean hasNext() {
    while(hasNextByte() && !isPrint(buffer[p])){
      p++;
    }
    return hasNextByte();
  }

  private boolean isPrint(int ch) {
    if(ch >= '!' && ch <= '~'){
      return true;
    }
    return false;
  }

  private int nextByte() {
    if(!hasNextByte()){
      return -1;
    }
    return buffer[p++];
  }

  public String next() {
    if(!hasNext()){
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = -1;
    while(isPrint((b = nextByte()))){
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public long nextLong() {
    return Long.parseLong(next());
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}


Measured memory_bytes: 25928
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}
int main() {
    int N,L;
    cin >> N >> L;
    Int ans = 0;

    Int total;
    rep(i,N){
        total += L+i;
    }

    Int d_min = 999999;
    Int d_min_i = 999;
    rep(i,N){
        if(d_min > abs(total - (total-(L+i)))) {
            d_min = min(d_min, abs(total - (total-(L+i))));
            d_min_i = i;
        }
    }



    ans = total - (L+d_min_i);


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

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define MAX 100002
using namespace std;
int n;
int nums[4][MAX];
int memo[MAX][4];
//int dp[MAX][3];
int dfs(int index,int flag){
	if(memo[index][flag]!=-1) return memo[index][flag];
	if(index==n) return 0;
	
	int res=0;
	for(int i=1;i<=3;i++){
		if(i!=flag) {
			if(index+1<=n) res= max(res,dfs(index+1,i)+nums[i][index]);
		}
	}
	memo[index][flag]=res;
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&nums[1][i],&nums[2][i],&nums[3][i]);
	}
	memset(memo,-1,sizeof(memo));
	printf("%d",dfs(0,0));
	
//	for(int i=0;i<=2;i++){
//		dp[0][i]=0;
//	}
	//dp[i][j] Ç°iÌìÇÒµÚiÌìÑ¡ÔñµÄÊÇa,b,cµÃµ½µÄ¿ìÀÖ¶¶È 
//	for(int i=1;i<=n;i++){
//		dp[i][0]=dp[i-1][1] dp[i-1][2]
//		for(int j=0;j<=2;j++){
//			if(j==0)dp[i][j]= dp[i-1][]
//		}	
//	}
	
	return 0;
}

Measured memory_bytes: 14312
x = Array.new(3, 0)
y = Array.new(3, 0)
ary = 3.times.map { gets.split.map(&:to_i) }
3.times { |i| y[i] = ary[0][i] - x[0] }
3.times { |i| x[i] = ary[i][0] - y[0] }
flg = true

3.times do |i|
  3.times do |j|
    flg = false if x[i] + y[j] != ary[i][j]
  end
end

puts flg ? 'Yes' : 'No'

Measured memory_bytes: 14236
#include <stdio.h>

long long llabs(long long n)
{
    return (n < 0 ? -n : n);
}

int main()
{
    long long a,b,c,k;

    scanf("%lld %lld %lld %lld",&a,&b,&c,&k);

    if(llabs(a - b) >= 1000000000000000000)
    {
        printf("Unfair");
    }
    else
    {
        printf("%lld",k % 2 == 1 ? b - a : a - b);
    }
    
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int n;
  cin >> n;
  vector<int> np(n);
  for (int i = 0; i < n; ++i) np[i] = i + 1;
  vector<int> p(n), q(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  for (int i = 0; i < n; ++i) cin >> q[i];

  int cnt = 0;
  int cnt_p, cnt_q;
  do {
    ++cnt;
    // cout << cnt << " " << np[0] << " " << np[1] << " " << np[2] << endl;
    bool chk_p = true;
    for (int i = 0; i < n; ++i) {
      if (p[i] != np[i]) chk_p = false;
    }
    if (chk_p == true) cnt_p = cnt;

    bool chk_q = true;
    for (int i = 0; i < n; ++i) {
      if (q[i] != np[i]) chk_q = false;
    }
    if (chk_q == true) cnt_q = cnt;
  } while (next_permutation(np.begin(), np.end()));

  cout << abs(cnt_p - cnt_q) << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

signed main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int res = 0;
  for (int l = 0; l < n; ++l) {
    int r = l;
    while (r < n && a[r] == a[l]) {
      ++r;
    }
    res += (r - l) / 2;
    l = r - 1;
  }
  cout << res << '\n';
}


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

int main()
{
   int n,i,x=0,y=0;
   string s;
   cin>>n>>s;
   for(i=0;i<n;i++)
   {
       if(s[i]=='(')
       {
           x++;
       }
       else
       {
           if(x<=0)
           {
               y++;
               x=0;
           }
           else
           {
              x--;
           }
       }
   }
   for(i=0;i<y;i++)
   {
       cout<<"(";
   }
   cout<<s;
   for(i=0;i<x;i++)
   {
       cout<<")";
   }
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, K, h[100000];
  long long  ans[100000];

  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  ans[0] = 0;
  for (int i = 1; i < N; i++) {
    ans[i] = 1e9;
    for (int j = 1; j <= K && j <= i; j++) {
      ans[i] = min(ans[i], ans[i-j] + abs(h[i-j] - h[i]));
    }
  }

  cout << ans[N-1] << endl;
}


Measured memory_bytes: 1408
import Control.Monad
import Control.Applicative

parse :: IO ()
parse = do
    [a, b] <- replicateM 2 $ (read :: String -> Integer) <$> getLine
    let s = show $ a + b
    if (length s) > 80
    then putStrLn "overflow"
    else putStrLn s

main :: IO ()
main = do
    n <- read <$> getLine
    replicateM_ n parse

Measured memory_bytes: 4284
S = str(input())
X =[]

for n in range(len(S)-2):
    dif = int(S[n])*100 + int(S[n+1])*10 + int(S[n+2])
    X.append(dif)

Y = [abs(x - 753) for x in X]
print(int(min(Y)))

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

int h, n;
vector< pair<int, int> > spells;

const int H = 1e4 + 10;
const int inf = 1e8;

int dp[H];

int solve(int x) {
	if(x <= 0) return 0;

	int &ans = dp[x];
	if(~ans) return ans;
	ans = inf;

	for(pair<int, int> &p : spells) {
		ans = min(ans, p.second + solve(x - p.first));
	}

	return ans;
}


int main() {
	ios::sync_with_stdio(false);
	memset(dp, -1, sizeof dp);
    cin >> h >> n;
	spells = vector< pair<int,int> >(n);

	for(int i = 0; i < n; ++i) cin >> spells[i].first >> spells[i].second;

	cout << solve(h) << '\n';

	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[200005];
ll B[200005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.first < b.first; });
    REP(i, N)
    {
        cin >> B[i];
        q.push(pll(B[i], i));
    }

    ll ans = 0;
    while (!q.empty())
    {
        pll t = q.top();
        q.pop();
        if (t.first <= A[t.second])
            continue;
        ll s = B[(N + t.second - 1) % N] + B[(t.second + 1) % N];
        ll m = std::max(B[(N + t.second - 1) % N], B[(t.second + 1) % N]);
        ll sec = std::max(m, A[t.second]);
        ll k = (t.first - sec + s - 1) / s;
        t.first = B[t.second] = t.first - k * s;
        ans += k;
        if (t.first < A[t.second])
            break;
        q.push(t);
    }

    bool exist = true;
    REP(i, N)
    {
        if (A[i] != B[i])
            exist = false;
    }

    if (exist)
        cout << ans << endl;
    else
        cout << -1 << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
#define MOD 1000000007

const int N = 2e5+5;
int n;
int c[N];
int prv[N], last[N];
int res[N];

int dp(int i) {
    if (i < 0) return 1;
    if (~res[i]) return res[i];
    res[i] = dp(i-1);
    if (prv[i] != -1 && prv[i]+1 < i) res[i] = (res[i] + dp(prv[i]))%MOD;
    //cout << i << " " << res[i] << " " << (prv[i] != -1 && prv[i]+1 < i) << " " << dp(i-1) << " " << dp(prv[i]-1) << endl;
    return res[i];
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    FOR(i, 0, n-1) cin >> c[i];

    memset(last, -1, sizeof last);
    FOR(i, 0, n-1) {
        prv[i] = last[c[i]];
        last[c[i]] = i;
    }
    memset(res, -1, sizeof res);
    cout << dp(n-1) << '\n';
}



Measured memory_bytes: 9600
import sys
from itertools import product
def input(): return sys.stdin.readline().strip()

def main():
    """
    itertools.productを使うと高速なようなので写経
    参考：https://atcoder.jp/contests/abc042/submissions/16188969
    """
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    l = len(str(N))
    if int(str(ok[-1]) * l) < N:
        if ok[0] == 0:
            print(ok[1] * 10 ** l)
        else:
            print(str(ok[0]) * (l + 1))
    else:
        for x in product(ok, repeat=l):
            x = int("".join(map(str, x)))
            if x >= N:
                print(x)
                return



if __name__ == "__main__":
    main()


Measured memory_bytes: 73252
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int a;
string s;

int main(){
	cin >> a >> s;
	
	if(a >= 3200) cout << s << endl;
	else cout << "red" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5 + 1)

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

M = 10**9 + 7
def mod(v):
    if v >= M:
        return v % M
    return v

def dfs(node=0, prev=-1):
    cnt = [1, 1]
    for c in graph[node]:
        if c == prev:
            continue
        w, b = dfs(c, node)
        cnt[0] = mod(cnt[0] * (w + b))
        cnt[1] = mod(cnt[1] * w)
    # print(node + 1, cnt)
    return cnt

print(mod(sum(dfs())))


Measured memory_bytes: 124848
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr double BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, A, B;
    cin >> N >> A >> B;
    cout << min(A * N, B);
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
int main () {
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  rp(i,N){
    
    cin >> vec.at(i);
  }
  int sum=0;
  rp(i,N){
    sum+=vec.at(i);
  }
  int X=sum/(4*M);
  if(sum%(4*M)==0)
    X=X-1;
  int count=0;
  rp(i,N){
    if(vec.at(i)>=X+1)
      count++;
  }
  if(count<M)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

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

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  bool capture[100001][31]={};
  int n,c;
  cin>>n>>c;
  for(int i=0;i<n;i++){
    int s,t,ch;
    cin>>s>>t>>ch;
    for(int j=s;j<=t;j++){
      capture[j][ch]=true;
    }
  }
  int result=0;
  for(int t=0;t<=100000;t++){
    int tmp=0;
    for(int ch=1;ch<=c;ch++){
      if(capture[t][ch]){
        tmp++;
      }
    }
    result=std::max(result,tmp);
  }
  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	n %= 1000;
	if (n == 0) {
		cout << n << endl;
	}
	else cout << 1000 - n << endl;
	return 0;
}

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

void selectionSort(int A[],int N);
void printList(int A[],int N);

int main()
{
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++) cin >> A[i];
  selectionSort(A,N);
  return 0;
}

void selectionSort(int A[],int N)
{
  int count = 0;
  for(int i=0;i<N;i++) {
    int minj = i;
    for(int j=i;j<N;j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if(i != minj) {
      swap(A[i],A[minj]);
      count++;
    }
  }
  printList(A,N);
  cout << count << endl;
}


void printList(int A[],int N)
{
  for(int i=0;i<N-1;i++) cout << A[i] << " ";
  cout << A[N-1] << endl;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define pb(x)                    push_back(x)
#define all(a)                   a.begin(), a.end()
#define dbg(a)                   cout<< #a <<" --> "<<(a)<<endl;
#define IO                       ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define read                     freopen("tst.txt","r",stdin)
#define write                    freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;
#define mx 1005
#define MX 1e12
vector<ll> v[mx];
ll cost[mx],n;

ll t;
ll dp[1001][5000];

ll fn(ll pos,ll mask){
    if(mask==(1ll<<n)-1)  return 0;
    if(pos==t)  return MX;
    ll &ans = dp[pos][mask];
    if(ans!=-1) return ans;
    ans = MX;
    ll p = mask;
    for(ll i:v[pos]){
       p|=(1ll<<i);
    }
    ans = min(ans,cost[pos] + fn(pos+1,p));
    ans = min(ans,fn(pos+1,mask));
    return ans;
}


main(){
//read;
IO;
cin>>n>>t;
memset(dp,-1,sizeof dp);

for(ll i = 0; i<t; i++){
    cin>>cost[i];
    ll p;cin>>p;
    for(ll j = 0; j<p; j++){
        ll x;  cin>>x;
        --x;
        v[i].push_back(x);
    }
}
ll ans = fn(0,0);
if(ans==MX) ans = -1;
cout<<ans;

return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, M;
	cin >> N >> M;
	ll tot = 1900*M + 100*(N-M);
	ll bai = 1;
	REP(i, M) bai *= 2;
	cout << tot * bai << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)


int main(){
    int n = 0;
    string s;
    cin >> s;
    rep(i,4){
        if(s[i] == '+') n++;
        else n--;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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() {   
    string s; cin >> s;
    int len = s.size();
    string s1 = s.substr(0, (len-1)/2);
    string s2 = s.substr((len+3)/2-1);
    string rs1 = s1; reverse(all(rs1));
    string rs2 = s2; reverse(all(rs2));
    string rs = s; reverse(all(rs));
    if(s1==rs1 && s2==rs2 && s == rs) cout << "Yes" << ln;
    else cout << "No" << ln;
}

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


#define For(k,i) for(int i=0;i<k;i++)

using namespace std;
using ll = long long;

int main() {
    int ans = 0;
    int h,w,n;
    cin >> h >> w >> n;
    int ma = max(h,w);
    int mi = min(h,w); 
    For(ma+3,i){
        if(i * ma >= n) {
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#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()
#define INF 1000000007
#define mod 1005
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;
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(){
    int k = nxt(), n = nxt();
    VI num(n);
    generate(all(num), nxt);
    int cost = INF;
    sort(all(num));
    REP(i, n-1){
        cost = min(cost, k-(num[i+1]-num[i]));
    }
    cost = min(cost, k-(num[0]+(k-num[n-1])));
    printf("%d ", cost);
    
    return 0;
}



Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		FenwickTree ft = new FenwickTree(a);

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int t = Integer.parseInt(sa[0]);
			if (t == 0) {
				int p = Integer.parseInt(sa[1]);
				int x = Integer.parseInt(sa[2]);
				ft.add(p, x);
			} else {
				int l = Integer.parseInt(sa[1]);
				int r = Integer.parseInt(sa[2]);
				sb.append(ft.sum(l, r)).append("\n");
			}
		}
		br.close();
		System.out.print(sb.toString());
	}
}

/**
 * Fenwick Tree（Binary Indexed Tree）
 */
class FenwickTree {
	private int n;
	private long[] data;

	/**
	 * 長さnの配列（a[0]～a[n-1]）を作る。初期値は全て0。<br>
	 * O(n)
	 * 
	 * @param n 配列の長さ
	 */
	public FenwickTree(int n) {
		this.n = n;
		data = new long[n];
	}

	/**
	 * 初期データを元にFenwick Treeを構成する。<br>
	 * O(n)
	 * 
	 * @param data 初期データ
	 */
	public FenwickTree(long[] data) {
		this(data.length);
		build(data);
	}

	/**
	 * a[p] += x を行う。<br>
	 * O(log n)
	 * 
	 * @param p 加算位置（0≦p＜n）
	 * @param x 加算値
	 */
	void add(int p, long x) {
		assert 0 <= p && p < n : "p=" + p;

		p++;
		while (p <= n) {
			data[p - 1] += x;
			p += p & -p;
		}
	}

	/**
	 * a[l] + ... + a[r-1] を返す。<br>
	 * O(log n)
	 * 
	 * @param l 開始位置（含む）    （0≦l≦r≦n）
	 * @param r 終了位置（含まない）（0≦l≦r≦n）
	 */
	long sum(int l, int r) {
		assert 0 <= l && l <= r && r <= n : "l=" + l + ", r=" + r;

		return sum(r) - sum(l);
	}

	/**
	 * a[0] + ... + a[r-1] を返す。<br>
	 * O(log n)
	 * 
	 * @param r 終了位置（含まない）（0≦r≦n）
	 */
	long sum(int r) {
		assert 0 <= r && r <= n : "r=" + r;

		long s = 0;
		while (r > 0) {
			s += data[r - 1];
			r -= r & -r;
		}
		return s;
	}

	private void build(long[] dat) {
		System.arraycopy(dat, 0, data, 0, n);
		for (int i = 1; i <= n; i++) {
			int p = i + (i & -i);
			if (p <= n) {
				data[p - 1] += data[i - 1];
			}
		}
	}
}


Measured memory_bytes: 99216
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n, s = LI()
A = LI()
dp = [[0] * (s + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(1, s + 1):
        if j == A[i]:
            dp[i + 1][j] += i + 1
        elif j > A[i]:
            dp[i + 1][j] += dp[i][j - A[i]]
        if j == s:
            dp[i + 1][j] = dp[i + 1][j] * (n - i) % mod
        dp[i + 1][j] += dp[i][j]
        dp[i + 1][j] %= mod


print(dp[n][s])


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    int a,b,c,k; cin>>a>>b>>c>>k;
	while(a>=b){
		if(k==0){cout<<"No"<<"\n"; return 0;}
		b*=2; k--;
	}
	while(b>=c){
		if(k==0){cout<<"No"<<"\n"; return 0;}
		c*=2; k--;
	}
	cout<<"Yes"<<"\n";
    return 0;	
}  

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back

#define rep(var,start,end)       for(int var=start;var<end;var++)
#define erep(var,start,end)      for(int var=start;var<=end;var++)
#define rrep(var,start,end)      for(int var=start;var>=end;var--)

#define pa(x)                    cout<<x<<endl

#define pii                      pair<int,int>
#define pci                      pair<char,int>
#define pll                      pair<ll,ll>
#define test                     int t;cin>>t;while(t--)

ll modularExponentiation(ll x,ll n,ll M){
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modularExponentiation((x*x)%M,n/2,M);
    return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
}
template<class T> 
T power(T n, T p){ if(p==0) return 1; else return power(n,p-1)*n;} 

void solve(){
    int n,m;
    cin>>n>>m;
    int a[n],sum=0;
    rep(i,0,n) {
        cin>>a[i];
        sum+=a[i];
    }
    double threshold= sum/(4.00*m);
    threshold=ceil(threshold);
  	int x=0;
    rep(i,0,n){
        if(a[i]>=threshold) x++;
    }
    if(x>=m) cout<<"Yes";
    else cout<<"No";
}

int main()
{
    bs;
    solve();
    
}


Measured memory_bytes: 256
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ show $ solve a b 0

solve :: Int -> Int -> Int -> Int
solve _ _ 2 = 0
solve x y z = if x > y then x + solve (x - 1) y (z + 1) else y + solve x (y - 1) (z + 1)

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  if(A <= 3){
    ans += (4 - A)*100000;
  }
  if(B <= 3){
    ans += (4 - B)*100000;
  }
  if(A == 1 && B == 1){
    ans += 400000;
  }
  cout << ans << endl;
} 

Measured memory_bytes: 256
// author : ayush_nishad
// Road to Expert since : 30 Aug 2020
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
/*
think fast
think simple
*/
void mysol()
{
	int arr[4];
	for (int &a : arr)
		cin >> a;
	int ans = -1e18;
	for (int i = 0; i < 2; i++)
		for (int j = 2; j < 4; j++)
			ans = max(ans, arr[i] * arr[j]);
	cout << ans;
}

int32_t main()
{
	fast();
	// w(t)
	{
		mysol();
	}
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Measured memory_bytes: 3648
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        int time = 0;

        foreach (var a in Enumerable.Repeat(0, 5).Select(_ => int.Parse(Console.ReadLine())).OrderByDescending(x => (x + 9) % 10))
        {
            time = (time / 10 + (time % 10 == 0 ? 0 : 1)) * 10;
            time += a;
        }
        Console.WriteLine(time);

    }
}


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

int main()
{
  int n;
  bool bf=false;
  for(;cin>>n;)
    {
      if(bf)
	cout<<endl;
      bf=true;
      int point[4][13];
      for(int i=0;i<4;i++)
	for(int j=0;j<13;j++)
	  cin>>point[i][j];
      /*
      for(int i=0;i<4;i++,cout<<endl)
	for(int j=0;j<13;j++)
	  cout<<point[i][j];
      */
      int power[9];
      for(int j=0;j<9;j++)
	cin>>power[j];      
      
      //s=0,c=1,h=2,d=3
      for(;n--;)
	{
	  int card[5];
	  int ans=0;
	  bool mark=true;
	  //  cout<<mark<<endl;
	  char buf;
	  for(int i=0;i<5;i++)
	    {
	      char a,b;
	      int aa,bb;
	      cin>>a>>b;

	      if(i!=0&&buf!=b)
		mark=false;
	      buf=b;

	      aa=a-'0';
	      if(a=='A')
		aa=1;
	      if(a=='T')
		aa=10;
	      if(a=='J')
		aa=11;
	      if(a=='Q')
		aa=12;
	      if(a=='K')
		aa=13;	      
	      //s=0,c=1,h=2,d=3
	      if(b=='S')
		bb=0;
	      if(b=='C')
		bb=1;
	      if(b=='H')
		bb=2;
	      if(b=='D')
		bb=3;	      
	      card[i]=aa;
	      //   cout<<a<<b<<endl;
	      // cout<<bb<<" "<<aa<<endl;
	      //cout<<point[bb][aa-1]<<endl;;
	      ans+=point[bb][aa-1];
	      
	    }
	  sort(card,card+5);
	  //  cout<<mark<<endl;
	  if(mark&&
	     card[0]==1&&card[1]==10&&card[2]==11 &&card[3]==12 &&card[4]==13)
	    //royal straight
	    ans*=power[8];
	  else if(mark &&
		  card[0]==card[1]-1&&card[1]==card[2]-1&&
		  card[2]==card[3]-1&&card[3]==card[4]-1)
	    ans*=power[7];
	  else if((card[0]==card[1]&&card[1]==card[2]&&
		   card[2]==card[3])
		  ||(card[1]==card[2]&&card[2]==card[3]&&
		     card[3]==card[4]))
	    ans*=power[6];
	  else if((card[0]==card[1]&&card[1]==card[2]&&
		   card[3]==card[4])
		  ||(card[0]==card[1]
		     &&card[2]==card[3]&&card[3]==card[4]))
	    ans*=power[5];
	  else if(mark)
	    ans*=power[4];
	  else if((card[0]==1&&card[1]==10&&card[2]==11 &&card[3]==12 &&card[4]==13)||
		  (card[0]==card[1]-1&&card[1]==card[2]-1&&
		   card[2]==card[3]-1&&card[3]==card[4]-1))	    
	    //straight
	    ans*=power[3];
	  else if((card[0]==card[1]&&card[1]==card[2])||
		  (card[1]==card[2]&&card[2]==card[3])||
		  (card[2]==card[3]&&card[3]==card[4])
		  )
	    //スリーカード
	    ans*=power[2];
	  else
	    {
	      int cnt=0;
	      for(int i=0;i<4;i++)
		{
		  //		  cout<<card[i]<<" "<<card[i+1]<<endl;
		  if(card[i]==card[i+1])
		    cnt++;
		  
		}
		  if(cnt>1)
		ans*=power[1];
	      else if(cnt>0)
		ans*=power[0];
	      else
		ans=0;

		  //  cout<<cnt<<endl;
	    }
	  
	  cout<<ans<<endl;	  
	}


    }

}

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

int main(){
  unsigned int h,m,s,h2,m2,s2,sum;
  while(cin>>h>>m>>s>>h2>>m2>>s2){
    sum = h2*3600 + m2*60 + s2;
    sum -= h*3600 + m*60 + s;
    cout << sum/3600 << " " << (sum%3600)/60 << " " <<(sum%3600)%60 << endl; 
  }
}



Measured memory_bytes: 3120
def multiple(n):
    a = []
    for i in range(1,int(n**.5)+1):
        a.append(i*i)
    return a
n = int(input())
a = multiple(n)
ans = 10**18
for i in a:
    if n-i < 0:
        continue
    ans = min(ans,abs(n-i))
print(n-ans)

Measured memory_bytes: 66852