akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char b; cin >> b;
    if(b == 'A') cout << 'T';
    if(b == 'T') cout << 'A';
    if(b == 'C') cout << 'G';
    if(b == 'G') cout << 'C';
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int w[n];
    int total = 0;
    int answer = INT32_MAX;
    REP(i,n){
        cin >> w[i];
        total += w[i];
    }
    int tmp = 0;
    REP(i,n){
        tmp += w[i];
        answer = min(abs(total-2*tmp),answer);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    set<int> st;
    rep(i,k){
        if(a+i > b)
            break;
        st.insert(a + i);
    }
    rep(i,k){
        if(b-i<a)
            break;
        st.insert(b - i);
    }
    for(auto e:st){
        cout << e << endl;
    }
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n; cin >> n;

    cout << "ABC" << n;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
void cmn(lint&x,lint y){if(x>y)x=y;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint h,w;std::cin>>h>>w;
    std::vector<std::vector<lint>>a(10,std::vector<lint>(10));
    for(lint i=0;i<10;i++){
    for(lint j=0;j<10;j++){
        std::cin>>a.at(i).at(j);
    }}
    for(lint i=0;i<10;i++){
    for(lint j=0;j<10;j++){
    for(lint k=0;k<10;k++){
        cmn(a.at(j).at(k),a.at(j).at(i)+a.at(i).at(k));
    }}}
    lint ans=0;
    for(lint i=0;i<h*w;i++){
        lint x;std::cin>>x;
        if(x==-1)continue;
        ans+=a.at(x).at(1);
    }
    std::cout<<ans<<'\n';
}


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

using namespace std;

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3128
#include <stdio.h>
#include <stdlib.h>


typedef struct _list_node list_node;
struct _list_node {
    int value;
    list_node *next;
};

list_node *root_node(list_node *node);

void union_tree(list_node *nodes, const int x, const int y) {
    if (elm_in_tree(nodes, x, y)) return;
    list_node *node = root_node(&nodes[x]);
    node->next = &nodes[y];
}

list_node *root_node(list_node *node) {
    while (node->next != NULL) {
        node = node->next;
    }
    return node;
}

int elm_in_tree(list_node *nodes, const int x, const int y) {
    // if (nodes[x].next == nodes[y].next) return 1;
    list_node *nx, *ny;
    nx = root_node(&nodes[x]);
    ny = root_node(&nodes[y]);
    return nx == ny;
}

int main(void) {
    int n, q, op, x, y, i;
    list_node *node;
    list_node *nodes;

    scanf("%d %d", &n, &q);
    nodes = (list_node *)malloc(sizeof(list_node) * n);

    for (i = 0; i < n; i++) {
        node = &(nodes[i]);
        node->value = i;
        node->next = NULL;
    }
    while (q--) {
        scanf("%d %d %d", &op, &x, &y);
        if (op == 0) {
            union_tree(nodes, x, y);
        }
        else { // op == 1
            printf("%d\n", elm_in_tree(nodes, x, y));
        }
    }

    free(nodes);

    return 0;
}

Measured memory_bytes: 700
n=int(input())
s=input()
ans=0
from collections import Counter
c=Counter(s)
for i in range(1000):
    x=str(i)
    if len(x)==1:
        x="00"+x
    elif len(x)==2:
        x="0"+x
    k=0
    for j in range(n):
        if s[j]==x[k]:
            k+=1
        if k==3:
            ans+=1
            break
        
print(ans)


Measured memory_bytes: 74404
s = input()
zenhan = s[:(len(s)-1)//2:]
san = s[(len(s)+3)//2-1:]
if s != s[::-1]:
    print('No')
elif zenhan != zenhan[::-1]:
    print('No')
elif san != san[::-1]:
    print('No')
else:
    print('Yes')

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

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  string ans = "NO";
  if (s1.at(0) == s2.at(2)) {
    if (s1.at(1) == s2.at(1)) {
      if (s1.at(2) == s2.at(0)) {
        ans = "YES";
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(){
	vector<int> d(5);
	rep(i,5) cin >> d[i];
	int sum = 0;
	rep(i,5){
		sum += ((d[i]+9)/10)*10;
	}
	int saa = 0;
	int ookii = 0;
	rep(i,5){
		int sa = 0;
		sa = ((d[i]+9)/10)*10 - d[i];
		if(saa < sa){
			ookii = d[i];
			saa = sa;
		}
	}
	cout << sum -((ookii+9)/10)*10 + ookii << endl;
}

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

        #define ll long long
        #define pb push_back
        #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
        #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
        #define sortV(v) sort(v.begin(),v.end())
        #define revV(v) reverse(v.begin(),v.end())
    

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        const int N = 3009;
       
    

        void solve(){
            string s1,s2;
            cin >> s1 >> s2;
            int size1 = s1.size();
            int size2 = s2.size();
            int answer = size2;
            for(int i=0;i<=size1-size2;i++){
                int cnt = 0;
                for(int j=0;j<size2;j++){
                    if(s1[i+j] != s2[j]) cnt++;
                }
                answer = min(answer,cnt);
            }
            cout << answer << endl;
        }  
        


        int main(){
            ios_base::sync_with_stdio(false);

         


            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
bool used[110][110];
int N;
int sum = 0;
int main(){
    cin >> N;
    int add = (N % 2 == 0 ? 1 : 0);
    sum = N * (N - 1) / 2;
    sum -= (N / 2);
    for(int i = 1; i <= N; i++){
        used[i][N - i + add] = true;
    }
    cout << sum << endl;
    for(int i = 1; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            if(!used[i][j]) cout << i << " " << j << endl; 
        }
    }
    return 0;
}

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

#define sz(v) int(v.size())
#define sqr(x) ((x) * (x))
#define range(i, n) for (int i = 0; i < n; ++i)

using ll = long long;
using ld = long double;
using namespace std;

template <class T1, class T2>
istream& operator >> (istream &in, pair <T1, T2> &a) {
    in >> a.first >> a.second;
    return in;
}

template <class T1, class T2>
ostream& operator << (ostream &out, pair <T1, T2> &p) {
    out << p.first << ' ' << p.second;
    return out;
}

template <class T>
istream& operator >> (istream &in, vector <T> &a) {
    for (T &i: a) in >> i;
    return in;
}

template <class T>
ostream& operator << (ostream &out, vector <T> &a) {
    out << sz(a) << '\n';
    for (T i : a) out << i << ' ';
    out << '\n';
    return out;
}

void fastIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
}

char a;

signed main() {
    fastIO();
    
    cin >> a;
    cout << (int(a) >= 97 ? "a" : "A");
    
    return 0;
}

Measured memory_bytes: 3604
from fractions import gcd
N=int(input())
L=list(map(int,input().split()))
l=[0]*(N+1)
r=[0]*(N+1)
ans=0
for i in range(N):
  l[i+1]=gcd(L[i],l[i])
  r[N-i-1]=gcd(L[N-i-1],r[N-i])
for i in range(N):
  ans=max(ans,gcd(l[i],r[i+1]))
print(ans)

Measured memory_bytes: 16144
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    ll n; cin >>n;

    vector<ll> march(5, 0);
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if(s[0] == 'M') {
            march[0] += 1;
        } else if (s[0] == 'A') {
            march[1] += 1;
        } else if (s[0] == 'R') {
            march[2] += 1;
        } else if (s[0] == 'C') {
            march[3] += 1;
        } else if (s[0] == 'H') {
            march[4] += 1;
        }
    }

    int count = 0;
    for (int i = 0; i < 5; i++) {
        if(march[i] > 0) {
            count += 1;
        } 
    }
    if(count <= 2) {
        cout << 0 << endl;
        return 0;
    } 

    ll res = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 5; k++) {
                if(i < j && j < k) {
                    res += (ll)march[i]*march[j]*march[k];
                } 
            }
        }
    }

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

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

int main() {
  long long a ,b ,c, k;
  cin >> a >> b>>c>>k;
  if (k == 0) {
    cout << a - b;
  } else if (k %2  == 1) {
    cout << b - a;
  } else {
    cout << a - b;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;
const int INF = 0xfffffff;

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

inline int dist(const P& a, const P& b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

int stoi(string s) {
	istringstream is(s);
	int res;
	is >> res;
	return res;
}

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

	for(int w, h; cin >> w >> h, w | h;) {
		int layer = 0;
		int num = 2;
		P g;
		vector<vector<pair<int, P> > > m(1);

		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				string in;
				cin >> in;

				if(in == "S")
					m[0].push_back(make_pair(0, make_pair(i, j)));

				else if(in == "G")
					g = make_pair(i, j);

				else if(isdigit(in[0])) {
					int digit = stoi(in);
					while(layer < digit) {
						m.push_back(vector<pair<int, P> >());
						++layer;
					}

					m[digit].push_back(make_pair(num++, make_pair(i, j)));
				}
			}
		}

		m.push_back(vector<pair<int, P> >(1, make_pair(1, g)));

		vector<int> dp(num, INF);
		dp[0] = 0;
		for(int i = 0; i + 1 < m.size(); ++i) {
			for(int j = 0; j < m[i].size(); ++j) {
				int from = m[i][j].first;
				P fpos = m[i][j].second;
				for(int k = 0; k < m[i + 1].size(); ++k) {
					int to = m[i + 1][k].first;
					P tpos = m[i + 1][k].second;
					chmin(dp[to], dp[from] + dist(fpos, tpos));
				}
			}
		}

		cout << dp[1] << endl;
	}


	return EXIT_SUCCESS;
}

Measured memory_bytes: 1368
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool solve(int f,int t,int o){
    return f+(t%2==0)>=o or (t%2 and f>=o) ;
}
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    //    std::ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
    int n; cin  >> n;
    vector<int>v(n);
    for(auto && e: v) cin >> e;
    int ans = 0;
    for(int i = 0; i+1 < n; ++i){
        if(v[i] % 2 and v[i+1])++v[i],--v[i+1];
    }
    for(auto e : v) ans += e /2;
    cout << ans << endl;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//define
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define elif else if
//vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
//queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
//mapdefine
#define mint map<int>
#define mc map<char>
//pairdefine
#define pint pair<int,int>
#define pis pair<int,str>
#define pic pair<int,char>
#define pci pair<char,int>
#define mod 100000007

string syugei(int N){
  string ST="b";
  for(int i=0;i<N;i++){
    if(i%3==0||i==0)ST="a"+ST+"c";
    else if(i%3==1||i==1)ST="c"+ST+"a";
    else if(i%3==2||i==2)ST="b"+ST+"b";
  }
  return ST;
}
//main
signed main(){
  int N,M,O,P,X,count=0,count2=0;
  double D;
  int c='A'-'a';
  char C;
  str S,T;
  cin>>N;
  cout<<N*N*N<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
long long  N=0;
long long  ans =0;
long long  i=0;
long long  b=0;

int main(){
  cin >> N;
  vector<long long> A(N);
  for(i=0;i<N;i++){
    cin >> A.at(i);
    A.at(i) -= i+1;
  }
  
  sort(A.begin(),A.end());
  b = A.at(N/2);
  
  for(i=0;i<N;i++){
    ans += abs(A.at(i) - b);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define rep(i,st,end)   for(int i=st;i<end;i++)
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void s_g_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	s_g_c();
	int n;
	cin >> n;
	char a[30];
	a[0] = 'z';
	for (int i = 1; i < 26; i++)
	{
		a[i] = 'a' + i - 1;
	}
	stack<char> v;
	while (n)
	{
		int rem = n % 26;
		v.push(a[rem]);
		if (rem == 0)
			n--;
		n = n / 26;
	}
	while (!v.empty())
	{
		cout << v.top();
		v.pop();
	}
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct P{
	int l,r,w;
}c[200005];
int n,m,a[200005],b[200005];
bool solve(int x){
	for(int i=1;i<=m;i++) b[i]=(a[i]>=x);
	int tot=0;
	for(int i=1;i<m;i++){
		if(b[i]!=b[i+1]) continue;
		tot++;c[tot].l=i;c[tot].w=b[i];
		while(b[i]==b[i+1]&&i<m) i++;
		c[tot].r=i;
	}
	if(!tot) return b[1];
	c[0].r=0;
	c[++tot].l=m+1;c[tot].r=1e9;
	for(int i=1;i<=tot;i++){
		int l=c[i-1].r+1,r=c[i].l-1;
		if(l>r) continue;
		int mid=l+r>>1;
		c[i-1].r=mid;c[i].l=mid+1;
	}
	for(int i=1;i<=tot;i++) if(c[i].l<=n&&c[i].r>=n) return c[i].w;
}
int main(){
	scanf("%d",&n);m=n+n-1;
	for(int i=1;i<=m;i++) scanf("%d",&a[i]);
	int l=1,r=m,mid,ans;
	while(l<=r){
		mid=l+r>>1;
		if(solve(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>M;
    vec po(N,0);
    bool yes = false;
    rep(i,M){
        cin>>A>>B;
        --A; --B;
        if(A == 0){
            if(po[B] == 1) yes = true;
            else po[B] = 1;
        }else if(B == N-1){
            if(po[A] == 1) yes = true;
            else po[A] = 1;
        }
    }
    cout<<(yes ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
}

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

void perm(int *elem, int n, function<void(int *)> f)
{
    do{
        f(elem);
    } while(next_permutation(elem, elem + n));
}

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

    int p[n], q[n];
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];

    int pe[n];
    for(int i = 0; i < n; i++) pe[i] = i + 1;
    
    int count = 0;
    int f = -1, s = -1;
    perm(pe, n, [&](int *t){
        bool f_flag = true, s_flag = true;
        for(int i = 0; i < n; i++)
        {
            if(t[i] != p[i]) f_flag = false;
            if(t[i] != q[i]) s_flag = false;
        }
        count++;
        if(f_flag) f = count;
        if(s_flag) s = count;
    });
    cout << abs(f - s) << endl;
}

Measured memory_bytes: 256
# abc 152 e
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(readline().strip())
A = list(map(int, readline().split()))

from fractions import gcd
def lcm(a, b):
    return (a * b) // gcd(a, b)

lcm_ = 1  # 倍数を出したいので初期値は1
for i in range(N):
    lcm_ = lcm(lcm_, A[i])

ans = 0
for i in range(N):
    ans += lcm_ * pow(A[i], MOD-2, MOD)

print(ans % MOD)

Measured memory_bytes: 5616
let _ =
  let cipher str = String.map (fun c -> if c = 'z' then 'a' else if c >= 'a' && c <= 'y' then char_of_int (int_of_char c + 1) else c) str in
  let elem s1 s2 =
    let l = String.length s2 in
    let rec iter i = 
      try
        let s = String.sub s1 i l in
        if String.compare s s2 = 0 then true else iter (i + 1)
      with
        Invalid_argument _ -> false in
    iter 0 in
  let rec iter str =
    if (elem str "this") || (elem str "that") || (elem str "the") then print_endline str
    else iter (cipher str) in
  try
    while true do
      let str = read_line () in
      iter str
    done
  with
    End_of_file -> ()

Measured memory_bytes: 2188
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;

using namespace std;

ll n, m, k;

int main(){
    cin >> n;
    n = 10000 - n;
    cout << (n % 1000) << endl;
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 3090 ,OO = 1e9;
ll a[N] , n , dp[N][N] , sum;
ll Dp(int i , int j){

if(i>j){

    return 0;
}
ll &ret = dp[i][j];
if(ret != -1) return ret;
ret=0;
ret = max(a[i] - Dp(i+1 , j)  , a[j] - Dp(i , j-1));

return ret;
}
int main()
{
    cin >> n;
    for(int i=0;i<n;i++){

        cin >> a[i] , sum+=a[i];
    }
    memset(dp , -1 , sizeof dp);
    cout << Dp(0 , n-1);
    return 0;
}


Measured memory_bytes: 75008
p = 10**9 + 7

def pow_mod(p,a,n):
    res = 1
    while n > 0:
        if n % 2 == 1:
            res = (res * a) % p
        n = n // 2
        a = (a*a)%p
    return res


def comb_mod(n,k):
    global fac
    res = fac[n] * pow_mod(p,fac[k],p-2) * pow_mod(p,fac[n-k],p-2) % p
    return res

X,Y = map(int,input().split())
X,Y = max(X,Y),min(X,Y)
n = (X+Y)//3

fac = [1]
foo = 1
for i in range(1,n+1):
    foo = (foo*i)%p
    fac.append(foo)

k = 2*n - X
if (X+Y)%3 != 0 or n < k or k < 0:
    ans = 0
else:
    ans = comb_mod(n,k)

print(ans)

Measured memory_bytes: 29484
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(true){
    if(c-b<=0){
      cout << "Yes";
      break;
	}else{
      c -= b;
    }
    
    if(a-d<=0){
      cout << "No";
      break;
    }
    else{
      a -= d;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0){
        cout<<"Possible";
    }else{
        cout<<"Impossible";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        String ans = "";
        for (int index = 0; index < s.length; index++) {
            switch (s[index]) {
            case '0':
                ans += "0";
                break;
            case '1':
                ans += "1";
                break;
            case 'B':
                ans = ans.substring(0, Math.max(0,ans.length() - 1));
                break;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 14804
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.rank = 0
        self.elements_count = 1


class DisjointSet:
    def __init__(self, nodes):
        self.nodes = nodes

    def find_set(self, key):
        pivot = self.nodes[key]
        while pivot.key != pivot.parent.key:
            pivot = pivot.parent
        self.nodes[key].parent = pivot
        return pivot.key

    def elements_count(self, key):
        repr_key = self.find_set(key)
        return self.nodes[repr_key].elements_count

    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)

    def unite(self, x, y):
        y_root = self.find_set(y)
        x_root = self.find_set(x)
        if self.nodes[x].rank > self.nodes[y].rank:
            self.nodes[y_root].parent = self.nodes[x_root]
            self.nodes[x_root].elements_count += self.nodes[y_root].elements_count
        elif self.nodes[x].rank < self.nodes[y].rank:
            self.nodes[x_root].parent = self.nodes[y_root]
            self.nodes[y_root].elements_count += self.nodes[x_root].elements_count
        else:
            self.nodes[x_root].parent = self.nodes[y_root]
            self.nodes[y_root].rank = self.nodes[y_root].rank + 1
            self.nodes[y_root].elements_count += self.nodes[x_root].elements_count


def comb_pair(n):
    return (n * (n - 1)) // 2


def m():
    N, M = [int(i) for i in input().split()]
    nodes = [Node(i) for i in range(0, N)]
    for node in nodes:
        node.parent = node
    ds = DisjointSet(nodes)

    convenience = [0] * (M + 1)
    inputs = [input().split() for _ in range(M)]
    inputs = [(int(x[0]) - 1, int(x[1]) - 1) for x in inputs]
    reversed_inputs = list(reversed(inputs))
    for i in range(M):
        a, b = reversed_inputs[i]
        if ds.same(a, b):
            convenience[i+1] = convenience[i]
            next
        else:
            before = comb_pair(ds.elements_count(a)) + comb_pair(ds.elements_count(b))
            ds.unite(a, b)
            after = comb_pair(ds.elements_count(a))
            diff = after - before
            convenience[i+1] = convenience[i] + diff
    maximum = convenience[-1]
    for c in convenience[-2::-1]:
        print(maximum - c)


if __name__ == '__main__':
    m()


Measured memory_bytes: 76516
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long 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 long long INF = 1LL << 60;

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

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

  cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        
        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var A = cin.SplitReadL();

            long ans = 0;
            var d = new long[N + 1];
            d[0] = 0;
            for (var i = 0; i < N; i++) d[i + 1] = d[i] + A[i];

            long cur = 0;
            int l = 0;
            for(var r = 0; r < N; r++)
            {
                cur ^= A[r];
                while (cur != d[r + 1] - d[l])
                {
                    cur ^= A[l];
                    l++;
                }
                ans += r - l + 1;
            }


            Console.WriteLine(ans);
            
            //Console.Out.Flush();
        }

    }

   

    

    

    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 33244
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;


int main(){
    long long N,M; cin >> N >> M;

    cout << (N*(N-1))/2 + (M*(M-1))/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e2+10;
const ll mod = 1e9+7;


int main()
{
	int n,m;
	cin>>n>>m;
	ll ans = 0;
	for(int i=1;i<=n-1;i++)
	{
		ans+=i;
	}
	for(int i=1;i<=m-1;i++)
	{
		ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}
	

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

int main() {
    int N, X; cin >> N >> X;
    vector<int> D(N + 1);
    D[0] = 0;
    for (int i = 0; i < N; ++i) {
        int x; cin >> x;
        D[i + 1] = D[i] + x;
    }
    int ans = 0;
    for (int i = 0; i <= N; ++i) {
        if (D[i] <= X) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static bool checking(int[] a)
    {
        return (a[0] + a[1] == a[2] || a[1] + a[2] == a[0] || a[2] + a[0] == a[1]);
    }

    static int Main()
    {
        int res;

        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                res = i * j;

                Console.WriteLine("{0}x{1}={2}", i, j, res);
            }
        }

        



        return 0;
    }
}
       

Measured memory_bytes: 5592
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = int(1 << 18);

int A[MAXN];
pii dp[MAXN];

void update(int idx, pii &cur) {
     if (idx == cur.first || idx == cur.second) return;
     if (cur.first == cur.second) {
        int fst = idx, scd = cur.first;
        if (A[cur.first] > A[idx]) swap(idx, cur.first);
        cur.first = fst;
        cur.second = scd;
     }
     if (A[idx] >= A[cur.first]) {
         cur.second = cur.first;
         cur.first = idx;
     } else if (A[idx] >= A[cur.second]) {
         cur.second = idx;
     }
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < (1 << N); i++) {
        scanf("%d", &A[i]);
        for (int j = 0; j < N; j++) {
            if ((1 << j) & i) {
               int tmp = i ^ (1 << j);
               update(i, dp[i]);
               update(dp[tmp].first, dp[i]);
               update(dp[tmp].second, dp[i]);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i < (1 << N); i++) {
        ans = max(ans, A[dp[i].first] + A[dp[i].second]);
        printf("%d\n", ans);
    }
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 4000

ll dp[MAXN+1][MAXN+1];

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

  bool f = n%2;
  rep(l, n)rep(i, n-l){

    // n奇数かつ今見ている長さが奇数なら先手番
    // n偶数かつ今見ている長さが偶数なら先手番
    bool isFirst = (f && !(l%2)) || (!f && (l%2));
    if(isFirst){
      dp[i][i+l] = max<ll>(dp[i][i+l-1] + a[i+l], dp[i+1][i+l] + a[i]);
    }else{
      dp[i][i+l] = min<ll>(dp[i][i+l-1] - a[i+l], dp[i+1][i+l] - a[i]);
    }
  }

  cout<<dp[0][n-1]<<endl;

  return 0;

  rep(i, n){
    rep(j, n)cout<<dp[i][j]<<' ';
    cout<<endl;
  }

  return 0;
}


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

int main() {
    int D; cin >> D;
    vector<int> c(26);
    for (int i=0; i<26; ++i) cin >> c[i];
    vector<vector<int> > s(D, vector<int>(26));
    for (int i=0; i<D; ++i) {
        for (int j=0; j<26; ++j) {
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    for (int i=0; i<D; ++i) cin >> t[i];
    /*
    long long now = 0;
    vector<int> last(26, -1);
    for (int i=0; i<D; ++i) {
        now += s[i][t[i] - 1];
        last[t[i] - 1] = i;
        for (int j=0; j<26; ++j) {
            now -= c[j] * (i - last[j]);
        }
    }
    */
    int m; cin >> m;
    vector<int> d(m), q(m);
    for (int i=0; i<m; ++i) cin >> d[i] >> q[i];
    for (int i=0; i<m; ++i) {
        long long sum = 0;
        t[d[i] - 1] = q[i];
        vector<int> last(26, -1);
        for (int j=0; j<D; ++j) {
            sum += s[j][t[j] - 1];
            last[t[j] - 1] = j;
            for (int k=0; k<26; ++k) {
                sum -= c[k] * (j - last[k]);
            }
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 3924
/*
[abc126] B - YYMM or MMYY
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int S;

bool maybe_month(int a) { return 0 < a && a <= 12; }

string solve() {
    bool a = maybe_month(S / 100);
    bool b = maybe_month(S % 100);
    if (a && b) {
        return "AMBIGUOUS";
    }
    if (!a && !b) {
        return "NA";
    }
    if (a) {
        return "MMYY";
    }
    return "YYMM";
}

int main() {
    cin >> S;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {a} else {gcd(b, a % b)}
}

fn run() {
    input! {
        n: usize,
        m: i64,
        a: [i64; n],
    }
    let mut lcm = 1;
    for &a in a.iter() {
        if lcm > m {
            break;
        }
        let x = a / 2;
        lcm = lcm * x / gcd(lcm, x);
    }
    if lcm > m {
        println!("0");
        return;
    }
    for &a in a.iter() {
        if (lcm / (a / 2)) % 2 == 0 {
            println!("0");
            return;
        }
    }
    let ans = (m / lcm - 1) / 2 + 1;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
//atRto TLH
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define ll long long
const ll MOD = 1e9 + 7;
#define ln '\n'
#define all(x) (x).begin(), (x).end()
#define rotate rotate(vec.begin(), vec.begin() + k, vec.end())
#define alloc(v) set<int> S(all(v))
#define bitset(n)  bitset<20>(n)
#define Min min({a, b, c, d})
 
      const ll INF=2*1e5;
      char tt[2003][2003];
    
     int vis[107];
     //vector<ll>v[107];
    int size=0;
 

 
 void solve(){
 
 }
    
 
    int main() {
      IOS;
    #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif
   
   ll n,k;
   cin>>n>>k;
   ll a[n];
    ll dp[n];

    for(ll i=0;i<n;i++) cin>>a[i];
    
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    //ll  minn=min(abs(a[2]-a[0])+dp[0],abs(a[2]-a[1]+dp[1]));
   
   
    for(ll i=2;i<n;i++){
      dp[i]=INT_MAX;
      for(ll j=0;j<=min(k,i);j++){
        dp[i]=min(abs(a[i]-a[i-j])+dp[i-j],dp[i]);
        
      }
    }
  cout<<dp[n-1]<<ln;
  return 0;
}


Measured memory_bytes: 5132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll MOD = 1e9+7;
const ll N = 1e7+10;
ll f[N], rf[N];
ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    for(int i = 1; i < N; i++) f[i] = (f[i - 1] * i) % MOD;
    rf[N - 1] = inv(f[N - 1]);
    for(int i = N-2; i >= 0; i--) rf[i] = (rf[i + 1] * (i + 1)) % MOD;
}
ll C(int n, int k) {
    if(k < 0 || n < k) return 0;
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!^(-1)
    ll c = rf[k]; // = k!^(-1)
    ll bc = (b * c) % MOD;
    return (a * bc) % MOD;
}
ll p(int n, int k) {
    if (k < 0 || n < k) return 0;
    ll a = f[n]; // = n!
    ll b = rf[n - k]; // = (n-k)!^(-1)
    return (a * b) % MOD;
}
ll H(int n, int k) {
    if (n == 0 && k == 0) return 1;
    return C(n + k - 1, k);
}
ll mod_pow(ll x, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n & 1)
        {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    init();
    int k;
    string s;
    cin >> k >> s;
    int n = s.size();
    int m = k + n;
    vector<ll> tf(m+1, 0);
    vector<ll> ts(m+1, 0);
    tf[0] = 1;
    ts[0] = 1;
    for(int i = 0; i < m; i++)
    {
        tf[i+1] = tf[i] * 25 % MOD;
        ts[i+1] = ts[i] * 26 % MOD;
    }
    ll ans = 0;
    for(int i = 1; i <= m+1; i++)
    {
        if(k-i+1 < 0) break;
        ll tmp = (C(m-i, n-1) * tf[k-i+1]) % MOD;
        tmp = (tmp * ts[i-1]) % MOD;
        ans = (ans+tmp) % MOD;
    }
    cout << (ans+MOD) % MOD << endl;
}


Measured memory_bytes: 191752
#include <stdio.h>

int main()
{
	int i, N, L[2001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(L[i]));
		
	int j, k, l;
	long long count[1001] = {};
	for (i = 1; i <= N; i++) count[L[i]]++;
	
	long long ans = 0, tmp[3];
	for (i = 1; i <= 1000; i++) {
		if (count[i] == 0) continue;
		tmp[0] = count[i]--;
		for (j = i; j <= 1000; j++) {
			if (count[j] == 0) continue;
			tmp[1] = count[j]--;
			l = (i + j - 1 < 1000)? i + j - 1: 1000;
			for (k = j; k <= l; k++) {
				if (count[k] == 0) continue;
				tmp[2] = tmp[0] * tmp[1] * count[k];
				if (i == j || j == k) tmp[2] /= 2;
				if (i == j && j == k) tmp[2] /= 3;
				ans += tmp[2];
			}
			count[j]++;
		}
		count[i]++;
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int count[4][3][10]={0},n=0,b,f,r,v,i;
	char sikiri[20];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		if(v>=0){
			count[b-1][f-1][r-1]+=v;
		}else{
			count[b-1][f-1][r-1]+=v;
		}
	}
	for(i=0;i<20;i++){
		sikiri[i]='#';
	}
	for(b=0;b<4;b++){
		for(f=0;f<3;f++){
			for(r=0;r<10;r++){
				printf(" %d",count[b][f][r]);
			}
			printf("\n");
		}
		if(b<3){
			for(i=0;i<20;i++){
				printf("%c",sikiri[i]);
				if(i==19){
					printf("\n");
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]
sort_A = sorted(A)
max_val = max(A)
second_val = sort_A[bisect.bisect_right(sort_A, max_val) - 2]

for i in range(N):
    if A[i] == max_val:
        print(second_val)
    else:
        print(max_val)

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

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

    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

    sort(data.begin(), data.end());

    cout << data.at(n - 1) - data.at(0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int T = sc.nextInt();
		int S = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
		}
		int[][] dp = new int[T + 1][N + 1];
		for (int i = 0; i < T; ++i) {
			for (int j = 0; j < N; ++j) {
				int n = i + B[j];
				if ((S <= i || n <= S) && n <= T) {
					dp[n][j + 1] = Math.max(dp[n][j + 1], dp[i][j] + A[j]);
				}
				dp[i][j + 1] = Math.max(dp[i][j + 1], dp[i][j]);
				dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j + 1]);
			}
		}
		int ans = 0;
		for (int i = 0; i <= T; ++i) {
			for (int j = 0; j <= N; ++j) {
				ans = Math.max(ans, dp[i][j]);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 85340
import sys, bisect

N = int(input())
L = list(map(int, sys.stdin.readline().rsplit()))
L.sort()

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        a, b = L[i], L[j]
        c_l = bisect.bisect_left(L, a + b)
        
        if c_l <= j:
            continue
        
        # print(i, j, c_l)
        res += c_l - (j + 1)

print(res)


Measured memory_bytes: 9292
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int x, y, z;
  cin >> x >> y >> z;
  int n = x+y+z;
  VVI coin(n, VI(3, 0));
  REP(i, n) cin >> coin[i][0] >> coin[i][1] >> coin[i][2];

  sort(ALL(coin), [&](vector<int> l, vector<int> r) -> bool {
    return l[0] - l[1] < r[0] - r[1];
  });

  // cout << coin << endl;

  priority_queue<PII, vector<PII>, greater<PII>> que;
  // i人目まで見たときに左側からもらえるコインの枚数
  VI left(n);
  int sil = 0, bro = 0;
  REP(i, y) {
    que.push({coin[i][1]-coin[i][2], i});
    sil += coin[i][1];
  }
  left[y-1] = sil;
  FOR(i, y, n-x) {
    que.push({coin[i][1]-coin[i][2], i});
    sil += coin[i][1];
    PII p = que.top(); que.pop();
    sil -= coin[p.second][1];
    bro += coin[p.second][2];
    left[i] = sil + bro;
  }

  reverse(ALL(coin));
  while(que.size()) que.pop();
  VI right(n);
  int gol = 0; bro = 0;
  REP(i, x) {
    que.push({coin[i][0]-coin[i][2], i});
    gol += coin[i][0];
  }
  right[x-1] = gol;
  FOR(i, x, n-y) {
    que.push({coin[i][0]-coin[i][2], i});
    gol += coin[i][0];
    PII p = que.top(); que.pop();
    gol -= coin[p.second][0];
    bro += coin[p.second][2];
    right[i] = gol + bro;
  }

  // cout << left << endl << right << endl;
  int ans = 0;
  FOR(i, y-1, n-x) {
    // cout << left[i] << " " << right[n-i-1] << endl;
    chmax(ans, left[i] + right[n-i-2]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9460
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program
{


    static void Main(string[] args)
    {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

        //int val = int.Parse(Console.ReadLine());
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //string str = Console.ReadLine();
        //string[] strs = Console.ReadLine().Split(cs);

        //string res="";
        //int res = 0; ;
        //int t = int.Parse(Console.ReadLine());
        //string str = Console.ReadLine();
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //int n = int.Parse(Console.ReadLine());
		//string res="";
		string res = "";
		int n = int.Parse(Console.ReadLine());
		string str = Console.ReadLine();
		int k = int.Parse(Console.ReadLine());

		for ( int i = 0; i < str.Length; i++ ) {
			if ( str[i] == str[k-1] ) { res += str[k-1].ToString(); ; } else { res += "*"; }
		}
		
			Console.WriteLine(res);


        return;
    }

    //　String[]  ----->  int[]
    static int[] parseAry(string[] str)
    {
        int[] nums = new int[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
        return nums;
    }
    //　String[]  ----->  long[]
    static long[] parseAryL(string[] str)
    {
        long[] nums = new long[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
        return nums;
    }


    //文字列を1文字ずつString[]に入れる
    static string[] strAry(String str)
    {
        string[] re = new string[str.Length];
        for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
        return re;
    }

}


Measured memory_bytes: 11092
alp=[chr(i) for i in range(97, 97+26)]
#文字コードで並び替える
#それぞれ一つずつにする
#print(alp)
s=sorted(set(list(input())))

for i in range(len(s)):
    if s[i]!=alp[i]:
        print(alp[i])
        break
    if i==len(s)-1:
        if len(s) != len(alp):
            print(alp[i+1])
        else:
            print("None")


Measured memory_bytes: 3956