akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
def Eratosthenes(N): #N以下の素数のリストを返す
    N+=1
    is_prime_list = [True]*N
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_list[i]]

#aを破壊的にgcd-zetaする
def zeta_gcd(a,primes):
    n = len(a)-1
    for p in primes:
        for i in range(n//p,0,-1):
            a[i] += a[p*i]
            a[i] %= MOD
#    return a

#aを破壊的にgcd-mobiusする
def mobius_gcd(a,primes):
    n = len(a)
    for p in primes:
        for i in range(1,n):
            if i*p >= n: break
            a[i] -= a[p*i] 
            a[i] %= MOD
#    return a

################################################

#################################################

SIZE=1000001; MOD=998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
inv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD

################################################
#################################################
import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]

num = [0]*SIZE
for i in a: num[i] += i

primes = Eratosthenes(SIZE)

zeta_gcd(num,primes)
ans = [i*i for i in num]
mobius_gcd(ans,primes)

res = 0
for i,c in enumerate(ans):
    res = (res + c*inv[i])%MOD
for i in a:
    res = (res-i)%MOD
        
print(res*inv[2]%MOD)









Measured memory_bytes: 125308
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n;
	m = n;
	int sn = 0;
	while (n!=0) {
		sn += n % 10;
		n /= 10;
	}
	//cout << sn << endl;
	if (m % sn == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//
// Created by 田島明弘 on 2019-04-20.
//
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int a, b, t;
    cin >> a >> b >> t;

    cout << b*(t/a) << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	int ans = 0;
	rep(i, n - 2) {
		if (p[i] < p[i + 1] && p[i + 1] < p[i + 2] || p[i] > p[i + 1] && p[i + 1] > p[i + 2]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int cnt = 1;
    int ans = 0;

    while (true) {
      if (cnt >= b) {
        break;
      } else {
        ans++;
        cnt += a - 1;
      }
    }

    System.out.println(ans);

  }
}

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

const int MN = 55, M = 1000000007;
int n, ans = 1, p = -1;
char s[2][MN];

int main(){
	scanf("%d%s%s", &n, s[0] + 1, s[1] + 1);
	for(int i = 1; i <= n; ){
		if(s[0][i] == s[1][i]){
			ans = int(1LL * ans * (p == -1 ? 3 : p == 0 ? 2 : 1) % M);
			p = 0;
			i++;
		}
		else{
			ans = int(1LL * ans * (p == -1 ? 6 : p == 0 ? 2 : 3) % M);
			p = 1;
			i += 2;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                   1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << a.at(K - 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll,ll> pp;

#define debug(x) cout << #x << " :: "<< x <<"\n";
#define debug2(x,y) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\n";
#define debug3(x,y,z) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree< pair<ll,ll> , null_type,less< pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    boost
    string s;
    cin >> s;
    bool flag=true;
    ll n=s.size();
    if(n&1) {
        cout << "No";
        return 0;
    }
    for(ll i=0;i<n;i++) {
        if( (i&1 && s[i]!='i') || ( i%2==0 && s[i]!='h' ) )
        {
            flag=false;
            break;
        }
    }
    if(flag)    {
        cout << "Yes\n";
    }
    else    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}


int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> h(n);
    ll ans=0;
    REP(i,n){
        cin >> h[i];
    }
    sort(h.begin(),h.end(),greater<ll>());
    REP(i,n){
        if (k > 0)
        {
            k--;
        }
        else
        {
            ans += h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int[] in = new int[6];
		for(int i = 0; i < 6; i++){
			in[i] = scan.nextInt();
		}
		int T = in[0];
		int S = in[1];
		int E = in[2];
		int W = in[3];
		int N = in[4];
		int U = in[5];
		String com = scan.next();
		int len = com.length();
		for(int i = 0; i < len; i++){
			char dir = com.charAt(i);
			String di = String.valueOf(dir);
			if(di.equals("S")){
				int a = T;
				T = N;
				N = U;
				U = S;
				S = a;
			}
			if(di.equals("E")){
				int a = T;
				T = W;
				W = U;
				U = E;
				E = a;
			}
			if(di.equals("N")){
				int a = T;
				T = S;
				S = U;
				U = N;
				N = a;
			}
			if(di.equals("W")){
				int a = T;
				T = E;
				E = U;
				U = W;
				W = a;
			}
		}
		System.out.println(T);
	}
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main(){

    // ll A, B;
    // cin >> A >> B;

    // ll ans = 0;

    // if(true){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }

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

    cout << max(A*B, C*D) << endl;

}

Measured memory_bytes: 764
/* vo00_07.cpp */
#include <iostream>
using namespace std;

int main()
{
	int debt = 100000, n, tmp;

	cin >> n;
	while (n--) {
		debt *= 1.05;
		if (tmp = debt % 1000) { debt += 1000; }
		debt -= tmp;
	}

	cout << debt << '\n';

	return 0;
}

Measured memory_bytes: 1160
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace ABC089
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(Int);
            var S = ss.Next(String, N).Distinct();
            sw.WriteLine(S.Count() == 3 ? "Three" : "Four");
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
        static readonly Func<string, int> Int = int.Parse;
        static readonly Func<string, long> Long = long.Parse;
        static readonly Func<string, double> Double = double.Parse;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13404
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 610

//head

int n, m;
vi G[N], _[N];
ld e[N];
ld prob[N];
ld ans;
bitset<N> check;

ld dfs(int i=0) {
  if(e[i] > -1) return e[i];
  ld &res = e[i] = 0;
  for(int x:G[i]) {
    res += dfs(x)+1;
  }
  res /= G[i].size();
  return res;
}
ld rfs(int i=n-1) {
  if(prob[i] > -1) return prob[i];
  ld &res = prob[i] = 0;
  for(int x:_[i]) {
    res += rfs(x)/G[x].size();
  }
  return res;
}
void afs(int i=0) {
  if(check.test(i)) return;
  check.set(i);
  if(G[i].size() < 2) {
    for(int x:G[i]) afs(x);
    return;
  }
  ld sum = 0;
  for(int x:G[i]) sum += e[x];
  for(int x:G[i]) {
    //cout << e[0] + ((sum-e[x])/((ld)G[i].size()-1) - sum/(ld)G[i].size())*prob[i] << endl;
    chmin(ans, e[0] + ((sum-e[x])/(G[i].size()-1) - sum/G[i].size())*prob[i]);
    afs(x);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    _[b].emplace_back(a);
  }
  fill(e, e+n-1, -100);
  fill(prob, prob+n, -100);
  prob[0] = 1;
  dfs();
  rfs();
  ans = LINF;
  afs();
  if(ans > LINF-1) ans = e[0];
  cout << ans << endl;
}

Measured memory_bytes: 6160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int num = scan.nextInt();
		
		scan.close();

		int A = num / 2;
		int B = num % 2 == 1 ? A + 1 : A;
		
		System.out.print(A * B);
	}
}


Measured memory_bytes: 21716
using System;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long a = long.Parse(input[1]);
		long b = long.Parse(input[2]);
		Console.WriteLine(((a+b) % 2 == 0) ? "Alice" : "Borys");
	}
}

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

void Main()
{
    long x, k, d;
    cin >> x >> k >> d;
    if(x < 0) x = -x;
    if(x/d > k) { cout << x-k*d << endl; return; }
    k -= x/d;
    x = x - (x/d * d);
    if(k % 2 == 0) cout << x << endl;
    else cout << d-x << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


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

int main(){
  int N;
  std::cin >> N;
  std::vector<int> H(N);
  for(int i=0; i<N; i++)
    std::cin >> H[i];

  int current = H[0];
  int moveCount = 0;
  int maxMoveCount = 0;
  for(int i=1; i<N; i++){
    if(current >= H[i]){
      current = H[i];
      moveCount ++;
      if(maxMoveCount < moveCount)
        maxMoveCount = moveCount;
    }else{
      if(maxMoveCount < moveCount){
        maxMoveCount = moveCount;
      }
      current = H[i];
      moveCount = 0;
    }
  }
  std::cout << maxMoveCount << std::endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template <typename T>
struct WeightedUnionFind{
  T d;
  vector<int> r,p;
  vector<T> ws;

  WeightedUnionFind(){}
  WeightedUnionFind(int n,T d):
    d(d),r(n,1),p(n),ws(n,d){iota(p.begin(),p.end(),0);}

  int find(int x){
    if(x==p[x]) return x;
    int t=find(p[x]);
    ws[x]+=ws[p[x]];
    return p[x]=t;
  }

  T weight(int x){
    find(x);
    return ws[x];
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y,T w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y),w=-w;
    r[x]+=r[y];
    p[y]=x;
    ws[y]=w;
  }

  T diff(int x,int y){
    return weight(y)-weight(x);
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n,m;
  while(cin>>n>>m,n){
    using ll = long long;
    WeightedUnionFind<ll> wf(n,0);
    for(int i=0;i<m;i++){
      char t;
      cin>>t;
      if(t=='!'){
        int a,b,w;
        cin>>a>>b>>w;
        a--;b--;
        wf.unite(a,b,w);
      }
      if(t=='?'){
        int a,b;
        cin>>a>>b;
        a--;b--;
        if(wf.same(a,b))
          cout<<wf.diff(a,b)<<"\n";
        else
          cout<<"UNKNOWN\n";
      }
    }
  }
  cout<<flush;
  return 0;
}



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

int main(){
	int n,m,v,x,y;
	string f,s;
	cin >> n >> m >> v;
	cin >> y >> x;
	cin >> f >> s;
	int x1=x,y1=y;
	for(int i = 0 ; i < v ; i += 1){
		if(f[i] == 'R'){
			x1 += 1;
		}
		if(x1 == m+1){
			cout << "NO";
			return 0;
		}
		if(s[i] == 'L' && x1 > 1){
			x1 -= 1;
		}
	}
	x1=x,y1=y;
	for(int i = 0 ; i < v ; i += 1){
		if(f[i] == 'D'){
			y1 += 1;
		}
		if(y1 == n+1){
			cout << "NO";
			return 0;
		}
		if(s[i] == 'U' && y1 > 1){
			y1 -= 1;
		}
	}
	x1=x,y1=y;
	for(int i = 0 ; i < v ; i += 1){
		if(f[i] == 'L'){
			x1 -= 1;
		}
		if(x1 == 0){
			cout << "NO";
			return 0;
		}
		if(s[i] == 'R' && x1 < m){
			x1 += 1;
		}
	}
	x1=x,y1=y;
	for(int i = 0 ; i < v ; i += 1){
		if(f[i] == 'U'){
			y1 -= 1;
		}
		if(y1 == 0){
			cout << "NO";
			return 0;
		}
		if(s[i] == 'D' && y1 < n){
			y1 += 1;
		}
	}
	cout << "YES";
}

Measured memory_bytes: 776
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N;
vector<int>E[202020];
int col[202020];
void dfs(int now,int p){
	fore(x, E[now]) {
		if (p != x) {
			col[x] = 1 - col[now];
			dfs(x, now);
		}
	}
}

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

	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
	}
	dfs(0,-1);
	queue<int>bq,wq;
	for (int i = 0; i < N; i++) {
		if (col[i] == 0) { bq.push(i); }
		else wq.push(i);
	}
	int b = bq.size();
	int w = wq.size();

	map<int, int>mp;
	if (b > N / 3 && w > N / 3) {
		for (int i = 1; i <= N; i++) {
			if (i % 3 == 1) {
				mp[bq.front()] = i;
				bq.pop();
			}
			else if(i%3 == 2){
				mp[wq.front()] = i;
				wq.pop();
			}
		}
		for (int i = 1; i <= N; i++) {
			if (i % 3 == 0) {
				if (bq.size()) {
					mp[bq.front()] = i;
					bq.pop();
				}
				else {
					mp[wq.front()] = i;
					wq.pop();
				}
			}
		}
	}
	else{
		if (w <= N / 3)swap(bq, wq);
		for (int i = 1; i <= N; i++) {
			if (i % 3 == 0) {
				if (bq.size()) {
					mp[bq.front()] = i;
					bq.pop();
				}
				else {
					mp[wq.front()] = i;
					wq.pop();
				}
			}
		}
		for (int i = 1; i <= N; i++) {
			if (i % 3 != 0) {
				mp[wq.front()] = i;
				wq.pop();
			}
		}
	}
	fore(x, mp)cout << x.second << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 28032
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<long long>;
using pll = pair<long long, long long>;
template<class T> using pr = pair<T, T>;
template<class T> using vec = vector<T>;

#define debug(x) (std::cerr << (x) << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t",n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define str(n)	(n.toString())

#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 rrep(i, n) for(ll i=(n)-1; i >= 0; --i)
#define rrep1(i, n) for(ll i=(n); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2000000100;
constexpr ll MOD = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = math_P(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T mod_pow(T x, T n, const T& p) { T ret = 1; while (n > 0) { if (n & 1) { (ret *= x) %= p; } (x *= x) %= p; n >>= 1; } return ret; }

/*****/

void Main()
{
	ll N, B, R;
	cin >> N >> B >> R;

	ll BN = 0;
	BN += N / (B + R) * B;
	if (N % (B + R) != 0)
		BN += min(N % (B + R), B);

	cout << BN;
}

/*****/

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

	//std::cout << std::fixed << std::setprecision(10);

	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/

	Main();
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))

int main(){
	ll w,h,n,q;
	while(scanf("%lld%lld%lld%lld",&w,&h,&n,&q),n){
		int tate[40],yoko[40];
		rep(i,0,h)tate[i]=1;
		rep(i,0,w)yoko[i]=1;
		while(n--){
			ll c,f;
			scanf("%lld%lld",&f,&c);
			if(f==1){
				//yoko
				int temp[40]={};
				rep(i,0,max(c,w-c)){
					if(c+i<w)temp[i]+=yoko[c+i];
					if(i<c)temp[i]+=yoko[c-1-i];
				}
				w=max(c,w-c);
				rep(i,0,w)yoko[i]=temp[i];
			}else{
				//tate
				int temp[40]={};
				rep(i,0,max(c,h-c)){
					if(c+i<h)temp[i]+=tate[c+i];
					if(i<c)temp[i]+=tate[c-1-i];
				}
				h=max(c,h-c);
				rep(i,0,h)tate[i]=temp[i];
			}
		}
		while(q--){
			ll x,y;
			scanf("%lld%lld",&x,&y);
			printf("%lld\n",yoko[x]*tate[y]);
		}
	}
}


Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;


int main() {
	long long n;
	long long d[100000];

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

	sort(d, d + n);

	long long a = d[n / 2 - 1];
	long long b = d[n / 2];
	// a+1以上、b以下にすればよい
	cout << b - (a + 1) + 1 << endl;
}

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

int main(){
  int N, A, B;
  string S;
  cin >> N >> A >> B;
  cin >> S;
  int dom=0, abr=0, count=0;
  for(int i=0; i<S.size(); i++){
    if(S[i]=='a'){
      dom++;
      if(count<A+B){
        cout << "Yes" << endl;
        count++;
      }else{
        cout << "No" << endl;
      }
    }
    else if(S[i]=='b'){
      abr++;
      if(count<A+B && abr<=B){
        cout << "Yes" << endl;
        count++;
      }else{
        cout << "No" << endl;
      }
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

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

#define rp(i, k, n) for (ll i = k; i < n; i++)
#define ll  long long

ll mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> data(n);
    rp(i,0,n) {
        cin >> data.at(i).second >> data.at(i).first;
    }
    sort(data.begin(), data.end());
    int now = 0;
    rp(i,0,n) {
        now += data.at(i).second;
        if (now > data.at(i).first) {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 3328
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
  int n, m;
  cin >> n >> m;
  vl h(n, 0);
  rep(i, n) {
    cin >> h[i];
  }
  vector<vector<int>> graph(n, vector<int>());
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }
  int result = 0;
  auto calc = [&](int start) {
    ll ma = h[start];
    map<int, int> memo;
    memo[ma]++;
    for(int i = 0; i < graph[start].size(); i++)
    {
      int ne = graph[start][i];
      if(ma <= h[ne]) {
        ma = h[ne];
        memo[ma]++;
      }
    }
    if(ma == h[start] && memo[ma] == 1) result++;
  };
  rep(i, n) {
    calc(i);
  }
  cout << result << endl;
}


Measured memory_bytes: 9020
function Main(input) {
	var tmp = input.split(" ");
	var n = parseInt(tmp[0], 10);
	var k = parseInt(tmp[1], 10);
	var a = 0;
	for(var i=1; i>=0; i++){
    	if(n >= Math.pow(k,i)){
           a = i;
        }else{
        	break;
        }
    }
	console.log(a+1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
def readinput():
    s=input()
    return s

def printTbl(tbl):
    for l in tbl:
        print(l)

def main(s):
    MOD=10**9+7

    Rtbl=[]
    for _ in range(10):
        Rtbl.append([0]*13)
    for i in range(1,10):
        for j in range(13):
            Rtbl[i][j]=(Rtbl[i-1][j]+j)%13
    #printTbl(Rtbl)

    n=len(s)
    p0=0
    q=[]
    for i in range(n):
        if s[i]!='?':
            p0=(p0*10+int(s[i]))%13
            for j in range(len(q)):
                q[j]=(q[j]*10)%13
        else:
            p0=(p0*10)%13
            for j in range(len(q)):
                q[j]=(q[j]*10)%13
            q.append(1)
    #print(p0,q)

    nq=len(q)
    if nq==0:
        if p0==5:
            return 1
        else:
            return 0

    Ptbl=[]
    for _ in range(13):
        Ptbl.append([0]*nq)
    q0=q[0]
    for i in range(10):
        Ptbl[(Rtbl[i][q0]+p0)%13][0]+=1
    for j in range(1,nq):
        qj=q[j]
        for n in range(10):
            for i in range(13):
                if Ptbl[i][j-1]>0:
                    ii=(i+Rtbl[n][qj])%13
                    Ptbl[ii][j]=(Ptbl[ii][j]+Ptbl[i][j-1])%MOD
    #printTbl(Ptbl)
    return Ptbl[5][nq-1]

def main2(s):
    MOD=10**9+7
    dp=[]
    n=len(s)
    for _ in range(13):
        dp.append([0]*(n+1))
    dp[0][0]=1
    for i in range(n):
        c=s[i]
        for j in range(13):
            for k in range(10):
                if c!='?' and c!=str(k):
                   continue
                jj=(j*10+k)%13
                dp[jj][i+1]=(dp[jj][i+1]+dp[j][i])%MOD
    return dp[5][n]

if __name__=='__main__':
    s=readinput()
    ans=main2(s)
    print(ans)


Measured memory_bytes: 83960
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    //int ans=0;
    bool ans=false;
    int a[3][3];
    bool c[3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
            c[i][j]=false;
        }
    }

    int N;
    cin>>N;
    vector<int> b;

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


    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<N;k++){
                if(a[i][j]==b[k]){
                    c[i][j]=true;
                }
            }
        }
    }

    if(c[0][0] && c[0][1] && c[0][2]){
        ans=true;
    }
    else if(c[1][0] && c[1][1] && c[1][2]){
         ans=true;
    }
    else if(c[0][2] && c[1][1] && c[2][0]){
         ans=true;
    }
    else if(c[2][0] && c[2][1] && c[2][2]){
         ans=true;
    }
    else if(c[0][0] && c[1][0] && c[2][0]){
         ans=true;
    }
    else if(c[0][1] && c[1][1] && c[2][1]){
         ans=true;
    }
    else if(c[0][2] && c[1][2] && c[2][2]){
         ans=true;
    }
    else if(c[0][0] && c[1][1] && c[2][2]){
         ans=true;
    }

    //cout<<ans<<endl;
    
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
  AOJ 2030
  Title:Ruins
  @kankichi573
*/
#include <stdio.h>
#include <math.h>
#include <limits.h>
extern double sqrt(double);

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int solve(int m,int n)
{
  int min_,sum,i,j,k,l,a[4],b[4];
  min_=INT_MAX;

  for(i=1;i<=sqrt(m);i++)
    {
      if(m % i)
	continue;
      a[0]=i;
      a[1]=m/i;
      for(j=1;j<=sqrt(n);j++)
	{
	  if(n % j)
	    continue;
	  a[2]=j;
	  a[3]=n/j;
	  for(k=0;k<4;k++)
	    b[k]=a[k];
	  qsort(b,4,sizeof(int),compare_int);
	  sum=0;
	  for(k=0;k<3;k++)
	    sum += (b[k]-b[k+1])*(b[k]-b[k+1]);
	  if(sum < min_)
	    {
	      /*
	      for(l=0;l<4;l++)
		printf("%d:",b[l]);
	      printf("\n");
	      */
	    min_ = sum;
	    }
	}
    }
  return(min_);
}
main()
{
  int N,M,ret;

  while(scanf("%d %d",&N,&M) && (N || M))
    {
      ret=solve(N,M);
      printf("%d\n",ret);
    }

  return(0);
}

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

#define int long long

int mod = 10000;
int n, k;
int p[111] = {0};

int dp[111][2][4];

int dfs(int i = 1, bool ff = false, int f = 0)
{
  int &ans = dp[i][ff][f];

  if (ans != -1) return ans;
  if (i == n + 1) {
    return 1;
  }
  
  if (p[i] != 0){
    if (ff && f == p[i]) return 0;
    ans = dfs(i + 1, f == p[i], p[i]);
    return ans %= mod;
  }

  ans = 0;
  for (int j = 1; j < 4; j++){
    if (ff && f == j) continue;
    ans += dfs(i + 1, f == j, j);
  }

  return ans %= mod;
}

main()
{
  memset(dp, -1, sizeof(dp));

  cin >> n >> k;
  for (int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    p[a] = b;
  }

  cout << dfs() << endl;
}

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

// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

#define rep(i, x) for(int i = 0; i < (int)(x); i++)/*{{{*/
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007/*}}}*/

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;/*{{{*/
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*}}}*/

// global variables

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

  int a[n];
  int s;
  rep(i,n){
    int tmp;cin>>tmp;
    if (tmp==1){
      s = i;
    }
  }

  int res = INF;
  rep(j, k){
    int tmp = 1;
    int l,r;
    l = s-j;
    r = n-(s+k-1-j)-1;
    dump(s,l,r);

    if (l<0 || r<0) continue;

    dump((l+(k-1)+1)/(k-1), (r+(k-1)+1)/(k-1));
    tmp += (l+(k-1)-1)/(k-1);
    tmp += (r+(k-1)-1)/(k-1);
    res = min(res, tmp);
  }

  std::cout << res << std::endl;


  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll R, G;
    cin >> R >> G;
    cout << 2*G - R << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main() {
    double n,k;
    double sum =0;
    cin >> n >> k;
    for (int i=1;i<=n;i++){
        double now=i;
        int cnt=0;
        while(now<k){
            now*=2;
            cnt++;
        }
        sum+=pow(2.f,-cnt);
    }

    printf("%.10lf",sum/n);
    return 0;
}

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
const int M = 1000000007;

int mul(int a, int b)
{
	return (a * b) % M;
}

int pwr(int a, int b)
{
	if (b == 0) return 1;
	int c = pwr(a, b / 2);
	if (b % 2 == 1) return mul(a, mul(c, c));
	return mul(c, c);
}

int inv(int a, int m)
{
	return pwr(a, m - 2);
}

void solve()
{
	int n;
	cin >> n;
	int arr[n];
	loop(i, 0, n) cin >> arr[i];

	int i = 0, ans = 1000, initial = 1000;
	while (i < n)
	{
		int j = i;
		while (j < n - 1  and arr[j] <= arr[j + 1] )j++;

		int cash = initial;
		int total = cash / arr[i];
		cash -= total * arr[i];

		initial = cash +  arr[j] * total;

		i = j + 1;
	}

	cout << initial << endl;


	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int W,H;
  int a[101],imos[102][102]={0},x[101],N,y[101],res=0;
  cin >> W >> H >> N;
  REP(i,N)cin >> x[i] >> y[i] >> a[i];
  REP(i,N){
    switch(a[i]){
    case 1:
      REP(k,H)REP(j,W){
        if(j < x[i])
          imos[k][j]++;
      }
      break;
    case 2:
      REP(k,H)REP(j,W){
        if(j >= x[i])
          imos[k][j]++;
      }
      break;
    case 3:
      REP(k,H)REP(j,W){
        if(k < y[i])
          imos[k][j]++;
      }
      break;
    case 4:
      REP(k,H)REP(j,W){
        if(k >= y[i])
          imos[k][j]++;
      }
      break;
    }
  }
  REP(k,H)REP(j,W){
    if(imos[k][j] == 0)res++;
  }
  cout << res << endl;
  return 0;  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define fi first
#define se second
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long LL;

LL A, B;
int dA[105], dB[105];

int main(){
	cin >> A >> B;
	if(A == B){
		printf("%d\n", 1);
		return 0;
	}
	if(A % 2 == 0 && B - A == 1){
		int ans = 2;
		if((A | B) != B && (A | B) != A) ans = ans + 1;
		printf("%d\n", ans);
		return 0;
	}
	REP(i, 0, 63){
		dA[i] = (A >> i) & 1;
		dB[i] = (B >> i) & 1;
	}
	LL X = 0, Y = 0, L = 0, ans = 0;
	PER(i, 63, 0){
		if(dA[i] != dB[i]){
			PER(j, i - 1, 0){
				if(dA[j]) X += 1LL << j;
				if(dB[j]) Y += 1LL << j;
				L += 1LL << j;
			}
			ans += L - X + 1;
			if(Y >= X){
				ans += L + 1;
			}else{
				ans += L - X + 1;
				int k = 0;
				for(; (1LL << k) <= Y; k ++);
				Y = (1LL << k) - 1;
				ans += min(Y, X - 1) + 1;
			}
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int N;
	cin >> N;
	int a[N];
	rep(i,N) cin >> a[i];
	int ans = 1e9;
	for (int i = -100; i <= 100; i++) {
		int sum = 0;
		rep(j,N) sum += (a[j]-i)*(a[j]-i);
		ans = min(ans,sum);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3528
#include <iostream>
using namespace std;
int main()
{
	
	int k,n,m;
	cin>>k>>n>>m;
	bool flag = false;
	for(int i=n;i<=m;i++)
	{
		if(i%k==0){
			flag = true;
			break;
		}
			
	}
	if(flag)
		cout<<"OK";
	else
		cout<<"NG";
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


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

int N,K,c;
scanf("%d%d",&N,&K);
int h[N];
rep(i,N)scanf("%d",&h[i]);
rep(i,N){
	if(h[i]>=K)c++;
}
printf("%d",c);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
    int n;
    double x1,y1,x2,y2,x,y,a,b,dx,dy,xy,x2y2;

    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

    dx = x1-x2;
    dy = y1-y2;
    xy = x1*y2 - x2*y1;
    x2y2 = dy*dy + dx*dx;
    
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lf %lf",&a,&b);

        x = (dx*(a*dx+b*dy) - dy*xy) / x2y2;
        y = (xy*dx + (a*dx+b*dy)*dy) / x2y2;

        if(x == -0.0) x = 0.0;
        if(y == -0.0) y = 0.0;

        printf("%.11lf %.11lf\n",x,y);
    }

    return 0;

}


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

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d,d+n);
  int ans = d[n/2] - d[n/2-1];
  cout << ans << endl;
}


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

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int cnt = 0;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            cnt++;
            i++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int r, c, n, cnt[100005], ans[102][102];



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

    cin>>r>>c>>n;
    for(int i=1;i<=n;i++)
    	cin>>cnt[i];

    int i = 1, j = 1;
    for(int z=1;z<=n;z++){
    	int l = cnt[z];
    	while(l--){
    		ans[i][j] = z;
// cout<<i<<" "<<j<<" "<<z<<endl;
    		if(i % 2 == 1){
    			j++;
    			if(j == c+1){
    				i++;	j = c;
    			}
    		}
    		else{
    			j--;
    			if(j == 0){
    				i++;	j = 1;
    			}
    		}
    	}
    }

    for(int i=1;i<=r;i++){
    	for(int j=1;j<=c;j++)
    		cout<<ans[i][j]<<" ";
    	cout<<endl;
    }

    return 0;
}
 




Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] c = new int[m][2];
		for(int i = 0; i < m; i++){
		    c[i][0] = sc.nextInt()-1;
		    c[i][1] = sc.nextInt();
		}
		
		// 計算
		int result = -1;
		char[] s = new char[n];
		Arrays.fill(s, '?');
		boolean flg = true;
		for(int i = 0; i < m; i++){
		    if(c[i][0] == 0 && c[i][1] == 0 && n > 1){
		        flg = false;
		        break;
		    }else if(s[c[i][0]] == '?' || s[c[i][0]] - '0' == c[i][1]){
		        s[c[i][0]] = String.valueOf(c[i][1]).charAt(0);
		    }else{
		        flg = false;
		        break;
		    }
		}
		if(flg){
		    if(s[0] == '?' && n > 1) s[0] = '1';
		    String ans = new String(s);
		    System.out.println(ans.replace('?', '0'));
		    return;
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long int
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector<long long>v(n);
#define mii unordered_map<ll,ll>
#define pb push_back
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

      
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
         ll u;
         cin>>u;ll cnt=0;
        vector<int>v(u+1);
         for(int i=1;i<=sqrt(u);i++)
         {
                  
                   for(int j=1;j<=sqrt(u);j++)
                   {
                             
                           for(int k=1;k<=sqrt(u);k++)
                           {
                             int d=(i*i+j*j+k*k+i*j+i*k+j*k);
                             if(d<=u)
                             {
                                   v[d]++;    
                             }
                           }
                   }
                   
         }
        
         for(int i=1;i<=u;i++)
         {
                   cout<<v[i]<<endl;
         }
       }
 }

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

main(){
  ll i,n,m,count=0;
  cin >> n;
  vector<ll> mon(n+1),yu(n);
  for(i=0;i<n+1;i++) cin >> mon[i];
  for(i=0;i<n;i++) cin >> yu[i];
  
  for(i=0;i<n;i++){
    m=min(mon[i],yu[i]);
    mon[i] -= m;
    yu[i] -= m;
    count += m;
    
    m=min(mon[i+1],yu[i]);
    mon[i+1] -= m;
    yu[i] -= m;
    count += m;
  }
  cout << count << endl;
}
  
  
  

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

from collections import Counter

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = []
    for i in range(n):
        lb.append((la[i],i))
    lb.sort()
    for b in lb:
        print(b[1]+1)


if __name__ == '__main__':
    main()


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

int main() {
    int n;
    cin >> n;
    vector<int> v;
    rep(i,n) {
        int a;
        cin >> a;
        if(a%2==0) v.push_back(a);
    }
    bool flag = true;
    for(int i : v) {
        if(i%3 != 0 && i%5 != 0) {
            flag = false;
            break;
        }
    }
    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC168C
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int A = int.Parse(target[0]);
            int B = int.Parse(target[1]);
            int H = int.Parse(target[2]);
            int M = int.Parse(target[3]);
            double theta = 2.0*Math.PI*((H/12.0+M/(12*60.0))-M/60.0);
            double L = Math.Sqrt(B*B*Math.Sin(theta)*Math.Sin(theta)+(A-B*Math.Cos(theta))*(A-B*Math.Cos(theta)));
            Console.WriteLine("{0:f12}", L);
        }
    }
}


Measured memory_bytes: 27864
#include <iostream>
#include <math.h>

int main(){
	int N;
	int flag = 0;
	std::cin >> N;
	int sousuu = N; 

	for(int i = 10;i <= N;i *= 100){
		if(N - (i*10-1) > 0){
			sousuu -= (i*10-i);
		}else{
			sousuu -= N - i + 1;
		}
		//std::cout << i << ":" << sousuu <<"\n";
	}
	sousuu = sousuu;
	std::cout << sousuu;
	
	return 0;
}

Measured memory_bytes: 256