akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
		int l,r,n;
		cin >> l >> r >> n;
		int cnt = 0;
		for(int i = l; i <= r; i++){
			if(i%n == 0){
				cnt++;
			}
		}
		cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N - 1) { cin >> A[i + 1]; A[i + 1]--; }
		vector<vector<UL>> E(N);
		for(UL i = 1; i < N; i++) E[A[i]].push_back(i);
		A[0] = N;

		vector<UL> q;
		queue<UL> q2;
		q2.push(0);
		while (q2.size()) {
			auto p = q2.front(); q2.pop();
			q.push_back(p);
			for (UL e : E[p]) q2.push(e);
		}
		reverse(q.begin(), q.end());
		vector<vector<UL>> ans(N + 1);

		rep(i, q.size()) {
			UL p = q[i];
			if (ans[p].size() == 0) { ans[A[p]].push_back(0); continue; }
			sort(ans[p].rbegin(), ans[p].rend());
			UL ansbuf = 0;
			rep(j, ans[p].size()) { ansbuf = max(ansbuf, ans[p][j] + j); }
			ans[A[p]].push_back(ansbuf + 1);
		}

		cout << ans[N][0] << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 12024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <deque>

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	vector<int> first;
	vector<int> second;

	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin >> tmp;
		first.push_back(tmp);
	}

	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin >> tmp;
		second.push_back(tmp);
	}

	second[0] += first[0];

	for (int i = 0; i < n-1; ++i)
	{
		first[i+1] += first[i];

		if(second[i]<first[i+1]) second[i+1] += first[i+1];
		else second[i+1] += second[i];
	}

	cout << second[n-1] << "\n";

	return 0;
}

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

int main(){
    int x,y;
   
    cin >> x>>y;
    while(!(x==0 && y==0)){
        if(x < y){
            cout << x <<" "<< y << endl;
            
        }else{
            cout << y <<" "<< x << endl;
        }
        cin >> x >> y;
    }
    return 0;
}



Measured memory_bytes: 3076
// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
bool check(ll ar[],ll n,ll x,ll k)
{
	ll ctr=0;
	for(ll i=0;i<n;i++)
	{
		if(x==0)
		{
			ctr+=ar[i]*2;
			continue;
		}
		ctr+=ar[i]/x;
		if(ar[i]%x==0) ctr--;
	}
//	cout<<x<<" "<<ctr<<' '<<k<<endl;
	if(ctr<=k)
	return true;
	else
	return false;
}
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>k;
	ll ar[n];
	for(i=0;i<n;i++)
	cin>>ar[i];
	ll ans=0;
	for(i=0;i<n;i++)
	ans=max(ans,ar[i]);
	ll l=1,r=ans;
	while(l<=r)
	{
		ll mid=(l+r)/2;
		if(check(ar,n,mid,k))
		{
			ans=min(ans,mid);
			r=mid-1;
		}
		else
		l=mid+1;
	}
	cout<<ans;
}

Measured memory_bytes: 5052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;

constexpr ll MAX_N = 1e5;
constexpr ll INF = 1e10;
ll N, E, T;
vector<ll> X;

int main(void) {
    cin >> N >> E >> T;
    X.push_back(0);
    for (size_t i = 0; i < N; i++) {
        ll x;
        cin >> x;
        X.push_back(x);
    }

    vector<ll> dp(N + 1, 0);

    dp[1] = T;
    for (ll i = 2, j = 0, k = 0; i <= N;) {
        ll L = max(2 * (X[i] - X[j + 1]), T);
        if (L == T) {
            dp[i] = min(dp[j] + T, dp[k] + max(2 * (X[i] - X[k + 1]), T));
            i++;
        } else {
            ll dpj = dp[j] + L;
            ll dpk = dp[k] + 2 * (X[i] - X[k + 1]);
            if (dpj < dpk) {
                k = j;
            }
            j++;
        }
    }

    cout << dp[N] + E << endl;
    return 0;
}



Measured memory_bytes: 2036
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] > max) {
               max = nums[i];
            }
            sum += nums[i];
        }
        if (max < sum - max) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#define __DEBUG__

using namespace std;
typedef long long ll;

int main(){
    int L;
    cin>>L;
    int N;
    int M;
    for(N = 0;(1<<N) <=L ;N++);
    M=2*(N-1);
    for(int i = 0;i < N-1;i++){
        if((L>>i)&1){
            M++;
        }
    }
    cout<<N<<" "<<M<<endl;
    for(int i = 0;i < N-1;i++){
        cout<<i+1<<" "<<i+2<<" "<<0<<endl;
        cout<<i+1<<" "<<i+2<<" "<<(1<<i)<<endl;
    }
    int newedge = 1<<(N-1);
    for(int i = 0;i < N-1;i++){
        if((L>>i)&1){
            cout<<i+1<<" "<<N<<" "<<newedge<<endl;
            newedge+=(1<<i);
        }
    }
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var bridge = new int[M, 2];
            for (int i = 0; i < M; i++)
            {
                input = ReadArrayInt();
                bridge[i, 0] = input[0] - 1;
                bridge[i, 1] = input[1] - 1;
            }
            var uf = new UnionFind(N);
            var ans = new long[M];
            ans[M - 1] = (long)N * (N - 1) / 2;
            for (int i = M - 1; i > 0; i--)
            {
                var A = bridge[i, 0];
                var B = bridge[i, 1];
                if (!uf.Same(A, B))
                {
                    ans[i - 1] = ans[i] - uf.Size(A) * uf.Size(B);
                    uf.Unite(A, B);
                }
                else
                {
                    ans[i - 1] = ans[i];
                }
            }
            foreach (var a in ans) Console.WriteLine(a);

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }

    class UnionFind
    {
        int[] par;
        int[] sizes;

        public UnionFind(int n)
        {
            par = new int[n];
            sizes = new int[n];
            for (var i = 0; i < n; i++)
            {
                par[i] = i;
                sizes[i] = 1;
            }
        }

        public int Root(int x)
        {
            return par[x] == x ? x : par[x] = Root(par[x]);
        }

        public bool Same(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public void Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);
            if (x == y) return;

            if (sizes[x] < sizes[y])
            {
                par[x] = y;
                sizes[y] += sizes[x];
                sizes[x] = 0;
            }
            else
            {
                par[y] = x;
                sizes[x] += sizes[y];
                sizes[y] = 0;
            }
        }

        public int Size(int x)
        {
            return sizes[Root(x)];
        }
    }
}

Measured memory_bytes: 20660
# -*- coding: utf-8 -*-
def main():
    n, x, m = map(int, input().split())
    a = [x]
    repeat_dic = {x: 0}
    cnt = 1
    repeat_start = -1
    repeat_end = -1
    for i in range(1, n):
        num = a[i-1] ** 2 % m
        a.append(num)
        if not num in repeat_dic.keys():
            repeat_dic[num] = cnt
            cnt += 1
        else:
            repeat_start = repeat_dic[num]
            repeat_end = i
            break
    if repeat_start == -1:
        ans = sum(a)
    else:
        nokori = n - repeat_start
        repeat_num = repeat_end - repeat_start
        q, mod = divmod(nokori, repeat_num)

        ans = sum(a[:repeat_start]) + q*sum(a[repeat_start:repeat_end]) + \
            sum(a[repeat_start: repeat_start + mod])
    # print(a)
    # print(q)
    # print(mod)
    # print(repeat_start)
    # print(repeat_end)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 15864
#include<iostream>
#include<sstream>
using namespace std;
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

bool chack(int n)
{
  if(n<10)
    return true;
  string tmp=toString(n);
  bool c = true;
  for(int i=0,j=tmp.size()-1;i<=j;i++,j--)
    {
      if(tmp[i]!=tmp[j])
	c=false;
    }
  return c;
}
int main()
{
  int n;
  for(;cin>>n;)
    {
      bool f1=false,f2=false;
      int n1=n,n2=n;
      for(;!(f1||f2);)
	{
	  f1=chack(n1);
	  if(!f1)
	    f2=chack(n2);
	  if(f1)
	    cout<<n1<<endl;
	  else if(f2)
	    cout<<n2<<endl;
	  n1--;
	  n2++;
	}
    }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	ll x,y;
	int ans=0;
	cin >>x>>y;
	for (ll i = x; i <= y;i+=i){
		ans++;
	} cout << ans << endl;
}

Measured memory_bytes: 3624
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

a, b, x = ISI()
ans = b//x -(a-1)//x
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
	long long n,t,c;
	double sum=0;
	scanf("%lld%lld",&n,&t);
	int vis=0;
	long long lst=0;
	while(n--){
		scanf("%lld",&c);
		if(!vis){
			vis=1;
		}
		else {
			if(c-lst>=t){sum+=t;lst=c;}
			else {sum+=c-lst;lst=c;}
		}
	}
	sum+=t;
    printf("%.0lf\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    char matrix[n][m];
    for (int i=0; i < n; i++) for (int j=0; j < m; j++) cin >> matrix[i][j];
    int used[n][m];
    for (int i=0;i<n;i++) for (int j=0; j < m; j++) used[i][j] = -1;
    queue<pair<int, int> > q;
    for (int i=0;i<n; i++) for (int j=0; j < m; j++) if (matrix[i][j] == '#'){
        q.push({i, j});
        used[i][j] = 0;
    }
    int ans = 0;
    while (q.size()){
        pair<int, int> p = q.front();
        q.pop();
        int X = p.first, Y = p.second;
        ans = max(ans, used[X][Y]);
        if (X-1 >= 0 && used[X-1][Y] == -1){
            used[X-1][Y] = used[X][Y]+1;
            q.push({X-1, Y});
        }
        if (X+1<n && used[X+1][Y] == -1){
            used[X+1][Y] = used[X][Y]+1;
            q.push({X+1, Y});
        }
        if (Y-1 >= 0 && used[X][Y-1] == -1){
            used[X][Y-1] = used[X][Y]+1;
            q.push({X, Y-1});
        }
        if (Y+1 < m && used[X][Y+1] == -1){
            used[X][Y+1] = used[X][Y]+1;
            q.push({X, Y+1});
        }

    }
    cout << ans;
}


Measured memory_bytes: 25396
#include <iostream>
using namespace std;
#define ll long long
int main(){
	int n,k; cin >> n >> k; ll ar[n];
	ll sum = 0,prev = 0,next = 0;
	for (int i = 0; i < n; i++){
		cin >> ar[i]; sum += ar[i]; ar[i] = sum;
	}
	prev = ar[k-1];
	for (int i = k; i < n; i++){
		next = ar[i] - ar[i-k];
		printf("%s\n",(next>prev) ? "Yes" : "No");
		prev = next;
	}
	return 0;
}

Measured memory_bytes: 5244
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

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

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,k;
int main()
{
	scanf("%d%d%d",&a,&b,&k);
	if(k>(b-a+1)/2)
	{
		for(int i=a;i<=b;i++)
			printf("%d\n",i);
	}
	else
	{
		for(int i=a;i<=a+k-1;i++)
			printf("%d\n",i);
		for(int i=b-k+1;i<=b;i++)
			printf("%d\n",i);
	}
}
/*
1 9 4
*/

Measured memory_bytes: 128
def resolve():
    import math
    N = int(input())
    A = []
    B = []
    for i in range(1, math.floor(math.sqrt(N))+1):
        if N%i == 0:
            A.append(i)
            B.append(N//i)
    print(max(len(str(A[-1])), len(str(B[-1]))))
resolve()

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1]*(n+1)#それぞれの要素がどの要素の子であるか

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]#それぞれの要素の根を再帰的に求める

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)#x,yが同じ集合に属するかどうか
    
    def size(self, x):
        return -self.par[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if root == self.find(i)]        

def main():
    n, m = map(int, input().split())
    union = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        union.union(a, b)
    
    ans = -1
    for j in range(1, n+1):
        if union.par[j] < 0:
            ans += 1

    print(ans)


    
if __name__ == "__main__":
    main()




Measured memory_bytes: 10804
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

const int64 md = 1e9 + 7;
int64 gt[1000005];

int64 pw(int64 a, int64 b){
    if (b == 0) return 1;
    int64 tmp = pw(a, b / 2);
    tmp = (tmp * tmp) % md;
    if (b % 2) return (tmp * a) % md;
    return tmp;
}

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    gt[0] = 1;
    for (int64 i = 1; i <= 1000000; i++)
        gt[i] = (gt[i - 1] * i) % md;
    int64 res = 0, x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++){
        if ((x - i) % 2) continue;
        if (i * 2 > y) continue;
        if (i * 2 + (x - i) / 2 != y) continue;
        int tmp = i + (x - i) / 2;
        res = (res + gt[tmp] * pw((gt[tmp - i] * gt[i]) % md, md - 2)) % md;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 8064
import math
X = int(input())

def check_exponential_sqrt(x):
    r = math.sqrt(x)
    int_r = int(r)

    if abs(r-int_r) <= 0.0001:
        return 1
    else:
        return 0

def check_exponential(x):
    for b in range(1,int(math.sqrt(x))+1):
        ans = 1
        for p in range(1,x+1):
            if(ans == x):
                return 1
            elif(ans > x):
                break
            ans *= b





for i in reversed(range(1,X+1)):
    if check_exponential(i) == 1:
        print(i)
        break


Measured memory_bytes: 3064
args = input().split()
S = args[0]
T = args[1]

args2 = input().split()
a = int(args2[0])
b = int(args2[1])

U = input()

if U == S:
	print(str(a-1)+" "+str(b))
	
else:
	print(str(a)+" "+str(b-1))

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	void run() {
		int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < 5; i++) {
			int n = scan.nextInt();
			max = Math.max(max, n);
			min = Math.min(min, n);
		}
		int k = scan.nextInt();
		System.out.println((k >= (max - min) ? "Yay!" : ":("));
	}
    public static void main(String[] args) {
    	new Main().run();
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void dfs(vector<vector<char>> &f,ll &count,ll a,ll b){
    if (f[a - 1][b] == 'B' || f[a + 1][b] == 'B' || f[a][b - 1] == 'B' || f[a][b + 1] == 'B') {
        f[a][b] = '#';
        return;
    }
    if (f[a][b] == 'G') {
        count--;
    }
    f[a][b] = '#';
    if (f[a - 1][b] != '#') {
        dfs(f,count, a-1, b);
    }
    if (f[a + 1][b] != '#') {
        dfs(f, count, a + 1, b);
    }
    if (f[a][b-1] != '#') {
        dfs(f, count, a, b-1);
    }
    if (f[a][b+1] != '#') {
        dfs(f, count, a, b+1);
    }
}

int main() {
    ll x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}

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

using namespace std;

int a[2010];
bitset<4000010> dp(1);

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

    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; i++)
    {
        dp |= (dp << a[i]);
    }
    for (int i = 1; i <= 4000000; i++)
    {
        if (dp[i] && 2 * i >= sum)
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int N;
long long M;
std::vector<long long > A(100000);
std::vector<long long > kumisuu(200000, 0); // A_i>=x を満たすiの数
std::vector<long long > souwa(200000, 0); // A_i>=x を満たすiについてA_iの総和

long long get_possible_count(int value){ // 値がvalue以上となる組み合わせ総数を求める
  long long count = 0;
  for (int i=0; i<N; i++){
    count += kumisuu[std::max(value-A[i], (long long)0)];
  }
  return count;
}

int main(){
  scanf("%d",&N);
  scanf("%lld",&M);

  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    kumisuu[A[i]]++;
  }
  sort(A.begin(), A.end(), std::greater<long long>());

  for (int i=0; i<N; i++){
    souwa[i+1] = souwa[i] + A[i];
  }

  /*  累積和を求める */
  for (int i=200000; i>0; i--){
    kumisuu[i-1] += kumisuu[i];
  }

  int left = 0;
  int right = 200001;
  int mid;
  long long ans = 0;
  std::map<long long, long long> mp;
  while(right-left>1){
    mid = (left+right)/2;
    ans=0;
    for (int i=0; i<N; i++){
      ans += souwa[kumisuu[std::max(mid-A[i],(long long)0)]];
      ans += A[i]*kumisuu[std::max(mid-A[i],(long long)0)];
    }
    if (get_possible_count(mid)>=M){ // 
      left = mid;
    } else {
      right = mid;
    }
    mp[mid] = get_possible_count(mid);
  }
  if (left == mid){
    std::cout << ans-abs(M-mp[left])*left << std::endl;
  } else if (right==mid){
    std::cout << ans+abs(M-mp[right])*left << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll sum=0,sum2=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll ans=1e18;
    rep(i,n){
        sum-=a[i];
        sum2+=a[i];
        chmin(ans,abs(sum2-sum));
    }
    cout<<ans<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll dp[20001][256];

const ll INF = 1e14;

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		rep(i,20001) rep(j,256) dp[i][j] = INF;
		vector<int> c(m);
		vector<ll> x(n);
		rep(i,m) cin >> c[i];
		rep(i,n) cin >> x[i];

		dp[0][128] = 0;
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				for(int k=0; k<256; k++) {
					if( dp[i][k] == INF ) continue;
					int z = k + c[j];
					if(z < 0) z = 0;
					else if(256 <= z) z = 255;
					dp[i+1][z] = min(dp[i+1][z], dp[i][k] + (x[i]-z)*(x[i]-z));
				}
			}
		}
		ll res = INF;
		for(int i=0; i<256; i++) {
			res = min(res, dp[n][i]);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 41356
#include<stdio.h>
int main()
{
    int n, x, y, sum= 0;
    scanf("%d", &n);
    int arr[n];

    for(x= y= 1; x<=n && y<=n; x++, y++)
        sum += x;
    printf("%d\n", sum);
    return 0;
}




// A no of long contest 4

Measured memory_bytes: 1720
N = gets.to_i
ary = []
N.times do 
    ary << gets.chomp.split(" ").map(&:to_i)
end

mtx = Array.new(N){Array.new(N)}
N.times do |i|
    N.times do |j|
       mtx[i][j] = Math.sqrt((ary[i][0] - ary[j][0])**2 + (ary[i][1] - ary[j][1])**2)
    end
end

sum = 0

mtx.each do |a|
    sum += a.inject(:+)
end


puts (sum) / N



Measured memory_bytes: 1788
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 
#include <atcoder/all>

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;
using namespace atcoder;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)-INF;
}

int target;

bool f(int x) {
    return x < target;
}

void solve()
{
    int n, K;
    scanf("%d%d", &n, &K);
    vector<int> a(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    int N = 300005;

    int ans = 0;
    vector<int> v(n);
    segtree<int, op, e> seg(N);
    for (i = 0; i < n; i++) {
        int tmp0 = max(0, a[i] - K);
        int tmp1 = min(N-1, a[i] + K);

        int m = seg.prod(tmp0, tmp1 + 1);
        if (m < 0) {
            m = 0;
        }
        v[i] = m + 1;
        ans = max(ans, v[i]);
        int aa=seg.get(a[i]);
        seg.set(a[i], max(aa, m + 1));
    }
    printf("%d\n", ans);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 10952
from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype='int')
#T=[]
S=np.zeros_like(T,dtype='int') 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#B=T.copy()    
d=0
c=deque()  
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue
 
          
        c.append((i,j))
        S[i][j] = 1
        #c.append(j)
        
        #t=len(c)
        while True:

                try:
                  m,n = c.popleft()
                except IndexError: break
                
                
                for kk in [(m+1,n),(m-1,n),(m,n+1),(m,n-1)]:
                  if not (0<=kk[0]<H and 0<= kk[1] <W): continue
                  if T[kk]==1:continue
                  if S[kk] == 0:
                    c.append(kk)
                    S[kk] = S[m][n]+1        
                        
 
        #print(T)
        d = max(d,np.max(S))
        S=np.zeros_like(T,dtype='int')
        
print(d-1)


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

bool ifnotprime[1000000];

void setPrimes(){
    ifnotprime[0] = ifnotprime[1] = true;
    for(int n = 2; n*n < 1000000; n++){
        if( !ifnotprime[n] ){
            int m = n*n;
            while(m < 1000000){
                ifnotprime[m] = true;
                m += n;
            }
        }
    }
}

int main(){
    setPrimes();
    int n, i;
    while(cin >> n, n){
        int ans = 0;
        for(i = 2; i <= n/2; i++){
            if( !ifnotprime[i] && !ifnotprime[n-i] ){
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2136
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

auto a = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];

void main() {
  auto s = readln.strip;
  foreach (i; 0 .. a.length) {
    if (a[i] == s) {
      writeln (7 - i);
      break;
    }
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<P> v(m);
  rep(i, 0, m) cin >> v[i].second >> v[i].first;

  sort(v.begin(), v.end());

  int b = -1, ans = 0;

  rep(i, 0, m) {
    if (b != -1 && b >= v[i].second && b <= v[i].first)
      continue;
    else {
      b = v[i].first - 1;
      ans++;
    }
  }

  cout << ans << endl;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

void fastscan(ll &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-') 
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

bool isprime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

bool checkisTree(ll degree[],ll n) 
{
    ll deg_sum = 0; 
    for (ll i = 0; i < n; i++) 
        deg_sum += degree[i]; 
    return (2*(n-1) == deg_sum);
}

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

int main()
{
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n, k;
      	cin>>n>>k;
		if((n+k)%2==0)
			cout<<(n+k)/2;
		else
			cout<<"IMPOSSIBLE";
	}	
}

Measured memory_bytes: 256
import math
n, d = map(int,input().split())
x = []
ans = 0
tmp = 0
for i in range(0, n):
    x.append(list(map(int,input().split())))
for i in range(0, n):
    for j in range(i + 1, n):
        tmp = 0
        for k in range(0,d):
            tmp += (x[j][k] - x[i][k])*(x[j][k] - x[i][k])
        if math.sqrt(tmp) == int(math.sqrt(tmp)):
            ans += 1

print(ans)


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

string a, b;

int main() {
    cin >> a;
    cin >> b;

    int s, t, all;
    s = t = 0;
    all = a.size() + b.size();

    for (int i = 0; i < all; ++i) {
        if (i%2 == 0) {
            cout << a[s];
            s++;
        }
        else {
            cout << b[t];
            t++;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        value_list.sort()
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll dp[100010],a[100010];
int main ( )
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	dp[2]=abs(a[2]-a[1]),dp[1]=0;
	for(int i=3;i<=n;i++) 
	   dp[i]=std::min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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; }


int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin>>S;
    int n=S.size();
    int ans=0;
    int d = S[0]-'0'-1;
    d += 9*(n-1);
    chmax(ans,d);

    d = 0;
    for(char c:S) d+= c-'0';
    chmax(ans,d);
    cout<<ans<<endl;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <map>
#include <numeric>

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

  int m = 200001;
  std::vector<int> p(m+1, 1);
  p[0] = p[1] = 0;
  for (int i = 2; i*i <= m; ++i) {
    if (!p[i]) continue;
    for (int j = i*i; j <= m; j += i)
      p[j] = 0;
  }

  for (int i = x; i <= m; ++i)
    if (p[i]) return !printf("%d\n", i);

  return 1;
}


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int a=ir.nextInt();
int b=ir.nextInt();
int c=ir.nextInt();
int ans=0;
for(int i=a;i<=b;i++){
 if(c%i==0) ans++;
}
out.println(ans);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24500
def path(edge, start, goal)
  q = [[[start], []]]
  until q.empty?
    p, used = q.shift
    return p if p.last == goal
    edge[p.last].each do |v|
      next if used[v]
      used[v] = true
      q << [p + [v], used]
    end
  end
  nil
end

def FordFulkerson(edge, m, n)
  source = m + n
  sink = m + n + 1

  result = 0

  while p = path(edge, source, sink)
    result += 1
    p.each_cons(2) do |u, v|
      edge[u].delete(v)
      edge[v] << u
    end
  end

  result
end

until (m, n = gets.split.map(&:to_i)).all?(&:zero?)
  source = m + n
  sink = m + n + 1
  size = m + n + 2

  b = Array.new
  r = Array.new
  b += gets.split.map(&:to_i) until b.size == m
  r += gets.split.map(&:to_i) until r.size == n

  edge = Array.new(size){Array.new}
  m.times do |u|
    n.times do |v|
      edge[u] << m + v unless b[u].gcd(r[v]) == 1
    end
  end
  m.times do |u| edge[source] << u end
  n.times do |v| edge[m + v] << sink end

  p FordFulkerson(edge, m, n)
end

Measured memory_bytes: 8252
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
bool erato[(int)1e5 + 20];
int main() {
  ll Q;
  cin >> Q;
  REP(i, (int)1e5 + 20) erato[i] = true;
  erato[0] = false;
  for (int i = 2; i <= (int)(1e5) / i; i++) {
    if (erato[i] != true) {
      continue;
    }
    for (int j = 2; j * i <= (int)(1e5); j++) {
      erato[i * j] = false;
    }
  }
  for (int i = (int)1e5; i > 1; i--) {
    if (i % 2 == 0) {
      erato[i] = false;
      continue;
    }
    if (erato[i] && erato[(i + 1) / 2]) {
      erato[i] = true;
    } else {
      erato[i] = false;
    }
  }
  erato[0] = false, erato[1] = false, erato[2] = false;
  vector<int> wa(1e5 + 20);
  wa[0] = 0;
  for (int i = 1; i <= 1e5 + 1; i++) {
    wa[i] = wa[i - 1] + erato[i];
  }
  REP(i, Q) {
    int l, r;
    cin >> l >> r;
    cout << wa[r] - wa[l - 1] << endl;
  }
}

Measured memory_bytes: 3684
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

#include <complex>
typedef complex<double> P;

#define LT(x,y) ((x)-(y)<=-EPS)
#define LE(x,y) ((x)-(y)<+EPS)

vector<P> cross_circles(P c1, double r1, P c2, double r2) {
	double d = abs(c2 - c1);
	if (LT(r1 + r2, d) || LT(d, fabs(r1 - r2))) {
		return vector<P>();
	}
	double l = 0.5*((r1*r1 - r2*r2) / d + d);
	double h = sqrt(r1*r1 - l*l);
	vector<P> ret(2);
	ret[0] = P(l, +h)*(c2 - c1) / d + c1;
	ret[1] = P(l, -h)*(c2 - c1) / d + c1;
	return ret;
}
 
int main() {
	int n;
	while (cin >> n, n) {
		double x, y;
		char c;
		vector<P> circles(n);
		REP(i, n) {
			cin >> x >> c >> y;
			circles[i] = P(x, y);
		}

		int ans = 1;
		REP(i, n - 1) {
			FOR(j, i + 1, n - 1) {
				vector<P> pts = cross_circles(circles[i], 1.0, circles[j], 1.0);
				int size = pts.size();
				REP(k, size) {
					int count = 2;
					REP(l, n) {
						if (l == i || l == j) {
							continue;
						}
						else {
							if (LE(abs(circles[l] - pts[k]), 1.0)) {
								count++;
							}
						}
					}
					ans = max(ans, count);
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

typedef long long LL;
typedef unsigned long long ULL;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

#if 0
12345 竍・
10000 + 1000 + 100 * 2 + 10 * 4 + 1 * 8 +
    2000 * 2 + 200 * 2 + 20 * 4 + 2 * 8 +
               300 * 4 + 30 * 4 + 3 * 8 +
                         40 * 8 + 4 * 8 +
                                  5 * 16
#endif

int main(void)
{
	char S[11];
	cin >> S;
	LL s[11];

	int N = strlen(S);
	Rep(i, N){
		s[i] = S[N - 1 - i] - '0';
	}

	LL ans = 0;
	Rep(i, N){
		LL sub = 0;
		Rep(j, N - 1){
			sub += s[i];
			sub *= (j != N - 2) ? 2 : 1;
			s[i] *= (i > j) ? 10 : 1;
		}
		//PrintLn(sub + s[i]);
		ans += sub + s[i];
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
import bisect
import sys
readline = sys.stdin.buffer.readline


def main():
    n = int(readline())
    a = list(map(int,readline().rsplit()))
    b = list(map(int,readline().rsplit()))
    c = list(map(int,readline().rsplit()))
    a.sort()
    c.sort()
    ans = 0
    for i in b:
        d = bisect.bisect_left(a, i)
        e = n - bisect.bisect_right(c, i)
        ans += d * e
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21088
#include<iostream>

using namespace std;

int main() {
	int H[10000], W[10000];

	for (int i = 0; i < 9999; i++) {
		cin >> H[i] >> W[i];

		if (H[i] == 0 && W[i] == 0) {
			break;
		}
	}

	for (int j = 0; j < 9999; j++) {

		if (H[j] == 0 && W[j] == 0) {
			break;
		}

		for (int k = 1; k <= H[j]; k++) {
		
			for (int l = 1; l <= W[j]; l++) {
				int s = k + l;

				if (s % 2 == 0) {
					cout << "#";
				}

				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define hell 1000000007
#define int long long int

using namespace std;

void solve(){
    char c;
    cin>>c;
    if(c>='A'&&c<='Z')
        cout<<"A";
    else
        cout<<"a";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i,n)
    cin >> d[i];
  sort(all(d));
  int num = n / 2;
  int diff = d[num] - d[num-1];
  cout << diff << endl;
  return 0;
}


Measured memory_bytes: 640
ar=[]
br=[]
for _ in range(int(input())):
    a,b=map(int,input().split())
    ar.append(a)
    br.append(b)
flag=0
for i in range(len(ar)-2):
    if ar[i]==br[i] and ar[i+1]==br[i+1] and ar[i+2]==br[i+2]:
        flag=1
        break
if flag:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 9184