akhauriyash/Code-Regression huggingface dataset:
import java.math.*;
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
	for(int i = 0 ; i < n ; i++){
	    BigInteger a = s.nextBigInteger();
	    BigInteger b = s.nextBigInteger();
	    BigInteger c = a.add(b);

	    if(c.toString().length() > 80){
		System.out.println("overflow");
	    }
	    else{
		System.out.println(c);
	    }
	}
    }
}

Measured memory_bytes: 18456
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int n;
    cin>>n;
    int a[4];
    for(int i=0;i<4;i++){
        a[i]=n%10;
        n/=10;
    }
    if((a[0]==a[1] && a[1]==a[2])||(a[1]==a[2] && a[2]==a[3])){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
la = list(range(1,N+1))
cnt1 = 0
cnt2 = 0
while cnt1 <= N-1:
    if P[cnt1] == la[cnt1]:
        cnt2 += 1
    cnt1 += 1
if cnt2 >= N-2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli f(lli n)
{
    if(n<5)
        return 0;
    return (n/5)/2+f(n/5);
}
int main()
{
    lli n;
    cin>>n;
    if(n%2!=0)
        cout<<0<<endl;
    else
        cout<<f(n)<<endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const long long int N = ((long long int)2e5) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
typedef long long int lli;

lli n;
lli arr[N];
lli hist1[N];
lli hist2[N];
lli ans;

void init ()
{
	stack<lli> s;
	for (lli i = 1; i <= n; i++)
	{
		while (!s.empty() && arr[s.top()] > arr[i])
			s.pop();
		if (s.empty())
			hist1[i] = 0;
		else
			hist1[i] = s.top();
		s.push(i);
	}
	while (!s.empty())
		s.pop();
	for (lli i = n; i >= 1; i--)
	{
		while (!s.empty() && arr[s.top()] > arr[i])
			s.pop();
		if (s.empty())
			hist2[i] = n + 1;
		else
			hist2[i] = s.top();
		s.push(i);
	}

}

int main ()
{
	fast;
	//freop;
	cin >> n;
	for (lli i = 1; i <= n; i++)
	{
		cin >> arr[i];
	}

	init();
	for (lli i = 1; i <= n; i++)
	{
		ans += (i - hist1[i]) * (hist2[i] - i) * arr[i];
	}
	cout << ans << "\n";
}


Measured memory_bytes: 6656
#include <iostream>

using namespace std;

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

    int a;
    int maxDiff = 0, minPrice = 1e9, ans = 0;

    for (int i = 0; i < n; i++) {
        cin >> a;

        minPrice = min(minPrice, a);

        if (maxDiff == a-minPrice) {
            ans++;
        } else if (maxDiff < a-minPrice) {
            maxDiff = a-minPrice;
            ans = 1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
A,B = [],[]
for _ in range(n):
	a,b = map(int,input().split())
	A.append(a)
	B.append(b)
c = 0
for i in reversed(range(n)):
	A[i] += c
	if A[i] % B[i] != 0:
		c += B[i]-(A[i]%B[i])
		
print(c)

Measured memory_bytes: 15060
N,M = map(int,input().split())
l = [list(map(int,input().split())) for i
     in range(N)]
for i in range(N):
  del l[i][0]

for i in range(N-1):
    a = set(l[i])&set(l[i+1])
    l[i+1] = a
if N==1:
  print(len(l[0])) 
else:
  print(len(a))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int e;
void solve(){
    int ans = INF;
    for(int z=0;z<=100;z++){
        for(int y=0;y<=1000;y++){
            int x = e - z*z*z - y*y;
            if(x<0) continue;
            ans = min(ans,x+y+z);
        }
    }
    cout << ans << endl;
}

int main(){
    while(cin >> e){
        if(e==0) break;
        solve();
    }
}

Measured memory_bytes: 3100
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	string s;
	cin >> s;
	string go[3] = { "Sunny","Cloudy","Rainy" };
	for (int i = 0; i < 3; ++i) {
		if (s == go[i]) {
			cout << go[(i + 1) % 3] << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 888
X = int(input())
for a in range(0, 121):
    for b in range(0, 121):
        if X == a**5 - b**5:
            print(a, b)
            exit()
        elif X == a**5 + b**5:
            print(a, -b)
            exit()
        elif X == -a**5 - (10**4 - b)**5:
            print(-a, 10**4 - b)
            exit()

Measured memory_bytes: 9056
#include<cstdio>
using namespace std;

int main(){
  char S[10];
  bool ans = false;

  scanf("%s", S);

  char a = S[0];
  char b;

  if (a == S[1]){
    b = S[2];
    if (b == S[3]) ans = true;
  }
  else{
    b = S[1];
    if (a == S[2] && b == S[3]) ans = true;
    else if (a == S[3] && b == S[2]) ans = true;
  }

  if (a == b) ans = false;

  if (ans) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

vector<int> ans;
vector<int> visited(MAX_N, 0);
void dfs(const vector<vector<int>> &G, int pos, int pre = -1)
{
    queue<int> que;
    que.push(pos);
    while(not que.empty())
    {
        int v = que.front(); que.pop();
        visited[v] = 1;
        for(int i = 0; i < G[v].size(); i++)
        {
            int u = G[v][i];
            if(ans[u] != -1) continue;
            ans[u] = v;
            que.push(u);
        }
    }
}

void solve()
{
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    ans.resize(n, -1);
    for(int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << "Yes" << endl;
    ans[0] = -1;
    dfs(G, 0);
    for(int i = 1; i < ans.size(); i++) cout << ans[i] + 1 << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 10660
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>

using namespace std;

const int maxn = 402;
const int maxtot = 200002;

int n, m, tot, color[maxtot];
vector<string> data;
vector<vector<int> > g;
bool vis[maxtot];

void addEdge(int a, int b) {
	g[a].push_back(b);
	g[b].push_back(a);
}

void bfs(int st, vector<long long> &count) {
	queue<int> qu;
	qu.push(st);
	vis[st] = true;
	++count[color[st]];

	while (!qu.empty()) {
		int cur = qu.front();
		qu.pop();

		for (int i = 0; i < g[cur].size(); ++i) {
			int v = g[cur][i];
			if (!vis[v]) {
				qu.push(v);
				vis[v] = true;
				++count[color[v]];
			}
		}
	}
}

int main() {

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

	cin >> n >> m;
	tot = n * m;
	data = vector<string>(n);
	g = vector<vector<int> >(tot);
	for (int i = 0; i < n; ++i)
		cin >> data[i];

	int cur = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {

			if (i < n-1 && data[i][j] != data[i+1][j])
				addEdge(cur, cur+m);

			if (j < m-1 && data[i][j] != data[i][j+1])
				addEdge(cur, cur+1);

			color[cur] = data[i][j] == '.' ? 0 : 1;
			++cur;
		}
	
	long long ans = 0;
	for (int i = 0; i < tot; ++i) 
		if (!vis[i]) {
			vector<long long> count(2, 0);
			bfs(i, count);

			ans += count[0] * count[1];
		}

	cout << ans << endl;

	return 0;
}

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

int main() {
  string s,t;
  cin>>s>>t;
  int ans=0;
  if(s[0]==t[0]) ans++;
  if(s[1]==t[1]) ans++;
  if(s[2]==t[2]) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int n;
	List<List<Integer>> g = new ArrayList<>();
	int[] d, f;
	int t = 1;

	void dfs(int x) {
		d[x] = t++;
		for (int c : g.get(x)) {
			if (d[c] == 0) {
				dfs(c);
			}
		}
		f[x] = t++;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		n = sc.nextInt();
		g = new ArrayList<>();
		g.add(new ArrayList<>());
		for (int i = 1; i <= n; i++) {
			g.add(new ArrayList<>());

			sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				g.get(i).add(sc.nextInt());
			}
		}

		d = new int[n + 1];
		f = new int[n + 1];

		sc.close();

		for(int i=1;i<=n;i++) {
			if(d[i] == 0) {
				dfs(i);
			}
		}
		
		for (int i = 1; i <= n; i++) {
			out.println(i + " " + d[i] + " " + f[i]);
		}

	}

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



Measured memory_bytes: 28164
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> T;
typedef long long int ll;




int main(){
    int N,A,B;
    string str;
    cin >> N >> A >> B;
    cin >> str;
    int contes=0;
    int kaigai=0;
    char kok,kai,oth;
    kok = 'a';
    kai = 'b';
    oth = 'c';
    for(int n=0;n<N;n++){
        if(str[n]==kok){
            if(contes<A+B){
                cout << "Yes\n";
                contes++;
            }else{
                cout << "No\n";
            }
        }else if(str[n]==kai){
            if(contes<A+B && kaigai<B){
                cout << "Yes\n";
                contes++;
                kaigai++;
            }else{
                cout << "No\n";
            }
        }else{
            cout << "No\n";
        }
    }
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 896
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/17
Solved on 2019/3/
@author: shinjisu
"""


# ABC 087 C Candies
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    A = getIntMat(2, N)
    d.dmp((N),'N')
    d.dmp((A),'A')
    dp = zeros2(2, N)
    d.dmp((dp),'dp')
    for i in range(2):
        for j in range(N):
            dp[i][j] = max(dp[max(0, i-1)][max(0, j)],
                           dp[max(0, i)][max(0, j-1)])\
                       + A[i][j]
    d.dmp((dp),'dp')
    return dp[1][N-1]


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)


Measured memory_bytes: 3192
#include <iostream>
#include <string>

using namespace std;
int main()
{
    int A, B;

    cin>>A>>B;

    if (A>B)
    {
        cout<<2*A-1<<endl;
    }else if(B>A){
       cout<<2*B-1<<endl;
    }else{
        cout<<2*A<<endl;
    }
}

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

int main() {

  string S,B;
  
  cin >> S;
  
  int a = S.size();
  
  if(S.at(a-1)=='s'){
   B = "es";
  }
  else{
   B = "s";
  }
  
  cout << S;
  cout << B << endl;
  
}


Measured memory_bytes: 3596
K, N = map(int, input().split())
A = list(map(int, input().split()))
maxnum = 0
for i in range(0,N-1):
    maxnum = max(maxnum, A[i+1] - A[i])
maxnum = max(maxnum, A[0]+K-A[N-1])

print(K-maxnum)

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

struct Data {
  ll v, is_b, idx;
};
bool operator<(const Data& d1, const Data& d2) {
  return d1.v < d2.v;
}

ll solve() {
  ll n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vector<Data> v;
  rep(i, n) {
    v.pb({a[i], false, i});
    v.pb({b[i], true, i});
  }
  sort(all(v));
  ll sum = 0;
  rep(i, n) {
    sum += v[i].v;
  }
  set<bool> s1;
  set<ll> s2;
  rep(i, n) {
    s1.insert(v[i].is_b);
    s2.insert(v[i].idx);
  }
  if (s1.size() == 1) return sum;
  if (s2.size() != n) return sum;
  ll res = linf;
  rep(i, n, 2*n) {
    if (v[i].idx == v[n-1].idx) {
      chmin(res, sum - v[n-2].v + v[i].v);
    }
    else {
      chmin(res, sum - v[n-1].v + v[i].v);
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << solve() << endl;
}


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

typedef long long ll;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;
    ll arr[n+1]={};    
    for(ll i=1; i<=n; i++){
        for(ll j=i; j<=n; j+=i){
            arr[j]++;
        }
    }
    ll ans=0;
    for(ll i=1; i<=n; i++){
        ans+=(arr[i])*i;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 81780
#include <iostream>
#include <queue>
#include <vector>
#define MAX_V 100000
#define INF 2000000000
using namespace std;

typedef struct {
  int to, cost;
} edge;

typedef pair<int, int> P;

vector<edge> G[MAX_V];
int d[MAX_V];

void init() {
  for (int i = 0; i < MAX_V; i++) {
    d[i] = INF;
  }
}

void dijkstra(int start) {
  priority_queue<P, vector<P>, greater<P> > que;
  init();
  d[start] = 0;
  que.push(P(0, start));

  while (que.empty() == false) {
    P temp = que.top();
    que.pop();

    int v = temp.second;
    if (d[v] < temp.first) continue;

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
	d[e.to] = d[v] + e.cost;
	que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int v, e, r;
  cin >> v >> e >> r;

  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge temp;
    temp.to = t;
    temp.cost = d;
    G[s].push_back(temp);
  }

  dijkstra(r);

  for (int i = 0; i < v; i++) {
    if (d[i] < INF) cout << d[i] << endl;
    else cout << "INF" << endl;
  }

  return 0;
}

Measured memory_bytes: 13044
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

long long f[1000001];
long long a,b,c,d;
map<long long,long long>ans;
long long dfs(long long n){
	if(n<=1000000)return f[n];
	if(ans[n])return ans[n];
	long long o=n<=2e9?n*d:~0ull>>1;
	o=min(o,min(dfs(n/2)+a+(n%2)*d,dfs(n/2+1)+a+(2-n%2)*d));
	o=min(o,min(dfs(n/3)+b+(n%3)*d,dfs(n/3+1)+b+(3-n%3)*d));
	o=min(o,min(dfs(n/5)+c+(n%5)*d,dfs(n/5+1)+c+(5-n%5)*d));
	return ans[n]=o;
}
int main(){
	int t;
	scanf("%d",&t);
	for(int tt=1;tt<=t;tt++){
		long long n;
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		ans.clear();
		for(int i=1;i<=1000000;i++){
			f[i]=i*d;
			f[i]=min(f[i],min(f[i/2]+a+(i%2)*d,f[i/2+1]+a+(2-i%2)*d));
			f[i]=min(f[i],min(f[i/3]+b+(i%3)*d,f[i/3+1]+b+(3-i%3)*d));
			f[i]=min(f[i],min(f[i/5]+c+(i%5)*d,f[i/5+1]+c+(5-i%5)*d));
		}
		printf("%lld\n",dfs(n));
	}

}


Measured memory_bytes: 11768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N, K;
  cin >> N >> K;
  priority_queue<pair<ll, int> > que;
  for(int i=0; i<N; i++){
    int t;
    ll d;
    cin >> t >> d;
    t--;
    que.push(make_pair(d, t));
  }
  
  map<int, int> mp;
  ll types = 0;
  vector<pair<ll, int> > order;
  ll ans = 0;
  for(int i=0; i<K; i++){
    auto q = que.top(); que.pop();
    ll d = q.first; int t = q.second;
    ans += d;
    if(mp[t]==0) types++;
    mp[t]++;
    order.push_back(make_pair(d, t));
  }
//  cout << types << endl;
  ans += types*types;
  sort(order.begin(), order.end());
//  cout << ans << endl;

  ll tmpans = ans;
  for(int i=0; i<K; i++){
    ll def_d = order[i].first;
    int def_t = order[i].second;
    if(mp[def_t] == 1) continue;
    
    // order[i]は2個以上ある
    while(que.size()){
      auto q = que.top(); que.pop();
      ll d = q.first; int t = q.second;
      if(mp[t] >=1) continue;

      // pair<q, t>は初めての種類t
      tmpans -= types*types;
      tmpans -= def_d;
      tmpans += d;
      tmpans += (types+1)*(types+1);
      
      types++;
      order[i] = q;
      mp[def_t]--;
      mp[t]++;
      break;
    }
      ans = max(ans, tmpans);    
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6512
h, w = map(int, input().split())
fields = [input() for _ in range(h)]
dp = [[0] * w for _ in range(h)]
for i in range(h):
    if fields[i][0] == '#':
        break
    dp[i][0] = 1
for j in range(w):
    if fields[0][j] == '#':
        break
    dp[0][j] = 1
for i in range(1, h):
    for j in range(1, w):
        if fields[i][j] == '#':
            continue
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007
print(dp[-1][-1])


Measured memory_bytes: 53232
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int N,K;
	cin >>N>>K;
	if (K == 1) {
		N = K;
	}
	cout << N-K<< endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// I DON'T KNOW WHO YOU ARE BUT I WILL FIND YOU AND SEE YOUR CODE _/\_

# define MOD         1000000007
# define gc          getchar
# define LL          long long
# define pb          push_back
# define mp          make_pair
# define vi          vector<int>
# define MAXN        1000005
# define INF         1e9
# define all(v)      v.begin(),v.end()

template<class T> void in(T &x) { register T c=gc();x=0;T neg=0;for(;((c<48||c>57)&&c!='-');c=gc());if(c=='-'){neg=1;c=gc();}for(;c>47&&c<58;c=gc()){x=(x<<1)+(x<<3)+c-48;}if(neg)x=-x;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
LL power(LL a,LL b,LL m){ if(b==0) return 1; if(b==1) return a%m; LL t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
LL lcm(LL a, LL b) { LL ret = a*b; ret /= __gcd(a,b); return ret;}
LL nC2(LL n) {LL ret = n*(n-1)/2; return ret;}

int main()
{
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	for(int i=0;i<abs(ty-sy);i++)
		cout<<"U";
	for(int i=0;i<abs(tx-sx);i++)
		cout<<"R";
	for(int i=0;i<abs(ty-sy);i++)
		cout<<"D";
	for(int i=0;i<abs(tx-sx);i++)
		cout<<"L";
	cout<<"L";
	for(int i=0;i<abs(ty-sy)+1;i++)
		cout<<"U";
	for(int i=0;i<abs(tx-sx)+1;i++)
		cout<<"R";
	cout<<"DR";
	for(int i=0;i<abs(ty-sy)+1;i++)
		cout<<"D";
	for(int i=0;i<abs(tx-sx)+1;i++)
		cout<<"L";
	cout<<"U";

    return 0;
}


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

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}
int getans(const int num, const int rest) {
	if (rest) {
		int ans = 0;
		for (int i = 0; i <= 9; ++i) {
			if (num >= i) {
				ans += getans(num - i, rest - 1);
			}
		}
		return ans;
	}
	else {
		return num == 0;
	}
}
int main() {
	int N;
	stack<int>sta;
	while (cin >> N) {
		
		if (N) {
			sta.emplace(N);
		}
		else {
			cout << sta.top() << endl;
			sta.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 3056
// Shift-JIS（シフトジス）

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, M, L, leftW = 1, R, rightW = N, result = 1;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> L >> R;
        if (leftW > R || rightW < L) {
            result = 0;
            break;
        }
        if (leftW < L) {
            leftW = L;
        }
        if (rightW > R) {
            rightW = R;
        }
    }
    if (result == 0) {
        cout << result << endl;
    } else {
        result = rightW - leftW + 1;
        cout << result << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS

int n, m;

int main()
{
    scanf("%d%d", &n, &m);
    if (n < m) std::swap(n, m);

    long long ans;
    if (n == m) {
        ans = 1;
        for (int i = 1; i <= n; ++i) (ans *= i)__;
        for (int i = 1; i <= m; ++i) (ans *= i)__;
        (ans *= 2)__;
        printf("%lld\n", ans);
    } else if (n == m + 1) {
        ans = 1;
        for (int i = 1; i <= n; ++i) (ans *= i)__;
        for (int i = 1; i <= m; ++i) (ans *= i)__;
        printf("%lld\n", ans);
    } else {
        puts("0");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;
#define mod 1e9+7
const ll inf= 1e17;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,W;
    cin>>N>>W;
    vector<pair<ll,ll> > p;
    ll v[40],w[40];
    rep(i,N)cin>>v[i]>>w[i];
    int n2=N/2;
    for(int i=0;i<1<<n2;i++){
        ll sw=0,sv=0;
        for(int j=0;j<n2;j++){
            if(i>>j&1){
                sw+=w[j];
                sv+=v[j];
            }
        }
        p.push_back(make_pair(sw,sv));
    }
    sort(all(p));
    int m=1;
    for(int i=1;i<1<<n2;i++)if(p[m-1].second<p[i].second) p[m++]=p[i];
    ll res=0;
     for(int i=0;i<1<<(N-n2);i++){
        ll sw=0,sv=0;
        for(int j=0;j<(N-n2);j++){
            if(i>>j&1){
                sw+=w[n2+j];
                sv+=v[n2+j];
            }
        }
        if(sw<=W){
            pair<ll,ll> pp=make_pair(W-sw,inf);
            ll tv=(lower_bound(p.begin(),p.begin()+m,pp)-1)->second;
            res=max(res,sv+tv);
        }
    }
    cout<<res<<endl;
    return 0;
}



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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;

    vector<pii> edges;
    REP(i,m){
        int a,b;
        cin>>a>>b;
        a--; b--;
        edges.emplace_back(pii(a,b));
    }

    int ans = 0;
    REP(i,m) {//除外辺
        UnionFind uf(n);
        //一つ辺を除いてくっつけてみる
        REP(j,m){
            if(i==j) continue;
            uf.unite(edges[j].first, edges[j].second);
        }

        if(uf.size(0) != n) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int> > ac(m);
	for (int i = 0; i < m; ++i) {
		int b; cin >> ac[i].first >> b;
		while (b--) {
			int c; cin >> c; c--;
			ac[i].second |= (1 << c);
		}
	}
	vector<long long> dp(1 << n, 1e18);
	dp[0] = 0;
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < (1 << n); ++j) {
			dp[j | ac[i].second] = min(dp[j | ac[i].second], dp[j] + ac[i].first);
		}
	}
	cout << (dp[(1 << n) - 1] == 1e18 ? -1 : dp[(1 << n) - 1]) << endl;

	return 0;
}

Measured memory_bytes: 256
#ABC 126
S =input()
if 1 <= int(S[:2]) <=12 and 1 <= int(S[2:]) <=12:
    print("AMBIGUOUS")
elif  1 <= int(S[:2]) <=12:
    print('MMYY')
elif  1 <= int(S[2:]) <=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
import java.io.*;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		
		
		while(true){
		String[] line = (br.readLine()).split(" ");

		int x =  Integer.parseInt(line[0]);
		int y =  Integer.parseInt(line[1]);


		if( x == 0 && y == 0){
		break;
		}

		else if(x<y){
		sb.append(x).append(" ").append(y).append("\n");
		}
		else{
		sb.append(y).append(" ").append(x).append("\n");
		}
	}
	System.out.print(sb);
}
}

Measured memory_bytes: 26448
#include <bits/stdc++.h>
using namespace std;
#define el '\n'

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector< pair<int,int> > kompres;
  char cur = s[0];
  int cnt = 1;
  for (int i = 1; i < (int)s.length(); i++) {
    if (s[i] == cur) cnt++;
    else {
      kompres.push_back({cur-'0', cnt});
      cnt = 1;
      cur = s[i];
    }
  }
  kompres.push_back({cur-'0', cnt});
  int mx = -69, tmp = 0, cnt0 = 0, le = 0;
  for (int i = 0; i < (int)kompres.size(); i++) {
    if (kompres[i].first == 0) cnt0++;
    tmp += kompres[i].second;
    while (cnt0 > k) {
      if (kompres[le].first == 0) cnt0--;
      tmp -= kompres[le].second;
      le++;
    }
    mx = max(mx, tmp);
  }
  cout << mx << el;
  return 0;
}

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

int main(){
    // 最初のAから最後のZ
    string s;
    cin>>s;

    int firstA=-1;
    int lastZ=-1;

    for(int i=0; i<s.size(); i++){
        if(s[i]=='Z'){
            lastZ=i;
        }

        if(firstA!=-1){
            continue;
        }

        if(s[i]=='A'){
            firstA=i;
        }
    }

    cout<<lastZ-firstA+1<<endl;
}

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


int main() {

  int64_t a,b,c;
  cin>>a>>b>>c;

  //偶数回はA-B
  //奇数回はB-A


  int64_t cnt=0;

  if(a==b&&b==c&&a%2!=0){
    cnt=0;
  }
  else if(a==b&&b==c){
    cnt=-1;
  }
  else{
    while(1){
      if(a%2!=0||b%2!=0||c%2!=0)
        break;

      int64_t wk_a=a,wk_b=b,wk_c=c;

      a=wk_b/2+wk_c/2;
      b=wk_a/2+wk_c/2;
      c=wk_b/2+wk_a/2;

      cnt++;
    }
  }

  cout<<cnt<<endl;

  return 0;
}

/*
//最初
A;
B;
C;
//1回目
A=B/2+C/2
B=A/2+C/2
C=A/2+B/2
//2回目
A=A/4+C/4+A/4+B/4=A/2+C/4+B/4;
B=B/4+C/4+A/4+B/4=B/2+C/4+A/4;
C=A/4+C/4+B/4+C/4=C/2+A/4+B/4;
//3回目
A=(B/4+C/8+A/8)+(C/4+A/8+B/8)=A/4+3B/8+3C/8;
B=(C/4+A/8+B/8)+(A/4+C/8+B/8)=B/4+3A/8+3C/8;
C=(B/4+C/8+A/8)+(A/4+C/8+B/8)=C/4+3B/8+3A/8;
//4回目
A=(B/8+3A/16+3C/16)+(C/8+3B/16+3A/16) =3A/8+5B/16+5C/16;
B=(A/8+3B/16+3C/16)+(C/8+3B/16+3A/16) =3B/8+5A/16+5C/16;
C=(A/8+3B/16+3C/16)+(B/8+3A/16+3C/16) =3C/8+5B/16+5A/16;
*/

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int P = sc.nextInt();
    int Q = sc.nextInt();
    int R = sc.nextInt(); 

      int a = P+Q;
      int b = P+R;
      int c = Q+R;
      
      if(a<=b && a<=c){
    System.out.println(a);
      }else if(b<=c && b<=a){
	System.out.println(b);
      }else{
    System.out.println(c);
      }
      }
}

Measured memory_bytes: 20820
N = int(input())
A = list(map(int, input().split()))
total = 0
for i in range(N-1):
    if(A[i+1]<A[i]):
        add= abs(A[i+1]-A[i])
        A[i+1] = A[i+1]+add
        total+=add
print(total)

Measured memory_bytes: 32196
H, W = map(int, input().split())
ans = []
for h in range(H+2):
    ans.append([0] * (W + 2))
qu = []
for h in range(H):
    qu.append(input())

for h in range(H):
    for w in range(W):
        if qu[h][w] == "#":
            for i in range(3):
                for j in range(3):
                    if ans[h+i][w+j] != "#":
                        ans[h+i][w+j] += 1
            ans[h+1][w+1] = "#"

for h in range(H):
    result = map(str, ans[h+1][1:W+1])
    print(''.join(result))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i++){
        cout << "x";
    }
    cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<double> a(n); rep(i, n)cin >> a[i];
	sort(ALL(a));
	double now = 0;
	rep(i, n-1) {
		if (i == 0) {
			now = (a[i] + a[i + 1]) / 2.0;
		}
		else {
			now = (now + a[i + 1]) / 2.0;
		}
	}
	cout << fixed << setprecision(15) << now << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {
	int n;
	cin >> n;

	vector<int> vec(n);

	for (int i = 0; i < n-1; i++)
	{
		int temp;
		cin >> temp;
		vec[temp - 1]++;
	}



	for (int i = 0; i < n; i++)
	{
		cout << vec[i] << endl;
	}





}

Measured memory_bytes: 3960
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

class UnionFind {
private:
  vector<int> data, rnk;

public:
  UnionFind(int size)
    : data(size), rnk(size) {
    iota(all(data), 0);
  }

  int root(int x) {
    return data[x] == x ? x : data[x] = root(data[x]);
  }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rnk[a] < rnk[b]) swap(a, b);
    data[b] = a;
    if (rnk[a] == rnk[b]) rnk[a]++;
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  UnionFind uf(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      cout << (uf.root(x) == uf.root(y)) << endl;
    } else {
      uf.unite(x, y);
    }
  }
}

Measured memory_bytes: 3228
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		String S = next();
		String[] weather = {"Sunny", "Cloudy", "Rainy"};

		if(S.equals(weather[0])) {
			out.println(weather[1]);
		}else if(S.equals(weather[1])) {
			out.println(weather[2]);
		}else if(S.equals(weather[2])) {
			out.println(weather[0]);
		}

	}


	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 20692
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{	long long n;
	vector<int> num(n);

	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
	}
	int cost=1000000;	
	for(int i=-200;i<=200;i++)
	{
		int be=0;
		for(int j=0;j<n;j++)
		{
			be+=(i-num[j])*(i-num[j]);
		}
		cost=min(cost,be);
	 }
	 cout<<cost;
	 return 0; 
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
//////////////////////////////////////////////////////////////////////

const int LO = 0 , HI = (int)1e8;
struct segtree{
  struct node{
    ll rs,mx;
    node *lt,*rt;
    node(){rs=mx=0;lt=rt=NULL;}
  };
  typedef node* pn;
  pn root=NULL;
  void pull(pn&it){
    it->rs = (it->lt?it->lt->rs:0)+(it->rt?it->rt->rs:0);
    it->mx = max((it->lt?it->lt->mx:0),(it->rt?it->rt->mx:0));
  }
  
  void upd(int &pos,ll &val,pn&it,int lx=LO,int rx=HI){
    if(it==NULL)it=new node();
    if(lx==rx){//==pos
      it->rs+=val;
      it->mx = it->rs;
      return;
    }
    int m = lx+rx>>1;
    if(pos<=m)upd(pos,val,it->lt,lx,m);
    if(pos>m)upd(pos,val,it->rt,m+1,rx);
    pull(it);
  }void upd(int pos,ll val){upd(pos,val,root);}
  
  ll qry(int &u,int &v,pn&it,int lx=LO,int rx=HI){
    if(it==NULL or u>rx or v<lx)return 0;
    if(u<=lx and rx<=v)return it->mx;
    int m = lx+rx>>1;
    return max(qry(u,v,it->lt,lx,m),qry(u,v,it->rt,m+1,rx));
  }ll qry(int u,int v){return qry(u,v,root);}
  
} T;

int sx,sy,dx,dy;
int n;
vector<pair<int,int> > pts;
const double ppi = 3.14159265358979323846;

int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  
  cin>>sx>>sy>>dx>>dy;
  cin>>n;
  for(int i=1;i<=n;i++){
    int u,v;
    cin>>u>>v;
    if(abs(u-sx)+abs(u-dx)==abs(sx-dx) and
       abs(v-sy)+abs(v-dy)==abs(sy-dy) ){
      pts.emplace_back(u,v);
    }
  }
  
  if(sx > dx){
    swap(sx,dx);
    for(auto&point:pts){
      point.ff = dx - ( point.ff - sx );
    }
  }
  
  if(sy > dy){
    swap(sy,dy);
    for(auto&point:pts){
      point.ss = dy - ( point.ss - sy );
    }
  }
  
  for(auto&point:pts){
    point.ff -= sx;
    point.ss -= sy;
  }
  dx -= sx;dy -= sy;
  
  if(pts.empty()){
    cout << fixed << setprecision(20) << 100.0*(dx+dy) << endl;
    return 0;
  }
  
  if(dx==0 or dy==0){
    double ans = 100.0*(dx+dy);
    double delta = -20.0*pts.size();
    delta += 10*ppi*pts.size();
    cout << fixed << setprecision(20) << ans + delta << endl;
    return 0;
  }
  
  sort(pts.begin(),pts.end());
  
  int fts = 0;
  for(auto&point:pts){
    int v = point.ss;
    int mx = T.qry(0,v);
    T.upd(v,mx+1);
    fts = max(fts,1+mx);
  }
  //cerr << fts << endl;
  
  long double dist = 100.0*(dx+dy);
  long double delta;
  if(fts == min(dx+1,dy+1)){
    delta = -20.0*fts;
    delta += 5.0*ppi*(fts-1);
    delta += 10.0*ppi;
  }else{
    delta = -20.0*fts;
    delta += 5.0*ppi*fts;
  }

  //cerr << delta << endl;
  
  cout << fixed << setprecision(20) << dist + delta << endl;
  
  return 0;
};


Measured memory_bytes: 97136
import java.util.Scanner;

public class Main {

    static long[] fac = new long[100003];
    static long[] finv = new long[100003];
    static long[] inv = new long[100003];
    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        //前処理
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2 ; i < 100003 ; i++ ) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }

        for (int i = 1 ; i <= k ; i++) {
            System.out.println(comb(n - k + 1 , i) * comb(k - 1, i - 1) % MOD);
        }

    }

    static long comb (int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

}

Measured memory_bytes: 24660
program main;
var k, a, b, i, x : integer;
    ok : boolean;
begin
    ok := false;
	readln(k);
    readln(a, b);
    
    for i := a to b do begin
        x := i mod k;
        if x = 0
            then ok := true;
    end;
    
    if ok
        then writeln('OK')
        else writeln('NG');
end.

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

void solve() 
{
    int n;cin>>n;
    ll a[n];REP(i,n)cin>>a[i];
    ll sum=0;REP(i,n)(sum+=a[i])%=mod;
    (sum*=sum)%=mod;
    REP(i,n) sum-=(a[i]*a[i])%mod,sum+=(sum<0?mod:0);
    cout<<(sum*(mod+1)/2)%mod<<endl;
}

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

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

using namespace std;
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("inputf.in", "r", stdin);
    // freopen("outputf.in", "w", stdout);
    // #endif
    int n,i;
    cin>>n;
    long long sum=0;
    for(i=1;i<n+1;i++)
    {
        if(i%3==0 || i%5==0)
        {
            continue;
        }
        else
        {
            sum=sum+(long long)i;
        }
    }
    cout<<sum;

}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int mod;
//a^n (mod mod)
//O(log a)
LL Pow(LL a, LL n, int M = mod) {
	LL res = 1;
	a %= M;
	while (n) {
		if (n & 1)
			res = (res*a) % M;
		a = (a*a) % M;
		n >>= 1;
	}
	return res;
}
LL cnt[112345];
// mを法とするaの逆元
// O(log a)
inline LL invMod(LL a, LL m = mod) {
	LL b = m, u = 1, v = 0;
	while (b) {
		LL t = a / b;
		swap(a -= t * b, b);
		swap(u -= t * v, v);
	}
	return (u % m + m) % m;
}


// 階乗
// O(n)
constexpr int SZ = 112345;
LL fact[SZ];
LL rfact[SZ];
LL f[3123][3123];
void init() {
	fact[0] = 1;
	for (int i = 1; i < SZ; i++)
		fact[i] = fact[i - 1] * i%mod;
	rfact[SZ - 1] = invMod(fact[SZ - 1]);
	for (int i = SZ - 1; i > 0; i--) {
		rfact[i - 1] = rfact[i] * i%mod;
	}
	for (int i : range(3123))
		for (int j : range(3123))
			f[i][j] = 0;
	f[0][0] = 1;
	for (int i : range(1, 3123)) {
		for (int j : range(0, i + 1)) {
			if(j>0)f[i][j] += f[i - 1][j - 1];
			f[i][j] += (j+1) * f[i - 1][j];
			f[i][j] %= mod;
		}
	}
}

// 組み合わせnCk (mod mod)
// O(1)
LL Comb(LL n, LL k) {
	LL u = fact[n];
	LL d = (rfact[k] * rfact[n - k]) % mod;
	return u * d%mod;
}

int main() {
	int N;
	while (cin >> N >> mod) {
		init();
		for (int i : range(N + 1)) {
			
			cnt[i] = 0;
			LL p = Pow(2, Pow(2, N - i, mod - 1));
			LL beet = Pow(2, N - i);
			LL t = 1;
			for (int j : range(i+1)) {
				cnt[i] += t*f[i][j] % mod;
				t = t * beet%mod;
			}
			cnt[i] %= mod;
			cnt[i] = cnt[i] * p % mod;
			cnt[i] = cnt[i] * Comb(N, i) % mod;
		}
		LL ret = 0;
		for (int i : range(N + 1)) {
			if (i % 2 == 0)ret += cnt[i];
			else ret += mod - cnt[i];
		}
		cout << ret % mod << endl;
	}
	return 0;
}


Measured memory_bytes: 78208
x, y ,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

list.sort(p,reverse=True)
list.sort(q,reverse=True)
list.sort(r,reverse=True)

mazemaze =p[:x]+q[:y]+r
list.sort(mazemaze, reverse=True)
print(sum(mazemaze[:x+y]))

Measured memory_bytes: 112168