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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

void rec(vector<string> &s, int p, int q) {
    int level = s[p].size() - 1;
    while(0 <= level && 'a' <= s[p][level] && s[p][level] <= 'z') level--;
    if (level >= 0) s[p][level] = '+';

    int i = p + 1;
    bool under = false;
    while(i < q) {
       if (s[i][level + 1] == '.') i++;
       else if ('a' <= s[p][level + 1] && s[p][level + 1] <= 'z') {
        under = true;
        break;
       }
    }

    if (under) {
        rec(s, p + 1, i);
        repl(j, p + 1, i) s[j][level] = '|';
        rec(s, i, q);
    } else {
        if (p + 1 < q) rec(s, p + 1, q);
    }
}

int main(){
    cin.sync_with_stdio(false);
    int n;
    while(cin >> n, n) {
        vector<string> s(n);
        rep(i, n) cin >> s[i];

        rec(s, 0, n);

        rep(i, n) {
            replace(all(s[i]), '.', ' ');
            cout << s[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3536
# coding: utf-8

import sys
input = sys.stdin.readline

N, M = map(int, input().split())

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while True:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)



Measured memory_bytes: 28940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string a,b;cin>>a>>b;
    ll x,y;cin>>x>>y;
    string s;cin>>s;

    if(s==a)x--;
    else y--;

    cout<<x<<" "<<y;

}




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


int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b) > (c+d)) cout << "Left" << endl;
  if((a+b) == (c+d)) cout << "Balanced" << endl;
  if((a+b) < (c+d)) cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s; i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    int n; cin >> n;
    string ans = "No\n";
    if(n/10 == 9) ans = "Yes\n";
    if(n%10 == 9) ans = "Yes\n";
    cout << ans;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int n;
ll dp[105][100005];
int arr[105][2];

ll solve(int idx, int want)
{
  if(want < 0)
    return 1e12;
  if(idx == n)
    return want == 0 ? 0 : 1e12;
  ll &ans = dp[idx][want];
  if(ans != -1)
    return ans;
  return ans = min(solve(idx + 1, want), solve(idx + 1, want - arr[idx][1]) + arr[idx][0]);
}

int main()
{
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int w;
  cin >> n >> w;
  for(int i = 0; i < n; i++)
    cin >> arr[i][0] >> arr[i][1];
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  for(int i = 1; i < 100005; i++)
  {
    ll taken = solve(0, i);
    if(taken <= w)
      ans = i;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 82304
package main

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

var mod = int64(1e9 + 7)

func main() {
	N := nextInt()
	K := nextInt()
	A := make(ints, N)
	nn := 0
	np := 0

	for i := 0; i < N; i++ {
		A[i] = nextInt64()

		if A[i] <= 0 {
			nn++
		}
		if A[i] > 0 {
			np++
		}
	}

	sort.Sort(A)

	k := 0
	ans := int64(1)

	// 答えが負になる？
	if K%2 == 1 && np == 0 {
		for i := 0; i < K; i++ {
			ans = mul(ans, A[nn-1-i])
		}
		fmt.Println(ans)
		return
	}
	// 正の数なのでできるだけ絶対値を大きくする
	p := len(A) - 1
	n := 0
	for k < K {
		// 負の数を選べる場合
		if k <= K-2 && A[n]*A[n+1] > A[p]*A[p-1] {
			ans = mul(ans, A[n])
			ans = mul(ans, A[n+1])
			k += 2
			n += 2
		} else {
			ans = mul(ans, A[p])
			p--
			k++
		}
	}

	fmt.Println(ans)
}

func mul(a, b int64) int64 {
	n := ((a % mod) * (b % mod)) % mod
	if n < 0 {
		n += mod
	}
	return n
}

type ints []int64

func (a ints) Len() int           { return len(a) }
func (a ints) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ints) Less(i, j int) bool { return a[i] < a[j] }

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

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

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 6432
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数
	long long GCD(long long a, long long b) {
		if (a < b)
			swap(a, b);
		if (b == 0) return a;
		else return GCD(b, a % b);
	}
	//素数判定
	bool sosuu_check(int num) {
		int i;
		for (i = 2; i <= sqrt(num); ++i) {
			if (num%i == 0)
				return false;
		}
		return (num < 2) ? false : true;
	}
	
	int check(int N, int a, int b) {
		int A,B,i;
		if (a > b) {
			A = a;
			B = b;
		}
		else {
			A = b;
			B = a;
		}
		for (i = N / b; i > 0; i--) {
			if ((N - b * i) % a == 0) {
				return i;
			}
		}
		return 0;
	}


int main() {
	int N,i;
	double sum=0,X;
	string Y;
	cin >> N;
	REP(i, N) {
		cin >> X >> Y;
		sum += (Y == "JPY") ? X: X *380000;
	}cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			Map<Integer, Integer> e_map = new HashMap<>();
			Map<Integer, Integer> o_map = new HashMap<>();
			for (int i = 0; i < n; i++) {
				int v = sc.nextInt();
				if (i % 2 == 0) o_map.put(v, o_map.containsKey(v) ? o_map.get(v) + 1 : 1);
				else e_map.put(v, e_map.containsKey(v) ? e_map.get(v) + 1 : 1);
			}
			int[] e_freq = e_map.entrySet()
					.stream()
					.sorted(Collections.reverseOrder(Entry.comparingByValue()))
					.mapToInt(r -> r.getKey())
					.toArray();
			int[] o_freq = o_map.entrySet()
					.stream()
					.sorted(Collections.reverseOrder(Entry.comparingByValue()))
					.mapToInt(r -> r.getKey())
					.toArray();

			int e1 = e_freq[0];
			int o1 = o_freq[0];
			int e_cnt = e_map.entrySet().stream().mapToInt(r -> r.getValue()).sum();
			int o_cnt = o_map.entrySet().stream().mapToInt(r -> r.getValue()).sum();
			if (e1 != o1) {
				System.out.println(e_cnt - e_map.get(e1) + o_cnt - o_map.get(o1));
			}
			else {
				if (e_freq.length > 1 && o_freq.length > 1) {
					int e2 = e_freq[1];
					int o2 = o_freq[1];
					int e1_o2 = e_cnt - e_map.get(e1) + o_cnt - o_map.get(o2);
					int e2_o1 = e_cnt - e_map.get(e2) + o_cnt - o_map.get(o1);
					System.out.println(Math.min(e1_o2, e2_o1));
				}
				else {
					System.out.println(n / 2);
				}
			}
		}
	}
}

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

int main()
{
	int n;
	cin>>n;
	vector<int> p(n);
	for(size_t i = 0; i<n; i++)
	{
		cin>>p[i];
	}
	int ans = 1;
	int min = p[0];
	for(size_t i = 1; i<n; i++)
	{
		if(min>=p[i])
		{
			ans++;
			min = p[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;

long long int ans[] = {1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000};

int main(){
  int a;
  scanf("%d", &a);
  printf("%lld\n", ans[a - 1]);
  return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
int mi=INT_MAX;
bool xx=false;
void recursrion(int index ,int currSum,int K,vector < pair< int , vector<int> > > &arr,vector<int> Books,int N,int M)
{
    if(index>=N){return ;}
    recursrion(index+1,currSum,K,arr,Books,N,M);
    int cost=arr[index].first;
    currSum+=cost;
    vector<int> x=arr[index].second;
    for(int i=0;i<M;i++)
    {
        Books[i]+=x[i];
    }
    int FLAG=0;
    for(int i=0;i<M;i++)
    {
        if(Books[i]<K)
        {
            FLAG=1;
            break;
        }
    }
    if(FLAG==0)
    {
        xx=true;
        mi=min(mi,currSum);
    }
    recursrion(index+1,currSum,K,arr,Books,N,M);
    return ;
}
int main()
{
    // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int N,M,K;
    cin>>N>>M>>K;
    vector < pair < int , vector<int> > > arr;
    for(int i=0;i<N;i++)
    {
        int x;
        cin>>x;
        vector<int> S(M);
        for(auto &it:S)
        {
            cin>>it;
        }
        arr.push_back(make_pair(x,S));
    }
    vector<int> Books(M,0);
    recursrion(0,0,K,arr,Books,N,M);
    if(xx==true)
    {
        cout<<mi;
    }
    else
    {
        cout<<-1;
    }
    
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    if(s == "keyence"){
      cout<<"YES"<<endl;
    }
    else{
      ll l=-1;
      ll r=7;
      string ans = "keyence";
      FOR(i,0,7){
        if(s[i]==ans[i]){
          l++;
        }
        else{
          break;
        }
      }
      FOR(i,0,7){
        if(s[s.size()-1-i] == ans[6-i]){
          r--;
        }
        else{
          break;
        }
      }

      if(r-l <= 1){
        cout<<"YES"<<endl;
      }
      else{
        cout<<"NO"<<endl;
      }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  ll sum=0;
  ll n;
  int a[200005];
  cin>>n;
  rep(i,n){cin>>a[i];sum+=a[i];}
  ll x=0;
  ll ans=100000000000000000;
  rep(i,n-1){
    x+=a[i];sum-=a[i];
    ans=min(ans,abs(x-sum));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    ll N, M;
    ll answer = 0;
    vector<pair<ll, ll>> C;

    cin >> N >> M;
    
    for(ll i = 0; i < N ; i ++ ){
        ll a, b;
        cin >> a >> b;
        C.push_back(make_pair(a, b));
    }

    sort(all(C));

    ll cnt = 0;
    int idx = 0;

    while(cnt < M){
        ll ad = min(C[idx].second, M - cnt);
        cnt += ad;
        answer += ad * C[idx].first;
        idx ++;
    }

    cout << answer << endl;

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    string s,tmp="";
    cin>>s;
    fr(i,0,SZ(s))
    {
        if(s[i]!='x')
            tmp.pb(s[i]);
    }
    string f=tmp;
    reverse(ALL(f));
    if(f!=tmp)
    {
        cout<<"-1\n";
        return;
    }
    ll i=0,j=SZ(s)-1,ct=0;
    while(i<=j)
    {
        if(s[i]==s[j])
        {
            i++,j--;
        }
        else
        {
            if(s[i]=='x')
            {
                i++;
            }
            else
            {
                j--;
            }
            ct++;
        }
    }
    cout<<ct<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	ll n,m; cin >>n>>m;
	if(n==1&&m==1)cout << 1 << endl;
	else if(n==1) cout << m-2 << endl;
	else if(m==1) cout << n-2 << endl;
	else{
		ll ans=(n-2)*(m-2);
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.1415926535897932384626433832
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
return true;}

void lok(){

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	cin>>t;
	if(t%1000==0){
		cout<<'0'<<endl;
	}
	else
		cout<<1000-t%1000<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int input[1000];

int ulang(int x){
	return x*=2;
}
int main (){
	for (int a=0;a<3;a++){
		scanf ("%d",&input[a]);
	}
	int k;
	scanf ("%d",&k);
	for (int k=0;k<3-1;k++){
		for (int l=0;l<3-k-1;l++){
			if (input[l]<input[l+1]){
				int temp=input[l];
				input[l]=input[l+1];
				input[l+1]=temp;
			}
		}
	}
	for (int a=0;a<k;a++){
		input[0]=ulang(input[0]);
	}
	printf ("%d\n",input[1]+input[0]+input[2]);
	
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextInt();
		long ans=0;
		for(long i =1;i<=N;i++ ) {
			if(i%3==0 &&i%5==0) {
				
			}else  if(i%3==0 ||i%5==0) {
				
			}else {
				ans = ans+i;
			}
		}
		System.out.println(ans);
		
		
	}
	
}


Measured memory_bytes: 35728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define IOS std::ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
const int N = 1e5+200;
const ll Mod = 1e5;
const int INF = 0x3f3f3f3f;
int a[N] = {0};
int b[N] = {0};
int main(){
  int n,m;
  cin>>n>>m;
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  vector<pair<int,int> > vct;
  for(int i = 0; i < m; i++){
    int x,y;
    cin>>x>>y;
    vct.push_back({y,x});
  }
  sort(vct.begin(),vct.end());
  int n2 = vct.size();
  int k = n2-1;
  for(int i = 0; i < n; i++){
    if(a[i] < vct[k].first){
      a[i] = vct[k].first;
      vct[k].second--;
    }
    if(vct[k].second == 0){
      k--;
    }
    if(k < 0 ){
      break;
    }
  }
  ll sum = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
  }
  cout<<sum<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N;
    cin >> N;
    vector <ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector <vector<ll>> DP(N, vector<ll>(2));
    DP[0][0] = A[0];
    DP[1][0] = A[0] + A[1];
    DP[1][1] = -1 * (A[0] + A[1]);
    for (int i = 2; i < N; i++) {
        DP[i][0] = max(DP[i - 1][0], DP[i - 1][1]) + A[i];
        DP[i][1] = max(DP[i - 1][1] + 2ll * (A[i - 1]) - A[i], DP[i - 1][0] - 2ll * A[i - 1] - A[i]);
    }
    cout << max(DP[N - 1][0], DP[N - 1][1]);
    return 0;
}



Measured memory_bytes: 6528
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] x = new int[n];
        int minX = 1000, maxX = 0;
        for(int i = 0; i < n; ++i) {
            x[i] = Integer.parseInt(sc.next());
            minX = Math.min(minX, x[i]);
            maxX = Math.max(maxX, x[i]);
        }

        long ans = Long.MAX_VALUE;
        for(int d = minX; d <= maxX; ++d) {
            long costSum = 0L;
            for(int i = 0; i < n; ++i) {
                costSum += (x[i] - d) * (x[i] - d);
            }
            ans = Math.min(ans, costSum);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
from sys import stdin

n,a,b = [int(x) for x in stdin.readline().rstrip().split()]

total = 0

for i in range(1,n+1):
    point = 0
    s = str(i)
    for j in s:
        point += int(j)
    if a<=point<=b:
        total += i

print(total)
    

Measured memory_bytes: 2940
import heapq


class PriorityQueue:
    def __init__(self):
        self.__heap = []
        self.__count = 0

    def empty(self) -> bool:
        return self.__count == 0

    def dequeue(self):
        if self.empty():
            raise Exception('empty')
        self.__count -= 1
        return heapq.heappop(self.__heap)

    def enqueue(self, v):
        self.__count += 1
        heapq.heappush(self.__heap, v)

    def __len__(self):
        return self.__count


def cake123(X: int, Y: int, Z: int, K: int, A: list, B: list, C: list)->list:
    ret = [0] * K

    sA = sorted(-a for a in A)
    sB = sorted(-b for b in B)
    sC = sorted(-c for c in C)

    q = PriorityQueue()
    q.enqueue((sA[0] + sB[0] + sC[0], 0, 0, 0))

    used = {}

    k = 0
    while k < K:
        delicious, ai, bi, ci = q.dequeue()
        if -delicious in used and (ai, bi, ci) in used[-delicious]:
            continue

        used.setdefault(-delicious, set())
        used[-delicious].add((ai, bi, ci))

        ret[k] = -delicious
        k += 1

        if ai+1 < X:
            q.enqueue((sA[ai+1] + sB[bi] + sC[ci], ai+1, bi, ci))
        if bi+1 < Y:
            q.enqueue((sA[ai] + sB[bi+1] + sC[ci], ai, bi+1, ci))
        if ci+1 < Z:
            q.enqueue((sA[ai] + sB[bi] + sC[ci+1], ai, bi, ci+1))

    return ret


if __name__ == "__main__":
    X, Y, Z, K = map(int, input().split())
    A = [int(s) for s in input().split()]
    B = [int(s) for s in input().split()]
    C = [int(s) for s in input().split()]
    ans = cake123(X, Y, Z, K, A, B, C)
    for a in ans:
        print(a)


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

int main()
{
    int N;
    cin >> N;
    int C[N - 1], S[N - 1], F[N - 1];
    for (int i = 0; i < N - 1; i++)
    {
        cin >> C[i] >> S[i] >> F[i];
    }

    for (int i = 0; i < N - 1; i++)
    {
        int now = 0;
        for (int j = i; j < N - 1; j++)
        {
            if (now < S[j])
            {
                now = S[j];
            }
            else
            {
                int tmp = S[j];
                while (now > tmp)
                {
                    tmp += F[j];
                }
                now = tmp;
            }
            now += C[j];
        }
        cout << now << endl;
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include<string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <map>
using namespace std;
long long ans[2005],mod=1000000007;
int main() {
    int n;
    cin >> n;
    ans[3] = 1;
    ans[4] = 1;
    for (int i = 5; i <= n; i++) {
        ans[i] = 1;
        for (int j = 3; j <= i - 3; j++) ans[i] += ans[j], ans[i] %= mod;
    }
    cout << ans[n] << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.io.*;
class Main{
	public static void main(String args[]){
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		try{
			String strS = in.readLine();
			int intS = (int)Integer.parseInt(strS);
			int h = intS / 3600;
			int m = (intS - h * 3600) / 60;
			int s = intS - (h * 3600 + m * 60);
			System.out.println(h + ":" + m + ":" + s);
		}catch(IOException e){
			System.out.println("error");
		}
	}
}

Measured memory_bytes: 24448
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N,M;
		N= sc.nextInt();
		M= sc.nextInt();
		int a[],b[];
		a = new int[3];
		b = new int[3];
		a[0] = a[1]=a[2]=0;
		b[0] = b[1]=b[2]=0;
		for (int i =0;i<M;i++) {
			int s,c ;
			s= sc.nextInt();
			c= sc.nextInt();
			if (s==1&&c==0&&N>1) {
				System.out.println("-1");
				return ;
			}
			if (a[s-1]==0 && b[s-1]==0) {
				a[s-1] =c;
			}else if (a[s-1]==0 && b[s-1]>0) {
				if (c!=0) {
					System.out.println("-1");
					return ;
				}
			}else {
				if (a[s-1] !=c) {
					System.out.println("-1");
					return ;
				}

			}
			b[s-1]++;
		}
		if (N>1 && a[0]==0) {
			a[0]=1;
		}
		for (int i=0;i<N;i++) {
			System.out.print(a[i]);
		}
	}
}

Measured memory_bytes: 21844
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

void solve(){
	//code
	ll a,b;
	cin>>a>>b;
	cout<<(a*b)/(gcd(a,b));
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ll INF = 1e18; //
const ld PI = acos((ld)-1);

void solve () {
	int k;
	cin >> k;
	vector<bool>visited(k,false);
	int cnt = 1;
	bool flag = false;
	int rem = 0;
	while (1) {
		rem = (rem*10+7)%k;
		if (rem == 0) {
			flag = true;
			break;
		} 
		if (visited[rem]) break;
		++cnt;
		visited[rem] = true;
	}
	if (!flag) {
		cout << -1 << '\n';
	} else {
		cout << cnt << '\n';	
	}

}

int main () {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



Measured memory_bytes: 3780
s=[list(input()) for i in range(3)]
n=[len(s[0]), len(s[1]), len(s[2])]
count = [0, 0, 0]
turn = 0

while(True):
  #print(count, n)
  count[turn] += 1
  if count[0] > n[0]:
    print("A")
    break
  elif count[1] > n[1]:
    print("B")
    break
  elif count[2] > n[2]:
    print("C")
    break
  turn = ord(s[turn][count[turn]-1])-97
  #print(count, turn)



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

using namespace std;

int main()
{
    long long int k,n,i,grad=0,ans=1,cnt=0;
    scanf("%lld%lld",&n,&k);
    long long int a[n+1];
    vector<long long int> vc;
    for(i=1;i<=n;i++)
        scanf("%lld",&a[i]);

    for(i=2;i<=n-k+1;i++){
        if(a[i+(k-1)]>a[i-1]) printf("Yes\n");
        else printf("No\n");
    }

}


Measured memory_bytes: 5220
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = 0;
    rep(i, 0, n){
        if((i+1)%2 == 1 && a[i]%2) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<vector<ll> > A(N, vector<ll>(N));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      scanf("%lld", &A[i][j]);
    }
  }
  vector<vector<int> > need(N, vector<int>(N, 1));
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (A[i][j] > A[i][k] + A[k][j]) {
          printf("-1\n");
          return 0;
        }
        else if (A[i][j] == A[i][k] + A[k][j] and k != i  and k != j) {
          need[i][j] = 0;
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      if (need[i][j]) { ans += A[i][j]; }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	
    string a, b;
    
    cin >> a;
    
    b = a;
    
    int len = a.size(), ind = 0;
    for(int i = 0; i < len; i++){
    	if(a[i] != 'B') b[ind++] = a[i];
    	else{
    		ind--;
		}
		
		if(ind < 0) ind = 0;
	}
	
	for(int i = 0; i < ind; i++){
		cout << b[i];
	}
   
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e9+1;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d){
        cout << "Left" << endl;
    }
    else if(a+b==c+d){
        cout << "Balanced" << endl;
    }
    else{
        cout << "Right" << endl;
    }
    return 0;
} 

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

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double rad = 0;
    double s = x / a;
    if(s <= a*b/2){
        s = s*2/b;
        rad = atan2(b,s);
    } else {
        s = a*b - s;
        s = s*2/a;
        rad = atan2(s,a);
    }
    double PI = acos(-1);
    double ans = rad/(2*PI) * 360;
    cout << setprecision(10) << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{

  int i,temp;
  vector<int> suuretu;
  
  for(i=0;i<5;i++){
    cin >>temp;
    suuretu.push_back(temp);
  }
  
  sort(suuretu.begin(),suuretu.end());
  
  for(i=0;i<5;i++){
    if (i==0)
      cout << suuretu[4-i];
    else
      cout << " " << suuretu[4-i];
  }
  cout << endl;

  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);
const int T = 1e5+7;

int main() {
  int n, c; cin >> n >> c;
  vvl time(c, vl(T, 0));
  rep(i, n) {
    int s, t, ch;
    cin >> s >> t >> ch; ch--;
    time[ch][s]++; time[ch][t]--;
  }
  rep(i,c) {
    rep(j,T-1) {
      if (time[i][j+1] == 1) {
        time[i][j] = 1;
      } else {
        time[i][j+1] += time[i][j];
      }
    }
  }
  int ans = 0;
  rep(i,T) {
    int cnt = 0;
    rep(j,c) {
      if (time[j][i]) {
        cnt++;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


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

const long inf = 1e18;
int m, n, q;
vector<long> a;
vector<long> b;
vector<long> x;

long sub(long p) {
  auto ita = lower_bound(a.begin(), a.end(), p);
  auto itb = lower_bound(b.begin(), b.end(), p);
  long al = ita[-1];
  long ar = *ita;
  long bl = itb[-1];
  long br = *itb;
  
  long mn = inf;
  for (int z : { 0, 1 }) {
    for (long ax : { al, ar }) {
      for (long bx : { bl, br }) {
        long ans;
        if (z == 0) {
          ans = abs(p - ax) + abs(ax - bx);
        } else {
          ans = abs(p - bx) + abs(ax - bx);
        }
        mn = min(mn, ans);
      }
    }
  }
  return mn;
}

int main() {
  cin >> m >> n >> q;
  for (int i = 0; i < m; ++i) {
    long p;
    cin >> p;
    a.push_back(p);
  }
  for (int i = 0; i < n; ++i) {
    long p;
    cin >> p;
    b.push_back(p);
  }
  for (int i = 0; i < q; ++i) {
    long p;
    cin >> p;
    x.push_back(p);
  }
  a.push_back(inf);
  b.push_back(inf);
  a.push_back(-inf);
  b.push_back(-inf);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (long p : x) {
    cout << sub(p) << endl;
  }
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define pb push_back
#define INF 1000000000000000000
#define PI 3.14159265358979323846
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 150;
ll maxSum = 0;
int n, k;
ll v[MAXN];

ll checkInter(int l, int r) {
   // if (l + n-r+1 > k) return -1;
    if (l==0 && r==n+1) return 0;
    ll ret = 0;
    vi hand;
    FOR(i, 1, l) hand.pb(v[i-1]);
    FOR(i, r, n) hand.pb(v[i-1]);
    if (hand.size() > k) return -1;
    int leftAfter = k-hand.size();
    sort(hand.begin(), hand.end());

    FOR(i, 0, hand.size()-1) if (hand[i] > 0) leftAfter = min(leftAfter, i);

    FOR(i, leftAfter, hand.size()-1) ret+= hand[i];
    return ret;
}

int main()
{
    FAST_IO;

    cin >> n >> k;
    FOR(i, 0, n-1) cin >> v[i];

    FOR (l, 0, n) FOR(r, l+1, n+1) maxSum = max(maxSum, checkInter(l, r));

    cout << maxSum;

    return 0;
}


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

std::string replaceString(std::string& str, const std::string& from, const std::string& to) {
    size_t pos = 0;
    while((pos = str.find(from, pos)) != std::string::npos) {
        str.replace(pos, from.length(), to);
        pos += to.length();
    }

    return str;
}

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

    std::vector<std::string> words;

    for (size_t i = 0; i < S.size(); ++i) {
        if ((S[i] == T[0] || S[i] == '?') && (T.size() <= (S.size() - i))) {
            std::string str = S; 
            bool flag = true;
            for (size_t j = 0; j < T.size(); ++j) {
                if ((str[i+j] == T[j] || str[i+j] == '?') == false) {
                    flag = false;
                    break;
                }

                str[i+j] = T[j];
            }

            if (flag) {
                words.push_back(str);
            }
        }
    }

    if (words.size() == 0) {
        std::cout << "UNRESTORABLE\n";
        return 0;
    }

    std::string top = replaceString(words[0], "?", "a");
    for (size_t i = 1; i < words.size(); ++i) {
        if (words[i].find('?') == std::string::npos) {
            if (words[i] < top) {
                top = words[i];
            }
        } else {
            const std::string rep = replaceString(words[i], "?", "a");
            if (rep < top) {
                top = rep;
            }
        }
    }
    
    std::cout << top << std::endl;

    return 0;
}


Measured memory_bytes: 256
n = input()
p = {i:0 for i in range(n)}
for i in xrange(n*(n-1)/2):
    a,b,sa,sb = map(int, raw_input().split())
    if sa > sb: p[a-1]+=3
    elif sa < sb: p[b-1]+=3
    else: p[a-1]+=1; p[b-1]+=1
p = reversed(sorted(p.items(), key = lambda x:x[1]))
ans = [0]*n
rank = 0
same = 0
top = 1<<10
for k,v in p:
    if top != v:
        rank += same + 1
        ans[k] = rank
        same = 0
    else:
        ans[k] = rank
        same += 1
    top = v
for i in ans:
    print i

Measured memory_bytes: 6500
# -*- coding: utf-8 -*-
import math


n = int(input().strip())
#----------
nums={}
for i in range(1,n+1):
    count=0
    tmp=i
    while (tmp % 2) == 0:
        if tmp % 2 == 0:
            tmp //= 2
            count += 1
    
    nums[i]=count

max_k = max(nums, key=nums.get)
print(max_k)


Measured memory_bytes: 3060
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};

use maplit::*;

use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF: usize = 1_000_000_007;
const MOD: usize = 2019;

#[fastout]
fn solve() {
  input! {
    s: Chars,
  };
  
  let s = s.iter().map(|&c| c as usize - 48).collect::<Vec<_>>();
  let n = s.len();
  let mut cur = *s.last().unwrap();
  let mut d = hashmap!{
    0usize => 1usize,
    cur => 1usize,
  };

  let res = if n < 4 {
    0
  } else {
    let mut md = 1usize;
    for i in (0..=n - 2).rev() {
      md = (md * 10) % MOD;
      cur = (cur + md * s[i]) % MOD;
      d.entry(cur)
        .and_modify(|e| *e += 1 )
        .or_insert(1);
    }
    d.values().map(|v| v * (v - 1) / 2 ).sum::<usize>()
  };
  
  println!("{}", res);
}

fn main() {
  std::thread::Builder::new()
    .name("big stack size".into())
    .stack_size(32 * 1024 * 1024)
    .spawn(|| {
      solve();
    })
    .unwrap()
    .join()
    .unwrap();
}


Measured memory_bytes: 3740
#include <stdio.h>
#include <algorithm>

using namespace std;

int N;
char s[101];

int main() {
    scanf("%d", &N);
    scanf("%s", s);
    int l = 0, r = 0;
    for (int i = 0; i < N; i ++) {
        if (s[i] == '(') {
            l ++;
        } else {
            r ++;
        }
    }
    int level = 0;
    int start = 0;
    for (int i = 0; i < N; i ++) {
        if (s[i] == '(') {
            level ++;
        } else {
            if (level == 0) {
                start ++;
            } else {
                level --;
            }
        }
    }
    int end = level;
    for (int i = 0; i < start; i ++) {
        printf("(");
    }
    printf("%s", s);
    for (int i = 0; i < end; i ++) {
        printf(")");
    }
    printf("\n");
}

Measured memory_bytes: 128
A, B, M = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

#割引を使わなくても一番安い価格を初期値にする
total = min(a) + min(b)

for i in range(0,M,1):
    c = list(map(int,input().split()))  #割引券を入手
    kakaku = a[c[0]-1]+ b[c[1]-1] - c[2]
    if total > kakaku:
        total = kakaku

print(total)


Measured memory_bytes: 24576
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  n <- readLn
  print $ solve n

solve :: Int -> Int
solve n = length . filter (<=n) . join $ map candidates [3..(keta n + 1)]

candidates :: Int -> [Int]
candidates n = map (sum . zipWith (*) tens) . validate $ replicateM n [3,5,7]

tens = (map (10^) [0..])

validate = filter isValid
  where isValid ls = (3 `elem` ls) && (5 `elem` ls) && (7 `elem` ls)

keta :: Int -> Int
keta n = round . (logBase 10) . fromIntegral . head $ filter (> n) tens


Measured memory_bytes: 3964
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        String a = sc.next();
        String b = sc.next();
        if (a.equals(b)) {
            System.out.println("Yes");
            return;
        }
        char[] charA = a.toCharArray();
        for (int j = 0; j < charA.length; j++) {
            char temp = charA[0];
            for (int i = 0; i < charA.length - 1; i++) {
                charA[i] = charA[i + 1];
            }
            charA[charA.length - 1] = temp;
            if (b.equals(String.valueOf(charA))) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long N,M;
  cin >> N >> M;
  if(M % 2 == 1){
  for(long long a = 0;a < (M - 1)/2;a++){
    cout << a + 1 << " " << M - a << endl;
  }
    for(long long a = 0;a < (M + 1)/2;a++){
    cout << a + M + 1 << " " << M * 2 + 1 - a << endl;
  }
  }
  if(M % 2 == 0){
  for(long long a = 0;a < M/2;a++){
    cout << a + 1 << " " << M + 1 - a << endl;
  }
    for(long long a = 0;a < M/2;a++){
    cout << a + M + 2 << " " << M * 2 + 1 - a << endl;
  }
  }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

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

    ll a = N % K;
    ll b = abs(a - K);
    // printf("%lld, %lld\n", a, b);

    cout << min(a, b) << endl;
    
    return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#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 sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    ll n;
    cin>>n;
    string ans;
    ll p = 26;
    ll s = 0;
    ll l = 1;
    while(p < n){
        n-=p;
        p*=26;
        l++;
    }
    n--;
    while(l > 0){
        l--;
        int cur = n % 26;
        ans+=(char)('a' + cur);
        n/=26;
    }
    reverse(all(ans));
    cout<<ans;    
}

Measured memory_bytes: 3668
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

typedef db T;
struct P{
    T x,y;
    P(){} P(T x,T y):x(x),y(y){}
    void read(){scanf("%lf%lf",&x,&y);}
    P operator - (const P&b) const {return P(x-b.x,y-b.y);}
    P operator + (const P&b) const {return P(x+b.x,y+b.y);}
    T operator * (const P&b) const {return x*b.x+y*b.y;}
    P operator * (const T&k) const {return P(x*k,y*k);}
    T operator ^ (const P&b) const {return x*b.y-y*b.x;}
};

struct L{
    P s,t;
    L(){} L(P s,P t):s(s),t(t){}
    void read(){s.read();t.read();}
};

P insLL(L a,L b){ // line x line
    P s = a.s - b.s , v = a.t - a.s , w = b.t - b.s;
    db k1 = s ^ w , k2 = w ^ v;
    return a.s + v * (k1 / k2);
}

int main(){
    int Q;scanf("%d",&Q);
    rep(i,0,Q){
        L a,b;a.read();b.read();
        P p=insLL(a,b);
        printf("%.10f %.10f\n",p.x,p.y);
    }
    return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main(){
  stack<int>s;
  string c;
  while(cin >> c){
    if(c[0] == '*' || c[0] == '+' || c[0] == '-' || c[0] == '/'){
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      if(c[0] == '*')s.push(a * b);
      if(c[0] == '+')s.push(a + b);
      if(c[0] == '-')s.push(a - b);
      if(c[0] == '/')s.push(a / b);
    }else{
      int temp = atoi(c.c_str());
      s.push(temp);
    }
  }
  cout << s.top() << endl;
  return 0;
}

Measured memory_bytes: 1200
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while (true) {
                        int D = sc.nextInt(), E = sc.nextInt();
                        if (D == 0 && E == 0) {
                                break;
                        }
                        double ans = 1 << 29;
                        for (int i = 0; i < D / 2 + 1; i++) {
                                double num = Math.abs(Math.sqrt(i * i + (D - i) * (D - i)) - E);
                                if (num < ans) {
                                        ans = num;
                                }
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 26448
/* Author rumoisen */
/* date 2018/10/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int n,m,X,Y,x[110],y[110];
    cin>>n>>m>>X>>Y;
    for(int i=0;i<n;i++) cin>>x[i];
    for(int i=0;i<m;i++) cin>>y[i];
    sort(x,x+n);
    sort(y,y+m);
    int maxX=max(X,x[n-1]),minY=min(Y,y[0]);
    if(maxX<minY) cout<<"No War"<<endl;
    if(maxX>=minY) cout<<"War"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

int main() {

  auto tmp0 = 0;
  char tmp1[101];
  char tmp2[101];
  char tmp3[101];

  scanf("%d\n%s\n%s\n%s", &tmp0, tmp1, tmp2, tmp3);
  unsigned int n = tmp0;
  std::string a = tmp1;
  std::string b = tmp2;
  std::string c = tmp3;

  auto result = 0;
  for (auto i=0; i < n; i++) {
    if (tmp1[i] == tmp2[i] && tmp1[i] == tmp3[i]) {
    } else if (tmp1[i] == tmp2[i]) {
      result = result + 1;
    } else if (tmp1[i] == tmp3[i]) {
      result = result + 1;
    } else if (tmp2[i] == tmp3[i]) {
      result = result + 1;
    } else {
      result = result + 2;
    }
  }

  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	if((n+1)/2>=k){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int k, x;
  cin >> k >> x;

  for (int i = x - k + 1; i < x + k; i++) cout << i << " ";
  return 0;
}


Measured memory_bytes: 256