akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
map<ll, ll> mp;
ll N;
ll ans;
ll A[10500];

ll beki(ll a, ll b) {
    if(b == 0) return 1;
    ll ret = beki(a, b / 2);
    ret = ret * ret % mod;
    if(b & 1) ret = ret * a % mod;
    return ret;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) {
        ll copy = A[i];
        for(ll j = 2; j * j <= copy; j++) {
            if(copy % j != 0) continue;
            ll num = 0;
            while(copy % j == 0) {
                copy /= j;
                num++;
            }
            chmax(mp[j], num);
        }
        if(copy != 1) {
            chmax(mp[copy], 1LL);
        }
    }
    ll LCM = 1;
    for(auto tmp : mp) {
        LCM *= beki(tmp.first, tmp.second);
        LCM %= mod;
    }
    for(int i = 0; i < N; i++) {
        ll now = LCM;
        now *= beki(A[i], mod - 2);
        now %= mod;
        ans += now;
        ans %= mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (a, b, c, x, y) = readLongList()
    var ans = Long.MAX_VALUE
    for (i in 0..(2 * Math.max(x, y))) {
        val aCount = Math.max(x - i / 2, 0)
        val bCount = Math.max(y - i / 2, 0)
        ans = Math.min(a * aCount + b * bCount + c * i, ans)
    }

    ans.let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 36036
//プリム法とかいうのを使うらしい
//結構当たり前だから諦めずに頑張れよ、こういうところだぞ

#include<iostream>
#include<queue>
#include<utility>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;

class Side{
public:
  ll from_Node;
  ll to_Node;
  ll cost;
  Side(ll f,ll t,ll c){
    from_Node=f;to_Node=t;cost=c;
  }
};

bool operator< (const Side& a,const Side& b){
    return a.cost > b.cost;
};

ll distance(vector<ll>& a,vector<ll>& b){
  return min({abs(a[0]-b[0]),abs(a[1]-b[1])});
}

int main(){
  ll n;cin >> n;
  vector< vector<ll> > v1(n,vector<ll>(3,0));
  vector< vector<ll> > v2(n,vector<ll>(3,0));
  //自作クラスのpr_queueどうする
  for(ll i=0;i<n;i++){
    ll x,y;cin >> x >> y;
    v1[i][0]=x;v1[i][1]=y;v1[i][2]=i;
    v2[i][0]=x;v2[i][1]=y;v2[i][2]=i;
  }
  sort(v1.begin(),v1.end(),[](vector<ll>& a,vector<ll>& b){return a[0] < b[0];});
  sort(v2.begin(),v2.end(),[](vector<ll>& a,vector<ll>& b){return a[1] < b[1];});

  //queue<Side> sides;
  vector< queue<Side> > sides_before(n);
  for(ll i=0;i<n-1;i++){
    sides_before[v1[i][2]].push(Side(v1[i][2],v1[i+1][2],distance(v1[i],v1[i+1])));
    sides_before[v1[i+1][2]].push(Side(v1[i+1][2],v1[i][2],distance(v1[i],v1[i+1])));
    sides_before[v2[i][2]].push(Side(v2[i][2],v2[i+1][2],distance(v2[i],v2[i+1])));
    sides_before[v2[i+1][2]].push(Side(v2[i+1][2],v2[i][2],distance(v2[i],v2[i+1])));
  }

  vector<bool> check(n,false);check[0]=true;
  priority_queue<Side> sides;
  ll l=sides_before[0].size();
  for(ll i=0;i<l;i++){
    sides.push(sides_before[0].front());
    sides_before[0].pop();
  }

  ll cost_sum=0;
  Side now=sides.top();
  while(sides.size()!=0){
    if(!check[now.to_Node]){
      check[now.to_Node]=true;
      cost_sum+=now.cost;
      int k=now.to_Node;
      ll l=sides_before[k].size();
      sides.pop();
      for(ll i=0;i<l;i++){
        Side s=sides_before[k].front();
        if(!check[s.to_Node]) sides.push(s);
        sides_before[k].pop();
      }
      now=sides.top();
    }else{
      sides.pop();now=sides.top();
    }
  }
  cout << cost_sum << endl;
}


Measured memory_bytes: 81524
k, n = [int(i) for i in input().strip().split()]
arr = [int(i) for i in input().strip().split()]
arr += [k + arr[0]]
max_d = 0
for i in range(1, n + 1):
    max_d = max(max_d, abs(arr[i] - arr[i - 1]))
print(k - max_d)


Measured memory_bytes: 26444
#include<iostream>
using namespace std;
#define max(x,y) ((x)>(y)?a:b)
#define vmax(x,y) ((x)>(y)?(x):(y))
int main()
{
int a,b,c,x,y;
cin>>a>>b>>c>>x>>y;
if((c*2)<max(x,y))
{
cout<<(vmax(x,y)*2*c);
return 0;
}
if((c*2)>=(a+b))
{
cout<<(x*a+y*b);
return 0;
}
if(x<y)
{
cout<<(x*2*c+(y-x)*b);
return 0;
}
else
{
cout<<(y*2*c+(x-y)*a);
return 0;
}
}


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

using ll=long long;

int func(int x) {
  int ret_val=0;
  switch (x) {
    case 1:
      ret_val=300000;
      break;
    case 2:
      ret_val=200000;
      break;
    case 3:
      ret_val=100000;
      break;
    default:
      break;
  }
  return ret_val;
}

int main() {
  int X,Y; cin >>X >>Y;
  int ans=func(X)+func(Y);
  if (X==1 and Y==1) {
    ans+=400000;
  }
  cout <<ans <<endl;
  return 0;
}


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

int main()
{
    int n, cnt = 0;
    scanf("%d", &n);
    string s;
    cin>>s;
    int len = s.size();
    for(int i = 0; i < len; i++){
        if(s[i] != s[i+1])
            cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 3896
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int k,x; cin >> k >> x;
    int start = x-k+1;
    int end = x+k-1;
    for(int i = start; i <= end;i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int main() {
    while(true) {
        int n,m; scanf("%d%d", &n, &m);
        if(n==0) break;
        static int ps[1001];
        static int pps[1002001];
        for(int i = 0; i < n; i++) scanf("%d", ps+i);
        ps[n++] = 0;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                pps[i*n+j] = ps[i]+ps[j];
        sort(pps, pps+n*n);
        int max_val = 0;
        int x = 0;
        int y = n*n-1;
        while(x<n*n && y>=0) {
            if(pps[x]+pps[y]<=m) {
                max_val = max(max_val, pps[x]+pps[y]);
                x++;
            } else {
                y--;
            }
        }
        printf("%d\n", max_val);
    }
    return 0;
}

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

int main(){
	vector<int> v(3);
	rep(i,3){
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	int ans = v[2] * 10 + v[1] + v[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define WIDTH 3001
#define HEIGHT 51

int dp[HEIGHT * WIDTH];

int main(void)
{
	int i, j, k;
	int n, m, s;
	while(scanf("%d%d%d", &n, &m, &s), n){
		n *= n;
		dp[0] = 1;
		for(i=1; i<WIDTH*HEIGHT; ++i)
			dp[i] = 0;

		for(i=1; i<=m; ++i){
			for(j=n; j>=0; --j){
				for(k=s; k>=0; --k){
					if(j && i <= k){
						dp[j*WIDTH + k] = (dp[j*WIDTH + k] + dp[(j-1)*WIDTH + k-i]) % 100000;
					}
				}
			}
		}

		printf("%d\n", dp[n*WIDTH + s]);
	}

	return 0;
}

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

int main() {
    int n;cin>>n;
    long a[n],ans=0;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n-1;++i){
        if(a[i]!=a[i+1] ){
            if(a[i]!=0)ans+=1;
        }
        else a[i+1]=0;
    }
    if(a[n-1]!=0)ans+=1;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B, X := sc.nextInt(), sc.nextInt(), sc.nextInt()

	if A > X || A+B < X {
		fmt.Fprintln(wtr, "NO")
	} else {
		fmt.Fprintln(wtr, "YES")
	}
	wtr.Flush()
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll n;
  cin >> n;
  vector<string> s(n);
  map<string, ll> mp;
  rep(i, n) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    mp[s[i]]++;
  }
  ll ans = 0;
  for(auto m: mp) {
    if (m.second > 1) {
      ans += m.second * (m.second-1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std;

int main() {

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    const int lower = max(A, C);
    const int upper = min(B, D);

    cout << max(0, upper - lower) << endl;
    
    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int min(int x ,int y){
    if(x<y)
        return x;
    else
        return y;

}
int main(){
    int n ;
    scanf("%d",&n);
    int arr[n] ;
    int i , sum = 0 , sum2 = 0;
    for(i = 0 ; i< n ; i++){
        scanf("%d",&arr[i]);
        sum+=arr[i];
    }
    int pre , pos ,mini ,diff , j;
    for(i = 0 ;i< n ;i++){
        pre =0 ,pos = 0 ;
        for(j = 0 ;j <i ; j++){
            pre +=arr[j] ;
            pos = sum -pre ;
            diff = abs(pre-pos);

            if(i == 0){
                mini = diff ;
            } else{
                mini = min(mini,diff);
            }
        }
    }


    printf("%d",mini) ;

}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;

  if (L > R) {
    cout << "Left" << endl;
  } else if (L == R) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <queue>
using namespace std;

 
int main(){

	priority_queue<int> q;
	int tmp;

	for(int i = 0; i < 10; i++){
		cin >> tmp;
		q.push(tmp);
	}

	for(int i = 0; i < 3; i++){
		cout << q.top() << endl;
		q.pop();
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#define max 999999

using namespace std;

int n[max];

int isprime(void){
  for( int i = 0 ; i < max ; i++ )n[i] = 1;
  n[0] = n[1] = 0; 

  for( int i = 2 ; i * i < max ; i++ ){
    if( n[i] == 1 ){
      for( int j = 2 * i ; j < max ; j += i ){
	n[j] = 0;
      }
    }
  }
  return 0;
}

int main(void){
  
  isprime();

  int num;  
  while( cin >> num ){
    int cnt = 0;
    for( int i = 2 ; i <= num ; i++ ){
      if(n[i]){
	cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 5064
/* One original thought is worth a thousand mindless quotings */

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<algorithm>
#include<bitset>
#include<queue>
#include <math.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 998244353
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define PIII pair<pair<int,int>,int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define M (L+R)/2
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define int long long
const int N = 4000 + 7;

int test;

int n,k;

int fpow(int a,int b) // podstawa,wykladnik
{
   if (b==0)
      return 1;
   if (b%2==0)
   {
      int pom=fpow(a,b/2);
      return (pom*pom)%mod;
   }
   if (b%2==1)
   {
      return (a*fpow(a,b-1))%mod;
   }

   return 0;
}

int rev(int a,int b) // (a/b)%mod
{
   return (a*fpow(b,mod-2))%mod;
}

int silnia[N];

int res[N];

int help[N][N];
int byl[N][N];

int C(int a, int b){
	if (byl[a][b])
		return help[a][b];

	byl[a][b] = 1;

	int x = silnia[b];
	x = rev(x,silnia[a]);
	x = rev(x,silnia[b-a]);

	help[a][b] = x;

	return x;
}

int pol[N];

void solve()
{
	cin >> k >> n;

	silnia[0] = 1;

	FOR(i,1,4000){
		silnia[i] = silnia[i-1] * i % mod;
	}

	FOR(j,1,n/2){
		int x = silnia[n+k-1-j*2];
		x = rev(x,silnia[n-j*2]);
		x = rev(x,silnia[k-1]);
		pol[j] = x;
	}

	FOR(i,2,2*k){
		res[i] = silnia[n+k-1];
		res[i] = rev(res[i],silnia[n]);
		res[i] = rev(res[i],silnia[k-1]);

		int ile = 0;

		FOR(j,1,i/2){
			if (i-j <= k){
				ile++;
			}
		}

		FOR(j,1,ile){
			res[i] -= pol[j] * C(j,ile) % mod * (j % 2 ? 1 : -1);
		}


		while(res[i] < 0)
			res[i] += mod;

		cout << res[i]%mod << endl;
	}

    return;
}

int32_t main()
{
    boost

    test=1;

	for(int i=1; i <= test; i++){
        solve();
	}

    return 0;
}


Measured memory_bytes: 64640
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
//import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        out.println(f(sc.nextLong()-1)^f(sc.nextLong()));
        out.close();
    }
    static long f(long x){
        long c=x%4;
        if(c==0)return x;
        if(c==1)return 1;
        if(c==2)return 1^x;
        return 0;
    }

    static long power(long x, long n) {
        long mod = 1000000007;
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans = (ans * x) % mod;
            }
            x = (x * x) % mod;
            n >>= 1;
        }
        return ans;
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

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

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }
    }

}

Measured memory_bytes: 23124
from sys import exit
n=int(input())
pyramid=[]
for i in range(n):
  x,y,h=map(int,input().split())
  pyramid.append([x,y,h])
flag=0
for i in range(n):
  if flag==0 and pyramid[i][2]!=0:
    flag=-1
  elif flag==-1 and pyramid[i][2]!=0:
    flag=1
if flag==-1:
  for i in range(n):
    if pyramid[i][2]!=0:
      print(pyramid[i][0],pyramid[i][1],pyramid[i][2])
      exit()
ans=[[0 for i in range(101)] for i in range(101)]
for i in range(n):
  if pyramid[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        H=pyramid[i][2]+abs(pyramid[i][0]-cx)+abs(pyramid[i][1]-cy)
        if flag==1:
          ans[cx][cy]=H
        else:
          if ans[cx][cy]!=H:
            ans[cx][cy]=0
    flag=0
for i in range(101):
  for j in range(101):
    if ans[i][j]!=0:
      print(i,j,ans[i][j])


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <iomanip>
#include <algorithm>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;


#define SPRE(x) setprecision(x) // 精度を指定

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	array<int, 100010> sc{};
	int n, c;
	cin >> n >> c;
	vector<vector<pair<int,int>>> times(c,vector<pair<int,int>>());
	for (int i = 0; i < n; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		times[c-1].push_back({s,t});
	}
	for(auto&& t : times){
		sort(t.begin(), t.end());
	}
	for(auto&& t : times){
		if(t.size() == 0)
			continue;
		sc[t[0].first-1]++;
		sc[t[0].second]--;
		for (int i = 1; i < t.size(); i++) {
			if(t[i-1].second == t[i].first)
				sc[t[i].first]++;
			else
				sc[t[i].first-1]++;
			sc[t[i].second]--;
		}
	}
	int maxim = 0;
	for (int i = 1; i < sc.size(); i++) {
		sc[i] += sc[i-1];
		maxim = max(maxim, sc[i]);
	}
	cout << maxim << '\n';
}


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

int main() {
	int N,K;
	cin >> N >> K;
	vector<double> P(N);
	for(double& e:P)cin >> e;
    vector<double> E(N);
    for(int i=0; i<N; i++){
      E[i] = (P[i]+1.0)/2.0;
    }
    double ans=0;
  for(int i=0; i<K ;i++){
    ans = ans + E[i];
  }
    double keisan = ans;
    for(int i=1; i+K-1<N ;i++){
      keisan = keisan - E[i-1] + E[i+K-1];
       ans = max(ans,keisan);
    } 
    cout << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;

int main() {
	int a,b,c;
	cin >> a >> b >>c;
	cout << (a+b)*c/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    for(int i=0; i<5; i++){
        int k;
        cin >> k;
        if(k==0){
            cout << i+1;
        }
    }
    return 0;
}

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

#define int long long

int32_t main(){
	int n ;
	cin >> n ;
	int cnt = 0 ;
	for(int i = 1 ; i <= n ; i++){
		int x ;
		cin >> x ;
		if(i%2 == 0) continue ;
		cnt += (x%2) ;
	}
	cout << cnt ;
	return 0 ;
}



Measured memory_bytes: 3632
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> P(N);
    for(int i=0;i<N;i++) cin>>P[i];

    set<int> s;
    for(int i=0;i<K;i++) s.insert(P[i]);

    int res=1;
    for(int i=K;i<N;i++){
        s.erase(P[i-K]);
        bool bl=(P[i-K]<*s.begin());
        bool br=(*s.rbegin()<P[i]);
        if(!(bl&&br)) res++;
        s.insert(P[i]);
    }

    vector<int> X(N);
    X[0]=1;
    for(int i=1;i<N;i++){
        if(P[i-1]<P[i]) X[i]=X[i-1]+1;
        else X[i]=1;
    }
    bool b=false;
    for(int i=K-1;i<N;i++){
        if(!b){
            if(X[i]>=K) b=true;
        }
        else{
            if(X[i-1]<K && X[i]>=K) res--;
        }
    }

    cout<<res<<endl;

    
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

vector<ll>adj[maxn];
ll a[maxn],lvl[maxn],p[maxn][20],h[maxn];
ll ans=0,A,T;
void dfs(ll u,ll par)
{
    h[u]=0;
    p[u][0]=par;
    lvl[u]=lvl[par]+1;
    for(auto v : adj[u])
    {
        if(v==par) continue;
        dfs(v,u);
        h[u]=max(h[u],h[v]+1);
    }
}
ll lca(ll u,ll v)
{
    ll i,lg;
    if(lvl[u]<lvl[v])swap(u,v);
    for(lg=0;(1<<lg)<=lvl[u];lg++);
    lg--;
    for(i=lg;i>=0;i--)
    {
        if((lvl[u]-(1<<i))>=lvl[v])
        u=p[u][i];
    }
    if(u==v) return u;
    for(i=lg;i>=0;i--)
    {
        if(p[u][i]!=-1&&p[u][i]!=p[v][i]){
            u=p[u][i];v=p[v][i];
        }
    }
    return p[u][0];
}
ll getAncestor(ll u,ll dis)
{
    dis=lvl[u]-dis;
    ll i,lg;
    for(lg=0;(1<<lg)<=lvl[u];lg++);
    lg--;
    for(i=lg;i>=0;i--)
    {
        if(lvl[u]-(1<<i)>=dis)
        u=p[u][i];
    }
    return u;
}
ll dis(ll u,ll v)
{
    if(lvl[u]<lvl[v]) swap(u,v);
    ll w=lca(u,v);
    return lvl[u]+lvl[v]-2*lvl[w];
}

int main()
{
    ll i,u,v,j,n,x,y;
    cin>>n>>T>>A;
    for(i=1;i<n;i++){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(i=0;i<20;i++)
    {
        for(j=1;j<=n;j++)
        {
            p[j][i]=-1;
        }
    }
    lvl[0]=-1;
    dfs(A,0);
    for(i=1;i<20;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(p[j][i-1]!=-1)
            p[j][i]=p[p[j][i-1]][i-1];
        }
    }
    if(p[T][0]==A){
        cout<<0;
        return 0;
    }
    ll cur=T;
    x=0;
    ll mv=T,mx=0;
    while(cur!=A){
        if(dis(T,cur)>=dis(A,cur)) break;
        if(x+h[cur]>mx){
            mx=x+h[cur];
            mv=cur;
        }
        x++;
        cur=p[cur][0];
    }
    cout<<dis(mv,A)+(h[mv]-1);
}


Measured memory_bytes: 27648
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


vector<vector<ld>>pers;
ld memo[16][1 << 16];
bool ok[16][1 << 16];
int M, N;
ld check(const int now,bitset<16>&lives) {
	const int a = lives.to_ulong();
	if (!(memo[now][a]<-1)) {
		return memo[now][a];
	}
	else {
		ld amax = 0;
		for (int i = 0; i < M; ++i) {
			if (lives[i]) {
				lives[i] = false;
				ld per = 0;
				ld living = 1;
				for (int enemy = now; enemy < N; ++enemy) {
					per += living*(1 - pers[i][enemy])*check(enemy,lives);
					living *= pers[i][enemy];
				}
				per += living;
				amax = max(amax, per);
				lives[i] = true;
			}
		}
		return memo[now][a] =amax;
	}

}

int main() {cin >> M >> N;
	pers.resize(M);
	for (int i = 0; i < 16; ++i) {
		for (int j = 0; j < 1 << 16; ++j) {
			memo[i][j] = -2;
		}
	}
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			ld p; cin >> p;
			pers[i].push_back(p);
		}
	}
	bitset<16>bs((1 << 16) - 1);
	ld ans = check(0, bs);
	cout << fixed << setprecision(22) << ans << endl;
	return 0;
}

Measured memory_bytes: 19676
#include<stdio.h>

int main()
{
    int h1,h2,m1,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    m1+=60*h1;
    m2+=60*h2;
    printf("%d\n",m2-m1-k);
    return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define MOD (ll) (1e9+7)
int main()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x = abs(x);
	ll cnt = x/d;
	if(cnt>=k)
	{
		cout<<x-(k*d)<<"\n";
	}
	else{
		if((k-cnt)%2 == 1)
		{
			ll ans = (cnt+1)*d-x;
			cout<<ans<<"\n";
		}
		else
		{
			ll ans = x-(cnt*d);
			cout<<ans<<"\n";
		}
	}
}

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

int main(){
  string o,e,s="";
  cin>>o;
  cin>>e;
  for(int i=0;i<o.size()+e.size();i++){
    if(i%2==0)s+=o[i/2];
    else s+=e[(i-1)/2];
  }
  cout<<s;
}

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

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

    int ans=0;
    for(int i=2;i<sqrt(x);i++){
        int c=0,d=1;
        while(d<=x){
            c=d;
            d*=i;
        }
        ans=max(c,ans);
    }
  	if(x==1)cout<<x<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll K,A,B;
    cin >> K >> A >> B;
    ll ans = 0;
    if((K <= A) || ((B-A)<=2)){
        ans = K + 1;
    }else{
        ll L = (K-A+1)/2;
        ll M = (K-A+1)%2;
        ans += L*(B-A) + M + A;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
 
        int ans = 0;
 
        if (a < 0) {
            ans += c * -a + d;
            a = 0;
        }
 
        ans += (b - a) * e;
         
        System.out.println(ans);
    }
}


Measured memory_bytes: 26228
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

long main(void){
    long N;
    long cnt = 0;
    scanf("%ld", &N);
    long array[1000] = {0};
    for (long i = (long)sqrt(N); i > 0 ; i--) {
        if (N % i == 0) {
            printf("%ld\n",i + N/i - 2);
            return 0;
        }
    }
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	av := nextInt()
	b := nextInt()
	bw := nextInt()
	t := nextInt()

	if av <= bw {
		fmt.Println("NO")
		return
	}

	// t以内に追いつく
	if t*(av-bw) >= abs(b-a) {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")

}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
using ll = long long;
int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<string>> a(h,vector<string>(w));
  char k;
  rep(i,h){
    rep(j,w){
      cin>>k;a.at(i).at(j)=k;
    }
  }
  rep(i,h){
    bool t=true;
    rep(j,w){
      if(a.at(i).at(j)!=".")t=false;
    }
    if(t){
      rep(j,w)a.at(i).at(j)="";
    }
  }
  rep(j,w){
    bool t=true;
    rep(i,h){
      if(a.at(i).at(j)!="."&&a.at(i).at(j)!="")t=false;
    }
    if(t){
      rep(i,h)a.at(i).at(j)="";
    }
  }
  
  rep(i,h){
    int l=0;
    rep(j,w){
      cout<<a.at(i).at(j);
    }
    rep(j,w){
      if(a.at(i).at(j)=="."||a.at(i).at(j)=="#")l++;
    }
    if(l>0){
      cout<<endl;
    }
    
  }
}

Measured memory_bytes: 768
#include<stdio.h>

int pa[100010]={0};

int root(int x)
{
	if(x==pa[x])return x;
	else return pa[x] = root(pa[x]);
}

void unite(int x,int y)
{
	int rx=root(x);
	int ry=root(y);
	if(rx==ry)return;
	else pa[rx]=ry;
}

int same(int x,int y)
{
	int rx=root(x);
	int ry=root(y);
	return (rx==ry);
}

int main()
{
	int n,m;
	int i,j,ans=0;
	int x,y,z;
	
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)pa[i]=i;
	
	for(j=0;j<m;j++)
	{
		scanf("%d %d %d",&x,&y,&z);
		unite(x,y);
	}
	for(i=1;i<=n;i++)
	{
		if(!same(0,i))
		{
			unite(0,i);
			ans++;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int x[N],bk[17][N];
int main()
{
	int n,l,q;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",x+i);
	scanf("%d%d",&l,&q);
	int pre=0;
	for(int i=0;i<n;i++)
	{
		while(x[i]-x[pre]>l)
			pre++;
		bk[0][i]=pre;
	}
	for(int i=1;i<17;i++)
		for(int j=0;j<=n;j++)
			bk[i][j]=bk[i-1][bk[i-1][j]];
	for(;q--;)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		if(a==b)
		{
			puts("0");
			continue;
		}
		if(a>b)
			swap(a,b);
		int ret=0;
		for(int i=16;i>=0;i--)
		{
			if(bk[i][b]>a)
			{
				ret+=1<<i;
				b=bk[i][b];
			}
		}
		printf("%d\n",ret+1);
	}
	return 0;
}
//

Measured memory_bytes: 7808
import sys
S = int(input())
MOD = 1000000007
x = S // 3
y = S % 3
if x == 0:
    print(0)
    sys.exit()
A = [1, 1, 1]
B = [0, 0, 0]
for i in range(x - 1):
    B[0] = (A[0] + A[2]) % MOD
    B[1] = (B[0] + A[1]) % MOD
    B[2] = (B[1] + A[2]) % MOD
    A = B
print(A[y])

Measured memory_bytes: 9200
package main

import (
  "fmt"
  "container/heap"
)

type IntHeap []int

func (h IntHeap) Len() int {
	return len(h)
}

func (h IntHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h IntHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n - 1]
	*h = old[0:n-1]
	return x
}

func main() {
  var n, m int
  var ans int64

  fmt.Scan(&n, &m)

  jobs := map[int][]int{}

  for i := 0; i < n; i++ {
    var a, b int
    fmt.Scan(&a, &b)
    jobs[a] = append(jobs[a], b)
  }

  h := &IntHeap{}
	heap.Init(h)

  for remain_days := 1; remain_days <= m; remain_days++ {
    if len(jobs[remain_days]) > 0 {
      for _, v := range jobs[remain_days] {
        heap.Push(h, v)
      }
    }
    if h.Len() > 0 {
      ans += (int64)(heap.Pop(h).(int))
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 12672
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}

ll n, ans;
vector<ll> g[210000];
bool used[210000];
ll dfs(ll a) {
	ll res = 0, a1 = powmod(2, n - 1) - 1;
	used[a] = true;
	REP(i, g[a].size()) {
		if (used[g[a][i]])continue;
		ll now = dfs(g[a][i]);
		res += now;
		a1 -= powmod(2, now) - 1;
		a1 = (a1 + MOD * 2) % MOD;
	}
	res++;
	a1 -= powmod(2, n - res) - 1;
	a1 = (a1 + MOD * 2) % MOD;
	ans += a1;
	ans %= MOD;
	return res;
}
int main() {
	cin >> n;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0);
	cout << ans * powmod(powmod(2, n), MOD - 2) % MOD;
}





Measured memory_bytes: 20864
#include <iostream>
using namespace std;
int main(void){
    int s = 0;
    int f[1000000];
    int flag = 0;
    int ans = 0;

    //入力
    cin >> s;
    
    //処理
    f[0] = s;
    for(int i=1; i<1000000; i++){
        if((f[i-1] % 2) == 0){
            f[i] = f[i-1] / 2;
        }
        else{
            f[i] = (3 * f[i-1]) + 1;
        }
        for(int j=0; j<i; j++){
            if(f[i] == f[j]) flag = 1;
        }
        if(flag){
            ans = i+1;
            break;
        }
    }

    //出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int cnt=0;
int arr[6666];
void dfs(int now,int num){
	if(now==n){
		
		for(int j=0;j<n;j++)
			cout<<(char)('a'+arr[j]);
		cout<<'\n';
	
		return ;
	}
	for(int j=0;j<=num;j++){
		arr[now]=j;
		if(j==num){
			dfs(now+1,num+1);
		}else{
			dfs(now+1,num);
		}
		
	}
}
/*

*/
int main(){
	
	cin>>n;
	dfs(0,0);
	
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
    C[i] = A[i] + B[i];
  }
  sort(all(C), greater<ll>());
  ll sum = 0;
  rep(i, N) if(i%2==0) sum += C[i];
  cout << sum - accumulate(all(B), 0LL) << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, m, i, j, a[303][303], k[303] = {}, ans;
    bool ps[303] = { false };

    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++) for (j = 0; j < m; j++) {
        scanf("%d", &a[i][j]);
    }

    for (j = 0; j < m; j++) {
        ps[j] = true;
    }

    ans = INF;
    for (int t = 0; t < m; t++) {
        int sel[303] = {}, selmax, seli;
        for (i = 0; i < n; i++) {
            while (!ps[a[i][k[i]] - 1]) {
                k[i]++;
            }
            sel[a[i][k[i]] - 1]++;
        }
        selmax = 0;
        seli = 0;
        for (j = 0; j < m; j++) {
            if (selmax < sel[j]) {
                selmax = sel[j];
                seli = j;
            }
        }
        ans = min(ans, selmax);
        ps[seli] = false;
    }

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

    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
#! python3

a, b = map(int, input().split())

ans = 'Positive'

if a*b <= 0:
    ans = 'Zero'
elif a < 0 and b < 0 and (a-b)%2 == 0:
    ans = 'Negative'
    
print(ans)
  

Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define sz(s) (int) s.size()
#define pb push_back
#define rc(x) return cout<<x<<"\n",0

using namespace std;
    void solve()
    {
     int n, first = -1, second = -1, max_first = 1, max_second = 1;
     vector < int > v;
     map < int , int > mp;
     cin >> n;
     while(n--)
     {
      int x;
      cin >> x;
      v.pb(x);
      mp[x]++;
      if (x > first)
      {
        second = first;
       // max_first = 1;
        first = x;
       // max_second = 1;
      }
       else
        if (x > second && x != first)
          second = x;
     }
    // cout << second << " " << first;
     for (int i = 0; i < sz(v); i++)
       if (v[i] == first && mp[v[i]] >=2)
           cout << v[i] << "\n";
           else
             if(v[i] == first && mp[v[i]] < 2)
               cout << second << "\n";
               else
                cout << first << "\n";

 }
               
    int main()
    {
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int t=1;
      // cin>>t;
        while(t--)
        {
            solve();
        }
    }

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
int a[22][22],b[22],n,m,c;
int main()
{
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int now=c;
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
			now+=a[i][j]*b[j];
		}
		if(now>0)
		{
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int  k = s.nextInt();
    int arr[] = new int[n];
    for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    }
    int dp[] = new int[n];
    dp[0] = 0;
    dp[1] = Math.abs(arr[1]-arr[0]);
    for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    }
      
 	System.out.println(dp[dp.length-1]);
  }
}

Measured memory_bytes: 50076
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

ll mypow2(int n){
    ll ans = 1;

    rep(i,n){
        ans *= 2;
    }

    return ans;
}


int main(){

    int n,m;
    cin >> n >> m;

    vector<pair<int,int>> key(1);

    rep(i,m){
        int a,b;
        cin >> a >> b;

        int state = 0;
        rep(j,b){
            int tmp;
            cin >> tmp;
            state += mypow2(tmp - 1);
        }

        key.pback(mpair(a, state));
    }

    int state_max = mypow2(n) - 1;
    vector<vector<int>> dp(m + 1, vector<int>(state_max + 1, INT_MAX / 2));

    dp[0][0] = 0;

    for(int i = 1; i <= m; i++){
        for(int j = 0; j <= state_max; j++){
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);

            int next_state = j | key[i].second;
            dp[i][next_state] = min(dp[i][next_state], dp[i - 1][j] + key[i].first);

        }
    }

    if(dp[m][state_max] != INT_MAX / 2){
        cout << dp[m][state_max] << endl;
    }else{
        cout << -1 << endl;
    }


    return 0;
}


Measured memory_bytes: 16384
// ABC121_B
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M, C, code;
    cin >> N >> M >> C;
    vector<ll> vec(M);
    REP(i, M) cin >> vec[i];
    
    ll res = 0;
    REP(i, N) {
        ll sum = C;
        REP(j, M) {
            cin >> code;
            sum += vec[j]*code;
        }
        if (sum > 0) res++;
    }
    
    cout << res << "\n";
    
    return 0;
}

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

int K,A,B;

int main(){
	cin>>K>>A>>B;
	for(int i=A;i<=B;i++){
		if(i%K==0){
			puts("OK");
			return 0;
		}
	}
	puts("NG");
}


Measured memory_bytes: 3676
s = input()
n = len(s)
def count_inv(arr):
    left = 0
    ans = 0
    for i in range(len(arr)):
        if arr[i] == 1:
            left += 1
        else:
            ans += left
    return ans

temp = []
ind = 0
ans = 0
while True:
    if ind == n:
        ans += count_inv(temp)
        break
    c = s[ind]
    if c == "A":
        temp.append(1)
        ind += 1
        continue
    elif c == "B":
        if ind == n-1:
            ans += count_inv(temp)
            break
        if s[ind+1] == "C":
            temp.append(0)
            ind += 2
            continue
        else:
            ans += count_inv(temp)
            temp = []
            ind += 1
            continue
    else:
        ind += 1
        ans += count_inv(temp)
        temp = []
        continue


print(ans)

Measured memory_bytes: 5092
string = input()
 
flg = True
while len(string) > 0:
  if string.endswith('dream'):
    string = string[:-5]
  elif string.endswith('dreamer'):
    string = string[:-7]
  elif string.endswith('erase'):
    string = string[:-5]
  elif string.endswith('eraser'):
    string = string[:-6]
  else:
    print('NO')
    flg = False
    break
if flg:
  print('YES')

Measured memory_bytes: 3188
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

using namespace std;

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

    int N, W;
    scanf("%d%d", &N, &W);

    vector<long long> dp(W + 1);

    for (int i = 0; i < N; ++i) {
        long long w, v;
        scanf("%lld%lld", &w, &v);

        for (int j = W - w; j >= 0; --j) {
            dp[j + w] = max({dp[j + w], dp[j] + v});
        }
    }

    printf("%lld", dp[W]);
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(c>0 && a>0)
  {
      c=c-b;
      a=a-d;
  }
    if(c<=0)
      cout<<"Yes"<<"\n";
  	else if(a<=0)
      cout<<"No"<<"\n";
  
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	long long d,p;
}a[200010];
int n;
bool cmp(node a,node b){return a.p<b.p;}
inline int erfen(long long x)
{
	int l=1,r=n,ans=n+1;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(a[mid].p>x)ans=mid,r=mid-1;
		else l=mid+1;
	}return ans;
}
long long cnt[200010];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read();long long dis=read(),w=read();
	for(int i=1;i<=n;i++)a[i].p=read(),a[i].d=ceil(1.0*read()/w);
	sort(a+1,a+n+1,cmp);
	long long ans=0,now=a[1].d;
	ans+=a[1].d;
	cnt[1]+=a[1].d,cnt[erfen(a[1].p+2*dis)]-=a[1].d;
	for(int i=2;i<=n;i++)
	{
		now+=cnt[i];
		if(a[i].d>now)
		{
			ans+=a[i].d-now;
			cnt[i]+=a[i].d-now,cnt[erfen(a[i].p+2*dis)]-=a[i].d-now;
			now=a[i].d;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<long long int> dp1(n+1,0),dp2(n+1,0),dp3(n+1,0);
    vector<long long int> arr1(n+1,0),arr2(n+1,0),arr3(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin>>arr1[i]>>arr2[i]>>arr3[i];
    }
    dp1[1]=arr1[1];
    dp2[1]=arr2[1];
    dp3[1]=arr3[1];
    for(int i=2;i<=n;i++)
    {
        dp1[i]=arr1[i]+max(dp2[i-1],dp3[i-1]);
        dp2[i]=arr2[i]+max(dp1[i-1],dp3[i-1]);
        dp3[i]=arr3[i]+max(dp1[i-1],dp2[i-1]);
    }
    cout<<max(dp1[n],max(dp2[n],dp3[n]));
}

Measured memory_bytes: 7500
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string input;
    int num = 0;
    cin >> input;
    if(input == "RRR"){
        cout << 3 << endl;
    }else if(input == "RRS" || input == "SRR"){
        cout << 2 << endl;
    }else if(input == "SSS"){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3624
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = 3;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(jud(a));
    }

    private static int jud(int a[]){
        int re = 0;
        int b = 0;
        //初期値0なのでいらない
        // if(a[0] < a[1]){
        // }
        if(a[0] <= a[1]){
            b = a[1] / a[0];
            re = b;
        }
        if(a[2] < b){
            re = a[2];
        }
        return re;
    }
}

Measured memory_bytes: 21844