akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

int p[800];
int d[800];
int map[800][800];
int count[800];

void dp(int now,int old,int n,int now_dis,int* dis_max,int* point){
	int cost = 0;
	int i;
	for(i=0;i<n;i++){
		if(map[i][now] != 0 && i != old){
			if(count[i] == 1){
				if(now_dis > *dis_max){
					*dis_max = now_dis;
					*point = now;
				}
			}else{
				dp(i,now,n,now_dis+map[i][now],dis_max,point);
			}
		}
	}
}

int bridge(int n){
	int i,j;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j] = 0;
		}
		count[i] = 0;
	}
	for(i=1;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
	}
	for(i=1;i<n;i++){
		scanf("%d",&d[i]);
		map[i][p[i]] = map[p[i]][i] = d[i];
		count[i]++;
		count[p[i]]++;
	}

	int cost = 0;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(count[i] == 1 || count[j] == 1) cost += map[i][j];
			else cost += (3 * map[i][j]);
		}
	}

	int point = -1;
	int maxint = -1;
	for(i=0;i<n;i++){
		if(count[i] > 1){
			dp(i,-1,n,0,&maxint,&point); //?????¨??°?????????????????¨????????????????????¨?????±???,?????§?????±???????????????
			break;
		}
	}
	maxint = -1;
	dp(point,-1,n,0,&maxint,&point);
	cost -= maxint;
	return cost;
}

int main(){
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		printf("%d\n",bridge(n));
	}
	return 0;
}

Measured memory_bytes: 3168
def main():
    A, B, C, K = map(int, input().split())
    V = 0

    if A >= K:
        V += K
        K = 0
    else:
        V += A
        K -= A

    if B >= K:
        K = 0
    else:
        K -= B

    if C >= K:
        V -= K
        K = 0
    else:
        V -= C
        K -= C

    print(V)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
package main

import (
  "fmt"
)

func stringReplaceAtIndex(s string, r rune, i int) string {
  runes := []rune(s); runes[i] = r
  return string(runes)
}

func main() {
  var s string; fmt.Scan(&s)
  fmt.Println(stringReplaceAtIndex(s, '8', 3))
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;

    public static void main(String[] args){
        while(read()){
            slove();
        }
    }
    static boolean read(){
        if(!sc.hasNext())return false;
        n = sc.nextInt();
        return true;
    }
    static void slove(){
        double Debt = 100000;
        for(int i = 0; i < n; i++){
            Debt = Debt*1.05;
            int r = (int)Debt%1000;
            if(r != 0){
                Debt += 1000;
                Debt -= r;
                //Debt = Math.round(Debt);
            }
        }
        System.out.println((int)Debt);
    }


}

Measured memory_bytes: 12000
#include<stdio.h>
#include<stdlib.h>
int H[2000000000];

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

void print(int *H,int i,int n){
  int l,r,p;
  l=left(i);
  r=right(i);
  p=parent(i);
  printf("node %d: key = %d, ",i,H[i]);
  if(i==1){
    if(l<=n){
      printf("left key = %d, ",H[l]);
}
    if(r<=n){
      printf("right key = %d, ",H[r]);
}

}
  else {
    if(p<=n){
      printf("parent key = %d, ",H[p]);
}
    if(l<=n){
      printf("left key = %d, ",H[l]);
    }
    if(r<=n){
      printf("right key = %d, ",H[r]);
    }


}
  printf("\n");
}

int main(){
  int i,n;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&H[i]);
}
  for(i=1;i<=n;i++){
    print(H,i,n);
}

  return 0;
}



Measured memory_bytes: 2044
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long> a(n), b(n);
    FOR(i, 0, n) {
        cin >> a[i] >> b[i];
    }
    FOR(i, 0, n) {
        a[i] = (b[i] - a[i] % b[i]) % b[i];
    }
    long long sumx = 0;
    long long before = 0;
    RFOR(i, n - 1, 0) {
        if (a[i] < before) {
            long long d = before - a[i];
            a[i] = before + (b[i] - d%b[i]) % b[i];
        }
        sumx += a[i] - before;
        before = a[i];
    }
    cout << sumx << endl;
    return 0;
}

Measured memory_bytes: 1792
n,m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

total = sum(A)
limit = total/(4*m)

cannot = 0
for i in range(m):
  if A[i]<limit:
    cannot=1
    break
    
if cannot:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

int main() {
	char a;
	cin >> a;

	if (a - 'a' <= 26 && a - 'a' >= 0) {
		cout << 'a' << endl;
	}
	else {
		cout <<'A' << endl;
	}

}






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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using vi  = vector<int>;

signed main(){
  int n; cin >> n;
  vi a(5); rep(i,5) cin >> a[i];
  int minv = *min_element(all(a));
  cout << (n+minv-1)/minv-1+5 << endl;  
}


Measured memory_bytes: 256
def bellmanford(n,edge)
  (n-1).times do
    edge.each do |i,j,k|
      if $score[i-1]+k > $score[j-1]
        $score[j-1] = $score[i-1]+k
      end
    end
  end
  return $score[-1]
end
n,m = gets.chomp.split(" ").map(&:to_i)
edge = m.times.map{gets.chomp.split(" ").map(&:to_i)}
$score = Array.new(n,-10**12)
$score[0] = 0
ans = bellmanford(n,edge)
if ans != bellmanford(n,edge)
  puts "inf"
else
  puts ans
end

Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <array>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back

const int dx[]={1,1,1,0,0,-1,-1,-1};
const int dy[]={-1,0,1,-1,1,-1,0,1};
inline bool in(int x, int y){ return 0<=x&&x<4&&0<=y&&y<4; }
int n;
char board[4][5];
array<int,100> v,w,c;
array<string,100> word;
array<array<bool,4>,4> used;
array<int,10001> dp;

void dfs(int i,int x,int y,int si){
    const string& s=word[si];
    used[y][x]=1;
    if(i==(int)s.size()-1){
        c[si]++;
    } else {
        rep(d,8){
            int nx=x+dx[d], ny=y+dy[d];
            if(in(nx,ny) && s[i+1]==board[ny][nx] && !used[ny][nx])
                dfs(i+1,nx,ny,si);
        }
    }
    used[y][x]=0;
}

int main(){
    cin>>n;
    rep(i,n){
        cin>>word[i];
        cin>>v[i];
        w[i]=word[i].size();
    }
    rep(i,4) cin>>board[i];
    rep(si,n)rep(y,4)rep(x,4){
        if(word[si][0]==board[y][x]) dfs(0,x,y,si);
    }
    int sum;cin>>sum;
    rep(i,n){
        if(c[i]==0) continue;
        for(int j=sum; j>=0; j--){
            for(int k=1; k<=c[i] && j-w[i]*k>=0; k++){
                dp[j]=max(dp[j],dp[j-w[i]*k]+v[i]*k);
            }
        }
    }
    cout<<dp[sum]<<endl;
}

Measured memory_bytes: 1248
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, M = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

requires = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# dp[i][0]: i 個のマッチ棒を使って作れる整数の最大の桁数
# dp[i][1][-j]: j を何個作るか
dp = [(0, [0] * 9) for _ in range(N + 10)]
for i in range(N):
    d, counts = dp[i]
    if i > 0 and d == 0:
        continue
    for a in A:
        cnts = counts[:]
        cnts[-a] += 1
        dp[i + requires[a]] = max(dp[i + requires[a]], (d + 1, cnts))
ans = ''
for i, cnt in enumerate(dp[N][1]):
    ans += str(9 - i) * cnt
print(ans)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vll v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
namespace mp = boost::multiprecision;
using INT = mp::cpp_int;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T &b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T &b) {
	a = min(a, b);
}

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

int main() {
	makei(N);
	makev(t, N);
	INT ans = 1;
	rep(N) {
		ans = ans * t[i] / gcd(ans, t[i]);
	}
	say(ans);
}

Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
 
const int N = 2e3 + 100, OO = 1e16 + 1000, T = 150, M = 1e9 + 7, P = 6151, SQ = 1000, lg = 44;
typedef pair <int, int> pii;
string s[5], t[5];
int a[5], ans = OO;
bool is[5][5][N];

void Do() {
	int n = (int)s[a[0]].size(), m = (int)s[a[1]].size(), k = (int)s[a[2]].size();
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= max(n, m); j++) {
			if(!is[a[0]][a[1]][i])
				continue;
			int q = max(n, i + m);
			if(j <= m)
				if(!is[a[1]][a[2]][j])
					continue;
			if(j > m && i + j > n)
				continue;
			if(i + j <= n && !is[a[0]][a[2]][i + j])
				continue;
			q = max(q, i + j + k);
			ans = min(ans, q);
		}
	}
}

int32_t main() {
	use_fast;	
	cin >> s[0] >> s[1] >> s[2];
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			if(i == j)
				continue;
			for(int k = 0; k <= (int)s[i].size(); k++) {
				int h = 0;
				bool u = true;
				for(int l = k; l < (int)s[i].size(); l++) {
					if(h < (int)s[j].size()) {
						if(s[j][h] != '?' && s[i][l] != '?' && s[j][h] != s[i][l]) {
							u = false;
							break;
						}
					}
					h++;
				}
				is[i][j][k] = u;
//				cout << i << " " << j << " " << k << " " << is[i][j][k] << endl;
			}
		}
	}
	a[0] = 0, a[1] = 1, a[2] = 2;
	do {
		Do();
	}
	while(next_permutation(a, a + 3));
	cout << ans << endl;
	return 0;
} 
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

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

typedef long long LL;

const int N=100005;

int n,cnt,last[N],deg[N];
struct edge{int to,next;}e[N*2];
LL f[N],a[N];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

bool dfs(int x,int fa)
{
	if (deg[x]==1) {f[x]=a[x];return 1;}
	LL mx=0;
	for (int i=last[x];i;i=e[i].next)
	{
		if (e[i].to==fa) continue;
		if (!dfs(e[i].to,x)) return 0;
		f[x]+=f[e[i].to];
		mx=max(mx,f[e[i].to]);
	}
	if (f[x]<a[x]||f[x]-mx<f[x]-a[x]) return 0;
	f[x]-=(f[x]-a[x])*2;
	if (f[x]<0) return 0;
	else return 1;
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	if (n==2) {puts(a[1]==a[2]?"YES":"NO");return 0;}
	for (int i=1;i<n;i++)
	{
		int x=read(),y=read();
		deg[x]++;deg[y]++;
		addedge(x,y);
	}
	int rt;
	for (int i=1;i<=n;i++) if (deg[i]>1) {rt=i;break;}
	if (!dfs(rt,0)) puts("NO");
	else if (!f[rt]) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
struct SegmentTree {
    int N;
    vector<Int> A;
    SegmentTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        A.resize(2 * N);
    }
    void add(int idx, Int val) {
        idx += N;
        A[idx] += val;
        idx >>= 1;
        while (idx > 0) {
            A[idx] = A[2*idx+0] + A[2*idx+1];
            idx >>= 1;
        }
    }
    Int sum(int L, int R) {
        L += N, R += N;
        Int ans = 0;
        while (L < R) {
            if (L & 1) ans += A[L++];
            if (R & 1) ans += A[--R];
            L >>= 1, R >>= 1;
        }
        return ans;
    }
};
int main() {
    int N; cin >> N;
    vector<string> S(N); for (auto &s : S) cin >> s;
    vector<string> R = S;
    for (auto &r : R) reverse(begin(r), end(r));
    sort(begin(R), end(R));
    vector<SegmentTree> st;
    vector<vector<int>> cnt(N, vector<int>(26));
    for (int i = 0; i < 26; i++) {
        st.emplace_back(N);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < R[i].size(); j++) {
            cnt[i][R[i][j] - 'a']++;
        }
        for (int j = 0; j < 26; j++) {
            if (cnt[i][j] > 0) {
                st[j].add(i, +1);
            }
        }
    }
    vector<int> currSet, nextSet;
    for (int i = 0; i < N; i++) currSet.push_back(i);
    int num = 1;
    Int ans = 0;
    while (!currSet.empty()) {
        for (int i : currSet) {
            if (R[i].size() == num) {
                string head = R[i].substr(0, R[i].size() - 1);
                int idx0 = lower_bound(begin(R), end(R), head) - begin(R);
                int idx1 = upper_bound(begin(R), end(R), head + '|') - begin(R);
                ans += st[R[i][R[i].size() - 1] - 'a'].sum(idx0, idx1) - 1;
            }
        }
        nextSet.clear();
        for (int i : currSet) {
            char ch = R[i][num - 1];
            cnt[i][ch - 'a']--;
            if (cnt[i][ch - 'a'] == 0) {
                st[ch - 'a'].add(i, -1);
            }
            if (R[i].size() > num) {
                nextSet.push_back(i);
            }
        }
        swap(currSet, nextSet);
        num++;
    }
    cout << ans << endl;
    return 0;
}


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

const int N = 1000005;
char str[N] , s[N];
int n , top;


int main() {
    scanf("%s" , str);
    n = strlen(str);

    for (int i = 0 ; i < n ; ++ i) {
        s[top ++] = str[i];
        while (top >= 2 && s[top - 2] == 'S' && s[top - 1] == 'T') {
            top -= 2;
        }
    }
    printf("%d\n" , top);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  
  long long n;
  cin>>n;
  if(n==1){
    cout<<"YES"<<endl;
    return 0;
  }
  long long a[n];
  long long s=0;
  for(long long i=0;i<n;i++){
    cin>>a[i];
    s += a[i];
  }
  long long temp = (n+1)*n/2;
  if(s%temp!=0){
    cout<<"NO"<<endl;
    return 0;
  }
  long long k = s/temp;//必要な操作回数
  long long d[n];
  for(long long i=0;i<n;i++){
    d[i]=a[(i+1)%n]-a[i];
  }
  bool flag = true;
  for(long long i=0;i<n;i++){
    if(d[i]>k){
      flag = false;
      break;
    }else if(((d[i]-k)%n+n)%n==0){
      continue;
    }else{
      flag = false;
      break;
    }
  }
  
  if(flag){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  vector<char> op(3);
  for (int i = 0; i < (1<< 3); i++) {
    bitset<3> b(i);
    ll cnt = s.at(0) - '0';
    bool flag = false;
    for (int j = 0; j < 3; j++) {
      if (b.test(j)) {
        cnt += s.at(j + 1) - '0';
      } else {
        cnt -= s.at(j + 1) - '0';
      }
    }
    if (cnt == 7) {
      
      for (int i = 0; i < 3; i++) {
        if (b.test(i)) {
      		op.at(i) = '+';
    	} else {
      	op.at(i) = '-';
    	}
      }
      
      break;
    }
  }
  
  /*vector<char> op(3);
  for (int i = 0; i < 3; i++) {
    if (b.at(i) == 1) {
      op.at(i) = '+';
    } else {
      op.at(i) = '-';
    }
  }*/
  
  printf ("%ld%c%ld%c%ld%c%ld=7\n", s.at(0) - '0', op.at(0), s.at(1) - '0', op.at(1), s.at(2) - '0', op.at(2), s.at(3) - '0');
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int i,t1=0,t2=0;
    string s;
    cin>>s;
    for (i=0;i<s.size();i++)
    {
        if (i&1)
        {
            if (s[i]=='1')
                t2++;
            else
                t1++;
        }
        else
        {
            if (s[i]=='0')
                t2++;
            else
                t1++;
        }
    }
    cout<<min(t1,t2)<<endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) cin >> A.at(i);

  int cnt = 0;
  for (int i = N; i > 0; i--) {
    for (int j = i + i; j <= N; j += i) A.at(i) ^= A.at(j);
    if (A.at(i)) cnt++;
  }

  cout << cnt << "\n";
  for (int i = 1; i <= N; i++) if (A.at(i)) cout << i << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int d[500005], a[500005], b[500005];

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

	int N, D; cin >> N >> D;
	for (int i = 0; i < N; ++i) cin >> d[i];
	
	a[0] = D;
	for (int i = 0; i < N; ++i) a[i + 1] = min(abs(a[i] - d[i]), a[i]);

	b[N] = 1;
	for (int i = N; i > 0; --i) {
		b[i - 1] = b[i] + (b[i] > d[i - 1] / 2 ? d[i - 1] : 0);
	}
	
	int Q; cin >> Q;
	while (Q--) {
		int q; cin >> q;
		cout << (a[q - 1] >= b[q] ? "YES\n" : "NO\n");
	}
}

Measured memory_bytes: 9480
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int k;
    cin>>k;
    vector<int>func(k+1);
  for(int i=1;i<=k;i++)
   {

       for(int j=i;j<=k;j+=i)
        func[j]++;
   }
    unsigned long long ans=0;
    for(int i=1;i<=k;i++)
        ans+=i*(1ll)*func[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 42308
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    char ans = abs(x-a) < abs(x-b) ? 'A' : 'B';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ma = 0
mi = 0
ans = 0

for i in range(K):
  ma = (ma + N - i) % MOD
  mi = (mi + i) % MOD

t = ma - mi + 1
while t < 0:
  t += MOD

ans = (ans + t) % MOD

for i in range(K, N + 1):
  ma = (ma + N - i) % MOD
  mi = (mi + i) % MOD
  t = ma - mi + 1
  while t < 0:
    t += MOD
  ans = (ans + t) % MOD

print(ans)




Measured memory_bytes: 9212
# Date [ 2020-08-23 14:02:31 ]
# Problem [ e.py ]
# Author Koki_tkg
# After Contest

import sys;          from decimal import Decimal
import math;         from numba import njit, i8, u1, b1
import bisect;       from itertools import combinations, product
import numpy as np;  from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints(x=0):  return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    h, w, m = read_ints()
    bomb = set([tuple(read_ints(x=1)) for _ in range(m)])
    
    row = [0] * h
    column = [0] * w
    for y, x in bomb:
        row[y] += 1
        column[x] += 1
        
    max_row = max(row)
    max_col = max(column)
    
    max_row_lis = [i for i, y in enumerate(row) if y == max_row]
    max_col_lis = [i for i, x in enumerate(column) if x == max_col]

    for r in max_row_lis:
        for c in max_col_lis:
            if (r, c) not in bomb:
                print(max_col + max_row)
                exit()

    print(max_col + max_row - 1)


if __name__ == '__main__':
    Main()

Measured memory_bytes: 166212
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<long long> a(x), b(y), c(z), ans_1(x*y);
	for (int i = 0; i < x; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < y; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < z; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			ans_1[i * y + j] = a[i] + b[j];
		}
	}
	sort(ans_1.begin(), ans_1.end(), [](long long &i, long long &j) {return i > j;});
	vector<long long>ans_2(ans_1.begin(), ans_1.begin() + min(3000, x*y));
	vector<long long>ans_3(ans_2.size() * z, 0);
	for (int i = 0; i < ans_2.size(); i++) {
		for (int j = 0; j < z; j++) {
			ans_3[i * z + j] = ans_2[i] + c[j];
		}
	}
	sort(ans_3.begin(), ans_3.end(), [](long long &i, long long &j) {return i > j;});
	for (int i = 0; i < k; i++) {
		cout << ans_3[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	string X;
  	cin >> X;
  	bool sflag = false;
  	bool nflag = false;
  	bool eflag = false;
  	bool wflag = false;
  	rep(i,X.size()){
      if(X[i] == 'S') sflag = true;
      if(X[i] == 'N') nflag = true;
      if(X[i] == 'E') eflag = true;
      if(X[i] == 'W') wflag = true;
    }
 
 	if(sflag && !nflag) cout << "No" << endl;
  	else if (!sflag && nflag) cout << "No" << endl;
  	else if (!wflag && eflag) cout << "No" << endl;
  	else if (wflag && !eflag) cout << "No" << endl;
  	else cout << "Yes" << endl;
}

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

using namespace std;

const int kMod = 1e9 + 7;

int main() {
    
    int n; cin >> n;
    vector<int> g(n, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int now; cin >> now;
            if (now) g[i] |= (1 << j);
        }
    }

    vector<int> dp(1 << n, 0);
    dp[0] = 1;

    for (int msk = 0; msk < (1 << n); ++msk) {
        int i = __builtin_popcount(msk);
        for (int j = 0; j < n; ++j) {
            if (msk & (1 << j)) continue;
            if (g[i] & (1 << j)) {
                dp[msk | (1 << j)] += dp[msk];
                dp[msk | (1 << j)] %= kMod;
            }
        }
    }

    cout << dp[(1 << n) - 1] << endl;

    return 0;
}


Measured memory_bytes: 8448
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	string s, t;
	cin >> s;

	for (int i = 0; i < s.length(); i++)
	{
		t += (i % 2 == 0) ? s.substr(i, 1) : "";
	}

	cout << t << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <ctype.h>
using namespace std;
int a,b;
char c;
int k;
vector<string> his;
int main(void)
{
    string s;
    cin >> a;
    cin >> s;
    his.push_back(s);
    k = s.size();
    c = s[k-1];
    for(int i = 1; i < a; i++)
    {
        cin >> s;
        k = s.size();
        auto itr = find(his.begin(), his.end(), s);
        if((s[0] != c) || (itr != his.end())){
            cout << "No";
            return 0;
        }
        his.push_back(s);
        c = s[k-1];
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

UL gcd(UL a, UL b) { return b ? gcd(b, a % b) : a; }

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL G; cin >> G;
		rep(i, N - 1) {
			UL a; cin >> a;
			G = gcd(G, a);
		}
		cout << G << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9
#define         lli         long long int

using namespace std;

///ISNJB

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {
    /***freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;


    return 0;
}


Measured memory_bytes: 3616
N = int(input())
lis = [[0, 0, 1]]
for i in range(N - 1):
    C, S, F = map(int, input().split())
    lis.append([C, S, F])

# i 駅スタート の電車
for i in range(N):
    C, S_ij, F = 0, 0, 1
    for j in range(i + 1, N):  # j 駅に着く
        C, S, F = lis[j]
        S = max(S, S_ij)  # max（j 駅のスタート時間、 ij 間の時間）
        S_ij = C + ((S - 1) // F + 1) * F
    print(S_ij)


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

using namespace std;
// using P = pair<long, long>;
using P = pair<double, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))

#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

vector<int> G[200005];

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

  int n;
  cin >> n;

  vector<P> hen;
  map<P, int> colors;

  rep(i, n-1) {
    long a, b;
    cin >> a >> b;
    hen.push_back({a, b});
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i, n) {
    set<int> c;
    for(auto x: G[i]) {
      if (colors.find({i, x}) != colors.end()) {
        c.insert(colors[{i, x}]);
      }
    }
    int j = 1;
    for(auto x: G[i]) {
      if (colors.find({i, x}) != colors.end()) {
        continue;
      }
      while (c.find(j) != c.end()) {
        j++;
      }
      colors[{i, x}] = j;
      colors[{x, i}] = j;
      j++;
    }
  }

  int mx = 1;
  rep(i, n-1) {
    mx = max(mx, colors[hen[i]]);
  }
  cout << mx << endl;

  rep(i, n-1) {
    cout << colors[hen[i]] << endl;
  }
}


Measured memory_bytes: 22384
'use strict'

const main = (input) => {
    const oparators = input.split('\n')[0].split('')
    let ans = 0
    for(let val of oparators){
        if(val === '+'){
            ans++
        }else{
            ans--
        }
    }
    console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define TLE() cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms.\n";
const ll MOD = 1E9+7;
const ll IINF = 1E18;
const int INF = 1e9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

const int N=105;
int n;
vector<pair<double,pair<ll,ll>>> p;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP(i,n){
		double x,y;
		cin>>x>>y;
		double angle=atan2(y,x)*180.0/PI;
		p.pb(mp(angle,mp(x,y)));
	}	
	sort(all(p));
	REP(i,n){
		p.pb(p[i]);
		p.back().fi+=360.0;
	}
	double res=0.0;
	REP(i,n){
		ll x=0,y=0;
		REP(j,n){
			if(p[i+j].fi-p[i].fi-180.0>EPS) break;
			x+=p[i+j].se.fi;
			y+=p[i+j].se.se;
			res=fmax(res,sqrt(x*x+y*y));
		}
	}
	cout<<fixed<<setprecision(12)<<res<<'\n';
}



Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define MN 12
int k;
int dp[MN][MN][MN];
int sm[MN][MN];
int calc(int st,int nd){
    dp[1][st][st]=1;
    FOR(i,2,nd){
        F0R(d,10){
            if(d!=0) dp[i][st][d]+=dp[i-1][st][d-1];
            dp[i][st][d]+=dp[i-1][st][d];
            if(d!=9) dp[i][st][d]+=dp[i-1][st][d+1];
        }
    }
    FOR(i,1,nd){
        F0R(j,10){
            sm[i][st]+=dp[i][st][j];
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>k;--k;
    F0R(j,10){
        calc(j,10);
    }
    int nd=1;
    int std=-1;
    while(nd!=0){
        bool ok=false;
        F0R(i,10){
            if(std==-1 && i==0) continue;
            else if(std!=-1 && abs(std-i)>1) continue;
            if(sm[nd][i]>k){
                cout<<i;
                --nd;
                ok=true;
                std=i;
                break;
            }else{
                k-=sm[nd][i];
            }
        }
        if(!ok){++nd;}
    }
    return 0;
}

Measured memory_bytes: 256
#define NDEBUG
NDEBUG


#include <algorithm>
#include <cassert>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <random>

#define FOR(i, n) for (int i = 0; i < (n); ++i)


typedef int64_t int64;


using namespace std;

/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    /// caide keep
    template<int N>
    struct bytetype {
        
    };

    /// caide keep
    template<>
    struct bytetype<4> {
        
    };

    /// caide keep
    template<>
    struct bytetype<3> {
        
    };

    /// caide keep
    template<>
    struct bytetype<2> {
        
    };

    /// caide keep
    template<>
    struct bytetype<1> {
        
    };

    /// caide keep
    template<>
    struct bytetype<0> {
        
    };

    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vector(istream& in, size_t n) {
    vector<T> ret(n);
    for (size_t i = 0; i < n; ++i) {
        ret[i] = next<T>(in);
    }
    return ret;
}


void solve(istream& in, ostream& out) {
    int n = next<int>(in);
    vector<int> a = next_vector<int>(in, n);
    int64 res = a[0] / 2;
    a[0] %= 2;
    FOR(i, n-1) {
        if (a[i] == 0) {
            res += a[i + 1] / 2;
            a[i + 1] %= 2;
        } else {
            if (a[i + 1]) {
                ++res;
                a[i + 1]--;
            }
            res += a[i + 1] / 2;
            a[i + 1] %= 2;
        }
    }
    out << res << endl;
}


int main() {
    solve(cin, cout);
    return 0;
}



Measured memory_bytes: 640
def calc(n,k):
    while n[0] == '0' and len(n)>1:
        n=n[1:]
    
    digit = len(n)
    if digit < k:
        return 0
    
    comb = [1]*(k+1)
    for i in range(1,k+1):
        comb[i] = comb[i-1] * (digit-i) //i
    if k==1:
        return 9*comb[1] + int(n[0])
    elif k==2:
        return (9**2)*comb[2] + (int(n[0])-1) * 9*comb[1] + calc(n[1:],1)
    elif k==3:
        return (9**3)*comb[3] + (int(n[0])-1) * (9**2) * comb[2] + calc(n[1:],2)

n=input()
k=int(input())
print(calc(n,k))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>

#define ll long long

using namespace std;

int v[505][505] = {0};
int h[505][505] = {0};
int n;
int diff[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

void
dfs(int i, int j) {
  for (int k = 0; k<4; k++) {
    int x = i + diff[k][0];
    int y = j + diff[k][1];

    if (v[x][y] - h[x][y] > v[i][j]) {
      v[x][y]--;
      dfs(x, y);
    }
  }
}

void
solve() {
  cin>>n;

  int len = n+2;
  for (int i=0; i<len; i++)
    for (int j=0; j<len; j++) {
      v[i][j] = min(min(i, len-1-i), min(j, len-1-j)) - 1;
      h[i][j] = 1;
    }

  int ans = 0;
  int p;
  for (int k=0; k<n*n; k++) {
    cin>>p;

    int i = (p-1) / n + 1;
    int j = (p-1) % n + 1;
    ans += v[i][j];
    v[i][j]--;
    h[i][j] = 0;
    dfs(i, j);
  }

  cout<<ans<<endl;
}

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

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

int main() {
	int N; std::cin >> N;
	std::vector<int> A(N);
	std::vector<int> B(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> A[i];
		B[i] = A[i];
	}
	std::sort(B.begin(), B.end());
	for (auto& r : A)
		if (r < B[N - 1]) std::cout << B[N - 1] << std::endl;
		else std::cout << B[N - 2] << std::endl;

	return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        string[] days = new string[] { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
        string s = Console.ReadLine();

        int index = 0;
        for (int i = 0; i < days.Length; i++)
        {
            if (days[i].Equals(s))
            {
                index = i;
            }
        }
        Console.WriteLine(7 - index);
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication14
{
    //ONLINE JUDGE (ITP1_8_D)
 
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string p = Console.ReadLine();
 
            bool bl = false;
            string str1 = string.Concat(s, s);      //???????????????£????????????
            string str2 = ""; 
 
            for (int i = 0; i < str1.Length; ++i)
            {
                if (str1.Length - (i + 1) < p.Length)
                {
                    break;
                }
 
                if (p[0] == str1[i])                
                {
                    str2 = str1.Substring(i, p.Length);         //???????????????????????????????????????????????????
 
                    if (p == str2)
                    {
                        bl = true;
                        break;
                    }
                }
            }
 
            if (bl)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main(){
  int N;
  cin >> N;
  
  int A[N];
  for(int i = 0; i < N;i++){
      cin >> A[i];
  }
  
  sort(A,A + N);
  
  int res = 1;
  for(int i = 0; i < N - 1;i++){
      if(A[i] == A[i + 1]) res = 0;
  }
  
  if(res == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 using namespace std;     
 int main()
{
    int n,i,k,j,p;
    cin >> n ;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++)
        cin >> a[i] >> b[i] >> c[i];
    int dp[n][3];
    dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
    for(i=1;i<n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <atcoder/convolution.hpp>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int MOD = 998244353;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pwr(int a, int b) {
	if (!b) return 1;
	int r = pwr(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}


const int MAXX = 1e5+7;
int fact[MAXX], ifact[MAXX];

int nCr(int n, int r) {
    if (r < 0 || n < r) return 0;
    return mul(fact[n], mul(ifact[r], ifact[n-r]));
}

int fr[MAXX];
int pinv[MAXX];
int dfact[MAXX];

vector< vector< mint > >w;
typedef pair< int , int >PII;

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

    fact[0] = 1;
    for (int i = 1; i < MAXX; i++)      fact[i] = mul(i, fact[i-1]);
    ifact[MAXX-1] = pwr(fact[MAXX-1], MOD-2);
    for (int i = MAXX-2; i >= 0; i--)   ifact[i] = mul(i+1, ifact[i+1]);

    pinv[0] = 1;
    pinv[1] = pwr(2, MOD-2);
    for (int i = 2; i < MAXX; i++) pinv[i] = mul(pinv[i-1], pinv[1]);

    dfact[0] = 1;
    for (int i = 2; i < MAXX; i+=2) dfact[i] = mul(dfact[i-2], i-1);

    int n;
    cin >> n;

    for (int i = 0; i < n+n; i++) {
        int h;
        cin >> h;
        fr[h]++;
    }

    priority_queue< PII >pq;
    for (int i = 1; i < MAXX; i++) {
        if (fr[i] == 0) continue;
        w.emplace_back();
        for (int j = 0; j+j <= fr[i]; j++) {
            w.back().push_back(mul(fact[fr[i]], mul(ifact[j], mul(ifact[fr[i]-j-j], pinv[j]))));
        }
        if (w.size() > 1 && w.back().size() == 1) {
            w.pop_back();
        } else {
            pq.emplace(-w.size(), w.size()-1);
        }
    }

    while (pq.size() > 1) {
        PII u = pq.top(); pq.pop();
        PII v = pq.top(); pq.pop();
        w[u.second] = convolution(w[u.second], w[v.second]);
//        w[u.second] = ntt.multiply(w[u.second], w[v.second]);
        while (w[u.second].size() > 1 && w[u.second].back() == 0) w[u.second].pop_back();
        pq.emplace(-w[u.second].size(), u.second);
    }

    int z = pq.top().second;
//    for (int i = 0; i < w[z].size(); i++) {
//        cout << "ways[" << i << "] = " << w[z][i] << endl;
//    }

    int ans = 0;
    for (int i = 0; i <= n && i < w[z].size(); i++) {
        int tmp = mul(w[z][i].val(), dfact[(n-i)*2]);
        if (i&1) ans = sub(ans, tmp);
        else ans = sum(ans, tmp);
    }

    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 11012
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[1000005];
char s[1000005];
ll b[1000005];
int main()
{
	ll n;
	scanf("%lld",&n);
	scanf(" %s",s);
	bool one=0;
	for(ll i=0;i<n;i++)
	{
		a[i]=s[i]-'1';
		if(a[i]==1) one=true;
	}
	if(!one)
	{
		for(ll i=0;i<n;i++) a[i]/=2;
	}
	else
	{
		for(ll i=0;i<n;i++) a[i]%=2;
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ll j=n-1-i;
		if((j^i)==(j+i))
		{
			ans^=a[i];
		}
	}
	if(!one)
	{
		ans*=2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 10752
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-05-03 21:03:15 +0900
# LastModified: 2020-05-03 21:09:37 +0900
#


import os
import sys


def main():
    n,k=map(int,input().split())
    child=[0]*n
    for i in range(k):
        d = int(input())
        a = list(map(int,input().split()))
        for a_ in a:
            child[a_-1]=1
    print(child.count(0))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf: VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf: VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn nextN<T>(&mut self, n: usize) -> Vec<T> where T: FromStr, T::Err: Debug {
            let mut vec: Vec<T> = Vec::with_capacity(n);
            for i in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

fn main() {
    let mut reader = reader::Reader::new();

    let a = vec![1, 3, 5, 7, 8, 10, 12];
    let b = vec![4, 6, 9, 11];
    let c = vec![2];

    let d = vec![a, b, c];

    let x: i32 = reader.next();
    let y: i32 = reader.next();

    let mut b = false;
    for i in 0..3 {
        b |= d[i].contains(&x) && d[i].contains(&y)
    }

    println!("{}", if b {"Yes"} else {"No"});
}
 

Measured memory_bytes: 4352