akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n[4];
	for (int i = 0; i < 4; i++)
		cin >> n[i];
	sort(n, n + 4);
	if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
		cout << "YES" << endl;
		return 0;
	}
	else {
		cout << "NO" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
n=gets.chomp.to_i
A=[]
B=[]
n.times do 
    a,b=gets.chomp.split(' ').map(&:to_i)
    A.push(a)
    B.push(b)
end
A.reverse!
B.reverse!
cnt=0
n.times do |i|
    A[i]+=cnt
    cnt+=B[i]-A[i]%B[i] unless A[i]%B[i]==0
end
puts cnt

Measured memory_bytes: 5508
#include<bits/stdc++.h>
using namespace std;
int n,k,a[200005];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int p1=1,p2=k+1;
	for(int i=k+1;i<=n;i++)
	{
		if(a[p1]<a[p2])
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
		p1++;
		p2++;
	}
	return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>

using ll = long long;

int main() {
    std::string S, T;
    std::cin >> S >> T;

    const int size = S.length();
    for (int i = 0; i < size; i++) {
        if (S == T) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
        char c = S[size - 1];
        S = c + S.substr(0, size - 1);
    }
    std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._


  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val weights = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(n){_ ⇒ Nil: List[Int]}
  val dimensions = Array.tabulate(n){_ ⇒ 0}
  for (_ ← 0 until m){
    val Array(u, v) = readLine.trim.split(' ').map(_.toInt)
    edges(u - 1) ::= v - 1
    dimensions(u - 1) += 1
    edges(v - 1) ::= u - 1
    dimensions(v - 1) += 1
  }
  val singlePathMemo = Array.tabulate(n){_ ⇒ 0}
  dimensions.indices.tail.filter(i ⇒ dimensions(i) == 1).foreach(i ⇒ singlePathCost(i))
  println(singlePathMemo.max + dimensions.indices.filter(i ⇒ i == 0 || dimensions(i) != 1).map(i ⇒ weights(i)).sum)
  @tailrec
  def singlePathCost(current: Int, prev: Int = -1, result: Int = 0): Unit = {
      if (dimensions(current) != 1 || current == 0) {
        singlePathMemo(current) = math.max(singlePathMemo(current), result)
      }
      else {
        edges(current).filter(i ⇒ i == 0 || dimensions(i) != 1) match {
          case next::Nil ⇒
            dimensions(next) -= 1
            singlePathCost(next, current, math.max(singlePathMemo(current), result) + weights(current))
          case _ ⇒ ???
        }
      }
  }


  case class Cost(any: Int, one: Int)
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
    @inline
    def takeIf(@inline predicate: T ⇒ Boolean): Option[T] = Some(value).filter(predicate)
  }
}


Measured memory_bytes: 185960
import sys
sys.setrecursionlimit(pow(10, 7))

n, m = map(int, input().split())
G = [[] for _ in range(n)]
color = [-1]*n

for i in range(m):
	a, b = map(int, input().split())
	G[a-1].append(b-1)
	G[b-1].append(a-1)

def dfs(v, c):
	color[v] = c
	ans = True
	for u in G[v]:
		if color[u] == c:
			return False
		if color[u] != -1:
			continue
		ans &= dfs(u, 1-c)
	return ans

if dfs(v=0, c=0):
	k = sum(color)
	print(k*(n-k) - m)
else:
	print(n*(n-1)//2 - m)

Measured memory_bytes: 40328
from collections import deque

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

k = 0
d = dict()
cs = [0] * N
used = [False] * N

que = deque([])
used[0] = 1
que.appendleft(0)
while len(que) > 0:
    v = que.pop()
    k = max(k, len(g[v]))
    cur = 1
    for u in g[v]:
        if used[u]:
            continue
        if cur == cs[v]:
            cur += 1
        cs[u] = d[(u, v)] = d[(v, u)] = cur
        cur += 1
        used[u] = True
        que.appendleft(u)
print(k)
for p in vp:
    print(d[p])


Measured memory_bytes: 60036
#include <iostream>
using namespace std;
const int MAX = 4001;
void chmin(int& x, int y) {if (x>y) x=y;}

int main() {
  int n; cin>>n;
  int m1,m2; cin>>m1>>m2;
  int a[n], b[n], c[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
  int mn[401][401];
  fill(mn[0],mn[401],MAX);
  mn[0][0]=0;
  for(int i=0;i<n;i++) {
    for(int j=399;j>=0;j--) {
      for(int k=399;k>=0;k--) {
        if (j + a[i] <= 400 && k + b[i] <= 400) {
          chmin(mn[j+a[i]][k+b[i]],mn[j][k]+c[i]);
        }
      }
    }
  }
  int an = MAX;
  for(int i=m1, j=m2; i <= 400 && j <= 400; i+=m1, j+=m2) {
    chmin(an,mn[i][j]);
  }
  if (an == MAX) cout<<-1<<endl;
  else cout<<an<<endl;
}

Measured memory_bytes: 4228
n = int(input())
h = [int(x) for x in input().split(" ")]
lis = []
ans = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        ans += 1
    else:
        lis.append(ans)
        ans = 0
lis.append(ans)
print(max(lis))

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

int sort (const void * a, const void * b){
    if( *(long long int*)a - *(long long int*)b < 0 )
        return -1;
    if( *(long long int*)a - *(long long int*)b > 0 )
        return 1;
    return 0;
}

int main(void){
    long long n,k;
    scanf("%lld%lld",&n,&k);
    long long a[n],b[n],count[100005],anscount=0;
    for (int i=0; i<100005; i++){
        count[i]=0;
    }
    for (long long i=0; i<n; i++){
        scanf("%lld%lld",&a[i],&b[i]);
        count[a[i]]+=b[i];
    }
    qsort (a,n,sizeof(long long),sort);
    
    for (long long i=0; i<n; i++){
        if (i==0 || a[i]!=a[i-1]){
            anscount+=count[a[i]];
        }
        if (anscount>=k){
            printf ("%lld\n",a[i]);
            break;
        }
    }
	return 0 ;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	int p=0;
	for (int i = 1; i <= N; i++) {
		int a; cin >> a;
		if (p + 1 == a)
			p++;
	}
	if (p)	cout << N -p << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 3620
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
 */
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        while (sc.hasNext()){
            double x=sc.nextDouble();
            double y=sc.nextDouble();
            double x0=sc.nextDouble();
            double y0=sc.nextDouble();
            out.println(sqrt(pow(x-x0,2)+pow(y-y0,2)));
        }
    }
}


Measured memory_bytes: 27968
using System;
class Program {
	static void Main(string[] args) 
    {
        int N = int.Parse(Console.ReadLine());
        string[] TA = Console.ReadLine().Split(' ');
        int T = int.Parse(TA[0]);
        int A = int.Parse(TA[1]);
        string[] strH = Console.ReadLine().Split(' ');
        int[] H = new int[N];
        double[] aveT = new double[N];
        int ans = 0;
        double diff = 100000.0;

        for(int i = 0; i < N; i++)
        {
            H[i] = int.Parse(strH[i]);
            aveT[i] = T - H[i] * 0.006;
            if(diff > Math.Abs(A - aveT[i]))
            {
                diff = Math.Abs(A - aveT[i]);
                ans = i + 1;
            }
        }

        Console.WriteLine(ans);
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
const int MAX = 100;
int n;
int M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  for(int i=0;i<n;i++){
    d[i] = INF;
    p[i] = -1;
    color[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INF;
    u = -1;
    for(int i=0;i<n;i++){
      if(minv > d[i] && color[i] != 2){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = 2;

    for(int v=0;v<n;v++){
      if(color[v] != 2 && M[u][v] != INF){
        if(d[v] > M[u][v]){
          d[v] = M[u][v];
          p[v] = u;
          color[v] = 1;
        }
      }
    }

  }
  int sum = 0;
  for(int i=0;i<n;i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}
//-----------------------------------------

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

  cin >> n;

  REP(i,n){
    REP(j,n){
      int e; cin >> e;
      if(e == -1) M[i][j] = INF;
      else M[i][j] = e;
    }
  }

  cout << prim() <<endl;









  return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
//order_of_key(k)= # of items strictly smaller than 'k'  //find_by_order(x)= iterator to x'th largest element (counting from ZERO) //erase("iterator") [log(n)] //end(<name>)
//os.find_by_order(os.order_of_key(x)=iterator to 'x' in the rb tree
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target ("avx2")
//#pragma GCC optimize ("O3")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef priority_queue<ll> pq;                                        //min-heap-> multiply the values by '-1'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for (ll i = a; i < b; i++)
#define test ll t;cin>>t;while(t--)
#define summ(a,n) accumulate(a,a+n,0)
#define bsrch(v,n) lower_bound(v.begin(), v.end(), n)
#define minindex(v) distance(v.begin(),min_element(v.begin(),v.end()))         //returns index of minimum(/max) element in the vector
#define bp(x) _builtin_popcount(x)
#define inf 1000000000000
#define PI = 3.1415926535897932384626
#define mod 1000000007

double dp[3000][3000];

int main()
{
    ll n; cin>>n;
    double p[n+1];
    forr(i,1,n+1) cin>>p[i];
    
    dp[0][0]=1;
    forr(i,1,n+1)
        forr(j,0,i+1)
        {
            dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
        }
    double ans=0.0;
    forr(i,ceil(n/2.0),n+1) ans+=dp[n][i];
    cout<<setprecision(10)<<ans;
}

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

int main(){
    using namespace std;
    unsigned long Q;
    cin >> Q;
    constexpr auto M{205891132094649UL};
    const auto& calc = [](auto a, auto b, auto c, auto d){
        auto u{b}, l{b}, p{M};
        while(p /= 3)if((a / p + (4 - a / p % 3) % 3) * p <= c){
            if(u / p % 3 == 1)u = u / (3 * p) * 3 * p + 2 * p;
            if(l / p % 3 == 1)l = l / (3 * p) * 3 * p + p - 1;
        }
        return c - a + min(u - b + max(u, d) - min(u, d), b + d - 2 * l);
    };
    for(unsigned long _{0}, a, b, c, d; _ < Q; ++_){
        cin >> a >> b >> c >> d;
        if(--a > --c)swap(a, c), swap(b, d);
        if(--b > --d){
            b = M - b - 1;
            d = M - d - 1;
        }
        cout << max(calc(a, b, c, d), calc(b, a, d, c)) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
from collections import defaultdict
N,*A = map(int, open(0).read().split())
dic1 = defaultdict(lambda :-10**20)
dic2 = defaultdict(lambda :-10**20)
for i in range(-1,N):
  dic1[(i,0)] = 0
  dic2[(i,0)] = 0
for i in range(N):
  for j in range(max(1,N//2-(N-i+1)//2), i//2+2):
    dic1[(i,j)] = max(dic1[(i,j)],dic2[(i-1,j-1)]+A[i])
  for j in range(N//2-(N-i)//2,(i-1)//2+2):
    dic2[(i,j)] = max(dic2[(i-1,j)],dic1[(i-1,j)])
print(max(dic1[(N-1,N//2)],dic2[(N-1,N//2)]))

Measured memory_bytes: 295568
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    int num = a[0];
    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        if (num <= a[i]) {
            num = a[i];
        }
        else {
            ans += num - a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

// dp[i][a][b][c] : i番目まで見て、直近3文字がa, b, c
// 文字を示す添字は 0123 が TAGC に対応
int64_t dp[101][4][4][4];

// a, b, cが "AGC" だったらtrue
bool ng(int a, int b, int c){
    return (a==1 && b==2 && c==3);
}

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

    // 初期状態の直近3文字はTTTであると見なして良い
    dp[0][0][0][0] = 1;

    for(int i=0; i<N; i++) for(int a=0; a<4; a++) for(int b=0; b<4; b++) for(int c=0; c<4; c++) for(int d=0; d<4; d++){

        // 3文字NGパターン AGC, GAC, ACG
        if(ng(b, c, d) || ng(c, b, d) || ng(b, d, c)) continue;
        // 4文字NGパターン AXGC, AGXC
        if(ng(a, c, d) || ng(a, b, d)) continue;

        // NGパターンがなければ遷移先に足す
        add(dp[i+1][b][c][d], dp[i][a][b][c]);
    }

    int64_t ans = 0;
    for(int a=0; a<4; a++) for(int b=0; b<4; b++) for(int c=0; c<4; c++) add(ans, dp[N][a][b][c]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    s = input().strip()
    n = len(s)-1
    ans = 0
    for i in range(1<<n):
        t = s[0]
        for j in range(n):
            if ((i >> j) & 1) == 1:
                t += "+"
            t += s[j+1]
        ans += eval(t)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stdio.h>
#include <queue>
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define inf 1001001001000
using namespace std;
int main(void){
    string s;
    cin>>s;
    ll zero = 0;
    ll one = 0;
    ll ans = 0;
    for(char c:s){
        if(c == '0'){
            if(one>0){
                one--;
                ans += 2;
            }else{
                zero++;
            }
        }else{
            if(zero>0){
                zero--;
                ans += 2;
            }else{
                one++;
            }
        }
    }
    cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int sum=0;
    vector<int> a(n);
    for (int i=0;i<n;++i) cin >> a[i];
  
	for (int i=0;i<n;i++){
		while (a[i] % 2 == 0){
          a[i] /= 2; 
          sum++;
        }
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
from copy import copy
import random
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
for k in range(1,30001):
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    z = random.randint(min(x,y),max(x,y))
    if x == y:
        continue
    na[x-1],na[y-1] = na[y-1],na[x-1]
    na[x-1],na[z-1] = na[z-1],na[z-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    if k%100 == 1:
        T = 300-(298*k/40000)
    p = pow(math.e,-abs(ns-score)/T)
    if ns > score or random.random() < p:
        ans = na
        score = ns
for a in ans:
    print(a)

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

using namespace std;

typedef long long ll;

char C3[4][4] = {"aa.", "..a", "..a"};
char C4[5][5] = {"aaca", "bbca", "acbb", "acaa"};
char C5[6][6] = {"abbaa", "acc.b", "b..cb", "b..ca", "aabba"};
char C7[8][8] = {"caa.aa.", "c..a..a", "b..a..a", "baa.aa.", "a..a..a", "a..a..a", ".aabbcc"};
char B[1010][1010];
int n;

int main()
{
	int i, j, k;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i ++){
		for(j = 0; j < n; j ++){
			B[i][j] = '.';
		}
		B[i][j] = '\0';
	}
	
	if(n < 3){
		printf("-1\n");
		return 0;
	}
	else if(n == 3){
		for(i = 0; i < 3; i ++){
			for(j = 0; j < 3; j ++){
				B[i][j] = C3[i][j];
			}
		}
	}
	else if(n == 6){
		for(i = 0; i < 3; i ++){
			for(j = 0; j < 3; j ++){
				B[i][j] = C3[i][j];
			}
		}
		for(i = 0; i < 3; i ++){
			for(j = 0; j < 3; j ++){
				B[i + 3][j + 3] = C3[i][j];
			}
		}
	}
	else if(n == 7){
		for(i = 0; i < 7; i ++){
			for(j = 0; j < 7; j ++){
				B[i][j] = C7[i][j];
			}
		}
	}
	else if(n == 11){
		for(i = 0; i < 4; i ++){
			for(j = 0; j < 4; j ++){
				B[i][j] = C4[i][j];
			}
		}
		for(i = 0; i < 7; i ++){
			for(j = 0; j < 7; j ++){
				B[i + 4][j + 4] = C7[i][j];
			}
		}
	}
	else{
		for(i = 0; (n - i) % 4; i += 5){
			for(j = 0; j < 5; j ++){
				for(k = 0; k < 5; k ++){
					B[i + j][i + k] = C5[j][k];
				}
			}
		}
		for(; i < n; i += 4){
			for(j = 0; j < 4; j ++){
				for(k = 0; k < 4; k ++){
					B[i + j][i + k] = C4[j][k];
				}
			}
		}
	}
	
	for(i = 0; i < n; i ++){
		printf("%s\n", B[i]);
	}
	
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
// #define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int N, M;
  cin >> N >> M;
  int sum = 0;
  for (int i = 0; i < M; i++) {
    int p; cin >> p;
    sum += p;
  }
  if (N-sum>=0) {
    cout << N-sum << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3568
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        Map<Character, Integer> sAlphaCnt = new HashMap<>();
        Map<Character, Integer> tAlphaCnt = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char cs = s.charAt(i);
            char ct = t.charAt(i);
            sAlphaCnt.put(cs, sAlphaCnt.getOrDefault(cs, 0) + 1);
            tAlphaCnt.put(ct, tAlphaCnt.getOrDefault(ct, 0) + 1);
        }
        Map<Integer, Integer> sPatternCnt = new HashMap<>();
        Map<Integer, Integer> tPatternCnt = new HashMap<>();
        for (Map.Entry<Character, Integer> e : sAlphaCnt.entrySet()) {
            sPatternCnt.put(e.getValue(), sPatternCnt.getOrDefault(e.getValue(), 0) + 1);
        }
        for (Map.Entry<Character, Integer> e : tAlphaCnt.entrySet()) {
            tPatternCnt.put(e.getValue(), tPatternCnt.getOrDefault(e.getValue(), 0) + 1);
        }
        for (Map.Entry<Integer, Integer> e : sPatternCnt.entrySet()) {
            Integer key = e.getKey();
            if (!tPatternCnt.containsKey(key)
                    || !e.getValue().equals(tPatternCnt.get(key))) {
                System.out.println("No");
                return;
            }
        }
        for (Map.Entry<Integer, Integer> e : tPatternCnt.entrySet()) {
            Integer key = e.getKey();
            if (!sPatternCnt.containsKey(key)
                    || !e.getValue().equals(sPatternCnt.get(key))) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

}


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

using namespace std;
using ll = long long;
using vi = vector<int>;

bool is_valid(int a, int b, int c)
{
    if (a + b <= c or a + c <= b or b + c <= a)
        return false;
    else
        return true;
}

int main(void)
{
    int n;
    vi  l;
    cin >> n;

    l.resize(n);
    for (auto &li : l)
        cin >> li;

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

    ll ans = 0;
    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)
            {
                if (l[i] == l[j] or l[i] == l[k] or l[j] == l[k])
                    continue;

                bool cur = is_valid(l[i], l[j], l[k]);
                ans += cur;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	ll N,index=1;
	cin>>N;
	while(index*index<=N)
		index++;

	printf("%lld\n",(ll)pow(index-1,2));

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	set<ll> st1, st2, st3;
	rep(i, n) {
		ll t = s[i] - '0';
		for (ll p : st2) st3.insert(p * 10 + t);
		for (ll p : st1) st2.insert(p * 10 + t);
		st1.insert(t);
	}
	co(st3.size());

	return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int a,b;
   cin >> a >> b;
   int gc = __gcd(a,b);
   set<int> s;
   while(gc%2==0){
      s.insert(2);
      gc = gc/2;
   }
   for(int i=3;i*i<=gc;i+=2){
      while(gc%i==0){
         s.insert(i);
         gc = gc/i;
      }
   }
   if(gc > 1)
      s.insert(gc);
   cout << s.size()+1 << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long R, G, B, N, i, j, sum=0, ans=0;

    cin >> R >> G >> B >> N;

    for(i=0; i<=N/R; i++){
        sum = R*i;

        for(j=0; j<=(N-sum)/G; j++){
            sum += G*j;
            
            if((N-sum)%B==0){
                ans++;
            }

            sum = R*i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N;
    scan(N);
    vector<int> a(N);
    scan(a);
    for (auto &&i : a) {
        if (i % 2 == 0) {
            if (i % 3 != 0 && i % 5 != 0) {
                print("DENIED");
                exit(0);
            }
        }
    }
    print("APPROVED");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
   /* ll t;
    cin>>t;
    while(t--)
    {
       
    }*/
    ll n,m;
    cin>>n>>m;
    ll ans;
    ans=(n-1)*n/2+(m-1)*m/2;
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
program test
integer(8)::n, x, ans, i, t, k, p, a
allocatable::a(:)
read(*,*)n, x
allocate(a(n))
read(*,*)(a(i), i=1,n)
 
if(n==1)then
t=a(1)-x
ans=abs(t)
 
else
t=x-a(1)
ans=abs(t)
 
do i=1,n
t=x-a(i)
k=abs(t)
call subr4(ans,k,p)
ans=p
end do
end if
write(*,*)ans
 
end program test
 
subroutine subr4(a,b,q)
  implicit none
  integer(8) :: a, b, q
  integer(8) :: m, n, k
  ! step 1
  m = a
  n = b
  do
     ! step 2
     k = mod(m, n)
     ! step 3
     if (k == 0) then
        q=n
        exit
     end if
     ! step 4
     m = n
     n = k
  end do
 end subroutine subr4

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

multiset <pair <int, int>> S;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		S.insert({b, -1 * a});
	}
	long long T = 0;
	for (auto s: S){
		T += s.second * -1;
		if (T > s.first){
			cout << "No";
			return 0;
		}
		// cout << T << ' ' << s.first << ' ';
	}
	cout << "Yes";
}

Measured memory_bytes: 9600
// ABC162D - RGB Triplets

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;

	long long int R = 0, G = 0, B = 0;
	for (int i = 0; i < N; i++) {
		switch (S[i]) {
			case 'R':
				R++;
				break;
			case 'G':
				G++;
				break;
			case 'B':
				B++;
				break;
			default:
				break;
		}
	}

	long long int ans = R * G * B;
	for (int i = 1; i <= N / 2; i++) {
		for (int j = 0; j + 2 * i < N; j++) {
			if ((S[j] != S[j + i])
			  &&(S[j] != S[j + 2 * i])
			  &&(S[j + i] != S[j + 2 * i])) {
				ans--;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	//min(x_i,abs(K-x_i))をたしていく
	int total = 0;
	for (int i = 0; i < N; i++) {
		total += min(x[i], abs(K - x[i])) * 2;
	}
	cout << total;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
const int maxn = 100500;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long ans = 0, r, g, b, n;
    cin >> r >> g >> b >> n;
    for(int i = 0 ; i <= n ; ++i)
        for(int j = 0 ; j <= n ; ++j){
            long long sm = i * r + j * g;
            if(sm > n || (n - sm) % b) continue;
            ans++;
        }
    cout << ans << '\n';
    return 0;

}

Measured memory_bytes: 256
from operator import itemgetter
import sys
input = sys.stdin.readline


class BIT1():
    """
    Binary Indexed Tree (1-indexed)
    """
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (self.n + 1)
        self.data = [0] * (self.n + 1)

    def add(self, idx, x):
        # add x to idx-th element
        # idx: 1-indexed
        self.data[idx] += x
        while idx <= self.n:
            self.bit[idx] += x
            idx += (idx & (-idx))

    def sum(self, idx):
        # get sum of [1, idx]
        # idx: 1-indexed
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= (idx & (-idx))
        return s


def main():
    n, q = map(int, input().split())
    c = list(map(int, input().split()))
    queries = []
    for i in range(q):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        queries.append((i, l, r))
    queries.sort(key=itemgetter(2))

    ans = [0] * q
    # last_visit[i] = 色iの最後のindex
    last_visit = [-1] * (n + 1)
    query_counter = 0
    bit = BIT1(n)
    for i in range(n):
        if last_visit[c[i]] != -1:
            bit.add(last_visit[c[i]] + 1, -1)

        last_visit[c[i]] = i
        bit.add(i + 1, +1)

        while query_counter < q and queries[query_counter][2] == i:
            idx, l, r = queries[query_counter]
            ans[idx] = bit.sum(r + 1) - bit.sum(l)
            query_counter += 1

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 192400
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,A,B;
      cin >> N >> A >>B;
     
      if (A*N>B) {
        cout << B << endl;
      }
      else if(A*N<=B){
        cout << A*N << endl;
      }
    }

Measured memory_bytes: 256
// Problem: E - Coprime
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define int long long
#define endl "\n"
#define deb(x) cout << #x << " -> " << x << endl;
#define print(x)                         \
    for (auto x_ : x) cout << x_ << " "; \
    cout << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define mod 1000000007  // 1e9 + 7
#define prec(x, y) fixed << setprecision(y) << x

const int N = (int)1e6 + 3;
bool visited[N] = {};

void solve() {
    int n;
    cin >> n;
    int e_count, o_count;
    e_count = o_count = 0;
    int a[n];
    for (auto &x : a) {
        cin >> x;
        if (x & 1)
            o_count++;
        else
            e_count++;
    }

    bool okay = true;

    for (int i = 0; i < n; ++i) {
        for (int k = 1; k * k <= a[i]; ++k) {
            if (a[i] % k == 0) {
                int factor1 = a[i] / k;
                int factor2 = k;

                if (factor1 != 1 && visited[factor1]) {
                    okay = false;
                    break;
                }

                if (factor2 != 1 && visited[factor2]) {
                    okay = false;
                    break;
                }

                else {
                    visited[factor1] = true;
                    visited[factor2] = true;
                }
            }
        }
    }

    if (okay) {
        cout << "pairwise coprime";
        return;
    }

    int total_gcd = __gcd(a[0], a[1]);
    for (int i = 2; i < n; ++i) total_gcd = __gcd(total_gcd, a[i]);

    if (total_gcd == 1) {
        cout << "setwise coprime\n";
        return;
    }

    cout << "not coprime\n";
    return;
}

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

    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll n, m;
ll a[55];

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

    cin >> n >> m;
    REP(i, n) cin >> a[i];

    ll ans = 0;
    FOR(l, -1, n) FOR(r, l+1, n+1) {
        if(n-r+l+1 > m) continue;
        ll ret = 0;
        vector<ll> v(1, -LLINF);
        REP(i, l+1) {
            ret += a[i];
            if(a[i]<0) v.push_back(a[i]);
        }
        FOR(i, r, n) {
            ret += a[i];
            if(a[i]<0) v.push_back(a[i]);
        }
        sort(ALL(v));
        v[0] = 0;
        FOR(i, 1, v.size()) v[i] += v[i-1];

        // cout << l << " " << r << " " << ret << " " << v << " " << m-(n-r+l+1) << endl;
        if(v.size()) ret -= v[min((ll)v.size()-1,m-(n-r+l+1))];
        chmax(ans, ret);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007

int dp[2005];

//int ans = 0;
int solve(int n){
   //cout << n << endl;
   if(n == 0)
   {
     // cout << "count\n";
      //ans += 1;
      //ans %= MOD;
      return 1;
   }
   if(n < 3)
     return 0;
  if(dp[n] != -1)
     return dp[n]; 
   dp[n] = 0;
   for(int i = 3; i <= n; i++){
       if(n - i >= 0)
        dp[n] += solve(n - i);
        dp[n] %= MOD;
   }
   return dp[n];
}
int gcd(int a, int b); 
  
// To compute x raised to power y under modulo m 
int power(int x, unsigned int y, unsigned int m); 
int modInverse(int a) 
{ 
    int m = MOD;
    int g = gcd(a, m); 
    return power(a, m-2, m);  
} 
  
// To compute x^y under modulo m 
int power(int x, unsigned int y, unsigned int m) 
{ 
    if (y == 0) 
        return 1; 
    int p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
  
// Function to return gcd of a and b 
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b%a, a); 
} 
int32_t main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int a1[4];
     a1[0] = a * c;
     a1[1] = a * d;
     a1[2] = b * c;
     a1[3] = b * d;
    sort(a1, a1+4);
    cout << a1[3];
}

Measured memory_bytes: 3636
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

const ll INF = 1000100100100100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b<d){
        swap(a,c);
        swap(b,d);
    }
    ll ma = -INF;
    ma = max(a*c, ma);
    ma = max(a*d, ma);
    ma = max(b*c, ma);
    ma = max(b*d, ma);

    cout << ma << endl;
}

Measured memory_bytes: 3612
#include<vector>
#include<iostream>

using namespace std;

int main(){
  int n;
  int val;
  int ct;
  std::vector<int> lst;

  cin >> n;
  ct =n;
  while(ct > 0 ){
    cin >> val;
    lst.push_back(val);
    ct--;
  }

  ct =0;
  while(1){
    bool even=true;
    for( int i=0; i<n; i++){
      if( (lst[i] % 2) != 0){
        even = false;
        break;
      }else{
        lst[i] /= 2;
      }
    }

    if( even == false) break;    
    ct++;
  }
  
  cout << ct << endl;
}
    


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

typedef long long ll;

bool f[233];
ll Le,Sum;
string s;

void dfs(int Pos){
	if(Pos > Le - 2){
		ll Now = s[Le - 1] - '0';
		ll Cheng = 1;
		for(int i = Le - 2; i >= 0 ; i--){
			if(f[i] == true){
				Sum += Now;
				Now = s[i] - '0';
				Cheng = 1;
			}
			else{
				Cheng *= 10;
				Now += (s[i] - '0') * Cheng;
			}
		}
		Sum += Now;
	}
	else{
		f[Pos] = false;
		dfs(Pos+1);
		f[Pos] = true;
		dfs(Pos+1);
	}
}

int main(){
	cin>>s;
	Le = s.length();
	dfs(0);
	cout<<Sum<<endl;
	return 0;
} 

Measured memory_bytes: 256
s=input()
s_1=s[0:int((len(s)-1)/2)]
s_2=s[int((len(s)+3/2))-1:len(s)]
if(s==s[::-1] and s_1==s_1[::-1] and s_2==s_2[::-1]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define min(a,b) (a>b?b:a)
// #define abs(a) (a<0?(a*-1):a)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

signed main(){
	cout<<fixed<<setprecision(7);
	int n, k, x, ans = 0;
	cin>>n>>k;
	// cout<<abs(n)<<endl;
	for(int i = 0; i < n; i++){
		cin>>x;
		// cout<<x<<" "<<x-k<<endl;
		ans += min(x*2,abs(x-k)*2);
	}
	
	cout<<ans<<endl;
	
	
	
	return 0;
}

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

using namespace std;

vector<int> v;

int main(){
  int n;
  cin >> n;
  for (int i=0;i<=n;i++) {
    v.push_back(100001);
  }
  v[0] = 0;
  for (int i=1;i<=n;i++) {
    if (v[i] > v[i-1]+1){
      v[i] = v[i-1] + 1;
    }
    int six_power = 6;
    while (i - six_power >= 0) {
      if (v[i] > v[i - six_power] + 1) {
	v[i] = v[i - six_power + 1];
      }
      six_power *= 6;
    }
    int nine_power = 9;
    while (i - nine_power >= 0) {
      if (v[i] > v[i - nine_power] + 1) {
	v[i] = v[i - nine_power] + 1;
      }
      nine_power *= 9;
    }
  }
  cout << v[n] << endl;
  return(0);
}


Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int n,K;
vector<int>G[22222];
vector<pair<int,int> >E;
main()
{
	scanf("%d%d",&n,&K);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		int now=i;
		while((now-1)/2>=1)
		{
			G[i].push_back((now-1)/2);
			G[(now-1)/2].push_back(i);
			E.push_back(make_pair((now-1)/2,i));
			now=(now-1)/2;
		}
	}
	printf("%d\n",(int)E.size());
	for(int i=0;i<E.size();i++)printf("%d %d\n",E[i].first,E[i].second);
	fflush(stdout);
	for(;K--;)
	{
		int nowp=1;
		vector<bool>ok(n*4,true);
		bool flag=0;
		while(nowp<=n)
		{
			printf("%d\n",nowp);
			fflush(stdout);
			string in;
			cin>>in;
			if(in=="Yes")
			{
				flag=1;
				break;
			}
			else if(in=="Near")
			{
				ok[nowp-1]=false;
				vector<bool>ok2(n,false);
				for(int j=0;j<G[nowp].size();j++)ok2[G[nowp][j]-1]=true;
				for(int j=0;j<n;j++)ok[j]=ok[j]&&ok2[j];
				nowp=nowp*2+1;
			}
			else
			{
				ok[nowp-1]=false;
				for(int j=0;j<G[nowp].size();j++)
				{
					ok[G[nowp][j]-1]=false;
				}
				nowp=(nowp+1)*2+1;
			}
		}
		if(!flag)
		{
			int id=0;
			while(1)
			{
				while(id<n&&!ok[id])id++;
				printf("%d\n",id+1);
				fflush(stdout);
				string in;
				cin>>in;
				if(in=="Yes")
				{
					break;
				}
				else
				{
					ok[id]=false;
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3860
N=int(input())
S=[input() for i in range(N)]

import sys
if N==1:
    A=list(S[0])
    A.sort()
    print(''.join(A))
    sys.exit()

U=set(list('abcdefghijklmnopqrstuvwxyz'))
for i in range(N):
    U=U&set(list(S[i]))

if len(U)==0:
    print('')
    sys.exit()

U=sorted(list(U))
ans=''
for i in U:
    k=51
    for j in range(N):
        k=min(k,S[j].count(i))
    ans+=i*k

print(ans)

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

string wcz;

void tak()
{
    printf("Yes\n");
    exit(0);
}

void nie()
{
    printf("No\n");
    exit(0);
}

int main()
{
    cin >> wcz;
    for (int i=0; i<wcz.size(); i++)
    {
        for (int j=i+1; j<wcz.size(); j++)
        {
            if (wcz[i]=='C' && wcz[j]=='F')
            {
                tak();
            }
        }
    }
    nie();
    return 0;
}


Measured memory_bytes: 764
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

LL N,M;
LL A[100000];

LL ans = 0;

LL gcd(LL a, LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a, LL b) { return a/gcd(a,b)*b;}

LL numof2(LL x){
	LL ret = 0;
	while(x%2==0){
		ret++;
		x /=2;
	}
	return ret;
}
 
void solve(){
	for(int i=0;i<N;i++){
		if(A[i]%2==1) return;
		A[i] /= 2;
	}
	LL lcm_a = 1;//Aの最小公倍数
	for(int i=0;i<N;i++){
		lcm_a = lcm(lcm_a,A[i]);
	}
	LL A1_2 = numof2(A[0]);
	for(int i=1;i<N;i++){
		if(A1_2!=numof2(A[i])) return;
	}
	ans = M/lcm_a;
	ans = (ans+ans%2)/2;
}
 
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++) cin >> A[i];
 
	solve();

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

Measured memory_bytes: 1024
S=input()
x=int(S[:2])
y=int(S[2:])
#print(x,y)
a1=0
a2=0
if 0<=x<=99 and 1<=y<=12:
    a1=1
if 1<=x<=12 and 0<=y<=99:
    a2=1
if a1==1 and a2==1:
    print('AMBIGUOUS')
elif a1==1:
    print('YYMM')
elif a2==1:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        String S = sc.next();
        int len = S.length();
        if(K >= len){
            System.out.println(S);
        }else{
            System.out.println(S.substring(0,K) + "...");
        }
    }
}


Measured memory_bytes: 38620
S = input()
Q = int(input())

res = S

is_rev = False

before = []
after = []

def add_char(s, f, c, is_rev):
  if(f == "1"):
    before.append(c)
  else:
    after.append(c)

for _ in range(Q):
  q = input().split()
  
  if(q[0] == '1'): # Ti = 1
    is_rev = not is_rev
    before, after = after, before
  
  else: #Ti = 2
    add_char(res, q[1], q[2], is_rev)

before.reverse()

res = "".join(before) + (res[::-1] if is_rev else res) + "".join(after)

print(res)

Measured memory_bytes: 5736
n=int(input())
a=list(map(int,input().split()))
a.sort()

# 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。
# ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。
# 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要)

s=set()
cnt=0
for i,aa in enumerate(a):
  if aa not in s:
    # 同値が複数ある場合、カウントしない。sortしているため、同値は並ぶ
    if i+1 == len(a) or aa != a[i+1]:
      cnt+=1
    
    for i in range(1,10**6+1):
      ma=aa*i
      if ma > 10**6:
        break
      s.add(ma)

print(cnt)
    


Measured memory_bytes: 86548