akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U>
void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, multiset<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } my_init;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
////////////////////////////////
const int INF = 1e10;

int32_t main() {
    int n,k; cin >> n >> k;
    vector<int> h(n); cin >> h;
    vector<int> dp(n+10,INF);
    dp[0] = 0;
    rep (i,n) loop (j,i+1,<=min(n-1,i+k)) {
        chmin(dp[j], dp[i] + abs(h[i]-h[j]));
    }
    cout << dp[n-1] << "\n"; 
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 500010


int main(){
	int a[N];
	int b[N];
	int c[N];
	int n, k;
	scanf("%d %d", &n,&k);
	f(i, n){
		scanf("%d", &a[i]);
	}
	b[0] = k;
	f(i, n){
		if (abs(b[i] - a[i]) < b[i])b[i + 1] = abs(b[i] - a[i]);
		else b[i + 1] = b[i];
	}
	c[n - 1] = 0;
	for (int i = n - 1; i > 0; i--){
		if (a[i] <= ((2 * c[i]) + 1))c[i - 1] = a[i] + c[i];
      else c[i-1]=c[i];
	}
	scanf("%d", &n);
	f(i, n){
		scanf("%d", &k);
		k--;
		if (b[k] > c[k])printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 7680
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: str):
    ret = 1
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            ret += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    rep(i,n){
        rep(j,m){
            int cnt=i*j + (n-i)*(m-j);
            if(k==cnt || k==n*m-cnt){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var X = nextLong()
    val P = prime(X, Math.min(100005L, X + X))
    val ans = P[0]
    println(ans)
}
fun next() = readLine()!!
fun nextLong() = next().toLong()
fun prime(from: Long, to: Long = from): List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j -> i % j != 0L }
    }
}

Measured memory_bytes: 33864
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 ll INF = 1e9;
const ll MOD = 1e9 + 7;


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

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

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<long> h;
  for(int i=0;i<n;i++) {
    long l;
    cin >> l;
    h.push_back(l);
  }
  sort(h.begin(), h.end());
  for(int i=0;i<k && !h.empty();i++){
    h.pop_back();
  }
  cout << accumulate(h.begin(), h.end(), 0L) << endl;
}


Measured memory_bytes: 2420
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var line = Console.ReadLine();
            
            if (line == "AAA" || line == "BBB")
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 11092
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

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

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

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

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

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

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

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

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	ll A; long double B; cin >> A >> B;
	ll x = A * B;
	cout << x << endl;
}

Measured memory_bytes: 11060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int main() {
    int n, t;
    cin >> n >> t;
    int64_t sum=t;
    vector<int> vec(n,0);
    rep(i,n) cin >> vec.at(i);
    int pre = 0, cd = t;
    rep(i,n) {
        int c = vec.at(i)-pre;
        if (c < t) sum -= t-c;
        sum += t;
        pre = vec.at(i);
    }
    ct(sum);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
 
int main() {
    int A,B,H,M;
    int t;
    cin >>A>>B>>H>>M;
    long double C;
    t=60.0*H+M;
    C = sqrt(pow(A,2.0) + pow(B,2.0) - 2.0*A*B*cos(t*M_PI*(1.0/30.0-1.0/360.0)));
    cout<< fixed << setprecision(15) <<C<<endl;
}

Measured memory_bytes: 4188
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,h,w;cin>>n>>h>>w;
  ll res=0;
  rep(i,n){
    ll a,b;cin>>a>>b;
    if(a>=h&&b>=w)res++;
  }
  cout<<res<<endl;

  return 0;

}


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

using namespace std;

const int SIZE = 210;
const double eps = 1e-10;

typedef long long ll;

typedef ll P_type;
typedef complex<P_type> P;
const P_type P_eps = 0; //整数の時はゼロ

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
  }
};

P rotate(P p, double theta){
  return p * P(cos(theta), sin(theta));
}

//内積
double dot(P a, P b) {
  return (a * conj(b)).real();
}

//外積
double cross(P a, P b) {
  return (conj(a) * b).imag();
}

//反時計回り
int ccw(P a, P b, P c){
  if(cross(b-a,c-a) > 0) return 1; //COUNTER_CLOCKWISE
  if(cross(b-a,c-a) < 0) return -1; //CLOCKWISE
  if(dot(b-a,c-a) < 0) return -2; //ONLINE_BACK
  if(dot(a-b,c-b) < 0) return 2; //ONLINE_FRONT
  return 0; //ON_SEGMENT
}

/* ConvexHull(凸包) */

vector<P> ConvexHull(vector<P> s){
  vector<P> g;
  int m, n = (int)s.size();
  
  if(n<3) return s;
  
  sort(s.begin(),s.end());
  
  for(int i=0;i<n;i++){
    while((m = g.size()) >= 2 && ccw(g[m-2],g[m-1],s[i]) <= 0) g.pop_back();     
    g.push_back(s[i]);
  }
  
  int t = (int)g.size();
  
  for(int i=n-2;i>=0;i--){
    while((m = g.size()) > t && ccw(g[m-2],g[m-1],s[i]) <= 0) g.pop_back();     
    g.push_back(s[i]);
  }

  g.pop_back();
  
  return g; //反時計回り
}


int main(){
  int n;
  vector<P> vec;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    int x, y;
    scanf("%d%d",&x,&y);
    vec.push_back(P(x,y));
  }

  auto res = ConvexHull(vec);

  printf("%d\n",(int)res.size());

  int start = 0;

  for(int i=1;i<(int)res.size();i++){
    if(res[i].imag() < res[start].imag() ||
       (res[i].imag() == res[start].imag() && res[i].real() < res[start].real())){
      start = i;
    }
  }
  
  for(int i=0;i<res.size();i++){
    printf("%d %d\n",(int)res[(start+i)%res.size()].real(), (int)res[(start+i)%res.size()].imag());
  }
  
  return 0;
}



Measured memory_bytes: 8248
S = input()
mod = 10 ** 9 + 7

dp = [0]*13
dp[0] = 1

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)


Measured memory_bytes: 43756
package main
import "fmt"
func main(){
	var N, M, K int
	fmt.Scan(&N, &M, &K)
	for i:=0; i<=N; i++{
		for j:=0; j<=M; j++{
			if (M-j)*i + (N-i)*j==K{
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 512
N,X,Y=map(int,input().split())
d=[0]*N
for i in range(N):
    for j in range(N):
        if not i<j:
            continue
        dist=min([j-i,abs((X-1)-i)+1+abs(j-(Y-1))])
        d[dist]+=1
print(*d[1:],sep='\n')

Measured memory_bytes: 74672
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    ans = 0
    for i in range(1,n+1):
        if i%3 != 0 and i%5 != 0:
            ans += i
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 73140
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    int n, a[201];
    cin>>n;
    int ans=0;
    for(int i=0; i<n; i++) cin>>a[i];
    bool exist_odd=false;
    while(1){
        for(int i=0; i<n; i++){
            if(a[i]%2==1) exist_odd=true;
            a[i]/=2;
        }
        if(exist_odd)break;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import heapq
n,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L1=[]
for i in range(n):
  L1.append((l[i][0]-l[i][2],1,l[i][2]))
  L1.append((l[i][1]-l[i][2],-1,l[i][2]))
for i in range(q):
  L1.append((int(input()),2,0))
L1.sort()
L2=[]
heapq.heapify(L2)
L3=[]
L3=set(L3)
for i in range(len(L1)):
  if L1[i][1]==1:
    heapq.heappush(L2,L1[i][2])
    L3.add(L1[i][2])
  elif L1[i][1]==-1:
    L3.remove(L1[i][2])
  else:
    while L2 and L2[0] not in L3:
      heapq.heappop(L2)
    if L2:
      print(L2[0])
    else:
      print(-1)

Measured memory_bytes: 138512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
ll quickpow(ll x, ll k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
const int maxn = 1e6 + 5;


int main()
{
    string s;
    cin >> s;
    int cnt = 0, ans = 0;
    for (int i = 0; i < s.size(); ++i){
        if (s[i] == 'R') ++cnt;
        else cnt = 0;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
N = int(input())

s = int(N*(N+1)/2)

N3 = N // 3
N5 = N // 5
N15 = N // 15

s3 = int(N3*(N3+1)/2*3)
s5 = int(N5*(N5+1)/2*5)
s15 = int(N15*(N15+1)/2*15)

print(int(s-s3-s5+s15))

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e5+5;

vector <ll> A(L);
vector <ll> cnt(L);

ll modexp(ll a, ll b, ll mod)
{
    a%=mod;
    
    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%mod;
        }

        a = (a*a)%mod;
        b>>=1;
    }   

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll mod = 1e9+7;

    ll N;
    cin >> N;

    for(ll i=1; i<=N; i++)
    {
        cin >> A[i];

        cnt[A[i]]++;
    }

    if(N&1)
    {
        if(cnt[0]!=1)
        {
            cout << "0" << endl;
            return 0;
        }
        
        for(ll i=1; i<N; i++)
        {
            if(i&1)
            {
                if(cnt[i]!=0)
                {
                    cout << "0" << endl;
                    return 0;
                }
            }

            else
            {
                if(cnt[i]!=2)
                {
                    cout << "0" << endl;
                    return 0;
                }
            }
        }
    }

    else
    {
        for(ll i=0; i<N; i++)
        {
            if(i&1)
            {
                if(cnt[i]!=2)
                {
                    cout << "0" << endl;
                    return 0;
                }
            }
            
            else
            {
                if(cnt[i]!=0)
                {
                    cout << "0" << endl;
                    return 0;
                }

            }
        }
    }

    cout << modexp(2, N/2, mod) << endl;

    return 0;
}

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


int main()
{
ll n ;
cin >> n ;
if(n==2){
  cout << -1 << endl;
  return 0;
}
if(n==3){
  cout << "aa." << endl;
  cout << "..a" << endl;
  cout << "..a" << endl;
  return 0;
}
vector<vector<ll>> v(n, vector<ll>(n,0) );
ll b=0;
ll c;
while(1){
  c=n-b*4;
  if(c>=4&&c<=7)break;
  v[b*4][b*4]=1;
  v[b*4][b*4+1]=1;
  v[b*4+1][b*4]=2;
  v[b*4+1][b*4+1]=2;
  v[b*4+2][b*4]=3;
  v[b*4+3][b*4]=3;
  v[b*4+2][b*4+1]=4;
  v[b*4+3][b*4+1]=4;
  v[b*4][b*4+2]=5;
  v[b*4+1][b*4+2]=5;
  v[b*4][b*4+3]=8;
  v[b*4+1][b*4+3]=8;
  v[b*4+2][b*4+2]=6;
  v[b*4+2][b*4+3]=6;
  v[b*4+3][b*4+2]=7;
  v[b*4+3][b*4+3]=7;
  b+=1;
}
rep(i,4*b){
  rep(j,n){
    if(v[i][j]==0)cout << '.' ;
    else cout << char('a'+v[i][j]) ;
  }
cout << endl ;
}
string k[4][7]={{"aabc","ddbc","bcaa","bcdd"},{"aabba","bcc.a","b..cb","a..cb","abbaa"},{"aabc..","ddbc..","..aabc","..ddbc","bc..aa","bc..dd"},{"aabbcc.","dd.dd.a","..d..da","..d..db","dd.dd.b","..d..dc","..d..dc"}};
rep(i,c){
  rep(j,4*b)cout << '.' ;
  cout << k[c-4][i] << endl;
  
}
return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>
int main(void){
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    
    if( (b-a) == (c-b)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque
H, W, K = map(int, input().split())
sh, sw, gh, gw = map(int, input().split())
sh, sw, gh, gw = sh - 1, sw - 1, gh - 1, gw - 1
G = [list(input()) for _ in range(H)]
INF = 10 ** 9


D = [[INF] * W for _ in range(H)]
D[sh][sw] = 0
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
que = deque([(sh, sw)])

while que:
    nh, nw = que.pop()
    for dh, dw in directions:
        for k in range(1, K + 1):
            nx_h, nx_w = nh + k * dh, nw + k * dw
            if not (0 <= nx_h < H and 0 <= nx_w < W):
                break

            if G[nx_h][nx_w] == '@':
                break

            if D[nx_h][nx_w] <= D[nh][nw]:
                break

            if D[nx_h][nx_w] > D[nh][nw] + 1:
                D[nx_h][nx_w] = D[nh][nw] + 1
                que.appendleft((nx_h, nx_w))

print(D[gh][gw] if D[gh][gw] != INF else -1)


Measured memory_bytes: 134752
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef string str;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vint ans(26,INF) ;
  REP(i,n){
    vint tmp(26,0) ;
    str s ;
    cin >> s ;
    int m = SZ(s) ;
    REP(j,m){
      tmp[s[j]-'a']++ ;
    }
    REP(j,26){
      ans[j] = min(ans[j],tmp[j]) ;
    }
  }
  REP(i,26){
    REP(j,ans[i]){
      cout << (char)(i+'a') ;
    }
  }
  cout << endl ;
      

  return 0 ;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
    int64_t a,b,x;
    cin >> a >> b >> x;
    cout << b/x - a/x + (a%x == 0 ? 1 : 0)  << endl;
    return 0;    
}


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

int main(){
	int y, m, d;
	char a, b;
	cin >> y >> a >> m >> b >> d;

	bool jud = false;
	if(y < 2019) jud = true;
	if(y = 2019 && m <= 4) jud = true;

	if(jud) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> sorted;
int arr[100005];
map<int,int> m;
int main(){
scanf("%d",&n);
for (int x = 0; x<n; x++){
    int t;
    scanf("%d",&t);
    arr[x] = t;
    sorted.push_back(t);
}
sort(sorted.begin(),sorted.end());
for (int x = 0; x<n; x++){
    m[sorted[x]] = x;
}
int ans = 0;
for (int x = 0; x<n; x++){
    if (x%2!=m[arr[x]]%2){
        ans++;
    }
}
printf("%d",ans/2);
}


Measured memory_bytes: 5752
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = 1, x;
        while (true) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                x = i + 0;
                while (x > 0) {
                    if (x % 10 == 3) {
                        System.out.print(" " + i);
break;
                    }
                    x /= 10;
                }
            }
            if(i >= n)break;
            i++;
        }
        System.out.print("\n");
    }
}


Measured memory_bytes: 28628
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int k,a,b; cin>>k>>a>>b;
	ll ans1=0;
	ll ans2=0;
	if(k+1>=a&&b-a>2) {
		ans1=a+1+(1ll*(k-a+1)/2)*1ll*(b-a)-(k-a)%2;
	}
	else{
		ans2=k+1;
	}
	cout<<max(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 256
<?php
$N = intval(fgets(STDIN));
$a = $b = $ab = $both = 0;
for($i = 0; $i < $N; $i++){
    $str = trim(fgets(STDIN));
    for($j = 0; $j < strlen($str) - 1; $j++){
        if($str[$j] == "A" && $str[$j+1] == "B")$ab++;
    }
    if($str[0] == "B")$b++;
    if($str[strlen($str) - 1] == "A")$a++;
    if($str[0] == "B" && $str[strlen($str) - 1] == "A")$both++;
}

if($a == $b && $both == $a){
    echo $ab + max(min($a, $b) - 1,0);
}else{
    echo $ab + min($a, $b);
}


Measured memory_bytes: 4856
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
ll a[100100], b[100100], c[100100];

ll solve() {
    vector<P> vec(m);
    for (int i = 0; i < m; i++) {
        vec[i] = P(c[i], b[i]);
    }
    sort(RALL(vec));

    sort(a, a+n);
    int idx = 0;
    for (int i = 0; i < n; i++) {
        if (vec[idx].first <= a[i]) continue;
        a[i] = vec[idx].first;
        vec[idx].second--;
        
        if (vec[idx].second == 0) idx++;
        if (idx >= m) break;
    }

    ll sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    return sum;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i] >> c[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 4096
a, b, x = map(int, input().split())
from math import degrees, atan2
if x<=a**2*b/2:
    tanj = (x*2)/(b*a)
    print(90-degrees(atan2(tanj, b)))
else:
    x = a**2*b - x
    tanj = (x*2)/(a**2)
    print(degrees(atan2(tanj, a)))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll sum,a,b,c,d,e,f,g;
int main(){
	cin>>a>>b>>e>>c>>d>>f>>g;
    sum = a/2*2 + b + c/2*2 + d/2*2;
    if(a>=1&&c>=1&&d>=1) sum = max(sum,(a-1)/2*2+b+3+(c-1)/2*2+(d-1)/2*2);
    cout << sum << endl;
}

Measured memory_bytes: 256
import itertools
import math

N=int(input())
zahyou=[list(map(int,input().split()))for i in range(N)]
jyunban=list(itertools.permutations(range(N)))
dist=list()
for i in range(len(jyunban)):
    tmp=0
    for j in range(N-1):
        tmp+=math.sqrt((zahyou[jyunban[i][j]][0]-zahyou[jyunban[i][j+1]][0])**2+(zahyou[jyunban[i][j]][1]-zahyou[jyunban[i][j+1]][1])**2)
    dist.append(tmp)
print(sum(dist)/math.factorial(N))

Measured memory_bytes: 15356
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int ans=700;
    cin>>s;
    for (size_t i = 0; i < 3; i++) {
        if (s.at(i)=='o') {
            ans+=100;
        }
    }
std::cout << ans << '\n';
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    a, b = 0, 0
    for _ in range(n):
        ca, cb = map(int, input().split())
        a += ca + cb if ca > cb else ca if ca == cb else 0
        b += ca + cb if ca < cb else cb if ca == cb else 0
    print(a, b)

Measured memory_bytes: 7656
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

# 階層iが取り得る最小値と最大値を記録する
minV = [0 for i in range(N + 1)]
maxV = [0 for i in range(N + 1)]

minV[-1] = A[-1]
maxV[-1] = A[-1]
for i in range(len(A) - 2, -1, -1):
  leaf = A[i] # その階層に必要な葉の数
  minV[i] = (minV[i + 1] + 1) // 2 + leaf
  maxV[i] = maxV[i + 1] + leaf

if 1 < minV[0] or maxV[0] < 1:
  print(-1)
  exit(0)

# 最大頂点数を確定していく
V = [0] * (N + 1)
V[0] = 1
for i in range(1, N + 1):
  V[i] = min((V[i - 1] - A[i - 1]) * 2, maxV[i]) # 親の頂点数から葉の数を引いたものの2倍

print(sum(V))

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll k, t; cin >> k >> t;
  ll vm = 0;
  for (ll i = 0; i < t; i++) {
    ll a; cin >> a;
    vm = max(vm, a);
  }
  if (vm <= (k + 1) / 2) {
    cout << 0 << endl;
  }else {
    cout << (vm - 1) - (k - vm) << endl;
  }


  return 0;
}



Measured memory_bytes: 3616
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


int main() {
  LL a, b, c, d, n;

  cin >> a >> b >> c >> d >> n;
  LL one = min(min(4 * a, 2 * b), c);


  cout << one * (n % 2) + n / 2 * min( 2 * one, d) << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
pair<long, long> x[100000];

pair<long, long> d[100000];

int main(int, char**)
{
	int  t, x;
	cin >> t >> x;

	cout << (double)t / x << endl;
	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
const int maxn = 1e5 + 5;
ll a[maxn], b[maxn];
ll c[maxn * 2];
ll sum[maxn * 2];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    ll ans =  1e18;
    ll suma = 0, sumb = 0;
    for(int i = 1;i <= n;i++){
        cin >> a[i] >> b[i];
        suma += a[i];
        sumb += b[i];
        c[i] = a[i];
        c[i + n] = b[i];
    }
    ans = min(ans, suma);
    ans = min(ans, sumb);
    sort(c + 1, c + 1 + 2 * n);
    sum[0] = 0;
    for(int i = 1;i <= 2 * n;i++){
        sum[i] = sum[i - 1] + c[i];
    }
    for(int i = 1;i <= n;i++){
        int u = upper_bound(c + 1, c + 1 + 2 * n, a[i]) - c - 1;
        int v = upper_bound(c + 1, c + 1 + 2 * n, b[i]) - c - 1;
        if(a[i] == b[i])
            u--;
        if(u > v)
            swap(u, v);
        ll tmp = 0;
        int ub = n - 2;
        if(u <= ub){
            ub++;
        }else{
            tmp += c[u];
        }
        if(v <= ub){
            ub++;
        }else{
            tmp += c[v];
        }
        ans = min(ans, tmp + sum[ub]);
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int n;
int fac[8];

int order(vector<int>& v) {
    set<int> st;
    int num = 0;
    for (int i = 0; i < n; ++i) {
        num += (v[i] - 1 - distance(st.begin(), st.lower_bound(v[i]))) * fac[n - i - 1];
        st.insert(v[i]);
    }
    num++;
    return num;
}

int main() {
    int a, b;
    cin >> n;
    fac[0] = 1;
    for (int i = 1; i < n; ++i) {
        fac[i] = fac[i - 1] * i;
    }
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    a = order(v);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    b = order(v);
    cout << abs(a - b) << endl;

    return 0;
}

Measured memory_bytes: 256
N, M=map(int,input().split())
nums=[list(map(int,input().split())) for i in range(M)]

for i in range(1000):
    n=str(i)
    if len(n)!=N:
        continue
    if all([n[s-1]==str(c) for s,c in nums]):
        print(n)
        break
else:
    print(-1)


Measured memory_bytes: 3060
N, A, B = map(int, input().split())
S = input()

jp = 0
os = 0
for s in S:
  ans = "No"
  if jp + os < A + B:
    if s == "a":
      jp += 1
      ans = "Yes"
    if s == "b" and os < B:
      os += 1
      ans = "Yes"
  print(ans)

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

int main() {
    int N;
    int c=0;
    cin>>N;
    int a=N;
    while(N>0){
        c+=N%10;
        N=N/10;
    }
    if(a%c==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
int main(){
	char ch;
	int n[12];
	int v1,v2;
	while( cin>>n[0]>>ch>>n[1]>>ch>>n[2]>>ch>>n[3]>>ch>>n[4]>>ch>>n[5]>>ch>>n[6]>>ch>>n[7]>>ch>>n[8]>>ch>>n[9]>>ch>>v1>>ch>>v2 ){
		int l=0;
		rep(i,10){
			l+=n[i];
		}
		double val=v1/( (double)(v1+v2)/l );

		int now=0;
		int ans=10;
		rep(i,10){
			now+=n[i];
			if(now>=val){
				ans=i+1;
				break;
			}
		}

		cout<<ans<<endl;

	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

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

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

const double PI=3.141592653589793;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);

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

    int count=0;
    int current=0;
    int pre=0;

    while(current!=1){
        if(current==a[current]){
            cout << "-1" << endl;
            return 0;
        }
        pre=current;
        current=a[current];
        a[pre]=pre;
        count++;
    }

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

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

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
int ind[maxn], que[maxn], n, m;//ind数组要清空
vector<int> G[maxn];
void topsort()//还要特判自环
{
    int qt = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(ind[i] == 0) que[qt++] = i;
    }
    for(int i = 0; i < qt; ++i)
    {
        int u = que[i];
        for(int j = 0; j < G[u].size(); ++j)
        {
            if(--ind[G[u][j]] == 0) que[qt++] = G[u][j];
        }
    }
    return ;
}
int dp[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        ind[v]++;
        G[u].pb(v);
    }
    topsort();
    for(int i=0;i<n;i++)
    {
        int u=que[i];
       // dbg(u);
        for(int j=0;j<G[u].size();j++)
        {
            int to=G[u][j];
            dp[to]=max(dp[to],dp[u]+1);
           // dbg2(to,dp[to]);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
    printf("%d\n",ans);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> p(n);
	rep (i, n) cin >> p[i];
	int res = Inf;
	FOR (i, 1, 101) {
	  int tmp = 0;
	  rep (j, n) tmp += (i - p[j]) * (i - p[j]);
	  res = min(res, tmp);
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    long long ans = 0;
    for(int i = 0; i < n; i++)
    {
        ans += a[i] - 1;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var h = NextInt;
        var w = NextInt;
        Console.WriteLine(Min(Solve(h, w), Solve(w, h)));
    }

    static long Solve(long h, long w)
    {
        var min = w % 3 == 0 ? 0 : w >= 3 ? h : long.MaxValue;
        for (int i = 1; i < h; i++)
        {
            var pieces = new long[] { w * i, (h - i) * (w / 2), (h - i) * (w - w / 2) };
            min = Min(min, pieces.Max() - pieces.Min());
        }
        return min;
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


Measured memory_bytes: 17484
#include <stdio.h>



int main(void)
{
    int a,b,c,d;
    scanf("%d\t%d\t%d\t%d",&a,&b,&c,&d);
    if((c-a<=d&&c-a>=-d)||((c-b<=d&&c-b>=-d)&&(a-b<=d&&a-b>=-d)))
    {
        printf("Yes");
    }else{
        printf("No");
    }
    
    return 0;
    
}


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

int main() {
  #define int long long
  int a, b, n;
  cin >> a >> b >> n;
  int m = min(n, b - 1);
  int x = a * m / b;
  int y = m / b;
  cout << x - a * y << endl;
}

Measured memory_bytes: 3612
N , M , X  = map ( int  ,input().strip().split(" ") ) 

dic = {} ;
dic [ tuple ( [ 0 for x in range ( M ) ] ) ] = 0 ;
for c in range ( N ) :
	l1  = list ( map ( int  ,input().strip().split(" ") )  ) ;
	dic2 = {} ; 

	for t in dic :

		if t in dic2 :
			dic2[t] = min ( dic2[t] , dic[t] ) ;
		else :
			dic2[t] = dic[t] ;

		x2 = l1[0] + dic[t] ;
		l2 = list ( t ) ;
		for x in range ( M ) :
			l2[x] += l1[x+1] ;

		t2 = tuple( l2 ) ; 
		if t2 in dic2 :
			dic2[t2] = min ( dic2[t2] , x2 ) ;
		else :
			dic2[t2] = x2 ;
	dic = dic2 ;

L = [] ;
for t in dic :
	if any(map(lambda x :x<X , t ) ) : continue ;
	L.append  ( t ) ;
if len(L) ==0 : 
	print ( -1 ) ; 
else :
	print ( min (  map ( lambda x:dic[x] , L ) ) ) ;






Measured memory_bytes: 11476
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int N = 2e5+5;
int n,sum[30][50][100];//ten&five&two
double d;ll ans;
signed main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		int tens=0;
		ll x=0;bool ok=false;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='.')ok=true;
			else{
				tens-=ok;
				x=x*10+(s[i]-'0');
			}
		}
		int fives=0,twos=0;
		while(x%10==0)x/=10,tens++;
		while(x%5==0)x/=5,fives++;
		while(x%2==0)x/=2,twos++;
		
		for(int j=0;j<25;j++)
		{
			for(int k=0;k<40;k++)
			{
				if((ll)j-10+tens+min(twos,k)>=0)
				{
					ans+=sum[j][k][0];
				}
			}
			for(int k=0;k<70;k++)
			{
				if((ll)j-10+tens+min(fives,k)>=0)
				{
					ans+=sum[j][0][k];
				}
			}
			if((ll)j-10+tens>=0)ans-=sum[j][0][0];
		}
		sum[tens+10][fives][twos]++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3712
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    targets = LI()
    targets.sort()
    deque = cl.deque(targets)

    count = 1
    if N % 2 != 0:
        target = deque.popleft()
        if target != 0:
            print(0)
            return
        count = 2

    while len(deque) > 0:
        a = deque.popleft()
        b = deque.popleft()
        if a == b == count:
            count += 2
            continue
        else:
            print(0)
            return

    print(pow(2, (N//2), 10**9+7))


main()


Measured memory_bytes: 85192
N,W = map(int, raw_input().split())
vs,ws = [],[]
for i in range(N):
    v,w = map(int, raw_input().split())
    vs.append(v)
    ws.append(w)
V = sum(vs)

DP = [10**10]*(V+1)
DP[0] = 0

for v,w in zip(vs, ws):
    for i in reversed(range(v, V+1)):
        DP[i] = min(DP[i], DP[i-v] + w)

ans = max(v for v,w in enumerate(DP) if w <= W)
print ans



Measured memory_bytes: 5028
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<Integer> monsters = new ArrayList<>();
        List<Integer> temp =  new ArrayList<>();
        for (int x=1;x<=n+1;x++) {
            monsters.add(Integer.parseInt(sc.next()));
        }
        for (int x=1;x<=n;x++) {
            temp.add(Integer.parseInt(sc.next()));
        }
        long res = 0;
        int a = 0;
        int b = monsters.get(0);
        int c = 0;
        for (int x=2;x<=n+1;x++) {
            a = b;
            b = monsters.get(x-1);
            c = temp.get(x-2);
            if (a<c) {
                if (a+b<=c) {
                    res = res+a+b;
                    b=0;
                } else {
                    res +=c;
                    b = b+a-c;
                }
            } else {
                res+=c;
            }
            
        }
        System.out.println(res);
    }
        
}


Measured memory_bytes: 62188
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(ulong[]);
    ulong x;
    size_t i, j;
    long r;
    while (j < N) {
        while (i < N && x&AS[j]) {
            x ^= AS[i++];
        }
        r += j-i+1;
        x |= AS[j++];
    }
    writeln(r);
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int n, k;
  cin >> n >> k;
  int h[n], t[n+100];
  for(int& i : h)
    	cin >> i;
  for(int& i : t)
    	i = 1e9;
  t[0] = 0;
  for(int i = 0; i < n-1; i++)
  	for(int j = i+1; j <= i+k; j++)
      t[j] = min(t[j], t[i] + abs(h[j] - h[i]));
  cout << t[n-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,i,p=0,l,r,d;
    cin>>n;
    long long a[n+1];
    for(i=1;i<=n;i++){
        cin>>a[i];
        if(i%2==1&&a[i]%2==1)
        p++;
    }cout<<p<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main(int args, char *argc[]){
  int student,locations;
  //ifstream ifs("input.txt");
  while(cin>>student>>locations, student&&locations){
    int wishes[locations];

    for(int i=0;i<locations;i++)
      wishes[i]=0;//,printf("wishes[%d]:%d ",i,wishes[i]);printf("\n");
    int stu=student;
    while(stu--){
      int loc=locations;
      while(loc--){
        int tmp;cin>>tmp;
        wishes[locations-loc-1]+=tmp;
      }
    }

    /*for(int i=0;i<locations;i++)
      printf("wishes[%d]:%d ",i,wishes[i]);printf("\n");*/

    map<double,int> res;
    int loc=locations;
    while(loc--){
      res.insert(make_pair((double)wishes[loc]-(double)loc/100,loc));
    }

    for(map<double,int>::iterator iz=(--res.end());
    iz!=res.begin();iz--)
      //cout<<"("<<(iz->first)<<")",
      cout<<(iz->second)+1<<" ";
    cout<<(res.begin())->second+1<<"\n";
  }
  return 0;
}


Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    int n,m;
    cin >> n >> m;
    
    cout << (n-1)*(m-1) << endl;
    return 0;
}


Measured memory_bytes: 256