akhauriyash/Code-Regression huggingface dataset:
/*B - Contest with Drinks Easy*/
#include <bits/stdc++.h>
using namespace std;

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

	long long tot = 0;
	long long costo;
	int bebidas;
	int tam;
	int pos;

	cin >> tam;

	vector <long long> tiempos(tam);

	for (int i = 0; i < tam; ++i){
		cin >> tiempos[i];
		tot += tiempos[i];
	}
	
	cin >> bebidas;

	for (int i = 0; i < bebidas; ++i)
	{
		cin >> pos >> costo;
		pos--;

		cout << tot - tiempos[pos] + costo << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
from scipy.special import comb

S = int(input())

sho = S // 3
ans = 1
S -= 5
if sho > 0:
    for i in range(1,sho):
        ans += comb(S, i, exact=True)
        S -= 2
    print(int(ans)%(10**9+7))
else:
    print(0)

Measured memory_bytes: 42268
/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define N 200000

int main() {
	static int aa[N];
	int n, i, j, x, s;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	ans = 0;
	x = s = 0;
	for (i = j = 0; i < n; i++) {
		while (j < n && (x ^ aa[j]) == s + aa[j]) {
			x ^= aa[j], s += aa[j];
			j++;
		}
		ans += j - i;
		x ^= aa[i], s -= aa[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 896
let solve c n m =
  let dp = Array.make_matrix (m + 1) (n + 1) max_int in
  for i = 1 to m do dp.(i).(0) <- 0 done;
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <-
        if j - c.(i-1) < 0 then dp.(i-1).(j)
        else
          let t = dp.(i).(j - c.(i-1)) + 1 in
          if t < dp.(i-1).(j) then t else dp.(i-1).(j)
    done
  done;
  dp.(m).(n)

let () =
  let n, m = Scanf.scanf "%d %d " (fun n m -> n, m) in
  let c = Array.init m (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  solve c n m |> Printf.printf "%d\n"

Measured memory_bytes: 10828
using System;
using System.Linq;

class p{
  static void Main(){
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int H = n[0];
    string[] C = new string[H];
    for(int i = 0; i < H; i++){
      C[i] = Console.ReadLine();
    }
    
    for(int i = 0; i < H; i++){
      Console.WriteLine(C[i]);
      Console.WriteLine(C[i]);
    }
  }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

const int MAX = 10000000;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/

/****** define variable start ******/
ll n, m;
vl a, b;
/******* define variable end *******/
// union by size + path having
struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};


int solve() {
	cin >> n >> m;
	a.resize(m);
	b.resize(m);
	UnionFind uf(n);
	map<pair<ll, ll>, bool> ma;
	REP(i, m){
		cin >> a[i] >> b[i];
		--a[i]; --b[i];
		if(ma[make_pair(min(a[i], b[i]), max(a[i], b[i]))]) continue;
		ma[make_pair(min(a[i], b[i]), max(a[i], b[i]))] = true;
		uf.unionSet(a[i], b[i]);
	}
	ll ans = 0;
	REP(i, n){
		ans = max(ans, uf.size(i));
	}
	cout << ans << endl;
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 20348
#include <stdio.h>

int main(void){
	char *v = "aiueo", c;
	scanf("%c", &c);
	int i = 0;
	while(v[i]){
		if(v[i++] == c){
			printf("vowel\n");
			return 0;
		}
	}
	printf("consonant\n");
	return 0;
}


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

static const int N = 1000;

int lcs(string X, string Y){
	int dp[N + 1][N + 1];
	int h = X.size();
	int w = Y.size();
	
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(X[i]==Y[j]){
				dp[i+1][j+1]=dp[i][j]+1;
			}
			else{
				dp[i+1][j+1]=max(dp[i+1][j], dp[i][j+1]);
			}
		}
	}
	return dp[h][w];
}



int main(void){

	int n;
	string s1, s2;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}

Measured memory_bytes: 7052
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D

// g++ -std=c++11 file_name.cpp
// ./file_name.out
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int) a.size())
typedef long long ll ;
const int MAXN = 5*1e5 + 10;
struct node {
    string s ;
    int score ;
    int index ;
} ;
node a[105] ;
bool compare(node x , node y){
    if(x.s == y.s) return x.score > y.score ;
    else return x.s < y.s ;
}
int main () {
    
    int N ;
    cin >> N ;
    for(int i =0 ; i < N ;i++)
    {
        string str ;int p ;
        cin >> str >> p ;
        a[i].s = str ;
        a[i].score = p ;
        a[i].index = i + 1;
    }
    sort(a , a+N , compare) ;
    for(int i = 0 ; i < N ;i++)
        cout<<a[i].index<<endl;
    
    return 0;
}


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

int main() {
  int X;
  cin >> X;
  long long sum = 0;
  int cnt = 0;
  while(true){
    cnt += 1;
    sum += cnt;
    if (X <= sum) {
      cout << cnt << endl;
      return 0;
    }
  }
}


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


int main()
{
	int n,x,t=0,l,cnt=1;
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;++i) {scanf("%d",&l);t+=l;if(t<=x) cnt++;}
	cout<<cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>

using namespace std;

string ans;

long long int N;

int b[100];

long long int FUNC(long long int M) {

	if (M == 0) { return 0; }

	long long int p;
	long long int num = 0;
	int count = 0; 
	if (M > 0) {
		num = 1; count = 1; p = 1;
		while (num < M) { p *= 4; count+=2; num += p; }
		b[count] = 1;
		return M - p;
	}
	else {
		num = -2; p = -2; count = 2;
		while (M < num) { p *= 4; count += 2; num += p; }
		b[count] = 1;
		return M - p;
	}
	return 0;
};

int main(void) {

	cin >> N;

	long long int K=N;

	do {
		K = FUNC(K);
		//cout << "K= " << K << endl;
	} while (K != 0);


	int i;
	for ( i = 99; i >= 0; i--) {
		if (b[i] != 0) { break; }
	}

	for (; i > 0; i--) {
		if (b[i] == 1) { ans += "1"; }
		else { ans += "0"; }
	}

	if (ans == "") { ans = "0"; }

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
list = []
keta = []
keta2 = []

for i in range(5) : 
    list.append(int(input()))
    
for i in range(5) : 
    a = str(list[i])
    keta.append(int(a[-1]))
    
    
# 0 は 10 に変更
for i in keta : 
    if i == 0 : keta2.append(int("10"))
    else : keta2.append(i)

    
# # minの位置を取得, 例外位置
# ex = keta2.index(min(keta2))


# minをリストから削除
sum = list.pop(keta2.index(min(keta2)))

num = 0

def ten(sel) : 
    global num
    if int(str(sel)[-1]) == 0 : num = sel
    else : 
        ten(sel+1)


for i in list : 
    if i == 0 : sum += i
    else : 
        ten(i)
        sum += num
        
print(sum)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int n;
int A, B, C;
struct Coordinates
{
    int map[40000];
    bool rever;
    Coordinates()
    {
        for (int i = 0; i < 40000; ++ i)
            map[i] = i;
        rever = false;
    }
    void reverse()
    {
        rever = !rever;
    } 
    int &operator [] (int a)
    {
        if (rever == true)
            return map[n - 1 - a];
        else
            return map[a];
    }
}X, Y;
Coordinates &x = X, &y = Y;
map <pair <int, int>, int > num;
bool flag = false;
pair <int, int> getCoorddinates(int a, int b)
{
    if (flag == false)
        return make_pair(x[a], y[b]);
    else
        return make_pair(y[b], x[a]);
}
int calc(pair <int, int> a)
{
    return ((long long) a.first * A + A + (long long) a.second * B + B) % C;
}
int &getNum(pair <int, int> a)
{
    if (num.find(a) != num.end())
        return num[a];
    else
        return num[a] = calc(a);
}
int getNum2(pair <int, int> a)
{
    if (num.find(a) != num.end())
        return num[a];
    else
        return calc(a);
}
void reflectHorizontal()
{
    x.reverse();
}
void reflectVertical()
{
    y.reverse();
}
void rotateLeft()
{
    flag = !flag;
    swap(x, y);
    x.reverse();
}
void rotateRight()
{
    flag = !flag;
    swap(x, y);
    y.reverse();
}
void swapColumn(int a, int b)
{
    swap(y[a], y[b]);
}
void swapRow(int a, int b)
{
    swap(x[a], x[b]);
}
char s[3];
int main()
{
    int q;
    scanf("%d%d", &n, &q);
    scanf("%d%d%d", &A, &B, &C);
    int D, E, F, G;
    scanf("%d%d%d%d", &D, &E, &F, &G);
    while (q --)
    {
        scanf("%s", s);
        if (strcmp(s, "WR") == 0)
        {
            int r, c, v;
            scanf("%d%d%d", &r, &c, &v);
            -- r;
            -- c;
            getNum(getCoorddinates(r, c)) = v;
        }
        else if (strcmp(s, "CP") == 0)
        {
            int r1, c1, r2, c2;
            scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
            -- r1;
            -- c1;
            -- r2;
            -- c2;
            getNum(getCoorddinates(r2, c2)) = getNum(getCoorddinates(r1, c1));
        }
        else if (strcmp(s, "SR") == 0)
        {
            int r1, r2;
            scanf("%d%d", &r1, &r2);
            -- r1;
            -- r2;
            swapRow(r1, r2);
        }
        else if (strcmp(s, "SC") == 0)
        {
            int c1, c2;
            scanf("%d%d", &c1, &c2);
            -- c1;
            -- c2;
            swapColumn(c1, c2);
        }
        else if (strcmp(s, "RL") == 0)
            rotateLeft();
        else if (strcmp(s, "RR") == 0)
            rotateRight();
        else if (strcmp(s, "RH") == 0)
            reflectHorizontal();
        else 
            reflectVertical();
//        for (int r = 0; r < n; ++ r, puts(""))
//            for (int c = 0; c < n; ++ c)
//                printf("%d ", getNum2(getCoorddinates(r, c)));
    } 
    int h = 314159265;
    for (int r = D - 1; r < E; ++ r)
        for (int c = F - 1; c < G; ++ c)
            h = ((long long) h * 31 + getNum2(getCoorddinates(r, c))) % 1000000007;
    printf("%d\n", h);
    return 0;
}

Measured memory_bytes: 2464
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,K;cin>>A>>B>>K;
  vector<int> a;
  for(int i=1;i<=min(A,B);i++)
    if(A%i==0 && B%i==0)a.push_back(i);
  cout<<a.at(a.size()-K);
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,m,n,p;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a>b) m=a-b;
    else m=b-a;
    if(b>c)n=b-c;
    else n=c-b;
    if(a>c) p=a-c;
    else p=c-a;
    if(m<=d && n<=d || p<=d) printf("Yes\n");
    else printf("No\n");
    return 0;

}



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

int main()
{
    int h, w, distance[2704]{}, block_num{}, goal;
    bool is_block[2704]{};
    std::fill(distance, distance + 2704, 10000);
    scanf("%d%d", &h, &w);
    goal = (w + 2) * (h + 1) - 2;
    for (int i = 0; i <= h + 1; i++)
        is_block[i * (w + 2)] = is_block[(i + 1) * (w + 2) - 1] = true;
    for (int i = 0; i <= w + 1; i++)
        is_block[i] = is_block[(h + 1) * (w + 2) + i] = true;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            char tmp;
            scanf(" %c", &tmp);
            is_block[i * (w + 2) + j] = (tmp == '#');
            block_num += (tmp == '#');
        }
    }
    distance[w + 3] = 0;
    std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> que;
    que.push({0, w + 3});

    while (!que.empty())
    {
        auto here = que.top();
        que.pop();
        if (is_block[here.second])
            continue;
        is_block[here.second] = true;
        distance[here.second] = here.first;
        if (here.second == goal)
            break;
        if (!is_block[here.second + 1])
            que.push({here.first + 1, here.second + 1});
        if (!is_block[here.second - 1])
            que.push({here.first + 1, here.second - 1});
        if (!is_block[here.second + w + 2])
            que.push({here.first + 1, here.second + w + 2});
        if (!is_block[here.second - w - 2])
            que.push({here.first + 1, here.second - w - 2});
    }

    if (distance[goal] == 10000)
        printf("-1\n");
    else
        printf("%d\n", w * h - block_num - distance[goal] - 1);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int n;
    cin >> n;
    cout << 180*(n-2) << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> f(1000000, 1);
    f[0] = 0;
    f[1] = 0;
    for (int i = 2; i < 1000000; i++) {
        if (f[i]) {
            for (int j = i + i; j < 1000000; j += i) {
                f[j] = 0;
            }
        }
    }
    int x;
    cin >> x;
    for (int i = x; i < 1000000; i++) {
        if (f[i]) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4224
import java.util.Scanner;

/**
 * @author yousack
 */
public class Main {
    static Scanner in = new Scanner(System.in);
    static int[] answerTable = new int[1001];
    
    public static void main(String[] args) {
        for (int i = 1; i <= 499; i++) {
            for (int j = i + 1; j <= 500; j++) {
                int sum = (i + j) * (j - i + 1) / 2;
                if (sum <= 1000) {
                    answerTable[sum]++;
                }
            }
        }

        while (true) {
            int n = in.nextInt();
            if (n == 0) {
                break;
            } else {
                solve(n);
            }
        }
    }
    
    public static void solve(int n) {
        System.out.println(answerTable[n]);
    }
}

Measured memory_bytes: 19828
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n,m;
vector<vector<int>>v(200005);
bool visited[200005];
int e=0;
void dfs(int node)
{

    if(!visited[node])
    {
        e++;
        visited[node]=1;
        for(int i=0; i<v[node].size(); i++)
            dfs(v[node][i]);
    }
}
int main()
{
    fast
    cin>>n>>m;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
        int mx=0;
    for(int i=1; i<=n; i++)
    {
        if(!visited[i])
        {
            dfs(i);
            mx=max(mx,e);
            e=0;
        }
    }
    cout<<mx;



    return 0;
}


Measured memory_bytes: 20564
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
typedef pair<int,int> P;

int main(){
    int a;
    cin>>a;
    int s[4]={a/1000,a/100%10,a/10%10,a%10};
    for(int bit=0;bit<(1<<3);bit++){
        int count=s[0];
        for(int i=0;i<3;i++){
            if(bit & (1<<i)){
                count+=s[i+1];
            }else {
                count-=s[i+1];
            }
        }
        if(count==7){
            for(int i=0;i<3;i++){
                cout<<s[i];
                if(bit & 1<<i){
                    cout<<"+";
                }else{
                    cout<<"-";
                }
            }
            cout<<s[3];
            break;
        }
    }
    cout<<"=7"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
    char target;
    char big = 'A';
    char small = 'a';
    int big_e = 90;
    int small_s = 97;

    scanf("%c", &target);

    if (target <= big_e)
    {
        printf("%c", big);
    } else {
        printf("%c", small);
    }

    return 0;
}

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

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

map<i64, int> primeFactorize(i64 n) { // {{{
    map<i64, int> ret;
    for (i64 i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            ++ret[i];
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
} // }}}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    var(i64, a, b);
    vector<i64> a_prime, b_prime;
    for (auto &e : primeFactorize(a)) a_prime.emplace_back(e.first);
    for (auto &e : primeFactorize(b)) b_prime.emplace_back(e.first);
    i64 res = 1;
    rep(i, a_prime.size()) rep(j, b_prime.size()) {
        if (a_prime[i] == b_prime[j]) ++res;
    }
    outl(res);
    return 0;
}


Measured memory_bytes: 256
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 pow2[] = new int[30];
    pow2[0] = 1;
    for (int i = 1; i < 30; i++) {
      pow2[i] = 2 * pow2[i - 1];
    }

    int ans=0;
    for(int i=0;i<N;i++) {
      int ai=Integer.parseInt(sc.next());;
      for(int j=1;j<30;j++) {
        if(ai%pow2[j]!=0) {
          ans+=j-1;
          break;
        } else if(j==29) {
          ans+=29;
          break;
        }
      }
    }
    
    System.out.println(ans);
  }
}

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

//abc-164
//c-gacha
int main() {
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    //vectorから重複を消すアルゴリズム
    //引用:uniqueは隣接する重複要素を削除するがvectorの長さは変更されないため、末尾にゴミが残る
    //なのでsortをして予めvectorをソートしておき、末尾のゴミを削除する
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    cout << s.size() << endl;
}

Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
//#define push push_back
//#define endl cout << "\n"
typedef long long ll;
int main(){ 
	map<string, int> m;
	int t;
	cin >> t;
	string s;
	while(t--){
		cin >> s;
		m[s]++;
	}
   cout << "AC x " << m["AC"] << endl;
   cout << "WA x " << m["WA"] << endl;
   cout << "TLE x " << m["TLE"] << endl;
   cout << "RE x " << m["RE"] << endl;
   bye;
}
 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
	cin >> n;
	std::vector<int> p(n);
	rep(i,n) cin >> p[i];

	int ans = 0;
	FOR(i,1,n-1){
		if(p[i-1] < p[i] && p[i] < p[i+1]){
			ans++;
		}else if(p[i-1] > p[i] && p[i] > p[i+1]){
			ans++;
		}
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
R0とL0がそれぞれ存在して、＋－が打ち消しあえばよさそう
+++----
0のやつが互いに端にならぶ
どちらも0でない、はありうるか
はじからスタートして、最小値がマイナスになったらOUT
0のやつの総和を、調整できないやつが超えてもOUT
((() (()((( (((     )))((()))(((    )))() (())) )))
0の余力　　　　　　　　ちょうど分ける？　　　　　　余力

))(  )))))(   )((((((
*/
int main(){
  ll N; cin>>N;
  vector<ll> R(N,0), L(N,0);
  for(ll i=0; i<N; i++){
    string S; cin>>S;
    ll sz=S.size(), tmp=0, left=0, right=0;
    for(ll j=0; j<sz; j++){//)のあぶれ数
      if(S[j]=='(') tmp++;
      else{
        tmp--;
        left=min(left,tmp);
      }
    }
    L[i]=left;
    tmp=0;
    for(ll j=sz-1; j>=0; j--){//(のあぶれ数
      if(S[j]==')') tmp++;
      else{
        tmp--;
        right=min(right,tmp);
      }
    }
    R[i]=right;
  }
  ll L0=0, L1=0, R0=0, R1=0, Lmin=-1e8, Rmin=-1e8;
  for(ll i=0; i<N; i++){
    if(L[i]==0) L0+=R[i];//余力
    else{
      if(R[i]!=0) Lmin=max(Lmin,L[i]);//外側にのこるであろう？
      L1+=L[i]-R[i];
    }
  }
  if(Lmin==-1e8) Lmin=0;
  Lmin=min(Lmin,L1);//耐えるべき攻撃

  for(ll i=0; i<N; i++){
    if(R[i]==0) R0+=L[i];//余力
    else{
      if(L[i]!=0) Rmin=max(Rmin,R[i]);//外側にのこるであろう？
      R1+=R[i]-L[i];
    }
  }
  if(Rmin==-1e8) Rmin=0;
  Rmin=min(Rmin,R1);//耐えるべき攻撃
  if(L0==Lmin && R0==Rmin) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 18748
n, q = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ans = n+1
sum = 0
l = 0
r = 0
while l < n
  if l == r then
    sum = a[r]
    r += 1
  else
    if sum >= q then
      sum -= a[l]
      l += 1
    elsif r < n then
      sum += a[r]
      r += 1
    else
      break
    end
  end
  ans = r - l if sum >= q && ans > r - l 
end
if ans <= n
  puts ans
else
  puts 0
end

Measured memory_bytes: 14220
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
  int x=0,y=0,z=0,w=0;
  std::cin >> x>>y>>z;
  for(int i=y;i<=z;i++){
    if(x%i==0)w++;
  }
  std::cout << w << '\n';
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    bool d = true;
    int l = 0, r = 0;
    int res = 0;
    while (n--) {
      string s; cin >> s;
      if (s[0] == 'l') l = 1 - l;
      else r = 1 - r;
      if (d and l + r == 2) {
        ++res;
        d = false;
      } else if (!d and l + r == 0) {
        ++res;
        d = true;
      }
    }
    cout << res << '\n';
  }
}


Measured memory_bytes: 3232
k,n = map(int,input().split())
al = list(map(int,input().split()))

al = sorted(al)

ans = 0

for i in range(n-1):
    ans = max(ans, al[i+1]-al[i])

ans = max(al[0] + (k - al[-1]) , ans)

print(k-ans)

Measured memory_bytes: 78540
using System;
using System.Linq;

namespace Search
{
    class Linear_Search
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var S = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Console.ReadLine();
            var T = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var C = Count(S, T);
            Console.WriteLine(C);
        }

        public static int Count(int[] S,int[] T)
        {
            var C = 0;
            for (int i = 0; i < T.Length; i++)
                for (int j = 0; j < S.Length; j++)
                    if(T[i]==S[j])
                    {
                        C++;
                        break;
                    }
            return C;
        }
    }
}

Measured memory_bytes: 10212
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static boolean ch(ArrayList<Integer> l,int num) {
		boolean flag = true;
		for(int i = 0; i < l.size();i++) {
			if(num%l.get(i)==0) {
				flag = false;
				break;
			}
		}
		return flag;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> intList = new ArrayList<Integer>();
		intList.add(2);
		int ans = 3;
		if(N==2) {
			System.out.println(2);
		}else {
			while(true) {
				boolean d = ch(intList,ans);
				if(d == true) {
					if(ans>=N) {
						System.out.println(ans);
						break;
					}else {
						intList.add(ans);
					}
				}
              ans = ans + 2;
			}
		}


	}

}


Measured memory_bytes: 21844
#include <stdio.h>
#define N 200002

int a[N] = {0}, b[N] = {0};

int read()
{
	char c;
	while((c = getchar()) < 48 || c > 57);
	int x = c - 48;
	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;
	return x;
}

int main()
{		
	int n, k, i, c = 0, t, ans = 0;
	
	n = read(), k = read();
	for(i = 0; i < n; i++){
		a[read()]++;
	}
	for(i = 1; i <= n; i++){
		if(t = a[i]) b[t]++, c++;
	}
	if(c <= k) puts("0");
	else{
		c -= k;
		for(i = 1; i <= n; i++){
			if(t = b[i]){
				if(c > t) c -= t, ans += t * i;
				else{
					ans += c * i;
					c = 0;
					break;
				}
			}
		}
		printf("%d\n", ans);
	}
				
	return 0;
}

Measured memory_bytes: 2372
import java.io.*;

class Main {
	public static void main(String[] args){
		BufferedReader br = null;
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[] count = new int[26];
		String str = null;
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			while((str = br.readLine()) != null){
				for(int i = 0; i < str.length(); i++){
					final char ch = str.charAt(i);
					if('A' <= ch && ch  <= 'Z'){
						count[ch - 'A']++;
					} else if('a' <= ch && ch <= 'z'){
						count[ch - 'a']++;
					} else {}
				}
			}

			for(int i = 0; i < count.length; i++){
				sb.append(String.valueOf((char)('a'+i))).append(" : ").append(count[i]).append(lb);
			}
			System.out.print(sb.toString());

		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(br != null){
					br.close();
				}
			} catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
}

Measured memory_bytes: 17004
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ull H,W; cin>>H>>W;
    if(H==1||W==1) cout<<1<<endl; 
    else if(H%2==1&&W%2==1) cout<<(H*W+1)/2<<endl;
    else cout<<H*W/2<<endl;
}

Measured memory_bytes: 256
while True :
    n=int(input())
    if n==0:break
    ssum=0
    smax=0
    smin=1000
    for i in range(n):
        s=int(input())
        ssum+=s
        if smax<s : smax=s
        if smin>s : smin=s
    print((ssum-smax-smin)//(n-2))


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

#define all(x) (x).begin(), (x).end()
#define itn int
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

struct Path {
	vector<pair<int, int>> p;
	int alpsz;

	int len() const {
		int ans = 0;
		for (const auto& pp : p) {
			ans += pp.second;
		}
		return ans;
	}

	int last() const {
		return p.back().first;
	}

	void elongate(int x, int cnt) {
		if (!p.empty() && x == p.back().first) {
			p.back().second += cnt;
		} else {
			p.push_back({x, cnt});
		}
	}

	bool transform(int size) {
		int cur = len();
		if (cur < size) {
			elongate(0, size - cur);
		} else {
			while (cur - p.back().second >= size) {
				cur -= p.back().second;
				p.pop_back();
			}
			p.back().second = size - (cur - p.back().second);

			while (!p.empty() && p.back().first == alpsz - 1) {
				p.pop_back();
			}
			if (p.empty()) {
				return false;
			}
			int x = p.back().first + 1;
			p.back().second -= 1;
			if (p.back().second == 0) {
				p.pop_back();
			}
			elongate(x, 1);
			elongate(0, size - len());
		}
		return true;
	}
};

int main() {
	int n = nxt();
	vector<itn> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}
	int l = 0, r = n;
	while (r > l + 1) {
		int m = (l + r) / 2;
		bool ok = true;
		Path path;
		path.alpsz = m;
		for (int i = 0; i < n; ++i) {
			if (!path.transform(a[i])) {
				ok = false;
				break;
			}
		}
		if (ok) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << r << "\n";

	return 0;
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

w, h, n = map(int, readline().split())
xya = [list(map(int, readline().split())) for i in range(n)]
ans = [[0, w], [0, h]]
for x, y, a in xya:
    if a == 1 and ans[0][0] < x:
        ans[0][0] = x
    elif a == 2 and ans[0][1] > x:
        ans[0][1] = x
    elif a == 3 and ans[1][0] < y:
        ans[1][0] = y
    elif a == 4 and ans[1][1] > y:
        ans[1][1] = y
if ans[0][0] > ans[0][1] or ans[1][0] > ans[1][1]:
    print(0)
else:
    print((ans[0][1] - ans[0][0]) * (ans[1][1] - ans[1][0]))


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int index = 0;
        while(index < s.length()){
            char c = s.charAt(index);
            if(c == 'd'){
                if(index + 5 > s.length()){
                    break;
                }
                if(index+7 < s.length() && (s.charAt(index+7) != 'a') || index+7 == s.length()){
                    if(s.substring(index,index+7).equals("dreamer")){
                        index += 7;
                    }else{
                        if(s.substring(index,index+5).equals("dream")){
                            index += 5;
                        }else{
                            break;
                        }
                    }
                }else{
                    if(s.substring(index,index+5).equals("dream")){
                        index += 5;
                    }else{
                        break;
                    }
                }
            }else if(c == 'e'){
                if(index + 5 > s.length()){
                    break;
                }
                if(index + 5 == s.length() || s.charAt(index+5) != 'r'){
                    if(s.substring(index,index+5).equals("erase")){
                        index += 5;
                    }else{
                        break;
                    }
                }else{
                    if(s.substring(index,index+6).equals("eraser")){
                        index += 6;
                    }else{
                        break;
                    }
                }
            }else{
                break;
            }
        }
        System.out.println(index == s.length() ? "YES" : "NO");
    }
}


Measured memory_bytes: 27604
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define iii tuple<int, int, int>
#define int long long
using namespace std;

const int INF = 1e18;
int sum1[100005];
int sum2[100005];
int val[2];

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

//    freopen("depart.inp", "r", stdin);
//    freopen("depart.out", "w", stdout);

    string s, t;
    cin >> s >> t;

    val[0] = 1;
    val[1] = -1;

    for (int i = 1; i <= s.size(); i++)
        sum1[i] = sum1[i-1] + val[s[i-1] - 'A'];
    for (int i = 1; i <= t.size(); i++)
        sum2[i] = sum2[i-1] + val[t[i-1] - 'A'];



    int q;
    cin >> q;
    while (q--)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x = sum1[b] - sum1[a-1];
        int y = sum2[d] - sum2[c-1];
        if (x < 0)
            x = x % 3 + 3;
        if (y < 0)
            y = y % 3 + 3;
        if (x%3 == y%3)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}


Measured memory_bytes: 5348
#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 n, k;
  cin >> n >> k;

  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    ll w = n % k;
    ll x = abs(w-k);
    ll y = abs(abs(w-k)-k);
    cout << min(x, y) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[],int n,int g){
	for(int i=g;i<n;i++){
		int v = A[i];
		int j= i-g;
		while(j>=0 && A[j] > v){
			A[j+g]=A[j];
			j -= g;
			cnt++;
		}
		A[j+g]=v;
	}
}


void shellsort(int A[],int n){
	for(int h=1;;){
		if(h>n)break;
		G.push_back(h);
		h = 3*h+1;
	}
	
	for(int i=G.size()-1;i>=0;i--){
		insertionSort(A,n,G[i]);
	}
}


int main(){
	cin >> n;
	
	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	cnt=0;
	
	shellsort(A,n);
	
	cout << G.size() << endl;
	for(int i=G.size()-1;i>=0;i--){
		printf("%d",G[i]);
		if(i)printf(" ");
	}
	
	printf("\n");
	
	printf("%d\n",cnt);
	
	for(int i=0;i<n;i++){
		printf("%d\n",A[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 7148
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long N, std::vector<long long> A);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
}

void solve(long long N, std::vector<long long> A){
    ll mx = *max_element(ALL(A));
    vec<int> memo(mx+1);
    REP(i, N){
        for(int j=1; j<=mx/A[i]; j++){
            memo[A[i]*j]++;
        }
    }
    ll cnt = 0;
    REP(i, N){
        if(memo[A[i]] == 1){
            cnt++;
        }
    }
    cout << cnt << el;
}



Measured memory_bytes: 8692
n,q=map(int,input().split())
if n==1:
    for i in range(q):
        v,w=map(int,input().split())
        print(min(v,w))
else:
    for i in range(q):
        v,w=map(int,input().split())
        while v!=w:
            if v>w:v,w=w,v
            w=(w+n-2)//n
        print(v)


Measured memory_bytes: 49944
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 300 + 9;
const ll inf = 1e6 + 7;
typedef pair<ll,ll> LL;

ll t,n,a[N],i,j;
string s;
bool chk(){
    vector<ll> v;
    v.push_back(0);
    for (i = n;i >= 1;i--){
        ll p = a[i];
        for (auto j : v) p = min(p,p^j);
        if (p){
            if (s[i] == '1') return true;
            v.push_back(p);
        }
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>t;
    while(t--){
        cin>>n;
        for (i = 1;i <= n;i++) cin>>a[i];
        cin>>s; s = " " + s;
        cout<<chk()<<"\n";
    }
}


Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
#define ll long long int
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    ll b, n, a;
    while (cin >> b, b)
    {
        n = a = 0;
        rep(i, (int)sqrt(b) + 2)
        {
            if (2 * b % (i + 1) == 0)
            {
                n = i + 1;
            }
        }
        n = 1e5;
        while (n > 0)
        {
            if ((2 * b) % n == 0)
                a = (((2 * b / n) - n + 1));
            if (a % 2 == 0 && a >= 1)
            {
                break;
            }
            n = n - 1;
        }
        cout << a / 2 << " " << n << endl;
    }

    return 0;
}



Measured memory_bytes: 3052
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

typedef long long int ll;

int MAX(int a, int b){return a>b?a:b;}
int MIN(int a, int b){return a>b?b:a;}
int compare(const void* a, const void* b){return *(int*)a - *(int*)b;}
ll llMAX(ll a, ll b){return a>b?a:b;}
ll llMIN(ll a, ll b){return a>b?b:a;}
ll digits(ll a){ll tmp=a; ll cnt=0; while(tmp>0){tmp/=10; cnt+=1;} return cnt;}

int main(void){
    int n;
    scanf("%d", &n);
    char s[n][51];
    for(int i=0; i<n; i++){scanf("%s", s[i]);}

    int alpha[n][26];
    for(int i=0; i<n; i++){
        int s_len = strlen(s[i]);
        for(int j=0; j<26; j++){
            alpha[i][j] = 0;
        }
        for(int j=0; j<s_len; j++){
            alpha[i][s[i][j]-'a'] += 1;
        }
    }

    for(int i=0; i<26; i++){
        char c = i+97;

        int min = 2501;
        for(int j=0; j<n; j++){
            min = MIN(min, alpha[j][i]);
        }

        for(int j=0; j<min; j++){
            putchar(c);
        }
    }

    printf("\n");

    return 0;
}

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

const int maxn = 1000010;
int n, suf[maxn];
char s[maxn];

int main() {
    scanf("%s", s + 1), n = strlen(s + 1);
    int mx = 0;
    for (int i = 1, cur = 0; i <= n; i++) {
        if (s[i] ^ '1') cur++;
        else mx = min(mx, --cur);
    }
    auto chk = [&](int x) {
        for (int i = n; i; i--) {
            suf[i] = min(0, suf[i + 1] + (s[i] ^ '1' ? 1 : -1));
        }
        int y = 0;
        for (int i = 1, cur = 0; i <= n; i++) {
            if (s[i] == '0') cur++;
            else if (s[i] == '1') cur--;
            else if (cur - 1 + suf[i + 1] >= x) cur--;
            else cur++;
            y = max(y, cur);
        }
        return y - x;
    };
    printf("%d\n", min(chk(mx), chk(mx - 1)));
    return 0;
}

Measured memory_bytes: 8700
#include <iostream>

using namespace std;

typedef long long ll;

ll modulo = 1e9+7;

ll fact(ll n){
  ll ans = 1;
  for(int i = 1;i <= n;i++){
	ans = (ans * i) % modulo;
  }
  return ans;
}

//algoritmul lui Euclid extins
ll cmmdc(ll a, ll b, ll &x, ll &y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    ll xPrim, yPrim;
    ll ans = cmmdc(b, a % b, xPrim, yPrim);
    x = yPrim % modulo;
    y = (xPrim - (a / b) * yPrim) % modulo;
    return ans;
  }
}

ll getj(ll n, ll m, ll i) {
  ll dn = n - i;
  ll dm = 2 * i - m;
  if(dn == dm && 0 <= dn && dn <= i) {
	return dn;
  } else {
	return -1;
  }
}

int main()
{
  ll n, m, i, j, facti, factj, factij;
  cin >> n >> m;
  if((n + m) % 3 == 0){
    i = (n + m) / 3;
    j = getj(n, m, i);
    if(j == -1){
      cout << 0;
      return 0;
    }
    facti = fact(i);
    factj = fact(j);
    factij = fact(i - j);
    ll x, y, ans;
    ans = cmmdc((factj * factij) % modulo, modulo, x, y);
    x = x % modulo;
    if(x < 0){
      x = x + modulo;
    }
    cout << (facti * x) % modulo;
  }else{
	cout << 0;
  }
  return 0;
}


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

using namespace std;

bool cmp(int x,int y) {
	return x>y;
}

int main () {
	int n;
	cin >> n;
	int a[100005];
	for (int i=1;i<=n;i++) cin >> a[i];
	a[0]=-1;
	sort (a+1,a+n+1);
	int ans=0;
	for (int i=1;i<=n;i++) {
		int cnt=0;
		if (a[i]==a[i-1]) continue;
		for (int j=i;j<=n;j++) {
			if (a[j]>a[i]+2) break;
			else cnt++;
		}
		ans=max(ans,cnt);
	}
	sort (a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++) {
		int cnt=0;
		if (a[i]==a[i-1]) continue;
		for (int j=i;j<=n;j++) {
			if (a[i]>a[j]+2) break;
			else cnt++;
		}
		ans=max(ans,cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var n =Console.ReadLine().Split(' ').Select(s => int.Parse(s)).Distinct().Count();
            Console.WriteLine(n);
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine()   { return Console.ReadLine(); }
        public int    ReadInt()    { return int.Parse(Read()); }
        public long   ReadLong()   { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
    }

    public class MyUtility
    {
        /// <summary>2値を入れ替える</summary>
        public static void Swap<T>(ref T m, ref T n)
        {
            T tmp = m;
            m = n;
            n = tmp;
        }

        public static void PutYN(bool f)
        {
        	Console.WriteLine(f ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 13280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans;
int n;
ll a[5];

int main(){

  cin>>n;

  for(int i=0;i<n;i++){
    char s[100];
    cin>>s;
    if(s[0]=='M') a[0]++;
    if(s[0]=='A') a[1]++;
    if(s[0]=='R') a[2]++;
    if(s[0]=='C') a[3]++;
    if(s[0]=='H') a[4]++;
  }
  
  for(int i=0;i<5;i++)
    for(int j=i+1;j<5;j++)
      for(int k=j+1;k<5;k++)
        ans+=a[i]*a[j]*a[k];


  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
w = []
v = []
sum_value = 0
inf = 10**9 + 1
for _ in range(N):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
    sum_value += v_

"""
dp[n][i]: n個目までの品物から価値の総量がiよりも大きくなるように選択したときの, 重さの最小値
"""

dp = [[inf] * (sum_value+1) for _ in range(N+1)]
dp[0][0] = 0


for n in range(1, N+1):
    for i in range(sum_value+1):
        if i >= v[n-1]:
            dp[n][i] = min(dp[n-1][i], dp[n-1][i-v[n-1]] + w[n-1])
        else:
            dp[n][i] = dp[n-1][i]
for i in range(sum_value+1)[::-1]:
    if dp[N][i] != inf and dp[N][i] <= W:
        print(i)
        break


Measured memory_bytes: 119916