akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    ++n;
    vector<ll> A(n);
    rep(i, n)
    {
        cin >> A[i];
    }
    if (n == 1 && A[0] != 1)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> SUM(n);
    ll total = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        total += A[i];
        SUM[i] = total;
    }
    vector<ll> dp(n);
    dp[0] = 1;
    for (int i = 0; i < n - 1; i++)
    {
        dp[i + 1] = min((dp[i] - A[i]) * 2, SUM[i + 1]);
        if (dp[i + 1] < A[i + 1])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    // cout << "A:";
    // print(A);
    // cout << "S:";
    // print(SUM);
    // cout << "d:";
    // print(dp);
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += dp[i];
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 5632
import sys
input = lambda : sys.stdin.readline().rstrip()

n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1):
        if i + j > n:
            continue
        if 10000*i + 5000*j + 1000*(n - (i + j)) == y:
            print(i, j, n - (i + j))
            sys.exit()
print(-1, -1, -1)

Measured memory_bytes: 40812
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<tuple>
using namespace std;
int main() {
  int A,B,X;
  cin >> A >> B >> X;
  int ans = X-A;
  if (ans >= 0 && ans <= B) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    
    int n;
    cin >> n;
    int ans = n % 1000;
    if(ans == 0){
        cout << "0";
    }
    else{
        cout << 1000 - ans;
    }

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,m;
  cin >> n>>m;
  int h[n],d[n];
  for(int i = 0;i<n;i++) 
  {
      d[i]=1;
      cin >> h[i];
  }
  for(int i = 0;i<m;i++)
  {
      int a,b;
      cin >> a >> b;
      if(h[a-1] > h[b-1]) d[b-1] = 0;
      else if(h[a-1] < h[b-1]) d[a-1] = 0;
      else
      {
          d[b-1] = 0;
          d[a-1] = 0;
      }
  }
  int c = 0;
  for(int i = 0;i<n;i++) c+=d[i];
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 4372
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int a,b;
string s1,s2;
int main(){
	cin>>a>>b;
	for(int i=1;i<=a;i++)
		s1+=char(b+'0');
	for(int i=1;i<=b;i++)
		s2+=char(a+'0');
	if(s1.size()>s2.size())
		cout<<s1;
	else
		cout<<s2;
	return 0;
}

Measured memory_bytes: 256
a, b, h, m = gets.split.map(&:to_i)

s_arg = h * 30 + m * 0.5
l_arg = m * 6
arg = (s_arg - l_arg).abs

puts Math.sqrt(a**2 + b**2 - 2 * a * b * Math.cos(arg * Math::PI / 180.0))

Measured memory_bytes: 14752
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

int main() {
    
    int n; cin>>n;
    vector<int> ans((n+1),1);
    vector<bool> prime((n+1),true);
    
    for(int i = 2;i <= n;i++){
        
        if(prime[i] == true){ 
            for(int j = 2*i;j <= n;j += i){
                
                ll cnt = 0;
                ll temp = j;
                while(temp%i == 0){ cnt++; temp = temp/i;}
                
                ans[j] *= (cnt+1);
                prime[j] = false;
            }
            ans[i] = 2;
        }
        
    }
    
    ll fn = 0;
    for(int i = 1;i <= n;i++){
        fn += (ll)i*ans[i];
    }
    
    cout<<fn<<"\n";

    
}

Measured memory_bytes: 43660
#include<stdio.h>
int main()
{
	char ch,nextch;
	while (scanf("%c", &ch) != EOF)
	{
		nextch = ch;
		if ('a' <= ch && ch <= 'z')
		{
			nextch = ch - ('a' - 'A');

		}
		else if ('A' <= ch && ch <= 'Z')
		{
			nextch = ch + ('a' - 'A');
			

			
		}
		printf("%c", nextch);
	}
	return 0;
}


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

#define ll long long
#define ull unsigned long long 
#define endl '\n'

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans=0;
    for(int i=0; i<=n; ++i){
        int sum, x = i;
        for(sum=0; x>0; sum+=x%10, x/=10);

        if(sum <= b && sum>=a)
            ans += i;
    }
    cout << ans;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxS =1e5+7;


int main()
{
   ll k;
    cin>>k;
      ll sum =0;
      for(int i=1;i<=k;i++)
      {
        for(int j=1;j<=k;j++)
        {
          for(int l=1;l<=k;l++)
          {
            ll gcd = __gcd(i,j);
            ll gcd2 = __gcd(gcd,(ll)l);
            sum+=gcd2;
          }
        }
      }
  cout << sum << "\n";
  
  
  
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n;
        cout<<3*n*n;
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);

void solv()
{
    int a, b, c, k;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    while (!(a < b))
    {
        b *= 2;
        --k;
    }
    while (!(b < c))
    {
        c *= 2;
        --k;
    }
    if (k >= 0)
        printf("Yes\n");
    else
        printf("No\n");
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 3748
import sys
input = sys.stdin.readline


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0 for _ in range(n + 2)]
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n, q = map(int, input().split())
c = list(map(int, input().split()))

rli = []
for i in range(q):
    l, r = map(int, input().split())
    rli.append((r, l, i))
rli.sort(key=lambda x: x[0])

last = [-1 for _ in range(n + 1)]

bit = Bit(n)
ans = [-1 for _ in range(q)]
cur = 1
for r, l, i in rli:
    for j in range(cur, r + 1):
        if last[c[j - 1]] != -1:
            bit.add(last[c[j - 1]], -1)
        last[c[j - 1]] = j
        bit.add(j, 1)
    cur = r + 1
    ans[i] = bit.sum(r) - bit.sum(l - 1)
print(*ans, sep="\n")


Measured memory_bytes: 299640
//#include "pch.h"
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;


int main()
{
	int A, B;
	cin >> A>>B;

	int answer = 0;

	if (A >= B) {
		answer += A;
		A -= 1;
	}
	else {
		answer += B;
		B -= 1;
	}
	if (A >= B) {
		answer += A;
		A -= 1;
	}
	else {
		answer += B;
		B -= 1;
	}
	

	cout << answer<< endl;

}




Measured memory_bytes: 256
a=int(input())
Papers=list(map(int,input().split()))
m=0
for i in range (a):
  if Papers[i] %2==0:
    if not (Papers[i] %3==0 or Papers[i] %5==0):
      m=m+1

if not m==0:
  print("DENIED")
else:
  print("APPROVED")


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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string s;
    cin >> s;

    vector<int> nisi(N);
    nisi[0] = (s[0] == 'W') ? 1 : 0;
    for(int i=1; i<N; i++)
    {
        nisi[i] = nisi[i-1] + ((s[i] == 'W') ? 1 : 0);
    }
    // cout << "nisi; ";
    // for(auto ni : nisi) cout << ni << ' ';
    // cout << '\n';

    vector<int> higasi(N);
    higasi[N-1] = (s[N-1] == 'E') ? 1 : 0;
    for(int i=N-2; i>=0; i--)
    {
        higasi[i] = higasi[i+1] + ((s[i] == 'E') ? 1 : 0);
    }
    // cout << "higa; ";
    // for(auto hi : higasi) cout << hi << ' ';
    // cout << '\n';

    int ans = 1<<30;
    for(int i=0; i<N; i++)
    {
        int lo = 0;
        if(i > 0) lo += nisi[i-1];
        if(i < N-1) lo += higasi[i+1];
        chmin(ans, lo);
    }
    cout << ans << '\n';

    return 0;
}


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

using namespace std;

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

  long long ret;
  long long L[87];
  L[0]=2;
  L[1]=1;
  for(int i=2;i<=N;i++)
  {
    L[i]=L[i-1]+L[i-2];
  }
  ret=L[N];
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MOD ((ll) 1e9 + 7)

ll mypow(ll n, ll k) {
	if (k < 0) {
		return 0;
	}
	ll ret = 1;
	ll cur = n;
	while (k) {
		if (k & 1) {
			ret *= cur;
			ret %= MOD;
		}
		cur *= cur;
		cur %= MOD;
		k >>= 1;
	}
	return ret;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll t0, t1, t2;
	t0 = mypow(2, n);
	t1 = mypow(2, n - 1);
	t2 = mypow(2, n - 2);
	ll s = 0, sm = 0;
	for (int i = 0; i < n; i++) {
		s += a[i];
		sm += a[i] * i;
		s %= MOD;
		sm %= MOD;
	}
	ll r1 = s * ((t2 * (n - 1) + t1) % MOD); 
	ll r2 = t2 * sm;
	r1 %= MOD;
	r2 %= MOD;
	ll ret = (r1 + MOD - r2) % MOD;
	ret *= t0;
	ret %= MOD;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4844
m = int(input())
c = []
d = []
for i in range(m):
    D,C = map(int,input().split())
    c.append(C)
    d.append(D)

ans = 0
for i in range(m):
    ans += c[i]*d[i]

print((ans-1)//9 + sum(c)-1)

Measured memory_bytes: 12624
sList = sorted(list(set(list(input()))))
chI = ord('a')
for i in sList:
  if chI == ord(i):
    chI += 1
  else:
    print(chr(chI))
    exit(0)
if len(sList) != 26:
  print(chr(chI))
else:
  print("None")


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

void a_infinite_coins(void) {
	int n;
	int a;
	cin >> n >> a;
	int hasu = n % 500;
	if (a >= hasu) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

int main()
{
	a_infinite_coins();
    return 0;
}

Measured memory_bytes: 3592
n,k,s=[int(i) for i in input().split()]

for i in range(k):
    print(s,end="")
    print(' ',end="")

if(s!=10**9):
    for i in range(n-k):
        print(s+1,end="")
        print(' ',end="")
else:
    for i in range(n-k):
        print(1,end="")
        print(' ',end="")




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

using Field=vector<string>;
using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

int dh[]={-1,0,1,0};
int dw[]={0,1,0,-1};
char dic[]="NESW";
bool solve(int h,int w,int n){
    vector<int> com(n);
    {
        string buf;
        cin>>buf;
        int now=0;
        for(int i=0;i<n;i++){
            if(buf[i]=='L') now=(now+4-1)%4;
            else now=(now+1)%4;
            com[i]=now;
        }
    }
    Field f(h+2,"");
    for(int i=0;i<h;i++) cin>>f[i+1];
    for(int i=0;i<h;i++){
        string tmp="#"+f[i+1]+"#";
        f[i+1]=tmp;
    }
    for(int i=0;i<w+2;i++){
        f[0]+="#";
        f[h+1]+="#";
    }
    h+=2,w+=2;

    vvvi dp(h,vvi(w,vi(4,n+1)));
    using Item=pair<int,tuple<int,int,int>>;
    priority_queue<Item,vector<Item>,greater<>> que;
    int gh,gw;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(f[i][j]=='S'){
                dp[i][j][0]=0;
                que.push({0,make_tuple(i,j,0)});
            }
            if(f[i][j]=='G'){
                gh=i,gw=j;
            }
        }
    }
    
    auto push=[&](int i,int j,int iter,int d){
        if(d<dp[i][j][iter]){
            dp[i][j][iter]=d;
            que.push({d,make_tuple(i,j,iter)});
        }
    };
    
    vvi compos(n+1,vector<int>(4,n));
    for(int i=n-1;i>=0;i--){
        compos[i]=compos[i+1];
        compos[i][com[i]]=i;
    }
    while(!que.empty()){
        int d;
        tuple<int,int,int> tmp;
        auto tmptmp=que.top(); que.pop();
        d=tmptmp.first,tmp=tmptmp.second;
        int i,j,iter;
        tie(i,j,iter)=tmp;
        if(dp[i][j][iter]<d) continue;
        for(int dir=0;dir<4;dir++){
            if(compos[d][dir]<n){
                int toh=i+dh[dir],tow=j+dw[dir];
                if(f[toh][tow]!='#'){
                    push(toh,tow,dir,compos[d][dir]+1);
                }
            }
        }
        int toh=i+dh[iter],tow=j+dw[iter];
        if(f[toh][tow]!='#') push(toh,tow,iter,d);
    }
    return *min_element(dp[gh][gw].begin(),dp[gh][gw].end())<=n;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,n;
    while(cin>>h>>w>>n,h){
        cout<<(solve(h,w,n) ? "Yes" : "No")<<"\n";
    }
    
    return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  int a[101];
  int n;

  ci>>n;

  double ave = 0;
  rep(i, n) {
    ci>>a[i];
    ave += a[i];
  }
  ave /= (double)n;

  double sa = 1000;

  int ans = 0;
  for(int i = n - 1; i >= 0; i--) {
    if(sa >= abs(ave - (double)a[i])) {
      ans = i;
      sa = abs(ave - (double)a[i]);
    }
  }

  co << ans << en;
  
  return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().strip().split())

# s :  1000円札の枚数
# g :  5000円札の枚数
# i : 10000円札の枚数

ans = '-1 -1 -1'
flag = 0

for s in range(N + 1):
    if flag == 1:
        break

    for g in range(N + 1 - s):
        i = N - s - g
        money = 1000 * s + 5000 * g + 10000 * i
        if money == Y:
            ans = str(i) + " " + str(g) + " " + str(s)
            flag = 1
            break


print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

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

	ll X;
	cin >> X;
	ll i = 0;
	ll cnt = 0;
	while (1) {
		cnt += i;
		if (cnt >= X) {
			break;
		}
		i++;
	}

	cout << i << endl;

	return 0;
}



Measured memory_bytes: 256
def gcd(a, b):
    while True:
        r = a % b
        if r == 0:
            return b
        else:
            a = b
            b = r


n = int(input())
integers = sorted([int(x) for x in input().split()])
min_gcd = integers[n-1]
for i in range(n):
    for j in range(i):
        a = integers[i]
        b = integers[j]
        min_gcd = min(gcd(a, b), min_gcd)


for i in range(1, min_gcd+1):
    if sum([x % i for x in integers]) == 0:
        print(i)



Measured memory_bytes: 5604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    bool same = true;
    map<int,int> num;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        if (i > 0){
            if (a[i] != a[i-1]){
                same = false;
            }
        }
    }

    if (same){
        cout << 0 << endl;
        return 0;
    }

    ll ans = INF;
    for(int i = 0;i <= 100;i++){
        ll sum = 0;
        for (int j = 0;j < n;j++){
            sum += pow(a[j] - i,2);
        }
        ans = min(ans,sum);
    } 

    
    for(int i = 0;i <= 100;i++){
        ll sum = 0;
        for (int j = 0;j < n;j++){
            sum += pow(a[j] - (0 - i),2);
        }
        ans = min(ans,sum);
    } 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// A-Frog2.cpp
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	// freopen("input.txt","r",stdin);
	ll n,k;
	cin>>n>>k;
	ll *arr=new ll[n];
	for(ll i=0;i<n;i++)cin>>arr[i];

	ll*dp=new ll[n+1]{};
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(ll i=2;i<n;i++){
		ll best=INT_MAX;
		for(ll j=1;j<=k;j++){
			if(j<=i)best=min(best,dp[i-j]+abs(arr[i-j]-arr[i]));
		}
		dp[i]=best;
	}
	// for(ll i=0;i<n;i++)cout<<dp[i]<<" ";
	cout<<dp[n-1]<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

ll N,M;
ll A[10001];

int main(){
    cin >> N >> M;
    for(int i=0;i<M;i++) cin >> A[i];
    ll sum = 0;
    for(int i=0;i<M;i++) sum += A[i];
    if(sum > N) cout << -1 << endl;
    else cout << N-sum << endl;
    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 1010
#define maxm 100010
#define inf 9999999999999999
#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[20];
ll solve(int l,int r,int x,int y)
{
    if(r-l<=1)  return 0;
    ll res=inf;
    for(int i=l+1;i<=r-1;i++)
    {
        res=min(res,1ll*(x+y)*a[i]+solve(l,i,x,x+y)+solve(i,r,x+y,y));
    }
    return res;
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    printf("%lld\n",solve(1,n,1,1)+a[1]+a[n]);
    return 0;
}

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

long long pow2(long long x, long long n, int mod=0) {
  if (n == 0) return 1;
  if (mod) {
    if (n & 1) return x * pow2(x, n - 1, mod) % mod;
    long long y = pow2(x, n / 2, mod);
    return y * y % mod;
  } else {
    if (n & 1) return x * pow2(x, n - 1);
    long long y = pow2(x, n / 2);
    return y * y;
  }
}

int MOD = 1e9 + 7;
int U = 1e6;
vector<unsigned long long> fac(U + 1);
vector<unsigned long long> ifac(U + 1);
vector<unsigned long long> n_choose(U + 1);
void make_tables(int n=1e9, int p=MOD) {
  fac[0] = 1;
  for (int i = 0; i < U; i++) fac[i+1] = fac[i] * (i + 1) % p;
  ifac[U] = pow2(fac[U], p - 2, p);
  for (int i = U; i > 0; i--) ifac[i-1] = ifac[i] * i % p;
  n_choose[0] = 1;
  for (int i = 0; i < U; i++) n_choose[i+1] = n_choose[i] * (n - i) % p;
  for (int i = 0; i < U + 1; i++) n_choose[i] = n_choose[i] * ifac[i] % p;
}

int mod_choose(int n, int r, int p=MOD) {
  if (r > n || r < 0) return 0;
  return fac[n] * ifac[r] % p * ifac[n-r] % p;
}

bitset<1001001001> is_prime(0);
vector<int> prime_numbers;
void sieve_of_eratosthenes(int n=1e6) {
  for (int i = 2; i < n + 1; i++) {is_prime.set(i);}
  for (int i = 2; i < (int)sqrt(n) + 1; i++) {
    if (is_prime[i]) for (int j = i * 2; j < n + 1; j += i) is_prime.reset(j);
  }
  for (int i = 2; i < n + 1; i++) if (is_prime[i]) prime_numbers.push_back(i);
}

unordered_map<int, int> prime_factorize(int n) {
  unordered_map<int, int> res;
  if (n < 2) return res;
  int border = int(sqrt(n));
  for (int &p : prime_numbers) {
    if (p > border) break;
    if (n % p == 0) {
      res[p] = 1; n /= p;
      while (n % p == 0) {res[p]++; n /= p;}
    }
    if (n == 1) return res;
  }
  res[n] = 1; return res;
}

unordered_map<int, int> prime_factorize_factorial(int n) {
  unordered_map<int, int> res;
  for (int i = 1; i < n + 1; i++) {
    for (auto &pc : prime_factorize(i)) {
      if (res.find(pc.first) == res.end()) res[pc.first] = pc.second;
      else res[pc.first] += pc.second;
    }
  }
  return res;
}

long long nHr(int n, int r) {
  return mod_choose(n-1+r, r);
}

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

  int n, m; cin >> n >> m;
  long long res = 1;
  for (auto p: prime_factorize(m)) {
    res *= nHr(n, p.second);
    res %= MOD;
  }
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 24444
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  long long X; cin>>X;
  long long yokin=100;
  long long ans=0;
  while(yokin<X){
    ans++;
    yokin*=1.01;
  }
  cout<<ans<<endl;
}

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

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

    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll count_1 = 0;
    ll sum = 0;
    rep(i, n){
        sum += a[i];

        if(sum == 0){
            count_1++;
            if(i % 2 == 0){
                sum = 1;
            }else{
                sum = -1;
            }
        }else if(sum != abs(sum) && i % 2 == 0){
            count_1 += 1 - sum;
            sum = 1;
        }else if(sum == abs(sum) && i % 2 == 1){
            count_1 += sum + 1;
            sum = -1;
        }
    }

    ll count_2 = 0;
    sum = 0;
    rep(i, n){
        sum += a[i];

        if(sum == 0){
            count_2++;
            if(i % 2 == 0){
                sum = -1;
            }else{
                sum = 1;
            }
        }else if(sum == abs(sum) && i % 2 == 0){
            count_2 += sum + 1;
            sum = -1;
        }else if(sum != abs(sum) && i % 2 == 1){
            count_2 += 1 - sum;
            sum = 1;
        }
    }

    cout << min(count_1, count_2) << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
A = [int(input()) for _ in range(n)]
A_copy = A[:]

A_max = max(A_copy)
A_copy.remove(A_max)
A_next = max(A_copy)
for i in A:
    if i == A_max:
        print(A_next)
    else:
        print(A_max)

Measured memory_bytes: 14060
#include<iostream>
using namespace std;
int main(void){
	long long x;
	cin>>x;
	long long div,mod;
	div = x / 11;
	mod = x % 11;
	long long tmp = div*2;
	if(mod == 0)cout<<tmp<<endl;
	else if(mod <= 6)cout<<(long long)(tmp+1)<<endl;
	else cout<<(long long)(tmp+2)<<endl;
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pip(k,l,n) for(int k =(int)l;k<=(int)n;k++)
int main() {
  int I,J;
  string A[I] ={};
  cin >> I >> J;
  int i,j,k,l;
  
  // ここにプログラムを追加
  rep(i,I){
    cin >> A[i];
    rep(j,J){
      if(A[i][j] == '.') A[i][j] = '0';
    }
  }
  
  rep(i,I){
    rep(j,J){
      if(A[i][j] == '#'){
        pip(k,-1,1){
          if((i+k < 0) || (i+k >= I)) continue;
          pip(l,-1,1){
            if((j+l < 0) || (j+l >= J)) continue;
            if(A[i+k][j+l] == '#') continue;
            int count = (int)A[i+k][j+l];
            A[i+k][j+l] = char(count+1);
            //cout << A[i+k][j+l];
          }
        }
      }
    }
  }
  
  rep(i,I) cout << A[i] << endl;
}


Measured memory_bytes: 49408
import math

def solve(n,s):
    m = sum(s)/n
    ans = 0
    for i in s:
        ans += (i-m)**2
    ans /= n
    print(math.sqrt(ans))

if __name__ == "__main__":
    while 1:
        n = int(input())
        if n == 0:
            break
        s = list(map(int,input().split()))
        solve(n,s)


Measured memory_bytes: 5700
import java.util.*;
public class Main {	
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new AOJ0036();
	}
	
	class AOJ0015{
		public AOJ0015() {
			Scanner in = new Scanner(System.in);
			int n = in.nextInt();
			for(int s=0;s<n;s++){
				String a = in.next(),c="";
				String b = in.next(),d="";
				for(int i=a.length()-1;i>=0;i--)c+=a.charAt(i);
				for(int i=b.length()-1;i>=0;i--)d+=b.charAt(i);
				String result = "";
				int save = 0;//余った数字
				for(int i=0;i<Math.max(a.length(), b.length());i++){
					if(c.length()>i&&d.length()>i){
						int num1=Integer.parseInt(c.charAt(i)+"");
						int num2=Integer.parseInt(d.charAt(i)+"");
						int sum = num1+num2;
						if(i!=0)sum+=save;
						save=0;
						if(sum>9){
							save = 1;
							sum-=10;
						}
						result+=Integer.toString(sum);
					}else if(c.length()>i&&d.length()<=i){
						int sum=Integer.parseInt(c.charAt(i)+"");
						if(i!=0)sum+=save;
						save=0;
						if(sum>9){
							save = 1;
							sum-=10;
						}
						result+=Integer.toString(sum);
					}else if(d.length()>i&&c.length()<=i){
						int sum=Integer.parseInt(d.charAt(i)+"");
						if(i!=0)sum+=save;
						save=0;
						if(sum>9){
							save = 1;
							sum-=10;
						}
						result+=Integer.toString(sum);
					}
				}
				if(save==1)result+="1";
				if(result.length()>80)System.out.println("overflow");
				else{
					for(int k=result.length()-1;k>=0;k--)System.out.print(result.charAt(k));
					System.out.println();
				}
			}
		}
	}
	
	class AOJ0036{
		char doIt(int y,int x){
			if(hyou[y+1][x] && hyou[y][x+1] && hyou[y+1][x+1] ){
				return 'A';
			}else if( hyou[y+1][x] && hyou[y+2][x] && hyou[y+3][x] ){
				return 'B';
			}else if( hyou[y][x+1] && hyou[y][x+2] && hyou[y][x+3] ){
				return 'C';
			}else if( hyou[y][x+1] && hyou[y+1][x+1] && hyou[y+1][x+2] ){
				return 'E';
			}else if( hyou[y+1][x] && hyou[y+1][x+1] && hyou[y+2][x+1] ){
				return 'F';
			}else if( hyou[y][x+1] && hyou[y+1][x] && hyou[y+1][x-1] ){
				return 'G';
			}else if( hyou[y+2][x-1] && hyou[y+1][x] && hyou[y+1][x-1] ){
				return 'D';
			}
			return ' ';
		}
		boolean[][] hyou = new boolean[10][10];
		public AOJ0036() {
			Scanner in = new Scanner(System.in);
			while(in.hasNext()){
				for(int s=0;s<8;s++){
					String a = in.next();
					for(int i=0;i<a.length();i++)hyou[s][i]=a.charAt(i)=='1'? true:false;
				}
				for(int s=0;s<8;s++){
					boolean a=false;
					for(int i=0;i<8;i++)
						if(hyou[s][i]){
							System.out.println(doIt(s, i));
							a = true;
							break;
						}
					if(a)break;
				}
			}
		}
	}
	
	class AOJ0034{
		int[] kyori = new int[11];
		int speed1,speed2;
		public AOJ0034() {
			Scanner in = new Scanner(System.in);
			while(in.hasNext()){
				String input[] = in.next().split(",");
				int sum=0;
				for(int i=1;i<=10;i++){
					kyori[i] = Integer.parseInt(input[i-1]);
					sum+=kyori[i];
				}
				speed1 = Integer.parseInt(input[10]);
				speed2 = Integer.parseInt(input[11]);
//				double one,two;
//				for(int s=1;s<=10;s++){//終点駅まで
//					
//				}
				
				
				
			}
			
			
			
			
		}
		
		
	}
}

Measured memory_bytes: 18212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (n+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int dp[3001][3001], op[3001][3001];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i-1] == t[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
				op[i][j] = 0;
			}
			else if (dp[i-1][j] >= dp[i][j-1]) {
				dp[i][j] = dp[i-1][j];
				op[i][j] = -1;
			}
			else {
				dp[i][j] = dp[i][j-1];
				op[i][j] = 1;
			}
		}
	}
	//printf("%d\n", dp[n][m]);
	string ans;
	while (n > 0 && m > 0) {
		if (op[n][m] == 0) {
			ans.push_back(s[n-1]);
			--n, --m;
		}
		else if (op[n][m] < 0)
			--n;
		else
			--m;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}


Measured memory_bytes: 70656
#include <iostream>

using namespace std;

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

    int cnt[M];
    fill(cnt, cnt + M, 0);
    for (int i = 0; i < N; ++i) {
        int K;
        cin >> K;
        for (int j = 0; j < K; ++j) {
            int a;
            cin >> a;
            ++cnt[--a];
        }
    }

    int ans = 0;
    for (int i = 0; i < M; ++i) ans += cnt[i] / N;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define ll long long
#define int long long
using namespace std;
const ll mod=1e9+7;
const int maxn=2001;
int m,n;
int c[maxn][maxn];
signed main() {
	int n,k;
	scanf("%lld %lld",&n,&k);
	c[0][0]=c[1][0]=c[1][1]=1;
	for(int i=2;i<maxn;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for(int i=1;i<=k;i++){
		printf("%lld\n",(1LL)*c[n-k+1][i]*c[k-1][i-1]%mod);
	}
	return 0;
}

Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
int table[1000010];
int main(){
    int s;
    cin >> s;
    int a1 = s;
    table[a1]++;
    int cnt = 1;
    while(table[a1]<=1){
        int f;
        if(a1%2==0)f = a1/2;
        else f = 3*a1+1;
        a1 = f;
        table[a1]++;
        cnt++;
    }   
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <map>


int main() {
	long long a;

	std::cin >> a;

	for (size_t i = 0; i < 50000; i++)
	{
		if ((int)(i * 1.08) == a) {
			std::cout << i << std::endl;
				return 0;
		}
	}

	std::cout << ":(" << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

void cmax(int &lhs,int rhs){
    lhs=max(lhs,rhs);
}

int main(){
    int n;
    cin>>n;
    
    vector<pair<int,int>> rb(n);
    for(int i=0;i<n;i++){
        int x,l;
        cin>>x>>l;
        rb[i].first=x-l;
        rb[i].second=x+l;
    }
    sort(rb.begin(),rb.end());

    vector<int> dp(n+1);

    for(int i=0;i<n;i++){
        int lb=i;
        int ub=n;
        while(ub-lb>1){
            int mid=(lb+ub)/2;
            if(rb[i].second<=rb[mid].first) ub=mid;
            else lb=mid;
        }
        cmax(dp[ub],dp[i]+1);
        cmax(dp[i+1],dp[i]);
    }

    cout<<dp[n]<<endl;
    
        
    return 0;
}


Measured memory_bytes: 1408
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let k = get!();
    
    if n % k == 0 {
    	println!("0");
    } else {
    	println!("1");
    }
    
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

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

    // solution comes here
    ll N, A[100100], B[100100];
    cin >> N ;
    rep(i, N) cin >> A[i] >> B[i];

    ll ans=0;
    for(int i=N-1; i>=0; i--) {
        if((A[i]+ans) % B[i]) ans += B[i] - (A[i]+ans)%B[i];
    }

    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main()
{
    LL L,R;
    cin>>L>>R;
    if(R-L>=2019){
        cout<<"0"<<endl;
    }else{
        LL mi=INT64_MAX;
        for(LL i=L;i<=R-1;i++){
            for(LL j=L+1;j<=R;j++){
                LL tmp=((i%2019)*(j%2019))%2019;
                mi=min(tmp,mi);
            }
        }
        cout<<mi<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int N;
int M;
map<string, int> S;
map<string, int> T;

signed main()
{
	cin >> N;
	REP(i, N)
	{
		string s;
		cin >> s;
		if (CONTAINS_MAP(S, s))
		{
			S[s]++;
		}
		else
		{
			S[s] = 1;
		}
	}
	cin >> M;
	REP(i, M)
	{
		string s;
		cin >> s;
		if (CONTAINS_MAP(T, s))
		{
			T[s]++;
		}
		else
		{
			T[s] = 1;
		}
	}

	int ma = 0;
	for (auto pair : S)
	{
		int n = pair.second;
		if (CONTAINS_MAP(T, pair.first))
		{
			n -= T[pair.first];
		}
		ma = max(ma, n);
	}
	cout << ma << endl;
}



Measured memory_bytes: 3144
n = int(input())
a = list(map(int,input().split()))
s = [0]*(n+1)
y = 1
p = 0
for i in range(n+1):
    if(y-a[i] > 0):
        s[i] = y
        y -= a[i]
        y *= 2
    else:
        if(i != n):
            p = -1
            break
        elif(y == a[i]):
            s[i] = y
        else:
            p = -1
            break
if(p == -1):
    print(-1)
elif(n == 0):
    if(a[0] == 1):
        print(1)
    else:
        print(-1)
else:
    q = 0
    for i in range(n+1):
        q += a[-1-i]
        if(q <= s[-1-i]):
            p += q
        else:
            p += s[-1-i]
    print(p)

Measured memory_bytes: 700644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

int ch[128];
int chr[128];

int main() {
    int n;
    cin >> n;
    for (char a = 'a'; a <= 'z'; a++) ch[a] = 1e9;
    REP(i,n) {
        for (char a = 'a'; a <= 'z'; a++) chr[a] = 0;
        string s;
        cin >> s;
        REP(j,s.size()) {
            chr[s[j]]++;
        }
        for (char a = 'a'; a <= 'z'; a++) {
            ch[a] = min(ch[a], chr[a]);
        }
    }
    for (char a = 'a'; a <= 'z'; a++) {
        if (ch[a]) {
            REP(j,ch[a]) {
                cout << a;
            }
        }
    }
    cout << endl;
}



Measured memory_bytes: 256
/*
*AOJ0009: Prime Number
**問題
[http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp:title]
**解法
エラトステネスのふるい。
*/
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
const int N = 1000000;

int main() {
  // エラトステネスのふるいを作成
  bool isPrime[N]; // ふるい
  int cntPrime[N]; // n個以下の素数の個数
  for (int i = 0; i < N; i++)
    isPrime[i] = true;
  isPrime[0] = false; isPrime[1] = false;
  cntPrime[0] = 0;
  for (int i = 1; i < N; i++) {
    if (isPrime[i]) {
      cntPrime[i] = cntPrime[i-1] + 1;
      for (int j = 2 * i; j < N; j += i)
        isPrime[j] = false;
    } else {
      cntPrime[i] = cntPrime[i - 1];
    }
  }

  // 入力と出力
  int n;
  while (cin >> n) {
    cout << cntPrime[n] << endl;
  }

}

Measured memory_bytes: 6044
let get_wday m d =
  let days_of_month = [|31;29;31;30;31;30;31;31;30;31;30;31|] in
  let days_of_month_total =
    if m = 0 then 0
    else Array.fold_left (+) 0 (Array.sub days_of_month 0 m) in
  let days_of_year = days_of_month_total + d in
  (days_of_year+3) mod 7;;

let () =
  let print_wday w =
    let wday =
      match w with
        0 -> "Sunday"
      | 1 -> "Monday"
      | 2 -> "Tuesday"
      | 3 -> "Wednesday"
      | 4 -> "Thursday"
      | 5 -> "Friday"
      | 6 -> "Saturday"
      | _ -> "Whatever"
    in print_endline wday
  in
  let rec read () =
    let a = read_line () |> Str.split (Str.regexp " ")
            |> List.map int_of_string |> Array.of_list
    in
    if (a.(0),a.(1)) = (0,0) then ()
    else begin
        print_wday (get_wday (a.(0)-1) a.(1));read ()
      end
  in read ()
;;

Measured memory_bytes: 2056
#include<iostream>
using namespace std;
int main()
{
	int A,B,C;
	cin>>A>>B>>C;
	if(A==B&&B!=C)
		cout<<"Yes";
	else if(A==C&&B!=A)
		cout<<"Yes";
	else if(B==C&&A!=B)
		cout<<"Yes";
	else
		cout<<"No";	
	return 0; 
} 

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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<ll> asum(n + 1), bsum(m + 1);
	asum[0] = 0;
	bsum[0] = 0;
	rep(i,n) {
		int a;
		cin >> a;
		asum[i + 1] = asum[i] + a;
	}
	rep(i,m) {
		int b;
		cin >> b;
		bsum[i + 1] = bsum[i] + b;
	}

	int ans = 0, j = m;
	rep(i,n + 1) {
		if (asum[i] > k) break;
		while (asum[i] + bsum[j] > k ) {
			j--;
		}
		ans = max(ans, i + j);
	}
 	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6440
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"Yes"<<endl;
}

void no(){
    cout<<"No"<<endl;
}

ll dp[2010];
void solve(){
    ll n,x,y;
    cin>>n>>x>>y;
    
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(x>=i&&x<=j&&y>=i&&y<=j){
                dp[j-i-abs(x-y)+1]++;
            }else{
                if(x>=i&&x<=j){
                    if(y-j+1<j-x){
                        dp[x-i+1+y-j]++;
                    }else{
                        dp[j-i]++;
                    }
                }else if(y>=i&&y<=j){
                    if(i-x+1+j-y<j-i){
                        dp[i-x+1+j-y]++;
                    }else{
                        dp[j-i]++;
                    }
                }else if(i>x && j<y){
                    if(i-x+1+y-j<j-i){
                        dp[i-x+1+y-j]++;
                    }else{
                        dp[j-i]++;
                    }
                }else{
                    dp[j-i]++;
                }
            }
        }
    }
    for(int i=1;i<n;i++){
        cout<<dp[i]<<endl;
    }
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


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

template<class T> inline T gcd(T a, T b) {
    if (b == 0) return a;
    return  gcd(b, a % b);
}

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

    ll n, x;
    cin >> n >> x;

    cout << 3 * (n - gcd(n, x)) << '\n';
    return 0;
}


Measured memory_bytes: 256
// Tsuta_J さんのコードを参考
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

using Complex = complex<double>;
vector<Complex> dft(vector<Complex> A, int N, int sgn = 1) {
    if(N == 1) return A;

    vector<Complex> F(N / 2), G(N / 2);
    for(int i = 0; i < N / 2; i++) {
        F[i] = A[2 * i + 0];
        G[i] = A[2 * i + 1];
    }

    F = dft(F, N / 2, sgn);
    G = dft(G, N / 2, sgn);

    Complex zeta(cos(2.0 * M_PI / N), sin(2.0 * M_PI / N) * sgn);
    Complex pow_zeta = 1;

    for(int i = 0; i < N; i++) {
        A[i] = F[i % (N / 2)] + pow_zeta * G[i % (N / 2)];
        pow_zeta *= zeta;
    }
    return A;
}

vector<Complex> inv_dft(vector<Complex> A, int N) {
    A = dft(A, N, -1);
    for(int i = 0; i < N; i++) {
        A[i] /= N;
    }
    return A;
}

vector<Complex> multiply(vector<Complex> A, vector<Complex> B) {
    int sz = A.size() + B.size() + 1;
    int N = 1;
    while(N < sz)
        N *= 2;

    A.resize(N), B.resize(N);
    A = dft(A, N);
    B = dft(B, N);

    vector<Complex> F(N);
    for(int i = 0; i < N; i++) {
        F[i] = A[i] * B[i];
    }
    return inv_dft(F, N);
}

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<Complex> A(100001,Complex(0)), B(100001,Complex(0));
    A[0] = B[0] = Complex(0);
    for(i = 1; i <= n; i++) {
        ll a;
        cin >> a;
        A[a] = A[a] + Complex(1);
        B[a] = B[a] + Complex(1);
    }
    ll ret = 0;
    vector<Complex> ans = multiply(A, B);
    ll cnt = 0;
    for(i = 200000; i >= 0; i--) {
        ret += (ll)(ans[i].real() + 0.1)*i;
        cnt += (ll)(ans[i].real() + 0.1);
        if(m<cnt){
            ret -= (cnt-m)*i;
            break;
        }
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 38196
using System;

namespace abc150A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            if (A * 500 >= B)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
local n = io.read("*n")
local a1, a2, a3 = 0, 0, 0
for i = 1, n do
  local a = io.read("*n")
  if a == 1 then a1 = a1 + 1
  elseif a == 2 then a2 = a2 + 1
  else a3 = a3 + 1
  end
end
local t = {}
local p = {}
for i = 1, n + 1 do
  local r0 = i - 1
  t[i] = {}
  p[i] = {}
  for j = 1, n + 2 - i do
    local r1 = j - 1
    t[i][j] = {}
    p[i][j] = {}
    for k = 1, n + 3 - i - j do
      local r2 = k - 1
      local r3 = n - r0 - r1 - r2
      t[i][j][k] = 0
      p[i][j][k] = 0
      if r0 == 0 and r1 == a1 and r2 == a2 then
        p[i][j][k] = 1
      elseif 3 < i + j + k then
        local p1, t1 = 0, 0
        if 1 < i then
          p1 = p[i - 1][j + 1][k] * (r1 + 1) / (r1 + 1 + r2 + r3)
          t1 = t[i - 1][j + 1][k] + n / (n - (r0 - 1))
        end
        local p2, t2 = 0, 0
        if 1 < j then
          p2 = p[i][j - 1][k + 1] * (r2 + 1) / (r1 + r2 + r3)
          t2 = t[i][j - 1][k + 1] + n / (n - r0)
        end
        local p3, t3 = 0, 0
        if 1 < k then
          p3 = p[i][j][k - 1] * (r3 + 1) / (r1 + r2 + r3)
          t3 = t[i][j][k - 1] + n / (n - r0)
        end
        p[i][j][k] = p1 + p2 + p3
        if 0 < p[i][j][k] then
          t[i][j][k] = (p1*t1 + p2*t2 + p3*t3) / (p1 + p2 + p3)
        end
      end
    end
  end
end

print(t[n + 1][1][1])


Measured memory_bytes: 108416