akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define trav(it, a) for(auto& it : a)
#define allin(it, a) for(auto it : a)
#define read(v, a, b) for(int i=(a); i<(b); i++) scanf("%d", &v[i]);
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define db(x) cerr << #x << " == " << x << endl

const int maxn = 110, maxv = 1e5 + 100, inf = 0x3f3f3f3f;

int n, W, w[maxn], v[maxn], dp[maxn][maxv];

int solve(int i, int value){ //we want the minimal weight using items up to i and with that value
	if(i==n && value) return inf;
	if(i==n) return 0;
	if(value < 0) return inf;
	if(dp[i][value] != -1) return dp[i][value];
	
	//int add = v[i] <= value? solve(i+1, value - v[i]) + w[i] : inf;
	int add = solve(i+1, value - v[i]) + w[i];
	int not_add = solve(i+1, value);
	int ans = min(add, not_add);
	if(ans > W) ans = inf;
	return dp[i][value] = ans;
}

int main(){
	scanf("%d %d", &n, &W);
	
	rep(i,0,n)
		scanf("%d %d", &w[i], &v[i]);
		
	clr(dp, -1);
	
	for(int i = maxv - 100; i >= 0; i--)
		if(solve(0, i) < inf){
			printf("%d\n", i);
			return 0;
		}
	
}


Measured memory_bytes: 43264
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const gojo=(a:number,b:number):number=>{if(a%b===0)return b;return gojo(b,a%b)};
let [N,K]=tnn(2)
const dfs=(n,k)=>{
  if(n==0)return k
  k = min(dfs(n-1,k*2),dfs(n-1,k+K))
  return k
}
const main=()=>{
  to(dfs(N,1))
}
main()

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
long long int N;
vector<string> field;
long long int dp[510][510];
bool flag[510][510];

void dfs(long long int h, long long int w) {
  	dp[h][w] -= 1;
  	for (long long int dir = 0; dir < 4; dir++){
      	long long int nh = h + dx[dir];
      	long long int nw = w + dy[dir];
        if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
        if (flag[nh][nw] == true && dp[nh][nw] <= dp[h][w] + 1) continue;
      	if (flag[nh][nw] == false && dp[nh][nw] <= dp[h][w]) continue;
      	dfs(nh, nw);
    }
}

int main() {
  	cin >> N;
  	long long int P[N][N];
  	for (long long int i = 0; i < N; i++) for (long long int j = 0; j < N; j++) cin >> P[i][j];
  	for (long long int i = 0; i < N; i++) for (long long int j = 0; j < N; j++) flag[i][j] = true;
  
  	for (long long int i = 0; i < N; i++) for (long long int j = 0; j < N; j++) {
      	dp[i][j] = i + 1;
      	dp[i][j] = min(dp[i][j], N - i);
      	dp[i][j] = min(dp[i][j], j + 1);
      	dp[i][j] = min(dp[i][j], N - j);
    }
  
  	long long int count = 0;
  
  	for (long long int i = 0; i < N; i++) for (long long int j = 0; j < N; j++) {
      	long long int A = P[i][j] - 1;
      	count += dp[A % N][A / N] - 1;
      	flag[A % N][A / N] = false;
      	dfs(A % N, A / N);
    }
  
  	cout << count << endl;
}

Measured memory_bytes: 23220
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

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

	public Main() {
		FasterScanner sc = new FasterScanner(System.in);

		int k = sc.nextInt();
		int sol = 0;
		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					sol += (gcd(i, gcd(j, l)));
				}
			}
		}
		
		System.out.println(sol);
		
		sc.close();
	}
	
	private int gcd(int a, int b) {
		if (b == 0) return a;
		return gcd(b, a%b);
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


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

class Program
{
    static void Main(string[] args)
    {
        var H = sc.ReadInt();
        var W = sc.ReadInt();
        var ans = "";
        for (int h = 0; h < H; h++)
        {
            for (int w = 0; w < W; w++)
            {
                var s = sc.ReadStr();
                if (s == "snuke")
                {
                    ans = (char)('A' + w) + (h + 1).ToString();
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }

    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 11092
#include <iostream>

using namespace std;

const int MAX_N = 1e2 + 10;

int main(int argc, char const *argv[])
{
    int n;
    double sum = 0, a[MAX_N];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += 1.0 / a[i];
    }
    double ans = 1.0 / sum;
    printf("%.16lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    long long R,L;
    
    cin >> L >> R;
    
    if (R-L >= 673){
        cout << 0 << endl;
    }
    else {
        int ans = 30000;
        for (long long i = L;i <= R-1;i++){
            for (long long j = i+1;j <= R;j++){
                int t = ((i%2019)*(j%2019))%2019;
                ans = min(ans,t);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
fun main() {
    val n = next()
    println(if (n.map {
        it.toInt() - 48
    }.sum() % 9 == 0) {
        "Yes"
    } else {
        "No"
    })
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 41164
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << "\n";
}
  

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



int main() {
    int H,W;
    cin>>H>>W;
    ll ans;
    
    if(H==1 || W==1){ans=1;}
    else if(H%2==0){ans=H/2;ans*=W;}
    else if(W%2==0){ans=W/2;ans*=H;}
    else{ll h,w;h=H/2;w=W/2;ans=h*w+(h+1)*(w+1);}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2e5+1e2;
int n;
ll Ans;
int val[maxn],fa[maxn],Fa[maxn],cnt[maxn][2];
vector<int>G[maxn];
struct node {
	int u;
	bool operator < (const node &aa) const {
		ll p1=1ll*cnt[u][0]*cnt[aa.u][1];
		ll p2=1ll*cnt[u][1]*cnt[aa.u][0];
		return (p1>p2 || (p1==p2 && u>aa.u));
	}
};
set<node>s;

inline void file() {
	freopen("AGC023F.in","r",stdin);
	freopen("AGC023F.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int find(int x) {
	if (x!=fa[x]) fa[x]=find(fa[x]);
	return fa[x];
}

int main() {
//	file();
	n=read();
	For (i,2,n) Fa[i]=read();
	For (i,1,n) val[i]=read(),++cnt[i][val[i]];
	For (i,2,n) s.insert((node){i});
	For (i,1,n) fa[i]=i;
	For (i,1,n-1) {
		int u=s.begin()->u; s.erase(s.begin());
		int p=find(Fa[u]); u=find(u); s.erase((node){p});
		Ans+=1ll*cnt[u][0]*cnt[p][1];
		cnt[p][1]+=cnt[u][1]; cnt[p][0]+=cnt[u][0];
		cnt[u][1]=0; cnt[u][0]=0;
		fa[u]=p;
		if (p!=1 &&	!s.count((node){p})) s.insert((node){p});
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 18176
# nいらんな
# -####-------
# ----##------
# --####------
# -----###----
# -------- ##-
# みたいな感じで終端でソートするといい感じに見えてくる


_, m = map(int, input().split())
interval = []
for _ in range(m):
    interval.append(list(map(int, input().split())))
interval = sorted(interval, key=lambda x: x[1])
divide_pos = -1
ans = 0
for itv in interval:
    if divide_pos < itv[0]:
        ans += 1
        divide_pos = itv[1] - 1
print(ans)

Measured memory_bytes: 29840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	double L; cin >> L;
	double ans = (L * L * L) / 27;
	cout << ans << endl;

	/*--------------------------*/
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int l = 0, r = 1e+9;
    while(l + 1 < r){
        int m = (l + r) / 2;
        ll cnt = 0;
        for(int i = n-1; i >= 0; i--){
            if(a[i] > m){
                cnt += ceil(a[i] / (double)m) - 1;
            }
        }
        if(cnt > k){
            l = m;
        } else {
            r = m;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3964
N = int(input())
Al = input().split()
A = list( map((lambda x: int(x)), Al))
num = 0
ma = 10**9 + 7
li = 0

for i in range(N-1, 0, -1):
  li += A[i]
  num += A[i-1] * li

num = num % ma
print(num)


Measured memory_bytes: 31656
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string s;
  cin >> s;
  if(s.size() == 2){
    if(s[0] == s[1]){
      printf("%d %d\n",1,2);
      return 0;
    }else{
      printf("%d %d\n",-1,-1);
      return 0;
    }
  }
  for(int i=0;i<s.size()-2;i++){
    if(s[i] == s[i+2] || s[i] == s[i+1] || s[i+1] == s[i+2]){
      printf("%d %d\n",i+1,i+3);
      return 0;
    }
  }
  printf("%d %d\n",-1,-1);
  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
 
using namespace std;
 
int main(void)
{
  int n;
  map<LL, LL> m;
  cin >> n;
  LL sum = 0ll;
  ++m[sum];
  LL answer = 0ll;
  REP(i,n) {
    LL x; cin >> x;
    sum += x; answer += m[sum]; ++m[sum];
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> size; // ランク
  ll sum;
  
  UnionFind(int n = 1) {
    init(n);
  }
  
  void init(int n = 1) {
    par.resize(n); size.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      size[i] = 1;
    }
    sum = (ll) n * (n - 1) / 2;
  }
  
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    sum -= size[x] * size[y];
    if (size[x] < size[y]) {
      par[x] = y;
      size[y] += size[x];
    } else {
      par[y] = x;
      size[x] += size[y];
    }
    return true;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> vec(M);
  for (int i = 0; i < M; i++) {
    cin >> vec[i].first >> vec[i].second;
    vec[i].first--;
    vec[i].second--;
  }
  
  UnionFind uf(N);
  vector<ll> his(M);
  for (int i = M - 1; i >= 0; i--) {
    his[i] = uf.sum;
    uf.merge(vec[i].first , vec[i].second);
  }
  
  for (int i = 0; i < M; i++) {
    cout << his[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int k,s;
	std::cin >> k >> s;
	int count = 0;
	for(int i=0;i<=k;i++) for(int j=0;j<=k;j++) if(s-i-j>=0&&s-i-j<=k) count++;
	print(count);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    vector<int> a[101];
    string s;
    int cnt = 0;
    while(cin >> s) {
        replace(s.begin(), s.end(), ',', ' ');
        stringstream ss(s);
        while(ss >> s) a[cnt].push_back(stoi(s));
        cnt++;
    }
    
    int dp[101][101];
    if(cnt == 1) cout << a[0][0] << endl;
    else {
        dp[0][0] = a[0][0];
        dp[1][0] = dp[0][0] + a[1][0];
        dp[1][1] = dp[0][0] + a[1][1];
        rep(i,2,cnt) rep(j,0,a[i].size()) {
            if(j != 0 && j != a[i].size() - 1 && i <= cnt / 2) dp[i][j] = a[i][j] + max(dp[i-1][j-1], dp[i-1][j]);
            else if(j != 0 && j != a[i].size() - 1 && i > cnt / 2) dp[i][j] = a[i][j] + max(dp[i-1][j+1], dp[i-1][j]);
            else if(j == 0 && i <= cnt / 2) dp[i][j] = a[i][j] + dp[i-1][j];
            else if(j == 0 && i > cnt / 2) dp[i][j] = a[i][j] + max(dp[i-1][j+1], dp[i-1][j]);
            else if(j == a[i].size() - 1 && i <= cnt / 2) dp[i][j] = a[i][j] + dp[i-1][j-1];
            else if(j == a[i].size() - 1 && i > cnt / 2) dp[i][j] = a[i][j] + max(dp[i-1][j+1], dp[i-1][j]);
        }
        
        cout << dp[cnt-1][0] << endl;   
    }
    return 0;
}

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

int main() {
    string S;
    cin >> S;

    int S_size = S.size();
    for(int i = 0; i < S_size; i++){
        if('?' == S[i]){
            S[i] = 'D';
        }
    }

    cout << S << endl;
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

signed main(){
    map<int, int> m;
    int n; cin >> n;
    
    int sum = 0;
    rep(i,n){
        int a; cin >> a;
        sum += a;
        m[a]++;
    }
    
    int Q; cin >> Q;
    while(Q--){
        int b,c; cin >> b >> c;
        sum -= m[b] * b;
        sum += m[b] * c;
        cout << sum << endl;
        m[c] += m[b];
        m.erase(b);
    }
}

Measured memory_bytes: 7612
import heapq

n,k = map(int,input().split())

v = list(map(int,input().split()))

r = min(n,k)

s = []
for a in range(0,r+1):
    for b in range(0,r-a+1):
        if a > 0 and b > 0:
            vv = v[0:a] + v[n-b:n]
        elif a > 0:
            vv = v[0:a]
        elif b > 0:
            vv = v[0:b]
        else:
            vv = [0]
        #print(vv)
        heapq.heapify(vv)
        t = 1
        while vv != [] and vv[0] < 0 and t <= k-a-b:
            _ = heapq.heappop(vv)
            t += 1
        s.append(sum(vv))

print(max(s))




Measured memory_bytes: 3188
n = int(input())
p = 0
ab = [list(map(int, input().split())) for _ in range(n)]
for i in range(n - 1, -1, -1):
    a, b = ab[i][0], ab[i][1]
    if (a + p) % b != 0:
        p += b - (a + p) % b
print(p)


Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18

int main(){
	ll N, W;
	cin >> N >> W;
	ll w[N+1], v[N+1];
	for (int i = 1; i <= N; ++i) cin >> w[i] >> v[i];
	ll dp[N+1][100001];	//dp[i][j] min weight used to get happiness j
	for (int i = 0; i <= N; ++i){
		for (int j = 0; j < 100001; ++j){
			dp[i][j] = 2 * W;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= N; ++i){
		for (int j = 0; j < v[i]; ++j) dp[i][j] = dp[i-1][j];
		for (int j = v[i]; j <= 100000; ++j){
			dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
		}
	}
	ll mx = 0;
	for (int i = 100000; i >= 0; --i){
		if (dp[N][i] <= W && i > mx) mx = i;
	}
	cout << mx << '\n';
	return 0;
}

Measured memory_bytes: 79104
#line 1 "template.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

ll power(ll base, long long int n, ll p) {
  ll res = 1;
  while (n) {
    if (n & 1) {
      res = (res * base) % p;
    }
    base = (base * base) % p;
    n /= 2;
  }
  return res % p;
}

ll inv(ll base, ll p) { return power(base, p - 2, p); }

int main() {
  ll n, p;
  cin >> n >> p;
  string s;
  cin >> s;

  // コーナーケース
  if (p == 2) {
    ll ans = 0;
    REP(i, n) {
      int num = s[i] - '0';
      if (num % 2 == 0) {
        ans += (i + 1);
      }
    }
    cout << ans << endl;
    return 0;
  }

  if (p == 5) {
    ll ans = 0;
    REP(i, n) {
      int num = s[i] - '0';
      if (num % 5 == 0) {
        ans += (i + 1);
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<ll> count(p, 0LL);
  ll cur = 0;
  ll inv10 = inv(10LL, p);

  REP(i, n) {
    ll num = s[i] - '0';
    cur = (cur * 10LL + num) % p;
    count[(cur * power(inv10, i, p)) % p]++;
  }

  ll ans = count[0];
  REP(i, p) {
    if (count[i] >= 2LL) {
      ans += (count[i] * (count[i] - 1LL)) / 2LL;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
int INF=2e+9;
int main(){
	int N;
	int a[200000],b[200000];
	scan(N);
	rep(i,N){
		scan(a[i]);
	}
	rep(i,N){
		scan(b[i]);
	}
	int xorans=0;
	rep(k,29){
		int amod[200000],bmod[200000];
		int T=(1<<k);
		int onenum=0;
		rep(i,N){
			amod[i]=a[i]%(1<<(k+1));
			bmod[i]=b[i]%(1<<(k+1));
		}
		sort(bmod,bmod+N);
		rep(i,N){
			onenum+=(lower_bound(bmod,bmod+N,4*T-amod[i])-lower_bound(bmod,bmod+N,3*T-amod[i])+lower_bound(bmod,bmod+N,2*T-amod[i])-lower_bound(bmod,bmod+N,T-amod[i]))%2;
		}
		xorans+=((onenum%2)<<k);

	}
	prin(xorans);
	return 0;
}


Measured memory_bytes: 3328
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

a = a1 + a2 + a3

n = int(input())

b = [int(input()) for i in range(n)]

for i in b:
    for j in range(len(a)):
        if i == a[j]:
            a[j] = 0

            
if a[0] == a[1] == a[2] == 0:
    print("Yes")
elif a[3] == a[4] == a[5] == 0:
    print("Yes")
elif a[6] == a[7] == a[8] == 0:
    print("Yes")
elif a[0] == a[3] == a[6] == 0:
    print("Yes")
elif a[1] == a[4] == a[7] == 0:
    print("Yes")
elif a[2] == a[8] == a[5] == 0:
    print("Yes")
elif a[0] == a[4] == a[8] == 0:
    print("Yes")
elif a[2] == a[4] == a[6] == 0:
    print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);
  if(n < 3) {
    printf("0\n");
    return 0;
  }
  long lens[100];
  for(int i = 0;i < n;i++)  {
    scanf("%ld", lens + i);
  }
  int ret = 0;
  for(int i = 0;i < n-2;i++) {
    for(int j = i+1;j < n-1;j++) {
      for(int k = j+1;k < n;k++) {
        long a = lens[i];
        long b = lens[j];
        long c = lens[k];
        if(a == b || b == c || c == a) continue;
        if(a + b > c && b + c > a && c + a > b) ret++;
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 10000000000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int n;
	cin>>n;
	lli a[n];
	FOR0(n) cin>>a[i];
	lli pr[n];
	pr[0]=a[0];
	FORQ(1,n-1){
		pr[i]=pr[i-1]+a[i];
	}
	lli dp[n][n];
	for(int i=n-1;i>=0;i--){
		for(int j=i;j<n;j++){
			lli mn=inf;
			if(i==j) dp[i][j]=0;
			else{
				for(int k=i;k<j;k++){
					if(i!=0)
					mn=min(mn,dp[i][k]+dp[k+1][j]+pr[j]-pr[i-1]);
					else
					mn=min(mn,dp[i][k]+dp[k+1][j]+pr[j]);
				}
				dp[i][j]=mn;
			}
//			dp[i][j]=mn;
		}
	}
	cout<<dp[0][n-1];
}



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

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

  reverse(all(a));

  LL minv = 2, maxv = 2;
  for (int i = 0; i < k; i ++) {
    minv = ((minv + a[i] - 1) / a[i]) * a[i];
    maxv = (maxv / a[i]) * a[i] + a[i] - 1;
    if (minv > maxv) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << minv << " " << maxv << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

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

Measured memory_bytes: 1736
using System;
class Program
 {
        static void Main(string[] args)
        {
            string u = Console.ReadLine();
          
          	int len = u.Length;
          
          for(int i = 0 ; i < len ; i++){
            Console.Write("x");//改行なし出力
          }
          Console.WriteLine("");
        }
 }

Measured memory_bytes: 11092
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string a, b;
  cin >> a >> b;

  int len1 = a.length(), len2 = b.length();
  if(len1 > len2 || (len1 == len2 && a > b)){
    cout << "GREATER\n";
  }else if(len1 < len2 || (len1 == len2 && a < b)){
    cout << "LESS\n";
  }else{
    cout << "EQUAL\n";
  }
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

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

int H, W;

struct bfs_xy{int x; int y; int d;};

bool is_within_map(int x,int y){
    return (0<=x && x<W) && (0<=y && y<H);
}

int bfs(vector<vector<char>> bfs_map, int sx, int sy, int gx, int gy){
    queue<bfs_xy> bfs_q;
    bfs_xy start = {sx,sy,0};
    bfs_q.push(start);
    
    while(!bfs_q.empty()){
        bfs_xy now = bfs_q.front();
        bfs_q.pop();
        
        for(int i=0; i<4; i++){
            int tx = now.x+dx[i], ty = now.y+dy[i];
            if(!is_within_map(tx, ty)) continue;
            if(bfs_map[ty][tx]=='#') continue;
            if(tx==gx && ty==gy) return now.d+1;
            
            bfs_xy new_xy = {tx,ty,now.d+1};
            bfs_q.push(new_xy);
            bfs_map[ty][tx] = '#';
        }
    }
    return -1;
}

signed main(){
    cin >> H >> W;
    vector<vector<char>> bfs_map(H,vector<char>(W));
    rep(i,H){
        string s; cin >> s;
        bfs_map[i] = vector<char>(all(s));
    }
    
    int maximum = 0;
    rep(sx,W)rep(sy,H){
        rep(gx,W)rep(gy,H){
            if(sx==gx && sy==gy) continue;
            if(bfs_map[sy][sx]=='#'||bfs_map[gy][gx]=='#') continue;
            maximum = max(maximum, bfs(bfs_map,sx,sy,gx,gy));
        }
    }
    
    cout << maximum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
 
using namespace std;
 
int num[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
 
bool isLeapYear(int year){
    if(year % 4 != 0)return false;
    else{
        if(year % 100 == 0){
            if(year%400 == 0)return true;
            else{
                return false;
            }
        }else{
            return true;
        }
    }
}
 
int main(){
 
    int year1,month1,day1,year2,month2,day2,sum;
 
    while(true){
        scanf("%d %d %d %d %d %d",&year1,&month1,&day1,&year2,&month2,&day2);
        if(year1 < 0 || month1 < 0 || day1 < 0 || year2 < 0 || month2 < 0 || day2 < 0)break;
 
        sum = 0;
 
        if(year1 == year2 && month1 == month2){
            printf("%d\n",day2-day1);
        }else if(year1 == year2){
 
            if(month1 == 2 && isLeapYear(year1) == true){
                sum += 29 - day1;
            }else{
                sum += num[month1] - day1;
            }
            for(int i=month1+1; i < month2; i++){
                if(i == 2 && isLeapYear(year1) == true){
                    sum += 29;
                }else{
                    sum += num[i];
                }
            }
            sum += day2;
 
            printf("%d\n",sum);
        }else{
 
            if(month1 == 2 && isLeapYear(year1)){
                sum += 29 - day1;
            }else{
                sum += num[month1] - day1;
            }
 
            for(int i = month1 + 1; i <=12; i++){
                if(i == 2 && isLeapYear(year1) == true){
                    sum += 29;
                }else{
                    sum += num[i];
                }
            }
 
            for(int i = year1+1; i < year2; i++){
                if(isLeapYear(i) == true)sum += 366;
                else{
                    sum += 365;
                }
            }
 
            for(int i=1; i < month2; i++){
                if(i == 2 && isLeapYear(year2) == true)sum += 29;
                else{
                    sum += num[i];
                }
            }
 
            sum += day2;
 
            printf("%d\n",sum);
 
        }
 
 
    }
 
    return 0;
}


Measured memory_bytes: 2692
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);

        while(true){

            int n = sc.nextInt();
            if(n == 0){
                break;
            }

            int score[] = new int[n];
            int i;
            double sum = 0;
            for(i = 0; i < n; i++){
                score[i] = sc.nextInt();
                sum += score[i];
            }

            int j;
            double a = 0;
            for(j = 0; j < n; j++){
                a += (score[j] - sum / n) * (score[j] - sum / n);
            }

            System.out.println(Math.sqrt(a / n));

        }

        sc.close();

    }
}


Measured memory_bytes: 31136
#include <bits/stdc++.h>
#define ll long 
using namespace std;
int main() {
    ll k,x;
    cin>>k>>x;
    ll ans = (x -k);
    ll arr[200];
    arr[0] = ans;
    ll i = 1;

    while(ans != k+x){
        ans++;
arr[i] = ans;
i++;
    }
   // cout<<arr[0]<<"\n";
    sort(arr,arr+i);
   // cout<<arr[0]<<"\n";
    for(ll j = 1;j<i-1;j++){
        cout<<arr[j]<<" ";
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define MAXN 1000100
#define ll long long
int n, a[MAXN], head, t;
int main()
{
	scanf("%d",&n);
	head = 1;
	for(int i=1;i<=n;i++)
	{
		a[1]++;
t = 0;
		for(int j=1;j<=head-1;j++)
		{
			if(a[j] > a[j+1]+1 || a[j] == 10)
				t = j, a[j+1]++;
			else break;
		}
		if(a[head] == 10)
		{
			t = head;
			a[++head] = 1;
		}
		for(int j=t;j>=1;j--) a[j] = max(0, a[j+1]-1);
//	for(int i=head;i>=1;i--) printf("%d",a[i]);
//	cout<<endl;
	}
	for(int i=head;i>=1;i--) printf("%d",a[i]);
	cout<<endl;//cout<<t<<endl;

	return 0;
}

Measured memory_bytes: 256
/*    三玖天下第一！！！  */
#include<bits/stdc++.h>
using namespace std;
const long long inf=0x3f3f3f3f3f3f3f3f;long long n,s,ans=inf;
long long f(long long bb,long long nn){return nn<bb?nn:(f(bb,nn/bb)+nn%bb);}
inline void in(){scanf("%lld%lld",&n,&s);}
inline void work()
{
	if(n<s) {puts("-1");return;}else if(n==s) {printf("%lld\n",n+1);return;}
	for(long long i=2;i*i<=n;i++) if(f(i,n)==s) {printf("%lld\n",i);return;} 
	for(long long i=1,temp;i*i<=(n-s);i++) if((n-s)%i==0) {temp=((n-s)/i)+1;if(f(temp,n)==s) ans=min(ans,temp);}
	printf("%lld\n",ans==inf?-1LL:ans);
}
int main(){in();work();return 0;}


Measured memory_bytes: 256
///
// File:  dpl_1_d.cpp
// Author: ymiyamoto
//
// Created on Thu Nov  2 08:05:56 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  uint32_t N;
  cin >> N;

  vector<uint64_t> arr(N, 0);
  for (uint32_t i = 0; i < N; i++) {
    cin >> arr[i];
  }

  vector<uint64_t> dp(N + 1, 1 << 30);
  for (uint32_t i = 0; i < N; i++) {
    *lower_bound(dp.begin(), dp.end(), arr[i]) = arr[i];
  }

  for (uint32_t i = 0; i <= N; i++) {
    if (dp[i] == 1 << 30) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, mx = 0;
    int a[200010], aa[200010];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        aa[i] = a[i];
    }
    sort(aa, aa + n);

    for (int i = 0; i < n; i++)
    {
        if (a[i] == aa[n - 1])
            cout << aa[n - 2] << endl;
        else
            cout << aa[n - 1] << endl;
    }
}

Measured memory_bytes: 4736
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
int S = scanner.nextInt();
int h = S/3600;
int x = S%3600;
int m = x/60;
int s = x%60;
System.out.println(h + ":" + m + ":" + s);
}
}


Measured memory_bytes: 26248
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
        new Main(); 
    }
 
    public Main() {
    	new aoj0167().doIt();
    }
    class aoj0167{
    	void doIt(){
    		while(true){
    			int n = sc.nextInt();
        		if(n == 0)break;
        		int a[] = new int [n];
        		for(int i = 0;i < n;i++){
        			a[i] = sc.nextInt();
        		}
        		System.out.println(Bubble(a,n));
    		}
    	}
    	int Bubble(int a[],int n){
    		int result = 0;
    		for(int i = 0;i < n;i++){
    			for(int j = 0;j < n-1;j++){
    				if(a[j] > a[j+1]){
    					int temp = a[j];
    					a[j] = a[j+1];
    					a[j+1] = temp;
    					result++;
    				}
    			}
    		}
    		return result;
    	}
    }
}

Measured memory_bytes: 29068
#include <bits/stdc++.h>
#define INF 4000000000000000007
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    long x[n], y[n];
    map<long, int> mp_x, mp_y;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        mp_x[x[i]] = 1;
        mp_y[y[i]] = 1;
    }
    int acc[n + 1][n + 1];
    acc[n + 1][n + 1];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            acc[i][j] = 0;
        }
    }
    int i = 1;
    for (auto p: mp_x) {
        mp_x[p.first] = i;
        i++;
    }
    i = 1;
    for (auto p: mp_y) {
        mp_y[p.first] = i;
        i++;
    }

    for (int i = 0; i < n; i++) {
        acc[mp_x[x[i]]][mp_y[y[i]]] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            acc[i][j] += acc[i][j - 1] + acc[i - 1][j] - acc[i - 1][j - 1];
        }
    }
    long ans = INF;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int r0, r1;
            long x0, x1;
            if (x[i] < x[j])
                x1 = x[j], x0 = x[i];
            else
                x0 = x[j], x1 = x[i];
            r0 = mp_x[x0], r1 = mp_x[x1];
            for (int m = 0; m < n; m++) {
                for (int l = m + 1; l < n; l++) {
                    int c0, c1;
                    long y0, y1;
                    if (y[m] < y[l])
                        y1 = y[l], y0 = y[m];
                    else
                        y0 = y[l], y1 = y[m];
                    c0 = mp_y[y0], c1 = mp_y[y1];
                    if (acc[r1][c1] - acc[r1][c0 - 1] - acc[r0 - 1][c1] + acc[r0 - 1][c0 - 1] >= k) {
                        ans = min(ans, (y1 - y0) * (x1 - x0));
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,sum=0,prev=-1;
    cin>>n;
    ll arr[n+5],b[n+5],c[n+5];
    for(i=1;i<=n;i++)
        cin>>arr[i];
    for(i=1;i<=n;i++)
        cin>>b[i];
    for(i=1;i<n;i++)
        cin>>c[i];
    for(i=1;i<=n;i++){
        sum+=b[arr[i]];
        if(prev!=-1){
            if(prev==(arr[i]-1))
                sum+=c[prev];
        }
        prev=arr[i];
    }
    cout<<sum<<endl;
    return 0;
}


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

int main()
{
    int a[5],k;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    cin>>k;
    sort(a,a+5);
    if(a[4]-a[0]>k){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define vt vector
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 1e2 + 5;

ll n, m, temp, ans;
priority_queue<ll> pq;

void solve() {
    cin >> n >> m;
    for(ll i = 1, x; i <= n; i++) {
        cin >> x;
        pq.push(x);
    }
    while(m--) {
        temp = pq.top(); pq.pop();
        pq.push(temp / 2);
    }
    ans = 0;
    while(pq.size()) {
        ans += pq.top(); pq.pop();
    }
    cout << ans << "\n";
}

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

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

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

    long long i = 0;
    while(true) {
        if(i != 0 && i % 2 == 0 && i % N == 0) {
            cout << i << endl;
            break;
        }
        i += N;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;
int main()
{
	int R[MAX],n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>R[i];		
	int maxv=-2000000000;
	int minv=R[0];
	for(int i=1;i<n;i++)
	{
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
	}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 3876
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=5e5+5;

ll sp[N];

void sieve(){
  for(int i=2;i<N;i++)sp[i]=i;

    for(int i=2;i*i<N;i++){
      if(sp[i]==i){
      for(int j=i*i;j<N;j+=i){
        sp[j]=i;
      }
    }
}

}

ll fac[N],inv[N];

ll p=1e9+7;

void fill(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
    inv[i]=powM(fac[i],p-2,p);
  }
}

ll c(ll a,ll b,ll p){
if(a<b)return 0;

  return (fac[a]*inv[a-b]%p)*(inv[b])%p;
}


int main()
{ 

  IOS;

fill();

ll n,m;

cin>>n>>m;

//cout<<c(5,3,p)<<endl;

ll x=c(m,n,p)*fac[n]%p;

ll d=0;

for(int i=0;i<=n;i++){
  ll temp=c(n,i,p)*fac[n-i]%p;
  //cout<<temp<<endl;
  temp=temp*c(m-i,n-i,p)%p;
  //cout<<temp<<endl;
  if(i&1){
d=d-temp+p;
  }
  else {
    d=d+temp;
  }
  d%=p;
//  cout<<d<<endl;
}


x=x*d%p;

cout<<x<<endl;




return 0;
 
}



Measured memory_bytes: 11460