akhauriyash/Code-Regression huggingface dataset:
// 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 forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
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 ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

std::vector<std::string> split(const std::string &s, const std::string &delim) {
  using string = std::string;
  std::vector<string> v;
  string::size_type pos = 0;
  while (pos != string::npos) {
    string::size_type p = s.find(delim, pos);
    if (p == string::npos) {
      v.push_back(s.substr(pos));
      break;
    }
    v.push_back(s.substr(pos, p - pos));
    pos = p + delim.size();
  }
  return v;
}

template<typename InputIterator> std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

main {
  vi dx = {1, -1, 4, -4};
  map<string, int> m;
  queue<string> q;
  q.emplace("01234567");
  while (q.size()) {
    string s = q.front();
    q.pop();
    int pos = distance(s.begin(), find(all(s), '0'));
    rep(i, 4) {
      if (pos + dx[i] < 0 || pos + dx[i] >= 8 || (i / 2 == 0 && pos / 4 != (pos + dx[i]) / 4)) continue;
      string t = s;
      swap(t[pos], t[pos + dx[i]]);
      if (m.count(t)) continue;
      q.emplace(t);
      m[t] = m[s] + 1;
    }
  }
  string s;
  while (getline(cin, s)) {
    auto x = split(s, " ");
    cout << m[join(all(x), "")] << endl;
  }
}

Measured memory_bytes: 5332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

#define MAX 10
#define EPS 1e-6

int w[MAX];
long double rcost[MAX], lcost[MAX];
bool used[MAX];

long double r;
int n;
long double ans;

void dfs(int now, long double cost){
  if(n-1 == now){
    ans = max(ans, cost);
    return;
  }
  
  for(int i = 0 ; i < n ; i++){
    if(used[i]) continue;
    for(int j = 0 ; j < n ; j++){
      if(i == j || used[j]) continue;
      long double weight = w[i] + w[j];
      long double tmpr = max( (w[i] / weight) + rcost[j], (-w[j] / weight) + rcost[i]);
      long double tmpl = max( (w[j] / weight) + lcost[i], (-w[i] / weight) + lcost[j]);
      
      if(tmpr + tmpl > r+EPS) continue;
      
      long double tr = rcost[i], tl = lcost[i], tw = w[i];      
      rcost[i] = tmpr;
      lcost[i] = tmpl;
      w[i] += w[j];
      used[j] = true;
      
      dfs(now+1, tmpr+tmpl);
      // back track
      rcost[i] = tr;
      lcost[i] = tl;
      w[i] = tw;
      used[j] = false;
    }
  }
}

void init(){
  ans = -1.0;
  for(int i = 0 ; i < MAX ; i++) w[i] = rcost[i] = lcost[i] = used[i] = 0;
}

int main(){
  int tc;
  cin >> tc;
  while(tc--){
    init();
    cin >> r >> n;
    for(int i = 0 ; i < n ; i++) cin >> w[i];
    dfs(0, 0);
    cout << setprecision(16);
    if(ans == -1.0) cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1296
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final String S = sc.next();

        Set<String> set = new HashSet<>();
        for (int i = 0; i <= 9; i++) {
            final int idx = S.indexOf(String.valueOf(i));
            if (idx == -1) {
                continue;
            }
            for (int j = 0; j <= 9; j++) {
                final int jdx = S.substring(idx+1).indexOf(String.valueOf(j));
                if (jdx == -1) {
                    continue;
                }
                for (int k = idx+jdx+2; k < N; k++) {
                    set.add(String.valueOf(new char[]{S.charAt(idx), S.charAt(idx+jdx+1), S.charAt(k)}));
                }
            }
        }

        System.out.println(set.size());
    }
}


Measured memory_bytes: 86676
n = int(input())
a = list(map(int, input().split()))

num = [0] * (3*10**6)
for i in range(n):
    a[i] -= i
    if abs(a[i]) <= 10**6:
        num[a[i]] += 1

ans = 0
for i in range(n):
    if abs(-2*i - a[i]) <= 10**6:
        ans += num[-2*i - a[i]]
    if abs(a[i]) <= 10**6:
        num[a[i]] -= 1

print(ans)


Measured memory_bytes: 114904
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,m,a[100010],x,y;

int main()
{
  cin>>n>>m;
  rep(i,n) cin>>a[i];
  x=a[0]/2;
  repn(i,n-1)
  {
    y=a[i]/2;
    LL tmp=__gcd(x,y),num,aa,bb;
    tmp=x*y/tmp;
    aa=tmp/x;
    bb=tmp/y;
    if(aa%2==0||bb%2==0)
    {
      puts("0");
      return 0;
    }
    x=tmp;
  }
  cout<<(m+x)/(x*2)<<endl;
	return 0;
}

Measured memory_bytes: 1024
object Main extends App {
  val input = readLine
  val n = input.split(" ")(0).toLong
  val k = input.split(" ")(1).toLong
  
  if(n == k) println(0)
  else if(n < k) {
    println(Array(n, (n-k).abs).min)
  } else if(k < n) {
    println(Array(n%k, k-(n%k)).min)
  }
}

Measured memory_bytes: 27328
n, m, d = map(int, input().split())
if d == 0:
    print((m-1) * (1/n))
elif d < n:
    # if d * 2 <= n:
    #     print((((2*n-6*d)/n)**(m-1)))
    print((m-1)*(2*n - 2*d)/(n**2))
    # else:
    #     print(((2*n-2*d) / n)**m-1)
else:
    print(0)


Measured memory_bytes: 2940
//
// Created by Hideaki Imamura on 2020-03-15.
//
# include <bits/stdc++.h>

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

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

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

# define EPS (1e-7)
//# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll N, K;
ll h[100010];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    const ll INF = 1LL << 60;
    vector<ll> dp(N, INF);
    dp[0] = 0;
    for (int i = 1; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            if (i - j >= 0) chmin(dp[i], dp[i - j] + (ll) abs(h[i] - h[i-j]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

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

int main() {
long long n;
cin >> n;
set <long long>a;
long long s[n];
a.clear();
for(long long i=0;i<n;i++){
    cin >> s[i];
    a.insert(s[i]);}
if(a.size()==n){cout << "YES";}
else {cout << "NO";}
}


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

long A[100000];
long B[100000][2];

long max(long a, long b) {
	return (a > b) ? a : b;
}

long rec(int a, int b) {

	if (B[a][b] != -1) {
		return B[a][b];
	}
	else if (a == 0) {
		if (b == 0) {
			B[a][b] = A[a];
		}
		else {
			B[a][b] = -A[a];
		}
	}
	else {
		if (b == 0) {
			B[a][b] = max(rec(a - 1, 0) + A[a], rec(a - 1, 1) - A[a]);
		}
		else {
			B[a][b] = max(rec(a - 1, 0) - A[a], rec(a - 1, 1) + A[a]);
		}
	}

	return B[a][b];
}

int main() {
	int i, N;
	long dmax;

	memset(B, -1, sizeof(B));

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%ld", &A[i]);
	}

	dmax = max(rec(N - 2, 0) + A[N - 1], rec(N - 2, 1) - A[N - 1]);

	printf("%ld\n", dmax);
	
	return 0;
}

Measured memory_bytes: 7168
x = int(input())
if x < 100:
	print(0)
	exit()
a = x //100
"""
l = len(str(x))
y = str(x)
head = int(y[0])
"""
tail = x - a*100
#print(tail)

if tail > 5*a:
	print(0)
else :
	print(1)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct Input
{
    int n;
};

static Input read_input()
{
    Input input {};
    cin >> input.n;
    return input;
}

static void solve(const Input& input)
{
    const auto odds_count = (input.n + 1) / 2;
    const auto probability = static_cast<double>(odds_count) / input.n;
    cout << fixed << setprecision(10) << probability << endl;
}

int main(int argc, char** argv)
{
    const auto input = read_input();
    solve(input);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	for(int i = a; i != a * b; i += a)
	{
		if(i % b == c)
		{
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
	return 0;
}

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

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

    //good luck kittu!
    int n; cin>>n;
    map<int, pair<ll ,ll>> m; 
    vector<int> a(n);
    for(int i = 0; i<n; i++){
        cin>>a[i];
        m[a[i]].first++;
    }

    ll sum = 0;
    for(auto p : m){
        p.second.second = max(0LL, (p.second.first-1)*(p.second.first-2)/2);
        p.second.first = max(0LL, p.second.first*(p.second.first-1)/2);

        sum += p.second.first;
    }

    for(int x : a){
        cout<<sum -m[x].first + m[x].second + 1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 10368
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	// B
	int a[4] = {};
	for (int i = 0; i < 3; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		a[x]++;
		a[y]++;
	}
	bool ok = true;
	for (int i = 0; i < 4; i++) {
		if (a[i] >= 3) ok = false;
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;	
}

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



double probability  (double x){
    if (x>=1 && x<=100){
        if (fmod(x,2)!=0){
            std::cout<<std::fixed;
            std::cout<<std::setprecision(10)<<((x+1)/(2*x))<<endl;
        }
	
        else{
        	std::cout<<std::fixed;
                std::cout<<std::setprecision(10)<<(0.5)<<endl;
	    }
    }
}

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


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

class Cube{
public:
    int f[6];

    Cube(){}

    void roll_z(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

bool eq(Cube c1, Cube c2){
    for(int i=0; i<6; i++)
        if(c1.f[i] != c2.f[i]) return false;
    return true;
}

bool equal(Cube c1, Cube c2){
    for(int i=0; i<6;i++){
        for(int j=0; j<4; j++){
            if(eq(c1, c2)) return true;
            c1.roll_z();
        }
        if(i % 2 == 0) c1.roll_y();
        else c1.roll_x();
    }
    return false;
}

Cube C[100]; int n;

bool check(){
    for(int i=0; i<n-1; i++)
        for(int j=i+1; j<n; j++) if(equal(C[i], C[j])) return false;
    return true;
}

int main(){
    cin >> n;

    for(int i=0; i<n; i++)
        for(int j=0; j<6; j++) cin >> C[i].f[j];

    if(check()) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <algorithm>
using namespace std;




int main () {
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		v.push_back(temp);
	}
	vector<int> res;
	for (int i = 0; i < n; i++) {
		int jump = 0;
		int index = -1;
		for (int j = 0; j < n; j++) {
			if (v[j] == 0) {
				jump++;
				continue;
			}
			if (v[j] == j + 1 - jump) {
				index = j;
			}
		}
		if (index == -1)
			break;
		else {

			res.push_back(v[index]);
			v[index] = 0;
		}
	}

	if (n != res.size()) {
		cout << -1;
		return 0;
	}
	reverse(res.begin(), res.end());
	for (int i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}
}

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

using namespace std;

int main(void)
{
	vector<vector<int>> a;
	vector<int> b;
	int n, m, c;

	cin >> n >> m >> c;

	for (int i = 0; i < m; ++i)
	{
		b.emplace_back();
		cin >> b.back();
	}

	for (int i = 0; i < n; ++i)
	{
		a.emplace_back();
		for (int j = 0; j < m; ++j)
		{
			a.back().emplace_back();
			cin >> a.back().back();
		}
	}

	int ans = 0;
	int val = 0;

	for (int i = 0; i < n; ++i)
	{
		val = 0;
		for (int j = 0; j < m; ++j)
		{
			val += a[i][j] * b[j];
		}
		val += c;
		if (val > 0)
		{
			++ans;
		}
	}

	cout << ans;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
H1,M1,H2,M2,K = map(int,input().split())
num = 0
num += 60 - M1
H1 += 1
num += M2
num += (H2-H1)*60
print(num-K)



Measured memory_bytes: 10544
#include<iostream>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    int K[N],A[N][M];
    for (int i=0; i<N; i++) {
        cin >> K[i];
        for (int j=0; j<K[i]; j++) {
            cin >> A[i][j];
        }
    }

    int food=M,cnt=0;
    while (food>0) {
        int hit=0;
        for (int i=0; i<N; i++) {
            for (int j=0; j<K[i]; j++) {
                if (food == A[i][j]) hit++;
            }
        }
        if (hit == N) cnt++;
        food--;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
ll power(ll x,ll y,ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int main(){
  ll n,m,sum=0;
  cin >> n >> m;
  vector <ll> v(m) ;
  for(ll i=0;i<m;i++){
    cin >> v[i] ;
    sum += v[i] ;
  }
  if(sum>=n)  cout << "Yes"<< endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<int,ll>
#define pll pair<ll,ll>
#define _path pair<ll,pair<ll,int> > // length, numlength, node,we also take numlength to be negetive so that paths with the same length is sorted by descending order of number of such path. this is essential otherwise it will lead to undercounting of number of same length paths
#define vv vector
//#define endl '\n'
using namespace std;

const int MAXN = 100*1000 + 5;
const ll INF = 1e17;
const ll MOD = 1e9 +7;


ll startTerm[MAXN];
ll diffTerm[MAXN];

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

	int n,m;
	cin >> n >> m;
	int arr[n];
	FOR(i,n)cin >> arr[i];FOR(i,n)arr[i]--;
	// 0,1,2,3,4,5,6,7
	ll sum = 0;
	FOR(i,n){
		if(i == 0)continue;
		if(arr[i] == arr[i-1])continue;
		if(arr[i] > arr[i-1]){
			sum += arr[i] - arr[i-1];

			startTerm[arr[i-1]+1] += 0;
			diffTerm[arr[i-1]+1] += 1;

			startTerm[arr[i] + 1] += -(arr[i]-arr[i-1]);
			diffTerm[arr[i] + 1] += -1;
		}else{
			startTerm[arr[i-1]+1] += 0;
			diffTerm[arr[i-1]+1] += 1;

			startTerm[0] += m - arr[i-1] - 1;
			diffTerm[0] += 1;

			int totDist = arr[i] + m-arr[i-1];
			sum += totDist;

			startTerm[arr[i] + 1] += -totDist;
			diffTerm[arr[i] + 1] += -1;
		}
	}
	FOR(i,m){
	//	cout << startTerm[i] << " ";
	}
	//cout << endl;
	//FOR(i,m)cout << diffTerm[i] << " ";cout << endl;
	ll a = 0;
	ll d = 0;
	ll mxval = 0;
	
	ll term = 0;
	FOR(i,m){
		term += startTerm[i];
		term += d;
		//cout << term << " " << endl;
		mxval = max(mxval,term);
		d += diffTerm[i];
		
	}	
	//cout << sum << endl;
	cout << sum - mxval << endl;

	return 0;
}

Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >>N;
  vector<int> M(N);
  for(int i=0;i<N;i++){
    cin >> M[i];
  }
  sort(M.begin(),M.end());
  int sum=M[0];int x=0;
  for(int i=1;i<N+1;i++){
    if(sum==M[i]){
      x++;
    }
    else if(sum<M[i]){
      sum=M[i];
    }
  }
  cout <<N-x<<endl;
}

Measured memory_bytes: 3504
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n;
string s;
map<string, int> m;

signed main(){
    cin >> n;
    REP(i,n){
        cin >> s;
        m[s]++;
    }
    int ret = 0;
    for (auto p:m) ret++;
    cout << ret << endl;
}

Measured memory_bytes: 19120
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;

char n[100000];

int main() {
	scanf("%s", n);
	int len = strlen(n);
	int num1 = 0, num2 = 0;
	for(int i = 0; i < len; ++i) {
		if(n[i] == '1') {
			++num1;
		} 
		if(n[i] == '0') {
			++num2;
		}
	}
/*
	cout << num1 << endl << num2 << endl;//*/
	if(num1 >= num2) {
		cout << num2 * 2;
/*
		cout << "num2";//*/
	} else {
		cout << num1 * 2;
/*
		cout << "num1";//*/
	}
/*
	while(1) {
/*
		cout << i << endl;
		if(i1 >= len || i2 >= len)
/*
		for(int i = 0; i < len; ++i) {
			cout << n[i] << endl;
		}
		cout << endl;
//		cout << flag << endl;//*
		if(flag) {
			break;
		}
		for(; i1 < len; ++i1) {
			if(n[i1] == '1') {
				flag1 = 1;
				place1 = i;
				break;
			}
		}
		for(; i2 < len; ++i2) {
			if(n[i2] == '0') {
				flag2 = 1;
				place2 = i;
				break;
			}
		}
		if(flag1 && flag2) {
			cou += 2;
			n[place1] = '?';
			n[place2] = '?';
			flag1 = 0;
			flag2 = 0;
			flag = 1;
/*
		for(int i = 0; i < len; ++i) {
			cout << n[i] << endl;
		}
		cout << endl;
//		cout << flag << endl;//*
		} else {
			break;
		}
	}//*/
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

int main(){
   int n;
   cin >> n;
   vector<int> a(n,0);
   vector<int> c(n, 0);
   vector<ll> comb(n,0);
   rep(i,n) {
       cin >> a[i];
       c[a[i]-1]++;
       }
   rep(i,n){
       if(c[i]==0){
           comb[i]=0;
       }
       else if(c[i]==1){
           comb[i]=0;
       }else{
           comb[i] = (ll)c[i]*(c[i]-1)/2;
       }
   }
   ll ans;
   ans = accumulate(comb.begin(), comb.end(), 0LL);
   //cout << c[0] << endl;
   rep(i,n){
       ll ans_new;
       if(c[a[i]-1]==0){
           cout << ans << endl;
           continue;
       }
       ans_new = ans - (c[a[i]-1]-1);
       cout << ans_new << endl;
   }
   return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int[] i = convStrToInt(s);
		System.out.println( TwoNorThree(i) );


	}

	private static int[] convStrToInt(String s) {
		String[] strs = s.split(" ");
		int[] ints = new int[strs.length];
		int i = 0;

		for (String st : strs) {
			ints[i] = Integer.parseInt(st);
			i++;
		}

		return ints;
	}

	private static int TwoNorThree(int[] i) {
		return i[0] - i[1] - i[2] + i[3];
	}
}



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

using namespace std;

int main()
{
    int n, K, q, M=2000000000;
    cin >> n >> K >> q;
    int A[n+1];
    vector <int> V;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    A[n] = -1;
    priority_queue <int, vector<int>, greater<int>> Q, QV;
    for (int i = 0; i < n; i++)
    {
        for (int y = 0; y <= n; y++)
        {
            if (A[y] < A[i])
            {
                while (Q.size() >= K)
                {
                    QV.push(Q.top());
                    Q.pop();
                }
                while (Q.size() > 0)
                {
                    Q.pop();
                }
            }
            else
            {
                Q.push(A[y]);
            }
        }
        if (QV.size() >= q)
        {
            for (int y = 0; y < q-1; y++)
            {
                QV.pop();
            }
            M = min(M, QV.top()-A[i]);
        }
        while (QV.size() > 0)
        {
            QV.pop();
        }
    }
    cout << M;
    return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 300005 ;
using namespace std ;

int n, e, ter[N], nxt[N], lnk[N], w[N] ;
ll d[N << 2], L ;

void add(int x, int y, int z) {
//	printf("%d %d %d\n", x, y, z) ;
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e, w[e] = z ;
}

ll dfs(int p, int las, ll sum) {
	ll ret = sum ;
	for (int i = lnk[p]; i; i = nxt[i]) if (ter[i] != las) 
	  ret = max(ret, dfs(ter[i], p, sum + w[i])) ;
	return ret ;
}

bool cmp(pair <ll, ll> a, pair <ll, ll> b) {
	return (a.first < b.first || (a.first == b.first && a.second < b.second)) ;
}

bool solve(int p, int las, vector <pair <ll, ll> > &S) {
	S.clear() ;
	vector <pair <ll, ll> > l, r, S1, S2, S3 ;
	int id = 0 ;
	for (int i = lnk[p]; i; i = nxt[i]) if (ter[i] != las) {
		++ id ;
		if (id == 1) {
			if (!solve(ter[i], p, l)) return false ;
			rep(j, 0, (int) l.size() - 1) l[j].first += w[i], l[j].second += w[i] ;
		} else {
			if (!solve(ter[i], p, r)) return false ;
			rep(j, 0, (int) r.size() - 1) r[j].first += w[i], r[j].second += w[i] ;
		}
	}
	if (!id) {
		S.push_back(make_pair(0LL, 0LL)) ;
		return true ;
	}
	if (l.size() > r.size()) swap(l, r) ;
	d[0] = 0 ;
	int top = 0, rsz = r.size() ;
	rep(i, 0, (int) l.size() - 1) {
		ll lx = l[i].first, lmid = l[i].second, rx ;
		for ( ; top < rsz && r[top].first + lmid <= L ; ++ top) ;
		if (!top) continue ;
		rx = r[top - 1].second ;
		S1.push_back(make_pair(lx, rx)), S3.push_back(make_pair(rx, lx)) ;
	}
	for (int i = (int) S3.size() - 1; i >= 0; -- i) S2.push_back(S3[i]) ;
	int ltop = 0, rtop = 0, lsz = S1.size() ; rsz = S2.size() ;
	rep(i, 0, lsz + rsz - 1) {
		pair <ll, ll> u ;
		if (ltop < lsz && (rtop >= rsz || cmp(S1[ltop], S2[rtop]))) u = S1[ltop ++] ;
			else u = S2[rtop ++] ;
		if (i) {
			int len = (int) S.size() - 1 ;
			if (S[len].second <= u.second) continue ;
			if (S[len].first == u.first) {
				S[len] = u ;
				continue ;
			}
		}
		S.push_back(u) ;
	}
	return ((int) S.size() > 0) ;
}

int main() {
	scanf("%d", &n) ;
	int x, y ;
	rep(i, 1, n - 1) {
		scanf("%d%d", &x, &y) ;
		add(x, i + 1, y), add(i + 1, x, y) ;
	}
	ll l = 0, r = dfs(1, 0, 0) << 1, ans ;	
	vector <pair <ll, ll> > S ;
	for ( ; l <= r ; ) {
		ll mid = (l + r) / 2 ;
		L = mid ;
		if (solve(1, 0, S)) ans = mid, r = mid - 1 ;
			else l = mid + 1 ;
	}
	printf("%lld\n", ans) ;
	return 0 ;
}

Measured memory_bytes: 23296
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    ll min = a*x + b*y;
    chmin(min, a*((x > y) ? x-y : 0) + c*2*y);
    chmin(min, c*2*x + b*((y > x) ? y-x : 0));
    cout << min;
    cout << endl;
    return 0;
}



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

using namespace std;

int main()
{
 int n;
 cin>>n;
 string s;
 int ac= 0,wa=0,tle=0,re=0;
 while(n--) {
    cin>>s;
    if(s == "AC") ac++;
    else if(s == "WA") wa++;
    else if(s == "TLE") tle++;
    else re++;
 }
 cout<<"AC x "<<ac<<endl;
 cout<<"WA x "<<wa<<endl;
 cout<<"TLE x "<<tle<<endl;
 cout<<"RE x "<<re<<endl;
return 0;
}


Measured memory_bytes: 3604
{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.Bits
import Debug.Trace

data MyTrie = MTnode Bool (Maybe MyTrie) (Maybe MyTrie)
            deriving(Show)

mtAdd :: Maybe MyTrie -> B.ByteString -> MyTrie
mtAdd xx@(Just (MTnode b mt0 mt1)) bs
  | B.null bs        = MTnode True mt0 mt1
  | B.head bs == '0' = MTnode b (Just (mtAdd mt0 (B.tail bs))) mt1
  | B.head bs == '1' = MTnode b mt0 (Just (mtAdd mt1 (B.tail bs)))
  | otherwise        = mtAdd xx (B.tail bs)
mtAdd Nothing bs = mtAdd (Just (MTnode False Nothing Nothing)) bs
  
toIntList :: Int -> Maybe MyTrie -> [Int]
toIntList _ Nothing = []
toIntList _ (Just (MTnode True Nothing Nothing)) = []
toIntList _ (Just (MTnode True _ _)) = error "Should not happen"
toIntList !d (Just (MTnode False (Just mt0) Nothing)) = tILSingle d mt0
toIntList !d (Just (MTnode False Nothing (Just mt1))) = tILSingle d mt1
toIntList !d (Just (MTnode False (Just mt0) (Just mt1))) 
  = toIntList (d - 1) (Just mt0) ++ toIntList (d - 1) (Just mt1)

tILSingle :: Int -> MyTrie -> [Int]
tILSingle !d mt = d : toIntList (d - 1) (Just mt)

toLSB :: Int -> Int
toLSB x = bit (countTrailingZeros x)

solve :: Int -> [B.ByteString] -> String
solve cL bss =
  let mt = foldr (\x y -> Just (mtAdd y x)) Nothing bss
      ns = toIntList cL mt
      val = foldr xor 0 (map toLSB ns)
  in if val == 0 then "Bob" else "Alice"

main :: IO ()
main = do
  cont <- B.getContents
  let line1 : lines = B.lines cont
  let [_, cL] = (map (fst . fromJust . B.readInt) . B.words) line1
--  putStrLn (show lines)
  putStrLn $ solve cL lines



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

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

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

	vector<int> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	x.push_back(X);
	sort(x.begin(), x.end());

	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		v[i] = x[i + 1] - x[i];
	}

	if (N == 1) {
		cout << v[0] << endl;
		return 0;
	}

	int res = gcd(v[0], v[1]);
	for (int i = 2; i < N; i++) {
		res = gcd(res, v[i]);
	}

	cout << res << endl;
	return 0;
}


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

int main(void){
    int n;
    cin >> n;
    
    vector<bool> a(8,0);
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        int b; cin >> b;
        if (b <= 399) a.at(0) = 1;
        else if(b <= 799) a.at(1) = 1;
        else if(b <= 1199) a.at(2) = 1;
        else if(b <= 1599) a.at(3) = 1;
        else if(b <= 1999) a.at(4) = 1;
        else if(b <= 2399) a.at(5) = 1;
        else if(b <= 2799) a.at(6) = 1;
        else if(b <= 3199) a.at(7) = 1;
        else if(b >= 3200) cnt++;
    }
    
    int min = 0;
    for (int i = 0; i < 8; i++) {
        if(a.at(i) == 1) min++;
    }
    
    int max = min;
    while (cnt > 0) {
        max++;
        cnt--;
    }
    if(min == 0) min = 1;
    cout << min <<  " " << max << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.HashMap
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val n = readInt
  val map = new HashMap[String,Int]
  val b = new ArrayBuffer[String]
  for(i<-1 to n) {
    val s = readLine.split(" ")
    if(s(0)(0)=='i') map(s(1)) = 1
    else if(map.contains(s(1))) b+="yes" else b+= "no"
  }
  println(b.mkString("\n"))
}

Measured memory_bytes: 418328
/**********************************************
*               COMMENT BOX                   *
**********************************************/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.1415926535
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ll long long
#define llu unsigned long long
#define pb push_back
#define mp make_pair
#define tc int t; cin>>t; while(t--)
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n-1 ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const long long int inf64 = 1e18;
const int mod = inf + 7;
//const int N = 1000010;

//bool prime[N];
//void sieve()
//{
//    memset(prime,true,sizeof(prime));
//    prime[0]=prime[1]=false;
//
//    for(int i=2;i*i<=N;i++)
//    {
//        if(prime[i])
//        {
//            for(int j=i*i;j<=N;j+=i)
//                prime[j]=false;
//        }
//    }
//}

int main()
{
    fast;
    //sieve();
    ll N;
    cin >> N;
    int ans = 0;
    f(i, 2, 1000010)
    {
        int cur = 0;
        while (N % i == 0)
        {
            cur++;
            N /= i;
        }
        f(j, 1, 10000)
        {
            if (cur < j)
                break;
            ans++;
            cur -= j;
        }
    }

    if (N > 1)
        ans++;
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3620
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
ans1 = 0
ans2 = 0
for l in range(len(N)):
    a, b, c = [int(i) for i in N[l].split(",")]
    if a*a + b*b == c*c:
        ans1 += 1
    if a == b:
        ans2 += 1
print(ans1)
print(ans2)



Measured memory_bytes: 5600
using System;
using System.Linq;
using System.Text;

namespace Heaps
{
    class Complete_Binary_Tree
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var str = new StringBuilder();
            for (int i = 1; i <= A.Length; i++)
            {
                str.Append("node ").Append(i)
                    .Append(": key = ").Append(A[i - 1]);
                if (i != 1) str.Append(", parent key = ").Append(A[i / 2 - 1]);
                if (2 * i - 1 < A.Length) str.Append(", left key = ").Append(A[2 * i - 1]);
                if (2 * i < A.Length) str.Append(", right key = ").Append(A[2 * i]);
                str.Append(", \n");
            }

            Console.Write(str.ToString());
        }
    }
}

Measured memory_bytes: 9660
import java.util.Scanner;

class Main {
	public static void main(String[] $){
		Scanner sc =new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int r[] = new int[n];
		int g[] = new int[n];
		int b[] = new int[n];
		String sArray[] = new String[n];
		sArray = s.split("");

		String tmp = "";
		r[0] = 0;
		g[0] = 0;
		b[0] = 0;
		tmp = String.valueOf(sArray[0]);
		if ("R".equals(tmp)) {
			r[0] = 1;
		} else if ("G".equals(tmp)) {
			g[0] = 1;
		} else if ("B".equals(tmp)) {
			b[0] = 1;
		}

		for (int i = 1; i < n; i++) {
			tmp = sArray[i];

			r[i] = r[i - 1];
			g[i] = g[i - 1];
			b[i] = b[i - 1];
			if ("R".equals(tmp)) {
				r[i] = r[i - 1] + 1;
			} else if ("G".equals(tmp)) {
				g[i] = g[i - 1] + 1;
			} else if ("B".equals(tmp)) {
				b[i] = b[i - 1] + 1;
			}
		}

		long sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (sArray[i].equals(sArray[j]))
					continue;
				if (!sArray[i].equals("R") && !sArray[j].equals("R")) {
					sum += r[n - 1] - r[j];
					if (j - i + j < n && "R".equals(sArray[j - i + j])) sum--;
				} else if (!sArray[i].equals("G") && !sArray[j].equals("G")) {
					sum += g[n - 1] - g[j];
					if (j - i + j < n && "G".equals(sArray[j - i + j])) sum--;
				} else if (!sArray[i].equals("B") && !sArray[j].equals("B")) {
					sum += b[n - 1] - b[j];
					if (j - i + j < n && "B".equals(sArray[j - i + j])) sum--;
 				}
			}
		}

		System.out.println(sum);

		sc.close();
	}
}




Measured memory_bytes: 29660
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int p, q, a, n; int nx, ny;
int dfs(int f,int c, int s ,int x, int y) {
	int res = 0;
	if (x*q == y * p)return 1;
	if (x*q>y*p||c == n)return 0;
	for (int i = f; i <= a / s; i++) {
		nx = i * x + y;
		ny = i * y;
		res += dfs(i, c + 1, s*i, nx, ny);
	}
	return res;
}
int main() {
	while (cin >> p >> q >> a >> n, p) {
		int out = 0;
		for (int i = 1; i <= a; i++) {
			out += dfs(i, 1, i, 1, i);
		}
		cout << out << endl;
	}
	return 0;
}


Measured memory_bytes: 3004
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
N = int(input())

def primes(N):
    P = [2]
    searched = [False]*(N+1)
    for i in range(3, N+1, 2):
        if searched[i]:
            continue
        P.append(i)
        searched[i:N+1:i] = [True]*(N//i)
    return P

P = primes(55555)
ans = []
l = 0
for p in P:
    if (p-1)%5 == 0:
        ans.append(p)
        l += 1
        if l == N:
            break

print(*ans)

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

// #define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;

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

const int N = 3e5 + 20;

int32_t main() {

    sync;

    int n; cin >> n;
    string s; cin >> s;
    int k; cin >> k;

    for(int i = 0; i < n; i++) cout << (s[i] == s[k - 1] ? s[i] : '*');

    cout << endl;

    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &T[i]);
  }
  // sort(all(T));
  // T.erase(unique(all(T)), end(T));

  ll ans = 1;
  rep(i, 0, sz(T)) { ans = lcm(ans, T[i]); }
  put(ll(ans));
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b);
  T d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var t1, t2, a1, a2, b1, b2 int
	fmt.Scan(&t1, &t2, &a1, &a2, &b1, &b2)

	a1, a2 = a1*t1, a2*t2
	b1, b2 = b1*t1, b2*t2
	if a1 < b1 {
		a1, b1 = b1, a1
		a2, b2 = b2, a2
	}

	if a1+a2 == b1+b2 {
		fmt.Println("infinity")
		return
	}
	if a1+a2 > b1+b2 {
		fmt.Println(0)
		return
	}

	x := a1 - b1
	y := (b1 + b2) - (a1 + a2)
	if x%y == 0 {
		fmt.Println(x / y * 2)
	} else {
		fmt.Println(x/y*2 + 1)
	}
}


Measured memory_bytes: 1832
#include<stdio.h>
int main(){
  int a,i,A[100000],b,B[50000],j,count=0,mid,left,right;
  scanf("%d", &a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&B[i]);
    left=0;
    right=a;
    while(left < right){
      mid=(left+right)/2;
      if(A[mid] ==B[i]){
		count++;
		break;
      }
      else if(left+1==right)break;
      else if(B[i] < A[mid])right=mid;
      else left = mid+1;
    }
    
  }
  printf("%d\n",count);
}



Measured memory_bytes: 3344
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

constexpr int GENTEN = 80 * 80 * 80 / 2 + 1;
constexpr int LEN = GENTEN * 2;

using Bitset = std::bitset<LEN>;
template <class T>
using Row = vector<T>;
template <class T>
using Table = vector<Row<T>>;

void solve(void)
{
  int H, W; cin >> H >> W;
  Table<int> A(H + 1, Row<int>(W + 1));
  Table<int> B(H + 1, Row<int>(W + 1));
  for (int row = 0; row < H; ++row) {
    for (int column = 0; column < W; ++column) {
      cin >> A[row][column];
    }
  }
  for (int row = 0; row < H; ++row) {
    for (int column = 0; column < W; ++column) {
      cin >> B[row][column];
    }
  }

  Table<Bitset> dp(H + 1, Row<Bitset>(W + 1));
  dp[0][0] |=  Bitset(1) << (GENTEN + A[0][0] - B[0][0])
            |  Bitset(1) << (GENTEN + B[0][0] - A[0][0]);

  for (int row = 0; row < H; ++row) {
    for (int column = 0; column < W; ++column) {
      dp[row][column + 1] |=
        ((dp[row][column] << A[row][column + 1]) >> B[row][column + 1])
      | ((dp[row][column] << B[row][column + 1]) >> A[row][column + 1]);

      dp[row + 1][column] |=
        ((dp[row][column] << A[row + 1][column]) >> B[row + 1][column])
      | ((dp[row][column] << B[row + 1][column]) >> A[row + 1][column]);

    }
  }

  const Bitset& res = dp[H - 1][W - 1];
  for (int i = 0; i < GENTEN; ++i) {
    if (res[GENTEN + i]) {
      cout << i << CRLF;
      return;
    }
  }
  assert(false);
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 415616
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;    
int main(){
    int h,w;
    while(cin>>w>>h){
    if(w==0 && h==0) break;
    int dp[200][200][4]={},ans=0;
    //0??????????????§??????????????????????????\???  
    //1   ????????£????????????
    //2  ???????????§??????????????????????????\???
    //3   ????????£????????????
    for(int y=1;y<=h;y++){
        for(int x=1;x<=w;x++){
            if((x==1 && y==1) || (x==1 && y==2) || (x==2 && y==1)){
                dp[1][1][0]=1;
                dp[1][1][1]=1;
                dp[1][1][2]=1;
                dp[1][1][3]=1;
                dp[2][1][0]=1;
                dp[1][2][2]=1;
            }
            else{
                 dp[y][x][0] = dp[y-1][x][0]%100000 + dp[y-1][x][1]%100000;
                     dp[y][x][1] = dp[y-1][x][2]%100000;
                     dp[y][x][2] = dp[y][x-1][2]%100000 + dp[y][x-1][3]%100000;
                     dp[y][x][3] = dp[y][x-1][0]%100000; 
            }
        }
    }
    ans=dp[h][w][0]+dp[h][w][1]+dp[h][w][2]+dp[h][w][3];
    cout<<ans%100000<<endl;
    }
    }

Measured memory_bytes: 3692