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

#define ll long long
#define pb push_back
#define mp make_pair
#define mo 1000000007
#define MAX 1000004
#define fast_io ios::sync_with_stdio(false)
ll wt[101], a[101];
map<ll, ll> m1;
ll m2[5];
vector<long long> arr[5];
vector<long long> arr2[5];
int main()
{
	fast_io;
	ll n, w;
	cin >> n >> w;
	int ct = 1;
	for(int i=1;i<=n;i++)
	{
		cin >> wt[i] >> a[i];
		if(m1.find(wt[i])==m1.end())
		{
			m1[wt[i]] = ct++;
			m2[m1[wt[i]]] = wt[i];
		}
	}
	for(int i=1;i<=n;i++)
		arr[m1[wt[i]]].pb(a[i]);
	for(int i=1;i<ct;i++)
	{
		sort(arr[i].begin(), arr[i].end());
		reverse(arr[i].begin(), arr[i].end());
		arr2[i].pb(0);
		long long temp = 0;
		//cout << i << " " << m2[i] << "\n"; 
		for(int j=0;j<arr[i].size();j++)
		{
			temp+=arr[i][j];
			arr2[i].pb(temp);
			//cout << temp << "\n";
		}
	}
	// for(int i=1;i<ct;i++)
	// {
	// 	cout << "Weight - " << i << " " << m2[i] << "\n";
	// 	for(int j=0;j<arr2[i].size();j++)
	// 		cout << arr2[i][j] << " ";
	// 	cout << "\n";
	// }
	long long ans = 0;
	for(int i=0;i<=(w/(m2[1])) && i<arr2[1].size();i++)
	{
		long long temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;
		temp1 = arr2[1][i];
		ans = max(ans, temp1);
		if(ct>2)
		{
			for(int j=0;j<=(w - m2[1]*i)/m2[2] && j<arr2[2].size();j++)
			{
				temp2 = arr2[2][j];
				if(ct>3)
				{
					for(int k=0;k<=(w - 1ll*m2[1]*i - 1ll*m2[2]*j)/m2[3] && k<arr2[3].size();k++)
					{
						temp3 = arr2[3][k];
						if(ct > 4)
						{
							for(int p = 0 ; p <= (w - 1ll*m2[1]*i - 1ll*m2[2]*j - 1ll*m2[3]*k)/m2[4] && p<arr2[4].size();p++)
							{
								temp4 = arr2[4][p];
								ans = max(ans, temp1 + temp2 + temp3 + temp4);
							}
						}
						ans = max(ans, temp1 + temp2 + temp3);
					}

				}
				ans = max(ans, temp1 + temp2);
			}
		}

	}
	cout << ans;


	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  std::vector<int64_t> x(n),y(n),z(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>z[i];
  }

  int64_t result=0;
  for(int xi=0;xi<=1;xi++){
    for(int yi = 0; yi < 2; ++yi){
      for(int zi = 0; zi < 2; ++zi){
        std::vector<int64_t> sweets(n);
        for(int si=0;si<n;si++){
          if(xi==0){
            sweets[si]+=x[si];
          }else{
            sweets[si]-=x[si];
          }
          if(yi==0){
            sweets[si]+=y[si];
          }else{
            sweets[si]-=y[si];
          }
          if(zi==0){
            sweets[si]+=z[si];
          }else{
            sweets[si]-=z[si];
          }
        }
        std::sort(sweets.begin(), sweets.end(), std::greater<>());

        int64_t tmp_result=0;
        for(int i=0;i<m;i++){
          tmp_result+=sweets[i];
        }
        result=std::max(result,tmp_result);

      }
    }
  }
  cout<<result<<endl;
  
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
ll exgcd(ll a, ll b, ll & x, ll & y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;	
	}
	ll d = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll pow(ll a, ll b, ll MOD) {
	ll ans = 1;
	a%=MOD;
	while(b){
		if(b&1) ans=(ll)ans*a%MOD;
		a=(ll)a*a%MOD;
		b>>=1;
	}
	return ans;
}
ll inv(ll a,ll MOD)
{
ll x,y;
exgcd(a,MOD,x,y);
x=(x%MOD+MOD)%MOD;
return x;
}
ll inv2(ll a,ll MOD)
{
ll x=pow(a,MOD-2,MOD);
return x;
}
ll C(ll n,ll m,ll p)
{
if(m>n) return 0;
ll a=1,b=1;
//组合数 C(n,m)=[n*(n-1)*...*(n-m+1)]/[m*(m-1)*...*1]
while(m){
a=a*n%p;
b=b*m%p;
n--;
m--;
}
return (ll)a*inv(b,p)%p;
}
ll lucas(ll n,ll m,ll p)
{
//递归结束条件 n>=m
if(m==0) return 1;
return (ll)C(n%p,m%p,p)*lucas(n/p,m/p,p)%p;
}
ll fac[200010];
void init(ll p) {
	fac[0] = 1;
	for (int i = 1; i <= p; i++) fac[i] = fac[i - 1] * i % mod;
}
ll lucas2(ll n, ll m) {
	ll ret = 1, a, b;
	while (n && m) {
		a = n % mod, b = m % mod;
		if (a < b) return 0;
		ret = ret * fac[a] % mod * inv(fac[b] * fac[a - b] % mod, mod) % mod;
		n /= mod, m /= mod;
	}
	return ret;
}
int main()
{
	ll x, y, n, m;
	
	scanf("%lld%lld%lld%lld", &n, &m, &x, &y);
	ll ans = 0;
	init(200005);
	ll z = y, p = n + m - 2;
	for (ll i = 0; i <= n - x - 1; i++) {
		ans = ans + lucas2(z + i - 1, i) * lucas2(p - z - i, n - 1 - i) % mod;
		ans %= mod;
		//printf("1  %lld  %lld\n", i, ans);
	}
	printf("%lld\n", ans);
}


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

struct Point { long long px, py; };

long long n, mod = 998244353; Point P[1009]; bool used[209][209];

bool solve(Point A, Point B, Point C) {
	if ((B.px - A.px)*(C.py - A.py) == (B.py - A.py)*(C.px - A.px)) return true;
	return false;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> P[i].px >> P[i].py;
	}
	long long ans = 1; for (int i = 1; i <= n; i++) { ans *= 2; ans %= mod; }
	ans += (mod - n - 1); ans %= mod;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (used[i][j] == true) continue;
			vector<int>G = { i,j };
			for (int k = j + 1; k <= n; k++) {
				if (solve(P[i], P[j], P[k]) == true) G.push_back(k);
			}
			for (int k = 0; k < G.size(); k++) {
				for (int l = k + 1; l < G.size(); l++) used[G[k]][G[l]] = true;
			}
			long long Y = 1; for (int k = 0; k < G.size(); k++) { Y *= 2; Y %= mod; }
			Y += (mod - G.size() - 1); Y %= mod;
			ans -= Y; ans += mod; ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();

    int n = sc.nextInt();
    String s = sc.next();

    for(int i = 0; i < s.length(); i++){
      if(s.charAt(i) + n > 'Z'){
        sb.append((char)(s.charAt(i) + n - 'Z' + 'A' - 1));
      } else {
        sb.append((char)(s.charAt(i) + n));
      }
    }

    String ans = sb.toString();

    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
table = list(map(int,input().split()))

for i in range(2,0,-1):
    k = 0
    while k < i:
        if table[k] > table[k+1]:
            table[k], table[k+1] = table[k+1], table[k]
        k +=1

print(table[0],table[1],table[2])



Measured memory_bytes: 5596
#include<iostream>
#include<vector>
using namespace std;
int parent(int a,vector<int>& p) {
  if(p[a] == a)return a;
  else return p[a] = parent(p[a],p);
}
void unite(int a,int b,vector<int>& p) {
  p[parent(a,p)] = parent(b,p);
}
int main() {
  int N,M,K;
  cin >> N >> M >> K;
  vector<int> FB(N,0),cnt(N,0),p(N);
  int i,j,a,b;
  for(i=0;i<N;i++)p[i] = i;
  for(i=0;i<M;i++) {
    cin >> a >> b;
    FB[a-1]++;
    FB[b-1]++;
    unite(a-1,b-1,p);
  }
  for(i=0;i<K;i++) {
    cin >> a >> b;
    if(parent(a-1,p) == parent(b-1,p)) {
      FB[a-1]++;
      FB[b-1]++;
    }
  }
  for(i=0;i<N;i++) {
    cnt[parent(i,p)]++;
  }
  for(i=0;i<N;i++)cout << cnt[parent(i,p)]-FB[i]-1 << endl;
}

Measured memory_bytes: 2560
package main

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

// 距離
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ary := strings.Split(sc.Text(), " ")
	x1, _ := strconv.ParseFloat(ary[0], 64)
	y1, _ := strconv.ParseFloat(ary[1], 64)
	x2, _ := strconv.ParseFloat(ary[2], 64)
	y2, _ := strconv.ParseFloat(ary[3], 64)
	fmt.Printf("%v\n", math.Sqrt(math.Pow((x2-x1), 2)+math.Pow((y2-y1), 2)))
}



Measured memory_bytes: 1132
#include <stdio.h>
int main ()
{
    int n,k,x,y,s;
    scanf ("%d %d %d %d",&n,&k,&x,&y);
    if (n<=k)
    {
        s = n*x;
    }
    else
    {
        s = k*x + y*(n-k);
    }
    printf ("%d", s);
    return 0;
}


Measured memory_bytes: 128
def main8():
    str = input('');
    buf = str.split();
    num = int(buf[0]);
    i = 0;
    n = 1;
    kouho = []
    while(True):
        n = n + 1;
        while(True):
            i = i + 1;
            if pow(i,n) <= num and num < pow(i+1,n):
                kouho.append(pow(i,n));
                break;
        i = 0;
        if pow(2,n+1) > num:
            break;
    print(max(kouho));
if __name__ == '__main__':
    main8()

Measured memory_bytes: 3188
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

string S;

int cnt(string S) {
	string p;
	int dif = 0, dif2 = 0;

	for (int i = 0; i < S.size(); i++) {
		if (i % 2 == 0) p.push_back('0');
		else p.push_back('1');
	}
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != p[i]) dif++;
	}

	p.clear();
	for (int i = 0; i < S.size(); i++) {
		if (i % 2 == 1) p.push_back('0');
		else p.push_back('1');
	}
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != p[i]) dif2++;
	}

	return min(dif, dif2);
}

int main(void){
	cin>>S;

	cout<< cnt(S) <<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;


int main(){
  long long r;
  cin >> r;
  cout <<3*r*r;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mod(int a)
{
	if(a>0)
	return a;
	return -a;
}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	int dp[n+1];
	dp[1]=0;
	dp[2]=mod(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
    	dp[i]=INT_MAX;
    	for(int j=i-1;j>=i-k && j>=1;j--)
    	{
    		dp[i]=min(dp[i],dp[j]+mod(a[i]-a[j]));
    	}
    	
    }
	cout<<dp[n];
	return 0;
	
}

Measured memory_bytes: 1024
class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3], self.data[5], self.data[2] = \
                self.data[3],self.data[5], self.data[2], self.data[0] 
        elif direction == 'N':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[1],self.data[5], self.data[4], self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[4],self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2], self.data[5], self.data[3] = \
                self.data[2],self.data[5], self.data[3], self.data[0]
        elif direction == 'R':
            self.data[1],self.data[2], self.data[4], self.data[3] = \
                self.data[2],self.data[4], self.data[3], self.data[1]


    def getTop(self):
        return self.data[0]

    def getRight(self, top, front):
        if self.data[0] != top:
            for i in range(4):
                if self.data[0] == top:
                    break
                self.move('E')
            for i in range(4):
                if self.data[0] == top:
                    break
                self.move('N')

        if self.data[1] != front:
            for i in range(3):
                self.move('R')
                if self.data[1] == front and self.data[0] == top:
                    break
        return self.data[2]

dice = Dice(input().split())
hoge = int(input())
fuga = []
for i in range(hoge):
    (x,y) = [j for j in input().split()]
    fuga += [dice.getRight(x,y)]
for i in fuga:
    print(i)

Measured memory_bytes: 6808
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

signed main() {
	string a; cin >> a;
	if (a[0] == a[2])puts("Yes");
	else puts("No");
}


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

using namespace std;

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

    string s;
    int tx, ty;
    cin >> s >> tx >> ty;

    if (s.back() == 'F') s += "T";
    const int n = s.size();
    vector<vector<char>> dpx(2, vector<char>(2 * n + 2, false));
    vector<vector<char>> dpy(2, vector<char>(2 * n + 2, false));

    int idx = 0, d = 0, dir = 0; // dir: 左右，上下
    while (idx < n && s[idx] == 'F') { ++d; ++idx; }
    dpx[idx % 2][n + d] = dpy[idx % 2][n] = true; // 原点 (n, n)

    int src = idx % 2, dst = (src + 1) % 2;
    while (idx < n) {
        // cout << "idx = " << idx << endl;
        // for (int p = 0; p <= 2 * n; ++p) {
        //     cout << p << ": " << (int)dpx[src][p] << " " << (int)dpy[src][p] << endl;
        // }
        // cout << endl;

        fill(dpx[dst].begin(), dpx[dst].end(), false);
        fill(dpy[dst].begin(), dpy[dst].end(), false);

        if (s[idx] == 'T') { // Turn
            for (int p = 0; p <= 2 * n; ++p) {
                dpx[dst][p] |= dpx[src][p];
                dpy[dst][p] |= dpy[src][p];
            }
            dir = (dir + 1) % 2;
        }
        else { // Foward
            for (d = 0; idx < n && s[idx] == 'F'; ++idx) ++d;
            --idx;

            for (int p = 0; p <= 2 * n; ++p) {
                if (dir == 0) {
                    if (0 <= p - d) dpx[dst][p - d] |= dpx[src][p];
                    if (p + d <= 2 * n) dpx[dst][p + d] |= dpx[src][p];
                    dpy[dst][p] |= dpy[src][p];
                }
                else {
                    if (0 <= p - d) dpy[dst][p - d] |= dpy[src][p];
                    if (p + d <= 2 * n) dpy[dst][p + d] |= dpy[src][p];
                    dpx[dst][p] |= dpx[src][p];
                }
            }
        }
        ++idx;
        swap(src, dst);
    }

    tx += n; ty += n;
    if (dpx[src][tx] && dpy[src][ty]) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 384
def f_d():
    from heapq import heappush, heappop

    n, m = map(int, input().split())
    ab = [[] for _ in range(m+1)]

    for _ in range(n):
        a, b = map(int, input().split())
        if a <= m:
            ab[a].append(b)

    q = []
    o = 0

    for i in range(m+1):
        for a in ab[i]:
            heappush(q, -a)
        if q:
            o += -heappop(q)
    
    print(o)


if __name__ == "__main__":
    f_d()


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int n, m, u, v ;
vvi adj ;
bool check ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    cin>> n >> m ;
    adj.resize(n+1) ;
    check=false ;
    for(int i=0 ; i<m ; i++)
      {
        cin>> u >> v ;
        adj[u].pb(v) ;
        adj[v].pb(u) ;
      }
    for(auto u:adj[1])
      if(u==n)
        check=true ;
    for(auto u:adj[1])
      for(auto v:adj[u])
        if(v==n)
          check=true ;
    if(check) cout<< "POSSIBLE" ;
    else cout<< "IMPOSSIBLE" ;
  }


Measured memory_bytes: 12016
n = gets.to_i
a = []
n.times{a << gets.to_i}
a.reverse!
i = 0
ctn = 0
if a[-1] != 0
    puts "-1"
    exit
end
while i < a.length - 1
    if a[i] != 0
        ar = []
        while a[i] >= a[i+1]
            if a[i] - a[i+1] > 1
                puts "-1"
                exit
            end
            ar << a[i]
            i += 1
            break if i == a.length - 1
        end
        ar << a[i]
        prev = ar[0]
        ctn += prev
        ar.shift
        while ar != []
            if ar.first == prev
                ctn += ar.first
            end
            prev = ar.first
            ar.shift
        end
    end
    i += 1
end
puts ctn


Measured memory_bytes: 6068
#include <stdio.h>
main(){
  int m,f,r;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1 && f==-1 && r==-1)break;
    if(m==-1 || f==-1){
      printf("F\n");
    }
    else if(m+f>=80){
      printf("A\n");
    }
    else if(m+f>=65 && m+f<80){
      printf("B\n");
    }
    else if(m+f>=50 && m+f<65){
      printf("C\n");
    }
    else if(r>=50){
      printf("C\n");
    }
    else if(m+f>=30 && m+f<50){
      printf("D\n");
    }
    else if(m+f<30){
      printf("F\n");
    }
  }
  return 0;
}

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

int main() {
    queue<pair<string, int>> q;
    int N, quantum;
    cin >> N >> quantum;
    rep(i, N) {
      string s;
      int t;
      cin >> s >> t;
      q.push(make_pair(s, t));
    }

    int timer = 0;
    while(!q.empty()) {
      pair<string, int> p = q.front(); q.pop();
      if (p.second > quantum) {
        p.second -= quantum;
        timer += quantum;
        q.push(p);
      } else {
        timer += p.second;
        cout << p.first << " " << timer << endl;
      }
    }
}


Measured memory_bytes: 6252
n=int(input())
s=input()
r=n//2
l=-1
while r-l>1:
  mid=(r+l)//2
  d=dict()
  ok=False
  for i in range(n-mid):
    ss=s[i:i+mid+1]
    if ss not in d:
      d[ss]=i
    else:
      if d[ss]+mid<i:
        ok=True
  if ok:
    l=mid
  else:
    r=mid
print(r)

Measured memory_bytes: 9452
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  int ans = 1;
  for (int i = 0; i + 1 < n; i++) {
    if (a[i] != a[i + 1]) ans++;
  }
  cout << ans << endl;
}


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

#define pb(a) push_back(a)
#define INF 1145141919810
#define mod 1000000007

typedef long long ll;

const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[dsize],fac[dsize];

template <class T = int> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%mod;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],mod-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%mod)*inv[n-r]%mod;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

bool ans[dsize];

class WarshallFloyd {
public:
	vector<vector<ll>> d;
	
	void init(int n);
	void wf(int n);
};
void WarshallFloyd::init(int n) {
	d = vector<vector<ll>>(n,vector<ll>(n,INF));
	for (int i=0;i<n;i++) d[i][i] = 0;
}
void WarshallFloyd::wf(int n) {
	for (int i=0;i<n;i++) {
		for (int j=0;j<n;j++) {
			for (int k=0;k<n;k++) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}
WarshallFloyd wf;
int main() {
	int n=in(),m=in();
	int ans;
	wf.init(n);
	vector<pair<pair<ll,ll>,ll>> edge;
	for (int i=0;i<m;i++) {
		int x=in(),y=in(),z=in();
		edge.push_back({{x-1,y-1},z});
		wf.d[x-1][y-1]=z;
		wf.d[y-1][x-1]=z;
	}
	wf.wf(n);
	for (int i=0;i<m;i++) {
		int x=edge[i].first.first,y=edge[i].first.second;
		if(wf.d[x][y]<edge[i].second) ans++;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int c[10][10];
  
  scanf("%d%d%d",&c[0][0],&c[0][1],&c[0][2]);
  scanf("%d%d%d",&c[1][0],&c[1][1],&c[1][2]);
  scanf("%d%d%d",&c[2][0],&c[2][1],&c[2][2]);

  if((c[0][0]-c[0][1]==c[1][0]-c[1][1])&&(c[0][0]-c[0][1]==c[2][0]-c[2][1])&&(c[0][1]-c[0][2]==c[1][1]-c[1][2])&&(c[0][1]-c[0][2]==c[2][1]-c[2][2])&&(c[0][0]-c[1][0]==c[0][1]-c[1][1])&&(c[0][0]-c[1][0]==c[0][2]-c[1][2])&&(c[1][0]-c[2][0]==c[1][1]-c[2][1])&&(c[1][2]-c[2][2]==c[1][1]-c[2][1]))printf("Yes\n");
  else printf("No\n");
  
  

      
  return 0;
}
  

   
      


Measured memory_bytes: 128
#include <iostream>

using namespace std;



int main () {
	int r,g,b;
	cin >> r >> g >> b;
	int ans = 100 * r + 10 * g + b;
	if(ans % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll a,b;

int main(){
    cin >> a >> b;
    ll ans = a*b;
    string bun = "Odd\n";
    if(ans % 2 == 0){
        bun = "Even\n";
    }
    cout << bun;

}

Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007

using namespace std;

int n, m, dp[1010][1010];

int main()
{
    cin >> n >> m;
    dp[1][0] = 1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            {   char c;
                cin >> c;
                if(c == '.') dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }
    cout << dp[n][m] << '\n';
    return 0;
}

Measured memory_bytes: 4224
import java.util.*;
public class Main{
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long b = 0;
         for (int i=1;i<=a;i++){
             if ( i % 3 == 0 || i % 5 == 0 ) continue;
            
             b+=i; 
         }
         
         System.out.println(b);
     }
}

Measured memory_bytes: 35532
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
using namespace std;

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

typedef long long lint;
typedef pair<int,int> P;

int main()
{

    string S;
    cin>>S;

    int max=0;
    int num=0;

    REP(i,S.size()){
    	if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
    		num ++;
    		if(max<num) max=num;
    	}else{
    		num = 0;
    	}
    }

    cout << max << endl;


}


Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      x: usize,
      _a: [usize; n]
   }

   let mut a = _a;
   let mut ans = 0;
   for i in 0..n - 1 {
      if a[i] + a[i + 1] > x {
         let diff = a[i] + a[i+1] - x;
         ans += diff;
         if a[i] <= x {
            a[i+1] -= diff;
         } else {
            a[i] -= diff - a[i+1];
            a[i+1] = 0;
         }
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void) {
    int sum,num,i,x,y,h,w;
    while (scanf("%d",&num)!=EOF&&num!=0) {
        sum=0;
        for (i=0; i<num; i++) {
            scanf("%d%d%d%d",&x,&y,&h,&w);
            x+=y+h;
            if (x<=60&&w<=2) {
                sum+=600;
            } else if (x<=80&&w<=5) {
                sum+=800;
            } else if (x<=100&&w<=10) {
                sum+=1000;
            } else if (x<=120&&w<=15) {
                sum+=1200;
            } else if (x<=140&&w<=20) {
                sum+=1400;
            } else if (x<=160&&w<=25) {
                sum+=1600;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 600
import Control.Applicative ((<$>))
import Data.List (intersperse)
import Data.Vector.Unboxed (Vector, (!), (//), fromList, toList, thaw, freeze)
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
import Debug.Trace (trace)

main :: IO ()
main = do
    n   <- readLn :: IO Int
    ns  <- fromList . (0 :) . map read . words <$> getLine :: IO (Vector Int)
    let maxHeap = runST $ do
            mns <- VU.thaw ns :: ST s (VUM.MVector s Int)
            forM_ [(n `div` 2), (n `div` 2 - 1)..1] $ \i -> maxHeapify i mns
            freeze mns
    putStrLn . (' ' :) . concat . intersperse " " . map show . tail . toList $ maxHeap


maxHeapify :: Int -> VUM.MVector s Int -> ST s ()
maxHeapify i xs = do
    root  <- VUM.read xs i
    let l    = i * 2
        r    = l + 1
        size = VUM.length xs
    case (size > l, size > r) of
        (True, False) ->
            VUM.read xs l >>= \left -> when (left > root) (VUM.swap xs i l >> maxHeapify l xs)

        (False, True) ->
            VUM.read xs r >>= \right -> when (right > root) (VUM.swap xs i r >> maxHeapify r xs)

        (True, True) ->
            VUM.read xs l >>= \left -> VUM.read xs r >>= \right ->
                if left > right then
                    when (root < left) (VUM.swap xs i l >> maxHeapify l xs)
                else
                    when (root < right) (VUM.swap xs i r >> maxHeapify r xs)
        (False, False) ->
            return ()


Measured memory_bytes: 141620
n,m=map(int,input().split())
x=[2,5,5,4,5,6,3,7,6]
a=[]
for i in map(int,input().split()):
    a.append([i,x[i-1]])
a.sort(reverse=True)
dp=[0]*(n+1)
for i in range(m):
    for j in range(n+1):
        if j==0 or dp[j]!=0:
            if j+a[i][1]<=n:
                dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])
print(dp[n])
'''
dp[i]をちょうどi本使った時に表せる最大の数と考えれば
(aが数字の値で降順ソートされていることにも注意して)、
a[i][0]をi番目に大きい数字、a[i][1]をその数を表すのに
必要なマッチ棒の本数として、
dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])
という更新を行ってdp[n]を求めれば良いです。
また、ある数字の組が決まればマッチの本数が一意に定まり
一番上の桁から順に大きい数字を入れるのが最適なので、
aを降順ソートして大きい数字から順に取ってDPを行うことで
これを実現することができます。
e.g. 9→3→3→2の順番に取れば、
((((0×10+9)×10+3)×10+3)×10+2)=9332((((0×10+9)×10+3)×10+3)×10+2)=9332
'''

Measured memory_bytes: 16488
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a: f64 = sc.read();
    let b: f64 = sc.read();
    let x: f64 = sc.read();
    let ans = bis_f64(0., 90., 0.00000000001, |deg| {
        let r = deg / 180. * std::f64::consts::PI;
        let t = r.tan();
        let h = a * t;
        if h <= b {
            x <= a * a * (b - h / 2.)
        } else {
            let w = b / t;
            x <= a * w * b / 2.
        }
    });

    format!("{:.10}\n", ans)
}
#[test]
fn test_solve() {
   assert_eq!(solve("2 2 4\n"), "45.0000000000\n");
   assert_eq!(solve("12 21 10\n"), "89.7834636934\n");
   assert_eq!(solve("3 1 8\n"), "4.2363947991\n");
}
fn bis_f64<P>(t: f64, f: f64, allow: f64, eval: P) -> f64
where
    P: Fn(f64) -> bool,
{
    if (t - f).abs() < allow {
        return t;
    }
    let m = (t + f) / 2.;
    if eval(m) {
        bis_f64(m, f, allow, eval)
    } else {
        bis_f64(t, m, allow, eval)
    }
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
#[allow(dead_code)]
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> pth[2010];

int dfs2(int idx,int par,int dep) {
	if (dep==0) return 0;
	int cnt=1;
	for (int i=0;i<(int)pth[idx].size();i++) {
		if (pth[idx][i]==par) continue;
		cnt+=dfs2(pth[idx][i],idx,dep-1);
	}
	return cnt;
}

int n,k;
int dfs(int idx,int par) {
	int ans=0;
	for (int i=0;i<(int)pth[idx].size();i++) {
		if (pth[idx][i]==par) continue;
		ans=max(ans,dfs2(pth[idx][i],idx,k));		
	}
	return ans+1;
}

vector<pair<int,int>> edge;

int main () {
	scanf("%d%d",&n,&k);
	int a,b;
	for (int i=1;i<n;i++) {
		scanf("%d%d",&a,&b);
		pth[a].push_back(b);
		pth[b].push_back(a);
		edge.push_back({a,b});
	}
	int mx=0;
	if (k%2==0) {
		for (int i=1;i<=n;i++) {
			mx=max(mx,dfs2(i,0,k/2+1));
		}
	} else {
		for (int i=0;i<(int)edge.size();i++) {
			mx=max(mx,dfs2(edge[i].first,edge[i].second,k/2+1)+dfs2(edge[i].second,edge[i].first,k/2+1));
		}
	}
	printf("%d\n",n-mx);
	return 0;
}


Measured memory_bytes: 384
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        mut n: usize,
        m: usize,
        h: [usize; n],
        ab: [(Usize1, Usize1); m],
    }
    let mut g = vec![true; n];
    for (a, b) in ab {
        if h[a] <= h[b] {
            g[a] = false;
        }
        if h[a] >= h[b] {
            g[b] = false;
        }
    }

    println!("{}", g.into_iter().filter(|&gi| gi).count());
}


Measured memory_bytes: 6612
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(3)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
const ll INF=1e18+8;
int a[N],vis[N];

int main(void){
    FAST_IO;
    int n;
    cin >> n;
    if(n<=999)
    cout <<"ABC";
    else    cout <<"ABD";
//    string s=to_string(n);
//    string t="";
//    while(s.size()<=2){
//        s.insert(0,"0");
//    }
//    cout <<s << endl;
    return 0;
}
/********

*********/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
const int maxn=1e6+100;
const double pi=4.0*atan(1.0);
int n,m,k,q;
int T;
int main()
{
    cin>>n;
    int x=n%10;
    if(x==2||x==4||x==5||x==7||x==9)
    {
        cout<<"hon"<<endl;
    }
    else if(x==0||x==1||x==6||x==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"bon"<<endl;
    }
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>

#define long long long int

#define MOD 1000000007

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;

    long res = 1;
    int last = 0;

    for (int i = 0; i < n; i++) {
        if (s1[i] == s2[i]) {
            if (i == 0) {
                res = 3;
            } else {
                if (last == 1) {
                    res *= 2;
                } else {
                    res *= 1;
                }
            }
            last = 1;
        } else {
            if (i == 0) {
                res = 6;
            } else {
                if (last == 1) {
                    res *= 2;
                } else {
                    res *= 3;
                }
            }
            i++;
            last = 2;
        }
        res %= MOD;
    }

    cout << res;


    return 0;
}

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

int main(int argc, char *argv[])
{
    int k, a, b;
    int diff;
    long long biscuit;
    long long money;
    int i;

    scanf("%d %d %d", &k, &a, &b);

    diff = b - a; //売買による増分

    biscuit = 1;
    money = 0;

    for (i = 0; i < k; i++) {
        if (diff > 2) { //売買による増分のほうが多い
            if (money > 0) {
                // 買う
                money--;
                biscuit += b;
                continue;
            } else if (biscuit >= a && k - i >= 2) {
                // 売る
                biscuit -= a;
                money++;
                continue;
            }
        }
        biscuit++;
    }

    printf("%lld\n", biscuit);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define rg register
#define ll long long
#define CL(a,b) memset(a,b,sizeof a)
int main()
{
    char s[11];
    int n,k;
    cin>>n>>s>>k;
    for(int i=0;i<n;i++)
        if(s[i]!=s[k-1])
        s[i]='*';
    cout<<s;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
    static void Main() {
        bool[,] have = new bool[4, 13];
        string mark = "SHCD";
        int n = int.Parse(Console.ReadLine());
        for(int i = 0; i < n; i++) {
            string[] card = Console.ReadLine().Split();
            for(int j = 0; j < 4; j++) {
                if(card[0][0] == mark[j]) have[j, int.Parse(card[1]) - 1] = true;
            }
        }

        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 13; j++) {
                if(!have[i, j]) Console.WriteLine("{0} {1}", mark[i], j + 1);
            }
        }
    }
}


Measured memory_bytes: 17996
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  ll N=S.size();
  ll ans=0;
  for(ll i=0;i<N/2;i++) {
    if(S[i]!=S[N-1-i]) {
ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
vector<bool> IsPrime;
void eratosthenes(int max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;
    for(int i = 2;i*i<=max;i++){
        if(IsPrime[i]){
            for(int j = 2;i*j<=max;j++){
                IsPrime[i*j] = false;
            }
        }
    }
}
int Tto1(bool b){
    return b?1:0;
}
bool isgood(int a){
    if(IsPrime[a] && IsPrime[(a+1)/2]){
        return true;
    } 
    return false;
}
int main(){
    int Q;
    cin >> Q;
    struct lr{
        int l;
        int r;
    };
    vector<lr> qlist(Q,lr{0,0});
    for(int i = 0;i<Q;i++){
        cin >> qlist[i].l >> qlist[i].r;
    }
    eratosthenes(100001);
    array<int,100001> ruiseki{0};
    for(int i = 1;i<100001;i++){
        ruiseki[i] = ruiseki[i-1] + Tto1(isgood(i));
    }
    for(int i = 0;i<Q;i++){
        cout << ruiseki[qlist[i].r] - ruiseki[qlist[i].l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define RFOR(i,k,n) for (int (i)=(n)-1; (i)>=(k); --(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(), v.end()
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
using namespace std;

enum Yokotate { NONE, YOKO, TATE };
long long mod = 1000000007;

int main() {
  int n;
  string s1, s2;
  cin >> n >> s1 >> s2;
  Yokotate pre = NONE, now;
  long long ans = (s1[0] == s2[0]) ? 3 : 6;
  for(int itr = 0; itr < n; ++itr) {
    if(s1[itr] == s2[itr]) { now = TATE; }
    else{
      now = YOKO;
      ++itr;
    }
    if(pre == YOKO && now ==YOKO) { ans = (ans * 3) % mod; }
    else if(pre == TATE) { ans = (ans * 2) % mod; }
    pre = now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
factorial=[1]
for i in range(1,2*n):
  factorial.append((factorial[i-1]*(i+1))%(10**9+7))
inv=[]
for i in range(n):
  inv.append(pow(factorial[i],10**9+5,10**9+7))
if k>=n-1:
  print((factorial[2*n-2]*inv[n-1]*inv[n-2])%(10**9+7))
else:
  ans=1
  for i in range (k):
    ans=(ans+factorial[n-1]*inv[i]*inv[n-i-2]*factorial[n-2]*inv[i]*inv[n-i-3])%(10**9+7)
  if k==1:
    ans-=1
  print(ans)


Measured memory_bytes: 69488
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9;
#define LINF = 1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << = << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

void input(vector<int> x, auto n){
   rep(i,n)cin >> x[i];
}

bool calc(int a, char op, int b){
   if(op =='+')cout << a+b << endl;
   else if (op == '-')cout << a-b << endl;
   else if(op == '*')cout << a*b << endl;
   else if(op == '/')cout << a/b << endl;
   else return 0;

   return 1;
}

int main(){

    bool f;
    do{
      int a,b;
      char op;
      cin >> a >> op >> b;
      f = calc(a, op, b);
    }while(f);

}


Measured memory_bytes: 3092
import math
N,K = [int(x) for x in input().split()]
inf = 10**9+7
for i in range(1,K+1):
  k = i-1
  kumi = math.factorial(K-i+k)//(math.factorial(K-i)*math.factorial(k))%inf
  a = math.factorial(N-K+1)
  b = math.factorial(i)
  if (N-K+1-i)<0:
    print(0)
    continue
  c = math.factorial(N-K+1-i)
  a = a//b
  a = a//c%inf
  ans = kumi*a
  print(int(ans%inf))
  
  

  

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

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

    int N;
    cin >> N;
    vector<ll> A(N), B(N);

    map<ll, ll> m;
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
        m[A[i]]++;
    }

    sort(all(A), greater<ll>());

    rep(i, N) {
        if (A[0] == B[i] && m[A[0]] == 1) {
            cout << A[1] << endl;
        } else {
            cout << A[0] << endl;
        }
    }
}

Measured memory_bytes: 12160
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 2019;

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

  string S;
  cin >> S;
  int size = S.size();
  vector<int> mods(MOD);
  int32_t tmp = 0;
  int32_t dig = 1;
  int64_t cnt = 0;
  for (int i = size - 1; i >= 0; i--) {
    tmp = dig * (S[i] - '0') + tmp;
    tmp %= MOD;
    dig *= 10;
    dig %= MOD;
    int c_mod = tmp % MOD;
    if (c_mod == 0) cnt++;
    cnt += (int64_t) mods[c_mod];
    mods[c_mod]++;
  }
  
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3700
def main():
    N, W = map(int, input().split())
    w = [None for _ in range(N)]
    v = [None for _ in range(N)]
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    dp = [[0 for _ in range(W+1)] for _ in range(N)]
    for i in range(0, N):
        for j in range(W+1):
            if j-w[i] >= 0:
                dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[-1][-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 171528
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

string s,t;
vector<char> _s;
vector<char> _t;
ll m,n;
vector<pair<int,int>> hsh(15600000,P(-1,-1));
ll idx=0;
const ll base=100007LL;
const ll mod1=1000000007LL,
		 mod2=1000000009LL;
vector<ll> fact1(300030,0);
vector<ll> fact2(300030,0);
ll rolling1=0,rolling2=0;

void fill_fact() {
	fact1[0]=1;
	fact2[0]=1;
	FOR(i,1,300030) {
		fact1[i]=(fact1[i-1]*base);
		fact1[i]%=mod1;
		fact2[i]=(fact2[i-1]*base);
		fact2[i]%=mod2;
	}
}

void fill_hash() {
	REP(i,n) {
		rolling1*=base;
		rolling2*=base;
		rolling1+=_t[i];
		rolling2+=_t[i];
		rolling1%=mod1;
		rolling2%=mod2;
	}
	REP(i,n) {
		rolling1-=fact1[n-1-i]*_t[i];
		rolling1=(rolling1%mod1+mod1)%mod1;
		rolling2-=fact2[n-1-i]*_t[i];
		rolling2=(rolling2%mod2+mod2)%mod2;
		for(ll j=1; j<=52; j++) {
			rolling1+=fact1[n-1-i]*j;
			rolling1%=mod1;
			rolling2+=fact2[n-1-i]*j;
			rolling2%=mod2;
			hsh[idx]=pair<int,int>(rolling1,rolling2);
			idx++;
			rolling1-=fact1[n-1-i]*j;
			rolling1=(rolling1%mod1+mod1)%mod1;
			rolling2-=fact2[n-1-i]*j;
			rolling2=(rolling2%mod2+mod2)%mod2;
		}
		rolling1+=fact1[n-1-i]*_t[i];
		rolling1=(rolling1%mod1+mod1)%mod1;
		rolling2+=fact2[n-1-i]*_t[i];
		rolling2=(rolling2%mod2+mod2)%mod2;
	}
	UNIQUE(hsh);
	auto ite=lower_bound(ALL(hsh),pair<int,int>(rolling1,rolling2));
	hsh.erase(ite);
}

ll solve() {
	fill_fact();
	fill_hash();
	ll r1=0,r2=0;
	ll ret=0;
	for(ll i=0; i<m-n+1; i++) {
		if(i==0) {
			REP(j,n) {
				r1*=base;
				r2*=base;
				r1+=_s[j];
				r2+=_s[j];
				r1%=mod1;
				r2%=mod2;
			}
		} else {
			r1*=base;
			r2*=base;
			r1+=_s[n-1+i];
			r2+=_s[n-1+i];
			r1-=fact1[n]*_s[i-1];
			r2-=fact2[n]*_s[i-1];
			r1=(r1%mod1+mod1)%mod1;
			r2=(r2%mod2+mod2)%mod2;
		}
		auto ite=lower_bound(ALL(hsh),pair<int,int>(r1,r2));
		if(*ite==pair<int,int>(r1,r2)) ret++;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>s>>t;
	m=s.size();
	n=t.size();
	_s.assign(m,0);
	_t.assign(n,0);
	REP(i,m) {
		if(s[i]>='A'&&s[i]<='Z') _s[i]=27+(s[i]-'A');
		else _s[i]=1+(s[i]-'a');
	}

	REP(i,n) {
		if(t[i]>='A'&&t[i]<='Z') _t[i]=27+(t[i]-'A');
		else _t[i]=1+(t[i]-'a');
	}
	cout<<solve()<<endl;
}


Measured memory_bytes: 130440
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		int d = c - (a - b);

		if (d > 0) {
			System.out.println(d);
		} else {
			System.out.println(0);
		}
	}
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

template<unsigned mod=998244353>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=998244353>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
using Mint=mint<>;

constexpr int N=1'000'000;
int cnt[N+10]={};
Mint sum[N+10];

int main(){
   int n; scanf("%d",&n);
   Mint res;
   rep(i,0,n){
      int tmp; scanf("%d",&tmp);
      cnt[tmp]++; res-=tmp;
   }
   rrep(k,N,0){
      Mint t;
      for(int j=k;j<=N;j+=k)t+=Mint(cnt[j])*j;
      t*=t;
      for(int j=k*2;j<=N;j+=k)sum[k]-=sum[j];
      sum[k]+=t; res+=sum[k]/k;
   }
   res/=2; printf("%d\n",res.val);
   return 0;
}

Measured memory_bytes: 8064
n,k = map(int,input().split())
l = []
for i in range(k):
  d = int(input())
  l += list(map(int,input().split()))
s = list(set(l))
count = 0
for i in range(1,n+1):
  if i not in l:
    count += 1
print(count)

Measured memory_bytes: 67396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repm(i,m,n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  
  vi p(n);
  rep(i,n) cin >> p.at(i);
  
  int ans = 0;
  rep(i,n-2) {
    int i1,i2,i3;
    i1 = p.at(i);
    i2 = p.at(i+1);
    i3 = p.at(i+2);
    
    int imax = max({i1,i2,i3});
    int imin = min({i1,i2,i3});
    
    if (i2 != imax && i2 != imin) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256