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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);

int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
int lcm(int x, int y) { return x/gcd(x, y)*y; }
int mod_pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % MOD; } x = x * x % MOD; y >>= 1; } return res; }
int comb(int n, int k) { k = min(k, n - k); int nnn = 1; for (int i = n - k + 1; i <= n; i++) { nnn *= i; nnn %= MOD; } int kkk = 1; for (int i = 1; i <= k; i++) { kkk *= i; kkk %= MOD; } return (nnn * mod_pow(kkk, MOD - 2)) % MOD; }
int to_int(string s) { int n = s.size(); int ans = 0; for (int i = 0; i < n; i++) { ans = ((ans * 10) + (s[i] - '0')) % MOD; } return ans; }
int DisitSum(int x){ int ret=0; while(x){ ret++;x/=10;} return ret; }
bool is_prime(int n) { for(int i = 2; i*i <= n; i++) { if (n % i == 0) return false; } return n != 1; }
int extgcd(int a, int b, int& x, int& y) { // ax+by = gcd(a,b) >> gcd(a,b)
    int d = a;
    if(d != 0) { d = extgcd(b, a%b, y, x); y -= (a/b)*x; }
    else { x = 1, y = 0; }
    return 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int k;
    cin>>k;
    int ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                int memo=gcd(i,j);
                memo=gcd(memo,l);
                ans+=memo;
            }
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 7792
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

main = do
    [n, a, b] <- getIntList
    putStrLn . show $ let res = n `divMod` (a+b)
                          q = fst res
                          r = snd res
                      in q * a + if r > a then a else r

Measured memory_bytes: 380
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")



void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;
/*ai(i=l~r)のうち、ai=xとなる最小のiまたはai<xとなる最大のi*/
ll lower_bound(ll n, ll a[n], ll l, ll r, ll x){
    while(r-l>1){
        ll p=(l+r)/2;
        if(a[p]<x){
            l=p;
        }else{
            r=p;
        }
    }
    return a[r]<x?r:a[l]<x?l:-1;
    // if(a[p]==x) return p;
    // return a[p]<x ? lower_bound(n,a,p,r,x) : lower_bound(n,a,l,p,x);
}
/*ai(i=l~r)のうち、ai=xとなる最大のi*/
ll upper_bound(ll n, ll a[n], ll l, ll r, ll x){
    while(r-l>1){
        ll p=(l+r)/2;
        if(a[p]<=x){
            l=p;
        }else{
            r=p;
        }
    }
    return a[l]>x?l:a[r]>x?r:n;
    // return a[p]<=x ? upper_bound(n,a,p,r,x) : upper_bound(n,a,l,p,x);
}
int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    ll a[n],b[n],c[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
    }
    rep(i,0,n){
        scanf("%lld",&b[i]);
    }
    rep(i,0,n){
        scanf("%lld",&c[i]);
    }
    sortup(a,n);
    sortup(c,n);
    rep(i,0,n){
        ll fa=lower_bound(n,a,0,n-1,b[i]), fc=upper_bound(n,c,0,n-1,b[i]);
        // if(fa!=-1 && fc!=-1){
            ans+=(fa+1)*(n-fc);
        // }
        // printf("%lld %lld   ",fa,fc);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3324
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll N; cin >> N;
    vs S(N); rep(i, N) cin >> S[i];
    
    ll ans = 0;
    FOR(sub, -N+1, N){
        ll a = -1, b = -1;
        vs T = S;
        if(sub > 0){
            a = sub; b = 0;
            rep(i, N) T[i] = S[(i-a+N)%N];
        }
        else{
            a = 0; b = -sub;
            rep(i, N) rep(j, N){
                T[i][j] = S[i][(j-b+N)%N];
            }
        }
        bool ok = true;
        rep(i, N) rep(j, N) if(T[i][j] != T[j][i]){
            ok = false; i = N; j = N;
        }
        if(ok) ans += N-abs(sub);
    }
    cout << ans << endstr;
    
    return 0;
}


Measured memory_bytes: 512
# coding: utf-8
# Here your code !
 
def func():
    data=[]
    while(True):
        try:
            [height,width] = [ int(item) for item in input().rstrip().split(" ") ]
        except:
            return inputError()
         
        if( (height > 0) and (width > 0) ):
            data.append([height,width])
        elif( (height == 0) and (width == 0) ):
            break
        else:
            return inputError()
    
    result=""
    for item in data:
        [height,width]=item
        for i in range(height):
            for j in range(width):
                strfunc = lambda x : "#" if x%2==0 else "."
                result+=strfunc(i+j)
            result+="\n"
        result+="\n"
    print(result[:-1])
        
def inputError():
    print("input Error")
    return -1
 
func()

Measured memory_bytes: 7752
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long A = long.Parse(str[1]);
		long B = long.Parse(str[2]);
		long ans = 0;
		if(Math.Abs(A-B)%2==0){
			ans = Math.Abs(A-B)/2;
		} else {
			long a1 = A-1;
			long b1 = B-a1;
			a1++;
			b1--;
			a1 += (b1-1)/2;
			long a2 = N-B;
			long b2 = A+a2;
			a2++;
			b2++;
			a2 += (N-b2)/2;
			ans = Math.Min(a1,a2);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
// luogu-judger-enable-o2
#include<iostream>
using namespace std;
int main(){
	string x;
	cin>>x;
	int len=x.length();
	if(x[0]==x[len-1])
		if(len&1) cout<<"Second";
		else cout<<"First";
	else if(len&1) cout<<"First";
			else cout<<"Second";
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n,c;
	int cost_arr[30][30];
	int mixed_arr[30][3];
	scanf("%d%d",&n,&c);
	for(int i = 0; i < 30; i++) for(int j = 0; j < 3; j++) mixed_arr[i][j] = 0;
	for(int i = 0; i < c; i++) {
		for(int j = 0; j < c; j++) {
			scanf("%d",&cost_arr[i][j]);
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			int color;
			scanf("%d",&color);
			color--;
			for(int k = 0; k < c; k++) {
				mixed_arr[k][(i+j)%3] += cost_arr[color][k];
			}
		}
	}
	int ans = 1<<30;
	for(int i = 0; i < c; i++) {
		for(int j = i+1; j < c; j++) {
			for(int k = j+1; k < c; k++) {
				ans = min(ans,mixed_arr[i][0]+mixed_arr[j][1]+mixed_arr[k][2]);
				ans = min(ans,mixed_arr[i][0]+mixed_arr[j][2]+mixed_arr[k][1]);
				ans = min(ans,mixed_arr[i][1]+mixed_arr[j][0]+mixed_arr[k][2]);
				ans = min(ans,mixed_arr[i][1]+mixed_arr[j][2]+mixed_arr[k][0]);
				ans = min(ans,mixed_arr[i][2]+mixed_arr[j][0]+mixed_arr[k][1]);
				ans = min(ans,mixed_arr[i][2]+mixed_arr[j][1]+mixed_arr[k][0]);
			}
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
typedef long long ll;
int dp[2][1000001];
int util(vector<int> adj[], int n, int u, int parent, int flag){
    if(dp[flag][u] != -1) return dp[flag][u]%MOD;
    int white = 1;
    for(int i=0;i<adj[u].size();i++){
        int v = adj[u][i];
        if(v != parent){
            ll o1 = util(adj, n, v, u, 0);
            white = (white*o1)%MOD;
        }
    }
    int res = white;
    if(flag == 0){
        int black = 1;
        for(int i=0;i<adj[u].size();i++){
            int v = adj[u][i];
            if(v != parent){
                ll o2 = util(adj, n, v, u, 1);
                black = (black*o2)%MOD;
            }
        }
        res = (res + black)%MOD;
    }
    dp[flag][u] = res;
    return res;
}
int main(){
	int n;
	cin>>n;
    vector<int> adj[n];
    for(int i=0;i<n-1;i++){
        int xi, yi;
        cin>>xi>>yi;
        adj[xi-1].push_back(yi-1);
        adj[yi-1].push_back(xi-1);
    }
    memset(dp, -1, sizeof(dp));
    int ans = util(adj, n, 0, -1, 0);
    cout<<ans;
	return 0;
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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;
}

int main(){
    int H, W; cin >> H >> W;
    vector<string> S;
    rep(i, H) {
        string temp; cin >> temp;
        S.push_back(temp);
    }
    vector<vector<int> > l(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j == 0 || S[i][j] == '#') l[i][j] = 0;
            else {
                if (S[i][j - 1] == '#') l[i][j] = 0;
                else l[i][j] = l[i][j - 1] + 1;
            }
        }
    }
    vector<vector<int> > r(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++) {
        for (int j = W - 1; j >= 0; j--) {
            if (j == W - 1 || S[i][j] == '#') r[i][j] = 0;
            else {
                if (S[i][j + 1] == '#') r[i][j] = 0;
                else r[i][j] = r[i][j + 1] + 1;
            }
        }
    }
    vector<vector<int> > u(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i == 0 || S[i][j] == '#') u[i][j] = 0;
            else {
                if (S[i - 1][j] == '#') u[i][j] = 0;
                else u[i][j] = u[i - 1][j] + 1;
            }
        }
    }
    vector<vector<int> > d(H, vector<int>(W, 0));
    for (int i = H - 1; i >= 0; i--) {
        for (int j = 0; j < W; j++) {
            if (i == H - 1 || S[i][j] == '#') d[i][j] = 0;
            else {
                if (S[i + 1][j] == '#') d[i][j] = 0;
                else d[i][j] = d[i + 1][j] + 1;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int temp = l[i][j] + r[i][j] + u[i][j] + d[i][j] + 1;
            if (temp > ans) ans = temp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 67200
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int n,a[2003];
long long ans=0;
int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for (int i=0;i<n;i++)
		for (int j=i+1;j<n;j++){
			int bd=a[i]+a[j];
			int st=lower_bound(a,a+n,bd)-a;
			ans+=st-j-1;
		}
	cout<<ans;
}

Measured memory_bytes: 256
// Editorial
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  long long k;
  cin >> k;
  vector<int> a(n);
  vector<int> f(n);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  long long start = 0;
  long long end = pow(10, 12);
  while(start != end) {
    long long h = (start + end) / 2;
    long long tmp = 0;
    for(int i=0;i<n;i++) {
      long long t = h / f[i];
      tmp += max(0LL, a[i] - t);
    }
    if(tmp <= k) end = h;
    else start = h + 1;
  }
  cout << start << endl;
}


Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    r = []
    n,x = list(map(int, input().split()))
    nn = n*2
    if x < 2 or x > nn-2:
        return 'No'
    print('Yes')
    r = list(range(1,nn))
    r[n-1],r[x-1] = r[x-1],r[n-1]
    r[n-2],r[0] = r[0],r[n-2]
    r[n],r[-1] = r[-1],r[n]
    return " ".join(map(str,r))


print(f())


Measured memory_bytes: 27540
#include<iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using vi = vector<int>;
using vii = vector<vi>;

int main() {
	long long int l, r;
	cin >> l >> r;
	bool flag = false;
	int m = 2019;

	if (l - r + 1 >= 2019) {
		m = 0;
		flag = true;
	}

	if (!flag) {
		for (long long int i = l; i < r; i++) {
			for (long long int j = l + 1; j <= r; j++) {
				long long int a, b;
				a = i % 2019;
				b = j % 2019;
				if (m > (a * b) % 2019) {
					m = (a * b) % 2019;
					if (m == 0) break;
				}
			}
			if (m == 0) break;
		}
	}
	cout << m << endl;
}


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

int main() {
  string s;cin>>s;
  int cnt=0;
  rep(i,s.size()){
    if(s[i]=='o')cnt++;
  }
  if(15-s.size()+cnt>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3580
N= int(input())
p = input().replace(" ","")
q = input().replace(" ","")
kai = [1]
for i in range(2,N):
    kai.append(kai[-1]*i)
def calc(s,N):
    count =0
    nlist = [str(i) for i in range(1,N+1)]
    for i in range(N-1):
        
        idx = nlist.index(s[i])
        nlist.remove(s[i])
        count += (idx)*(kai[len(nlist)-1])
        
    return count+1

print(abs(calc(p,N)-abs(calc(q,N))))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MAX_N 1000100

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define LOWBIT(x) ( (x) & -(x) )

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

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

int main()
{
	//freopen("t.txt","r",stdin);
	char a,b; cin>>a>>b;
	if (a=='H'){
        cout<<b;
	}
	if (a=='D'){
        if (b=='H') cout<<'D';
        else cout<<'H';
	}
}


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

using LL = long long;

void eval(LL arr[50]) {
    auto it = std::min_element(arr, arr + 50) - arr;
    arr[it] += 50;
    for (int i = 0; i < 50; ++i) {
        if (i != it)
            --arr[i];
    }
}

bool solve() {
    LL k;
    std::cin >> k;
    if (k == 0) {
        std::cout << "2\n1 1";
    } else if (k == 1) {
        std::cout << "2\n2 0";
    } else if (k <= 50) {
        std::cout << k << '\n';
        for (LL i = 0; i < k; ++i)
            std::cout << i + 1 << ' ';
    } else {
        LL p = 50;
        std::cout << p << '\n';
        LL n = k / p + p - 1; 
        LL s = k % p;
        LL arr[50];
        for (LL i = 0; i < p; ++i)
            arr[i] = n - i;
        for (LL i = 0; i < s; ++i)
            eval(arr);
        for (int i = 0; i < p; ++i)
            std::cout << arr[i] << ' ';
    }
    std::cout << '\n';

    return 0;
}

int main() {
#ifdef LOCALHOST
    freopen("input", "r", stdin);
#endif
    while (solve());

    return 0;
}


Measured memory_bytes: 256
def punch(n)
	0.upto(2) do |i|
		0.upto(2) do |j|
			if $a[i][j] == n then
				$a[i][j] = 0
			end
		end
	end
end

def bingo?()
	0.upto(2) do |i|
		if $a[i][0]==0 && $a[i][1]==0 && $a[i][2]==0 then return true end
		if $a[0][i]==0 && $a[1][i]==0 && $a[2][i]==0 then return true end
	end
	if $a[0][0]==0 && $a[1][1]==0 && $a[2][2]==0 then return true end
	if $a[0][2]==0 && $a[1][1]==0 && $a[2][0]==0 then return true end
end

$a = []
3.times do
	$a << gets.chomp.split(" ").map{|e|e.to_i}
end

gets.chomp.to_i.times do
	punch(gets.chomp.to_i)
end

if bingo? then
	print("Yes")
else
	print("No")
end

Measured memory_bytes: 1788
import java.util.*;

public class Main{
	public static void main(String[] args){
		//new Main().printHelloWorld();
		//System.out.println(new Main().ITP1_1_B(Integer.parseInt(new Scanner(System.in).next())));
		//new Main().ITP1_1_C();
		//new Main().ITP1_1_D();
		//new Main().ITP1_2_A();
		//new Main().ITP1_2_B();
		//new Main().ITP1_2_C();
		//new Main().ITP1_2_D();
		//new Main().ITP1_3_A();
		//new Main().ITP1_3_B();
		new Main().ITP1_3_C();
	}

	public void printHelloWorld(){
		System.out.println("Hello World");
	}

	public int ITP1_1_B(int x){
		return x*x*x;
	}

	public void ITP1_1_C(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println(a*b + " " + 2*(a+b));
	}

	public void ITP1_1_D(){
		int seconds = new Scanner(System.in).nextInt();
		System.out.println(seconds/3600 + ":" + (seconds%3600)/60 + ":" + (seconds%3600)%60);
	}

	public void ITP1_2_A(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println((a==b)?"a == b":(a > b)?"a > b":"a < b");
	}

	public void ITP1_2_B(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		System.out.println((a < b && b < c)?"Yes":"No");
	}

	public void ITP1_2_C(){
		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		for(int i=0;i<a.length-1;i++){
			for(int j=i+1;j<a.length;j++){
				if(a[i] > a[j]){
					int t=a[i];a[i]=a[j];a[j]=t;
				}
			}
		}
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}

	public void ITP1_2_D(){
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int h = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		System.out.println((x+r<=w && x-r>=0 && y+r<=h && y-r>=0)?"Yes":"No");
	}

	public void ITP1_3_A(){
		for(int i=0;i<1000;i++){
			System.out.println("Hello World");
		}
	}

	public void ITP1_3_B(){
		Scanner scan = new Scanner(System.in);
		int i = 1;
		while(scan.hasNext()){
			int x = scan.nextInt();
			if(x == 0){
				break;
			}
			System.out.println("Case " + i + ": " + x);
			i++;
		}
	}

	public void ITP1_3_C(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int x = scan.nextInt();
			int y = scan.nextInt();
			if(x == 0 && y == 0){
				break;
			}
			System.out.println((x < y)?x+" "+y:y+" "+x);
		}
	}
}

Measured memory_bytes: 35416
# include <iostream>
# include <algorithm>
# define MAX_N 201
# define MAX_D 201

int d, n;
int a[MAX_N], b[MAX_N], c[MAX_N];
int t[MAX_D];
int dp[MAX_D][MAX_N];

int main() {
	std::cin >> d >> n;
	for (int i = 1; i <= d; ++i)
		std::cin >> t[i];
	for (int i = 1; i <= n; ++i)
		std::cin >> a[i] >> b[i] >> c[i];
	for (int i = 2; i <= d; ++i) {
		for (int j = 1; j <= n; ++j) {
			int max = -1;
			if (a[j] <= t[i] && b[j] >= t[i]) {
				for (int k = 1; k <= n; ++k) {
					if (a[k] <= t[i - 1] && t[i - 1] <= b[k]) {
						max = std::max(max, dp[i - 1][k] + std::abs(c[j] - c[k]));
					}
				}
				dp[i][j] = max;
			}
		}
	}
	int res = -1;
	for (int i = 1; i <= n; ++i)
		res = std::max(res, dp[d][i]);
	std::cout << res << std::endl;
	return 0;
}

Measured memory_bytes: 1320
s = input()
n = len(s)-1
if n == 0:
    print(s)
    exit()

ans = 0
for i in range(2**n):
    data = []
    for j in range(n):
        if((i >> j) & 1):
            data.append(1)
        else:
            data.append(0)
    # print(data)
    num = s[0]
    x = []
    for i in range(n-1):
        if data[i] == 1:
            x.append(int(num))
            num = s[i+1]
        else:
            num += s[i+1]
    if data[-1] == 0:
        num += s[-1]
        x.append(int(num))
    else:
        x.append(int(num))
        x.append(int(s[-1]))
    ans += sum(x)
    # print(x)
print(ans)


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int areaA = a * b;
        int areaB = c * d;
        if(areaA >= areaB) System.out.println(areaA);
        else System.out.println(areaB);

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 21204
#include <stdio.h>
#include <stdlib.h>
#define N 8

void search(int);
void output();

int n,arr[N][N],row[N],col[N],rina[2*N-1],lena[2*N-1];
int main(){
  int i,j,x,y;

  for(i=0;i<N;i++) row[i]=col[i]=-1;
  for(i=0;i<2*N-1;i++) rina[i]=lena[i]=-1;
  
  scanf("%d",&n);
  for(i=0;i<N;i++)
    for(j=0;j<N;j++) arr[i][j] = -1;
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    arr[x][y] = 1;
  }
  search(0);
  return 0;
}

void search(int put){
  int i,j;
  
  if(put == N){
    output();
    return ;
  }
  for(i=0;i<N;i++){
    if(col[i] == 1 || lena[i+put] == 1 || rina[put-i+N-1] == 1) continue;
    row[put]=i;
    col[i]=lena[i+put]=rina[put-i+N-1]=1;
    search(put+1);
    row[put]=col[i]=lena[put+i]=rina[put-i+N-1]=-1;
  }
}

void output(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(arr[i][j]==1 && row[i]!=j)return ;
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        if(a[i]*(4*m) >= sum) count += 1;
    }

    if(count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;

int main(){
    scanf("%ld", &n);
    for(long i = 1; i <= 9; i++){
        if(n % i == 0 && n / i < 10){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
}


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

using namespace std;

int main() {
    int x, n;
    cin >> x >> n;

    unordered_set<int> p;
    int tmp;
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        p.insert(tmp);
    }

    if(p.find(x) == p.end()) {
        cout << x << endl;
        return 0;
    }

    for(int i = 1; i <= 100; i++) {
        if(p.find(x-i) == p.end()) {
            cout << (x-i) << endl;
            break;
        }
        if(p.find(x+i) == p.end()) {
            cout << (x+i) << endl;
            break;
        }
    }
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>

int main(void){
  unsigned long a, b, x;
  scanf("%ld %ld %ld", &a, &b, &x);
  if(a%x == 0){
    printf("%ld\n", b/x - a/x + 1);
  }else{
    printf("%ld\n", b/x - a/x);
  }
}


Measured memory_bytes: 128
A = sum([list(map(int, input().split())) for _ in range(3)], [])
N = int(input())

ans = 0

for _ in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
    if (
        A[0] + A[1] + A[2] == 0
        or A[3] + A[4] + A[5] == 0
        or A[6] + A[7] + A[8] == 0
        or A[0] + A[3] + A[6] == 0
        or A[1] + A[4] + A[7] == 0
        or A[2] + A[5] + A[8] == 0
        or A[0] + A[4] + A[8] == 0
        or A[2] + A[4] + A[6] == 0
    ):
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int N = 10010;
const int s[10] = {0,2,5,5,4,5,6,3,7,6};
struct Node {int id, cnt;} a[20];
int f[N], n, m;
std::vector<int>v[N];
bool operator < (Node a, Node b) { return a.id > b.id; }
int main() {
	std::cin >> n >> m;
	for(int i = 1; i <= m; ++i) std::cin >> a[i].id, a[i].cnt = s[a[i].id];
	std::sort(a + 1, a + m + 1); std::memset(f, -0x3f, sizeof(f)); f[0] = 0;
	for(int i = 1; i <= n; ++i) 
		for(int j = 1; j <= m; ++j) 
			if(i - a[j].cnt >= 0 && f[i - a[j].cnt] + 1 > f[i]) 
				v[i] = v[i - a[j].cnt], v[i].push_back(a[j].id), f[i] = f[i - a[j].cnt] + 1;
	for(int i = v[n].size() - 1; i >= 0; --i) std::cout << v[n][i];
}

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

void solve () {
    int x;
    cin >> x;
    if (x >= 400 && x <= 599) {
        cout << 8;
    } else if (x >= 600 && x <= 799) {
        cout << 7;
    } else if (x >= 800 && x <= 999) {
        cout << 6;
    } else if (x >= 1000 && x <= 1199) {
        cout << 5;
    } else if (x >= 1200 && x <= 1399) {
        cout << 4;
    } else if (x >= 1400 && x <= 1599) {
        cout << 3;
    } else if (x >= 1600 && x <= 1799) {
        cout << 2;
    } else {
        cout << 1;
    }
}

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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	//sort(a.begin(), a.end(),greater<ll>());
	sort(a.begin(), a.end());
	vector<ll> sums(N + 1);
	for (int i = 0; i < N; i++) {
		sums[i + 1] = a[i] + sums[i];
	}
	ll ans = 1;
	for (int i = N - 1; i >= 0; i--) {
		//cout << sums[i] << endl;
		if (2*sums[i] >= a[i]) 
			ans++;
		else break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a>0) cout << "Positive" << endl; 
  if(a<=0&&b>=0) cout << "Zero" << endl;
  if(b<0) {
    if((b-a)%2==0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
  }
  return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
		int d , t , s ;
		cin>>d>>t>>s;
		int dist = t * s ;
		if( dist >= d )
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		} 
		
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    int cur1 = 0, cur2 = K;
    while (cur2 < N) {
        if (a[cur1] < a[cur2]) cout << "Yes" << endl;
        else cout << "No" << endl;
        cur1++;
        cur2++;
    }
}


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

int n;
int a[100005], f[100005];
int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &a[i]), ++f[a[i]];
    int Max = 0;
    for(int i = 1; i <= 100000 ; ++i)
        Max = max(Max, f[i] + f[i - 1] + f[i + 1]);
    printf("%d", Max);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,h; cin >> n >> h;
  vector<int> a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  
  int cnt=0;
  while(h>0 && b[cnt]>a[0]){
    h -= b[cnt];
    cnt++;
    if(cnt==n){ break; }
  }
  int ans = cnt;
  if(h>0){ ans += (h+a[0]-1)/a[0]; }
  cout << ans << endl; 
  return 0;
}  


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> v(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++)cin >> v[i][j];
    }

    int ret = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) {
                int dis = (v[i][k] - v[j][k]);
                sum += dis * dis;
            }
            if ((int) sqrt(sum) * (int) sqrt(sum) == sum)ret++;
        }
    }

    cout << ret << endl;
    return 0;
}

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

int main(){
  int r;
  cin >>r;
  if(r < 1200){
      cout << "ABC" <<endl;
      return 0;
  } 
  else if(r < 2800) {
      cout << "ARC" << endl;
      return 0;
  }
  else {
      cout << "AGC" << endl;
  }
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const string YES = "Yes";
const string NO = "No";

void solve()
{
  ll A;
  scanf("%lld",&A);
  ll B;
  scanf("%lld",&B);
  if (A*B%2==1) cout << YES << endl;
  else cout << NO << endl;
}

int main()
{
  solve();
  return 0;
}


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

/**
|||||||||||||       |||||     |||||    ||||||||||
||||||||||||||      |||||     |||||  |||||
|||||     |||||     |||||     |||||  |||||
||||||||||||||||    |||||||||||||||    ||||||||||
|||||||||||||||||   |||||||||||||||           |||||
|||||        |||||  |||||     |||||           |||||
|||||         ||||| |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;
long long div(long long a,long long b,long long c) {
    return (b/c)-(a/c)+!(a%c);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << (b-a+1)-(div(a,b,c)+div(a,b,d)-div(a,b,(c*d/(__gcd(c,d)))))<< endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a,b,c,total,count int

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&total)

	for i := 0; i < a+1; i++ {
		for j := 0; j < b+1; j++ {
			for k := 0; k < c+1 ; k++ {
				if total == 500*i+100*j+50*k {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1768
import java.util.Scanner;
/**
 * 2018-04-14
 * https://beta.atcoder.jp/contests/abc094/tasks/abc094_a
 */
public class Main {
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int  A = sc.nextInt();
        int  B = sc.nextInt();
        int  X = sc.nextInt();

      //  System.out.println(A);
      //  System.out.println(B);
      //  System.out.println(X);


        String ans = null;
        if((A <= X )&& (A+B)>=X){
            ans ="YES";
        }else{
            ans ="NO";
        }

        System.out.println(ans);


    }
}


Measured memory_bytes: 24916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    while(true){
        int n; cin >> n;
        if(n==0) return 0;
        string s; cin >> s;
        vector<int> v(n,0);
        int field = 0;
        rep(i,100) {
            if(s[i]=='S') {
                field += v[i%n] + 1;
                v[i%n] = 0;
            }else if(s[i]=='M') {
                v[i%n]++;
            }else {
                v[i%n] += field + 1;
                field = 0;
            }
        }
        sort(ALL(v));
        rep(i,n) cout << v[i] << " ";
        cout << field << endl;
    }

    return 0;
}


Measured memory_bytes: 3212
n = int(input())
s = input()

num_r = s.count("R")
num_g = s.count("G")
num_b = s.count("B")


def search(n,s):
    ans = num_r * num_g * num_b

    for i in range(n):
        for j in range(i,n):
            k=2*j-i
            if (k<n) and (s[i]!=s[j]) and (s[i]!=s[k]) and (s[j]!=s[k]):
                ans -= 1

    return ans
print(search(n,s))


Measured memory_bytes: 9208
#include<iostream>
#include<vector>
#include<cstdio>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

inline pair<int,int> hitBlow(int a, int b){
  int hit = 0;
  int blow = 0;
  int cntA[10] = { 0 };
  int cntB[10] = { 0 };

  REP(i, 4){
    int aa = a % 10;
    int bb = b % 10;

    if(aa == bb) ++hit;
    ++cntA[aa];
    ++cntB[bb];

    a /= 10;
    b /= 10;
  }

  REP(i,10){
    blow += min(cntA[i], cntB[i]);
  }
  blow -= hit;

  return mp(hit, blow);
}

inline bool different(int a){
  int cnt[10] = { 0 };
  REP(i,4){
    int aa = a % 10;
    if(cnt[aa]++ != 0)
      return false;
    a /= 10;
  }
  return true;
}

int main(){
  int n;
  while((n = getInt()) != 0){
    int fdn[n];
    int hits[n];
    int blows[n];
    vector<int> ans;

    REP(i,n){
      fdn[i] = getInt();
      hits[i] = getInt();
      blows[i] = getInt();
    }

    REP(i,10000) if(different(i)){
      REP(j,n){
        pair<int,int> ret = hitBlow(i, fdn[j]);
        int hit = ret.f;
        int blow = ret.s;

        if(hits[j] != hit || blows[j] != blow){
          goto bad;
        }
      }
      ans.push_back(i);
    bad:;
    }

    if(ans.size() == 1){
      printf("%04d\n", ans[0]);
    }else if(ans.size() > 1 && ans.size() < 25){
      bool ok = false;
      REP(i,10000) if(different(i)){
        int cnt[5][5] = {{ 0 }};
        REP(j, ans.size()){
          pair<int,int> ret = hitBlow(i, ans[j]);
          if(cnt[ret.f][ret.s]++ != 0)
            goto bad2;
        }
        printf("%04d\n", i);
        ok = true;
        break;
      bad2:;
      }
      if(!ok) puts("????");
    }else{
      puts("????");
    }
  }
  return 0;
}

Measured memory_bytes: 904
N,K=map(int,input().split())
p=list(map(int,input().split()))

x=[0]*N
y=[0]*(N+1-K)

for i in range(N):
  x[i]=0.5*(p[i]+1)
for i in range(K):
  y[0]+=x[i]
for i in range(N+1-K):
  if i!=0:
    y[i]=y[i-1]-x[i-1]+x[i-1+K]
print(max(y))

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int a, b, c, d, e, f;
int vis[35][3005];

int dfs(int water, int sugar)
{
    if (water * 100 + sugar > f)
        return 0;
    if (sugar > water * e)
        return 0;
    if (vis[water][sugar])
        return 1;
    
    dfs(water + a, sugar);
    dfs(water + b, sugar);
    dfs(water, sugar + c);
    dfs(water, sugar + d);
    return vis[water][sugar] = 1;
}

ii bst(ii a, ii b)
{
    int x, y, p, q;
    tie(x, y) = a;
    tie(p, q) = b;
    if (100 * y * (p + q) > 100 * q * (x + y))
        return a;
    return b;
}

int main()
{
    cin >> a >> b >> c >> d >> e >> f;
    dfs(0, 0);
    ii sol;
    for (int i = 0; i <= 30; ++i)
        for (int j = 0; i + j <= f; ++j)
            if (vis[i][j])
                sol = bst(sol, {i * 100, j});
    cout << sol.first + sol.second _ sol.second;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,n,p,k,a[N],K;
long long f[N],g[N],M1,M2,sum[N],ans,F[N],G[N];
int main()
{
		scanf("%d%d",&n,&K);
		for (i=1;i<=n;++i) scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i];
		M1=M2=0;
		for (i=1;i<=n;++i)
		{
			 f[i]=M1+sum[i];
			 g[i]=M2;
			 M1=max(M1,g[i]-sum[i]);
			 M2=max(M2,f[i]);
		}
		M1=0+sum[n]; M2=0;
		for (i=n;i>=1;--i)
		{
			F[i]=M1-sum[i-1];
			G[i]=M2;
			M1=max(M1,G[i]+sum[i-1]);
			M2=max(M2,F[i]);
		}
		for (i=1;i<=n;++i)	
		if (i+K-1<=n) ans=max(ans,max(f[i-1],g[i-1])+max(0ll,sum[i+K-1]-sum[i-1])+max(G[i+K],F[i+K]));
		cout<<ans<<endl;
}

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

using namespace std;

int main()
{
  string S[100];
  int H, W;

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

  cout << string(W + 2, '#') << endl;
  for(int i = 0; i < H; i++) {
    cout << "#" << S[i] << "#" << endl;
  }
  cout << string(W + 2, '#') << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================

	ll N;
	cin >> N;
	vll A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

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

	ll n_same = 0;
	for (int i = 0; i < N - 1; i++)
	{
		if (A[i] == A[i + 1])
		{
			n_same++;
		}
	}

	if (n_same % 2 == 0)
	{
		cout << N - n_same << endl;
		return 0;
	}
	else
	{
		cout << N - n_same - 1 << endl;
	}





}





Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a = 0, b = 0;
	while (cin >> a)
	{
		b = 0;
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				for (int k = 0; k < 10; k++)
				{
					for (int l = 0; l < 10; l++)
					{
						if (i + j + k + l == a)
						{
							b++;
						}
					}
				}
			}
		}
		cout << b << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2988
#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
#include<functional>

int const MAXN = 2e5;
int const MAXNN = 1<<18;
int a[MAXN], ans[MAXN], N;
std::vector<int> G[MAXN];

template<typename T, int NN>
struct bit {
  typedef std::function<T(T,T)> OP;
  T data_[NN]; // 0-base
  OP& op_;
  T e_;
  std::stack<std::vector<std::pair<int,T>>> ul_;
  bit(OP& op, T e) : op_(op), e_(e) { std::fill_n(data_, NN, e_); }
  int lb(int i){ return i&-i; }
  T query(int i) { // 1-base
    T res = e_;
    while(i > 0) { res = op_(res, data_[i-1]); i -= lb(i); }
    return res;
  }
  void add(int i, T const& v) { // 1-base
    std::vector<std::pair<int,T>> save;
    while(i <= NN) {
      save.emplace_back(i-1, data_[i-1]);
      data_[i-1] = op_(data_[i-1], v);
      i += lb(i);
    }
    ul_.push(save);
  }
  void undo() {
    std::vector<std::pair<int,T>>& save = ul_.top();
    for(auto p: save) data_[p.first] = p.second;
    ul_.pop();
  }
};
bit<int, MAXNN>::OP op = [](int x, int y){ return std::max(x, y); };
bit<int, MAXNN> max_bit(op, 0);

void dfs(int v, int p) {
  max_bit.add(a[v], max_bit.query(a[v]-1)+1);
  ans[v] = max_bit.query(MAXN);
  for(auto c: G[v]) if(c != p) dfs(c, v);
  max_bit.undo();
}

int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> a[i];
  
  // compress a[]
  std::set<int> s(a, a+N);
  std::map<int,int> m;
  int fv = 0;
  for(int v: s) m[v] = ++fv;
  for(int i = 0; i < N; ++i) a[i] = m[a[i]];
  
  for(int i = 0; i < N-1; ++i) {
    int u, v; std::cin >> u >> v; --u; --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1);
  for(int i = 0; i < N; ++i) std::cout << ans[i] << "\n";
  return 0;
}


Measured memory_bytes: 67004