akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	int a[n];
	int cnt = 0;
	zip(i, 0, n)
	{
		cin >> a[i];
		if (a[i] % 2 == 0)
			cnt++;
	}
	if (cnt == n)
		cout << "second" << en;
	else
		cout << "first" << en;

	return 0;
}



Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
const long long mod = 1000000007;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
int main(){
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int n;
    cin>>n;
    while(n>0){
        if((n%10)==7)
            break;
        n/=10;
    }
    if(n)
        cout<<"Yes";
    else
        cout<<"No";
return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

int main() {
    int n;
    map<string, int> products;
    vector<pair<string, int> > p;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        string name;
        int num;
        cin>>name>>num;

        if (products[name] > 0) {
            products[name] += num;
        }
        else {
            products[name] = num;
        }
    }

    for (auto& e : products) {
        p.push_back(make_pair(e.first, e.second));
    }

    sort(p.begin(), p.end(), [](auto& lhs, auto& rhs) -> bool {
            if (lhs.first.size() < rhs.first.size()) return true;
            else if (lhs.first.size() > rhs.first.size()) return false;
            else if (lhs.first < rhs.first) return true;
            else return false;
            });


    for (auto& e : p) {
        cout<<e.first<<" "<<e.second<<endl;
    }

    return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
long N,K,A[1<<17],M=1e9+7,F[1<<17],I[1<<17],i,r;
long C(long a,long b){return F[a]*I[b]%M*I[a-b]%M;}
long P(long a,long b){return b?P(a*a%M,b/2)*(b%2?a:1)%M:1;}
int main(){
	cin>>N>>K;
	F[0]=1;
	for(i=1;i<=N;i++)F[i]=F[i-1]*i%M;
	I[N]=P(F[N],M-2);
	for(i=N;i--;)I[i]=I[i+1]*(i+1)%M;
	for(i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	for(i=K-1;i<N;i++){
		(r+=A[i]*C(i,K-1))%=M;
		(r-=A[N-i-1]*C(i,K-1))%=M;
	}
	cout<<r%M<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int func(int x){
  if(x%100!=0) return 0;
  return func(x/100)+1;
}

int main(){
  string s;
  ll k;
  cin>>s>>k;
  int cnt=0;
  rep(i,len(s)){
    if(s[i]=='1') cnt++;
    if(s[i]!='1') break; 
  }
  if(k>cnt) cout<<s[cnt]<<endl;
  if(k<=cnt) cout<<1<<endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    string n;
	long long int s=0, i;
    cin>>n;
    for(i=0; i<n.length(); i++)s+=n[i]-'0';
    s%9?cout<<"No\n":cout<<"Yes\n";

    return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long
const int maxn=5e5+10;
int ans=0;
ll read()
{
	char c=getchar();
	ll x=0;
	int flag=1;
	while(c<'0'||c>'9')
	{
		if(c=='-')flag=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-48;
		c=getchar();
	}
	x*=flag;
	return x;
}
int n,a,b;
int main()
{
	n=read(),a=read(),b=read();
	if(abs(a-b)%2==0)cout<<"Alice";
	else cout<<"Borys";
	return 0;
}

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

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

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
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; }

int main(void) {
    int n; cin >> n;
    if (n % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - (n % 1000) << endl;
}

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

using ll = long long;

int grid[102][102];
int dp[2][102][102];

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int h,w;
	cin>>h>>w;

	for(int i=1; i<=h; i++)
	{
		string s;
		cin>>s;

		for(int j=1; j<=w; j++)
		{
			if(s[j-1]=='.') grid[i][j]=1;
			else grid[i][j]=2;
		}
	}

	if(grid[1][1]==1)
	{
		// initially white

		dp[0][1][1]=0;
		dp[1][1][1]=1e9;
	}

	else
	{
		dp[0][1][1]=1e9;
		dp[1][1][1]=1;
	}

	for(int i=1; i<=h; i++)
	{
		for(int j=1; j<=w; j++)
		{
			if(i==1&&j==1) continue;
			dp[0][i][j]=1e9;
			dp[1][i][j]=1e9;

			if(i>1)
			{
				dp[0][i][j]=min(dp[0][i][j],dp[1-int(grid[i][j]==grid[i-1][j])][i-1][j]);
				dp[1][i][j]=min(dp[1][i][j],dp[int(grid[i][j]==grid[i-1][j])][i-1][j]+int(grid[i][j]!=grid[i-1][j]));
			}

			if(j>1)
			{
				dp[0][i][j]=min(dp[0][i][j],dp[1-int(grid[i][j]==grid[i][j-1])][i][j-1]);
				dp[1][i][j]=min(dp[1][i][j],dp[int(grid[i][j]==grid[i][j-1])][i][j-1]+int(grid[i][j]!=grid[i][j-1]));
			}
		}
	}

	// for(int i=1; i<=h; i++)
	// {
	// 	for(int j=1; j<=w; j++)
	// 	{
	// 		cout << "(" << dp[0][i][j] << ", " << dp[1][i][j] << ") ";
	// 	}
	// 	cout << endl;
	// }

	cout << min(dp[0][h][w],dp[1][h][w]) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf=(1LL<<60);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> a(5);
  for(auto&& o:a) cin >>o;
  for(int i=0;i<5;i++){
    if(a[i]==0){
      cout <<i+1<<'\n';
      return(0);
    }
  }
  return (0);
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
 
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
 
n = I()
a = LI()
if n == 0:
    if a[0] == 1 or a[0] == 0:
        print(1)
        quit()
    else:
        print(-1)
        quit()
for i in range(n):
    if a[i] > 2**i - 1:
        print(-1)
        quit()
if a[-1] > 2**n:
    print(-1)
    quit()

lst = [1]
for i in range(1, n+1):
    l = lst[-1] - a[i-1]
    if l <= 0:
        print(-1)
        quit()
    lst.append(2*l)
if lst[-1] - a[-1] < 0:
    print(-1)
    quit()

i = n-1
tmp = a[-1]
ans = 0
lst2 = [a[-1]]
while i >= 0:
    tmp += a[i]
    tmp = min(tmp, 2**i)
    lst2.append(tmp)
    i -= 1
lst2 = lst2[::-1]
for i in range(n+1):
    ans += min(lst[i], lst2[i])
print(ans)


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

// 小数点以下桁数
// fixed << setprecision(i)

int gcd(int a,int b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//   for(auto x : v) cout << x << " "; cout << "\n";    // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

int main()
{
  int n, p, ans = 0, min_p = 200000;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> p;
    if (p <= min_p)
      ans++;
    min_p = min(p, min_p);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100010;

ll arr[MAX_N+2],arr2[MAX_N+2],arr3[MAX_N+2],arr4[MAX_N+2],vsum[MAX_N+2],N,C,x[MAX_N+2],v[MAX_N+2];


int main(){
  cin>>N>>C;
  x[0]=0;v[0]=0;
  for(ll i=1;i<=N;i++){
    cin>>x[i]>>v[i];
  }
  x[N+1]=C;v[N+1]=0;

//  for(ll i=0;i<=N;i++){
//    cout<<x[i]<<" "<<v[i]<<endl;
//  }
  ll vt=0;
  for(ll i=0;i<=N;i++){
    vt+=v[i];
    vsum[i]=vt;
    arr[i]=vt-x[i];
    arr3[i]=vt-2*x[i];
  }

//  for(ll i=0;i<=N;i++){
//    cout<<vsum[i]<<" "<<arr[i]<<endl;
//  }

  ll armax=arr[0],armax4=0;
  for(ll i=0;i<=N;i++){
    armax=max(armax,arr[i]);
    arr2[i]=armax;
    armax4=max(armax4,arr3[i]);
    arr4[i]=armax4;
  }
//  for(ll i=0;i<=N;i++){
//    cout<<arr2[i]<<endl;
//  }

  ll ans=arr2[N];
  for(ll i=0;i<N;i++){
    ll tmp1=(vsum[N]-vsum[i])-2*(C-x[i+1])+arr2[i];
    ll tmp2=(vsum[N]-vsum[i])-(C-x[i+1])+arr4[i];
//    cout<<tmp<<endl;
    ans=max(ans,max(tmp1,tmp2));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int ma=0,ma2=0;
  for(i=0;i<n;i++){
    if(ma<a[i]){
      ma=a[i];
      cnt=i;
    }
  }
  for(i=0;i<n;i++){
    if(ma2<a[i] && i!=cnt){
      ma2=a[i];
    }
  }
  if(ma2==0)ma2=ma;
  for(i=0;i<cnt;i++){
    cout<<ma<<endl;
  }
  cout<<ma2<<endl;
  for(i=cnt+1;i<n;i++){
    cout<<ma<<endl;
  }
}

Measured memory_bytes: 2432
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }

    val target = getNodeToInsert(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 287676
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(void){
    int res=0;
    vector<pair <int,int>> a;
    a.resize(5);
    for(int i=0;i<5;i++){
        cin >> a[i].second;
    }
    for(int i=0;i<5;i++){
        a[i].first = a[i].second % 10;
        if(a[i].first == 0){
            res += a[i].second;
            a[i].first = 10;
        }
    }
    sort(a.begin(),a.end());
    for(int i=4;i>=0;i--){
        if(a[i].first == 10)continue;
        res += a[i].second;
        if(i != 0){
            while(res % 10 != 0)res++;
        }
    }
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;
int main() {
    string s;
    cin>>s;
    bool ans =false;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) ans=true;
    if(ans) puts("Yes");
    else puts("No");
    return 0;

}



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


int main(){

int n , m ;
string s[123];

cin>>n>>m;
for(int i=0;i<n;i++)cin>>s[i];

for(int i=0;i<m+2;i++)cout<<"#"; cout<<endl;
for(int i=0;i<n;i++)cout<<"#"<<s[i]<<"#"<<endl;
for(int i=0;i<m+2;i++)cout<<"#"; cout<<endl;

return 0;
}


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

int x[3], y[3], xc, yc, r, d[4];
const double INF = 10000000;

bool in() {
	bool f[3];

	for (int i = 0; i < 3; i++) {
		int j = (i + 1) % 3, k = (i + 2) % 3;
		f[i] = ((x[i] - x[j]) * (yc - y[i]) - (y[i] - y[j]) * (xc - x[i])) * ((x[i] - x[j]) * (y[k] - y[i]) - (y[i] - y[j]) * (x[k] - x[i])) >= 0;
	}

	return f[0] && f[1] && f[2];
}

double minds() {
	double g[3];
	for (int i = 0; i < 3; i++) {
		int j = (i + 1) % 3;

		if ((x[j] - x[i]) * (xc - x[i]) + (y[j] - y[i]) * (yc - y[i]) >= 0
			&& (x[i] - x[j]) * (xc - x[j]) + (y[i] - y[j]) * (yc - y[j]) >= 0)
			g[i] = pow((y[j] - y[i]) * xc - (x[j] - x[i]) * yc - x[i] * y[j] + y[i] * x[j], 2) / (pow(y[j] - y[i], 2) + pow(x[j] - x[i], 2));
		else
			g[i] = INF;
	}
		return min({ g[0], g[1], g[2] });
}

int main()
{
	cin >> x[0] >> y[0];

	while (x[0] != 0 || y[0] != 0) {
		for (int i = 1; i < 3; i++)
			cin >> x[i] >> y[i];

		cin >> xc >> yc >> r;

		for (int i = 0; i < 3; i++)
			d[i] = (int)(pow(x[i] - xc, 2) + pow(y[i] - yc, 2));
		
		int rs = r * r;

		if (rs >= d[0] && rs >= d[1] && rs >= d[2])
			cout << "b" << endl;
		else if (in() && minds() >= rs)
			cout << "a" << endl;
		else if (!in() && rs < d[0] && rs < d[1] && rs < d[2] && minds() > rs)
			cout << "d" << endl;
		else
			cout << "c" << endl;

		cin >> x[0] >> y[0];
	}

	return 0;
}



Measured memory_bytes: 3080
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		String b = sc.next();
		
		if(b.equals("A")) {
			System.out.println("T");
		}else if(b.equals("T")) {
			System.out.println("A");
		}else if(b.equals("C")){
			System.out.println("G");
		}else {
			System.out.println("C");
		}
	}
}

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

int main() {
    string s;
    cin >> s;
    
    int ans;
    if (s == "SUN") ans = 7;
    else if (s == "MON") ans = 6;
    else if (s == "TUE") ans = 5;
    else if (s == "WED") ans = 4;
    else if (s == "THU") ans = 3;
    else if (s == "FRI") ans = 2;
    else if (s == "SAT") ans = 1;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:https://github.com/kei1107/algorithm/blob/master/template/template_for_problems.cpp>
 ?????????============================================================
 n????????´??°a1, a2, ???, an??¨n????????´??°p1, p2, ???, pn?????´??°m?????????????????????
 k???????????´??°ak???pk[%]????¢??????§?????¶?????¨??????????????????k(1 ??? k ??? n)?????????????????????
 0?????\???n?????\????????´??°??????????????????1??\???m??\????????´??°????????§???
 ?????°????????´??°????°?????????¨???1?????§?????????????????????????????°????????????????±??????????
 =================================================================
 ?§£??¬=============================================================
 ????????????( := ????????????????????????)
 ================================================================
 
 
 <reference:http://d.hatena.ne.jp/simezi_tan/20130522/1369203086>
 
 ???????????????????????????????????? < rep(j, 0, n) if(j & (1 << i)) f[j] -= f[j ^ (1 << i)]; >
 ????????????????????????????????? <rep(j, 0, n) if(j & (1 << i)) f[j] += f[j ^ (1 << i)];>
 */

inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    vector<long double> p(n);
    for(auto &x:a) cin >> x;
    for(auto &x:p) {
        cin >> x;
        x/=100;
    }
    
    // Preprocessing
    // probability
    // ??????????±???????????????????????????£??????????????????
    vector<long double> dp1((1<<n),1.0);
    for(int i = 0; i < n;i ++){
        for(int j = 0; j < (1<<n);j++){
            if((j>>i)&1){
                dp1[j] *= p[i];
            }else{
                dp1[j] *= (1-p[i]);
            }
        }
    }
    
    // ????????????????????????
    /* ?????????????????? +=??¨?????? -=???????????°??????*/
    vector<ll> dp2((1<<n),0);
    for(int i = 0; i <(1<<n);i++){
        ll LCM = 1;
        for(int j = 0; j < n;j++){
            if(LCM > m) continue;
            if((i>>j)&1){
                ll tmp = a[j] / gcd(LCM,a[j]);
                if(1.0 * tmp * LCM < 1.5e18) LCM*=tmp;
                else LCM = m+1;
            }
        }
        dp2[i] = m/LCM;
    }
    for(int i = 0; i < n;i++){
        for(int j = 0;j < (1<<n);j++){
            if((j>>i)&1){
                dp2[j] -= dp2[j^1 << i];
            }
        }
    }
    
    long double res = 0;
    for(int i = 0; i < (1<<n);i++){
        res += dp1[i] * (m - abs(dp2[i])); // ??¶???????????¨???
    }
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<pair<pair<string,int>,int>> r(n);
    rep(i,n) r[i].second = i+1;
    rep(i,n){
        cin >> r[i].first.first >> r[i].first.second;
        r[i].first.second *= -1;
    }

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

    rep(i,n) cout << r[i].second << endl;

    return 0;
}


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

int main(void) {
  char s[32], t[32], u[32];
  int a, b;
  
  scanf("%s%s", s, t);
  scanf("%d%d", &a, &b);
  scanf("%s", u);
  
  if (strcmp(s, u) == 0)
    printf("%d %d", a - 1, b);
  
  if (strcmp(t, u) == 0)
    printf("%d %d", a, b - 1);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n, m;

	std::cin >> n >> m;

	std::vector<long long> a(n + 1, 0);
	std::vector<bool>b(n + 1, false);
	long long wa = 0;
	long long ac = 0;

	for (long long i = 0; i < m; i++)
	{
		long long c;
		std::string d;

		std::cin >> c >> d;

		if (d == "WA") {
			a[c]++;
		}
		else {
			if (b[c] == false) {
				wa += a[c];
				ac++;
				b[c] = true;
			}
		}
	}

	std::cout << ac << " " << wa << std::endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<char>> S(N, vector<char>(M));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < M; j++){
			cin >> S[i][j];
		}
	}
	vector<vector<int>> A(N + 1, vector<int>(M + 1, 0));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < M; j++){
			A[i + 1][j + 1] = S[i][j] - '0';
		}
	}
	for (int i = 1; i <= N; i++){
		for (int j = 1; j <= M; j++){
			A[i][j] += A[i][j - 1];
		}
	}
	for (int j = 1; j <= M; j++){
		for (int i = 1; i <= N; i++){
			A[i][j] += A[i - 1][j];
		}
	}
	vector<vector<int>> B(N, vector<int>(M + 1, 0));
	for (int i = 0; i < N - 1; i++){
		for (int j = 0; j < M; j++){
			if (S[i][j] == '1' && S[i + 1][j] == '1'){
				B[i + 1][j + 1] = 1;
			}
		}
	}
	for (int i = 1; i < N; i++){
		for (int j = 1; j <= M; j++){
			B[i][j] += B[i][j - 1];
		}
	}
	for (int j = 1; j <= M; j++){
		for (int i = 1; i < N; i++){
			B[i][j] += B[i - 1][j];
		}
	}
	vector<vector<int>> C(N + 1, vector<int>(M, 0));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < M - 1; j++){
			if (S[i][j] == '1' && S[i][j + 1] == '1'){
				C[i + 1][j + 1] = 1;
			}
		}
	}
	for (int i = 1; i <= N; i++){
		for (int j = 1; j < M; j++){
			C[i][j] += C[i][j - 1];
		}
	}
	for (int j = 1; j < M; j++){
		for (int i = 1; i <= N; i++){
			C[i][j] += C[i - 1][j];
		}
	}
	for (int i = 0; i < Q; i++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1--;
		y1--;
		int ans = A[x2][y2] - A[x2][y1] - A[x1][y2] + A[x1][y1];
		ans -= B[x2 - 1][y2] - B[x2 - 1][y1] - B[x1][y2] + B[x1][y1];
		ans -= C[x2][y2 - 1] - C[x2][y1] - C[x1][y2 - 1] + C[x1][y1];
		cout << ans << endl;
	}
} 

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

int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int i=1;
    while(k>0&&i<n){
        if(s[i]==s[0]){
            while(i<n&&s[i]==s[0]){
                i++;
            }
        }
        else{
            while(i<n&&s[i]!=s[0]){
                s[i]=s[0];
                i++;
            }
            k--;
        }
    }
    int ans=0;
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1])ans++;
    }
    ans=n-ans-1;
    cout<<ans<<endl;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

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

int main(int argc, char **argv)
{
	ll N, A, B; cin >> N >> A >> B;
	vector<ll> H(N); REP(i, N) cin >> H[i];

	auto isok = [=](ll t) -> bool
				{
					vector<ll> tmp = H;
					REP(i, N)
					{
						tmp[i] -= t*B;
					}

					ll cnt{0};
					ll k = A-B;
					REP(i, N)
					{
						cnt += max(0ll, tmp[i]+k-1) / k;
					}
					return cnt <= t;
				};

	ll ok{(ll)1e9+10};
	ll ng{-1};

	while (abs(ok - ng) > 1)
	{
		ll mid = (ok + ng) / 2;
		if (isok(mid)) ok = mid;
		else ng = mid;
	}

	std::cout << ok << std::endl;
}


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

int main() {
	int N;
    cin >> N ;
    int N2 = N;
    int sum = 0;
    for(int i = 0; i < 10; i++){
    	sum += N % 10;
        N = N / 10;
    }
    if(N2 % sum == 0){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
}


Measured memory_bytes: 3644
// Problem: C - Marks
// Contest: AtCoder - M-SOLUTIONS Programming Contest 2020
// URL: https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define y1 y114514
#define elif else if
#define y2 y1919810
typedef pair <int, int> PII;
typedef vector <int> VI;
//#define int long long
#define all(x) x.begin(),  x.end()
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define range(i, s, t)  for (int i = s; i <= (int)t; i++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
long long qread() {
    char c = getchar();
    int neg = 1;
    long long val = 0;
    while (c != '-' && !isdigit(c)) c = getchar();
    if (c == '-') c = getchar(), neg = -1;
    while (isdigit(c)) val = (val << 3) + (val << 1) + c - '0', c = getchar();
    return neg * val;
}
int n, k;
const int N = 200020;
int a[N];
void solve() {
    n = qread(); k = qread(); repn(i, n) a[i] = qread();
    int fi = a[1], fid = 1;
    for (int i = k + 1; i <= n; i++) {
        int d = a[i] - fi;
        if (d > 0) puts("Yes"); else puts("No");
        fid++;
        fi = a[fid];
    }
}
int main() {
    int T = 1;
    //T = qread();
    while (T--) solve();
    return 0;
}


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

const ll MX = 1e18;

int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);

    ll ans = 1;
    bool flag = 0;

    rep(i, n)
    {
        ll a;
        cin >> a;
        if (a == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        if (a > MX / ans||MX<ans*a)
        {
            flag = 1;
            continue ;
        }
        ans *= a;
    }

    if (flag)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3780
import sys
input = sys.stdin.readline

from collections import deque

# 伸ばせる限り伸ばせば答

N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

path = deque(AB[0])
visited = set(AB[0])

while True:
    x = path[0]
    update = False
    for y in graph[x]:
        if y not in visited:
            path.appendleft(y)
            visited.add(y)
            update = True
            break
    if not update:
        break
while True:
    x = path[-1]
    update = False
    for y in graph[x]:
        if y not in visited:
            path.append(y)
            visited.add(y)
            update = True
            break
    if not update:
        break

print(len(path))
print(*path)

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

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

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

  int ans = 0;
  for (int i = 0; i < N;) {
    // 数列の開始
    ans++;
    int from;

    // 単調非減少
    int j1;
    from = A.at(i);
    for (j1 = (i + 1); j1 < N; j1++) {
      int to = A.at(j1);
      if (from == to) {
        continue;
      } else if (from < to) {
        from = to;
        continue;
      } else {
        break;
      }
    }

    // 単調非増加
    int j2;
    from = A.at(i);
    for (j2 = (i + 1); j2 < N; j2++) {
      int to = A.at(j2);
      if (from == to) {
        continue;
      } else if (from > to) {
        from = to;
        continue;
      } else {
        break;
      }
    }

    // cout << "# loop start" << endl;
    // cout << "i:  " << i << endl;
    // cout << "j1: " << j1 << endl;
    // cout << "j2: " << j2 << endl;
    i = max(j1, j2);
  }

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

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

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

    for (int i = k; i < n; i++) {
        if (a[i-k] < a[i]) {
            puts("Yes");
        }
        else {
            puts("No");
        }
    }
}


Measured memory_bytes: 5628
H, W, M = list(map(int, input().split()))
hrz = [0]*H
vrt = [0]*W
targets = set()
for _ in range(M):
    h, w = list(map(lambda x: int(x) - 1, input().split()))
    targets.add((h, w))
    hrz[h] += 1
    vrt[w] += 1

hrz_max = max(hrz)
vrt_max = max(vrt)
hrz_max_lines = [i for i in range(H) if hrz[i] == hrz_max]
vrt_max_lines = [i for i in range(W) if vrt[i] == vrt_max]
for h in hrz_max_lines:
    for w in vrt_max_lines:
        if not (h, w) in targets:
            print(hrz_max+vrt_max)
            exit()
print(hrz_max+vrt_max-1)


Measured memory_bytes: 158024
/*

 Remember, Hope is a good thing... May be the best of things... And No Good thing ever Dies !!!

 */
#include <bits/stdc++.h>
using namespace std;
#define m 100000
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
//#define endl "\n"
const ll inf=(1LL<<60)-1;
ll q,t,x,y,n,k,c,c1,l,r,i,j;
vector<int>a= {4,8,15,16,23,42};
int ans[4];
void solve()
{
   cin>>n;
   if(n%1000!=0)
    cout<<1000-(n%1000)<<endl;
   else
    cout<<0<<endl;
}
int main()
{
    //IOS;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}
//33g5iazc


Measured memory_bytes: 3624
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;

  double ans;
  if(n % 2 == 0){
    ans = (double)(n / 2) / n;
  } else {
    ans = (double)(n / 2 + 1) / n;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = int(input().rstrip('\n'))
    w = int(input().rstrip('\n'))
    print((n - h + 1) * (n - w + 1))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    int ans = 0;
    int active = 0;
    rep(i, n) {
        if(active >= h[i]) {
            active = h[i];
        }
        else {
            ans += h[i] - active;
            active = h[i];
        }
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
d = int(input())
c = list(map(int,input().split()))
cmax = max(c)
for al in range(26):
  if c[al] == cmax:
    maxc = al
up = []
for _ in range(d):
  up.append(list(map(int,input().split())))
ans = [[-1] for _ in range(26)]
for i in range(d):
  ans[maxc].append(i)
task = [maxc for i in range(d)]
#print(task)
#ans[0].append(0)
#ans[16].append(1)
#ans[12].append(2)
#ans[13].append(3)
#ans[12].append(4)

for al in range(26):
  ans[al].append(d)
#print(ans)
import bisect
from random import random
from random import randrange
import math
scr = 0
for al in range(26):
  now = ans[al]
  l = len(now)
  for j in range(1,l):
    scr -= c[al] * (now[j]-now[j-1]-1) * (now[j]-now[j-1]) // 2
    #print(c[al] * (now[j]-now[j-1]-1) * (now[j]-now[j-1]) // 2)
  for j in range(1,l-1):
    scr += up[now[j]][al]
    #print(up[now[j]][al])
  #print('$')
#print(scr)
est = 20000
for _ in range(222):
  for _ in range(2000):
    day = randrange(d)
    pre = task[day]
    pst = randrange(26)
    if pre == pst:
      continue
    bpre = bisect.bisect_left(ans[pre],day)
    bpst = bisect.bisect_left(ans[pst],day)
    bpre1 = ans[pre][bpre-1]
    bpre2 = ans[pre][bpre+1]
    bpst1 = ans[pst][bpst-1]
    bpst2 = ans[pst][bpst]
    #print(day,ans[pre][bpre],ans[pst][bpst])
    #print(day)
    #print(bpre1,day,bpre2,'#',pre)
    #print(bpst1,day,bpst2,'#',pst)
    tmp = 0
    tmp -= c[pre] * (day-bpre1) * (bpre2-day)
    #print(c[pre] * (day-bpre1) * (bpre2-day))
    tmp += c[pst] * (day-bpst1) * (bpst2-day)
    #print(c[pst] * (day-bpst1) * (bpst2-day))
    tmp -= up[day][pre]
    #print(up[day][pre])
    tmp += up[day][pst]
    #print(up[day][pst])
    #print(tmp)
    r = random()
    if est > 0:
      exp = math.exp(tmp/est)
    else:
      exp = bool(tmp>0)
    if exp > r:
      #print(ans[pre])
      #print(ans[pst])
      ans[pre].remove(day)
      bisect.insort(ans[pst],day)
      #print(ans[pre])
      #print(ans[pst])
      task[day] = pst
      scr += tmp
      #print(scr)
    #print('%')
  est -= 100
#for x in ans:
  #print(x)
for x in task:
  print(x+1)
#print(scr)

Measured memory_bytes: 88876
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))
#define all(x) (x).begin(), (x).end()

#define fr first
#define se second
/*
const ll mod = 1000000007;

inline ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

inline ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

inline ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}/**/

const int N = 2e5 + 5;

ll add[N];
ll ans[N];
vector <int> g[N];

void dfs(int u, int p, ll sum = 0) {
	sum += add[u];
	ans[u] = sum;
	for(auto v : g[u]) {
		if(v == p) continue;
		dfs(v, u, sum);
	}
}

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

	int n, q, a, b;
	cin >> n >> q;
	for(int i=1; i<n; i++) {
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}
	while(q--) {
		cin >> a >> b;
		add[a] += b;
	}
	dfs(1, 0);
	for(int i=1; i<=n; i++) cout << ans[i] << " ";

	return 0;
}

Measured memory_bytes: 25600
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let a = read::<i32>();
  let b = read::<i32>();
  let c = read::<i32>();

  println!("{}", (a * b) / 2);
}



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

int main() {
	int n, t;
	cin >> n >> t;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int mini = 1000000001;
	int profit = 0;
	int count = 0;
	for (int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
		int res = a[i] - mini;
		if (res > profit) {
			count = 1;
			profit = res;
		} else if (res == profit) {
			count++;
		}
	}
	cout << count << endl;
	
	return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


ll way0(){
}

int main(){
	//ios_base::sync_with_stdio(false);
	ll I, O, T, J, L, S, Z;
	ll ans = 0;

	cin >> I >> O >> T >> J >> L >> S >> Z;

	ans += O;
	if( (I%2) + (J%2) + (L%2) >= 2 && I > 0 && J > 0 && L > 0 ){
		I--;
		J--;
		L--;
		ans += 3;
	}
	ans += (I/2) * 2;
	ans += (J/2) * 2;
	ans += (L/2) * 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */
 
#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main() {
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 //~ cin >> T;
	 for(int t = 1; t <= T; t++) {
		 int n;
		 cin >> n;
		 int input[n + 1];
		 map<int,int> count;
		 int max_number = -1,second_max = -1;
		 vector<int> max_;
		 for(int i = 1;i <= n; i++){
			 cin >> input[i];
			 count[input[i]] += 1;
			 max_.push_back(input[i]);
		 }
		 sort(max_.rbegin(),max_.rend());
		 max_number = max_[0],second_max = max_[1];
		 if(count[max_number] > 1){
			 second_max = max_number;
		 }
		 for(int i = 1; i <= n; i++){
			 if(input[i] == max_number){
				 if(count[input[i]] > 1){
					 cout << max_number << "\n";
				 }else{
					 cout << second_max << "\n";
				 }
			 }else{
				 cout << max_number << "\n";
			 }
		 }
	 }
}


Measured memory_bytes: 10228
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
 
void _main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  rep(i, 0, N) cin >> V[i];
  rep(i, 0, N) cin >> C[i];
 
  int ans = 0;
  rep(i, 0, N) {
    ans += max(0, V[i] - C[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        else:
            while self.parent[x] >= 0 and self.parent[self.parent[x]] >= 0:
                self.parent[x] = self.parent[self.parent[x]]
                x = self.parent[x]
#        self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return (x if self.parent[x] < 0 else self.parent[x])

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]


n,m=[int(i) for i in input().split()]

A=[[int(i)-1 for i in input().split()] for _ in range(m)]

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
    
    
    
    
    
    





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

int main(){
    int N; cin >> N;
  	int M = pow(10,9) + 7;

    vector<bool> IsPrime(N, true); IsPrime[0] = false; IsPrime[1] = false;
    for(int i=2; i<N+1; i++){
        if(IsPrime[i]){
            for(int j=2; j*i<N+1; j++) IsPrime[i*j] = false;
        }
    }

    vector<int> prime;
    rep(i, N+1){
        if(IsPrime[i]) prime.push_back(i);
    }

    vector<int> cnt(prime.size(), 0);
    rep(i,N){
        int div = i+1; int j = 0;
        while(div > 1){
            int mod = div % prime[j];
            if(mod == 0){
                div /= prime[j];
                cnt[j]++;
            }
            else{
                j++;
            }
        }
    }

    long long int ans = 1;
    rep(i, cnt.size()){
        //cout << cnt[i] << endl;
        ans = (ans * (cnt[i]+1)) % M;
    }
    cout << ans;
}

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

int main(){
  int N,X;
  cin >> N >> X;
  int now = 0;
  int cnt = 1;
  for(int i = 0;i < N;i++){
    int l; cin >> l;
    now += l;
    if(now <= X)cnt++;
  }

  cout << cnt  << endl;

  return 0;
}


Measured memory_bytes: 256
//2011
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int i,A,B,C,n,csum=0,sum=0,ave=0;
	cin>>n;
	cin>>A>>B;
	cin>>C;
	int D[n];
	for(i=0;i<n;i++){
		cin>>D[i];		
	}
	sort(D,D+n,greater<int>());
	int j=1;
	for(i=0;i<n;i++){
		//cout<<"C="<<C<<" "<<"D="<<D[i]<<endl;
		if((double)(C+D[i])/(A+B*(i+1))>(double)C/(A+B*i)){
			C+=D[i];
			//cout<<"*"<<endl;
		}
		 /* if((C+D[i])/(A+B*j)>C){
			C+=D[i];
			cout<<"*"<<endl;
			j++;
		}  */
		else{
			++i;
			break;
		}
	}
	cout<<C/(A+B*(i-1))<<endl;
	return 0;
}















Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
int main(){
    ll n, a, b; cin >> n >> a >> b;
    ll ans = 0;
    if(a == 0) ans = 0;
    else{
        ll x = n / (a + b);
        ll y = n % (a + b);
        if(y <= a) ans = x * a + y;
        else ans = x * a + a;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>){
    val n=readInt()
    val a=readInts()
    var ans=Int.MAX_VALUE
    for(i in 0 until 100){
        ans=Math.min(ans,a.map{(it-i)*(it-i)}.sum())
    }
    println(ans)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 37936
#include <iostream>
#include <string>
#include <map>

using namespace std;

void solve()
{
	map<char, int> Map;
	Map['I'] = 1;
	Map['V'] = 5;
	Map['X'] = 10;
	Map['L'] = 50;
	Map['C'] = 100;
	Map['D'] = 500;
	Map['M'] = 1000;
	string s;
	while(cin >> s)
	{
		int sum = 0;
		int n = s.size();
		for(int i = 0; i < n; ++i)
		{
			if(i < n - 1 && Map[s[i]] < Map[s[i + 1]])
			{
				sum += Map[s[i + 1]] - Map[s[i]];
				++i;
			}
			else
			{
				sum += Map[s[i]];
			}
		}
		cout << sum << endl;
	}
}

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  unordered_map<int, int> D{};
  REP(i, N) {
    int a;
    cin >> a;
    D[a]++;
  }
  int M;
  cin >> M;
  bool ok = true;
  REP(i, M) { int a;
    cin >> a;
    if (D[a] <= 0) ok = false;
    D[a]--;
  }
  puts(ok?"YES":"NO");
  cout << "\n\n";
}

Measured memory_bytes: 11432