akhauriyash/Code-Regression huggingface dataset:
//Scc Puzzle

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define nxvarep(n,x,a) ll n,x;cin>>n>>x;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    ll s,c;cin>>s>>c;
    if(c/2<=s){
        cout<<c/2<<nnn;
        return 0;
    }
    c+=s*2;
    cout<<c/4<<nnn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int main(int argc, const char * argv[]) {
    // input from txt
    /////////
    //write//
    /////////
    
    int n, k;
    cin >> n >> k;
    int *a = new int[MAX];
    
    rep(i, n){
        cin >> a[i];
    }
    
    sort(a, a+n);
    
    int res = INTINF;
    rep(i, n){
        if(i+k-1<n){
            res = min(res, a[i+k-1] - a[i]);
        }
        else break;
    }
    
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 764
//#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <queue>
#include <stack>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define umap unordered_map
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

const int MAXN = 1e5 + 1;
int n;
ll a[MAXN];
ll s[MAXN], e[MAXN], o[MAXN];
void solve() {
  cin >> n;
  cin >> a[0];
  s[0] = e[0] = o[0] = a[0];
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
  }
  ll even = 0, odd = 0;
  if (s[0] < 0) {
    e[0] = 1;
    even += abs(s[0]) + 1;
  } else if (s[0] > 0) {
    o[0] = -1;
    odd += abs(s[0]) + 1;
  } else {
    e[0] = 1;
    o[0] = -1;
    even = odd = 1;
  }
  for (int i = 1; i < n; ++i) { //even:+ - + - + -
    e[i] = e[i - 1] + a[i];
    if (i % 2 == 0 && e[i] <= 0) {
      even += abs(e[i]) + 1;
      e[i] = 1;
    } else if (i % 2 != 0 && e[i] >= 0) {
      even += abs(e[i]) + 1;
      e[i] = -1;
    }
  }
  for (int i = 1; i < n; ++i) { //odd :- + - + - +
    o[i] = o[i - 1] + a[i];
    if (i % 2 != 0 && o[i] <= 0) {
      odd += abs(o[i]) + 1;
      o[i] = 1;
    } else if (i % 2 == 0 && o[i] >= 0) {
      odd += abs(o[i]) + 1;
      o[i] = -1;
    }
  }
  cout << min(even, odd) << endl;
}

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



Measured memory_bytes: 3456
package main

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

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	A := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
	}
	q := partition(A, 0, n-1)

	pref := strings.TrimRight(fmt.Sprintf("%+v", A[:q])[1:], "]")
	suf := strings.TrimRight(fmt.Sprintf("%+v", A[q+1:])[1:], "]")
	return pref + " [" + strconv.Itoa(A[q]) + "] " + suf
}

func partition(A []int, p, r int) int {
	x := A[r]
	i := p - 1
	for j := p; j < r; j++ {
		if A[j] > x {
			continue
		}
		i++
		A[i], A[j] = A[j], A[i]
	}
	A[i+1], A[r] = A[r], A[i+1]
	return i + 1
}



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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int ticket[ 4 ] = { 6000, 4000, 3000, 2000 };
int what, many;

//function---------------------------------------------------------------------------------------------------------------------
int main() {
	rep( i, 4 ) {
		scanf( "%d %d", &what, &many );
		printf( "%d\n", ticket[ what - 1 ] * many );
	}
	return 0;
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-


def main():
    """Function."""
    x1 = str(input())
    x2 = str(input())
    c11, c12, c13 = x1[0], x1[1], x1[2]
    c21, c22, c23 = x2[0], x2[1], x2[2]

    if c11 == c23 and c12 == c22 and c13 == c21:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
};
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return abs(a.x-b.x)>=EPS || abs(a.y-b.y)>=EPS;
}
Point operator+(Point a,Point b){
	return Point(a.x+b.x,a.y+b.y);
}
Point operator-(Point a,Point b){
	return Point(a.x-b.x,a.y-b.y);
}
Point operator*(double c,Point p){
	return Point(c*p.x,c*p.y);
}
Point operator/(Point p,double c){
	return Point(p.x/c,p.y/c);
}
double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Dot(Point a,Point b){
	return a.x*b.x+a.y*b.y;
}

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vector<Point> ds(n); vd ss(n); // 犬の位置と速度
		rep(i,n) cin>>ds[i].x>>ds[i].y>>ss[i];
		vector<Point> fs(m),us(m);     // フリスビーの発射位置と速度
		rep(i,m) cin>>fs[i].x>>fs[i].y>>us[i].x>>us[i].y;
		
		vi res(n);
		rep(i,m){
			vd ts(n,INFTY);
			vector<Point> vs(n,Point(0,0));
			rep(j,n){
				double a=Abs2(us[i])-ss[j]*ss[j];
				double b=2*Dot(fs[i]-ds[j],us[i]);
				double c=Abs2(fs[i]-ds[j]);
				if(b*b-4*a*c>EPS){
					double t1=(-b-sqrt(b*b-4*a*c))/(2*a);
					double t2=(-b+sqrt(b*b-4*a*c))/(2*a);
					if(t1>t2)
						swap(t1,t2);
					if(t1>EPS){
						ts[j]=t1;
						vs[j]=(fs[i]-ds[j])/t1+us[i];
					}
					else if(t2>EPS){
						ts[j]=t2;
						vs[j]=(fs[i]-ds[j])/t2+us[i];
					}
				}
			}
			int mi=min_element(all(ts))-ts.begin();
			res[mi]++;
			rep(j,n)
				ds[j]=ds[j]+ts[mi]*vs[j];
		}
		rep(i,n)
			cout<<res[i]<<(i<n-1?' ':'\n');
	}
	
	return 0;
}

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

// マクロ //
#define rep(v,times) for(int v = 0; v < (int)(times); v++)
#define req(v,first,endplus1) for(int v = first; v < (int)(endplus1); v++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

template<class T, class Q> double distance(T a, Q b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);
const int dx4[4] = { 1,0,-1,0 };
const int dy4[4] = { 0,1,0,-1 };
const int dx8[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy8[8] = { 0,1,1,1,0,-1,-1,-1 };

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N, AC = 0, WA = 0, TLE = 0, RE = 0;
    cin >> N;
    vs S(N);
    rep(i, N) cin >> S[i];
    rep(i, N) {
        if (S[i] == "AC") { AC++; }
        else if (S[i] == "WA") { WA++; }
        else if (S[i] == "TLE") { TLE++; }
        else if (S[i] == "RE") { RE++; }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
int n, k, dp[42000000];
vector<int> id[21];
char s[21][1145141];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i <= n; i++) {
		scanf(" %s", s[i]);
	}
	int tot = 0;
	for (int i = 0; i <= n; i++) {
		id[i].resize((i + 1) * (1 << i));
		for (int j = 0; j < (i + 1) * (1 << i); j++) {
			id[i][j] = tot++;
		}
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < (1 << i); j++) {
			if (s[i][j] == '1')
				dp[id[i][j * (i + 1)]] = 1;
		}
	}
	for (int i = n; i >= 0; i--) {
		for (int j = 0; j < (1 << i); j++) {
			for (int p = 0; p < i; p++) if (dp[id[i][j * (i + 1) + p]]) {
				dp[id[p][(j >> (i - p)) * (p + 1) + p]] += dp[id[i][j * (i + 1) + p]];
				int fnd = -1;
				for (int q = p + 1; q <= i; q++) {
					if ((j >> (i - q)) & 1) {
						fnd = q;
						break;
					}
				}
				if (fnd != -1) {
					dp[id[p + i - fnd + 1][(((j >> (i - p)) << (i - fnd + 1)) | (j & ((1 << (i - fnd + 1)) - 1))) * (p + i - fnd + 2) + p + 1]] += dp[id[i][j * (i + 1) + p]];
				}
				fnd = -1;
				for (int q = p + 1; q <= i; q++) {
					if (!((j >> (i - q)) & 1)) {
						fnd = q;
						break;
					}
				}
				if (fnd != -1) {
					dp[id[p + i - fnd + 1][(((j >> (i - p)) << (i - fnd + 1)) | (j & ((1 << (i - fnd + 1)) - 1))) * (p + i - fnd + 2) + p + 1]] += dp[id[i][j * (i + 1) + p]];
				}
			}
			if (dp[id[i][j * (i + 1) + i]] >= k) {
				for (int p = i - 1; p >= 0; p--) {
					putchar('0' + ((j >> p) & 1));
				}
				putchar('\n');
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 349568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	


	void solve(){


		ini(n);
		ini(n1);
		ini(x);
		int tmp = 0;
		int tmp1= 0;
		FOR(i,0,n-1){
			ini(x);
			tmp1+=min(n1,x-tmp);
			tmp = x;
		}
		out(tmp1+n1);
		






	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  string s1,s2;
  cin >> s1 >> s2;
  cout << s2+s1;
  

  return 0;
}

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

typedef struct {
    int *stk;
    int ptr;
    int size;
} Stk;

bool isDlmChar(char c, char dlm) {
    return c == dlm || c == '\0';
}

int split(char** des, int desNum, char* src, char dlm) {
    int cnt = 0;
    int src_len = strlen(src);

    for(int i = 0; i < src_len && cnt < desNum; i++) {
        des[cnt++] = &src[i];
        while(!isDlmChar(src[i], dlm)) {
            i++;
        }
        src[i] = '\0';
    }

    return cnt;
}

bool isStringOnlyNumber(char* str) {
    return strlen(str) == strspn(str, "0123456789");
}

bool initStk(Stk *s, int size) {
    if((s->stk = malloc(size * sizeof(int))) == NULL) {
        return false;
    }

    s->ptr = 0;
    s->size = size;
    return true;
}

bool isStkEmpty(Stk *s) {
    return s->ptr <= 0;
}

bool isStkFull(Stk *s) {
    return s->ptr >= s->size;
}

bool pushStk(Stk *s, int x) {
    if(isStkFull(s)) {
        return false;
    }

    s->stk[s->ptr++] = x;
    return true;
}

bool popStk(Stk *s, int *x) {
    if(isStkEmpty(s)) {
        return false;
    }

    *x = s->stk[--s->ptr];
    return true;
}

void teminateStk(Stk *s) {
    free(s->stk);

    s->ptr = s->size = 0;
}

int main(void) {
    Stk s;
    int stkSize = 256;
    char buf[1024];

    if(!initStk(&s, stkSize)) {
        return 1;
    }

    fgets(buf, sizeof(buf), stdin);
    buf[strlen(buf) - 1] = '\0';

    char *ptr[256];
    int num = split(ptr, sizeof(ptr) / sizeof(ptr[0]), buf, ' ');

    int x;
    for(int i = 0; i < num; i++) {
        if(isStringOnlyNumber(ptr[i])) {
            pushStk(&s, atoi(ptr[i]));
        } else {
            int a, b;
            if(!popStk(&s, &a) || !popStk(&s, &b)) {
                return 1;
            }
            if(!strcmp(ptr[i], "+")) {
                x = a + b;
            } else if(!strcmp(ptr[i], "-")) {
                x = b - a;
            } else if(!strcmp(ptr[i], "*")) {
                x = a * b;
            }

            if(!pushStk(&s, x)) {
                return 1;
            }
        }
    }

    if(!popStk(&s, &x)) {
        return 1;
    }
    printf("%d\n", x);

    teminateStk(&s);
    return 0;
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

vector<bool> prime_table(int n){ //素数全列挙
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i*i<=n;i++){
        if(prime[i]!=true) continue;
        for(int j=2*i;j<=n;j+=i){
            prime[j]=false;
        }
    }
    return prime; //i番目の要素が素数の場合trueを返す
}

int main(){
    int x; cin >> x;
    int tmp=1e6;
    vector<bool> prime=prime_table(tmp);
    for(int i=2;i<=tmp;i++){
        if(prime[i]==true&&i>=x){
            cout << i << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 384
i,s=lambda:map(int,input().split()),sorted
n,k=i()
z=s(i()),s(i())[::-1]
o=10**12
g=-1
while o-g>1:
 m,l=o+g>>1,k
 for a,f in zip(*z):l-=max(0,a-m//f)
 if l<0:g=m
 else:o=m
print(o)

Measured memory_bytes: 119500
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

charMap 'J' = 0
charMap 'O' = 1
charMap 'I' = 2

main = do
    [m, n] <- getInts
    k <- getInt
    arr <- newArray ((0,0,0),(2,m,n)) 0 :: IO (IOUArray (Int,Int,Int) Int)
    forM_ [1..m] $ \y -> do
        s <- getLine
        forM_ (zip [1..n] s) $ \(x, c) -> do
            writeArray arr (charMap c,y,x) 1
    forM_ [(t,y,x) | t <- [0..2], y <- [1..m], x <- [1..n]] $ \(t,y,x) ->  (-) <$> ((+) <$> readArray arr (t,y,x) <*> ((+) <$> readArray arr (t,y-1,x) <*> readArray arr (t,y,x-1))) <*> readArray arr (t,y-1,x-1) >>= writeArray arr (t,y,x)
    replicateM_ k $ do
        [a,b,c,d] <- getInts
        sequence [(-) <$> ((+) <$> readArray arr (i,c,d) <*> readArray arr (i, a-1, b-1)) <*> ((+) <$> readArray arr (i,c,b-1) <*> readArray arr (i, a-1, d)) | i <- [0..2]] >>= putStrLn . sjoin
    return ()

Measured memory_bytes: 52012
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n,m,x0,y0;
  cin>>n>>m>>x0>>y0;
  vector<int> x(n),y(m);
  for(int i=0;i<n;i++)
    cin>>x[i];
  for(int i=0;i<m;i++)
    cin>>y[i];
  sort(x.begin(),x.end(),greater<int>());
  sort(y.begin(),y.end());
  cout<<(max(x[0],x0)>=min(y[0],y0)?"War":"No War")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  int m,d;
  cin>>m>>d;
  if(d<20){
    cout<<0<<endl;
    return 0;
  }
  int c = 0;
  for(int i = 1; i <= m; i++){
    for(int j = 20; j <= d; j++){
      if(i==(j/10)*(j%10)&&j%10>=2){
        
        c++;
       
      }
    }
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
b = input()

b = b.replace('A','a')
b = b.replace('T','t')
b = b.replace('G','g')
b = b.replace('C','c')

b = b.replace('a','T')
b = b.replace('t','A')
b = b.replace('g','C')
b = b.replace('c','G')

print(b)

Measured memory_bytes: 3060
from heapq import heappush, heappop, heapify

N = int(input())
edge = [[] for i in range(N)]

for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    u -= 1; v -= 1

    edge[u].append((w, v))
    edge[v].append((w, u))

dist = [float('inf')] * N
visited = [False] * N
dist[0] = 0
visited[0] = True

count = N-1
q = edge[0]
heapify(q)

while q and count:
    w, v = heappop(q)

    if visited[v]: continue
    visited[v] = True
    dist[v] = w
    count -= 1

    for c, u in edge[v]:
        if not visited[u]: heappush(q, (w+c, u))

for a in dist:
    if a % 2: print(0)
    else: print(1)

Measured memory_bytes: 47580
n=int(input())
p=list(map(int,input().split()))

minl=[0 for _ in range(n)]

for i in range(n):
  if i==0:
    minl[0]=p[0]
  else:
    minl[i]=min(minl[i-1],p[i])
ans=sum([p[i]==minl[i] for i in range(n)])
print(ans)

Measured memory_bytes: 87420
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n,d;
    cin >> n >> d;

    cout << ceil((double)n/(2.0f*d+1)) << endl;
}

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


int main(){
    string S;
    cin >> S;
    ll ans = 0;
    for(int i = 0; i < S.size() - 1; i++){
        if(S[i] == S[i + 1]){
            ans++;
            if(S[i] == '0') S[i + 1] = '1';
            if(S[i] == '1') S[i + 1] = '0';
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
# tenka1-2019-beginnerB - *e**** ********e* *e****e* ****e**
def main():
    N, S, K = open(0).read().split()
    tgt = S[int(K) - 1]
    ans = [i if i == tgt else "*" for i in S]
    print("".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0 :
        a, b = b, a % b
    return a

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == [] and n != 1:
        arr.append([n, 1])
    return arr

a, b = map(int, input().split())
gcd_ab = gcd(a, b)
print(len(factorization(gcd_ab)) + 1)

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

int main(){
    int N, A, B, abroad = 1, join = 1;
    string S;
    cin >> N >> A >> B;
    cin >> S;

    rep(i, N){
        if(S[i] == 'a'){
            if(join <= A + B){
                cout << "Yes" << endl;
                join++;
            }else{
                cout << "No" << endl;
            }
        }else if(S[i] == 'b'){
            if((join <= A + B) && (abroad <= B)){
                cout << "Yes" << endl;
                join++;
                abroad++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<seinomi(min(b,d)-max(a,c))<<endl;
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  string s;
  cin >> s;
  bool ok = true;
  rep(i,s.size()){
    if(i%2==0 && s[i]=='L'){
      ok = false;
    }
    if(i%2==1 && s[i]=='R'){
      ok = false;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

typedef struct pair{int x,y;}point;
 
int pcmp(const void*a,const void*b){
    if((*(point*)a).y<(*(point*)b).y)return -1;
    return 1;
}
 
 
point kukan[100010];
 
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0;i < m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        kukan[i].x=x;
        kukan[i].y=y;
    }
    
    qsort(kukan,m,sizeof(point),pcmp);
    
    int pre=-1;
    int ans=0;
    
    for(int i = 0;i < m;i++){
        if(pre<kukan[i].x){
            ans++;
            pre=kukan[i].y-1;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,q;cin>>n>>q&&n|q;){
		vl a(n);
		rep(i,n) cin>>a[i];

		vl sum(n+1),sume(n+1),sumo(n+1);
		rep(i,n)
			sum[i+1]=sum[i]+a[i];
		rep(i,n){
			sume[i+1]=sume[i];
			sumo[i+1]=sumo[i];
			if(i%2==0)
				sume[i+1]+=a[i];
			else
				sumo[i+1]+=a[i];
		}

		rep(_,q){
			ll x; cin>>x;
			ll lo=0,hi=1e9;
			while(lo<hi){
				ll mi=(lo+hi)/2;
				int l=lower_bound(all(a),x-mi)-begin(a);
				int r=lower_bound(all(a),x+mi)-begin(a);
				if(r-l>n-r)
					hi=mi;
				else
					lo=mi+1;
			}
			// 青木くんが取る区間: [al,ar)
			int al=lower_bound(all(a),x-(lo-1))-begin(a);
			int ar=lower_bound(all(a),x+(lo-1))-begin(a);
			// 高橋くんが取る区間: [tl,n)
			int tl=n-(ar-al);
			while(ar<tl){
				tl--;
				if(al==0&&ar==tl)
					break;
				if(al>0&&(ar==tl||abs(x-a[al-1])<=abs(x-a[ar])))
					al--;
				else
					ar++;
			}

			ll res=sum[n]-sum[tl];
			if(al%2==0)
				res+=sumo[al];
			else
				res+=sume[al];
			cout<<res<<endl;
		}
	}
}


Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		char chLow = 'a';
		char chUpp = 'A';

		StringBuilder sb = new StringBuilder();
		Scanner sc = new Scanner(System.in);

		while (sc.hasNextLine()) {
			sb.append(sc.nextLine());
		}

		char[]car  = sb.toString().toCharArray();

		int count;
		for(int i = 0; i < 26;i++) {
			count=0;
			for(int j = 0;j<car.length;j++) {
				if(car[j]==chLow || car[j]==chUpp) {
					count++;
				}
			}
			System.out.println(chLow +" : "+count);
			chLow+=1;
			chUpp+=1;
		}

	}
}


Measured memory_bytes: 26132
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
long long dp[1000001][2];
string s;
int main(){
	ios::sync_with_stdio(0);
	cin>>s;
	dp[0][1]=1;
	forn(i,1,sz(s)+1){
		dp[i][0]=min(dp[i-1][0]+(s[i-1]-'0'),dp[i-1][1]+10-(s[i-1]-'0'));
		dp[i][1]=min(dp[i-1][0]+1+(s[i-1]-'0'),dp[i-1][1]+9-(s[i-1]-'0'));
	}
	cout<<dp[sz(s)][0];
	re 0;
}


Measured memory_bytes: 16924
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 998244353

using namespace std;



void solve()
{   
    int N, M;
    cin >> N >> M;

    int even_count = (M + 1) / 2;
    int odd_count = M / 2;

    int a = even_count;
    int b = a + 1;

    for (int i = 0; i < even_count; i++)
    {
        cout << a << " " << b << endl;
        a--;
        b++;
    }

    a =2 * even_count + odd_count;
    b = a + 2;

    for (int i = 0; i < odd_count; i++)
    {
        cout << a << " " << b << endl;
        a--;
        b++;
    }
}



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

    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3636
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int x = sc.nextInt();
			int full = a * a * b;
			if(x < full/2) {
				BigDecimal h = new BigDecimal(x * 2).divide(new BigDecimal(a * b), 8, BigDecimal.ROUND_DOWN);
				double rad = Math.atan2(b, h.doubleValue());
				System.out.print(Math.toDegrees(rad));
				return;
			}
			if(x == full) {
				System.out.print(0);
				return;
			}
			BigDecimal h = new BigDecimal((full - x) * 2).divide(new BigDecimal(a * a), 8, BigDecimal.ROUND_DOWN);
			double rad = Math.atan2(h.doubleValue(), a);
			System.out.print(Math.toDegrees(rad));
			return;
		}
	}
}


Measured memory_bytes: 22096
//
// Weighted Union Find Tree
//
// c.f.
//   https://qiita.com/drken/items/cce6fc5c579051e64fab
//
// verified:
//   ABC 087 D - People on a Line
//     https://beta.atcoder.jp/contests/abc087/tasks/arc090_b
//


/*
 ・併合時の工夫: union by size
    par[x]: x が根のときは x を含むグループのサイズ (の -1 倍)、そうでないときは親ノード
 
*/


#include <iostream>
#include <vector>
#include <map>
using namespace std;


template<class Abel> struct UnionFind {
    const Abel UNITY_SUM = 0;      // to be set
    vector<int> par;
    vector<Abel> diff_weight;
    
    UnionFind(int n) : par(n, -1), diff_weight(n, UNITY_SUM) {}
    void init(int n) { par.assign(n, -1), diff_weight.assign(n, UNITY_SUM); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    
    Abel calc_weight(int x) {
        root(x);
        return diff_weight[x];
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y, Abel w = 0) {
        w += calc_weight(x); w -= calc_weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y), w = -w; // merge technique
        par[x] += par[y];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    
    Abel diff(int x, int y) {
        return calc_weight(y) - calc_weight(x);
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


/* debug */
template<class Abel> ostream& operator << (ostream& s, UnionFind<Abel> uf) {
    map<int, vector<int> > res;
    for (int i = 0; i < uf.par.size(); ++i) {
        int r = uf.root(i);
        res[r].push_back(i);
    }
    for (map<int, vector<int> >::iterator it = res.begin(); it != res.end(); ++it) {
        s << endl;
        for (int j = 0; j < (int)it->second.size(); ++j) {
            s << it->second[j] << "(" << uf.calc_weight(it->second[j]) << "), ";
        }
    }
    return s << endl;
}



int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<long long> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d; cin >> l >> r >> d; --l, --r;
        if (uf.issame(l, r)) {
            long long diff = uf.diff(l, r);
            if (diff != d) {
                puts("No");
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    puts("Yes");
}


Measured memory_bytes: 1408
N = int(input())
A=[]
A.append(int(input()))
for i in range(N-1):
    A.append(int(input()))
A_s = sorted(A, reverse=True)
for i in A:
    if i!=A_s[0]:
        print(A_s[0])
    else:
        print(A_s[1])

Measured memory_bytes: 70360
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] g = new int[N * 2 + 1][N * 2 + 1];
		for (int i = 0; i < N; ++i) {
			g[i + N][i] = 1;
		}
		MaxFlow mf = new MaxFlow(N * 2 + 1);
		for (int i = 0; i < M; ++i) {
			int A = sc.nextInt() - 1;
			int B = sc.nextInt() - 1;
			g[A][N * 2] = g[B][N * 2] = 1;
			mf.set(g);
			System.out.println(mf.calc(0, N * 2) >= 2 ? "Yes" : "No");
			g[A][N * 2] = g[B][N * 2] = 0;
			g[A][B + N] = g[B][A + N] = 1;
		}
	}

	static class MaxFlow {

		int[][] g;
		int[][] res;

		MaxFlow(int size) {
			g = new int[size][size];
			res = new int[size][size];
		}

		void set(int[][] g) {
			for (int i = 0; i < g.length; ++i) {
				for (int j = 0; j < g.length; ++j) {
					g[i][j] = res[i][j] = g[i][j];
				}
			}
		}

		MaxFlow(int[][] g) {
			this.g = g;
			this.res = new int[g.length][];
			for (int i = 0; i < g.length; ++i) {
				this.res[i] = g[i].clone();
			}
		}

		int calc(int src, int sink) {
			int result = 0;
			int[] prev = new int[g.length];
			while (true) {
				Arrays.fill(prev, -1);
				boolean[] visited = new boolean[g.length];
				Queue<Integer> q = new LinkedList<Integer>();
				q.add(src);
				visited[src] = true;
				OUT: while (!q.isEmpty()) {
					int cur = q.poll();
					for (int i = 0; i < g.length; ++i) {
						if (!visited[i] && res[cur][i] > 0) {
							prev[i] = cur;
							visited[i] = true;
							if (i == sink) {
								break OUT;
							}
							q.add(i);
						}
					}
				}
				if (!visited[sink]) {
					break;
				}
				int pos = sink;
				int pathCap = Integer.MAX_VALUE;
				while (pos != src) {
					int p = prev[pos];
					pathCap = Math.min(pathCap, res[p][pos]);
					pos = p;
				}
				pos = sink;
				while (pos != src) {
					int p = prev[pos];
					res[p][pos] -= pathCap;
					res[pos][p] += pathCap;
					pos = p;
				}
				result += pathCap;
				if (result >= 2) return result;
			}
			return result;
		}
	}

}

Measured memory_bytes: 59188
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+7;

LL sum[maxn];
int a[maxn],b[maxn];
int n,m,k;

int main(){
    read(n);read(m);read(k);
    fo(i,1,n) read(a[i]),sum[i]=sum[i-1]+a[i];
    LL s=k;
    int ans=0;
    ans = lower_bound(sum+1,sum+1+n,k+1)-sum-1;
    fo(i,1,m){
        read(b[i]);s-=b[i];
        if(s<0) break;
        int pos = lower_bound(sum+1,sum+1+n,s+1)-sum-1;
        ans = max(ans, pos+i);
    }
    ans = max(ans,0);
    printf("%d\n",ans);


    return 0;
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 105
//---------------------

ll n,x[MAXN];

int main(){
	cin >> n ;
	ll maxp=0,minp=108;
	REP(i,n){
		cin >> x[i];
		MIN(minp,x[i]);
		MAX(maxp,x[i]);
	}
	ll res = minp;
	ll sum = 1000000000000000;
	FORE(i,minp,maxp){
		ll cursum=0;
		REP(j,n){
			cursum += (x[j]-i) * (x[j]-i);
		}
		if(cursum < sum){
			res = i;
			sum = cursum;
		}
	}
	PRT(sum);
	return 0;
}









Measured memory_bytes: 256
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
H=T[0]
bus=1
x=0
for i in range(N):
  x+=1
  if T[i]>H+K or x>C:
    H=T[i]
    bus+=1
    x=1
print(bus)

Measured memory_bytes: 7384
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		System.out.println(factorial(sc.nextLong()));
		sc.close();
	}
	
	static long factorial(long n) {
		return (n == 1)? 1: n * factorial(n-1);
	}
}

Measured memory_bytes: 17228
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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


Measured memory_bytes: 3640