akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main() {
    while(true) {
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0 ) break;
        int a[1005];
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int ans = -1;
        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                //cerr << i << " " << j << endl;
                if(a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]);
            }
        }
        if(ans == -1) cout << "NONE" << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>
#include <math.h>
int main(void){
    int n,ans=0;
    scanf("%d",&n);
    double a[n],ave=0;
    for (int i=0; i<n; i++){
        scanf("%lf",&a[i]);
        ave+=a[i];
    }
    ave/=n;
    for (int i=0; i<n; i++){
        if (fabs(a[ans]-ave)>fabs(a[i]-ave)){
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

const int MOD=1000000007;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

int dp[200000];
int main(){
	int n,m;cin>>n>>m;
	dp[0]=1;
	int sum=1;
	for(int i=1;i<=n;i++){
		dp[i]=sum;
		(sum+=dp[i])%=MOD;
		if(i-m>=0){
			(sum+=MOD-dp[i-m])%=MOD;
		}
	}
	ll U=ppow(2,n);
	cout<<(U+MOD-sum)%MOD<<endl;
}


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

#define int long long 

signed main()
{
  int N,K;
  cin >> N >> K;
  int W[100000];
  Rep(i,N)cin >> W[i];
  int left = 0;
  int right = 100000 * 10000;
  while(right - left > 1){
    int P = (left + right) / 2;
    int i = 0;
    Rep(j,K){
      int sum = 0;
      while(i < N && sum + W[i] <= P){
	sum += W[i];
	i++;
      }
      if(i == N)break;
    }
    if(i == N)right = P;
    else left = P;
  }
  cout << right << endl;
  return 0;
}

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

using namespace std;

#define endl '\n'

typedef long long ll;
typedef long double lb;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y, int x, int H, int W)
{ 
  return (y >= 0 && x >= 0 && y < H && x < W);
}

inline int in() {int x; cin >> x; return x;}



const ll mod = 1e9 + 7;
const ll inf = 1e9 + 9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

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

  int n[10];
  int k;

  while (~scanf("%1d", &n[0])){
    for (int i = 1; i < 10; i++){
      scanf("%1d", &n[i]);
    }

    k = 9;
    for (int i = 0; i < 10; i++){
      for (int j = 0; j < k; j++){
        n[j] = (n[j] + n[j + 1]) % 10;
      }
      k--;
    }
    cout << n[0] << endl;
  }
  return (0);
}

Measured memory_bytes: 3272
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N, i;
    cin >> N >> i;
    cout << (N - i + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m;
    while(cin>>n>>m,n,m){
    	bool num[100000]={};
    	int co=0;
    	for(int i=0,x;i<m;i++){
    		cin>>x;
    		if(x==0)co++;
    		else num[x]=1;
    	}
    	int ans=0;
    	for(int i=1;i<=n;i++){
    		if(num[i]){
    			for(int j=i+1,now=1,fin=co;;j++,now++){
    				if(!num[j]&&fin>0)fin--;
    				else if(!num[j]){
    					ans=max(ans,now);
    					break;
    				}
    			}
    		}
    	}
    	cout<<ans<<endl;
    }
}

Measured memory_bytes: 1264
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main(){
    ll n,m;
    cin >> n >> m;
    cout << (100*(n-m)+1900*m)*(1<<m) << endl;
}


Measured memory_bytes: 3500
#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 <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }



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

	int n;
	cin >> n;
	map<string, int> mp;
	ll res = 0;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		sort(all(s));
		mp[s]++;
		res += mp[s] - 1;
	}
	cout << res;
}

Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		long[] a = new long[1005];
		for (int i = 0; i < 1005; i++) {
			a[i] = i;
		}
		for (int i = 0; i < 1004; i++) {
			a[i + 1] += a[i];
		}
		
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int ans = 0;
			for (int i = 0; i <= n; i++) {
				for (int j = i + 2; j <= n; j++) {
					if (a[j] - a[i] == n) {
						ans++;
					}
				}
			}
			
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 19636
#include<stdio.h>
int main(){
  int x,y,ans,i,j,temp;
  scanf("%d %d",&x,&y);
  if(x<y){
    while(x!=0){
      temp=x;
      x=y%x;
      y=temp;
    }
    printf("%d\n",y);
  }
  else{
    while(y!=0){
      temp=y;
      y=x%y;
      x=temp;
    }
    printf("%d\n",x);
  }
  return(0);
}

Measured memory_bytes: 592
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
#define N 100009
#define ll long long

int main(){
    int a,b;
    cin>>a>>b;
    if (a>b){
        for (int i=0; i<a; i++) cout<<b;
    }
    else{
        for (int i=0; i<b; i++) cout<<a;
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
vector<pair<int,int>> graph[100010];
int memo[100010];
void solve(int idx, int color) {
    rep(i,graph[idx].size()) {
        pair<int, int> g = graph[idx][i];
        if (memo[g.first] != -1)continue;
        if (g.second % 2 == 0) {
            memo[g.first] = color;
            solve(g.first, color);
        }
        else {
            memo[g.first] = 1-color;
            solve(g.first, 1-color);
        }
    }
}
int main() {
    memset(memo,-1,sizeof(memo));
    int N;
    cin >> N;
    rep(i,N-1){
        int u,v,w;
        cin >> u >> v >> w;
        --u; --v;
        graph[u].pb(mk(v,w));
        graph[v].pb(mk(u,w));
    }
    memo[0] = 0;
    solve(0, 0);
    rep(i,N){
        printf("%d\n",memo[i]);
    }
   return 0;  
}

Measured memory_bytes: 8448
program redistribution
  implicit none
  integer(8), parameter :: modu = 1000000007
  integer :: s
  integer(8) :: m(3, 3) = 0
  read(*,*) s
  if (s < 6) then
    write(*,'(i0)') s / 3
    stop
  end if
  m(1, 1) = 1
  m(2, 1) = 1
  m(3, 2) = 1
  m(1, 3) = 1
  m = modmatpow(m, s - 6)
  write(*,'(i0)') mod(m(1, 1) * 2 + m(1, 2) + m(1, 3), modu)
contains
  function modmatmul(x, y) result(res)
    integer(8), parameter :: modu = 1000000007
    integer(8), intent(in) :: x(3, 3), y(3, 3)
    integer(8) :: tmp, res(3, 3)
    integer :: i, j, k
    do j = 1, 3
      do i = 1, 3
        res(i, j) = 0
      end do
      do k = 1, 3
        tmp = y(k, j)
        do i = 1, 3
          res(i, j) = mod(res(i, j) + x(i, k) * tmp, modu)
        end do
      end do
    end do
  end
  function modmatpow(x, n) result(res)
    integer(8), intent(in) :: x(3, 3)
    integer, intent(in) :: n
    integer(8) :: res(3, 3), tmp(3, 3)
    integer :: m
    res(1, 1) = 1
    res(2, 1) = 0
    res(3, 1) = 0
    res(1, 2) = 0
    res(2, 2) = 1
    res(3, 2) = 0
    res(1, 3) = 0
    res(2, 3) = 0
    res(3, 3) = 1
    tmp = x
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = modmatmul(res, tmp)
      tmp = modmatmul(tmp, tmp)
      m = rshift(m, 1)
    end do
  end
end program redistribution

Measured memory_bytes: 2900
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
  l,r,d = map(int,input().split())
  g[l-1].append([r-1,d])
  g[r-1].append([l-1,-d])
syo = [-1] * n
que = []
for i in range(n):
  if syo[i] != -1:
    continue
  syo[i] = 0
  que.append(i)
  while que:
    x = que.pop()
    for j,jb in g[x]:
      if (syo[j] != syo[x]+jb and syo[j] != -1):
        print("No")
        exit()
      syo[j] = syo[x] + jb
      que.append(j)
    g[x] = []
print("Yes")

Measured memory_bytes: 76576
n=10**5
p=[0,0]+[1]*~-n
for i in range(2,int(n**0.5)+1):
  if not p[i]:continue
  for j in range(i*2,n+1,i):p[j]=0
c=[0]
for i in range(1,n+1):
  c.append(c[-1]+(i%2and p[i]and p[-~i//2]))
for _ in range(int(input())):
  l,r=map(int,input().split())
  print(c[r]-c[l-1])

Measured memory_bytes: 54092
// Last Change: 03/07/2019 19:38:17.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int N, A, B, C;
vector<int> l;
const int INF = 1000000000;

//各a,b,cはA,B,Cの素材。
// pos番目の素材をA,B,Cいずれかの素材にするかしないか。
int dfs(int pos, int a, int b, int c) {
  int ans = INF;
  if (pos == N) {
    if (a > 0 and b > 0 and c > 0) {
      //各素材a,b,cから延長、縮小のみでA,B,Cを作るときのコスト
      ans = abs(a - A) + abs(b - B) + abs(c - C) - 30;
      return ans;
    } else {
      return INF;
    }
  }
  int next = pos + 1;
  int tmp = dfs(next, a, b, c);
  ans = min(ans, tmp);
  tmp = dfs(next, a + l[pos], b, c) + 10;
  ans = min(ans, tmp);
  tmp = dfs(next, a, b + l[pos], c) + 10;
  ans = min(ans, tmp);
  tmp = dfs(next, a, b, c + l[pos]) + 10;
  ans = min(ans, tmp);
  return ans;
}

int main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> l[i];
  }

  int ans = dfs(0, 0, 0, 0);
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
ll dp[100005][13];
ll mod=1e9+7;

int main(){
   string s;cin>>s;
   int n=s.length();
   dp[0][0]=1;
   for(int i=0;i<n;i++){
       int c=s[i]-'0';
       if(s[i]=='?')c=-1;
       for(int j=0;j<10;j++){
           if(c==-1||c==j){
               for(int k=0;k<13;k++){
                   dp[i+1][(10*k+j)%13]+=dp[i][k];
                 
               }
               
           }
           else continue;
       }
       for(int j=0;j<13;j++)dp[i+1][j]%=mod;
   }
   cout<<dp[n][5];
}


Measured memory_bytes: 10624
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
65
)");
#define cin input
#endif

int main()
{
	int l;
	cin >> l;

	int c = 0;
	int r = 0;
	for (auto i = l; i; i >>= 1)
	{
		++c;
		if (i & 1)
			++r;
	}

	cout << c << ' ' << ((c - 1) * 2 + r - 1) << endl;
	int x = 1;
	int a = 0;
	for (auto i = l; i > 1; i >>= 1)
	{
		++a;
		cout << c - 1 << ' ' << c << ' ' << 0 << endl;
		cout << c - 1 << ' ' << c << ' ' << x << endl;
		if (i & 1)
			cout << 1 << ' ' << c << ' ' << ((i >> 1) << a) << endl;
		x <<= 1;
		--c;
	}

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 2003;

class comb{
	vector<ll> f,fr;
	ll MOD;
	public:
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){//input max_n
		MOD = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
			fr[i] = calc(f[i],mod-2,mod);
		}
	}
	ll nCr(ll n,ll r){
		return f[n] * fr[r] % MOD * fr[n-r] % MOD;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	comb co;
	vector<ll> a,c,h,b;
	string s;
	ll ans = 0;
	cin>>s;
	ll ss = s.size();
	a.resize(ss);
	b.resize(ss);
	c.resize(ss);
	h.resize(ss);
	if(s[0]=='A')a[0]=1;
	else a[0]=0;
	if(s[0]=='C')c[0]=1;
	else c[0]=0;
	if(s[0]=='?')h[0]=1;
	else h[0]=0;
	if(s[0]=='B')b[0]=1;
	else b[0]=0;
	FOR(i,1,ss){
		a[i]=a[i-1];c[i]=c[i-1];h[i]=h[i-1];b[i]=b[i-1];
		if(s[i]=='A')a[i]++;
		if(s[i]=='B')b[i]++;
		if(s[i]=='C')c[i]++;
		if(s[i]=='?')h[i]++;
	}
	FOR(i,1,ss-1){
		if(s[i]=='B'||s[i]=='?'){
			//ans += (a[i]+h[i])*(c[ss-1]-c[i]+h[ss-1]-h[i]) % MOD * co.calc(3,h[ss-1]-2,MOD) % MOD;
			ans += (a[i])*(c[ss-1]-c[i])%MOD*co.calc(3,h[ss-1]-TO(s[i]=='?',1,0),MOD) % MOD;
			ans %= MOD;
			ans += (h[i-1])*(c[ss-1]-c[i])%MOD*co.calc(3,h[ss-1]-1-TO(s[i]=='?',1,0),MOD) % MOD;
			ans %= MOD;
			ans += (a[i])*(h[ss-1]-h[i])%MOD*co.calc(3,h[ss-1]-1-TO(s[i]=='?',1,0),MOD) % MOD;
			ans %= MOD;
			ans += (h[i-1])*(h[ss-1]-h[i])%MOD*co.calc(3,h[ss-1]-2-TO(s[i]=='?',1,0),MOD) % MOD;
			ans %= MOD;	
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
string N,c="h";
int main(){
    cin>>N;
    if(N.back()=='3')c="b";
    if(N.back()=='0'||N.back()=='1'||N.back()=='6'||N.back()=='8')c="p";
    cout<<c+"on"<<endl;
    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair

void solve(){

   int x,y;
   cin >> x >> y;
   if(y >= 2*x and y <= 4*x and y%2 == 0){
    cout << "Yes" << endl; 
   }else{
    cout << "No" << endl;
   }

    
}


int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);

    ll T;
    T = 1;
    //cin >> T;
    while(T--){
        solve();
    }

   
    

}


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


int main() {
	long int C[1000], S[1000], F[1005];
	int N;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		cin >> C[i] >> S[i] >> F[i];
	}

	for (int i = 0; i < N - 1; i++) {

		long long int Y = 0;
		Y += S[i];
		Y += C[i];
		for (int k = i + 1; k < N - 1; k++) {

			if ((Y%F[k]) == 0) {
			
				if (Y >= S[k]) {
				exit:;
					Y += C[k];

				}
				else {
					Y = S[k];
					goto exit;
				}
			}
			else {

				Y += (F[k]-Y%F[k]);
				k--;
			}

		}
		cout << Y << endl;


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




Measured memory_bytes: 256
//include
//------------------------------------------
#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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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 main(void){
    int N,T; cin >> N >> T;
    int t[N]; REP(i,N) cin >> t[i];
    ll ans = T;
    REP(i,N-1) ans += min(t[i+1]-t[i], T);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cassert>

using namespace std;

const double EPS = 1e-8;

int dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    else {
        return d < 0? -1 : 1;
    }
}

struct Vector {
    double x, y;
    Vector(double x = 0, double y = 0): x(x), y(y){
    }
    
    bool operator<(const Vector& other) const {
        return dcmp(x - other.x) < 0 || (dcmp(x - other.x) == 0 && dcmp(y - other.y) < 0);
    }
};

typedef Vector Point;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x; 
}

Vector operator+(const Vector& a, const Vector& b) {
    return Vector(a.x + b.x, a.y + b.y);
}

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

Vector operator*(const Vector& a, const double& p) {
    return Vector(a.x * p, a.y * p);
}

double angle(const Vector& a) {
    return atan2(a.y, a.x);
}

double length(const Vector& a) {
    return sqrt(dot(a, a));
}

struct Circle {
    Point c;
    double r;
    Circle(double x = 0, double y = 0,  double r = 0): c(Point(x, y)), r(r){}
    
    Point point(double rad) const {
        return Point(c.x + r * cos(rad), c.y + r * sin(rad));
    }
};


vector<Point> circleCross(const Circle& a, const Circle& b) {
    
    Vector v = b.c - a.c;
    
    double d = length(v);
    
    assert(d <= a.r + b.r);
    
    //b.r * b.r = d * d + a.r * a.r - 2 * d * a.r*cos(alpha);
    double x = acos((d * d + a.r * a.r - b.r * b.r)/(2 * d * a.r));
    
    double rad = angle(v);
    
    Point p1 = a.point(rad + x);
    Point p2 = a.point(rad - x);
    
    vector<Point> results{p1, p2};
    
    sort(results.begin(), results.end());
    
    return results;
}

int main() {
    double x, y, r;
    cin >> x >> y >> r;
    Circle c1(x, y, r);
    
    cin >> x >> y >> r;
    Circle c2(x, y, r);
    
    vector<Point> ans = circleCross(c1, c2);
    
    cout << fixed << setprecision(8);
    
    cout << ans[0].x << "  " << ans[0].y << " " << ans[1].x << "  " << ans[1].y << endl;
    
    return 0;
    
}

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

using namespace std;

bool solve(){
    int n, m;
    cin >> n >> m;
    if(!n)
        return false;
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }
    vector<int> col(n, -1);
    function<bool(int, int)> f = [&](int pos, int co){
        for(auto& x : edges[pos]){
            if(col[x] == -1){
                col[x] = co ^ 1;
                if(!f(x, col[x]))
                    return false;
            }else if(col[x] == co)
                return false;
        }
        return true;
    };
    col[0] = 0;
    if(!f(0, 0)){
        cout << 0 << endl;
        return true;
    }
    assert(count(col.begin(), col.end(), -1) == 0);
    int c0 = count(col.begin(), col.end(), 0);
    int c1 = count(col.begin(), col.end(), 1);
    set<int> s;
    if(c0 % 2 == 0)
        s.emplace(c0 / 2);
    if(c1 % 2 == 0)
        s.emplace(c1 / 2);
    cout << s.size() << endl;
    for(auto& x : s)
        cout << x << endl;
    
    return true;
}

int main(){
    
    while(solve());
    
    return 0;
}


Measured memory_bytes: 3220
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (n, k) = InputLine.to_ia

  cs = [0] * n
  k.times do |i|
    d = InputLine.to_i

    a = InputLine.to_ia
    a.each{|x| cs[x - 1] += 1}
  end

  puts cs.count(0).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14416
#include <iostream>
#include <climits>
#include <queue>

static const int N=100;

int n,M[N][N];
int d[N];

using namespace std;
void bfs(int s)
{
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++) d[i]=INT_MAX;
    d[s]=0;
    int u;
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        for(int v=0;v<n;v++)
        {
            if(M[u][v]==0) continue;
            if(d[v]!=INT_MAX) continue;
            d[v]=d[u]+1;
            q.push(v);
         }
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<" "<<((d[i]==INT_MAX)?(-1):d[i])<<endl;
    }
}

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

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



Measured memory_bytes: 3116
#include<stdio.h>
#include<math.h>
int main()
{
	double x,h;
	while(1){
		scanf("%lf%lf",&x,&h);
		if(x==0&&h==0){
			break;
		}
		printf("%5lf\n",x*x+(sqrt(h*h+(x/2)*(x/2))*x/2*4));
	}
	return 0;
}

Measured memory_bytes: 648
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  N = int(input())
  for h in range(1,3501):
    for n in range(1, 3501):
      d = 4*h*n - N * (h+n)
      if d <= 0:
        continue
      w = (N*h*n) / d
      if w.is_integer():
        print(h, n, int(w))
        return

if __name__=='__main__':
  main()



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	cin>>n>>m;
	long long a[n];
	long long total=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		total = total+a[i];
	}
	long long count=0;
	long long y = total/(4*m);
	for(int i=0;i<n;i++)
	{
		if((a[i]*4*m)<total)
		{
			continue;
		}
		else{
			count++;
		}
	}
	if(count>=m)
	{
		cout<<"Yes"<<"\n";
	}
	else{
		cout<<"No"<<"\n";
	}
}

Measured memory_bytes: 3632
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solution task = new Solution(in, out);
        task.solve();
        out.close();
	}

	static class Solution {
		
		private InputReader in;
		private PrintWriter out;

		public Solution(InputReader in, PrintWriter out) {
			this.in = in;
			this.out = out;
		}

		public void solve() {
            HashMap<Integer, Integer> p = new HashMap<Integer, Integer>();
            int N = in.nextInt();
            for (; N > 0; N--) {
                int d = in.nextInt();
                if (p.containsKey(d))
                    p.put(d, p.get(d) + 1);
                else
                    p.put(d, 1);
            }
            int M = in.nextInt();
            for (; M > 0; M--) {
                int d = in.nextInt();
                if (!p.containsKey(d) || p.get(d) == 0) {
                    out.println("NO");
                    return;
                }
                p.put(d, p.get(d) - 1);
            }
            out.println("YES");
		}
	}

	static class InputReader {
        
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
	
}


Measured memory_bytes: 77120
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}
//cout << fixed << setprecision(10);

int main()
{
  ll n,m;
  cin>>n>>m;
  vector<bool>a(n+1,true);
  rep(i,m)
  {
    ll tmp; cin>>tmp;
    a[tmp]=false;
  }
  vector<ll>dp(n+1);
  dp[0]=1;
  for(ll now=0;now<n;now++)
  {
    for(ll next=now+1;next<=min(n,now+2);next++)
    {
      if(a[next])
      {
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }
  cout<<dp[n]<<endl;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

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

int main() {
  int N;
  cin>>N;
  vector<string> s(N);
  for(int i = 0; i < N; i++) cin>>s[i];
  int ans = 0;
  for(int i = 0; i < N; i++){
    bool can = true;
    for(int j = 0; j < N; j++){
      for(int k = 0; k < N; k++){
        if(s[j][k]!=s[(k+N-i)%N][(j+i)%N]){
          can=false;
          break;
        }
      }
      if(!can) break;
    }
    if(can) ans++;
  }
  cout<<ans*N<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const long INF=1000000000000;

//関数



int main() {
    
    
    //入力
    long N;
    cin>>N;
    vector<long> T(N);
    for(int i=0;i<N;i++){
        cin>>T.at(i);
    }
    
    //計算
    long ans=1;
    for(int i=0;i<N;i++){
        ans*=(T.at(i)/__gcd(ans,T.at(i)));
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    char a,b;
    std::cin >> a >> b;
    if((a=='H' && b=='H') || (a=='D' && b=='D')){
        printf("H\n");
    }
    else if((a=='H' && b=='D') || (a=='D' && b=='H')){
        printf("D\n");
    }
    else{
        return -1;
    }
    return 0;
}

Measured memory_bytes: 256
# 解説放送
# tee, isliceをやめた

def main():
    k, q = map(int, input().split())
    *d, = map(int, input().split())
    for _ in range(q):
        n, x, m = map(int, input().split())
        *g, = map(lambda x: x % m, d)
        rep, rest = divmod(n - 1, k)
        last = x + (sum(g) * rep) + sum(g[:rest])
        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0)
        ans = (n - 1) - eq - (last // m - x // m)
        print(ans)


if __name__ == '__main__':
    main()


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

const int INF = INT_MAX;
const int MAX = 200010;

int ls[MAX], rs[MAX];

long long merge(vector<int> &as, int left, int mid, int right)
{
  int l_size = mid-left;
  int r_size = right-mid;

  copy(as.begin()+left, as.begin()+left+l_size, ls);
  copy(as.begin()+mid, as.begin()+mid+r_size, rs);
  ls[l_size] = INF;
  rs[r_size] = INF;

  long long ans = 0;
  for (int i = left, li = 0, ri = 0; i < right; i++) {
    if (ls[li] <= rs[ri]) {
      as[i] = ls[li++];
      ans += ri;
    } else {
      as[i] = rs[ri++];
    }
  }
  return ans;
}

long long merge_sort(vector<int> &as, int left, int right)
{
  if (left+1 == right) return 0; 
  long long ans = 0;
  int mid = left+(right-left)/2;
  ans += merge_sort(as, left, mid);
  ans += merge_sort(as, mid, right);
  ans += merge(as, left, mid, right);
  return ans;
}

int main()
{
  int n; cin >> n;
  vector<int> arr = vector<int>(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  cout << merge_sort(arr, 0, n) << endl;
  return EXIT_SUCCESS;
}




Measured memory_bytes: 4464
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

struct node {
	vector<int> children;
};

void solve(int nodeNum, int num, node* nodes, ll k, ll &ans) {
	ll t = 2;
	if (nodeNum == 0) t = 1;

	int counter = 0;
	rep(i, nodes[nodeNum].children.size()) {
		if (nodes[nodeNum].children[i] != num) {
			ans *= k - t - counter;
			ans %= _MOD;

			solve(nodes[nodeNum].children[i], nodeNum, nodes, k, ans);

			++counter;
		}
	}
}

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

	int n;
	ll k;
	cin >> n >> k;
	node* nodes = new node[n];
	int a, b;
	rep(i, n - 1) {
		cin >> a >> b;
		nodes[a - 1].children.push_back(b - 1);
		nodes[b - 1].children.push_back(a - 1);
	}

	ll ans = k;
	solve(0, -1, nodes, k, ans);

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 12800
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  ll d = abs(a - b), vv = v - w;
  cout << (vv * t >= d ? "YES" : "NO") << '\n';

  




  
  return 0;
}

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

void insertionSort(int A[], int N){
  for ( int i = 1; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
}

int main(void){

  int A[3];

  for ( int i = 0; i < 3; i++){
    cin >> A[i];
  }

  insertionSort(A, 3);

  int cost = 0;
  for ( int i = 1; i < 3; i++) {
    cost += abs(A[i-1] - A[i]);
  }

  cout << cost;

  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_z
#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';

template <const int MAXN, class T, class Comparator = less<T>> struct ConvexHullTrick {
    Comparator cmp; T M[MAXN], B[MAXN]; int front = 0, back = 0;
    void addLine(T m, T b) { // in non decreasing order of slope, as sorted by the comparator
        while (back >= 2 && (B[back - 2] - B[back - 1]) * (m - M[back - 1]) >= (B[back - 1] - b) * (M[back - 1] - M[back - 2])) back--;
        while (back >= 1 && !cmp(m, M[back - 1]) && !cmp(M[back - 1], m) && !cmp(b, B[back - 1])) back--;
        M[back] = m; B[back++] = b;
    }
    T getMax(T x) { // in non decreasing order of x, regardless of comparator
        while (front < back - 1 && !cmp(M[front + 1] * x + B[front + 1], M[front] * x + B[front])) front++;
        return M[front] * x + B[front];
    }
    void clear() { front = back = 0; }
};

const int MAXN = 2e5 + 5;

int N;
ll C, H, dp;
ConvexHullTrick<MAXN, ll, greater<ll>> cht;

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // freopen("err.txt", "w", stderr);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        cin >> H;
        cht.addLine(-2 * H, H * H + (dp = i == 0 ? 0 : H * H + C + cht.getMax(H)));
    }
    cout << dp << nl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    int h[n];
    for (int i = 0; i < n; ++i)
        cin>>h[i];
    int dp[n];
    dp[0] = 0 ;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2 ; i < n ; i++)
    {
        int val1 = dp[i-1] + abs(h[i]-h[i-1]);
        int val2 = dp[i-2] + abs(h[i]-h[i-2]);
        dp[i] = min(val1,val2);
    }
    cout<<dp[n-1];

    printclock;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);
int main(){
    string s;cin>>s;
    int n =s.length();
    ll a =0;
    rep(i,n){
        a+=s[i]-'0';
    }
    if(a%9==0){cout<<"Yes"<<endl;}
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 3748
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

#define ll unsigned long long
#define MP make_pair

using namespace std;

int main(void) {
	int n,p[100];
	vector<string> s(100);
	string str;
	vector<pair<string,pair<int,int>>>pairs(100);
	vector<pair<int,int>>prepairs(100);

	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>str>>p[i];
		s[i]=str;
		prepairs[i]=MP(p[i]*(-1),i+1);
		pairs[i]=MP(s[i],prepairs[i]);
	}

	sort(pairs.begin(),pairs.begin()+n,less<pair<string,pair<int,int>>>());


	for (int i = 0; i < n; i++) {
		//cout<<pairs[i].first<<pairs[i].second.first<<(pairs[i].second).second<<"\n";
		cout<<(pairs[i].second).second<<"\n";
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

const LL MOD = 1e9 + 7;

LL dp[2005];
LL solve(int x) {
    if (dp[x] != -1) {
        return dp[x];
    } else if (x == 0) {
        return 1;
    }
    LL ans = 0;
    for (int i = 3; i <= x; i++) {
        ans += solve(x - i);
        ans %= MOD;
    }
    dp[x] = ans;
    return ans;
}

int main() {
    memset(dp, -1, sizeof(dp));
    int s;
    cin >> s;
    LL ans = solve(s);
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef node* Node;
#define NIL NULL
 
node array[500000];
int size=0;
 
Node root = NIL;
  
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
  
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
  
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeMinimum(z->right);
    
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  
  if(x!=NIL)x->parent=y->parent;
    
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
  
  if(y!=z)z->key=y->key;
    
  //free(y);
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = &array[size++];
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;   
}
 
 
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
 
int main(){
  int n,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
 
  return 0;
}

Measured memory_bytes: 15084
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//

        string S, T;
        cin >> S >> T;
        if (S[0] - 'A' < T[0] - 'A')
        {
                cout << '<' << endl;
        }
        else if (S[0] - 'A' == T[0] - 'A')
        {
                cout << '=' << endl;
        }
        else
        {
                cout << '>' << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;
//author_name:unused
//date:2018/11/18
//title:AGC 010 E Rearranging
//ÒòÎªÇÓÅ³£¬ËùÒÔÌÓ±ÜÉúÃü£¬ÒÔ²»µÖ¿¹ÔÚ×îºÚ°µµÄ³ÁÂÙÖÐÉú³ö½¾°Á£¬ÒòÎª½¾°Á£¬ËùÒÔ²»Ñ¡ÔñÉú£¬ËùÒÔ¾Ü³â´Ö±ÉµÄÀÖ¹ÛÖ÷Òå¡£
//Ìì²ÅµÄ±¯¾çµØÓÚ±»Ð¡¶øÊæÊÊµÄÃûÍûËùÊø¸¿¡£
//It's human to lie. Most of the time we can't even be honest with ourselves.

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

int dat[2020];
vector<int> graph[2020];
bool visit[2020];
int n;

vector<int> merge(vector<vector<int>> vvt,int head)
{
	int total=0;
	for(auto v:vvt) total+=v.size();
	vector<int> ret(total+(head>=0));
	int ptr=0;
	if(head>=0) ret[ptr++]=head;
	priority_queue<tuple<int,int,int>> pq;
	for(int i=0;i<vvt.size();i++) 
		pq.emplace(vvt[i][0],i,0);
	while(!pq.empty())
	{
		int val,idx,nxt;
		tie(val,idx,nxt)=pq.top();
		pq.pop();
		ret[ptr++]=val;
		
		if(nxt+1<vvt[idx].size())
			pq.emplace(vvt[idx][nxt+1],idx,nxt+1);
	}
	return ret;
}

vector<int> process(int u)
{
	visit[u]=true;
	vector<vector<int> > vvt;
	for(int v:graph[u])	if(!visit[v])
	{
		vvt.emplace_back(process(v));
	}
	return merge(move(vvt),u);
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",dat+i);
	sort(dat,dat+n);
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(gcd(dat[i],dat[j])>1)
			{
				graph[i].emplace_back(j);
				graph[j].emplace_back(i);
			}
	for(int i=0;i<n;i++) sort(graph[i].begin(),graph[i].end());
	
	vector<vector<int>> vvt;
	for(int i=0;i<n;i++)
		if(!visit[i])
		{
			
			vvt.emplace_back(process(i));
		}
	auto ret=merge(vvt,-1);
	for(int i=0;i<n;i++)
		printf("%d ",dat[ret[i]]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 17792
from math import pow
from collections import deque, Counter
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())

def cal_score(N, K, records):
    sorted_recs = sorted(records, key=lambda x: -x[1])
    target_queue = deque(sorted_recs[0:K]) # only allow pop() action, so use dequeue
    compare_queue = deque(sorted_recs[K:])
    distinct_set = set()
    dup_queue = deque()
    score = 0
    for neta_point in target_queue:
        score += neta_point[1]
        if neta_point[0] not in distinct_set:
            distinct_set.add(neta_point[0])
        else:
            dup_queue.append(neta_point)

    cardinality = len(distinct_set)
    score += pow(cardinality, 2)
    score = int(score)
    maybe_score = score
    # start iteration and comparing gain and lost
    while compare_queue:
        comp = compare_queue.popleft()
        if comp[0] in distinct_set:
            continue
        elif len(dup_queue) < 1:
            break
        else:
            old = dup_queue.pop()
            inc = 2 * len(distinct_set) + 1
            dec = old[1] - comp[1]
            delta = inc - dec
            maybe_score = maybe_score + delta
            score = max(score, maybe_score)

            distinct_set.add(comp[0])
    # both queues are drained
    return score


N, K = li()
records = [tuple(li()) for i in range(N)]
score = cal_score(N, K, records)
print(score)


Measured memory_bytes: 22500
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> v;
  for (int i = 0; i < 5; i++) {
    int n;
    cin >> n;
    v.push_back(n);
  }
  sort(v.begin(), v.end(), greater<int>());
  cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[3] << ' ' << v[4] << endl;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll n,d,cnt=0;
    cin>>n>>d;
    
    for(ll i=0;i<n;++i){
        double a,b,c;
        cin>>a>>b;
        c=sqrt(a*a+b*b);
        if(c<d||abs(c-d)<0.000000001){
            cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 3800