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

const int sz = 5001;
ll visited[sz];

void solve() {

    // INPUT
    ll n, k; cin >> n >> k;
    vector<ll> p(n), c(n);
    for (ll& pi : p) { cin >> pi; --pi; }
    for (ll& ci : c) cin >> ci;

    // LOGIC
    ll ans = LLONG_MIN;
    for (int i = 0; i < n; ++i) {
        fill(visited, visited + sz, 0);
        int idx = p[i];
        ll sum = 0; ll cnt = 0;
        while (visited[idx] == 0 && cnt++ < k) {
            visited[idx] = 1;
            sum += c[idx];
            idx = p[idx];
            ans = max(ans, sum);
        }
        if (sum <= 0 || cnt >= k) continue;

        int cnt1 = 0; ll res = 0;
        fill(visited, visited + sz, 0);
        while (visited[idx] == 0 && cnt1++ < k) {
            visited[idx] = 1;
            res += c[idx];
            int num = (k - cnt1) / cnt;
            ll score = res + max(0ll, sum) * num;
            idx = p[idx];
            ans = max(ans, score);
        }
    }
    cout << ans << "\n";
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3776
n, k, c = map(int, input().split())
s = input()

INF = 1 << 20
ldp = [-INF] * n
rdp = [-INF] * n

past_max = 0

for i in range(n):
    if i-c-1>= 0: past_max = max(past_max, ldp[i-c-1])
    if s[i] == 'x': continue
    ldp[i] = past_max + 1

future_max = 0
for i in range(n-1, -1, -1):
    if i+c+1 < n: future_max = max(future_max, rdp[i+c+1])
    if s[i] == 'x': continue
    rdp[i] = future_max + 1

dist = [[] for i in range(k + 10)]

for i in range(n):
    if s[i] == 'x':continue
    if ldp[i] + rdp[i] - 1 != k:continue
    dist[ldp[i]].append(i)

for i in range(k+10):
    if len(dist[i]) == 1:
        print(dist[i][0] + 1)

    
        

Measured memory_bytes: 50548
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[0] != s[s.size()-1]){
    if(s.size()%2){
      cout << "First" << endl;
    }
    else{
      cout << "Second" << endl;
    }
  }
  else{
    if(s.size()%2){
      cout << "Second" << endl;
    }
    else{
      cout << "First" << endl;
    }
  }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,t; cin>>n>>t;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	int mn=a.front(),mx=0,mxc=0;
	for(auto&&i:a){
		int dif=i-mn;
		if(dif<0){
			mn=i;
		}
		else if(dif>mx){
			mx=dif;
			mxc=1;
		}
		else if(dif==mx){
			++mxc;
		}
	}
	cout<<mxc<<"\n"s;
}


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

int sum(int num){
    int sum = 0;
    while (num) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int s = sum(i);
        if (s >= A && s <= B) {
            ans += i;
        }
    }
    cout << ans << endl;


}


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

#define NAME "A"
#define show(x) cout << (#x) << " is " << (x) << endl
#define ll long long
#define ms(arr,val) memset(arr,val,sizeof(arr))
#define len length()

const int maxn = 2e5;

int main(){
    //ifstream cin(NAME".inp");
    //ofstream cout(NAME".out");
    vector<string> p (10);
   
    p[3] = "bon";
    p[2]= p[4] =  p[5] = p[7] = p[9] = "hon";
    p[0] =  p[1] = p[6] = p[8] = "pon";
    string n;
    cin>>n;
    cout<<p[ n[n.len-1]-'0' ];

}





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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int train, bus;
    
    if (a >= b) train = b;
    else train = a;
    
    if (c >= d) bus = d;
    else bus = c;
    
    cout << train + bus << endl;
    
}

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

int main(){
    int n, m, sum;
    cin >> n >> m;
    int a[n][m], b[m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        sum = 0;
        for(int j = 0; j < m; j++){
            sum += a[i][j] * b[j];
        }
        cout << sum << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3176
def main():
  import numpy as np
  n=int(input())
  p=np.array([float(i) for i in input().split()])
  
  dp=np.zeros([n+1,n+1],dtype=np.float64)
  dp[0][0]=1
  for i in range(n):
    tmp=np.roll(dp[i],1)
    tmp[0]=0
    dp[i+1]+=dp[i]*(1-p[i])+tmp*p[i]
    

  print(sum(dp[n][(n+1)//2:]))
      
if __name__=='__main__':
  main()
        

Measured memory_bytes: 82808
l1 = set(tuple(map(int,input().split())))
l2 = set(tuple(map(int,input().split())))
l3 = set(tuple(map(int,input().split())))

L = (l1,l2,l3)

town = [1,2,3,4]

ret = 0

for t1 in town:
    for t2 in town:
        if t1==t2: continue
        if not {t1,t2} in L: continue
        for t3 in town:
            if t3==t2 or t3==t1: continue
            if not {t2,t3} in L: continue
            for t4 in town:
                if t4==t3 or t4==t2 or t4==t1: continue
                if not {t3,t4} in L: continue
                ret += 1

ans = 'YES' if ret>0 else 'NO'
print(ans)



Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int X,Y;
  scanf("%d %d", &X, &Y);
  int s = X + Y;
  if(s==2){
    printf("1000000\n");
  } else if(s == 3){
    printf("500000\n");
  }else if(s == 4){
    
    printf("400000\n");
    
  } else if(s == 5){
    printf("300000\n");
  } else if(s == 6){
    printf("200000\n");
  } else if(X == 1 || Y == 1){
    printf("300000\n");
  }else if(X == 2 || Y == 2){
    printf("200000\n");
  }else if(X == 3 || Y == 3){
    printf("100000\n");
  } else {
    printf("0\n");
  }

  return 0;
}

Measured memory_bytes: 128
//#include <bits/stcd++.h>
#include <iostream>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep2(i,a,b) for(ll i=a; i<=b; i++)
#define drep2(i,a,b) for(ll i=a; i>=b; i--)


int main ()
{
  int a,b;
  cin >> a >> b;
  // int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
  int ans = a-1;
  if ( b >= a ) {
    ans += 1;
  }
  cout << ans << endl;
}

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

const int mod = 1e9 + 7;

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

  vector<int> a(n),cnt(n + 1);
  rep(i,n) cin >> a[i];

  cnt[0] = 3;
  int ans = 1;

  for (int i = 0; i < n; i++) {
    ans *= cnt[a[i]];
    ans %= mod;

    cnt[a[i]]--;
    cnt[a[i] + 1]++;
  }

  cout << ans << '\n';

}


Measured memory_bytes: 4768
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

ll gcd(ll x, ll y) {
	if (x > y) swap(x, y);
	if (y%x != 0) return gcd(y%x, x);
	else return x;
}

int main() {
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll g = a[0];
	sort(a.begin(), a.end());
	rep(i, n) g = gcd(g, a[i]);
	if (k%g == 0 && k <= a[n - 1]) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, w;
    cin >> n >> w;
    vector<long long> dp(w + 1);
    ll wi, vi;
    for (int i = 1; i <= n; i++)
    {
        cin >> wi >> vi;
        for (int j = w; j >= wi; j--)
        {
            dp[j] = max(dp[j], dp[j - wi] + vi);
        }
    }
    cout << dp[w];
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
arr = []
for i in range(N):
  arr.append(input())
found = {}

# print(found, arr)

for candidate in arr:
  try:
    found[candidate] += 1
  except KeyError:
    found[candidate] = 1

s = sorted(found.items(), key=lambda n: n[1])
max = s[len(s) - 1][1]
s = list(filter(lambda t: t[1] == max, s))
s = sorted(s, key=lambda c: c[0])

print("\n".join(list(map(lambda t: t[0], s))))


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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define rreps(i, n) for (int (i) = (n); (i) > 0; (i)--)
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} init;

int N;
vector<pair<pint, bool>> points;
signed main() {
    cin >> N;
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        points.push_back({{x, y}, true});
    }
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        points.push_back({{x, y}, false});
    }
    sort(points.begin(), points.end());
    set<int> r;
    int ans = 0;
    rep(i, N * 2) {
        if (points[i].second) {
            r.insert(-points[i].first.second);
        } else {
            auto it = r.upper_bound(-points[i].first.second);
            if (it != r.end()) {
                ans++;
                r.erase(it);
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int ans = INT_MAX;
  for (int bit = 0; bit < 1 << N; bit++) {
    int csum = 0;
    vector<int> tmp(M);
    for (int i = 0; i < N; i++) {
      if (bit >> i & 1) {
        csum += C.at(i);
        for (int j = 0; j < M; j++) {
          tmp.at(j) += A.at(i).at(j);
        }
      }
    }
    int mi = *min_element(tmp.begin(), tmp.end());
    if (mi < X) continue;
    ans = min(ans, csum);
  }
  if (ans == INT_MAX) return cout << -1 << "\n", 0;
  cout << ans << "\n";
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{
	int n, m;
	while (true){
		cin >> n >> m;
		if (n == 0 && m == 0){
			break;
		}
		int map[100][100] = { 0 };
		int dp[100][100] = { 0 };
		for (int i = 0; i < m; i++){
			for (int i2 = 0; i2 < n; i2++){
				cin >> map[i][i2];
			}
		}
		for (int i = 0; i < n; i++){
			if (map[0][i] == 0){
				dp[0][i] = 1;
			}
		}
		for (int i = 0; i < m; i++){
			for (int i2 = 0; i2 < n; i2++){
				if (map[i][i2] == 0){
					for (int i3 = -1; i3 <= 1; i3++){
						if (i2 + i3 >= 0 && i2 + i3 < n && (map[i + 1][i2 + i3] == 0 || i3 == 0 && map[i + 1][i2 + i3] == 2)&&(i<m-1||i3==0)){
							dp[i + 1][i2+i3]  += dp[i][i2];
						}
					}	
				}
				else if (map[i][i2] == 2){
							dp[i + 2][i2] += dp[i][i2];
					}
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++){
			ans += dp[m][i];
			ans += dp[m+1][i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, N;
  cin >> N;
  cin >> A;
  if ((A >= 499)||(N%500 <= A)) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

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

int main(){
    int n,k;
    cin>>n>>k;
    
    unsigned long long ans=0;
    ans += pow(n/k,3);

    if(k%2 == 0){
        float a = n/(k*1.0) - 0.5;
        ans += pow(floor(a)+1,3);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

vector<ll> res;

vector<long long> enum_divisors(long long N) {
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N / i != i) res.push_back(N / i);
        }
    }
    // 小さい順に並べ替える
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ll n;
    cin >> n;
    enum_divisors(n);
    ll a = res[res.size() / 2];
    int ans = 0;
    while (a > 0) {
        ans++;
        a /= 10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
int main(){
    string S;
    cin >> S;
    if (S == "AAA" || S == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter

#参考 https://atcoder.jp/contests/abc111/submissions/14666502

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

v0 = v[0:n-1:2]
v1 = v[1:n:2]

c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()


if len(set(v0)) == len(set(v1)) == 1:
    if c0[0] == c1[0]:
        ans = len(v0)
    else:
        ans = 0
else:
    if c0[0] != c1[0]:
        ans = n - c0[0][1] - c1[0][1]
    else:
        ans = min(n - c0[0][1] - c1[1][1], n - c0[1][1] - c1[0][1])
print(ans) 

Measured memory_bytes: 105524
dic = dict()
while 1:
    try:
        c,d = (int(x) for x in input().split(","))
    except:
        break
    value = dic.get(c)
    if not value:
        dic.setdefault(c,-1)
    else:
        dic.update({c:value - 1})

while 1:
    try:
        c,d = (int(x) for x in input().split(","))
    except:
        break
    value = dic.get(c)
    if value:
        if value < 0:
            value *= -1
        dic.update({c:value + 1})
dic = dict(sorted(dic.items()))

for x, y in dic.items():
    if y > 0:
        print(x,y)


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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

const int MOD = 1e9 + 7;

vector <vector <int> > dp;

int main() {
    int h, w;
    cin >> h >> w;

    char a[h][w];
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> a[i][j];
    dp.assign(h, vector <int> (w, 0));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            if (!i && !j) dp[i][j] = 1;
            else {
                ll sum = 0;
                if (i > 0 && a[i - 1][j] != '#') sum += dp[i - 1][j];
                if (j > 0 && a[i][j - 1] != '#') sum += dp[i][j - 1];
                dp[i][j] = sum % MOD;
            }
        }
    cout << dp.back().back() << '\n';
    return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(){
typedef long long ll;
 ll a[4][1001],m[4][1001],n,w,t,ans=0;
 vector<ll>b,c;
  cin>>n>>w;
 
  for(int i=0;i<4;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
 
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      b.push_back(a[0][i]+a[1][j]);
      c.push_back(a[3][i]+a[2][j]);
    }
  }
 
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
 
  for(vector<ll>::iterator it=b.begin();it!=b.end();it++){
    ans+=upper_bound(c.begin(),c.end(),w-(*it))-lower_bound(c.begin(),c.end(),w-(*it));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 18856
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7


void calcDiv(ll n, queue<ll>& div)
{
    for (ll i = 1; i*i <= n; i++)
    {
        if (n % i != 0) continue;
        if (i != 1) div.push(i);
        if (i * i < n) div.push(n / i);
    }
}

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

    queue<ll> div1, div2;
    calcDiv(n, div1); // こっちはチェックが必要
    calcDiv(n - 1, div2); // こっちは全部OK

    int s = div1.size();
    rep(i, 0, s)
    {
        ll k = div1.front();
        div1.pop();

        ll h = (n / k) % k;
        if (h == 1)
        {
            div1.push(k);
        }
        else if (h == 0)
        {
            ll tmp = n, r = 0;
            while(r == 0)
            {
                tmp /= k;
                r = tmp % k;
            }
            if (r == 1)
            {
                div1.push(k);
            }
        }
    }

    map<ll, bool> ans;
    while (!div1.empty())
    {
        ans[div1.front()] = true;
        div1.pop();
    }
    while(!div2.empty())
    {
        ans[div2.front()] = true;
        div2.pop();
    }

    cout << ans.size() << endl;
}


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

int main(void)
{   
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    while(b - a >= 0) {
        cnt++;
        if(cnt == c) break;
        b -= a;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int w = 0, r = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'W') w++;
    else r++;
  }
  int ans = 0;
  for(int i = 0; i < r; i++){
    if(s[i] == 'W') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3744
import java.util.*;
 
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[100001];
    int ans = 0;
    for(int i = 1;i <= N;i++){
      int num = sc.nextInt();
      if(num <= 100000){
        a[num]++;
      }else{
        a[0]++;
      }
    }
    for(int i = 0;i <= 100000;i++){
      if(a[i] > i){
        ans += a[i] - i;
      }else if(a[i] < i){
        ans += a[i];
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50444
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int n;
int a[22];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 0;
	sort(a, a + n);
	rep(i, n - 1)ans += a[i];
	if (ans > a[n - 1])puts("Yes");
	else puts("No");
	ggr
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    for(int i = a; i <= b && i < a + k; ++i){
        cout << i << endl;
    }
    for(int j = b - k + 1; j <= b; ++j){
        if(j < a + k){ continue; }
        cout << j << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	int ans = 0;
	while (1) {
		int tmp = 0;
		bool now = false;
		bool ok = false;
		rep(i, n) {
			if (h[i] <= 0) {
				if (now) tmp++;
				now = false;
			}
			else {
				ok = true;
				now = true, h[i]--;
			}
		}
		if (!ok) break;
		if (now) tmp++;
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = tuple(map(int, input().split()))
student = []
check = []
ans = []

for i in range(N):
    student.append(list(map(int, input().split())))

for i in range(M):
    check.append(list(map(int, input().split())))

for s in student:
    x = 10**9
    tmp = 0
    index = 1
    for c in check:
        y = abs(s[0]-c[0])+abs(s[1]-c[1])
        if (x > y):
            x = y
            tmp = index
        index+=1
    ans.append(tmp)

for a in ans:
    print(a)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] < 0) cnt++;
  }

  for (int i = 0; i < N; i++)
    if (A[i] < 0) A[i] = -A[i];

  if (cnt % 2 == 1) {
    cout << accumulate(A.begin(), A.end(), 0LL) -
                *min_element(A.begin(), A.end()) * 2
         << endl;
  } else {
    cout << accumulate(A.begin(), A.end(), 0LL) << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
fn main() {
    let input = read_vec::<u128>();

    let a: f64 = input[0] as f64;
    let b: f64 = input[1] as f64;
    let c: f64 = input[2] as f64;
    let d: f64 = input[3] as f64;

    let taka_count = (c / b).ceil();
    let ao_count = (a / d).ceil();

    println!("{}", if taka_count <= ao_count {"Yes"} else {"No"});
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 2656
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define vi vector <int >
#define vvi vector < vi > 
#define vii vector < pii >
#define viii vector < piii >
#define vll vector <ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n, m, k;
    cin >> n >> m;
    vi arr(m);
    vvi a(m);
    vi ax(m);
    forn(i, m){
        cin >> arr[i] >> k;
        a[i].resize(k);
        ax[i] = 0;
        forn(j, k){
            cin >> a[i][j];
            a[i][j]--;
            ax[i] = ax[i]|(1 << a[i][j]);
        }
    }

    vi dp((1 << n) + 5);
    dp[0] = 0;
    for(int i = 1; i < (1 << n); i++){
        dp[i] = INT_MAX;
        forn(j, m){
            if(!(i&ax[j])) continue;
            int aux = i;
            for(auto z:a[j]){
                if(aux&(1 << z)){
                    aux = aux^(1 << z);
                }
            }
            dp[i] = min(dp[i], arr[j] + dp[aux]);
        }
    }
    int bitmask = (1 << n) - 1;

    if(dp[bitmask] >=INT_MAX){
        cout << -1 << endl;
    }else{
        cout << dp[bitmask] << endl;
    }


    return 0;
}


Measured memory_bytes: 384
PROGRAM b164
 
IMPLICIT NONE
INTEGER :: A, B, C, D, T1, T2

READ *, A, B, C, D

IF (MOD(C,B) == 0) THEN
	T1 = (C / B) -1
    ELSE 
    T1 = C / B 
END IF

IF (MOD(A,D) == 0) THEN
	T2 = (A / D) -1
    ELSE
    T2 = A / D
END IF
 
IF (T2 < T1) THEN
	PRINT *, 'No'
    ELSE
    PRINT *, 'Yes'
END IF
 
END PROGRAM b164

Measured memory_bytes: 2792
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
int main() {
    ll N;
    cin>>N;
    vi A(N+2);
    A[0]=0;
    A[N+1]=0;
    FOR(i,1,N+1)cin>>A[i];
    /*vi ac(N+1,0);
    FOR(i,0,N+1){
        ac[i+1]=ac[i]+llabs(A[i]-A[i+1]);
    }*/
    ll ac=0;
    REP(i,N+1)ac+=llabs(A[i]-A[i+1]);
    FOR(i,1,N+1){
        if((A[i]-A[i-1])*(A[i+1]-A[i])>=0)cout<<ac<<endl;
        else cout<<ac-2*min(llabs(A[i]-A[i-1]),llabs(A[i+1]-A[i]))<<endl;
    }
    //REP(i,N+2)cout<<ac[i]<<" ";
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a >= b) cout << b << endl;
    else cout << n*a << endl;
    return 0;
}

Measured memory_bytes: 3500
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
int main(void){
  ll n;
  cin>>n;
  vl a(n);
  rep(i,n){
    cin>>a[i];
  }
  vll dp=vll(3,vl(n,0));
  dp[0][0]=1;
  vl dp2(n,1);//結び目の個数
  dp2[0]=3;
  ll ans=1;
  if(a[0]!=0){
    cout<<0;
    return 0;
  }
  if(n==2){
    if(a[1]==1){
      cout<<3;
    }else if(a[1]==0){
      cout<<6;
    }else{
      cout<<0;
    }
    return 0;
  }else if(n==1){
    cout<<3;
    return 0;
  }
  for(ll i=1;i<n;i++){
    ll num=a[i];
    ll cross=0;
    if(dp[0][i-1]==num)cross+=1;;
    if(dp[1][i-1]==num)cross+=1;;
    if(dp[2][i-1]==num)cross+=1;;
    dp2[i]=cross;
    if(cross==0){
      cout<<0<<endl;
      return 0;
    }
    rep(j,3){
      dp[j][i]=dp[j][i-1];
    }
    rep(k,3){
      if(dp[k][i-1]==num){
        dp[k][i]=num+1;
        break;
      }
    }
  }
  rep(i,n){
    ans*=dp2[i];
    ans%=d9_7;
  }
  cout<<ans%d9_7<<endl;
  return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        string S; cin >> S;
        vector<vector<int>> positions(10);
        rep(i, N) {
            positions[S[i] - '0'].push_back(i);
        }
        int cnt = 0;
        rep(i, 10) {
            if(positions[i].size() == 0) continue;
            int pi = positions[i].front();
            rep(j, 10) {
                if(positions[j].size() == 0) continue;
                int pj = upper_bound(all(positions[j]), pi) - begin(positions[j]);
                if(pj >= positions[j].size()) continue;
                pj = positions[j][pj];
                rep(k, 10) {
                    if(positions[k].size() == 0) continue;
                    int pk = upper_bound(all(positions[k]), pj) - begin(positions[k]);
                    if(pk >= positions[k].size()) continue;
                    pk = positions[k][pk];
                    cnt++;
                    // cout << i << j << k << " " << pi << " " << pj << " " << pk <<  endl;
                }
            }
        }
        cout << cnt << endl;

        return 0;
    }
};

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


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
  int N, INF = 1e9;
  cin >> N;
  int m = INF, M = 0, bigger_m = INF, smaller_M = 0, x, y;
  priority_queue< pair<int,int> > smaller;
  vector<int> X(N), Y(N);
  for(int i = 0; i < N; ++i){
    cin >> x >> y;
    if(x > y) swap(x,y);
    m = min(m,x);
    M = max(M,y);
    bigger_m = min(bigger_m,y);
    smaller_M = max(smaller_M,x);
    smaller.emplace(-x, i);
    X[i] = x;
    Y[i] = y;
  }
  long long int ans = (long long int)(M - bigger_m)*(smaller_M - m);
  for(int i = 0; i < N; ++i){
    pair<int,int> p = smaller.top();
    int x = -p.first, k = p.second;
    smaller.pop();
    if(Y[k] < x) break;
    smaller.emplace(-Y[k],k);
    smaller_M = max(Y[k], smaller_M);
    bigger_m = -smaller.top().first;
    ans = min(ans,(long long int)(M-m)*(smaller_M-bigger_m));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4084
import numpy as np
import math

def main():
    X=int(input())

    res=0
    vec=np.array([1,0])
    rot=np.array([[math.cos(math.radians(X)),-1*math.sin(math.radians(X))],[math.sin(math.radians(X)),math.cos(math.radians(X))]])
    pos=np.array([0,0])

    pos=pos+vec
    vec=np.dot(rot,vec)
    res+=1
    while abs(pos[0])>=0.001 or abs(pos[1])>=0.001:
        pos=pos+vec
        vec=np.dot(rot,vec)
        res+=1
    print(res)

if __name__=="__main__":
    main()

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

int main()
{
	int y,m,d;
	scanf("%d/%d/%d",&y,&m,&d);
	if(y>2019) 
		cout <<"TBD";
	else if(y==2019) {
		if(m>4) cout <<"TBD";
		else {
		    cout <<"Heisei";
		}
	}
	else cout <<"Heisei";
	return 0;
}

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

int main()
{
  int A, B;
  cin >> A >> B;

  if (A <= 8 && B <= 8)
  {
    cout << "Yay!" << endl;
  }
  else
  {
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 3612
use std::cmp::min;

const INF: i64 = std::i64::MAX;

fn main() {
    let mut ns = vec![];
    let mut ms = vec![];
    let mut xs = vec![];
    let mut cs = vec![];
    loop {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut s = buf.split_whitespace();
        let n: usize = s.next().unwrap().parse().unwrap();
        let m: usize = s.next().unwrap().parse().unwrap();
        if n == 0 && m == 0 { break; }
        let mut c = vec![];
        for _ in 0..m {
            let mut ims = String::new();
            std::io::stdin().read_line(&mut ims).unwrap();
            let i: i64 = ims.trim().parse().unwrap();
            c.push(i)
        }
        let mut x = vec![];
        for _ in 0..n {
            let mut ins = String::new();
            std::io::stdin().read_line(&mut ins).unwrap();
            let i: i64 = ins.trim().parse().unwrap();
            x.push(i)
        }
        ns.push(n);
        ms.push(m);
        xs.push(x);
        cs.push(c);
    }
    for i in 0..ns.len() {
        let (n, m, x, c) = (ns[i], ms[i], &xs[i], &cs[i]);
        let mut dp = vec![vec![INF; 256]; n + 1];
        dp[0][128] = 0;
        for i in 0..n {
            for j in 0..256 {
                for k in 0..m {
                    if dp[i][j] < INF {
                        let mut nx = j as i64 + c[k];
                        nx = if nx < 0 { 0 } else if nx > 255 { 255 } else { nx };
                        dp[i + 1][nx as usize] = min(dp[i + 1][nx as usize],
                                           dp[i][j] + (nx - x[i]).pow(2));
                    }
                }
            }
        }
        let ans = dp[n].iter().min().unwrap();
        println!("{}", ans);
    }
}




Measured memory_bytes: 46000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << t * ((n + x - 1) / x) << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll n, k;
	cin >> n >> k;
	cout << (n%k ? 1 : 0) << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from scipy.sparse.csgraph import floyd_warshall

h,w=nii()
c=[lnii() for i in range(10)]
a=[lnii() for i in range(h)]

s=floyd_warshall(c)

ans=0
for i in range(h):
  for j in range(w):
    if a[i][j]==-1:
      continue
    ans+=s[a[i][j]][1]
print(int(ans))

Measured memory_bytes: 38176
// AOJ 1527: Yu-kun Likes Rectangles
// 2019.2.20 bal4u

#include <stdio.h>
#include <stdlib.h>

#define gc() getchar()

#define NA -10000000
int H, W, h, w;
int A[55][55];
char B[55][55], C[55][55];

int in()
{
	int n = 0, c = gc();
	if (c == '-') {
		c = gc();
		do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int match(int rr, int cc)
{
	int r, c;

	for (r = 0; r < h; r++) for (c = 0; c < w; c++) 
		if (B[rr + r][cc + c] != C[r][c]) return 0;
	return 1;
}

int sum(int rr, int cc)
{
	int s, r, c;

	s = 0;
	for (r = 0; r < h; r++) for (c = 0; c < w; c++) s += A[rr + r][cc + c];
	return s;
}

int main()
{
	int r, c, dh, dw;
	int s, max;

	H = in(), W = in();
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) A[r][c] = in();
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) B[r][c] = in();
	h = in(), w = in();
	for (r = 0; r < h; r++) for (c = 0; c < w; c++) C[r][c] = in();

	dh = H - h, dw = W - w;
	max = NA;
	for (r = 0; r <= dh; r++) for (c = 0; c <= dw; c++) {
		if (match(r, c)) {
			s = sum(r, c);
			if (s > max) max = s;
		}
	}
	if (max == NA) puts("NA");
	else printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    if (n % 2 == 0) {
        cout << n / 2 - 1 << endl;
    }
    else {
        cout << (n + 1) / 2 - 1 << endl;
    }
    return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	int an = a[n - 1], ar = a[0];
	long long dis = 1e9;
	for (int i = 1; i < n - 1; i++) {
		if (dis > abs(a[i] * 2 - an)) {
			dis = abs(a[i] * 2 - an);
			ar = a[i];
		}
	}
	cout << an << ' ' << ar << endl;

	return 0;
}

Measured memory_bytes: 640
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

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

void test() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool ok = false;
    while (a > 0 and c > 0) {
        ok ^= true;
        if (ok) {
            c -= b;
        } else {
            a -= d;
        }
    }
    cout << (ok ? "Yes\n" : "No\n");
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        test();
    }
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize(3)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

const int maxn = 5000 + 10;
const int inf = 0x3f3f3f3f;

bool cmp(ll x, ll y)
{
	return x > y;
}

ll read()
{
	ll x;
	scanf("%lld", &x);
	return x;
} 

ll x, y, z, k, a[maxn], b[maxn], c[maxn], ans1[maxn * maxn], ans2[maxn * maxn];

int main()
{
	x = read(), y = read(), z = read(), k = read();
	for(int i = 1; i <= x; i ++)
	{
		a[i] = read(); 
	}
	for(int i = 1; i <= y; i ++)
	{
		b[i] = read();
	}
	for(int i = 1; i <= z; i ++)
	{
		c[i] = read();
	}
	sort(a + 1, a + x + 1, cmp);
	sort(b + 1, b + y + 1, cmp);
	sort(c + 1, c + z + 1, cmp);
	
	int res = 0, res2;
	
	for(int i = 1; i <= x; i ++)
	{
		for(int j = 1; j <= y; j ++)
		{
			ans1[++res] = a[i] + b[j];
		}
	}
	sort(ans1 + 1, ans1 + 1 + res, cmp);
	for(int i = 1; i <= min(res, 3000); i ++)
	{
		for(int j = 1; j <= z; j ++)
		{
			ans2[++res2] = ans1[i] + c[j];
		}
	}
	sort(ans2 + 1, ans2 + 1 + res2, cmp);
	for(int i = 1; i <= k; i ++)
	{
		cout << ans2[i] << endl;
	}
}

Measured memory_bytes: 35072
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)+1
v1 = [None]*n
v2 = [None]*n
v1[0] = 0
v2[-1] = 0
v = 0
for i,c in enumerate(s):
    if c=="<":
        v += 1
    else:
        v = 0
    v1[i+1] = v
v = 0
for i,c in enumerate(s[::-1]):
    if c==">":
        v += 1
    else:
        v = 0
    v2[n-2-i] = v
ans = [max(v1[i], v2[i]) for i in range(n)]
print(sum(ans))

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

int main() {
  int N;
  cin >> N;
  if ((N/100)%10 == (N/10)%10 && (N/1000 == N/100%10 || N/10%10 == N%10) ){
  cout << "Yes" << endl;}
  else
    cout << "No" << endl;
  }


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

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

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile("\\s");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 181820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,d;
	cin>>n>>d;
	ll ans=0;
	ll a,b;
	while(n--){
		cin>>a>>b;
		if(a*a+b*b<=d*d)ans++;
	}
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,rs,ans = 0;
    cin >> N;

    for(int i = 1;i <= N;i+=2){
        rs=0;
        for(int j = 1;j <= i;j++){
            if(i % j == 0)
                rs++;
        }
        if(rs == 8)
            ans++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    static class Point implements Comparable<Point>{
    	int point, x, y;
    	Point(int x, int y) {
    		this.x=x;
    		this.y=y;
    	}
    	public int compareTo(Point p1) {
    		if(p1.x == this.x) {
                return this.y - p1.y;
            }
            return this.x - p1.x;
    	}
    }
    
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
                int n = sc.nextInt();
                ArrayList<Point> pairs=new ArrayList<Point>();
                
                for(int i=0; i<n; i++){
                    int X = sc.nextInt();
                    int Y = sc.nextInt();
                    pairs.add(new Point(X, Y));
                }//準備
                Collections.sort(pairs);
                for(int i = 0; i < n; i++) {
                    System.out.println(pairs.get(i).x+" "+pairs.get(i).y);
                }
                
        }
    }
}


Measured memory_bytes: 114912
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
#define LOCAL  1
#define UPLOAD 2
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

// #define int long long

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  int N = input();
  int prev = 0;
  int max = 0;
  int currentMax = 0;
  for(int i=0;i<N;i++){
    int now = input();
    
    if(i > 0){
      if(prev >= now){
        currentMax++;
      }
      else{
        currentMax = 0;
      }
      if(currentMax > max)max = currentMax;
    }
    prev = now;
  }

  output(max);


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	string s;
  	cin>>s;
  	if(s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]) cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
	return 0;
}

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

int main(void) {
	int n, f;
	long long int t = 0;
	t=0;
	scanf("%d",&n);
	int a[n+1], b[n];
	for(int i=0;i<n+1;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	 b[n] = 0;
	for(int i=0;i<n;i++){
		if(a[i]>b[i]){
			t+=b[i];
		}else{
			t+=a[i];
			f=b[i]-a[i];
			if(f>=a[i+1]){
				t+=a[i+1];
				a[i+1]=0;
			}else{
				t+=f;
				a[i+1]-=f;
			}
			}
		}
		  printf("%lld\n",t);
	

	
	// your code goes here
	return 0;
}


Measured memory_bytes: 896
n = gets.to_i
h = gets.split.map(&:to_i)
r = n.times.map {|i| 0}

def sorted?(a)
  a.each_cons(2).all? {|a, b| a <= b }
end

n.times do |i|
  if i == h.length - 1
  elsif h[i+1] == h[i]
  elsif h[i] > h[i+1]
    h[i] -= 1 if r[i] == 0
    r[i] = 1
  elsif h[i+1] > h[i]
    h[i+1] -= 1 if r[i+1] == 0
    r[i+1] = 1
  end
end

puts (sorted?(h) ? 'Yes' : 'No')


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

using namespace std;
int n,l;
string a[100005];
int main()
{
	cin>>n>>l;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		cout<<a[i];

 
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int c[100];
int main(){
	int n,ans;
	while(true){
	cin>>n;
	if(!n)break;
	for(int i=0;i<n*2;i++)c[i]=1;
	for(int i=0;i<n;i++){
		cin>>ans;
		c[ans-1]=0;
	}
	n*=2;
	int find=0;
	while(true){
		for(int i=0;i<n;i++){
			if(c[i]==find)c[i]=-1,find=1-find;
			bool t=false;
			for(int i=0;i<n;i++)if(c[i]==0)t=true;
			if(!t){find=1;goto loop;}
			t=false;
			for(int i=0;i<n;i++)if(c[i]==1)t=true;
			if(!t){find=0;goto loop;}
		}
		find=1-find;
	}
	loop:
	ans=0;
	for(int i=0;i<n;i++)if(c[i]==find)ans++;
	if(find)cout<<ans<<"\n0"<<endl;
	else cout<<"0\n"<<ans<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int a,b; cin >> a >> b;
	if(b%a == 0 ) cout << a+b << endl;
	else cout << b-a << endl;

	return 0;

}


Measured memory_bytes: 256