akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

typedef long long LL;

const int mod = 1e9 + 7;


const int maxn = 1e6 + 5;

pair<int, int> point[maxn];
int fac[maxn], inv[maxn];

int qpow(int a, int n){
    int ret = 1;
    while(n > 0){
        if(n & 1){
            ret = 1LL * ret * a % mod;
        }
        a = 1LL * a * a % mod;
        n >>= 1;
    }
    return ret;
}

void pre_comb(){
    fac[0] = 1;
    for(int i = 1;i < maxn;i++){
        fac[i] = 1LL * fac[i - 1] * i % mod;
    }
    inv[maxn - 1] = qpow(fac[maxn - 1], mod - 2);
    for(int i = maxn - 2;i >= 0;i--){
        inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
    }
}

int comb(int n, int m){
    if(m > n or m < 0) return 0;
    return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int n, m;
int C;
int dp[maxn];
int main(){
    cin >> n >> m >> C;
    for(int i = 1;i <= C;i++){
        scanf("%d%d", &point[i].first, &point[i].second);
    }     
    sort(point + 1,point + 1 + C);
    pre_comb();
    for(int i = 1;i <= C;i++){
        int x = point[i].first, y = point[i].second;
        dp[i] = comb(x - 1 + y - 1, x - 1);
        for(int j = 1;j < i;j++){
            int x1 = point[j].first, y1 = point[j].second;
            if(x1 <= x and y1 <= y){
                dp[i] = (dp[i] - 1LL * dp[j] * comb(x - x1 + y - y1, x - x1) % mod + mod) % mod;
            }
        }
    } 
    int ans = comb(n - 1 + m - 1, n - 1);
    for(int i = 1;i <= C;i++){
        int x = point[i].first, y = point[i].second;
        ans = (ans - 1LL * dp[i] * comb(n - x + m - y, n - x) % mod + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10496
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,b,g;
    cin >> r >> b >> g;
    int rbg = 100 * r + 10 * b + g;
    if(rbg % 4 == 0 ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
# -*-coding:utf-8

import math

def main():

    while True:
        scoreNumber = int(input())
        if(scoreNumber == 0):
            break

        scoreList = list(map(float, input().split()))
        scoreAve = sum(scoreList) / len(scoreList)

        scoreSum = 0
        for i in scoreList:
            scoreSum += pow(i-scoreAve, 2) / len(scoreList)

        print(math.sqrt(scoreSum))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7820
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool solve(const vector<vector<int>>& g){
    if(any_of(g.begin(), g.end(), [](auto& v){ return v.size()%2 == 1; })) return false;
    const int N = g.size();
    vector<int> four;
    for(int i=0;i<N;i++){
        if(g[i].size() >= 6) return true;
        if(g[i].size() == 4) four.push_back(i);
    }
    if(four.size() != 2) return four.size() >= 3;
    for(auto& t : g[four[0]]){
        int pre = four[0];
        int cur = t;
        while(g[cur].size() == 2){
            int tmp = cur;
            cur = (g[cur][0] == pre ? g[cur][1] : g[cur][0]);
            pre = tmp;
        }
        if(cur == four[0]) return true;
    }
    return false;
}

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<vector<int>> g(N);
        for(int i=0;i<M;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        cout << (solve(g) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 5760
function gcd(a, b) {
    if (a < b) {
        var tmp = b;
        b = a;
        a = tmp;
    }

    if (b === 0) return a;
    return gcd(b, a%b);
}

function lcm(a, b) {
    return a * b / gcd(a, b);
}

function Main(input) {
    var inputArr = input.split('\n');
    var N = parseInt(inputArr[0]);
    var a = inputArr[1].split(' ').map(function(num) { return parseInt(num) });

    var sum = 0;
    for(var i = 0 ; i < a.length ; ++i) {
        sum += (a[i] - 1);
    }

    console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll ma=1e9;
    int n,k;
    ll s;
    cin>>n>>k>>s;
    if(s==ma)
    {
        for(int i=0;i<k;i++)
            printf("%lld ",ma);
        for(int i=k;i<n;i++)
            printf("1 ");
        cout<<endl;
    }
    else
    {
        for(int i=0;i<k;i++)
            printf("%lld ",s);
        for(int i=k;i<n;i++)
            printf("%lld ",ma);
        cout<<endl;
    }
    return 0;
}


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

int main(){
    while(true){
        int n;
        cin>>n;
        if(!n)return 0;
        int a[n];
        double total=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            total += a[i];
        }
        double average=total/n;
        
        int lower_pep=0;
        for(int i=0;i<n;i++){
            if(a[i]<=average)lower_pep++;
        }
        cout<<lower_pep<<endl;
    }
}


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

int main() {
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}


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

using namespace std;

#define ll long long

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

	ll ans = 0;
	for (ll i = 2; i * i <= N; i++) {
		ll powN = 1;
		ll cnt = 0;
		while (N % i == 0) {
			N /= i;
			cnt++;
			if (cnt >= powN) {
				ans++;
				powN++;
				cnt = 0;
			}
		}
	}

	if (N != 1) {
		ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3600
#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 = 1001001001;

int main(){
    int a;
    cin >> a;
    int ans = a + a * a + a * a * a;
    cout << ans << endl;
}

Measured memory_bytes: 3584
import math
def is_ok(K, N, A, length):
    s = 0
    for i in range(N):
        if A[i] > length:
            s += math.ceil(A[i] / length)-1
    return K >= s


N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
if K == 0:
    print(max(A))
    exit()
ok = max(A)
ng = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(K, N, A, mid):
        ok = mid
    else:
        ng = mid

print(math.ceil(ok))

Measured memory_bytes: 104416
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  int S, K;
  int combi = 0;

  cin >> K >> S;

  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      int z = S - x - y;
      if (z >= 0 && z <= K) {
        combi += 1;
      }
    }
  }

  cout << combi << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX 110000


int main() {
	int n;
	cin >> n;
	int num,ans=0;

	for (int i = 0; i < n; i++) {
		cin >> num;
		while (num >= 2) {
			if (num % 2 == 0) {
				ans++;
				num /= 2;
			}
			else {
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
graph = [[] for i in range(2*10**5+1)]
ans = 0
for x,y in xy:
  y += 10**5
  graph[x].append(y)
  graph[y].append(x)
  ans -= 1
vis = [0 for i in range(2*10**5+1)]
for i in range(1,2*10**5+1):
  if vis[i]:
    continue
  stack = [i]
  nx = 0
  ny = 0
  while stack:
    x = stack.pop()
    if x > 10**5:
      ny += 1
    else:
      nx += 1
    vis[x] = 1
    for y in graph[x]:
      if not vis[y]:
        stack.append(y)
        vis[y] = 1
  ans += nx*ny
print(ans)

Measured memory_bytes: 86056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x=0,y=0;
    int t=0;
    int a,b,c;
    for(int i=1;i<=n;i++)
    {
        cin>>c>>a>>b;
        if(abs(x-a)+abs(y-b)>c-t)
        {
            cout<<"No";
            return 0;
        }
        if((abs(x-a)+abs(y-b))%2==0 &&(c-t)%2==1)
        {
            cout<<"No";
            return 0;
        }
        if((abs(x-a)+abs(y-b))%2==1 &&(c-t)%2==0)
        {
            cout<<"No";
            return 0;
        }
        x=a;y=b;t=c;
    }
    cout<<"Yes";
    return 0;
}

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

int main ()
{
    int n, m;
    cin >> n >> m;
    vector<double> R(n), G(n), B(n);
    for (int i = 0; i < n; i++) {
        cin >> R[i] >> G[i] >> B[i];
    }

    double res = 0.0;
    for (int i = 1; i < 1 << n; i++) {
        int bits = 0;
        int s = i;
        while (s) {
            if (s % 2) bits++;
            s /= 2;
        }
        if (bits == m) {
            double ret = 0.0;
            int k = 0;
            for (int j = 0; k < bits; j++) {
                if (i&(1 << j)) {
                    k++;
                    for (int l = j + 1; l < n; l++) {
                        if (i & (1 << l)) {
                            ret += pow(R[j] - R[l], 2) + pow(G[j] - G[l], 2) + pow(B[j] - B[l], 2);
                        }
                    }
                }
            }
            res = max(ret, res);
        }
    }

    printf("%.8f\n", res);

    return 0;
}

Measured memory_bytes: 1248
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

long long MAX = 1e18;

int main() {
    int x, i;
    for(i = 1; i <= 5; i++){
        cin >> x;
        if(x == 0){
            cout << i << endl;
            return 0;
        }
    }

return 0;
}


Measured memory_bytes: 3628
n = int(input())
d_list = [int(x) for x in input().split()]

sum = 0

for i in range(n):
    for j in range(i+1, n):
        sum += d_list[i] * d_list[j]
        #print(i, j, d_list[i]*d_list[j])
print(sum)

Measured memory_bytes: 39024
#include<cstdio>
#include<algorithm>
using namespace std;

int N;
int A[205];

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	N+=N;
	for(int i=1;i<=N;i++)
		scanf("%d",&A[i]);
	sort(A+1,A+N+1);
	long long ans=0;
	for(int i=1;i<=N;i+=2) {
		ans+=min(A[i],A[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;


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

    int mn_cost = INF;
    rep(i, N) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            mn_cost = min(mn_cost, c);
        }
    }
    if (mn_cost == INF) cout << "TLE" << endl;
    else cout << mn_cost << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) vc<vc<T>> xs(n, vc<T>(m)); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, x);
    printf("%.16f\n", x*x*x/27.0);
}


Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
sum1=0
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(m):
        sum1+=a[j]*b[j]
    if sum1+c>0:
        ans+=1
    sum1=0
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_1_C
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int res = 0;
            for (int i = 0 ; i < n ; i++) if (IsPrime(ReadInt())) res++;
            Console.WriteLine(res.ToString());
        }

        //●素数判定
        public static bool IsPrime(long number)
        {
            long boundary = (long)Math.Floor(Math.Sqrt(number));

            if (number == 1) return false;
            if (number == 2) return true;

            for (long i = 2 ; i <= boundary ; ++i)
            {
                if (number % i == 0) return false;
            }
            return true;
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



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

int main() {
  //freopen("input.txt","r",stdin);
  string str;
  while(cin>>str) {
    bool a_bool=false;
    bool b_bool=false;
    for(int i=0; i<3; i++) {
      if(str[i]=='A') a_bool=true;
      if(str[i]=='B') b_bool=true;
    }
    if(a_bool && b_bool) cout<<"Yes";
    else cout<<"No";
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		sc.close();
		long e = b - a + 1;
		a--;
		System.out.println(e - (((b / c) + (b / d) - (b / lcm(c, d))) - ((a / c) + (a / d) - (a / lcm(c, d)))));
	}

	public static final long gcd(long a, long b) {
		// a > b にする(swap)
		if (a < b) {
			a = a ^ b;
			b = a ^ b;
			a = a ^ b;
		}
		// ユークリッドの互除法
		long r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}

		return a; // b には r=0 の値が入るため、a を返す
	}

	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 21716
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_x) vec.erase(remove_if(all(vec),[](auto x){return condition_x;}),vec.end())
#define countif(vec,condition_x) count_if(all(vec),[](auto x){return condition_x;})
#define replaceif(vec,condition_x,n) replace_if(all(vec),[](auto x){return condition_x;},n)
#define optvalue(vec,condition_x,relation_x_opt) *min_element(all(vec),[](int x,int opt){return condition_x ? (opt==0)||!(relation_x_opt):false;})
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_x) for_each(all(vec),[](int&x){x= calc_x;})
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}




#define int int64_t
// #define double long double


// 無名関数template
// map,makepair

signed main(){
  IOS;

  in(int,n);
  VI a(n);
  fou(i,0,n)cin>>a[i];

  fou(i,0,n) a[i]-=(i+1);
  sortup(a);
  int d=a[n/2];
  VI dvec(n,d);
  calc2vec(a,-,dvec);
  calcvec(a,abs(x));

  int ans=0;
  fou(i,0,n) ans+=a[i];
  out(ans);

}

Measured memory_bytes: 3456
def func(n):
    if n%2==0 :
        return n//2
    else :
        return 3*n+1

s = int(input())
l = []
l.append(s)
for i in range(1000000):
    a = func(s)
    if a not in l:
        l.append(a)
        s = a
    else :
        print(i+2)
        break

Measured memory_bytes: 3060
# your code goes here
#binary
n=int(input())
S=[int(i) for i in input().split()]
q=int(input())
T=[int(i) for i in input().split()]
C=0
for i in range(q):
    j=n//2
    b=n//2
    while T[i]!=S[j] and b>1:
        if b%2==1:
            b+=1
        b//=2
        if T[i]>S[j]:
            j+=b
        elif T[i]<S[j]:
            j-=b
        if j>=n:
            j=n-1
        elif j<0:
            j=0
    #    if i==25:
       #     print(b)
#            print(j)
    if T[i]==S[j]:
        C+=1
    else:
        if T[i]>S[j]:
            j+=b
        else:
            j-=b
        if T[i]==S[j]:
            C+=1
#    print(j)
print(C)

Measured memory_bytes: 18764
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};



ll n;
string s;
ll rui[200010];
ll dp[200010][20];
void sub(){
  rep(i, n){
    dp[i+1][(s[i]-'0')%MOD]++;
    rep(j, MOD){
      dp[i+1][(j*10+s[i]-'0')%MOD] += dp[i][j];
    }
  }
  ll ans = 0;
  rep(i, n+1){
    ans += dp[i][0];
  }
  cout << ans << endl;
}

void solve(){
  cin >> n >> MOD;
  cin >> s;
  if(MOD < 20){
    sub();
    return;
  }
  rep(i, n){
    rui[i+1] = rui[i] + (s[i] - '0') * pow_mod(10, n-i-1);
    rui[i+1] %= MOD;
  }
  vector<ll> cnt(MOD, 0);
  rep(i, n+1){
    if(i == 0) continue;
    cnt[rui[i]]++;
  }

  ll ans = 0;
  rep(i, n){
    ans += cnt[rui[i]];
    cnt[rui[i+1]]--;
  }
  cout << ans << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}


Measured memory_bytes: 33300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    string s;
    ll ans = 0;
    cin>>s;
    rep(i,(1<<(s.size()-1))){
        ll tmp = s[0]-'0';
        // cout<<i<<endl;
        repl(j,1,s.size()){
            // cout<<ans<<" "<<tmp<<endl;
            if((1<<(j-1)) & i) {
                ans += tmp;
                tmp = s[j]-'0';
            }else {
                tmp  = tmp * 10 + s[j]-'0';
            }
            // cout<<ans<<" "<<tmp<<endl;
        }
        ans += tmp;
        // cout<<"--"<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int main(){
    int n,m; cin >> n >> m;
    int mon[200020];
    fill(mon,mon+200020,MM);
    mon[0] = 0;
    for(int i = 0; i < m; i++){
        int c; cin >> c;
        for(int num = 0; num <= n; num++){
            if (mon[num-c] != MM && num >= c){
                mon[num] = min(mon[num],mon[num-c]+1);
            }
        }
    }
    cout << mon[n] << endl;
}
  




Measured memory_bytes: 3892
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    int ans =0;
    for(int i=1;i<n-1;i++){
        vector<pair<int,int>> pii;
        pii.push_back({v[i-1],i-1});
        pii.push_back({v[i+1],i+1});
        pii.push_back({v[i],i});
        sort(pii.begin(),pii.end());
        if(pii[1].second==i) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
const main = (input) => {
  const inputs = input.trim().split("\n");
  const N = Number(inputs[0].split(" ")[0]);
  const Q = Number(inputs[0].split(" ")[1]);
  const S = inputs[1];

  const map = [];
  var cnt = 0;
  for(var i=0;i<S.length;i++){
    if(S[i]=='C' && S[i-1]=='A'){
      cnt++;
    }
    map[i+1]=cnt;
  }


  for(var i=2;i<inputs.length;i++){
    var l = Number(inputs[i].split(" ")[0]);
    var r = Number(inputs[i].split(" ")[1]);
    console.log(map[r]-map[l]);
  }

}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


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

using namespace std;

struct card {
  char suit;
  char value;
};

void print_vec(vector<card> &vec, int n) {
  for (int i = 0; i < n; i++) {
    cout << vec[i].suit << vec[i].value;
    if (i < n - 1) cout << " ";
  }
  cout << endl;
}

int main() {
  int n; //number of entries;
  cin >> n;

  vector<card> sort_vec1;

  for (int i = 0; i < n; i++) {
    string entry;
    cin >> entry;
    card new_card = {entry[0], entry[1]};
    sort_vec1.push_back(new_card);
  }

  vector<card> sort_vec2 = sort_vec1; //make copy

  //bubble sort
  for (int i = 0; i < n; i++) {
    for (int j = n-1; j > i; j--) {
      if (sort_vec1[j].value < sort_vec1[j-1].value) {
	swap(sort_vec1[j], sort_vec1[j-1]);
      }
    }
  }

  print_vec(sort_vec1, n);
  
  cout << "Stable" << endl; // bubble sort always stable

  //selection sort
  bool unstable = false;
  for (int i = 0; i < n; i++) {
    int min_index = i; // assume min is first element
    int min_value = sort_vec2[i].value; // value at minimum
    int repeated_index = n; // track min index of repeated value
    for (int j = i+1; j < n; j++) {
      // test for minimum
      if (sort_vec2[j].value == min_value) { // if same value card found
	if (repeated_index == n) repeated_index = j; //set min repeated index
      }					      
      if (sort_vec2[j].value < sort_vec2[min_index].value) min_index = j;
    }
    if (i != min_index) {
      // if same value cards inverted, unstable
      if (min_index > repeated_index) unstable = true;
      swap(sort_vec2[i], sort_vec2[min_index]); //swap 
    }
  }

  print_vec(sort_vec2, n);
  
  if (unstable) {
    cout << "Not stable" << endl;
  } else {
    cout << "Stable" << endl;
  }
  
}

Measured memory_bytes: 1224
from bisect import bisect_left as bl
INF = 10 ** 20

def main():
  
  w, h = map(int, input().split())
  n = int(input())
  
  xlst = []
  ylst = []
  
  for i in range(n):
    x, y = map(int,input().split())
    xlst.append(x)
    ylst.append(y)
  
  sorted_xlst = sorted(xlst)
  sorted_ylst = sorted(ylst)
  accx = accy = 0
  cum_sum_xlst = []
  cum_sum_ylst = []
  
  for i in range(n):
    accx += sorted_xlst[i]
    accy += sorted_ylst[i]
    cum_sum_xlst.append(accx)
    cum_sum_ylst.append(accy)
  
  if n % 2:
    clx = crx = sorted_xlst[n // 2]
    cly = cry = sorted_ylst[n // 2]
  else:
    clx = sorted_xlst[n // 2 - 1]
    crx = sorted_xlst[n // 2]
    cly = sorted_ylst[n // 2 - 1]
    cry = sorted_ylst[n // 2]
  
  ans = ansx = ansy = INF
  
  for i in range(n):
    xi = xlst[i]
    yi = ylst[i]

    if xi <= clx:
      cx = crx
    else:
      cx = clx

    if yi <= cly:
      cy = cry
    else:
      cy = cly
  
    px = bl(sorted_xlst, cx)
    py = bl(sorted_ylst, cy)
   
    if px:
      csx = cum_sum_xlst[px - 1]
      xlen = (cx * px - csx) * 2 + (accx - csx - cx * (n - px)) * 2 - abs(xi - cx)
    else:
      xlen = (accx - cx * n) * 2 - abs(xi - cx)
  
    if py:
      csy = cum_sum_ylst[py - 1]
      ylen = (cy * py - csy) * 2 + (accy - csy - cy * (n - py)) * 2 - abs(yi - cy)
    else:
      ylen = (accy - cy * n) * 2 - abs(yi - cy)
    
    tlen = xlen + ylen

    if ans > tlen:
      ans = tlen
      ansx = cx
      ansy = cy
    elif ans == tlen:
      if ansx > cx:
        ansx = cx
        ansy = cy
      elif ansx == cx:
        if ansy > cy:
          ansy = cy 
  
  print(ans)
  print(ansx, ansy)

main()


Measured memory_bytes: 25184
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
string s,s1;
ll ar[250007],cr[200098],a,b, test, sum,t,x=0,p,q,y,i,j,k=0,l,cnteven=0,w=0,cnt;
map<ll,ll>mp,br;


int main()
{
    ll test;
    for(i=1; i<=5; i++)
        cin>>ar[i];
    ll p;
    for(j=1; j<=5; j++)
    {
        k=0;
        for(i=0;i<=10000;i=k*10)
        {
            if(ar[j]<=i)
            {if(cnt<=i-ar[j])
               {cnt=i-ar[j];
                 p=ar[j];
                }
                   break;

            }
            else
            k++;
        }
    }
    sum=0;
    cnt=0;
    for(j=1; j<=5; j++)
    {
        k=0;
        if(ar[j]!=p||cnt==1)
        {
            for(i=0; i<=130; i=k*10)
            {
                if(ar[j]<=i)
                {
                    sum+=i;

                    break;
                }
                k++;
            }
        }
        else if(ar[j]==p)
            cnt=1;
    }
    cout<<sum+p;


}



Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, A = sc.nextInt()
    val X = Array.fill(N)(sc.nextInt())

    // N <= 16のデータセットの場合は, 単に 2^16 通りなので
    // 全探索しても間に合うが...
    // dp[i][j][s] := i + 1枚目までのカードの中でカードをj枚選んだ時, 合計がsとなる場合の数 とする
    def solve(N: Int, A: Int, X: Array[Int]): Long = {
      val dp = Array.fill(N + 1, N + 1, 50 * 50 + 1)(0L)
      dp(0)(0)(0) = 1L
      for {
        i <- 1 to N
        j <- 0 to i
        s <- 0 to 2500
      } if (j >= 1 && s >= X(i-1)) dp(i)(j)(s) = dp(i - 1)(j - 1)(s - X(i-1)) + dp(i - 1)(j)(s)
        else dp(i)(j)(s) = dp(i - 1)(j)(s)
      (1 to N).map(i => dp(N)(i)(A * i)).sum
    }

    println(solve(N, A, X))
  }

}


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

int n, m;
vector<int> et[100000];
int q;
int v[100000], d[100000], c[100000];

int max_remDist[100000];
int color[100000];

void query(int v, int d, int c) {
	typedef pair<int, int> P;	//remDist, pos
	static queue<P> que;
	
	if (max_remDist[v] >= d) return;
	max_remDist[v] = d; if (color[v] == 0) color[v] = c;
	que.push(P(d, v));
	while (!que.empty()) {
		int remDist = que.front().first;
		int pos = que.front().second;
		que.pop();
	
		for (int i = 0; i < et[pos].size(); i++) {
			int npos = et[pos][i];
			if (remDist - 1 < 0 || max_remDist[npos] >= remDist - 1) continue;
			max_remDist[npos] = remDist - 1;
			if (color[npos] == 0) color[npos] = c;
			que.push(P(remDist - 1, npos));
		}
	}
}

signed main() {
	int i;
	
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		max_remDist[i] = -1;
	}
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}
	
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
	}
	
	for (i = q - 1; i >= 0; i--) {
		query(v[i], d[i], c[i]);
	}
	
	for (i = 0; i < n; i++) {
		cout << color[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8952
import numpy as np

mod = 998244353

n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
DP[0] = 1

for a in A:
    double = DP * 2
    double[a:] += DP[:-a]  # shift
    DP = double % mod

print(DP[s])


Measured memory_bytes: 27168
#include <stdio.h>
int main(){
  int n,x,i,j,k,co;

  while(1){
    scanf("%d %d",&n,&x);
    if((n==0)&&(x==0)) break;
    for(co=0,i=1;i<=n-2;i++) for(j=i+1;j<=n-1;j++) for(k=j+1;k<=n;k++) if((i+j+k)==x) co++;
    printf("%d\n",co);
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n,a,b,c;
    cin >> n >> a >> b >> c;
    vector<int> v;
    for(int i=0;i<n;i++) {
        int l;
        cin >> l;
        v.push_back(l);
    }
    int ans = 300000;
    for(int i=0;i < (1 << (2*n)); i++) {
        int ca,cb,cc;
        ca=cb=cc=0;
        int cur =0;
        for(int j=0;j<n;j++) {
            int k = (i >> (2*j)) & 3;
            #define C(k) do{if((k)>0){cur+=10;}(k)+=v[j];}while(0)
            if (k==0) {
                C(ca);
            } else if (k==1) {
                C(cb);
            } else if(k==2) {
                C(cc);
            }
        }
        if (ca == 0 || cb ==0 || cc == 0) {
            continue;
        }
        cur += abs(ca-a) + abs(cb-b) + abs(cc-c);
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct edge{
    int to;
    ll cost;
};
void dijkstra(int s, vector<vector<edge>> &g, vector<ll> &d) {
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> que;
    for(ll &x : d) x = LINF;
    d[s] = 0;
    que.push(make_pair(0, s));
    
    while(!que.empty()) {
        pair<ll,int> p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        
        rep(i,sz(g[v])) {
            edge e = g[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--;t--;
    vector<vector<edge>> g_yen(n);
    vector<vector<edge>> g_snuuk(n);
    rep(i,m) {
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;v--;
        g_yen[u].push_back({v,a});
        g_yen[v].push_back({u,a});
        g_snuuk[u].push_back({v,b});
        g_snuuk[v].push_back({u,b});
    }
    
    vector<ll> d_s(n),d_t(n);
    dijkstra(s,g_yen,d_s);
    dijkstra(t,g_snuuk,d_t);
    
    ll now=LINF;
    vector<ll> ans;
    rrep(i,n) {
        now=min(now,d_s[i]+d_t[i]);
        ans.push_back(now);
    }
    rrep(i,n) cout<<1000000000000000-ans[i]<<endl;
}


Measured memory_bytes: 19964
h, w = map(int, input().split())

s = [input() for _ in range(h)]

def dfs(i, j):
  if s[i][j] == '#':
    return '#'
  else:
    cnt = 0
    moves = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
    for move in moves:
      if 0 <= i + move[0] < h and 0 <= j + move[1] <w:
        if s[i + move[0]][j + move[1]] == '#':
          cnt += 1
    return str(cnt)

for i in range(h):
  for j in range(w):
    print(dfs(i, j), end='')
  print()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
struct res{
    string na;
    int p,sit;
}a[10004];
int n;
inline bool dex(res A,res B){
    if(A.na == B.na){
        return A.p>B.p;
    }
    else return A.na<B.na;
}
int LiangJiaJun(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].na>>a[i].p;
        a[i].sit=i;
    }
    sort(a+1,a+n+1,dex);
    for(int i=1;i<=n;i++)cout<<a[i].sit<<endl;
    return 0;
}


Measured memory_bytes: 384
n, k, q = list(map(int, input().split()))
A = [int(input()) for _ in range(q)]

P = [0] * n 
for a in A:
    P[a-1] += 1

for p in P:
    if p > len(A) - k:
        print("Yes")
    else:
        print("No")
        


Measured memory_bytes: 8632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  string ans="";
  int i=0,j=0;
  while(i<n||j<n)
  {
    ans.push_back(s[i]);
    ans.push_back(t[j]);
    i++;j++;}
  cout<<ans<<endl;}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
ll bigpow(ll base,ll pw,ll M)
{
	if(pw==0) return 1;
	if(pw%2==0)
	{
		ll ret=bigpow(base,pw/2,M);
		return ((ret%M)*(ret%M))%M;
	}
	else return ((base%M)*(bigpow(base,pw-1,M)))%M;

}
ll maxi(ll a,ll b)
{
    if(a>b)return a;
    return b;
}
ll mini(ll a,ll b)
{
    if(a<b)return a;
    return b;
}
ll abse(ll a)
{
    if(a<0)return -a;
    return a;
}
ll ceili(ll a,ll div)
{
    return (a+div-1)/div;
}
int h,w;
ll**  dp;

char** v;
ll f(int i,int j)
{
    if(i>h||j>w) return 0;
    if(v[i][j]=='#')return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    if(i==h&&j==w) return 1;
    return dp[i][j]=(f(i+1,j)+f(i,j+1))%MOD;
}
int main(void)
{
    io;
    int T=1,cas=0,i,j;
    char c;
    //cin>>T;
    while(T--)
    {
        cin>>h>>w;

        dp=new ll*[h+5];
        for(i=0;i<h+5;i++)dp[i]=new ll[w+5];
        v=new char*[h+5];
        for(i=0;i<h+5;i++)v[i]=new char[w+5];

        for(i=0;i<h;i++)
        {
            cin>>v[i];

        }


      for ( i = 0; i <=h; i++)
        for ( j = 0; j <= w; j++)
            dp[i][j] = -1;
        h--;w--;
        dp[h][w]=1;
    cout<<f(0,0);

    }
}



Measured memory_bytes: 9216
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	b int64
	c int64
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].c < s[j].c }

// -----------------------------------------------------------------

func main() {
	n := readInt64()
	m := readInt64()
	a := make([]int64, n)
	for i := range a {
		a[i] = readInt64()
	}
	x := make(sortArray, m)
	for i := range x {
		x[i] = xxx{
			b: readInt64(),
			c: readInt64(),
		}
	}

	sort.Sort(int64Array(a))
	sort.Sort(sort.Reverse(x))

	y := make([]int64, 0, n)
	for _, xx := range x {
		if len(y) > int(n) {
			break
		}
		for i := 0; i < int(xx.b); i++ {
			y = append(y, xx.c)
		}
	}

	l := min(len(a), len(y))
	for i := 0; i < l; i++ {
		if y[i] > a[i] {
			a[i] = y[i]
		} else {
			break
		}
	}

	var ans int64
	for i := range a {
		ans += a[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 9728
#include "iostream"
#include "algorithm"

using namespace std;
int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b))
  {
    cout << 'A' << endl;
  }
  else
  {
    cout << 'B' << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a[100]={},b[100]={},ma,mu,i,j,x,z;
	z=0;
	ma=0;
	mu=1000000000;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	for(i=0;i<n;i++){
		x=1000000000-a[i];
		while(j<1000000000){
			if(x==1000000000) break;
			b[i]++;
			x++;
		}
	}
	for(i=0;i<n;i++){
		if(ma<a[i]) ma=a[i];
		if(mu>b[i]) mu=b[i];
	}
	z=ma-mu;
	printf("%d\n",z);
	return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int X, Y;
    cin >> X >> Y;
    int ans = 1 << 30;
    vector<int> dx{1,1,-1,-1};
    vector<int> dy{1,-1,1,-1};
    REP(i,4) {
        int nx = X * dx[i];
        int ny = Y * dy[i];
        int b = dx[i] == -1 ? 1:0;
        b += dy[i] == -1 ? 1:0;
        if (nx <= ny) ans = min(ans,abs(nx-ny)+b);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n = 0;
    static int m = 0;
    static int k = 0;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();

        for(int r = 0; r <= n; ++r) {
            for(int c = 0; c <= m; ++c) {
                int blackNum = c * n + r * m - 2 * c * r;
                if(blackNum == k) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        
        System.out.println("No");
    }
}

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

#define MAX 1000000000

typedef pair<int,int> P;

int main(void){
	int n;

	while(cin>>n, n){
		deque<P> d;
		d.push_back(P(-1,MAX));

		while(n--){
			char ch;
			cin>>ch;
			if(ch == 'W'){
				int x,y;
				cin>>x>>y;
				for(int i=0;i<d.size();i++){
					if(d[i].first != -1) continue;

					if(y > d[i].second){
						d[i].first = x;
						y -= d[i].second;
					}
					else if(y == d[i].second){
						d[i].first = x;
						break;
					}
					else{
						d[i].second -= y;
						d.insert(d.begin()+i,P(x,y));
						break;
					}
				}
			}
			else if(ch == 'D'){
				int x;
				cin>>x;
				for(int i=0;i<d.size();i++)
					if(d[i].first == x)
						d[i].first = -1;
			}
			else{
				int x;
				cin>>x;
				if(x >= MAX){
					cout<<-1<<endl;
					continue;
				}
				int idx = 0;
				for(idx=0;idx<d.size();idx++){
					x -= d[idx].second;
					if(x <= -1) break;
				}
				cout<<d[idx].first<<endl;
			}
		}

		cout<<endl;
	}

	return 0;
}

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


int main(){
    int n;
    cin >> n;
    unordered_map<int, int> hash;
    rep(i,n){
        int tmp;
        cin >> tmp;
        hash[tmp]++;
    }
    int cnt = 0;
    for(auto p : hash){
        if(p.first == p.second) continue;
        else cnt += p.first < p.second ? p.second - p.first : p.second;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 4260
#include <iostream>
#include <string>
#include <vector>
#include <atcoder/all>
using ll=long long;
using namespace std;
using namespace atcoder;

int main(){
    int N,Q;
    cin>>N>>Q;
    fenwick_tree<ll> fw(N);
    ll a;
    for(int i=0;i<N;i++){
        cin>>a;
        fw.add(i,a);
    }

    int q,x,y;
    for(int i=0;i<Q;i++){
        cin>>q>>x>>y;
        if(q){
            cout<<fw.sum(x,y)<<endl;
        }else{
            fw.add(x,y);
        }
    }

    return 0;
}

Measured memory_bytes: 8220
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<double>h;
	double x;
	while (cin >> x) {
		h.push_back(x);
	}
	cout << *max_element(h.begin(), h.end()) - *min_element(h.begin(), h.end()) << endl;
	return 0;
}

Measured memory_bytes: 1300
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }

        int[] sorted = Arrays.copyOf(A, N);
        Arrays.sort(sorted);

        for (int i = 0; i < N; i++) {
            if (A[i] == sorted[N - 1]) {
                System.out.println(sorted[N - 2]);
            } else {
                System.out.println(sorted[N - 1]);
            }
        }
    }
}


Measured memory_bytes: 75624