akhauriyash/Code-Regression huggingface dataset:
# Problem D - Teleporter

# input
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

# initialization
visit_list = [0] * N
pos = a_list[0]
visit_list[pos-1] = 1
visit_count = 1
remain = K - 1
is_ok = True
ans = 0

# count
while remain>0 and is_ok:
    pos = a_list[pos-1]
    remain -= 1
    visit_count += 1
    if pos==1 or not visit_list[pos-1]==0:
        tmp_1 = visit_count - visit_list[pos-1]
        tmp_2 = remain % tmp_1
        for t in range(tmp_2):
            pos = a_list[pos-1]
        is_ok = False
        break
    else:
        visit_list[pos-1] = visit_count

# output
print(pos)


Measured memory_bytes: 32376
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n, x;
        cin >> n >> x;
        if(n==0 && x==0) break;
        int count=0;
        for(int i=1; i<=n; i++){
            for(int j=1; i>j; j++){
                for(int k=1; j>k; k++){
                    if(i+j+k==x) count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n, m;
    cin >> n >> m;
    ll a[n];
    std::vector<ll> v;
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        v.push_back(a[i]);
        sum += a[i];
    }
    Sort_rev(v);
    // ll all = accumulate(ALL(v), 0LL);
    ll ans = 0;
    rep(i, n) {
        if ( v[i]*4*m >= sum ) {
            ans++;
        } else {
            break;
        }
    }
    if ( ans >= m ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
	N, M = [int(x) for x in input().split(" ")]
	A = [int(a) for a in input().split(" ")]
	A.sort()
	overwrite = []
	for i in range(M):
		B, C = [int(x) for x in input().split(" ")]
		overwrite.append({
			"count": B,
			"number": C
		})
	overwrite.sort(key=lambda o: -o["number"])
	j = 0
	k = 0
	flag = False
	while not flag and j < len(A) and k < len(overwrite):
		o = overwrite[k]
		for m in range(o["count"]):
			if j < len(A) and A[j] <= o["number"]:
				A[j] = o["number"]
				j += 1
			else:
				flag = True
		k += 1

	print(sum(A))

main()


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


#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 100005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long 

#define mod  1000000007



int main()
{
	FAST;
	int n;
	cin >> n;
	if(n == 5 || n == 3 || n == 7){
		cout << "YES"; return 0;
	}
	cout << "NO";
	return 0;
	
}

Measured memory_bytes: 3556
#include <stdio.h>

int N, T;
int A[4096], B[4096];

/*
「最後の料理を食べるのはT-0.5分を過ぎてもいい」→「タダ券が1枚ある」と考える (川柳)
*/

int memo[4096][4096][2];

int horieyui(int pos, int time_left, int ticket) {
	int asumikana, hanazawakana;
	if (pos >= N) return 0;
	if (memo[pos][time_left][ticket]) return ~memo[pos][time_left][ticket];

	/* 食べない */
	asumikana = horieyui(pos + 1, time_left, ticket);
	/* 普通に食べる */
	if (time_left >= A[pos]) {
		hanazawakana = horieyui(pos + 1, time_left - A[pos], ticket) + B[pos];
		if (hanazawakana > asumikana) asumikana = hanazawakana;
	}
	/* タダ券を使って食べる */
	if (ticket > 0) {
		hanazawakana = horieyui(pos + 1, time_left, ticket - 1) + B[pos];
		if (hanazawakana > asumikana) asumikana = hanazawakana;
	}

	return ~(memo[pos][time_left][ticket] = ~asumikana);
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &T) != 2) return 1;
	if (N < 0 || (int)(sizeof(A) / sizeof(*A)) < N) {
		puts("danger!");
		return 2;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%d%d", &A[i], &B[i]) != 2) return 1;
	}
	printf("%d\n", horieyui(0, T - 1, 1));
	return 0;
}


Measured memory_bytes: 96000
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.LoopSimulation
{
    class ABC_065_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] array = new int[n];
            bool[] gone = new bool[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
                gone[i] = false;
            }

            int pushCnt = 0;
            int now = 0;
            while (gone[1] == false)
            {
                now = array[now] - 1;
                if (gone[now] == true)
                {
                    Console.WriteLine(-1);
                    return;
                }
                pushCnt++;
                gone[now] = true;
            }

            Console.WriteLine(pushCnt);
        }
    }
}

Measured memory_bytes: 15200
#include <iostream>
using namespace std;
int main(void){
    int x;
    for(int i=1; i<=10000; i++){
    cin>>x;
    if( x!=0){
        cout << "Case " << i << ": " << x <<endl;
    }
    else{
        break;
    }
    
}
        return 0;
    }



Measured memory_bytes: 2976
l = list(map(int, input().split()))
l.sort()
a = l[1]-l[0]
b = l[2]-l[0]
k = 0
if a%2 == 1 and b%2 ==1:
  a,b = a+1,b+1
  k = 1
elif a%2 == 1:
  a = a-1
  k = 1
elif b%2 == 1:
  b = b-1
  k = 1
print((b+(b-a))//2+k)

Measured memory_bytes: 3064
N, L = map(int, input().split())

a = [L + int(x) for x in range(N)]
for i in range(len(a)):
    if a[i] < 0:
        if i == len(a)-1:
            a.pop(i)
    else:
        a.pop(i)
        break
print(sum(a))

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

int main() {
  char x;
  cin >> x;
  
  if (x >= 'A' && x <= 'Z'){
   cout << 'A' << endl;
  }
  else if (x >= 'a' && x <= 'z'){
   cout << 'a' << endl;
  }
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, M;
	while (cin >> N >> M && N+M) {
		using T = tuple<int64, int64, int64>;
		bool infected[20020] = {};
		int64 res = 1;
		infected[0] = 1;
		vector<T> v;
		REP(i, M) {
			int64 a, b, c;
			cin >> a >> b >> c; b--; c--;
			v.push_back(T(a, b, c));
		}
		sort(all(v));
		REP(i, M) {
			int64 a, b, c;
			tie(a, b, c) = v[i];
			if (infected[b] && !infected[c]) {
				res++;
				infected[c] = 1;
			}
		}
		cout << res << endl;
	}
}



Measured memory_bytes: 4092
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
//#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dist[7][7]={
    {},
    {6},
    {13, 7},
    {18, 12, 5},
    {23, 17, 10, 5},
    {43, 37, 30, 25, 20},
    {58, 52, 45, 40, 35, 15}
};
int cost[7][7]{
    {0, 300, 500, 600, 700, 1350, 1650},
    {0, 0,350, 450, 600, 1150, 1500},
    {0, 0, 0,250, 400, 1000, 1350},
    {0, 0, 0,0,250, 850, 1300},
    {0,0,0,0,0,600, 1150},
    {0,0,0,0,0,0,500},
    {}
};

int main(){
    int a, b;
    int s, t;
    int h, m;
    while(cin>>a && a){
        cin>>h>>m;
        s = h * 60 + m;
        cin>>b>>h>>m;
        t = h *60 + m;

        a--; b--;
        if(a> b) swap(a, b);
        bool f = true;
        if(dist[b][a] > 40) f=false;
        if(f&&((s>=17*60+30&&s<=19*60+30)||(t>=17*60+30&&t<=19*60+30))){
            int ans = cost[a][b];

            cout<<(cost[a][b]/100)/2*100+(cost[a][b]%100==50?50:0)+((cost[a][b]/100)%2==1?50:0)<<endl;
        }
        else{
            cout<<cost[a][b]<<endl;
        }
        //cout<<a<<" "<<b<<endl;
    }
}

Measured memory_bytes: 1160
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

const int max_n = 50;
int n, m, a[max_n], b[max_n];
bool g[max_n][max_n];
bool seen[max_n];

void dfs(int now) {
    seen[now] = true;
    rep(i, n) {
        if (!g[now][i]) continue;
        if (seen[i]) continue;
        dfs(i);
    }
}

void solve() {
    int ans = 0;
    rep(i, m) {
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        fill(seen, seen + n, false);
        dfs(0);

        rep(j, n) {
            if (!seen[j]) {
                ans++;
                break;
            }
        }

        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << ans << endl;
}

int main() {
    cin >> n >> m;
    fill(g[0], g[n], false);
    rep(i, m) {
        int ta, tb;
        cin >> ta >> tb;
        ta--, tb--;
        a[i] = ta, b[i] = tb;
        g[ta][tb] = g[tb][ta] = true;
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        if (n == 1){
            System.out.println("Hello World");
        }else{
            System.out.println(Integer.parseInt(input.readLine()) +  Integer.parseInt(input.readLine()));
        }
    }
}


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

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

ll N,K;
ll A[100005];

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

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

    cin >> N >> K;
    for (int i = 0;i < N;i++){
        cin >> A[i];
    }

    Mod m(1e9+7);
    ll mod = 1e9+7;

    sort(A,A+N);
    ll ans = 0;

    ll tmp = m.comb(N-1,K-1);
    //vector<ll> lis;

    for (int i = N-1;i >= K-1;i--){
        //lis.push_back(tmp);
        ans += (A[i]*tmp)%mod;
        ans %= mod;
        tmp = (tmp*m.modpow(i,mod-2))%mod;
        tmp *= i-(K-1);
        tmp %= mod;
    }

    tmp = m.comb(N-1,K-1);

    for (int i = 0;i <= N-K;i++){
        ans += mod;
        ans -= (A[i]*tmp)%mod;
        ans %= mod;
        tmp = (tmp*m.modpow(N-i-1,mod-2))%mod;
        tmp *= (N-i-1)-(K-1);
        tmp %= mod;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


int costmin(int n,int h[][3]){
	int dp[n+1][3];
	dp[0][0]=0;dp[0][1]=0;dp[0][2]=0;
	for (int i = 0; i < n; ++i){
		dp[i+1][0] = max(dp[i][1] + h[i][0], dp[i][2] + h[i][0]);
	    dp[i+1][1] = max(dp[i][0] +  h[i][1], dp[i][2] +  h[i][1]);
	    dp[i+1][2] = max(dp[i][0] +  h[i][2], dp[i][1] +  h[i][2]);
	}

   return max({dp[n][0],dp[n][1],dp[n][2]});
}


int main(){
	fastio();
	int n;cin>>n;
	int a[n][3];
	for (int i = 0; i < n; ++i){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	int ans=costmin(n,a);
	cout<<ans<<endl;







    return 0;
	
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderD
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();
        int n = s.Length;

        int[] modSum = new int[n + 1];
        int tenMod = 1;
        for (int i = n - 1; i >= 0; i--)
        {
            int num = int.Parse(s[i].ToString());
            modSum[i] = (num * tenMod + modSum[i + 1]) % 2019;
            tenMod = (tenMod * 10) % 2019;
        }

        long answer = 0;
        int[] counts = new int[2019];
        for (int i = 0; i <= n; i++)
        {
            answer += counts[modSum[i]];
            counts[modSum[i]]++;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 33712
n = int(input()) 
l = list(map(int, input().split()))
if l[0] != 0:
    print(0)
    exit()

for i in range(1, n):
    if l[i] == 0:
        print(0)
        exit()

max_vertex = max(l)
ll = []
l=sorted(l)
l.append(-4)
c=1
for i in range(1, n):
    if l[i] != l[i+1]:
        if l[i] != l[i+1]-1 and l[i+1] > 0:
            print(0)
            exit()
        ll.append(c)
        c = 0
    c+=1

count = 1
for i in range(1, max_vertex):
    tmp = ll[i-1]
    count *= pow(tmp, ll[i])
print(count%998244353)


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n;
    double ans;
    cin >> n;
    vector<double> v(n);
    rep0(i, n)cin >> v[i];
    sort(all(v));
    ans = v[0];
    rep1(i, n){
        ans = (ans + v[i]) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int sum=0;
char zt;
int main(){
	cin>>s;
	zt=s[0];
	for(int i=1;i<s.size();i++){
		if(s[i]=='B'){
			if(zt=='W'){
				sum++;
				zt='B';}}
		else if(s[i]=='W'){
		    if(zt=='B'){
		    	sum++;
//cout<<sum<<endl;
		    	zt='W';}}}
	cout<<sum;
	return 0;	    	
	//return(printf("%.d",sum))&0;	    	
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n,m,A[15],B[101];

int mem[101][1<<15],used[101][1<<15];
int dfs(int idx,int sta,int sum){
  if(idx==m) return 0;
  if(used[idx][sta]++)return mem[idx][sta];
  int &res=mem[idx][sta]=abs(sum-B[idx])+dfs(idx+1,sta,sum);
  for(int i=0;i<n;i++)
    if((sta>>i)&1)res=min(res,dfs(idx,~((~sta)|(1<<i)),sum-A[i]));
  return res;
}

int main(){
  while(1){
  cin>>n>>m;
  if(!n&&!m)break;
  int sum=0;
  for(int i=0;i<n;i++) scanf("%d",&A[i]),sum+=A[i];
  for(int i=0;i<m;i++) scanf("%d",&B[i]);
  sort(B,B+m,greater<int>());
  memset(used,0,sizeof(used));
  cout<<dfs(0,(1<<n)-1,sum)<<endl;
  }
  return 0;
}

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

int main(){
 int a,b,c;
  cin >> a >> b >> c;
  
  int payByTimes = a * b;
  if( payByTimes < c) {
  	cout << payByTimes << endl;
  } else {
    cout << c << endl; 
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-9
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

string s;

int solve(char c) {
	int ans = 0;
	string ss = s;
	while (1) {
		bool flag = false;
		for (char cc: ss) if (cc != c) flag = true;
		if (!flag) return ans;
		string tmp = "";
		ans++;
		REP (i, ss.size() - 1) {
			if (ss[i] == c || ss[i + 1] == c) tmp += c;
			else tmp += ss[i];
		}
		ss = tmp;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> s;
	int ans = s.size() - 1;
	// BUG(solve('a')); return 0;
	REP (i, 26) ans = min(ans, solve('a' + i));
	cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int A[3];
    for (int i=0; i<3; ++i)
        scanf("%d", &A[i]);

    sort(A, A+3);

    printf("%s\n", (A[0]==5&&A[1]==5&&A[2]==7)? "YES":"NO");
    return 0;
}


Measured memory_bytes: 128
/******************************************
/@Author: LeafBelief
/@Date: 2020-04-04
/@Remark:    
/@FileName: numbertheory
******************************************/
#include <bits/stdc++.h>
#define CSE(x,y) memset(x,y,sizeof(x))
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn = 111111;

int main()
{
    FAST;
    ll n, k;
    while(cin >> n >> k)
    {
        n %= k;
        cout << min(n, abs(n - k)) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define SIZE 100
int stack[SIZE];
int n=0;

void push(int x){
    stack[n]=x;
    n++;
}
int pop(){
    n--;
    return stack[n];
}

int main(void){
    char c[1000000];
    int x,a,b;
    
    while(scanf("%s",c)!=EOF){
      if(isdigit(c[0])){
          x=atoi(c);
          push(x);
      }else if(c[0]=='+'){
          push(pop()+pop());
      }else if(c[0]=='-'){
          b=pop();
          a=pop();
          push(a-b);
      }else if(c[0]=='*'){
          push(pop()*pop());
      }
    }
    printf("%d\n",pop());
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    vector <int> as;
    int a;
    REP(i, n){
        cin >> a;
        as.push_back(a);
    }
    vector <int> as_sorted = as; sort(as_sorted.begin(), as_sorted.end());
    int max_a = as_sorted[n-1];
    int second_max_a = as_sorted[n-2];
    REP(i, n){
        if (as[i] == max_a){
            cout << second_max_a << endl;
        } else {
            cout << max_a << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3316
n = int(input())
a = map(int, input().split())
ok=True
for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            pass
        else:
            ok = False
if ok:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940
def solve():
    H, W = map(int, input().split())
    if H == 0:
        return False
    MP = [input() for i in range(H)]
    C = [[0]*W for i in range(H)]
    for j in range(W):
        cnt = 0
        for i in range(H-1, -1, -1):
            if MP[i][j] == '.':
                cnt += 1
            else:
                cnt = 0
            C[i][j] = cnt
    ans = 0
    for i in range(H):
        st = [(0, -1)]
        for j in range(W):
            e = C[i][j]
            last = j
            while st and e <= st[-1][0]:
                f, k = st.pop()
                ans = max(ans, (j - k) * f)
                last = k
            st.append((e, last))
        while st:
            f, k = st.pop()
            ans = max(ans, (W - k) * f)
    print(ans)
    return True
while solve():
    ...



Measured memory_bytes: 7956
#include <bits/stdc++.h>
using namespace std;
int n, m, d;
int a[305][305];
int sum[305 * 305];
int x[305 * 305], y[305 * 305];
int main() {
	scanf("%d%d%d", &n, &m, &d);
	for (int i = 0; i < n; ++ i) {
		for (int j = 0; j < m; ++ j) {
			scanf("%d", &a[i][j]);
			x[a[i][j]] = i;
			y[a[i][j]] = j;
		}
	}
	for (int i = d; i <= n * m; ++ i) {
		sum[i] = sum[i - d] + abs(x[i] - x[i - d]) + abs(y[i] - y[i - d]);
	}
	int q;
	scanf("%d", &q);
	while (q --) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", sum[r] - sum[l]);
	}
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
#define int long long

int32_t main()
{
    double w,h,x,y;cin>>w>>h>>x>>y;
    int flag=0;
    if(w/2==x&&h/2==y)flag=1;
    printf("%f %d",(w*h)/2,flag);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
	public static void main(String[] args) throws IOException, Exception{
		BufferedReader st = new BufferedReader(new InputStreamReader(System.in));
		int[] data = getIntArry(st);
		int m = data[0];
		int t = data[1];
		int cnt = 1;
		int t2 = m;
		while(t2 < t) {
			t2+=(m - 1);
			cnt++;
		}
		if (t == 1) {
			cnt = 0;
		}
		anser(cnt);
	}
 
	private static int[] getIntArry(BufferedReader st) throws Exception, IOException {
		String line = st.readLine();
		String[] strData = line.split(" ");
		int[] intData = new int[strData.length];
		for (int i = 0; i < strData.length; i++) {
			intData[i] = Integer.parseInt(strData[i]);
		}
		return intData;
	}
 
	private static void anser(int num) {
		System.out.println(num);
	}
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int p[] = {14, 2,3,4,5,6,7,8,9,10, 11, 12, 13};

  if (p[a-1] - p[b-1] > 0)
    cout << "Alice" << endl;
  else if (p[b-1] - p[a-1] > 0)
    cout << "Bob" << endl;
  else 
    cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	double T, X;
	cin >> T >> X;
	printf("%.15lf\n", T / X);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,N) for(i=0;i<N;i++)
#define split 1000000007
#define W_MAX 8
int H,W,K;
ll n_s[W_MAX+1][3];
vector<int> fib;

int fibonacci(int n){
  if(fib[n] != 0) return fib[n];
  return fib[n] = fibonacci(n-1) + fibonacci(n-2);
}

ll n_sit(int n,int l){
  ll ret=1;
  if(n_s[n][l] > 0) return n_s[n][l];
  if(l==0){
    if(n!=1)ret *= fib[n-2];
    return n_s[n][l] = ret*fib[W-n];
  }else if(l==1){
    return n_s[n][l] = fib[n-1]*fib[W-n];
  }else{
    if(n!=W)ret *= fib[W-n-1];
    return n_s[n][l] = fib[n-1]*ret;
  }
}

int main(void){
  cin >> H >> W >> K;
  int i,j,k;
  ll dp[H+1][W+1];
  fib.resize(W+1);
  fill(fib.begin(),fib.end(),0);
  fib[0] = 1;
  fib[1] = 1;
  fib[W] = fibonacci(W);

  REP(i,H+1)REP(j,W+1) dp[i][j] = 0;
  dp[0][1] = 1;
  REP(i,W_MAX+1)REP(j,3)n_s[i][j]=0;

  REP(i,H){
    REP(j,W+1){
      if(j==0) continue;
      REP(k,3){
        dp[i+1][j] += n_sit(j,k)*dp[i][j-1+k]%split;
      }
      dp[i+1][j] %= split;
    }
  }
//  REP(i,W_MAX+1) cout << n_s[i][0] << " " << n_s[i][1] << " " << n_s[i][2] << endl;
  cout << dp[H][K] << endl;
  return 0;
}

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

using namespace std;

const int maxN = 1e5 + 10;

int n;
int a[maxN], cnt[maxN], basis[maxN];

void add(int mask){
    for(int i = 60; i >= 0; --i){
        if(mask >> i & 1){
            if(!basis[i]){
                basis[i] = mask;
                return;
            }
            else
                mask ^= basis[i];
        }
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n;

    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    int res = 0;
    for(int i = 60; i >= 0; --i){
        int cnt = 0;
        for(int j = 1; j <= n; ++j)
            if(a[j] >> i & 1) ++cnt;
        if(cnt & 1){
            for(int j = 1; j <= n; ++j)
                if(a[j] >> i & 1)
                    a[j] -= (1LL << i);
            res += 1LL << i;
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i)
        add(a[i]);

    for(int i = 60; i >= 0; --i){
        if(!basis[i]) continue;
        if(ans >> i & 1) continue;
        ans ^= basis[i];
    }

    cout << ans * 2 + res << endl;
}


Measured memory_bytes: 4396
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    #print(h[a],h[b])
    if h[a] > h[b]:
        ans[b] = 0
    elif h[b] > h[a]:
        ans[a] = 0
    else:
        ans[a],ans[b] = 0,0

#print(ans)
print(ans.count(1))


Measured memory_bytes: 85100
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

const long long INF = 1LL << 60;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(a==b && a!=c){
        cout << "Yes" << endl;
    }
    else if(c==b && a!=c){
        cout << "Yes" << endl;
    }
    else if(a==c && b!=c){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,X = map(int,input().split())
m = [int(input()) for i in range(N)]
m_min = min(m)
count = len(m)
X = X - sum(m)
while X > 0:
    X = X - m_min
    count = count + 1
if X < 0:
    count = count - 1
print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int n;
	cin >> n;
	vector<double> a(n);
	double sum = 0.0;
	rep(i, n)
	{
		cin >> a[i];
		sum += 1.0 / a[i];
	}

	cout << setprecision(20) << 1.0 / sum << endl;

}

Measured memory_bytes: 256
n = int(input())

if n == 2:
  count = 1
else:
  count = 2
divisor = []

d = 2
while d * d < n - 1:
  if (n - 1) % d == 0:
    count += 2
  d += 1
if d * d == n - 1:
  count += 1

d = 2
while d * d < n:
  if n % d == 0:
    divisor.append(d)
    divisor.append(n // d)
  d += 1
if d * d == n:
  divisor.append(d)

for d in divisor:
  tmp = n
  while tmp % d == 0:
    tmp //= d
  if tmp % d == 1:
    count += 1

print(count)

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

#define REP(i,a,b) for (int i = a; i <= b; i++)
using namespace std;

struct UnionFind
{
    vector<int> r;

    UnionFind(int n)
    {
        r = vector<int>(n, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }
};


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

    UnionFind UF(N);

    REP(i,1,M)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, UF.size(i));
    }

    cout << ans << "\n";
}

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

using ll = long long;
using ld = long double;

int main()
{
    int n,ans=1000000007;
    cin >> n;
    
    
    for(int i = 0; i < n; i++)
    {
        int x,tmp=0;
        cin >> x;
        while(x%2==0)
        {
            x/=2;
            tmp++;
        }
        ans=min(ans,tmp);
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
	int H, A;
	scanf ("%d %d", &H, &A);
	if (H % A == 0)
	{
		printf ("%d", H/A);
	}
	else
	{
		printf ("%d", H/A + 1);
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void warshall_floyd(Graph &graph) {
    int V = graph.size();
    for (int k = 0; k < V; ++k) {
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
}

void Main() {
    ll N, M, L;
    cin >> N >> M >> L;
    Graph graph(N, vector<ll>(N, INF));
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a][b] = c;
        graph[b][a] = c;
    }
    int Q;
    cin >> Q;
    vector<P> query(Q);
    rep(q, Q) cin >> query[q].first >> query[q].second;

    warshall_floyd(graph);

    Graph graph2(N, vector<ll>(N, INF));
    rep(i, N) {
        rep(j, N) {
            if (i == j) continue;
            if (graph[i][j] <= L) {
                graph2[i][j] = 1;
                graph2[j][i] = 1;
            }
        }
    }
    warshall_floyd(graph2);
    rep(q, Q) {
        P p = query[q];
        ll ans = graph2[p.first - 1][p.second - 1];
        if (ans != INF) {
            cout << ans - 1 << '\n';
        } else {
            cout << -1 << '\n';
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

//========================================================================//

int main() {
	cout << setprecision(12);
	double a, b, x; cin >> a >> b >> x;
	double ans = atan(2 * (a * a * b - x) / pow(a, 3));
	if (a * tan(ans) <= b) {
		cout << ans * 180 / M_PI << endl;
	}
	else {
		ans = atan(a * b * b / (2 * x));
		cout << ans * 180 / M_PI << endl;
	}

}

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

int main(){

	const std::string correct_word = "Hoshina";
	const std::string find_word = "Hoshino";
	
	int N;
	std::cin >> N;
	std::cin.ignore();

	for(int i = 0; i < N; ++i){
	
		std::string str;
		std::getline(std::cin,str);

		std::string::size_type pos = str.find(find_word); //find place of "Hoshino"
		
		while(pos != std::string::npos){
			str.replace(pos, find_word.length(), correct_word); //replace
			pos = str.find(find_word, pos + find_word.length()); //find place of "Hoshino"
		}
	
		std::cout << str << std::endl;
	
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<c-(d-b)<<" "<<d-(a-c)<<" "<<a-(d-b)<<" "<<b-(a-c)<<endl;
}












Measured memory_bytes: 256
n = gets.to_i
sArr = gets.chomp.split(' ').map(&:to_i)
q = gets.to_i
tArr = gets.chomp.split(' ').map(&:to_i)

ans = 0
tArr.each do |t|
    arr = sArr.dup
    while true do
        a = arr[arr.size / 2]
        if t == a then
            ans += 1
            break
        elsif t > a then
            if arr.size == 1 then
                break
            else
                arr = arr[arr.size / 2, arr.size]
            end
        else
            if arr.size == 1 then
                break
            else
                arr = arr[0, arr.size / 2]
            end
        end
    end
end

puts ans


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//実行部
void Main()
{
  ll a, b, c; cin >> a >> b >> c;
  fin(c > a + b?"No":"Yes")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))
ans = 0 
for i in range(n):
  #左を全力で倒す
  left = min([enemy[i], beat[i]])
  ans += left
  beat[i] -= left
  
  right = min([enemy[i+1], beat[i]])
  ans += right
  enemy[i + 1] -= right
  beat[i] -= right
  
print(ans)


Measured memory_bytes: 19156
#include <iostream>
#include <vector>
using namespace std;
int main() {
        int n,x,bounces = 0;
        cin >> n >> x;
        vector<int> l(n);
        vector<int> d(n + 1);
        for (int i = 0; i < n; i++)
                cin >> l[i];
        d[0] = 0;
        for (int i = 1; i < n + 1; i++)
                d[i] = d[i - 1] + l[i - 1]; 
        for (int i = 0; i < n + 1; i++)
                if (d[i] <= x)
                        bounces++;
        cout << bounces << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		Double d = scan.nextDouble();
		int count = 0;
		while (t-- > 0) {
			Double a = scan.nextDouble();
			Double b = scan.nextDouble();
			Double dis = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
			if (dis <= d) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 63728
n,e,t=map(int,input().split())
a,f,l,c=[0]+list(map(int,input().split())),[0]*(n+1),1,int(1e18)
for i in range(1,n+1):
	while 2*(a[i]-a[l])>=t:
		c=min(c,f[l-1]-2*a[l])
		l+=1
	f[i]=min(f[l-1]+t,c+2*a[i])
print(f[n]+e)

Measured memory_bytes: 64408
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int maxn=100007;
int a[maxn];
int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int x=a[1];
	for(int i=2;i<=n;i++){
		x=gcd(x,a[i]);
	}
	cout<<x;
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace _0009 {

	public static class Program {

		public static void Main() {
			var cache = new Dictionary<int, bool>();

			string input;
			while (!string.IsNullOrEmpty(input = Console.ReadLine())) {
				var x = int.Parse(input);
				var count = 0;
				if (x < 2) {
					count = 0;
				} else {
					count = 1;

					for (int i = 3; i <= x; i += 2) {
						bool prime;
						if (cache.ContainsKey(i)) {
							prime = cache[i];
						} else {
							prime = true;
							for (int j = 3; j <= Math.Sqrt(i); j += 2) {
								if (i % j == 0) {
									prime = false;
									break;
								}
							}

							cache.Add(i, prime);
						}

						if (prime) {
							count++;
						}
					}
				}

				Console.WriteLine(count);
			}
		}

		//private static bool IsPrime(int x) {
		//	if (x == 2) {
		//		return true;
		//	}
		//	if (x < 2 || x % 2 == 0) {
		//		return false;
		//	}

		//	for (int i = 3; i <= Math.Sqrt(x); i += 2) {
		//		if (x % i == 0) {
		//			return false;
		//		}
		//	}

		//	return true;
		//}

	}

}

Measured memory_bytes: 29992
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    scanf("%d",&n);
    int mx = INT_MIN,counter =0;
    while(n--){
        int temp;
        scanf("%d",&temp);
        if(mx<=temp){
            mx = temp;
            counter++;
        }
    }
    printf("%d\n",counter);
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using T=tuple<int,int,int,int>;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int w,h;
    cin>>w>>h;
    while(w+h>0){
        vector<T> wall(0);
        int x;
        rep(i,2*h-1)rep(j,w){
            if(i%2==0&&j==0) continue;
            cin>>x;
            if(x==0) continue;
            if(i%2==0){
                wall.emplace_back(i/2,j-1,i/2,j);
                wall.emplace_back(i/2,j,i/2,j-1);
            }
            else{
                wall.emplace_back(i/2,j,i/2+1,j);
                wall.emplace_back(i/2+1,j,i/2,j);
            }
        }
        sort(all(wall));
        queue<P> b;
        b.emplace(0,0);
        int y;
        vector<vector<int>> d(h,vector<int>(w,0));
        d[0][0]=1;
        while(!b.empty()){
            tie(y,x)=b.front();
            b.pop();
            rep(i,4){
                int nx=x+dx[i],ny=y+dy[i];
                if(nx<0||ny<0||nx>=w||ny>=h||d[ny][nx]!=0) continue;
                if(lower_bound(all(wall),T(y,x,ny,nx))!=upper_bound(all(wall),T(y,x,ny,nx))) continue;
                d[ny][nx]=d[y][x]+1;
                b.emplace(ny,nx);
            }
        }
        cout<<d[h-1][w-1]<<'\n';
        cin>>w>>h;
    }
}


Measured memory_bytes: 3256