akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
vector<int> to[N];
int colour[N];
void dfs(int no,int p){
	for(auto s:to[no]){
		if(s==p||colour[s]==1)continue;
		colour[s]=1;
		dfs(s,no);
	}
}
int main(){
    int n,m;
    cin>>n>>m;
    REP(i,m){
        int a,b,z;
        cin>>a>>b>>z;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    int ans=0;
    REP(i,n){
        if(colour[i]==1)continue;
        dfs(i,-1);
        ans++;
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 10752
N, M = [int(i) for i in input().split()]

boat_dict = {}

for boat in range(M):
    a, b = [int(i) for i in input().split()]
    boat_dict.setdefault(a, [])
    boat_dict[a].append(b)
        
flag = False

for i in boat_dict[1]:
    if i in boat_dict.keys():
        if N in boat_dict[i]:
            flag = True
            break

if flag :
    print('POSSIBLE')
else :
    print('IMPOSSIBLE')

Measured memory_bytes: 31712
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;
int tosi = 2019;

int main()
{
	cin >> n;
	map<char, ll> march;
	rep(i, n) { cin >> s; march[s[0]]++; }
	ll ans = 0;
	ans += march['M'] * march['A'] * march['R'];
	ans += march['M'] * march['A'] * march['C'];
	ans += march['M'] * march['A'] * march['H'];
	ans += march['M'] * march['R'] * march['C'];
	ans += march['M'] * march['R'] * march['H'];
	ans += march['M'] * march['C'] * march['H'];
	ans += march['A'] * march['R'] * march['C'];
	ans += march['A'] * march['R'] * march['H'];
	ans += march['A'] * march['C'] * march['H'];
	ans += march['R'] * march['C'] * march['H'];
	cout << ans << endl;


	return 0;
}


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

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

	int N, K;
	scanf("%d %d", &N, &K);

	vector<int> x(N);
	int x_tmp;
	for (int i = 0; i < N; i++) {
		scanf("%d", &x_tmp);
		x[i] = x_tmp;
	}

	int result = 300000000;
	for (int i = 0; i + K - 1 < N; i++) {
		result = min(result, min(abs(x[i]), abs(x[i + K - 1])) +
		                         abs(x[i + K - 1] - x[i]));
	}
	cout << result;

	// vector<int> x_pos;
	// vector<int> x_neg;
	// int x_tmp, i_pos = 0, i_neg = 0;
	// int num_0 = 0;
	// for (int i = 0; i < N; i++) {
	// 	scanf("%d", x_tmp);
	// 	if (x_tmp > 0) {
	// 		x_pos[i_pos] = x_tmp;
	// 	} else if (x_tmp < 0) {
	// 		x_neg[i_neg] = -x_tmp;
	// 	} else {
	// 		num_0++;
	// 	}
	// }

	// sort(x_pos.rbegin(), x_pos.rend());
	// sort(x_neg.rbegin(), x_neg.rend());
	// int result = ;
	// for (int i = max(0, K - 1 - x_neg.size());
	//      i < x_pos.size() && K - i - 2 < x_neg.size(); i++) {
	// 	if (x_pos[i] > x_neg[N - i - 1]) {
	// 		result = min(result, x_pos[i] + x_neg[K - i - 2] * 2);
	// 	} else {
	// 		result = min(result, x_pos[i] * 2 + x_neg[K - i - 2]);
	// 	}
	// }

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;

struct BIT{
	int N;
	vector<int> bit;
	BIT(int n){		//nは区間幅!!!
		N=n;
		bit.assign(n+1,0);
	}
	BIT(){}
	void init(int n){
		N=n;
		bit.assign(n+1,0);
	}
	int sum(int i){		//i個の和a[0]+..a[i-1]
		int s=0;
		while(i>0){
			s+=bit[i];
			i-=(i&-i);
		}
		return s;
	}
	int val(int i){	//return a[i]	(0-ind)
		return sum(i+1)-sum(i);
	}
	void add(int i,int x){	//a[i]+=x (0-indexed)
		i++;
		while(i<=N){
			bit[i]+=x;
			i+=(i&-i);
		}
	}
};

int cnt[26];
int ind[200010];
vector<int> c2vs[26];

ll inv(string s,string t){
	int N = s.size();
	int it[26]={};
	ll res = 0;
	BIT bit(N);
	rep(i,N){
		int c = t[i]-'a';
		int to = c2vs[c][it[c]];
		int ad = bit.sum(N) - bit.sum(to);
		res += ad;
		bit.add(to,1);
		it[c]++;
	}
	return res;
}

int main(){
	int N;
	string s;
	cin>>s;
	N = s.size();
	rep(i,N){
		int c = s[i]-'a';
		c2vs[c].pb(i);
		ind[i] = cnt[c];
		cnt[c]++;
	}
	int odd = 0;
	rep(i,26) if(cnt[i]%2) odd++;
	if(odd>=2){
		puts("-1");
		return 0;
	}
	int id = -1;
	rep(i,26) if(cnt[i]%2) id = i;

	string le;
	rep(i,N){
		int c = s[i]-'a';
		if(ind[i]<cnt[c]/2) le+='a'+c;
	}
	string tar = le;
	if(id!=-1) tar += 'a'+id;
	reverse(all(le));
	tar += le;
	cout<<inv(s,tar)<<endl;
}

Measured memory_bytes: 3844
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int X = scan.nextInt();
    
    while(true){
      
      int count = 0;
      for (int i = 2; i < (X-1); i++){
        if (X % i == 0){
          count++;
          break;
        }
      }
      
      if (count == 0){
        System.out.println(X);
        return;
      }
      X++;
    }
  }
}

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

int main() {
  double n, k;
  cin >> n >> k;
  double ans = 0;

  for (double i = 1; i <= n; i++) {
    double cnt = 1;
    double tmp = i;
    while (tmp < k) {
      tmp *= 2;
      cnt *= 2;
    }
    ans += ((1/n) * (1/cnt));
  }
  printf("%.12f\n", ans);
  return 0;
}

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



int main(){
  int N;cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++) cin>>a.at(i);
  sort(a.begin(),a.end());
  
  ll res=0;
  
  int right=2;
  
  for(int left=0;left<N-2;left++){
    
    for(int center=left+1;center<N-1;center++){
      
      while(right<N && a.at(right)<a.at(left)+a.at(center) ){
        right++;
      }
      
      
      res+=right-center-1;
      //cout<<left<<" "<<center<<" "<<right<<endl;
      
      
      if(center==right)
        right++;
      
    }
    right=left+3;
  }
  
  cout<<res;
}

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

typedef pair<pair<int, int>, int> point;

int main()
{
	point *S;
	point *T;
	int x, y, n;
	scanf("%d", &n);
	S = new point [n];
	T = new point [n];

	for(int i = 0; i < n; i++){
		scanf("%d %d", &x, &y);
		S[i] = make_pair(make_pair(x, y), i);
		T[i] = make_pair(make_pair(y, x), i);
	}
	sort(S, S + n);
	sort(T, T + n);

	int cnt;
    int Q[100];

    int sx, tx, sy, ty, q;

    scanf("%d", &q);
    while(q){
        cnt = 0;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);

		int x_low = lower_bound(S, S + n, make_pair(make_pair(sx, sy), 0)) - S;
		int x_high = upper_bound(S, S + n, make_pair(make_pair(tx, ty), n)) - S;
		int y_low = lower_bound(T, T + n, make_pair(make_pair(sy, sx), 0)) - T;
		int y_high = upper_bound(T, T + n, make_pair(make_pair(ty, tx), n)) - T;
		int x_width = x_high - x_low;
		int y_width = y_high - y_low;

		if(x_width < y_width){
			for(int i = x_low; i < x_high; i++){
				int y = S[i].first.second;
				if(sy <= y && y <= ty){ Q[cnt++] = S[i].second; }
			}
		}else{
			for(int i = y_low; i < y_high; i++){
				int x = T[i].first.second;
				if(sx <= x && x <= tx){ Q[cnt++] = T[i].second; }
			}
		}
        sort(Q, Q + cnt);
        for(int i = 0; i < cnt; i++){ printf("%d\n", Q[i]); }
        printf("\n");
        q--;
    };
    return 0;
}

Measured memory_bytes: 12600
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int n; cin >> n; int res = 1e7;
    rep(i, n + 1){
        int ns = i, nn = n - i, c = 0;
        while(ns > 0) c += ns % 6, ns /= 6;
        while(nn > 0) c += nn % 9, nn /= 9;
        if(res > c) res = c;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	bool flag = true;
	ll ans = 0, tot = 0;
	rep(i, n){
		int ina, inb;
		cin >> ina >> inb;
		a.at(i) = ina;
		b.at(i) = inb;
		if(ina > inb){
			if(ans == 0 || ans > inb){
				ans = inb;
			}
		}
		if(ina != inb) flag = false;
		tot = tot + (ll)ina;
	}
	if(flag == true){
		cout << 0 << endl;
		return 0;
	}
	
	ans = tot - ans;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long ans=0;
  long long ans1=0,ans2=0,ans3=0,ans4=0;
 
    ans1=b*d;
    ans2=a*c;
    ans3=a*d;
    ans4=b*c;
    ans1=max(ans1,ans2);
    ans2=max(ans3,ans4);
    ans=max(ans1,ans2);
  
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3632
M[15][15],C[15][15],X,Y;
int D(x,y){
	if(y>=Y-1)return 1;
	if(M[x][y])return M[x][y];
	if(C[x][y]==2)return M[x][y]=y+2>=Y||C[x][y+2]!=1?D(x,y+2):0;
	int s=0;
	if(0<x&&C[x-1][y+1]==0)s+=D(x-1,y+1);
	if(C[x][y+1]!=1)s+=D(x,y+1);
	if(x<X-1&&C[x+1][y+1]==0)s+=D(x+1,y+1);
	return M[x][y]=s;
}
main(i,j,s){for(;scanf("%d%d",&X,&Y),X;printf("%d\n",j)){
memset(M,0,sizeof(M));
for(j=0;j<Y;j++)for(i=0;i<X;i++)scanf("%d",C[i]+j);
for(j=i=0;i<X;i++)if(C[i][0]!=1)j+=D(i,0);
}exit(0);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int n;
const int sz=1e5+9;
char a[sz];
int ans[sz];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%s",a);
    n=strlen(a);
    for(int i=0;i+1<n;i++){
        if(a[i]=='R'&&a[i+1]=='L'){
            int st=i;
            int en=i+1;
            while(st>=0&&a[st]=='R'){
                ans[((i-st)&1)==0?i:i+1]++;
                st--;
            }
            while(en<n&&a[en]=='L'){
                ans[((en-i-1)&1)==0?i+1:i]++;
                en++;
            }
        }
    }
    for(int i=0;i<n;i++) printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, a[100000], b[100000];
    cin >> n;
    int i_max, i_min;
    int a_min = 1000000000, a_max = 0;
    rep(i, n) {
        cin >> a[i] >> b[i];
        if (a[i] < a_min) {
            i_min = i;
            a_min = a[i];
        }
        if (a[i] > a_max) {
            i_max = i;
            a_max = a[i];
        }
    }
    cout << b[i_max] + a[i_max] << endl;
	return 0;
}

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

int main(){
	int n, m, p, x[1000];
	while(1){
		cin >> n >> m >> p;
		
		int sum=0;
		
		if(n==0 && m==0 && p==0) break;
		
		p=100-p;
		
		for(int i=0; i<n; i++){
			cin >> x[i];
			sum+=x[i];
		}
		p*=sum;
		
		if(x[m-1]==0) p=0;
		else p=p/x[m-1];
		
		cout << p << endl;
	}
	return 0;
}

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

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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


int main()
{
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<llong> a(x,0);
    vector<llong> b(y,0);
    vector<llong> c(z,0);
    REP(i,x) cin>>a[i];
    REP(i,y) cin>>b[i];
    REP(i,z) cin>>c[i];
    vector<llong> cnt(x*y,0);

    REP(i,x)
    {
        REP(j,y)
        {
            llong v=a[i]+b[j];
            cnt.push_back(v);
        }
    }
    sort(cnt.begin(),cnt.end(),greater<llong>());
    vector<llong> ans(k*z,0);
    REP(i,k)
    {
        REP(j,z)
        {
            llong t=cnt[i]+c[j];
            ans.push_back(t);
        }
    }
    sort(ans.begin(),ans.end(),greater<llong>());
    for(int i=0; i<k; i++)
    {
        cout<<ans[i]<<endl;
    }
    cout<<endl;
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0){
    c-=b;
    if(c>0)
      a-=d;
    else
      break;
  }
  if(a<=0)
    cout<<"No";
  else
    cout<<"Yes";
}

Measured memory_bytes: 3568
#include<stdio.h>

int main(void)
{
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);

	d = a/b;
	r = a%b;
	f = (double)a/b;

	printf("%d %d %.5f\n", d, r, f);

	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 9;

int _;

//========================================================================

//========================================================================
int main()
{
   int n,x,t;
   scanf("%d%d%d",&n,&x,&t);
    int k=n/x;
    if(n%x) k++;
    printf("%d\n",k*t);
    return 0;
}



Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)
const int N = 2e5+1;
int x[N],y[N],n;
char d[N];
void rotate() {
  
  for(int i=0;i<n;i++) {
    if(d[i] == 'R') d[i] = 'U';
    else
    if(d[i] == 'D') d[i] = 'R';
    else
    if(d[i] == 'L') d[i] = 'D';
    else
    if(d[i] == 'U') d[i] = 'L';
    swap(x[i],y[i]);
    x[i] *= -1;
    x[i] += 200000;
    // int temp = x[i];
    // x[i] = y[i];
    // y[i] = 200000 - temp;
  }
}

int solve1() {
  // U and R
  vector<vector<pair<int,char>>> v(2*N);
  int m = 2 * N;
  int ans = 1e16;
  for(int i=0;i<n;i++) {
    if(!(d[i] == 'R' || d[i] == 'U'))
      continue;
    v[x[i]+y[i]].emplace_back(x[i],d[i]);
  }
  for(int i=0;i<2*N;i++) {
    sort(v[i].begin(),v[i].end());
    if(!v[i].empty())
    for(int j=0;j<v[i].size()-1;j++) {
      if(!(v[i][j].second == 'R' && v[i][j+1].second == 'U'))
        continue;
      ans = min(ans, v[i][j+1].first - v[i][j].first);
    }
  }
  return ans*10;
}
int solve2() {
  // for U and D
  vector<vector<pair<int,char>>> v(N);
  int ans = 1e16;
  for(int i=0;i<n;i++) {
    if(!(d[i] == 'U' || d[i] == 'D'))
      continue;
    v[x[i]].emplace_back(y[i],d[i]);
  }
  for(int i=0;i<N;i++) {
    sort(v[i].begin(),v[i].end());
    if(!v[i].empty())
    for(int j=0;j<v[i].size()-1;j++) {
      if(!(v[i][j].second == 'U' && v[i][j+1].second == 'D'))
        continue;
      ans = min(ans,v[i][j+1].first - v[i][j].first);
    }
  }
  return ans*5;
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin>>n;
  for(int i=0;i<n;i++) {
    cin>>x[i]>>y[i]>>d[i];
  }
  int ans = 1e16;
  for(int i=0;i<4;i++) {
    ans = min(ans, solve1());
    ans = min(ans, solve2());
    rotate();
  }
  if(ans == 1e16) cout<<"SAFE\n";
  else 
  cout<<ans;
  return 0;
}

Measured memory_bytes: 27076
//
// Created by 永徳泰明 on 2019-01-27.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

typedef pair <ll,ll> llp;

ll calc(llp a){
    return a.first-a.second;
}

int main() {
    readFromInputFile();
    int n;
    cin>>n;
    vector<llp>arr;
    rep(i,n){
        llp tmp;
        cin>>tmp.first>>tmp.second;
        arr.push_back(tmp);
    }
    sort(arr.begin(), arr.end(), [](const llp &a, const llp &b){
        return (a.first+a.second) > (b.first+b.second);
    });

    ll sum = 0;
    rep(i,n){
        if (i%2==0){
            sum += arr[i].first;
        } else {
            sum -= arr[i].second;
        }
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n,t,a;
  cin>>n;
  cin>>t>>a;
  int ans = -1;
  double diff = 1111111111;
  for(int i = 0;i<n;i++){
    int h;
    cin>>h;
    double tmp = a - (t - h * 0.006);
    if(tmp < 0 ) tmp *= -1;
    if(diff > tmp){
      ans = i;
      diff = tmp;
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<cstdio>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
#define abs Abs
#define int long long
using namespace std;

int d[50];
int dp[55][55];
double Abs(double a) {
	if (a < 0)return -a;
	return a;
}
signed main() {
	map<int, int>O;
	for (int i = 0; i < 55; i++) {
		dp[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
		}
	}
	int a, b, c; cin >> a >> b >> c;
	for (int e = 0; e < a; e++) {
		cin >> d[e];
		O[d[e]]++;
	}
	double MAX = 0;
	sort(d, d + a, greater<int>());
	double sum = 0;
	for (int i = 0; i < a; i++) {
		sum += d[i];
		if (i+1 >= b&&i<c) {
			MAX = max(MAX, sum / (i + 1));
		}
	}
	printf("%.10lf\n", MAX);
	if (d[0] == d[b - 1]) {
		int ans = 0;
		for (int i = b; i <= c; i++) {
			ans += dp[O[d[0]]][i];
		}
		cout << ans << endl;
	}
	else {
		int t = 0;
		for (int i = 0; i < b; i++) {
			if (d[i] == d[b - 1])t++;
		}
		cout << dp[O[d[b-1]]][t] << endl;
	}
}

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();
    System.out.println(n % digitSum(n) == 0 ? "Yes" : "No");
  }
  
  public static int digitSum(long n){
    int ans = 0;
    while(n != 0){
      ans += n % 10;
      n /= 10;
    }
    
    return ans;
  }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define inf (1ll<<60)
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;

int main() {
    
    
    fast();
    int t,n,m,sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>t;
        sum+=t;
    }
    if(sum>n)
    cout<<"-1\n";
    else
    cout<<n-sum<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  std::vector<int> H(N);
  bool result = true;
  int max_val = 0;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
    if (max_val < H[i]) max_val = H[i];
    if(max_val-1 > H[i]) {
      result = false;
      break;
    }
  }

  if(result) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 640
N = int(input())
a = list(map(lambda x: int(x) // 400, input().split()))
s_a = []
b_a = []

for i in range(N):
    if a[i] <= 7:
        s_a.append(a[i])
    else:
        b_a.append(a[i])

if len(s_a) == 0:
    min = 1
else:
    min = len(set(s_a))


max = len(set(s_a)) + len(b_a)


print(min, max)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
k = int(input())
ans = 0
n = 7

if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit(0)
c = 1
while True:
    if n % k == 0:
        break
    n = (n * 10 + 7) % k
    c += 1

print(c)


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

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

    int ans;
    if (b % a == 0) {
        ans = a + b;
    } else {
        ans = b - a;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

int N;
int main (){
    cin >> N;
    int a[109];
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort( a, a+N);
    int ali = 0;
    for(int i=0; i<N; i+=2){
        ali += a[N-1-i];
    }
    cout << ali - (sum - ali) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, N, K, al, bl, cl, t=1;
	string a, b, c, d;
	cin >> a >> b >> c;
	al = a.length(); bl = b.length(); cl = c.length();

	while (1) {
		switch (t) {
		case 1:	if (a[i] == 'a')t = 1;
				if (a[i] == 'b')t = 2;
				if (a[i] == 'c')t = 3;
				if (al) { al--; i++; }
				else	{ cout << 'A' << endl; return 0; }
				break;
		case 2:	if (b[j] == 'a')t = 1;
				if (b[j] == 'b')t = 2;
				if (b[j] == 'c')t = 3;
				if (bl) { bl--; j++; }
				else	{ cout << 'B' << endl; return 0; }
				break;
		case 3:	if (c[k] == 'a')t = 1;
				if (c[k] == 'b')t = 2;
				if (c[k] == 'c')t = 3;
				if (cl) { cl--; k++; }
				else	{ cout << 'C' << endl; return 0; }
				break;
		}
	}	
	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
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; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first >> p.second; return is; }
using namespace std;
// clang-format on

template<typename InputIterator> std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

set<int> bin(set<int> l, set<int> r, char op) {
  set<int> val;
  if (op == 'u') set_union(all(l), all(r), inserter(val, val.begin()));
  if (op == 'i') set_intersection(all(l), all(r), inserter(val, val.begin()));
  if (op == 'd') set_difference(all(l), all(r), inserter(val, val.begin()));
  if (op == 's') val = bin(bin(l, r, 'd'), bin(r, l, 'd'), 'u');
  return val;
}

using state = string::const_iterator;

set<int> expr(state &);

map<char, set<int>> m;
set<int> u;

set<int> elem(state &s) {
  char c = *s;
  s++;
  return m[c];
}

set<int> factor(state &s) {
  if (*s == '(') {
    s++;
    set<int> val = expr(s);
    s++;
    return val;
  }
  return elem(s);
}

set<int> term(state &s) {
  int k = 0;
  while (*s == 'c') s++, k++;
  if (odd(k)) {
    set<int> val = factor(s);
    return bin(u, val, 'd');
  }
  return factor(s);
}

set<int> expr(state &s) {
  set<int> val = term(s);
  while (1) {
    char c = *s;
    if (string("uidsc").find(c) != string::npos) {
      s++;
      val = bin(val, term(s), c);
    } else {
      break;
    }
  }
  return val;
}

main {
  while (1) {
    m.clear();
    u.clear();
    char c;
    int k;
    while (1) {
      if (!(cin >> c >> k)) return 0;
      if (!k) break;
      while (k--) {
        int x;
        cin >> x;
        m[c].insert(x);
        u.insert(x);
      }
    }
    string s;
    cin >> s;
    state p = s.begin();
    set<int> w = expr(p);
    cout << (w.size() ? join(all(w), " ") : "NULL") << endl;
  }
}

Measured memory_bytes: 3232
#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;
}
const int MAX = 1000001;
int arr[1000000];
int last_visit[MAX];
struct Query
{
    int l, r, idx;
};
bool cmp(Query x, Query y)
{
    return x.r < y.r;
}
void update(int idx, int val, int bit[], int n)
{
    for (; idx <= n; idx += idx & -idx)
        bit[idx] += val;
}
int query(int idx, int bit[], int n)
{
    int sum = 0;
    for (; idx > 0; idx -= idx & -idx)
        sum += bit[idx];
    return sum;
}
void answeringQueries( int n, Query queries[], int q)
{
    int bit[n + 1];
    memset(bit, 0, sizeof(bit));
 
   
    memset(last_visit, -1, sizeof(last_visit));
 
    int ans[q];
    int query_counter = 0;
    for (int i = 0; i < n; i++)
    {
       
        if (last_visit[arr[i]] != -1)
            update(last_visit[arr[i]] + 1, -1, bit, n);
 
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);

     
        while (query_counter < q && queries[query_counter].r == i)
        {
            ans[queries[query_counter].idx] =
                query(queries[query_counter].r + 1, bit, n) -
                query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }
 
    for (int i = 0; i < q; i++)
        cout << ans[i] << endl;
}
void solve()
{
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n;i++){
        cin >> arr[i];
    }
    Query queries[q];
    int a, b;
    
    for (int i = 0; i < q;i++){
        cin >> a >> b;
        a--;
        b--;
        queries[i].l = a;
        queries[i].r = b;
        queries[i].idx = i;
    }
    sort(queries, queries + q, cmp);
    answeringQueries(n, queries, q);
}   
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<string> S(n);
    for(int i=0;i<n;i++){
        cin >> S[i];
    }
    map<char,ll> M;
    for(int i=0;i<n;i++){
        char ca = S[i][0];
        M[ca]++;
    }
    ll m = M['M'];
    ll a = M['A'];
    ll r = M['R'];
    ll c = M['C'];
    ll h = M['H'];
    ll ans = 0;
    ans += m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
    cout << ans << endl;

}

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

int f(string s1, string s2) { 
  int count = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    bool left = false;
    bool right = false;
    for (int i = 0; i < s1.size(); i++) {
      if (c == s1[i]) {
        left = true;
      }
    }
    for (int i = 0; i < s2.size(); i++) {
      if (c == s2[i]) {
        right = true;
      }
    }
    if (left && right) {
      count += 1;
    }
  }
  return count; 
}

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;

  int mx = 0;
  string s1;
  string s2;
  for (int i = 1; i < S.length(); i++) {
    s1 = S.substr(0, i);
    s2 = S.substr(i, S.length() - 1);
    // cout << s1 << endl;
    // cout << s2 << endl;
    mx = max(mx, f(s1, s2));
  }
  cout << mx << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	long long int a[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int ans = a[0] - 1;
	long long int v = 2;
	for (i = 1; i < n; i++)
	{
		ans += a[i] / v;
		if (a[i] % v == 0)
			ans--;
		if (a[i] == v)
			v++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2472
S=input()
if S[1-1]=='R':
  if S[2-1]=='R':
    if S[3-1]=='R':
      print(3)
    else:
      print(2)
  else:
    print(1)
elif S[2-1]=='R':
  if S[3-1]=='R':
    print(2)
  else:
    print(1)
elif S[3-1]=='R':
  print(1)
else:
  print(0)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
    using namespace std;
#define ll long long
     const int N=100100;
    ll n , mem[N],a[N];

  ll dp(int i){

  if(i==n+1)
    return 1e10;
 if(i==n)
  return 0;
  if (mem[i]!=-1)
    return mem[i];

    ll path1= abs(a[i]-a[i+1])+dp(i+1);
  ll path2= abs(a[i]-a[i+2])+dp(i+2);
return mem[i]=min(path1,path2);


  }


int main(){




    scanf("%lld",&n);
for(int i=1;i<=n;i++)
    scanf("%lld",&a[i]);
    memset(mem, -1 ,sizeof mem);
printf("%lld\n",dp(1));
return 0;
}






Measured memory_bytes: 4992
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        ArrayList<Character> list = new ArrayList<>();

        for(int i = 0; i<sa.length(); i++) {
            char c = sa.charAt(i);
            if(c=='B') {
                if (list.size() > 0) list.remove(list.size() - 1);
            }
            else list.add(c);
        }
        Character[] carray = list.toArray(new Character[list.size()]);
        for(char c: carray) System.out.print(c);
        System.out.println();

    }
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, m;

vector<int> a, b;

vector<ll> ans;

/////////////////////////////////////////////////////////
class UnionFind {
public:
  static const int MAX_N_LIB = (ll)(2e5 + 100);

  int uf_par[MAX_N_LIB];
  int uf_rank[MAX_N_LIB];
  int uf_size[MAX_N_LIB];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for (int i = 0; i < n; ++i) {
      uf_par[i] = i;
      uf_rank[i] = 0;
      uf_size[i] = 1;
    }
  }

  int find(int x) {
    if (uf_par[x] == x) return x;
    else {
      return uf_par[x] = find(uf_par[x]);
    }
  }

  void unite(int leaf_x, int leaf_y) {
    int x = find(leaf_x);
    int y = find(leaf_y);

    if (x == y) return;

    if (uf_rank[x] < uf_rank[y]) {
      uf_par[x] = y;
      uf_size[y] += uf_size[x];
    }
    else if (uf_rank[x] > uf_rank[y]) {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
    }
    else {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
      uf_rank[x] += 1;
    }
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return uf_size[find(x)];
  }
};
/////////////////////////////////////////////////////////

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    int tmp_a, tmp_b;
    scanf("%d %d", &tmp_a, &tmp_b);
    a.push_back(tmp_a);
    b.push_back(tmp_b);
  }

  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());

  UnionFind union_find(n + 5);

  ll decayed = (ll)(n - 1) * (ll)(n) / 2;

  ans.push_back(decayed);

  for (int i = 0; i < a.size(); ++i) {
    if (!union_find.same(a[i], b[i])) {
      decayed -= (ll)(union_find.size(a[i])) * (ll)(union_find.size(b[i]));
      union_find.unite(a[i], b[i]);
    }

    ans.push_back(decayed);
  }

  reverse(ans.begin(), ans.end());

  for (int i = 1; i < ans.size(); ++i) {
    printf("%lld\n", ans[i]);
  }

  return 0;
}


Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define N 409
#define M 100009
using namespace std;

int n,m,a[M],b[M]; bool bo[N][N],ban[N];
int main(){
	scanf("%d%d",&n,&m);
	int i,j,k,ans=0;
	for (i=1; i<=m; i++) scanf("%d%d",&a[i],&b[i]);
	for (i=1; i<=n; i++){
		bo[i][i]=1;
		for (j=m; j; j--) if (bo[i][a[j]] && bo[i][b[j]]){
			ban[i]=1; break;
		} else if (bo[i][a[j]]) bo[i][b[j]]=1;
		else if (bo[i][b[j]]) bo[i][a[j]]=1;
	}
	for (i=1; i<n; i++) if (!ban[i])
		for (j=i+1; j<=n; j++) if (!ban[j]){
			for (k=1; k<=n; k++) if (bo[i][k] && bo[j][k]) break;
			if (k>n) ans++;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf = 1e3+9,MX = 1e9+9;
ll n,m,X1,Y1,X2,Y2;
ll dis[inf][inf];
ll idx[] = {-1,1,0,0};
ll idy[] = {0,0,-1,1};
string grid[inf];
priority_queue < pair< ll,pair< ll,ll > >  > pq;
int main(){

    cin>>n>>m;
    cin>>X1>>Y1>>X2>>Y2;
    for(ll i=1;i<=n;i++)
        for(ll j=1;j<=m;j++)
            dis[i][j] = MX;
    dis[X1][Y1] = 0;
    for(ll i=1;i<=n;i++)
        cin>>grid[i],grid[i] = " " +grid[i];
    pq.push({0,{X1,Y1} } );
    while(!pq.empty()){
        pair<ll,pair<ll,ll > > cur = pq.top();
        pq.pop();
        ll x = cur.second.first,y = cur.second.second;
        cur.first *= -1;
        if(cur.first > dis[ x][y])
            continue;
        for(ll z=0;z<4;z++){
            ll i = x + idx[z],j = y +idy[z];
            if(!(i >0 && j>0 && i<=n && j<=m && grid[i][j] == '.' && dis[i][j] > dis[x][y]))
                continue;
            dis[i][j] = dis[x][y];
            pq.push( {-dis[i][j], {i,j} } );
        }
        for(ll i = x-2;i<=x+2;i++){
            for(ll j=y-2;j<=y+2;j++){
            if(!(i >0 && j>0 && i<=n && j<=m && grid[i][j] == '.' && dis[i][j] > dis[x][y]+1))
                continue;
                dis[i][j] = dis[x][y] + 1;
                            pq.push( {-dis[i][j], {i,j} } );

            }
        }
    }
    cout<<(dis[X2][Y2] == MX?-1:dis[X2][Y2])<<endl;
}



Measured memory_bytes: 12732
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(ll i=cc;i<=n;++i)
#define drep(i,cc,n) for(ll i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll l,r;
    cin>>l>>r;
    ll ans = 2018;
    if(r-l>3000){
        cout<<0<<endl;
        return 0;
    }
    else {
        rep(i,l,r-1){
            rep(j,i+1,r){
                ans = min(ans,(i*j) % 2019);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

void Sieve(vector<bool> &IsPrime,ll n){
    rep(i,n+1) IsPrime[i]=1;
    IsPrime[0]=IsPrime[1]=0;
    for(ll i=2;i*i<=n;i++){
        if(IsPrime[i]){
            for(ll j=i;i*j<=n;j++){
                IsPrime[i*j]=0;
            }
        }
    }
}

int main(){
    ll n;
    cin>>n;
    vector<bool> isp(55556);
    Sieve(isp,55555);
    ll now=0;
    rep(i,n){
        while(1){
            now++;
            if(isp[now]&&now%10==1){
                cout<<now<<' ';
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#include <map>
#include <set>
#include <array>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

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

int n, a[100009][3], dp[100009][3];

int call(int i, int prev)
{
    if(i > n)
        return 0;

    if(prev != -1 && dp[i][prev] != 0)
        return dp[i][prev];

    int ret = -1;
    for(int j = 0; j < 3; j++)
    {
        if(j != prev)
            ret = max(ret, call(i+1, j) + a[i][j]);
    }

    if(prev != -1)
        dp[i][prev] = ret;

    return ret;
}

int main()
{
    int i, j;
    cin >> n;
    for(i = 1; i <= n; i++)
    {
        for(j = 0; j < 3; j++)
            cin >> a[i][j];
    }

    cout << call(1, -1);
}


Measured memory_bytes: 8832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

ll euclid(ll x, ll y, ll &k, ll &l) {
	if (y == 0) {
		k = 1;
		l = 0;
		return x;
	}
	ll g = euclid(y, x % y, l, k);
	l -= k * (x / y);
	return g;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	ll n;
	scanf("%lld", &n);
	ll ans = 2 * n;
	vector<ll> d;
	for (ll x = 2; x * x <= n; x++) {
		if (n % x) continue;
		ll y = 1;
		while(n % x == 0) {
			n /= x;
			y *= x;
		}
		d.push_back(y);
	}
	if (n > 1) d.push_back(n);
	bool ok = false;
	for (int i = 0; i < (int)d.size(); i++) {
		if (d[i] % 2 == 0) {
			d[i] *= 2;
			ok = true;
		}
	}
	if (!ok) d.push_back(2);

	int m = (int)d.size();
	assert(m < 18);
	for (int mask = 0; mask < (1 << m); mask++) {
		ll x = 1, y = 1;
		for (int i = 0; i < m; i++) {
			if ((mask >> i) & 1)
				x *= d[i];
			else
				y *= d[i];
		}
		if (y == 1) continue;
		ll k, l;
		euclid(x, y, k, l);

		l %= x;
		//cout<<x<<" "<<k<<endl;
		if (l <= 0) l += x;
		k = l * y - 1;
		ans = min(ans, k);
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <deque>

using namespace std;
using graph = vector<vector<int>>;


int main() {
    int n, m;
    cin >> n >> m;
    graph g(n+1);
    while(m--) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    deque<int> path;
    path.push_back(1);
    vector<int> visited(n+1);
    int v = 1;
    visited[1] = true;
    bool cont = true;
    while(cont) {
        cont = false;
        for(auto&& w : g[v]) {
            if(!visited[w]) {
                visited[w] = true;
                path.push_back(w);
                v = w;
                cont = true;
                break;
            }
        }
    }
    v = 1;
    cont = true;
    while(cont) {
        cont = false;
        for(auto&& w : g[v]) {
            if(!visited[w]) {
                visited[w] = true;
                path.push_front(w);
                v = w;
                cont = true;
                break;
            }
        }
    }
    cout << path.size() << endl << path.front();
    path.pop_front();
    while(!path.empty()) cout << " " << path.front(), path.pop_front();
    cout << endl;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h> 
const long long MOD = 1e9+7;
using namespace std;


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

	string AtCoder,S,Contest;
	cin >> AtCoder >> S >> Contest;

	cout << "A" << S.at(0) << "C" << endl;
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;int x[1<<23],p,q,n,i,j;main(){for(i=0;i<999;i++){for(j=0;j<999;j++){x[i*i+j*j]++;}}cin>>n;for(i=0;i<n;i++){cin>>p>>q;int r=p*p+q*q,s=0;for(j=1;j<=r;j++){if(r%j<1){s+=x[j]*x[r/j];}}if(s==8){cout<<'P'<<endl;}else{cout<<'C'<<endl;}}}

Measured memory_bytes: 9336
import numpy as np

N=int(input())
A=np.array(input().split(" "),dtype=np.int64)

mod=1000000007

# 累積和
s=0
for i in range(N):
    s+=A[i]
    s=s%mod

ans=0
for i in range(N):
    s=s-A[i]
    if(s<0):
        s+=mod
    
    ans+=A[i]*s
    ans=ans%mod
    

print(ans)

Measured memory_bytes: 53248
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << a[0] + a[1] + a[2] * 10 <<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,p,q,p1,q1;
int a[105],b[105];
bool cmp(const int &x,const int &y)
{
	return x>y;
}
int main()
{
	scanf("%d%d%d%d",&n,&m,&p,&q);
	for(register int i=1;i<=n;i++)
	    scanf("%d",&a[i]);
	for(register int i=1;i<=m;i++)
	    scanf("%d",&b[i]);
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+m+1);
    if(a[1]>=q||b[1]<=p||b[1]<=a[1]) cout<<"War\n";
    else cout<<"No War\n";
    return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    int n,k;cin>>n>>k;
    vector<int>cnt(n);
    rep(i,n){
        int a;cin>>a;
        cnt[a]++;
    }

    sort(cnt.begin(),cnt.end());
    reverse(cnt.begin(),cnt.end());

    int cnt2=0;
    rep(i,k){
        cnt2+=cnt[i];
    }

    cout<<n-cnt2<<endl;

}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    ll Q;
    cin >> Q;
    vector<pair<ll,ll> > value(Q);
    rep(i,Q){
        cin >> value[i].first >> value[i].second;
    }
    vector<ll> match(100001, 0);
    ll ans = 0;
    rep(i,N){
        match[vec[i]]++;
        ans += vec[i];
    }
    rep(i,Q){
        ll num = match[value[i].first];
        match[value[i].first] = 0;
        match[value[i].second] += num;
        ans -= num * value[i].first;
        ans += num * value[i].second;
        cout << ans << endl;
    }
}



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

using namespace std;
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define N 3010
ll f[N][N],n,a[N];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int l=0;l<n;l++){
     for(int i=0;i+l<n;i++){
      int j=i+l;
      if(n%2==l%2){
       if(i==j)f[i][j]=-a[i];
       else f[i][j]=min(f[i+1][j]-a[i],f[i][j-1]-a[j]);   
      }
      else{
          if(i==j)f[i][j]=a[i];
            else f[i][j]=max(f[i+1][j]+a[i],f[i][j-1]+a[j]);   
      }
     }
    }
    cout<<f[0][n-1]<<endl;
 return 0;   
}

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


int main() {
    string tmp;
    deque<char> S;
    cin >> tmp;
    rep(i, tmp.size()){
        S.push_back(tmp[i]);
    }
    int Q;
    cin >> Q;
    int flag = 0; //ひっくり返っているかを判定する.
    rep(i, Q){
        int T;
        cin >> T;
        if(T == 1){
            flag++;
        }else if(T == 2){
            int F;
            char C;
            cin >> F >> C;
            if((F + flag) % 2 == 1){
                S.push_front(C);
            }else if((F + flag) % 2 == 0){
                S.push_back(C);
            }else{
                cout << "error" <<endl;
            }
        }else{
            cout << "error" <<endl;
        }
    }
    if(flag % 2){
        while(!S.empty()){
            cout << S.back();
            S.pop_back();
        }
    }else{
        while(!S.empty()){
            cout << S.front();
            S.pop_front();
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

int mydiv(int x,int y){
    if(x%y==0)return x/y;
    else return x/y+1;
}

signed main(){
    int A[12]={0,2,0,1,0,1,0,0,1,0,1,0};
    int x,y;cin>>x>>y;x--;y--;
    cout<<(A[x]==A[y]?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        double a= sc.nextInt();
        double b= sc.nextInt();
 
        int d = (int)(a / b);
        int r = (int)(a % b);
        double f = a / b;
        
        
        System.out.println(d +" " + r +" "+(String.format("%.5f", f)));
        
        
    }
}




Measured memory_bytes: 26384