akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
using namespace std;

string c[50];
string e[50];
signed main() {
	int a, b; cin >> a >> b;
	for (int d = 0; d < a; d++)cin >> c[d];
	for (int d = 0; d < b; d++)cin >> e[d];
	for (int d = 0; d <= a - b; d++) {
		for (int f = 0; f <= a - b; f++) {
			bool k = true;
			for (int g = 0; g < b; g++) {
				for (int h = 0; h < b; h++) {
					if (e[g][h] != c[d + g][f + h])k = false;
				}
			}
			if (k) { puts("Yes"); return 0; }
		}
	}
	puts("No");
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=(0..read::<i32>()).map(|_|read::<i32>()).collect::<Vec<i32>>();
    println!("{}",a.iter().max().unwrap()-a.iter().min().unwrap())
}


Measured memory_bytes: 4352
s=input()
ans=len(s)
for i in "abcdefghijklmnopqrstuvwxyz":
  t=a=0
  for j in s:
    if j==i:a=max(a,t);t=0
    else:t+=1
  a=max(a,t)
  ans=min(ans,a)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int N; cin >> N;
    cout << N*800 - (N/15)*200 << endl;
}


Measured memory_bytes: 256
var main = standardInput => {
  var s = standardInput;
  var length = s.length;
  var count = 0;
  s = s.replace(/BC/g,"D")

  var tmpA = 0;
  for(i=0;i<length;i++){
    if(s[i] === "A"){
      tmpA += 1;
    } else if(s[i] === "D"){
      count += tmpA
    } else {
      tmpA = 0;
    }
  }
  console.log(count)
};

main(require("fs").readFileSync("/dev/stdin", "UTF-8"));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



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

	int N,M,S;
	cin>>N>>M>>S;
	vector<vector<array<int,3>>> adj(N);
	rep(i,0,M) {
		int u,v,a,b;
		cin>>u>>v>>a>>b;
		u--,v--;
		adj[u].push_back({v,a,b});
		adj[v].push_back({u,a,b});
	}

	vector<int> C(N),D(N);
	rep(i,0,N) cin>>C[i]>>D[i];

	const int maxs=2500;
	const ll inf=(ll)1e18;
	vector<array<ll,maxs+1>> dist(N);
	rep(i,0,N) fill(dist[i].begin(),dist[i].end(),inf);
	S=min(S,maxs);
	dist[0][S]=0;
	using state=tuple<ll,int,int>;
	priority_queue<state,vector<state>,greater<state>> q;
	q.emplace(0,0,S);
	vector<ll> res(N,inf);
	while (!q.empty()) {
		ll d;
		int v,s;
		tie(d,v,s)=q.top();
		q.pop();
		if (d!=dist[v][s]) continue;
		res[v]=min(res[v],d);

		// buy silver coins

		if (s+C[v]<=maxs) {
			int ns=s+C[v];
			ll nd=d+D[v];
			if (dist[v][ns]>nd) {
				dist[v][ns]=nd;
				q.emplace(nd,v,ns);
			}
		}

		// go to other city
		fore(adj[v],[u,a,b]) {
			int ns=s-a;
			ll nd=d+b;
			if (ns>=0 && dist[u][ns]>nd) {
				dist[u][ns]=nd;
				q.emplace(nd,u,ns);
			}
		}
	}

	rep(i,1,N) cout<<res[i]<<'\n';
}


Measured memory_bytes: 6252
#include<stdio.h>

int main(){
    int K,A,B;

    scanf("%d", &K);
    scanf("%d %d", &A, &B);

    int t_min = A / K;
    int t_max = B / K;
    int i,flag=0;

    for( i = t_min-1; i <= t_max+1; i++ ){
        if( i * K <= B && i * K >= A ){
            flag = 1;
            break;
        }
    }

    if( flag == 1 ) printf("OK\n");
    else printf("NG\n");

    return 0;
}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n; cin >> n;
    int dp[100100][3];
    int a[100100][3];
    rep(i,n)rep(j,3) cin >> a[i][j];

    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(j == k)continue;
                dp[i + 1][k] = max(dp[i][j] + a[i][k], dp[i + 1][k]);
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

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

Measured memory_bytes: 21204
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype>  // isupper, islower, isdigit, toupper, tolower
#include <cmath>   // abs, sin, cos, tan
#include <ctime>   // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  vll h(n); rep(i, n) cin >> h[i];
  ll ans = 0;
  for(ll i = 0;i < n;i++)
  {
    ans += h[i];
    ll tmp = h[i];
    for(ll j = i;j < n;j++)
    {
      tmp = min(tmp, h[j]);
      h[j] -= tmp;
    }
  }
  fin(ans);
  return;
}

//前処理
int main()
{
  int ti = clock();
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  //printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
    ll a[1000000] ;
    for(ll i = 0 ; i < 1000000 ; i++){
        a[i] = 0 ;
    }
    ll N ;
    cin >> N ;
    ll b ;
    for(int j = 0 ; j < N ; j++){
        cin >> b ;
        if(b == 0){
            a[0] ++ ;
            a[1] ++ ;
        }else{
            a[b-1]++ ;
            a[b]++ ;
            a[b+1]++ ;
        }
    }
    ll ans = 0 ;
    for(ll i = 0 ; i < 1000000 ; i++){
        if(ans < a[i]){
            ans = a[i] ;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 11448
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	char c; cin>>c;
	set<char> a,b;
	rep(i,0,26){
		a.insert('a'+i);
		b.insert('A'+i);
	}
	if(a.count(c)) cout<<"a";
	else cout<<"A";
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;
const int maxn=123456;
int n,m;
int ai[maxn];

void init(){
    for(int i=1;i<=n;i++)scanf("%d",&ai[i]);
    sort(ai+1,ai+1+n);
}
int ans;
void play(){
    ans=0;
    for(int i=1;i<=n;i++){
        if(m>=ai[i]){
            m-=ai[i];
            ans++;
        }
        else{
            return;
        }
    }
    if(m!=0){
        ans--;
    }
    
    
}

void Pri(){
    printf("%d\n",ans);
}



int main() {
    while(scanf("%d%d",&n,&m)!=EOF){
        init();
        play();
        Pri();
    }
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int A[3][3];
	for (int i = 0; i != 3; ++i)
	{
		for (int j = 0; j != 3; ++j)
		{
			int temp = 0;
			std::cin >> temp;
			A[i][j] = temp;
		}
	}

	int N = 0;
	std::cin >> N;

	int *b = new int[N];
	for (int i = 0; i < N; ++i)
	{
		int temp = 0;
		std::cin >> temp;
		b[i] = temp;
	}

	for (int i = 0; i != 3; ++i)
	{
		for (int j = 0; j != 3; ++j)
		{
			for (int bID = 0; bID < N; ++bID)
			{
				if (A[i][j] == b[bID])
				{
					A[i][j] = 0;
				}
			}
		}
	}


	int sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[0][i];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[1][i];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[2][i];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[i][0];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[i][1];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[i][2];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[i][i];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	sum = 0;
	for (int i = 0; i != 3; ++i)
	{
		sum += A[2 - i][i];
	}
	if (sum == 0)
	{
		std::cout << "Yes" << std::endl;
		return 0;
	}

	std::cout << "No" << std::endl;


	return 0;
}

Measured memory_bytes: 256
/**
 * Shuffle.cpp
 * Create:20180430
 * Description:n舞のカードの山のシャッフルした
 * 結果を出力するプログラム
 */
#include <iostream>
#include <vector>

/**
 * シャッフル関数
 * @param  cards カード順番文字列
 * @param  h     シャッフルの分離地点
 * @return       シャッフル結果
 */
std::string shuffle(std::string cards, int h){
  cards += cards.substr(0, h);
  cards.erase(cards.begin(), cards.begin() + h);
  return cards;
}

int main(int argc, char* argv[]){
  std::string cards;
  std::vector<std::string> results;

  // 入力
  while (true){
    std::cin >> cards;
    if (cards == "-")
      break;
    int shuffleCount;
    std::cin >> shuffleCount;
    for (int i = 0;i < shuffleCount; i++){
      int h;
      std::cin >> h;
      cards = shuffle(cards, h);
    }
    results.push_back(cards);
  }

  // 出力
  for (std::string str:results){
    std::cout << str << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3052
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int max_count=0,count=0;
    for(int i=0;i<s.length();++i)
    {
        if(s[i]=='R')
        {
            count++;
            max_count=max(max_count,count);
        }
        if(s[i]=='S')
        {
                count=0;
        }
    }
    cout<<max_count;
    return 0;
}


Measured memory_bytes: 3616
import heapq
N,M=map(int,input().split())
hq=list(map(float,input().split()))
hq=[-n for n in hq]
heapq.heapify(hq)
for i in range(M):
    heapq.heappush(hq,heapq.heappop(hq)/2)
hq=[int(a) for a in hq]
print(-sum(hq))

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}
ll ans[10];
int main(){
	map<pii,int> check;
	int h=read(),w=read(),n=read();
	REP(i,n){
		int b=read(),a=read();
		FOR(x,-2,1)
			FOR(y,-2,1)
				if(1<=a+x&&a+x<=w-2&&1<=b+y&&b+y<=h-2)
					check[MP(a+x,b+y)]++;
	}
	for(auto kv:check){
		ans[kv.second]++;
	}
	ans[0]=ll(h-2)*(w-2);
	FOR(i,1,10)
		ans[0]-=ans[i];
	REP(i,10){
		cout<<ans[i]<<endl;
	}
}


Measured memory_bytes: 56448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, k;
    sc(n) sc(k)
    vector<int> x(n);
    for (int i = 0; i < n; i++) sc(x[i])
    int ans = 1e9, tmp;
    for (int i = 0; i < n - k + 1; i++){
        tmp = min(abs(x[i]), abs(x[i+k-1]));
        tmp += abs(x[i+k-1] - x[i]);
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL //デバッグ出力系
#define dout(s) cout<<s<<"\n";
#define debug() if(true)
#else
#define dout(s)
#define debug() if(false)
#endif//
#define next asdnext
#define prev asdprev
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define vout(v) for(auto &i:v){cout<<i<<" ";}cout<<"\n"; //配列出力
#define vin(v) for(auto &i:v)cin>>i; //配列入力
#define vec(v,n) vector<int> v(n,0);
typedef long long ll;
typedef unsigned long long ull;

//void Main() {
//	int M, N;
//	cin >> N >> M;
//	vec(a,M);
//	vin(a);
//	sort(all(a));
//
//	rep(i,M-1) {
//		if (a[i] + 1 == a[i + 1]) {
//			cout << 0 << "\n";
//			break;
//		}
//	}
//
//	N -= M;
//
//	ll ans;
//
//	for (int i = 0; i * 2 <= N; i++) {
//
//	}
//}

void Main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	vin(S);

	vector<vector<bool>> B(H, vector<bool>(W));
	rep(i,H) {
		rep(j, W) {
			B[i][j] = (S[i][j] == '#');
		}
	}
	int ans = 1;

	vec(_up, W);
	vec(_down, W);

	rep(i,H) {
		int _left = 0, _right = 0;
		rep(j, W) {
			if (B[i][j] == 1) {
				continue;
			}

			int left=j, right = j, up = i, down = i;

			if (j > _right) {
				if (j != 0)while (B[i][left - 1] == 0) {
					left--;
					if (left == 0) break;
				}
				if (right != W - 1)while (B[i][right + 1] == 0) {
					right++;
					if (right == W - 1) break;
				}
			}
			else {
				right = _right; left = _left;
			}

			if (i > _down[j]) {
				if (i != 0)while (B[up - 1][j] == 0) {
					up--;
					if (up == 0) break;
				}
				if (down != H - 1)while (B[down + 1][j] == 0) {
					down++;
					if (down == H - 1) break;
				}
			}
			else {
				up = _up[j];
				down = _down[j];
			}
			int tmp = (right - left) + (down - up) + 1;

			_left = left; _up[j] = up; _down[j] = down;  _right = right;

			//cout << i << "\t:" << j << "\ttmp:" << tmp << "\tright:" << right << "\tleft:" << left << "\tup:" << up << "\tdown:" << down<< "\n";
			ans = max(ans, tmp);
		}
	}

	cout << ans;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 5120
import itertools
N,M,Q = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(Q)]
data = list(range(1,M+1))
A=list(itertools.combinations_with_replacement(data,N))
max_score = 0

for Ai in A:
  x = 0
  for a,b,c,d in L:
    if Ai[b-1] - Ai[a-1] == c:
      x += d
  max_score = max(max_score,x)

print(max_score)

Measured memory_bytes: 21548
#include <bits/stdc++.h>
using namespace std;
long long A, B, K;
int main() {
    cin >> A >> B >> K;
    if(K*2 > B-A+1) {
        for(long long i = A; i <= B; ++i) {
            cout << i << endl;
        }
    }else {
        for(long long i = A; i < A+K; ++i) {
            cout << i << endl;
        }
        for(long long j = B-K+1; j <= B; ++j) {
            cout << j << endl;
        }
    }
}

Measured memory_bytes: 256
/*
Question: 

*/

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ull i = a; i <= (ull)b; i++)
#define show(arr)                            \
    cerr << #arr << " is:"                   \
         << "\n";                            \
    for (auto& ax : arr) cout << ax << ", "; \
    cout << "\n\n";
#define disp(x) cerr << #x << " is " << x << "\n";
#define en "\n"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    if (s == t.substr(0, t.size() - 1))
        cout << "Yes\n";
    else 
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> cards(2*n),ans(2*n);
    iota(all(cards),1);
    rep(i,m){
        int k; cin >> k;
        if (k) rep(i,2*n) ans[i]=cards[(i+k)%(2*n)];
        else rep(i,2*n){
            if (i%2==0) ans[i]=cards[i/2];
            else ans[i]=cards[n+i/2];
        }
        rep(i,2*n) cards[i]=ans[i];
    }
    rep(i,2*n) cout << ans[i] << endl;
}


Measured memory_bytes: 3220
//Harjot Singh Student NIT JALANDHAR	

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;

int main()
{


    int n,k;
    cin>>n>>k;
    int move[n];
    for(int i=0;i<n;i++)
    	cin>>move[i];

    int dp[k+1];
    dp[0]=0;
  
    for( int i=1;i<=k;i++)
    {
    	dp[i]=0;
    	for(int j=0;j<n;j++)
    	{
    		if(i>=move[j])
    		{
    			if(dp[i-move[j]]==0)
    				dp[i]=1;
    			
    		}
    	}
     

    }
   if(dp[k]==0)
   	cout<<"Second"<<endl;
   else
   	cout<<"First"<<endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5+1;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w,m;
	cin >> h >> w >> m;
	vector<int> row(N,0),col(N,0);
	map<pair<int,int>,int > mp;
	for(int i = 0; i < m;++i){
		int x,y;
		cin >> x >> y;
		++row[x];
		++col[y];
		++mp[{x,y}];
	}
	int maxx = 0,maxy = 0;
	for(int i = 1; i < N;++i){
		maxx = max(maxx,row[i]);
		maxy = max(maxy,col[i]);
	}
	int ans = maxx + maxy - 1;
	vector<int> r,c;
	for(int i = 1; i < N;++i){
		if(maxx == row[i])
			r.push_back(i);
		if(maxy == col[i])
			c.push_back(i);
	}
	for(int i = 0; i < (int)r.size();++i){
		for(int j = 0; j < (int)c.size();++j){
			if(mp[{r[i],c[j]}] == 0){
				cout << ans+1 << "\n";
				return 0;
			}
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 27420
N = gets.to_i
a = gets
b = gets
ichi = []
ni = []
a.split.each{|num|
    ichi << num.to_i
}
b.split.each{|num|
    ni << num.to_i
}

sum = []

for i in 0...N do
    count = 0
    for j in 0..i do
        count += ichi[j]
    end

    for k in i...N do
        count += ni[k]
    end
    sum[i] = count
end

print sum.max

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=b-(a-1);i<b+a-1;i++){
		printf("%d ",i);
	}
	printf("%d\n",b+a-1);
	return 0;
}

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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(2*N);
  for (int i = 0; i < 2*N; i++) {
    std::cin >> A[i];
  }
  int max_candies = 0;
  for (int move_down_point = 0; move_down_point < N; move_down_point++) {
    int total_candy = 0;
    for (int i = 0; i < move_down_point + 1; i++) {
      total_candy += A[i];
    }
    for (int i = N + move_down_point; i < 2*N; i++) {
      total_candy += A[i];
    }
    if (total_candy > max_candies) {
      max_candies = total_candy;
    }
  }
  std::cout << max_candies << std::endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=305;
string s;
int dp[305][305][305],K;
int dfs(int l,int r,int x)
{
    if(r<l)return 0;
    if(l==r)return 1;
    if(dp[l][r][x]!=-1)return dp[l][r][x];//记忆化思想，减少搜索次数
    int t=max(dfs(l+1,r,x),dfs(l,r-1,x));//向左或右扩展一个
    if(s[l]==s[r])t=max(t,dfs(l+1,r-1,x)+2);//相等，进行扩展
    if(x)t=max(t,dfs(l+1,r-1,x-1)+2);//改变一个字符，向内扩展
    return dp[l][r][x]=t;
}
int main()
{
    cin>>s>>K;
    memset(dp,-1,sizeof(dp));
    cout<<dfs(0,s.size()-1,K)<<endl;
    return 0;
}


Measured memory_bytes: 111232
let N = stdin.ReadLine() |> int
let A = stdin.ReadLine().Split() |> Array.map int64

let rec solver prod n =
    if n = N then prod
    else
        let tmp = prod * A.[n]
        if (tmp < prod || tmp > 1000000000000000000L) then -1L
        else solver (prod * A.[n]) (n + 1)

if (Array.contains 0L A) then 0L
else solver 1L 0
|> stdout.WriteLine


Measured memory_bytes: 42496
#include <bits/stdc++.h>
using namespace std;
int a,b;
char s[100001];
int main()
{
    cin>>a>>b;
    for(int i=1; i<=a+b+1; i++) cin>>s[i];
    for(int i=1; i<=a+b+1; i++)
    {
        if((s[i]<48 && i!=a+1)||(s[i]>58 && i!=a+1)) 
        {
            cout<<"No";
            return 0;
        }
        if(i==a+1 && s[i]!='-')
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int A, B, C;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> A >> B >> C;

  cout << min(B / A, C) << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

vector<int> score(5);

int calculateScore(vector<vector<int> > a)
{
    int bonus = 1;
    int ret = 0;

    for(;;){
        vector<vector<bool> > check(5, vector<bool>(5, false));
        for(int y=0; y<5; ++y){
            for(int x=0; x<3; ++x){
                if(a[y][x] != -1 && a[y][x] == a[y][x+1] && a[y][x] == a[y][x+2])
                    check[y][x] = check[y][x+1] = check[y][x+2] = true;
            }
        }
        for(int y=0; y<3; ++y){
            for(int x=0; x<5; ++x){
                if(a[y][x] != -1 && a[y][x] == a[y+1][x] && a[y][x] == a[y+2][x])
                    check[y][x] = check[y+1][x] = check[y+2][x] = true;
            }
        }

        bool stop = true;
        for(int y=0; y<5; ++y){
            for(int x=0; x<5; ++x){
                if(check[y][x]){
                    ret += bonus * score[a[y][x]];
                    a[y][x] = -1;
                    stop = false;
                }
            }
        }
        if(stop)
            return ret;

        for(int x=0; x<5; ++x){
            int y2 = 4;
            for(int y=4; y>=0; --y){
                if(a[y][x] != -1){
                    swap(a[y][x], a[y2][x]);
                    -- y2;
                }
            }
        }

        ++ bonus;
    }
}

int solve(int n, vector<vector<int> >& a, int y, int x, int prev)
{
    int ret = calculateScore(a);
    if(n == 0)
        return ret;

    for(int i=0; i<4; ++i){
        if(i == prev)
            continue;

        int y2 = y + dy[i];
        int x2 = x + dx[i];
        if(y2 < 0 || y2 > 4 || x2 < 0 || x2 > 4)
            continue;

        swap(a[y][x], a[y2][x2]);
        ret = max(ret, solve(n-1, a, y2, x2, i^2));
        swap(a[y][x], a[y2][x2]);
    }

    return ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == -1)
            return 0;

        vector<vector<int> > a(5, vector<int>(5));
        for(int y=0; y<5; ++y){
            for(int x=0; x<5; ++x){
                cin >> a[y][x];
                -- a[y][x];
            }
        }

        for(int i=0; i<5; ++i)
            cin >> score[i];

        int ret = 0;
        for(int y=0; y<5; ++y){
            for(int x=0; x<5; ++x){
                ret = max(ret, solve(n, a, y, x, -1));
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1216
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

class DisjointSet {
public:
	vector<int> rank;
	vector<int> parent;

	DisjointSet() {}

	// 0, 1, ... size-1 をそれぞれ唯一の要素とする
	// size個の互いに素な集合を作成
	DisjointSet(int size) {
		rank.resize(size, 0);
		parent.resize(size, 0);
		for (int i=0; i<size; i++) {
			makeSet(i);
		}
	}

	// 要素がXただ一つである新しい集合を作る
	void makeSet(int x) {
		parent[x] = x;
		rank[x] = 0;
	}

	// xとyが同じ集合に属しているかを判定する
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	// 指定された2つの要素x, yを合併する
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	// 低い方の木を高い方の木に合併
	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			parent[y] = x;
		} else {
			parent[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	// 要素xが属する集合の代表の要素を求める
	int findSet(int x) {
		if (x != parent[x]) {
			parent[x] = findSet(parent[x]);
		}
		return parent[x];
	}
};

int A[100000], B[100000];
int C[100000], D[100000];
map<int, int> F;
int ans[100000];

int main(){
	int N, M, K;
	cin >> N >> M >> K;

	for (int i=0; i<M; i++) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	for (int i=0; i<K; i++) {
		cin >> C[i] >> D[i];
		C[i]--;
		D[i]--;
	}

	DisjointSet ds = DisjointSet(N);

	for (int i=0; i<M; i++) {
		ds.unite(A[i], B[i]);
	}

	for (int i=0; i<N; i++) {
		F[ds.findSet(i)]++;
	}

	for (int i=0; i<N; i++) {
		ans[i] = F[ds.findSet(i)] - 1;
	}

	for (int i=0; i<M; i++) {
		if (ds.findSet(A[i]) == ds.findSet(B[i])) {
			ans[A[i]]--;
			ans[B[i]]--;
		}
	}

	for (int i=0; i<K; i++) {
		if (ds.findSet(C[i]) == ds.findSet(D[i])) {
			ans[C[i]]--;
			ans[D[i]]--;
		}
	}

	for (int i=0; i<N; i++) {
		if (i>0) cout << " ";
		cout << ans[i];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 7808
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
k = 0
sh = shiro
for i in range(n):
    if s[i] == "#":
        k += 1
    else:
        sh -= 1
    mi = min(mi,k+sh)
print(mi)

Measured memory_bytes: 3500
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        int sum=0;
        rep(i,n/4){int temp;cin>>temp;sum+=temp;}
        cout<<sum<<endl;
    }
}

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

int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int N;
    N = ((H2*60+M2) - (H1*60+M1)) - K;
  cout << N << endl;
}


Measured memory_bytes: 3624
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main() {
  let ab: Vec<u32> = read_vec();
  let ans = if ab[0] % 3 == 0 || ab[1] % 3 == 0 || (ab[0] + ab[1]) % 3 == 0 {
    "Possible"
  } else {
    "Impossible"
  };
  
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
   
#define pb push_back
#define ll long long
#define f first
#define s second
#define ld long double
#define fa fflush(stdout); 

using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
} 
const int N = 5e5 + 100;
const ll mod = 1e9 + 7;
 
int main ()
{
	data();                          
	int n;
	cin >> n;
	int a[n + 1];
	int mx = 0;
	int kol = 0;
	set<int> s;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		mx = max(mx, a[i]);
		s.insert(a[i]);
	}
	s.erase(*s.rbegin());
	int ans2;
	if (s.size() > 0)
	{
		ans2 = *s.rbegin();
	}
	for (int i = 1; i <= n; i++)
	{
		if (mx == a[i])
		{
			kol++;
		}
	}
	for (int i = 1; i <= n; i++)
	{                                
		if (a[i] != mx)
		{
			cout << mx << '\n';
			continue;
		}
		if (kol > 1)
		{
			cout << mx << '\n';
			continue;
		}
		cout << ans2 << '\n';
	}
	
}     
//JUDGE_ID: 295965SY
//Tis I

Measured memory_bytes: 9768
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 310

/* Dijkstra O(NlogM)*/

struct Dijkstra{
  
  typedef ll Type;
  
  int V;
  vector<vector<pair<int,Type> > > G;
  vector<int> cost;
  
  Dijkstra(int n):
    V(n),G(n,vector<pair<int,Type> >()){}
  
  void add_edge(int u, int v, Type c){
    G[u].push_back({v,c});
  }
  
  Type solve(int s, int g = -1){
    cost.assign(V,-1);
    priority_queue<pair<Type,int> > pq;
    Type max_cost = 0;
    
    pq.push({0,s});
    
    while(pq.size()){
      Type now_cost = pq.top().first;
      int now = pq.top().second;
      pq.pop();
      
      if(cost[now] >= 0) continue;
      
      cost[now] = -now_cost;
      max_cost = max(max_cost, -now_cost);
      
      if(now == g) return -now_cost;
      
      for(int i=0;i<(int)G[now].size();i++){
        pq.push({now_cost-G[now][i].second, G[now][i].first});
      }
    }
    
    return INF;
  }
  
};

int main(){
  int n;
  int a[SIZE][SIZE];
  pair<int,pair<int,int> > dist_list[SIZE*SIZE];
  scanf("%d",&n);

  int t = 0;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",a[i]+j);

      if(i > j){
        dist_list[t++] = {a[i][j],{i,j}};
      }
    }
  }

  sort(dist_list,dist_list+t);

  ll ans = 0;

  Dijkstra dijk(n);
  
  for(int i=0;i<t;i++){
    int p = dist_list[i].second.first;
    int q = dist_list[i].second.second;
    int d = dist_list[i].first;

    ll dist_p_q = dijk.solve(p,q);

    if(dist_p_q < d){
      puts("-1");
      return 0;
    }
    
    if(dist_p_q == INF || dist_p_q != d){
      dijk.add_edge(p,q,d);
      dijk.add_edge(q,p,d);
      ans += d;
    }
  }

  
  printf("%lld\n",ans);
  
  return 0;
}



Measured memory_bytes: 1920
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
    cin.tie(0);

    int m;
    cin >> m;
    int h[m];
    for (int i = 0; i < m; i++) {
        cin >> h[i];
    }

    int max = 0, ans = 0;
    for (int i = 0; i < m; i++) {
        if (max <= h[i]) {
            ans++;
            max = h[i];
            // cout << h[i] << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int B[2005][2005];
int W[2005][2005];

int main(){
    int N, K; cin >> N >> K;
    int M = 2 * K;
    REP(i,M+1)REP(j,M+1){
        B[i][j] = 0;
        W[i][j] = 0;
    }
    REP(i,N){
        int x, y; char c;
        scanf("%d %d %c", &x, &y, &c);
        if (c=='B') B[x%M+1][y%M+1]++;
        else W[x%M+1][y%M+1]++;  
    }

    // REP(i,M+1){REP(j,M+1) cout << B[i][j] << " "; cout << "\n";}
    // REP(i,M+1){REP(j,M+1) cout << W[i][j] << " "; cout << "\n";}

    REP(i,M+1)REP(j,M){
        B[i][j+1] += B[i][j];
        W[i][j+1] += W[i][j];
    }

    REP(j,M+1)REP(i,M){
        B[i+1][j] += B[i][j];
        W[i+1][j] += W[i][j];
    }
    
    int ans = 0;
  
    FOR(i,0,K+1)FOR(j,0,K+1){
        
        int tmp = 0;

        tmp += B[M][M];
        tmp -= B[i+K][M];
        tmp += B[i][M];
        tmp -= B[M][j+K];
        tmp += 2*B[i+K][j+K];
        tmp -= 2*B[i][j+K];
        tmp += B[M][j];
        tmp -= 2*B[i+K][j];
        tmp += 2*B[i][j];
        
        tmp += W[i+K][M];
        tmp -= W[i][M];
        tmp += W[M][j+K];
        tmp -= 2*W[i+K][j+K];
        tmp += 2*W[i][j+K];
        tmp -= W[M][j];
        tmp += 2*W[i+K][j];
        tmp -= 2*W[i][j];

        ans = max(ans, tmp); 
    }

    FOR(i,0,K+1)FOR(j,0,K+1){
        
        int tmp = 0;

        tmp += W[M][M];
        tmp -= W[i+K][M];
        tmp += W[i][M];
        tmp -= W[M][j+K];
        tmp += 2*W[i+K][j+K];
        tmp -= 2*W[i][j+K];
        tmp += W[M][j];
        tmp -= 2*W[i+K][j];
        tmp += 2*W[i][j];
        
        tmp += B[i+K][M];
        tmp -= B[i][M];
        tmp += B[M][j+K];
        tmp -= 2*B[i+K][j+K];
        tmp += 2*B[i][j+K];
        tmp -= B[M][j];
        tmp += 2*B[i+K][j];
        tmp -= 2*B[i][j];

        ans = max(ans, tmp); 
    }
  
    cout << ans << endl;
  
    return 0;
}

Measured memory_bytes: 31616
#include<iostream>
#include<vector>
#include<cmath>

int main() {
  int N;
  std::cin >> N;
  std::vector<std::vector<int>> point(N,std::vector<int>(2));
  for (int i=0; i < N; i++) {
    std::cin >> point.at(i).at(0) >> point.at(i).at(1);
  }
  double sum = 0;
  for (int i = 0; i<N-1; i++) {
    for (int j = i+1; j < N; j++) {
      double x_dif = (point.at(i).at(0)-point.at(j).at(0))*(point.at(i).at(0)-point.at(j).at(0));
      double y_dif = (point.at(i).at(1)-point.at(j).at(1))*(point.at(i).at(1)-point.at(j).at(1));
      sum += std::sqrt(x_dif+y_dif);
    }
  }
  sum *= N-1;
  sum /= (N * (N-1) / 2);
  
  printf("%f", sum);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
ll L, R;

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

  cin >> L >> R;
  if (R-L >=2019){
    cout << 0 << endl;
    return 0;
  }
  L%=2019;
  R%=2019;
  if (L > R){
    cout << 0 << endl;
    return 0;
  }

  int ans = 2018;
  for(int i=L; i<R; i++){
    for(int j=i+1; j<=R; j++){
      ans = min(ans, (i*j)%2019);
      if (ans ==0) break;
    }
    if (ans ==0) break;
  }

  cout << ans << endl;
  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    string t = "keyence";
    int i = 0;
    for(; i < 7; i++) if(s[i] != t[i]) break;
    int j = 0;
    for(; j < 7; j++) if(s[n - 1 - j] != t[6 - j]) break;
    if(i + j >= 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define pi pair<ll,ll>
#define fi first
#define si second
#define mkp make_pair
#define pb push_back
#define clr(arr) memset(arr,0,sizeof(arr))
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
deque<ll>dq;
map<ll,ll>mp;
set<ll>st;
vector<ll>vt;
ll mod=1e9+7;
const int N=1e6+5;
ll arr[N];

int main()
{
    IOS;
    ll n,m,x,y,z,i,j,k,p,f=0,tc,cnt=0,sum=0,mul=1,mi=1e18,ma=-1e18,a,b,c,d,sz;
    string str;
    char ch;
    double db;
    //code
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i],mi=min(mi,arr[i]),ma=max(ma,arr[i]);
  x=ma;
  ll mi1=1e18;
  for(i=mi;i<=x;i++)
  {
      sum=0;
      for(j=0;j<n;j++)
      {
          p=abs(i-arr[j]);
          sum+=p*p;
      }
      mi1=min(sum,mi1);
  }

   cout<<mi1<<endl;



    //code
    return 0;
}



Measured memory_bytes: 3592
[A, B, M] = [int(i) for i in input().split()]
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
min_amount = min(a_list) + min(b_list)

for m in range(M):
  [x, y, c] = [int(i) for i in input().split()]
  amount = a_list[x-1] + b_list[y-1] - c
  min_amount = min(amount, min_amount)
print(min_amount)

Measured memory_bytes: 18488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	ll n;cin>>n;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=10*n;j++){
			if(4*i*j-j*n-i*n==0) continue;
			if((n*i*j)%(4*i*j-n*j-n*i)==0&&(n*i*j)/(4*i*j-n*j-n*i)>0){
				cout<<i<<" "<<j<<" "<<(n*i*j)/(4*i*j-n*j-n*i)<<"\n";
				return 0;
			}
		}
	}
}

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

int main() {
  int N ,alice=0,bob=0;
  cin >> N;
  
  vector<int> vec ( N) ;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  } 
    sort(vec.begin(), vec.end()); 
    reverse(vec.begin(), vec.end()); 
 
    for (int i = 0; i < N; i++) {

       if (i%2 ==0){
       alice = alice + vec.at(i);
       }else{
        bob = bob + vec.at(i);
          }   
    }
  cout << alice - bob << endl;
  
}


Measured memory_bytes: 3624
import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;

public class Main {
	public static int convertTo (ArrayList<Integer> a) {
		int result = 0 ; 
		for(int i = a.size()-1; i >= 0 ; i --) {
			result += (int)(a.get(i)*(Math.pow(10,i)));
		}
		return result ;
	} 
	public static int repeat (int a , HashSet<Integer> b) {
		int c = 0 ;
		 while(a!= 0) {
			 if(b.contains(a%10))
        	    c++ ;
        	  a/=10;
        }
		 return c ;
	}
	public static void main(String[]args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] a = br.readLine().split(" ");
        int N = Integer.parseInt(a[0]);
        int r = N ;
        int K = Integer.parseInt(a[1]);
        HashSet<Integer> kNumbers = new HashSet<>();
        TreeSet<Integer> nNumbers = new TreeSet<>();
        String[] b = br.readLine().split(" ");
        for(int i = 0 ; i < K ; i ++) {
        	kNumbers.add(Integer.parseInt(b[i]));
        }
        while(true) {
        if(repeat(r , kNumbers) == 0) {
        	System.out.print(r);
        	break;
        }
        else
        	r++;
        }
	}
}


Measured memory_bytes: 33156
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<ll> A(N + 1,0);
    rep(i, N) cin >> A[i+1];
    rep(i, N+1) A[i + 1] += A[i];

    vec<ll> B(M + 1,0);
    rep(i, M) cin >> B[i+1];
    rep(i, M+1) B[i + 1] += B[i];

    ll ans = 0;
    int b_i = M;
    rep(i, N+1) {
        if (A[i] > K) break;
        while(A[i] + B[b_i] > K) --b_i;
        ans = max(ans,i+b_i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 6412
def main():
    N = int(input())
    A = list(map(int, input().split()))

    for e in A:
        if e % 2 == 0 and e % 3 != 0 and e % 5 != 0:
            print("DENIED")
            exit(0)

    print("APPROVED")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int N, M, W, T;
map<string,int> f_item;
vector<pii> item;
vector<pii> pos;
vector<vector<pii> > sale;

vector<pii> item_set;

const ll INF = 1e15;

ll bitDP[1<<8][8];
ll solve_bitdp(int status, int now) {
	if(bitDP[status][now]+1)
		return bitDP[status][now];
	if(!status)
		return bitDP[status][now] = abs(pos[N].fi-pos[now].fi)
			+ abs(pos[N].se-pos[now].se);
	ll res = INF;
	for(int i = 0; i < N; i++) {
		if((status & (1 << i))) {
			ll cost;
			cost = abs(pos[i].fi-pos[now].fi) + abs(pos[i].se-pos[now].se);
			assert(cost < INF);
			res = min(res, solve_bitdp(status ^ (1 << i), i) + cost);
		}
	}
	return bitDP[status][now] = res;
}

ll dp[10100];
ll solve() {
	for(int i = 0; i < (1 << N); i++) {
		ll route, earn;
		route = solve_bitdp(i,N);
		memset(dp,0,sizeof(dp));
		for(int j = 0; j < N; j++) {
			if(i & (1 << j)) for(int k = 0; k < sale[j].size(); k++) {
				pii tmp;
				pii dpitem;
				tmp = item[sale[j][k].fi];
				dpitem = pii(tmp.fi, tmp.se-sale[j][k].se);
				for(int l = 0; l <= W; l++)
					if(0 <= l-dpitem.fi && l-dpitem.fi <= W)
						dp[l] = max(dp[l],dp[l-dpitem.fi]+dpitem.se);
			}
		}
		earn = dp[W];
		item_set.push_back(pll(route,earn));
		//cout << route << "," << earn << endl;
	}
	memset(dp,0,sizeof(dp));
	for(int i = 0; i < item_set.size(); i++) {
		for(int j = 0; j <= T; j++) {
			if(0 <= j-item_set[i].fi && j-item_set[i].fi <= T)
				dp[j] = max(dp[j], dp[j-item_set[i].fi] + item_set[i].se);
		}
	}
	return dp[T];
}

int main() {
	cin >> N >> M >> W >> T;
	for(int i = 0; i < M; i++) {
		string S;
		int V, P;
		cin >> S >> V >> P;
		f_item[S] = i;
		item.push_back(pii(V,P));
	}
	sale.resize(N);
	for(int i = 0; i < N; i++) {
		int L, X, Y;
		cin >> L >> X >> Y;
		pos.push_back(pii(X,Y));
		for(int j = 0; j < L; j++) {
			string R;
			int K;
			cin >> R >> K;
			sale[i].push_back(pii(f_item[R],K));
		}
	}
	pos.push_back(pii(0,0));
	memset(bitDP,-1,sizeof(bitDP));
	cout << solve() << endl;
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;
typedef map<ll,ll>::iterator mit;
typedef set<ll>::iterator sit;
typedef vector<ll>::iterator vit;

ll mod = 1e9 + 7;

void solve()
{
	ll N, W;
	cin>>N>>W;
	vll Wt(N+1, 0), V(N+1, 0);
	ll val = 0;
	rep1(i, N+1)
	{
		cin>>Wt[i]>>V[i];
		val += V[i];
	}
	vll dp(val+1, INT_MAX);
	dp[0] = 0;
	rep1(i, N+1)
	{
		ll w = Wt[i], v = V[i];
		for(ll j = val; j >= v; j--)
			dp[j] = min(dp[j], dp[j-v] + w);
	}
	for(ll i = val; i >= 0; i--)
	{
		//trace2(i, dp[i]);
		if(dp[i] <= W)
		{
			cout<<i<<endl;
			break;
		}
	}
	return;
}


int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
	{
		solve();
	}
	return 0;	
}

Measured memory_bytes: 1024