akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left,insort_left
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
t=[int(input())for _ in range(d)]
m=int(input())
dq=[list(map(int,input().split()))for _ in range(m)]
x=[[0]for _ in range(26)]
ans=0
for i in range(d):
  x[t[i]-1].append(i+1)
  ans+=s[i][t[i]-1]
  for j in range(26):ans-=((i+1)-x[j][-1])*c[j]
for i in range(26):
  x[i].append(d+1)
for dd,q in dq:
  p=t[dd-1]
  t[dd-1]=q
  ans-=s[dd-1][p-1]
  ans+=s[dd-1][q-1]
  pi=bisect_left(x[p-1],dd)
  qi=bisect_left(x[q-1],dd)
  pl=dd-x[p-1][pi-1]
  pr=x[p-1][pi+1]-dd
  ql=dd-x[q-1][qi-1]
  qr=x[q-1][qi]-dd
  del x[p-1][pi]
  insort_left(x[q-1],dd)
  ans-=c[p-1]*pl*pr
  ans+=c[q-1]*ql*qr
  print(ans)

Measured memory_bytes: 22180
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int res = 1000 - n % 1000;
	if (res == 1000)
		res = 0;
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3628
#include <stdio.h>

int main() {

	int i, min=1000, max=0, cnt, buf[1000];
	
	scanf( "%d", &cnt );
	
	for( i = 0; i < cnt; i++ ){
		scanf( "%d", &buf[i] );
		if ( min > buf[i] )
			min = buf[i];
		if ( max < buf[i] )
			max = buf[i];
	}
	printf( "%d", max-min );
	return( 0 );
}


Measured memory_bytes: 128
n=int(input())
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
if digitSum(n)%9==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11188
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll n,k;
vector<ll>hist;
vector<vector<ll>>countvec;//何回目のテレポートで到着したか(これの要素数が2になったとき二回目の到着)
vector<ll>cycle;
vector<ll>vec;//1-indexed
int main() {

cin>>n>>k;
vec.resize(n+1);
countvec.resize(n+1);
rep(i,n)
{cin>>vec[i+1];}
ll counter = 0;
ll nowx=1;
while(1)
{
  hist.push_back(nowx);
  countvec[nowx].push_back(counter);
  if(countvec[nowx].size()==2)//2回以上訪れた地点を見つけたとき
  {int cyclesize=countvec[nowx][1]-countvec[nowx][0];
    rep(i,cyclesize)
    {cycle.push_back(hist[countvec[nowx][0]+i]);}
    break;
  }
  counter++;
  nowx=vec[nowx];
 if(counter==k){cout<<nowx<<endl;return 0;}
}

cout<<cycle[(k-counter)%cycle.size()]<<endl;
//cout<<k-counter%cycle.size()<<endl;


/*rep(i,cycle.size())
{cout<<cycle[i];}cout<<endl;*/
/*rep(i,hist.size())
{cout<<hist[i];}cout<<endl;*/

return 0;
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 16692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int count = 0;
        if (s.charAt(0)=='1'){
            count++;
        }
        if (s.charAt(1)=='1'){
            count++;
        }
        if (s.charAt(2)=='1'){
            count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23636
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<math.h>
using namespace std;
const int maxn=3e2+7;
typedef long long ll;
const int INF=0x3f3f3f3f;
int dis[300][300],n,color[300],visited[300];
vector<int> v[300];
char c[300][300];
int dfs(int x,int flag)
{
	color[x]=flag;
	for(int i=1;i<=n;i++)
	{
		if(c[x][i]=='1')
		{
			if(color[x]==color[i])
				return 0;
			if(color[i]==0)
			{
				if(dfs(i,3-flag)==0)
					return 0;
			}
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='1')
			{
				dis[i][j]=dis[j][i]=1;
			}
			else
				dis[i][j]=dis[j][i]=INF;
			if(i==j)
				dis[i][j]=0;
		}
	int flag=dfs(1,1);
	for(int i=1;i<=n;i++)
		if(color[i]==0)
		{
			flag=0;
			break;
		}
	if(flag==0)
	{
		printf("-1\n");
		return 0;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(dis[i][j]>dis[i][k]+dis[k][j])
				dis[i][j]=dis[i][k]+dis[k][j];
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(dis[i][j]<=INF&&i!=j)
				ans=max(ans,dis[i][j]);
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 1152
a,b=map(int,input().split())
a_s=a/0.08
a_t=(a+1)/0.08
b_s=b/0.1
b_t=(b+1)/0.1

a0=int(a_s)
a1=int(a_t)
b0=int(b_s)
b1=int(b_t)


if (a_s-a0)>0:
  a0+=1
if (a_t-a1)<=0:
  a1-=1
if (b_s-b0)>0:
  b0+=1
if (b_t-b1)<=0:
  b1-=1

lista=[i for i in range(a0,a1+1)]
listb=[i for i in range(b0,b1+1)]

ansl=[]
for j in range(len(lista)):
  if lista[j] in listb:
    ansl.append(lista[j])

if not ansl==[]:
  ans=ansl[0]
  print(ans)
else:
  print(-1)

Measured memory_bytes: 9228
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), sum = 0;;
    vector<ll>w(n); REP(i, n)sum += w[i] = in();
    vector<ll>imos(n); REP(i, n - 1)imos[i + 1] = imos[i] + w[i];
    ll ans = INFLL;
    REP(i, n)ans = min(ans, abs(imos[i] - (sum - imos[i])));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

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

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

//-----end of template-----//

using ll = long long int;
ll PowMod(ll N, ll P){
    ll ans = 1;
    for(ll i=0; i<P; ++i){
        ans *= N;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	bool flag = false;
	for(int i = 0; i < n; ++i){
		i64 a;
		cin >> a;
		if(a % 2) flag = true;
	}
	if(flag) cout << "first" << endl;
	else cout << "second" << endl;
}

Measured memory_bytes: 256
let NXT = readLine()!.split(separator: " ").compactMap { Int($0) }

if NXT[0] % NXT[1] == 0 {
    print(NXT[0] / NXT[1] * NXT[2])
} else {
    print((NXT[0] / NXT[1] + 1) * NXT[2])
}


Measured memory_bytes: 8256
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, q, now = 0, c;
	cin >> n >> q;

	vector<string> name(n);
	vector<int> time(n);
	queue<int> Q;

	for (int i = 0; i < n; ++i) {
		cin >> name.at(i) >> time.at(i);
		Q.push(i);
	}

	while (Q.size() > 0) {
		c = Q.front();
		Q.pop();
		if (time.at(c) > q) {
			time.at(c) -= q;
			now += q;
			Q.push(c);
		} else {
			now += time.at(c);
			cout << name.at(c) << " " << now << endl;
		}
	}
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    vector<vector<int>> graph(n,vector<int>(n,0));
    int i,j;
    for(i = 0;i < m;++i){
        cin >> a.at(i) >> b.at(i);
        graph.at(a.at(i)-1).at(b.at(i)-1) = 1;
        graph.at(b.at(i)-1).at(a.at(i)-1) = 1;
    }
    int ans = 0;
    int tmp;
    for(i = 0;i < m;++i){
        graph.at(a.at(i)-1).at(b.at(i)-1) = 0;
        graph.at(b.at(i)-1).at(a.at(i)-1) = 0;
        vector<bool> bridge(n,false);
        queue<int> ten;
        bridge.at(0) = true;
        for(j = 0;j < n;++j){
            if(graph.at(0).at(j)){
                bridge.at(j) = true;
                ten.push(j);
            }
        }
        vector<bool> check(n,false);
        check.at(0) = true;
        while(ten.size()){
            tmp = ten.front();
            ten.pop();
            for(j = 0;j < n;++j){
                if(graph.at(tmp).at(j)){
                    bridge.at(j) = true;
                    if(!check.at(j)){
                        ten.push(j);
                    }
                }
            }
            check.at(tmp) = true;
        }
        bool flag = false;
        for(j = 0;j < n;++j){
            if(!bridge.at(j)){
                flag = true;
                break;
            }
        }
        if(flag){
            ++ans;
        }
        graph.at(a.at(i)-1).at(b.at(i)-1) = 1;
        graph.at(b.at(i)-1).at(a.at(i)-1) = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
using namespace std;
int main()
{
    int max_profit = numeric_limits<int>::min();
    int min_value;
    int N;
    cin >> N;
    cin >> min_value;
    for (int i = 1; i <= N - 1; i++)
    {
        int value;
        cin >> value;
        max_profit = max(max_profit, value - min_value);
        min_value = min(value, min_value);
    }
    cout << max_profit << "\n";
    return 0;
}


Measured memory_bytes: 3120
#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 REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int n;cin>>n;
  int tmp1=0,tmp2=0;
  int ans;
  vector<int> w(n);
  rep(i,n){
    cin>>w[i];
    tmp1+=w[i];
  }

  vector<int> T;
  rep(i,n){
    tmp1-=w[i];
    tmp2+=w[i];
    T.push_back(abs(tmp1-tmp2));
  }
  sort(T.begin(),T.end());
  ans=T[0];
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<math.h>
#include<string>
using namespace std;

class dice {
public:
	dice(int m1, int m2, int m3, int m4, int m5, int m6);
	~dice();
	void roll(char c);
	int getmT() { return mT; };
	int getmS() { return mS; };
	int getmE() { return mE; };
	int getmW() { return mW; };
	int getmN() { return mN; };
	int getmB() { return mB; };
private:
	int mE, mW, mS, mN;
	int mT, mB;

};

dice::dice(int m1, int m2, int m3, int m4, int m5, int m6) : mT(m1), mS(m2), mE(m3), mW(m4), mN(m5), mB(m6) {

}

dice::~dice() {

}

void dice::roll(char c) {
	switch (c) {
	case 'E':
		int tE;
		tE = mE;
		mE = mT;
		mT = mW;
		mW = mB;
		mB = tE;
		break;
	case 'W':
		int tW;
		tW = mW;
		mW = mT;
		mT = mE;
		mE = mB;
		mB = tW;
		break;
	case 'N':
		int tN;
		tN = mN;
		mN = mT;
		mT = mS;
		mS = mB;
		mB = tN;
		break;
	case 'S':
		int tS;
		tS = mS;
		mS = mT;
		mT = mN;
		mN = mB;
		mB = tS;
		break;
	}
}



int main() {
	int me[12];
	for (int i = 0; i < 12; i++) {
		cin >> me[i];
	}
	dice* mDice1;
	dice* mDice2;
	mDice1 = new dice(me[0], me[1], me[2], me[3], me[4], me[5]);
	mDice2 = new dice(me[6], me[7], me[8], me[9], me[10], me[11]);
	string meirei = "SWSWSWSWWSWSWSWSENENENENNENENENESWENSWENSSWWEENNSWESWESWESWESSSSWWWW";
	for (int j = 0; j < meirei.length(); j++) {
		mDice1->roll(meirei[j]);
		if ((mDice1->getmT() == mDice2->getmT()) &&
			(mDice1->getmW() == mDice2->getmW()) &&
			(mDice1->getmN() == mDice2->getmN()) &&
			(mDice1->getmE() == mDice2->getmE()) &&
			(mDice1->getmS() == mDice2->getmS()) &&
			(mDice1->getmB() == mDice2->getmB())) {
			cout << "Yes" << endl;
			break;
		}
		else if ((mDice1->getmT() == mDice2->getmT()) &&
			(mDice1->getmW() == mDice2->getmN()) &&
			(mDice1->getmN() == mDice2->getmE()) &&
			(mDice1->getmE() == mDice2->getmS()) &&
			(mDice1->getmS() == mDice2->getmW()) &&
			(mDice1->getmB() == mDice2->getmB())) {
			cout << "Yes" << endl;
			break;
		}
		else if ((mDice1->getmT() == mDice2->getmT()) &&
			(mDice1->getmW() == mDice2->getmE()) &&
			(mDice1->getmE() == mDice2->getmW()) &&
			(mDice1->getmN() == mDice2->getmS()) &&
			(mDice1->getmS() == mDice2->getmN()) &&
			(mDice1->getmB() == mDice2->getmB())) {
			cout << "Yes" << endl;
			break;
		}
		else if ((mDice1->getmT() == mDice2->getmT()) &&
			(mDice1->getmW() == mDice2->getmS()) &&
			(mDice1->getmS() == mDice2->getmE()) &&
			(mDice1->getmE() == mDice2->getmN()) &&
			(mDice1->getmN() == mDice2->getmW()) &&
			(mDice1->getmB() == mDice2->getmB())) {
			cout << "Yes" << endl;
			break;
		}
		if (j == meirei.length() - 1)cout << "No" << endl;
	}
	delete mDice1, mDice2;
	mDice1 = 0;
	mDice2 = 0;
	return 0;
}


Measured memory_bytes: 3228
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=get_nsp
puts N.count("2")

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

char S[100000][11];
int main() {
	int N; cin >> N;
	ll n[5] = { 0 };

	rep(i, 0, N) {
		cin >> S[i];
		if (S[i][0] == 'M')n[0]++;
		else if (S[i][0] == 'A')n[1]++;
		else if (S[i][0] == 'R')n[2]++;
		else if (S[i][0] == 'C')n[3]++;
		else if (S[i][0] == 'H')n[4]++;
	}

	ll cnt = 0;
	rep(i, 0, 5) {
		rep(j, i + 1, 5) {
			rep(k, j + 1, 5) {
				cnt += n[i] * n[j] * n[k];
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];
    REP(i,n)REP(j,d) cin >> x[i][j];
    int dis, sum, cnt = 0;
    REP(i,n) {
        for (int j = i+1; j < n; j++) {
            sum = 0;
            REP(k,d) {
                dis = abs(x[i][k] - x[j][k]);
                sum += dis * dis;
            }
            for (int f = 0; f <= sum; f++) {
                if (f*f == sum) {
                    cnt++;
                    break;
                }
            }
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

long long cnt;
int i,A[1000000],n;
vector<int> G;


void insertionSort(int A[],int n,int g){
	for(int i=g;i<n;i++){
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}


void shellSort(int A[],int n){
	for(int h=1;h <= n;h = 3*h+1)
		G.push_back(h);
	for(int i=G.size() -1;i>=0;i--)
		insertionSort(A,n,G[i]);
}

int main(){
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> A[i];
	cnt = 0;
	
	shellSort(A,n);
	
	cout <<G.size() << endl;
	for(int i= G.size() -1;i>0;i--)
		cout << G[i] << ' ';
	cout << G[0] << endl;
	cout << cnt << endl;
	for(int i=0;i<n;i++)
		cout << A[i] << endl;
	return 0;

}
		

Measured memory_bytes: 7008
#include <iostream>
using namespace std;
void output(int A[],int N){
    for(int i=0;i<N;i++){
            if(i)cout<<" ";
            cout<<A[i];
        }
        cout<<endl;
}

void insertionSort(int A[],int N){
    int j,key;
    for(int i = 1;i< N;i++){
        key = A[i];
        /* insert A[i] into the sorted sequence A[0,...,j-1] */
        j = i - 1;
        while(j >= 0 && A[j] > key){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        output(A,N);
    }
}

int main(void){
    int N;
    int A[100];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    output(A,N);
    insertionSort(A,N);
    return 0;
}

Measured memory_bytes: 3088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int t = 0;
  int cnt = 0;
  bool pushA = false;
  bool pushB = false;
  while(t <= max(B, D)){
    if(t == A){
      pushA = true;
    }
    if(t == B){
      pushA = false;
    }
    if(t == C){
      pushB = true;
    }
    if(t == D){
      pushB = false;
    }
    if(pushA && pushB){
      cnt++;
    }
    t++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
       cin>>n;
        for(int i=1;i<=n;++i)
            cin>>a[i];//scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else cout<<G[i][j]<<endl;
            }
        }
    }
    return 0;
}

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

using namespace std;

long long inf=1000000007;
vector<int> num;
priority_queue<int,vector<int>,greater<int>> ans;
int n;

void solve(string s){
	if(s!="" && stoi(s)>=n){
		ans.push(stoi(s));
		return;
	}
	if(s!="" && s.size()>to_string(n).size()) return;

	for(auto a:num){
		solve(s+to_string(a));
	}
}

int main(){
	int k;
	cin>>n>>k;
	map<int,bool> hoge;
	for(int i=0;i<k;i++){
		int piyo;
		cin>>piyo;
		hoge[piyo]=true;
	}

	for(int i=0;i<=9;i++){
		if(!hoge.count(i)) num.push_back(i);
	}

	solve("");

	cout<<ans.top()<<endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(c, i, n) for (int i = c; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int A, B;
    cin >> A >> B;
    rep(0, i, 10001)
    {
        if (((int)(0.08 * i) == A) && ((int)(0.10 * i) == B))
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll gcd(ll x, ll y){
    return y ? gcd(y,x%y) : x;
}

int main() { 
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i,n) cin >> a[i];

  ll m = a[0];
  ll ma = a[0];
  srep(i,1,n){
    maxs(ma,a[i]);
    m = gcd(m,a[i]);
  }
  if(k>ma || k%m != 0){
    cout<<"IMPOSSIBLE"<<endl;
  }
  else cout<<"POSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 1024
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 25/07/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n = ii1()
if n>=1800 and n<=1999:
    print(1)
elif n>=1600 and n<=1799:
    print(2)
elif n>=1400 and n<=1599:
    print(3)
elif n>=1200 and n<=1399:
    print(4)
elif n>=1000 and n<=1199:
    print(5)
elif n>=800 and n<=999:
    print(6)
elif n>=600 and n<=799:
    print(7)
elif n>=400 and n<=599:
    print(8)



Measured memory_bytes: 65348
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
	int n,k,temp;
	cin >> n >> k;
	vector<int> dis(10,0);
	for(int i=0; i<k; i++){
		cin >> temp;
		dis[temp]=1;
	}
	for(int i=n;; i++){
		temp=i;
		while(temp){
			if(dis[temp%10])break;
			temp/=10;
		}
		if(temp==0){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi v(n);
	ll vt=0,ct=0;
	for(int &i:v)cin>>i;
	for(int i=0;i<n;i++) {
		int c;
		cin>>c;
		if(c<v[i]){
			ct+=c;
			vt+=v[i];
		}
	}
	cout<<vt-ct;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3568
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

int main() {
    int n = read();
    LL  m = read();
    int q = read();

    vector<int> par(n), siz(n);
    iota(par.begin(), par.end(), 0);
    fill(siz.begin(), siz.end(), 1);
    function<int(int)> find = [&](int x) {
        return par[x] == x ? x : (par[x] = find(par[x]));
    };
    function<bool(int, int)> merge = [&](int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        par[y] = x; siz[x] += siz[y];
        return true;
    };

    vector<pair<int, int> > c1;
    LL cur = m;
    while (q--) {
        int a = read(), b = read();
        if (read() == 0) {
            cur -= merge(a, b);
        } else {
            c1.emplace_back(a, b);
        }
    }

    int comp = 0;
    for (int i = 0; i < n; ++i) {
        if (find(i) == i) {
            ++comp;
        }
    }
    for (auto &pr : c1) {
        int x = pr.first;
        int y = pr.second;
        if (find(x) == find(y)) {
            return puts("No"), 0;
        }
    }
    LL lb = c1.empty() ? comp - 1 : max(3, comp);
    LL rb = (LL) comp * (comp - 1) / 2;
    puts(lb <= cur && cur <= rb ? "Yes" : "No");
    return 0;
}

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

int main()
{
    int n,pts=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        pts=pts+b[i];
    }
    for(int i=0;i<n-1;i++)
    {
        cin>>c[i];
    }
    for(int i=0;i<n;i++)
    {
        if(a[i+1]==a[i]+1)
        pts=pts+c[a[i]-1];
    }
    cout<<pts;
    
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

int N, K, L, s, t;
std::vector<std::vector<int> > road, railway;
int c1[2 * 100001], c2[2 * 100001];

void dfs(std::vector<std::vector<int> >& g, int c[], int v, int id) {
  c[v] = id;

  for (int i = 0; i < g[v].size(); ++i) {
    int nv = g[v][i];

    if (c[nv] == -1) {
      dfs(g, c, nv, id);
    }
  }
}

int main() {
  scanf("%d%d%d", &N, &K, &L);
  road.resize(N);
  railway.resize(N);
  for (int i = 0; i < K; ++i) {
    scanf("%d%d", &s, &t);
    s--, t--;
    road[s].push_back(t);
    road[t].push_back(s);
  }
  for (int i = 0; i < L; ++i) {
    scanf("%d%d", &s, &t);
    s--, t--;
    railway[s].push_back(t);
    railway[t].push_back(s);
  }

  std::memset(c1, -1, sizeof c1);
  std::memset(c2, -1, sizeof c2);

  int id = 0;

  for (int i = 0; i < N; ++i) {
    if (c1[i] == -1) {
      dfs(road, c1, i, id++);
    }
  }

  id = 0;

  for (int i = 0; i < N; ++i) {
    if (c2[i] == -1) {
      dfs(railway, c2, i, id++);
    }
  }

  std::map<std::pair<int, int>, int> mp;

  for (int i = 0; i < N; ++i) {
    mp[{c1[i], c2[i]}]++;
  }

  for (int i = 0; i < N; ++i) {
    printf("%d%c", mp[{c1[i], c2[i]}], (i == N - 1 ? '\n' : ' '));
  }

  return 0;
}


Measured memory_bytes: 27776
#include<iostream>
#include<cstring>
using namespace std;
int main() {
	int n,m,sa[110],sb[110];
	char a[110][12],b[110][12];
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		sa[i]=strlen(a[i]);
	}
	cin>>m;
	for(int i=1; i<=m; i++) {
		cin>>b[i];
		sb[i]=strlen(b[i]);
	}
	int finda[110]= {0},max1=0,findb[110]= {0};
	for(int i=1; i<=n; i++) {
		if(!finda[i]) {
			int cmp=1;
			for(int o=i+1; o<=n; o++)
				if(sa[i]==sa[o])
					for(int p=0; p<sa[i]; p++) {
						if(a[i][p]!=a[o][p])break;
						if(p==sa[i]-1)
							finda[o]++,cmp++;
					}
			for(int o=1; o<=m; o++)
				if(!findb[o]&&sa[i]==sb[o])
					for(int p=0; p<sa[i]; p++) {
						if(a[i][p]!=b[o][p])break;
						if(p==sa[i]-1)
							findb[o]++,cmp--;
					}
			max1=max(max1,cmp);
		}
	}
	cout<<max1<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		for(int i=0;i<26;i++){
		for(int j=0; j< 15; j++){
		        if(4 * i + 7* j == n){
		           System.out.println("Yes");
		           return;
		        }
			}
		}
		System.out.println("No"); 
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
#include<unordered_map>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const int mod=10007;
#define ll long long

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    const int dx=tx-sx,dy=ty-sy;
    cout<<string(dy,'U')<<string(dx,'R');
    cout<<string(dy,'D')<<string(dx,'L');
    cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
    cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define EPS 1e-5

typedef struct {
    int x, y;
} vector_t;

typedef struct {
    double x, y;
} vectord_t;

void complex_div(vector_t *a, vector_t *b, vectord_t *t) {
    double d = a->x*a->x + a->y*a->y;
    t->x = (double)(a->x * b->x + a->y * b->y) / d;
    t->y = (double)(a->x * b->y - a->y * b->x) / d;
}

vector_t tmpl[10], poly[50][10];
vectord_t vec[10];

int main(void) {
    int n, m, tm, i, j;
    vector_t *p, v0, v1;
    vectord_t v;

    while (scanf("%d", &n) != EOF && n) {
        scanf("%d", &tm);
        for (i = 0; i < tm; i++) {
            scanf("%d%d", &(tmpl[i].x), &(tmpl[i].y));
            if (i >= 2) {
                v0.x = tmpl[i-1].x - tmpl[i-2].x;
                v0.y = tmpl[i-1].y - tmpl[i-2].y;
                v1.x = tmpl[i].x - tmpl[i-1].x;
                v1.y = tmpl[i].y - tmpl[i-1].y;
                complex_div(&v0, &v1, &(vec[i]));
            }
        }
        for (i = 0; i < n; i++) {
            p = poly[i];
            scanf("%d", &m);
            for (j = 0; j < m; j++) {
                scanf("%d%d", &(p[j].x), &(p[j].y));
            }

            for (j = 2; j < tm; j++) {
                v0.x = p[j-1].x - p[j-2].x;
                v0.y = p[j-1].y - p[j-2].y;
                v1.x = p[j].x - p[j-1].x;
                v1.y = p[j].y - p[j-1].y;
                complex_div(&v0, &v1, &v);
                if (fabs(v.x - vec[j].x) > EPS ||
                    fabs(v.y - vec[j].y) > EPS) break;
            }
            if (j == tm) {
                printf("%d\n", i + 1);
                continue;
            }
            for (j = 2; j < tm; j++) {
                v0.x = p[m-j].x - p[m-j+1].x;
                v0.y = p[m-j].y - p[m-j+1].y;
                v1.x = p[m-j-1].x - p[m-j].x;
                v1.y = p[m-j-1].y - p[m-j].y;
                complex_div(&v0, &v1, &v);
                if (fabs(v.x - vec[j].x) > EPS ||
                    fabs(v.y - vec[j].y) > EPS) break;
            }
            if (j == tm) {
                printf("%d\n", i + 1);
            }
        }

        puts("+++++");
    }
    return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll ans = LONG_LONG_MAX;
    rep(i, n - k + 1) {
        ll l = x[i], r = x[i + k - 1];
        ll diff;
        if ((l < 0) && (r >= 0)) {
            diff = min(abs(l), abs(r)) + abs(l) + abs(r);
        }
        else {
            diff = max(abs(r), abs(l));
        }
        ans = min(ans, diff);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const long long inf = 1e9+7;
const long long mod = 1e9+7;

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

    int ans=0;

    rep2(i,1,n-1){
        ans+=(n+i-1)/i-1;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3628
n,m = map(int,input().split())
s = [list(map(int,input().split()[1:])) for _ in range(m)]
p = list(map(int,input().split()))

ans = 0

for i in range(2**n):
    f = 1
    for j in range(m):
        g = 1
        g &= (sum([int(bin(i>>(u-1)),2) for u in s[j]])%2 == p[j])
        f &= g
    ans += f
print(ans)

Measured memory_bytes: 3064
# coding: utf-8
C=[]
for i in range(3):
    c=list(map(int,input().split()))
    #print(c)
    C.append(c)


cnt=0
#横
if C[0][0]-C[1][0]==C[0][1]-C[1][1]==C[0][2]-C[1][2]:
    cnt+=1
if C[1][0]-C[2][0]==C[1][1]-C[2][1]==C[1][2]-C[2][2]:
    cnt+=1
if C[2][0]-C[0][0]==C[2][1]-C[0][1]==C[2][2]-C[0][2]:
    cnt+=1
    
#縦
if C[0][0]-C[0][1]==C[1][0]-C[1][1]==C[2][0]-C[2][1]:
    cnt+=1
if C[0][1]-C[0][2]==C[1][1]-C[1][2]==C[2][1]-C[2][2]:
    cnt+=1
if C[0][2]-C[0][0]==C[1][2]-C[1][0]==C[2][2]-C[2][0]:
    cnt+=1
#print(cnt)
if cnt==6:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin, a, b, c, d;
    int x = (a + d - 1) / d;
    int y = (b + c - 1) / b;
    cout << (y <= x ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
    private static long solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        long[] a = lineToNums(scanner.nextLine());

        long sumAll = Arrays.stream(a).sum();

        long[] xSum = new long[N];
        long[] ySum = new long[N];

        xSum[0] = a[0];
        ySum[0] = sumAll - xSum[0];

        long ret = Math.abs(xSum[0] - ySum[0]);

        for (int i = 1; i < N - 1; i ++) {
            xSum[i] = xSum[i - 1] + a[i];
            ySum[i] = sumAll - xSum[i];
            ret = Math.min(ret, Math.abs(xSum[i] - ySum[i]));
        }

        return ret;
    }

    private static final String ex1 = "6\n" +
            "1 2 3 4 5 6";
    private static final String ex2 = "2\n" +
            "10 -10";

    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));
    }

    private static long[] lineToNums(String line) {
        String[] strNums = line.split(" ");
        long[] ret = new long[strNums.length];
        for (int i = 0; i < strNums.length; i ++) {
            ret[i] = Long.parseLong(strNums[i]);
        }
        return ret;
    }
}


Measured memory_bytes: 57756
#include <iostream>
using namespace std;
long long n,m,i,j,a[100005],dp[1005][2];
int main()
{
	cin>>n;
	dp[0][0]=1;
	for (i=1;i<=n;i++) cin>>a[i];
	for (i=1;i<=n;i++)
	{
		if ((a[i]&1)==0)
		{
			dp[i][0]=dp[i-1][0]*2;
			dp[i][1]=dp[i-1][1]*3+dp[i-1][0]*1;
		}
		else
		{
			dp[i][0]=dp[i-1][0]*1;
			dp[i][1]=dp[i-1][1]*3+dp[i-1][0]*2;
		}
	}
	cout<<dp[n][1];
	return 0;
}

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

int main()
{
    string s, t;
    int ans = 0;
    cin >> s >> t;
    for (int i = 0; i < 3; i++)
    {
        if(s[i]==t[i]) 
        {
            ans ++;
        }
    }
    cout << ans <<  endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int n,m,Q;
int query[505][505];
int accum[505][505];
int ans=0;
int main(int argc,char const* argv[])
{
  memset(accum,0,sizeof(accum));
  memset(query,0,sizeof(query));
  cin >> n >> m >> Q;
  for(int i=0;i<m;i++)
    {
      int l,r;
      cin >> l >> r;
      accum[l][r]++;
    }
  for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=n;j++)
	{
	  query[i][j]=query[i][j-1]+accum[i][j];
	}
    }
  for(int i=0;i<Q;i++)
    {
      int p,q;
      cin >> p >> q;
      int sum=0;
      for(int j=p;j<=q;j++) sum+=query[j][q]-query[j][p-1];
      cout << sum << endl;
    }
  
  return 0;
}
//return 0;



Measured memory_bytes: 2944
#include<stdio.h>
int gcd(int a,int b){
    if(a<b)return gcd(b,a);
    return b?gcd(b,a%b):a;
}
int main(){
    int a[100000],b[100000],c[100000],i,n,q,r=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    b[0]=a[0];
    for(i=1;i<n;i++)b[i]=gcd(b[i-1],a[i]);
    c[n-1]=a[n-1];
    for(i=n-2;i>0;i--)c[i]=gcd(c[i+1],a[i]);
    r=c[1];
    if(r<b[n-2])r=b[n-2];
    for(i=1;i<n-1;i++)if(r<(q=gcd(b[i-1],c[i+1])))r=q;
    printf("%d",r);
    return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import java.math.BigInteger;
class Main{

     public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int x = scan.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for(int i = 0 ; i < n ; i++){
          a.add(scan.nextInt());
      }
      int sum = 0 ;
      Collections.sort(a,Collections.reverseOrder());
      for(int i = 0 ; i <x ; i++){
          sum+=a.get(i);
      }
      System.out.println(sum);
    }
}

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

int main(){
    double w,h,x,y;
    cin>>w>>h>>x>>y;

    cout<<w*h/2 << " ";

    if(x==w/2 && y==h/2)cout<<fixed<<setprecision(10)<<"1";
    else cout<<"0";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}

// head
int m,n,k,res,tmp,tmp2,tmp3,h,w,ans;
int a[3200][2] = {};
int b[8000100] = {};
int r[100001][25];
deque<PII> que;
string s;
map<int,VPII> kukan;
vector<PII> g[3000];
//int dp[200000];
int flag;
//VPII g2[200000];
int cost[200005];
double dp[1020][2] = {};
double dp2[1020][2] = {};
//VVI g(200005);

signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	cin>>n>>m;
    cout<<max({n+m,n*2-1,m*2-1})<<endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

long long a[100020];

int main(void)
{
    int n;
    long long o;

    scanf("%d", &n);
    o = 1;
    for(int i = 0; i < n; i ++)
        scanf("%lld", &a[i]);
    sort(a, a + n);
    for(int i = 0; i < n; i ++)
    {
        if((__int128)o * a[i] > 1000000000000000000LL)
        {
            printf("-1\n");
            return 0;
        }
        o *= a[i];
    }
    printf("%lld\n", o);

    return 0;
}


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

#define endl '\n'

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, N, max_distance;
    cin >> K >> N;
    int A[N+1];
    cin >> A[1];
    cin >> A[2];
    max_distance = abs(A[2] - A[1]);
    for(int i = 3; i <= N; i++) {
        cin >> A[i];
        int diff = abs(A[i] - A[i-1]);
        max_distance = (max_distance < diff) ? diff : max_distance;
    }
    int last_distance = (K - A[N]) + A[1];
    max_distance = (max_distance < last_distance) ? last_distance : max_distance;
    cout << (K - max_distance) << endl;
    return 0;
}

Measured memory_bytes: 1024
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
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;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    VI A(3);
    REP(i,3)
    {
        cin >> A[i];
    }
    
    RSORT(A);
    int ans=0;
    REP(i,2)
    {
        ans += A[i] - A[i+1];
    }
    cout << ans <<endl;
    return 0;
}



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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

struct RMQ {
  int n;
  vector<int> dat;

  RMQ(int node) {
    n = 1;
    while(n < node) n *= 2;

    dat.resize(2 * n - 1, INT_MAX);
  }

  void update(int k, int a) {
    k += n - 1;
    dat[k] = a;

    while(k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  int query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if(r == -1) r = n;
    if(a <= l && r <= b) return dat[k];
    if(r <= a || b <= l) return INT_MAX;

    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};

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

  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  rep(i, 0, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if(com) cout << rmq.query(x, y + 1) << endl;
    else rmq.update(x, y);
  }
}



Measured memory_bytes: 3908
package main

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

func solve() {
	n := getInt()
	xs := getIntSlice(n)

	ans := inf
	for p := 1; p <= 100; p++ {
		sum := 0
		for _, x := range xs {
			sum += pow(x-p, 2)
		}
		ans = min(ans, sum)
	}
	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func pow(a, b int) int {
	ret := 1
	for i := 0; i < b; i++ {
		ret *= a
	}
	return ret
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 1784