akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>

using namespace std;


int N;
long long x[100005];
long long a[100005];
int main() {
	cin >> N;

	x[0] = 0;
	int tmp1 = 1;
	for (int i = 0; i < N; i++) {
		cin >> a[i];

		x[0] += a[i] * tmp1;
		tmp1 *= -1;
	}
	x[0] /= 2;

	for (int i = 0; i < N-1; i++) {
		x[i + 1] = a[i] - x[i];
	}

	for (int i = 0; i < N; i++) {
		cout << x[i]*2 << endl;
	}


	return 0;
}


Measured memory_bytes: 2816
import java.util.Scanner;

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

		// 入力値の取得
		String N = sc.next();
		
		// 結果の出力
		System.out.println(N.contains("7")? "Yes" : "No");

		sc.close();
	}
}


Measured memory_bytes: 26888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    int N; cin >> N;
    vector<int> a(N);
    int ans = 0;
    rep(i, N){
        cin >> a.at(i);
        if((i+1)%2==1 && a.at(i)%2==1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
/**
 * @File   : atcoder.cpp
 * @Author : pasnger 
 * @Date   : 29/8/2020, 2:59:47 pm 
 */

#include<bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long
#define f(i, a, b) for(int i=a; i<b; i++)
#define rf(i, a, b) for(int i=a; i>b; i--)

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  double d, t, s;
  cin>>d>>t>>s;
  if(d/s <= t) cout<<"Yes\n";
  else cout<<"No\n";

}


int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  // cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 3732
from operator import itemgetter
N = int(input())
A = list(map(int, input().split()))
ans = 0

L = [[int(i)+1] for i in range(N)]

for i in range(N):
    L[i].append(A[i])

L.sort(key=itemgetter(1))

ans = []
for i in range(N):
    ans.append(L[i][0])

print(*ans)

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

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++) // repマクロ
#define all(v) v.begin(), v.end() // sort等の関数呼び出しを簡潔にする

using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
    int64_t X;
    cin >> X;

    int64_t ans;

    ans = ((X / 500) * 1000 + (X % 500) - (X % 5));

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

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc106/tasks/abc106_d
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// 二次元BIT
// source: https://iq.opengenus.org/2d-fenwick-tree/

// 2D fenwick tree for sub-matrix sum problem
class FenwickTree {
  private:
    // Matrix to store the tree
    std::vector<std::vector<int>> ft;

  public:
    // Function to get least significant bit
    int LSB(int x) { return x & (-x); }

    int query(int x, int y) {
        int sum = 0;
        for (int x_ = x; x_ > 0; x_ = x_ - LSB(x_)) {
            for (int y_ = y; y_ > 0; y_ = y_ - LSB(y_)) {
                sum = sum + ft[x_][y_];
            }
        }
        return sum;
    }

    int query(int x1, int y1, int x2, int y2) {
        return (query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) +
                query(x1 - 1, y1 - 1));
    }

    void update(int x, int y, int value) {
        // also update matrix[x][y] if needed.
        for (int x_ = x; x_ < (int)ft.size(); x_ = x_ + LSB(x_)) {
            for (int y_ = y; y_ < (int)ft[0].size(); y_ = y_ + LSB(y_)) {
                ft[x_][y_] += value;
            }
        }
    }

    FenwickTree(std::vector<std::vector<int>> matrix) {
        // 引用元のコードはn, mが逆転してバグっているので修正
        int n = matrix.size();
        // matrix must not be empty.
        int m = matrix[0].size();
        // Initialize matrix ft
        ft.assign(n + 1, std::vector<int>(m + 1, 0));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                update(i + 1, j + 1, matrix[i][j]);
        }
    }

    FenwickTree(int h, int w) { ft.assign(h + 1, std::vector<int>(w + 1, 0)); }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    FenwickTree ft(N, N);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        ft.update(l, r, 1);
    }
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << ft.query(l, l, r, r) << "\n";
    }

    return 0;
}


Measured memory_bytes: 4188
def gs() STDIN.gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
 
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n,x = gsmi
xs = gsmi

subs = Array.new(n){|i| (xs[i]-x).abs }
puts subs.inject(subs[0]){|ret,n| ret.gcd(n) }

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

int main() {
	int a, b, k, s;
	cin >> a >> b >> k;
	s = (b - a) + 1;
	if ((k * 2) > s) {
		for (int i = a;i <= b;i++)
			cout << i << endl;
	
	}
	else
	{
		for (int i = a;i < (a + k);i++)
			cout << i << endl;
		for (int i = (b - k + 1);i <= b;i++)
			cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from math import ceil
H,W,D=map(int,input().split())
A=[[0]*(int(ceil(H*W/D))) for i in range(D)]
for i in range(H):
    Ai=list(map(int,input().split()))
    for j in range(W):
        A[(Ai[j]-1)%D][(Ai[j]-1)//D]=(i,j)
B=[[0]*(int(ceil(H*W/D))+1) for i in range(D)]
for j in range(D):
    for i in range(len(A[j])):
        if  type(A[j][i])!=type((0,0)):
            #B[j][i+1]=B[j][i]
            break
        if i==0:
            B[j][i+1]=A[j][i][0]+A[j][i][1]
            continue
        B[j][i+1]=B[j][i]+abs(A[j][i-1][0]-A[j][i][0])+abs(A[j][i-1][1]-A[j][i][1])
Q=int(input())
for _ in range(Q):
    L,R=map(int,input().split())
    L,R=L-1,R-1
    print(B[R%D][R//D+1]-B[L%D][L//D+1])


Measured memory_bytes: 75940
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

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


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;




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

	int n,m;cin>>n>>m;

	vector<int> jobs[m];

	for(int i=0; i<n; i++){
		int a, b;cin>>a>>b;
		if(a >m )continue;

		jobs[m-a].push_back(b);

	}
	priority_queue<int> q;
	ll ans=0;
	for(int i=m-1; i>=0; i--){
		for(int b : jobs[i]){
			q.push(b);
		}
		if(!q.empty()){
			ans +=q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;




}




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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> vv(m);
  for(int i=0;i<m;i++){
    int k;
    cin >> k;
    for(int j=0;j<k;j++){
      int h;cin >> h;
      vv[i].push_back(--h);
    }
  }
  vector<int> swi(m);
  for(auto& x:swi)cin >> x;
  int ret=0;
  for(int i=0;i<1<<n;i++){
    bool flag=true;
    for(int j=0;j<m;j++){
      int on=0;
      for(const auto& x:vv[j]){
        if(i>>x &1)on++;
      }
      if(on%2!=swi[j])flag=false;
    }
    if(flag)ret++;
  }
  cout << ret << endl;
}


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

int main(){
  int N; cin >> N;
  long long height=0;
  long long humidai=0;
  for(int i=0; i<N; i++){
    long long A; cin >> A;
    if(height<=A){
      height=A;
    }else{
      humidai+=(height-A);
    }
  }
  cout << humidai << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int mn=50,mlen=100;

int n;
char a[mn+3][mlen+3];
int t[mn+3];
char x[mlen+3];
bool equ(char a[],char b[]) {
	for(int w=0;;w++) {
		if(a[w]==0&&b[w]==0) return true;
		
		if(a[w]!=b[w]) return false;
	}
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		scanf("%s",a[i]);
		cin>>t[i];
	}
	scanf("%s",x);
	
	int w;
	for(int i=1;i<=n;i++) {
		if(equ(x,a[i])) w=i;
	}
	long long ans=0;
	for(int i=w+1;i<=n;i++) ans+=t[i];
	cout<<ans;
	return 0;
}

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

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

    ll maxn = 0;
    for(long long i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            maxn = max(maxn, i);
        }
    }
    put(max(to_string(maxn).size(),to_string(n / maxn).size()));
}

Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;
int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}
int main() {
	int N, X;
	cin >> N >> X;
	int g = 0;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		g = gcd(g, abs(x - X));
	}
	cout << g << endl;
}


Measured memory_bytes: 256
/************************************/
/* NoobM							*/
/* File Name : chaa.cpp				*/
/* Date : 13.07.2020 02:37:00 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	vector<vii> a(3, vii (3));
	rr(i, 3) {
		rr(j, 3) cin >> a[i][j];
	}
	
	int n;
	cin >> n;
	
	map<int, bool> is;
	
	rr(i, n) {
		int x;
		cin >> x;
		
		is[x] = true;
	}
	
	rr(i, 3) {
		rr(j, 3) {
			int x = a[i][j];
			if(is[x] == true) a[i][j] = -1;
		}
	}
	int flag = 0;
	
	rr(i, 3) {
		int counter = 0;
		int counter2 = 0;
		rr(j, 3) {
			if(a[i][j] == -1) counter++;
			if(a[j][i] == -1) counter2++;
		}
		if(counter == 3 || counter2 == 3) flag = 1;
	}
	
	int c = 0, c2 = 0;
	
	rr(i, 3) {
		rr(j, 3) {
			if(i == j && a[i][j] == -1)c++;
			if(i + j == 2 && a[i][j] == -1) c2++;
		}
	}
	
	if(c == 3 || c2 == 3) flag = 1;
	
	if(flag == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3656
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        int n = IO.INT();
        string s = IO.STRING();
        string t = IO.STRING();
        int o = 2 * n;
        for (int i = 0; i < n; i++)
        {
            if (s.Substring(i, n - i) == t.Substring(0, n - i))
            {
                o = n + i;
                break;
            }
        }
        IO.WRITE(o);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

Measured memory_bytes: 2776
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'

main() {
	int x, k, d;
	cin>>x>>k>>d;
	x=abs(x);
	if(x>d){
		int steps=(x/d);
		if(steps>k){
			cout<<x-k*d;
			return 0;
		}
		k=k-steps;
		x=x-steps*d;
		if(k%2==0){
			cout<<x;
			return 0;
		}
		else{
			cout<<d-x;
			return 0;
		}
	}
	else{
		if(k%2==0){
			cout<<x;
			return 0;
		}
		else{
			cout<<d-x;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3620
# エラトステネスの篩

N = int(input())
A = sorted(map(int, input().split()))
maxA = A[N - 1]
dp = [0] * (maxA + 1)

for i in range(len(A)):
    cursor = A[i]
    while cursor <= maxA:
        dp[cursor] += 1
        cursor += A[i]

ans = 0
for a in A:
    if dp[a] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 32384
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();

        int a[] = new int[3];
        a[0] = P;
        a[1] = Q;
        a[2] = R;

        int ans = 1000;
        for (int i=0;i<3;i++) {
            for (int j=i+1;j<3;j++) {
                ans = Math.min(a[i] + a[j], ans);
            }
        }

        System.out.println(ans);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>

using namespace std;

int a[200010] , k , n ;
long long tong;

int main()
{
    cin >> n >> k;
    for (int i=1 ; i<=n ; i++)
        cin >> a[i];
    for (int i=2 ; i<=n ; i++)
        tong = tong + min(k,(a[i]-a[i-1]));
    tong += k;
    cout << tong;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,m,h[101010],f[101010][22],dt[101010],c[101010],cc[101010],ans[101010];
vector<pair<int,pair<int,int> > >v[101010],q[101010];
void gt(int x)
{
	h[x]=h[f[x][0]]+1;
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i].first!=f[x][0])
		{
			f[v[x][i].first][0]=x;
			dt[v[x][i].first]=dt[x]+v[x][i].second.second;
			gt(v[x][i].first);
		}
	}
}
int hb(int x,int y)
{
	if(h[x]>h[y])
	{
		swap(x,y);
	}
	int ch=h[y]-h[x];
	for(int i=0;i<=20;i++)
	{
		if(ch&(1<<i))
		{
			y=f[y][i];
		}
	}
	if(x==y)
	{
		return x;
	}
	for(int i=20;i>=0;i--)
	{
		if(f[x][i]!=f[y][i])
		{
			x=f[x][i];
			y=f[y][i];
		}
	}
	return f[x][0];
}
void dfs(int x)
{
	for(int i=0;i<q[x].size();i++)
	{
		if(q[x][i].first>0)
		{
			ans[q[x][i].first]+=dt[x]+c[q[x][i].second.first]*q[x][i].second.second-cc[q[x][i].second.first];
		}
		else
		{
			ans[-q[x][i].first]-=2*(dt[x]+c[q[x][i].second.first]*q[x][i].second.second-cc[q[x][i].second.first]);
		}
	}
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i].first==f[x][0])
		{
			continue;
		}
		c[v[x][i].second.first]++;
		cc[v[x][i].second.first]+=v[x][i].second.second;
		dfs(v[x][i].first);
		c[v[x][i].second.first]--;
		cc[v[x][i].second.first]-=v[x][i].second.second;
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n-1;i++)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		v[a].push_back(make_pair(b,make_pair(c,d)));
		v[b].push_back(make_pair(a,make_pair(c,d)));
	}
	gt(1);
	for(int i=1;i<=20;i++)
	{
		for(int j=1;j<=n;j++)
		{
			f[j][i]=f[f[j][i-1]][i-1];
		}
	}
	for(int i=1;i<=m;i++)
	{
		int c,d,x,y;
		cin>>c>>d>>x>>y;
		q[x].push_back(make_pair(i,make_pair(c,d)));
		q[y].push_back(make_pair(i,make_pair(c,d)));
		q[hb(x,y)].push_back(make_pair(-i,make_pair(c,d)));
	}
	dfs(1);
	for(int i=1;i<=m;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

int main(void) {
  int a[4];
  int b[4] = {1, 9, 7, 4};
  int c[4] = {0, 0, 0, 0};
  for (int i = 0; i < 4; i++) {
    cin >> a[i];
    for (int j = 0; j < 4; j++) {
      if (a[i] == b[j]) c[j] = 1;
    }
  }
  int res = 0;
  for (int j = 0; j < 4; j++) {
    res += c[j];
  }
  if (res == 4) cout << "YES";
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var a int

func main() {

	fmt.Scan(&a)

	nn := make([]int, a-1)
	kai := 1
	for i := 1; i < a; i++ {
		kai *= i
		nn[a-i-1] = kai
	}

	bs := make([]int, a)
	for i := range bs {
		fmt.Scan(&bs[i])
	}
	cs := make([]int, a)
	for i := range cs {
		fmt.Scan(&cs[i])
	}
	bc := 1
	cc := 1
	for i := 0; i < a-1; i++ {
		for j := i + 1; j < a; j++ {
			if bs[i] > bs[j] {
				bc = bc + nn[i]
			}
			if cs[i] > cs[j] {
				cc = cc + nn[i]
			}
		}
	}
	if bc < cc {
		fmt.Print(cc - bc)
	} else {
		fmt.Print(bc - cc)
	}
}


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

int main() {
    int64_t N, M, ans;
    cin >> N >> M;
    vector<int64_t> H(N), T(N);
    ans = N;
    for (int64_t i = 0; i < N; i++) {
        cin >> H[i];
        T[i] = 1;
    }
    for (int64_t i = 0; i < M; i++) {
        int64_t A, B;
        cin >> A >> B;
        if (H[A - 1] >= H[B - 1] && T[B - 1] == 1) {
            T[B - 1] = 0;
            ans--;
        }
        if (H[A - 1] <= H[B - 1] && T[A - 1] == 1) {
            T[A - 1] = 0;
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4792
#include <stdio.h>
#include <iostream>
using namespace std;
const int N = 200000 + 10;
#define lson rt << 1
#define rson rt << 1 | 1
struct node
{
    int l, r;
    int w; //  w维护值  lazy懒标记
} tree[(N << 2) + 10];
void push_up(int rt)
{
    tree[rt].w = tree[lson].w + tree[rson].w;
}

void build(int rt, int l, int r) //建树初始化
{
    tree[rt].l = l;
    tree[rt].r = r;
    tree[rt].w = 0;
    if (l == r)
    {
        tree[rt].w = 0;
        return;
    }
    int mid = (l + r) >> 1;
    build(lson, l, mid);
    build(rson, mid + 1, r);
    push_up(rt);
}
int query(int rt, int ql, int qr) //区间查询 单点查询时ql==qr
{
    int l = tree[rt].l;
    int r = tree[rt].r;
    if (l >= ql && r <= qr)
    {
        return tree[rt].w; //查询维护值w
    }

    int mid = (l + r) >> 1;
    int ans = 0;
    if (ql <= mid)
        ans += query(lson, ql, qr);
    if (qr > mid)
        ans += query(rson, ql, qr);
    return ans;
}

void updata(int rt, int x, int val) //单点更新  x更新点 val更新值
{
    int l = tree[rt].l;
    int r = tree[rt].r;
    if (l == r)
    {
        tree[rt].w += val;
        return;
    }
    int mid = (l + r) >> 1;

    if (x <= mid)
        updata(lson, x, val);
    else if (x > mid)
        updata(rson, x, val);
    push_up(rt);
}
int main()
{
    int n;
    cin >> n;
    build(1, 0, n);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int temp;
        scanf("%d", &temp);
        int res = query(1, 0, temp - 1);
        if (!res)
            ans++;
        updata(1, temp, 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8448
# -*- coding: utf-8 -*-
N = int(input())

dic = {
  'AC': 0,
  'WA': 0,
  'TLE': 0,
  'RE': 0
}
for i in range(N):
  string = input()
  dic[string] += 1

for key, value in dic.items():
  print('{} x {}'.format(key,value))

Measured memory_bytes: 9204
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let nums: Vec<i32> = s.trim()
        .split_whitespace()
        .map(|e| e.parse().unwrap()).collect();
    let (a, b, c): (i32, i32, i32) = (nums[0], nums[1], nums[2]);

    if a < b && b < c {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a;
  cin>>a;
  ll b=a/11;
  if(a-b*11>6){
    cout<<2*b+2<<endl;
    return 0;
  }
  if(a-b*11==0){
    cout<<2*b<<endl;
    return 0;
  }
  cout<<2*b+1<<endl;
  return 0;
}


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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
//inv[i] mod. MODにおける[i]の逆元
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long nCk(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    long long ans = 0;
    for (int i = B+1; i <= W; i++) {
        int h = H-A-1, w = i-1;
        long long tmp = nCk(h+w, h);
        h = A-1, w = W-i;
        tmp *= nCk(h+w, w);
        ans += tmp%MOD;
    }
    // 計算例
    cout << ans%MOD << endl;
}

Measured memory_bytes: 12160
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        System.out.println((H-h)*(W-w));
   }
}

Measured memory_bytes: 23252
#include <stdio.h>

int main(void){
    int a,b,c,d,e=0;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
    if(a==0){
        printf("1");
    }else if(b==0){
        printf("2");
    }else if(c==0){
        printf("3");
    }else if(d==0){
        printf("4");
    }else if(e==0){
        printf("5");
    }
    return 0;
}

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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b / gcd(a,b) ;}


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}


int n, x, cntr;

int main(){
  cin >> n;
  cin >> x;
  cntr++;
  n--;
  while(n--){
    int c;
    cin >> c;
    if(c >= x){
      cntr++;
      x = c;
    }
  }
  cout << cntr;
  return 0;
}


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

#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define all(v) v.begin(),v.end()
#define mod %
#define pb push_back

const ll N = (ll)(100007);


int main()
{
	FIO
	ll a, b;
	cin >> a >> b;
	cout << ((a * b) / __gcd(a, b)) << "\n";
	return 0;	
}

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

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

    for(int i = 0; i < m; i++) {
        int a;
        cin >> a;
        n = n - a;
    }


    cout << max(-1, n) << '\n';
    
    return 0;
}

Measured memory_bytes: 3620
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]

Rmin = 0
Rmax = 0
Cmin = 0
Cmax = 0

#行方向への探索
for r in range(H):
    #列方向への検索
    for c in range(W):
        #爆弾の場合、周りを加算
        if S[r][c] == ".":
            S[r][c] = 0
        elif S[r][c] == "#":
            if r == 0 and H == 1:
                Rmin = r
                Rmax = 1
            elif r == 0:    
                Rmin = r
                Rmax = r+2
            elif r == H-1:
                Rmin = r-1
                Rmax = r+1
            else:
                Rmin = r-1
                Rmax = r+2

            if c == 0 and W ==1 :
                Cmin = c
                Cmax = 1
            elif c == 0:
                Cmin = c
                Cmax = c+2
            elif c == W-1:
                Cmin = c-1
                Cmax = c+1
            else:
                Cmin = c-1
                Cmax = c+2
            for i in range(Rmin,Rmax):
                for t in range(Cmin,Cmax):
                    if S[i][t] == "." or S[i][t] == 0:
                        S[i][t] = 1
                    elif not S[i][t] == "#":
                        S[i][t] += 1

for i in range(H):
    a = map(str,S[i])
    print(''.join(a))


Measured memory_bytes: 9196
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int a,b;

    scanf("%d %d",&a,&b);

    if(a<=0 && b>=0) printf("Zero");
    else if(b<0 && (b-a)%2==0) printf("Negative");
    else printf("Positive");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef vector<ll> vll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, z, w;
        in >> n >> z >> w;
        vll a(n);
        for (int i = 0; i < n; i++) {
            in >> a[i];
        }
        ll ans = 0;
        if (2 <= n) {
            ans = abs(a[a.size() - 2] - a[a.size() - 1]);
        }
        out << max(ans, abs(a[a.size() - 1] - w)) << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define endl '\n'
#define int ll

const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;
const int MX = 777777 + 5;
const int mod = 1777777777;
const double EPS = 1e-10;
const ll MXP = 8999251775770639633;

inline int len(string s){return s.size();}
inline int len(int* A){return (sizeof(A))/sizeof(A[0]);}
template <typename T>inline int len(vector<T> v){return v.size();}
template <typename T>inline int len(set<T> v){return v.size();}
template <typename T,typename S>inline int len(map<T,S> v){return v.size();}

int fac[MX+5];
int power(int x, int y, int p)
{
    int res = 1;

    x = x % p;

    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}

int C(int n, int r, int p)
{
    if (r==0)
        return 1;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

void init(int mod){
    fac[0] = 1;
    for (int i=1 ; i<=MX; i++)
        fac[i] = fac[i-1]*i%mod;
}

int CC(int a, int b){
    int res = 1;
    rep(i,a+1,a-b+1)res *= i,res/=a-i+1;
//    rep(i,1,b+1)res /= i;
    return res;
}

bool equal(double a, double b) {
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}

map<string, int> m;
string trim(string s){
    string res;
    for (int i = 0; i < s.size() && isalpha(s[i]); ++i) {
        res += tolower(s[i]);
    }
    return res;
}

vector<int > vi;
int a,b;
void _() {
    char c;
    while(cin >> c)(c=='0'?b++:a++);
    cout << 2*min(a,b);



};

#undef int
int main() {
#if __MINGW32__
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r", stdin);
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w", stdout);

#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();

}

Measured memory_bytes: 256
import sys
N = int(input())

XYH = []
for _ in range(N):
    x, y, h = list(map(int, input().split()))
    XYH.append((x, y, h))


for cx in range(101):
    for cy in range(101):
        for xyh in XYH:
            if xyh[2] > 0:
                H = abs(cx - xyh[0]) + abs(cy - xyh[1]) + xyh[2]
                break
        for xyh in XYH:
            _x, _y, _h = xyh
            if _h == max(0, H - abs(cx-_x) - abs(cy-_y)):
                continue
            break
        else:
            print(cx, cy, H)
            sys.exit(0)


Measured memory_bytes: 41712
n = int(input())
A = [int(item) for item in input().split()]
B = [int(item) for item in input().split()]
 
dp = [0] * (n+1)
AB = [] 
for a, b in zip(A, B):
    if b > a:
        AB.append((a, b))
for i in range(n+1):
    for a, b in AB:
        if i - a >= 0:
            y = dp[i-a] + b - a
            if y > dp[i]:
                dp[i] = y
n += dp[n]
dp = [0] * (n+1)
BA = []
for b, a in zip(B, A):
    if a > b:
        BA.append((b, a))
for i in range(n+1):
    for b, a in BA:
        if i - b >= 0:
            y = dp[i-b] + a - b
            if y > dp[i]:
                dp[i] = y 
print(n + dp[n])

Measured memory_bytes: 230424
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def powmod(x, n, k):
    if k == 0:
        return 1

    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x
            ans %= k
        x = x*x
        x %= k
        n = n >> 1
    return ans % k

def popcnt(n):
    return bin(n).count("1")

def main():
    N = I()
    X = S()
    cnt = 0
    for i in range(len(X)):
        if int(X[i]) & 1  == 1:
            cnt += 1
    a = cnt + 1
    b = cnt - 1

    pow2a = [0] * (N+2)
    pow2b = [0] * (N+2) # 2 ^ i mod b

    suma = 0
    sumb = 0
    dX = X[::-1]
    for i in range(N+1):
        pow2a[i] = powmod(2, i, a)
        pow2b[i] = powmod(2, i, b)
        if i >= len(dX):
            continue
        if b == 0:
            sumb = 0
            continue
        if int(dX[i]) == 1:
            suma += pow2a[i]
            sumb += pow2b[i]
            suma %= a
            sumb %= b
    # rev
    X = X[::-1]
    # i=0 -> 2^(len(X) - i)
    # 0 ... len(X) - 1
    subx = []
    ans = [1] * N
    for i in range(len(X)):
        cp_suma = suma
        cp_sumb = sumb
        if int(X[i]) == 0:
            # 1にするので、加算してからaでわる
            # i = 0なら2^0 = 1のくらい
            cp_suma += pow2a[i]
            cp_suma %= a
            res = cp_suma
        else:
            # 0 にするので引き算してからbでわる
            if b == 0:
                ans[N-1-i] -= 1
                subx.append(0)
                continue
            cp_sumb -= pow2b[i]
            cp_sumb %= b
            res = cp_sumb
        subx.append(res)

    subx = subx[::-1]
    for i, a in enumerate(subx):
        while a > 0:
            a %= popcnt(a)
            ans[i] += 1
    for a in ans:
        print(a)


main()



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

using namespace std;

int mod =1000000007;
#define fr first 
#define sc second 
int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int a[n+1]={};
    for(int i =1;i<=2*m;i++)
    {
    	int b;
    	cin>>b;
    	a[b]++;
    }

    for(int i =1;i<=n;i++)
    {
    	cout<<a[i]<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  double A,B;
  cin>>A>>B;
  double a=A,b=A+1.0,c=B,d=B+1.0;
  a/=0.08;
  b/=0.08;
  c/=0.1;
  d/=0.1;
  a=(int)(a+0.9999);
  b=(int)(b);
  c=(int)(c+0.9999);
  d=(int)(d);
  if(d<=a||b<=c)
    puts("-1");
  else cout<<max(a,c)<<endl;
  return 0;
}

Measured memory_bytes: 256
INF = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
rui = [0] * (N + 1)
for i in range(N):
    rui[i + 1] = A[i] + rui[i]

ans = 0
for i in range(N - 1):
    ans += (rui[N] - rui[i + 1]) * A[i]
    ans %= INF
print(ans % INF)


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

int main() {
	string S; int N;
	cin >> N >> S;
	vector<int> ANS(N,0);
	for(int i = 1 ; i < N ; i++){
		if(S[i] == 'E')ANS[0]++;
	}
	for(int i = 1 ; i < N ; i++){
		ANS[i] = ANS[i-1];
		if(S[i] == 'E') ANS[i]--;
		if(S[i-1] == 'W')ANS[i]++;
	}
	sort(ANS.begin(),ANS.end());
	cout << ANS[0] << endl;
}

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


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

    int n;
    cin>>n;
    if(n<=2){
        cout << "-1\n";
        return 0;
    }
    if(n==3){
        cout << "aab\n";
        cout << "b.b\n";
        cout << "bcc\n";
        return 0;
    }
    if(n==6){
        cout << "aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n";
        return 0;
    }
    string ans[n]={};
    string a[7],b[4],c[5];
    a[0] = "zzyu...";
    a[1] = "ggyu...";
    a[2] = "d.a.hh.";
    a[3] = "d.a..kk";
    a[4] = ".j.ggyy";
    a[5] = ".j..t.u";
    a[6] = "..ggt.u";
    
    b[0]="aabc";
    b[1]="ffbc";
    b[2]="tyll";
    b[3]="tykk";

    c[0]="aabbc";
    c[1]="qww.c";
    c[2]="q..gh";
    c[3]="z..gh";
    c[4]="zbbjj";

    int x=0,y=0,z=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int t = n - i*7 - j*4;
            if(t>=0 && t%5==0){
                x=i,y=j,z=t/5;
                break;
            }
        }
    }
    //cerr << x << " " <<y << " " << z<<endl;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans[i] += ".";
        }
    }
    int now = 0;
    while(x){
        for(int i=0;i<7;i++){
            for(int j=0;j<7;j++){
                ans[now+i][now+j] = a[i][j];
            }
        }
        now += 7;
        x--;
    }
    while(y){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                ans[now+i][now+j] = b[i][j];
            }
        }
        now+=4;
        y--;
    }
    while(z){
        for(int i=0;i<5;i++){
            for(int j=0;j<5;j++){
                ans[now+i][now+j] = c[i][j];
            }
        }
        now+=5;
        z--;
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 2304
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC104.Task03_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ');
            int d = int.Parse(line1[0]);
            int g = int.Parse(line1[1]);

            var ps = new List<int>();
            var cs = new List<int>();


            for (var i = 0; i < d; i++)
            {
                var s = Console.ReadLine().Split(' ');
                ps.Add(int.Parse(s[0]));
                cs.Add(int.Parse(s[1]));
            }

            var result = Solve(d, g, ps, cs);
            Console.WriteLine(result);
        }

        static long Solve(int d, int g, List<int> ps, List<int> cs)
        {
            int ans = 1000000000;
            for (int mask = 0; mask < (1 << d); mask++)
            {
                int s = 0;
                int num = 0;
                int rest_max = -1;

                for (int i = 0; i < d; ++i)
                {
                    if (((mask >> i) & 1) == 1)
                    {
                        s += 100 * (i + 1) * ps[i] + cs[i];
                        num += ps[i];
                    }
                    else
                    {
                        rest_max = i;
                    }
                }

                if (s < g)
                {
                    int s1 = 100 * (rest_max + 1);
                    int need = (g - s + s1 - 1) / s1;
                    if (need >= ps[rest_max])
                    {
                        continue;
                    }
                    num += need;
                }
                ans = Math.Min(ans, num);
            }
            return ans;
        }
    }
}


Measured memory_bytes: 11220
K = int(input())
dic = {i+1:[] for i in range(11)}

dic[1] = [str(i+1) for i in range(9)]

if K < 10:
    print(dic[1][K-1])
else:
    cnt = 9
    ans = -1
    for i, nums in dic.items():
        for n in nums:
            ds = n[-1]
            dd = int(ds)
            if dd > 0:
                dic[i+1].append(n + str(int(ds)-1))
                cnt += 1
            if cnt == K: break
            dic[i+1].append(n + str(int(ds)))
            cnt += 1
            if cnt == K: break
            if dd < 9:
                dic[i+1].append(n + str(int(ds)+1))
                cnt += 1
            if cnt == K: break
        if cnt == K:
            ans = dic[i+1][-1]
            break
    # from pprint import pprint
    # pprint(dic)
    print(ans)
            

Measured memory_bytes: 10200
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n; cin >> n;
  int a,amin = n+1;
  int ans = 0;
  
  for(int i=0; i<n; i++){
    cin >> a;
    if(a<amin){
      amin = a;
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll dp[20004][256]; 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while(cin>>N>>M,N||M) {
    int c[M]; FOR(i,0,M) cin >> c[i];
    int x[N]; FOR(i,0,N) cin >> x[i];
    FOR(i,0,N+1) FOR(j,0,256) dp[i][j] = 1e18;
    dp[0][128] = 0;
    FOR(i,0,N) {
      FOR(j,0,256) {
        if(dp[i][j] == 1e15) continue;
        FOR(k,0,M) {
          int y = max(0, min(255, j + c[k]));
          dp[i+1][y] = min(dp[i+1][y], dp[i][j] + (ll)(x[i]-y) * (ll)(x[i]-y));
        }
      }
    }
    ll ans = 1e18;
    FOR(i,0,256) ans = min(ans, dp[N][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 43216
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,c=0;
	char S[3];
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%s",S);
		if(S[0]=='A')
			c++;
		else
		{
			c--;
			if(c<0)
			{
				puts("NO");
				return 0;
			}
		}
	}
	puts(c==0?"YES":"NO");
	return 0;
}

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

using namespace std;

int main(){
	char c;
	vector<int> list(26,0);
	while(cin >> c){
		if(c>='A' && c<='Z'){
			c+='a'-'A';
		}
		if(c>='a' && c<='z'){
			int num=c-'a';
			list[num]++;
		}
	}
	for(int i=0;i<26;i++){
		char t=i+'a';
		cout << t << " : " << list[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
// 解法#2

'use strict'
function main(input) {
  input = input.trim().split('\n')
  const counts = input.shift().split(' ')
  input = input.map(val => val.split(' '))

  let result = []

  input.map(items => items.sort((a, b) => Number(b) - Number(a)))

  for (let i = 0; i < counts[0]; i++) {
    for (let j = 0; j < counts[1]; j++) {
      for (let k = 0; k < counts[2]; k++) {
        if ((i + 1) * (j + 1) * (k + 1) <= 3000) {
          result.push(Number(input[0][i]) + Number(input[1][j]) + Number(input[2][k]))
        } else {
          break
        }
      }
    }
  }
  result = result.sort((a, b) => b - a).slice(0, counts[3])

  console.log(result.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 48652
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n;
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    a[n-1] /= 2;
    int ans=0;
    REP(i,n){
        ans += a[i];
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
// ABC137B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
	int limit_Left  = -1000000;
	int limit_Right = 1000000;

	int K,X;
	cin >> K >> X;

	int left = max(X - K + 1, limit_Left);
	int right = min(X + K - 1, limit_Right);
	
	int ans = left;
	while (ans<=right)
	{
		cout << ans << " ";
		ans++;
	}
		cout << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np

x, y, z, k = map(int, sys.stdin.readline().split())
a, b, c = (np.array(sys.stdin.readline().split(), dtype=np.int64) for _ in range(3))

def main():
    res = np.sort(np.ravel(a[:, None] + b))[::-1]
    res = np.sort(np.ravel(c[:, None] + res[:min(k, x*y)]))[::-1]
    return res[:k]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 67256
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N,M,C = LI()
B = LI()
A = [list(map(int,input().split())) for i in range(N)]

ans = 0
for i in range(len(A)):
    temp = 0
    for q in range(len(A[i])):
        temp += B[q]*A[i][q]
        if q == len(A[i]) - 1:
            temp += C
            
            if temp > 0:
                ans += 1

print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  int n;
  cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int count=0;
  int count2=0;
  for(int i=0;i<n;i++){
    if(a[i]%4==0){
      ++count2;
    }
    if(a[i]%2==0){
      ++count;
    }
  }
  count-=count2;
  if(count>=n-count2*2 | count2>=n/2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def reach_all(G, N):
    visited = [0] * N
    def dfs(G, v):
        visited[v] = 1
        for next_v in G[v]:
            if visited[next_v]:
                continue
            dfs(G, next_v)
    dfs(G, 0)
    if sum(visited) != N:
        return False
    return True

def main():
    N, M = LI()
    edge = []
    for _ in range(M):
        a, b = LI_()
        edge.append((a, b))

    cnt = 0
    for i in range(M):
        G = [[] for _ in range(N)]
        for j in range(M):
            if i == j:
                continue
            a, b = edge[j]
            G[a].append(b)
            G[b].append(a)
        if not reach_all(G, N):
            cnt += 1
    print(cnt)
main()



Measured memory_bytes: 68696