akhauriyash/Code-Regression huggingface dataset:
import Data.Maybe

main = do
  input <- getLine
  let ans = solve 1 input
  if ans == Nothing then putStrLn "-1 -1"
                    else putStrLn $ (\(x, y) -> show x ++ " " ++ show y) . fromJust $ ans

solve :: Int -> String -> Maybe (Int, Int)
solve n [] = Nothing
solve n (a:[]) = Nothing
solve n (a:b:[])
  | a == b = Just (n, n+1)
  | otherwise = Nothing
solve n (a:b:c:cs)
  | a == b || a == c || b == c = Just (n, n+2)
  | otherwise                  = solve (n+1) (b:c:cs)


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

int k,s,cnt=0,z;

int main(){
    cin>>k>>s;
    for (int x=0; x<=k; x++){
        for (int y=0; y<=k; y++){
            z=s-x-y;
            if ((z<=k) && (z>=0)) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define ll long long

using namespace std;
bool b[1000002];
map<int,int>mp;
int divisors(int n)
{
    // Note that this loop runs till square root
    for (int i=2; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            // If divisors are equal, print only one
            if (n/i == i)
            {
                if(b[i]==false) return 0;
            }
                //printf("%d ", i);

            else // Otherwise print both
            {
                if(b[i]==false||b[n/i]==false) return 0;
            }
                //printf("%d %d ", i, n/i);
        }
    }
    if(mp[n]==1)
    return 1;
    else return 0;
}

///Code starts from here
int main()
{
        int n,i,cnt=0,flag=0;
        cin>>n;
        int a[n];
        memset(b,true,sizeof(b));

        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]==1) flag=1;
            b[a[i]]=false;
            mp[a[i]]++;
        }
        if(flag&&mp[1]==1)
        {
            cout<<"1"<<endl;
            return 0;
        }
        else if(flag&&mp[1]>1)
        {
             cout<<"0"<<endl;
            return 0;
        }

        for(i=0;i<n;i++)
        {
            cnt+=divisors(a[i]);
        }

        cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 14788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a,b,c,d;
  cin >> N;
  a=N/1000;
  b=(N%1000)/100;
  c=(N%100)/10;
  d=N%10;
  if ((a==b&&b==c)||(b==c&&c==d)) {
    cout << "Yes" << endl;
  }
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}

#define REP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    if (a.second == b.second) return a.first < b.first;
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> AB(N);

    REP(i, 0, N) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(all(AB), _less);
    map<ll, vector<ll> > m;
    REP(i, 0, N) {
        m[AB[i].first].push_back(AB[i].second);
    }
    
    priority_queue<ll> s;
    ll R = 0;
    REP(k, 1, M+1) {
        REP(i, 0, m[k].size()) {
            s.push(m[k][i]);
        }
        
        if (s.size()) {
            R += s.top();
            s.pop();
        }
    }
    
    cout << R << endl;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

#define	MOD 1000000007

int	main() {
	int x, a, b;
	cin >>x >>a >>b;
	int A=abs(a-x);
	int B=abs(b-x);
	if (A<B)
		cout <<'A' <<endl;
	else
		cout <<'B' <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    int total = 0;
    for (int i=0; i < 4; i++){
        if (to_string(n)[i] == '2') {
            total++;
        }
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  char c;
  rep(i,3){cin>>c;cout<<c;}
  cout<<endl;
}

Measured memory_bytes: 3584
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back


#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64_t
#endif

const long long MOD = 1e9 + 7;
const long long MAXN = 2e6 + 1;
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


int mul(int a, int b)
{
	return (ll)a * b % MOD;
}


int binpow(int a, int n) {
	if (n == 1){ 
		return a;
	}
	if (n % 2 == 0) {
		int x = binpow(a, n / 2);
		return mul(x, x);
	}
	return mul(a, binpow(a, n - 1));
}

int fact[MAXN];



int C(int n, int k) {
	if (n < 0 || k < 0) return 0;
	if (k > n) return 0;
	int res = mul(fact[n - k], fact[k]);
	return mul(fact[n], binpow(res, MOD - 2));
}

main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    fact[0] = 1;
    for (int i = 1; i < MAXN; i++) {
		fact[i] = mul(fact[i - 1], i);
	}
    n--;
    int ans = mul(n, fact[n]);
    for (int i = 1; i < n; i++) {
		ans -= mul(mul(fact[i], fact[n - i]), C(i - 1, n - i));
    	if (ans < 0)
    	ans+= MOD;
    }
    cout << (ans+MOD)%MOD;
    return 0;
}

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

  int k, a, b,n;

	cin >> k ;
    cin >> a >> b;

	for (int i = 1; n < b; i++) {
		n = k*i;
		if (a <= n && n <= b){
			cout << "OK" << endl;
          return 0;
		}

	}

	cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N,R;
  cin>>N>>R;
  
  int ans=0;
  if(N>=10)
    ans=R;
  else
    ans=R+100*(10-N);
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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()
{
	int N;
	cin >> N;

	map<int, int> m;
	rep(i, N)
	{
		int a;
		cin >> a;
		m[a]++;
	}

	if (m.count(0) == 1)
	{
		ll ans = 1;
		int prev = 0;
		for (auto x : m)
		{
			if (x.first == 0)
			{
				if (x.second != 1)
				{
					cout << 0 << endl;
					return 0;
				}
			}
			else if (x.first != prev + 2 || x.second != 2)
			{
				cout << 0 << endl;
				return 0;
			}

			ans *= x.second;
			ans %= MOD;

			prev = x.first;
		}

		cout << ans << endl;
	}
	else if (m.count(1) == 1)
	{
		ll ans = 1;
		int prev = -1;
		for (auto x : m)
		{
			if (x.first != prev + 2 || x.second != 2)
			{
				cout << 0 << endl;
				return 0;
			}

			ans *= x.second;
			ans %= MOD;

			prev = x.first;
		}

		cout << ans << endl;
	}
	else
	{
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 3200
import math


def main():
    a, b, x = map(int, input().split())
    x /= a
    if x <= a * b / 2:
        c = x * 2 / b
        ans = math.atan2(b, c) * 360 / (math.pi * 2)
    else:
        y = a * b - x
        c = y * 2 / a
        ans = math.atan2(c, a) * 360 / (math.pi * 2)
    print(ans)


if __name__ == "__main__":
    main()


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

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

const Int MAX = 100;
Int dp[MAX][MAX];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const Int INF = 1LL<<61;
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(Int i=1;i<MAX;i++){
    for(Int j=0;j<MAX;j++){
      dp[i][j]=dp[i-1][j];
      if(j) dp[i][j]+=dp[i-1][j-1];
      chmin(dp[i][j],INF);
    }
  }  
  
  Int n,m;
  while(cin>>n>>m,n){
    m--;
    Int k=0;
    while(dp[n][k]<=m) m-=dp[n][k++];
    string s;
    for(Int i=1;i<n;i++){
      if(k<=n-i&&dp[n-i][k]>m){
	s.push_back('0');
      }else{
	s.push_back('1');
	m-=dp[n-i][k];
	k--;
      }
    }
    s.push_back('0'+k);
    cout<<s<<endl;
  }
}




Measured memory_bytes: 3112
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	int a[200000]={0};
	int i,x,sum=0;;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		a[x]++;
	}
	sort(a,a+200000);
	for(i=0;i<200000-k;i++)
	{
		sum+=a[i];
		//printf("%d",a[i]);
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int h,w,a,b,M=12801;
    in>>h>>w;
    vector<vector<int>> c(h,vector<int>(w));
    fr(i,h) fr(j,w) in>>c[i][j];
    fr(i,h) fr(j,w) in>>b,c[i][j]=abs(c[i][j]-b);
    vector<vector<vector<bool>>> v(h,vector<vector<bool>>(w,vector<bool>(M)));
    v[0][0][c[0][0]]=true;
    fr(i,h) fr(j,w){
        fr(k,M){
            if(i&&v[i-1][j][abs(k-c[i][j])]) v[i][j][k]=true;
            if(i&&k+c[i][j]<M&&v[i-1][j][k+c[i][j]]) v[i][j][k]=true;
            if(j&&v[i][j-1][abs(k-c[i][j])]) v[i][j][k]=true;
            if(j&&k+c[i][j]<M&&v[i][j-1][k+c[i][j]]) v[i][j][k]=true;
        }
    }
    //fr(i,h) fr(j,w) fr(k,6) cout<<i<<" "<<j<<" "<<k<<" "<<v[i][j][k]<<endl;
    fr(i,M) if(v[h-1][w-1][i]) return cout<<i<<endl,0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long K){
    string answer = "";
    rep(i,0,K) answer += "ACL";
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>  

int main(void) {    

int a,b,c,i;    

int count;    

scanf("%d %d %d\n", &a, &b, &c);    

for(i=a,count=0;i<=b;i++) {        

if(c%i==0) count ++;    

}    

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

return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  ll ans = 0;
  if (S[0]!=S[1]){
      ans = 1;
  } else if (S[1]!=S[2]){
      ans = 1;
  } else if (S[2]!=S[0]){
      ans = 1;
  }
  
  cout << ((ans==0) ? "No" : "Yes") << "\n";
  return 0;
}


Measured memory_bytes: 256
var y,n,ans:int64;
var i:longint;
var x:array[0..10020] of int64;
begin
  read(n);for i:=1 to n do read(x[i]);
  for i:=1 to n do begin read(y);if x[i]<y then inc(ans,(y-x[i]) div 2)
  else dec(ans,x[i]-y);end;if ans>=0 then writeln('Yes')else writeln('No');
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = LINF;
	for (int r = k - 1; r < n; r++) {
		int l = r - k + 1;
		ans = min({ans, abs(a[l] - a[r]) + abs(a[l]), abs(a[l] - a[r]) + abs(a[r])});
	}
	cout << ans << endl;
	return 0;
}

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

const int mod = 1e9 + 7;

int T, n;
int fac[25], inv[25];

inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

inline int mpow(int a, int x)
{
	int ans = 1;
	while(x)
	{
		if(x & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		x >>= 1;
	}
	return ans;
}

inline int C(int n, int m)
{
	if(n < m) return 0;
	return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main()
{
	fac[0] = 1;
	for(int i = 1; i <= 20; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[20] = mpow(fac[20], mod - 2);
	for(int i = 19; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;

	scanf("%d", &T);
	while(T --)
	{
		scanf("%d", &n);
		if(n < 5) { puts("0"); continue; }
		n -= 5;
		int ans = 0;
		for(int i = 0; i <= 11; i++)
		{
			if((n - i) & 1) continue;
			int m = (n - i) / 2, s = inv[15];
			for(int j = m + 15; j >= m + 1; j--) s = 1ll * s * j % mod;
			update(ans, 1ll * C(11, i) * s % mod);
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

int main()
{
	int i=0,j, k, l, h[100], w[100];

	cin >> h[0] >> w[0];

	while ((h[i] != 0) && (w[i] != 0)) {
		i++;
		cin >> h[i] >> w[i];
	}

	for (j=0; j < i; j++) {

		for (k=0; k < w[j]; k++)
			cout << '#';
		cout << endl;

		for (k=0; k < (h[j]-2); k++) {
			cout << '#';
			for (l=0; l < (w[j]-2); l++)
				cout << '.';
			cout << '#' << endl;
		}
		
		for (k=0; k < w[j]; k++)
			cout << '#';
		cout << endl;
		
		cout << endl;
	}		
	return 0;
}

Measured memory_bytes: 3040
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[M];
		int[] B = new int[M];
		for (int i=0; i<M; i++) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
		}
		Integer[] sp = new Integer[N+1];
		Arrays.fill(sp, 0);
		for (int i=0; i<M; i++) {
			sp[A[i]] ++;
			sp[B[i]] ++;
		}
		for (int i=1; i<N+1; i++) {
			System.out.println(sp[i]);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x7fffffff
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
typedef vector<int> VI;
typedef map<int,int> MII;
const int N = 234, MOD = 7+1e9;
int getA(int x)
{
    int res = 0;
    while(x)
    {
        res += x % 10;
        x /= 10;
    }
    return res;
}

int main()
{
#ifdef YUUKILP
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int _min = n;
    for(int i = 1;i < n;i ++)
    {
        _min = min(_min, getA(i) + getA(n - i));
    }
    cout << _min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  long long i,s;
  vector<long long> a(n);
  s=1;
  for(i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)==0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(i=0;i<n;i++){
    if(a.at(i)>1000000000000000000/s){
      cout << -1 << endl;
      return 0;
    }
    s *= a.at(i);
  }
  cout << s << endl;
}

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,l,c=0;
    string s;
    cin>>n;
    cin>>s;
    string ss="ABC";
    k=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        {
            c++;
        }

    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int c()
{
	int n;
	cin >> n;
	struct info{
		int x;
		int y;
		long long int h;
	};
	vector<info> infos(n);
	for(int i = 0; i < n; i++)
	{
		int x, y, h;
		cin >> x >> y >> h;
		info temp = {x, y, h};
		infos[i] = temp;
	}
	for(int cx = 0; cx <= 100; cx++)
	{
		for(int cy = 0; cy <= 100; cy++)
		{
			long long int h = -1;
			long long int upper = -1;
			bool flag = true;
			for(int i = 0; i < n; i++)
			{
				if(infos[i].h == 0)
				{
					long long int temp = abs(infos[i].x - cx) + abs(infos[i].y - cy);
					if(upper == -1)
					{
						upper = temp;
					}else{
						upper = min(upper, temp);
					}
				}else{
					long long int temp = infos[i].h + abs(infos[i].x - cx) + abs(infos[i].y - cy);
					if(h == -1 || h == temp)
					{
						h = temp;
					}else{
						flag = false;
						break;
					}
				}
			}
			if(flag)
			{
				if(upper == -1 || h <= upper)
				{
					cout << cx << " " << cy << " " << h << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> divides;
	for(int i = 1; i * i <= m; i++)
	{
		if(m % i == 0)
		{
			divides.push_back(i);
			if(i == m / i) continue;
			divides.push_back(m / i);
		}
	}
	sort(divides.begin(), divides.end());
	int i = 0;
	for(; i < divides.size(); i++)
	{
		if(n <= divides[i]) break;
	}
	cout << m / divides[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

ll mid(vector<ll> &a){
    ll n = a.size();
    if(n%2 == 0) return a[n/2]+a[(n-1)/2];
    else return a[n/2];
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll amid = mid(a);
    ll bmid = mid(b);
    int ans = 0;

    ans += bmid-amid+1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6412
#include <iostream>

using namespace std;

int main(){
  long long int N,K;
  cin >> N >> K;
  long long int a[100001]={0};
  int x,y;
  for(int i=0;i<N;i++){
    cin >> x >> y;
    a[x]+=y;
  }
  for(int i=1;i<100001;i++){
    if((K-=a[i])<=0&&a[i]!=0){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;


int main() {
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++){
    cin>>a[i];       
   }
   int aj=0;
   int max=0;
 for(int i=0;i<n;i++){
     if(max<a[i]){
         max=a[i];
     }
 }
 double mid_min=max;
 double tmp=0;
 for(int i=0;i<n;i++){
     if(a[i]==max){
         continue;
     }
     tmp=(max/2.0)-a[i];
     if(tmp<0){
         tmp=-1*tmp;
     }
     if(mid_min>tmp){
 aj=a[i];
 mid_min=tmp;
     }
     
 }

 cout<<max<<" "<<aj;
 
 
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
 
int main(void){
    double a,b,c,d,e,f;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)>0){
            f=(f-c/a*d)/(e-b/a*d);
            c=c/a-f*b/a;
            printf("%.3f %.3f\n",c,f);
    }
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int K;
  cin >> N >> K;
  if(K!=1){
    cout << N-K << endl;
  }
  else{
    cout << 0 << endl;
  }


  return 0;
}

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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    string s=to_string(n);
    char prev=s[0];
    for(int i=1;i<4;i++)
    {
        if(s[i]==prev){
            cout<<"Bad";
            return 0;
        }
        prev=s[i];
    }
    cout<<"Good";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

const ll MOD = 1e+9 + 7;
const int MAX_N = 1e+5 + 1;
const int MAX_M = 1e+5 + 1;

ll x[MAX_N], y[MAX_M];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) cin >> x[i];
    for (int i = 0; i < M; i++) cin >> y[i];
    vector<ll> sub_x, sub_y;
    for (int i = 0; i < N - 1; i++) {
        sub_x.push_back((i + 1) * (x[i + 1] - x[i]));
    }
    for (int i = 0; i < M - 1; i++) {
        sub_y.push_back((i + 1) * (y[i + 1] - y[i]));
    }
    for (int i = 1; i < sub_x.size(); i++) {
        sub_x[i] = (sub_x[i] + sub_x[i - 1]) % MOD;
    }
    for (int i = 1; i < sub_y.size(); i++) {
        sub_y[i] = (sub_y[i] + sub_y[i - 1]) % MOD;
    }
    ll sum_x = 0, sum_y = 0;
    for (int i = 0; i < sub_x.size(); i++) {
        sum_x = (sum_x + sub_x[i]) % MOD;
    }
    for (int i = 0; i < sub_y.size(); i++) {
        sum_y = (sum_y + sub_y[i]) % MOD;
    }
    cout << (sum_x * sum_y) % MOD << endl;
    return 0;
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#include <sys/time.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N, K, C;

vector<int> sub(const string &S) {
    int N = S.size();
    int cur = 0, last = -C-1;
    vector<int> res(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i - last > C && S[i] == 'o') ++cur, last = i;
        res[i+1] = cur;
    }
    return res;
}

void solve(const string &S) {
    const auto &left = sub(S);
    string T = S;
    reverse(T.begin(), T.end());
    const auto &right = sub(T);
    vector<int> res;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'x') continue;
        if (left[i] + right[N-i-1] < K) res.push_back(i+1);
    }
    for (auto v : res) cout << v << endl;
}

int main() {
    string S;
    cin >> N >> K >> C >> S;
    solve(S);
}

Measured memory_bytes: 4344
n,disup=map(int,input().split())
A=list(map(int,input().split()))
dis=0
ans=1
for i in A:
  dis+=i
  if dis>disup:
    print(ans)
    exit()
  if dis==disup:
    print(ans+1)
    exit()
  ans+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

#define PI acos(-1)

using namespace std;

typedef long double ld;

ld ans;
ld theta;
ld a, b, x;

int main(void) {
    scanf("%Lf %Lf %Lf", &a, &b, &x);

    if (x > (a * a * b) / 2.0) {
    	theta = atan((a * a * a) / (2.0 * (a * a * b - x)) );
    } else {
    	theta = atan(2.0 * x / (a * b * b));
    }

    ans = PI/2.0 - theta;
    ans = ans * 180.0 / PI;
   
    printf("%0.10Lf\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	string name1, name2;

	cin >> name1;
	cin >> name2;

	for (int i = 0; i < name1.size(); i++)
	{
		if (name1[i] != name2[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N;
    cin >> N;
    ll i;
    priority_queue<ll> q;
    
    for(i=0; i<N; i++) {
        ll a;
        cin >> a;
        q.push(-a);
    }
    
    while(q.size()>1) {
        ll u=-q.top(); q.pop();
        ll v=-q.top(); q.pop();
        v%=u;
        q.push(-u);
        if(v!=0) q.push(-v);
    }
    pt(-q.top());
    
}





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

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int t[N+2],v[N+2];
  t[0]=0;
  v[0]=0;
  REP(i,N){
    int ti;
    cin>>ti;
    t[i+1]=t[i]+ti;
  }
  REP(i,N)cin>>v[i+1];
  t[N+1]=t[N];
  v[N+1]=0;
  double v_max[t[N+1]*2+1];
  FOR(i,1,N+1){
    FOR(ti,t[i-1]*2,t[i]*2+1)v_max[ti]=v[i];
  }
  FOR(i,0,N+1){
    FOR(ti,t[i]*2,t[N+1]*2+1)v_max[ti]=min(v_max[ti],0.5*(ti-t[i]*2)+v[i]);
  }
  FOR(i,1,N+2){
    FOR(ti,0,t[i-1]*2+1)v_max[ti]=min(v_max[ti],0.5*(t[i-1]*2-ti)+v[i]);
  }
  double ans=0;
  REP(ti,t[N+1]*2+1)ans+=(v_max[ti]+v_max[ti+1])*0.25;
  cout<<fixed<<setprecision(3)<<ans<<endl;
  // REP(i,t[N+1]*2+1)cerr<<fixed<<setprecision(1)<<0.5*i<<": "<<v_max[i]<<endl;
  return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
res = 0
ia = []
ja = []
dia={}
dja={}
for i in range(n):
  dia[i+a[i]] = dia.get(i+a[i],0)+1
  dja[i-a[i]] = dja.get(i-a[i],0)+1
ans = 0
for di,nmi in dia.items():
  nmj = dja.get(di,0)
  ans += nmi*nmj

print(ans)


Measured memory_bytes: 130780
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    ll k;
    cin >> n >> k;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) sum += a[i];

    const int MAX = 60;
    vint bit(MAX, 0);
    rep(i, n) {
        ll tmp = a[i];
        int count = 0;
        while(tmp > 0) {
            if (tmp & 1) bit[count]++;
            tmp >>= 1;
            count++;
        }
    }

    ll ans = 0;
    rrep(i, MAX) {
        ll tmp = 0;
        if ((k >> i) & 1) {
            rep(j, MAX) {
                if (j > i) {
                    if ((k >> j) & 1) tmp += (1ll << j) * (n-bit[j]);
                    else tmp += (1ll << j) * bit[j];
                }
                else if (j == i) tmp += (1ll << j) * bit[j];
                else tmp += (1ll << j) * max(bit[j], n-bit[j]);
            }
        }
        ans = max(ans, tmp);
    }
    ll add = 0;
    rep(i, MAX) {
        if ((k >> i) & 1) add += (1ll << i) * max(bit[i], n-bit[i]);
        else add += (1ll << i) * bit[i];
    }
    ans = max(ans, add);

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

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

    long long a;
    cin >> a;

    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    return (1000 - N % 1000) %1000


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 76912
#include <iostream>

using namespace std;

string f(int a, int b, int c, int d, int e, int k) {

    if (abs(a - b) > k) {
        return ":(";
    }
    if (abs(a - c) > k) {
        return ":(";
    }
    if (abs(a - d) > k) {
        return ":(";
    }
    if (abs(a - e) > k) {
        return ":(";
    }
    if (abs(b - c) > k) {
        return ":(";
    }
    if (abs(b - d) > k) {
        return ":(";
    }
    if (abs(b - e) > k) {
        return ":(";
    }
    if (abs(c - d) > k) {
        return ":(";
    }
    if (abs(c - e) > k) {
        return ":(";
    }
    if (abs(d - e) > k) {
        return ":(";
    }

    return "Yay!";
}

int main() {

    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    string result = f(a, b, c, d, e, k);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
def DFS(x,y): # h*wの配列logの深さ優先探索
    global h,w,maze,log
    if not (x<0 or h<=x or y<0 or w<=y):
        if (y!=0 and maze[x][y-1]=="#") or (y!=w-1 and maze[x][y+1]=="#") or (x!=0 and maze[x-1][y]=="#") or (x!=h-1 and maze[x+1][y]=="#"):
            log[x][y]=1
    

def main():
    n,m = map(int,input().split())
    global h,w,maze,log
    maze=[]
    for _ in range(n):
        maze.append(list(input()))
    log = [[0 for _ in range(m)] for _ in range(n)]
    for i in range(n):
        for j in range(m):
            if maze[i][j]==".":
                log[i][j]=1
    h=n
    w=m
    for i in range(n):
        for j in range(m):
            if log[i][j]==0:
                DFS(i,j)
    for i in range(n):
        for j in range(m):
            if log[i][j]==0:
                print("No")
                return
    print("Yes")
    
main()

Measured memory_bytes: 40048
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string s,t;
  string ans = "";
  std::cin >> s >> t;
  for(int i=0;i<n;i++){
    ans+=s[i];
    ans+=t[i];
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int p; cin >> p;
			v.push_back(p);
		}

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

		int ans = 0, count = 0;
		for (int i = 0; i < n; ++i)
			if (++count >= m)
				count = 0;
			else
				ans += v[i];

		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

int n;
int a[200005];
multiset < int > s;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for ( int i = 0; i < n; i++ ){
		cin >> a[i];
		s.insert(a[i]);
	}

	for ( int i = 0; i < n; i++ ){
		s.erase(s.find(a[i]));
		auto it = s.end();
		it--;
		cout << (*it) << endl;
		s.insert(a[i]);
	}
	return 0;
}

Measured memory_bytes: 11776
import sys

MAX = 300001
candidate =[0 for i in xrange(MAX)]

for i in xrange(MAX):
    if i % 7 == 1 or i % 7 == 6:
        candidate[i] = 1

prime = []
for i in xrange(2, MAX):
    if candidate[i] == 1:
        prime.append(i)
        temp = i * 2
        while temp < MAX:
            candidate[temp] = 0
            temp += i

while True:
    n = int(sys.stdin.readline())
    if n == 1:
        break
    div = set()
    for p in prime:
        if n < p:
            break
        while n % p == 0:
#            n /= p
            div.add(p)
            break
    l_div = list(div)
    l_div.sort()
    print '{}:'.format(n),
    for d in l_div:
        print d,
    print

Measured memory_bytes: 7712
from bisect import bisect_left

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0

# a<b<c として、aとbを固定する
# 残る条件は c<a+b のみ
# aとbの固定方法がO(N^2), cの二分探索がO(logN)、結局O(N^2logN)
# 二分探索は事前にソートが必要

# ex. 2, 4(a), 4, 7(b), | 8, 9, 9 | (ここにa+b=11が挿入される), 12, 14
# cとして適切なのは8,9,9の3通り
# bisect_rightだとa+bが存在した時にバグる

for ai in range(n):
    for bi in range(ai + 1, n):
        ans += bisect_left(l, l[ai] + l[bi]) - bi - 1
print(ans)


Measured memory_bytes: 9236
#include<bits/stdc++.h>
using namespace std;
int fact(int n)
{
  int ans=1;
  for(int i=n;i>=1;i--)
  {
    ans*=i;
  }
  return ans;
}
int andy(int a[],int n)
{
	int count=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]!=0)
			count++;
	}
	return count;
}
int main()
{
  int n;
  cin>>n;
  int a[n];
  int b[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    cin>>b[i];
  }
  int x[n+1];
  for(int i=1;i<=n;i++){
  	x[i]=1;
  }
  int y[n+1];
  for(int i=1;i<=n;i++)
  {
  	y[i]=1;
  }

  int count=0;
  int r1=(a[0]-1)*fact(n-1);
  x[a[0]]=0;
  y[b[0]]=0;
  int r2=(b[0]-1)*fact(n-1);
  //int prev=a[0];
  //int prev1=b[0];
  for(int i=1;i<n-1;i++)
  {
    r1+=(andy(x,a[i])-1)*fact(n-1-i);
    x[a[i]]=0;
  }
  for(int i=1;i<n-1;i++){
    {
      r2+=(andy(y,b[i])-(1))*fact(n-1-i);
    }
    y[b[i]]=0;
  }
  cout<<abs(r2-r1)<<endl;
  return 0;
}
  

Measured memory_bytes: 256
program id
  implicit none
  integer :: n, m, a(100001,3) = 0, i, j
  read(*,*) n, m
  do i = 1, m
    read(*,*) a(i,1:2)
    a(i,3) = i
  end do
  call merge_sort(a(1:m,:),2)
  call merge_sort(a(1:m,:),1)
  i = 1
  do while (i <= m)
    j = i
    do while (a(j,1) == a(i,1))
      a(j,2) = j-i+1
      j = j+1
    end do
    i = j
  end do
  call merge_sort(a(1:m,:),3)
  do i = 1, m
    write(*,'(i6.6,i6.6)') a(i,1), a(i,2)
  end do
contains
  subroutine merge_sort(a,k)
    integer, intent(inout) :: a(:,:)
    integer, intent(in) :: k
    integer :: n, m, l, i, u
    n = size(a,1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(a(2*(i-1)*l+1:(2*i-1)*l,:),a((2*i-1)*l+1:u,:),k)
      end do
      l = 2*l
      m = (m+1)/2
    end do
  end
  subroutine merger(a1,a2,k)
    integer, intent(inout) :: a1(:,:), a2(:,:)
    integer, intent(in) :: k
    integer :: a(size(a1,1)+size(a2,1),size(a1,2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1,1)
    n2 = size(a2,1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (a1(i1,k) <= a2(i2,k)) then
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1 <= n1) then
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    a1 = a(1:n1,:)
    a2 = a(n1+1:n1+n2,:)
  end
end program id

Measured memory_bytes: 3876
using System;
using System.Collections.Generic;
using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            Console.WriteLine(abc[2]>=abc[0] && abc[2]<=abc[1] ? "Yes":"No");
        }
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}

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

int A, B, C;

int main () {
  cin >> A >> B >> C;

  cout << (A == B ? C : (A == C) ? B : A) << endl;
  return 0;
}


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

int main(void){
    // 入力
    double W,H,x,y;
    cin >> W >> H >> x >> y;

    // 回答
    double ans_1 = W*H/2.0;
    int ans_2=0;
    if(W/2.0 == x && H/2.0 == y) ans_2=1;

    cout << ans_1 << " " << ans_2;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
//#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)

void printVec(std::vector<int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec1(std::vector<string> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec2(std::vector<Int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

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

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

bool ispositive(Int num,int i) {
    if (num > 0) return true;
    if (num < 0) return false;
    else if(i==0) return false;
    else return true;
}

int main() {
    IOS;
    //std::ifstream in("01-04.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vector<int>l(n+n);
    for (int i=0;i<n+n;i++){
        cin>>l[i];
    }
    rsort(l);
    Int sum=0;
    for (int i=0;i<n;i++){
        sum+=l[i*2+1];
    }
    cout<<sum;


    cout << endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 256
N, T = map(int,input().split())
t = list(map(int,input().split()))
s = 0
start = 0
end = 0
for p in t:
  if end > p:
    end = p+T
  else:
    s += (end - start)
    start = p
    end = p+T
s += end - start
print(s)

Measured memory_bytes: 25196
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--) 
    {
        int n;
        cin>>n;
        ll sum=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                for(int k=1;k<=n;k++)
                sum+=__gcd(i,__gcd(j,k));
            }
        }
        cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 3652