akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin>>n;
	int ans = 0;
	if(1<=n&&n<10) {
		ans = n;
	}
	if(10<=n&&n<100) {
		ans = 9;
	}
	if(100<=n&&n<1000) {
		ans = n - 90;
	}
	if(1000<=n&&n<10000) {
		ans = 999 - 90;
	}
	if(10000<=n&&n<100000) {
		ans = n - 90 - 9000;
	}
	if(100000<=n) {
		ans = 99999 - 90 - 9000;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, j, u, n, v, k, matrix[101][101] = {0};

  /* 各頂点uの隣接リストを読込み、隣接行列を作成 */
  scanf("%d", &n);
  for( i = 0; i<n; i++ )
    {
      scanf("%d%d", &u, &k);
      for( j = 0; j<k; j++ )
	{
	  scanf("%d", &v);
	  matrix[u][v] = 1;
	}
    }

  for( i = 1; i<=n; i++ )
    {
      for( j = 1; j<=n; j++ )
	{
	  printf("%d", matrix[i][j]);
	  if( j != n )
	    printf(" ");
      
	}
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2088
/*
 * @Autor: valk
 * @Date: 2020-07-17 16:50:40
 * @LastEditTime: 2020-09-19 17:27:22
 * @Description: 如果邪恶  是华丽残酷的乐章 它的终场 我会亲手写上 晨曦的光 风干最后一行忧伤 黑色的墨 染上安详
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int seed = 12289;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int arr[N], brr[N];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &brr[n - i + 1]);
    }
    int pos = 1, flag = 1;
    for (int i = 1; i <= n; i++) {
        if (arr[i] == brr[i]) {
            while (pos <= n && (arr[i] == brr[pos] || arr[i] == arr[pos])) {
                pos++;
            }
            if (pos > n) {
                flag = 0;
                break;
            }
            swap(brr[pos], brr[i]);
        }
    }
    if (!flag) {
        printf("No\n");
    } else {
        printf("Yes\n");
        for (int i = 1; i <= n; i++) {
            printf("%d ", brr[i]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 4796
#include<stdio.h>

int linearSearch(int);

int s[10001], t[500], n;

int main()
{
  int q, i, count=0;

  scanf("%d",&n);
  for( i=0 ; i<n ; i++ )
    scanf("%d",&s[i]);
  scanf("%d",&q);
  for( i=0 ; i<q ; i++ )
    scanf("%d",&t[i]);

  for( i=0 ; i<q ; i++ )
    if(linearSearch(t[i])>=0) count++;
  printf("%d\n",count);

  return 0;
}

int linearSearch(int key)
{
  int i=0;
  s[n]=key;
  while(s[i]!=key){
    i++;
    if(i==n) return -1;
  }
  return i;
}

Measured memory_bytes: 640
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
using namespace std;

int h,w;
char G[55][55];
int vis[55][55];
int dxy[8][2]={1,0,1,1,0,1,-1,1,-1,0,-1,-1,0,-1,1,-1};

int main()
{
    while(cin>>h>>w)
    {
        for(int i=0;i<h;i++)
        {
            scanf("%s",G[i]);
        }
        /*for(int i=0;i<h;i++)
        {
            printf("%s\n",G[i]);
        }*/
        memset(vis,-1,sizeof(vis));
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(G[i][j]=='.')
                {
                    vis[i][j]=0;
                    for(int k=0;k<8;k++)
                    {
                        if(i+dxy[k][0]>=0&&i+dxy[k][0]<h&&j+dxy[k][1]>=0&&j+dxy[k][1]<w)
                        {
                            if(G[i+dxy[k][0]][j+dxy[k][1]]=='#')
                            {
                                vis[i][j]++;
                            }
                        }
                    }
                }
            }
        }
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(vis[i][j]==-1)
                    printf("%c",G[i][j]);
                else
                    printf("%d",vis[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int popcnt(int x)
{
    int ret = 0;
    while (x != 0)
    {
        ret += x & 1;
        x >>= 1;
    }
    return ret;
}

VL pp(2 * 101010, 0);
VL pm(2 * 101010, 0);

int calc(string &s, int c, int x, int ind)
{
    // cerr << "*" << s << " " << ind << " " << c << endl;
    if (c == 0)
        return 0;

    int cur = 1;
    if (s[ind] == '1')
    {
        x += pp[s.size() - 1 - ind];
        x %= c;
    }
    else
    {
        x += c - pm[s.size() - 1 - ind];
        x %= c;
    }

    int ret = 0; //cerr << x << endl;
    ret++;
    while (x != 0)
    {
        //   cerr << "*" << x << endl;
        c = popcnt(x);
        x %= c;
        ret++;
    }
    return ret;
}

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int c = 0;
    rep(i, n)
    {
        if (s[i] == '1')
            c++;
    }
    pm[0] = 1;
    if (c > 1)
        rep(i, n)
        {
            pm[i + 1] = pm[i] * 2;
            pm[i + 1] %= c - 1;
        }
    pp[0] = 1;
    rep(i, n)
    {
        pp[i + 1] = pp[i] * 2;
        pp[i + 1] %= c + 1;
    }

    int xp = 0;
    int xm = 0;
    int curp = 1;
    int curm = 1;

    for (int i = s.size() - 1; i >= 0; i--)
    {
        if (s[i] == '1')
        {
            xp += curp;
            xp %= (c + 1);
            if (c > 1)
            {
                xm += curm;
                xm %= (c - 1);
            }
        }
        curp *= 2;
        curp %= (c + 1);
        if (c > 1)
        {
            curm *= 2;
            curm %= (c - 1);
        }
    }
    cerr << xp << " " << xm << endl;
    rep(i, n)
    {
        // cerr << i << endl;
        if (s[i] == '0')
        {
            s[i] = '1';
            cout << calc(s, c + 1, xp, i) << "\n";
            s[i] = '0';
        }
        else
        {
            assert(xm != -1);
            s[i] = '0';
            cout << calc(s, c - 1, xm, i) << "\n";
            s[i] = '1';
        }
    }

    return 0;
}


Measured memory_bytes: 6756
#include <stdio.h>

int main(void)
{
	int i;
	int N, N1;
	int masu[100000];
	// int saar[100000];
	int sa;
	int max   = 0;
	int migin = 0;
	int idx   = 0;

	scanf("%d", &N);
	N1 = N - 1;

	for (i = 0; i < N; i++) {
		scanf("%d", &masu[i]);
		if (i == 0)
			continue;
		sa = masu[i - 1] - masu[i];
		// printf("%d\n", sa);
		if (sa >= 0) {
			migin++;
			// printf("migin %d\n", migin);
		} else {
			migin = 0;
		}
		if (max < migin) {
			max = migin;
			// idx = i - migin;
		}
	}

	printf("%d\n", max);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS = 1e-10;
typedef complex<double> P;
typedef pair<P,P> L;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
  }
}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
P crosspoint(const L &l, const L &m) {
  double A = cross(l.S - l.F, m.S - m.F);
  double B = cross(l.S - l.F, l.S - m.F);
  if (fabs(A) < EPS && fabs(B) < EPS) return m.F;
  return m.F + B / A * (m.S - m.F);
}
double area(vector<P> p) {
  double a=0;
  for(int i=0; i<(int)p.size(); i++) a+=cross(p[i],p[(i+1)%p.size()]);
  return fabs(a)/2;
}
int main() {
  int n;
  while(cin >> n && n) {
    L a[n+2],b[n+2];
    double c[n+2],d[n+2];
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++) cin >> d[i];
    c[0]=d[0]=0;
    c[n+1]=d[n+1]=1;
    for(int i=0; i<n+2; i++) a[i]=L(P(c[i],0),P(d[i],1));
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++) cin >> d[i];
    c[0]=d[0]=0;
    c[n+1]=d[n+1]=1;
    for(int i=0; i<n+2; i++) b[i]=L(P(0,c[i]),P(1,d[i]));
    P p[n+2][n+2];
    for(int i=0; i<n+2; i++) {
      for(int j=0; j<n+2; j++) p[i][j]=crosspoint(b[i],a[j]);
      sort(p[i],p[i]+n+2);
    }
    double ans=0;
    for(int i=0; i<n+1; i++) {
      for(int j=0; j<n+1; j++) {
        vector<P> v;
        v.push_back(p[i][j]);
        v.push_back(p[i][j+1]);
        v.push_back(p[i+1][j+1]);
        v.push_back(p[i+1][j]);
        ans=max(ans,area(v));
      }
    }
    printf("%.10f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3212
def selectionsort(a)
    swapcount = 0
    (0...a.size).each{|i|
        minj = i
        (i...a.size).each{|j|
            minj = j if a[j]<a[minj]
        }
        a[i], a[minj], swapcount = a[minj], a[i], swapcount+1 if i!=minj
    }
    return swapcount
end

gets
a = gets.split.map(&:to_i)
ct = selectionsort a
puts a.join(' '), ct


Measured memory_bytes: 6872
using System;

    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            for(int i = 0;i<1000;i++)
            {
                var tmp = (input + i).ToString();
                if ((tmp[0]== tmp[1])&&(tmp[1] == tmp[2]))
                {
                    Console.WriteLine(tmp);
                    return;
                }
            }
        }
    }

Measured memory_bytes: 11092
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


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

  cin >> N >> M;
  cout << max(N+M, max(N-M, N*M)) << endl;


}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] *= -1

tmp = 0
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A) * (-1) // 2
    heapq.heappush(A, (-1) * tmp)
print(sum(A) * (-1))

Measured memory_bytes: 14180
import itertools
N = int(input())
coordinate = []
order = []
total = 0
count = 0

for i in range(N):
    order.append(i)
    coordinate.append(list(map(float,input().split())))

#print(coordinate)

for vect in itertools.permutations(order):
    #print(vect)
    count+=1
    individual = 0.0
    for i in range(1,N):
        individual += ((coordinate[vect[i]][0]-coordinate[vect[i-1]][0])**2+(coordinate[vect[i]][1] - coordinate[vect[i-1]][1])**2)**0.5
    total +=individual

print(total/count)

Measured memory_bytes: 3064
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!long;
  
  long res = (10L^^12)+1;
  
  foreach (long a; 1..10^^6+1) {
    if (n % a) continue;
    auto b = n / a;
    res = min(res, a - 1 + b - 1);
  }
  res.writeln;
}


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

class Stack {
    private:
        int head;
        int buf[1 << 20];
    public:
        Stack() { head = 0; }
        void push(int x) {
            buf[head++] = x;
        }
        int pop() {
            return buf[--head];
        }
        bool isEmpty() {
            return head == 0;
        }
};

int main() {
    string inp;
    Stack s;
    while (cin >> inp) {
        char c = inp[0];
        if (c == '+' || c == '-' || c == '*') {
            int a = s.pop(), b = s.pop();
            switch (c) {
                case '+':
                    s.push(a + b);
                    break;
                case '-':
                    s.push(b - a);
                    break;
                case '*':
                    s.push(a * b);
                    break;
            }
        }
        else {
            s.push(stoi(inp));
        }
    }
    cout << s.pop() << "\n";
    return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    ll res=1;
    ll INF = 1e18;
    ll a[n];
    bool ok=0;
    rep(i,n){
        cin >> a[i];
        if(a[i]==0){
            ok=1;
        }
    }
    if(ok){
        cout << 0 << endl;
        return 0;
    }
    rep(i,n){
        ll x=(INF+res-1)/res;
        if(x<a[i]){
            cout << -1 << endl;
            return 0;
        }
        res*=a[i];
        if(res>INF){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 4416
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >>  N;
  ll l[N];
  ll max_l = 0, count = 0;
  rep(i, N) {
    cin>>l[i];
    max_l = max(l[i], max_l);
    count += l[i];
  }
  if (count-max_l>max_l) cout << "Yes" << endl;
  else cout <<"No" << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n=0;
	scanf("%d",&n);
	int a[100000]={0},l[100000]={0},r[100000]={0};
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	l[0]=a[0];
	for(int i=1;i<n;i++){
		l[i]=__gcd(l[i-1],a[i]);
	}
	r[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--){
		r[i]=__gcd(r[i+1],a[i]);
	}
	int maxn=max(l[n-1],r[1]);
	for(int i=0;i<n;i++){
		maxn=max(maxn,__gcd(l[i-1],r[i+1]));
	}
	printf("%d\n",maxn);
	return 0;
}

Measured memory_bytes: 1408
n = int(input())

ans = 0
a = 0
b = 0
c = 0
for i in range(n):
    s = input()
    if s[0] == "B" and s[-1] == "A":
        c += 1
    elif s[0] == "B":
        b += 1
    elif s[-1] == "A":
        a += 1
    ans += s.count("AB")

if c == 0:
    print(ans + min(a,b))

else:
    if a+b==0:
        print(ans+c-1)
    else:
        print(ans+c+min(a,b))


Measured memory_bytes: 44392
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
P a[100010];
int main() {
	int n;
	cin >> n;
	rep(i,n) cin >> a[i].first >> a[i].second;
	sort(a,a+n,greater<P>());
	int x = a[0].first, y = a[0].second;
	cout << x + y << endl;
	return 0;
}

Measured memory_bytes: 4368
import java.io.*;
import java.util.*;

public class Main {
    public static HashMap<Long, Long> map;

    public static void main(String args[]) {
        InputOutput io = new InputOutput(System.in, System.out);
        long h = io.l();
        map = new HashMap<>();
        io.pln(hit(h));
        io.flush();
    }
    
    public static long hit(long h) {
        if (h == 1)
            return 1;
        if (map.containsKey(h))
            return map.get(h);
        long ans = hit((long) Math.floor(h / 2)) + hit((long) Math.floor(h / 2)) + 1;
        map.put(h, ans);
        return ans;
    }

    public static class InputOutput {
        private BufferedReader br;
        private StringTokenizer tok;
        private PrintWriter pw;

        InputOutput(InputStream inputStream, OutputStream outputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            pw = new PrintWriter(new OutputStreamWriter(outputStream));
        }

        public String s() {
            while (tok == null || !tok.hasMoreElements()) {
                try {
                    tok = new StringTokenizer(br.readLine());
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
            return tok.nextToken();
        }

        public int i() {
            return Integer.parseInt(this.s());
        }

        public long l() {
            return Long.parseLong(this.s());
        }

        public void p(Object... out) {
            for (Object e : out)
                pw.print(e.toString());
        }

        public <T> void pln(T out) {
            pw.println(out);
        }

        public void pln() {
            pw.println();
        }

        public void flush() {
            pw.flush();
        }
    }
}

Measured memory_bytes: 21076
n, m = map(int, raw_input().split())
	
a0 = map(int, raw_input().split())
if n == 1:
	print a0[0]
else:
	a1 = map(int, raw_input().split())
	com = set(a0[1:]) & set(a1[1:])
	if n == 2:
		print len(list(com))
	else:
		for i in range(n-2):
			a1 = map(int, raw_input().split())
			com = com & set(a1[1:])
		print len(list(com))

Measured memory_bytes: 2568
from math import floor, ceil
h, w = map(int, input().split(' '))
result = []
if h%3 == 0 or w%3 == 0:
    print(0)
elif h<3 or w<3:
    if h<3 and w>=3:
        for i in range(1, w-1):
            x = i*h
            y = (w-i)*floor(h/2)
            z = (w-i)*ceil(h/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((w-i)/2)*h
            z = ceil((w-i)/2)*h
            result.append(max(x,y,z)-min(x,y,z))
        print(min(result))
    elif h>=3 and w<3:
        for i in range(1, h-1):
            x = i*w
            y = (h-i)*floor(w/2)
            z = (h-i)*ceil(w/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((h-i)/2)*w
            z = ceil((h-i)/2)*w
            result.append(max(x,y,z)-min(x,y,z))
        print(min(result))
    else:
        print(1)
else:
    for i in range(1, h-1):
        x = i*w
        y = (h-i)*floor(w/2)
        z = (h-i)*ceil(w/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((h-i)/2)*w
        z = ceil((h-i)/2)*w
        result.append(max(x,y,z)-min(x,y,z))
    for i in range(1, w-1):
        x = i*h
        y = (w-i)*floor(h/2)
        z = (w-i)*ceil(h/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((w-i)/2)*h
        z = ceil((w-i)/2)*h
        result.append(max(x,y,z)-min(x,y,z))
    print(min(result))

Measured memory_bytes: 19016
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split())) 
ans = 0
for i in range (n):
  ans += B[i]
for i in range (1,n):
  if A[i] == (A[i-1] + 1):
    ans += C[A[i-1]-1]
print(ans)

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

int main(){
  ll N, K;
  cin >> N >> K;
  ll x = N % K;
  ll y = K - x;
  cout << min(x, y) << endl;
}


Measured memory_bytes: 3588
n = int(input())
i = 1
table = [False for _ in range(10**6)]
while True:
    if table[n]:
        print(i)
        exit()
    else:
        table[n] = True
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    i += 1


Measured memory_bytes: 10904
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll k;
	cin >> k;
	ll ans = 0, cur = 1;
	while(k){
		ans += cur;
		cur *= 2;
		k /= 2;
	}
	cout << ans << '\n';

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
 string s,t;
 int c=0;
 cin>>s>>t;
 for(int i=0;i<3;i++)
 {
     if(s[i]==t[i])
        c++;
 }
 cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define f(a,j,k) for(int i = a ; i < j ; i += k)
#define f1(a,j,k) for(int i = a ; i > j ; i -= k)
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
typedef pair<int,int> pri;
typedef pair<long long,long long> prl;
ll cnt[200001];
int a[200001];
int main() {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	f(0,n,1) cin >> a[i] , cnt[a[i]]++;
	ll sum = 0;
	f(0,200001,1) sum += cnt[i] * ( cnt[i] - 1 ) / 2;
  f(0,n,1){
		  ll ans = sum - cnt[a[i]] * ( cnt[a[i]] - 1 ) / 2;
			ll k = cnt[a[i]] - 1;
			if(k > 0)
			ans += k * ( k - 1 ) / 2;
			cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<cstdio>
using namespace std ;
int main()  {
  int a,b,d,r;
  double f;
  cin>>a>>b;
d=a/b;
  r=a%b;
  f=(double)a/b;
  printf("%d %d %.8lf\n", d,r,f); 
  
  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define MD 1000000007
#define INF 1ll<<60
const double PI=3.141592653589;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n;
    cin>>n;
    map <string,int> mp;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(!mp.count(s)) mp[s]=1;
        else mp[s]++;
    }
    cout<<mp.size()<<endl;
    return 0;
}


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

ans = 0

for i in range(1,N+1) :
    dev = 0
    if i%2 == 0 :
        continue
    for j in range(1,i+1) :
        if i%j == 0 :
            dev += 1
    if dev == 8 :
        ans += 1

print(ans)


Measured memory_bytes: 2940
def examC():
    N = I()
    A = LI()
    Ad = [0]*N
    for i in range(N):
        Ad[i] = A[i]-(i+1)
    Ad.sort()
#    print(Ad)
    b = Ad[N//2]
    ans = 0
    for a in Ad:
        ans +=abs(a-b)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examC()


Measured memory_bytes: 26396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main(void)
{   
    int s, w;
    cin >> s >> w;
    if(w >= s) puts("unsafe");
    else puts("safe");
    return 0;
}

Measured memory_bytes: 3580
program gt_lt
  implicit none
  character(500000) :: s
  integer :: n, i, f(0:500000) = 0, a(0:500000) = 0
  read(*,*) s
  n = len_trim(s)
  f(0) = -1
  f(n+1) = 1
  do i = 1, n
    if (s(i:i) == "<") then
      f(i) = 1
    else
      f(i) = -1
    end if
  end do
  do i = 1, n+1
    if (f(i-1) == 1) then
      a(i) = a(i-1)+1
    end if
  end do
  do i = n, 0, -1
    if (f(i) == -1) then
      a(i) = max(a(i),a(i+1)+1)
    end if
  end do
  write(*,'(i0)') sum(int(a(1:n+1),8))
end program gt_lt

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

ll mod = 1e9 + 7;
int main() {
    int n;
    cin >> n;
    vector<int> a(n), c(3, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        ll cnt = 0;
        int id = -1;
        if (a[i] == c[0]) cnt++, id = 0;
        if (a[i] == c[1]) cnt++, id = 1;
        if (a[i] == c[2]) cnt++, id = 2;
        if (id == -1) {
            cout << 0 << endl;
            return 0;
        }
        ans *= cnt;
        ans %= mod;
        c[id]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
n,x,y=map(int,input().split())

d=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
  d[i][i]=0
num=[0 for i in range(n)]
g=[[i+1] for i in range(n-1)]
g.append([])
for i in range(1,n):
  g[i].append(i-1)
x-=1
y-=1
g[x].append(y)
g[y].append(x)

def bfs(start):
  #global d
  #global g
  q=[start]
  while q:
    now=q.pop(0)
    #print("now",now,"q",q,"d",d)
    for i in g[now]:
      if d[start][i]!=-1:
        continue
      else:
        d[start][i]=d[start][now]+1
        q.append(i)
 
for i in range(n):
  bfs(i)

for i in range(n-1):
  for j in range(i+1,n):
    num[d[i][j]]+=1

for i in range(1,n):
  print(num[i])

Measured memory_bytes: 79068
#include <stdio.h>

int main(void)
{
  int pages, papers, tmp1, tmp2;
  tmp1 = scanf("%d", &pages);
  if(tmp1 > 0 && tmp1 < 101);
  tmp2 = pages % 2;
  papers = pages / 2;
  if(tmp2 == 1){
    papers += 1;
  }
  printf("%d", papers);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define WHOLE(v) v.begin(), v.end()
using namespace std;
int main() {
    int64_t N, A, B;
    cin >> N >> A >> B;
    if(N == 1) {
        cout << (A == B ? 1 : 0) << endl;
    } else {
        cout << max<int64_t>(0, (B - A) * (N - 2) + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Unplanned Queries
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

bool vs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int ai, bi;
    scanf("%d%d", &ai, &bi);
    ai--, bi--;
    vs[ai] ^= true;
    vs[bi] ^= true;
  }

  bool ng = false;
  for (int i = 0; ! ng && i < n; i++) ng = vs[i];

  if (ng) puts("NO");
  else puts("YES");
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <NTL/ZZ.h>
using namespace std;
//using namespace NTL;
typedef long long ll;
const int inf = 2147483647;

int n, mod;
int power(int x, int times, int mod) {
  int rt = 1, base = x;
  while (times) {
    if (times & 1) rt = 1LL * rt * base % mod;
    base = 1LL * base * base % mod;
    times >>= 1;
  }
  return rt;
}

const int maxn = 3000 + 7;
long long power2[maxn], super_power2[maxn];
long long f[maxn], s[maxn][maxn], g[maxn][maxn];
long long c[maxn][maxn];
int main() {
  scanf("%d%d", &n, &mod);

  for (int i = 1; i <= n; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }

  power2[0] = 1;
  for (int i = 1; i <= n; i++) power2[i] = power2[i - 1] * 2 % mod;

  super_power2[0] = 1;
  for (int i = 1; i <= n; i++) super_power2[i] = super_power2[i - 1] * 2 % (mod - 1);
  for (int i = 0; i <= n; i++) super_power2[i] = power(2, super_power2[i], mod);

  s[1][1] = 1;
  for (int i = 2; i <= n; i++) 
    for (int j = 1; j <= n; j++) 
      s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j) % mod;

  f[0] = 1;

  g[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    g[i][0] = 1;
    for (int j = 1; j <= n; j++) 
      g[i][j] = (g[i - 1][j - 1] + g[i - 1][j] * j + g[i - 1][j]) % mod;
    long long cur = 1;
    for (int j = 0; j <= n; j++) {
      f[i] = (f[i] + g[i][j] * cur) % mod;
      cur = (cur * power2[n - i]) % mod;
    }
      //f[i] = (f[i] + g[i][j] * power(power2[n - i], j, mod)) % mod;
      //f[i] = (f[i] + g[i][j] * super_power2[n - i]) % mod;
  }
  

  //cout << f[n] << endl;
  for (int i = 0; i <= n; i++) 
    f[i] = f[i] * (super_power2[n - i]) % mod;

  //for (int i = 0; i <= n; i++) cout << f[i] << ' ';
  //cout << endl;

  int flag = 1;
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = (ans + flag * c[n][i] * f[i]) % mod;
    flag = -flag;
  } 
  cout << (ans + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 210432
N,A,B,C=map(int,input().split())
l=[int(input()) for _ in range(N)]
ABC=[A,B,C]

def base2n(Num,n):
    if Num<n:
        return str(Num)
    else:
        return base2n(Num//n,n)+str(Num%n)

ans=10**6
    
for i in range(4**N):
    i_4=("0"*N+base2n(i,4))[-N:]
    Group=[[] for i in range(4)]
    for j in range(N):
        Group[int(i_4[j])-1].append(l[j])
    if len(Group[0])*len(Group[1])*len(Group[2])!=0:
        ans=min(ans,(N-3-len(Group[3]))*10+sum([abs(ABC[j] - sum(Group[j])) for j in range(3)]))
        
print(ans)

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

struct candy_t {
    int i, p, q, r;
    candy_t(int i = 0, int p = 0, int q = 0, int r = 0) :
        i(i), p(p), q(q), r(r) {}
    int calorie() {
        return (p+r) * 4 + q * 9;
    }
};

int main() {
    int n;
    while (cin >> n, n != 0) {
        vector<candy_t> cal;
        for (int a = 0; a  < n; a++) {
            candy_t c;
            cin >> c.i >> c.p >> c.q >> c.r;
            cal.push_back(c);
        }
    
        candy_t ideal; 
        int ideal_calorie;
        cin >> ideal.p >> ideal.q >> ideal.r >> ideal_calorie;
    
        vector<int> ok;
    
        for (int a = 0; a < n; a++) {
            if (cal[a].p <= ideal.p && cal[a].q <= ideal.q &&
                    cal[a].r <= ideal.r && cal[a].calorie() <= ideal_calorie) {
                ok.push_back(cal[a].i);
            }
        }
    
        if (ok.size() == 0) cout << "NA" << endl;
        else {
            for (int a = 0; a < ok.size(); a++) {
                cout << ok[a] << endl;
            }
        }
    }

    return 0;
}

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

int main()
{
    int n,l;
    cin >> n >> l;
    long long int ans = l * n;

    for(int i = 0; i < n; i++){
        ans += i;
    }

    if(l + n - 1 < 0) ans -= l + n - 1;
    else if(l > 0) ans -= l;

    cout << ans << endl;

}

Measured memory_bytes: 256
N, M = list(map(int,input().split()))

A = [-1]
A += list(map(int,input().split()))
A.sort()

BC = [[1,-1]]

for i in range(M):
    BC.append(list(map(int,input().split())))

BC = sorted(BC, key=lambda x: x[1])


x = 0

for i in range(N):
    if A[-1] > BC[-1][1]:
        x += A.pop()
        
    else:
        x += BC[-1][1]
        BC[-1][0] -= 1
        if BC[-1][0] == 0:
            BC.pop()

print(x)

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

int sum(int x){
    int s = 0;
    while( x > 0 ){
        s += x % 10;
        x /= 10;
    }
    return s;
}

int main(){
    int a,b,n;
    cin >> n;
    int ans = 200 ;

    for ( int a = 1 ; a < n ; a++ ){
        b = n - a;
        int sumab = sum(a) + sum(b);
        ans = min(ans,sumab);
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	int n = 1;
	for (int i = 0; i < N; ++i) { n *= 2; }
	vector<int> a(n);
	for (int i = 0; i < n; ++i) { cin >> a[i]; }
	sort(a.rbegin(), a.rend());

	vector<int> v;
	v.push_back(a[0]);
	multiset<int> st;
	for (int i = 1; i < n; ++i) { st.insert(a[i]); }
	st.insert(0);

	for (int i = 0; i < N; ++i) {
		int sz = v.size();
		for (int j = 0; j < sz; ++j) {
			auto itr = prev(st.lower_bound(v[j]));
			if (*itr < 1) { continue; }
			v.push_back(*itr);
			st.erase(itr);
		}
	}
	cout << (st.size() > 1 ? "No" : "Yes") << endl;
	
	return 0;
}


Measured memory_bytes: 13568
// 1_8_A
#include <iostream>
using namespace std;

string swap_case(string str){
  for(int i = 0; i < (int)str.size(); i++){
    if(islower(str[i])){
      str[i] = toupper(str[i]);
    } else if(isupper(str[i])){
      str[i] = tolower(str[i]);
    }
  }
  return str;
}

int main(){
  string str;
  getline(cin, str);
  cout << swap_case(str) << endl;
  return 0;
}

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

int main() {
    vector<bool> primeFiled(static_cast<unsigned long>((int)sqrt(1e12)) + 100, false);
    vector<long int> prime;
    for (int i = 2; i <= sqrt(1e12); i++) {
        if (!primeFiled[i]) {
            prime.push_back(i);
            for (int j = i; j <= sqrt(1e12); j += i) {
                primeFiled[j] = true;
            }
        }
    }
    long int N, P;
    cin >> N >> P;
    long int temp = P;
    vector<int> primeFactor(prime.size(), 0);
    while (P > 1) {
        bool check = false;
        for (int i = 0; i < prime.size(); ++i) {
            if (P % prime[i] == 0) {
                ++primeFactor[i];
                P /= prime[i];
                check = true;
                break;
            }
        }
        if (!check) break;
    }
    long int answer = 1;
    for (int i = 0; i < primeFactor.size(); ++i) {
        if (primeFactor[i] >= N) {
            for (int j = 0; j < (int)(primeFactor[i] / N); ++j) {
                answer *= prime[i];
            }
        }
    }
    if (N == 1) {
        cout << temp << endl;
    } else {
        cout << answer << endl;
    }
}

Measured memory_bytes: 1528
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;

int main()

{

	int n, m, q;

	scanf("%d%d%d", &n, &m, &q);

	vector<int>a[505];

	for (int i = 0; i < m; i++)

	{

		int l, r;

		scanf("%d%d", &l, &r);

		a[l].push_back(r);

	}

	for (int i = 1; i <= n; i++)

		sort(a[i].begin(), a[i].end());

	while (q--)

	{

		int p, k;

		scanf("%d%d", &p, &k);

		int ans = 0;

		for (int i = p; i <= k; i++)

			ans += (upper_bound(a[i].begin(), a[i].end(), k) - a[i].begin());

		printf("%d\n", ans);

	}

}




Measured memory_bytes: 2176
program main
  implicit none
  
  integer :: n,x,m(100)=0,i,mi,nok,j,t
  
  read(*,*)n,x
  do i = 1, n
    read(*,*)m(i)
  end do
  nok = x - sum(m)
  
  do i=1,N-1
     do j=i+1,N
        if(m(i) .gt. m(j))then
           t=m(i)
           m(i)=m(j)
           m(j)=t
        end if
     end do
  end do
  
  mi = m(1)
  write(*,*)n+nok/mi
end program main

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
ls_a = []
ls_xy = []
for i in range(n):
    a = int(input())
    ls_a.append(a)
    xy = mylistinput(a)
    ls_xy.append(xy)
# print(a)
# print(ls_xy)

ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if i & (2**j):
            for k in range(len(ls_xy[j])):
                x = ls_xy[j][k][0] - 1
                y = ls_xy[j][k][1]
                if y==1:
                    if i & (2**x) > 0:
                        pass
                    else:
                        flag = False
                elif y==0:
                    if i & (2**x) == 0:
                        pass
                    else:
                        flag = False
    if flag:
        tmp = sum( list(map(int,list(bin(i)[2:]))) )
        ans = max( ans, tmp )

print(ans)            

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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int a, b; cin >> a >> b;
    cout << (b%a==0? a+b : b-a) << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, m;
    sc(n)
    int T[n];
    REP(i, n) sc(T[i]);
    sc(m)
    int P[m], X[m];
    REP(i, m){
        sc(P[i]) sc(X[i])
    }
    int sum = 0, ans;
    REP(i, n) sum += T[i];
    REP(i, m){
        ans = sum;
        ans -= T[P[i] - 1];
        ans += X[i];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;
int main(void){
    int n, T; cin >> n >> T;
    long minC = 10e9;
    int i = 0;
    while (i < n) {
        int c,t;
        cin >> c >> t;
        if (t <= T) {
            if (minC > c) minC = c;
        }
        i++;
    }
    minC == 10e9 ? cout << "TLE" << endl : cout << minC << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin>>n;
 long long ans=0;
 for(int i=1;i<=n;i++){
 if(i%3!=0 && i%5!=0)
   ans+=i;
 }
  cout<<ans;
  return 0;
 }


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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=1;

int main()
{
   int k,a,b;
   scanf("%d%d%d",&a,&b,&k);
   for(int i=100;i>=1;i--){

   if(a%i==0 && b%i==0){
    k--;
   }
   if(k==0){
    cout<<i;
    return 0;
   }
   }
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int X,Y;

int main(){
	fast;
	
	cin>>X>>Y;
	
	Y -= X * 2;
	if (Y < 0) cout<<"No";
	else{
		if (Y % 2 == 0 && Y <= X * 2) cout<<"Yes";
		else cout<<"No";
	}
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

lli g(vector<lli> v)
{
  lli cnt = 0;
  for (int i = 0; i + 1 < v.size(); ++i) {
    cnt += v[i] / 2;
    v[i] %= 2;
    int j = i + 1;
    int mn = min(v[i], v[j]);
    v[i] -= mn;
    v[j] -= mn;
    cnt += mn;
  }
  each (i, v) cnt += i / 2;
  return cnt;
}

lli f(vector<lli> v)
{
  vector<lli> u = v;
  reverse(u.begin(), u.end());
  return max(g(v), g(u));
}

int main(int argc, char *argv[])
{
  int n;
  while (cin >> n) {
    lli sum = 0;
    vector<lli> v;
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      if (a == 0 && v.size()) {
        sum += f(v);
        v.clear();
      } else {
        v.push_back(a);
      }
    }
    if (v.size()) sum += f(v);
    cout << sum << endl;
  }
  return 0;
}


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

bool is_integer(double x) {
    return floor(x)==x;
}

int main() {
    int n,d,count=0;
    cin>>n>>d;
    vector<vector<int>> x(n,vector<int>(d));
    double distance=0;

    rep(i,n) {
        rep(j,d) cin>>x[i][j];
    }

    rep(i,n-1) {
        for (int j=1; j<n; j++) {
            if (j<=i) continue;
            for (int z=0; z<d; z++) {
                distance+=(x[i][z]-x[j][z])*(x[i][z]-x[j][z]);
            }
            if (is_integer(sqrt(distance))) count++;
            distance=0;
        }
    }
    cout<<count<<endl;
}   

Measured memory_bytes: 256
n = int(input())
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table


a = prime_decomposition(n)


d ={}
for i in a:
    if i not in d:
        d[i] = int(0)
    d[i] += 1
    


c = list(d.values())


l =[]
for i in c:
    e = 1
    count = 1
    f = 0
    while i >=  e:
        count += 1
        f += 1 
        e = e + count
    l.append(f)
    
print(sum(l))

Measured memory_bytes: 9296
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


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

Measured memory_bytes: 256
package main
import "fmt"
const mod int64 = 998244353
func main() {
  var n,a,b,k,m int64
  fmt.Scan(&n,&a,&b,&k)
  if k == 0 { fmt.Println(1);return }
  initlz(n)
  if a > b { a,b = b,a }
  g := gcd(b,a)
  if k%g != 0 || k < a || n*(a+b) < k { fmt.Println(0);return }
  a,b,k = a/g,b/g,k/g
  for i:=min(k/b,n);i>-1;i-- {
    if (k-i*b)%a != 0 || (k-i*b)/a > n { continue }
    j := (k-i*b)/a
    m = (m+(comb(n,i)*comb(n,j))%mod)%mod
  }
  fmt.Println(m)
}
func min(x,y int64) int64 {
  if x < y { return x }
  return y
}
func gcd(x,y int64) int64 {
  if x%y == 0 { return y }
  return gcd(y,x%y)
}

const size int = 50
var f []int64
var invf []int64
func initlz(n int64) {
  f = make([]int64,n+1)
  invf = make([]int64,n+1)
  f[0] = 1
  invf[0] = 1
  for i:=int64(1);i<n+1;i++ {
    f[i] = (f[i-1]*(i%mod))%mod
    invf[i] = inv(f[i])
  }
}
func comb(n,k int64) int64 {
  if k < 0 || k > n { return 0 }
  if n == 0 && k == 0 { return 1 }
  if n == 0 { return 0 }
  return (f[n]*((invf[k]*invf[n-k])%mod))%mod
}
func inv(n int64) int64 {
  if n == 1 { return 1 }
  k := make([]int64,size)
  a,b,u := mod,n,size
  for i:=0;i<size;i++ {
    k[i],a,b = a/b,b,a%b
    if b == 0 { u = i;break }
  }
  var y0,y1 int64 = 1,-k[0]
  for i:=1;i<u;i++ { y0,y1 = y1,y0-k[i]*y1 }
  for y1 < 0 { y1 += mod }
  return y1%mod
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<pair<string ,int>, int> > res(n);
  for(int i=0;i<n;i++){
    cin >> res[i].first.first >> res[i].first.second;
    res[i].first.second*=(-1);
    res[i].second = i+1;
  }
  sort(res.begin(),res.end());
  for(int i=0;i<n;i++){
    cout << res[i].second << "\n";
  }
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

void test_case(){

}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	string s,t;
	cin >> s >> t;
	int ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]) ans++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3740