akhauriyash/Code-Regression huggingface dataset:
/************************************/
/* NoobM							*/
/* File Name : atjp.cpp				*/
/* Date : 27.06.2020 19:24:07 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

vector<long long> divisors(10000001, 0);

void sieve(int N){ 	
  	for(int p=1; p <=N; p++) {
        for(int i=p ; i<=N; i+=p)
            divisors[i]++;
    }
  	
}

void solve() {
	int n;
	cin >> n;
	
	sieve(n);
	
	ll counter = 0;
	
	for(int i = 1; i <= n; i++) {
		counter += (i * divisors[i]);
	}
	
	cout << counter << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string a,b,c; cin>>a>>b>>c;
  string s={a[0]-32,b[0]-32,c[0]-32};
  
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int min(int a,int b){
    return a < b ? a : b;
}
int f(int n){
    int res = 1;
    if(n > 1){
        res = n*(n-1)/2;
    }
    else {
        res = 0;
    }
    return res;
}
int main(void){
    int N,M;
    cin >> N >> M;
    int ans = 0;
    ans = f(N) + f(M);
    cout << ans <<endl;
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}


int main(){
  ll ans = 0;
  ll N; cin >> N;
  rep(i,N){
    ans += (i+1)*(N-i);
  }
  rep(i,N-1){
    ll a,b; cin >> a >> b;
    ll r = max(a,b);
    ll l = min(a,b);
    ans -= l*(N-r+1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
// ABC070-D
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

struct edge {
   ll to, cost;
};

const ll INF = 1e18;
int N, Q, K;
vec<edge> G[100010];
ll dist[100010];
bool visited[100010];

void findK(int s, int p) {
   for (edge e : G[s]) {
      if (e.to != p) {
         dist[e.to] = dist[s] + e.cost;
         findK(e.to, s);
      }
   }
}

int main() {
   cin >> N;
   rep (i, 0, N-1) {
      ll a, b, c;
      cin >> a >> b >> c;
      a--, b--;
      G[a].push_back(edge{b, c});
      G[b].push_back(edge{a, c});
   }

   cin >> Q >> K;
   K--;
   dist[K] = 0;
   findK(K, K);
   for (int i = 0; i < Q; i++) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      cout << dist[x] + dist[y] << endl;
   }

   return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{
    int n; cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    vector<ll> a(n+1,INF);
    a[0] = 0;
    for(int i=1;i<n;i++){
        chmin(a[i],a[i-1]+abs(h[i]-h[i-1]));
        if(i!=1) chmin(a[i],a[i-2]+abs(h[i] -h[i-2]));
    }
    cout << a[n-1] << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,k,x,y,a[100001];
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>s;
   if(s=="ABC")
   {
      cout<<"ARC"<<endl;
   }
   else
   {
      cout<<"ABC"<<endl;
   }
   return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll x;
  cin >> x;

  ll tmp = 100;
  ll y = 0;
  ll ans = 0;
  while(true) {
    
    y = tmp / 100;
    tmp = tmp + y;
    ans++;
    if (x <= tmp) {
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3192
// inputに入力データ全体が入る
function Main(input) {
  
var a = input.substr( 0,1 );
  var b = input.substr( 1, 1 );
  var c = input.substr(2, 1 );
  var d = input.substr( 3, 1 );
 
 var str = input; 
// 0文字目から4文字分を指定
  
  
 var str = [a,b,c,d];
str.sort();
 
  
 var a= str[0];
  var b= str[1];
 var c= str[2];
  var d= str[3];
 //  console.log(a,b,c,d)
var f = 0;
  if (a == b) {
              if (a !==c) {if  ( c == d){var f = 1;}
                                        
                            }
  }
    
     if (f == 1){console.log('Yes')}else{console.log('No');}
  
}

  
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  


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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);

  for(int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }

  int x0 = W;
  int y0 = H;
  int x1 = 0;
  int y1 = 0;
  for(int i = 0; i < N; i++) {
    if(a[i] == 1 && x1 < x[i]) {
      x1 = x[i];
    }
    else if(a[i] == 2 && x0 > x[i]) {
    x0 = x[i];
    }
    else if(a[i] == 3 && y1 < y[i]) y1 = y[i];
    else if(a[i] == 4 && y0 > y[i]) y0 = y[i]; 
  }
  if(x0 <= x1 || y0 <= y1) cout << 0;
   else cout << (y0 - y1) * (x0 - x1);


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n,k; cin>>n>>k;
    int h[n]; rep(i,n) cin>>h[i];
    sort(h,h+n);
    int r=k-1,ans=INF;
    for(int d=0;r+d<n;d++){
        ans=min(ans,h[r+d]-h[d]);
        // cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int A,B;
    cin>>A>>B;
    
    int ans=6-A-B;
    cout<<ans<<endl;
  
    }
    
    



Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long K = sc.nextLong();
		long D = sc.nextLong();
		sc.close();

		long c = Math.abs(X) / D;

		long ans = Long.MAX_VALUE / 2;
		// 収束しない場合
		if (K < c) {
			ans = Math.abs(X) - D * K;
		} else {
			// 収束する場合
			long std = Math.abs(X) - D * c;
			long rest = K - c;
			if (rest % 2 == 0) {
				ans = std;
			} else {
				if (std >= 0) {
					ans = std - D;
				} else {
					ans = std + D;
				}
			}
		}
		System.out.println(Math.abs(ans));
	}
}


Measured memory_bytes: 35644
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("output.txt", "w", stdout);
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for(int& x : a)
        cin >> x;
    int res = 0;
    for(int i = 1; i < n; ++i)
        if (a[i] == a[i - 1])
        {
            a[i] = -1;
            ++res;
        }
    cout << res << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long x;
long long f(long long y) {
if(y < 0) return 0;
return y / x + 1;
}
int main () {
long long a, b; cin >> a >> b >> x;
cout << f(b) - f(a - 1) << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	ll n,ans=INF;
	cin >> n;
	FOR(i,1,sqrt(n)+1)
	{
		if(n%i==0)
		{
			ll t = n / i;
			string sa = to_string(i), sb = to_string(t);
			ans = min(ans, static_cast<ll>(max(sa.size(), sb.size())));
		}
	}
	cout << ans << endl;
}

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

int main()
{
	int n;
	cin>>n;
	string str;
	cin>>str;
	if( n >= str.length())
		cout<<str;
	else
	{
		for(int i=0;i<n;i++)
			cout<<str[i];
		cout<<"...";
	}
	
	
	//getchar();getchar();

	
	
	return 0;
}


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


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const ll MOD = 1e9+7;

int A[100100];
int main(){
    int N;
    cin >> N;
    REP(i,N){
        int a;
        cin >> a;
        //A[i] = a;
        A[a]++;
    }

    bool odd = N%2; 
    bool ok = true;
    ll ans = 1;
    for(int i = !odd; i < N; i += 2){
        int a = A[i];
        if(odd && i == 0){
            if(a != 1) ok = false;
        }
        else{
            if(a != 2) ok = false;
            ans *= 2;
            ans %= MOD;
        }
    }


    if(ok) cout << ans << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n; cin >> n;
    VI l(n); REP(i,n) cin >> l[i];
    Yn(MAX(l)<SUM(l,-MAX(l)));

    return 0;
}

Measured memory_bytes: 256
N = gets.to_i

def rec(x)
  res = 0
  if x <= N
    s = x.to_s
    res += 1 if ["3", "5", "7"].map { |c| s.count(c) }.all? { |cnt| cnt > 0 }
    [3, 5, 7].each do |d|
      res += rec(10 * x + d)
    end
  end
  res
end

p rec(0)


Measured memory_bytes: 1788
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	vector<pair<int,int> >v[200];
	priority_queue<pair<int, int> > pq;
	int a[200];
	int b[8];
	int c[8];
	int p[8];
	int d[8][8];
	int e;
	int n, m, r;
	int x, y, z;
	int s, ans;
	scanf("%d %d %d", &n, &m, &r);
	for (int i = 0; i < r; i++){
		scanf("%d", &b[i]);
		b[i]--;
	}

	for (int i = 0; i < m; i++){
		scanf("%d %d %d", &x, &y, &z);
		x--;
		y--;
		v[x].push_back(make_pair(y, z));
		v[y].push_back(make_pair(x, z));
	}
	for (int center = 0; center < r; center++){
		for (int i = 0; i < n; i++)a[i] = -1;
		pq.push(make_pair(0, b[center]));
		for (int j = 0; j < n; j++){
			while (a[pq.top().second] != -1)pq.pop();
			a[pq.top().second]=-pq.top().first;
			x = pq.top().second;
			y = pq.top().first;
			pq.pop();
			for (int i = 0; i < v[x].size(); i++){
				z=v[x][i].first;
				if (a[z] == -1){
					pq.push(make_pair(y - v[x][i].second, z));
				}
			}
		}
		for (int i = 0; i < r; i++){
			d[center][i] = a[b[i]];
		}
		for(;pq.empty()==0;)pq.pop();
	}
	e = 1;
	for (int i = 0; i < r; i++){
		e = e*r;
	}
	ans = 1000000000;
	for (int k = 0; k < e; k++){
		x = k;
		s = 0;
		for (int i = 0; i < r; i++){
			p[i] = x % r;
			x = x / r;
			if (c[p[i]]>0)break;
			c[p[i]]++;
			if (i > 0){
				s = s + d[p[i - 1]][p[i]];
			}
			if (i == r - 1){
				if (s < ans)ans = s;
			}
		}
		for (int i = 0; i < r;i++)c[i] = 0;
	}

	printf("%d\n", ans);

	return 0;
}


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

int main() {
    int n;
    cin >> n;
    
    if(n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a,b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<ll> a(n+1),b(n);
    for(int i=0;i<n+1;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        if(b[i]<=a[i]){
            ans+=b[i];
        }
        else{
            ans+=a[i];
            ans+=min(b[i]-a[i],a[i+1]);
            a[i+1]=max(0LL,a[i+1]-(b[i]-a[i]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

        int X = scanner.nextInt();
        int Y = scanner.nextInt();

        System.out.println(Y%2 == 0 && X*2 <= Y && Y <= X*4 ? "Yes" : "No");
    }
}

Measured memory_bytes: 35588
#include <stdio.h>

int main()
{
  char str[3];
  scanf("%s", &str);
  int i, count = 0, result = 0;
  
  for (i = 0;i < 3;i ++) {
    if (str[i] == 'R') {
      count ++;
      result = count;
    } else if (str[i] == 'S') {
      count = 0;
    }
  }
  
  printf("%d", result);
}


Measured memory_bytes: 1704
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
int main() {
  string s;
  cin>>s;
  map<string, string> ma;
  ma["A"]="T";
  ma["T"]="A";
  ma["C"]="G";
  ma["G"]="C";
  cout << ma[s] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100004
int memo[N][3];
int A[N];
int B[N];
int C[N];
int n;
int m3(int a, int b, int c){
    return max(c, max(a,b));
}
int dp(int pos, int l) {
    if(pos >= n) {
        return 0;
    }
    if(memo[pos][l]!=-1) return memo[pos][l];
    if(l == 0)return memo[pos][l] = max(B[pos] + dp(pos+1,1), C[pos] + dp(pos+1,2));
    if(l == 1)return memo[pos][l] = max(A[pos] + dp(pos+1,0), C[pos] + dp(pos+1,2));
    if(l == 2)return memo[pos][l] = max(A[pos] + dp(pos+1,0), B[pos] + dp(pos+1,1));
}
int main(){
    scanf("%d",&n);
    for(int i = 0; i < n; i++) {
        scanf("%d %d %d",A + i, B + i, C + i);
    }
    memset(memo,-1, sizeof memo);
    printf("%d\n", m3(A[0] + dp(1, 0), B[0] + dp(1,1), C[0] + dp(1,2)));
}

Measured memory_bytes: 7296
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
map<string,ll>mp;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s={};
		cin>>s;
		mp[s]++;
	}
	ll ma=0;
	for(auto p:mp){
		chmax(ma,p.se);
	}
	V<string> a;
	for(auto p:mp){
		if(ma==p.se)a.push_back(p.fi);
	}
	sort(all(a));
	for(int i=0;i<a.size();i++){
		cout<<a[i]<<endl;
	}
}

Measured memory_bytes: 27376
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
typedef long long ll;
int H, W, h, w;
int A[505][505];
#define INF 4000
//-----------------------------------------------------------------------------------
void _main() {
    cin >> H >> W >> h >> w;

    rep(y, 0, H) rep(x, 0, W) {
        if (y % h == h - 1 && x % w == w - 1) A[y][x] = -(h * w - 1) * INF - 1;
        else A[y][x] = INF;
    }

    ll sm = 0;
    rep(y, 0, H) rep(x, 0, W) sm += A[y][x];
    
    if (sm <= 0) {
        printf("No\n");
        return;
    }
 
    printf("Yes\n");
    rep(y, 0, H) {
        rep(x, 0, W) {
            if (0 < x) printf(" ");
            printf("%d", A[y][x]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 2560
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll Q, T,F;
	string s;
	char C;
	while(cin>>s>>Q) {
		bool rev=false;
		deque<char> q;
		REP(i, s.size()) q.push_back(s[i]);
		REP(i, Q) {
			cin>>T;
			if(T==1) rev=!rev;
			else {
				cin>>F>>C;
				if(F==1) {
					if(rev) q.push_back(C);
					else q.push_front(C);
				} else {
					if(!rev) q.push_back(C);
					else q.push_front(C);
				}
			}
		}
		string ans(ALL(q));
		if(rev) reverse(ALL(ans));
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1232
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

N,K =  ints_raw()
def main():
    ans = 0
    buf = 0
    for n in range(N,0,-1):
        tmp  =n*(2**buf)
        if tmp< K:
            while tmp < K:
                tmp *=2
                buf+=1
        ans += (0.5)**(buf)
    return ans/N

print(main())


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    ll CN=N;
    ll fx=0;
    while(1){
        if(CN==0)break;
        fx+=CN%10;
        CN/=10;
    }
    if(N%fx==0){
        cout<<"Yes"<<endl;
    }else{
        cout << "No" << endl;
    }
    


    return 0;
    

}

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

#define type_num 26

int main(){
    int D;
    cin >> D;
    
    vector<int> c(type_num);
    vector<vector<int>> s(D, vector<int>(type_num));
    vector<int> t(D);
    vector<int> last(type_num, 0);
    vector<int> one(type_num, 1);
    for (int i = 0; i < type_num; i++){
        cin >> c[i];
    }

    for (int d = 0; d < D; d++){
        for (int i = 0; i < type_num; i++){
            cin >> s[d][i];
        }
    }

    for (int d = 0; d < D; d++){
        cin >> t[d];
    }

    int S = 0;
    for (int d = 0; d < D; d++){
        int plus_num = s[d][t[d] - 1];
        int minus_num = 0;
        for (int i = 0; i < type_num; i++){
            if (i != t[d] - 1){
                minus_num += c[i] * (d + 1 - last[i]);  
            }
        }
        S += plus_num - minus_num;
        last[t[d] - 1] = d + 1;

        cout << S << endl;
    }
}

Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void){
  string s;
  int ans=0;
  while(cin >> s){
    int cnt=0;
    for(int i=0;i<s.size()/2;i++)
      if(s[i]==s[s.size()-i-1])cnt++;

    if(cnt==s.size()/2)ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  scanf("%d", &n);

  int even[100001] = {}, odd[100001] = {};
  REP(i,n){
    int v;
    scanf("%d", &v);
    if(i % 2 == 0){
      odd[v] += 1;
    }else{
      even[v] += 1;
    }
  } 

  int odd1 = 0, even1 = 0, odd2 = 0, even2 = 0;
  int odd1_idx, even1_idx;
  REP(i,100001){
    if(odd[i] > odd1){
      odd2 = odd1;
      odd1 = odd[i];
      odd1_idx = i;
    }else if(odd[i] > odd2){
      odd2 = odd[i];
    }
    if(even[i] > even1){
      even2 =  even1;
      even1 = even[i];
      even1_idx = i;
    }else if(even[i] > even2){
      even2 = even[i];
    }
  }

  if(odd1_idx != even1_idx){
    printf("%d\n", n - odd1 - even1);
  }else{
    printf("%d\n", min(n-odd1-even2, n-odd2-even1));
  }

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>

int N, K, arr[10], tmp1, tmp2, tmp3;

bool checknot(int arr[], int n) {
    while (n > 0) {
        tmp3 = n % 10;
        if (arr[tmp3] != 0) {
            return false;
            break;
        }
        n /= 10;
    }
    return true;
}

void solve() {
    std::cin >> N >> K;
    tmp2 = N;
    for (int i=0; i<K; ++i) {
        std::cin >> tmp1;
        arr[tmp1] = 1;
    }
    
    while (1) {
        if (checknot(arr, tmp2)) {
            std::cout << tmp2 << std::endl;
            break;
        }
        ++tmp2;
    }
}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M;
vector<int> lst;

void mysort(int i,int x){
    //二ブタンにする。
    int t_min = i;
    int t_max = lst.size();
    while(t_max > t_min+1){
        int t_mid = (t_min + t_max)/2;
        if(lst[t_mid] >= x){
            t_max = t_mid;
        }else{
            t_min = t_mid;
        }
    } 
    auto it = lst.begin() + t_max;
    lst.insert(it,x);
}

int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++){
        int tmp;cin>>tmp;
        lst.push_back(-tmp);
    }
    sort(lst.begin(),lst.end());
    for(int i=0;i<M;i++){
        lst[i] /= 2;
        mysort(i,lst[i]);
    }
    long long sum=0;
    for(int i=M;i<N+M;i++){
        sum += lst[i]; 
    }
    cout<<-sum<<endl;
    return 0;
}

Measured memory_bytes: 1400
from collections import Counter
N = int(input())
S = set()
cnt = 0

def createStr(counter):
    ret = ""
    keys = list(counter.keys())
    keys.sort()
    for key in keys:
        ret += key
        ret += str(counter[key])
    return ret

ret = {}
for i in range(N):
    s = Counter(input())
    s = createStr(s)
    if s in ret.keys():
        ret[s] += 1
    else:
        ret[s] = 1

for i in ret.values():
    cnt += i*(i-1)//2

print(cnt)


Measured memory_bytes: 18820
#include <stdio.h>
int a,b;
int kouzi[17][17]={0,};

int keiro(int i,int j){
    static int memo[17][17];
    if(i>a || j>b || kouzi[i][j])
        return 0;
    if(i==a&&j==b)
        return 1;
/*  if(memo[i][j])
        return memo[i][j];
    else*/
        return memo[i][j]=keiro(i+1,j)+keiro(i,j+1);
}
main(){
    int i;
    int t,t2;
    int n;
    while(scanf("%d %d",&a,&b)!=EOF){
        if(a==0)
            break;
        scanf("%d",&n);
        for(i=0;i<17*17;i++)
            kouzi[0][i]=0;
        for(i=0;i<n;i++){
            scanf("%d %d",&t,&t2);
            kouzi[t][t2]=1;
        }
        printf("%d\n",keiro(1,1));
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>n>>x>>m;
        ans = (n + x-1)/x;
        ans*=m;
        cout<<ans<<endl;

    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3652
N,M = list(map(int,input().split()))
atob = [0] * N
btoz = [0] * N
for _ in range(M):
    a, b = list(map(int,input().split()))
    if a == 1:atob[b-1] = 1
    elif a == N:btoz[b-1] = 1
    if b == 1:atob[a-1] = 1
    elif b == N:btoz[a-1] = 1

for i in range(N):
    if atob[i]*btoz[i] == 1:
        print('POSSIBLE')
        break
else:print('IMPOSSIBLE')

Measured memory_bytes: 6260
# coding: utf-8
# Your code here!
b=input()
s=input()
n=int(input())-1
a=s[n]
ans=""
#print(a)
for i in range(len(s)):
    m=s[i]
    if(s[i]!=a):
        m="*"
    ans+=m
print(ans)

Measured memory_bytes: 3060
using System;
namespace a
{
  class program
  {
    static void Main()
    {
      string s = Console.ReadLine();
      int ans = 0;
      for (int i=0;i<4;i++)
      {
        var s2=Convert.ToString(s[i]);
        if (s2.Equals("+"))
        {
          ans=ans+1;
        }
        else
        {
          ans=ans-1;
        }
      }
      Console.WriteLine(ans);
    }
  }
}

Measured memory_bytes: 27204
A, B = map(int, input().split())
# a = A
# if A == B:
#     print(A)
#     exit(0)
# if A != 0:
#     a = A - 1
# if a % 2 != 0:
#     a = a ^ (a - 1)
#     t = (a - 1) // 2
#     if t % 2 != 0:
#         a = a ^ 1
# else:
#     t = A // 2
#     if t % 2 != 0:
#         a = a ^ 1
#
# if B % 2 != 0:
#     B = B ^ (B - 1)
#     t = (B - 1) // 2
#     if t % 2 != 0:
#         B = B ^ 1
# else:
#     t = B // 2
#     if t % 2 != 0:
#         B = B ^ 1
# ans = a ^ B
def calc(a):
    t = (a + 1) // 2
    ans = t % 2
    if a % 2 == 0:
        ans = ans ^ a
    return ans

print(calc(A-1) ^ calc(B))


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
ll pow2(int x);

ll pow2(int x){
    if(x==0)return 2;
    ll a;
    a = pow2(x-1)*2;
    return a;
}
int main(){
    ll h;
    cin>>h;
    ll e,count=0;
    while(true){
        count++;
        e=h/2;
        if(e<=1)break;
        h=e;
    }
    ll ans=pow2(count)-1;
    if(h==1)ans=1;
    cout<<ans<<endl;

    return 0;
}


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

typedef vector<int> vi;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)

int main()
{
    int N, M; cin >> N >> M;
    vi c(N+1, 0);
    rep(i, M) {
        int a, b; cin >> a >> b;
        c[a]++;
        c[b]++;
    }
    cout << (all_of(all(c),[](int x){return x%2==0;}) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 640
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	var H = parseInt(input[0][0], 10);
	var W = parseInt(input[0][1], 10);
	var ans = calc(H, W);
	console.log(ans);
}

function calc(H, W){
	if (H % 3 === 0 || W % 3 === 0) return 0;
	var result = H * W;
	var tmp;
	var oldtmp = result;
	for (var i = 0; i <= W; i++){
		tmp = Math.max(Math.abs(i * H - (W - i) * Math.ceil(H / 2)), Math.abs(i * H - (W - i) * Math.floor(H / 2)), (H % 2) * (W - i));
		result = Math.min(result, tmp);
		if (tmp > oldtmp) break;
		oldtmp = tmp;
	}
	[W, H] = [H, W];
	oldtmp =  H * W;
	for (var i = 0; i <= W; i++){
		tmp = Math.max(Math.abs(i * H - (W - i) * Math.ceil(H / 2)), Math.abs(i * H - (W - i) * Math.floor(H / 2)), (H % 2) * (W - i));
		result = Math.min(result, tmp);
		if (tmp > oldtmp) break;
		oldtmp = tmp;
	}
	return Math.min(result, H, W);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

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

#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = "  << x << endl

using namespace std;

typedef long long tint;

random_device rd;
mt19937 gen(rd());

uniform_int_distribution<tint> dis(1, 10000);

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{ 
		tint p = tint(v.size());
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

int main()
{
	#ifdef ACMTUYO
		assert(freopen("entrada.in", "r", stdin));
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	tint n,m;
	while (cin >> n >> m)
	{
		cout << n*(n-1)/2 + m*(m-1)/2 << "\n";
	}
	
	
	return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INF (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest;
  l=2*i;
  r=2*i+1;

  if(l <= H && A[l] > A[i]) largest=l;
  else largest=i;
  if(r <= H && A[r] > A[largest]) largest=r;

  if(largest != i)
  {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if(H < 1) return -INF;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  if(key < A[i]) return;
  A[i]=key;
  while(i > 1 && A[i/2] < A[i])
  {
    swap(A[i], A[i/2]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H]= -INF;
  increaseKey(H, key);
}

int main(){
  int key;
  char com[10];

  while(1)
  {
    scanf("%s", com);
    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i')
    {
      scanf("%d", &key);
      insert(key);
    }
    else
    {
      printf("%d\n", extract());
    }
  }

  return 0;
}



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

int main() {
	//入力
	int n, m;
	cin >> n >> m;

	int a[50], b[50], c[50], d[50];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}

	//計算
	int ans[50];
	for (int i = 0; i < n; i++) {
		ans[i] = 1;
		int q = 400000000;

		for (int j = 0; j < m; j++) {
			int p = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (q > p) {
				q = p;
				ans[i] = j + 1;
			}
		}

		cout << ans[i] << endl; //出力
	}

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int n, a[209];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	int ret = 0;
	while (true) {
		bool flag = true;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 1) flag = false;
		}
		if (!flag) break;
		for (int i = 0; i < n; i++) {
			a[i] /= 2;
		}
		ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 384
#include"cstdio"
#include"algorithm"
using namespace std;
bool cmp(int a,int b)
{
 return a>b;
}
int main(){
	int n;
	scanf("%d",&n);
	int b[100005];
	int i=0,j=0,max=0,min=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}	
	long long sum=1;
	int t=0;
	sort(b,b+n,cmp);
	for(i=1;i<n;i++)
	{
		if(b[i]==b[i-1])
		{
			sum=sum*b[i];
			i++;
			t++;
		}
		if(t==2)
			break;		
	}
	if(sum==1&&t!=2)
		sum=0;
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  string s;
  cin>>s;
  ll c = 0;
  rep(i,0,s.sz){
    if(s[i]=='x')c++;
  }
  if(c>7){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;

int n;
ll w;
ll W[105];
ll V[105];
ll dp[105][100005];

ll solve(int i, ll cap) {
  if (cap < 0) {
    return -1e13;
  }
  if (i < 0) {
    return 0;
  }
  ll& res = dp[i][cap];
  if (res != -1) {
    return res;
  }
  return res = max(solve(i - 1, cap), V[i] + solve(i - 1, cap - W[i]));
}

int main() {
  cin >> n >> w;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= w; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> W[i] >> V[i];
  }
  cout << solve(n - 1, w) << '\n';
  return 0;
}


Measured memory_bytes: 80128
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if b[i] <= a[i]:
        cnt += b[i]
    else:
        if b[i] - a[i] <= a[i + 1]:
            a[i + 1] -= b[i] - a[i]
            cnt += b[i]
        else:
            cnt += a[i] + a[i + 1]
            a[i + 1] = 0
print(cnt)


Measured memory_bytes: 19156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    bool flag = true;
    ll n,k,rop = 0,nx = 0,ans;
    cin>>n>>k;
    vector<ll>a(n),isVisit(n,-1);
    rep(i,n)cin>>a[i];
    rep(i,k){
        if(isVisit[nx] != -1 && flag){
            flag = false;
            rop = i - isVisit[nx];
            nx = a[nx] - 1;
            i = k - 1 - (k - 1 - i) % rop;
        }
        else{
            isVisit[nx] = i;
            nx = a[nx] - 1;
        }
    }

    cout<<nx + 1<<endl;

    return 0;
}


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

#define bigmod 1000000007

int n, a[25][35], memo[2097152];

int dp(int mask, int cnt) {
	int sum = 0;
	if (cnt == n)
		return 1;
	if (memo[mask] != -1)
		return memo[mask];
	for (int j = 0; j < n; j++) {
		if ((mask & (1 << j)) || (a[cnt][j] == 0))
			continue;
		sum += dp(mask | (1 << j), cnt + 1);
		sum %= bigmod;
	}
	memo[mask] = sum;
	return sum;
}

int main() {
	int ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			scanf("%d", &a[i][j]);
	memset(memo, -1, sizeof memo);
	ans = dp(0, 0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8320
/****************
 *		*
 * ALDS_1_6_B	*
 * Partition	*
 *		*
 * 2019/08/21	*
 *		*
 ****************/

#include<iostream>
#include<vector>

using namespace std;

#define	MAX_ARRAY	100000
#define MAX		100000

int A[MAX_ARRAY];

void swap(int i,int j){
  int temp = A[i];
  A[i] = A[j];
  A[j] = temp;

  return;
}

int partition(int p,int r){
  int x = A[r];
  int i = p-1;

  for(int j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      swap(i,j);
    }
  }
  swap(i+1,r);

  return i+1;
  
}

int main(void){
  int n=0;
  int standard = 0;
  cin >> n;
  for(int i=0;i<n;i++) cin >>A[i];

  standard = partition(0,n-1);

  for(int i=0;i<n;i++){
    if(i > 0) cout << " ";

    if(i == standard)
      cout << "[" << A[i] << "]"; 
    else
      cout << A[i];
  }
  cout << "\n";
  
  return 0;
}



Measured memory_bytes: 3472