akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

ans = 0
for i in range(N):
    if ans < min(L[i], L[-1] - L[i]):
        ans = L[i]

print(L[i], ans)

Measured memory_bytes: 14020
#!/usr/bin/env python
# coding: utf-8

# In[39]:


N = int(input())


# In[40]:


for x in range(int(N * 10/11), N+1):
    if (x*1.08)//1 == N:
        print(x)
        break
else:
    print(":(")


# In[ ]:






Measured memory_bytes: 2940
#include "bits/stdc++.h"


// vector
#define MAX_ELE(vec) *max_element(vec.begin(), vec.end())
#define SORT(vec) sort(vec.begin(), vec.end());


// ---------------------------------------

// string
#define TO_UP(str) transform(str.cbegin(), str.cend(), str.begin(), ::toupper)

// ---------------------------------------



using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

    int N, ans;
    vector<int> d;

    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> ans;
        d.push_back(ans);
    }

    ans = 0;
    SORT(d);
    
    cout << d[N/2] - d[N/2 - 1] << "\n";

}

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

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
 
    ll dist = abs(a - b);
    ll dist2 = t *(v-w); 
    if (dist <= dist2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;
static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

struct edge { int to, cost; };
typedef pair<ll, ll> P;
int V;
vector<edge> G[MAX_N];
ll d[MAX_N];
priority_queue<P, vector<P>, greater<P>> que;

void dijkstra(int s) {
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		rep(i, 0, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	ll E, r;
	cin >> V >> E >> r;

	rep(i, 0, E) {
		int s, t, d; cin >> s >> t >> d;
		G[s].push_back(*(new edge{ t,d }));
	}

	dijkstra(r);

	rep(i, 0, V) {
		if (d[i] == INF)cout << "INF" << endl;
		else cout << d[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 29792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)  	
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
const double pi = acos(-1.0);
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
ll read()     //输入外挂
{
    ll res = 0, ch, flag = 0;
    if ((ch = getchar()) == '-')
        flag = 1;
    else if (ch >= '0' && ch <= '9')
        res = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9')
        res = res * 10 + ch - '0';
    return flag ? -res : res;
}
struct code {
    ll r;
    ll l;
}X[maxn];
bool cmp(code a, code b) {
    if (a.l == b.l) return a.r < b.r;
    else return a.l < b.l;
}
int main() {
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        X[i].l = x - y;
        X[i].r = x + y;
    }
    sort(X, X + n, cmp);
    ll ans = 0;
    ll xx = X[0].r;
    for (ll i = 1; i < n; i++) {
        if (X[i].l < xx) {
            ans++;
            xx = min(xx, X[i].r);
        }
        else xx = X[i].r;

    }
    cout << n - ans << endl;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


int main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	t = 1;

	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

ll calc(ll a[], ll b[], ll c[], ll n, ll f, vector<vector<ll>> &dp)
{
	if (n < 0)
		return 0;

	if (dp[n][f] != -1)
		return dp[n][f];

	if (f == 0)
	{
		dp[n][f] = max({a[n] + calc(a, b, c, n - 1, 1, dp), b[n] + calc(a, b, c, n - 1, 2, dp),
		                c[n] + calc(a, b, c, n - 1, 3, dp)
		               });
	}
	else if (f == 1)
	{
		dp[n][f] = max(b[n] + calc(a, b, c, n - 1, 2, dp), c[n] + calc(a, b, c, n - 1, 3, dp));
	}
	else if (f == 2)
	{
		dp[n][f] = max(a[n] + calc(a, b, c, n - 1, 1, dp), c[n] + calc(a, b, c, n - 1, 3, dp));
	}
	else if (f == 3)
	{
		dp[n][f] = max(a[n] + calc(a, b, c, n - 1, 1, dp), b[n] + calc(a, b, c, n - 1, 2, dp));
	}

	return dp[n][f];
}

void solve()
{
	ll n, i, ans;
	cin >> n;

	ll a[n], b[n], c[n];

	for (i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];

	vector<vector<ll>> dp(n, vector<ll>(4, -1));
	ans = calc(a, b, c, n - 1, 0, dp);

	cout << ans << endl;
}


Measured memory_bytes: 21888
#include<stdio.h>
#include <iostream>

int main(void) {

	int n;
	scanf("%d", &n);

	int i = 1;
	while (++i <= n) {
		int x = i;
		if (x % 3 == 0) {
			std::cout << " " << i;
			continue;
		}

		while (x) {
			if (x % 10 == 3) {
				std::cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	std::cout << std::endl;

	return 0;
}



Measured memory_bytes: 3148
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // int TC = Integer.parseInt(sc.next(), 10);
        
        while (true) {
            int N = sc.nextInt();
            int R = sc.nextInt();
            if (N == 0 && R == 0) break;
            
            int[] cards = new int[N];
            int[] temp = new int[N];
            
            for (int i = 0; i < N; i++) {
                cards[i] = N - i;
            }
            
            while (R-- > 0) {
                int p = sc.nextInt() - 1;
                int c = sc.nextInt();
                
                for (int pos = 0; pos < c; pos++) {
                    temp[pos] = cards[p + pos];
                }
                for (int i = 0; i < p; i++) {
                    temp[c + i] = cards[i];
                }
                for (int i = p + c; i < N; i++) {
                    temp[i] = cards[i];
                }
                cards = Arrays.copyOf(temp, N);
            }
            
            System.out.println(cards[0]);
        }
    }
}




Measured memory_bytes: 38852
using System;

namespace ABC087_B_Coins
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int a = int.Parse(Console.ReadLine());
			int b = int.Parse(Console.ReadLine());
			int c = int.Parse(Console.ReadLine());
			int x = int.Parse(Console.ReadLine());

			int count = 0;

			for (int i = 0; i <= a; i++) {
				for (int j = 0; j <= b; j++){
					for (int k = 0; k <= c; k++) {
						int money = 500 * i + 100 * j + 50 * k;
						
						if (money == x) count++;
					}
				}
			}
			
			Console.WriteLine(count);
		}
	}
}

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

int main()
{
	int n;
	cin >> n;
	string s;
	int n_ac=0, n_wa=0, n_tle=0, n_re=0;
	for (int i = 0; i < n; ++i)
	{
		//getline(cin, s);// 不行，会接受前面cin的空格或回车符， 
		cin >> s;
		if (s=="AC") n_ac++;
		else if (s=="WA") n_wa++;
		else if (s=="TLE") n_tle++;
		else if (s=="RE") n_re++;
	}

	cout << "AC x " << n_ac << endl;
	cout << "WA x " << n_wa << endl;
	cout << "TLE x " << n_tle << endl;
	cout << "RE x " << n_re << endl;


	return 0;
}

Measured memory_bytes: 3572
S = input()
N = len(S)
ans = 0

# 二進数で考えると、0, 1, 10, 11, 100 ... 1111
for i in range(2**(N-1)):
    exp = S[0]

    # 右に一つずつシフトしていき、
    for j in range(1, N):

        # 最初の桁が1であれば（&1でTrue）+, そうでなければスルー
        if (i >> (j-1)) & 1: exp += '+'
        exp += S[j]
        
    ans += eval(exp)

print(ans)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
    int A,B,C;
    cin>>A>>B>>C;

    if(A==B && B==C){
        cout << "No";
    }else if(A!=B && B!=C && C!=A){
        cout << "No";
    }else{
        cout << "Yes";
    }

    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
h[0]-=1
ans='Yes'
for i in range(1,n):
  if h[i]>h[i-1]:
    h[i]-=1
  if h[i]<h[i-1]:
    ans='No'
    break
print(ans)

Measured memory_bytes: 63984
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N;cin>>N;vi a(N);rep(i,N)cin>>a[i];
  
  sort(all(a));
  cout<<a[N-1]-a[0]<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	string st;
	cin>>st;
	int cnt = 0;
	for(int i=0;i<3;i++){ if(st[i] == 'B')cnt++; }
	if( cnt == 0 || cnt == 3 ){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

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

int main(){
    long x, ans = 0;
    cin >> x;
    ans += 2 * (x / 11);
    x %= 11;
    if(x > 0) ans++;
    if(x > 6) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX_V 600
struct edge {
  int to,cap,rev;
  edge(){}
  edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};

vector<edge> G[MAX_V];
map<int,int> M[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
  M[from][to]=G[from].size();
  M[to][from]=G[to].size();
  G[from].push_back(edge(to,cap,G[to].size()));
  G[to].push_back(edge(from,cap,G[from].size()-1));
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int i=0;i<(int)G[v].size();i++){
      edge &e = G[v][i];
      if(e.cap>0&&level[e.to]<0){
	level[e.to]=level[v]+1;
	que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t) return f;
  for(int &i=iter[v];i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t, int lim){
  int flow=0;
  for(;;){
    bfs(s);
    if(level[t]<0||lim==0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,lim))>0){
      flow+=f;
      lim-=f;
    }
  }
}

int max_flow(int s,int t){
  return max_flow(s,t,INF);
}

bool back_edge(int s,int t,int from, int to){
  for(int i=0;i<(int)G[from].size();i++) {
    edge& e=G[from][i];
    if(e.to == to) {
      if(e.cap == 0 && max_flow(from, to, 1) == 0) {
	max_flow(from, s, 1);
	max_flow(t, to, 1);
	return 1;
      }
    }
  }
  return 0;
}

int main(){
  int N,E,Q;
  cin>>N>>E>>Q;
  for(int i=0,f,t;i<E;i++) scanf("%d%d",&f,&t),add_edge(f,t,1);
  int ans=max_flow(1,N);
  while(Q--){
    int m,a,b;
    scanf("%d%d%d",&m,&a,&b);
    if(m==1){
      if(M[a].find(b)==M[a].end()) add_edge(a,b,1);
      else G[a][M[a][b]].cap=G[b][M[b][a]].cap=1;
    }else{
      ans-=back_edge(1,N,a,b);
      ans-=back_edge(1,N,b,a);
      G[a][M[a][b]].cap=G[b][M[b][a]].cap=0;
    }
    ans+=max_flow(1,N);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5540
#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;

int main() {
    
    string S;
    cin >> S;
    string S2,S3;
    for ( int i = 0; i < S.length(); i++ ) {
        if ( S[i] != 'x' ) { S2 += S[i]; }
    }
    S3 = S2;
    reverse( S3.begin(), S3.end() );
    
    if ( S3 != S2 ) { cout << -1 << endl; return 0; }
    
    int ans = 0;
    vector<int> V;
    int count = 0;
    for ( int i = 0; i < S.length(); i++ ) {        
        if ( S[i] == 'x' ) { count++; }
        else {
            V.push_back(count);
            count = 0;
        }        
    }
    V.push_back(count);
    
    for ( int i = 0; i < V.size()/2; i++ ) {
        ans += abs( V[i] - V[V.size()-i-1] );
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1148
import java.util.Formatter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();

		int zero = 0;
		Formatter formatterA = new Formatter();
		a = formatterA.format("%0" + (102 - a.length()) + "d" + "%s", zero, a).toString();
		Formatter formatterB = new Formatter();
		b = formatterB.format("%0" + (102 - b.length()) + "d" + "%s", zero, b).toString();

//		System.out.println(a);
//		System.out.println(b);
		System.out.println(a.compareTo(b) > 0 ? "GREATER" :
			a.compareTo(b) < 0 ? "LESS" : "EQUAL");
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(26,50);
  rep(x,n) {
    string s;
    cin >> s;
    vector<int> b(26);
    for(int i=0; s[i]!='\0'; i++) {
      b[s[i]-'a']++;
    }
    rep(i,26) {
      a[i]=min(a[i],b[i]);
    }
  }
  rep(x,26) {
    rep(i,a[x]) cout << (char)('a'+x);
  }
  cout << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 998244353;

ll dp[6060];

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


	int A, B, C, D;
	cin >> A >> B >> C >> D;

	C -= A;
	D -= B;

	dp[C + 2] = 1;
	for (int i = C + 2; i < C + D + 2; i++) dp[i + 1] = dp[i] * A % mod;

	for (int i = A; i < A + C; i++) {
		auto t = dp + C - i + A - B + 2;

		for (int j = B; j <= B + D; j++) {
			t[j - 1] = t[j - 2] * (i + 1) + t[j] * j - t[j - 1] * i * (j - 1);

			t[j - 1] %= mod;

		}
	}
	co((dp[D + 2] + 10 * mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 3152
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String tmp = sc.next();
            if (map.containsKey(tmp)) {
                map.put(tmp, map.get(tmp) + 1);
            } else {
                map.put(tmp, 1);
            }
        }
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            String tmp = sc.next();
            if (map.containsKey(tmp)) {
                map.put(tmp, map.get(tmp) - 1);
            }
        }
        int max = 0;
        for (Integer num : map.values()) {
            max = Math.max(max,num);
        }
        System.out.println(max);
    }    
}


Measured memory_bytes: 23124
X = int(input())
l = []
for i in range(-1000,1001):
    l.append(i**5)
for i in range(len(l)-1):
    for j in range(i,len(l)):
        if abs(l[i]-l[j]) == X:
            ai = i-1000
            aj = j-1000
            break

print(aj,ai)

Measured memory_bytes: 70756
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()

if n == 2:
    print(a[1] - a[0])
    exit()

ans = 0
middles = [n // 2 - 1, n // 2, n // 2 + 1]
if middles.count(0):
    middles.remove(0)
if middles.count(n-1):
    middles.remove(n-1)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[l])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            l += 1
            if l == mid:
                l += 1
            state = False
        else:
            r -= 1
            if r == mid:
                r -= 1
            state = True
    ans = max(ans, val)
for mid in middles:
    l = 0; r = n-1
    val = abs(a[mid] - a[r])
    state = True 
    while l != r:
        val += abs(a[r] - a[l])
        if state:
            r -= 1
            if r == mid:
                r -= 1
            state = False
        else:
            l += 1
            if l == mid:
                l += 1
            state = True
    ans = max(ans, val)
print(ans)

Measured memory_bytes: 7516
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
   string a;
   cin>>a;
   int c=0,m=0;
   for(int i=0;i<3;i++)
   {
       if(a[i]=='R')
       {
           c++;
           //Rcout<<c<<" ";
           if(i==2)
           {
               if(c>m)
               {
                   m=c;
                   c=0;
               }
           }
       }
       else
       {
           if(c>=m)
           {
               m=c;
               c=0;
           }
       }
   }
   cout<<m;
  }


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {

	int A, a[4] = {}, b[4] = {};

	while (cin >> a[0]) {
		int hit = 0, blow = 0;
		if (cin.eof()) {
			break;
		}
		else {
			for (int i = 1; i < 4; i++) {
				cin >> a[i];
			}
			for (int i = 0; i < 4; i++) {
				cin >> b[i];
			}
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					if (a[i] == b[j]) {
						if (i == j) {
							hit++;
						}
						else {
							blow++;
						}
					}
				}
			}
		}
		
		cout << hit << " " << blow << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
// AOJ 2363: Unequal Dice
// 2017.12.30 bal4u@uu

#include <stdio.h>

double e[11];

int main()
{
	int t, n, m, v, p, q, i, j, ans;
	double r, e0, s;

	scanf("%d", &t);
	for (i = 0; i < t; i++) {
		scanf("%d%d", &n, &m);
		e0 = 0, s = 0;
		for (j = 0; j < m; j++) {
			scanf("%d%lf", &v, &r);
			e0 += v*r;
			s += r;
		}
		e[i] = e0 / s;
	}

	scanf("%d%d", &p, &q);
	e0 = 0, s = 0;
	while (q--) {
		scanf("%d%lf", &v, &r);
		e0 += v*r;
		s += r;
	}
	e0 /= s;

	ans = 0;
	for (i = 0; i < t; i++) {
		if (e[i] > e0 + 0.0000001) { ans = 1; break; }
	}
	puts(ans? "YES": "NO");
	return 0;
}

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

int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(1)
  {
    c=c-b;
    if(c<=0)
    {
      cout<<"Yes";
      break;
    }
    a=a-d;
    if(a<=0)
    {
      cout<<"No";
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=998244353;
int n,m;
ll a[405],b[405],fact[405],inv[405],invp,sa,sb,A[405][405],B[405][405];
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
int main()
{
	fact[0]=1;
	for(int i=1;i<=400;i++)fact[i]=fact[i-1]*i%MOD;
	inv[400]=quick_pow(fact[400],MOD-2);
	for(int i=400;i>=1;i--)inv[i-1]=inv[i]*i%MOD;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		sa+=a[i];
	}
	invp=quick_pow(sa,MOD-2);
	A[0][0]=1;
	sa=0;
	for(int i=1;i<=n;i++)
	{
		for(int k=0;k<b[i];k++)
		{
			ll v=MOD-inv[k]*quick_pow(a[i]*invp%MOD,k)%MOD;
			for(int p=0;p<=sa;p++)
			  for(int q=0;q<=sb;q++)
				B[p][q+k]=(B[p][q+k]+A[p][q]*v)%MOD;
		}
		for(int p=0;p<=sa;p++)
		  for(int q=0;q<=sb;q++)
			B[p+a[i]][q]=(B[p+a[i]][q]+A[p][q])%MOD;
		sa+=a[i],sb+=b[i]-1;
		for(int p=0;p<=sa;p++)
		  for(int q=0;q<=sb;q++)
		    A[p][q]=B[p][q],B[p][q]=0;
	}
	ll ans=0;
	for(int p=0;p<=sa;p++)
	for(int q=0;q<=sb;q++)
	{
		A[p][q]=(MOD-A[p][q])%MOD;
		if(p==sa&&q==0)A[p][q]=(A[p][q]+1)%MOD;
		ans=(ans+A[p][q]*fact[q]%MOD*quick_pow(quick_pow(1+MOD-p*invp%MOD,q+1),MOD-2))%MOD;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2688
#include<stdio.h>
int main(){
  int r,c,sum=0,i,j,sum2=0,sum3=0;
  int a[101][101];
  scanf("%d %d",&r,&c);
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf("%d",&a[i][j]);
    }
  }
for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      printf("%d ",a[i][j]);
      sum+=a[i][j];
      if(j==c-1){
	printf("%d\n",sum);
	sum=0; 
      }
    }
 }
 for(j=0;j<c;j++){
   for(i=0;i<r;i++){
     sum2+=a[i][j];
     sum3+=a[i][j];
     if(i==r-1){
       printf("%d ",sum2);
       sum2=0;
     }
    
   }
 }
 printf("%d\n",sum3);
 return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <complex>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <fstream>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const int INF = 10e8;

int main (){
  int N;
  while (cin >> N){
    vector<int> na;
    REP(i,N){
      int a;
      cin >> a;
      na.push_back(a);
    }
    int minn = na[0];
    int maxn = -INF;
    FOR(i,1,N){
      maxn = max(maxn, (na[i] - minn));
      minn = min(minn, na[i]);
    }
    
    cout << maxn << endl;
    na.clear();
  }
  return 0;
}



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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    int a[m],b[m];
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
    }
    int ans=0;
    for(int i=0;i<m;i++){
        int visited[n+1];
        for(int j=0;j<=n;j++){
            visited[j]=0;
        }
        stack<int> s;
        vi v[n+1];
        for(int j=0;j<m;j++){
            if(i==j) continue;
            v[a[j]].pb(b[j]);
            v[b[j]].pb(a[j]);
        }
        s.push(1);
        visited[1]=1;
        while(!s.empty()){
            int u=s.top();
            s.pop();
            for(int j=0;j<v[u].size();j++){
                if(visited[v[u][j]]==0){
                    s.push(v[u][j]);
                    visited[v[u][j]]=1;
                }
            }
        }
        for(int j=1;j<=n;j++){
            if(visited[j]==0){
                ans+=1;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();
    if (n % x == 0) {
      System.out.println((n / x) * t);
    } else {
      System.out.println((n / x + 1) * t);
    }
  }
}

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

int main()
{
  string s; cin>>s;
  string t = "CODEFESTIVAL2016";
  int n = s.size();
  int cnt = 0;
  rep(i, n) if (s[i]!=t[i]) cnt++;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
array=gets.chomp.split(" ")
class Node
    attr_accessor :mark, :value, :index
end

array1 = array.map do |e|
    node = Node.new
    node.mark = e[0]
    node.value = e[1].to_i
    node
end

array2 = array.map do |e|
    node = Node.new
    node.mark = e[0]
    node.value = e[1].to_i
    node
end

array3 = array.map.with_index do |e, i|
    node = Node.new
    node.mark = e[0]
    node.value = e[1].to_i
    node.index = i
    node
end

def bubbleSort(array)
    (0..(N-2)).each do |i|
        ((i+1)..(N-1)).to_a.reverse.each do |j|
            if array[j].value < array[j-1].value 
                tmp = array[j]
                array[j] = array[j-1]
                array[j-1] = tmp
            end
        end
    end
    array
end

def selectionSort(array)
    (0..(N-1)).each do |i|
        mini = i
        (i..(N-1)).each do |j|
            mini = j if array[j].value < array[mini].value
        end
        tmp = array[i]
        array[i] = array[mini]
        array[mini] = tmp
    end
    array
end

bubbleSorted = bubbleSort(array1).map {|e| "#{e.mark}#{e.value}" }.join(" ")
selectionSorted = selectionSort(array2).map {|e| "#{e.mark}#{e.value}" }.join(" ")
sorted = array3.sort_by {|e| e.value*40+e.index }.map {|e| "#{e.mark}#{e.value}" }.join(" ")

puts bubbleSorted
puts bubbleSorted == sorted ? "Stable" : "Not stable"
puts selectionSorted
puts selectionSorted == sorted ? "Stable" : "Not stable"



Measured memory_bytes: 8928
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int k,q;
ll d[5005];
int main(){
	scanf("%d%d",&k,&q);
	rep(i,k) scanf("%lld",&d[i]);
	
	rep(i,q){
		ll n,x,m; scanf("%lld%lld%lld",&n,&x,&m);
		ll en = x;
		ll all = 0;
		rep(j,k){
			ll zan = n-2-j;
			if(zan < 0) continue;
			en += (zan/k+1)*(d[j]%m);
			if(d[j]%m > 0) all += (zan/k+1);
		}
		ll ans = (en/m) - (x/m);
		cout<<(all-ans)<<endl;
	}
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int w=0,a;
		for (int i = 0; i < n / 4; i++) {
			cin >> a;
			w += a;
		}
		cout << w << endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    double m;
    cin>>n>>m;
    int item[n];
    double sum = 0;
    for(int x = 0; x < n; x++)
    {
        cin>>item[x];
        sum = sum + item[x];
    }
    //cout<<sum<<endl;

    double y = 1 / (4 * m) * sum;
    //cout<<y<<endl;
    int c = 0;
    for(int z = 0; z < n; z++)
    {
        if(item[z] >= y)
        {
            c++;
        }
        if(c >= m)
        {
            cout<<"Yes"<<endl;
            break;
        }
    }
    if(c < m)
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
X =[]
ans = 0
for _ in range(N):
    X.append(input().split())
    X[_][0] = float(X[_][0])
    if X[_][1] == 'BTC':
        X[_][0] = X[_][0] * 380000
    ans += X[_][0]
print(ans)


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

int main() {
  int n;
  cin >> n;
  
  int i;
  vector<int> a(n);
  for(i = 0; i < n; i++) cin >> a.at(i);
  
  int j, keep, ans = 100000000;
  for(i = -100; i <= 100; i++){
    keep = 0;
    for(j = 0; j < n; j++){
      keep += (a.at(j) - i) * (a.at(j) - i);
    }
    ans = min(ans, keep);
  }
  
  cout << ans << endl;
}

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

using namespace std;
typedef long long LL;
const int mod=13;
const LL MOD=1e9+7;

LL modpow(LL x, LL n){
	LL r=1;
	while(n){
		if(n&1) r=r*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return r;
}

int main(){
	string S;
	cin >> S;
	LL dp[100010][13]={0};
	dp[0][0]=1;
	int N=S.size();
	rep(i,N){
		rep(j,13){
			if(S[N-1-i]=='?'){
				rep(k,10){
					int n=modpow(10,i)*k;
					dp[i+1][(j+n)%mod]+=dp[i][j];
                  	dp[i+1][(j+n)%mod]%=MOD;
				}
			}
			else{
				int k=S[N-1-i]-'0';
				int n=modpow(10,i)*k;
				dp[i+1][(j+n)%mod]+=dp[i][j];
              	dp[i+1][(j+n)%mod]%=MOD;
			}
		}
	}
	cout << dp[N][5] << endl;

	return 0;
}

Measured memory_bytes: 10624
#include<stdio.h>
#include<string.h>
int map[5][1005][1005];
int main(){
	int i,j,h,m,n,k;
	int a,b,c,d,x,y,z;
	char s[1005];
	memset(map,0,sizeof(map));
	scanf("%d%d%d",&m,&n,&k);
	for(i=0;i<m;i++){
		scanf("%s",s);
		for(j=0;j<n;j++){
			for(h=0;h<3;h++)
				map[h][i+1][j+1]=map[h][i][j+1]+map[h][i+1][j]-map[h][i][j];
			if(s[j]=='J')map[0][i+1][j+1]++;
			if(s[j]=='O')map[1][i+1][j+1]++;
			if(s[j]=='I')map[2][i+1][j+1]++;
		}
	}
	while(k--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		x=map[0][c][d]-map[0][c][b-1]-map[0][a-1][d]+map[0][a-1][b-1];
		y=map[1][c][d]-map[1][c][b-1]-map[1][a-1][d]+map[1][a-1][b-1];
		z=map[2][c][d]-map[2][c][b-1]-map[2][a-1][d]+map[2][a-1][b-1];
		printf("%d %d %d\n",x,y,z);
	}
	return 0;
}

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
vector<pair<int,int>>v;
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    int a,b;
    for(int i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        v.push_back({b,a});
    }
    sort(all(v));
    int time=0;
    for(int i=0;i<n;i++){
        time+=v[i].second;
        if(time>v[i].first){puts("No");return 0;}
    }
     puts("Yes");
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

int dp[100005][15];
void solve() {
  string s;
  cin >> s;
  int n = sz(s);
  dp[0][0] = 1;
  rep(i, n) rep(j, 13) {
    if (s[i] == '?') {
      rep(k, 10) {
        add(dp[i + 1][(j * 10 + k) % 13], dp[i][j]);
      }
    } else {
      int k = s[i] - '0';
      add(dp[i + 1][(j * 10 + k) % 13], dp[i][j]);
    }
  }
  cout << dp[n][5] << endl;
}


Measured memory_bytes: 6352
import java.io.*;

import java.util.*;

class pair{
	int a ;int b;
	public pair(int a,int b){
		this.a=a;
		this.b=b;
	}}

public class Main {
	
	 static long fun(long n,int i) 
	    { 
	         return (long)Math.pow(n,i);
	    } 

	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		long x=s.nextLong();
		long a=0;
		long b=0;
		boolean fl=false;
		for (int i = 0; i < 10000; i++) {
			a=i;
			for (int j = 0; j < 10000; j++) {
				
				b=j;
			long tt1=(a-b)*(fun(a,4) + fun(a,3)*b + fun(a,2)*fun(b,2) + a*fun(b,3) + fun(b,4));
			long tt2=(a+b)*(fun(a,4) - fun(a,3)*b + fun(a,2)*fun(b,2) - a*fun(b,3) + fun(b,4));
				if(tt1==x) {
					System.out.println(a+" "+b);
					return;
				}
				if(tt2==x) {
					System.out.println(a+" "+-b);
					return;
					
				}
			}
		}

	}


}

Measured memory_bytes: 38856
import java.util.*;

class Main {
    public static void main(String... args) {
        int N = IN.nextInt();
		HashSet<String> h = new HashSet<String>();
		boolean flag = true;
		String w1 = IN.next();
		h.add(w1);
		char prev = w1.charAt(w1.length() - 1);
        for (int i = 0; i < N - 1; i++) {
			String w = IN.next();
			if (h.contains(w) || prev != w.charAt(0)) {
				flag = false;
				break;
			} else {
				h.add(w);
				prev = w.charAt(w.length() - 1);
			}
		}
		puts(flag ? "Yes" : "No");
    }
    static final Scanner IN = new Scanner(System.in);
    static <T> void puts(T arg) { System.out.println(arg); }
}


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

int n;
vector<int> A(50);

int solve(int i,int m){
    if(m == 0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1,m) || solve(i+1,m-A.at(i));
    return res;
}

int main(){
    int q, M;
    cin >> n;
    for(int i = 0;i<n;i++){
        cin >> A.at(i);
    }
    cin >> q;
    for(int i = 0;i<q;i++){
        cin >> M;
        if(solve(0,M)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

const int MAX_N = 123459 * 2;

int prime[MAX_N];
bool is_prime[MAX_N + 1];
void sieve(int n){
    int p = 0;
    for(int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j = 2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
}

int sum[MAX_N + 10];

int main(){
    int n;
    sieve(MAX_N);
    rep(i, 1, MAX_N){
        sum[i] = sum[i - 1] + is_prime[i];
    }
    while(cin >> n, n){
        int ans = sum[2 * n] - sum[n];
        cout << ans << endl;
    }
}

Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

/*
  先に縦と横 それぞれに走査して，黒のマスがある場所をチェックする
  その後，両方ともチェックがある場所のみ出力すると楽

*/

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> field(H);
  REP(h,H){
    string s;
    cin >> s;
    field[h] = s;
  }

  vector<bool> tate(H, false);
  vector<bool> yoko(W, false);

  REP(h,H){
    bool ok = false;
    REP(w,W){
      if(field[h][w] == '#'){
        ok = true;
        break;
      }
    }
    tate[h] = ok;
  }


  REP(w,W){
    bool ok = false;
    REP(h,H){
      if(field[h][w] == '#'){
        ok = true;
        break;
      }
    }
    yoko[w] = ok;
  }

  //Output

  REP(h,H){
    bool ok = false;
    REP(w,W){
      if(tate[h] && yoko[w]){
        cout << field[h][w];
        ok = true;
      }
    }
      if(ok) cout << endl;
    }

  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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; }
typedef long long ll;
const long long INF = 1LL << 60;
ll N, M;
int main(){
   cin >> N >> M;
   ll can = min(N, M / 2);
   ll ans = can;
   M -= can * 2;
   ans += M / 4;
   cout << ans << endl;
}

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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    for(int i = 0;i < m;i++){
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        uf.unite(x,y);
    }
    int ret = 0;
    for(int i = 0;i < n;i++){
        if(uf.root(i) == i){
            ret++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <math.h>
#include <stdbool.h>


bool isPrime(int num) {
	if(num < 2) return false;
	if(num == 2) return true;
	if(num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for(int i = 3; i <= sqrtNum; i += 2)
		if(num % i == 0) return false;
	return true;
}

int main() {
	int a[100000] = {};
	int n;
	int count = 0;

	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if(isPrime(a[i])) count++;
	}

	printf("%d\n", count);

	return 0;
}


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

int main()
{  
  #ifndef ONLINE_JUDGE
	 freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);

  #endif

    long long n;
    cin>>n;
    vector<long long> dp(3,0);
    for(int i=0; i<n; i++)
    { 
      vector<long long> ndp(3,0);
      long long c[3];
      cin>>c[0]>>c[1]>>c[2];
      for(int j=0; j<3; j++)
      { for(int k=0; k<3; k++)
      	  if(j!=k)
           { 
           	 ndp[j]=max(ndp[j], dp[k]+c[j]);

           }

       }

      

       dp=ndp;
       
    }

   long long  ans= max(dp[0],dp[1]);
   ans=max(ans,dp[2]);

   cout<<ans<<endl;

 }

Measured memory_bytes: 3612
def sk(k):
    tk = k
    ret = 0
    while tk!=0:
        ret+=tk%10
        tk//=10
    return ret
an = []
for i in range(1,100):
    tp = i/sk(i)
    if len(an)==0:an.append((i,tp))
    else:
        ls=an[-1]
        if ls[1]>tp:an[-1]=(i,tp)
        else:an.append((i,tp))
for j in range(15):
    for i in range(100,1000):
        ns=str(i)+''.join(['9']*j)
        nm=int(ns)
        tp=nm/sk(nm)
        if an[-1][1] > tp:
            while an[-1][1]>tp:
                an.pop()
        an.append((nm,tp))
for i in range(int(input())):print(an[i][0])

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b&&b!=c)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(a==c&&b!=c)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(c==b&&a!=c)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  string ans = "";
  while(n != 0){
    if(n % 2 != 0){
      n--;
      ans = "1" + ans;
    }else ans = "0" + ans;
    n /= -2;
  }
  if(ans == "") ans = "0";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sum_digits(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N, A, B;
    cin >> N;
    cin >> A;
    cin >> B;

    int sum_A_to_B = 0;
    for (int n = 1; n <= N; n++) {
        int sum_n = sum_digits(n);
        if (A <= sum_n && sum_n <= B) {
            sum_A_to_B += n;
        }
    }

    cout << sum_A_to_B << endl;
    return 0;
}


Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(r);
    cout<<r*r<<endl;

    return 0;
}

Measured memory_bytes: 256