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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++(i))

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

  int cnt = 0;
  for (int i = A; i <= B; ++i)
  {
    string str = to_string(i);
    if (str[0] == str[4] && str[1] == str[3])
    {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    import bisect
    n = i_input()
    l = sorted(i_list())
    ans = 0
    for a in range(n-2):
        for b in range(a+1,n-1):
            ans += bisect.bisect(l, l[a]+l[b]-1) -b-1
    print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 9548
n=int(input())
s=input()
wc=[0]
ec=[0]
for i in range(n):
    if s[i]=="W":
        wc.append(wc[i]+1)
        ec.append(ec[i])
    else:
        wc.append(wc[i])
        ec.append(ec[i]+1)
ans=10**6
for i in range(n+1):
    tmp=0
    
    tmp+=wc[i]
    tmp+=ec[n]-ec[i]
    ans=min(tmp,ans)
print(ans)

Measured memory_bytes: 17644
#include <stdio.h>
#include <string.h>
// #include <math.h>

int main() {
    int h,w,i,j;
    char s[300]="";
    while(1){
        scanf("%d %d",&h,&w);
        if(h==0&&w==0){
            break;
        }
        for(j=0;j<w;j++){
            strcat(s,"#");
        }
        for(i=0;i<h;i++){
            printf("%s\n",s);
        }
        printf("\n");
        memset(s,0,sizeof(s));
    }
    
    return 0;
}



Measured memory_bytes: 2120
let rec f a b = if b = 0 then a else f b (a mod b)
let n, m, s, t, l = Scanf.scanf "%d %d %s %s" @@ fun n m s t -> n, m, s, t, n / f n m * m
let d1, d2 = l / m, l / n
let _ = for i = 0 to f n m - 1 do if s.[i * d1] <> t.[i * d2] then (print_endline "-1"; exit 0) done; Printf.printf "%d\n" l

Measured memory_bytes: 2816
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }
  printf("%d\n", sum);
  return 0;
}




Measured memory_bytes: 2040
N, M = map(int, input().split())
store = [list(map(int, input().split())) for i in range(N)]
store = sorted(store, key=lambda x: x[0])

cnt = 0
ans = 0

i = 0
while cnt < M:
    ans += store[i][0]
    cnt += 1
    store[i][1] -= 1

    if store[i][1] == 0:
        i += 1

print(ans)


Measured memory_bytes: 29792
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

int calc(int A) {
	if (A <= 0)return 0;

	A++;
	int ans = 0;
	REP(i, 50) {
		int loop = (1LL << (i + 1));
		int cnt = (A / loop)*(loop / 2);
		cnt += max(0LL, (A%loop) - (loop / 2));

		if (cnt % 2 == 1)
			ans += 1LL << i;
	}
	return ans;
}

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

	int A, B;
	cin >> A >> B;
	int ans = calc(B) ^ calc(A - 1);
	cout << ans << endl;
	return 0;
}



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

int main()
{
    char ch[12] ;
    cin.getline(ch,11);
    bool ok=1;
    if(ch[0]!='A')
    {
       cout<<"WA";
       return 0;
    }
  //  cout<<(int)'A';
    for(int i=1; i<strlen(ch); ++ i)
    {
        if((int) ch[i]< 97 ){
            if(ch[i]!='C' || ok == 0)
            {
                //cout<<"ADD";
                cout<<"WA";
                return 0;
            }
            else
            {
                if(i<2 || i>strlen(ch)-2)
                {
                    cout<<"WA";
                    return 0;
                }

            }
            ok=0;

        }
    }
    if(ok==0)
    cout<<"AC";
    else cout<<"WA";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e6+10;
struct node{
	int id,sum;
};
struct node a[maxn];
bool cmp(node t1,node t2){
	return t1.sum<t2.sum;
}
int to[maxn<<1],nex[maxn<<1],beg[maxn],ans[maxn],s[maxn];
int e;
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
inline void add(int x,int y){
	to[++e]=y;
	nex[e]=beg[x];
	beg[x]=e;
}
int main(){
	int i,j,k,m,n;
	n=read();
	for(i=1;i<=n;i++){
		a[i].sum=read();
		a[i].id=i;
	}
	for(i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++)
		s[a[i].id]=a[i].sum;
	for(i=1;i<=n;i++){
		for(j=beg[a[i].id];j;j=nex[j])
			if(s[a[i].id]>s[to[j]] && ans[to[j]]==0){
				ans[a[i].id]=1;
				break;
			}
	}
	for(i=1;i<=n;i++)
		if(ans[i])
			printf("%d ",i);
	puts("");
	return 0;
}

Measured memory_bytes: 10496
n=int(input())
l=list(map(int,input().split()))
s=sum(l)//n
k=1+(sum(l)//n)
c=0
x=0
for i in range(n):
    c+=(l[i]-s)**2
for i in range(n):
    x+=(l[i]-k)**2
print(min(c,x))


Measured memory_bytes: 61852
def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    enemy = sum(a)
    for i in range(n):
        if b[i]>=a[i]: 
            b[i] = b[i]-a[i]
            a[i]=0
        else:
            a[i] = a[i]-b[i]
            b[i] = 0
        if a[i+1]>=b[i]:
            a[i+1]=a[i+1]-b[i]
        else:
            a[i+1]=0
    print(enemy-sum(a))


if __name__ == "__main__":
    main()

Measured memory_bytes: 18476
#include <stdio.h>

int S[1000000], n;

int BinarySearch(int key)
{
  int left=0, right=n, mid;

  while(left < right){
    mid = (left+right)/2;
    if(S[mid] == key) return 1;
    else if(key < S[mid]) right = mid;
    else left = mid+1;
  }
  return 0;
}

int main()
{
  int i, q, T[50000], C=0;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &S[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
    if(BinarySearch(T[i]) == 1) C++;
    else ;
  }

  printf("%d\n", C);
  return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main(double r) {
    cin >> r;
    cout << std::fixed;
    cout << std::setprecision(6) << r*r*M_PI << " " << 2*r*M_PI << endl;
    return 0;
}


Measured memory_bytes: 3268
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;


int main(void) {
	string str;
	cin >> str;
	string f = str.substr(0, 2);
	string b = str.substr(2, 2);
	int fi = stoi(f);
	int bi = stoi(b);
	bool fM = true, fY = true, bM = true, bY = true;
	if (fi < 1 || fi > 12)fM = false;
	if (bi < 1 || bi > 12)bM = false;
	if ((fM && bY) && (fY && bM)) cout << "AMBIGUOUS" << endl;
	else if (fM && bY) cout << "MMYY" << endl;
	else if (fY && bM) cout << "YYMM" << endl;
	else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    char a[n+5][m+5];
    for (int i=1;i<=n;i++) {
        string s;
        cin >> s;
        for (int j=1;j<=m;j++) {
            a[i][j] = s[j-1];
        }
    }
    int dx[]={0,-1,0,1};
    int dy[]={1,0,-1,0};
    int ans = 0;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            if (a[i][j] == '#') continue;
            pii start = mp(i,j);
            int vis[n+5][m+5];
            memset (vis,0,sizeof(vis));
            queue<pii> q;
            q.push(start);
            vis[i][j] = 1;
            while (!q.empty()) {
                pii cur = q.front();
                q.pop();
                for (int k=0;k<4;k++) {
                    pii next = mp(cur.fi+dx[k], cur.se+dy[k]);
                    if (vis[next.fi][next.se] == 0 && a[next.fi][next.se] == '.' && next.fi>=1&&next.fi<=n&& next.se>=1&&next.se<=m) {
                        vis[next.fi][next.se] = vis[cur.fi][cur.se]+1;
                        q.push(next);
                    }
                }
            }
            int p=0;
            for (int k=1;k<=n;k++) {
                for (int l=1;l<=m;l++) {
                    p = max(p, vis[k][l]);
                }
            }
            ans = max(ans, p);
        }
    }
    cout << ans-1 << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    N, M, Q = map(int, input().split())
    #data = np.array([list(map(int, input().split())) for _ in range(Q)])
    data = [list(map(int, input().split())) for _ in range(Q)]
    #print(data)
    # A = data[:, 0]
    # B = data[:, 1]
    # C = data[:, 2]
    # D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = combinations_with_replacement(range(1, M+1), N)
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        # for i in range(Q):
        #     if a[data[i, 1]-1] - a[data[i, 0]-1] == data[i, 2]:
        #         s += data[i, 3]
        for d in data:
            if a[d[1]-1] - a[d[0]-1] == d[2]:
                s += d[3] 

        if s > ans:
            ans = s
    print(ans)





Measured memory_bytes: 27108
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] m = new int[N+1][N+1];
		for(int i=0; i<M; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			m[a][b] = 1;
			m[b][a] = 1;
		}
		int ans = 0;
		for(int i=1; i<=N; i++) {
			for(int j=i+1; j<=N; j++) {
				if(m[i][j] == 1 && m[j][i] == 1) {
					m[i][j] = 0;
					m[j][i] = 0;
					ArrayList<Integer> visited = new ArrayList<>();
					dfs(1, m, visited, N);
					if(visited.size() != N) ans++;
					m[i][j] = 1;
					m[j][i] = 1;
				}
			}
		}
		System.out.println(ans);
	}
	
	static void dfs(int current, int[][] nm, ArrayList<Integer> visited, int N) {
		if(visited.contains(current)) return;
		visited.add(current);
		for(int i=1; i<=N; i++) {
			if(visited.contains(i)) continue;
			if(nm[current][i] == 1) {
				dfs(i, nm, visited, N);
			}
		}
		return;
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

Measured memory_bytes: 23160
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class BKagamiMochi {
public:
	void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    set<int> d;
    REP(i,n) {
      int t;
      in >> t;
      d.insert(t);
    };
    out << d.size() << endl;

	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	BKagamiMochi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3624
import re

pattern = '[a-z]+$'
w = input()
result = re.match(pattern, w)
if result:
    w_set = set(list(w))
    for word in w_set:
        counter = w.count(word)
        if counter % 2 == 1:
            print('No')
            break
    else:
        print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>

using namespace std;
using ll = long long;

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

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


//////////////////////////////////////////////////


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

    double ans = 0;
    for (int i = 1; i <= n; i++) {
        int now = i;
        double a = (double)1/n;
        // cout << a << endl;
        while (now < k) {
            a *= 0.5;
            now *= 2;
        }
        // cout << a << endl;
        ans += a;
    }
    printf("%.10lf\n", ans);
    return 0;
}

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

int main(){
    int n,r;
    cin >>n>>r;
    int m;
    if(n>=10){
        m=r;
    }
    else{
        m=r+100*(10-n);
    }
    cout<<m<<endl;
}

Measured memory_bytes: 256
#ある国で、宮殿を作ることになりました。
#この国では、標高が x メートルの地点での平均気温は T−x×0.006 度です。
#宮殿を建設する地点の候補は N 個あり、地点 i の標高は Hi メートルです。
#joisinoお姫様は、これらの中から平均気温が A 度に最も近い地点を選んで宮殿を建設するようにあなたに命じました。
#宮殿を建設すべき地点の番号を出力してください。
#ただし、解は一意に定まることが保証されます。

N = int(input())
T, A = map(int, input().split())
H = input().split()
h = list(map(int, H))
tans = T - 0.006*h[0]
for i in range(N):
    tmp = T - 0.006*h[i]
    if abs(A - tmp) <= abs(A - tans):
        tans = tmp
        ans = i+1
print(ans)
        

Measured memory_bytes: 38384
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

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

    std::vector<long long> a;
    a.reserve(N);
    long long x;
    for (int i = 0; i < N; ++i) {
        std::cin >> x;
        a.push_back(x);
    }

    const auto N_half = N / 2LL;
    const auto b_sum = std::accumulate(a.cbegin(), a.cend(), 0LL);

    std::vector<long long> b;
    b.reserve(N);

    auto others = 0LL;
    for (int j = 0; j < N_half; ++j) {
        others += a[1 + 2*j];
    }
    b.push_back(b_sum - 2*others);

    for (int i = 1; i < N; ++i) {
        b.push_back(2LL*a[i - 1] - b[i - 1]);
    }

    for (int i = 0; i < N; ++i) {
        std::cout << b[i];
        if (i < N) {
            std::cout << " ";
        } else {
            std::cout << std::endl;
        }
    }
}


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

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 100;
const int inf = 0x3f3f3f3f;
int n, m;
char mp[1100][1100];
int dist[1100][1100];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
struct node {
    int x, y;
    int dis;
};
queue<node> q;


void bfs() {
    node temp;
    node tt;
    while (!q.empty()) {
        temp = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            tt.x = temp.x + dx[i];
            tt.y = temp.y + dy[i];
            if (tt.x >= 0 && tt.y >= 0 && tt.x < n && tt.y < m) {
                if (dist[tt.x][tt.y] == inf) {
                    q.push(tt);
                    dist[tt.x][tt.y] = dist[temp.x][temp.y] + 1;
                }
            }
        }
    }
}

int main() {
   // freopen("in.txt", "r", stdin);
    //cin >> n >> m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%s", mp[i]);
    }
    node te;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (mp[i][j] == '#') {
                te.x = i;
                te.y = j;
                q.push(te);
                dist[i][j] = 0;
            } else dist[i][j] = inf;
        }
    }
    bfs();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (dist[i][j] != inf)
                ans = max(ans, dist[i][j]);
        }
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 17680
import sys
# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    if a >= b:
        return a
    return b

def chmin(a, b):
    if a <= b:
        return a
    return b

def main():
    N = int(input())
    a = list(map(int, input().split()))

    # aiからajのX−Yの最大値
    # [左端,右端)=[l,r)からの遷移    
    # 左をとる[l+1,r)、右をとる[l,r−1)の2通り
    dp = [[0] * (N+2)  for _ in range(N+2)]

    for len in range(1, N + 1):
        for i in range(N + 1 - len):
            j = i + len

            if (N - len) % 2 == 0:
                dp[i][j] = chmax(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = chmin(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])

    print(dp[0][N])

main()

Measured memory_bytes: 112604
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
typedef long long int ll;

int main()
{
	int a, b, c;
	bool f = false;
	string s;
	cin >> a;
	for (int i = 1; i <= 9; i++)
	{
		if (a%i == 0 && a / i < 10)f = true;
	}
	cout << (f ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int A[505];
int S[505];
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int S = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    S += A[i];
  }
  vector<int> v;
  for (int i=1; i*i<=S; i++) {
    if (S % i == 0) {
      v.push_back(i);
      if (i*i != S) {
        v.push_back(S/i);
      }
    }
  }
  sort(v.begin(), v.end(), greater<int>());
  for (auto d : v) {
    int u[505];
    for (int i=0; i<N; i++) {
      u[i] = A[i] % d;
    }
    sort(u, u+N);
    int v[505];
    for (int i=0; i<N; i++) {
      v[i] = (d == 0) ? 0 : (u[i] - d);
    }
    for (int i=1; i<N; i++) {
      u[i] += u[i-1];
    }
    for (int i=N-2; i>=0; i--) {
      v[i] += v[i+1];
    }
    for (int i=0; i<N-1; i++) {
      if (u[i] + v[i+1] == 0) {
        if (u[i] <= K) {
          cout << d << endl;
          return 0;
        }
      }
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}


int main()
{
    string inp;
    cin>>inp;
    bool con=false;
    fori(inp.size()){
        if(inp[i]=='7'){
            con=true;
            break;
        }
    }
    if(con) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}


Measured memory_bytes: 3632
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n%M) * (f(n - 1) % M);
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else 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;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

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

	ll x = ceil(A / D);
	ll y = ceil(C / B);

	if (x == y) cout << "Yes" << endl;
	else if (x > y) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 11048
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    set<int> s;
    rep(i, 3){
        int c ;
        cin >> c;
        s.insert(c);
    }

    cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i = 0;
  int n = 0;
  int min;
  int now;
  int max_margin = -2147483648;
  int margin;

  scanf("%d", &n);
  scanf("%d", &min);
  for(i = 1; i < n; i++){
    scanf("%d", &now);
    margin = now - min;
    if(margin > max_margin){
      max_margin = margin;
    }
    if(now < min){
      min = now;
    }
  }
  printf("%d\n", max_margin);

  return 0;
}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
  string s ,t ;
  cin >>s>>t ;
  ll k = s.size() ;
  ll len = t.size() ;
  vector<vector<ll>> mp(26) ;
  rep(i,k){
    ll  a= s[i]-'a' ;
    mp[a].pb(i) ;
  }
  ll now=0 ;
  bool ok=0;
  

  rep(i,len){
    ll p= now%k ;
    ll unti =t[i]-'a' ;
    
    if(mp[unti].empty()){
      ok=1 ;
      break ;
    } 
    auto itr = lower_bound(mp[unti].begin(),mp[unti].end(),p) ;
    if(itr==mp[unti].end()){
      now= now-p+mp[unti][0]+k+1 ;
    }
    else{
      ll q= itr-mp[unti].begin() ;
    now = now-p+mp[unti][q]+1 ;
    }
    //cout<<now<<endl ;
  }
   if(ok) cout<<-1<<endl ;
   else cout<<now<<endl ;
  
   return 0 ;
 }



Measured memory_bytes: 4656
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = float("inf")
for i in range(n-1):
  if a[i] == a[i+1]:
    continue
  else:
    c = min(c, a[i+1]-a[i])
    if c == 1:
      break
if k > a[-1]:
  print("IMPOSSIBLE")
else:
  kr = k%c
  for i in a:
    if kr == i%c:
      print("POSSIBLE")
      exit()
  print("IMPOSSIBLE")

Measured memory_bytes: 14252
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int asc(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a[200005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for (i = 0; i < n; i++)
        a[i] -= i + 1;
    qsort(a, n, sizeof(int), asc);
    int b = a[n / 2];
    unsigned long long int ans = 0;
    for (i = 0; i < n; i++)
    {
        ans += abs(a[i] - b);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

ll t,len;

int f(int a){
    for(int i=0;i<10;i++){
        if((a*i+t)%10==7){
            t=(a*i+t)/10;
            len++;
            return 1;
        }
    }
    return 0;
}

bool ok(int n){
    int l=0;
    while(n){
        if(n%10!=7){
            return 0;
        }
        l++;
        n/=10;
    }
    len+=l;
    return 1;
}

int main(){
    int k;
    while(cin>>k){
        t=0;
        len=0;
        while(1){
            if(f(k)==0){
                cout<<-1<<endl;
                break;
            }
            if(ok(t)){
                cout<<len<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A, B, C, D;
  cin >> A >> B;
  C = A + B;
  D = A * B;
  if(C == 15) {
    cout << "+" << endl;
  }
  else if(D == 15) {
    cout << "*" << endl;
  }
  else {
    cout << "x" << endl;
  }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	// int main  or  int32_t main ...
	int a[3][3];
	bool check[3][3];
	fill_n(&check[0][0],3*3,0);
	FO(i,0,3){
		FO(j,0,3){
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	int b;
	while(n--){
		cin >> b;
		FO(i,0,3){
			FO(j,0,3){
				if(a[i][j] == b)check[i][j] = true;
			}
		}
	}
	bool ans = false;
	FO(i,0,3){
		bool tmp = (check[i][0] and check[i][1] and check[i][2]);
		ans |= tmp;
	}
	FO(i,0,3){
		bool tmp = (check[0][i] and check[1][i] and check[2][i]);
		ans |= tmp;
	}
	ans |= (check[0][0] and check[1][1] and check[2][2]);
	ans |= (check[0][2] and check[1][1] and check[2][0]);
	
	if(ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	while(t--){ solve(); }
	return 0;
}


Measured memory_bytes: 256
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

L = []
for i in range(N):
    L.append(V[i] - C[i])

L.sort(reverse=True)
ans = 0
for i in range(N):
    if ans > ans+L[i]:
        break
    else:
        ans += L[i]

print(ans)

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    vector<int> tmp(4);
    REP(i, 3) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tmp[a]++, tmp[b]++;
    }

    REP(i, 4) {
        if(tmp[i] > 2) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n = int(input())
a = list(map(int,input().split()))

plc = [0 for i in range(n)]
for i in range(n):
  plc[a[i]-1] = i
ans = 0
uf = UnionFind(n)
for i in range(n)[::-1]:
  p = plc[i]
  x = i+1
  if p < n-1 and a[p] < a[p+1]:
    x *= uf.size(p+1)+1
    uf.union(p,p+1)
  if p > 0 and a[p-1] > a[p]:
    x *= uf.size(p-1)+1
    uf.union(p-1,p)
  ans += x
print(ans)

Measured memory_bytes: 122452
global N,K
global ws

def check(max_p):
    track=0
    now=0
    for i in range (N):
        if(ws[i]>max_p):return False
        if(now+ws[i]>max_p):
            track+=1
            now=ws[i]
        else:
            now+=ws[i]
    if now>0:
        track+=1
    if(track>K):
        return False
    else:
        return True

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

ans=0
now=0
ws=[]
for i in range(N):
    w=int(input())
    ws.append(w)

amin=0
amax=int(1E20)

while amin+1!=amax:
    amid=(amin+amax)//2
    if(check(amid)):
        amax=amid
    else:
        amin=amid
print(amax)
   

Measured memory_bytes: 11624
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

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

const ll mod = 1e9 + 7;
const double eps = DBL_EPSILON;

int a[101000][3], dp[101000][3];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2];
	}
	cout << max({ dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] }) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));
    rep(i, N) {
        int a;
        cin >> a;
        C[i] = a;
        rep(j, M) { cin >> A[i][j]; }
    }

    ll res = INF;
    for (int bit = 0; bit < (1 << N); ++bit) {
        vector<bool> buy(N, false);
        vector<int> und(M, 0);
        for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {
                buy[i] = true;
            }
        }

        ll price = 0;
        rep(i, N) {
            if (buy[i]) {
                price += C[i];
                rep(j, M) { und[j] += A[i][j]; }
            }
        }

        bool judge = 1;
        for (auto u : und) {
            if (u < X)
                judge = 0;
        }

        if (judge)
            res = min(res, price);
    }

    if (res == INF)
        res = -1;
    cout << res << endl;
}

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

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

	if (s.size() == 2) {
		cout << s << endl;
	}
	else {
		reverse(s.begin(), s.end());
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())

    print(max(A + B, A - B, A * B))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
import java.util.Scanner;

public class Main {
	static char[] AZ = {'A','Z'};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		char[] c = s.toCharArray();
		int cnt = 0;
		int len = c.length/2;
		int max = c.length;
		for(int i=0;i<len;i++) {
//			System.out.println(c[i] + ";" + c[len+(c.length%2)+i]);
//			System.out.println(c[i] + ";" + c[max-1-i]);
			if(c[i]!=c[max-1-i]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

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

int c[100005];

int main() {
    int N,Q;
    ll K;
    cin >> N >> K >> Q;
    int A;
    ll  b = Q - K;
    for(int i=0;i<Q;i++) {
        cin >> A;
        c[--A]++;
    }
    for(int i=0;i<N;i++) {
        if(c[i] > b) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main(void){
    cout << fixed << setprecision(10);
    long double a,b,x,ans;cin>>a>>b>>x;
    if(a*a*b/2.0<x){
        ans = 2*(a*a*b-x)/(a*a*a);
    }
    else{
        ans = a*b*b/(2*x);
    }
    ans = atanf(ans) * 180.0 / M_PI;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int X[100001];
int bit[100001];
int n;
int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x) {
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

int main() {
    int N;
    cin >> N;
    n = N;
    vint A(N);
    rep(i, N) {
        cin >> A[i];
    }
    multiset<int> maxA;
    int min_maxA = INF;
    int ans = 0;
    rep(i, N) {
        auto it = maxA.lower_bound(A[i]);
        if (maxA.begin() == it) {
            maxA.insert(A[i]);
        }
        else {
            maxA.erase((--it));
            maxA.insert(A[i]);
        }

    }
    cout << maxA.size() << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    if(a % 2 == 1 || a % 6 == 0 || a % 10 == 0)
      continue;
    else {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int K;
	cin >> K;

	cout << K / 2 * (K - K / 2) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>
#include <functional>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846264338327950L

int main() {
	int n, k, ans=0;
	cin >> n >> k;
	vector<int> p(n);
	rep(i, n) {
		cin >> p[i];
	}

	sort(p.begin(), p.end());
	rep(i, k) {
		ans += p[i];	
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}


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

    string s, t; cin >> s >> t;
    int slen = s.length(), tlen = t.length();

    vector<bool> mps(30, false);
    for(int i=0; i<slen; ++i) mps[s[i]-'a'] = true;
    for(int i=0; i<tlen; ++i) if(mps[t[i]-'a'] == false){
        cout << "-1" << endl;
        return 0;
    }

    s = '0' + s;
    
    vector<int> pos[30];
    for(int i=1; i<=slen; ++i){
        pos[s[i]-'a'].push_back(i);
    }

    ll ans = 0;
    ll now = 0;

    for(int i=0; i<tlen; ++i){
        int c = t[i]-'a';
        auto itr = lower_bound(pos[c].begin(), pos[c].end(), now);
        if(itr == pos[c].end()){
            ans += slen;
            now = 0;
            itr = lower_bound(pos[c].begin(), pos[c].end(), now);
        }
        now = *itr;
        
        if(i == tlen-1){
            cout << ans+now << endl;
        }
        else ++now;
    }
    
    return 0;
}



Measured memory_bytes: 1260
#include <math.h>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	int a;
	cin >> a;
  	long long b[a];
  	long long m = 0;
	for(int i = 0; i < a; ++i){
      cin >> b[i];
    }
  	for(int i = 0; i < a; ++i){
      for(int j = 0; j < a; ++j){
      	m = max(m, (long long)fabs(b[j] - b[i]));
      }
    }
  	cout << m << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int ,input().split()))
avg = sum(a) / n
diffs = []
for i in range(n):
    diff = abs(a[i] - avg)
    diffs.append(diff)
minVal = 100
idx = 0
for k in range(n):
    if diffs[k] < minVal:
        minVal = diffs[k]
        idx = k
    else:
        continue
print(idx)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
        int a,b,c;
        char op;
        while(1){
                scanf("%d %c %d",&a,&op,&b);
                if(op=='+')
                        c=a+b;
                if(op=='-')
                        c=a-b;
                if(op=='*')
                        c=a*b;
                if(op=='/')
                        c=a/b;
                if(op=='?')
                        break;
                printf("%d\n",c);
        }
        return 0;
}

Measured memory_bytes: 600