akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define debug(x) cerr << #x << ": " << x << "\n"
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}


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

    
    int n,m,l;
    cin >>n>>m>>l;

    ll c[101][101];
    ll a[101][101];
    ll b[101][101];
    rep(i,n)rep(j,m)cin>>a[i][j];
rep(i,m)rep(j,l)cin>>b[i][j];
//rep(i,n)rep(j,l)cin>>c[i][j];

 rep(i,n){rep(j,l){
     c[i][j]=0;
     rep(k,m){
     c[i][j] += a[i][k]*b[k][j];
 }}}
 rep(i,n){

     rep(j,l){
         if(j)cout<<" ";
     cout<<c[i][j];
      }
      cout<<endl;
    }
   // cout<<endl;
    
   
}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A, B;
    cin >> A >> B;
    cout << (A*B/__gcd(A, B));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        int n, f;
        cin >> n >> f;
        int a[n + 1];
        int vis[n + 1] = {0};
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        vector<int> v;
        v.pb(1);
        int k = 1;
        int ans = 1;
        vis[1] = 1;
        k = a[1];
        while (vis[k] != 1)
        {
            v.pb(k);
            vis[k] = 1;
            k = a[k];
            ans++;
        }
        vector<int> p;
        vector<int> ve;
        int i = 0;
        while (v[i] != k)
        {
            p.pb(v[i]);
            i++;
        }
        while(i!=v.size()){
            ve.pb(v[i]);
            i++;
        }
        if (f < p.size())
        {
            f = f % p.size();
            cout << p[f] << endl;
        }
        else{
        f -= p.size();
        f = f % ve.size();
        cout << ve[f] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 10912
#include<iostream>
using namespace std;
int main(){
	int st,e;
	string s;
	cin>>s;
	int l=s.length();
	for(int i=0;i<l;i++){
		if(s[i]=='A'){
			st=i+1;
			break;
			
		}
	}
	for(int i=0;i<l;i++){
		if(s[i]=='Z'){
			e=i+1;
		}
	}
	cout<<e-st+1<<endl;
}

Measured memory_bytes: 640
def main():
    #input
    N,K=map(int,input().strip().split())
    P=list(map(int,input().strip().split()))
    
    #期待値行列
    E=list(map(lambda x:(x+1)*x//2/x,P))
    S=[0 for n in range(N-K+1)]
    for n in range(K):
        S[0]+=E[n]
    
    ans=S[0]
    for i in range(1,N-K+1):
        S[i]=S[i-1]-E[i-1]+E[i+K-1]
        ans=max(ans,S[i])
    print(ans)

if __name__=="__main__":
    main()

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

int kaijo(int a){
    if( a != 0){
        return a*(kaijo(a-1));
    }

    return 1;
}

int main(){
    int n; cin>>n;
    vector<pair<int,int>> p(n);
    for(int i=0; i<n; i++)cin>>p[i].first>>p[i].second;
    double sum=0;
    sort(p.begin(),p.end());
    do{
        for(int i=0; i<n-1; i++){
            sum += sqrt((p[i].first-p[i+1].first)*(p[i].first-p[i+1].first)+
            (p[i].second-p[i+1].second)*(p[i].second-p[i+1].second));
        }

    }while(next_permutation(p.begin(),p.end()));
    
    cout<<setprecision(6)<<fixed;
    cout<<(double)sum/kaijo(n)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  ll even_pair = 0, odd_pair = 0;
  if (N == 0 || N == 1)
    even_pair = 0;
  else
    even_pair = N * (N - 1) / 2;
  if (M == 0 || M == 1)
    odd_pair = 0;
  else
    odd_pair = M * (M - 1) / 2;
  cout << even_pair + odd_pair << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
mod=10**9+7

data=[i for i in range(1,int(n**.5)+1)]+[n//i for i in range(int(n**.5),0,-1)]

L=len(data)
dp=[1]*L
for i in range(1,L):
    dp[i]=data[i]-data[i-1]

for i in range(k-1):
    h=dp[:]
    for i in range(1,L):
        h[i]=(h[i]+h[i-1])%mod
    h=h[::-1]
    for i in range(1,L):
        h[i]=h[i]*(data[i]-data[i-1])%mod
    dp=h

ans=0
for u in dp:
    ans=(ans+u)%mod
print(ans)

Measured memory_bytes: 65276
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   if(s.back() == 's'){
      s += "e";
   }
   s += "s";
   cout << s << '\n';
   return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh


#else

void solve() {

    ll x;
    cin >> x;
    ld now = 100;
    ld coef = 1.01;

    int answr = 0;
    while (now < x)
    {
        ++answr;
        now *= coef;
        now = (ll)now;
    }
    cout << answr;
}

#endif

void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << (i++) << ": ";
        solve();
//        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);



#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int res = 0;
	res += (N / 500) * 1000;
	N = N % 500;


	res += (N / 5) * 5;

	cout << res << endl;
}

Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    int a,b;
    cin>>a>>b;
    if(a<10&&b<10)cout<<a*b<<endl;
    else cout<<-1<<endl;

}


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

#define fastIO                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);                   \
	cout.tie(0);

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
	fastIO;
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * c, max(a * d, max(b * c, b * d)));
}

Measured memory_bytes: 3660
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Team implements Comparable<Team>{
	int passCnt = 0;
	int time = 0;
	int num;
	ArrayList<Integer> wrongAnswer = new ArrayList<Integer>();
	
	Team(int num){
		this.num = num;
	}
	
	void record(int time, int questionNum,int isPassed){
				
		if(isPassed == 0){
			passCnt++;
			this.time += time + 20*getPenalty(questionNum);
		} else wrongAnswer.add(questionNum);
	}
	@Override
	public int compareTo(Team that) {
		if(this.passCnt == that.passCnt){
			if(this.time == that.time){
				return that.num - this.num;
			}else return this.time - that.time;
		} else{
			return that.passCnt - this.passCnt;
		}
	}
	
	boolean equals(Team that){
			return this.passCnt == that.passCnt && this.time == that.time;
	}
	
	public String toString(){
		return this.num+"";
	}
	
	int getPenalty(int questionNum){
		int cnt = 0;
		for(int i : wrongAnswer)
			if(i == questionNum) cnt++;
		return cnt;
	}
	
}


public class Main {
	public static void main(String[] args){
		Scanner sn = new Scanner(System.in);
		int teamNum = 0 ,n = 0;
		while(true){
			int k = sn.nextInt();
			teamNum = sn.nextInt();
			int qn = sn.nextInt();
			n = sn.nextInt();
			if(k == 0 && teamNum == 0 && qn == 0 && n == 0) break;
			Team[] teams = new Team[teamNum];
			for(int i = 0; i < teamNum; i++) teams[i] = new Team(i+1);
			for(int i = 0; i < n; i++){
				int time = sn.nextInt();
				teams[sn.nextInt()-1].record(time, sn.nextInt(), sn.nextInt());
			}
			Arrays.sort(teams);
			System.out.println(getResult(teams));
		}
	}
	
	static String getResult(Team[] ts){
		String out = ts[0].toString();
		for(int i = 1; i < ts.length; i++){
			if(ts[i-1].equals(ts[i])){
				out += "=" + ts[i];
			} else out += "," + ts[i].num;
		}
		return out;
	}
}

Measured memory_bytes: 61176
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

string s;

int main(){
  cin >> s;
  int ans = 1000;
  REP(i, s.size() - 2) {
    ans = min(ans, abs(stoi(s.substr(i, 3)) - 753));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum,count;
  while(1){
  count = 0;
  cin >> n;
  if(n==0) break;
  for(int i=0; i<n; i++){
    sum = 0;
    for(int j=i+1; j<n; j++){
        sum += j;
        if(sum==n) count++;
        if(sum>n) break;
    }
  }
  cout << count << endl;
  }
  return 0;
}



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

int main() {
	int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i=0;i<n;i++){
      cin >> p[i];
    }
    sort(p.begin(),p.end());
    int sum = 0;
    for(int i=0;i<k;i++){
      sum = sum+p[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
void print(int A[], int N)
{
    int k;
    for (k = 0; k < N; k++) {
        if (k > 0) printf(" ");
        printf("%d", A[k]);
    }
    printf("\n");
}

int main (void)
{
   int i, N;
   int A[100];
   scanf("%d", &N);
   for (i = 0; i < N; i++) {
     scanf("%d", &A[i]);
   }
   print(A, N);
 
   for (i = 1; i < N; i++) {
     int v = A[i];
     int j = i - 1;
     while (j >= 0 && A[j] > v) {
       A[j+1] = A[j];
       j--;
     }
 
     A[j+1] = v;
     print(A, N);
   }
   return 0;
}

Measured memory_bytes: 604
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int [] A = new int[1000];

    for (int i = 1; i < 1000; i++) {
      A[i] = A[i-1] + i;
      if ( b - a  == i) {
          System.out.println(A[i]-b);
          break;
      }
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>
#include <vector>

using std::cout;
using std::cin;
using std::string;


int main()
{
  std::vector<std::pair<int,int>> ct(5);
  for(size_t i = 0; i < ct.size(); ++i)
  {
    int tmp;
    cin >> tmp;
    int tmp2 = tmp %10;
    ct[i] = std::make_pair(tmp2, tmp);
  }

  std::sort(ct.begin(), ct.end());
  auto it = std::find_if(ct.begin(), ct.end(), [](std::pair<int,int> a){return a.first != 0;});
  std::sort(it, ct.end(), [](std::pair<int, int> a, std::pair<int, int> b) {return a.first > b.first;});
  // cout << "---\n";
  // for(const auto& it : ct)
  // {
  //   cout << it.second << "\n";
  // }

  int stime = 0;
  for(size_t i = 0; i < ct.size() ;++i)
  {
    int tmp = 0;
    tmp = (ct[i].first != 0) ? ct[i].second - ct[i].first + 10 : ct[i].second; 
    if(i == ct.size() - 1) { tmp = ct[i].second;}
    stime += tmp;
  }
  cout << stime << "\n";
  return 0;
}


Measured memory_bytes: 256
import math

N, M = map(int, input().split())

n = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2)) if N > 1 else 0
m = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2)) if M > 1 else 0

print(n + m)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	// your code goes here
	int a,b,c,d,e,f,g,h;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	e=c-(d-b);
	f=d+(c-a);
	g=a+e-c;
	h=b+f-d;
	printf("%d %d %d %d\n",e,f,g,h);
	return 0;
}


Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Yutori
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int ls[MAX_N], rs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k, c;
  scanf("%d%d%d%s", &n, &k, &c, s);
  c++;

  for (int i = 0, x = 0; i < k; i++) {
    while (s[x] == 'x') x++;
    ls[i] = x;
    x += c;
  }
  for (int i = k - 1, x = n - 1; i >= 0; i--) {
    while (s[x] == 'x') x--;
    rs[i] = x;
    x -= c;
  }
  //for (int i = 0; i < k; i++) printf("%d ", ls[i]); putchar('\n');
  //for (int i = 0; i < k; i++) printf("%d ", rs[i]); putchar('\n');

  for (int i = 0; i < k; i++)
    if (ls[i] == rs[i]) printf("%d\n", ls[i] + 1);
  return 0;
}


Measured memory_bytes: 3200
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main()
{
	cout << fixed << setprecision(10);
	int k;
	cin >> k;

	LLI sum = 0;
	FOR(a, 1, k + 1)
		FOR(b, 1, k + 1)
		FOR(c, 1, k + 1)sum += gcd(gcd(a, b), c);
	cout << sum;
	return 0;
}

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

int main(){
  ll N,K; cin >> N >> K;
  if(N <= K){
    cout << "0";
    return 0;
  }
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(), A.end()); //小さい順
  rep(i,K){
    A.pop_back();
  }
  ll ans = 0;
  rep(i,A.size()){
    ans += A[i];
  }
  cout << ans;
}

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

struct UnionFind {
  vector<int> ps, rs;

  UnionFind(){};

  UnionFind(int n) {
    ps.resize(n, 0);
    rs.resize(n, 0);
    for (int i = 0; i < n; ++i) {
      ps[i] = i;
    }
  }

  int find(int x) {
    if (ps[x] != x) {
      ps[x] = find(ps[x]);
    }
    return ps[x];
  }

  void unite(int x, int y) {
    int x_root = find(x);
    int y_root = find(y);
    if (x_root == y_root) {
      return;
    }
    if (rs[x_root] < rs[y_root]) {
      swap(x_root, y_root);
    }
    ps[y_root] = x_root;
    if (x_root == y_root) {
      rs[x_root] += 1;
    }
  }
};

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

  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    p[i] -= 1;
  }

  UnionFind u = UnionFind(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    u.unite(x, y);
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (u.find(i) == u.find(p[i])) {
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4584
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    string s;
	int k, ans = 0;
	cin >> s >> k;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'a') continue;
        int t = 26 - (s[i] - 'a');
        if(t <= k){
            s[i] = 'a';
            k -= t;
        }
    }
    s.back() = ((s.back() - 'a' + k) % 26) + 'a';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

int n;
int a[MAXN];

void read()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
}

void solve()
{
	int mx = 0;
	for(int i = 0; i < n; i++)
		chkmax(mx, a[i]);

	int val = -1;
	for(int i = 0; i < n; i++)
		if(a[i] != mx)
		{
			if(val == -1) val = a[i];
			else if(min(val, mx - val) < min(a[i], mx - a[i]))
				val = a[i];
		}

	cout << mx << " " << val << endl;
}

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

	read();
	solve();
	return 0;
}



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

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

const int INF = 1000000007;
const ll INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int MAX = 1e5 + 7;
const ll MOD = 1e9 + 7;

bool visited[MAX];
ll dp[MAX][2];
vector <int> v[MAX];

void dfs(int u)
{
    visited[u] = true;

    for(auto i : v[u])
    {
        if(!visited[i])
        {
            dfs(i);
            dp[u][1] *= dp[i][0];
            dp[u][1] %= MOD;
            dp[u][0] *= (dp[i][0] + dp[i][1]);
            dp[u][0] %= MOD;
        }
    }
}

int main() {
    _boost;

    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }

    for(int i = 0; i <= n; i++)
    {
        dp[i][0] = 1;
        dp[i][1] = 1;
    }

    dfs(1);

    cout << ((dp[1][0]+dp[1][1])%MOD);

    return 0;
}


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

const int INF = 1001001001;

int main() {
	ll n, k;
	cin >> n >> k;
	cout << min(n % k, abs(n % k - k)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
  int a, b;		cin >> a >> b;
  int ans = 0;
  bool endFlag = false;
  for(int i = 1 ; i <= a ; i++){
    for(int j = 1 ; j <= 12 ; j++){
      
      if((i == a && b < j) || a < i){
        endFlag = true;
        break;
      }
      if(i == j)	ans += 1;

    }
    if(endFlag)	break;
  }
  
  cout << ans << endl;
  return 0;
  
}

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

int main() {
  string w;
  cin >> w;
  for(int i=0;i<w.size();i++){
    if( count(w.begin(),w.end(),w.at(i)) % 2 != 0 ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1, n - 1):
    if (p[i - 1] <= p[i] and p[i] <= p[i + 1]) or (p[i + 1] <= p[i] and p[i] < p[i - 1]):
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
 string a,b;
 cin>>a>>b;
 string t=a+b;
 int c=stoi(t);
 for(int i=0;i<=c;i++){
     if(i*i==c){cout<<"Yes"<<endl;return 0;}
 }
 cout<<"No"<<endl;
 return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double W = sc.nextDouble();
        double H = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();
        int assess =0;
        if(x*2 ==W&&y*2==H) assess =1;
        System.out.println(W*H/2+" "+assess);
    }
}


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

typedef long long ll;

int main(){

    ll H,W;
    cin >> H >> W;

    std::vector<string> v(H);
    for(ll i = 0; i < H ;i++){
      cin >> v[i];
    }
    for(ll i = 0; i < H; i++){
      cout << v[i] << endl;
      cout << v[i] << endl;;
    }

}


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

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

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;



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

    int n;
    cin >> n;

    int cnt = 0, zeros = 0, m = INF;
    ll ans = 0;
    rep(i, n) {
        int a;
        cin >> a;

        if(a > 0){
            ans += a;
            m = min(m, a);
        }else{
            ans += -a;
            m = min(m, -a);
        }
        if(a < 0) cnt++;
        if(a == 0) zeros++;

    }

    if(cnt % 2 == 1 && zeros == 0){
        ans -= 2 * m;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll n;
    cin>>n;
    vector<ll>v(n);
    for(int i=0;i<n;i++)
      cin>>v[i];
    ll res=0;
    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
    for(int k=j+1;k<n;k++){
      if((v[i]+v[j])>v[k] && (v[j]+v[k])>v[i] && (v[k]+v[i])>v[j] && v[i]!=v[j] && v[j]!=v[k] && v[k]!=v[i] )
      res++;
    }
    cout<<res;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll a;
  scanf("%lld", &a);
  cout << (a * 3.1415 * 2.0) << endl;
}


Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define um unordered_map
#define mod 1000000007
#define MAX 1000
using namespace std;

ll dp[MAX+1][MAX+1];
char arr[MAX+1][MAX+1];

int main() {
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp[i][j]=-1;
            cin>>arr[i][j];
            if(arr[i][j]=='#')
            dp[i][j]=0;

        }
    }
    for(int i=1;i<=n;i++)
    {
        if(arr[i][1]=='.')
        dp[i][1]=1;
        else
        {
            while(i<=n)
            {
                dp[i][1]=0;
                i++;
            }
        }
    }
    
    for(int i=1;i<=m;i++)
    {
        if(arr[1][i]=='.')
        dp[1][i]=1;
        else
        {
            while(i<=m)
            {
                dp[1][i]=0;
                i++;
            }
        }
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=2;j<=m;j++)
        {
            if(dp[i][j]!=0)
            dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 12380
#include <iostream>
#include <string>
#include <vector>
int main(){
	int N,K,count1,count2,score =1;
	std::cin >> N >> K;
	while(count1+count2!=N){
		if(2*score>score+K){
			score=score+K;
			count1++;
		}else{
			score = 2*score;
			count2++;
		}
	}
	std::cout << score << std::endl;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N;cin>>N;
  vector<string> s(N);
  rep(i,N) cin>>s[i];
  ll M;cin>>M;
  vector<string> t(M);
  rep(i,M) cin>>t[i];
  ll ans = 0;
  rep(i,N){
    ll cnt = 0;
    string a = s[i];
    rep(i,N){
      if(s[i]==a) cnt++;
    }
    rep(i,M){
      if(t[i]==a) cnt--;
    }
    ans = max(ans,cnt);
  }
  cout<<ans<<endl;

}


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

int main(){
    int a,b;
    char c;
    
    while(true){
        cin >> a >> c >> b;
        if(c=='?') break;
        
        switch(c){
                case '+':
                cout << a+b << endl;
                break;
                case '-':
                cout << a-b << endl;
                break;
                case '*':
                cout << a*b << endl;
                break;
                case '/':
                cout << a/b << endl;
                break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

struct RH {
  unsigned long long p,q;
  vector<unsigned long long> pow,hash;
  void init(const string s,int n) {
    p=1000000007,q=1;
    pow.resize(n+1);hash.resize(n+1);pow[0]=q;hash[0]=0;
    rep(i,n){pow[i+1]=pow[i]*p;hash[i+1]=s[i]+hash[i]*p;}
  }
  unsigned long long h(int i)const{return hash[i];}
  unsigned long long h(int i,int j)const{return h(j)-h(i)*pow[j-i];}
};

void Main() {
  int n,m,l=1,r=1;
  string s;
  cin >> n >> m >> s;
  RH t;
  t.init(s,n);
  set<unsigned long long> se;
  while(m--) {
    string z;
    cin >> z;
    if(z[0]=='R') {
      if(z[1]=='+') r++;
      else r--;
    } else {
      if(z[1]=='+') l++;
      else l--;
    }
    se.in(t.h(l-1,r));
  }
  pr(se.size());
}

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


Measured memory_bytes: 20224
#include <iostream>

using namespace std;

int main(){
  bool bingo = false;
  int i, j, n, N;
  int A[3][3];
  
  for(i = 0; i < 3; i++){
    for(j = 0; j < 3; j++){
      cin >> A[i][j];
    }
  }
  
  cin >> N;
  
  int* b = new int[N];
  
  for(n = 0; n < N; n++){
    cin >> b[n];
    
    for(i = 0; i < 3; i++){
      for(j = 0; j < 3; j++){
        if(A[i][j] == b[n]){
          A[i][j] = 0;
        }
      }
    }
  }
  
  if(A[0][0] + A[1][1] + A[2][2] == 0){
    bingo = true;
  }
  else if(A[0][2] + A[1][1] + A[2][0] == 0){
    bingo = true;
  }
  
  for(i = 0; i < 3; i++){
    if(A[i][0] + A[i][1] + A[i][2] == 0){
      bingo = true;
      break;
    }
    else if(A[0][i] + A[1][i] + A[2][i] == 0){
      bingo = true;
      break;
    }
  }
  
  if(bingo){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  /*
  for(i = 0; i < 3; i++){
    for(j = 0; j < 3; j++){
      cout << A[i][j] << " ";
    }
    
      cout << endl;
  }
  */
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int Q=1<<20;
ll a[Q],b[Q],d[Q],c[Q];
ll va[Q],vb[Q];
int st[Q];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&va[i]),va[i+n]=va[i];
    for(int i=1;i<=n;i++)
        scanf("%lld",&vb[i]),vb[i+n]=vb[i];
    int id=0;
    ll mx=-1e18;
    for(int i=1;i<=n;i++)
        if(va[i]>mx)mx=va[i],id=i;
    ll als=0;
    a[0]=a[n]=mx;
    for(int i=0;i<=n;i++)
        a[i]=va[id+i],b[i]=vb[id+i];
    for(int i=1;i<n;i++)
        d[i+1]=d[i]+2LL*b[i];
    for(int i=1;i<=n;i++)
        c[i]=c[i-1]+d[i];
    for(int i=0;i<=n;i++)
        a[i]-=c[i];
    for(int i=0;i<n;i++)
        als+=c[i]<<1;
    int tp=0;
    for(int i=0;i<=n;i++){
        while(tp>1){
            int l=st[tp-1],r=st[tp];
            if(1LL*(i-r)*(a[r]-a[l])<=1LL*(r-l)*(a[i]-a[r]))--tp;
            else break;
        }
        st[++tp]=i;
    }
    for(int i=1;i<tp;i++){
        int l=st[i],r=st[i+1];
        als+=2LL*(r-l)*a[l];
        als+=1LL*(r-l-1)*(a[r]-a[l]);
    }
    // cerr<<als<<"???\n";
    // ll p1=als/(n<<1),p2=als%(n<<1);
    // printf("%lld.%.15Lf\n",p1,1.0l*p2/(2.0l*n));
    printf("%.15Lf\n",1.0l*als/(2.0l*n));
    return 0;
}

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

int main() {
  int64_t N;
  cin >> N;
  
  vector<int64_t> numl(N + 1);
  numl.at(0) = 2;
  numl.at(1) = 1;
  
  int64_t L_i = 0;
  
  for (int i; i < N - 1; i++) {
    numl.at(i + 2) = numl.at(i + 1) + numl.at(i);
  }
  
  cout << numl.at(N) << endl;
}

Measured memory_bytes: 3560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int[] a =  new int[n+1];
		int ans = 0;
      
      //6なら
      //1,2,
		for(int i=1;Math.pow(i,2)<n+1;i++){
          for(int j=1;Math.pow(j,2)<n+1-Math.pow(i,2);j++){
            for(int k=1;Math.pow(k,2)<n+1-Math.pow(i+j,2)+i*j;k++){
              //System.out.println(i+":"+j+":"+k);
              if( i*i + j*j + k*k + i*j + j*k + k*i < n+1 ){
              	//System.out.println(i*i + j*j + k*k + i*j + j*k + k*i);
                //System.out.println(i+":"+j+":"+k);
                a[i*i + j*j + k*k + i*j + j*k + k*i]++;
              }
            }
          }
		}
      	for(int i=1;i<n+1;i++){
          System.out.println(a[i]);
        }
	}
}

Measured memory_bytes: 30100
N = int(input());

count = [0] * (N+1);

for i in range(N+1):
    tmp = i
    if i != 0:
        while tmp % 2 == 0:
            tmp = tmp /2
            count[i] += 1

max_value = max(count)
num = count.index(max_value)
if num == 0:
    num += 1
print(num)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<iostream>
using namespace std;
const int maxn=10005;
typedef long long ll;
const int inf=0x3fffffff;
const int mod=1000000007;

string s="CODEFESTIVAL2016";

int main() {
   // freopen("in.cpp","r",stdin);
    string tt;
    cin>>tt;
    int n=0;
    for(int i=0;i<s.size();i++)if(s[i]!=tt[i])n++;
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
  import sys
  input = sys.stdin.readline
  import numpy as np
  n,k=map(int,input().split())
  ans=0
  for i in range(1,n+1):
    ans+=1/pow(2,max(int(np.ceil(np.log2(k/i))),0))         
  print(ans/n)
if __name__=='__main__':
  main()

Measured memory_bytes: 12484
#include <bits/stdc++.h>
#define Joe ios::sync_with_stdio(0); cin.tie(NULL); ios_base::sync_with_stdio(0); cout.tie(NULL);
#define INF 1e9+7
using namespace std;
long long arr[100500];
int main(){
	Joe
	int n,k;
	long long ans=INF;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	for(int i=k-1;i<n;i++){
		ans=min(ans,arr[i]-arr[i-k+1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=100004;
int N, M, k;
int arr[MX];
string s;;
pair<int,int> solve(char c)
{
    int cur=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == c) cur--;
        else ++cur;
        if(cur < 0 && i) return mp(0, i);
    }
    map<int,int> m;
    cur=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == c) cur--;
        else ++cur;
        map<int,int>::iterator it=m.lower_bound(cur+1);
        int c=2;
        while(it != m.end() && c--)
        {
            if(i-it->S > 1) return mp(it->S+1, i);
            it++;
        }
        if(m.find(cur) != m.end()) continue;
        m[cur]=i;
    }
    return mp(-1, -1);
}
int main()
{
    cin>>s;
    pair<int,int> an=mp(-1, -1);
    for(char c='a';c<='z';c++)
    {
        pair<int,int> cur=solve(c);
        if(cur.F != -1) {
            an=cur;
            break;
        }
    }
    if(an.F == -1) cout<<"-1 -1\n";
    else {
        cout<<++an.F<<" "<<++an.S<<"\n";
    }
    return 0 ;
}



Measured memory_bytes: 4992
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
n = int(input())
arr = list(map(int , input().split()))
arr.sort(reverse = True)
ptr = 1
s = arr[0]
n-=2
while n:
	s+=arr[ptr]
	n-=1
	if n == 0: break
	s+=arr[ptr]
	n-=1
	ptr+=1
print(s)






Measured memory_bytes: 90980
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	cout << n * n * 3 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}

int N,M,Q;
vector<long long>a,b,c,d;

long long getScore(vector<int>&A){
    long long ans = 0;
    for(int i = 0;i < Q;++i){
        if(A[b[i]] - A[a[i]] == c[i]){
            ans += d[i];
        }
    }
    return ans;
}

long long recursive(vector<int>&A){
    if(A.size() == N){
        return getScore(A);
    }
    long long res = 0;
    int pre = A.empty() ? 0 : A.back();
    for(int i = pre;i < M;++i){
        A.push_back(i);
        res = max(res,recursive(A));
        A.pop_back();
    }
    return res;
}

void calculate(){
    
    Input::input(N,M,Q);
    a.resize(Q);b.resize(Q);
    c.resize(Q);d.resize(Q);
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    vector<int> A;
    cout << recursive(A) << '\n';

}

int main(int,char**){
    calculate();    
}





Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main(){
    long long a, b, c;
    while(cin>>a>>b>>c){
      if(c-(a+b)<0)cout<<"No"<<endl;
       else if(4*a*b<(c-(a+b))*(c-(a+b)))
        cout<<"Yes"<<endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    List<String> list = new ArrayList<String>();
    for(int i = 0; i<n; i++){
      list.add(sc.next());
    }
    
    Collections.sort(list);
    for(int i=0; i<list.size(); i++){
      System.out.print(list.get(i));
    }
    }
}

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


int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (d < a || b < c) {
    cout << 0 << endl;
    return 0;
  }
  cout << min(b, d) - max(a, c) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

#define N 100000
int p[N+1];

void eratosthenes(void){
    int i,j;
    for(i=2;i<N;i++)
        p[i]=1;
    for(i=2;i*i<N;i++){
        if(p[i]){
            for(j=2*i;j<=N;j=j+i){
                p[j]=0;
            }
        }
    }
}
int main(void){
	int q=in(),i,l,r,f[N+1]={};
	eratosthenes();
	for(i=1;i<N;i+=2)
		if(p[i]&&p[(i+1)/2])f[i]=1;
	for(i=1;i<N;i++)f[i]+=f[i-1];
	rep(i,q){
		l=in();
		r=in();
		print(f[r]-f[l-1]);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    size_t n=G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s]=0;
    Q.emplace(0,s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge<int>>> G(3*n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b+n, 0);
        G[a+n].emplace_back(b+2*n, 0);
        G[a+2*n].emplace_back(b, 1);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;
    auto d = dijkstra(s, G);
    if(d[t] == INF<int>){
        puts("-1");
    }else {
        cout << d[t] << "\n";
    }
    return 0;
}

Measured memory_bytes: 17792