akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
bool Pos(long long K, long long A, long long B) {
	for (long long i = K / 2 - 5; i <= K / 2 + 5; i++) {
		if (i<1 || i>K)continue;
		long long t1, t2;
		if (i < A)t1 = i;
		else t1 = i + 1;
		if (K-i+1 < B)t2 = K-i+1;
		else t2 = K-i+2;
		if (t1*t2 >= A*B)return false;
	}
	return true;
}
int main() {
	int Q;
	scanf("%d", &Q);
	long long A, B, bb, ee, r, mid;
	while (Q--) {
		scanf("%lld%lld", &A, &B);
		r = 0;
		bb = 1, ee = A + B;
		while (bb <= ee) {
			mid = (bb + ee) >> 1;
			if (Pos(mid, A, B)) {
				r = mid;
				bb = mid + 1;
			}
			else ee = mid - 1;
		}
		printf("%lld\n", r);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,m,f[310][310][310];
char s[310];

int dfs(int l,int r,int k)
{
    if (l==r) return 1;
    if (l>r) return 0;
    if (f[l][r][k]!=-1) return f[l][r][k];
    f[l][r][k]=max(dfs(l,r-1,k),dfs(l+1,r,k));
    if (s[l]==s[r]) f[l][r][k]=max(f[l][r][k],dfs(l+1,r-1,k)+2);
    else if (k) f[l][r][k]=max(f[l][r][k],dfs(l+1,r-1,k-1)+2);
    return f[l][r][k];
}

int main()
{
    memset(f,-1,sizeof(f));
    scanf("%s",s+1);m=read();
    n=strlen(s+1);
    printf("%d",dfs(1,n,m));
    return 0;
}

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

int main(){
	int N,M;
	cin >> N >> M;
	int m = -1;
	int ans = 0;
	REP(i, M){
		int a,b;
		cin >> a >> b;
		if(b > a){
			ans += b-(a+b)/2;
			m = max(b-(a+b)/2, m);
		}
	}
	cout << ans-m<<endl;
	return 0;
}


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

#define int long long int

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

int p[1000001];
 
void go(){
    for( int i = 2; i*i <= 1000000; i++ ){
        if( p[i] == 0 ){
            for( int j = i; j <= 1000000; j += i ){
                if( p[j] == 0 ){
                    p[j] = i;
                }
            }
        }
    }
    for( int i = 1; i <= 1000000; i++ ){
        if( p[i] == 0 )p[i] = i;
    }
}

int32_t main(){
    go();
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

    int n;
    cin >> n;
    int ar[n];
    for( int i = 0; i < n; i++ ){
        cin >> ar[i];
    }
    map<int,int> cnt;
    for( int i = 0; i < n; i++ ){
        int num = ar[i];
        while( num > 1 ){
            int d = p[num];
            cnt[d]++;
            while( num % d == 0 ){
                num /= d;
            }
        }
    }
    int flag = 1;
    for( auto it : cnt ){
        if( it.second > 1 ){
            flag = 0;
        }
    }
    if( flag ){
        cout << "pairwise coprime";
    }
    else{
        int gc = ar[0];
        for( int i = 1; i < n; i++ ){
            gc = gcd(gc, ar[i]);
        }
        if( gc == 1 ){
            cout << "setwise coprime";
        }
        else{
            cout << "not coprime";
        }
    }
}

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

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

    int n,k;
    cin >> n >> k;
    vector<int> stoneHeights(n);
    for (int i = 0; i < n; ++i) {
        cin >> stoneHeights[i];
    }

    vector<long long> dp(n);
    dp[0] = 0;
    dp[1] = abs(stoneHeights[0] - stoneHeights[1]);
    for (int i = 2; i < n; ++i) {
        dp[i] = 10e17;
        for (int j = 1; j <= k; ++j) {
            if(i-j < 0)
                break;
            long long temp = dp[i - j] + abs(stoneHeights[i] - stoneHeights[i-j]);
            if(temp < dp[i])
                dp[i] = temp;
        }

    }

    cout << dp[n-1];

}




Measured memory_bytes: 1408
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for i in range(1,K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and j == k:
                ans += i
            elif i == j or j == k or k == i:
                ans += gcd(i, j, k) * 3
            else:
                ans += gcd(i, j, k) * 6
print(ans)

Measured memory_bytes: 9652
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  int n, k, ans = 0, r, s, p;
  string t;
  map<char, int> m;
  cin >> n >> k >> r >> s >> p;
  m.insert({'r', p});
  m.insert({'s', r});
  m.insert({'p', s});
  cin >> t;
  for (int i = 0; i < n; i++) {
    if (i < k || t[i] != t[i - k]) {
      ans += m[t[i]];
    } else if (i + k < n && t[i] == t[i + k]) {
      t[i] = (113 ^ t[i - k] ^ t[i + k]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
s=input()
s=s[:len(s)-1]
flag=True

while(flag):
    if len(s)%2==0:
        left=s[:len(s)//2] 
        right=s[len(s)//2:]
        if left==right:
            print(len(s))
            flag=False
        else:
            s=s[0:len(s)-1]
    else:
        s=s[0:len(s)-1]
    
    

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

namespace AtCoder
{
    class Program2
    {

        static void Main(string[] args)
        {
            //lee una linea con numeros
            //var cantidades = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var posicion = Int64.Parse(Console.ReadLine());

            Int64 suma = 0;

            for (int i = 1; i<= posicion; i++)
            {
                if (i % 3 != 0 && i % 5 != 0)
                    suma += i;
            }

            Console.WriteLine(suma.ToString());
        }
    }
}

Measured memory_bytes: 27544
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 10;
int N;
ll A[MAXN];
char C[MAXN];
ll f[3];

int main() {
	register int i;
	f[0] = f[1] = f[2] = -1e18;
	scanf("%d", &N);
	scanf("%lld", &f[0]);
	for(i = 1; i < N; ++i) {
		scanf(" %c", &C[i]);
		scanf("%lld", &A[i]);
		C[i] = C[i] == '+' ? 1 : -1;
		f[0] += A[i] * C[i];
		f[1] -= A[i] * C[i];
		f[2] += A[i] * C[i];
		if(C[i] == -1) f[2] = max(f[2], f[1]), f[1] = max(f[1], f[0]);
		f[1] = max(f[1], f[2]), f[0] = max(f[0], f[1]);
	}
	printf("%lld\n", f[0]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n;
	cin >> n;
	VI a(n);
	rep(i, n)cin >> a[i];

	int ans = INT_MAX;
	FOR(i, -100, 101) {
		int sum = 0;
		rep(j, n) {
			sum += (a[j] - i)*(a[j] - i);
		}
		if (ans > sum)ans = sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define rep1(i,n)  for(int i=1;i<=n;i++)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
typedef long long ll;

int main(){
    fast_io();
    int k;
    cin >> k;
    ll sum = 0;
    rep1(a,k){
        rep1(b,k){
            rep1(c,k){
                int i = 1;
                int gcd = 0;
                while(i <=a && i<=b && i<=c){
                if(a%i == 0 && b%i == 0 && c%i == 0 )
                gcd=i;
                i++;
                }
                sum += gcd;
            }
        }
    }
    
    cout << sum;
    return 0;
}


Measured memory_bytes: 3652
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
s.sort()
ans = 0
c = 0
for i in range(n):
    if s[i][1] <= m - c:
        c += s[i][1]
        ans += s[i][0] * s[i][1]
    else:
        ans += (m - c) * s[i][0]
        break
print(ans)

Measured memory_bytes: 27760
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int A[100005];

int main() {
	int n4 = 0;
	int n2 = 0;
	int odd = 0;
	int flag;
	int n;
	int a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 4 == 0)n4++;
		else if (a % 2 == 0)n2++;
		else odd++;
	}

	if (n == n2)flag = 1;
	if (n2 >= 2) {
		n2 = 1;
		n = n2 + n4 + odd;
	}
	if (2*n4 + 1 >= n)flag = 1;
	else flag = 0;

	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll K,N; cin>>K>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    A.emplace_back(K+A[0]);
    ll ans=K;
    rep(i,N){
        mini(ans,K-(A[i+1]-A[i]));
    }
    cout<< ans <<"\n";


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int a, b, d, e;
  int count = 0;
  for (int i=A; i<=B; i++) {
    a = i / 10000;
    b = i % 10000 / 1000;
    d = i % 100 / 10;
    e = i % 10;
    if (a==e && b==d)
      count++;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
x1 , y1 , x2 , y2 = gets.split.map(&:to_i)
a = x2 - x1
b = y2 - y1
x3 = x2 - b
y3 = y2 + a
x4 = x1 - b
y4 = y1 + a

puts x3.to_s + " " + y3.to_s + " " +  x4.to_s + " " +  y4.to_s


Measured memory_bytes: 1788
import queue

n,m=map(int,input().split())

to = [[] for i in range(n+1)]
pre = [-1] * (n+1)
for i in range(m):
    a,b=map(int,input().split())
    to[a].append(b)
    to[b].append(a)

q = queue.Queue()
q.put((1,0))
while not q.empty():
    x,p = q.get()
    if pre[x] != -1:
        continue
    
    pre[x] = p
    for i in to[x]:
        if pre[i] == -1:
            q.put((i,x))

print('Yes')
for p in pre[2:]:
    print(p)

Measured memory_bytes: 40168
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        String[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);

        if (a > b)
        {
            Console.WriteLine("a > b");
        }
        else if (a < b)
        {
            Console.WriteLine("a < b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 8964
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a=nxtl(),b=nxtl();
    cout<<(a*b)/__gcd(a,b)<<endl;
    
    

    return 0;   
}


 
 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <numeric>
#include <algorithm>
#include <math.h>

using namespace std;

int N, ans = 1000000000;

int main(){
    cin >> N;

    for(int i=0;i<=N;i++){
        int res = 0;
        int j=i;
        while( j > 0 ){
            res += j % 6;
            j /= 6;
        }
        j = N - i;
        while( j > 0 ){
            res += j % 9;
            j /= 9;
        }
        ans = min(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
typedef unsigned long long ull;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    char t[1000001], p[10001];
    cin>>t>>p;
    int tl=strlen(t);
    int pl=strlen(p);
    if(pl>tl) return 0;
    const ull base = 1000000007ULL;
    ull bt = 1;
    for(int i=0; i<pl; i++) bt*=base;
    ull th=0, ph=0;
    for(int i=0; i<pl; i++){
        ph*=base;
        ph+=p[i];
        th*=base;
        th+=t[i];
    }
    for(int pos=0; pos<=tl-pl; pos++) {
        if(th==ph) {
            if(memcmp(t+pos, p, pl)==0) cout<<pos<<'\n';
        }
        th*=base;
        th-=bt*t[pos];
        th+=t[pos+pl];
    }
    return 0;
}

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

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

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int a; cin >> a;
	cout << a+a*a+a*a*a << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>

int main(void){
int i,n,tmp;
long long int min=1000000,max=-1000000,sum=0;

scanf("%d",&n);
	
for(i=0;i<n;i++){
scanf("%d",&tmp);
if(min>tmp)min=tmp;
if(max<tmp)max=tmp;
sum+=tmp;
}

printf("%ld %ld %ld\n",min,max,sum);

return 0;
}


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

int main() {

  int A,B,C,K;
int count=0;
  cin >>A>>B>>C>>K;
  
 while(A>=B){
   B=B*2;
   count++;
 }
  while(B>=C){
    C=C*2;
    count++;
  }
   
  if(count<=K){
    cout<<"Yes"<<endl;
  }
  else{
    
    cout<<"No"<<endl;
  }
 
 return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    if (n%k==0){
        printf("0\n");
    } else {
        printf("1\n");
    }
	return 0 ;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int pow_100(int d)
{
    int res = 1;

    rep(_, d) res *= 100;
    return res;
}

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

    cout << ((n == 100) ? pow_100(d) * (n + 1) : pow_100(d) * n) << '\n';
    return (0);
}


Measured memory_bytes: 3588
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

vector<vector<ll>> num(30);
/*
ll runrun(ll x){
  ll res = num[x-1];
  bool flag = true;
  while(flag){
    res++;
    string s = to_string(res);
    int l = s.size();
    //bool hantei = true;
    //while(hantei){
      rep(i,l-1)if(abs((s.at(i)-'0')-(s.at(i+1)-'0')) > 1)flag = false;
      if(flag){
        flag = false;
        break;
      }else{
        flag = true;
      }

  }
  return res;
}
*/

int main(){
  ll N;
  cin >> N;
  for(int i = 1;i < 10;i++){
    num.at(1).push_back(i);
  }
  for(int i = 2;i < 12;i++){
    ll l = num.at(i-1).size();
    rep(j,l){
      ll iti = num.at(i-1).at(j)%10;
      if(iti-1>=0 && iti-1<=9){
        ll tmp = num.at(i-1).at(j)*10+iti-1;
        num.at(i).push_back(tmp);
      }
      if(iti>=0 && iti<=9){
        ll tmp = num.at(i-1).at(j)*10+iti;
        num.at(i).push_back(tmp);
      }
      if(iti+1>=0 && iti+1<=9){
        ll tmp = num.at(i-1).at(j)*10+iti+1;
        num.at(i).push_back(tmp);
      }
    }
  }
  

  ll cnt = 0;
  bool flag = false;
  int keta = 1;
  while(N>0){
    rep(i,num.at(keta).size()){
      N--;
      //cnt++;
      if(N==0){
        cout << num.at(keta).at(i) << endl;
        //flag = true;
        break;
      }
    }
    keta++;
  }


  //cout << num[N] << endl;
}


Measured memory_bytes: 8172
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

patterns = list(itertools.permutations(list(range(1,N+1))))

pi = 0
qi = 0

for index, pattern in enumerate(patterns):
  if P == pattern:
    pi = index
  if Q == pattern:
    qi = index

print(abs(pi - qi))


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

int main(){
    string str;
    cin >> str;
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        string op;
        int a, b;
        cin >> op >> a >> b;
        if(op == "print"){
            string res = str.substr(a, b - a + 1);
            cout << res << endl;
        }else if(op == "reverse"){
            reverse(str.begin() + a, str.begin() + b + 1);
        }else if(op == "replace"){
            string after;
            cin >> after;
            str.replace(a, b - a + 1, after);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=2e5,mod=998244353;
typedef ll fuko[yuzu|10];
fuko rem[10],p10={1}; 
struct chtholly_tree{
  struct node{
    mutable int l,r,v;
    node(int nl,int nr=-1,int val=0):l(nl),r(nr),v(val) {}
    bool operator <(const node b) const {
      return l<b.l;
    } 
  };
  typedef set<node>::iterator it;
  set<node> s;
  ll yu;
  void insert(int l,int r,int v) {
    s.insert(node(l,r,v));
  }
  it split(int pos) {
    it p=s.lower_bound(pos);
    if (p!=s.end()&&p->l==pos) return p; --p;
    int l=p->l,r=p->r,v=p->v;
    s.erase(p);
    s.insert(node(l,pos-1,v));
    return s.insert(node(pos,r,v)).first;
  }
  void assign(int l,int r,int v,int n) {
    it p,itr=split(r+1),itl=split(l);
    for (p=itl;p!=itr;++p) 
      yu=(yu-rem[p->v][p->r-p->l+1]*p10[n-p->r]%mod+mod)%mod;
    s.erase(itl,itr);
    s.insert(node(l,r,v));
    yu=(yu+rem[v][r-l+1]*p10[n-r]%mod)%mod;
  } 
  void dfs() {
    for (auto p:s) {
      printf("%d %d %d\n",p.l,p.r,p.v);
    }
  }
}lxy;
int main() {
  int i,n,q,j;
  read(n),read(q);
  for (i=1;i<10;++i) {
    for (j=1;j<=yuzu;++j) 
      rem[i][j]=(rem[i][j-1]*10+i)%mod;
  }
  for (i=1;i<=yuzu;++i) p10[i]=p10[i-1]*10%mod;
  lxy.insert(1,n,1);
  lxy.yu=rem[1][n];
  for (int l,r,d;q--;) {
    read(l),read(r),read(d);
    lxy.assign(l,r,d,n);
    printf("%lld\n",lxy.yu);
  }
}

Measured memory_bytes: 31716
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int a[200005], n, m;
bool used[200005];
int main(){
	int i, j;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> a[i];
	}
	int now = 1, ans = 0;
	while(now != 2){
		if(used[now]){
			cout << -1;
			return 0;
		}
		used[now] = 1;
		now = a[now];
		ans++;
	}
	cout << ans;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }

int main()
{
	string S, T;
	int count = 0;

	cin >> S >> T;

	rep(i, 3)
	{
		if (S[i] == T[i])
			count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = [int(input()) for _ in range(N)]

cA = list(Counter(A).items())

cA.sort(reverse=True)

for i in A:
  if i == cA[0][0] and cA[0][1] == 1:
    print(cA[1][0])
  else:
    print(cA[0][0])

Measured memory_bytes: 25720
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

tmp = ""
for i in range(len(s)):
  if s[i] == tmp:
    print("Bad")
    exit()
  tmp = s[i]
else:
  print("Good")

Measured memory_bytes: 21468
#include <stdio.h>

int main(){
  int i,leg;
  int x,y;
  int n = scanf("%d %d",&x ,&y);
  if (1 <= x <= 100 || 1 <= y <= 100){
    for(i=0;i<=x;i++){
      leg = ( 4 * i ) + 2 * (x - i);
      if(leg == y) break; 
     }
    if(i != x+1) printf("Yes");
    if(i == x+1) printf("No");
  
  }else{
  	printf("error");
  } 
  
return 0;
}

Measured memory_bytes: 1736
n, q = map(int, input().split())
s = input()

query = [list(input().split()) for _ in range(q)]

# 左に落ちる。leftから左(leftを含む)は左に落ちて、rightから右は左に落ちない。
left = -1
right = n
while right - left > 1:
    mid = (left + right) // 2
    index = mid
    for w, dir in query:
        if s[index] != w:
            continue
        if dir == 'R':
            index += 1
        elif dir == 'L':
            index -= 1

        if index == n:
            right = mid
            break
        elif index == -1:
            left = mid
            break
    if index != -1:
        right = mid
c1 = left + 1

# 右に落ちる。leftから左(leftを含む)は右に落ちず、rightから右は右に落ちる。
left = -1
right = n
while right - left > 1:
    mid = (left + right) // 2
    index = mid
    for w, dir in query:
        if s[index] != w:
            continue
        if dir == 'R':
            index += 1
        elif dir == 'L':
            index -= 1

        if index == n:
            right = mid
            break
        elif index == -1:
            left = mid
            break
    if index != n:
        left = mid

c2 = n - 1 - left

print(n - c1 - c2)




Measured memory_bytes: 93388
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;           //円形の餅の枚数
  
  set<int> mochi;     //setを使えば、重複を考慮しなくてもよいし計算量も少ない
  int a;                            //というかN使ってない...N使うなら配列＆sortの利用かwhile文-> for文
  while(cin >> a)
    mochi.insert(a);

  cout << mochi.size() << endl;

}

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

typedef long long int int64;

int main()
{
    int64 a,b=0;
    int64 arr[30]={0};
    int64 ans=0;
    int i=0,j;

    scanf("%lld",&a);

    b = a;
    //printf("%lld\n",b);

    if(b%2==1)ans=0;
    else
    {
        while(b>0)
        {
            //printf("b = %lld\n",b);
            b/=5;
            arr[i]=b;
            i++;
        }
        for(j=0;j<i;j++)
        {
            ans+=(arr[j]/2);
        }
    }
    printf("%lld",ans);

}

Measured memory_bytes: 128
import java.util.Scanner;

// print the koch curve
public class Main {
	public static final double sin60 = Math.sqrt(3)/2.0;
	public static final double cos60 = 0.5;
	static class point{
		public double x;
		public double y;
		
		public point(double _x, double _y){
			x = _x;
			y = _y;
		}
		
		public void display() {
			System.out.println(x+" "+y);
		}
	}
	
	
	
	public static point rotate_60(point o, point t) {
		double d_x = t.x - o.x;
		double d_y = t.y - o.y;
		
		return new point(o.x + (cos60*d_x - sin60*d_y), o.y + (sin60*d_x + cos60*d_y));
	}
	
	public static void koch(point s, point e, int depth) {
		if(depth == 0) {
			s.display();
		}
		point x_1 = new point((2*s.x+e.x)/3.0, (2*s.y+e.y)/3.0);
		point x_2 = new point((s.x+2*e.x)/3.0, (s.y+2*e.y)/3.0);
		point x_mid = rotate_60(x_1, x_2);
		if(depth!=0){
			koch(s,x_1,depth-1);
			koch(x_1, x_mid, depth-1);
			koch(x_mid, x_2, depth-1);
			koch(x_2, e, depth-1);
		}
	}
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		point s = new point(0, 0);
		point e = new point(100,0);

		
		koch(s , e, n);
		e.display();
		cin.close();
	}
}

Measured memory_bytes: 32316
n,m,s = map(int,input().split())
uvab = [list(map(int,input().split())) for i in range(m)]
cd = [list(map(int,input().split())) for i in range(n)]
graph = [[] for i in range((n+1)*2500+1)]
for u2,v2,a,b in uvab:
  for u,v in (u2,v2),(v2,u2):
    for i in range(u*2500,u*2500+2500):
      if i%2500 >= a:
        graph[i].append((i+(v-u)*2500-a,b))
for i in range(n):
  c,d = cd[i]
  for j in range((i+1)*2500,(i+2)*2500-1):
    graph[j].append((min((i+2)*2500-1,j+c),d))
import heapq as hq
start = 2500+min(s,2499)
dist = [10**18]*((n+1)*2500+1)
dist[start] = 0
q = [(0,start)]
hq.heapify(q)
while q:
  _,x = hq.heappop(q)
  for y,d in graph[x]:
    if dist[y] > dist[x]+d:
      dist[y] = dist[x]+d
      hq.heappush(q,(dist[y],y))
for i in range(2,n+1):
  print(min(dist[i*2500:(i+1)*2500]))

Measured memory_bytes: 112144
import sys
from collections import deque

fin = sys.stdin.readline

n, k = map(int, fin().split())
ab = [tuple(map(int, fin().split())) for i in range(n - 1)]
ab = [(a[0] - 1, a[1] - 1) for a in ab]

edge = {i: [] for i in range(n)}
for i in range(n - 1):
    edge[ab[i][0]].append(ab[i][1])
    edge[ab[i][1]].append(ab[i][0])

visited = [0] * n
queue = deque([0])
visited[0] = 1


def mul(a, b):
    return (a * b) % 1000000007


ans = k

pos = queue.popleft()
next_nodes = [e for e in edge[pos] if not visited[e]]
for i, ne in enumerate(next_nodes):
    queue.append(ne)
    visited[ne] = 1
    ans = mul(ans, k - i - 1)

while queue:
    pos = queue.popleft()
    next_nodes = [e for e in edge[pos] if not visited[e]]
    for i, ne in enumerate(next_nodes):
        queue.append(ne)
        visited[ne] = 1
        ans = mul(ans, k - 2 - i)

print(ans)


Measured memory_bytes: 84188
import java.io.*;
import java.util.*;
public class Main{
    static int cSize = 2001;
    static long[][] C = new long[cSize][cSize];    
    static {
        for(int i = 0; i < cSize; i++){
            Arrays.fill(C[i], -1);
            C[i][0] = C[i][i] = 1;
        }        
    }
    static long c(int n, int r){
        if(n < r)
            return 0;
        else if(C[n][r] > -1)
            return C[n][r];
        else
            if(n/2 < r)
                return C[n][r] = c(n, n-r);
            else
                return C[n][r] = (c(n-1, r-1)+c(n-1, r))%1000000007;
    }
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <= K; i++){
            sb.append((c(N-K+1, i)*c(K-1, i-1))%1000000007);
            sb.append("\n");
        }
        print(sb);
    }

    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 80084
n,m=gets.split.map(&:to_i).sort
MOD=1000000007

def f(n)
    ret=1
    for i in 2..n
        ret = (ret * i) % MOD
    end
    return ret
end

if m-n>1
    p 0
elsif m==n
    a=f(n)
    p (2*a*a)%MOD
else
    p (f(n)*f(m))%MOD
end

Measured memory_bytes: 1788
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
lcsTable2 :: BS.ByteString -> BS.ByteString -> UArray (Int,Int) Word16
lcsTable2 s t = runSTUArray $ do
  let !m = BS.length s
      !n = BS.length t
  arr <- newArray ((0,0),(m,n)) 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BS.index s i
    forM_ [n-1,n-2..0] $ \ !j -> do
      let !y = BS.index t j
      if x == y
        then do l2 <- readArray arr (i+1, j+1)
                writeArray arr (i,j) (l2 + 1)
        else do l0 <- readArray arr (i+1, j)
                l1 <- readArray arr (i, j+1)
                writeArray arr (i,j) (max l0 l1)
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable2 s t
      !m = BS.length s
      !n = BS.length t
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | table ! (i+1,j) >= table ! (i,j+1) = recon (i+1) j
                  | otherwise = recon i (j+1)
        where x = BS.index s i
              y = BS.index t j
      (result, _) = BS.unfoldrN (fromIntegral $ table ! (0,0)) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


Measured memory_bytes: 19580
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="keyence")
    {
        cout<<"YES\n";
        return 0;
    }
    int i,j,k;
    int m=s.size();
    for(i=0;i<s.size();i++)
    {
        for(j=i;j<s.size();j++)
        {
            string r="";
            for(k=0;k<i;k++)
            {
                r+=s[k];
            }
            for(k=j+1;k<m;k++)
            {
                r+=s[k];
            }
            if(r=="keyence")
            {
                cout<<"YES\n";
                return 0;
            }
        }
    }
    cout<<"NO\n";
}


Measured memory_bytes: 256
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**9
a = 10**9

for i in range(-100,102):
    if not(i in p):
        sa = abs(x-i)
        if sa < a:
            ans = i
            a = sa
        elif sa == a:
            ans = min(ans,i)

print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using plli = pair<ll, int>;
using vplli = vector<pair<ll, int>>;
using pllll = pair<ll, ll>;
using vpllll = vector<pair<ll, ll>>;

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

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--)

long long INF = 1LL << 60;
int main()
{
    int n;
    cin >> n;
    rep(i, 0, n)
    {
        int y, m, d;
        cin >> y >> m >> d;
        int res=0;
        rep(year,y,1000){
            if(year%3==0){
                res+=20*10;
            }
            else {
                res+=(20+19)*5;
            }
        }
        int minu=0;
        rep(i,1,m){
            if(i%2||y%3==0)minu+=20;
            else minu+=19;
        }
        minu+=d-1;
        cout<<res-minu<<endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;


ll MAX = 100003;
vector<ll> prime(ll _max){
    vector<ll> res;
    res.push_back(2);
    for(ll i=3;i<=_max;i+=2){
        bool flag = true;
        for(ll j=0;j<res.size();j++){
            if(i%res[j]==0)flag=false;
            if(res[j]*res[j]>i)break;
        }
        if(flag)res.push_back(i);
    }
    return res;

}

int main(){
    vector<ll> primes = prime(MAX);
    ll Q;
    cin>>Q;
    ll L[Q],R[Q];
    for(ll i=0;i<Q;i++){
        cin>>L[i]>>R[i];
    }
    vector<ll> num;
    for(ll i=0;i<primes.size();i++){
        if(binary_search(primes.begin(),primes.end(),(primes[i]+1)/2))
            num.push_back(primes[i]);

    }
    for(ll i=0;i<Q;i++){
        ll low_ind = lower_bound(num.begin(),num.end(),L[i])-num.begin();
        ll upp_ind = upper_bound(num.begin(),num.end(),R[i])-num.begin();
        cout<<upp_ind-low_ind<<"\n";
    }
    

}

Measured memory_bytes: 2432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = ReadInts();
            if (x[0] * x[1] % 2 == 0)
            {
                WriteLine("Even");
            }
            else
            {
                WriteLine("Odd");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n,k;
  cin >> n >> k;
  vi h(n);
  REP(i,n)cin >> h[i];

  vi dp(n+1, INF);
  dp[0]=0;
  REP(i,n){
    FOR(j,1,k+1) if(i+j<n)chmin(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
  }
  cout << dp[n-1] << endl;
}



Measured memory_bytes: 4016
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,h;cin>>h>>n;
    vector<ll>dp(h+1,inf);
    dp[0]=0;
    rep(i,n){
        ll a,b;cin>>a>>b;
        rep(j,h+1){
            if(j+a>h)dp[h]=min(dp[h],dp[j]+b);
            else dp[j+a]=min(dp[j+a],dp[j]+b);
        }
    }
    cout<<dp[h]<<endl;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if((g*10+b)%4==0)
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))


#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

#define MAXN 100500
int N,M,K,Q,T;
map<ll,ll> mp;
int main(void){
	geti(N);
	repp(i,N){
		int x; geti(x); mp[x]++;
	}
	ll ans = 0;
	vector<ll> list;
	for(auto e : mp){
		if( e.Se >= 4 ){
			list.push_back(e.Fi);
		}
		if( e.Se >= 2 ){
			list.push_back(e.Fi);
		}
	}
	sort(all(list));
	if( list.size() <= 1 ){
		cout << ans; return 0;
	}
	printf("%lld",list[list.size()-1]*list[list.size()-2]);

}

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

typedef long long ll;
// int = ll;

int main(){
	
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b;
	
	cin >> a >> b;
	
	if(a==1&&b==2){
		cout << 3 << endl;
	}else if(a==2&&b==1){
		cout << 3 << endl;
	}else if(a==1&&b==3){
		cout << 2 << endl;
	}else if(a==3&&b==1){
		cout << 2 << endl;
	}else if(a==2&&b==3){
		cout << 1 << endl;
	}else if(a==3&&b==2){
		cout << 1 << endl;
	}
	
	
	
return 0;	
}


Measured memory_bytes: 3480
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a+b>a-b){
        if(a+b>a*b){
            cout<<a+b<<endl;
        }else{
            cout<<a*b<<endl;
        }
    }else if(a-b>a*b){
        cout<<a-b<<endl;
    }else{
        cout<<a*b<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, m; cin >> n >> m;
	vector<ll> x(n);
	vector<ll> y(n);
	vector<ll> z(n);
	for( int i = 0; i < n; ++i ){
		cin >> x[i] >> y[i] >> z[i];
	}
	ll ans = 0;
	int opr[2] = {1, -1};
	for( int bit = 0; bit < 8; ++bit ){
		vector<ll> sumlist(n, 0);
		for( int i = 0; i < n; ++i ){
			sumlist[i] = opr[!!(bit&1)]*x[i] + opr[!!(bit&2)]*y[i] + opr[!!(bit&4)]*z[i];
		}
		/*
		for( int i = 0; i < n; ++i ){
			cout << sumlist[i] << " ";
		}
		cout << endl;
		*/
		sort( sumlist.begin(), sumlist.end(), greater<ll>() );
		ll sum = 0;
		for( int i = 0; i < m; ++i ){
			sum += sumlist[i];
		}
		ans = max( ans, accumulate( sumlist.begin(), sumlist.begin() + m, 0ll ) );
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5,M=8*N;
int n,pa,pb,d,i,g[N];long long ans;
struct arr{int x,y,id;}a[N];
bool operator < (arr A,arr B){
	return A.x<B.x||A.x==B.x&&A.y<B.y;
}
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int et,he[N];struct edge{int l,to;}e[M];
void line(int x,int y){
	e[++et].l=he[x];he[x]=et;e[et].to=y;
	e[++et].l=he[y];he[y]=et;e[et].to=x;
}
void work(int k){
	int i,j,l,r;sort(a+1,a+n+1);
	for (i=j=l=r=1;i<=n;i++){
		for (;a[l].x<a[i].x-d||
			a[l].x==a[i].x-d&&a[l].y<a[i].y-k;l++);
		for (;a[r].x<a[i].x-d||
			a[r].x==a[i].x-d&&a[r].y<=a[i].y+k;r++);
		g[a[i].id]+=r-l;j=max(j,l);if (j>=r) continue;
		for (line(a[i].id,a[j].id);j+1<r;j++)
			line(a[j].id,a[j+1].id);
	}
}
bool vis[N];
void dfs(int x){
	vis[x]=1;ans+=g[x];
	for (int i=he[x];i;i=e[i].l)
		if (!vis[e[i].to]) dfs(e[i].to);
}
int main(){
	n=read();pa=read();pb=read();
	for (i=1;i<=n;i++){
		int x=read(),y=read();
		a[i]=(arr){x+y,x-y,i};
	}
	d=max(abs(a[pa].x-a[pb].x),abs(a[pa].y-a[pb].y));
	for (work(d),i=1;i<=n;i++) swap(a[i].x,a[i].y);
	work(d-1);dfs(pa);printf("%lld",ans);
}

Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    ll r,d,x;
    cin>>r>>d>>x;
    rep(i,10){
        x=r*x-d;
        fin(x);
    }
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
n=int(input())
s=[[a,b,0]]+[list(map(int,input().split()))for i in range(n)]+[[c,d,0]]
c=[[0]*(n+2)for i in range(n+2)]
for i in range(n+2):
    for j in range(i,n+2):
        c[i][j]=c[j][i]=max(0,((s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2)**0.5-s[i][2]-s[j][2])
c=tuple(c)
n+=2
a=[float("INF")]*(n)
b=[1]*(n)
a[0]=0
while 1:
    v=-1
    for i in range(n):
        if v==-1 and b[i]:
            v=i
        elif b[i] and a[i]<a[v]:
            v=i
    if v==-1:
        break
    b[v]=0
    for j in range(n):
        a[j]=min(a[j],a[v]+c[v][j])
print(a[-1])

Measured memory_bytes: 85100
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using namespace std;

int gcd(int a, int b){
    if (a < b){
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b){
    return a * b / gcd(a, b);
}

int main(){
    long long a,b,ans;
    cin >> a >> b;
    ans = lcm(a,b);
    cout << ans << endl;
}


Measured memory_bytes: 256