akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n) {
        cin >> s[i];
    }
    int q;
    cin >> q;
    vector<int> t(q);
    rep(i, q) {
        cin >> t[i];
    }
    int c = 0;
    rep(i, q) {
        decltype(s)::iterator fd = lower_bound(all(s), t[i]);
        if(fd != s.end() && *fd == t[i]) c++;
    }
    cout << c << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


Measured memory_bytes: 3296
#include <stdio.h>
#include <algorithm>

#define LIM_S 200002
#define LIM_N 200001

char str[LIM_S];
int a[5];

void receive_input() {
	for (size_t i = 0; i < 5; i++) {
		fgets(str, sizeof(str), stdin);
		sscanf(str, "%d", &a[i]);
	}
}

void initialize() {
}

int solve() {
	int min_d = 10;
	int min_d_num = -1;

	for (size_t i = 0; i < 5; i++) {
		int d = a[i] % 10;
		if (0 < d && d < min_d) {
			min_d = d;
			min_d_num = i;
		}
	}

	int s_time = 0;
	for (size_t i = 0; i < 5; i++) {
		if (min_d_num != i) {
			int d = a[i] % 10;
			if (d > 0) {
				s_time += (a[i] / 10 + 1) * 10;
			} else {
				s_time += a[i];
			}
		} else {
			s_time += a[i];
		}
	}

	return s_time;
}

int main(void) {
	receive_input();
	initialize();

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

	return 0;
}


Measured memory_bytes: 128
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int n;
    std::cin >> n;
    int dp[10][10];
    rep(i, 10) rep(j, 10) dp[i][j] = 0;
    repeat(i, 1, n + 1) {
        dp[std::to_string(i)[0] - '0'][i % 10]++;
    }
    i64 ans = 0;
    repeat(i, 1, n + 1) {
        ans += dp[i % 10][std::to_string(i)[0] - '0'];
    }
    std::cout << ans << std::endl;
}

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

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i<m; i++){
		int a,b;
		cin >> a >> b;
		v[a-1]++;
		v[b-1]++;
	}
	for(int x: v) cout << x << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	ll X,Y,Z,K; cin >> X >> Y >> Z >> K;
	ll A[1005],B[1005],C[1005];

	for (int i = 0;i < X;i++){
		cin >> A[i];
	}
	for (int i = 0;i < Y;i++){
		cin >> B[i];
	}
	for (int i = 0;i < Z;i++){
		cin >> C[i];
	}
	sort(A,A+X); sort(B,B+Y); sort(C,C+Z);

	vector<ll> lis;

	for (int i = 1;i <= X;i++){
		if(i > K) break;
		for (int j = 1;j <= Y;j++){
			if(i*j > K) break;
			for (int k = 1;k <= Z;k++){
				if(i*j*k > K) break;
				lis.push_back(A[X-i]+B[Y-j]+C[Z-k]);
			}
		}
	}

	sort(lis.begin(),lis.end(),greater<ll>());

	for (int i = 0;i < K;i++){
		cout << lis[i] << endl;
	}

	return 0;

}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> vec(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    vec[i] = make_pair(i + 1, a);
  }

  sort(vec.begin(), vec.end(),
       [](auto &left, auto &right) { return left.second < right.second; });

  for (int i = 0; i < n - 1; ++i)
    cout << vec[i].first << " ";
  cout << vec[n-1].first << endl;

}

Measured memory_bytes: 1664
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N, M, L = map(int, input().split())
    graph = [[0] * N for _ in range(N)]
    for _ in range(M):
        s, t, w = map(int, input().split())
        if w <= L:
            graph[s-1][t-1] = graph[t-1][s-1] = w
    graph = floyd_warshall(graph, directed=False)
    graph = floyd_warshall(graph <= L, directed=False)
    graph[np.isinf(graph)] = 0

    Q = int(input())
    ans = []
    for _ in range(Q):
        s, t = map(int, input().split())
        ans.append(int(graph[s-1][t-1]) - 1)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 26544
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> red(A);
    for (int i = 0; i < A; i++) {
        cin >> red.at(i);
        }
    vector<int> bulue(B);
    for (int i = 0; i < B; i++) {
        cin >> bulue.at(i);
        }
    vector<int> less(C);
    for (int i = 0; i < C; i++) {
        cin >> less.at(i);
        }
    

    sort(red.begin(),red.end());
    sort(bulue.begin(),bulue.end());
    sort(less.begin(),less.end());

    vector<int> ans = vector<int>(X+Y, 0);

    for (int i = 0; i < X; i++) {
        ans.at(i)=red.at(red.size()-i-1);
    }
    for(int i = 0; i < Y; i++) {
        ans.at(i+X)=bulue.at(bulue.size()-i-1);
    }

    

    for (int i = 0; i < less.size(); i++) {
        ans.push_back(less.at(i));
    }

    sort(ans.begin(),ans.end());
    
    long int sum = 0;
    for (int i = 0; i < X+Y; i++) {
        sum += ans.at(ans.size()-i-1);
        }

    cout << sum << endl;

}

Measured memory_bytes: 2816
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r, d, X;
    int arr[11];
    cin >> r >> d >> X;
    arr[0] = X;
    for(int i = 0; i < 10; i++){
        arr[i+1] = (r * arr[i]) - d;
    }
    
    for(int i = 0; i < 10; i++){
        cout << arr[i+1] << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  
  int count = 0;
  for (int i = 1; i <= N; i++){
    string A = to_string(i);
    if (A.length() % 2 == 1){
      count++;
    }
  }
  cout << count;
  
  return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())
A = [int(x) for x in input().split()]

def choose2(n):
  return int(n * (n - 1) / 2)

counter = collections.Counter(A)

ttl = 0
for key in counter:
  ttl += choose2(counter[key])
    
for i in range(N):
  ans = ttl - choose2(counter[A[i]]) + choose2(counter[A[i]] - 1)
  print(ans)
  

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

using namespace std;

#define MOD 998244353
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

ll F[300005];

ll inv(ll x) {
	ll a = x % MOD;
	ll b = MOD - 2;
	ll ans = 1;
	while (b) {
		if (b&1) ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

ll ncr(ll n, ll r) {
	ll ret = (F[n] * inv(F[r] * F[n-r])) % MOD;
	return ret;
}

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

	ll n, m, i, j, k, x, y, z, a, b, c;
	F[0] = 1;
	for (i = 1; i <= 300000; ++i) F[i] = (i * F[i-1]) % MOD;
	cin >> n >> a >> b >> k;
	ll ans = 0;
	for (x = 0; x <= n; ++x) {
		ll req = k - x * a;
		if (req < 0) break;
		if (req%b) continue;
		y = req / b;
		if (y > n) continue;
		ans = (ans + ncr(n, x) * ncr(n, y)) % MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
N = int(input())
a_s = [int(n) for n in input().split()]

boxes = [0] * N
for i, a in enumerate(reversed(a_s)):
    i = N - i
    if a != sum(boxes[i - 1::i]) % 2:
        boxes[i-1] = 1

print(boxes.count(1))
for i, b in enumerate(boxes, 1):
    if b == 1:
        print(i)

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

int main(void){
  int n,x,ans=0;
  vector<int> v;
  
  cin >> n >> x;
  for (int i=0; i<n; i++){
    int t;
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(),v.end());
  for (int i=0; i<n; i++){
    if (v[i]<=x){
      //cout << v[i] << " " << x << endl;
      ans++;
      x -= v[i];
    } else break;
  }
  if (ans==n && x) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
// ???????????£???????????????????????????????????????

int main()
{
    int n, i;
    string suit;
    int num;
    int cards[52];

    for(i = 0; i < 52; i++) cards[i] = 0;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> suit >> num;
        if(suit == "S") cards[num - 1] = 1;
        if(suit == "H") cards[num + 12] = 1;
        if(suit == "C") cards[num + 25] = 1;
        if(suit == "D") cards[num + 38] = 1;
    }
    for(i = 0; i < 52; i++){
        if(cards[i] == 1) continue;
        if(i < 13){
            cout << "S " << i + 1;
        }else if(i < 26){
            cout << "H " << i - 12;
        }else if(i < 39){
            cout << "C " << i - 25;
        }else{
            cout << "D " <<  i - 38;
        }
        cout << endl;
    }

    return 0;
}

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

int dx[8] = {-1, 0,+1,-1,+1,-1, 0,+1};
int dy[8] = {-1,-1,-1, 0, 0,+1,+1,+1};
char f[256] = {0};

void debug(const vector<string>& v){
	cout << "[debug]" << endl;
	for(int y=0 ; y < 8 ; y++ ){
		cout << v[y] << endl;
	}
	cout << endl;
}

// (x,y) に c を置く
void place(int x, int y, char c, vector<string>& v){
	if( v[y][x] != '.' ) return;
	v[y][x] = c;
	
	// p[i] := 方向 i に置けるかどうか 
	int p[8] = {false};
	for(int i=0 ; i < 8 ; i++ ){
		int mx = x + dx[i];
		int my = y + dy[i];
		if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) continue;
		if( v[my][mx] == f[c] ){
			while( true ){
				mx += dx[i];
				my += dy[i];
				if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) break;
				if( v[my][mx] == '.' ) break;
				if( v[my][mx] == c ){
					p[i] = true;
					break;
				}
			}
		}
	}
	for(int i=0 ; i < 8 ; i++ ){
		if( !p[i] ) continue;
		int mx = x + dx[i];
		int my = y + dy[i];
		if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) continue;
		if( v[my][mx] == f[c] ){
			while( true ){
				if( v[my][mx] == f[c] ){
					v[my][mx] = c;
				}
				mx += dx[i];
				my += dy[i];
				if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) break;
				if( v[my][mx] == '.' || v[my][mx] == c ) break;
			}
		}
	}
}

// (x,y) に c をおいた時にひっくり返す個数を返す.
int get_stone(int x, int y, char c, vector<string> v){
	if( v[y][x] != '.' ) return 0;
	
	// p[i] := 方向 i に置けるかどうか 
	int p[8] = {false};
	for(int i=0 ; i < 8 ; i++ ){
		int mx = x + dx[i];
		int my = y + dy[i];
		if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) continue;
		if( v[my][mx] == f[c] ){
			while( true ){
				mx += dx[i];
				my += dy[i];
				if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) break;
				if( v[my][mx] == '.' ) break;
				if( v[my][mx] == c ){
					p[i] = true;
					break;
				}
			}
		}
	}
	int res = 0;
	for(int i=0 ; i < 8 ; i++ ){
		if( !p[i] ) continue;
		int mx = x + dx[i];
		int my = y + dy[i];
		if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) continue;
		if( v[my][mx] == f[c] ){
			while( true ){
				if( v[my][mx] == f[c] ) res++;
				mx += dx[i];
				my += dy[i];
				if( mx < 0 || my < 0 || 8 <= mx || 8 <= my ) break;
				if( v[my][mx] == '.' || v[my][mx] == c ) break;
			}
		}
	}
	return res;
}

vector<string> solve(char c, vector<string> v, bool pass = false){
	int cnt = 0;
	for(int y=0 ; y < 8 ; y++ ){
		for(int x=0 ; x < 8 ; x++ ){
			cnt = max( cnt , get_stone(x,y,c,v) );
		}
	}
	
	//debug(v);
	
	if( cnt == 0 ){ // パスするとき
		if( pass ){ // 前回もパスなら試合終了
			return v;
		}else{ // パスする
			return solve(f[c],v,true);
		}
	}
	
	if( c == 'o' ){
		for(int y=0 ; y < 8 ; y++ ){
			for(int x=0 ; x < 8 ; x++ ){
				if( cnt == get_stone(x,y,c,v) ){
					place(x,y,c,v);
					return solve(f[c],v);
				}
			}
		}
	}else{
		for(int y=7 ; y >= 0 ; y-- ){
			for(int x=7 ; x >= 0 ; x-- ){
				if( cnt == get_stone(x,y,c,v) ){
					place(x,y,c,v);
					return solve(f[c],v);
				}
			}
		}
	}
}


int main(){
	f['o'] = 'x';
	f['x'] = 'o';
	vector<string> v(8);
	for(int y=0 ; y < 8 ; y++ ){
		cin >> v[y];
	}
	vector<string> ans = solve('o',v);
	for(int y=0 ; y < 8 ; y++ ){
		cout << ans[y] << endl;
	}
}

Measured memory_bytes: 1228
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX 10000
#define INFTY (1 << 29)

class DisjointSet {
	public:
	    vector<int> rank, p;
	    
	    DisjointSet() {}
	    DisjointSet(int size) {
    		rank.resize(size, 0);
    		p.resize(size, 0);
    		for(int i = 0; i < size; i++) makeSet(i);
    	}
    	
    	void makeSet(int x) {
    	    p[x] = x;
    	    rank[x] = 0;
    	}
    	
    	bool same(int x, int y) {
	    	return findSet(x) == findSet(y);
	    }
	    
	    void unite(int x, int y) {
    		link(findSet(x), findSet(y));
    	}
    	
    	void link(int x, int y) {
	    	if(rank[x] > rank[y]) {
	    		p[y] = x;
	    	} else {
	    		p[x] = y;
	    		if(rank[x] == rank[y]) {
		    		rank[y]++;
		    	}
	    	}
	    }
	    
	    int findSet(int x) {
    		if(x != p[x]) {
		    	p[x] = findSet(p[x]);
		    }
		    return p[x];
    	}
};

class Edge {
	public:
	int source, target, cost;
	Edge(int source = 0, int target = 0, int cost = 0):
	source(source), target(target), cost(cost) {}
	bool operator < (const Edge &e) const {
		return cost < e.cost;
	}
};

int kruskal(int N, vector<Edge> edges) {
	int totalCost = 0;
	sort(edges.begin(), edges.end());
	
	DisjointSet dset = DisjointSet(N + 1);
	
	for(int i = 0; i < N; i++) dset.makeSet(i);
	
	int source, target;
	for(int i = 0; i < edges.size(); i++) {
		Edge e = edges[i];
		if(!dset.same(e.source, e.target)) {
			totalCost += e.cost;
			dset.unite(e.source, e.target);
		}
	}
	return totalCost;
}

int main() {
	int N, M, cost;
	int source, target;
	
	cin >> N >> M;
	
	vector<Edge> edges;
	for(int i = 0; i < M; i++) {
		cin >> source >> target >> cost;
		edges.push_back(Edge(source, target, cost));
	} 
	
	cout << kruskal(N, edges) << endl;
	
	return 0;
}

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

int main() {
    int D;
    cin >> D;
    if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
    else if (D == 23) cout << "Christmas Eve Eve" << endl;
    else if (D == 24) cout << "Christmas Eve" << endl;
    else if (D == 25) cout << "Christmas" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> c(1e5,0);
  for(int i = 0; i < n; i++){
    cin>>a[i];
    a[i]--;
    c[a[i]]++;
  }
  int cnt1 = 0;
  int cnt2 = 0;
  for(int i = 0; i < 1e5; i++)
  {
    if(c[i]!=0){
      if(c[i]%2==1) cnt1++;
      else cnt2++;
    }
  }
  cout<<cnt2/2*2+cnt1<<endl;
  
  return 0;
}


Measured memory_bytes: 1024
A,B,C,X,Y = map(int,input().split())

ans = float("inf")
AB = max(X,Y)
for i in range(2*AB+1):
    if X-i//2>=0 and Y-i//2>=0:
        ans = min(A*(X-i//2)+B*(Y-i//2)+C*i,ans)
    elif X-i//2<0 and Y-i//2>=0:
        ans = min(B*(Y-i//2)+C*i,ans)
    elif X-i//2>=0 and Y-i//2<0:
        ans = min(A*(X-i//2)+C*i,ans)
print(ans)

Measured memory_bytes: 39664
// -*- coding: utf-8 -*-
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskB solver = new TaskB();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskB {    
    int n;
    int[] a;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      n = in.nextInt();
      a = new int[n];
      for (int i= 0; i < n; ++i) {
        a[i] = in.nextInt();
      }
      Arrays.sort(a);
      long cnt = 0, acc = a[0];
      for (int i = 1; i < n; ++i) {
        if (2 * acc >= a[i]) {
          ++cnt;
        } else {
          cnt = 0;
        }
        acc += a[i];
      }
      ++cnt;
      out.println(cnt);
    }
    
    int i(long x) {
      return (int) x;
    }
    
    <T> void heapsort(T[] a, int s, int e) {
      Queue<T> queue = new PriorityQueue<>();
      for (int i = s; i <= e; ++i)
        queue.add(a[i]);
      for (int i = s; i <= e; ++i)
        a[i] = queue.poll();
    }    
    
  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N;
ll A[202020];
ll i, j, k;

int main(){
    scanf("%lld", &N);
    rep(i,0,N){
        scanf("%lld", &A[i]);
    }
    sort(A, A + N);
    priority_queue<ll> pq;
    pq.push(A[N - 1]);
    ll ans = 0;
    rep(i,1,N){
        ll ii = N - 1 - i;
        ans += pq.top();
        pq.pop();
        pq.push(A[ii]);
        pq.push(A[ii]);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 6960
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    bool first = true;

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<pair<int, int>, string> > score(n);
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> score[i].second >> a >> b >> c;
            score[i].first.first = 3 * a + c;
            score[i].first.second = n-i;
        }

        sort(score.rbegin(), score.rend());
        if(first)
            first = false;
        else
            cout << endl;
        for(int i=0; i<n; ++i){
            cout << score[i].second << ',' << score[i].first.first << endl;
        }
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
	
int A,B,C;
int sum = 0;
int i;

scanf("%d %d %d",&A,&B,&C);
for(i=0;i<B;i++){
	sum += A;
	if(sum % B == C){
		printf("YES\n");
		return 0;
	}
}
printf("NO\n");

return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int h1 = sc.nextInt();
            int h2 = sc.nextInt();
            int k1 = sc.nextInt();
            int k2 = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();

            int hiroshi = h1 * a + (h1 / 10) * c + h2 * b + (h2 / 20) * d;
            int kenjiro = k1 * a + (k1 / 10) * c + k2 * b + (k2 / 20) * d;

            if ( hiroshi > kenjiro ) {
                System.out.println("hiroshi");
            } else if ( hiroshi < kenjiro ) {
                System.out.println("kenjiro");
            } else {
                System.out.println("even");
            }
        }
    }
}



Measured memory_bytes: 26232
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int W, H;
  while (cin >> W >> H, W) {
    vs v(H);
    rep(i, H) cin >> v[i];
    vvi dp(H, vi(W));
    int b = 0, w = 0;
    rep(i, H) rep(j, W) {
      dp[i][j] = 2 * (v[i][j] == 'B') + (v[i][j] == 'W');
      b -= v[i][j] == 'B';
      w -= v[i][j] == 'W';
    }
    rep(_, W * H) rep(i, H) rep(j, W) {
      if (v[i][j] != '.') continue;
      if (i > 0) dp[i][j] |= dp[i - 1][j];
      if (j > 0) dp[i][j] |= dp[i][j - 1];
      if (i < H - 1) dp[i][j] |= dp[i + 1][j];
      if (j < W - 1) dp[i][j] |= dp[i][j + 1];
    }
    rep(i, H) rep(j, W) {
      b += dp[i][j] == 2;
      w += dp[i][j] == 1;
    }
    cout << b << ' ' << w << endl;
  }
}

Measured memory_bytes: 3052
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
int ctoi(char a) {
	return (int)a - '0';
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[200001];
int bit[300000];
int b[200001];
int ma(int x) {
	int ma = 0;
	while (x > 0) {
		ma = max(ma, bit[x]);
		x -= x&-x;
	}
	return ma;
}
void add(int x, int y) {
	while (x <= n) {
		bit[x] = max(bit[x], y);
		x += x&-x;
	}
}
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++) {
		b[i] = i - ma(a[i]);
		add(a[i], i);
	}
	for (int i = 1; i < 300000; i++) {
		bit[i] = 0;
	}
	reverse(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		b[(n - i + 1)] *= i - ma(a[i]);
		add(a[i], i);
	}
	int sum = 0;
	for (int i = 1; i <= n; i++)
		sum += a[(n-i+1)]*b[i];
	cout << sum << endl;
	getchar(); getchar();
}

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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
template <class T>
void show(vector<T> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cerr << v[i] << " ";
    }
    cerr << "\n";
}
typedef long long ll;

typedef long long ll;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w,n;
    cin >> h >> w >> n;
    map<pair<int, int>, int> mp,mp2;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        mp[{a, b}]++;
    }
    vector<int> ans(10, 0);
    for (auto &u : mp)
    {
        pair<int, int> p = u.first;
        int x = p.first;
        int y = p.second;
        //cerr << p << endl;
        for (int dx = -2; dx <= 0; dx++)
        {
            for (int dy = -2; dy <=0; dy++)
            {
                int nx = x + dx;
                int ny = y + dy;
                if(nx<0 || nx>=h || ny<0 || ny>w){
                    continue;
                }
                if(nx+2>=h || ny+2>=w){
                    continue;
                }
                mp2[{nx, ny}]++;
            }
        }
        
    }
    for(auto & u :mp2){
        int x = u.second;
        ans[x]++;
    }
    int sum = 0;
    for (int i = 1; i < 10; i++)
    {
        sum += ans[i];
    }
    int maxzero = (h - 2) * (w - 2);
    ans[0] = maxzero - sum;
    for (int i = 0; i < 10; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 62720
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
ll n,m;
int main()
{
	cin>>n>>m;
	if(n==1&&m==1)cout<<1<<endl;
	else if(n==1)cout<<m-2<<endl;
	else if(m==1)cout<<n-2<<endl;
	else cout<<1ll*(n-2)*(m-2)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    s[3]='8';
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 1001000
using namespace std;
char s[N];
int r[N];
int p2fac[N];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	p2fac[1]=0;
	if(n==2){
		int tmp=abs(s[0]-s[1]);
		printf("%d\n",tmp);
		return 0;
	}
	for(int i=2;i<n;i++){
		p2fac[i]+=p2fac[i-1];
		for(int j=i;!(j&1);j>>=1){
			p2fac[i]++;
		}
	}
	int ans=0;
	for(int i=0;s[i];i++){
		if(s[i]=='1'||s[i]=='3'){
			if(p2fac[n-1]==p2fac[i]+p2fac[n-1-i]) ans^=1;
		}
	}
	if(ans==0){
		bool flag=true;
		for(int i=0;s[i];i++){
			if(s[i]=='2') flag=false;
		}
		if(flag){
			for(int i=0;s[i];i++){
				if(s[i]=='3'){
					if(p2fac[n-1]==p2fac[i]+p2fac[n-1-i]) ans^=2;
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7040
#include<stdio.h>

int main()
{
	int a[100];
	int x,i;
	scanf("%d",&x);
	for(i=0;i<x;i++){
		scanf("%d",&a[i]);
	}
	for(i=x-1;i>=1;i--){
		printf("%d ",a[i]);
	}
	 printf("%d\n",a[0]);
		return 0;
}

Measured memory_bytes: 596
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない



int main() {

	int n;
	ll ans = 1;
	cin >> n;
	int fac[1000] = {0};

	mrep(i, n, 1) {   //iをかける
		int sub = i;
		rep(j, 2, i+1) {  //因数jで割り続ける
			while (sub %j==0) {
					fac[j - 1]++;
					sub = sub / j;
			}
		}
	}

	rep(i, 1, n) {
		if(fac[i]!=0)ans = ans * (fac[i]+1) % 1000000007;
	}

	cout << ans << endl;

	cin >> ans;
	return 0;
}


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

int main(int argc, char const *argv[])
{
    int n,k;cin>>n>>k;
    double prob = 0;
    for(int i=1;i<=n;++i){
        if(i>=k){
            prob+=(1/(double)n)*(n-i+1);
            break;
        }
        else{
            int p =i;
            int num=1;
            while (true)
            {
                p*=2;
                if(p>=k)break;
                num++;
            }
            prob+=(double)(1/(double)n)*pow(0.5,num);
        }
    }
    cout << setprecision(10) << prob << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Mod[] mods = new Mod[m];
		for (int i = 0; i < m; i++) {
		    mods[i] = new Mod();
		}
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    mods[x % m].add(x);
		}
		int count = 0;
		for (int i = 1; i <= (m - 1) / 2; i++) {
		    int min = Math.min(mods[i].count, mods[m - i].count);
		    count += min;
		    mods[i].count -= min;
		    mods[m - i].count -= min;
		}
		if (m % 2 == 0) {
		    int min = mods[m / 2].count / 2;
		    count += min;
		    mods[m / 2].count -= min * 2;
		}
	    int min = mods[0].count / 2;
	    count += min;
	    mods[0].count -= min * 2;
		for (int i = 0; i < m; i++) {
		    count += mods[i].getPair();
		}
		System.out.println(count);
	}
	
	static class Mod {
	    int count;
	    HashMap<Integer, Integer> map = new HashMap<>();
	    
	    public void add(int x) {
	        count++;
	        if (map.containsKey(x)) {
	            map.put(x, map.get(x) + 1);
	        } else {
	            map.put(x, 1);
	        }
	    }
	    
	    public int getPair() {
	        int pair = 0;
	        for (int x : map.values()) {
	            if (x + pair * 2 > count) {
	                pair += (count - pair * 2) / 2;
	                break;
	            } else {
	                pair += x / 2;
	            }
	        }
	        return pair;
	    }
	}
}
	


Measured memory_bytes: 82792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

class Comb {
 public:
  Comb(int n) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= n; i++){
        fact[i] = fact[i-1] * i % kMod;
        inv[i] = kMod - inv[kMod%i] * (kMod / i) % kMod;
        finv[i] = finv[i-1] * inv[i] % kMod;
    }
  }

  LL nCr(int n, int r) const {
    LL numerator = fact[n];
    LL denominator = finv[r] * finv[n-r] % kMod;
    return (numerator * denominator) % kMod;
  }

 private :
  static constexpr int kMax = 2e5 + 5;
  LL fact[kMax];
  LL inv[kMax];
  LL finv[kMax];
};

int main() {
  LL n, k; std::cin >> n >> k;
  k = std::min(n-1, k);

  Comb c(n + 1);

  LL sum = 0;
  for (LL i = 0; i <= k; ++i) {
    LL item = (c.nCr(n, i) * c.nCr(n-1, n-i-1)) % kMod;
    sum = (sum + item) % kMod;
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 4992
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
int main(){
long long counter1,counter2;
counter1=0;
counter2=0;
long long counter3=0;
long long N;
cin>>N;
long long a[N];
vector<long long>b(N);
for (int i=0;i<N;i++){
cin>>a[i];
b.at(i)=abs(a[i]);
counter1+=abs(a[i]);
if(a[i]<0)
counter2++;}
if (counter2%2==0)
cout<<counter1<<endl;
else{
sort(b.begin(),b.end());
for (int i=1;i<N;i++){
counter3+=b[i];}
cout<<counter3-b.at(0)<<endl;}}




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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

bool c,f;
string s;

signed main() {
    cin >> s;
    rep(i,s.size()) {
        if (!c) {
            if (s[i] == 'C') c = true;
        }
        else {
            if (s[i] == 'F') f = true;
        }
    }
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
}












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

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

using namespace std;
using ll = long long;
typedef pair<int, int> Pair;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<pair<ll, ll>> f(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n, 1);
  return res;
}

int main() {
  ll a, b, g, ans = 0;
  cin >> a >> b;
  g = gcd(a, b);
  auto ff = f(g);
  ans = ff.size() + 1;
  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++)
typedef long long ll;
using namespace std;
#define m 1046527

vector<string> a(m,"0");

int getChar(char ch){
  if(ch=='A')return 1;
  if(ch=='C')return 2;
  if(ch=='G')return 3;
  if(ch=='T')return 4;
}
ll getKey(string str){
  ll sum=0,p=1;
  rep(i,str.length()){
    sum+=p*getChar(str[i]);
    p*=5;
  }
  return sum;
}

int h1(int key){
  return key%m;
}
int h2(int key){
  return 1+key%(m-1); //1足さなかったらゼロになって移動させられないかもしれない
}

int insert(string str){
  ll key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+h2(key)*i)%m;
    if(a[h]==str)return 1;
    else if(a[h]=="0"){
      a[h]=str;
      return 0;
    }
  }
  return 0;
}

int find(string str){
  ll key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%m;
      if(a[h]==str)return 1;
      else if(a[h]=="0")return 0;
  }
  return 0;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    string b;
    cin>>b;
    if(s=="insert")insert(b);
    else if(s=="find"){
      if(find(b))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 27092
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        long H = scan.nextLong();
        long W = scan.nextLong();
        long ans = 0;
        if(W == 1 || H == 1){
            os.println(1);
            return;
        }
        if(W%2 == 1) {
            if(H%2 == 1){
                ans = W*(H-1)/2 + (W+1)/2;
            } else {
                ans = W*H/2;
            }
        } else {
            ans = W/2*H;
        }

        os.println(ans);
    }


}

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

const int MAXN = 3e3 + 5;
double dp[MAXN][MAXN], p[MAXN];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> p[i];
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; i++) {
        for(int h = 0; h <= n; h++) {
            dp[i][h] = (1.0 - p[i])*dp[i - 1][h];
            if(h > 0)
                dp[i][h] += p[i]*dp[i - 1][h - 1];
        }
    }
    double ans = 0;
    for(int i = n/2 + 1; i <= n; i++)
        ans += dp[n][i];
    cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 70656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

// ================================================= //

/*
 update : [s,t)にxを加算する
 query : [s,t) の総和を出力する
 */
const ll INIT = 0;
struct SegTree {
    int N;
    ll init_v;
    vector<ll> node, lazy;
    
    SegTree(int _N):init_v(INIT) {
        N = 1;
        while (N < _N) N *= 2;
        node.resize(2 * N - 1, init_v);
        lazy.resize(2 * N - 1, init_v);
    }
    
    void lazy_evaluate(int k) {
        node[k] += lazy[k]; // add のため加算
        if (k < N - 1) {
            lazy[2 * k + 1] += lazy[k] / 2; // add のため加算
            lazy[2 * k + 2] += lazy[k] / 2;
        }
        lazy[k] = 0;
    }
    
    /* [a,b) 引数の範囲に注意!! s~tまでを更新→update(s,t+1,~) */
    ll update(int a, int b, int x) { return update(a, b, 0, 0, N, x); }
    ll update(int a, int b, int k, int l, int r, int x) {
        if (r <= a || b <= l) {
            lazy_evaluate(k); // nodeを参照する前には必ず更新
            return node[k];
        }
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x; // 参照区間が指定区間を完全に含んでいれば, 参照区間長*加算値分nodeに加算される
            lazy_evaluate(k);
            return node[k];
        }
        else {
            lazy_evaluate(k);
            ll vl = update(a, b, 2 * k + 1, l, (l + r) / 2, x);
            ll vr = update(a, b, 2 * k + 2, (l + r) / 2, r, x);
            return node[k] = vl + vr;
        }
    }
    
    /* [a,b) 引数の範囲に注意!! */
    ll query(int a, int b) { return query(a, b, 0, 0, N); }
    ll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init_v;
        if (a <= l && r <= b) {
            lazy_evaluate(k);
            return node[k];
        }
        else {
            lazy_evaluate(k);
            ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return vl + vr;
        }
    }
};


int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    
    SegTree ST(n);
//    BIT bit(n);
    while(q--){
        int com; cin >> com;
        if(com == 0){
            int s,t,x; cin >> s >> t >> x;
           ST.update(s-1,t,x);
        }else{
            int s,t; cin >> s >> t;
            cout << ST.query(s-1,t) <<endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 7000
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import IPython

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M = ds_in()
X_list = ds_in()
if N >= M:
    print(0)
    exit()

X_list.sort()
diff = [X_list[i+1] - X_list[i] for i in range(M-1)]

diff.sort()
print(sum(diff[:M-N]))


Measured memory_bytes: 13948
x,y = map(int,input().split(" "))

def a(H,W):
    m = float('inf')
    def b(HH,WW):
        ww = WW//2
        return [HH*ww,HH*(WW-ww)]
    h = 1
    while h < H:
        Sa = h * W
        Sb,Sc = b(H-h,W)
        a = sorted([Sa,Sb,Sc])
        m = min(a[2]-a[0],m)
        Sb,Sc = b(W,H-h)
        a = sorted([Sa,Sb,Sc])
        m = min(a[2]-a[0],m)
        h += 1
    return m

print(min(a(x,y),a(y,x)))

Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%d", $a);
$input = explode(' ', trim(fgets(STDIN)));

$ans = 0;
$j_max = 10**6;
foreach ($input as $n) {
    if ($j_max >= $n) {
        $j_max = $n;
        $ans++;
    }
}
echo $ans;

Measured memory_bytes: 18932
import math
N=int(input())
ans=0
if N<105:
	print(0)
else:
	for i in range (105,N+1):
		tmp=[]
		if i%2==1:
			for j in range(1,int(math.sqrt(N)+1)):
				if i%j==0:
					tmp.append(j)
					tmp.append(i//j)
			if len(set(tmp))==8:
				ans+=1
	print(ans)

Measured memory_bytes: 3060
# C - Big Array
from operator import itemgetter
N, K = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]
S = 0
A.sort(key=itemgetter(0))

for i in range(N):
    S += A[i][1]
    if S >= K:
        print(A[i][0])
        exit()
    else:
        pass

Measured memory_bytes: 29096