akhauriyash/Code-Regression huggingface dataset:
A,B,C,D,E,F = map(int,input().split())

amax = F // (100 * A)
bmax = F // (100 * B)
cmax = F // C
dmax = F // D

ans = 0
summ = 0
suge = 0


for a in range(amax+1):

    for b in range(bmax+1):

        for c in range(cmax+1):

            for d in range(dmax+1):


                if 100*A*a + 100*B*b + C*c + D*d <= F and (A*100*a+B*100*b)*E >= 100*(C*c+D*d):

                    if A*100*a+B*100*b+C*c+D*d !=0 and ans < 100*(C*c+D*d)/(A*100*a+B*100*b+C*c+D*d):

                        ans = 100*(C*c+D*d)/(A*100*a+B*100*b+C*c+D*d)
                        summ = A*100*a+B*100*b+C*c+D*d
                        suge = C*c+D*d

if summ == 0:
    summ = 100*A
print (summ,suge)

Measured memory_bytes: 43500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
  string s;
  cin >> s;
  int n=s.size();
  ll ans=0;
  rep(i,n-1){
    if(s[i]!=s[i+1]) ans++;
  }
  cout << ans << endl;
}


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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  VI a(5);
  int k;
  REP(i,5) cin >> a[i];
  cin >> k;
  str ans="Yay!";
  if(a[4]-a[0]>k) ans = ":(";

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
	//Cs[i][0]: min, Cs[i][1]: max, Cs[i][2]: 派手さ
	//dp[i][j]: i日目に服jを着た時の派手さの最大値
	int D, N, Ts[200], Cs[200][3], dp[200][200];
	const int INF = 1 << 24;

	std::cin >> D >> N;
	for(int i=0;i<D;i++){
		std::cin >> Ts[i];
	}
	for(int j=0;j<N;j++){
		std::cin >> Cs[j][0] >> Cs[j][1] >> Cs[j][2];
	}

	for(int i=0;i<200;i++){
		for(int j=0;j<200;j++){
			dp[i][j] = 0;
		}
	}

	int res = 0;
	for(int i=1;i<D;i++){
		for(int j=0;j<N;j++){
			if(Cs[j][0] <= Ts[i] && Ts[i] <= Cs[j][1]);
			else continue;
			for(int k=0;k<N;k++){
				if(Cs[k][0] <= Ts[i-1] && Ts[i-1] <= Cs[k][1]);
				else continue;
				dp[i][j] = std::max(dp[i][j], std::abs(Cs[j][2]-Cs[k][2]) + dp[i-1][k]);
				res = std::max(res, dp[i][j]);
			}
		}
	}

	std::cout << res << std::endl;
}

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

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

	b *= 2;
	if (a <= b)
		cout << 0 << endl;
	else
		cout << a - b << endl; 
	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#include<cstdio>

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	long N;
	cin >> N;
	
	int answer = (int)sqrt(N);
	cout << answer * answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, p;
    cin >> n >> p;
    vector<char>s(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> s[i];
    }
    long long ans = 0;
    if(p == 2){
        for(int i = 1; i <= n; i++){
            if((s[i] - '0') % 2 == 0){
                ans = ans + 1LL * i;
            }
        }
        cout << ans;
        return 0;
    }
    if(p == 5){
        for(int i = 1; i <= n; i++){
            if((s[i] - '0') % 5 == 0){
                ans = ans + 1LL * i;
            }
        }
        cout << ans;
        return 0;
    }
    vector<int>power(n + 3);
    power[0] = 1;
    for(int i = 1; i <= n; i++){
        power[i] = (10 * power[i - 1]) % p;
    }
    vector<int>v(n + 3), pref(n + 3), cnt(p + 3, 0);
    for(int i = n; i >= 1; i--){
        int d = s[i] - '0';
        v[i] = d * power[n - i];
    }
    pref[0] = 0;
    cnt[0] = 1;
    for(int i = 1; i <= n; i++){
        pref[i] = (pref[i - 1] + v[i]) % p;
        cnt[pref[i]]++;
    }
    for(int i = 0; i < p; i++){
        long long cur = (1LL * cnt[i] * (cnt[i] - 1))/2;
        ans = ans + cur;
    }
    cout << ans;
    return 0;
}

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

int main() {
    int a[5];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a, a + 5);
    int ans = 1e9;
    do {
        int sum = a[0];
        for (int i = 1; i < 5; i++) {
            sum += a[i] + (10 - sum % 10) % 10;
        }
        ans = min(ans, sum);
    } while (next_permutation(a, a + 5));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,x,y;
	cin>>n>>x>>y;
	int m=n-1;
	int ans[m+1];
	for(int i=1;i<=m;i++) {
		ans[i]=0;
	}
	int f;
	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {
			f=min(min(abs(j-i),abs(i-x)+1+abs(j-y)),abs(i-y)+1+abs(j-x));
			ans[f]++;
		}
	}
	for(int i=1;i<=m;i++) {
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import collections

s = input()
n = len(s)

if n == 2:
    if s[0] == s[1]:
        print(1, 2)
    else:
        print(-1, -1)
else:
    for i in range(n - 2):
        if max(collections.Counter(s[i:i + 3]).values()) > 1:
            print(i + 1, i + 3)
            break
    else:
        print(-1, -1)

Measured memory_bytes: 3444
var
    n,k,min,i,cnt:longint;
    a:array[0..100010] of longint;
begin
    readln(n,k);
    min:=maxlongint;
    for i:=1 to n do
        begin
            read(a[i]);
            if a[i]<min then min:=a[i];
        end;
    for i:=1 to n do
        if a[i]=min then inc(cnt);
    n:=n-cnt;
    if n mod (k-1)=0 then writeln(n div (k-1)) else writeln(n div (k-1)+1);
end.

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

int main(){
    int64_t N, P;
    cin >> N >> P;
    int64_t ans = 1;
    for(int64_t p=2; p*p<=P; p++){
        int num = 0;
        while(P%p == 0){
            num++;
            P /= p;
        }
        int cnt = num/N;
        for(int i=0; i<cnt; i++) ans *= p;
    }
    if(N==1) ans *= P;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int d, t, s;
    cin >> d >> t >> s;

    if (t*s >= d){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



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

int main() {
  int p, q, r;
  cin >> p >> q >> r;
  cout << min(p+q, min(q+r, r+p)) << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}

ll n, m;
string s, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    cin >> s >> t;
    ll L = lcm(n, m);
    vll sc, tc;
    rep(i, 0, n) sc.pb(1 + i * (L / n));
    rep(i, 0, m) tc.pb(1 + i * (L / m));
    rep(i, 0, n) {
      ll itr = abs(distance(tc.begin(), lower_bound(ALL(tc), sc[i])));
      if (itr < m && sc[i] == tc[itr] && s[i] != t[itr]) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << L << endl;
    return 0;
}



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

class Dice{
	int mn[6];	
	
	public:
		void set(int num, int val){
			mn[num] = val;
		}
	
		void rot(char dir){
			int buf, old[6];
			memcpy(old, mn, sizeof(mn));
			switch(dir){
				case 'E':
				mn[0] = old[3];
				mn[2] = old[0];
				mn[5] = old[2];
				mn[3] = old[5];
				break;
				case 'W':
				mn[3] = old[0];
				mn[0] = old[2];
				mn[2] = old[5];
				mn[5] = old[3];
				break;
				case 'S':
				mn[0] = old[4];
				mn[1] = old[0];
				mn[5] = old[1];
				mn[4] = old[5];
				break;
				case 'N':
				mn[4] = old[0];
				mn[0] = old[1];
				mn[1] = old[5];
				mn[5] = old[4];
				break;
				case 'R':
				mn[1] = old[2];
				mn[2] = old[4];
				mn[4] = old[3];
				mn[3] = old[1];
				break;
				case 'L':
				mn[2] = old[1];
				mn[4] = old[2];
				mn[3] = old[4];
				mn[1] = old[3];
				break;
			}
		}
		
		int get(int num){
			return mn[num];
		}
		
		int serch(int val){
			int i;
			for(i = 0; 6 > i; i++){
				if(mn[i] == val) return i;
			}
			return -1;
		}
		
		void Aset(int up, int front){
			int i, su = serch(up);
			if(su == 3 || su == 2){
				while(get(0) != up){
					rot('E');
				}
			}
			else {
				while(get(0) != up){
					rot('S');
				}
			}
			while(get(1) != front){
				rot('R');
			}
		}
};


int main() {
	int b, i, n;
	Dice dice;
	
	for(i = 0; 6 > i; i++){
		scanf("%d", &b);
		dice.set(i,b);
	}
	scanf("%d", &n);
	for(i = 0; n > i; i++){
		int cm[2];
		scanf("%d%d", &cm[0], &cm[1]);
		
		dice.Aset(cm[0], cm[1]);
		printf("%d\n", dice.get(2));
	}
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
ans = 0

def F(N):
  if(N == 0):
    return ''
  
  if(N % 2 == 0):
    return F(N//-2) + '0'
  else:
    return F((N-1)//-2) + '1'

if(N == 0):
  print(0)
else:
  print(F(N))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a+b, a+c, b+c}) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	ll n,k;
	cin>>k>>n;
	int a[n];
	set<int>s,s1;
	rep(i,0,n)
	{
		int x;
		cin>>x;
		if(x<k)
		{
			s1.insert(k-x);
		}
		else
		s.insert(x-k);
	}
	int ans=0;
	for(auto it=s.begin();it!=s.end();it++)
	{
		if(*it==ans)
		{
			ans++;
		}
		else
		break;
	}
	int ans1=1;
	for(auto it=s1.begin();it!=s1.end();it++)
	{
		if(*it==ans1)
		{
			ans1++;
		}
		else
		break;
	}
	if(ans1<=ans)
	{
		cout<<k-ans1<<endl;
	}
	else
	cout<<k+ans;
}



Measured memory_bytes: 3544
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007

    using namespace std;
     //int g[105][105];
    //vector < int > wt(100004);
   // vector < int > a;
    //vector < int > v(30500);
    //int cst[102][100005];
    //int ansr[100005];
 //ll int sum,x=0,c=0,n,m,flag=0,a1,a2,flag1=0,flag2=0;
    //vector < vector < int > > adj(5000, vector < int > (5000));
 //int  dp[1000006];
   // int level[500];
   ll int C[2005][2002];
 void bC( )

{
    ll int  n=2003, k=2000;
    ll int i, j;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;


            else
                C[i][j] = (C[i - 1][j - 1])%hell +
                          (C[i - 1][j])%hell;

                          C[i][j]%=hell;
        }
    }

}

    void solve()
    {
         ll int i,j=0,r=200,p,q,y=0,k=0,ans=0,d,h,flag=0,n,m;
         cin>>n>>k;
         bC();
         rep(i,1,k+1)
           {
             r=(((C[n-k+1][i])%hell)*((C[k-1][i-1])%hell)%hell);
               cout<<(r%hell)<<endl;
           }





    }



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

       /*

  void bfs( int i , int j)
       {
           vis[i][j]= true;
         queue < int > que;
         que.push(k);
         while(!que.empty())
         {
            int x= que.front();
            que.pop();
             for ( int i=1;i<=n;i++)
             {
                 if((!g[1][n] and g[x][i] ) or (g[1][n] and ! g[x][i]))
                 {
                   if(!vis[i])
                   {
                       que.push(i);
                       level[i]=level[x]+1;
                       vis[i]= true;
                   }
                 }
             }
         }
       }

      ll int por(ll int a,ll int b)
         {
            ll int k=1;
            while(b>0)
            {
                if(b%2) k=k*a,k%=hell;
                b/=2;
                a*=a; a%=hell;
            }
            return k;
         } */


Measured memory_bytes: 30208
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[6];
    rep(i,1){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << (A[0]<1200 ? "ABC" : "ARC") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   vector<vector<int>> a(n);
   vector<int> ans(3);
   for(int i=0;i<n;i++)
   {
       int x,y,z;
       cin>>x>>y>>z;
       x+=max(ans[1],ans[2]);
       y+=max(ans[0],ans[2]);
       z+=max(ans[1],ans[0]);
       ans[0]=x;
       ans[1]=y;
       ans[2]=z;
   }
   cout<<*max_element(ans.begin(),ans.end());
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    agc014b()
}

fun agc014b() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val abList = (1..m).map { readLine()!!.split(' ').map { it.toLong() } }
        .flatten()

    val all = abList.groupBy { it }.map { it.value.size }.all { it % 2 == 0 }

    val answer = if (all) "YES" else "NO"

    println(answer)
}


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

using namespace std;

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

        int large = (b / k) * k;

        if (a <= large){
                cout << "OK" << endl;
        }
        else {
                cout << "NG" << endl;
        }
        return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
typedef pair<int, int> P;
int N;
vector<P> A;

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

  cin >> N;
  int a;
  rep(i, N){
    cin >> a;
    P p = make_pair(a, i%2);
    A.push_back(p);
  }
  sort(A.begin(), A.end());

  int cnt=0;
  rep(i, N){
    int v = A[i].second;
    if (i%2!=v){
      cnt++;
    }
  }
  cout << cnt/2 << "\n";
  return 0;
}

Measured memory_bytes: 1400
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let n = read_line();
    let bs = n.as_bytes();
    if (bs[0] == bs[1] &&bs[0] == bs[2] ) || 
        (bs[3] == bs[1] &&bs[3] == bs[2]) {
            println!("Yes");
        }
    else{
        println!("No");
    }
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : (x))
#define all(x) x.begin(), x.end() // sort(all(x))
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair((x), (y))

typedef long long ll;

typedef double T;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<T> vt;
typedef vector<vt> vvt;
typedef vector<pii> vpi;
typedef vector<pii> vpl;
typedef vector<vpi> graph;
typedef complex<T> Pt;
typedef pair<Pt, Pt> Line;

const ll MOD = 1000; // 998244353;
const T EPS = 1e-10;
const int INF = 1e9 + 1;

/* Mod Library */

struct Mod {
    ll x;
    Mod (ll x = 0) : x(x) {}
    Mod operator+(Mod b) { return Mod((x + b.x)%MOD); }
    Mod operator-(Mod b) { return Mod((x - b.x + MOD)%MOD); }
    Mod operator*(Mod b) { return Mod((x * b.x)%MOD); }
    Mod operator/(Mod b) { return *this * inverse(b); }
    Mod operator%(Mod b) { return Mod(x % b.x); }

    ll euclid(ll a, ll b, ll &x, ll &y) {
        if (b) {
            ll d = euclid(b, a%b, y, x);
            y -= a/b*x;
            return d;
        }
        x = 1; 
        y = 0;
        return a;
    }
    
    Mod inverse(Mod a) {
        ll x, y, g = euclid(a.x, MOD, x, y);
        assert(g == 1);
        return Mod((x + MOD)%MOD);
    }

    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this^(e/2);
        r = r*r;
        return e&1 ? *this*r : r;
    }
};

/* Input Library */
template <typename A, typename B>
istream& operator>>(istream &in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template <typename A, typename B>
ostream& operator<<(ostream &out, pair<A, B> &p) {
    out << p.first << " " << p.second;
    return out;
}

template <typename I>
istream& operator>>(istream &in, vector<I> &a) {
    trav(i, a) in >> i;
    return in;
}

template <typename I>
ostream& operator<<(ostream &out, vector<I> &a) {
    rep(i, 0, sz(a)) {
        if (i) out << " ";
        out << a[i];
    }
    return out;
}

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);
    cin.exceptions(cin.failbit);
}

/* Solution */

int enc(int a, int b, int n) {
    assert(a != b);
    if (a > b) swap(a, b);
    return a*n + b;
}

void solve_test() {
    int n; 
    cin >> n;
    vpi a(n);
    cin >> a;

    sort(all(a), [](pii a, pii b) {
            Pt x(a.first, a.second);
            Pt y(b.first, b.second);
            return arg(x) < arg(y);
            });

    T best = 0;
    rep(i, 0, n) {
        Pt cur;
        rep(oj, i, i+n) {
            int j = oj%n;
            cur += Pt(a[j].first, a[j].second);
            best = max(best, abs(cur));
        }
    }
    cout << fixed << setprecision(15) << best << endl;
}

void setup() {

}

int main() {
    setup();
    srand(time(0));
    fast_io();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve_test();
    }
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int sum=a*100+b*10+c;
    if(sum%4==0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cassert>

#define db(x) cout << "> " << #x << ": " << x << endl;

const int N = 200100;
using namespace std;

long long pos_pref[N];
long long neg_pref[N];

int T[4 *N];
vector <long long> val;
map <long long, int> cnt;

inline int c1(int n) { return (n << 1); }
inline int c2(int n) { return (n << 1)|1; }

void build(int curr, int st, int end)
{
	if(st == end)
	{
		T[curr] = cnt[val[st]];
		return;
	}
	
	int mid = st +end >> 1;
	
	build(c1(curr), st, mid);
	build(c2(curr), mid +1, end);
	
	T[curr] = T[c1(curr)] +T[c2(curr)];
}

void update(int curr, int st, int end, int idx)
{
	if(st == end)
	{
		assert(T[curr] > 0);
		T[curr]--;
		return;
	}
	
	int mid = st +end >> 1;
	
	if(idx <= mid)
		update(c1(curr), st, mid, idx);
	
	else
		update(c2(curr), mid +1, end, idx);
		
	T[curr] = T[c1(curr)] +T[c2(curr)];
}

int query(int curr, int st, int end, int l, int r)
{
	if(st > end || r < st || end < l)
		return 0;
	
	if(l <= st && end <= r)
		return T[curr];
	
	int mid = st +end >> 1;
	
	int q1 = query(c1(curr), st, mid, l, r);
	int q2 = query(c2(curr), mid +1, end, l, r);
	
	return q1 +q2;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		
		pos_pref[i] = pos_pref[i -1];
		neg_pref[i] = neg_pref[i -1];
		
		if(a -k > 0)
			pos_pref[i] += (a -k);
		
		else
			neg_pref[i] += (k -a);
	}
	
//	for(int i = 1; i <= n; i++)
//		cout << pos_pref[i] << ' ';
//	cout << '\n';

//	for(int i = 1; i <= n; i++)
//		cout << neg_pref[i] << ' ';
//	cout << '\n';
	
	for(int i = 1; i <= n; i++)
		cnt[pos_pref[i] -neg_pref[i]]++;
	
	for(auto it = cnt.begin(); it != cnt.end(); it++)
		val.push_back(it->first);
	
	map <long long, int> idx;
	int sz = val.size();
	for(int i = 0; i < sz; i++)
		idx[val[i]] = i;
	
	build(1, 0, sz -1);
	
//	cout << "val: ";
//	for(int i = 0; i < sz; i++)
//		cout << val[i] << ' ';
//	cout << '\n';
//	
//	cout << "cnt[val]: ";
//	for(int i = 0; i < sz; i++)
//		cout << cnt[val[i]] << ' ';
//	cout << '\n';
	
	long long res = 0, offset = 0;
	for(int i = 1; i <= n; i++)
	{
		auto it = lower_bound(val.begin(), val.end(), offset);
		
		if(it == val.end())
		{
			offset = (pos_pref[i] -neg_pref[i]);
			update(1, 0, sz -1, idx[pos_pref[i] -neg_pref[i]]);
			continue;
		}
		
		res += query(1, 0, sz -1, idx[*it], sz -1);
		offset = (pos_pref[i] -neg_pref[i]);
		update(1, 0, sz -1, idx[pos_pref[i] -neg_pref[i]]);
	}
	
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 33136
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL gcd(LL a, LL b)
{
	if (a < b) std::swap(a, b);
	LL r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

int main()
{
	LL N, M;
	std::string S, T;
	in >> N >> M >> S >> T;

	LL L = lcm(N, M);
	std::map<LL, char>X;
	for (LL i = 0; i < N; ++i) X[i*(L / N) + 1] = S[i];

	bool flag = true;
	for (LL i = 0; i < M; ++i)
	{
		if (X.count(i*(L / M) + 1))
		{
			if (X[i*(L / M) + 1] != T[i])
			{
				flag = false;
				break;
			}
		}
	}
	if (flag) out << L << std::endl;
	else out << -1 << std::endl;
}


Measured memory_bytes: 6144
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		if(Character.isUpperCase(str.charAt(0))){
			System.out.println("A");
		}else {
			System.out.println("a");
		}
	}
}

Measured memory_bytes: 26996
#include <bits/stdc++.h>
#define int long long
#define double long double
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int n;
    cin >> n;
    vector<int> kek(n);
    for (int i = 0; i < n; i++) {
        cin >> kek[i];
    }
    sort(kek.begin(), kek.end());
    multiset<pair<int, int>> polina;
    int cnt = kek[n - 1];
    polina.insert({kek[n - 2], kek[n - 1]});
    for (int i = n - 3; i >= 0; i--) {
        pair<int, int> pr = *(--polina.end());
        if (i != n - 3) polina.erase(--polina.end());
        cnt += pr.first;
        polina.insert({kek[i], pr.first});
        polina.insert({kek[i], pr.second});
    }
    cout << cnt << '\n';

    fflush(stdout);
    return 0;
}


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


void selectionSort(int* A,int N,int& count){
    for(int i=0;i!=N;++i){
        int minj=i;
        for(int j=i;j!=N;++j){
            if(A[j]<A[minj]){
                minj=j;
                
            }
        }
        if(A[i]!=A[minj]){
            ++count;
            int tmp=A[i];
            A[i]=A[minj];
            A[minj]=tmp;
        }
        
        
        
    }
}

void print_l(int* array,int N){
    for(int i=0;i!=N;++i){
        cout<<array[i];
        if(i!=N-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }
    
}

int main(){
    int N;
    cin>>N;
    int array[N];
    int count=0;
    for(int i=0;i!=N;++i){
        cin>>array[i];
    }
    
    selectionSort(array, N, count);
    
    print_l(array,N);
    cout<<count<<endl;
}



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

using namespace std;

int main()
{
    int n; cin>>n;
    int *a=new int[n];
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int>dp(n,0);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi A(n);
  ll sum = 0;
  for(auto &a:A)cin>>a;
  sort(ALL(A));
  for(int i=0;i<k;i++)sum += A[i];
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
const Int MOD = 1000000007;
int main() {
    int N, K; cin >> N >> K;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    int pos = 0, zero = 0, neg = 0;
    for (auto a : A) {
        if (a > 0) pos++;
        if (a == 0) zero++;
        if (a < 0) neg++;
    }
    sort(begin(A), end(A));
    Int ans = 1;
    if (K == N) {
        for (int i = 0; i < N; i++) {
            if (A[i] < 0) A[i] = MOD - abs(A[i]);
            ans = (ans * A[i]) % MOD;
        }
    } else if (pos == 0 && K % 2 == 1) {
        for (int i = N - K; i < N; i++) {
            ans = (ans * abs(A[i])) % MOD;
        }
        ans = (ans * (MOD - 1)) % MOD;
    } else {
        vector<pair<Int, int>> B;
        for (auto a : A) {
            B.emplace_back(abs(a), a < 0);
        }
        sort(rbegin(B), rend(B));
        vector<Int> plus, minus;
        for (int i = 0; i < N; i++) {
            if (B[i].second == 0) {
                plus.push_back(B[i].first);
            } else {
                minus.push_back(B[i].first);
            }
        }
        int p = K, n = 0;
        while (p > plus.size()) {
            p--, n++;
        }
        if (n % 2 == 1) p--, n++;
        while (p >= 2 && n + 2 <= minus.size()
            && plus[p-1] * plus[p-2] < minus[n] * minus[n+1]) {
            p -= 2, n += 2;
        }
        for (int i = 0; i < p; i++) ans = (ans * plus[i]) % MOD;
        for (int i = 0; i < n; i++) ans = (ans * minus[i]) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	ll n,m,v,p;
	cin >> n >> m >> v >> p;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(),a.rend());
	ll ans(p);
	ll line = a[p-1];
	ll cum(0);
	for(ll i(p);i<n;++i){
		ll ok_n = n - i + p - 1;
		ll over = v - ok_n;
		if(over <= 0){
			if(a[i] + m >= line)ans++;
		}else{
			if(a[i] + m >= line){
				ll cap = cum + (a[i] + m - line) * (i - p + 1);
				// if ((a[i - over] < (a[i] + m + 1)) && (cap > over * m))ans++;
				if (cap >= over * m)ans++;
			}
		}
		cum += line - a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Sat May 19 19:34:44 2018
ALDS1_7_B
@author: maezawa
"""

n = int(input())

parent = [-1 for _ in range(n)]
left = [-1 for _ in range(n)]
right = [-1 for _ in range(n)]
height = [None for _ in range(n)]
depth = [None for _ in range(n)]

def set_parent():
    global parent
    for i in range(n):
        if left[i] != -1:
            parent[left[i]] = i
        if right[i] != -1:
            parent[right[i]] = i

    
def set_depth(i, p):
    global depth
    if depth[i] != None:
        return
    depth[i] = p
    if right[i] != None:
        set_depth(right[i], p)
    if left[i] != None:
        set_depth(left[i], p+1)
       
def get_depth(i):
    global depth
    if depth[i] != None:
        return depth[i]
    d = 0
    u = i
    while parent[u] != -1:
        u = parent[u]
        d += 1
    depth[i] = d
    return d

def set_height(u):
    global height
    h1 = 0
    h2 = 0
    if right[u] != -1:
        h1 = set_height(right[u])+1
    if left[u] != -1:
        h2 = set_height(left[u])+1
    height[u] = max(h1, h2)
    return height[u]    

def get_sib(i):
    if right[parent[i]] == i:
        return left[parent[i]]
    else:
        return right[parent[i]]
    
def get_deg(i):
    deg = 0
    if right[i] != -1:
        deg += 1
    if left[i] != -1:
        deg += 1
    return deg    

def get_height(i):
    return height[i]
    
for i in range(n):
    line = list(map(int, input().split()))
    left[line[0]] = line[1]
    right[line[0]] = line[2]

set_parent()

for i in range(n):
    set_height(i)
    
for i in range(n):
    out_str = 'node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, '.format(i,parent[i],get_sib(i), get_deg(i), get_depth(i), get_height(i))
    if parent[i] == -1:
        out_str += 'root'
    elif right[i] == -1 and left[i] == -1:
        out_str += 'leaf'
    else:
        out_str += 'internal node'
    print(out_str)
        
        



Measured memory_bytes: 5640
import scala.io.{StdIn => stdin}
import scala.util.{Try, Success}

object Main {
  case class CookieCounts(notDeliciousDetoxic: Int, deliciousDetoxic: Int, toxic: Int)
  def readInput: Option[CookieCounts] = {
    val inputLine = stdin.readLine
    val splitAndToIntResult = Try {
      inputLine.split(" ").map(_.toInt)
    }
    splitAndToIntResult match {
      case Success(intArray) => intArray match {
        case Array(notDeliciousDetoxic, deliciousDetoxic, toxic) => {
          Some(CookieCounts(notDeliciousDetoxic, deliciousDetoxic, toxic))
        }
        case _ => None
      }
      case _ => None
    }
  }

  def calcNumEdibleDeliciousCookie(cc: CookieCounts): Int = {
    val detoxic = cc.notDeliciousDetoxic + cc.deliciousDetoxic
    val delicious = cc.deliciousDetoxic + cc.toxic
    if (detoxic + 1 >= cc.toxic) {
      delicious
    } else {
      detoxic + 1 + cc.deliciousDetoxic
    }
  }

  def main(args: Array[String]) {
    val cookieCounts = readInput match {
      case Some(cc) => cc
      case None => sys.exit(1)
    }
    println(calcNumEdibleDeliciousCookie(cookieCounts))
  }
}


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

int main() {
  
  string s;
  cin >> s;
  
  if (s.at(0) == s.at(1) && s.at(0) == s.at(2)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

string l;
ll dp[100000 + 1][2];

ll rec(int digit, bool tight){
    if(dp[digit][tight] != -1){
        return dp[digit][tight];
    }
    if(digit == l.size()){
        return 1;
    }
    int x = l[digit] - '0';
    int r = (tight ? x : 1);
    ll res = 0;
    for(int a = 0; a <= 1; a++){
        for(int b = 0; b <= 1; b++){
            int i = a + b;
            if(i > r) continue;
            res += rec(digit + 1, tight && i == r);
            res %= MOD;
        }
    }
    return dp[digit][tight] = res;
}

signed main(){
    cin >> l;
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 1) << endl;
    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    string s;
    int div=-2;
    while(n!=0){
        int r=n%(-2);
        if(r<0) r=1;
        s.pb(r+'0');
        n=(n-r)/(-2);
    }
    reverse(all(s));
    if(s.length()==0)cout<<0<<endl;
    else cout<<s<<endl;
}

Measured memory_bytes: 3652
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

const ll maxn  = 1000002;
vector < ll > primes;
bool vis[maxn+10];

void sieve()
{
    vis[0] = 1;
    vis[1] = 1;

    for(ll i = 4; i <= maxn; i += 2)
    {
        vis[i] = 1;
    }

    for(ll i = 3; i * i <= maxn; i += 2)
    {
        if(vis[i] == 0)
        for(ll j = i * i; j <= maxn; j += i)
        {
            vis[j] = 1;
        }
    }

    for(ll i = 2; i <= maxn; i++)
    {
        if(vis[i] == false)
        primes.pb(i);
    }

}

ll arr[1000006];
ll freq[1000005];

bool pairwise(ll n)
{
	memset(freq,0,sizeof freq);

	for(ll i = 1; i <= n; i++)
	{
		ll x = arr[i];

		for(ll j = 0; primes[j] * primes[j] <= x; j++)
		{
			if(x % primes[j] == 0)
			{
				freq[primes[j]]++;

				while(x % primes[j] == 0) x /= primes[j];
			}
		}

		if(x > 1) freq[x]++;
	}

	for(ll i = 1; i <= 1000000; i++)
	{
		if(freq[i] > 1) return 0;
	}

	return 1;
}

bool setwise(ll n)
{
	ll gc = 0;

	for(ll i = 1; i <= n; i++) gc = __gcd(gc, arr[i]);

	return gc == 1;
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    sieve();

    while(cin >> n)
    {
		for(ll i = 1; i <= n; i++) cin >> arr[i];

		if(pairwise(n)) cout << "pairwise coprime\n";
		else if(setwise(n)) cout << "setwise coprime\n";
		else cout << "not coprime\n";
    }


}






Measured memory_bytes: 20484
#include<bits/stdc++.h>
using namespace std;
int a,b,s;
int main()
{
    cin>>a>>b; 
    s=1;
    for(int i=a;i<=b;i++)
    {  
      if(i<0)
	  s*=-1;
      if(i==0)
	  {
	    cout<<"Zero"<<endl;
	     return 0;
	  }
    }
    if(s>0)
	cout<<"Positive"<<endl;
    if(s<0)
	cout<<"Negative"<<endl;
    if(s==0)
	cout<<"Zero"<<endl;
    
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

struct StVal {
	int v = 0; StVal() {}
	StVal(const int _v) : v(_v) {}
	StVal(const StVal &v1, const StVal &v2) { v = max(v1, v2); }
	operator int() const { return v; }
};

struct StUpdate {
	int v = 1 << 20; StUpdate() {}
	StUpdate(const int v) : v(v) {}
	StUpdate(const StUpdate &u1, const StUpdate &u2) { v = min(u1, u2); }
	operator int() const { return v; }
	void apply(StVal &V, const int lo, const int hi) {
		V.v = min(V.v, this->v);
	}
};

struct SegTree {
	int n;
	vector<StVal> st;
	vector<StUpdate> lazy;
	vector<int> leaves;

	SegTree(const int n) : n(n), leaves(n) {
		init(1, 0, n - 1); lazy.resize(st.size());
	}

	void init(const int si, const int lo, const int hi) {
		if (lo == hi) {
			if (si >= (int)st.size()) st.resize(si + 1);
			st[si] = StVal(n - 2); leaves[lo] = si;
		}
		else {
			const int mid = (lo + hi) >> 1;
			init(si << 1, lo, mid);
			init(si << 1 | 1, mid + 1, hi);
			st[si] = StVal(st[si << 1], st[si << 1 | 1]);
		}
	}

	void updateLazy(const int si, const int lo, const int hi) {
		lazy[si].apply(st[si], lo, hi);
		if (lo != hi) {
			lazy[si << 1] = StUpdate(lazy[si << 1], lazy[si]);
			lazy[si << 1 | 1] = StUpdate(lazy[si << 1 | 1], lazy[si]);
		}
		lazy[si] = StUpdate();
	}

	StVal query(const int l, const int r) { return (l <= r && l < n && r >= 0) ? query(l, r, 1, 0, n - 1) : StVal(); }
	StVal query(const int l, const int r, const int si, const int lo, const int hi) {
		updateLazy(si, lo, hi);
		if (l <= lo && hi <= r) return st[si];

		const int mid = (lo + hi) >> 1;
		if (r <= mid) return query(l, r, si << 1, lo, mid);
		if (mid < l) return query(l, r, si << 1 | 1, mid + 1, hi);
		return StVal(query(l, r, si << 1, lo, mid), query(l, r, si << 1 | 1, mid + 1, hi));
	}

	void update(const int l, const int r, const StUpdate u) { if (l <= r) update(l, r, u, 1, 0, n - 1); }
	void update(const int l, const int r, const StUpdate &u, const int si, const int lo, const int hi) {
		if (l <= lo && hi <= r) {
			lazy[si] = StUpdate(lazy[si], u);
			updateLazy(si, lo, hi);
		}
		else {
			updateLazy(si, lo, hi);
			if (hi < l || r < lo) return;
			const int mid = (lo + hi) >> 1;
			update(l, r, u, si << 1, lo, mid);
			update(l, r, u, si << 1 | 1, mid + 1, hi);
			st[si] = StVal(st[si << 1], st[si << 1 | 1]);
		}
	}

	void update(const int i) {
		int si = leaves[i];
		for (si >>= 1; si; si >>= 1)
			st[si] = StVal(st[si << 1], st[si << 1 | 1]);
	}
};

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

	int n, q; cin >> n >> q; 
	SegTree rows(n), cols(n);
	ll res = (ll)(n - 2) * (ll)(n - 2);

	while (q--) {
		int t, x; cin >> t >> x;
		x--; if (t == 1) {
			int v = cols.query(x, x);
			res -= v; rows.update(1, v, x - 1);
			cols.update(x, x, 0);
		}
		else {
			int v = rows.query(x, x);
			res -= v; cols.update(1, v, x - 1);
			rows.update(x, x, 0);
		}
	}
	cout << res << '\n';
	cin.ignore(2); return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
bool R(){return true;}
template<typename T, typename ... Args>
bool R(T & x, Args & ... args){return cin >> x && R(args...);}
void init_io(){ios::sync_with_stdio(false);cin.tie(0);}

#define PB push_back
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 4000000000000000007LL

int n, a[100014], q, b, c, freq[100014];
ll sum;

void solve ()
{
  R(n);
  FOR(i, 0, n) R(a[i]);
  MM(freq, 0);
  sum = 0;
  FOR(i, 0, n) 
  {
    ++freq[a[i]];
    sum += a[i];
  }
  R(q);
  FOR(qq, 0, q)
  {
    R(b, c);
    int diff = c - b;
    sum += 1LL * freq[b] * diff;
    freq[c] += freq[b];
    freq[b] = 0;
    printf("%lld\n", sum);
  }
}

int main ()
{
  init_io();
  int T = 1;
  //R(T);
  while (T--) solve();
  return 0;
}


Measured memory_bytes: 4564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int max_n = 200000;

int main(){
    string S;
    cin>>S;
    ll n = S.length();
    vector<ll> mod(max_n,0);
    //int modi = 1;
    mod[0] = 1;
    REP(i,max_n){
        mod[i+1] = 10*mod[i] % 2019;
    }
    vector<ll> amari(2019,0);
    vector<ll> dp(max_n+1,0);
    ll amari0 = (S.at(0) - '0');
    dp[0] = 0;
    amari[0]++;
    REP(i,n){
       dp[i+1] = ((dp[i] + (S.at(S.length() - 1 - i) - '0') * mod[i] ) % 2019);
       amari[dp[i+1]]++;
       //cout << dp[i+1] << endl;
    }

    ll ans = 0;
    REP(i,2019){
        ans += amari[i] * (amari[i]-1) / 2;
    }
    cout << ans <<endl;

}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  ll N, M; scanf("%lld %lld", &N, &M);
  ll ans = -1;
  if (N == 1 and M == 1) { ans = 1; }
  else if (N == 1 or M == 1) { ans = max(N, M) - 2; }
  else { ans = (N - 2) * (M - 2); }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
vi adj[(int)1e5 + 5];
int leaf[(int)1e5 + 5];
int ans[(int)1e5 + 5];
bool aboveNeed= false;
int root = 0;
void dfs(int cur, int P){
    int cnt = 0;
    bool found =false;
    ans[cur] = leaf[cur] = 0;
    for(int child :adj[cur]){
        if(child == P)continue;
        dfs(child, cur);
        ans[cur] += ans[child];
        leaf[cur] += leaf[child];
        if(leaf[child] == 1)found = true;
        cnt++;
    }
    if(cnt - found >= 2){
        aboveNeed = false;
    }
    if(cnt>=2 && found){
        ans[cur]--;
        if(cur != root)aboveNeed= true;
        cnt--;
    }
    if(cnt == 0){
        ans[cur] = 1;
        leaf[cur] =1;
    }
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
//    freopen("1_13.txt", "r", stdin);
    int n;cin >> n;
    int x,y;
    FOR(i, n - 1)cin >> x >> y, adj[x].pb(y), adj[y].pb(x);
    if(n == 2){
        cout <<1;
        return 0;
    }

    FOR(i, n){
        if(adj[i].size() > 1){
            root =i;
            dfs(i, -1);
            cout << ans[i] + aboveNeed;
            return 0;
        }
    }
}




Measured memory_bytes: 14976