akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  rep(i,0,s.size()-1){
    if(s[i] == s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
    if(i == s.size()-2) continue;
    if(s[i] == s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


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

int main() {
	string s; cin >> s;
	sort(s.begin(), s.end());
	int N = s.size();
	while( !(s.empty()) ){
		if(s[N - 1] == s[N - 2]){
			s.pop_back();
			s.pop_back();
			N -= 2;
		} else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

long long calculate_sum(int a, int N) 
{ 
    long long m = N / a; 
  
    long long sum = m * (m + 1) / 2; 
  
    long long ans = a * sum; 
  
    return ans; 
} 

int main() {
	long long n;
	cin>>n;
	cout << calculate_sum(1, n) -  calculate_sum(3, n) - calculate_sum(5, n)
	 + calculate_sum(15, n) << "\n";
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.lang.*;

/**
 * StandardDeviation
 */
public class Main {

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

        while (true) {
            int n = sc.nextInt();

            if (n == 0)
                break;

            int list[] = new int[n];
            double sum = 0;
            for (int i = 0; i < n; i++) {
                list[i] = sc.nextInt();
                sum += list[i];
            }

            sum /= n;
            double ans = 0;
            for (int i = 0; i < n; i++) {
                ans += Math.pow((list[i] - sum), 2);
            }

            System.out.printf("%.8f\n", Math.sqrt((double) ans / n));
        }
    }
}


Measured memory_bytes: 31548
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#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 RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int x,y;cin>>x>>y;
  if(y%2==1){
    cout<<"No"<<endl;
    return 0;
  }

  y = y/2;
  if(y>=x&&y<=2*x){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  



  return 0;
}

Measured memory_bytes: 3128
'use strict';
const main = x => {
  x = x[0].split(' ').map(val => parseInt(val, 10));
  const a = x[0], b = x[1], c = x[2];
  console.log(b+c>a?b+c-a:0);
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 9420
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

struct UnionFind{
  vector<int> par;
  UnionFind(int N):par(N){
    REP(i,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }

};

int main(){
  int N,K,L;
  cin>>N>>K>>L;
  UnionFind RTree(N);
  UnionFind TTree(N);
  int Rr[N],Tr[N];
  REP(i,K){
    int p,q;
    cin>>p>>q;
    p--;q--;
    RTree.unite(p,q);
  }
  REP(i,L){
    int r,s;
    cin>>r>>s;
    r--;s--;
    TTree.unite(r,s);
  }
  REP(i,N){
    Rr[i]=RTree.root(i);
    Tr[i]=TTree.root(i);
  }
  map<pair<int,int>,int> m;
  REP(i,N){
    m[make_pair(Rr[i],Tr[i])]+=1;
  }
  // REP(i,N)cerr<<Rr[i]<<endl;
  // REP(i,N)cerr<<Tr[i]<<endl;
  REP(i,N){
    cout<<m[make_pair(Rr[i],Tr[i])]<<endl;
  }
  return 0;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a = 0;
  string s;
  in(s);
  rep(i, s.size() - 1){
    if(s[i] != s[i + 1])
      a++;
  }
  out(a);
  memi;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,p;
int d[10001];
int dist(int i,int j){
    if(i==j) return 0;
    else if(i<j) return j-i;
    else return j+n-i;
}

void solve(){
    int ans=1000000;
    int prev,next;

    for(int i=0;i<m;i++){
	prev=(i+m-1)%m,next=(i+1)%m;
	ans=min(ans,dist(p,d[i])+dist(d[next],d[i]));
	ans=min(ans,dist(d[i],p)+dist(d[i],d[prev]));
    }
    printf("%d\n",ans*100);
}

int main(){
    scanf("%d%d%d",&n,&m,&p);
    d[0]=p;
    for(int i=1;i<=m;i++){
	scanf("%d",&d[i]);
    }
    m++;
    sort(d,d+m);

    solve();

    return 0;
}

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

using namespace std;

#define int long long

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(args...) { string _s = #args; replace(ALL(_s), ',', ' '); stringstream ss(_s); cerr << endl;_debug(ss, args); }
#define _rg auto it = next(v.begin()); it != v.end(); it++
#define _input ostream& operator <<(ostream& out

template<typename T, typename U>
_input, const pair<T, U>& p) {
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}

#define cont(c) template<typename T> _input, const c<T>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}
				
#define cont2(c) template<typename T, typename U> _input, const c<T, U>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}

cont(vector) cont(set) cont(multiset) cont(queue) cont2(map)

template<typename T, size_t n, typename= enable_if_t<!is_same<T, char>::value>>
_input, const T(&v)[n]) {
	if (n == 0) return out;
	out << "[" << v[0];
	for (int i = 1; i < (int)n; i++) out << ", " << v[i];
	out  << "]"; return out;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T &arg) {
	string name; ss >> name;
	cerr << name << " = " << arg << endl;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T& arg, const Ts&... args) {
	string name; ss >> name; 
	cerr << name << " = " << arg << ", ";
	if (is_class<T>::value || is_array<T>::value) cerr << endl;
	_debug(ss, args...);
}

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX/2;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

const int N = 1000009;
int has[N];

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	int a[n];
	for (int& x: a) {
		cin >> x;
		has[x]++;
	}
	
	int ans = n;
	for (int i = 0; i < n; i++) {
		has[a[i]]--;
		for (int j = 1; j*j <= a[i]; j++) {
			if (a[i]%j == 0) {
				int x = j;
				int y = a[i]/j;
				
				if (has[x]) {
					ans--;
					break;
				}
				if (has[y]) {
					ans--;
					break;
				}
			}
		}
		has[a[i]]++;
	}
	
	cout << ans << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 12916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int numofbits(ll bits) {
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main(){
	int h, w, k; cin >> h >> w >> k;
	vector<vector<bool>> f(h,vector<bool>(w,0));
	string s;
	REP(i,h){
		cin >> s;
		REP(j,w)
			f[i][j]=(s[j]=='1');
	}
	int ans=INF;
	REP(i,(1<<(h-1))){
		int kh=numofbits(i);
		VI c(h,0); bool no=0;
		int koe=0;
		REP(j,w){
			int sj=0;
			REP(m,h){
				if(f[m][j])
					c[sj]++;
				if(c[sj]>k){
					if(koe==j){
						no=1;
						break;
					}
					kh++;
					koe=j;
					REP(l,h)
						c[l]=0;
					j--;
					break;
				}
				if((i>>m)&1){
					sj++;
				}
			}
			if(no)
				break;
		}
		if(!no){
			ans=min(ans,kh);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    int c = 0, f = 0;
    rep(i,s.size()){
        if (s[i] == 'C') c++;
        if (s[i] == 'F' && c >= 1) f++;
    }
    if (c > 0 && f > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    long long l[n],r[n];
    l[0]=a[0];
    for(int i=1;i<n;i++) l[i]=l[i-1]+a[i];
    r[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--) r[i]=r[i+1]+a[i];
    long long res=l[n-1];
    for(int i=0;i<n-1;i++) res=min(res,max(l[i]-r[i+1],r[i+1]-l[i]));
    cout << res << endl;
    return 0;
}


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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
const LL INT32 = (LL(MAXINT) + 1) * 2;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'

template<class T>
inline bool Read(T &ret) {
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF) return 0;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

template<class T>
inline void Write(T x) {
    if (x < 0) putchar('-'), Write(x);
    if (x > 9) Write(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    map<int, int> ans;
    for (int i = 1; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            {
                int dis = j - i;
                if (dis >= (abs(i - x) + abs(j - y)) + 1)
                    dis = abs(i - x) + abs(j - y) + 1;
                if (dis >= (abs(i - y)) + abs(j - x) + 1)
                    dis = abs(i - y) + abs(j - x) + 1;
                ans[dis]++;
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << ans[i] << END;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int X[3][3];
bool XX[3][3];
int main()
{
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin>>X[i][j];
  int N;
  cin>>N;
  while(N--)
  {
    int x;
    cin>>x;
    for(int i=0;i<3;i++)
    	for(int j=0;j<3;j++)
     	 if(X[i][j]==x)
           	XX[i][j]=true;
  }
  for(int i=0;i<3;i++)
    if(XX[i][0]&&XX[i][1]&&XX[i][2]||XX[0][i]&&XX[1][i]&&XX[2][i])
    {
      puts("Yes");
      return 0;
    }
  if(XX[0][0]&&XX[1][1]&&XX[2][2]||XX[0][2]&&XX[1][1]&&XX[2][0])
    puts("Yes");
  else	puts("No");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Data = pair<long long, vector<int> >;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
vector<ll> ans;
ll dp[0][0];


int main()
{
ll x,y,z,K;

cin >> x>>y>>z>>K;
ll tabx[x]={};
rep(i,x) {
    cin >> tabx[i];
}
ll taby[y]={};
rep(i,y) {
    cin >> taby[i];
}
ll tabz[z]={};
rep(i,z) {
    cin >> tabz[i];
}
sort(tabx, tabx + x, greater<ll>());
sort(taby, taby + y, greater<ll>());
sort(tabz, tabz + z, greater<ll>());

priority_queue<Data> que;
set<Data> se;
que.push(Data(tabx[0] + taby[0] + tabz[0], vector<int>({0, 0, 0})));
ll N[3]={x,y,z};
ll sum[3];

for (int k = 0; k < K; ++k) {
    auto c = que.top();que.pop();
    ans.push_back(c.first);
    sum[0]=c.first - tabx[c.second[0]] + tabx[c.second[0] + 1];
    sum[1]=c.first - taby[c.second[1]] + taby[c.second[1] + 1];
    sum[2]=c.first - tabz[c.second[2]] + tabz[c.second[2] + 1];

    // 次の三候補
    for (int iter = 0; iter < 3; ++iter) {
        if (c.second[iter] + 1 < N[iter]) {
            auto num = c.second; num[iter]++;
            auto d = Data(sum[iter], num);
            
            // すでに push されたもの以外
            if (!se.count(d)) se.insert(d), que.push(d);
        }
    }
}

rep(i,K){
cout << ans[i]<< endl;
}

return 0;
}





Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
  long long n, m, d;
  cin >> n >> m >> d;
  if(d == 0) printf("%.6lf\n", (double)(m - 1) / n);
  else printf("%.6lf\n", (double)(m - 1) * 2 * (n - d) / (n * n));
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#include<math.h>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 9 && b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << "-1" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

int main()
{
    double x1,x2,x3,x4,y1,y2,y3,y4,ansx,ansy;
    int q;
    scanf("%d",&q);
 
    for(int i=0;i<q;i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        ansx = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
        if(x1 != x2){
            ansy = ((y2-y1)*ansx+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
        }else{
            ansy = ((y4-y3)*ansx+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
        }
        printf("%.10lf %.10lf\n",ansx,ansy);
    }
}



Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] A = new int[n]; 
		for(int i=0;i<n;i++){
			A[i] = Integer.parseInt(sc.next()); 
		}
		
		int cnt = shellSort(A,n);
		System.out.println(cnt);
		
		for(int i=0;i<n;i++){
			System.out.println(A[i]);
		}

	}
	
	public static int insertionSort(int[] A, int n, int g){
		int cnt=0;
		for(int i=g;i<n;i++){
			int v = A[i];
			int j = i - g;
			while(j>=0 && A[j]>v){
				A[j+g]=A[j];
				j=j-g;
				cnt++;
			}
			A[j+g]=v;
		}
		return cnt;
	}
	
	public static int shellSort(int[] A, int n){
		int cnt = 0;
		int m = 0;
		int p=n;
		while(p>1){
			p/=2;
			m++;
		}
		if(m==0) m=1;
		int[] G=new int[m];
		System.out.println(m);
		p=n/2;
		for(int i=0;i<m;i++){
			G[i]=p;
			p/=2;
			System.out.print(G[i]);
			if(i != m-1){
				System.out.print(" ");
			}else{
				System.out.println();
			}
		}
		for(int i=0;i<m;i++){
			cnt += insertionSort(A,n,G[i]);
		}
		return cnt;
	}

}

Measured memory_bytes: 178088
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 2500;
typedef pair<int,int> P;
int main()
{
  int n,x,y,t=0,i,j,k=0,res=0;
  P pp=P(0,0);
  P xy[N_MAX],p[N_MAX];
  cin >> n;
  if(n==1){
    cout << "1" << endl;
    return 0;
  }
  for(i=0;i<n;i++)
    cin >> xy[i].first >> xy[i].second;
  for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++){
      p[k]=P(xy[i].first-xy[j].first,xy[i].second-xy[j].second);
      k++;
      p[k]=P(-p[k-1].first,-p[k-1].second);
      k++;
    }
  sort(p,p+k);
  for(i=0;i<k;i++)
    if(p[i]==pp){
      t++;
    }else{
      res=max(t,res);
      t=1;
      pp=p[i];
    }
  res=n-res;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  int n,x;
  cin >> n >> x;

  int ans = n;
  int s = x, t = n-x;
  while(1){
    ans += 2*(s/t)*t;
    int tmp = s % t;
    if(tmp == 0){
      ans -= t;
      break;
    }
    //debug(ans);
    s = t;
    t = tmp;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

ind = -1
for i in range(1, N+1):
    if A[i] == 1:
        ind = i

hoge = ind - 1

ans = 0
ans += hoge // (K-1)

fuga = hoge % (K-1)
if fuga > 0:
    ans += 1
    ind += (K-1) - fuga

ans += max(0, (N - ind) // (K-1) + (1 if (N-ind) % (K-1) else 0))
print(ans)


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  int S=0;
  for(int i=0; i<M; i++){
    cin >> A.at(i);
    S+=A.at(i);
  }
  cout << max(-1, N-S) << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	int ans = 2 * n;
	for (int i = 1; i <= n; i++) {
		if (s.substr(n - i, i) == t.substr(0, i))ans = 2 * n - i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
	int n, x, k;
	scanf("%d", &n);

	for(int i = 1; i <= n; i++){
		x = i;
		k = 0;
		if ((x % 3) == 0) printf(" %d", i);
		else {
			while (x){
				if((x % 10) == 3) k += 1;
				x /= 10;
			}
			if (k) printf(" %d", i);
		}
	}

	printf("\n");

	return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//container util
//------------------------------------------
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

typedef pair<int, int> Pii;
typedef struct{ int x, y; } Point;
const int INF = 1001001001;

string s;
bool c = false;
bool f = false;

int main(void)
{
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'C'){
            c = true;
        }
        else if(s[i] == 'F' && c == true){
            f = true;
        }
    }

    if(f){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
        
        
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max 2000000+20
int n;
void buildMaxHeap(int *A);
void my(int *A,int i);


int main(){
  int A[max];
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  
  buildMaxHeap(A); 
  
  for (i=1;i<=n;i++)
  printf(" %d",A[i]);
  
  printf("\n");
  return 0;
  
  
}

void buildMaxHeap(int *A){
  int i; 
  
  for(i=n/2;i>=1;i--)
  my(A,i);

}
void my(int *A,int i){
  int l,r;
  int largest;
  int tp;
  l=i*2; r=i*2+1;
  if(l<=n && A[l]>A[i]) largest = l;
  
  else largest = i;
  
  if(r<=n && A[r]>A[largest]) largest = r;
  
  if(largest!=i){
    tp=A[i];
    A[i]=A[largest];
    A[largest]=tp;
    my(A,largest);
  } 
}



Measured memory_bytes: 3660
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
from collections import defaultdict
from collections import deque
import heapq


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, s, t, w=1):
        self.E[s].append((t, w))
        # self.E[t].append((s, w))


def shortestPath(g: Graph, s: int):
    # 返り値 (dist, prev)
    # dist: 始点からの距離が格納されたリスト
    # prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト
    dist = defaultdict(lambda: INF)
    dist[s] = 0

    prev = defaultdict(lambda: None)
    Q = []
    heapq.heappush(Q, (dist[s], s))

    while len(Q) > 0:
        _, u = heapq.heappop(Q)
        for v, w in g.E[u]:
            if dist[v] > dist[u] + w:
                dist[v] = dist[u] + w
                prev[v] = u
                heapq.heappush(Q, (dist[v], v))
    return dist, prev


def solve(N: int, M: int, S: int,
          U: "List[int]", V: "List[int]",
          A: "List[int]", B: "List[int]",
          C: "List[int]", D: "List[int]"):

    # (頂点数, 所持している銀貨の枚数)ごとにノードを増やす
    # ノード数は 50*(N-1)*N 未満
    NN = 50*N*N
    g = Graph(NN)
    # U[i]-1, V[i]-1間ではなくて、
    # (U[i]-1, a), (V[i]-1, a-A[i])間に重みB[i]の有向リンクがある
    # (V[i]-1, a), (U[i]-1, a-A[i])間に重みB[i]の有向リンクがある
    for i in range(M):
        for j in range(50*N):
            if j - A[i] < 0:
                continue
            g.add_edge((U[i]-1, j), (V[i]-1, j-A[i]), B[i])
            g.add_edge((V[i]-1, j), (U[i]-1, j-A[i]), B[i])
        # print(U[i]-1, V[i]-1)
    # 都市iで補給する時のパス
    for i in range(N):
        for j in range(50*N):
            if j-C[i] >= 0:
                g.add_edge((i, j-C[i]), (i, j), D[i])

    if S >= (N-1)*50:
        S = (N-1)*50
    dist, prev = shortestPath(g, (0, S))
    # print(dist, prev)

    # nに至るパスで最短時間となるものを選ぶ
    for n in range(1, N):
        tot = INF
        for i in range(50*N):
            if (n, i) in dist:
                tot = min(tot, dist[n, i])
                # print((n, i), dist[n, i], prev[n, i])
        print(tot)
        # print(n, "done")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    U = [int()] * (M)  # type: "List[int]"
    V = [int()] * (M)  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        U[i] = int(next(tokens))
        V[i] = int(next(tokens))
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    C = [int()] * (N)  # type: "List[int]"
    D = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(N, M, S, U, V, A, B, C, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 182052
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#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(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll 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> 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;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	int mi=inf;
	rep(i,n){
		int a;cin>>a;
		mi=min(mi,a);
		m-=a;
	}
	cout<<n+m/mi<<endl;
}












Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    ans = 0
    L = []
    for _ in range(N):
        l = []
        D = input().split()
        for d in D:
            l.append(int(d))
        L.append(l)
    for n in range(N - 1):
        for i in range(N)[n + 1:]:
            s = 0
            for m in range(M):
                s += (L[n][m] - L[i][m]) ** 2
            r = 1
            while True:
                R = r * r
                if R == s:
                    ans += 1
                elif R > s:
                    break
                r += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> vec = { a,b,c };

	sort(vec.begin(), vec.end());
	//cout << vec[0] << endl;

	if (vec[0] + vec[1] == vec[2])
	{
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}

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

int main() {
    int n,count;
    cin>>n;
    vector<string> s(n);
    string ans="";
    rep(i,n) cin>>s[i];
    for (char c='a'; c<='z'; c++) {
        int mini=100;
        rep(i,n) {
            count=0;
            rep(j,s[i].size()) {
                if (c==s[i][j]) count++;
            }
            mini=min(count,mini);
        }
        rep(i,mini) {
            ans.push_back(c);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] elem = new int[n];
    for (int i = 0 ; i < n; i++) {
      elem[i] = Integer.parseInt(sc.next());
    }
    int q = Integer.parseInt(sc.next());
    int[] checks = new int[q];
    for (int i = 0 ; i < q; i++) {
      checks[i] = Integer.parseInt(sc.next());
    }

    for (int check : checks) {
      if (solve(elem, 0, check)) {
        System.out.println("yes");
      } else {
        System.out.println("no");
      }
    }
  }

  public static boolean solve(int[] elem, int i, int target) {

    if (target == 0) {
      return true;

    } else if (target < 0) {
      return false;

    } else if (i >= elem.length) {
      return false;

    } else {
      return solve(elem, i + 1, target - elem[i])
          || solve(elem, i + 1, target);
    }
  }
}



Measured memory_bytes: 26588
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        string s;
        cin >> s;
        REP(i,0,2){
                if(s[i] == '1'){
                        s[i] = '9';
                }else if(s[i] == '9'){
                        s[i] = '1';
                }
        }
        cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int n, R;
int max_v = -999999999;
int min_v;

int main()
{

	cin >> n;
	cin >> min_v;
	for (int i = 1; i < n; ++i)
	{
		cin >> R;
		int diff = R - min_v;
		if (max_v < diff) max_v = diff;
		if (min_v > R) min_v = R;
	}

	cout << max_v << endl;
	return 0;
}


Measured memory_bytes: 3100
import collections
N, C = map(int, input().split())
D = [tuple(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

table = [collections.defaultdict(int) for i in range(3)]

for i in range(N):
    for j in range(N):
        k = (i+j) % 3
        table[k][c[i][j] - 1] += 1


ans = 10**9
for i in range(C):
    tmp = 0
    for x in table[0]:
        tmp += D[x][i]*table[0][x]

    for j in range(C):
        if i == j:
            continue
        tmp2 = 0
        for x in table[1]:
            tmp2 += D[x][j]*table[1][x]
        for k in range(C):
            if i == k or j == k:
                continue
            tmp3 = 0
            for x in table[2]:
                tmp3 += D[x][k]*table[2][x]

            ans = min(ans, tmp+tmp2+tmp3)
print(ans)


Measured memory_bytes: 5996
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int32_t main(){
	int n;
	cin >> n;
	int x = 0;
	int a[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
		x ^= a[i];
	}
	for (int i =0 ; i < n; i++){
		cout << (x ^ a[i]) << ' ';
	}
}


Measured memory_bytes: 5180
N=int(input())
L=[[]]
for i in range(N):
    A=int(input())
    l=[]
    for j in range(A):
        x,y=map(int,input().split())
        l.append([x,y])
    L.append(l)
#print(L,N)
ans=0
for i in range(2**N):
    X=[0]
    I=i
    for j in range(N):
        X.append(I//(2**(N-1-j)))
        I%=(2**(N-1-j))
    #print(X)
    F=1
    for k in range(1,N+1):
        #print(X,k,N)
        if X[k]==1:
            for z in range(len(L[k])):
                a,b=L[k][z]
                #print(X,k,a,b)
                if X[a]!=b:
                    F=0
                    break
        
    if F==1:
        if ans<sum(X):
            ans=sum(X)
    #print(F,sum(X))
print(ans)
            
                    

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

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;


int32_t main(){

    string a , b ;cin >> a >> b;
    int n = a.length() , m = b.length() , ans = 1e9;
    for(int i = 0 ; i < n - m + 1; ++i){
        string x = a.substr(i,m);
        // cout << x << endl;
        int c = 0;
        for(int j = 0 ; j < m ; ++j) if(x[j]!=b[j]) c++;
        ans = min(ans,c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
g = [[0 for i in range(250)] for j in range(250)]


k = int(input())
r = range(1, k + 1)

import math
ans = 0

for a in r:
    for b in r:
        for c in r:

            if g[a][b] > 0:
                ab = g[a][b]
            else:
                ab = g[a][b] = math.gcd(a, b)
            if g[ab][c] > 0:
                ab = g[ab][c]
            else:
                ab = g[ab][c] = math.gcd(ab, c)
            ans += ab

print(ans)


Measured memory_bytes: 68568
import sys
import math

def solve():
    vs = [float(s) for s in sys.stdin]
    
    for v0 in vs:
        N, v = 1, 0.0
        
        while True:
            y = 5 * N - 5
            v = math.sqrt(2 * 9.8 * y)
            if v > v0:
                print(N)
                break
            else:
                N += 1

if __name__ == "__main__":
    solve()


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


class UnionFind{
private:
    vec<int> p,s;
    int cnt;
public:
    UnionFind(){}
    UnionFind(int N):cnt(N),s(N,1),p(N){
        iota(p.begin(),p.end(),0);
    }
    int find(int x){
        if(p[x]==x) return x;
        else return p[x] = find(p[x]);
    }
    void unite(int x,int y){
        x = find(x); y = find(y);
        if(x==y) return;
        if(s[x]>s[y]) swap(x,y);
        p[x] = y;
        s[y] += s[x];
        cnt--;
    }
    bool is_same_set(int x,int y) {return find(x)==find(y);}
    int size(int x) {return s[find(x)];}
    int compnents_number(){return cnt;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    UnionFind uf(N);
    while(Q--){
        int t,a,b;
        cin >> t >> a >> b;
        if(t==0) uf.unite(a,b);
        else cout << (uf.is_same_set(a,b)? 1:0) << "\n";
    }
}

Measured memory_bytes: 4436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

string s;

int main(){
	cin >> s;
	string ans = "";
	REP(i, s.size()){
		if (s[i] == 'S')ans += s[i];
		else{
			if (ans.empty() || ans[ans.size() - 1] == 'T'){
				ans += s[i];
			}
			else ans.pop_back();
		}
	}
	cout << ans.size() << endl;
}

Measured memory_bytes: 776
/**
 *    author:  tourist
 *    created: 29.09.2018 15:33:19       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> d(n);
  vector<int> weight(n, 1);
  map<long long,int> mp;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    mp[d[i]] = i;
  }
  vector<pair<int,int>> res;
  for (int itt = 0; itt < n - 1; itt++) {
    auto it = mp.rbegin();
    int i = it->second;
    long long want = d[i] - (n - weight[i]) + weight[i];
    if (mp.find(want) == mp.end() || mp[want] == i) {
      cout << -1 << '\n';
      return 0;
    }
    int j = mp[want];
    res.emplace_back(i, j);
    weight[j] += weight[i];
    mp.erase(--mp.end());
  }
  vector<long long> real_dist(n, -1);
  real_dist[0] = 0;
  vector<vector<int>> g(n);
  for (auto &p : res) {
    g[p.first].push_back(p.second);
    g[p.second].push_back(p.first);
  }
  vector<int> que(1, 0);
  for (int b = 0; b < (int) que.size(); b++) {
    for (int j : g[que[b]]) {
      if (real_dist[j] == -1) {
        que.push_back(j);
        real_dist[j] = real_dist[que[b]] + 1;
      }
    }
  }
  if (accumulate(real_dist.begin(), real_dist.end(), 0LL) != d[0]) {
    cout << -1 << '\n';
    return 0;
  }
  for (auto &p : res) {
    cout << p.first + 1 << " " << p.second + 1 << '\n';
  }
  return 0;
}


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

int step;

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

int main() {
  int a, b;

  while( cin >> a >> b, a+b ) {
    step = 0;
    if( a < b ) swap( a, b );
    cout << gcd( a, b );
    cout << " " << step << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
 
class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){
    roll(1,2,4,3);
  }
  void roll_y(){
    roll(0,2,5,3);
  }
  void roll_x(){
    roll(0,1,5,4);
  } 
  void roll(int i, int j, int k, int l){
    int t=f[i];
    f[i]=f[j];
    f[j]=f[k];
    f[k]=f[l];
    f[l]=t;
  }
};
 
int getRight(Cube c1, int f1, int f2){
  for(int i=0;i<6;i++){
    for(int j=0;j<4;j++){
      if(c1.f[0]==f1 && c1.f[1]==f2) return c1.f[2];
      c1.roll_z();
    }
    if(i%2==0) c1.roll_y();
    else c1.roll_x();
  }
  return -1;
}
 
int main(){
  Cube c;
  int f1,f2;
 
  for(int i=0;i<6;i++)cin >> c.f[i];
  int q;
  cin >> q;
 
  for(int i=0;i<q;i++){
    cin >> f1 >>f2;
    cout << getRight(c,f1,f2) << endl;
  }
}

Measured memory_bytes: 3092
sticks_canJoinNum = input()
str_stickLength = input()

sticks_num = int(sticks_canJoinNum.split()[0])
num_canJoin = int(sticks_canJoinNum.split()[1])
stick_list = [int(i) for i in str_stickLength.split()]

stick_list.sort(reverse=True)
max_length = sum(stick_list[:num_canJoin])
print(max_length)

Measured memory_bytes: 3060
#include <stdio.h>
#define SIZE 1002

int main(void){
    int n, k, p1[SIZE], count[SIZE] = {0}, p2[SIZE], i, max = 0, min = 0;
    scanf("%d %d", &n, &k);
    for(i = 1; i <= n; i++){
        scanf("%d", &p1[i]);
        count[p1[i]]++;
        if(max < p1[i])max = p1[i];
    }
    for(i = 1; i <= max; i++)
        count[i] += count[i-1];
    for(i = n; i >= 1; i--){
        p2[count[p1[i]]] = p1[i];
        count[p1[i]]--;
    }
    for(i = 1; i <= k; i++)
        min += p2[i];
    printf("%d", min);
    return 0;
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

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

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

/////////////////////////////////////////////////////////

void Main() {
  ll N; cin >> N;
  vector<ll> A(N), B(N);
  rep(i, 0, N) cin >> A[i] >> B[i];
  ll res = 0;
  for(int i = N - 1; i >= 0; i--){
    A[i] += res;
    if(A[i] % B[i] != 0){
      res += B[i] - A[i] % B[i];
      A[i] += B[i] - A[i] % B[i];
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

d = {}

for i in range(N - 1):
    if A[i] in d:
        d[A[i]].append(i + 2)
    else:
        d[A[i]] = [i + 2]

for i in range(1, N + 1):
    if i in d:
        print(len(d[i]))
    else:
        print(0)

Measured memory_bytes: 52492
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        long c = in.nextInt();
        long d = in.nextInt();

        long diff = b - a;
        for (int i = 0; i < n - 1; i++) {
            long min = c * (n - 1 - i) - d * i;
            long max = - c * i + (n - 1 - i) * d;
            if (min <= diff && diff <= max) {
                out.println("YES");
                return;
            }
        }

        out.println("NO");
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int n,m,deg[100005];
set < int > adjs[100005];
vector < int > adj[100005];
vector < int > us,vs;
bool vis[100005];
void dfs(int v){
	vis[v]=1;
	int i;
	for(i=0;i<(int)adj[v].size();++i){
		int u=adj[v][i];
		if(!vis[u]){
			dfs(u);
		}
	}
	if(deg[v]&1){
		++deg[v];
		int st=*(adjs[v].begin());
		adjs[v].erase(adjs[v].begin());
		adjs[st].erase(adjs[st].find(v));
		us.push_back(v);
		vs.push_back(st);
	}
	while(adjs[v].size()>1){
		int ux=*(adjs[v].begin()),vx=*(adjs[v].rbegin());
		adjs[v].erase(adjs[v].begin());
		adjs[v].erase(adjs[v].find(vx));
		adjs[vx].erase(adjs[vx].find(v));
		adjs[ux].erase(adjs[ux].find(v));
		us.push_back(v);
		us.push_back(v);
		vs.push_back(ux);
		vs.push_back(vx);
	}
	if(!adjs[v].empty()){
		int fn=*(adjs[v].begin());
		adjs[v].clear();
		adjs[fn].erase(adjs[fn].find(v));
		++deg[fn];
		us.push_back(fn);
		vs.push_back(v);
	}
}
int main(){
	int i,j,k;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		--u;--v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		adjs[u].insert(v);
		adjs[v].insert(u);
	}
	if(m&1){
		printf("-1\n");
		return 0;
	}
	dfs(0);
	for(i=0;i<m;++i){
		printf("%d %d\n",us[i]+1,vs[i]+1);
	}
	return 0;
}

Measured memory_bytes: 28576
#include<iostream>
using namespace std;
int M[101][101];

int main(){
  int n,u,k,v;
  cin>>n;

  for(int i=1;i<=n;i++){
    cin>>u>>k;
    for(int j=1;j<=k;j++){
      cin>>v;
      M[u][v]=1;
    }
  }

  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j-1) cout<<" ";
      cout<<M[i][j];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3128
n = int(input())
p = [int(x) for x in input().split()]

ans = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1]:
        ans += 1
    elif p[i-1] > p[i] > p[i+1]:
        ans += 1
    else:
        pass
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

void solve(int idx, vector< vector< tuple< int, ul > > > & path, vector< int > & color) {
  for (auto c : path[idx]) {
    int ci=get<0>(c);
    ul cw = get<1>(c);
    if (color[ci] != -1) continue;
    if (cw%2==0) color[ci] = color[idx];
    else color[ci] = 1-color[idx];
    solve(ci, path, color);
  }
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< vector< tuple< int, ul > > > path(n, vector< tuple< int, ul > >(0));
  for (int i=0; i<n-1; ++i) {
    int u, v;
    ul w;
    cin >> u >> v >> w;
    u--; v--;
    path[u].push_back(make_tuple(v, w));
    path[v].push_back(make_tuple(u, w));
  }
  vector< int > c(n, -1);
  c[0] = 0;
  solve(0, path, c);
  for (int i=0; i<n; ++i) cout << c[i] << endl;
  return 0;
}


Measured memory_bytes: 10496