akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	char s[15]={0};
	cin>>s;
	if(s[0]!='A')
	{
		cout<<"WA"<<endl;
		return 0;
	}
	int f=0,i=1;
	for(;s[i+1]!=0;i++)
	{
		if(s[i]<91&&f==0&&i!=1)
		{
			f=1;
		}
		else if(s[i]<91&&(f==1||i==1))
		{
			cout<<"WA"<<endl;
			return 0;
		}
	}
	if(f==0||s[i]<91)
	{
		cout<<"WA"<<endl;
		return 0;
	}
	cout<<"AC"<<endl;
	return 0;
}

Measured memory_bytes: 888
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long[] x = new long[n];
		for(int i = 0; i < n; i++){
		    x[i] = sc.nextLong();
		}
		
		// 計算
		long result = Long.MAX_VALUE;
		for(int i = 1; i < 101; i++){
		    long temp = 0;
		    for(int j = 0; j < n; j++){
		        temp += (x[j]-i)*(x[j]-i);
		    }
		    result = min(result, temp);
		}
		
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23252
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  string S;
  cin >> S;
  int l = S.size();
  int cnt = 0;
    rep(i,l/2){
      if(S.at(i)!=S.at(l-i-1))cnt++;
    }
  cout << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int x[100010],n,m;
vector<long long> v;
int main(){
	int i;
	cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> x[i];
	}
	sort(x,x + m);
	for(i=1;i<m;i++){
		v.push_back(x[i] - x[i-1]);
	}
	sort(v.begin(),v.end());
	long long ans = 0;
	for(i=0;i<m - n;i++){
		ans += v[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mp make_pair
#define REPP(i,l,r,c) for (int i=l;i<r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define REPS(i,l,r) REP(i,l,r+1)
#define FOR(i,n) REP(i,0,n)
#define REPD(i,l,r) for (int i=r-1;i>=l;i--)
#define FORD(i,n) REPD(i,0,n)
#define FOREACH(i,n) for (auto i:n)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const int INF=(int)1E9;
const double INFD=1E9;
const ll INFLL=(ll)1E15;
const ll MOD=(ll)1E9+7;
const long double PI=acos(-1);
const long double EPS=1E-9;

bool between(int x,int l,int r) {
	return (l<=x && x<=r);
}

string tostring(int x) {
	char dum[20]; sprintf(dum,"%d",x);
	string ret(dum); return ret;
}

inline void work(int kasus) {
	
//	printf("Case #%d:",kasus);
}

int n;
int A[100010];
set<int> S;
map<int,int> P,Q;

int main() {
//	int kasus; scanf("%d",&kasus); REPS(ik,1,kasus) work(ik);
	scanf("%d",&n); FOR(i,n) {
		scanf("%d",A+i), S.insert(A[i]);
		if (i&1) P[A[i]]++; else Q[A[i]]++;
	}
	if (S.size()==1) {
		printf("%d\n",n/2); return 0;
	}
	int ans=INF;
	int kaya=-INF, p;
	FOREACH(data,P) {
		if (kaya<data.se) kaya=data.se, p=data.fi;
	}
	int kaya2=-INF, q;
	FOREACH(data,Q) {
		if (kaya2<data.se) kaya2=data.se, q=data.fi;
	}
	if (p!=q) {
		printf("%d\n",n-kaya-kaya2); return 0;
	}
	{
		int temp=n/2-kaya;
		int asd=-INF;
		FOREACH(data,Q) {
			if (data.fi==p) continue;
			asd=max(asd,data.se);
		}
//		printf("%d %d\n",temp,asd);
		if (asd!=-INF) temp+=n/2-asd, ans=min(ans,temp);
	}
	{
		int temp=n/2-kaya2;
		int asd=-INF;
		FOREACH(data,P) {
			if (data.fi==q) continue;
			asd=max(asd,data.se);
		}
//		printf("%d %d\n",temp,asd);
		if (asd!=-INF) temp+=n/2-asd, ans=min(ans,temp);
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int F[50];
  F[0] = F[1] = 1;
  for (int i = 2; i <= n; i++)
    F[i] = F[i - 1] + F[i - 2];
  cout << F[n] << endl;
  return 0;
}



Measured memory_bytes: 3208
///Bismillahir Rahmanir Rahim

#include<iostream>

using namespace std;
int main()
{
    int x1,x2,x3,x4,x5;

    cin>>x1>>x2>>x3>>x4>>x5;

    if(x1==0)
    {
        cout<<"1";
    }
    else if(x2==0)
    {
        cout<<"2";
    }
    else if(x3==0)
    {
        cout<<"3";
    }
    else if(x4==0)
    {
        cout<<"4";
    }

    else
    {
        cout<<"5";
    }

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <sstream>
#include <cctype>
using namespace std;
int main(){
	string W, Wt;
	cin >> W;
	int co = 0;
	while(cin >> Wt){
		if (Wt == "END_OF_TEXT")break;
		for (int i = 0; i < Wt.size(); i++){
			Wt[i] = tolower(Wt[i]);
		}
		if (Wt == W)co++;
	}
	cout << co << endl;
}


Measured memory_bytes: 3156
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    string S;
    cin >> S;
    if(S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0;i<n;i++)
#define P pair<ll,ll>
#define F first
#define S second
#define all(a) (a.begin(),a.end())
long long INF=1000000000000000000;
long long mod=1000000007;
int dp[1010][1010];
int main(void){
    int q;cin>>q;string x,y;
    rep(k,q){
        cin>>x>>y;
        rep(i,1010)rep(j,1010)dp[i][j]=0;
        
        rep(i,x.size())rep(j,y.size()){
            if(x[i]==y[j])dp[i+1][j+1]=dp[i][j]+1;
            else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
        cout<<dp[x.size()][y.size()]<<endl;
    }
}


Measured memory_bytes: 7120
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// << fixed << setprecision
// --------------------------------------
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<ll> a(n);

  REP(i, n) {
    double t;
    cin >> t;
    a[i] = (ll)llround(t * 1e9);
  }


  vector<vector<ll>> cnt(20, vector<ll>(20, 0LL));
  REP(i, n) {
    ll x = a[i];

    int t = 0;
    while(x % 2 == 0 && t < 18) {
      t++;
      x /= 2;
    }

    int f = 0;
    while(x % 5 == 0 && f < 18) {
      f++;
      x /= 5;
    }

    cnt[t][f]++;
  }

  ll ans = 0;
  REP(t1, 19) REP(f1, 19) REP(t2, 19) REP(f2, 19) {
    if (t1 + t2 < 18 || f1 + f2 < 18) continue;

    if (t1 == t2 && f1 == f2) {
      ans += cnt[t1][f1] * (cnt[t1][f1] - 1);
    } else {
      ans += cnt[t1][f1] * cnt[t2][f2];
    }
  }

  ans /= 2;
  cout << ans << endl;
}


Measured memory_bytes: 4772
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n,a; cin >> n >> a;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(n+1, vector<ll>(2525,0)));
    dp[0][0][0]=1;
    rep(i,n){
        rep(j,n+1){
            rep(k,2525){
                //select
                if(k-x[i]>=0&&j-1>=0) dp[i+1][j][k]+=dp[i][j-1][k-x[i]];
                dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    ll ans=0;
    rep(i,n+1){
        ans+=dp[n][i][a*i];
    }
    cout << ans-1 << endl;
}




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


int main() {
    string t,s;
    cin >> s >> t;
    int ans = t.size();
    for (int i=0; i<s.size()-t.size()+1; i++){
        int cnt=0;
        for (int j=0; j<t.size(); j++) {
            if (s[i+j] != t[j]) cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

  int count = 0;
  for (int i = 0; i < (int)S.length(); i++) {
    if (S[i] != T[i]) count++;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3924
import java.io.*;
import java.util.*;

public class Main {

	static long m = (long) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		HashSet<String> hs = new HashSet<>();
		for (int i = 0; i < n; i++)
			hs.add(scn.next());
		System.out.println(hs.size());
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

Measured memory_bytes: 72056
import collections
n=int(input())
s=[]
for i in range(n):
  S=input()
  s.append(S)

c = collections.Counter(s)
l=c.most_common()
x=[l[0][0]]
for i in range(1,len(l)):
  if l[i-1][1]==l[i][1]:
    x.append(l[i][0])
  else:
    break
x.sort()    
for i in x:
  print(i)

Measured memory_bytes: 47672
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;

int n;
ll a[N];
ll sum = 0;
vector < pair < ll, ll > > v;

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


    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        sum += a[i];
    }
    sort(a + 1, a + 1 + n);

    for (int i = 2; i < n; ++i)
    {
        if (a[i] > 0)
        {
            v.push_back({a[1], a[i]});
            a[1] -= a[i];
        }
    }
    v.push_back({a[n], a[1]});
    a[n] -= a[1];
    for (int i = 2; i < n; ++i)
    {
        if (a[i] <= 0)
        {
            v.push_back({a[n], a[i]});
            a[n] -= a[i];
        }
    }
    cout << a[n] << endl;
    for (auto t: v)
    {
        cout << t.x << ' ' << t.y << endl;
    }
    return 0;
}


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

int main(){
  int n,t,a;
  cin >> n >> t >> a;
  t *= 1000;
  a *= 1000;
  int h[n];
  for(int i = 0; i < n; ++i){
    cin >> h[i];
  }
  
  int c = 100000000;
  int res = 0;
  
  for(int i = 0; i < n; ++i){
    int temp = t - 6 * h[i] - a;
    //cout << temp << " " << c << endl;
    if(abs(temp) < c){
      res = i;
      c = abs(temp);
    }
  }
  
  ++res;
  cout << res << endl;
}

Measured memory_bytes: 3588
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	t, x := nextInt(), nextInt()
	fmt.Println(float64(t) / float64(x))
}


Measured memory_bytes: 640
N,K=map(int,input().split())
H=[0]+[int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    if i-K < 1:
        starter=1
    else:
        starter=i-K

    lists=[dp[i]]+[dp[x]+abs(H[x]-H[i]) for x in range(starter,i)]

    dp[i] = min(lists)


print(dp[N])



Measured memory_bytes: 57312
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N, M;
  cin >> N >> M;
  priority_queue<int> pq;
  vector<ll> V[100000];
  rep(i, N){
    ll a, b;
    cin >> a >> b; a--;
    V[a].push_back(b);
  }
  ll ans = 0;
  rep(i, M){
    for(int b : V[i]) pq.push(b);
    if (!pq.empty()) {ans+=pq.top(); pq.pop();}
  }
  cout << ans << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for (int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back

int n, k, q, A[2005], ans = 1e9+100;

int check(int g) {
	vector<int> v, vv;
	v.clear(); vv.clear();
	int pre = 0;
	FOR(i, 1, n+1) {
		if (A[i] >= g) vv.pb(A[i]);
		else {
			sort(vv.begin(), vv.end(), greater<int>());
			FOR(j, 1, i-pre-k) {v.pb(vv.back()); vv.pop_back();}
			vv.clear();
			pre = i;
		}
	}
	sort(v.begin(), v.end());
	if (v.size() < q) return 1e9+100;
	else return (v[q-1] - g);
}

int main() {
	cin >> n >> k >> q;
	FOR(i, 1, n) cin >> A[i];
	A[n+1] = -1;
	FOR(i, 1, n) ans = min(ans, check(A[i]));
	cout << ans;
}


Measured memory_bytes: 256
/*************************************************************************
    > File Name: E.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-12-22 20:12:24
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,k,a[MAXN],t;
ll pre[MAXN],suf[MAXN];
P st[MAXN];
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    pre[1]=1;
    t=0;
    for(ll i=2;i<=n;i++)
    {
        if(a[i-1]>=a[i])
        {
            ll dummy=a[i],need=0;
            while(dummy<=a[i-1]) dummy*=4,need++;
            need--;
            if(need>0) st[t++]=P(i,need);
            pre[i]=pre[i-1]+1;
        }
        else
        {
            ll need=0,dummy=a[i-1];
            while(dummy<a[i]) dummy*=4,need++;
            ll pos=i;
            while(t>0&&need>0) 
            {
                pre[i]+=2*need*(pos-st[t-1].F);
                if(st[t-1].S>need) {st[t-1].S-=need; need=0; break;}
                else
                {
                    need-=st[t-1].S;
                    pos=st[t-1].F;
                    t--;
                }
            }
            if(need>0) pre[i]+=2*need*(pos-1);
            pre[i]+=pre[i-1]+1;
        }
    }
    suf[n]=0;
    t=0;
    for(ll i=n-1;i>=1;i--)
    {
        if(a[i+1]>=a[i])
        {
            ll dummy=a[i],need=0;
            while(dummy<=a[i+1]) dummy*=4,need++;
            need--;
            if(need>0) st[t++]=P(i,need);
            suf[i]=suf[i+1];
        }
        else
        {
            ll need=0,dummy=a[i+1];
            while(dummy<a[i]) dummy*=4,need++;
            ll pos=i;
            while(t>0&&need>0) 
            {
                suf[i]+=2*need*(st[t-1].F-pos);
                if(st[t-1].S>need) {st[t-1].S-=need; need=0; break;}
                else
                {
                    need-=st[t-1].S;
                    pos=st[t-1].F;
                    t--;
                }
            }
            if(need>0) suf[i]+=2*need*(n-pos);
            suf[i]+=suf[i+1];
        }
    }
    ll ans=min(suf[1],pre[n]);
    for(ll i=1;i<=n-1;i++) ans=min(ans,pre[i]+suf[i+1]);
    printf("%lld\n",ans);
    return 0;
}



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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

int Pow(int a, int b, int mod)
{
	int x = 1;
	for (; b > 0; b >>= 1)
	{
		if (b&1) x = (ll)x * a % mod;
		a = (ll)a * a % mod;
	}
	return x;
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);

	map<int, int> mp;
	for (auto &i : a)
	{
		cin >> i;
		int x = i;

		for (int j = 2; j*j <= x; ++j)
			if (x % j == 0)
			{
				int c = 0;
				while (x % j == 0) x /= j, ++c;
				mp[j] = max(mp[j], c);
			}
		if (x > 1)
			mp[x] = max(mp[x], 1);
	}

	const int mod = 1e9+7;
	int m = 1;
	for (auto &i : mp)
		for (int j = i.S; j--; )
			m = (ll)m * i.F % mod;

	int ans = 0;
	for (auto &i : a)
		ans = (ans + (ll)m * Pow(i, mod-2, mod)) % mod;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 768
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run() {
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			String num1 = sc.next();
			String num2 = sc.next();
			String ans = rev(add(rev(num1),rev(num2)));
			if (ans.length() > 80) ans = "overflow";
			System.out.println(ans);
		}
	}
	
	String rev(String str) {
		String rev = "";
		for(int i=str.length()-1;i>=0;i--)
			rev += str.charAt(i);
		return rev;
	}
	
	String add(String num1, String num2) {
		String n1,n2;
		if(num1.length()-num2.length()>0) { n1 = num1; n2 = num2; }
		else { n1 = num2; n2 = num1; }
		String num = "";
		int n = 0;
		
		for (int i=0;i<n2.length();i++) {
			num += ( n + (n1.charAt(i)-'0') + (n2.charAt(i)-'0') ) % 10;
			n = ( n + (n1.charAt(i)-'0') + (n2.charAt(i)-'0') ) / 10;
		}
		
		for (int i=n2.length();i<n1.length();i++) {
			num += ( n + (n1.charAt(i)-'0') ) % 10;
			n = ( n + (n1.charAt(i)-'0') ) / 10;
		}
		if(n == 1) num += 1;
		return num;
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 12000
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    set<int> S;
    int q; cin >> q;
    REP(i, q){
        int op, x, y; cin >> op >> x;
        switch(op){
            case 0:
                S.insert(x);
                cout << S.size() << endl;
                break;
            case 1:
                cout << noboolalpha << (S.find(x) != S.end()) << "\n";
                break;
            case 2:
                S.erase(x);
                break;
            case 3:
                cin >> y;
                for(auto itr = S.lower_bound(x); itr != S.end(); ++itr){
                    if(x <= *itr && *itr <= y)
                        cout << *itr << "\n";
                    if(y <= *itr)
                        break;
                }
        }
    }
    return 0;
}



Measured memory_bytes: 12448
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    string S,T;
    while (cin >> S >> T) {
        const int n = S.size();
        const int m = T.size();
        string ans = "";
        FOR(i,0,n) if (i+m <= n) {
            bool isfit = true;
            FOR(j,0,m)
                isfit &= S[j+i] == '?' || S[j+i] == T[j]; 
            if (isfit) {
                string res;
                FOR(j,0,i) {
                    if (S[j] == '?')
                        res += "a";
                    else
                        res += string(1,S[j]);
                }
                res += T;
                FOR(j,i+m,n) {
                    if (S[j] == '?')
                        res += "a";
                    else
                        res += string(1,S[j]);
                }
                if (ans == "")
                    ans = res;
                else
                    ans = min(ans,res);
            }
        }
        if (ans == "")
            cout << "UNRESTORABLE" << endl;
        else
            cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int W,H,x,y,r,i=0;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if(x-r<0)i=1;
	if(y-r<0)i=1;

	if(W-x-r<0)i=1;
	if(H-y-r<0)i=1;

	
	if(i==1){
		printf("No\n");
	}else{
		printf("Yes\n");
	}

	return 0;
}

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


int main(){
ll A, B,C;
cin>>A>>B>>C;
ll ans;
if(A%2==0 ||B%2==0||C%2==0)ans = 0;
else{
vector<ll> a(3);
a[0]=A;
a[1]=B;
a[2]=C; 
sort(a.begin(),a.end());
ans = a[0]*a[1];
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
mod = 10**9+7


y = []
for i in range(1,n):
    y.append(x[i]-x[i-1])

#p:倍率
#q:倍率積
p = []
q = 1
last = 1
fac = 1

for i in range(2,n):
    last = (last*i+fac)%mod
    fac = fac*i%mod
    p.append(last*pow(fac*q,mod-2,mod)%mod)
    q = q*p[-1]%mod


res = 0
r = fac
for i in range(n-1):
    res = (res + y[i]*r)%mod
    if i != n-2:
        r = (r*p[i])%mod
print(res%mod)


Measured memory_bytes: 73880
N, x = map(int, input().split())
a_list = list(map(int, input().split()))

#%%
ans = 0
a_list.sort()

for a in a_list:
    x = x - a
    if x < 0:
        break
    ans += 1

if x > 0 and ans == N:
    ans -= 1

print(ans)

Measured memory_bytes: 38256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		long a = sc.nextInt();
      long b = sc.nextInt();
      long c = sc.nextInt();
      long d = sc.nextInt();

      long stock;
        stock = a*c;

      if(a*d >= stock){
        stock = a*d;
      }
	if(b*d >= stock){
        stock = b*d;
      }
      if(b*c >= stock){
        stock = b*c;
      }
System.out.println(stock);
	}
}

Measured memory_bytes: 35648
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool check(string s, char c);

int main()
{
	string s;
	cin >> s;

	int ans = 1010101010;
	string t, t_;
	for (char c = 'a'; c <= 'z'; c++) {
		t = s;

		for (int i = 0; i < s.length(); i++) {
			if (check(t, c)) {
				ans = min(i, ans);
				break;
			}

			t_ = "";
			for (int j = 0; j < t.length() - 1; j++) {
				if (t[j] == c || t[j + 1] == c) {
					t_ += c;
				} else {
					t_ += t[j];
				}
			}
			t = t_;
		}
	}
	cout << ans << endl;

	return 0;
}

bool check(string s, char c)
{
	bool ret = true;

	for (char sc : s) {
		if (sc != c) {
			ret = false;
			break;
		}
	}
	return ret;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

def main():
    n = int(input())

    A = sorted(map(int, input().split()))
    counter = Counter(A)

    ans = 0
    maxi = max(A)
    cache = set()
    for a in A:
        if a in cache:
            continue

        x = a
        while x <= maxi:
            cache.add(x)
            x += a

        if counter[a] == 1:
            ans += 1

    print(ans)

main()


Measured memory_bytes: 102700
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int ans = 0, a = 0;
  REP(i, 3){
    if(s[i] == 'S'){
      a = 0;
    }else{
      a++;
    }
    chmax(ans, a);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    vector<int> dp(1000001, 1e9);
    vector<int> dp2(1000001, 1e9);
    dp[0] = dp2[0] = 0;
    for(int i=1; i*(i+1)*(i+2)/6 <= 1000000; ++i) {
        int l = i*(i+1)*(i+2)/6;
        for(int j=0; j+l<=1000000; ++j) {
            dp[j+l] = min(dp[j+l], dp[j] + 1);
        }
        if(l % 2 == 1) {
            for(int j=0; j+l<=1000000; ++j) {
                dp2[j+l] = min(dp2[j+l], dp2[j] + 1);
            }
        }
    }


    int n;
    while(cin >> n, n) {
        cout << dp[n] << " " << dp2[n] << endl;
    }
}


Measured memory_bytes: 10568
#include<iostream>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)

int main(){
	long long n,sum=0,num;
	cin>>n;
	rep(i,n){
		cin>>num;
		sum+=num;
	}
	cout<<sum/n<<endl;
	return 0;
}

Measured memory_bytes: 1156
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a<=b)
		cout<<a<<endl;
	else
		cout<<a-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
vector<string> v;

void dfs(string s, char curMax) {
    if (s.size() == n) {
        cout << s << endl;
    } else {
        for (char c = 'a'; c <= curMax; c++) {
            dfs(s+c, ((c == curMax) ? (char)(curMax + 1) : curMax));
        }
    }
}

int main() {
    cin >> n;
    dfs("", 'a');
}


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

#include<map>
#include<set>
#include<iomanip>
#include<cstdio>
#include<sstream>
#include<cstring>

#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<bitset>
#include<numeric>
#include<utility>
#include<cstdlib>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);


	double n, d,ans=0;
	cin >> n >> d;
	vector<double> x(n), y(n),c(n);
	for(int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
		if(sqrt(x[i] * x[i] + y[i] * y[i]) <= d)
			++ans;
	}
	cout << ans << endl;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    string s;

    cin>> s;

    if(s[0] != 'A' )
    {
        cout<< "WA\n";
        return 0;
    }

    int cn= 0;

    for(int i=1; i<s.size(); i++)
    {
        if (i>=2 && i<= (s.size() -2 ))
        {
            if(s[i]== 'C')
            {
                cn++;
                continue;
            }
        }

        if(s[i]< 'a' || s[i] > 'z'  || cn>1)
        {
            {
                cout<< "WA\n";
                return 0;
            }
        }
    }


    cout<< (cn==1?  "AC\n" : "WA\n");

    return 0;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int n;
	cin >> n;
	vector<int> v(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> v[i];
	map<int, int> mp;
	ll cnt = 0;
	for (int i = 1; i <= n; i++) {
		cnt += mp[i - v[i]];
		mp[i + v[i]]++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 20996
#include<stdio.h>
int main(void){
int r,i,t;
int n[3];
scanf("%d %d %d",&n[0],&n[1],&n[2]);
for(r=2;r>=0;r--){
for(i=0;i<r;i++){
if(n[i]>n[r]){
t=n[r];
n[r]=n[i];
n[i]=t;
}
}
}
printf("%d %d %d\n",n[0],n[1],n[2]);
return 0;
}

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut a: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut bc: Vec<(u64,u64)> = (0..m).map(|_| (read(),read())).collect();

    a.sort();
    bc.sort_by(|x,y| y.1.partial_cmp(&x.1).unwrap());
    let mut b: Vec<u64> = Vec::new();
    for i in 0..m{
        for _ in 0..bc[i].0{
            b.push(bc[i].1);
        }
        if b.len() >= n{
            break;
        }
    }

    let mut ans = 0;
    for i in 0..n{
        if b.len() <= i{
            ans += a[i];
        }else{
            ans += std::cmp::max(a[i],b[i]);
        }
    }
    println!("{}",ans);

}


Measured memory_bytes: 5852
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    s += s;
    for (int i = 0; i < s.length(); i++) {
        string subs = s.substr(i, t.length());
        if (subs == t) {
            Yes;
            return 0;
        }
    }
    No;
    return 0;
}


Measured memory_bytes: 256
ans=[]
numLst=[512,256,128,64,32,16,8,4,2,1]
while True:
    ansLst=[]
    try:
        n=input()
    except EOFError:
        break
    for i in numLst:
        if n>= i:
            ansLst.append(str(i))
            n-=i
        if n==0:
            break
    ans.append(' '.join(reversed(ansLst)))
for i in ans:
    print i

Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
int main() {
  int c=0;
  string s; cin>>s;
  for(int i=0;i<s.size();i++) if((i%2&&s[i]=='1')||(i%2==0&&s[i]=='0')) c++;
  cout<<min(c,(int)s.size()-c);
}

Measured memory_bytes: 3756
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt
  
    // 0 0が入力された
    if(!width && !height){
      break;
    }
  
    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
      
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];
  
        switch(c){
        case 'S':
          start = pos(x, y);
          break;
        case 'G':
          goal = pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c - 1][elem[c - 1].length] = pos(x, y);
          break;
        }
      }
    }
  
      
    var bestElement = -1;
    var distance = Infinity;
      
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = Infinity;
        }
      }
        
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;
  
      var firstLength = elem[first].length;
      for (var j = 0; j < firstLength; j++) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
        
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        var nowLength = elem[now].length;
        var nextLength = elem[next].length;
        for (var j = 0; j < nowLength; j++) {
          for (var k = 0; k < nextLength; k++) {
            dp[next][k] = fmin(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
        
      var last = (first + 3) % 5;
      var lastLength = elem[last].length;
      for (var j = 0; j < lastLength; j++) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
          
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
          
      }
        
    }
      
    if (distance == Infinity) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }
  
    i++;
  }
    
  
}
  
function dist(from, to){
  return fabs((from >> 11) - (to >> 11)) + fabs((from & 2047) - (to & 2047));
}
  
function fmin(a1, a2){
  return a1 > a2 ? a2 : a1;
}
  
function pos(a, b){
  // 2^10 = 1024なので、下位10ビットでy座標を、上位ビットでx座標を表す
  return (a << 11) + b;
}
 
function fabs(a){
 var mask = a >> 31;
 return (a ^ mask) - mask;
}
  
var
input = '';
  
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 51456
# coding: utf-8
import math

a, b, x = [int(y) for y in input().split(" ")]

if a * a * b == x:
    print(0)
else:
    if a * a * b <= 2 * x:
        t = (a * a * a / (a * a * b - x)) / 2
        print(90 - math.degrees(math.atan(t)))
    else:
        t = 2 * (x / (a * b * b))
        print(90 - math.degrees(math.atan(t)))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	if (a[0] + a[1] + a[2] >= 22)
		printf("bust\n");
	else
		printf("win\n");
	return 0;
}

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

int main(int argc, char const *argv[])
{
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (
        (x-r) >= 0 && (y-r) >= 0 &&
        (x+r) <= W && (y+r) <= H
    ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

struct Point {
    int x;
    int y;
};


int main() {
    
    int H,W,D;
    cin >> H >> W >> D;
    vector< Point > V(H*W+1);
    for ( int y = 0; y < H; y++ ) {
    for ( int x = 0; x < W; x++ ) {
        int a;
        cin >> a;
        Point p;
        p.x = x;
        p.y = y;
        V[a] = p;
    }
    }

    vector<int> S(H*W+1,0);
    for ( int i = 1; i <= D; i++ ) {
        for ( int j = 1; i+j*D <= H*W; j++ ) {
            S[i+j*D] = S[i+(j-1)*D] + abs( V[i+j*D].x-V[i+(j-1)*D].x ) + abs( V[i+j*D].y-V[i+(j-1)*D].y );
        } 
    }

    vector<long long> A;
    int Q;
    cin >> Q;
    for ( int i = 0; i < Q; i++ ) {
        int l,r;
        cin >> l >> r;        
        A.push_back( S[r] - S[l] );
    }
    for ( int i = 0; i < Q; i++ ) {
        cout << A[i] << endl;
    }

    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *NodePointer;

NodePointer root = NULL;

NodePointer make_1node(int, NodePointer);
void insert(int);
void inorder(NodePointer);
void preorder(NodePointer);

int main(){
  int command_num, key, i;
  char command[10];

  scanf("%d",&command_num);
  for(i = 1; i <= command_num; i++){
    scanf("%s",command);
    if( strcmp(command,"print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if( strcmp(command,"insert") == 0 ){
      scanf("%d",&key);
      insert(key);
    }
  }
  
  return 0;
}

void insert(int key){
  NodePointer x=root, y=NULL;

  while( x != NULL ){
    y = x;
    if( key < x->key ) x = x->left;
    else x = x->right;
  }
  if( y == NULL ) root = make_1node(key, NULL); //Tree is empty
  else if( key < y->key ) y->left = make_1node(key, y);
  else y->right = make_1node(key, y);
}

NodePointer make_1node(int key, NodePointer parent){
  NodePointer newnode;
  newnode = (NodePointer)malloc( sizeof(struct node) );
  newnode->parent = parent;
  newnode->right = NULL;
  newnode->left = NULL;
  newnode->key = key;
  return newnode;
}

void inorder(NodePointer x){
  if( x != NULL ){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(NodePointer x){
  if( x != NULL ){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}


Measured memory_bytes: 25148
I = input()

n     = len(I)
left  = 0
right = n - 1

block_left_index  = 0
block_right_index = n

## Example:
## 000011000
## |     |
##    or
##     |    |
while left < right:
    if I[left] != I[left+1]:
        block_left_index = left+1
    if I[right] != I[right-1]:
        block_right_index = right
    left  += 1
    right -= 1

ans = min(n-block_left_index, block_right_index)
print(ans, flush=True)


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

using namespace std;

#define ll unsigned long long
#define pi pair<int, int>
#define mkp make_pair
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  998244353;
ll arr[mxn];
int n, m, k, q;
string s, t;
int x, y;

void solve() {
   cin >> n;
   for (int i = 0; i < n; i++) cin >> arr[i];
   ll res = 1;
   ll mx = (ll) (1e18);
   sort(arr, arr + n);
   for (int i = 0; i < n; i++) {
        if (arr[i] == 0) {
            cout << 0 << endl;
            return;
        }
        if (res <= (mx + arr[i] - 1) / arr[i]) {
            res *= arr[i];
        } else {
            cout << -1 << endl;
            return;
        }
   }
   if (res > mx) {
        cout << -1 << endl;
   } else {
        cout << res << endl;
   }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF 1e12

int N, M, P, A, B;
int T[8];
vector<pair<int, int> > E[30];

struct Comp {
	bool operator() (pair<int,double> a, pair<int, double> b) {
		return a.second > b.second;
	}
};

void solve()
{
	priority_queue<pair<int, double>, vector<pair<int, double> >, Comp> que;
	double dist[30][256];
	bool done[30][256];

	rep(i, 0, 30) rep(j, 0, 256)
	{
		dist[i][j] = INF;
		done[i][j] = false;
	}

	dist[A][0] = 0;
	que.push(make_pair(A * 10000, 0));
	while (!que.empty())
	{
		auto q = que.top(); que.pop();

		int node = q.first / 10000;
		int flag = q.first % 10000;

		if (done[node][flag]) continue;
		done[node][flag] = true;

		if (node == B)
		{
			printf("%.12f\n", q.second);
			return;
		}

		for (auto to : E[node])
		{
			rep(i, 0, N) if ((flag & (1 << i)) == 0)
			{
				int n_node = to.first;
				int n_flag = flag + (1 << i);
				double n_dist = q.second + (double)to.second / (double)T[i];

				if (done[n_node][n_flag]) continue;

				if (n_dist < dist[n_node][n_flag])
				{
					dist[n_node][n_flag] = n_dist;
					que.push(make_pair(n_node * 10000 + n_flag, n_dist));
				}
			}
		}
	}

	printf("Impossible\n");
}

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

	while (cin >> N >> M >> P >> A >> B)
	{
		if (N == 0) return 0;

		A--;
		B--;
		rep(i, 0, N) cin >> T[i];
		rep(i, 0, M) E[i].clear();
		rep(i, 0, P)
		{
			int x, y, z;
			cin >> x >> y >> z;
			x--; y--;

			E[x].push_back(make_pair(y, z));
			E[y].push_back(make_pair(x, z));
		}

		solve();
	}
}

Measured memory_bytes: 4416
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] N = new int[4];
    N[0] = sc.nextInt();
    N[1] = sc.nextInt();
    N[2] = sc.nextInt();
    N[3] = sc.nextInt();
    Arrays.sort(N);
    int[] array = {1,4,7,9};
    if(Arrays.equals(N, array)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 23892