akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ABC047
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int W = int.Parse(input[0]);
            int H = int.Parse(input[1]);
            int N = int.Parse(input[2]);

            int x0 = 0;
            int y0 = 0;
            int x1 = W;
            int y1 = H;

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine().Split();
                int x = int.Parse(input[0]);
                int y = int.Parse(input[1]);
                int a = int.Parse(input[2]);

                if (a == 1)
                {
                    x0 = Math.Max(x0, x);
                }

                if (a == 2)
                {
                    x1 = Math.Min(x1, x); ;
                }

                if (a == 3)
                {
                    y0 = Math.Max(y0, y);
                }

                if (a == 4)
                {
                    y1 = Math.Min(y1, y);
                }
            }

            if ((x1 - x0) < 0 || (y1 - y0) < 0) Console.WriteLine(0);
            else Console.WriteLine((x1 - x0) * (y1 - y0));
        }
    }
}


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

	public static void main(String[] args) throws Exception{
		long num = 1000000007;
		long[] fact = new long[2001];
 		fact[0] = 1;
 		long ans1 = 1;
 		for(int i = 1;i<=2000;i++){
 			ans1= (ans1*i) % num;
 			fact[i] = ans1;
 		}
 		long[] inv = new long[2001];
 		inv[0] = 1;
 		for(int i = 1;i<=2000;i++){
 			inv[i] = power(fact[i], num-2, num)%num;
 		}
		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int s = Integer.parseInt(bf.readLine());
 		long sum = 0;
 		if (s >= 3)
 			sum = 1;
 		int count = 1;
 		for(int j = 5;j<=s;j+=2){
 			if (s-j >= count){
 				long prod = 1;
 				prod*=fact[s-j];
 				prod%=num;
 				prod*=inv[count];
 				prod%=num;
 				prod*=inv[s-j-count];
 				prod%=num;
 				sum+=prod;
 				sum%=num;
 			}
 			count++;
 		}
 		
 		
 		out.println(sum);
	 		
 		out.close();
 		
 		
 		
 	}
	public static int power(long x, long y, long mod){
		long ans = 1;
		while(y>0){
			if (y%2==1)
				ans = (ans*x)%mod;
			x = (x*x)%mod;
			y/=2;
		}
		return (int)(ans);
	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
  int n;
  cin >> n;
   vector<ll> t(n);
   ll ans = 1;
   rep(i,n) cin >> t.at(i);

   rep(i,n){
     ans = lcm(t.at(i),ans);
   }
   cout << ans << endl;
}

Measured memory_bytes: 3600
S = input()
T = input()
LS = [[0, 0] for _ in range(len(S) + 1)]
LT = [[0, 0] for _ in range(len(S) + 1)]
for i, s in enumerate(S):
  LS[i + 1] = list(LS[i])
  if s == 'A': LS[i + 1][0] += 1
  if s == 'B': LS[i + 1][1] += 1
for i, t in enumerate(T):
  LT[i + 1] = list(LT[i])
  if t == 'A': LT[i + 1][0] += 1
  if t == 'B': LT[i + 1][1] += 1
q = int(input())
for _ in range(q):
  a, b, c, d = map(int, input().split())
  sa = (LS[b][0] - LS[a - 1][0]) % 3
  sb = (LS[b][1] - LS[a - 1][1]) % 3
  ta = (LT[d][0] - LT[c - 1][0]) % 3
  tb = (LT[d][1] - LT[c - 1][1]) % 3
  print('YES' if (sa - sb) % 3 == (ta - tb) % 3 else 'NO')

Measured memory_bytes: 33524
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

int main() {
  string s,t;
  cin >> s >> t;
  int l = s.length();
  bool flag = false;
  REP(i,l) {
    REP(j, l) {
      if(s[(i+j)%l] != t[j]) break;
      if(j == l-1) flag = true;
    }
  }

  if(flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll h,w,n;
cin>>h>>w>>n;
ll ans=0;
ll x=max(h,w);
ll y=0;
while(y<n)
{
    y+=x;
    ans++;
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  ll u=stoi(s.substr(0,2));
  ll n=stoi(s.substr(2,2));
  bool uu=false;
  bool nn=false;
  if(u>0&&u<=12) uu=true;
  if(n>0&&n<=12) nn=true;
  if(uu&&nn){
    COUT("AMBIGUOUS");
  }
  else if(!uu&&!nn){
    COUT("NA");
  }
  else if(uu){
    COUT("MMYY");
  }
  else{
    COUT("YYMM");
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	cin >> n;
	int a;
	vector<int> v;
	rep(i,n){
		cin >> a;
		v.push_back(a);
	}
	//v[0]-v[n-1]まで1きざみでしらべていく
	int sum = 0;
	int mi = 40000000;
	FOR(i,-100,101){
		sum = 0;
		rep(j,n){
			sum += (i - v[j])*(i-v[j]);
		}
		mi = min(sum,mi);
	}
		cout <<mi << endl;
	

	return 0;
}


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

int solve(vector<int> &memo, const vector<int> &h, int i) {
    if (i == 0) return 0;
    if (i == 1) return abs(h[1] - h[0]);
    if (memo[i] != -1) return memo[i];
    return memo[i] = min(solve(memo, h, i - 1) + abs(h[i - 1] - h[i]), solve(memo, h, i - 2) + abs(h[i - 2] - h[i]));
}

int main() {
    int n; cin >> n;
    vector<int> h(n);
    for (auto &e : h) cin >> e;

    vector<int> memo(n, -1);
    cout << solve(memo, h, n - 1) << endl;
}



Measured memory_bytes: 7196
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007
#define w while
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
long double PI=acos(-1);
//////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
int main()
{
	ll n;
	cin>>n;
	n--;
	string ans="";
	while(n>=0)
	{
		int r=(n)%26;
		r++;
		char ch=(char)(r+96);
		ans.pb(ch);
		n/=26;
		n--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
    return 0;
}





Measured memory_bytes: 3624
import java.util.*;
 interface aisatu{
	final String str="こんにちは";
	void mesod();
}

public class Main {
	static public void main(String args[]){
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		
		String str=sc.next();
		int b=(int)(Double.parseDouble(str)*100+0.01);
		System.out.print((a*b)/100);
	}

}



Measured memory_bytes: 35860
def insertion_sort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while (j>=0)&(A[j]>v):
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return A, cnt
    
    
def shell_sort(A,n):
    G = []
    g = 1
    while True:
        G.append(g)
        g = 3*g+1
        if g>n:
            break
    m = len(G)
    G = G[::-1]
    cnt = 0
    for i in range(m):
        A,cnt_tmp = insertion_sort(A,n,G[i])
        cnt += cnt_tmp
    return G,A,cnt
    

n = int(input())
A = [int(input()) for i in range(n)]

G,A,cnt = shell_sort(A,n)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
    print(A[i])


Measured memory_bytes: 45516
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    int N,ans;
    cin>>N;
    ans=N%10;
    if(ans==2||ans==4||ans==5||ans==7||ans==9){
        cout<<"hon"<<endl;
    }else if(ans==0||ans==1||ans==6||ans==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"bon"<<endl;
    }
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,z,x;
	scanf("%d",&a);
	scanf("%d",&s);
	scanf("%d",&d);
	scanf("%d",&f);
	scanf("%d",&g);
	h=s/f;
	if(s%f!=0){
		h++;
	}
	z=d/g;
	if(d%g!=0){
		z++;
	}
	if(h>=z){
		printf("%d\n",a-h);
	}
	else if(z>h){
		printf("%d\n",a-z);
	}
	return 0;
}

Measured memory_bytes: 1028
import bisect
n = int(input())
L = []
for i in range(n):
    L.append(int(input()))
dp = [float('inf')]*n
for i in range(n):
    k = bisect.bisect_left(dp,L[i])
    dp[k] = L[i]
ans = 0
for i in range(n):
    if dp[i] != float('inf'):
        ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 10460
S = input()
st = [(0, 0, -1)]
cur = 0; ma = 0
for i, c in enumerate(S):
    if c == '/':
        cur += 1
        s = 0
        while st and st[-1][0] == cur-1 and cur <= ma:
            lev, su, j = st.pop()
            s += su
        if st and st[-1][0] == cur:
            s += i - st[-1][2] - 1
        ma = max(ma, cur)
        st.append((cur, s, i))
    elif c == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif c == '_':
        st.append((cur, 0, i))
ans = []
for lev, su, j in st:
    if su > 0:
        ans.append(su)
print(sum(ans))
print(len(ans), *ans)

Measured memory_bytes: 10060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c = 0, d = 0, e;
	cin >> a;
	for (int h = 1; h <= a; h++) {
		cin >> b;
		c = max(b, c);
		d += b;
	}
	cout << d - c / 2 << "\n";
	cin >> e;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = True
for ai in A:
    if ai % 2 == 0:
        if ai % 3 == 0 or ai % 5 == 0:
            pass
        else:
            ans = False

if ans:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp1, mp2;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i % 2)
            mp1[a[i]]++;
        else
            mp2[a[i]]++;
    }
    vector<p> v1, v2;
    for (auto e : mp1) {
        v1.push_back(p(e.second, e.first));
    }
    for (auto e : mp2) {
        v2.push_back(p(e.second, e.first));
    }
    sort(v1.begin(), v1.end());
    reverse(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    reverse(v2.begin(), v2.end());
    int m1 = v1[0].first, m2 = v1[1].first;
    int e1 = v2[0].first, e2 = v2[1].first;
    if (v1.size() == 1) m2 = 0;
    if (v2.size() == 1) e2 = 0;
    int sum;
    if (v1[0].second == v2[0].second) {
        sum = min(n - m1 - e2, n - m2 - e1);
    } else {
        sum = n - m1 - e1;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6520
N = int(input())
A = list(map(int, input().split()))
C = [100000000000000 for i in range(N)]
C[0] = 0
for i in range(1, N):
  if i == 1:
    C[1] = abs(C[0] + A[1] - A[0])
  else:
    C[i] = min(C[i-2] + abs(A[i] - A[i-2]), C[i-1] + abs(A[i] - A[i-1]))
print(C[N-1])

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



int main()
{	
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// cout.tie(NULL);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    	cin>>a[i];
    int ans=1;
    int c = a[0];
    for(int i=1;i<n;i++){
    	if(a[i]>=c){
    		ans++;
    		c=a[i];
    	}
    }
    cout<<ans;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Vector.Generic ((!))
import qualified Data.Vector.Unboxed as U
import Data.Vector.Algorithms.Intro

main = C.interact $ put . sol . get

get = U.unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v 
  | U.length w<2  = 0
  | w!0 /= w!1    = w!0 * w!1
  | U.length w==2 = 0
  | otherwise     = w!0 * w!2
  where
  u = U.modify (sortBy (flip compare)) $ U.tail v
  w = U.map fst . U.take 3 . U.filter (uncurry (==)) . U.zip u $ U.tail u

Measured memory_bytes: 8736
func gcd(x: Int, _ y: Int) -> Int {
    if y == 0 {
        return x
    } else {
        return gcd(y, x%y)
    }
}
func lcm(x: Int, _ y: Int) -> Int {
    return x * y / gcd(x, y)
}
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (A, B, C, D) = (input[0], input[1], input[2], input[3])
let tmp = lcm(C, D)
let tmp1 = B/C - (A-1)/C        // AからBまでのうちCで割り切れる数の個数
let tmp2 = B/D - (A-1)/D        // AからBまでのうちDで割り切れる数の個数
let tmp3 = B/tmp - (A-1)/tmp    // AからBまでのうちCとD両方で割り切れる数の個数
let tmp4 = tmp1 + tmp2 - tmp3   // AからBまでのうちCもしくはDで割り切れる数の個数
print(B - A + 1 - tmp4)

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

int m, s, g;
map<int, int> mp;
//ダイスの目
int dice[7] = {0};
//ワープ位置
int wp[305] = {0};
// iでjを出した時に行く場所のメモ(0で正、1で負)
int memo[305][7][2] = {0};
//ゴールに行くまでの最短手数と、そのときのダイスの目
pair<int, int> process[305];
// iに行くためにいる必要がある場所と、そのときに振る必要があるダイスの目のペア
vector<pair<int, int>> v[305];
// process埋め
queue<int> qu;
//ダイクストラ 辺の重み、現在の場所
priority_queue<pair<int, int>, vector<pair<int, int>>,
               greater<pair<int, int>>>
    pq;

int main() {
  int i, j, x, now = 0, y;
  cin >> m;
  for(i = 0; i <= m; ++i) process[i].first = inf;

  for(i = 1; i <= 6; ++i) {
    cin >> dice[i];
    ++mp[dice[i]];
  }
  cin >> s >> g;
  for(i = 1; i <= m; ++i) cin >> wp[i];
  for(i = 1; i <= m; ++i)
    for(j = 1; j <= 6; ++j) {
      if(i + dice[j] <= m) {
        memo[i][j][0] = i + dice[j] + wp[i + dice[j]];
        v[memo[i][j][0]].push_back(make_pair(i, j));
      }
      if(i - dice[j] >= 1) {
        memo[i][j][1] = i - dice[j] + wp[i - dice[j]];
        v[memo[i][j][1]].push_back(make_pair(i, -j));
      }
    }
  qu.push(g);
  process[g].first = 0;
  pq.push(make_pair(0, g));
  while(pq.size() > 0) {
    pair<int, int> np;
    np = pq.top();
    pq.pop();
    x = np.second;
    for(i = 0; i < v[x].size(); ++i) {
      y = process[x].first +
          60 / mp[dice[max(v[x][i].second,
                           -v[x][i].second)]];
      if(process[v[x][i].first].first > y) {
        process[v[x][i].first].first = y;
        process[v[x][i].first].second = v[x][i].second;
        pq.push(make_pair(process[v[x][i].first].first,
                          v[x][i].first));
      }
    }
  }
  now = s;
  while(now != g) {
    cin >> x;
    if(dice[max(process[now].second,
                -process[now].second)] == dice[x]) {
      if(process[now].second > 0) {
        cout << 1 << endl;
        now = memo[now][x][0];
      }
      else {
        cout << -1 << endl;
        now = memo[now][x][1];
      }
    }
    else {
      cout << 0 << endl;
    }
  }
  return 0;
}


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

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

  for(int i=0; i < c; i++){
    b -= a;
    if(b < 0){
      break;
    } else {
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char a[101],b[101],c[101];
  int state=0,c0=0,c1=0,c2=0;
  char now;
  scanf("%s",a);
  scanf("%s",b);
  scanf("%s",c);
  while(1){
    if(state==0){
      now = a[c0];
      c0++;
    }else if(state==1){
      now = b[c1];
      c1++;
    }else if(state==2){
      now = c[c2];
      c2++;
    }
    if(now=='\0'){
      if(state==0) printf("A\n");
      else if(state==1) printf("B\n");
      else if(state==2) printf("C\n");
      break;
    }else state = now - 'a';
    //printf("%d\n",state);
  }
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Stack;

public class Main {
	void run() {
		MyScanner sc = new MyScanner();

		int n = sc.nextInt();
		int[] a = sc.nextIntArray(n);

		Stack<Integer> s = new Stack<Integer>();
		s.push(0);
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (s.peek() < a[i]) {
				s.push(a[i]);
				cnt++;
			} else if (s.peek() > a[i]) {
				while (s.peek() > a[i]) {
					s.pop();
				}
				if (s.peek() < a[i]) {
					s.push(a[i]);
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

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

int main(){
  ll n,k;cin >> n >> k;
  vector<ll> vec(n);
  for(ll i=0; i<n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end(),greater<ll>());
  ll ans=0;
  for(ll i=k; i<n; i++){
    ans += vec.at(i);
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N;
  vector<string> blue(N);
  int MAX = 0;
  
  for(int i = 0; i < N; i++){
     cin >> blue.at(i);
  }
  
  cin >> M;
  vector<string> red(M);
  
  for(int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  
  int count;
  string S;
  
  for(int i = 0; i < N; i++){
    count = 0;
    S = blue.at(i);
    for(int j = 0; j < N; j++){
      if(S == blue.at(j)){
        count++;
      }
    }
   for(int k = 0; k < M; k++){
     if(S == red.at(k)){
       count--;
     }
   }
   if(MAX < count){
     MAX = count;
   }
  
  }
  
  if(MAX < 1){
    cout << 0 << endl;
  }else{
  cout << MAX << endl;
  }
    
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    ll x, y, tmp = 0;
    sc(x) sc(y)
    vector<int> ans;
    tmp = x;
    ans.push_back(x);
    while (tmp * 2 <= y){
        tmp += tmp;
        ans.push_back(tmp);
    }
    cout << ans.size() << endl;
    return 0;
}

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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  int ua=0,ab=0,ob=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if(x<=A)ua++;
    else if(x>=B+1)ob++;
    else ab++;
  }
  cout << min({ua,ab,ob});
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n=1;
    int a;
    int b[10000];
    while(cin >> a && a != 0){
        b[n] = a;
        n++;
    }
    for(int i=1;i<n;i++){
    cout <<"Case "<<i<<": "<<b[i]<<endl;
    }
}

Measured memory_bytes: 3124
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    int n;
    cin>>n;
    int ans = (1000 - n%1000) % 1000;
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll K,A,B;
  cin>>K>>A>>B;
  if(B-A<2||K<A-1){
    cout<<K+1;
    return 0;
  }
  ll ans=A;
  if((K-A+1)%2) ans++;
  ans+=(K-A+1)/2*(B-A);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
using namespace std;

int main() {
    unsigned int N;
    bool flag = false;
    vector<unsigned int> id;
    cin >> N;
    vector<pair< unsigned int, unsigned int>> vec(N);
    for (unsigned int i = 0; i < N; i++) {
        cin >> vec[i].first >> vec[i].second;
        if (vec[i].first == vec[i].second) {
            id.push_back(i);
        }
    }

    if (id.size() > 2) {
        for (unsigned int j = 0; j < (id.size() - 2); j++) {
            if (id[j]+2 == id[j+2] && id[j]+2 == id[j+1] +1 ) {
                flag = true;
                break;
            }
        }
        if (flag == true) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3128
function insert(tree, rootId, z) {
    let y = null;
    let x = tree[rootId];
    while(x){
        y = x;
        if(z < x.key){
            x = tree[x.left];
        } else {
            x = tree[x.right];
        }
    }

    if(y === null){
        tree[rootId] = {key: z, parent: y, left: null, right: null};
    } else if(z < y.key){
        y.left = z;
        tree[z] = {key: z, parent: y ? y.key : null, left: null, right: null};
    } else {
        y.right = z;
        tree[z] = {key: z, parent: y ? y.key : null, left: null, right: null};
    }
}

function preParse(inputs, idx, walked) {
    if(!idx){
        return;
    }
    walked[0] += ' ';
    walked[0] += inputs[idx].key;
    preParse(inputs, inputs[idx].left, walked);
    preParse(inputs, inputs[idx].right, walked);
}

function inParse(inputs, idx, walked) {
    if(!idx){
        return;
    }
    inParse(inputs, inputs[idx].left, walked);
    walked[1] += ' ';
    walked[1] += inputs[idx].key;
    inParse(inputs, inputs[idx].right, walked);
}

function printOut(tree, rootId) {
    const walked = ['', ''];
    preParse(tree, rootId, walked);
    inParse(tree, rootId, walked);

    console.log(walked[1]);
    console.log(walked[0]);
}


function main(_stdin){
    const stdin = _stdin.split('\n');
    const len = stdin.shift();
    const inputs = stdin.filter((e, i) => i < len);

    const tree = [];
    const rootId = parseInt(inputs[0].split(' ')[1], 10);
    for(const input of inputs){
        const order = input.split(' ');
        if(order[1]){
            insert(tree, rootId, parseInt(order[1], 10));
        } else {
            // console.log(tree);
            printOut(tree, rootId);
        }
    }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 241680
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main(){
  string s;
  cin >> s;
  int res = 0;
  for (int i=0; i<s.length(); i++) res += s[i] - '0';
  int sum = 0;
  for (int i=0; i<s.length(); i++) {
    sum = 0;
    string tmp(s);
    tmp[i]--;
    for (int k=i+1; k<s.length(); k++) 
      tmp[k] = '9';
    for (int k=0; k<s.length(); k++) sum += tmp[k] - '0';
    res = max(res, sum);
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int N;
  cin >> N;
  int a[N];
  rep(i, N) cin >> a[i];

  int ans = 0;
  int j = 0;
  bool can = false;

  rep(i, N) {
    ans++;
    j = a[j] - 1;
    if (j == 1) {
      can = true;
      break;
    }
  }

  cout << (can ? ans : -1 ) << endl;


}


Measured memory_bytes: 640
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-19 22:56:34
**/

#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n; cin >> n;

  int64 cnt[10][10];
  fill(cnt[0], cnt[10], 0LL);

  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    char c1 = s[0], c2 = s.back();
    ++cnt[c1 - '0'][c2 - '0'];
  }

  int ans = 0;

  for (int i = 1; i < 10; ++i) {
    for (int j = 1; j < 10; ++j) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;
lint p=1000*1000*1000+7;
int main(){
  int N;
  cin>>N;
  string S,T;
  cin>>S;
  cin>>T;
  int pattern;
  lint ans;
  int i=0;
  if(S[0]==T[0]){
    i++;
    pattern=1;
    ans=3;
  }else{
    i+=2;
    pattern=2;
    ans=6;
  }
  for(i;i<N;i++){
    if(S[i]==T[i]){
      ans*=(pattern==1?2:1);
      ans%=p;
      pattern=1;
    }else{
      ans*=(pattern==1?2:3);
      ans%=p;
      i++;
      pattern=2;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
ls = [0]+[0]*N
couterls = collections.Counter(ls)
for i in range(1,N+1):
    for j in range(2,N+1):
        if i % j == 0:
            while i % j == 0:
                couterls[j] += 1
                i = i // j
        elif i == 1:
            break
        else:
            pass
ans = 1
couterls.pop(0)
for i in couterls.values():
    ans = (ans * (i+1) ) % (10**9+7)
print(ans)

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int s=0,x=0;
  for(int i=0;i<105;i++){
    s+=b;
    x+=d;
    if(s>=c){
      cout<<"Yes"<<endl;
      break;
    }
    if(x>=a){
      cout<<"No"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if(A1+A2+A3 <= 21){
    cout << "win" << endl;
  }else{
    cout << "bust" << endl;
  }
}

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

int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c;
    d = b - a;
    e = c - b;

    if(d == e)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

    ll n,i,j;
    cin>>n;
    ll ans = 0;
    for(i=1;i<=n;i++) ans+=(i*(n-i+1));
    ll u,v;
    for(i=0;i<n-1;i++)
    {
        cin>>u>>v;
        ll mn = min(u,v);
        ll mx = max(u,v);
        ans-=(mn*(n-mx+1));
    }
    cout<<ans;
}

Measured memory_bytes: 3676
W, H, N =map(int,input().split())
xya = [list(map(int,input().split())) for i in range(N)]
lxy=[0,0]
rxy=[W,H]
for i in range(N):
    if xya[i][2]==1:
        lxy[0] = max(lxy[0],xya[i][0])
    elif xya[i][2]==2:
        rxy[0] = min(rxy[0],xya[i][0])
    elif xya[i][2]==3:
        lxy[1] = max(lxy[1],xya[i][1])
    else: rxy[1] = min(rxy[1],xya[i][1])
#(rxy[1],lxy[1],rxy[0],lxy[0])
print(max(0,(rxy[1]-lxy[1]))*(max(0,rxy[0]-lxy[0])))

Measured memory_bytes: 3064
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  int sum;
  auto tmp = n;
  while (tmp != 0) {
    auto x = tmp % 10;
    sum += x;
    tmp /= 10;
  }

  if (n % sum) {
    writeln("No");
  } else {
    writeln("Yes");
  }
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int q;
    scan(q);

    while (q--) {
        string s, t;
        scan(s);
        scan(t);
        auto ans = solve(s, t);
        writeln(ans);
    }
}

int solve(string s, string t) {
    auto n = s.length.to!int;
    auto m = t.length.to!int;

    auto dp = new int[][](n + 1, m + 1);
    foreach (i ; 1 .. n + 1) {
        foreach (j ; 1 .. m + 1) {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (s[i - 1] == t[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1);
        }
    }

    auto res = dp[n][m];
    return res;
}

















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
ll N;
#define pow5(x) ((x)*(x)*(x)*(x)*(x))
int main()
{
	ll x;
	cin >> x;
	int rate = 120;
 
	ll a, b;
	for (a = -rate; a < rate; a++)
	{
		for (b = -rate; b < rate; b++)
		{
			if ( a == b ) continue;
 
			ll p5a = pow5(a), p5b = pow5(b);
			if ( p5a - p5b == x ) {
				cout << a << " " << b << endl;
				return 0;
			}
			else
			{
				if ( p5a - p5b < x ) break;
			}
		}
	}
 
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

int n;
map<string, int> M;
string s;

int main() {
	fastio;
	cin >> n;
	FOR(i, n) {
		cin >> s;
		M[s]++;
	}
	cout << "AC x " << M["AC"] << endl;
	cout << "WA x " << M["WA"] << endl;
	cout << "TLE x " << M["TLE"] << endl;
	cout << "RE x " << M["RE"];
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
//#define endl '\n'

int n;
int a[maxn],b[maxn];

int32_t main()
{
    IOS
    cin>>n;
    for (int i=1;i<=n+1;i++) cin>>a[i];
    int ans=0;
    for (int i=1;i<=n;i++)
    {
        cin>>b[i];
        int minn=min(a[i],b[i]);
        a[i]-=minn,b[i]-=minn,ans+=minn;
        minn=min(b[i],a[i+1]);
        a[i+1]-=minn,b[i]-=minn,ans+=minn;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 5120
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int x[100010];
    rep(i, N) cin >> x[i];
    int ans = INF;
    rep(i, N - K + 1) {
        int tmp1 = abs(x[i + K - 1]) + x[i + K - 1] - x[i];
        int tmp2 = abs(x[i]) + x[i + K - 1] - x[i];
        ans = min({ans, tmp1, tmp2});
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,x,min;
  cin>>k>>x;
  min=x-k+1;
  for(int i=0;i<2*k-1;++i){
    cout<<min+i;
    if(i<2*k-2)cout<<" ";
  }
}

Measured memory_bytes: 256
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A,B,C = map(int, readline().split())
if (A == B and B != C) or (B == C and C != A) or (A == C and C != B):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll A=n/100;
	bool a=false;
	if(A<=12&&A>=1){
		a=true;
	}
	ll B=n%100;
	bool b=false;
	if(B<=12&&B>=1){
		b=true;
	}
	if(a){
		if(b){
			cout <<"AMBIGUOUS";
		}
		else{
			cout << "MMYY";
		}
	}
	if(a!=true){
		if(b){
			cout << "YYMM";
		}
		else{
			cout << "NA";
		}
	}
	// your code goes here
	
	return 0;
}

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

using namespace std;
int main() {
    int a=0,b=0,t_int=0;
    float t=0.0;
    cin>>a>>b>>t;
    t_int=floor(t+0.5);
    cout<<(t_int/a)*b;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(a, b, x) = sc.nextLine.split(" ").map(_.toInt)
    if (x > a + b) println("NO")
    else if (x < a) println("NO")
    else println("YES")
  }
}


Measured memory_bytes: 27308
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int a,b,c,x,t;
  cin >> a >> b >> c >> x;
  t=0;
  REP(i,a+1){
    REP(j,b+1){
      REP(k,c+1){
        if(k*50+j*100+i*500 == x) t++;
      }
    }
  }
  cout << t;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;

ll euclid(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    
    return b;
}

int main(void){
    ll result = 0;
    
    ll N;
    cin >> N;
    
    vector<ll> A(N, 0);
    rep(i, N){
        ll x;
        cin >> x;
        A[i] = x;
    }
    
    result = A[0];
    For(i, 1, A.size()){
        result = euclid(result, A[i]);
    }
    
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1024
a,b = map(int,input().split(" "))
ar = [[] for j in range(a+1)]
for i in range(b):
    l = list(map(int,input().split(" ")))
    ar[l[0]].append(l[1])
    ar[l[1]].append(l[0])
count = 0
for r in ar[1]:
    for s in ar[r]:
        if s == a:
            count += 1
if count == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

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

int main(void){
   long long int x, y;
   cin >> x >> y;
   int count = 0;
   for(long long int i = x; i <= y; i+=x){
            count++; x=i;
   }

   cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

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

if 0 in a_list:
    print(0)
    sys.exit()
else:
    cul = 1
    for a in a_list:
        cul *= a
        if cul > 10 ** 18:
            print(-1)
            sys.exit()
    print(cul)


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

sayTable = []
for i in range(n):
	a = int(input())
	
	sayArray = []
	for j in range(a):
		x, y = [int(v) for v in input().split()]
		sayArray.append((x-1, y+1))
	sayTable.append(sayArray)

def countHonest(honest):
	count = 0
	for v in honest:
		if v == 2:
			count += 1
	return count

def checkHonest(sayArray, honest):
	for x, y in sayArray:
		if honest[x] == 0:
				continue
		if y == 2 and honest[x] != 2:
			return False
	return True

def checkHonestAll(sayTable, honest):
	for i in range(n):
		h = honest[i]
		if h != 2:
			continue
		sayArray = sayTable[i]
		for x, y in sayArray:
			if y != honest[x]:
				return False
	return True

def setHonest(sayArray, honest):
	for x, y in sayArray:
		honest[x] = y

def search(sayTable, honest, i):
	if i >= n:
		if checkHonestAll(sayTable, honest):
			return countHonest(honest)
		else:
			return 0

	count = 0
	h = honest[i]
	sayArray = sayTable[i]
	if (h == 0 or h == 2) and checkHonest(sayArray, honest):
		copyHonest = honest[:]
		setHonest(sayArray, copyHonest)
		copyHonest[i] = 2
		c = search(sayTable, copyHonest, i+1)
		if count < c:
			count = c

	honest[i] = 1
	c = search(sayTable, honest, i+1)
	if count < c:
		count = c
	return count

print(search(sayTable, [0] * n, 0))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

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

  cout << (abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d) ? "Yes" : "No");
  return 0;
} 

Measured memory_bytes: 3600
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>


int N_all;


int main(int argc, char* argv[]){
    int i,j,sqrti;
    int count,now;
    double i_d;
    count=0;
    scanf("%d",&N_all);
    for(i=1;i<=N_all-1;i++){
        i_d = 1.*i;
        sqrti = sqrt(i_d);
        if((sqrti+1)*(sqrti+1) == i){
            sqrti ++;
        }
        for(j=1;j<=sqrti;j++){
            //printf("%d %d %d %d\n",i,j,N_all-i,(i/j)*j+(N_all-i) );
            if(i%j == 0){
                //printf("count\n");
                count++;
                if(j!=sqrti || sqrti*sqrti!=i){
                    count++;
                }
            }
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 2156
N = gets.chomp.to_i
A = gets.chomp.split(" ").map(&:to_i)

sum = A.inject(:+)

half = sum / 2.0

sum = 0
A.each.with_index do |n, i|
  sum += n
  if sum >= half then
    ans = []

    rest = i == A.size - 1 ? 0 : A[i+1..-1].inject(:+)
    if rest >= sum then
      ans << (rest - sum)
    else
      ans << (sum - rest)
    end

    rest = A[i..-1].inject(:+)
    sum -= n
    if rest >= sum then
      ans << (rest - sum)
    else
      ans << (sum - rest)
    end

    puts ans.min
    exit
  end
end

Measured memory_bytes: 18316
N=int(input())

m=list(map(int,input().split()))

count=0
for i in range(N):
    p=m[i:i+3]
    if len(p) == 3:
        if max(p) > p[1] and min(p) < p[1]:
            count +=1
            
            
print(count)     
       

Measured memory_bytes: 2940
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
#define rep(i,n) for (int i=0; i< (n); ++i)                                                           
typedef pair<int, int> P;                                                                             
                                                                                                      
int main() {                                                                                          
  int s, w;                                                                                           
  cin >> s >> w;                                                                                      
  if (w >= s) {                                                                                       
    cout << "unsafe" << endl;                                                                         
  } else {                                                                                            
    cout << "safe" << endl;                                                                           
  }                                                                                                   
  return 0;                                                                                           
}                                                                                                     
        

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,W=MAP()
VW=[]
for i in range(N):
    v,w=MAP()
    VW.append((v, w))

dp=list2d(N+1, W+1, 0)
for i in range(1, N+1):
    v,w=VW[i-1]
    for j in range(W+1):
        dp[i][j]=max(dp[i][j], dp[i-1][j])
        if j-w>=0:
            # i-1ではなく同じiからも遷移することが、重複して選ぶことに相当する
            dp[i][j]=max(dp[i][j], dp[i-1][j-w]+v, dp[i][j-w]+v)
print(dp[N][W])



Measured memory_bytes: 15728