akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, stdin, BufRead};
use std::str::FromStr;

fn read_one<T>() -> T
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();

    buf.trim().parse::<T>().unwrap()
}

macro_rules! read_tuple {
        ( $( $t:ty ), * ) => {
            {
                let stdin = stdin();
                let mut handle = stdin.lock();
                let mut buf = String::new();
                handle.read_line(&mut buf).unwrap();
                let mut v = buf.trim().split_whitespace()
                    .collect::<VecDeque<&str>>();
                (
                    $({
                        v.pop_front().unwrap().parse::<$t>().unwrap()
                    },)*
                )
            }
        }
    }

fn read_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();

    buf.trim()
        .split_whitespace()
        .map(|s| s.parse::<T>().unwrap())
        .collect::<Vec<T>>()
}

fn main() -> io::Result<()> {
    let mut n = read_one::<i32>();
    while n > 0 {
        if n % 10 == 7 {
            println!("Yes");
            return Ok(());
        }
        n /= 10;
    }
    println!("No");
    return Ok(());
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
int main(){
    int cnt = 0,N;
    cin >> N;
    for(int i = 1;cnt < N;i ++){
        bool isP = true;
        for(int j =2;j <= floor(sqrt(10*i-1));j ++){
            if((10*i-1)%j==0){
                isP = false;
                break;
            } 
        }
        if(isP){
            cnt ++;
            cout << 10*i -1 << " ";
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 3 != 0 and A[i] % 5 != 0:
            print("DENIED")
            exit()
print("APPROVED")   
            
        
            

Measured memory_bytes: 38384
#include<stdio.h>

int isprime(int);
main()
{
  int i, n[10000], p, count=0;
  scanf("%d",&p);
  
  for(i=0; i<p; i++){
    scanf("%d",&n[i]);
    if(isPrime(n[i]) == 1) count++;
  }
  printf("%d\n",count);
  return 0;
}
int isPrime(int n)
{
  int i;
  
  if(n < 2)return 0;
  else if(n == 2) return 1;
  if(n % 2 == 0) return 0;
  for(i=3; i<=n/i; i+=2){
    if(n % i == 0)
      return 0;
  }
    return 1;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1e+7;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n,q;cin>>n>>q;
    vector<ll> a(n+10),s1(n+10),s2(n+10),s3(n+10);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=n-1;i>=0;i--)s1[i]=s1[i+1]+a[i];
    for(int i=0;i<n;i++){
        if(i%2){
            s3[i]+=a[i];
        }else{
            s2[i]+=a[i];
        }
        s2[i+1]+=s2[i];
        s3[i+1]+=s3[i];
    }
    for(int i=0;i<q;i++){
        ll x;cin>>x;
        int ok=-1,ng=n+1;
        while(ng-ok>1){
            int k=(ok+ng)/2;
            if(abs(a[n-k]-x)<=abs(a[n-k/2-k%2]-x)){
                ok=k;
            }else{
                ng=k;
            }
        }
        cout<<s1[n-ok/2-ok%2]+(ok<n?(n%2?s2[n-ok-1]:s3[n-ok-1]):0)<<endl;
    }
}   


Measured memory_bytes: 4864
import math
S = int(input())
X1 = 0
Y1 = 0
#S=abs(X2*Y3-X3*Y2)の解が欲しい
X2 = math.ceil(S**0.5)
X3 = 1
Y3 = math.ceil(S**0.5)
Y2 = int((X2*Y3-S)/X3)

print("{} {} {} {} {} {}".format(X1,Y1,X2,Y2,X3,Y3))


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

int count_digits(ll n) {
    int digits = 0;
    while (n > 0) {
        n /= 10;
        ++digits;
    }
    return digits;
}

int main() {

    ll N;
    cin >> N;

    int ans = count_digits(N);
    for (ll a = 1LL; a*a <= N; ++a) {
        if (N%a != 0) continue;
        ll b = N / a;
        int c = max(count_digits(a), count_digits(b));
        ans = min(ans, c);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3548
import sys

def main():
    inp = [[i for i in map(int, line.rstrip().split())] for line in sys.stdin.readlines()]
    rule = inp.pop(0)
    inp.sort(key=lambda x:x[0])
    n = 0
    temp = 0
    price = 0
    for i in inp:
        temp += i[1]
        if(rule[1] < temp):
            price += i[0] * (rule[1] - n)
            break
        n = temp
        price += i[0] * i[1]

    print(price)

if __name__ == '__main__':
    sys.exit(main())



Measured memory_bytes: 29076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	private	static	BufferedReader		br   = null;
	private	static	ArrayList<Integer>	list = null;

	static {
		br   = new BufferedReader(new InputStreamReader(System.in));
		list = new ArrayList<Integer>();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strNum = null;
		int		nNum   = 0;
		int		nOut   = 0;

		while ((strNum = parseNum()) != null) {
			nNum = Integer.parseInt(strNum);
			if (nNum == 0) {
				nOut = list.get(0);
				list.remove(0);
				System.out.println(nOut);
			}
			else {
				list.add(0, nNum);
			}
		}
	}

	private static String parseNum() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
int main() {
  int H, W; cin >> H >> W;
  int ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<string> S(H); REP(i, H) cin >> S[i];

  vector<vector<ll>> cnt(H, vector<ll>(W, pow(10, 9))); // 魔法を使った回数
  queue<P> q, visited; // これから見るマスと、行ったことのあるマスかどうか
  q.push(P(ch, cw));
  cnt[ch][cw] = 0;

  // だいたい01BFSと同じことをしている
  while(!q.empty() || !visited.empty()) {
    if(!q.empty()) {
      ll X = q.front().first; ll Y = q.front().second;
      visited.push(P(X, Y)); // 今見たマスを探索済み探索済みキューに追加する
      q.pop();
      REP(i, 4) {
        ll nextX = X + dx[i]; ll nextY = Y + dy[i];
        if(0 <= nextX && nextX < H && 0 <= nextY && nextY < W) {
          if(S[nextX][nextY] == '#') continue;
          if(cnt[X][Y] < cnt[nextX][nextY]) {
            cnt[nextX][nextY] = cnt[X][Y];
            q.push(P(nextX, nextY));
          }
        }
      }
    } else { // 移動Aで行ける道をすべて探索したら、移動Bで行ける道を探索する
      ll X = visited.front().first; ll Y = visited.front().second;
      visited.pop();
      for(int x = -2; x <= 2; ++x) {
        for(int y = -2; y <= 2; ++y) {
          ll nextX = X + x; ll nextY = Y + y;
          if(0 <= nextX && nextX < H && 0 <= nextY && nextY < W) {
            if(S[nextX][nextY] == '#') continue;
            if(cnt[X][Y] < cnt[nextX][nextY]) {
              cnt[nextX][nextY] = cnt[X][Y] + 1;
              q.push(P(nextX, nextY));
            }
          }
        }
      }
    }
  }
  if(cnt[dh][dw] == pow(10, 9)) cout << -1 << endl;
  else cout << cnt[dh][dw] << endl;
}

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

using namespace std;

int main() {
	int q;
	string strX, strY;

	cin >> q;
	for (int n = 0; n < q; n++) {
		cin >> strX;
        cin >> strY;
		char X[strX.length() + 1];
		for (int x = 0; x < strX.length(); x++) {//文字列を配列に入れる
			X[x + 1] = strX[x];
		}

        char Y[strY.length() + 1];
		for (int y = 0; y < strY.length(); y++) {//文字列を配列に入れる
			Y[y + 1] = strY[y];
		}

        int c[strX.length()+1][strY.length()];
        int maxLen = 0;

		for (int i = 0; i<=strX.length(); i++){
            for(int j = 0; j<=strY.length(); j++){
                if(i == 0 || j == 0){
                    c[i][j] = 0;
                }
                else if(X[i] == Y[j]){
                    c[i][j] = c[i-1][j-1] + 1;
                } else {
                    c[i][j] = max(c[i][j-1], c[i-1][j]);
                }

                if(c[i][j] > maxLen){
                    maxLen = c[i][j];
                }
            }
        }
        cout << maxLen << endl;
	}

    return 0;
}


Measured memory_bytes: 7104
#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
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r1, c1, r2, c2;
    fact();
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = 0;
    REP(i, c1 + 1, c2 + 1) {
        ans = (ans + C(r2  + i, i) - C(r1  + i - 1, i) + mod) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16640
#include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <map>
    using namespace std;
     
    int main()
    {
        int N, K, d, a, c = 0;
        cin >> N >> K;
        int Z[N];
        for (int i = 0; i < N; i++)
        {
            Z[i]=1;
        }
        
        for (int i = 0; i < K; i++)
        {
            cin >> d;
            for (int j = 0; j < d; j++)
            {
                cin >> a;
                Z[a-1] = 0;
            }
        }
        for (int i = 0; i < N; i++)c += Z[i];
        cout << c;
        return 0;
    }

Measured memory_bytes: 3620
import sys


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    n %= k
    while True:
        if abs(n - k) >= n:
            break
        else:
            n = abs(n - k)
    print(n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val x = sc.nextInt()
    val y = sc.nextInt()

    def gcb(a: Int, b: Int): Int = {
      if (b == 0) a else gcb(b, a % b)
    }

    println(gcb(Math.max(x, y), Math.min(x, y)))
  }

}




Measured memory_bytes: 44888
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=3e5+2;
int n,k,p[N],f[N];

template <typename _Tp> inline void IN(_Tp&x) {
    char ch;bool flag=0;x=0;
    while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1 ;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    if(flag) x=-x;
}

struct Segment_Tree {
    #define mid ((l+r)>>1)
    int Mi[N<<2],Mx[N<<2];
    void build(int x,int l,int r) {
        if(l==r) {Mi[x]=Mx[x]=p[l];return;}
        build(x<<1,l,mid),build(x<<1|1,mid+1,r);
        Mi[x]=min(Mi[x<<1],Mi[x<<1|1]),Mx[x]=max(Mx[x<<1],Mx[x<<1|1]);
    }
    int query_Mi(int x,int l,int r,int L,int R) {
        if(L==l&&r==R) return Mi[x];
        if(R<=mid) return query_Mi(x<<1,l,mid,L,R);
        else if(L>mid) return query_Mi(x<<1|1,mid+1,r,L,R);
        else return min(query_Mi(x<<1,l,mid,L,mid),query_Mi(x<<1|1,mid+1,r,mid+1,R));
    }
    int query_Mx(int x,int l,int r,int L,int R) {
        if(L==l&&r==R) return Mx[x];
        if(R<=mid) return query_Mx(x<<1,l,mid,L,R);
        else if(L>mid) return query_Mx(x<<1|1,mid+1,r,L,R);
        else return max(query_Mx(x<<1,l,mid,L,mid),query_Mx(x<<1|1,mid+1,r,mid+1,R));
    }
}T;

int main() {
    IN(n),IN(k);
    for(int i=1;i<=n;++i) IN(p[i]);
    T.build(1,1,n);
    int Mi=T.query_Mi(1,1,n,1,k),Mx=T.query_Mx(1,1,n,1,k),cnt=0;
    f[1]=1;
    bool flag=false;
    for(int i=2;i<=n;++i)
        f[i]=(p[i-1]<=p[i])?f[i-1]+1:1,
        flag|=((f[i]>=k)&&i>k);
    if(flag) ++cnt;
    if((f[k]==k&&!flag)||(f[k]<k)) ++cnt;
    for(int r=k+1;r<=n;++r) {
        int now_Mi=T.query_Mi(1,1,n,r-k+1,r),now_Mx=T.query_Mx(1,1,n,r-k+1,r);
        if(!(Mi==p[r-k]&&now_Mx==p[r])&&f[r]<k) ++cnt;
        Mi=now_Mi,Mx=now_Mx;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
 
typedef long long ll;


const int N = 25 * 25;
const int INF = (int)1e4 + 7;

int n, m;

char tab[N][N];

bool check(int i, int j) {
    return (0 <= i && i < n) && (0 <= j && j < m) && tab[i][j] == '.';
}
bool check(int v) {
    int i = v / m;
    int j = v % m;
    return check(i, j);
}

int getV(int i, int j) {
    return i * m + j;
}
void printV(int v) {
    printf("%d %d  ", v / m + 1, v % m + 1);
}

int g[N][N];

void addEdge(int x1, int y1, int x2, int y2) {
    if (!check(x1, y1) || !check(x2, y2)) return;
    int v = getV(x1, y1);
    int u = getV(x2, y2);
    g[u][v] = g[v][u] = 1;
}

int main()
{
    scanf("%d%d", &n, &m);
    
    for (int i = 0; i < n; ++i)
        scanf("%s", tab[i]);
    
    int S = n * m;
    for (int i = 0; i < S; ++i) {
        for (int j = 0; j < S; ++j)
            g[i][j] = INF;
        g[i][i] = 0;
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            addEdge(i, j, i, j - 1);
            addEdge(i, j, i - 1, j);
            addEdge(i, j, i, j + 1);
            addEdge(i, j, i + 1, j);
        }
    }
    
    for (int k = 0; k < S; ++k)
        for (int i = 0; i < S; ++i)
            for (int j = 0; j < S; ++j)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    
    int ans = 0;
    for (int i = 0; i < S; ++i)
        for (int j = 0; j < S; ++j)
            if (check(i) && check(j)) ans = max(ans, g[i][j]);
    printf("%d\n", ans);
}



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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s, A, B;
  int q;
  cin >> s >> q;
  int inverte = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      inverte = inverte ? 0 : 1;
    }
    else {
      int f;
      char c;
      cin >> f >> c;
      if ((f==1)&&(inverte)||(f==2)&&(!inverte))
        B.pb(c);
      else
        A.pb(c);
    }
  }
  if (inverte == 0) {
    for (auto a = A.rbegin(); a < A.rend(); a++)
      cout << *a;
    cout << s << B << ende;
  }
  else {
    for (auto b = B.rbegin(); b < B.rend(); b++)
      cout << *b;
    for (auto x = s.rbegin(); x < s.rend(); x++)
      cout << *x;
    cout << A << ende;
  }
  return 0;
}


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

int main() {
  string s,t;
  bool k=true;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i))k=false;
  }
  if(k)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
//https://atcoder.jp/contests/abc150/tasks/abc150_d
//D - Semi Common Multiple
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
ll lcm(ll num1,ll num2){
  return num1 / __gcd(num1,num2) * num2;
}
int main() {
  ll N,M; cin>>N>>M;
  vector<ll> an(N);
  ll lcmv=1;
  for(auto&a:an){
    cin>>a;
    lcmv=lcm(lcmv,a/2); //a/2(2p+1)なので、a/2のlcmの奇数の数
  }
  FOR(i,0,an.size()){
    ll tmp=lcmv/(an.at(i)/2);
    if(tmp%2==0){
      cout<<0<<endl;
      return 0;
    }
  }

  ll ans=M/lcmv;
  ans = (ans+1)/2; //奇数の数
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int h, w, n;
char maze[1003][1003];

int bfs(int sx, int sy, int gx, int gy) {
  int dist[1003][1003];
  int dx[] = { -1, 0, 0, 1 };
  int dy[] = { 0, -1, 1, 0 };
  rep (i, 1003) {
    rep (j, 1003) {
      dist[j][i] = -1;
    }
  }
  dist[sy][sx] = 0;

  queue< pair<int, int> > q;
  q.push( make_pair(sx, sy) );

  while ( !q.empty() ) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x+dx[i];
      int ny = y+dy[i];
      if ( dist[ny][nx] != -1 ) { continue; }
      if ( maze[ny][nx] == '#' ) { continue; }
      if ( nx < 0 || ny < 0 || nx >= w || ny >= h ) { continue; }
      dist[ny][nx] = dist[y][x]+1;
      q.push( make_pair(nx, ny) );
    }
  }
  return dist[gy][gx];
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  cin >> h >> w;

  rep(i, h) {
    cin >> maze[i];
  }

  int black = 0;
  rep(y, h) {
    rep(x, w) {
      if (maze[y][x] == '#') {
        black++;
      }
    }
  }
  int t = bfs(0, 0, w-1, h-1);
  cout << ( t == -1 ? -1 : h*w-t-black-1) << endl;

  return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    int x=max(h,w);
    cout<<(n+x-1)/x<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a % 2 && b % 2 && c % 2) {
		long long res = (long long) a * b;
		if (res > (long long) b * c) res = (long long) b * c;
		if (res > (long long) c * a) res = (long long) c * a;
		printf("%lld\n", res);
	} else puts("0");
	return 0;
}


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

long long con=1000000007,a[100070],cnt[100070],fac[100050];

long long fact(long long n)
{
    if(n==0)
    {
        return 1;
    }
    long long mul=1,i;

    mul=fac[n-1]*n;
    mul=mul%con;

    return mul;
}

int main()
{

    long long n,i,ans=1;

    for(i=0; i<100050; i++)
    {
        fac[i]=fact(i);
    }
    scanf("%lld",&n);

    for(i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        cnt[a[i]]++;
    }

    for(i=1;i<100050; i++)
    {
        if(cnt[i]%2!=0)
        {
            printf("0");
            return 0;
        }


        ans*=fac[cnt[i]];
        ans=ans%con;
    }

    printf("%lld",ans);
    return 0;
}



Measured memory_bytes: 2560
n = gets.to_i
a = gets.split.map(&:to_i)

while true
    amin = a.select{|i|i>0}.min
    amin_idx = a.index(amin)
    if amin == 1
        puts 1
        exit
    end

    for i in 0..a.length-1
        if a[i] > 0 && i != amin_idx
            a[i] -= amin * (a[i] / amin)
        end
    end

    if a.count{|i|i>0} == 1
        puts a.max
        exit
    end
end


Measured memory_bytes: 9996
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
from copy import *

N = int(input())
t, v = list(map(int, input().split())), list(map(int, input().split()))
s = sum(t)*2
u = [[0.5*i, 0.5*(s-i)] for i in range(s+1)]
T = [0] * (N+1)
for i in range(N):
    T[i+1] = T[i]+t[i]
for i in range(s):
    now = 0.5*i
    for j in range(N):
        if now < T[j]:
            u[i].append(v[j]+T[j]-now)
        elif T[j] <= now <= T[j+1]:
            u[i].append(v[j])
        else:
            u[i].append(v[j]+now-T[j+1])
for i in range(s+1):
    u[i] = min(u[i])
ans = 0
for i in range(s):
    ans += (u[i]+u[i+1])/4
print(ans)


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+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; }

int main() {
    char c;
    scanf("%c", &c);
    printf("%c", c+1);

}



Measured memory_bytes: 256
import * as fs from "fs";

const [H, W] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(Number);

function solve(H: number, W: number): number {
	if (H == 1 || W == 1) {
		return 1;
	}
	if (H%2 == 0) {
		return Math.floor(H/2)*W;
	} else {
		let H1 = Math.floor(H/2);
		let H0 = H1+1;
		if (W%2 == 0) {
			return (H0+H1)*Math.floor(W/2);
		} else {
			let W1 = Math.floor(W/2);
			let W0 = W1+1;
			return W0*H0+W1*H1;
		}
	}
}

console.log(solve(H, W));


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

using namespace std;

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

int main() {
    int n;

    cin >> n;

    int p[n], q[n];

    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
    }

    int nlist[n];
    for(int i = 0; i < n; i++) {
        nlist[i] = i+1;
    }

    int a = 1, b = 1;
    int kaijo;
    bool flag = false;

    kaijo = facctorialMethod(n);
    int m = kaijo;

    for(int i = 0; i < n - 1; i++) {
        m /= (n-i);
        for (int j = 0; j < n - i; j++)
        {
            if (flag == false) {
                if(p[i] == nlist[j]) {
                    a += j*m;
                    nlist[j] = nlist[j+1];
                    flag = true;
                }
            }else {
                if(j < n-i-1) {
                    nlist[j] = nlist[j+1];
                }
            }
            
        }
        flag = false;
        
    }

    m = kaijo;
    for(int i = 0; i < n; i++) {
        nlist[i] = i+1;
    }

    for(int i = 0; i < n - 1; i++) {
        m /= (n-i);
        for (int j = 0; j < n - i; j++)
        {
            if (flag == false) {
                if(q[i] == nlist[j]) {
                    b += j*m;
                    nlist[j] = nlist[j+1];
                    flag = true;
                }
            }else {
                if(j < n-i-1) {
                    nlist[j] = nlist[j+1];
                }
            }
            
        }
        flag = false;
        
    }


    cout << abs(a-b) << endl;    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
 
int main()
{
  int i, j, n, u, k, temp;
  int Adj[101][101];
  
  scanf("%d", &n);
  
  for(i=1; i<=n; i++)
    {
      for(j=1; j<=n; j++)
	{
	  Adj[i][j] = 0;
	}
    }
  
  for(i=0; i<n; i++)
    {
      scanf("%d%d", &u, &k);
    for(j=0; j<k; j++)
      {
	scanf("%d",&temp);
	Adj[u][temp] = 1;
      }
    }
  
  for(i=1; i<=n; i++)
    {
      for(j=1; j<=n; j++)
	{
	  if(j == 1) printf("%d", Adj[i][j]);
	  else printf(" %d", Adj[i][j]);
	}
      printf("\n");
    }
  
  return 0;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

int N;
ll K;
vector<ll> A, F;
bool check(ll X) {
  ll k = K;
  vector<bool> used(N, false);
  rep(i, N) {
    if (A[i] * F[i] > X)
      k -= (A[i] * F[i] - X + F[i] - 1) / F[i];
  }
  // rep(i, N) cout << used[i];
  return k >= 0;
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> N >> K;

  A.resize(N);
  F.resize(N);
  rep(i, N) {
    cin >> A[i];
  }
  rep(i, N) {
    cin >> F[i];
  }
  sort(all(A));
  reverse(all(A));
  sort(all(F));

  ll ok = 1e12, ng = -1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }
  out(ok);
  return 0;
}


Measured memory_bytes: 3456
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        string S;
        S = cin.next();
        if (S.Length >= 4 && S.Substring(0, 4) == "YAKI") Console.WriteLine("Yes");
        else Console.WriteLine("No");

    }




}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int,int>
#define vvi vector<vector<int> >
#define vpi vector<pii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define INF 0x7fffffff
#define LINF 0x7fffffffffffffff
#define MOD 1000000007
#define mod 998244353
#define lowbit(x) x&(-x)
#define HS 173LL
using namespace std;
int read()
{
	int x=0;
	char ch=getchar();
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int n,m,cnt[15][26],a[15],b[15];
char grid[15][15];
vector<int> v[15];
bool ispd(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return s==t;
}
void dfs2(int x,bool g)
{
	if(x==m+1)
	{
		cout<<"YES"<<endl;
		exit(0);		
	}
	if(b[x])
	{
		dfs2(x+1,g);
		return;
	}
	for(int y=1;y<=m;y++)
		if(!b[y]&&x!=y)
		{
			bool flag=true;
			for(int i=1;i<=n;i++)
			{
				int j=a[i];
				if(grid[i][x]!=grid[j][y])
				{
					flag=false;
					break;
				}
			}
			if(flag)
			{
				b[x]=y;
				b[y]=x;
				dfs2(x+1,g);
				b[x]=0;
				b[y]=0;
			}
		}
	bool flag=true;
	for(int i=1;i<=n;i++)
	{
		int j=a[i];
		if(grid[i][x]!=grid[j][x])
		{
			flag=false;
			break;
		}
	}
	if(m%2&&!g&&flag)
	{
		b[x]=x;
		dfs2(x+1,true);
		b[x]=0;
	}
}
void dfs1(int x,bool g)
{
	if(x==n+1)
	{
		dfs2(1,false);
		return;
	}
	if(a[x])
	{
		dfs1(x+1,g);
		return;
	}
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		if(!a[y])
		{
			a[x]=y;
			a[y]=x;
			dfs1(x+1,g);
			a[x]=0;
			a[y]=0;
		}
	}
	if(n%2&&!g&&ispd(grid[x]))
	{
		a[x]=x;
		dfs1(x+1,true);
		a[x]=0;
	}
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>grid[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cnt[i][grid[i][j]-'a']++;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			bool flag=true;
			for(int k=0;k<26;k++)
				if(cnt[i][k]!=cnt[j][k])
				{
					flag=false;
					break;
				}
			if(flag)
			{
				v[i].pb(j);
				v[j].pb(i);
			}
		}
	dfs1(1,false);
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll t[105];

int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	FOR(i, a, b)
	{
		t[i] = 1;
	}
	FOR(i, c, d)
	{
		if (t[i] == 1) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Programming Education
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  if (n == 1) puts("Hello World");
  else {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a + b);
  }
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

summary = {}
for a in A:
    if a not in summary.keys():
        summary[a] = 1
    else:
        summary[a] += 1
s_list = list(summary.values())
s_list.sort()
res = 0
i = 0
while len(s_list)-i > K:
    res += s_list[i]
    i += 1
print(res)

Measured memory_bytes: 32264
S = input()
Q = int(input())

A=""
Z=""
AZFlag = 0
for i in range(Q):
    Que = input().split()

    if Que[0] == '1':
        if AZFlag == 0:
            AZFlag = 1
            continue

        if AZFlag == 1:
            AZFlag = 0
            continue

    if Que[0] == '2':
        if Que[1] == '1' and AZFlag == 0:
            A = Que[2]+A
            continue

        if Que[1] == '1' and AZFlag == 1:
            Z = Z+Que[2]
            continue
        
        if Que[1] == '2' and AZFlag == 0:
            Z = Z+Que[2]
            continue

        if Que[1] == '2' and AZFlag == 1:
            A = Que[2]+A
            continue


if AZFlag == 0:
    print(A+S+Z)
if AZFlag == 1:
    print(Z[::-1]+S[::-1]+A[::-1])




Measured memory_bytes: 4564
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int V[N], C[N];
  for(int i=0; i<N; i++) cin>>V[i];
  for(int i=0; i<N; i++) cin>>C[i];
  int sum=0;
  for(int i=0; i<N; i++) sum += (V[i]-C[i]>=0?V[i]-C[i]:0);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N>>M;
    vec L(N);
    rep(i,N) cin>>L.at(i);
    ll ans = 1;
    ll temp = 0;
    rep(i,N){
        temp += L.at(i);
        if(temp<=M) ++ans;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int N,M;

int main() {
  cin >>M >>N;
  vector<int> C(N); rep(i, N) cin >>C[i];
  sort(C.rbegin(), C.rend());
  vector<vector<int>> dp(N+1, vector<int>(M+1, 1000000000));
  // dp[i][j] := i枚目までのコインを使って合計をjにするのに必要なコインの最小枚数
  dp[0][0] = 0;
  for (int i=0; i<N; i++){
    for (int j=0; j<=M; j++){
      chmin(dp[i+1][j], dp[i][j]);
      if (j-C[i]>=0) chmin(dp[i+1][j], dp[i+1][j-C[i]] + 1);
    }
  }
  int res = dp[N][M];
  cout <<res <<endl;
}



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

min_div2count = 10 ** 12
for a in A:
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	min_div2count = min(min_div2count, count)

print(min_div2count)


Measured memory_bytes: 2940
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;

long gcd(long n,long m){
  long nn,mm;
  if(n > m){
    nn = n;
    mm = m;
  }
  else{
    nn = m;
    mm = n;
  }

  if(nn % mm == 0){
    return mm;
  }else{
    return gcd(mm,nn % mm);
  }
}

int main(){
  long n,ii,jj,min=LONG_MAX;
  vector<long> a,mm,nn;
  vector<long> right,left,max2;

  cin >> n;
  a.resize(n);
  mm.resize(n);
  nn.resize(n);
  right.resize(n + 2);
  left.resize(n + 2);
  max2.resize(n);
  for(ii=0;ii<n;ii++){
    cin >> a[ii];
    if(a[ii] < min){
      min = a[ii];
    }
    mm[ii] = 0;
    nn[ii] = 0;
  }

  left[0] = a[0];

  for(ii=1;ii<n;ii++){
    left[ii] = __gcd(left[ii-1],a[ii]);
    //cout << left[ii] << endl;
  }

  right[n-1] = a[n-1];

  for(ii=n-2;ii>=0;ii--){
    right[ii] = __gcd(right[ii+1],a[ii]);
    //cout << right[ii] << endl;
  }

  for(ii=0;ii<n;ii++){
    //cout << "ii:" << ii << "right" << right[ii] << "left" << left[ii] << endl;
  }

  for(ii=0;ii<n;ii++){
    if(ii == 0){
      max2[0] = right[1];
    }
    else if(ii == n -1){
      max2[ii] = left[ii-1];
    }
    else{
      max2[ii] = __gcd(left[ii-1],right[ii+1]);
    }
  }
  
  long max = 0;
  long change;
  long ret;

  for(ii=0;ii<n;ii++){
    if(max2[ii] > max){
      max = max2[ii];
    }
  }
  

  cout << max << endl;
  
  return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N;
	vector<int> exist;
	cin >> N;
	exist.resize(N,0);

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

	llong ans = 1;
	int cnt = 0;
	for(int i = 0; i < N; i++){
		if(exist[i] >= 3)
			ans = 0;
		else if(exist[i] == 1 && i != 0)
			ans = 0;
		else
			(ans *= max(1,exist[i])) %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	private static void p(String s) {System.out.println(s);}
	static Scanner sc = new Scanner(System.in);
	static int a,b,c,n,m;

	//<--main------------------------------------------------>
	public static void main(String[] args) {
	char c[]=sc.next().toCharArray();
	char last='0';
	int ans1=0;
	for(int i=0;i<c.length;i++) {
		if(c[i]==last) {
			if(last=='0') {
				last='1';
				ans1++;
			}else {
				last='0';
				ans1++;
			}
		}else {
			if(last=='0') {
				last='1';
			}else {
				last='0';
			}
		}
		}
	char last2='1';
	int ans2=0;
	for(int i=0;i<c.length;i++) {
		if(c[i]==last2) {
			if(last2=='0') {
				last2='1';
				ans2++;
			}else {
				last2='0';
				ans2++;
			}
		}else {
			if(last2=='0') {
				last2='1';
			}else {
				last2='0';
			}
		}
		}
	int ans=Math.min(ans1, ans2);
	p(""+ans);
	}

}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
using namespace std;
int i,s1,j=0,z=0;
string s;
int main(){
    cin>>s;
    for(i=0;i<s.size();i++){
        if(s[i]=='C') j=1;
        if(j && s[i]=='F') z=1;
    }
    if(z) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final long K = sc.nextLong();
			
			long X = 7;
			
			for(int times = 1; times <= 10000000; times++) {
				final long mod = X % K;
				
				if(mod == 0) {
					System.out.println(times);
					return;
				}else {
					X = (X * 10 + 7) % K;
				}
			}
			
			System.out.println("-1");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  for (int i = 0; i < 5; ++i) cin >> a[i];
  for (int i = 0; i < 5; ++i) {
    if (a[i] == 0) cout << i + 1;
  }

  return 0;
}



Measured memory_bytes: 3580
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
    string[] ss = readln.split;
    foreach (i, ref arg ; args) arg = ss[i].parse!int;
}

void main() {
    int a,b,c;
    scan(a,b,c);
    writeln(max(0, c - (a - b)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

const int MAX_V = 100000;

// 行き先toとコストcost
struct edge
{
    int to;
    int cost;
};
typedef pair<int, int> P; // firstは最短距離、secondは頂点の番号

// int V;
// vector<edge> graph[MAX_V]; // グラフ(隣接リスト)
// int d[MAX_V];              //最短距離

void dijkstra(int s, vector<vector<edge>> &graph, vector<int> &d, int V)
{
    priority_queue<P, vector<P>, greater<P>> pq;
    fill(d.begin(), d.begin() + V, INF);
    d[s] = 0;
    pq.push(P(0, s));

    while (!pq.empty())
    {
        P p = pq.top(); // 未確定の中から確定させた頂点
        pq.pop();
        int v = p.second; // 取り出した頂点の番号
        // もう探索する必要のない経路がpqに残っていた場合は枝刈り
        if (d[v] < p.first)
        {
            continue;
        }

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E, r;
    cin >> V >> E >> r;
    vector<vector<edge>> g(V);
    for (int i = 0; i < E; i++)
    {
        int s, t, d;
        cin >> s >> t >> d;
        g[s].push_back(edge{t, d});
    }
    vector<int> dist(V);
    dijkstra(r, g, dist, V);
    for (auto ans : dist)
    {
        cout << (ans == INF ? "INF" : to_string(ans)) << endl;
    }
}


Measured memory_bytes: 12836
n = int(input())
ans = 1
l = list(map(int, input().split()))
l.sort()
for i in range(n):
    x = l[i]
    ans *= x
    if ans == 0:
        print(0)
        exit()
    if ans > 10**18:
        print(-1)
        exit()
print(ans if ans <= 10**18 else -1)

Measured memory_bytes: 21784
s = input()
from string import ascii_lowercase
a = ascii_lowercase
if s == a[::-1]:
  print(-1)
else:
  if len(set(s))<26:
    for ele in a:
      if ele not in s:
        print(s+ele)
        break
  else:
    suf=[s[-1]]
    for i in range(25, 0, -1):
      if s[i]<s[i-1]:
        suf.append(s[i-1])
      else:
        last = i-1
        break
    suf.sort()
    for i in range(len(suf)):
      if s[last]<suf[i]:
        print(s[:last]+suf[i])
        break

Measured memory_bytes: 3892