akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N, A, B;
    cin >> N >> A >> B;

    int allSum = 0;
    for (int i = 1; i < N + 1; i++) {
        int sum = 0;
        int tmp = i;
        while (1) {
            sum += tmp % 10;
            tmp /= 10;
            if (tmp == 0) {
                break;
            }
            if (sum > B) {
                break;
            }
        }

        if (sum <= B && sum >= A) {
            allSum += i;
        }
    }
    cout << allSum;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> D(n);
    rep(i, n) cin >> D[i];
    sort(all(D));
    cout << D[n / 2] - D[n / 2 - 1] << endl;
}

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


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    string s;
    cin >> s;
    int count=0;
    int n=s.size();
    for (int i = 0; i < n; i++){
        if((i%2==1&&s[i]=='1') || (i%2==0&&s[i]=='0')) count++;
    }
    count = min(count,n-count);
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 512
while True:
  b,r,g,c,s,t = map(int,input().split(" "))
  if b == r == g == c == s == t == 0: break
  print(100+(b+r)*15+g*7+c*2+(b*5+r*3)*13-(t-(s+b*5+r*3))*3)


Measured memory_bytes: 5596
#include <iostream>
#include <cstring>

using namespace std;

string s;

int main()
{
	cin >> s;
	if (s[0] == s[s.length() - 1] && s.length() % 2) cout << "Second" << endl;
	else if (s[0] == s[s.length() - 1] || s.length() % 2) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 512
data = Array.new
out = Array.new
while input = STDIN.gets
  data.push(input.to_i)
end
data.sort!
out.push([data[0],1])
data.shift
for i in 0.. data.length-1
  if out[out.length-1][0] != data[i]
    out.push([data[i],1])
  else
    out[out.length-1][1] += 1
  end
end
max=0
num = Array.new
for i in 0.. out.length-1
  if out[i][1] > max
    max = out[i][1]
    num = Array.new
    num.push(out[i][0])
  elsif out[i][1] == max
    num.push(out[i][0])
  end
end
puts num.sort!*"\n"

Measured memory_bytes: 2308
def main():
    bingo = []
    for i in range(3):
        a = list(map(int, input().split()))
        bingo.append(a)
    
    n = int(input())
    for j in range(n):
        b = int(input())

        for k in range(3):
            for l in range(3):
                if int(bingo[k][l]) == b:
                    bingo[k][l] = -1
    

    if [bingo[0][0],bingo[1][1],bingo[2][2]] == [-1,-1,-1] or [bingo[2][0],bingo[1][1],bingo[0][2]] == [-1,-1,-1]:
        print('Yes')
    else:
        for ii in range(3):    
            if bingo[ii][0:3] == [-1,-1,-1] or [bingo[0][ii],bingo[1][ii],bingo[2][ii]] == [-1,-1,-1]:
                
                print('Yes')
                break
        else:
            print('No')




if __name__ == '__main__':
    main()



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

int main(){
  int sum = 0;
  for (int i = 0; i < 5; i ++) {
    int t; cin >> t;
    t = max(40, t);
    sum += t;
  }

  cout << sum/5 << endl;
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#define max_size (int)(2 * 1e5 + 1)
#define inf (int)(1e9)

int min(int a, int b){
	return a <= b ? a : b;
}

int main(){
	int i, j, N, dp_min;
	char *S = (char *)malloc(sizeof(char) * max_size);
	scanf("%s", S);
	for(i = 0; S[i] != '\0'; i++){}
	N = i;
	int *S_num = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		S_num[i] = (int)S[i] - (int)'a';
	}
	int *a = (int *)malloc(sizeof(int) * (N + 1));
	a[0] = 0;
	for(i = 0; i < N; i++){
		a[i + 1] = a[i] ^ (1 << S_num[i]);
	}
	int P_alf = (1 << 26);
	int *dp = (int *)malloc(sizeof(int) * P_alf);
	dp[0] = 0;
	for(i = 1; i < P_alf; i++){
		dp[i] = inf;
	}
	int *opt = (int *)malloc(sizeof(int) * (N + 1));
	opt[0] = 0;
	for(i = 1; i <= N; i++){
//		printf("i = %d\n", i);
		dp_min = dp[a[i]];
//		printf("dp_min = %d\n", dp_min);
		for(j = 0; j < 26; j++){
			dp_min = min(dp_min, dp[a[i] ^ (1 << j)]);
//			printf("j = %d: dp_min = %d\n", j, dp_min);
		}
		opt[i] = dp_min + 1;
//		printf("opt[%d] = %d\n", i, opt[i]);
		dp[a[i]] = min(dp[a[i]], opt[i]);
	}
	printf("%d\n", opt[N]);
	return 0;
}

Measured memory_bytes: 264832
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;

 ll mod=1e9 +7;


const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

int main()
{

	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
 //    #endif

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    compute();

    ll tests=1,t=1;
   // cin>>tests;
    while(tests--)
    {
    	ll i,n;
    	cin>>n;
    	vector<ll>a(n+1);
    	rep(i,1,n) cin>>a[i];
    	for(i=n;i>=1;i-=2)
    	{cout<<a[i]<<" ";}
    	if(i==0) i=1;
    	else i=2;
    	while(i<=n)
    	{
    		cout<<a[i]<<" ";
    		i+=2;
    	}
    }

	return 0;
}

Measured memory_bytes: 12708
import math

n = int(input())
nums = list(map(int, input().split()))

avg_ceil = math.ceil(sum(nums) / len(nums))
avg_floor = math.floor(sum(nums) / len(nums))

cost_ceil = 0
cost_floor = 0

for x in nums:
    if x == avg_ceil:
        continue
    cost_ceil += (x - avg_ceil)**2

for x in nums:
    if x == avg_floor:
        continue
    cost_floor += (x - avg_floor)**2

if cost_ceil <= cost_floor:
    print(cost_ceil)
else:
    print(cost_floor)



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

int main() {
  int N, K;
  cin >> N;
  cin >> K;
  
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x < abs(x - K))
      sum += x * 2;
    else
      sum += abs(x - K) * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
from math import radians, cos

def main():
    a,b,h,m = map(int,input().split())
    A = (h*60+m)/720*360
    B = (h*60+m)/60*360%360
    x = radians(A-B)
    c = (a**2+b**2-2*a*b*cos(x))**0.5
    print("{:.12f}".format(c))
main()

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, t_score=0, h_score=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string taro,hanako;
		cin >> taro >> hanako;
		if (taro == hanako) {
			t_score++;
			h_score++;
		}
		else if (taro > hanako) t_score+=3;
		else h_score+=3;
	}
	cout << t_score << " " << h_score << "\n";;
	return 0;
}



Measured memory_bytes: 3220
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    mat = [-1]*n
    susis = []
    smo = 0
    knds = 0
    for _ in range(n):
        t,d = map(int,ipt().split())
        t -= 1
        if mat[t] < d:
            mat[t] = d
        susis.append((d,t))
    susis.sort(reverse=True)
    kh = []
    res = []
    for i in range(k):
        di,ti = susis[i]
        smo += di
        if di == mat[ti]:
            mat[ti] = -1
            knds += 1
        else:
            hpq.heappush(res,di)
    for i in mat:
        if i != -1:
            hpq.heappush(kh,-i)

    ma = smo + knds**2
    while len(res) and len(kh):
        knds += 1
        smo -= hpq.heappop(res)
        smo -= hpq.heappop(kh)
        if ma < smo+knds**2:
            ma = smo+knds**2

    print(ma)


    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 59864
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  int c = 0;
  if(s[0] == 'o') c++;
  if(s[1] == 'o') c++;
  if(s[2] == 'o') c++;
  cout<< 700 + c * 100 << endl;
  
  return 0;
}


Measured memory_bytes: 256
n = STDIN.gets.to_i
s = STDIN.gets.split[0...n].map(&:to_i)
q = STDIN.gets.to_i
t = STDIN.gets.split[0...q].map(&:to_i)

count = 0
t.each do |te|
	s.each do |se|
		if te == se
			count += 1
			break
		end
	end
end
p count

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector< vector<long long> > dp(n + 1, vector<long long>(n + 1));
  int sgn = (n & 1) ? 1 : -1;

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j + i <= n; j++) {
      if (sgn > 0) {
        dp[j][j + i] = max(a[j] + dp[j + 1][j + i],
                           a[j + i - 1] + dp[j][j + i - 1]);
      } else {
        dp[j][j + i] = min(-a[j] + dp[j + 1][j + i],
                           -a[j + i - 1] + dp[j][j + i - 1]);
      }
    }
    sgn *= -1;
  }
  cout << dp[0][n] << '\n';
  return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	vector<ll> a(n), b(n);

	rep(i, 0, n) read(a[i], b[i]);

	ll lo, hi;

	sort(all(a));
	sort(all(b));

	if (n % 2 == 1) {
		lo = a[n / 2], hi = b[n / 2];
		die(hi - lo + 1);
	} else {
		lo = a[n / 2 - 1] + a[n / 2];
		hi = b[n / 2 - 1] + b[n / 2];
		die(hi - lo + 1);
	}
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define lpx(i,x,n) for(int i=x; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
ll arr[N],arr2[N] ;

int dcmp(double x, double y)
{
    return fabs(x - y) <= eps ? 0 : x > y ? -1 : 1;
}



int main()
{

    int n, ans = 0; cin>> n;
    for(int i = 1 ; i <= n ; ++i){
        int a = 0,j=i;
        while(j){
            j/=10;
            ++a;
        }
        if(a%2)++ans;
    }
    cout << ans << endl;

    return 0;
}
























Measured memory_bytes: 256
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    # Prime Factor Decomposition
    @classmethod
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    # List up aliquots
    @classmethod
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
max_ans = M // N
print(max(filter(lambda a: a <= max_ans, PrimeUtils.aliquots(M))))

Measured memory_bytes: 4180
function Main(input) {
    // 最後の文字を取得
    input = input.split("\n");
    input = input[0];
    const last = input.slice(-1) ;
    const sufix = last === "s" ? "es" : "s";
	//出力
	console.log(`${input}${sufix}`);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 114514;
Int dp[MAX*2];
signed main(){
  const Int INF = 1e9;
  for(Int i=0;i<MAX*2;i++) dp[i]=INF;
  dp[0]=0;
  vector<Int> v;
  for(Int k=1;k<MAX;k*=6) v.emplace_back(k);
  for(Int k=1;k<MAX;k*=9) v.emplace_back(k);
  for(Int k:v)
    for(Int i=0;i<MAX;i++)
      chmin(dp[i+k],dp[i]+1);
  
  Int n;
  cin>>n;
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 2048
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;
typedef complex<ld>     cld;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define kill(x)         return cout << x << endl, 0;
#define Mp              make_pair
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

const ll MAXN = 1e5 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7,
         LOG  = 32;
//const ld PI   = M_PI;

ll n, k, a[110], dp[MAXN];

int main()
{
    fastio;
    //ld_io;

    cin >> n >> k;
    for (ll i = 0; i < n; i++)
        cin >> a[i];

    for (ll i = 0; i < MAXN; i++) {
        for (ll j = 0; j < n; j++) {
            if (a[j] > i) continue;
            if (!dp[i-a[j]]) dp[i] = 1;
        }
    }

    cout << (dp[k] ? "First" : "Second") << endl;

    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D, ans;
		N = sc.nextInt();
		D = sc.nextInt();
		int[][] X = new int[N][D];

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();
		ans = 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++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define clr(v, d) memset(v, d, sizeof(v))
#define fi first
#define se second
#define pp push_back
#define pb pop_back
#define pi 3.141592654
#define MOD 1000000007 
#define cons1 1e12
#define cons2 1e6
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned long long int ull;
typedef double long dl;
const int N = 1e5+9,oo=1e9;
int n,k;
int v[N][3], ans[N][4];
int sol(int i,int l) {
	if (i == n)
		return 0;
	int mx = INT_MIN;
	if (!ans[i][l]) {
		if (l != 0)
			mx = max(mx, v[i][0] + sol(i + 1, 0));
		if (l != 1)
			mx = max(mx, v[i][1] + sol(i + 1, 1));
		if (l != 2)
			mx = max(mx, v[i][2] + sol(i + 1, 2));
		ans[i][l] = mx;
	}

	return ans[i][l];
	
}
void solve() {
	cin >> n;
	rep(i, 0, n)
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	cout << sol(0,3) << endl;
	
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while (t--)
		solve();

#ifndef ONLINE_JUDGE
	- system("pause");
#endif

}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b;
	cin>>a>>b;
	long long int sum;
	sum = a * b;
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

class Prime {
public:
    Prime(ll n) {
        mPrimeTbl.clear();
        vector<bool> u(n, false);
        for (ll i = 2; i <= n; ++i) {
            if (u[i])
                continue;
            mPrimeTbl.push_back(i);
            for (ll p = i; p <= n; p += i)
                u[p] = true;
        }
    }

    ~Prime() {}

    ll num() {
        return static_cast<ll>(mPrimeTbl.size());
    }

    ll get(ll index) {
        return mPrimeTbl[index];
    }

private:
    vector<ll> mPrimeTbl;
};

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

    Prime p(55555);
    vector<ll> v;
    REP(i, p.num()) {
        if (p.get(i) % 10 == 1)
            v.push_back(p.get(i));
        if (v.size() == N)
            break;
    }

    REP(i, N) {
        cout << v[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
tree = Unionfindtree(N)
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    tree.union(a,b)
H=set()
for i in range(N):
    s=tree.find(i)
    if s not in H:
        H.add(s)
    #print(s)
print(len(H))

Measured memory_bytes: 72880
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    
    rep(i, 0, N) {
        cin >> x[i] >> y[i];
    }
    
    auto dist = [&](int i, int j) {
        double dx = x[i] - x[j];
        double dy = y[i] - y[j];
        return sqrt(dx * dx + dy * dy);
    };
    vector<int> p(N);
    rep(i, 0, N) p[i] = i;
    double len = 0;
    int cnt = 0;
    do {
        rep(i, 0, N-1){
            len += dist(p[i], p[i+1]);
        }
        cnt++;
    }while (next_permutation(p.begin(), p.end()));
    double ans = len/cnt;
    printf("%.10f\n", ans);
    return 0;

}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const steps = arg[1].split(" ").map(n=>parseInt(n));
    
    const dp = [...Array(N)].fill(Infinity);
    
    dp[0] = 0;
    
    for(let i=1; i<N; i++) {
        let temp = Infinity;
        
        for(let j=1; j<=K; j++) {
            if(i-j >= 0) {
                temp = Math.min(temp, dp[i-j] + Math.abs(steps[i] - steps[i-j]));
            }
        }
        
        dp[i] = temp;
    }
    
    console.log(dp[N-1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32124
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 200010
#define mod 1000000007
using namespace std;
int a[maxn];
LL ans=1,x,y;
int main(){
	int n,k,i,b,l,r;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(a[1]>=0){//全是非负数,绝对值越大越好
		for(i=n;i>=n-k+1;i--)ans=ans*a[i]%mod;
	}else if(a[n]<0){//全是负数
		if(k&1){//k是奇数,乘积结果是负数，要求绝对值越小越好
			for(i=n;i>=n-k+1;i--)ans=ans*a[i]%mod;
			ans=(ans%mod+mod)%mod;
		}else{//k是偶数,乘积结果是正数，要求绝对值越大越好
			for(i=1;i<=k;i++)ans=ans*a[i]%mod;
		}
	}else{//负数,0,正数交织在一起。a[n]>=0,a[1]<0
		int cnt1=0,cnt2=0;
		for(i=1;i<=n;i++)
			if(a[i]<0)cnt1++;//负数个数
			else break;
		cnt2=n-cnt1;//正数与0的个数
		if(cnt1/2*2+cnt2<k){//乘积为负
			for(i=1;i<=n;i++)ans=ans*a[i]%mod;
			ans=(ans%mod+mod)%mod;
		}else{//乘积为非负
			//要求绝对值最大
			if(k&1){//k是奇数，得特殊处理一下，里面一定包含了非负最大值a[n]
				ans=a[n],n--,k--;
			}
			l=1,r=n;//两个两个的选取
			while(k){
				x=(LL)a[l]*a[l+1],y=(LL)a[r]*a[r-1];
				if(x>y)x%=mod,ans=ans*x%mod,l+=2;
				else y%=mod,ans=ans*y%mod,r-=2;
				k-=2;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int x = 1, y = 0, z;
  
  for(int i=0; ; i++) {
    x *= 10; 
    y += (N%x-N%(x/10))/(x/10);
    if(N < x)
     break;
}
  
  if(N%y == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(){

    string s;
    cin >> s;

    string akiba = "KIHBR";
    s = " " + s + " ";
    bool ok = true;
    int idx = 0;

    set<char> f;
    REP(i, 1, s.length() - 1){
        if (s[i] != 'A'){
            if (f.find(s[i]) != f.end()){
                ok = false;
            }
            f.insert(s[i]);
        }
        if (s[i - 1] == s[i]){
            ok = false;
            break;
        }
        else if (s[i - 1] == 'K' && s[i + 1] == 'I'){
            ok = false;
            break;
        }
        else if (s[i - 1] == 'I' && s[i + 1] == 'H'){
            ok = false;
            break;
        }
        if (s[i] == akiba[idx]){
            idx++;
        }
    }
    if (ok && idx == 5 && f.size() == 5){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <sstream>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,e;
    //int f=0;
    string st,tt,nt;
    vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    //a=0;
    e=0;d=0;
    cin>>a>>b;
    if(a*b==15)printa("*");
    else if(a+b==15)printa("+");
    else printa("x");
    return 0;
}

Measured memory_bytes: 384
n = int(input());

cnt = [10000] * 26

for i in range(n) :
	s = input();
	tmp = [0] * 26
	for c in s :
		tmp[ord(c)-ord('a')] += 1;
	for j in range(26):
		cnt[j] = min(cnt[j], tmp[j]);

for i in range(26) :
	for j in range(cnt[i]) :
		print(chr( ord('a') + i  ), end="" )
print("");


Measured memory_bytes: 3060
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
    S[i+1] = (S[i] + A[i])%K
    T[i+1] = (S[i+1] - (i+1))%K
rest = defaultdict(int)
for i in range(N+1):
    if i < K:
        ans += rest[T[i]]
        rest[T[i]] += 1
    else:
        rest[T[i-K]] -= 1
        ans += rest[T[i]]
        rest[T[i]] += 1
print(ans)

Measured memory_bytes: 112972
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
	lli n;
	cin>>n;
	lli arr[n][3];
	for(lli i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	lli dp[n][3];
	for(lli i=0;i<n;i++){
		dp[i][0]=0;
		dp[i][1]=0;
		dp[i][2]=0;
	}
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	for(lli i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
	}
	lli ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4992
/*input
1
1
*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b) {
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int r;
  cin >> r;
  cout << r * r << endl;

  return 0;
}

Measured memory_bytes: 256
function check(n)
  
  for i in 2:round(Int,sqrt(n))
    
    if n % i == 0
      return false
    end
    
  end
  
  return true
  
end

function main()
  
  X = parse(Int, readline())
  
  prime = false
  
  while prime == false
    
	prime = check(X)
    X += 1
    
  end
	
  println(X-1)
  
end

main()

Measured memory_bytes: 112284
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

for($i=0;$i<$N;$i++) {
  list($x[],$y[]) =  explode(" ",trim(fgets(STDIN)));
}
$t = 0.0;
for($i=0;$i<$N;$i++) {
  for($j=$i;$j<$N;$j++) {
    if ($j==$i) continue;
    $t = sqrt(pow($x[$j]-$x[$i],2)+pow($y[$j]-$y[$i],2));
    $tot += $t;
  }
}
for($i=0;$i<$N;$i++) {
  for($j=$i;$j<$N;$j++) {
    if ($j==$i) continue;
    $t = sqrt(pow($x[$i]-$x[$j],2)+pow($y[$i]-$y[$j],2));
    $tot += $t;
  }
}
printf("%f\n",$tot/$N);


Measured memory_bytes: 4856
#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>
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-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, b, c;
	state(int p, int b, int c) : p(p), b(b), c(c) {};
	bool operator<(const state &o)const {
		return o.c<c;
	}
};

int main() {
	int n, m;
	while(cin >> n >> m, n) {
		vvi dist(n, vi(n, INF));
		vvi data(m, vi(3));
		REP(i, m) {
			int a, b, m;
			cin >> a >> b >> m;
			a--; b--;
			data[i][0] = m;
			data[i][1] = a;
			data[i][2] = b;
			dist[a][b] = dist[b][a] = m;
		}
		sort(ALL(data));

		int ans = INF;
		REP(i, m) {
			vector<bool> used(n, false);
			vi usedCost;
			priority_queue<state> Q;
			Q.push(state(0, -1, 0));
			while(!Q.empty()) {
				state st = Q.top();
				Q.pop();
				if(used[st.p]) {
					continue;
				} else if(st.b != -1) {
					usedCost.push_back(dist[st.b][st.p]);
				}
				used[st.p] = true;
				REP(j, n) {
					if(dist[st.p][j] != INF && st.p != j) {
						Q.push(state(j, st.p, dist[st.p][j]));
					}
				}
			}

			REP(j, n) {
				if(!used[j]) {
					goto next;
				}
			}

			sort(ALL(usedCost));
			ans = min(ans, usedCost[usedCost.size()-1]-usedCost[0]);
			dist[data[i][1]][data[i][2]] = dist[data[i][2]][data[i][1]] = INF;

			next:;
		}

		if(ans == INF) {
			cout << -1 << endl;
		} else {
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1796
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int ans;

void dfs(vector<vector<int> >& G,int p,int cost,bitset<101>& visited)
{
  bool update = false;
  for(int i=0;i<G[p].size();i++)
    {
      int next = G[p][i];
      if(!visited[next])
	{
	  visited[next] = 1;
	  dfs(G,next,cost+1,visited);
	  visited[next] = 0;
	  update = true;
	}
    }
  if(!update)
    ans = max(ans,cost);
}

int main()
{
  int n;
  while(cin >> n,n)
    {
      vector<vector<int> > G;
      set<int> input;
      G.resize(101);
      for(int i=0;i<n;i++)
	{
	  int a,b;
	  cin >> a >> b;
	  input.insert(a);
	  input.insert(b);
	  G[a].push_back(b);
	  G[b].push_back(a);
	}

      ans = 2;
      for(set<int>::iterator it = input.begin();it != input.end();it++)
	{
	  bitset<101> visited(0);
	  visited[(*it)] = true;
	  dfs(G,(*it),1,visited);
	  
	}
      cout << ans << endl;
    }
  return 0;
}

Measured memory_bytes: 1228
import java.util.*;

public class Main{

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

        int N = sc.nextInt();
        long[] T = new long[N];
        for(int i = 0; i < N; i++){
            T[i] = sc.nextLong();
        }
        sc.close();

        
        long[] a = new long[N];
        long[] b = new long[N];
        a[0] = T[0];
        b[0] = T[0];
        for(int i = 1; i < N; i++){
            a[i] = gcd(b[i-1], T[i]);
            b[i] = b[i-1]*(T[i]/a[i]);
        }
        System.out.println(b[N-1]);
    }
    static long gcd(long n, long m){
        if(m > n)
            return gcd(m, n);
        else {
            if(m == 0)
                return n;
            else
                return gcd(m, n%m);
        }
    }
}

Measured memory_bytes: 23764
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func countBlack(h, w, i, j int, c []string) int {
	cnt := 0
	for x := 0; x < h; x++ {
		if (i>>uint(x))&1 == 0 {
			continue
		}
		for y := 0; y < w; y++ {
			if (j>>uint(y))&1 == 0 {
				continue
			}
			if c[x][y] == '#' {
				cnt++
			}
		}
	}
	return cnt
}

func solve(h, w, k int, c []string) int {
	hNum := (1 << uint(h))
	wNum := (1 << uint(w))

	ans := 0
	for i := 0; i < hNum; i++ {
		for j := 0; j < wNum; j++ {
			if countBlack(h, w, i, j, c) == k {
				ans++
			}
		}
	}
	return ans
}

func main() {
	h, _ := strconv.Atoi(input())
	w, _ := strconv.Atoi(input())
	k, _ := strconv.Atoi(input())
	c := make([]string, h)
	for i := 0; i < h; i++ {
		c[i] = input()
	}
	fmt.Println(solve(h, w, k, c))
}


Measured memory_bytes: 1772
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int n;
	int[] a;
	
	void run() {
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			a=new int[n];
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve() {
		sort(a);
		int sum=0;
		for(int i=1;i<n-1;i++){
			sum+=a[i];
		}
		println(""+sum/(n-2));
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        while(true){
            int x = Integer.parseInt(in.next()), y = Integer.parseInt(in.next());
            if(x == 0 && y == 0)break;

            if(x <= y)System.out.println(x +" "+ y);
            else System.out.println(y +" "+ x);
        }
    }
}


Measured memory_bytes: 36312
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int n, s, t, c=0;
    bool f=false;
    cin >> n;
    REP(i, n) {
        cin >> s >> t;
        if(s == t) c++; else c = 0;
        if(c == 3) {
            f = true;
            break;
        }
    }
    Yes(f);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
string num2str (int n, int base) {
  assert(n >= 0 and 2 <= base and base <= 36);
  string res;
  while (n) {
    int r = n % base;
    res = (r < 10 ? (char) ('0' + r) : (char) ('A' + r - 10)) + res;
    n /= base;
  }
  return res;
}
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<int> d(k); for (int i = 0; i < k; i++) cin >> d[i];
  auto f = [&](int n) {
    string s = num2str(n, 10);
    for (auto&& c : s) {
      if (binary_search(d.begin(), d.end(), c - '0')) return false;
    }
    return true;
  };
  while (not f(n)) n++;
  cout << n << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int l = 0;
    int r = n - 1;
    int i = 0;
    while (l < r) {
        while (s[l] == 'R') l ++;
        // when it stops s[l] == 'L'
        while (s[r] == 'W') r --;
        // same
        if (l >= r) break;
        swap(s[l], s[r]);
        i ++;
    }
    cout << i << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int d;

int dp[10005][105];

void precompute(){
    dp[0][0]=1;
    For(i, 0, 10){
        dp[1][i%d]++;
    }
    For(i, 2, 10001){
        For(j, 0, d){
            For(l, 0, 10){
                int mod = (j+l)%d;
                dp[i][mod]+=dp[i-1][j];
                dp[i][mod]%=MOD;
            }
        }
    }
}

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s; cin>>s;
    cin>>d;
    precompute();
    dp[0][0]=1;
    int cur = 0;
    int ans = 0;
    For(z, 0, sz(s)){
        int dig = s[z]-'0';
        int r = sz(s)-z-1;
        // rem length mod
        For(i, 0, dig){
            int mo = (cur+i)%d;
            mo = (d-mo)%d;
            ans += dp[r][mo];
            ans %= MOD;
        }
        cur = (cur+dig)%d;
    }
    if(cur!=0){
        ans = (ans-1+MOD)%MOD;
    }
    cout<<ans;
    return 0;
}





Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template <typename X>
struct RMQ{
  vector<X> dat;
  int n;
  X init;
  
  RMQ(int _n,X _init)
  {
    n = 1;
    init = _init;
    while(n < _n) n *= 2;
    dat.resize(2*n-1);
    rep(i,2*n-1){
      dat[i] = init;
    }
  }
  
  void update(int k,X a)
  {
    k += n - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1)/2;
      dat[k] = (dat[2*k+1]+dat[2*k+2])%3;
    }
  }
  
  X query(int a,int b,int k,int l,int r)
  {
    if(r<=a||b<=l) return init;

    if(a<=l&&r<=b) return dat[k];
    else{
      X vl = query(a,b,2*k+1,l,(l+r)/2);
      X vr = query(a,b,2*k+2,(l+r)/2,r);
      return (vl+vr)%3;
    }
  }
};


int main()
{
  string s,t;
  cin >> s >> t;
  int q;
  cin >> q;
  vector<int> a(q),b(q),c(q),d(q);
  rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  rep(i,q){
    a[i]--;
    b[i]--;
    c[i]--;
    d[i]--;
  }
  
  RMQ<int> rmqs(s.size(),0);
  RMQ<int> rmqt(t.size(),0);  

  rep(i,s.size()){
    rmqs.update(i,(int)(s[i]-'A'+1));
  }

  rep(i,t.size()){
    rmqt.update(i,(int)(t[i]-'A'+1));
  }

  rep(i,q){
    int sn = rmqs.query(a[i],b[i]+1,0,0,rmqs.n);
    int tn = rmqt.query(c[i],d[i]+1,0,0,rmqt.n);    
    if(sn==tn) cout << "YES" << "\n";
    else cout << "NO" << "\n";
  }

  
  return 0;
}


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

const int N = 1e5 + 5;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<int> > cnt(10, vector<int> (10, 0));
    for (int i = 1;i <= n;i++) {
        int x = i%10;
        int y = i;
        while (y > 9) {
            y /= 10;
        }
        cnt[y][x]++;
    }
    int ans = 0;
    for (int i = 1;i <= n;i++) {
        int x = i%10;
        int y = i;
        while (y > 9) {
            y /= 10;
        }
        ans += cnt[x][y];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256