akhauriyash/Code-Regression huggingface dataset:
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let input  =read_vec::<i32>();
    let ans = if input[0]*input[1] > input[2] * input[3] {
        input[0] * input[1]
    } else {
        input[2] * input[3]
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>
#include<stack>
#include<math.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<=(n);i++)
#define LL long long int
#define MOD 1000000007
 
 
using namespace std;
 
LL lcm(LL n, LL m)
{
	LL u;
	LL ansl = 0;
	for(u=m; u>=m; u++){
		if(u%n == 0){
			if(u%m == 0){
				ansl = u;
				break;
			}
		}
	}
	return ansl;
}
 
int main(void){
    LL n,k;
    cin >>n>>k;

    LL ans=0;
    LL min=0,max=1;
    for(LL i = 1;i<=n+1;i++){
      
        min+=i-1;
        max+=n-i+1;
 //       cout <<i<<" "<<ans<<" "<<max<<" "<<min<<endl;
        if(i>=k)
            ans=(ans+max-min)%MOD;
    }
    cout <<ans<<endl;
}

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

using namespace std;

/*
 * 1: x < xi
 * 2: x > xi
 * 3: y < yi
 * 4: y > yi
*/

int main() {
    int w, h, n;
    cin >> w >> h >> n;

    int maxx = w;
    int minx = 0;
    int maxy = h;
    int miny = 0;
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;

        switch (a) {
            case 1:
                minx = max(minx, x);
                break;
            case 2:
                maxx = min(maxx, x);
                break;
            case 3:
                miny = max(miny, y);
                break;
            case 4:
                maxy = min(maxy, y);
                break;
        }
    }

    cout << max(maxx - minx, 0) * max(maxy - miny, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
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; }
typedef long long ll;
typedef pair<ll,ll> pint;
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
    ll x;cin>>x;
    ll k= 100;
    ll cnt=0;;
    while(k<x){
        k=k*1.01;
        k/=1;
        cnt+=1;
    }
    cout<<cnt<<endl;
}


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

int main(){
  int H,W,X;
  cin >> H >> W;
  vector<vector<char>> sq(H, vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> sq.at(i).at(j);
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(sq.at(i).at(j)=='#') continue;
      X=0;
      if(i>0){
        if(j>0 && sq.at(i-1).at(j-1)=='#') X++;
        if(sq.at(i-1).at(j)=='#') X++;
        if(j<W-1 && sq.at(i-1).at(j+1)=='#') X++;
      }
      if(j>0 && sq.at(i).at(j-1)=='#') X++;
      if(j<W-1 && sq.at(i).at(j+1)=='#') X++;
      if(i<H-1){
        if(j>0 && sq.at(i+1).at(j-1)=='#') X++;
        if(sq.at(i+1).at(j)=='#') X++;
        if(j<W-1 && sq.at(i+1).at(j+1)=='#') X++;
      }
      sq.at(i).at(j)= '0'+ X;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << sq.at(i).at(j);
      if(j==W-1) cout << endl;
    }
  }
}

Measured memory_bytes: 3596
"""
まず、答えは必ずAの総和以下になる。なぜなら、A同士の差の最大値がAの総和だからである。
移動回数が足りるのであれば、一つだけAの総和になるような項を作って、他を全部0にするのがよい。
ここからわかるのは、数を移動させ終わった後の各Aは全て0以上になるということである。

また答えはからなずAの総和の約数になる。
理由：
答えをXとすると、各AはbXと表すことができる。
したがって、Aの総和＝(bの総和*X)となる。
ゆえに、答えXはAの総和の約数である。

解法としては、Aの総和の約数を列挙して、大きい順に実現可能かどうかを試していく。
実現可能かどうかを試すには、各Aを総和の約数dで割ったときの余りをもとめて、小さい順にソートする。
そのうえで、左からL番目までを「数を与える側」、L+1番目以降を「数をもらう側」として余りが0になるように調整できないかを確かめる。
これは累積和を活用することですくない計算量で実行可能である。
最後に、移動した数がK以下かどうかを確認する。
"""
from itertools import accumulate
N,K = map(int,input().split())
A = list(map(int,input().split()))
sumA = sum(A)
 
yakusu = []
d = 1
while d*d < sumA:
    if sumA%d == 0:
        yakusu.append(d)
        yakusu.append(sumA//d)
    d += 1
if d*d == sumA:
    yakusu.append(d)
yakusu.sort(reverse=True)
for d in yakusu:
    #約数の大きい順に、実現可能かどうかを試していく。
    rest = [a%d for a in A]
    rest.sort()
    
    rest = [a%d for a in A]
    rest.sort()
    Rrest = [d-r for r in rest]
    Rrest = Rrest[::-1]
    rest = [0]+list(accumulate(rest))
    Rrest = [0]+list(accumulate(Rrest))
    for i in range(N+1):
        if rest[i] == Rrest[N-i]:
            if rest[i] <= K:
                print(d)
                exit()
            break

Measured memory_bytes: 74612
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<double> x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	vector<double> y(n);
	for (int i = 0; i < n; i++)
	{
		cin >> y[i];
	}
	vector<double> d(4, 0);
	for (int i = 0; i < n; i++)
	{
		d[0] += abs(x[i] - y[i]);
		d[1] += pow(abs(x[i] - y[i]), 2);
		d[2] += pow(abs(x[i] - y[i]), 3);
		d[3] = max(abs(x[i] - y[i]), d[3]);
	}
	cout << fixed << setprecision(6) << d[0] << endl;
	cout << pow(d[1], 1 / 2.0) << endl;
	cout << pow(d[2], 1 / 3.0) << endl;
	cout << d[3] << endl;
}


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define PF push_front
#define PB push_back
#define FST first
#define SEC second
#define sz(obj) ((int)(obj).size())
#define ALL(v) (v).begin(), (v).end()

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in() {int x; std::cin >> x; return x;}
 
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

int gcd(int a, int b){ int c; while (a != 0){ c = a; a = b % a; b = c; } return b; }

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

  int n[3];
  REP(i, 3) cin >> n[i];
  sort(n, n + 3);
  int x = n[2], y = n[1], z = n[0];
  long long int ans = 0;
  long long int red = (x % 2 ? (x + 1) / 2 : x / 2) * z;
  long long int blue = (x % 2 ? (x - 1) / 2 : x / 2) * z;
  
  ans = (red - blue) * y;
  if (x % 2 == 0 and y % 2 == 0) ans = 0;
  if (x % 2 == 0 and z % 2 == 0) ans = 0;
  if (y % 2 == 0 and z % 2 == 0) ans = 0;

  print(ans);

  return (0);
}


Measured memory_bytes: 256
gets
a=gets.split.map &:to_i
n=a.count{|x|x<0}
z=a.count{|x|x==0}
if n%2==1&&z==0
	b=a.map(&:abs)
	p b.reduce(:+)-b.min*2
else
	b=a.map(&:abs)
	p b.reduce(:+)
end

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

int main()
{
  int k, x;
  cin >> k >> x;

  if (k * 500 >= x)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long


signed main(){

  int n; cin >> n;
  vector<int> b(n,0);
  for(int i = 0; i < n-1; i++) cin >> b[i];

  int ans = 0;
  vector<int> a(n+1,0);
  for(int i = 0; i < n; i++){
    if(i == 0) a[i] = b[i];
    else if(i == n-1) a[i] = b[i-1];
    else {
      a[i] = min(b[i-1],b[i]);
    }
  }

  for(int i = 0; i < n; i++){
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <vector>
#include <map>

//#define DEBUG


void func_to_create(){
    std::vector<int> map2019(2019, 0);
    std::vector<int> tempMap(2019, 0);
    int count = 0;
    int c = getchar_unlocked();
    while( ! isdigit(c)){
        c = getchar_unlocked();
    }
    while(true){
        //reset map
        std::fill(tempMap.begin(), tempMap.end(), 0);
        for(int i = 0 ; i < 2019; i++){
            int rnum = map2019[i];
            if( rnum > 0){
                int new_remainder =  (i * 10 + ( c - '0')) % 2019;
                tempMap[new_remainder] = rnum;
            }
        }
        map2019.swap(tempMap);
        map2019[c- '0'] = map2019[c - '0'] + 1;
        count += map2019[0];
        c = getchar_unlocked();
        if(!isdigit(c)){
            break;
        }
    }
    printf("%d\n", count);
}

int main()
{

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    func_to_create();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3076
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
vector< vector<int> > rot( vector< vector<int> > &ary){
  int n = (int)ary.size();
  vector< vector<int> > ret(n,vector<int>(n));
  REP(y,n)REP(x,n)ret[y][x]=ary[n-1-x][y];
  return ret;
} 
int main(void){
  int m1,m2;
  while(cin>>m1>>m2){
    if(m1==0) break;
    vector< vector<int> > view(m1,vector<int>(m1));
    REP(y,m1)REP(x,m1) cin>>view[y][x];
    vector< vector<int> > pict(m2,vector<int>(m2));
    REP(y,m2)REP(x,m2) cin>>pict[y][x];
    vector<PII> ans;
    REP(k,4){
      for(int sy=0; sy+m2-1<m1; sy++){
        for(int sx=0; sx+m2-1<m1; sx++){
          bool f = true;
          REP(dy,m2)REP(dx,m2){
            if(pict[dy][dx]!=-1 && pict[dy][dx]!=view[sy+dy][sx+dx]){
              f=false;
              goto READ;
            }
          }
          READ:
          if(f){
            REP(y,m2)REP(x,m2){
              if(pict[y][x]!=-1){
                ans.push_back(PII(sy+y,sx+x));
                goto END;
              }
            }
          }
          END:;
        }
      }
      pict = rot(pict);
    }
    if(ans.empty()){
      cout<<"NA"<<endl;
    }else{
      sort(ans.begin(),ans.end());
      printf("%d %d\n",ans[0].second+1,ans[0].first+1);
    } 
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define pb emplace_back

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

string s;
vector<string> str;
void dfs(string t){
    str.pb(t);
    if(t.size() == 9) return;
    if(stoi(t+'3') <= stoi(s)) dfs(t+'3');
    if(stoi(t+'5') <= stoi(s)) dfs(t+'5');
    if(stoi(t+'7') <= stoi(s)) dfs(t+'7');
}

int main()
{
    cin >> s;
    dfs("");
    int ans = 0;
    for(auto x: str){
        int flag[3]; fill(flag,flag+3,0);
        for(int i = 0; i < x.size(); i++){
            if(x[i] == '3') flag[0] = 1;
            if(x[i] == '5') flag[1] = 1;
            if(x[i] == '7') flag[2] = 1;
        }
        if(flag[0] && flag[1] && flag[2]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
typedef pair<int, int> P;

int INF = 1145141919;
int n;
string a;
string b;
vector<int> bPos;
int c[2000];

int getCost(int rShift) {
	int i;
	vector<P> query;
	
	for (i = 0; i < n; i++) {
		if (c[i] == 1) {
			int l, r;
			vector<int>::iterator it;
			it = upper_bound(bPos.begin(), bPos.end(), i);
			if (it == bPos.begin()) { l = bPos[bPos.size() - 1] - i - n; }
			else { it--; l = (*it) - i; }
			it = lower_bound(bPos.begin(), bPos.end(), i);
			if (it == bPos.end()) { r = bPos[0] - i + n; }
			else { r = (*it) - i; }
			query.push_back(P(l, r));
		}
	}
	sort(query.begin(), query.end());
	
	//いくつを右シフトに割り当てるか
	int lShift = (n - rShift) % n;
	int rMaxi = 0;
	int ret = INF;
	for (i = 0; i <= query.size(); i++) {
		int a = (i == query.size()) ? 0 : -query[i].first;
		int b = rMaxi;
		int rShiftEnd = 2 * a + b + abs(b - rShift);
		int lShiftEnd = 2 * b + a + abs(a - lShift);
		int cost = query.size() + min(rShiftEnd, lShiftEnd);
		ret = min(ret, cost);
		if (i < query.size()) rMaxi = max(rMaxi, query[i].second);
	}
	return ret;
}

signed main() {
	cin >> a >> b;
	n = a.length();
	
	for (int i = 0; i < n; i++) {
		if (b[i] == '1') {
			bPos.push_back(i);
		}
	}
	if (a != b && bPos.size() == 0) { cout << -1 << endl; return 0; }
	
	int ans = INF;
	for (int r = 0; r < n; r++) {
		for (int i = 0; i < n; i++) {
			c[i] = (a[i] != b[(i + r) % n]);
		}
		ans = min(ans, getCost(r));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 500000;
const ll INF = 1LL<<60;
typedef struct Node { ll num; char c; } node;
ll cnt, n;
const ll N_MAX = 2000001;
const ll V_MAX = 10000;

signed main() {
    scanf("%lld", &n); 
    vector<ll> seq(n+1), B(n+1), C(V_MAX+1, 0);
    for( ll i = 1; i <= n; i++ ) cin >> seq.at(i);

    for(ll i = 1; i <= n; i++) {
        C.at(seq.at(i))++;
    }
    for(ll i = 1; i <= V_MAX; i++) {
        C.at(i) = C.at(i) + C.at(i-1);
    }
    for(ll j = 1; j <= n; j++) {
        B.at(C.at(seq.at(j))--) = seq.at(j);
    }

    for (ll j = 1; j < n; j++)
    { printf("%lld ", B.at(j)); }
    printf("%lld\n", B.at(n));

    return 0;
}




Measured memory_bytes: 34252
n = int(input())
inp = list(map(int,input().split()))
d = {}
for x in inp:
    d[x] = d.get(x, 0) + 1
v = [0 for _ in range(n+1)]
for x, y in d.items():
    v[x] = (y)*(y-1)//2
tot = sum(v)
for i in range(n):
    print(tot-v[inp[i]]+((d[inp[i]]-1)*(d[inp[i]]-2)//2))

Measured memory_bytes: 24996
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}

	private void run_case() {
		int K = reader.ni();
		int N = reader.ni();
		int[] arr = new int[N];
		for (int i=0; i<N; i++) arr[i] = reader.ni();

		int max_dist = 0;
		for (int i=0; i<N-1; i++) {
			max_dist = Math.max(max_dist, arr[i+1] - arr[i]);
		}
		max_dist = Math.max(max_dist, arr[0] + K - arr[N-1]);

		int res = K - max_dist;
		System.out.println(res);
		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 47264
#include <cstdio>

int main(void) {
    int i, n;
    scanf("%d", &n);
    int fib[n+1];
    fib[0] = fib[1] = 1;
    for (i = 2; i <= n; i++) fib[i] = fib[i-2] + fib[i-1];
    printf("%d\n", fib[n]);

    return 0;
}

Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.0000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
long long ans[500000] = {};
int main() {
	int n;
	cin >> n;
	iostream::sync_with_stdio(false);
	vector<pair<int, int>> wow;
	REP(i, n) {
		int a;
		cin >> a;
		wow.push_back(make_pair(a, i));
	}
	sort(wow.begin(), wow.end());
	for (int i = 0; i < n / 2; ++i) {
		ans[wow[i].second] = wow[n / 2].first;
	}
	for (int i = n / 2; i < n; ++i) {
		ans[wow[i].second] = wow[n / 2 - 1].first;
	}
	for (int i = 0; i < n; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5488
import copy
def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    dp = [[0] * (50*N + 1) for _ in range(N+1)]
    dp[0][0] = 1
    for k in range(N):
        dpn = copy.deepcopy(dp)
        for i in range(k+1):
            for j in range(50 * N + 1 -x[k]):
                dpn[i+1][j+x[k]] += dp[i][j]
        dp = dpn
    r = 0
    for i in range(1, N+1):
        r += dp[i][i*A]
    return r
print(main())


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


int main() {
	int n;
	cin >> n;
	int odd;
	double ans;
	odd = (n + 1) / 2;
	ans = double(odd)/double(n);
	cout << ans << endl;


}

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

int main(){
    int a, b, c, d, e, k;
    bool flag = false;
    cin >> a >> b >> c >> d >> e >> k;
    if(b - a > k) flag = true;
    else if(c - a > k) flag = true;
    else if(d - a > k) flag = true;
    else if(e - a > k) flag = true;
    else if(c - b > k) flag = true;
    else if(d - b > k) flag = true;
    else if(e - b > k) flag = true;
    else if(d - c > k) flag = true;
    else if(e - c > k) flag = true;
    else if(e - d > k) flag = true;

    if(flag == false) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
xor = lsbsum = 0
for i in range(N):
    n = int(input())
    xor ^= n
    lsbsum |= (n&-n)

ans = 0
while xor > 0:
    msb = 1 << (len(str(bin(xor))) - 3)
    if lsbsum & msb:
        ans += 1
        xor ^= ((msb << 1) - 1)
    else:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
string a[4];
void solve(int x){
	if(a[x].length()==0){
		printf("%c",'A'+x-1);
		return;
	}
	int next=a[x][0]-'a'+1;
	a[x]=a[x].substr(1);
	solve(next);
}
int main(){
	cin>>a[1]>>a[2]>>a[3];
	solve(1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define all(v) v.begin(), v.end()
#define rep(i, from, to) for (ll i = from; i < ll(to); ++i)

int main()
{

    ll n;
    cin>>n;
    cout<<0<<endl;
    string s;
    cin>>s;
    map<string,ll> fc;
    fc.insert({"Male",0});
    fc.insert({"Female",1});
    fc.insert({"Vacant",-1});
    ll mf = fc[s];
    if(mf==-1)return 0;
    ll l = 1;
    ll h = n-1;
    while(true){
        ll m = (l+h)/2;
        cout<<m<<endl;
        cin>>s;
        ll tf=fc[s];
        if(tf==-1)return 0;
        if((tf+m)%2==mf){
            l = m+1;
        }else{
            h=m-1;
        }
    }


    return 0;
}


Measured memory_bytes: 852
import numpy as np

def main():
    N, D = list(map(int, input().split()))
    X = []
    for i in range(N):
	    line = [int(a) for a in input().split()]
	    X.append(line)
    X_np = np.array(X)

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if(is_dist_int(X_np, D, i, j)):
                ans += 1
    print(ans)

def is_dist_int(X_np, D, i, j):
    dif = np.sum(np.square(np.abs(X_np[i] - X_np[j])))
    dis = np.sqrt(dif)
    return dis.is_integer()

main()


Measured memory_bytes: 12424
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<pair<int, int>> v;
	char key;
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i == 0) {
			key = s[i];
			count = 1;
			continue;
		}
		if (s[i] != key) {
			v.push_back(make_pair(key - 48, count));
			key = s[i];
			count = 1;
		} else
			count++;

	}
	v.push_back(make_pair(key - 48, count));

	//for (auto e : v)
	//	printf("v: %d, %d\n", e.first, e.second);

	int right = 0;
	int kcount = 0;
	int maxsum = 0;
	int sum = 0;
	for (int i = 0; i < v.size(); i++) {
		if (i == 0) {
			if (v[0].first == 1) {
				sum = v[0].second;
				right++;
			}
		} else {
			if (v[i-1].first == 1) {
				continue;
			}
			sum -= v[i-1].second;
			if (i-2 >= 0)
				sum -= v[i-2].second;
			kcount--;
		}
		while (kcount < k && right < v.size()) {
			if (v[right].first == 0) {
				kcount++;
				sum += v[right].second;
				right++;
				if (right < v.size()) {
					sum += v[right].second;
					right++;
				}
			}
		}
		//printf("left:%d, right:%d, sum:%d\n", i, right, sum);

		if (maxsum < sum)
			maxsum = sum;
	}
	cout << maxsum << endl;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int ans = 700; 
  if (S[0] == 'o') ans += 100;
  if (S[1] == 'o') ans += 100;
  if (S[2] == 'o') ans += 100;
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  map<int, int> count;
  for(int i=0;i<n;i++) {
    int a;
    cin >> a;
    count[a]++;
  }
  
  int even = 0;

  for(auto it = count.begin(); it != count.end(); it++) {
    if(it->second % 2 == 0) {
      it->second = 2;
      even++;
    }
    else it->second = 1;
  }

  if(even % 2 == 0) cout << count.size() << endl;
  else cout << count.size() - 1 << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double star_coor[500][4];
int star_num;
double telescope_direction[50][4];
int telescope_num;

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

int parse()
{
	scanf("%d", &star_num);
	if (star_num == 0)
		return 0;
	fors(i, star_num)
	{
		scanf("%lf %lf %lf", &star_coor[i][0], &star_coor[i][1], &star_coor[i][2]);
		star_coor[i][3] = 0;
	}
	scanf("%d", &telescope_num);
	fors(i, telescope_num)
		scanf("%lf %lf %lf %lf", &telescope_direction[i][0], &telescope_direction[i][1], &telescope_direction[i][2], &telescope_direction[i][3]);
	return 1;
}

int run()
{
	fors(i, star_num)
	{
		fors(j, telescope_num)
		{
			double edge1 = pow(telescope_direction[j][0] - star_coor[i][0], 2);
			edge1 += pow(telescope_direction[j][1] - star_coor[i][1], 2);
			edge1 += pow(telescope_direction[j][2] - star_coor[i][2], 2);
			double edge2 = pow(telescope_direction[j][0], 2);
			edge2 += pow(telescope_direction[j][1], 2);
			edge2 += pow(telescope_direction[j][2], 2);
			double edge3 = pow(star_coor[i][0], 2);
			edge3 += pow(star_coor[i][1], 2);
			edge3 += pow(star_coor[i][2], 2);
			double cosA = (edge2 + edge3 - edge1) / (2 * sqrt(edge2 * edge3));
			if (cosA > cos(telescope_direction[j][3]))
			{
				star_coor[i][3] = 1;
				break;
			}
		}
	}
	int res = 0;
	fors(i, star_num)
	{
		res += star_coor[i][3];
	}
	return res;
}

int main()
{
	while (parse())
	{
		printf("%d\n", run());
	}
}


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

void selectSort(int* a,int n){
	int trade = 0;
	int minI,v;
	for(int i = 0;i < n;i++){
		minI = i;
		for(int j = i + 1;j < n;j++){
			if(a[j] < a[minI]){
				minI = j;
			}
		}
		v = a[i];
		a[i] = a[minI];
		if(i != minI)
			trade++;
		a[minI] = v;
	}

	for(int i = 0; i < n;i++){
		cout << a[i] << flush;
		if(i != n - 1){
			cout << " " << flush;
		}else{
			cout << endl;
		}
	}
	cout << trade << endl;
}

int main(){
	int n;
	cin >> n;
	int* a = new int[n];
	for(int i = 0; i < n;i++){
		cin >> a[i];
	}
	selectSort(a,n);
}


Measured memory_bytes: 3080
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

template <typename T>
void say(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}


/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int X, A, B;
	cin >> X >> A >> B;

	if (B <= A) cout << "delicious" << endl;
	else if (B <= A + X) cout << "safe" << endl;
	else cout << "dangerous" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W, H, x, y, r,R,L,U,D;
	scanf("%d", &W); scanf("%d", &H); scanf("%d", &x);
	scanf("%d", &y); scanf("%d", &r);

	R = r + x;
	L = x - r;
	U = r + y;
	D = y - r;

	if (R > W || L < 0 || U > H ||D < 0)
	{
		puts("No");
	}
	else
	{
		puts("Yes");
	}

	return 0;

}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  if (a+b > a*b && a+b > a-b) {
    cout << a+b; return 0;
  }
  if (a*b > a+b && a*b > a-b) {
    cout << a*b; return 0;
  }
  cout << a-b;
  
  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <numeric>
//#include <omp.h>
#include<memory>
#include <cstdio>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,s,e) for (int i = s; i > (e); --i)
typedef long long int ll;
const int MOD=1000000007;
int main(){
    char s;
	cin >> s;
   	if (isupper(s)){
    	cout << 'A' << endl;
   	} else {
        cout << 'a' << endl;
   }
    return 0;
}

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

using namespace std;

int main(){
    int N,M,C; cin >> N >> M >> C;
    vector<int> B(M);

    for(int i=0;i<M;++i){
        cin >> B[i];
    }
    vector<vector<int>> A(N,vector<int>(M));
    for(int i=0;i<N;++i){
        for(int j=0;j<M;++j){
            cin >> A[i][j];
        }
    }

    int ans = 0;
    for(int i=0;i<N;i++){
        int sum = 0; 
        for(int j=0;j<M;++j){
            sum += A[i][j]*B[j];
        }
        if(sum + C > 0){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
using LL=long long;
using VI=vector<int>;
using VL=vector<long long>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(T & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(T& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(T& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template <class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template <class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template <class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template <class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define Cin(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define VecIn(T,name,n) vector<T> name(n); for(auto &i:name)cin>>i;

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template <class T>void out(T n) { cout << n << endl; }
template <class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
template <> void out(double a) { printf("%.20f\n", a); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void Yay(bool f) { puts(f ? "Yay!" : ":("); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	Cin(int, n);
	VecIn(int, a, n);
	out(Max(a) - Min(a));
}

Measured memory_bytes: 256
def main():
    n = int(input())
    _list = list(range(1,n+1))
    for x in _list:
        if x % 3 == 0 or any(list(map(lambda x: int(x) == 3, list(str(x))))):
            print(' %d' %  x, end = '')
    print()
    

main()

Measured memory_bytes: 8388
str_search = input().upper()
int_cnt = 0
len_search = len(str_search)
while True:
    str_line = input()

    if str_line == "END_OF_TEXT":
        break
    
    str_line = str_line.upper()
    int_cnt = int_cnt + str_line.split().count(str_search)

print(str(int_cnt))

Measured memory_bytes: 7436
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
// #define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<a*b/2<<endl;


    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    a50(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a50(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val argList = args[0].split(" ")
    println(when (argList[1]) {
        "+" -> argList[0].toInt() + argList[2].toInt()
        "-" -> argList[0].toInt() - argList[2].toInt()
        else -> throw IllegalArgumentException()
    })
}

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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 


// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;



inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);


template<class T> inline T gcd(T a,T b) //NOTES:__gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

bool sortby(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

const int MAX_N = 4123;

int arr[MAX_N];
 
int main() {
	int N;
	ll H;
	scanf("%d %lld",&N,&H);
	ll a,b,ma=0,mb=LLONG_MAX;
	vector<pair<ll,ll> > V;
	V.push_back(make_pair(0LL,0LL));
	for(int i=0;i<N;i++){
		scanf("%lld %lld",&a,&b);
		V.push_back(make_pair(a,b));
		if(a>ma){
			ma=a;
		}
	}
	sort(V.begin(),V.end(),sortby);
	ll ans=0;
	int j=N;
	while(H>0 && V[j].second>ma){
		H-=V[j].second;
		ans++;
		j--;
	}
	if(H>0){
		ans+=max((H-1)/ma+1,0LL);
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL n;
    cin>>n;
    for(LL i=n;;i++)
    {
        LL x=i;
        int f=0;
        for(LL j=2;j*j<=x;j++)
        {
            if(x%j==0)f=1;
        }
        if(f==0)
        {
            cout<<i;
            return 0;
        }
    }

}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> g[100005];
int dist[100005][3];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
	}
	int s, t;
	cin >> s >> t;
	s--; t--;
	memset(dist, -1, sizeof(dist));
	dist[s][0] = 0;
	queue<P> que;
	que.emplace(s, 0);
	while (que.size()) {
		int u = que.front().first;
		int v = que.front().second;
		que.pop();
		for (auto& c : g[u]) {
			int nv = (v + 1) % 3;
			if (dist[c][nv] != -1) continue;
			dist[c][nv] = dist[u][v] + 1;
			que.emplace(c, nv);
		}
	}
	if (dist[t][0] == -1) cout << -1 << endl;
	else cout << dist[t][0] / 3 << endl;
	return 0;
}

Measured memory_bytes: 6912
#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

v=n//(a+b)
ans=v*a
mod=n%(a+b)

temp=min(mod,a)
ans+=temp
print(ans)  

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

int main(){
	int a[5];
	for (int i = 0; i < 5; i++){
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < 5; i++){
		if (a[i] < 40){
			a[i] = 40;
		}
	}
	printf("%d\n", (a[0] + a[1] + a[2] + a[3] + a[4]) / 5);

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	rep(i, n) cnt += (s[i] == 'R' ? 1 : -1);
	if(cnt > 0){
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = 0; i < a.length; i++) {
            int tmp = a[i];
            b[i] = a[n - 1 - i];
            a[n - 1 - i] = tmp;
            if(i != 0) System.out.print(" ");
            System.out.print(b[i]);
        }

        System.out.println();
    }
}


Measured memory_bytes: 26368
class SegmentTree:
	def __init__(self, orig, func, unit):
		_len = len(orig)
		self.func = func
		self.size = 1 << (_len - 1).bit_length()
		self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
		self.unit = unit

		for i in range(self.size - 1, 0, -1):
			self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])

	def update(self, i, v):
		i += self.size
		self.tree[i] = v
		while i:
			i //= 2
			self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

	def find(self, l, r):
		l += self.size
		r += self.size
		ret = self.unit
		while l < r:
			if l & 1:
				ret = self.func(ret, self.tree[l])
				l += 1
			if r & 1:
				r -= 1
				ret = self.func(ret, self.tree[r])
			l //= 2
			r //= 2
		return ret

import sys
input = sys.stdin.readline
from operator import or_

def main():
	input()
	seg = SegmentTree([1 << ord(x) - 97 for x in input()[:-1]], or_, 0)
	ans = []
	for _ in range(int(input())):
		f, x, y = input().split()
		if f == "1":
			seg.update(int(x) - 1, 1 << ord(y) - 97)
		else:
			ans.append(bin(seg.find(int(x) - 1, int(y))).count("1"))
	print(*ans)

if __name__=="__main__":
	main()


Measured memory_bytes: 93304
import java.util.*;

public class Main {
    public static int po[];
    public static int ans=Integer.MAX_VALUE;
    public static int[]abc;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
        abc=new int[3];
        for(int i=0;i<3;i++)abc[i]=sc.nextInt();
        
        po=new int[n];
        for(int i=0;i<n;i++)po[i]=sc.nextInt();
        
        int ppp[]=new int[3];
        po(ppp,n,0);
        System.out.println(ans);
    }
    public static void po(int[]a,int n,int ans2){
        if(n==0){
            if(a[0]!=0&&a[1]!=0&&a[2]!=0){
                for(int i=0;i<3;i++){
                    ans2+=Math.abs(a[i]-abc[i]);
                }
                ans=Math.min(ans,ans2);
            }
        }
        else{
        
            int[]b=a.clone();
            
            po(a,n-1,ans2);
            
            if(a[0]==0){
                b[0]+=po[n-1];
                po(b,n-1,ans2);
            }
            else {
                b[0]+=po[n-1];
                po(b,n-1,ans2+10);
            }
            
            if(a[1]==0){
                b=a.clone();
                b[1]+=po[n-1];
                po(b,n-1,ans2);
            }
            else {
                b=a.clone();
                b[1]+=po[n-1];
                po(b,n-1,ans2+10);
            }
            
            if(a[2]==0){
                b=a.clone();
                b[2]+=po[n-1];
                po(b,n-1,ans2);
            }
            else{
                b=a.clone();
                b[2]+=po[n-1];
                po(b,n-1,ans2+10);
            }
           
            
        }
    }
}


Measured memory_bytes: 26836
#include<iostream>

using namespace std;

int main(){
    int x,h,m,s;
    cin >> x;
    h = x / 3600;
    m = (x % 3600)/60;
    s = x % 60;
    
    cout << h << ":" << m << ":" << s  << endl;
    
    return 0;
}


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

int main() {
  
  long long X;
  cin >> X;

  long long ans = 0;
  int rest = X % 11;
  long long num = X / 11 * 2;
  ans += num;
  
  if(rest > 0) {
    if(rest - 6 <= 0) {
      ans++;
    }else {
      ans += 2;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.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

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
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");}

int main(){
  ll T1, T2; cin >> T1 >> T2;
  ll A1, A2; cin >> A1 >> A2;
  ll B1, B2; cin >> B1 >> B2;

  ll D1 = (A1 - B1) * T1;
  ll D2 = (A1 - B1) * T1 + (A2 - B2) * T2;

  if (D1 == 0 || D2 == 0){
    cout << "infinity" << endl;
    return 0;
  }

  if ((D1 < 0 && D2 < 0) || (D1 > 0 && D2 > 0)){
    cout << 0 << endl;
    return 0;
  }

  ll N = abs(D1/D2);

  if (D1 % D2 == 0) cout << 2 * N << endl;
  else cout << 2 * N + 1 << endl;

  return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main(){
    int a,b,c,i;
    int count=0;
    int v;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;i<=b;i++){
        v=c%i;
        if(v==0)count++;
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;

  vector<string> v;
  // for(int size=1;size<=s.size();size++){
  for(int size=1;size<=min(5, (int)s.size());size++){
    for(int pos=0;pos<s.size()-size+1;pos++){
      v.push_back(s.substr(pos,size));
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  // for(int i=0;i<v.size();i++){
  //   cout << v[i] << endl;
  // }

  cout << v[k-1] << endl;

  return 0;
}

Measured memory_bytes: 1660