akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int table[1000000] = {0};

int main()
{
    int N, M, K;
    bool flag = false;

    cin >> N >> M >> K;

    for (int i = 0; i <= N; i++)
        table[i*M]++;
    for (int i = 0; i <= M; i++)
        table[i*N]++;

    for (int i = 1; i < N-1; i++) {
        for (int j = 1; j < M-1; j++) {
            table[i*j + (N-i)*(M-j)]++;
        }
    }


    if (table[K])
        flag = true;

    if (flag)
        cout << "Yes" << endl;

    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cin>>n>>m;
    if(n%3==0||m%3==0||(n+m)%3==0)cout<<"Possible";
    else cout<<"Impossible";
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector <vector <int>> s(10,vector <int> (10,0));


    int am,au,i2;
    ll ans;
    ans=0;

    rep(i,n){
        i2=i+1;
        au=i2%10;
        while(i2>=10){
            i2/=10;
        }
        am=i2;
        ++s[am][au];

    }

    rep(i,9){
        rep(j,9-i){
            if(j==0){
                ans+=s[i+1][i+1]*s[i+1][i+1];
            }
            else{
                ans+=s[i+1][j+i+1]*s[j+i+1][i+1]*2;
            }
        }
    }
        
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
a, op, b = input().split()
a = int(a)
b = int(b)
while op != "?":
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    

Measured memory_bytes: 7656
#include<stdio.h>

int main()
{
   int n,a,b;
   scanf("%d %d %d",&n,&a,&b);
   if(n == 1 ){
       if( a == b)
           printf("1");
        else
            printf("0");
   } 
   else{
       if(a > b ) 
         printf("0");
       else
         printf("%lld",(long long)(b-a)*(n-2)+1);
   
   }
    return 0;
}
    


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

int main() {
  int x, y, z,a, w;
  cin >> x >>y >>z>>a>>w;
  if (x==0){
    cout << 1;
  }
  if (y==0){
    cout << 2;
  }
  if (z==0){
    cout << 3;
  }
  if (a==0){
    cout << 4;
  }
  if (w==0){
    cout << 5;
  }
	return 0;
}


Measured memory_bytes: 3560
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = 10**9+7

    if abs(iN - iM) <= 1:
        if iN < iM:
            iN,iM = iM,iN
        iFacM = 1
        for i in range(1,iM+1):
            iFacM *= i
            iFacM %=iD
        if iN == iM:
            print( iFacM ** 2 % iD * 2 % iD )
        else:
            #うーむ。たしかに。差分が1だからNかけるだけでいいわけだ。
            print( iFacM ** 2 % iD * iN % iD  )
    else:
        print(0)
解()


Measured memory_bytes: 3060
# 1 <= N <= 10 ** 5
# 0 <= M <= N − 1
# 1 <= a <= N - 1
N, M = map(int, input().split())

memo = {1: 1, 0: 1}
for i in range(2, int(10**5) + 1):
  memo[i] = memo[i-1] + memo[i-2]


stairs = [False for _ in range(N + 1)]
pattern = 1
prev = 0
for _ in range(M):
  a = int(input())
  sub = a - prev - 1
  if sub == -1:
    print(0)
    break
  pattern *= memo[sub]
  prev = a + 1
else:
  sub = N - prev
  pattern *= memo[sub]
  print(pattern % 1000000007)


Measured memory_bytes: 469376
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b,c,t;
    while(cin>>a>>b>>c)
    {
        if(a>b)
        {
            t=a;
            a=b;
            b=t;
        }
        if(a>c)
        {
            t=a;
            a=c;
            c=t;
        }
        if(b>c)
        {
            t=b;
            b=c;
            c=t;
        }
        if(a==5&&b==5&&c==7)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,count=0;
double s;
cin>>n;
for(i=1;i<=n;i++)
{
    if(i%2!=0)
    {
        count++;
    }
}
s=(double)count/n;
printf("%.10lf\n",s);
return 0;
}


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 asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	int n;
	int b[105];
	cin >> n;
	rep(i, n-1) cin >> b[i];
	int cnt = b[0];
	for(int i = 0; i < n-1; i++){
		if(i != n-2){
			if(b[i+1] > b[i]){
				cnt += b[i];
			}else{
				cnt += b[i+1];
			}
		}else{
			cnt += b[i];
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N,D;
    int count = 0;
    int ans = 0;
    scanf("%d",&N);
    scanf("%d",&D);
    int range = 2 * D + 1;
    while(count < N){
        count = count + range;
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

ans = 0
for i in range(K + 1):
    for j in range(K + 1 - i):
        for k in range(K + 1 - i - j):
            tmp = list()
            tmp.extend(V[:min(i, N)])
            tmp.extend(V[max(i, N - j):N])
            tmp.sort(reverse=True)
            for _ in range(k):
                if len(tmp) > 0 and tmp[-1] < 0:
                    tmp.pop()
            ans = max(ans, sum(tmp))

print(ans)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    ll tmp = n;
    ll s = 0;
    while(tmp){
        s += tmp%10;
        tmp /= 10;
    }
    print((n%s == 0)? "Yes" : "No")
    return 0;
}

Measured memory_bytes: 256
N=gets.to_i
S=gets.chomp
e=Array.new(N)
w=Array.new(N)
e[0]=0
w[-1]=0
(N-1).times{|i|
    e[i+1]=e[i]
    e[i+1]+=1 if S[i]=="W"
    w[-i-2]=w[-i-1]
    w[-i-2]+=1 if S[-i-1]=="E"
}
warn e.inspect
warn w.inspect
puts e.zip(w).map{|x,y|x+y}.min


Measured memory_bytes: 38744
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k == X:
                counter += 1

print(counter)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());


int main(){
    string s,t;
    cin >> s >> t;
    if(s[0] == t[0]) cout << 'H' << endl;
    else cout << 'D' << endl;
}



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

int stones[100001] = {};
void fillCost(vector<int> &v, int n){
	stones[1] = abs(v[1] - v[0]);
	for (int i = 2; i < n; i++){
		stones[i] = min(stones[i-1]+abs(v[i-1]-v[i]), stones[i-2]+abs(v[i-2]-v[i]));
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,x;
	cin >> n;
	vector<int> h;
	int arr[n] = {};
	for (int i = 0; i < n; i++){
		cin >> x;
		h.push_back(x);
	}
	fillCost(h,n);
	cout << stones[n-1];
}

Measured memory_bytes: 4544
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        Sort(a);
        int num = 0;
        // check
        if(n % 2 == 0)
        {
            for(int i = 0, c = 1; i < n; i += 2 , c += 2)
            {
                if(a[i] != c || a[i + 1] != c)
                {
                    WriteLine("0");
                    return;
                }
            }
            num = n / 2;
        }
        else
        {
            if(a[0] != 0)
            {
                WriteLine("0");
                return;
            }
            for(int i = 1, c = 2; i < n; i += 2, c += 2)
            {
                if(a[i] != c || a[i + 1] != c)
                {
                    WriteLine("0");
                    return;
                }
            }
            num = (n - 1) / 2;
        }
        long result = 1;
        for(int i = 0; i < num; i++)
        {
            result = (result << 1) % 1000000007;
        }
        WriteLine(result);
    }
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	int N, K;
	cin >> N >> K;
	vector<int> left, right;
	left.push_back(0);
	right.push_back(0);

	rep(i, 0, N) {
		int x;
		cin >> x;
		if(x <= 0) left.push_back(-x);
		else right.push_back(x);
	}

	vsort(left);
	vsort(right);
	int res = 1000000000;
	rep(i, 0, left.size()) {
		int n = K - i;
		if(0 <= n && n < right.size()) res = min(res, left[i] * 2 + right[n]);
	}

	rep(i, 0, right.size()) {
		int n = K - i;
		if(0 <= n && n < left.size()) res = min(res, right[i] * 2 + left[n]);
	}

	cout << res << endl;
}


Measured memory_bytes: 1020
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
lr = [list(map(int,input().split())) for i in range(M)]
for l,r in lr:
    num[l-1][r-1] += 1

for j in range(N):
    for i in range(N-1,0,-1):
        num[i-1][j] += num[i][j]
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
pq = [list(map(int,input().split())) for i in range(Q)]
for p,q in pq:
    print(num[p-1][q-1])


Measured memory_bytes: 73264
#include<bits/stdc++.h>
using namespace std;
#define  ll long long int
const ll N=100000;
int main()
{
    int a,b;
    cin>>a>>b;
     if(a==b){
        for(int i=0;i<b;i++)
        {
            cout<<a;
        }
     }
    else if(a>b){
        for(int i=0;i<a;i++)
        {
            cout<<b;
        }
    }
    else {
        for(int i=0;i<b;i++)
        {
            cout<<a;
        }
    }

   return 0;

}


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

int main(){
    long long n , v ;
    cin >> n >> v ;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            int k = n-i-j ;
            if ( k >= 0 ){
                long long ans = i*10000LL + 5000LL * j + k * 1000LL;
                if ( ans == v ){
                    cout << i << ' ' << j << ' ' << k << endl;
                    return 0 ;
                }
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int n;
    int b,f,r,v;
    int a[4][3][10] = {};

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }

    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                    cout << " " << a[i][j][k];
            }
        cout << endl;
        }
        if(i!=3){
            cout << "####################" << endl;
        }
    }
}


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

int main(){
    vector<pair<char,int>> m;
    string s;
    cin >> s;

    char x = s[0];
    int cnt = 1;
    for(int i = 1; i < s.length(); i++){
        if(x == s[i]){
            cnt++;
        }else{
            m.push_back({x, cnt});
            x = s[i];
            cnt = 1;
        }
    }
    m.push_back({x, cnt});

    int n = m.size();
    int ans = 0;

    for(int i = 0; i < n-2; i++){
        if(m[i].first == 'J' && m[i+1].first == 'O' && m[i+2].first == 'I'){
            if(m[i].second >= m[i+1].second && m[i+2].second >= m[i+1].second)
                ans = max(ans, m[i+1].second);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12568
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int d[100];
int main()
{
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	int p[3];
	fill(p, p + 3, 0);
	int now = 0;
	for (;;)
	{
		if (p[now] == s[now].size())
		{
			printf("%c\n", 'A' + now);
			return 0;
		}
		p[now]++;
		now = s[now][p[now] - 1] - 'a';
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
  
void dfs();
void visit(int );
  
int n, G[MAX][MAX], d[MAX], f[MAX], color[MAX], time=0;
  
int main()
{
  int i, j, u, k, v;
  
  scanf("%d", &n);
  for(i=0; i<=n; i++)
    {
      for(j=0; j<=n; j++)
    {
      G[i][j] = 0;
    }
    }
  for(i=1; i<=n; i++)
    {
      scanf("%d %d", &u, &k);
      for(j=1; j<=k; j++)
    {
      scanf("%d", &v);
      G[u][v] = 1;
    }
      color[u] = WHITE;
    }
  
  dfs();
  
  for(i=1; i<=n; i++) printf("%d %d %d\n", i, d[i], f[i]);
  
  return 0;
}
  
void dfs()
{
  int i;
  
  for(i=1; i<=n; i++)
    {
      if(color[i] == WHITE) visit(i);
    }
}
  
void visit(int u)
{
  int i;
  
  color[u] = GRAY;
  d[u] = ++time;
  
  for(i=1; i<=n; i++)
    {
      if(G[u][i] == 1 && color[i] == WHITE)
    {
      visit(i);
    }
    }
  color[u] = BLACK;
  f[u] = ++time;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    string s, t;
    cin >> s >> t;
    s = s + s;
    for(ll i = 0; i < s.size(); i++){
        if(s.substr(i, t.size()) == t){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define N 10000
#define true 1
#define false 0

int isPrime(int);

int main(){
  int i,data[N],n,cnt=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&data[i]);
  }

  for(i=0; i<n; i++)
    cnt += isPrime(data[i]);
  printf("%d\n",cnt);

  return 0;
}

int isPrime(int x){
  int i;

  if(x==2) return true;
  if(x<=1 || x%2==0) return false;
  for(i=3; i<=(int)sqrt(x); i+=2){
    if(x%i == 0) return false;
  }
  return true;

}

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

int main(){
  ll L,R,ans=2e9;
  cin>>L>>R;
  for(ll i=L;i<=R;i++){
    for(ll j=i+1;j<=R;j++){
      ans=min(ans,i*j%2019);
      if(i*j%2019==0){
        cout<<"0"<<endl;
        return 0;
      }
    }
  }
  cout<<ans<<endl;
}



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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string S;
    cin>>S;
    if(S=="ABC") cout << "ARC" <<endl;
    else cout << "ABC" <<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define SIZE 101
using namespace std;
int main(){
    int n,m,x,y;
    int count1=0,count2=0;
    int a[SIZE]={},b[SIZE]={};
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<m;i++)
        cin>>b[i];
    for(int i=x+1;i<=y;i++){
        count1=0;
        count2=0;
        for(int j=0;j<n;j++){
            if(a[j]<i)count1++;
        }
        if(count1==n){
            for(int k=0;k<m;k++){
                if(b[k]>=i)count2++;
            }
        }
        else continue;
        if(count2==m){
            cout<<"No War"<<endl;
            return 0;
        }
        }
    cout<<"War"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
li = [0]*18

def bisect(x):
    ok = 17
    ng = 0
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if x*(2**mid)>=k:
            ok = mid
        else:
            ng = mid
    return ok

for i in range(1, n+1):
    if i>=k:
        li[0] += n-i+1
        break
    li[bisect(i)] += 1

ans = 0
for i, j in enumerate(li):
    ans += 2**(-i)*j
print(ans/n)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long num = 0;
        long numB = 0;
        long numA = 0;
        if (k % 2 == 1) {
            for (int i = 1; i <= n; i++)
                if (i % k == 0)
                    num++;
            System.out.println(num * num * num);
        } else {
            for (int i = 1; i <= n; i++) {
                if (i % k == 0)
                    numA++;
                if (i % k == k / 2)
                    numB++;
            }
            System.out.println(numA * numA * numA + numB * numB * numB);
        }
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x <<  " " << x << endl;
#define all(x) x.begin(), x.end()
typedef std::vector<int> vi;
typedef std::vector<vector<int>> vvi;
typedef std::vector<string> vs;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef long long ll;
const int inf = 1e9 + 5;

template <typename T>
void print(T v){ for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(2)<<*i<<" ";cout<<endl; }
template <typename T>
void print_vv(T v, bool same_line=true){
for(auto i= 0; i<v.size(); i++){cout<<"{";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(3)<<v[i][j]<<",";}cout<<"},";if(same_line) cout<<endl;}cout<<endl;}

const int mod = 1e9+7;

void add_self(int &a, int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

void sub_self(int &a, int b){
    a-=b;
    if(a<0)
        a+=mod;
}

int main(){
    int n, k;
    while(cin>>n>>k){
        vi dp(k+1); // number of ways such that we used k candies so far

        dp[0] = 1;
        for(int child=0; child<n; child++){
            int upto; cin>>upto;

            vi fake(k+1);   
            for(int used=k; used>=0; used--){
                int tmp = dp[used];
                int L = used + 1;
                int R = used + min(upto, k-used);
                if(L<=R)
                    add_self(fake[L], tmp);
                if(R+1<=k)
                    sub_self(fake[R+1], tmp);
            }

            int prefix_sum = 0;
            for(int i=0; i<=k ;i++){
                add_self(prefix_sum, fake[i]);
                add_self(dp[i], prefix_sum);
            }
        }
        

        cout<<dp[k]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {

 public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a=sc.nextInt();
	String nine="090909";
	int loga=(int)Math.log10(a);
	if(loga%2==1){
		 System.out.println(Integer.parseInt(nine.substring(0,(loga+1))));
	}else{
		int f=0;
		if(loga>0)f=Integer.parseInt(nine.substring(0,loga));
		System.out.println((int)(f+(a-Math.pow(10,loga)+1)));
	}
 }
}


Measured memory_bytes: 21204
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<string> g ;
bool inRange(int x, int y){
    if ( x < 0 || x >= n ) return false ;
    if ( y < 0 || y >= m ) return false ;
    if ( g[x][y] == '#' ) return false ;
    return true ;
}
signed main(){
    fastio
    cin >> n >> m ;
    g = vector<string>(n) ;
    int a , b , x , y ; 
    cin >> a >> b >> x >> y ; 
    a--, b--, x--, y-- ;
    for(int i = 0; i < n; i++){
        cin >> g[i] ;
    }
    deque<pair<int,int> > q ;
    vector<vector<int> > dist(n, vector<int>(m, INF)) ;
    q.push_front(make_pair(a, b)) ;
    dist[a][b] = 0 ;
    int X[] = {0, 0, -1, 1} ;
    int Y[] = {1, -1, 0, 0} ;
    while(not q.empty()){
        auto f = q.front() ; q.pop_front() ;
        int c = f.first , d = f.second ;
        for(int i = 0; i < 4; i++){
            int newx = c + X[i] , newy = d + Y[i] ;
            if ( not inRange(newx, newy) ) continue ;
            if ( dist[newx][newy] > dist[c][d] ){
                dist[newx][newy] = dist[c][d] ;
                q.push_front(make_pair(newx, newy)) ;
            }
        }
        int startx = c - 2 , starty = d - 2 ;
        for(int i = startx; i < startx + 5; i++){
            for(int j = starty; j < starty + 5; j++){
                if ( not inRange(i, j) ) continue ;
                if ( dist[i][j] > dist[c][d] + 1 ){
                    dist[i][j] = dist[c][d] + 1 ;
                    q.push_back(make_pair(i, j) ) ;
                }
            }
        }
    }
    if ( dist[x][y] == INF ){
        cout << -1 << endl;
    }
    else cout << dist[x][y] << endl;
    return 0; 
}

Measured memory_bytes: 12624
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

int nextVal(int N, int M){
//    cout<<N<<" "<<M<<endl;
    return (N*N)%M;
}

signed main(){
    int N, X, M; cin>>N>>X>>M;

    // 絶対に周期性があり、その周期は10^5以下
    vec_int exist(M+1,-1);

    int a_val = X;
    int index=1;
    exist.at(a_val) = index;

    int cycle;
    int start_pos;
    int cycle_start_num;
    while(true){
        a_val = nextVal(a_val, M);
        index++;
 //       cout<<index<<" "<<a_val<<" "<<M<<" "<<exist.at(a_val)<<endl;
        if(exist.at(a_val)!=-1){
            start_pos = exist.at(a_val);
            cycle = index-start_pos;
            cycle_start_num = a_val;
            break;
        }
        exist.at(a_val)=index;
    }
//    cout<<X<< " "<<index<<endl;
//    cout<<cycle<< " "<<start_pos<<endl;

    int cycle_N = 0;
    a_val = cycle_start_num;
    cycle_N+=a_val;
    for(int i=1;i<cycle;i++){
        a_val = nextVal(a_val, M);
        cycle_N+=a_val;
    }
    /*
    a_val = X;
    index=1;
    while(true){
        a_val = nextVal(a_val, M);
        index++;
        if(index==start_pos)cycle_start_num = a_val;
        if(index>=start_pos && index<start_pos+cycle){
            cycle_N += a_val;
        }else if(index>=start_pos+cycle){
            break;
        }
    }
    */

    if(N<3*pow(10,7)){
        int tot_val = 0;
        int a = X;
        tot_val += a;
        for(int i=1;i<N;i++){
            a = nextVal(a,M);
            tot_val += a;
        }
        cout<<tot_val<<endl;
        return 0;
    }

    if(N<start_pos+cycle){
        int tot_val = 0;
        int a = X;
        tot_val += a;
        for(int i=1;i<N;i++){
            a = nextVal(a,M);
            tot_val += a;
        }
        cout<<tot_val<<endl;
        return 0;
    }else{
        ll tot_val = 0;
        // サイクルの数を数える
        int cycle_num = (N-(start_pos-1))/cycle;
        //int yobun = (N-(start_pos-1)) - cycle_num*cycle;
        int yobun = (N-(start_pos-1))%cycle;

        int a = X;
        if(start_pos>1){
        tot_val += a;
        for(int i=1;i<start_pos-1;i++){
            a = nextVal(a,M);
            tot_val += a;
        }
        }

        tot_val += cycle_num* cycle_N;

        if(yobun>0){
        a = cycle_start_num;
        tot_val += a;
        for(int i=1;i<yobun;i++){
            a = nextVal(a,M);
            tot_val += a;
        }
        }

        cout<<tot_val<<endl;
        return 0;
    }






    return 0;
}

Measured memory_bytes: 4020
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
using namespace std;
struct people
{
    string a;
    int b;
}m,n;
int main()
{
    string c;
    cin >> m.a >> n.a;
    cin >> m.b >> n.b;
    cin >> c;
    if(m.a == c)
        m.b--;
    else
        n.b--;
    cout << m.b << " " << n.b << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&an[0][0],n*m,0); typedef long long ll;*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}

void solve(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int t1 = a/d;
	if(a%d != 0)t1++;
	int t2 = c/b;
	if(c%b != 0)t2++;
	
	if(t2 <= t1)cout << "Yes" << endl;
	else cout << "No" << endl;
}

int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	FE(i,1,t)
		solve();
	return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  string s;
  cin >> s;

  int k = s.size();
  rep(i, 1, s.size()) {
    if(s[i] != s[i - 1]) {
      k = min(k, max(i, (int)s.size() - i));
    }
  }
  cout << k << endl;
}


Measured memory_bytes: 512
import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d, directed=False):
        """
        #0-indexedでなくてもよいことに注意
        #u = from, v = to, d = cost
        #directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.e[u].append([v, d])
            self.e[v].append([u, d])
        else:
            self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def Dijkstra_search(self, s):
        """
        #0-indexedでなくてもよいことに注意
        #:param s: 始点
        #:return: 始点から各点までの最短経路と最短経路を求めるのに必要なprev
        """
        d = collections.defaultdict(lambda: float('inf'))
        prev = collections.defaultdict(lambda: None)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    prev[uv] = u
                    heapq.heappush(q, (vd, uv))

        return d, prev

    def getDijkstraShortestPath(self, start, goal):
        _, prev = self.Dijkstra_search(start)
        shortestPath = []
        node = goal
        while node is not None:
            shortestPath.append(node)
            node = prev[node]
        return shortestPath[::-1]


N, M = map(int, input().split())
graph = Dijkstra()
for i in range(M):
    a, b, c = map(int, input().split())
    graph.add(a-1, b-1, c, directed=False)

usedPaths = collections.defaultdict(set)
for i in range(N):
    for j in range(i+1, N):
        path = graph.getDijkstraShortestPath(i, j)
        if len(path) == 2:
            usedPaths[path[0]].add(path[1])
            usedPaths[path[1]].add(path[0])
        else:
            for k, v in enumerate(path[:-1]):
                usedPaths[v].add(path[k + 1])
                usedPaths[path[k + 1]].add(v)

ans = M - sum([len(a) for a in list(usedPaths.values())])//2
print(ans)

Measured memory_bytes: 86492
#include<bits/stdc++.h>
using namespace std;
int main() {
	char r, g, b;
	cin >> r >> g >> b;
	string ans;
	ans[0] = r;
	ans[1] = g;
	ans[2] = b;
	int sum;
	sum = stoi(ans);
	if (sum % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main(){
    int n;
    while(cin>>n&&n!=0){
        set<int> schedules[101];
        for(int i = 0; i < n; i++){
            int t;
            cin>>t;
            for(int j = 0; j < t; j++){
                int p;
                cin>>p;
                schedules[i].insert(p);
            }
            //sort(schedules[i].begin(),schedules[i].end());
        }
        // ツつサツづェツつシツづェツつェツつ「ツづ慊づづ個地ツ図ツづーツ篠敖づづつ「ツづゥツつゥ
        set<int> having[101];
        for(int i = 0; i < n; i++)
            having[i].insert(i);
        int idx=31;
        for(int i = 1; i <= 30; i++){
            vector<int> v;
            set<int> s;
            for(int j = 0; j < n; j++){
                if(schedules[j].find(i)!=schedules[j].end()){
                    v.push_back(j);
                    for(set<int>::iterator it = having[j].begin(); it!=having[j].end(); it++)
                        s.insert(*it);
                }
            }
            if(s.size()==n){
                idx=i;
                break;
            }
            for(int j = 0; j < v.size(); j++)
                having[v[j]]=s;
        }
        if(idx==31)
            cout<<-1<<endl;
        else
            cout<<idx<<endl;
    }

    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007 
#define ff first
#define ss second
#define pb push_back  
#define INF 1000000000000
									//nestedcode






int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    ll fl = 0;
    cin>>s;
    if(s[0] == '7')	fl = 1;
    if(s[1] == '7')	fl = 1;
    if(s[2] == '7')	fl = 1;
    if(fl){
    	cout<<"Yes";
	}else{
		cout<<"No";
	}
}


Measured memory_bytes: 3652
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

int main(void) {
    int K;
    string S;
    cin >> K >> S;
    if (S.size() <= K) cout << S << endl;
    else cout << S.substr(0,K) << "..." << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
typedef long long ll;

ll n, ans, a[200005];
multiset<ll> st = {-1, -1};
int main() {
	ll i, t;
	multiset<ll>::iterator x, y, w, v;
	cin >> n;
	for(i=0; i<n; i++) scanf("%lld", &t), a[t] = i;
	st.insert(n);
	st.insert(n);
	for(i=n; i; i--) {
		x = st.lower_bound(a[i]);
		y = next(x);
		w = prev(x);
		v = prev(w);
		ans += i * ((*y-*x) * (a[i]-*w) + (*w-*v) * (*x-a[i]));
		st.insert(a[i]);
	}
	cout << ans;
	return 0;
}


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

int main(){
  int N; cin >> N;
  int T; cin >> T;
  int A; cin >> A;
  int a[1500] = {};
  for(int i = 1; i <= N; i++)cin>>a[i];

  int temp = abs((T*1000-a[1]*6)-A*1000);

  int index = 1;
  for(int i = 1; i <= N; i++){

    if(abs((T*1000-a[i]*6)-A*1000) <= temp){
      temp = abs((T*1000-a[i]*6)-A*1000);
      index = i;
    }
  }
  cout<<index<<endl;

}


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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int a,b,c,x,y;

signed main()
{
    cin>>a>>b>>c>>x>>y;

    if(x==0&&y==0){
        cout <<0<<endl;
        return 0;
    }

    if(y==0){
        cout << min(a*x,2*c*x)<<endl;
        return 0;
    
    }

    if(x==0){
        cout <<min(b*y,2*c*y)<<endl;
    }

    int ans=1e9;
    rep(i,100001){
        int temp = i*2*c+max(0,(signed)(x-i))*a+max(0,(signed)(y-i))*b;
        ans = min(ans,temp);
    }

    cout <<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL N = 3005;

LL ec = 0,hed[N] = {0},nxt[N << 1],to[N << 1];
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL dep[N],siz[N],l[N],r[N];
LL s[N],n; string t;
void dfs(LL u,LL f){
	LL sr = 0,id = 0;
	dep[u] = dep[f] + 1;
	if(s[u]) siz[u] = 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		siz[u] += siz[v];
	}
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		l[v] += siz[v]; r[v] += siz[v];
		sr += r[v];
		if(l[v] > l[id]) id = v;
	}
	l[u] = max(0LL,l[id] + r[id] - sr); r[u] = sr;
}

LL solve(LL x){
	LL sum = 0; dep[0] = -1;
	for(LL i = 1;i <= n;i ++) l[i] = r[i] = siz[i] = 0;
	dfs(x,0);
	for(LL i = 1;i <= n;i ++) if(s[i]) sum += dep[i];
	if(l[x] == 0 && sum % 2 == 0) return sum / 2;
	return INF;
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v,ans = INF;
	cin >> n;
	cin >> t; for(LL i = 0;i < n;i ++) s[i + 1] = t[i] - '0';
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v);
		add_edge(v,u);
	}
	for(LL i = 1;i <= n;i ++) ans = min(ans,solve(i));
	if(ans == INF) ans = -1;
	cout << ans << '\n';
	return 0;
}
//



Measured memory_bytes: 3924
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] commands = sc.next().toCharArray();
		int x = sc.nextInt();
		int y = sc.nextInt();
		HashSet<Integer> xIdxes = new HashSet<>();
		HashSet<Integer> yIdxes = new HashSet<>();
		xIdxes.add(0);
		yIdxes.add(0);
		boolean isFirst = true;
		boolean isHorisontal = true;
		int count = 0;
		for (char c : commands) {
		    if (c == 'F') {
		        count++;
		    } else {
		        if (isFirst) {
		            x -= count;
		            isFirst = false;
		        } else {
		            HashSet<Integer> next = new HashSet<>();
		            if (isHorisontal) {
		                for (int a : xIdxes) {
		                    next.add(a + count);
		                    next.add(a - count);
		                }
		                xIdxes = next;
		            } else {
		                for (int a : yIdxes) {
		                    next.add(a + count);
		                    next.add(a - count);
		                }
		                yIdxes = next;
		            }
		        }
		        count = 0;
		        isHorisontal ^= true;
		    }
		}
        if (isFirst) {
            x -= count;
        } else {
            HashSet<Integer> next = new HashSet<>();
            if (isHorisontal) {
                for (int a : xIdxes) {
                    next.add(a + count);
                    next.add(a - count);
                }
                xIdxes = next;
            } else {
                for (int a : yIdxes) {
                    next.add(a + count);
                    next.add(a - count);
                }
                yIdxes = next;
            }
        }
        if (xIdxes.contains(x) && yIdxes.contains(y)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 149996
N = int(input())
B = list(map(int, input().split()))
res = []
while 0 < len(B):
    index = None
    for i, b in enumerate(B, 1):
        if i == b:
            index = i
    if index is None:
        print(-1)
        exit()
    else:
        res.append(B[index-1])
    del B[index-1]
for x in res[::-1]:
    print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N;

int dis[555], used[555];

int d[555][555];

int check[555];

int INF = 9998;
void CALC(int K, int num) {
	
	used[K] = 1;

	for (int m = 1; m <= K-1; m++) {
		if (used[m] == 0 && d[K][m] == num) { dis[m] = dis[K] + 1; CALC(m, num); }
	}

}

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {

		for (int j = 1; j <= i; j++) {check[j] = 0; }

		int Q = 1;
		for (int j = i-1; j >=1; j--) {
			if (check[j] != 0) { continue; }

			d[i][j] = Q; d[j][i] = Q;  check[j] = 1;

			for (int k = 1; k <= i - 1; k++) { dis[k] = INF; used[k] = 0; }
			dis[i] = 0;
			CALC(i, Q);

			for (int k = 1; k <= j; k++) {
				if (dis[k] % 2 == 1) { check[k] = 1; d[i][k] = Q; d[k][i] = Q; }
			}

			Q++;
		}

	}

	for (int i = 1; i <= N - 1; i++) {
		for (int j = i+1; j <= N; j++) {
			if (j != i+1) { cout << " "; }
			cout << d[i][j];
		}cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main(){
  int a[5],tmp;
  for(int i=0;i<5;i++){
    cin >> a[i];
  }
  for(int i=0;i<5;i++){
    for(int j=0;j<4;j++){
      if(a[j] < a[j+1]){
	tmp = a[j];a[j] = a[j+1]; a[j+1] = tmp;
      }
    }
  }
    for(int i=0;i<4;i++){
      cout << a[i] << " ";
    }
    cout << a[4] << endl;
}
     
     

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

def peaks(n,m,h,ab):
    g = [0] * n
    path = [ [] for i in range(n)]
    #print(ab)
    for l,r in ab:
        path[l-1].append(r)
        path[r-1].append(l)

    #print(path)

    for i,p in enumerate(path):
        if p == []:
            g[i] = 1
            continue
        
        for j in p:
            #print(i+1,j,h[i],h[j-1])
            if h[i] > h[j-1]:
                g[i] = 1
            else:
                g[i] = 0
                break
    print(sum(g))

if __name__ == "__main__":
    n,m = map(int,input().split())
    h = list(map(int,input().split()))
    ab = [list(map(int,input().split())) for _ in range(m)]
    ab_sorted = sorted(ab)
    peaks(n,m,h,ab_sorted)


Measured memory_bytes: 43048
#include<iostream>
#include<cmath>

using namespace std;

#define MAX_VALUE 1000000

int get_numprime( int num );

int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		int result = get_numprime( num );
		cout << result << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はカウント済み

	bool erat[MAX_VALUE] = {0};

	for( int i = 0 ; i < num+1 ; i++ )
	{
		erat[i] = true;
	}
	erat[0] = false; erat[1] = false;
	for( int i = 2 ; i <= num ; i++ )
	{
		if( erat[i] )
		{
			for( int j = i*2 ; j <= num ; j+=i )
			{
				erat[j] = false;
			}
		}
	}
	for( int i = 3 ; i <= num ; i+=2 )
	{
		if( erat[i] ) numprime++;
	}

	if( num == 1 ) numprime = 0;

	return numprime;
}

Measured memory_bytes: 2140
N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
x = [0] * N
x1 = [0] * N
a1 = 0
for i in range(N):
    x[i] = sum(L[i])
x1 = sorted(x, reverse=True)
for i in range(M):
    a1 += x1[i]
#print(a1)

x2 = [0] * N
a2 = 0
for i in range(N):
    x[i] = L[i][0] + L[i][1] - L[i][2]
x2 = sorted(x, reverse=True)
for i in range(M):
    a2 += x2[i]
#print(a2)

x3 = [0] * N
a3 = 0
for i in range(N):
    x[i] = L[i][0] - L[i][1] + L[i][2]
x3 = sorted(x, reverse=True)
for i in range(M):
    a3 += x3[i]
#print(a3)

x4 = [0] * N
a4 = 0
for i in range(N):
    x[i] = L[i][0] - L[i][1] - L[i][2]
x4 = sorted(x, reverse=True)
for i in range(M):
    a4 += x4[i]
#print(a4)

x5 = [0] * N
a5 = 0
for i in range(N):
    x[i] = -L[i][0] + L[i][1] + L[i][2]
x5 = sorted(x, reverse=True)
for i in range(M):
    a5 += x5[i]
#print(a5)

x6 = [0] * N
a6 = 0
for i in range(N):
    x[i] = -L[i][0] + L[i][1] - L[i][2]
x6 = sorted(x, reverse=True)
for i in range(M):
    a6 += x6[i]
#print(a6)

x7 = [0] * N
a7 = 0
for i in range(N):
    x[i] = -L[i][0] - L[i][1] + L[i][2]
x7 = sorted(x, reverse=True)
for i in range(M):
    a7 += x7[i]
#print(a7)

x8 = [0] * N
a8 = 0
for i in range(N):
    x[i] = -L[i][0] - L[i][1] - L[i][2]
x8 = sorted(x, reverse=True)
for i in range(M):
    a8 += x8[i]
#print(a8)

print(max(a1, a2, a3, a4, a5, a6, a7, a8))
# 8通り試せばいいかな


Measured memory_bytes: 3700
<?php
fscanf(STDIN, '%d', $n);
$ans = 'No';
for ($i = 1; $i < 10; $i++) {
    for ($j = 1; $j < 10; $j++) {
        if ($i * $j === $n) $ans = 'Yes';
    }
}
echo $ans.PHP_EOL;

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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define pi acos(-1.0)
#define eps 1e-9
#define all(v) v.begin(),v.end()

#define MAX 400005

double ang;

pair<double,double> newXY(pair<double, double> oldp, ll mul)
{
    double oti = 1;
    double lomb = oti*sin(ang*mul);
    double vumi = lomb/tan(ang*mul);

    // cout << lomb << " " << vumi << " " << endl;

    return {oldp.xx - vumi, oldp.yy+lomb-vumi };
}

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

    cin >> ang;

    ang*=pi;
    ang/=180.0;

    pair<double,double> nowp(0,0);

    ll ans =0 ;
    for(int i=1;i<=400;i++)
    {
        nowp = newXY(nowp,i);
        ans++;

        // cout << setprecision(5) << fixed << nowp.xx << " " << nowp.yy << endl;

        if(fabs(nowp.xx - (double)0) < eps && fabs(nowp.yy - (double)0) <eps) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	vector<int> rope_array;
	int N,L;
	cin>>N;
	cin>>L;
	rope_array.resize(N);
	REP(i,N){
		cin>>rope_array[i];
	}
	
	bool is_possible = false;
	int last_rope_index;
	for(int i = 1; i < N;i++){
		int last_rope = rope_array[i] + rope_array[i - 1];
		// cout<<last_rope<<endl;
			if(last_rope >= L){
				is_possible = true;
				last_rope_index = i;
				break;
			}
	}
	// cout<<"last: "<<last_rope_index<<endl;

	if(is_possible){
		cout<<"Possible"<<endl;	
		for(int i = 1;i < last_rope_index;i++){
			cout<<i<<endl;
		}
		for(int i = N-1; i > last_rope_index;i--){
			cout<<i<<endl;
		}
		cout<<last_rope_index<<endl;
	}
	else{
		cout<<"Impossible"<<endl;
	}
	

	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll res=n/(a+b);
    res*=a;
    res+=min(a,n%(a+b));
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256