akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int A, P;
    cin >> A >> P;
    cout << (3 * A + P) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int n, m, q, ans;
int a[50], b[50], c[50], d[50];

int ctoi(char c){
	return c - '0';
}

void makenum(int x, string s){
	if (x == n){
		int temp = 0;
		for (int i = 0; i < q; i++){
			if (s[b[i]-1] == 't' || s[a[i]-1] == 't'){
				if (s[a[i]-1] == 't'){
					if (c[i] == 0) temp += d[i];
				}else{
					if (10 - ctoi(s[a[i]-1]) == c[i]) temp += d[i];
				}
			}else{
				if (ctoi(s[b[i]-1]) - ctoi(s[a[i]-1]) == c[i]) temp += d[i];
			}
		}
		ans = max(ans, temp);
		return;
	}
	if (x == 0){
		makenum(x+1, s+to_string(1));
		return;
	}
	if (s[x-1] == 't'){
		makenum(x+1, s+'t');
		return;
	}
	for (int i = ctoi(s[x-1]); i <= m; i++){
		if (i == m && m == 10){
			makenum(x+1, s+'t');
			return;
		}
		makenum(x+1, s+to_string(i));
	}
	return;
}


int main(){
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	string s;
	makenum(0, s);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3688
n = gets.to_i
a = gets.split.map(&:to_i)
x = 0
sum = a.inject(:+)
min = 1_000_000_000_000_000
0.upto(n - 2) do |i|
  x += a[i]
  min = (sum - 2 * x).abs if min > (sum - 2 * x).abs
end
puts min

Measured memory_bytes: 15236
N = int(input())
A = list(map(int, input().split()))

node = [[] for i in range(N + 1)]
idx = list(range(N+1))  # 0 ~ N
idx = idx[1:]  # 1 ~ N

# Depth = N
node[0].append(A[N])
node[0].append(A[N])

for i in idx:
    # min
    node[i].append(- (- node[i - 1][0] // 2) + A[- i - 1])
    # max
    node[i].append(node[i - 1][1] + A[- i - 1])

if 1 not in node[-1]:
    print(-1)
    exit()

node.reverse()
idx = list(range(N + 1))
idx = idx[1:]
maximum = []
maximum.append(1)

for i in idx:
    val = min(node[i][1], (maximum[i - 1] - A[i - 1]) * 2)
    maximum.append(val)

print(sum(maximum))


Measured memory_bytes: 39720
#include<bits/stdc++.h>
using namespace std;
int n;
char a[1001],b[1001];
int main()
{
	cin>>n;
	scanf("%s%s",a,b);
	int l=strlen(a);
	int k=strlen(b);
	for(int i=0;i<n;++i)
		cout<<a[i]<<b[i];
	return 0;
}                                  

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

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

	int A;

	map <int, int> m;
	rep(i, N) {
		cin >> A;
		m.insert(make_pair(A, i + 1));
	}


	for (auto it : m) { //autoはC++11から
		cout << it.second << " ";
	}
}

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

int main(){
    string s; cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define N 100000

int main()
{
  int i, n, q, v, x, y, z, dx, dy, x0, y0, ex, rx, sx, tmp;
  char *p, buf[32];
  buf[31]=0;
  buf[30]='\n';
  int *s = (int*)malloc(sizeof(int)*N+1);
  int *d = (int*)malloc(sizeof(int)*N+1);
  while (1) {
    fgets(buf, 32, stdin);
    for (n=0,p=buf; *p!=' '; n=n*10+*(p++)-'0'); 
    for (q=0,p++; *p!='\n'; q=q*10+*(p++)-'0'); 
    if (n==0 && q==0) break;
    for (i=1; i<=n; s[i]=i,d[i++]=0);
    for (int t=0; t<q; t++) {
      fgets(buf, 32, stdin);
      for (x=0,p=buf+2; *p!=' '; x=x*10+*(p++)-'0');
      for (y=0,p++; *p>='0'; y=y*10+*(p++)-'0');

      if (buf[0]=='!') { // relate x y z
	for (z=0,p++; *p!='\n'; z=z*10+*(p++)-'0');
	x0=x;
	y0=y;
	for (dx=0; s[x]!=x; dx+=d[x], x=s[x]);
	for (dy=0; s[y]!=y; dy+=d[y], y=s[y]);
	s[x0]=x;
	d[x0]=dx;
	s[y0]=y;
	d[y0]=dy;
	
	if (x<y) {
	  s[y] = x;
	  d[y] = z + dx - dy;
	} else if (x>y) {
	  s[x] = y;
	  d[x] = -z - dx + dy;
	} else continue;
	
      } else { // diff

	for (x0=x,dx=dy=0; s[x]!=x; dx += d[x], x=s[x]);
	for (rx=x, x=x0, ex=dx; s[x]!=x; x=sx) {
	  sx=s[x];
	  s[x]=rx;
	  tmp = d[x];
	  d[x]=ex;
	  ex-=tmp;
	}
	for (y0 = y; s[y]!=y; dy+=d[y], y = s[y]);
	v=-dx+dy;
	if (x!=y) {
	  fputs("UNKNOWN\n", stdout);
	} else {
	  i=30;
	  if (v>0)  for (; v>0; buf[--i]='0'+v%10,v/=10);
	  else if (v<0) {
	    for (; v<0; buf[--i]='0'-v%10,v/=10);
	    buf[--i] = '-';
	  } else  buf[--i] = '0';
	  fputs(buf+i, stdout);
	}
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1000000000;
typedef pair<int,int> P;
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; }
vector<string> v;
queue<P> Q;
int main(){
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }
    else if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    }
    else {S.at(K-1)='c';}
    cout<<S<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int main()
{
	lint N,a[100010]={},x;
	lint tmp;
	lint ans=0;
	
	cin >> N >> x;
	for(int i=0;i<N;i++)
		cin >> a[i];
	
	
	if(a[0]>x)
	{
		ans+=(a[0]-x);
		a[0]=x;
	}
	for(int i=0;i<N-1;i++)
	{
		tmp=a[i]+a[i+1];
		if(tmp>x)
		{
			ans+=(tmp-x);
			a[i+1]-=(tmp-x);
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N;
std::queue<int> block, temp;

bool isTriangleNumber(int n){
    int x = 8 * n + 1;
    int lb = 0, ub = 3000;

    while(ub - lb > 1){
        int mid = (lb+ub) / 2;

        if(mid * mid <= x){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    if(lb * lb != x){return false;}
    return lb % 2 == 1;
}

bool isFinished(){
    bool f = true;
    int i = 1;
    while(!block.empty()){
        int b = block.front();
        // printf("%d\n", b);
        if(b != i){f = false;}
        temp.push(b);
        block.pop();
        
        i += 1;
    }
    // puts("------------------------");

    if(f){return true;}

    while(!temp.empty()){
        block.push(temp.front());
        temp.pop();
    }

    return false;
}

int main(){
    // while(1){std::cin >> N; if(isTriangleNumber(N)){puts("Yes");}else{puts("No");}}

    while(std::cin >> N, N){
        while(!block.empty()){block.pop();}
        while(!temp.empty()){temp.pop();}

        int block_n = 0;
        REP(i, N){
            int b;
            std::cin >> b;

            block.push(b);
            block_n += b;
        }

        if(!isTriangleNumber(block_n)){
            puts("-1"); continue;
        }

        int t = 0;
        while(t <= 10000){
            if(isFinished()){break;}

            int group_n = block.size(), new_b = 0;
            REP(i, group_n){
                int b = block.front(); block.pop();

                new_b += 1;
                if(b-1 > 0){block.push(b-1);}
            }

            block.push(new_b);

            t += 1;
        }

        if(t > 10000){
            puts("-1");
        }else{
            printf("%d\n", t);
        }
    }
}

Measured memory_bytes: 1204
#include <iostream>
using namespace std;
double n,d,x,ans;
int main(){
    cin>>n>>d>>x;
    double ans = 0.0;
    while(n){
        ans+=d+(n-0.5)*x;
        d+=(2*d+5*x)/(2*n);
        x+=2*x/n;
        n--;
    }
    printf("%.9f\n",ans);
    return 0;
}


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

#define endl '\n'

using namespace std;

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

    int n, arr[100];
    cin >> n;
    for(size_t i = 0; i < n; i++) cin >> arr[i];

    for(size_t i = 0; i < n; i++)
    {
        cout << arr[i];
        if(i < n - 1)
            cout << " ";
    }
    cout << endl;
    for(size_t i = 1; i < n; i++)
    {
        int key = arr[i];
        int j = i - 1;
        while(j >= 0 && arr[j] > key)
        {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = key;

        for(size_t i = 0; i < n; i++)
        {
            cout << arr[i];
            if(i < n - 1)
                cout << " ";
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  double a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    a[i]=1/a[i];
  }
  double sum=0;
  for(int i=0;i<n;i++)
  {
    sum+=a[i];
  }
  double ans=1/sum;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*#include <bits/stdc++.h>
using namespace std;
string ans,s[3055][3055],s1,s2;
int dp[3055][3055],n,m,ma;
int main()
{

    cin>>s1>>s2;
    if (s1.size()>s2.size()) swap(s1,s2);
    n=s1.size();
    m=s2.size();
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            dp[i+1][j+1]=dp[i][j+1];
            s[i+1][j+1]=s[i][j+1];
            if (s1[i]==s2[j])
            {
                    dp[i+1][j+1]++;
                    s[i+1][j+1]=s[i+1][j+1]+s1[i];
            }
            if (dp[i+1][j+1]<=dp[i+1][j])
            {
                s[i+1][j+1]=s[i+1][j];
                dp[i+1][j+1]=dp[i+1][j];
            }
            //cout<<s[i+1][j+1]<<dp[i+1][j+1]<<" ";
        }

    }
    for (int i=0;i<=m;i++)
    {
        if (dp[n][i]>ma)
        {
            ma=dp[n][i];
            ans=s[n][i];
        }
    }
    cout<<ans;
}*/
#include<bits/stdc++.h>
using namespace std;
int dp[200099],m,n,ans;
vector<int> v[100009];
int dfs(int node)
{
    if (dp[node]!=-1) return dp[node];
    int ret=0;
    for (int i=0;i<v[node].size();i++)
    {
        int u=v[node][i];
        ret=max(ret,dfs(u)+1);
    }
    return dp[node]=ret;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for (int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        v[x].push_back(y);
    }
    for (int i=0;i<n;i++)
    {
        ans=max(dfs(i),ans);
    }
    cout<<ans;
}


Measured memory_bytes: 8576
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){
    const double PI=3.14159265358979323846;
    double a,b,h,m;
    double zishin = 0.5,hunsin = 6.0;
    double zi_sita,hun_sita,sita,ans;

    cin >> a >> b >> h >> m;

    zi_sita = h*60*zishin+m*zishin;
    hun_sita = m*hunsin;

    if(zi_sita>=hun_sita){
        sita = zi_sita-hun_sita;
    }else{
        sita = hun_sita-zi_sita;
    }

    if(sita >= 180.0)sita = 360-sita;

    ans = sqrt((a*a+b*b)-(2.0*a*b*cos(sita*PI/180.0)));

    cout << fixed << setprecision(20) << ans << endl;


    return 0;
}

Measured memory_bytes: 4192
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Lucky 7
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 3;

/* typedef */

/* global variables */

char s[N + 4];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);

  for (int i = 0; i < N; i++)
    if (s[i] == '7') {
      puts("Yes");
      return 0;
    }

  puts("No");
  return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<cstring>
using namespace std;int x[100][1000][150],a,b,c,i,j,k,l,sum;
int main(){
	while(true){
		sum=0;
		memset(x,0,sizeof(x));
		cin>>a>>b>>c;if(a==0){break;}
		x[0][0][0]=1;
		for(i=1;i<=b;i++){
			for(j=0;j<=c;j++){
				for(l=0;l<a;l++){
					for(k=l+1;k<=a;k++){
						x[i][j+k][k]+=x[i-1][j][l];
					}
				}
			}
		}
		for(i=0;i<=a;i++){sum+=x[b][c][i];}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 59760
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define all(L) L.begin(),L.end()
using ll=long long;
#define RO 1
#define SI 2
#define PA 3

ll N,M;
int A[15];
int x[15][15],y[15][15];

void dfs(ll m,int bits,int &count){
    if(m>N) return;
    if(bits==0b111) count++;
    dfs(10*m+7,bits|0b100,count);
    dfs(10*m+5,bits|0b010,count);
    dfs(10*m+3,bits|0b001,count);
}

int main(){
    cin>>N;
    ll m=0;
    int bits=0;
    int count=0;
    dfs(m,bits,count);
    cout<<count<<endl;
}    




Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int[] mt = new int[10];
            for(int i=0; i<10; i++)
            {
                mt[i] = sc.nextInt();
            }
                Arrays.sort(mt);
                    for(int i=0; i<3; i++)
                    {
                        System.out.println(mt[9-i]);
                    }
    }
}

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

int main()
{
    string s;
    int posA, posZ;
    cin >> s;

    for(int i=0; ;i++)
    {
        posA = i;
        if(s[i]=='A') break;
    }

    for(int i=s.length(); ;i--)
    {
        posZ = i;
        if(s[i]=='Z') break;
    }
    cout << posZ - posA + 1 << endl;
    return 0;
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  ll X;
  cin>>X;
  ll ans=0;
  ans+=(X/500)*1000;
  X-=(X/500)*500;
  ans+=(X/5)*5;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010

int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int main(void){
	int n;
	scanf("%d",&n);
	int L[2*n];
	for(int i=0;i<2*n;i++)scanf("%d",&L[i]);
	qsort(L,2*n,sizeof(int),compare_int);
	int ans=0;
	for(int i=0;i<2*n;i+=2){
		ans += L[i];
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int a;
	scanf("%d",&a);
	float N[a];
	float sum=0;
	for(int i=0;i<a;i++){
		scanf("%f",&N[i]);
		sum+=1/N[i];
	}
	printf("%f",1/sum);
	return 0;
}

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

using namespace std;
typedef long long ll;
ll inf = (ll)1 << 60;

ll n;
vector<ll> v;

vector<vector<ll>> memo;
vector<vector<ll>> size;

// Find the cheapest cost to combine the range [lo,hi]
ll solve(ll lo, ll hi) {
    if(memo[lo][hi] != inf) return memo[lo][hi];

    if(lo == hi) {
        memo[lo][hi] = 0;
        return 0;
    }

    ll best = inf;
    for(ll i = lo; i < hi; i++) {
        ll here = solve(lo,i) + solve(i+1,hi);
        best = min(best,here);
    }
    best += size[lo][hi];

    memo[lo][hi] = best;
    return best;
}

void sizes(ll lo, ll hi) {
    if(size[lo][hi] != inf) return;

    if(lo == hi) {
        size[lo][hi] = v[lo];
        return;
    }

    ll best = inf;
    for(int i = lo; i < hi; i++) {
        sizes(lo,i);
        sizes(i+1,hi);
        ll here = size[lo][i] + size[i+1][hi];
        best = min(best, here);
    }

    size[lo][hi] = best;
}

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

    v.resize(n);
    for(auto& i : v) {
        cin >> i;
    }

    memo.resize(n+1,vector<ll>(n+1,inf));
    size.resize(n+1,vector<ll>(n+1,inf));

    sizes(0,n-1);
    cout << solve(0,n-1) << endl;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int  n,m;
	while(cin>>n>>m)
	{
		char x[123];
		for(int i=0;i<n;i++)
		{
			scanf("%s",x);
			puts(x);
			puts(x);
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;
int main() {
    ll n;
    cin >> n;
    ll a;
    vector<ll> b;
    for(ll i=1; i<=n; i++) {
        cin >> a;
        b.push_back(a - i);
    }
    sort(b.begin(), b.end());

    ll mid = b[n/2];
    ll ans = 0;
    for(int i=0; i<n; i++) {
        ans += abs(b[i] - mid);
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  string s;
  cin >> s;

  const string U = "AKIHABARA";

  int ptr = 0;

  for (char ch : s) {
    while (ptr < SZ(U) && U[ptr] != ch) {
      if (U[ptr] != 'A') {
        cout << "NO\n";
        return 0;
      }
      ++ptr;
    }

    if (ptr == SZ(U)) {
      cout << "NO\n";
      return 0;
    }
    ++ptr;
  }

  if (ptr < SZ(U) - 1) {
    cout << "NO\n";
    return 0;
  }

  cout << "YES\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i = 1;
		// ?¨??????\???????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while (true) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
			} else {
				while (true) {

					if (x % 10 == 3) {
						System.out.printf(" %d", i);
						break;
					} else {
						x /= 10;
						if (x == 0)
							break;
					}
				}
			}
			if (++i > n) {
				System.out.print("\n");
				break;
			}
		}
	}
}

Measured memory_bytes: 41008
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {//スッキリ版
	int n;
	cin >> n;
	ll a[Nmax]={};
	REP(i,n) cin >> a[i];
	bool flag=true;
	REP(i,n-1){
		a[i+1]+=a[i];
		if(a[i+1]*a[i]>=0) flag=false;
	}
	if(flag){
		cout<< 0 << endl;
		return 0;
	}
	ll tasu=0,aa=0,cnt=0;//aa:変更量
	REP(i,n){//- → + → - → + →,,,
		aa=0;
		if(i%2==0){
			if(a[i]+tasu<0) continue;
            else if(a[i]+tasu>0) aa=abs(a[i]+tasu)+1;
			else aa=1;
			cnt+=aa;
			tasu-=aa;
		}else{
			if(a[i]+tasu>0) continue;
            else if(a[i]+tasu<0) aa=abs(a[i]+tasu)+1;
			else aa=1;
			cnt+=aa;
			tasu+=aa;
		}
    }
	ll cnt2=0;
  	tasu=0;
	REP(i,n){
      	aa=0;
		if(i%2!=0){
			if(a[i]+tasu<0) continue;
            else if(a[i]+tasu>0) aa=abs(a[i]+tasu)+1;
			else aa=1;
			cnt2+=aa;
			tasu-=aa;
		}else{
			if(a[i]+tasu>0) continue;
            else if(a[i]+tasu<0) aa=abs(a[i]+tasu)+1;
			else aa=1;
			cnt2+=aa;
			tasu+=aa;
		}
    }
	cout << min(cnt,cnt2) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF = 1000000100;

int main(){
    int x,y;
    cin >> x >> y;
    if(y/2<=2*x && 2*x<=y && (y-2*x)%2==0 && y%2==0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 3040
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

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

    ll N, M;
    vector<ll> acc(N + 1);

    cin >> N >> M;
    acc[0] = 0;
    ll tmp;
    map<ll, ll> mp;
    mp[0]++;
    for (int i = 1; i <= N; i++)
    {
        cin >> tmp;
        acc[i] = (acc[i - 1] + tmp) % M;
        mp[acc[i]]++;
    }

    ll ans = 0;
    for (auto m : mp)
    {
        ans += m.second * (m.second - 1) / 2;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    string a;
    cin>>a;
    while(1){
        if(a=="0") break;
        int s=0;
        for(int i=0;i<a.length();i++)
        {
            s += (a[i]-'0');
        }
        cout<<s<<endl;
        cin>>a;
    }
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<60;
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; }
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


ll a[1100],b[1100];
vector<vector<ll>> dp(1100,vector<ll>(11000,INF));
main(){
  ll h,n,ans=0;
  cin>>h>>n;
  rep(i,0,n)cin>>a[i]>>b[i];
  dp[0][0]=0;
  rep(i,0,n){
    rep(j,0,h+1){
      chmin(dp[i+1][j],dp[i][j]);
      chmin(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
    }
  }
  cout<<dp[n][h];
}


Measured memory_bytes: 94976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll INF64 = 1e18;

template <typename T>
string to_string(const vector<T> &v) {
    string ret = "<";
    for (auto it : v) {
        ret += to_string(it) + ", ";
    }
    ret.pop_back(); ret.pop_back();
    ret += ">";
    return ret;
}

void debug_print() { cerr << endl; }

template <typename T, typename ...U>
void debug_print(T t, U... u) {
    cerr << " " << to_string(t);
    debug_print(u...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_print(__VA_ARGS__)
const int N = 1e5 + 5;

ll numOfFactor(ll x) {
    ll ret = 1ll;
    ll bound = x;
    for (ll i = 2; i * i <= bound; i++) {
        ll cnt = 0ll;
        while (x % i == 0) {
            cnt++;
            x /= i;
        }
        ret = ret * (cnt + 1);
    }
    if (x != 1) {
        ret = ret * 2;
    }
    return ret;
}

ll solve(ll x) {
    ll ret = numOfFactor(x - 1);
    for (ll i = 2; i * i <= x; i++) {
        if (x % i == 0) {
                ll cur = x;
            while (cur % i == 0) {
                cur /= i;
            }
            if (cur == 1 || cur % i == 1)
            ret++;
        }
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    cout << solve(n) << endl;
    return 0;
}

Measured memory_bytes: 256
def is_prime(q):
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(5, q-1, q)*pow(7, q-1, q) == 1
  
def main():
  s = set([561, 11041, 29341, 38081, 46657, 50737, 75361, 79381, 88831])
  b = [5,7]
  for i in range(2,10**5):
    if i in s:
      continue
    if is_prime(i):
      b.append(i)

  a = set([2*i-1 for i in b])
  b = set(b)
  chk = sorted(tuple(a&b))

  from bisect import bisect,bisect_left
  import sys
  input = sys.stdin.readline

  q = int(input())
  for i in range(q):
    l,r = map(int,input().split())
    print(bisect(chk,r)-bisect_left(chk,l))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 5536
import bisect

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

count = 0

for i in range(len(B)):
    a_b = bisect.bisect_left(A,B[i])
    c_b = bisect.bisect_right(C,B[i])
    count += a_b * (N - c_b)

print(count)

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

int n,a[2000],ans;

main()
{
	scanf("%d",&n);
	for(int i=0; i<n; i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	for(int i=0,j,k; i<n; i++)
		for(j=i+1; j<n-1; j++)
		{
			k=upper_bound(a+j+1,a+n,a[i]+a[j]-1)-a;
			ans+=k-j-1;
		}
	printf("%d",ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdint>
template<typename T>
T input(std::istream& is = std::cin){T t; is >> t; return t;}
int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  const auto S = input<std::string>();
  const auto N = input<std::uint64_t>();
  if(N <= S.size() && S.find(std::string(N, '1')) == 0)
    std::cout << '1' << std::endl;
  else
    std::cout << S[S.find_first_not_of('1')] << std::endl;
}


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

using namespace std;

int main()
{
    //freopen("inp.in", "r", stdin);
    string s;
    cin >> s;
    vector<int> tel(27, 0);
    for(char ch : s) tel[ch-'a']++;
    int nb_odd=0;
    int which=-1;
    for(int i=0; i<27; i++)
    {
        if(tel[i]&1){
            nb_odd++;
            which=i;
        }
    }
    if((s.size()%2==0 && nb_odd != 0) || (s.size()%2==1 && nb_odd != 1))
    {
        printf("-1\n");
        return 0;
    }
    long long ans=0;
    vector<int> tel2(27, 0);
    string s1="";
    string s2="";
    int pos=0;
    for(int i=0; i<s.size(); i++)
    {
        tel2[s[i]-'a']++;
        if(tel2[s[i]-'a']<=tel[s[i]-'a']/2)
        {
            s1+=s[i];
            ans+=i-pos;
            pos++;
        }
        else s2+=s[i];
    }
    if(s.size()%2==1)
    {
        for(int i=0; i<s2.size(); i++)
        {
            if(s2[i]-'a'==which)
            {
                ans+=i;
                int curr=i;
                while(curr != 0)
                {
                    swap(s2[curr], s2[curr-1]);
                    curr--;
                }
                break;
            }
        }
    }
    //cerr << s1 << " " << s2 << endl;
    reverse(s2.begin(), s2.end());
    if(s.size()%2==1) s2.pop_back();
    vector< vector<int> > na_mij1(s1.size(), vector<int>(26, 0));
    vector< vector<int> > na_mij2(s2.size(), vector<int>(26, 0));
    for(int i=(int)(s1.size())-2; i>=0; i--)
    {
        for(int j=0; j<26; j++)
        {
            na_mij1[i][j]=na_mij1[i+1][j];
            na_mij2[i][j]=na_mij2[i+1][j];
        }
        na_mij1[i][s1[i+1]-'a']++;
        na_mij2[i][s2[i+1]-'a']++;
    }
    vector< vector<int> > posities(26);
    for(int i=0; i<s1.size(); i++)
    {
        posities[s1[i]-'a'].push_back(i);
    }
    vector<int> wijzers(26, 0);
    vector<int> uiteindelijke_plaats(s2.size(), -1);
    for(int i=0; i<s2.size(); i++)
    {
        uiteindelijke_plaats[i]=posities[s2[i]-'a'][wijzers[s2[i]-'a']++];
    }
    for(int i=0; i<s2.size(); i++)
    {
        for(int j=0; j<26; j++)
        {
            ans+=max(0,na_mij2[i][j]-na_mij1[uiteindelijke_plaats[i]][j]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 28288
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
ll modFact(ll n,ll p) 
{ 
    // n! % p is 0 if n >= p 
    if (p <= n) 
        return 0; 
  
    // Initialize result as (p-1)! which is -1 or (p-1) 
    ll res = (p - 1); 
  
    // Multiply modulo inverse of all numbers from (n+1) 
    // to p 
    for (ll i = n + 1; i < p; i++) 
        res = (res * modInverse(i, p)) % p; 
    return res; 
} 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k,n,a,b,i;
    cin>>n>>a>>b;
    
   ll ans=power(2,n,p);
   
    ans--;
    
  
    ll m1=std::max(a,n-a);
    ll m2=std::min(a,n-a);
    ll fac[m2+1];
    fac[0]=1;
    ll t1=(m1+1)%p;
    for(i=m1+2;i<=n;i++)
    {
    t1*=i;
    t1%=p;
    }
    
    
    for(i=1;i<=m2;i++)
    {
    fac[i]=(fac[i-1]*i);
    fac[i]%=p;
    }
    t1*=(modInverse(fac[m2],p)%p);
    t1%=p;
  if(m2==0)
    t1=1;
    
    ll m3=std::max(b,n-b);
    ll m4=std::min(b,n-b);
    ll t2=m3+1;
    for(i=m3+2;i<=n;i++)
    {
        t2*=i;
        t2%=p;
    }
   ll fa[m4+1];
    fa[0]=1;
     for(i=1;i<=m4;i++)
     {
    fa[i]=(fa[i-1]*i);
    fa[i]%=p;
     }
    t2*=(modInverse(fa[m4],p)%p);
    t2%=p;
    
  if(m4==0)
    t2=1;
  ll x=(t1+t2)%p;

    ans-=x;
    ans=(ans+100*p)%p;
    cout<<ans;


    
    return 0;
    
}
    

Measured memory_bytes: 3328
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7
constexpr ll LIM = 220010;

//変数
ll H, W, A, B;
vector<ll> fact, inv;


//繰り返し累乗法
//in:  x,n,mod
//out: x^n(Mod mod)
template<typename T>
T mod_pow(T x, T n, T mod) {
	T res = 1;
	while (n > 0) {
		if (n & 1)res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}






//サブ関数
//入力
void input()
{
	cin >> H >> W >> A >> B;
}

void make_contents()
{
	ll tmp = 1;
	fact.push_back(0);
	FOR(i, 1, LIM) {
		tmp *= i;
		tmp %= MOD;
		fact.push_back(tmp);
	}

	tmp = mod_pow(tmp, MOD - 2, MOD);
	//inv.push_back(tmp);
	for (ll i = LIM-1; i > 0; i--) {
		tmp *= i;
		tmp %= MOD;
		inv.push_back(tmp);
	}
	reverse(inv.begin(), inv.end());
	fact[0] = inv[0] = 1;
	/*正当性確認
	REP(i, LIM) {
		cerr << (fact[i] * inv[i]) % MOD << endl;
	}
	*/
}

ll comb(ll n, ll k) {
	ll res = fact[n];
	res *= inv[k]; res %= MOD;
	res *= inv[n - k]; res %= MOD;
	return res;
}


//計算
void calc()
{
	ll res = 0;
	make_contents();

	ll hc = H - A - 1;
	ll wc = B;
	while(true){
		ll restH = H - 1 - hc;
		ll restW = W - 1 - wc;

		ll more1 = comb(hc + wc, hc);
		ll more2 = comb(restH + restW, restH);
		ll more = more1 * more2;
		more %= MOD;
		res += more;
		res %= MOD;

		hc--; wc++;
		if (hc < 0 || wc >= W)break;
	}

	cout << res << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 4976
// https://atcoder.jp/contests/abc108/tasks/abc108_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int k, e, o;

  cin >> k;

  e = k / 2;
  o = (k + 1) / 2;

  cout << e * o << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();

    if (D == 22) {
      System.out.println("Christmas Eve Eve Eve");
    } else if (D == 23) {
      System.out.println("Christmas Eve Eve");
    } else if (D == 24) {
      System.out.println("Christmas Eve");
    } else {
      System.out.println("Christmas");
    }

  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

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

    int n; 
    cin>>n;
    int a[n];
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    set<int> s;
    bool f = 1;
    for(int i = 0; i<n; i++){
        if(s.find(a[i]) != s.end()){
            f = 0;
            break;
        }
        s.insert(a[i]);
    }
    if(f){
        cout<<"YES";
    }else{
        cout<<"NO";
    }   
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    int K; cin >> K;
    int num = 7;
    int max = K;
    int counter = 1;
    vector<int> list(max);
    int ex_num = num % K;
    if (ex_num == 0){
        cout << "1" << endl;
        return 0;
    }
    list[ex_num] = 1;
    while (true){
        num = 10 * ex_num + 7;
        ex_num = num % K;
        counter++;
        if (ex_num == 0){
            cout << counter << endl;
            break;
        }
        if(list[ex_num] > 0){
            cout << "-1" << endl;
            break;
        }
        else {
            list[ex_num] = 1;
        }
        if(counter > K){
            cout << "-1" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 7220
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
l = inp.shift().split(' ')
A = l[0] * 1
B = l[1] * 1
max = A + B
if (max < A - B) {
    max = A - B
}
if (max < A * B) {
    max = A * B
}
if (max === 0) {
    max = 0
}
console.log(max)

Measured memory_bytes: 7372
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    var(string, s);

    i64 cnt[3]{};
    rep(i, 0, N) {
        if (s[i] == 'R') cnt[0]++;
        if (s[i] == 'G') cnt[1]++;
        if (s[i] == 'B') cnt[2]++;
    }

    i64 ans = cnt[0] * cnt[1] * cnt[2];
    rep(i, 0, N) rep(j, i + 1, N) {
        const int k = j + (j - i);
        if (k >= N) continue;
        if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) --ans;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(void)
{
	char a[4][4];
	int i;
	for(i=0; i<3; i++){
		scanf("%s",a[i]);
	}
	printf("%c%c%c\n",a[0][0],a[1][1],a[2][2]);
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vl;
typedef pair<long long, long long> pl;
typedef vector<vector<long long>> matrix;

#define F 						first
#define S 						second
#define PB 						push_back
#define MP 						make_pair
#define all(c) 					c.begin(), c.end()
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define tr(c,i) 				for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) 			(c.find(x) != c.end())	//for set and map
#define cpresent(c,x) 			(find(all(c),x) != c.end())	//for vectors
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon 				1e-9
#define MOD						(ll)1e9

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	doublade();
	// w(t) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		ll ans = max(b*d, max(a*c, max(a*d, b*c)));
		cout<<ans<<"\n";
	// }
	return 0;
}	

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector <ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <vector<ll>> vv;
typedef vector <string> vs;
typedef vector <char> vc;


ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl


/*--------------------template--------------------*/

ll v[10][10];

map<ll, ll> mp;

int main() {
    cin >> n >> m;
    REP(i, 10) {
        REP(j, 10) {
            cin >> v[i][j];
        }
    }
    REP(i, 10) {
        mp[i] = 0;
    }
    REP(i, n*m) {
        cin >> k;
        if (k != -1) {
            mp[k]++;
        }
    }

    REP(i, 10) {
        REP(j, 10) {
            REP(k, 10) {
                v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
            }
        }
    }
    FOR(i, 0, 10) {
        ans += (v[i][1] * mp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <uint_fast64_t MOD> class ModInt {
    using u64 = uint_fast64_t;

  public:
    u64 val;

    ModInt(const u64 x = 0) : val((x + MOD) % MOD) {}
    constexpr u64 &value() { return val; }
    constexpr ModInt operator-() { return val ? MOD - val : 0; }
    constexpr ModInt operator+(const ModInt &rhs) const {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt &rhs) const {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt &rhs) const {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt &rhs) const {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt &operator+=(const ModInt &rhs) {
        val += rhs.val;
        if(val >= MOD) {
            val -= MOD;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &rhs) {
        if(val < rhs.val) {
            val += MOD;
        }
        val -= rhs.val;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &rhs) {
        val = val * rhs.val % MOD;
        return *this;
    }

    constexpr ModInt &operator/=(const ModInt &rhs) {
        *this *= rhs.inv();
        return *this;
    }

    constexpr bool operator==(const ModInt &rhs) {
        return this->val == rhs.val;
    }
    constexpr bool operator!=(const ModInt &rhs) {
        return this->val != rhs.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) {
        return os << x.val;
    }
    friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) {
        return is >> x.val;
    }

    constexpr ModInt inv() const { return ModInt(*this).pow(MOD - 2); }

    constexpr ModInt pow(ll e) const {
        u64 x = 1, p = val;
        while(e > 0) {
            if(e % 2 == 0) {
                p = (p * p) % MOD;
                e /= 2;
            } else {
                x = (x * p) % MOD;
                e--;
            }
        }
        return ModInt(x);
    }
};

using mint = ModInt<MOD>;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    mint sum = 0;
    rep(i, N) sum += mint(A[i]);
    mint res = 0;
    rep(i, N) { res += mint(A[i]) * (sum - mint(A[i])); }
    res /= 2;
    cout << res << endl;
}

Measured memory_bytes: 4840
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/23/20 20:47:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 1e9;
constexpr int dir[4][2] = {
    {1,0},
    {-1,0},
    {0,1},
    {0,-1}
};

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

  int n; cin>>n;

  vector<vector<int>> H(n, vector<int>(n));
  vector<vector<bool>> exist(n, vector<bool>(n, true));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      H[i][j] = min({
        i,n-1-i,
        j,n-1-j
      });
    }
  }

  int ans = 0;
  for (int i = 0; i < n*n; i++) {
    int p; cin>>p; p--;
    int row = p/n;
    int col = p%n;
    ans += H[row][col];
    exist[row][col] = false;

    queue<pair<int,int>> qs;
    qs.emplace(row, col);
    while (not qs.empty()) {
      auto [r,c] = qs.front(); qs.pop();
      auto nh = H[r][c] + (exist[r][c] ? 1 : 0);
      for (auto d:dir) {
        auto nr = r+d[0];
        auto nc = c+d[1];
        if (nr < 0 or nr >= n or nc < 0 or nc >= n)
          continue;
        if (nh >= H[nr][nc])
          continue;
        H[nr][nc] = nh;
        qs.emplace(nr,nc);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
int main() {
 
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c)cout<<"Yes"<<endl;
	else if(a!=b&&b==c)cout<<"Yes"<<endl;
	else if(a==c&&a!=b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


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

	if(A>8 || B>8){
		printf(":(\n");
	}else{
		printf("Yay!\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	int w, h, n, x, y, a, m[4] = {};
	cin >> w >> h >> n;
	m[1] = w;	m[3] = h;
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		switch (a) {
		case 1: m[0] = max(m[0], x);	break;
		case 2: m[1] = min(m[1], x);	break;
		case 3: m[2] = max(m[2], y);	break;
		case 4: m[3] = min(m[3], y);	break;
		}
	}
	w = w - m[0] - (w - m[1]);
	h = h - m[2] - (h - m[3]);
	if (w <= 0 || h <= 0) {
		cout << 0 << endl;
	}
	else {
		cout << w * h << endl;
	}
	return 0;
}

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

int main() {
    int i, j, n, m;
    cin >> n >> m;
    int a[n][m], b[m], c[n];

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

    for(i=0; i<n; ++i) {
        c[i] = 0;
        for(j=0; j<m; ++j) {
            c[i] += a[i][j] * b[j];
        }
        cout << c[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int mn, mx=1e9, n, m, a, b, arr[100002];
int main()
{
    IOS
    //freopen("planet.in", "r", stdin);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        arr[a]++;
        arr[b+1]--;
    }
    for (int i = 1; i <= n; ++i) {
        arr[i] += arr[i-1];
    }
    int cnt = 0;
    for (int i = 0; i <= n; ++i) {
        if (arr[i]==m) {
            cnt++;
        }
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 640
#!/usr/bin/ruby
n,k=gets.split.map &:to_i
s=gets.chomp.chars.map(&:ord)
l=0
while k>0&&l<n
	if (s[l]+l)%2>0
		s[l]^=3
		break if 0==k-=1
	end
	l+=1
	k-=1
end
s=s.rotate(l%n)
if l%2>0
	s=s.map{|e|e^3}
end
if (n*k)%2>0
	s[0]^=3
end
puts s.map(&:chr)*''

Measured memory_bytes: 27900