akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI 3.14159265358979

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<lli> a(n);
	vector<lli> f(n);

	REP(i,0,n)cin>>a[i];
	REP(i,0,n)cin>>f[i];

	sort(a.begin(),a.end());
	sort(f.rbegin(),f.rend());

	lli minScore = 0;
	lli maxScore = 1e13;

	if(DEBUG){
		REP(i,0,n)cout<<a[i]<<" ";
		cout<<endl;
		REP(i,0,n)cout<<f[i]<<" ";
		cout<<endl;
	}
	while(1){
		lli middle = (maxScore+minScore)/2;

		if(DEBUG)cout<<"middle="<<middle<<endl;

		vector<lli> ans;
		REP(i,0,n){
			ans.push_back(middle/f[i]);
		}
		sort(ans.begin(),ans.end());
		lli diff=0;
		REP(i,0,n){
			if(DEBUG)cout<<"i="<<i<<" ans[i]="<<ans[i]<<endl;
			if(ans[i]<=a[i]){
				diff += a[i] - ans[i];
			}
		}
		/*成功*/
		if(DEBUG)cout<<"diff="<<diff<<endl;
		if(diff <=k){
			maxScore = middle;
		}
		else{//失敗
			minScore = middle+1;
		}
		if(minScore>=maxScore){
			cout<<minScore<<endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 7028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    double ans=w*h/2.0;
    cout<<setprecision(15)<<ans<<' ';
    if(x==w/2 && y==h/2) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
k=int(input())
List=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(List[k-1])

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {
  private static void solve() {
    int n = ni();
    int k = ni();
    int[][] p = ntable(n, 2);
    Arrays.sort(p, (o1, o2) -> o2[1] - o1[1]);
    
    Set<Integer> eat = new HashSet<>();
    long[] sum = new long[n];
    int ptr = 0;
    long head = 0;
    
    long ret = 0;
    for (int[] v : p) {
      if (eat.contains(v[0])) {
        sum[ptr + 1] = sum[ptr] + v[1];
        ptr ++;
      } else {
        eat.add(v[0]);
        head += v[1];
      }
      
      int m = eat.size();
      if (k - m >= 0 && k - m <= ptr) {
        long now = head + (long)m * m + sum[k - m];
        ret = Math.max(now, ret);
      }
    }
    System.out.println(ret);
  }
  

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 52960
n = gets.to_i
ss = []

ans = 0

start_with_b = 0
end_with_a = 0
both = 0

n.times do
  s = gets.chomp
  ans += s.scan(/AB/).size
  if s[0] == 'B' && s[-1] == 'A'
    both += 1
  elsif s[0] == 'B'
    start_with_b += 1
  elsif s[-1] == 'A'
    end_with_a += 1
  end
end

if both > 0
  ans += both - 1
  if end_with_a > 0
    end_with_a -= 1
    ans += 1
  end
  
  if start_with_b > 0
    start_with_b -= 1
    ans += 1
  end
end

ans += [start_with_b, end_with_a].min

puts ans


Measured memory_bytes: 14360
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
using namespace std;

map<string, int> mp;
int main(){ int n;
    cin >> n;
    for (int i=0; i<n; i++){ string s;
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19196
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  ll n; cin >> n;
  vector<ll> a(n); REP(i,n) cin >> a[i];
  ll ans = 0;
  sort(ALL(a));

  vector<ll> s(n+1);
  REP(i,n) { s[i+1] = (a[i] + s[i]); }
  for (ll i = 0; i < n-1; i++) {
    ll v = (s[n] - s[i+1]) % MOD;
    ans += (a[i] * v) % MOD;
    // cout << a[i] << " x " << s[n] - s[i+1] << endl;
    ans %= MOD;
  }

  COUT(ans);

  return 0;
}


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

using namespace std;

typedef long long ll;

ll dp[100][21];

int n;
int a[100];

ll rec(int i, int j)
{
    if (j < 0 || j > 20) return 0;

    if (dp[i][j] >= 0) return dp[i][j];

    ll res;

    if (i == n - 2) {
        res = j == a[n - 1];
    } else {
        res = rec(i + 1, j + a[i + 1]) + rec(i + 1, j - a[i + 1]);
    }

    return dp[i][j] = res;
}

int main()
{
    cin >> n;

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

    memset(dp, -1, sizeof(dp));

    printf("%lld\n", rec(0, a[0]));
}

Measured memory_bytes: 1176
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

//中学高校受験でよくあるN！に対して0はいくつ続くかという問題の類題
//今回はN!ではなくN(N-2)(N-4)みたいに2個飛ばしになっている
//つまり，2，4，6...を2で割ってみるとN/2!であることがわかるので
//あとは2と5の素因数の指数の個数の少ない方を取る
//ただし，よく考えると絶対に2の指数部のほうが多くなるので5の指数部の数だけみる
int main() {

    ll N = 0;
    cin >> N;

    //奇数のときは2の素因数が現れなくて10が作れないので駄目
    if(N % 2 == 1){
        cout << 0 << endl;
        return 0;
    }

    N /= 2;

    ll ans = 0;
    //N/2までで5で割れるものがいくつあるか...5^2は...5^3は...
    while(N > 0){
        N /= 5;
        ans += N;
    }

    /*
    ll waru = 5;
    while(N / waru != 0){
        ans += waru;
        waru *= 5;
    }
    */

    cout << ans << endl;
}

Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:i64
    }

    let ans = if n % 2 == 0 {
        1.0 / 2.0
    } else {
        let denom = n;
        let numer = (denom + 1) / 2;
        numer as f64 / denom as f64
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

typedef long long LL;

LL solve1(const vector<int> &a, const vector<int> &b) {
	int n = (int)a.size();
	vector<int> bs[29];
	for (int bi = 0; bi < 29; ++bi) {
		int bm = (1 << bi) - 1;
		for (int i = 0; i < n; ++i) {
			bs[bi].push_back(a[i] & bm);
		}
		sort(bs[bi].begin(), bs[bi].end());
	}
	int as = 0;
	for (int i = 0; i < n; ++i) {
		as ^= a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans ^= as;
		for (int bi = 0; bi < 29; ++bi) {
			int bf = 1 << bi;
			int cnt = (n % 2) && ((1 << bi) & b[i]);
			int bm = bf - 1;
			int br = bf - (b[i] & bm);
			int pos = lower_bound(bs[bi].begin(), bs[bi].end(), br) - bs[bi].begin();
			int ov = n - pos;
			cnt += ov;
			if (cnt & 1) {
				ans ^= bf;
			}
		}
	}
	return ans;
}

LL solve2(const vector<int> &a, const vector<int> &b) {
	int n = (int)a.size();
	LL r = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			r ^= (a[i] + b[j]);
		}
	}
	return r;
}

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}

	LL ans = solve1(a, b);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 29180
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
AB=sorted(AB, key=lambda a:a[0]  )
ans=0
l=0
for ab in AB:
  if l+ab[1]<=M:
    l+=ab[1]
    ans+=ab[0]*ab[1]
  else:
    for i in range(ab[1]):
      if l<M:
        l+=1
        ans+=ab[0]
  if l==M:
    print(ans);break

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

int main(){
  int s, h, m, sc;
  cin >> s;

  h=s/3600;
  m=(s%3600)/60;
  sc=(s%60);

  cout << h << ":" << m << ":" << sc << endl;
  return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int ptr = 0;						
		int[] prime = new int[10000000];	
		Scanner stdIn = new Scanner(System.in);
		int st;
		do{
			st = stdIn.nextInt();
		}while(st<2||st>100000);
		int min = 0;
		prime[ptr++] = 2;
		prime[ptr++] = 3;					

		for (int n = 5 ; n <= 1000000; n += 2) {		
			boolean flag = false;
			for (int i = 1; prime[i] * prime[i] <= n; i++) {
				if (n % prime[i] == 0) {	
					flag = true;
					break;						
				}
			}
			if (!flag) {						
				prime[ptr++] = n;
				if(n >= st) {
					min = n;
					break;
				}
			}
		}
		if(st == 2)	min = 2;
		if(st == 3) min = 3;
			System.out.println(min);
	}
}


Measured memory_bytes: 64596
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
 
typedef long long ll;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int n,d;
    std::cin >> n>>d;
    d=2*d+1;
    std::cout <<int(ceil(double(n)/d)) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    int result = 0;
    RANGE(now_r,(N/R) + 1){
        int rest = N- (R*now_r);
        int plus = 0;
            RANGE(now_g, (rest/G) +1){
                if((rest - G*now_g) % B ==0)plus++;
            }
        result += plus;
        //cout << plus << endl;
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if ( a == b ) {
    cout << c << endl; 
  }
  else if ( a == c ) {
     cout << b << endl; 
  }
  else {
     cout << a << endl; 
  }
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def same(self, x, y):
        if self.find(x) == self.find(y):
            return True
        else:
            return False 


N, Q = map(int, input().split())

UF = UnionFind(N)

for i in range(Q):
    com, x, y = map(int, input().split())

    if com == 0:
        UF.unite(x, y)
    if com == 1:
        print(int(UF.same(x, y)))



Measured memory_bytes: 6116
// ------------------------------------
// Date:2018/ 3/20
// Problem:A- Simple Calculator a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") <<　endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int INF = 2e9 + 1;
static const int MAX_N = 1;

ll solve(ll x, ll y)
{
  if (y - x < 0) return INF;
  return y - x;
}

int main()
{
  LCIN(X, Y);
  ll ans = INF;
  ans = min(ans, solve(X, Y));
  ans = min(ans, solve(X, -Y) + 1);
  ans = min(ans, solve(-X, Y) + 1);
  ans = min(ans, solve(-X, -Y) + 2);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  string s; cin >>s;
  ll n=s.size();
  rep(i,n)if(s[i]=='?')s[i]='D';
  cout <<s<<endl;
}



Measured memory_bytes: 3728
n = int(input())
s = input()

su = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i+1,n):
        if s[i] != s[j]:
            for lis in ['R','G','B']:
                if lis != s[i] and lis != s[j]:
                    try:
                        su -= s[2*j-i].count(lis)
                    except:
                        pass

print(su)

Measured memory_bytes: 74208
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val S = sc.next
    println(if (S.reverse.equals(S)) ("Yes") else ("No"))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 25536
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main(){
	string a,b;
	while(cin>>a>>b){
		a+=b;
		int n=atoi(a.c_str());
		int m=sqrt(n);
		if(m*m==n) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, M[MAX][MAX];

void dijkstra(int s)
{
    int u, minv;
    int color[MAX], d[MAX], p[MAX];
    for (int i = 0; i != n; ++i)
    {
        color[i] = WHITE;
        d[i] = INFTY;
        p[i] = -1;
    }
    d[s] = 0;
    while (true)
    {
        minv = INFTY;
        for (int i = 0; i != n; ++i)
        {
            if (color[i] != BLACK && d[i] < minv)
            {
                u = i;
                minv = d[i];
            }
        }
        if (minv == INFTY)
        {
            break;
        }
        color[u] = BLACK;
        for (int v = 0; v != n; ++v)
        {
            if (M[u][v] != INFTY && color[v] != BLACK)
            {
                if (d[u] + M[u][v] < d[v])
                {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                    p[v] = u;
                }
            }
        }
    }
    for (int i = 0; i != n; ++i)
    {
        cout << i << " " << d[i] << endl;
    }
}

int main()
{
    int u, k, v, c;
    cin >> n;
    for (int i = 0; i != n; ++i)
    {
        for (int j = 0; j != n; ++j)
        {
            M[i][j] = INFTY;
        }
    }
    for (int i = 0; i != n; ++i)
    {
        cin >> u >> k;
        for (int j = 0; j != k; ++j)
        {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    dijkstra(0);
    return 0;
}


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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

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

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	long long a,b,c,d;
	cin >>a >>b >>c >>d;
	cout <<max(max(a*c,a*d),max(b*c,b*d));
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
    int X,N;
    cin >> X >> N;
    vector<bool> ok(102);
    rep(i,102) ok[i] = true;
    rep(i,N){
        int p;
        cin >> p;
        ok[p] = false;
    }
    if(ok[X]){
        cout << X << endl;
        return 0;
    } 
    int i,j;
    i = X-1;
    j = X+1;
    while(1){
        if(ok[i]){
            cout << i << endl;
            return 0;
        }
        if(ok[j]){
            cout << j << endl;
            return 0;
        }
        i--;
        j++;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

bool isPrime(ll n) {
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (ll i = 3; i * i <= n; i+= 2) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}


vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ll num = 0;
        while(n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;

    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }

    if (isPrime(n)) {
        cout << 1 << endl;
        return 0;
    }

    ll res = 0;
    vector<pair<ll, ll>> p = prime_factorize(n);

    vector<ll> v;
    for (auto np : p) {
        ll x = np.first;
        ll y = np.second;
        ll i = 1;
        while(y > 0) {
            v.push_back(pow(x, i));
            y -= i;
            i++;
            if (y < i) break;
        }
    }

    sort(v.begin(), v.end());

    rep(i, v.size()) {
        if (n < v[i]) break;
        n /= v[i];
        res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
typedef long long ll;

int main()
{
	ll A,B,N;
	scanf("%lld %lld %lld", &A,&B,&N);
	ll i = N;
	ll x;
	ll n;
	if (N >= B -1)
		n = B -1;
	else
		n = N;
	ll max = LLONG_MIN;
	ll sum ;
	// while (i >= n)
	// {
		sum = (A*n/B) - A * (n/B);
	// 	if (sum >= max)
	// 	{
	// 		x = i;
	// 		max = sum;
	// 	}
	// 	i--;
	// }
	printf("%lld\n",sum);
	return (0);
}


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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl;
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

int N;
vector<int> P;

int
main()
{
  cin >> N;
  REP(i, N) { int tmp; cin >> tmp; P.emplace_back(tmp); }

  int ans = 0;
  for (int i = 0; i < N - 2; i++) {
    if (P[i] < P[i+1] && P[i+1] < P[i+2]) ++ans;
    if (P[i+2] < P[i+1] && P[i+1] < P[i]) ++ans;
  }

  ANS(ans);
  
  return 0;
}


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

//#define int ll
#define pb push_back
#define DBGB if (false)

using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;


void update(int& maxg, int g, int sum, int k, const vi& as) {
    //DBGB { cerr << "DBG upd " << g << " " << maxg << " " << endl; }
    if (g <= maxg)
        return;
    const int n = as.size();
    int off[500];
    assert(n <= 500);
    int offsum = 0;
    for (int i=0; i<n; ++i) {
        off[i] = as[i]%g;
        offsum += off[i];
    }
    assert(offsum % g == 0);
    sort(off, off+n, greater<int>());
    int offabsum = offsum;
    for (int i=0; i<n && offsum != 0; ++i) {
        offabsum -= off[i] + (off[i]-g);
        offsum -= g;
    }
    assert(offsum == 0);
    if (offabsum <= 2*k)
        maxg = g;
    //DBGB { cerr << "DBG upd res " << offabsum << " ?<= 2* " << k << " " << endl; }
}


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

    int n, k;
    cin >> n >> k;
    vi as(n);
    int sum = 0;
    for (int i=0; i<n; ++i) {
        cin >> as[i];
        sum += as[i];
    }
    int maxg = 1;
    for (int i=1; i*i<=sum; ++i) {
        if (sum%i == 0) {
            int g1 = i;
            int g2 = sum/i;
            if (g2 < maxg)
                break;
            update(maxg, g2, sum, k, as);
            update(maxg, g1, sum, k, as);
        }
    }
    cout << maxg << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char x[200000],y[200000];
long n,q,c=-1,d,i;
string s;
int main(){
  cin>>n>>q>>s;
  d=n;
  for(i=0;i<q;i++)cin>>x[i]>>y[i];
  for(i=q-1;i>=0;i--){
    if(x[i]==s[c+1]&&y[i]=='L')c++;
    if(x[i]==s[d-1]&&y[i]=='R')d--;
    if(x[i]==s[c]&&y[i]=='R')c--;
    if(x[i]==s[d]&&y[i]=='L')d++;
  }
  cout<<max(0,(int)(d-c-1))<<endl;
  return 0;
}


Measured memory_bytes: 900
W, H, N = map(int, input().split())
XYA = [tuple(map(int, input().split())) for _ in range(N)]
XYA += [(0,0,1),(W,0,2),(0,0,3),(0,H,4)]
h1 = max(x for x,y,a in XYA if a == 1)
h2 = min(x for x,y,a in XYA if a == 2)
w1 = max(y for x,y,a in XYA if a == 3)
w2 = min(y for x,y,a in XYA if a == 4)
print((max(0,h2-h1))*(max(0,w2-w1)))

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=5005;
const long long INF=1e18;
int n,a,b,x; long long f[N][N],ans=INF;
int main()
{
	RI i,j; for (scanf("%d%d%d",&n,&a,&b),i=1;i<=n;++i)
	for (j=1;j<=n;++j) f[i][j]=INF; for (i=1;i<=n;++i)
	for (scanf("%d",&x),j=1;j<=n;++j)
	if (x<j) f[i][j]=min(f[i][j],f[i-1][j]+b); else
	f[i][x]=min(f[i][x],f[i-1][j]),f[i][j]=min(f[i][j],f[i-1][j]+a);
	for (i=1;i<=n;++i) ans=min(ans,f[n][i]);
	return printf("%lld",ans),0;
}

Measured memory_bytes: 199196
K=int(input())
s=input()
S=len(s)
mod=10**9+7
MAX_N=10**7
fact=[1]
fact_inv=[0]*(MAX_N+4)
for i in range(MAX_N+3):
  fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
  fact_inv[i]=fact_inv[i+1]*(i+1)%mod

def mod_comb_k(n,k,mod):
  return fact[n]*fact_inv[k]%mod*fact_inv[n-k] %mod

cnt=0
for i in range(K+1):
  a=(pow(26,i,mod)*pow(25,K-i,mod))*(mod_comb_k(K+S-i-1,S-1,mod))
  a%=mod
  cnt+=a
  cnt%=mod
print(cnt)

Measured memory_bytes: 384680
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

int main()
{
     
            int n,a,b;
           scf(a),scf(b), scf(n);

            cout<<((n<=a+b)&&n>=a?"YES":"NO");


}

Measured memory_bytes: 3768
#include<stdio.h>
int main(){
	int a,b,c,t;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	if(a>c){
		t=a;
		a=c;
		c=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	if((a-b)==(b-c))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll K, S, c = 0, z;
  cin >> K >> S;

  for (int x = 0; x <= min(K, S); x++) {
    for (int y = 0; y <= min(K, S - x); y++) {
      z = S - x - y;
      if (0 <= z && z <= K) c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,q,c,up,low,t,x,y,a,b;
double ff;
string str;
vector<string>veca[1000000];
set<ll>seta;
bool f,arr[1000000];

int main()
{
    cin >> n >> str;
    q=str.size();
    for (ll i=0;i<q;i++)
    {
        if ((str[i]+n)>90)
        {
            x=90-str[i];
//            cout << x;
            x=n-x;
//            cout << x;
            str[i]=64+x;
        }
        else
            str[i]+=n;
        cout << str[i];
    }
    cout << endl;
}


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

#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;
    int h[N];

    for(int i=0; i < N; i++) cin >> h[i];

    int dp[N];
    for(int i=0; i < N; i++) dp[i] = 1e9 + 5;
    dp[0]=0;
    for(int i=0; i < N; i++){
        for(int j=i+1; j <= i+2; j++){
            if(j < N)
                dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define llint long long
 
void openFile() {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
}
 
const int maxN = 1e3 + 5;
const int maxM = 5e3 + 5;
const llint INF = 1e9 + 7;
 
int N;
vector<int> vertex[maxN];
int X[maxN];
int dp[2][maxN];
int g[2][maxM], f[2][maxM];
 
void enter() {
    cin >> N;
 
    for (int i = 2; i <= N; ++i) {
        int p;
        cin >> p;
        vertex[p].push_back(i);
    }
 
    for (int i = 1; i <= N; ++i) {
        cin >> X[i];
    }
}
 
void dfs(int u, int p) {
    for (int i = 0; i < vertex[u].size(); ++i) {
        int v = vertex[u][i];
        dfs(v, u);
    }
    fill_n(&g[0][0], 2 * maxM, INF);
    g[0][0] = g[1][0] = 0;
 
    for (int i = 0; i < vertex[u].size(); ++i) {
        int v = vertex[u][i];
 
        for (int d = 0; d <= X[u]; ++d) {
            if (d >= X[v]) {
                f[0][d] = min(f[0][d], g[0][d - X[v]] + dp[0][v]);
                f[1][d] = min(f[1][d], g[1][d - X[v]] + dp[1][v]);
            }
 
            if (d >= dp[1][v]) f[0][d] = min(f[0][d], g[0][d - dp[1][v]] + X[v]);
            if (d >= dp[0][v]) f[1][d] = min(f[1][d], g[1][d - dp[0][v]] + X[v]);
        }
 
        int min0 = INF, min1 = INF;
        for (int d = 0; d <= X[u]; ++d) { g[0][d] = f[0][d];
            min0 = min(min0, g[0][d]);
            g[1][d] = f[1][d];
            min1 = min(min1, g[1][d]);
            f[0][d] = INF;
            f[1][d] = INF;
        }
 
        dp[0][u] = min0;
        dp[1][u] = min1;
 
        if (min0 == INF && min1 == INF) {
            puts("IMPOSSIBLE");
            exit(0);
        }
    }
}
 
void solve() {
    fill_n(&f[0][0], 2 * maxM, INF);
    dfs(1, 0);
    puts("POSSIBLE");
}
 
int main() {
    openFile();
    enter();
    solve();
    return 0;
}


Measured memory_bytes: 384
n = int(input())
nums = [[0,0,0]]
ans = []

for v in range(n):
    t, x, y = map(int,input().split())
    nums.append([t,x,y])

# print(nums)
# print(nums[1][1])

for x in range(n):
    p = nums[x+1][0] - nums[x][0]
    px = nums[x+1][1] - nums[x][1]
    py = nums[x+1][2] - nums[x][2]
    ps = px + py
    # print(p,px,py,ps)

    for w in range(p+1):
        pp = w
        mp = p - pp
        # print(pp,mp)
        if pp-mp==ps:
            ans.append(1)
        else:
            ans.append(0)

    
sum = 0 
for num in ans:
    sum = sum + num


if sum==n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 21300
#include <iostream>

int main(){
   double W, H, x, y;
   std::cin >> W >> H >> x >> y;

   double S = W * H * 0.5;
   printf("%.9f ",S);
   if(2*x==W && 2*y==H) std::cout << 1 << std::endl;
   else std::cout << 0 << std::endl;
   return 0;
}


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

int main(void){
    int S;
    int h = 0;
    int m = 0;
    int s = 0;

    cin >> S;
    if(0 <= S && S < 86400){
        h = S / 3600;
        m = (S - (h * 3600)) / 60;
        s = S - (h * 3600) - (m * 60);  
        cout << h << ":" << m << ":" << s << endl;
    }else{
        cout << "Out of range!" << endl;
    }
}

Measured memory_bytes: 3084
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define srep(i) for (int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
    using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n, w;
int weight[105] = {}, value[105] = {};

int dp[105][10005] = {};

int main()
{
    string s;
    cin >> s;
    srep(i){
       if(!(i&1)){
           cout<<s[i];
       }
    }
    cout<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
int N, A, B, n, m;
scanf("%d%d%d", &N, &A, &B);
if(A>B){
n=B;
}
else{
n=A;
}
if(A+B>N){
m=A+B-N;
}
else{
m=0;
}
printf("%d %d", n, m);
return 0;
}

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

int main(){
    vector<ll> a(5); rep(i,5) cin>> a[i];

    rep(i,5){
        if(a[i] == 0){
            cout << i+1 << endl;
        }
    }

}

Measured memory_bytes: 3624
// Problem : 
// 			O - Matching
// 			Editorial
// 		
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_o
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int unsigned int
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int dp[25][(1<<21)];
void solve()
{
	int n;
	cin >> n;
	int a[n][n];	
	rep(i,0,n)
		rep(j,0,n)
			cin >> a[i][j];
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int mask =0;mask<(1<<n);mask++)
		{
			int curr = i-1;
			dp[i][mask] = dp[i-1][mask];
			if(i == __builtin_popcount(mask))
			for(int j=0;j<n;j++)
			{
				if((mask&(1<<j)) and a[curr][j])
				{
					dp[i][mask] += dp[i-1][(mask^(1<<j))];	
					dp[i][mask] %= mod;	
				}		
			}
		}
	cout << dp[n][(1<<n)-1];
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 175676
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

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


int main()
{
	int N = 0, A = 0, B = 0, i = 0;
	int ans = 0;
	scanf("%d %d %d", &N, &A, &B);
	for (i = 1; i <= N; i++) {
		int val = 0;
		val = (i/10000) + ((i%10000)/1000) + ((i%1000)/100) + ((i%100)/10) + (i%10);
		if ((A <= val ) && (val <= B)) {
			//printf("i=%d val=%d\n", i, val);
			ans += i;
		}
	}
	printf("%d\n", ans);
    return 0;
}


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

B.append(0)
C=[0]*(N+1)

cnt = 0
for i in range(N+1):
    if C[i]>A[i]:
        cnt += A[i]
        if i!=N:
            C[i+1] += B[i]
    else:
        A[i] -= C[i]
        cnt += C[i]
        if B[i]>A[i]:
            B[i] -= A[i]
            cnt += A[i]
            if i!=N:
                C[i+1] += B[i]
        else:
            cnt +=B[i]
print(cnt)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll k, t;
  cin >> k >> t;
  vector<ll> a(t);
  rep(i,t) cin >> a[i];
  rep(i,t-1) {
    sort(All(a));
    a[t-1] -= a[i];
    a[i] = 0;
  }
  sort(All(a));
  cout << max(a[t-1]-1, 0LL) << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else 
      x=x->right;
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }
  else if(z->key<y->key){
    y->left=z;
  }
  else{
    y->right =z;
  }
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;

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

int32_t main(){
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n){
        cin >> v[i];
    }

    list<int> l;
    l.pb(v[0]);
    FOR(i, 1, n){
        if(n%2){
            if(i%2){
                l.pb(v[i]);
            }
            else{
                l.push_front(v[i]);
            }
        }
        else{
            if(i%2){
                l.push_front(v[i]);
            }
            else{
                l.pb(v[i]);
            }
        }
    }

    REP(i, n-1){
        cout << l.front() << " ";
        l.pop_front();
    }
    cout << l.front() << endl;
}

Measured memory_bytes: 9984
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int main(){
  int n;
  cin >> n;
  ll mul=1;
  for(int i=1;i<=n;i++){
    mul *= i;
    mul %= MOD;
  }
  cout << mul;
}


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

int main(int argc, char const *argv[]) {
	int num;
	cin >> num;
	vector<tuple<ll, ll, char>> a(num);
	for(int i = 0; i < num; i ++) {
		cin >> get<0>(a[i]) >> get<1>(a[i]) >> get<2>(a[i]);
	}
	ll mmin = (ll)1e18;
	for(int q = 0; q < 4; q ++) {
		vector<tuple<ll, ll, ll, char>> upDown;
		vector<tuple<ll, ll, ll, char>> upRight;
		for(int i = 0; i < num; i ++) {
			switch(get<2>(a[i])) {
			case 'U':
				upDown.push_back(make_tuple(get<0>(a[i]), get<0>(a[i]), get<1>(a[i]), get<2>(a[i])));
				upRight.push_back(make_tuple(get<0>(a[i]) + get<1>(a[i]), get<0>(a[i]), get<1>(a[i]), get<2>(a[i])));
				get<2>(a[i]) = 'R'; break;
			case 'D':
				upDown.push_back(make_tuple(get<0>(a[i]), get<0>(a[i]), get<1>(a[i]), get<2>(a[i])));
				get<2>(a[i]) = 'L'; break;
			case 'R':
				upRight.push_back(make_tuple(get<0>(a[i]) + get<1>(a[i]), get<0>(a[i]), get<1>(a[i]), get<2>(a[i])));
				get<2>(a[i]) = 'D'; break;
			case 'L': get<2>(a[i]) = 'U'; break;
			}
			long tmp = get<0>(a[i]);
			get<0>(a[i]) = get<1>(a[i]);
			get<1>(a[i]) = 300000 - tmp;
		}

		sort(upDown.begin(), upDown.end());
		sort(upRight.begin(), upRight.end());

		for(int i = 0; i < (int)upDown.size() - 1; i ++) {
		if(get<3>(upDown[i]) == 'U' && get<3>(upDown[i + 1]) == 'D' && get<0>(upDown[i]) == get<0>(upDown[i + 1])) {
				mmin = min(mmin, (get<2>(upDown[i + 1]) - get<2>(upDown[i])) * 5);
			}
		}
		for(int i = 0; i < (int)upRight.size() - 1; i ++) {
		if(get<3>(upRight[i]) == 'R' && get<3>(upRight[i + 1]) == 'U' && get<0>(upRight[i]) == get<0>(upRight[i + 1])) {
				mmin = min(mmin, (get<1>(upRight[i + 1]) - get<1>(upRight[i])) * 10);
			}
		}
	}
	if(mmin > (long)1e17) cout << "SAFE" << endl;
	else cout << mmin << endl;
	return 0;
}

Measured memory_bytes: 27616