akhauriyash/Code-Regression huggingface dataset:
# A 
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a=nl()

if 1 in a and 9 in a and 7 in a and 4 in a:
    print('YES')
else:
    print('NO')



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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a)) 
#define all(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll d;
	cin >> d;
	if(d==22) cout << "Christmas Eve Eve Eve";
	if(d==23) cout << "Christmas Eve Eve";
	if(d==24) cout << "Christmas Eve";
	if(d==25) cout << "Christmas";
	return 0;
}
/* The judge is never wrong! Your code is buggy 
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,a,b,c,d;

// dp[i][j] : 残りi人をj人以下のグループで構成する方法
// dp[i][j] = dp[i][j-1] + dp[i-j][j-1] * iCj + dp[i-2j][j-1] * iC2j / 2! + ...
ll dp[1252][1252];

ll fact[1252];
void extgcd(int a,int b,int &x,int &y){
  int g=a;x=a;y=0;
  if(b!=0){
    extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }
}
int inv(int x){
  int m = MOD;
  int a,b;
  extgcd(x,m,a,b);
  return (a+MOD)%MOD;
}
ll ifact[1252];
ll comb(ll a,ll b){
  return fact[a]*ifact[b]%MOD*ifact[a-b]%MOD;
}

int main(){
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  fact[0] = 1;
  FOR(i,1,1252)fact[i]=fact[i-1]*i%MOD;
  FOR(i,0,1252)ifact[i]=inv(fact[i]);

  REP(j,b+1)dp[0][j] = 1;
  FOR(i,1,n+1)FOR(j,a,b+1){
    dp[i][j] = dp[i][j-1];
    ll mul = 1;
    FOR(k,1,d+1){
      if(i-k*j>=0){
        mul = mul * comb(i-(k-1)*j,j) % MOD;
        if(k<c)continue;
        dp[i][j] += dp[i-k*j][j-1] * mul % MOD * ifact[k] % MOD;
        if(dp[i][j]>=MOD)dp[i][j]-=MOD;
      }
    }
  }
  printf("%lld\n",dp[n][b]);
  return 0;
}


Measured memory_bytes: 10112
package main

import (
	"bufio"
	"fmt"
	"strconv"
	"strings"
	"os"
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func readInt(sc *bufio.Scanner) (res int) {
	res, _ =strconv.Atoi(readLine(sc))
	return
}

func readInts(sc *bufio.Scanner, n int) []int {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int, n)

	for i, n := range ns {
		res[i], _ = strconv.Atoi(n)
	}
	return res
}

func readInt64s(sc *bufio.Scanner, n int) []int64 {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int64, n)

	for i, n := range ns {
		res[i], _ = strconv.ParseInt(n, 10, 64)
	}
	return res
}

func readMatrix(sc *bufio.Scanner, rows, cols int) [][]int {
	res := make([][]int, rows)
	for i := 0; i < rows; i ++ {
		res[i] = readInts(sc, cols)
	}
	return res
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	xs := readInt64s(sc, 2)

	n := xs[0]
	m := xs[1]

	if (2 * n <= m) {
		fmt.Println((n * 2 + m) / 4)
	} else {
		fmt.Println(m / 2)
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

int fib(int n, int dp[]) {
  if (dp[n] != -1) return dp[n];
  else {
    dp[n] = fib(n - 1, dp) + fib(n - 2, dp);
    return dp[n];
  }
}

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

  int n;
  cin >> n;
  int dp[n+1];
  REP(i, n+2) {
    if (i == 0 || i == 1) dp[i] = 1;
    else dp[i] = -1;
  }

  cout << fib(n, dp) << endl;
}

Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        System.out.println(String.format("%.6f",r*r*Math.PI) + " " + String.format("%.6f",2*r*Math.PI));
    }
}


Measured memory_bytes: 28316
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int ans = 0;
        Map<Integer, Integer> l2 = new HashMap<Integer, Integer>();
        for(int i = 0;i < N;i++){
            int a = sc.nextInt();
            if(l2.containsKey(a))   l2.put(a, l2.get(a)+1);
            else    l2.put(a, 1);
        }
        for(Integer key : l2.keySet()){
            int v = l2.get(key);
            if(key <= v)    ans += v-key;
            else    ans += v;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 63244
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l[q],r[q];
    for(int i = 0;i<q;i++){
        cin >> l[i] >> r[i];
    }
    int rs[s.size()];
    rs[0] = 0;
    for(int i = 1;i<s.size();i++){
        if(s[i] == 'C' && s[i-1] == 'A'){
            rs[i] = rs[i-1] + 1;
        }
        else{
            rs[i] = rs[i-1];
        }
    }
    for(int i = 0;i<q;i++){
        cout << rs[r[i]-1] - rs[l[i] - 1] << endl;
    }
}

Measured memory_bytes: 2240
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int N, M, count, ans = 0;
	set<string>ss;

	cin >> N;
	vector<string> s1(N);
	rep(i, 0, N)
	{
		cin >> s1[i];
		ss.insert(s1[i]);
	}
	cin >> M;
	vector<string> s2(M);
	rep(i, 0, M)
	{
		cin >> s2[i];
	}
	
	for (string x : ss)
	{
		count= 0;
		rep(i, 0, N)if (x == s1[i])count++;
		rep(i, 0, M)if (x == s2[i])count--;
		ans = max(ans, count);
	}
	cout << ans << endl;
	return 0;
}

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

int n;
int graph[100][100];
int d[100];
int f[100];

// 時刻
int cnt;

// 0:未探索 1:探索中 2:探索終わり
int visited[100];

void dfs(int i) {
  // 探索開始
  visited[i] = 1;
  d[i] = ++cnt;
  for (int j = 0; j < n; j++) {
    if (graph[i][j] == 0) {
      continue;
    }
    // 再帰
    if (visited[j] == 0) {
      dfs(j);
    }
  }
  visited[i] = 2;
  f[i] = ++cnt;
}

int main() {

  cin >> n;

  // 各変数を初期化
  cnt = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      graph[i][j] = 0;
    }
    visited[i] = 0;
    d[i] = 0;
    f[i] = 0;
  }

  // 入力を受け取る
  for(int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;
      graph[u - 1][v - 1] = 1;
    }
  }

  // 探索
  for (int i = 0; i < n; i++) {
    if(visited[i] == 0) {
      dfs(i);
    }
  }

  // 探索結果を出力
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }

  return 0;

}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int L,R,d;
  cin>>L>>R>>d;
  int ans=0;
  for(int i=L;i<=R;i++)
  {
    if(i%d==0)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

int n, d[50];
int main(){
  cin >> n;
  for(int i=0;i<n;i++) cin >> d[i];
  
  int s1 = 0, s2 = 0;
  for(int i=0;i<n;i++){
    s1 += d[i];
    s2 += d[i] * d[i];
  }
  cout << (s1 * s1 - s2) / 2 << endl;
  return 0;
}
  

Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e) int i; for(int i=s;i<=e;i++)
#define repd(i,s,e) int i; for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    read(n);
    string k = to_string(n);
    loop(i,3){
    	if(k[i]=='7'){
    	cout<<"Yes"<<endl;
    	return 0;
    	}
    }
    cout<<"No"<<endl;
    
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 3708
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<usize> = (0..n).map(|_| input()).collect();

    let mut c = vec![0; 3];
    for a in a {
        c[a - 1] += 1;
    }
    let (c1, c2, c3) = (c[0], c[1], c[2]);

    let mut m = vec![vec![vec![-1.0; n + 1]; n + 1]; n + 1];
    dfs(n, c1, c2, c3, &mut m);

    println!("{}", m[c1][c2][c3]);
}

fn dfs(n: usize, c1: usize, c2: usize, c3: usize, m: &mut Vec<Vec<Vec<f64>>>) -> f64 {
    if m[c1][c2][c3] >= 0.0 {
        m[c1][c2][c3]
    } else if (c1, c2, c3) == (0, 0, 0) {
        0.0
    } else {
        let mut p = 1.0;
        if c1 > 0 {
            p += c1 as f64 / n as f64 * dfs(n, c1 - 1, c2, c3, m);
        }
        if c2 > 0 {
            p += c2 as f64 / n as f64 * dfs(n, c1 + 1, c2 - 1, c3, m);
        }
        if c3 > 0 {
            p += c3 as f64 / n as f64 * dfs(n, c1, c2 + 1, c3 - 1, m);
        }
        p /= (c1 + c2 + c3) as f64 / n as f64;

        m[c1][c2][c3] = p;
        p
    }
}


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

using namespace std;

int n, ans;
string a, b, c;

int main(){
	scanf("%d", &n);
	cin >> a >> b >> c;
	for(int i = 0; i < n; i++){
		if(a[i] == b[i]){
			ans += (a[i] != c[i]);
		}else{
			ans += 1 + (a[i] != c[i] && b[i] != c[i]);
		}
	}
	printf("%d\n", ans);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
int main(){
	int N;
	cin >> N;
	int ans = N*800 - 200 * (N/15);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long A=0;
    long B=0;
    long n =0;
    long num=0;
    long C =0;
    long D =0;
    long amari=1;
    vector <int> L(1, 1); //可変長配列
    cin >> A >> B;
    //num = gcd(A, B);
    C = max(A, B);
    D = min(A, B);
    while(amari !=0){
        amari = C%D;
        C = D;
        D = amari;
    }
    num = C;
    
    n = sqrt(C);
    for (long i =2; i<n+1; i++){
        while(num % i ==0){
            if (num % i ==0){
                num = num/i;
                if (find(L.begin(), L.end(), i) ==L.end()){
                    L.push_back(i); //追加
                }
            }
        }
    }
    if(num>1){
        L.push_back(num);
    }
    cout << L.size();
}

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

int main(){
    string S, T;
    cin >> S >> T;

    int count = 0;

    for(int i = 0; i < 3; i++){
        if(S[i] == T[i]){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,q,t;
    int count=0;
    int S[10000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>t;
        for(int j=0;j<n;j++){
            if(S[j]==t) {
            count++;
            break;
            }
        }    
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできるよ
//時間をかけすぎない
//コードテストちゃんとして
//画面とにらめっこするな

//以下回答
int main(){
    ll N,M;
    cin>>N>>M;
    ll count=0;
    vvl vec(M,vl(N));
    vl p(M);
    rep(i,M){
        ll k;
        cin>>k;
        vec.at(i).resize(k);
        rep(j,k){
            cin>>vec.at(i).at(j);
        }
    }
    rep(i,M){
        cin>>p.at(i);
    }
    vl sw(N,0);
    for (ll bit=0;bit<(1<<N);++bit){
        rep(i,N){
            if(bit&(1<<i)){
                sw.at(i)=1;
            }else{
                sw.at(i)=0;
            }
        }
        bool check=false;
        rep(i,M){
            ll res=0;
            rep(j,vec.at(i).size()){
                if(sw.at(vec.at(i).at(j)-1)==1){
                    res++;
                }
            }
            if(res%2!=p.at(i)){
                check=true;
                break;
            }
        }
        if(check){
            continue;
        }else{
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long int
using namespace std;
const ll mod=1000000007;
const int MAX=1e5+5;
vector<int>polaczenia[MAX];
bool odwiedzony[MAX];
long long int dp[MAX][2];

void dfs(int n)
{
    int s=0;
    for (int i=0;i<polaczenia[n].size();i++)
    {

        int l=polaczenia[n][i];
        if (!odwiedzony[l])
        {
            s++;
            odwiedzony[l]=1;
            dfs(l);
            dp[n][0]=(dp[n][0]*dp[l][1])%mod;
            dp[n][1]=(dp[n][1]*(dp[l][0]+dp[l][1]))%mod;
        }
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        dp[i][0]=1;
        dp[i][1]=1;
    }
    for (int i=0;i<n-1;i++)
    {
       int a,b;
       scanf("%d%d",&a,&b);
       polaczenia[a].pb(b);
       polaczenia[b].pb(a);
    }
    odwiedzony[1]=true;
    dfs(1);
    printf("%lld",(dp[1][0]+dp[1][1])%mod);

    return 0;
}


Measured memory_bytes: 12928
#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 Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N;
    if(N == 3){
        cout<<2<<' '<<5<<' '<<63<<endl;
    }else if(N <= 24){
        vec ans = {2,3,4,9};
        rep(i, N - 4) ans.push_back((i+1)*6);
        rep(i, ans.size()){
            cout<<ans[i];
            i == ans.size() - 1 ? cout<<endl : cout<<' ';
        }
    }else{
        ll num_6 = min(2500LL, N/6);
        vec ans(0);
        rep(i, num_6 * 2) rep(j, 3) ans.push_back(i*6 + j + 2);
        ll rest = N - ans.size();
        rep(i, rest) ans.push_back((i+1) * 6);
        rep(i, ans.size()){
            cout<<ans[i];
            i == ans.size() - 1 ? cout<<endl : cout<<' ';
        }
    }
}

Measured memory_bytes: 640
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A=np.array(A)
    meanA=np.mean(A)
    A1=np.abs(A-meanA)
    print(np.argmin(A1))


if __name__=='__main__':
    main()

Measured memory_bytes: 12504
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

const double EPS = 1e-10;
int N;
ll A[int(2e5 + 5)], B[int(2e5 + 5)];
pair <double, int> P[int(2e5 + 5)];

ll GCD(ll a, ll b){
	if (a < b) swap(a, b);
	if (b == 0) return 1;
	while (a % b != 0){
		a %= b; swap(a, b);
	}
	return b;
}

ll Pow(ll a, ll n){
	if (n == 0) return 1;
	else if (n % 2 == 0) return Pow(a * a % MOD, n / 2);
	else return a * Pow(a * a % MOD, n / 2) % MOD; 
}

map <Pll, int> cnt;
map <Pll, bool> visited;

int main(){
	scanf("%d", &N);
	for (int i = 0; i < N; i++){
		scanf("%lld%lld", A + i, B + i);
		ll G = GCD(abs(A[i]), abs(B[i]));
		A[i] /= G; B[i] /= G;
		cnt[mp(A[i], B[i])]++;
	}

	vector <Pll> Count;
	ll ZeroA = 0, ZeroB = 0, Zero = cnt[mp(0, 0)];
	visited[mp(0, 0)] = true;
	for (int i = 0; i < N; i++){
		Pll P = mp(A[i], B[i]);
		if (visited[P]) continue;
		visited[P] = true;

		if (P.fi == 0){
			ZeroA += cnt[P]; continue;
		}
		if (P.se == 0){
			ZeroB += cnt[P]; continue;
		}

		Pll P1 = mp(-1 * A[i], -1 * B[i]);
		Pll next1 = mp(B[i], -1 * A[i]);
		Pll next2 = mp(-1 * B[i], A[i]);

		Count.push_back(mp(cnt[P] + cnt[P1], cnt[next1] + cnt[next2]));
		visited[P1] = true;
		visited[next1] = true;
		visited[next2] = true;
	}
	Count.push_back(mp(ZeroA, ZeroB));

	ll ans = 1;
	for (int i = 0; i < Count.size(); i++){
		ll now = Pow(2, Count[i].fi) + Pow(2, Count[i].se) - 1;
		now %= MOD;
		ans *= now; ans %= MOD;
	}
	ans += Zero - 1; ans %= MOD;
	if (ans < 0) ans += MOD;
	printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 109480
#!/usr/bin/python

from sys import stdin

def eval(ds, ops):
  e = ds[0]
  for i in range(1, len(ds)):
    e = e + (ds[i] if ops[i - 1] == '+' else -ds[i])
  return e

def solve(ds):
  ops = ['+', '-']
  for op1 in ops:
    for op2 in ops:
      for op3 in ops:
        if eval(ds, [op1, op2, op3]) == 7:
          return str(ds[0])+op1+str(ds[1])+op2+str(ds[2])+op3+str(ds[3])+"=7"

ABCD = stdin.readline().strip()
ds = [int(ABCD[i]) for i in range(len(ABCD))]
print(solve(ds))


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

int main(void){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0; i<n; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();

        int b = scan.nextInt();

        if(a<b){
            System.out.println("a < b");
        }
        if(a>b){
            System.out.println("a > b");
        }
        if(a==b){
            System.out.println("a == b");
        }    
      }
}



Measured memory_bytes: 26176
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
    int ans[100000]={0};
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                ans[((i+j)*(i+j)+(i+k)*(i+k)+(j+k)*(j+k))/2]++;
            }
        }
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}

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

int n;
int tate[300][301];	//[x][y?´????]
int yoko[301][300];	//[x?´????][y]

int tateSum(int x,int y0,int y1){return tate[x][y1+1]-tate[x][y0];}
int yokoSum(int x0,int x1,int y){return yoko[x1+1][y]-yoko[x0][y];}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		tate[i][0]=0;
		yoko[0][i]=0;
	}
	int tmp;
	for(int y=0;y<n;y++){
		for(int x=0;x<n;x++){
			cin>>tmp;
			tate[x][y+1]=tate[x][y]+tmp;
			yoko[x+1][y]=yoko[x][y]+tmp;
		}
	}
	
	int ans=-114514810;
	int koMax;
	int ko;
	
	int i,j,k;
	for(i=0;i<n;i++){
	for(j=i;j<n;j++){
		koMax=-114514810;
		for(k=0;k<n;k++){
			if(i==j){	//?¨???????
				ko=yokoSum(k,k,i);
				koMax=max(koMax+yokoSum(k,k,i),ko);
				ans=max(ans,koMax);
			}else{	//????????\???
				ko=tateSum(k,i,j);
				ans=max(ans,max(koMax+ko,ko));
				koMax=max(koMax+yokoSum(k,k,i)+yokoSum(k,k,j),ko);
			}
		}
	}
	}

	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char s[3];
    cin>>s;
    sort(s,s+3);
    if(s[0]=='a'&&s[1]=='b'&&s[2]=='c')
      cout<<"Yes";
    else 
    cout<<"No";
}   
    
    
     

     
   





Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll memo[64];

ll fib(int n){
    if(memo[n]!=-1) return memo[n];
    if(n==0 or n==1) return memo[n]=1;

    return memo[n] = fib(n-1) + fib(n-2);
}

int main(){
    rep(i,64) memo[i]=-1;

    int n;
    cin >> n;
    cout << fib(n) << endl;
}

Measured memory_bytes: 3076
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
	int a,b,c;
	String s = buf.readLine();
	String[] strlAry =s.split(" ");
	for(int i=0;i<strlAry.length;i++){
	}	
	a= Integer.parseInt(strlAry[0]);
	b= Integer.parseInt(strlAry[1]);
	c= Integer.parseInt(strlAry[2]);

	if(a<b&&b<c){
		System.out.println("Yes");
		}
	else{
		System.out.println("No");
	}

	}
}

Measured memory_bytes: 17060
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader(System.in);
        StringBuilder sb = new StringBuilder();
        int i,j;
       long m=in.nextInt();
       int n=in.nextInt();
       for(i=0;i<n;i++){
           m=m-in.nextInt();
       }
       if(m<0)
           System.out.println("-1");
       else
           System.out.println(m);
    }
}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c !=10 && c!=13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
    char nextChar() throws IOException{
        int c;
        for (c = scan(); c <= 32; c = scan());
        return (char)c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}


Measured memory_bytes: 32380
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

#define rep1(i,x) for(ll i=1;i<=(x);++i)

ll imos[100002];
ll P[100002];
ll A[100002], B[100002], C[100002];

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

	ll N, M; cin >> N >> M;

	cin >> P[0];
	ll pre = P[0];

	rep1(i, M - 1) {
		cin >> P[i];
		if (pre < P[i]) {
			imos[pre]++; imos[P[i]]--;
		} else {
			imos[P[i]]++; imos[pre]--;
		}

		pre = P[i];
	}

	rep1(i, N - 1) {
		cin >> A[i] >> B[i] >> C[i];
	}

	long long ans = 0;

	rep1(i, N - 1) {
		imos[i] += imos[i - 1];
		ans += min(A[i] * imos[i], C[i] + B[i] * imos[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 5100
H, W = gets.split.map(&:to_i)
MAP = H.times.map{
  gets.chomp.chars.map{|c| c == "." ? Float::INFINITY : c}
}

DIRS = [[0, 1], [0, -1], [1, 0], [-1, 0]]
def get(x, y)
  if 0 <= x && x < W && 0 <= y && y < H
    MAP[y][x]
  else
    nil
  end
end

def dump
  MAP.each do |row|
    row.each do |c|
      print case c
      when String
        c
      when Float::INFINITY
        "_"
      else
        c.inspect
      end
    end
    puts
  end
  puts
end

def solve
  MAP[0][0] = "v"
  q = [[0, 0, [[0, 0]]]]
  until q.empty?
    x, y, route = *q.shift
    #p current: [x, y, route], q: q
    if x == W-1 && y == H-1
      MAP[y][x] = "v"
      return route
    end
    case get(x, y)
    when "#", nil
      next
    else
      DIRS.each do |dx, dy|
        nx, ny = x+dx, y+dy
        nn = get(nx, ny)
        if nn == Float::INFINITY
          MAP[ny][nx] = "v"
          q.push [nx, ny, route + [[nx, ny]]]
        end
      end
    end
    #dump
  end
end

route = solve
if MAP[H-1][W-1] == Float::INFINITY
  p(-1)
else
  route.each do |x, y|
    MAP[y][x] = "o"
  end
  p MAP.map{|row|
    row.count{|c| c == "v" || c == Float::INFINITY }
  }.inject(:+)
end


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

typedef long long int lli;

int main(){
	lli n;
	cin >> n;
	
	for(lli i=1; i<=3500; i++){
		for(lli j=1; j<=3500; j++){
			if(4*i*j != (i+j)*n && i*j*n % (4*i*j-(i+j)*n) == 0){
				lli k = i*j*n / (4*i*j-(i+j)*n);
				if(k<=0) continue;
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	return -1;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    a = list(map(str, input().split()))

    d = dict()
    for i in range(n):
        if a[i] in d:
            d[a[i]] = d[a[i]] + 1
        else:
            d[a[i]] = 1

    total = 0
    normal = dict()
    target = dict()
    for k, v in d.items():
        if v == 1:
            normal[k] = 0
            target[k] = 0
        else:
            normal[k] = (v-1) * ((v-1) + 1) // 2
            target[k] = normal[k] - (v-1)
            total += normal[k]

    for i in range(n):
        print(total - normal[a[i]] + target[a[i]])


main()


Measured memory_bytes: 94164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct item
{
    int wt;
    int val;
};
ll solve(vector<struct item>v,int n,int w)
{
    ll dp[n+1][w+1]{};
    dp[1][v[1].wt]=v[1].val;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=w;j++ )
        {
            dp[i][j]=dp[i-1][j];
            if(j<v[i].wt)
            continue;
            dp[i][j]=max(dp[i][j],dp[i-1][j-v[i].wt] +v[i].val);
        }
    }
    return *(max_element(dp[n],dp[n]+w+1));
}

int main()
{
    int n,w;
    cin>>n>>w;
 vector< item>v(n+1);
 for (int i = 1; i <= n; i++)
 {
     cin>>v[i].wt>>v[i].val;
     /* code */
 }
  cout<<solve(v,n,w);
  return 0;
 
}

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


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

    int n,m;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n-1){
        cin >> a[i];
        b[a[i]-1]++;
    }
    rep(i,n) cout << b[i] << endl;

    return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 1000000000

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int V,vector<vector<edge> >& graph) {
	priority_queue<Node> q;
	vector<int> d(100000);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	for (int i = 0;i < V;i++) {
		if (d[i] == INF) {
			cout << "INF"<<endl;
		}
		else cout << d[i] << endl;
	}


}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int main() {
	int V, E, r;
	cin >> V >> E >> r;
	vector<vector<edge> > graph(100000);
	for (int i = 0;i < E;i++) {
		int s, t, d;
		cin >> s >> t >> d;
		graph[s].push_back(edge(t,d));
	}
	dijkistra(r, V, graph);
	
}

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

Measured memory_bytes: 11292
#include <stdio.h>

int main(void)
{
  int h, w, i, j, k, c, d;
  char a[100][100];
  scanf("%d %d", &h, &w);
  for (i = 0; i < h; i++)
    scanf("%s", a[i]);
  for (i = 0; i < h; i++) {
    int d = 0;
    for (j = 0; j < w; j++) {
      c = 0;
      for (k = 0; k < h; k++)
	if (a[k][j] == '#') {
	  c++;
	  break;
	}
      for (k = 0; k < w; k++)
	if (a[i][k] == '#') {
	  c++;
	  break;
	}
      if (c == 2) {
	 printf("%c", a[i][j]);
	 d++;
      }
    }
    if (d != 0)
      printf("\n");
  }
}


Measured memory_bytes: 128
a = input()
b = input().split()
b = [int(x) for x in b]
X = []
for i in range(len(b) - 1):
    if b[i + 1] <= b[i]:
        X.append(b[i] - b[i + 1])
        b[i + 1] = b[i + 1] + b[i] - b[i + 1]
print(sum(X))

Measured memory_bytes: 32192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int ans = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
//
//		int[] array = new int[n];
//		for (int i = 0; i < n; i++) {
//			array[i] = sc.nextInt();
//		}
		int k = Math.abs(n-d);

		if(k % 2 == 0) {
			if(n < d) {
				System.out.println(n+(k/2));
			} else {
				System.out.println(d+(k/2));
			}
		} else {
			System.out.println("IMPOSSIBLE");
		}

		sc.close();
	}
}


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

int main(){
    string S;
    cin >> S;
    for (int i = 0; i < (int)S.size()-1; i++) {
        if (S.substr(i, 2) == "AC") {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll N;
  cin >> N;
  ll a=0,b=0,ab=0;
  ll cnt = 0;
  rep(i,N){
    string s;
    cin >> s;
    for(ll j=0;j<s.size()-1;j++){
      if(s[j]=='A' && s[j+1]=='B'){
        cnt++;
      }
    }
    if(s[0]=='B' && s[s.size()-1]=='A') ab++;
    else if(s[s.size()-1]=='A') a++;
    else if(s[0]=='B') b++;

  }
  if(ab>0){
    cnt += (ab-1);
    if(b>0) a++;
    if(a>0) b++;
  }

  cout << cnt+min(a,b) << endl;
}


Measured memory_bytes: 256
#prag\
ma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define N 55
using namespace std;
int H,W,graph[N][N],dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
bool visited[N][N];
char s[N];
struct node
{
	int x,y,step;
};
queue <node > Q;
int main()
{
	scanf("%d%d",&H,&W);
	int cnt=0;
	for(int i=1;i<=H;++i)
	{
		scanf("%s",s);
		for(int j=1;j<=W;++j)
			if(s[j-1]=='.') graph[i][j]=1,++cnt; else graph[i][j]=0; 
	}
	if(!graph[1][1] || !graph[H][W])
	{
		printf("-1\n");
		return 0;	
	}
	node tmp; tmp.x=tmp.y=tmp.step=1; Q.push(tmp); visited[1][1]=true;
	while(!Q.empty())
	{
		int _x=Q.front().x,_y=Q.front().y,_step=Q.front().step; Q.pop();
		for(int i=0;i<4;++i)
		{
			int tx=_x+dir[i][0],ty=_y+dir[i][1];
			if(tx>0 && tx<=H && ty>0 && ty<=W && !visited[tx][ty] && graph[tx][ty])
			{
				visited[tx][ty]=true;
				tmp.x=tx; tmp.y=ty; tmp.step=_step+1; Q.push(tmp);
				if(tx==H && ty==W)
				{
					printf("%d\n",cnt-tmp.step);
					return 0;
				}
			}
		}
	}
	printf("-1\n");
	return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

template<typename T>
using reversed_priority_queue = \
    std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll INF = 1ll << 60;

signed main() {
    ll K;
    cin>>K;
    vector<vector<PLL>> edges(K); // edges[k]: first: コスト second: 次の頂点
    rep(i,0,K){
        // 頂点i の次は、コスト1で(i+1)%K 
        // あるいは、    コスト0で(i*10)%K
        edges[i].push_back({1, (i+1)%K});
        edges[i].push_back({0, (i*10)%K});
    }

    vector<ll> dist(K, INF);
    reversed_priority_queue<PLL> q;
    q.push({1,1}); // 整数1は、最小で1回の加算で作れる
    while(!q.empty()){
        ll d = q.top().first;
        ll id = q.top().second;
        q.pop();
        if (d < dist[id]) {
            dist[id] = d;
            for(auto e: edges[id]){
                q.push({e.first + d, e.second});
            }
        }
    }
    cout<<dist[0]<<endl;
    return 0;
}


Measured memory_bytes: 10228
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
u = sum(b)
for i in range(1,n):
    if a[i] - a[i-1] == 1:
        u = u + c[a[i]-2]
print(u)

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

int main(){
	long long int a, b;
	int c1000, c500, c100;

	while(cin >> a >> b, a || b){
		b -= a;
		c1000 = b / 1000;
		b -= 1000 * c1000;
		c500 = b / 500;
		b -= 500 * c500;
		c100 = b / 100;

		cout << c100 << " " << c500 << " " << c1000 << endl;
	}
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ1043
{
    class Program
    {
        private static void Main()
        {
            foreach (var sortedTeams in from teams in ReadInputs()
                                        select (from team in teams
                                                orderby team.Id ascending
                                                orderby team.Penalty ascending
                                                orderby team.Correct descending
                                                select team).ToList())
            {
                var picked = new List<Team>();
                foreach (var team in sortedTeams)
                {
                    var sameAffiliation = picked.Count(t => t.Affiliation == team.Affiliation);

                    if (picked.Count < 10)
                    {
                        if (sameAffiliation < 3)
                        {
                            picked.Add(team);
                        }
                    }
                    else if (picked.Count < 20)
                    {
                        if (sameAffiliation < 2)
                        {
                            picked.Add(team);
                        }
                    }
                    else if (picked.Count < 26)
                    {
                        if (sameAffiliation == 0)
                        {
                            picked.Add(team);
                        }
                    }
                }

                foreach (var team in picked)
                {
                    Console.WriteLine(team.Id);
                }
            }
        }

        public static IEnumerable<Team[]> ReadInputs()
        {
            while (true)
            {
                var count = int.Parse(Console.ReadLine() ?? "");
                if (count == 0) yield break;

                var teams = new Team[count];

                for (var i = 0; i < count; i++)
                {
                    var values = (Console.ReadLine() ?? "").Split(' ').Select(int.Parse).ToArray();
                    teams[i] = new Team(values[0], values[1], values[2], values[3]);
                }

                yield return teams;
            }
        }
    }

    public class Team
    {
        public int Id { get; private set; }
        public int Affiliation { get; private set; }
        public int Correct { get; private set; }
        public int Penalty { get; private set; }

        public Team(int id, int affiliation, int correct, int penalty)
        {
            Id = id;
            Affiliation = affiliation;
            Correct = correct;
            Penalty = penalty;
        }
    }
}

Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  cout << min(a, b) << " " << max((a+b) - n, 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 123;
const int mod = (int)1e9 + 7;

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int n, a, b;
    cin >> n >> a >> b;
    if (a > b) {
        cout << "0\n";
        return 0;
    }
    if (n == 1) {
        cout << (a == b ? 1 : 0) << endl;
        return 0;
    }
    ll maxi = 0ll + a + 1ll * (n - 1) * b;
    ll mini = 0ll + b + 1ll * (n - 1) * a;
    cout << maxi - mini + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	long long n, k,ans;
	long long x,y,z;
	ans = 0;
	scanf("%lld %lld", &n,&k);
	if (k == 0){
		ans = n*n;
		printf("%lld\n", ans);
		return 0;
	}
	else{
		for (long long i = 2; i <= n; i++){
			if (i > k){
				x = i;
				y = n / x;
				ans += ((x - k)*y);
				z = n % x;
				if (k <= z){
					ans += (z - k + 1);
				}
			}
		}

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

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  }
}


Measured memory_bytes: 94408
#include <stdio.h>
typedef struct _Player
{
	int no;
	double time;
}Player;

Player ExtractTop(Player player[], int from, int to)
{
	int i;
	int minNo=from;
	Player top;
	for(i=from+1; i<=to; i++)
	{
		if(player[i].time < player[minNo].time)
			minNo = i;
	}
	top.no   = player[minNo].no;
	top.time = player[minNo].time;
	player[minNo].time = 999;
	return top;
}

void ExtractTop2(Player player[], int from, int to, Player top[2])
{
	top[0] = ExtractTop(player, from, to);
	top[1] = ExtractTop(player, from, to);
}

int main(void)
{
	//FILE* f=fopen("in.txt", "r");
	int i, cls, minNo;
	Player player[24];
	Player top[4][2];

	for(i=0; i<24; i++)
	{
		//fscanf(f, "%d %lf", &player[i].no, &player[i].time);
		scanf("%d %lf", &player[i].no, &player[i].time);
	}
	
	for(cls=0; cls<3; cls++)
		ExtractTop2(player, cls*8, cls*8 +7, top[cls]);
	ExtractTop2(player, 0, 23, top[3]);
	
	for(cls=0; cls<4; cls++)
	for(i=0; i<2; i++)
	{
		printf("%d %.2f\n", top[cls][i].no, top[cls][i].time);
	}
	//fclose(f);

	return 0;
}

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

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

int main()
{
    long N, M;
    cin >> N >> M;
    long long A[N];
    rep(i, N){
        cin >> A[i];
    }
    long long sum = 0;
    rep(i, N){
        sum += A[i];
    }
    long long count = 0;
    rep(i, N){
        if(sum <= (A[i] * 4 * M)){
            count++;
        }
    }

    if(count >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e3+5;
const ll inf=1e18;
int main()
{
    int n;
    cin >> n;
    ll t;
    long double ans = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        if (ans != -1)
            ans *= t;
        if (ans > 1000000000000000000 || ans < 0)
            ans = -1;
        if (t == 0)
            ans = 0;
    }
    cout << (ll)ans;
    return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  if(s.size()==t.size()){
    for(int i=0;i<s.size();i++){
      cout<<s.at(i)<<t.at(i);
    }
    cout<<endl;
  }
  if(s.size()!=t.size()){
    for(int i=0;i<s.size()-1;i++){
      cout<<s.at(i)<<t.at(i);
    }
    cout<<s.at(s.size()-1)<<endl;
  }
}

Measured memory_bytes: 256