akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n;
	cin >> n;
	int a[55], mi, mii, ma, maa;
	mi=1000000;
	mii=-1;
	maa=-1;
	ma=-1000000;
	rep(i, n)
	{
		cin >> a[i];
		if(a[i]<=mi) mi=a[i], mii=i;
		if(a[i]>=ma) ma=a[i], maa=i;
	}
	if(ma>=abs(mi))
	{
		cout << 2*n-1 << endl;
		rep(i, n) cout << maa+1 << ' ' << i+1 << endl;
		rep(i, n-1) cout << i+1 << ' ' << i+2 << endl;
 	}
 	else
 	{
 		cout << 2*n-1 << endl;
 		rep(i, n) cout << mii+1 << ' ' << i+1 << endl;
 		rep(i, n-1) cout << n-i << ' ' << n-i-1 << endl;
 	}
	return 0;
}

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


int main() {
  ll k,a,b,ans=0;
  cin>>k>>a>>b;
  if(b-a>k-2||a%k==0||b/k!=a/k){
    
  
  cout<<"OK"<<endl;   
    
  }else
    cout<<"NG"<<endl;
  
}

Measured memory_bytes: 3620
//
// Created by chuan on 2020-04-10.
//

#include <iostream>
#include <numeric>
#include <algorithm>
#include <string>
#include <vector>

using ll = long long ;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    ll N; cin >> N;
    ll ans{};

    for (int i = 1; i <= N; ++ i) {
        for (int j = 1; j <= N; ++ j) {
            for (int k = 1; k <= N; ++ k) {
                ans += (gcd(gcd(i, j), k));
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3640
import bisect

x,y,a,b,c = list(map(int,input().split()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
l = p[-x:] + q[-y:]
l.sort()
r.sort()

for i in range(min(x+y,c)):
    if l[i]<r[-1]:
        l[i]=r.pop()
    else:
        break
print(sum(l))

Measured memory_bytes: 22720
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
s = [input()[0] for i in range(n)]
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for c in s:
    if c in dic:
        dic[c]+=1
ans = 0
judge = [dic[c] for c in dic.keys()]
for tmp in itertools.combinations(judge, 3):
    ans += tmp[0]*tmp[1]*tmp[2]
print(ans)

Measured memory_bytes: 87432
package main

import "fmt"

func main () {
var n int
var k int
fmt.Scan(&n)
fmt.Scan(&k)
var h []int
i := 0
for i < n {
  var tmp int
  fmt.Scan(&tmp)
  h = append(h, tmp)
  i++
}
var c int
c = 0
j := 0
for j < n {
  if h[j] >= k {
    c++
  }
  j++
}
fmt.Printf("%d", c)
}

Measured memory_bytes: 5504
import java.util.Scanner;


// 139_b
public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int count = 1;

        for (int i = 0; i < 100; i++) {

            if (a + (a - 1) * i >= b) {
                break;
            }
            count++;
        }

        if (b == 1) {
            count = 0;
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 21716
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(len(lists)):
    print(lists[i])

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

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

int gcb(int a,int b){
  if(a==b) return a;
  if(b==0) return a;
  return gcb(b,a%b);
}
int main(){
  int n,X,g;
  int x[100005]={0};
  cin>>n>>X;
  for(int i = 0;i<n;i++)  cin>>x[i];
  if(n==1) g=abs(X-x[0]);
  else if(abs(X-x[0])<abs(X-x[1])){
    g = gcb(abs(X-x[1]),abs(X-x[0]));
  } else{
    g = gcb(abs(X-x[0]),abs(X-x[1]));
  }
  for(int i=2;i<n;i++){
    g=gcb(abs(X-x[i]),g);
  }
  cout<<g<<endl;


}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
#define repd(i,a,b) for (int i=a;i<int(b);i++)
#define rep(i,n) repd(i,0,n)
#define VARNAME(v) #v
using P = pair<int,int>;


int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int BEAM = 870;
  int d;vector<int> c(26);cin>>d;rep(i,26)cin>>c[i];
  vector<array<int, 26>> s(d);
  rep(i,d)rep(j,26)cin>>s[i][j];
  vector<int> curs = {0};
  vector<array<int, 26>> curl(1);
  vector<vector<int>> cura(1);
  rep(i,d){
    int len = int(curs.size()) * 26, ind = 0;
    vector<P> nxs(len);
    vector<array<int, 26>> nxl(len);
    vector<vector<int>> nxa(len);
    rep(j, curs.size()){
      rep(t, 26){
        int score = curs[j];
        array<int, 26> last = curl[j];
        vector<int> ans = cura[j];
        score += s[i][t];
        last[t] = i+1;
        rep(k,26)score -= c[k]*(i+1 - last[k]);
        ans.emplace_back(t);
        nxs[ind] = P(score, ind);
        nxl[ind] = last;
        nxa[ind] = ans;
        ind++;
      }
    }
    sort(nxs.rbegin(), nxs.rend());
    len = min(len, BEAM);
    curs.resize(len);curl.resize(len);cura.resize(len);
    rep(j,len){
      curs[j] = nxs[j].first;
      curl[j] = nxl[nxs[j].second];
      cura[j] = nxa[nxs[j].second];
    }
    if(i % 73 == 0)BEAM -= 70;
  }
  int ans = 0;
  rep(i,min(int(curs.size()), BEAM)){
    if(curs[ans] < curs[i])ans = i;
  }

  for(auto x : cura[ans]){
    cout << x+1 << endl;
  }
}


Measured memory_bytes: 25724
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_N = 100;
int N, K;
int X[MAX_N];
int main(){
scanf("%d", &N);
scanf("%d", &K);
for(int i = 0; i < N; ++i){
scanf("%d", X + i);
}
int ans = 0;
for(int i = 0; i < N; ++i){
int tmp = min(X[i], K - X[i]);
ans += tmp;
}
printf("%d\n", ans * 2);
return 0;
}


Measured memory_bytes: 128
#pragma comment(linker, "/stack:20000000") comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd __gcd
//#define int ll
using namespace std;
//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 40, T = 4 * N, inf = 1e9 + 7;
ll n, m, f, r, l, e, w, o, z, test, id, mx = -inf;
ll a[N], d[N], b[N];

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}
void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
main()
{
    //freop();
    boos();
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        e += b[i];
    }
    memset(d, inf, sizeof d);
    d[0] = 0;
    for (int j = 0; j < n; j++)
    {
        for (int i = e; i >= 0; i--)
        {
            if (!i || (d[i] != inf && d[i]))
            {
                d[i + b[j]] = min(d[i + b[j]], d[i] + a[j]);
            }
        }
    }
    for (int i = e; i >= 0; i--)
    {
        if (d[i] > m || d[i] == inf) continue;
        cout << i;
        return 0;
    }
}


Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(500000)

N = int(input())
*H, = map(int, input().split())
dp  = [-1]*N

def dfs(n):#足場nまでにたどり着くための最小コスト
    
    if n==0:
        return 0
    if n-1==0:
        return abs(H[n]-H[n-1])
    if dp[n]!=-1:
        return dp[n]
    ans = min(abs(H[n]-H[n-1])+dfs(n-1), abs(H[n]-H[n-2])+dfs(n-2))
    dp[n] = ans
    return ans

print(dfs(N-1))

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

int par[5000];
int find(int x){
	if(par[x]==-1)return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);y=find(y);
	par[x]=y;
}
struct st{int a,b,c;};

int s[200000],t[200000];
int l[200000],r[200000];
vector<int>query[5000];

int main(){
	int n,m;scanf("%d%d",&n,&m);
	vector<st>v,u;
	rep(i,m){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		v.push_back({a,b,c});
	}
	sort(v.begin(),v.end(),[](st a,st b){return a.c<b.c;});
	memset(par,-1,sizeof(par));
	ll cnt=0;
	for(st&p:v){
		if(find(p.a)==find(p.b))continue;
		cnt+=p.c;unite(p.a,p.b);
		u.push_back(p);
	}
	int q;scanf("%d",&q);
	rep(i,q){
		scanf("%d%d",&s[i],&t[i]);s[i]--;t[i]--;
		l[i]=0;r[i]=n-1;
	}
	rep(i,15){
		rep(j,n-1)query[j].clear();
		rep(j,q){
			if(r[j]-l[j]>1)query[(l[j]+r[j])/2].push_back(j);
		}
		memset(par,-1,sizeof(par));
		rep(j,n-1){
			for(int k:query[j]){
				if(find(s[k])!=find(t[k]))l[k]=j;
				else r[k]=j;
			}
			unite(u[j].a,u[j].b);
		}
	}
	rep(i,q){
		printf("%lld\n",cnt-u[l[i]].c);
	}
}

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

int n;
vector<int> p;
int w[25];
int x[5] = {3, 5, 15, 25, 75};
int y[5];
int ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=2; i<=100; ++i){
		bool f = true;
		for(int j=0; j<p.size(); ++j){
			if(i % p[j] == 0){
				f = false;
			}
		}
		if(f) p.push_back(i);
	}
//	cout << p.size() << "\n";
//	for(int i=0; i<p.size(); ++i)
//		cout << p[i] << (i+1 == p.size() ? "\n" : " ");
	for(int i=2; i<=n; ++i){
		int t = i;
		for(int j=0; j<p.size(); ++j){
			while(t % p[j] == 0){
				++w[j];
				t /= p[j];
			}
		}
	}
	for(int i=0; i<25; ++i)
		for(int j=0; j<5; ++j)
			if(x[j]-1 <= w[i])
				++y[j];
//	for(int i=0; i<5; ++i)
//		cout << y[i] << "\n";
	ans = y[4] + y[3] * (y[0] - 1) + y[2] * (y[1] - 1) + y[1] * (y[1] - 1) * (y[0] - 2) / 2;
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <set>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	int n;
	cin >> n ;
	vector<ll> x(n);
	ll ans = 0;

	for (int i = 0; i < n; i++) 
	{
		cin >> x[i];
		ans += x[i];
	}
	cout<< ans - n << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge
{
    ll to, cost, val;
};
template <class T, class U>
bool chmin(T &a, const U &b)
{
    if (a <= b)
        return false;
    a = b;
    return true;
}
template <class T, class U>
bool chmax(T &a, const U &b)
{
    if (a >= b)
        return false;
    a = b;
    return true;
}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll

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

    int N;
    cin>>N;
    if(N==3 || N==4){
        if(N==3) cout<<"2 5 63"<<endl;
        else cout<<"2 5 20 63"<<endl;
        return 0;
    }
    //N%8で場合分け
    int x;
    if(N%8==7 || N%8==5 || N%8==6) x=N;
    else x=N/8*8;
    int count=0;
    int now=0;
    vector<int> ans;
    while(count<x){
        while(now%2!=0 && now%3!=0 || now==0){
            now++;
        }
        ans.push_back(now);
        count++;
        now++;
    }
    now--;
    if(N%8==1) ans.push_back(now+6);
    else if(N%8==2){
        ans.push_back(now+6);
        ans.push_back(now+12);
    }else if(N%8==3){
        for(int i=3;i<=9;i+=3) ans.push_back(now+i);
    }else if(N%8==4){
        for(int i=3;i<=12;i+=3) ans.push_back(now+i);
    }else if(N%8==5){
        ans[count-1]++;
    }else if(N%8==6){
        ans[count-2]+=4;
    }
    //cout<<(int)ans.size()<<endl;
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,n-1){
        cin >> c[i];
    }
    int get = 0;
    rep(i,n){
        get += b[a[i]-1];
        if(a[i-1]+1 == a[i])
            get += c[a[i - 1] - 1];
    }
    cout << get << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long n;
  cin>>n;
  
  int minimum=100;
  for(long long i=1;i*i<=n;i++){
    if(n%i==0){
      long long a=i;
      long long b=n/a;
      int cnt1=0;
      int cnt2=0;
      while(a>0){
	cnt1++;
	a/=10;
      }
      while(b>0){
	cnt2++;
	b/=10;
      }
      minimum=min(minimum,max(cnt1,cnt2));
    }
  }
  cout<<minimum<<endl;
  return(0);
}

Measured memory_bytes: 3644
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

typedef pair<int, int> pint;
typedef long long ll;

#define int ll

//get vector of prime numbers which is lower than or equal n
vector<int> get_primes(int n)
{
    vector<bool> is_prime(n + 1, true);
    vector<int> res;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            res.push_back(i);
            for (int j = 2 * i; j < is_prime.size(); j = j + i)
            {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

vector<pair<int, int>> factorize(int n)
{
    vector<pair<int, int>> res;
    for (int i = 2; i * i <= n; i++)
    {
        int tmp = 0;
        while (n % i == 0)
        {
            tmp++;
            n /= i;
        }
        res.push_back(make_pair(i, tmp));
    }
    if (n != 1)
    {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

int mpow(int x, int n)
{
    int res = 1;
    while (n != 0)
    {
        if (n & 1)
            res = res * x % INF;
        x = x * x % INF;
        n = n >> 1;
    }
    return res;
}

//mod frac
vector<int> mfrac;
void set_mfrac(int n)
{
    if (mfrac.size() == 0)
    {
        mfrac.push_back(1);
    }
    for (int i = mfrac.size(); i <= n; i++)
    {
        mfrac.push_back((i * mfrac[i - 1]) % INF);
    }
}

//get nCm mod INF
int mcomb(int n, int m)
{
    if (mfrac.size() <= n)
    {
        set_mfrac(n);
    }
    int res = mfrac[n];
    res = res * mpow(mfrac[m], INF - 2) % INF;
    res = res * mpow(mfrac[n - m], INF - 2) % INF;
    return res;
}

signed main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> fact = factorize(M);
    int ans = 1;
    for (int i = 0; i < fact.size(); i++)
    {
        //cout << fact[i].first << " " << fact[i].second << endl;
        ans = ans * mcomb(N - 1 + fact[i].second, N - 1) % INF;
    }
    cout << ans << endl;
}

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

int main()
{
 int x;
 cin>>x;
 int n;
 cin>>n;
 set<int> st;
 for(int i=0;i<n;i++)
 {
     int c;
     cin>>c;
    st.insert(c);
 }
 
 int i=x;
 while(st.find(i)!=st.end())
 i++;
 int j=x;
 while(st.find(j)!=st.end())
 j--;
 
 int ans;
 if(abs(i-x) > abs(j-x))
 {
     ans=j;
 }
 else if(abs(i-x) < abs(j-x))
 ans=i;
 
 else
 {
     ans=j;
 }
 
 cout<<ans;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string operation(string s){
	string ret = "";
	int it = 0;
	while(it < s.size()){
		int cnt = 1;
		while(it < s.size()-1 && s[it] == s[it+1]){
			cnt++;
			it++;
		}
		ret += to_string(cnt) + s[it];
		it++;
	}
	return ret;
}

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

	while(true){
		int n; cin >> n;
		if(n==0) break;
	 	string s; cin >> s;

		for (int i = 0;i < n;i++){
			s = operation(s);
		}

		cout << s << endl;
	}

	return 0;

}


Measured memory_bytes: 3332
n,m,x = map(int, input().split())
C = [0]*n
A = []

for i in range(n):
    Q = list(map(int, input().split()))
    C[i] = Q[0]
    A.append(Q[1:])

ans = 10**7

for i in range(1 << n):
    res = True
    skill = [0]*m
    money = 0
    for j in range(n):
        if (i>>j)&1:
            for k in range(m):
                skill[k] += A[j][k]
            money += C[j]

    for s in skill:
        if s < x:
            res = False
    
    if res:
        ans = min(ans,money)

if ans == 10**7:
    print(-1)
else:
    print(ans)




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

int main(void){
    int n,t;
    cin>>n>>t;
    ll sum=0, cycle=0;
    rep(i,n) {
        ll h;
        cin>>h;
        cycle = max(cycle, h);
        ll tt = t-sum;
        ll res = tt/cycle + 1;
        if(tt%cycle >= h) res++;
        cout<<max(res,1LL)<<endl;
        sum += h;
    }
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
const ll mod = 1000000007;


int main() {
int n;
cin>>n;
string s;
cin>>s;
int sum=1;
r(i,n-1){
  if(s.at(i)!=s.at(i+1))sum++;
}

cout<<sum<<endl;





  return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    }

    public static int check(int num) {
        int cnt = 0;
        for(int i = 1; i <= Math.sqrt(num); i++) {
            if(num % i == 0) {
                cnt += num / i == i ? 1 : 2;
            }
        }
        
        return num %2 == 1 && cnt == 8 ? 1 : 0;
    }
}


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

using namespace std;


typedef long long ll;
ll mod=1e9+0LL;
ll MOD=1e18+0LL;
#define line printf("\n")
double pi=acos(-1);
ll md=1000000007;
ll gcd(ll a,ll b){
    //if(b>a) swap(a,b);
    return b==0?abs(a):gcd(b,a%b);
}
ll poW(ll a ,ll n)
{
    if(n==0) return 1;
    if(n%2==0)
    {
        ll b=poW(a,n/2);
        return (b*b)%md;
    }
    return (poW(a,n-1)*a)%md;
}

char gap=' ';






















//vector<int>v[200100];
//bool visit[200100]={0};
//int vc[200100]={0};
//
//
//int cnt;
//void dfs(int s,int c=0)
//{
//    if(visit[s]) return;
//    cnt++;
//        visit[s]=1;
//
//        for(int i=0;i<v[s].size();i++) {
//                dfs(v[s][i]);
//        }
//
//}


int main()
{
    int cs=1;
    //scanf("%d",&cs);
    while(cs--)
    {
       int n,x,i,a;
       bool ok[105]={0};
       cin>>x>>n;
       for(i=0;i<n;i++)
       {
           cin>>a;
           ok[a]=1;
       }
       int p;
       for(i=0;i<=100;i++)
       {
           int l=x-i;
           int r=x+i;
           if(l<0) {p=l;break;}
           else if(l>=0 && !ok[l])
           {
               p=l;break;
           }else if(!ok[r])
           {
               p=r;break;
           }
       }
       cout<<p;
    }
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        System.out.println((b % a == 0) ? a + b : b - a);
    }
}


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

int ans[2005];
bool arr[2005];
vector<int> adjl[2005];
int n;
int temp;

pair<int,int> getans(int node, int parent){
    int numnode = 0;
    int dist = 0;
    for (int x : adjl[node]){
        if (x==parent) continue;
        auto t = getans(x,node);
        numnode += t.first;
        dist += t.second;
    }
    dist += numnode;
    if (arr[node]) numnode++;
    return {numnode,dist};
}

/// max, min,  numnodes
pair<pair<int,int>,int> func(int node, int parent){
    int maxv = 0;
    int numnodes = 0;
    pair<int,int> maxp = {0,0};
    for (int x : adjl[node]){
        if (x==parent) continue;
        auto res = func(x,node);
        res.first.first += res.second;
        res.first.second+=res.second;
        maxv += res.first.first;
        maxp = max(maxp,res.first);
        numnodes += res.second;
    }
    int minv = max(0,maxp.second-maxv+maxp.first);
    if (maxv%2==1){
        minv = max(minv,1);
    }
    if (arr[node]) numnodes++;



    return {{maxv,minv},numnodes};
}


int main(){
    scanf("%d",&n);
    for (int x = 0; x<n; x++){
        char c;
        scanf(" %c",&c);
        arr[x] = (c=='1');
    }
    for (int x = 0; x<n-1; x++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;b--;
        adjl[a].push_back(b);
        adjl[b].push_back(a);
    }
    int finalans = 1000000000;
    for (int x = 0; x<n; x++){
        ans[x] = getans(x,-1).second;
        if (ans[x]%2==0){
            temp = x;
            if (func(x,-1).first.second==0){
                //printf("%d is possible\n",x+1);
                finalans = min(finalans,ans[x]/2);
            }
        }
    }
    printf("%d",finalans==1000000000?-1:finalans);
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int h, w;
char input[51][51];
map<char, int> m;
vector<vector<int> > v;

bool isfront(int now, char tgt, vector<int> range)
{
	for(int i = range[0]; i <= range[2]; i++){
		for(int j = range[1]; j <= range[3]; j++){
			if(input[i][j] < 0 || (input[i][j] != tgt && (now & (1 << input[i][j])) != 0)) return false;
		}
	}
	return true;
}

bool issafe()
{
	int tmp = m.size();
	// cout << tmp << endl;
	if(tmp == 0) return true;
	vector<bool> result(1 << tmp, false);
	result[0] = true;
	for(int i = 0; i < (1 << tmp); i++){
		if(!result[i]) continue;
		for(int j = 0; j < tmp; j++){
			if((i & (1 << j)) != 0) continue;
			vector<int> tmp = v[j];
			// cout << j << " : " << endl;
			// 	for(int l = 0; l < 4; l++){
			// 		cout << tmp[l] << " ";
			// 	}
			// 	cout << endl;
			result[(i | (1 << j))] = result[(i | (1 << j))] || isfront(i, j, tmp);
			// cout << result[(i | (1 << j))] << endl;
		}
	}
	return result[(1 << tmp) - 1];
}

int main()
{
	int num;
	cin >> num;
	for(int i = 0; i < num; i++){
		m.clear();
		v.clear();
		int cnt = 0;
		cin >> h >> w;
		for(int j = 0; j < h; j++){
			for(int k = 0; k < w; k++){
				char tmp;
				cin >> tmp;
				if(tmp == '.'){
					input[j][k] = -1;
					continue;
				} else if(m.find(tmp) == m.end()){
					v.push_back(vector<int>{j, k, j, k});
					m[tmp] = cnt;
					cnt++;
					// cout << tmp << "->" << cnt-1 << endl;
				}
				input[j][k] = m[tmp];
				v[m[tmp]][0] = min(v[m[tmp]][0], j);
				v[m[tmp]][1] = min(v[m[tmp]][1], k);
				v[m[tmp]][2] = max(v[m[tmp]][2], j);
				v[m[tmp]][3] = max(v[m[tmp]][3], k);
			}
		}
		if(issafe()) cout << "SAFE" << endl;
		else cout << "SUSPICIOUS" << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
import java.util.Scanner;

public class Main {
    public static void trace(int[] a, int n) {
        for (int i = 0; i < n; i++) {
            if (i > 0)
                System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.print("\n");
    }

    public static int bubbleSort(int[] a, int n) {
        int i = 0;
        int count = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = n - 1; j >= i + 1; j--) {
                if (a[j] < a[j - 1]) {
                    int temp = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = temp;
                    flag = true;
                    count++;
                }
            }
            i++;
        }
        return count;
    }

    public static void main(String[] args) {
        int n;
        int[] a = new int[100];
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 0; i < n; i++)
            a[i] = sc.nextInt();
        int count = bubbleSort(a, n);
        trace(a, n);
        System.out.println(count);
    }
}



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

int a[100000];

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++)
		cin >> a[i];

	map<int, int> mp;
	for (int i = 0; i < N; i++)
		mp[a[i]]++;

	int ans = 0;
	for (auto p: mp) {
		int x = p.first;
		int n = p.second;
		if (n < x) ans += n;
		else ans += n - x;
	}

	cout << ans << endl;
}



Measured memory_bytes: 5120
n, m = map(int, input().split())
G = [[] for i in range(n)]
I = [0 for i in range(n)]
for j in range(m):
    x, y = map(int, input().split())
    G[x-1].append(y-1)
    I[y-1] += 1
# Q:出発点の候補
Q = [i for i in range(n) if I[i] == 0]
# L[i]=iを終点とする最長パスの長さ
L = [0 for i in range(n)]
while Q:
    i = Q.pop()
    while G[i]:
        j = G[i].pop()
        I[j] -= 1
        L[j] = max(L[j], L[i]+1)
        if I[j] == 0:
            Q.append(j)
print(max(L))


Measured memory_bytes: 19692
#include <iostream>
#include<deque>
#include<numeric>
using namespace std;

int main()
{

    int N;
    cin >> N;
    long long ans = 0;
    for (int i = 1; i <= N; i++)
    {

        for (int k = 1; k <= N;++k)
            for (int m = 1; m <= N;++m)
                    ans += gcd(gcd(i,k),m);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll MAX_ANS=1e3;
ll X;
bool isans(ll a,ll b){
	return a*a*a*a*a-b*b*b*b*b==X;
}
void prt(ll a,ll b){
	cout<<a<<' '<<b<<endl;
}
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>X;
	REP(a,1e3){
		REP(b,a){
			if(isans(a,b)){
				prt(a,b);
				return 0;
			}
		}
	}
	REP(a,1e3){
		REP(b,1e3){
			if(isans(a,-b)){
				prt(a,-b);
				return 0;
			}
		}
	}
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

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

    
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 3624
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

G = [0] * N

for a, b in AB:
    a -= 1
    b -= 1
    G[a] = max(G[a], H[b])
    G[b] = max(G[b], H[a])

ans = 0
for i in range(N):
    if G[i] < H[i]:
        ans += 1

print(ans)

Measured memory_bytes: 32020
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, s, t, d[3][100005] = {};
    vector<int> g[100005] = {};
    cin >> n >> m;
    while (m--) cin >> u >> v, g[u].push_back(v);
    cin >> s >> t;
    queue<pii> q;
    q.push({0, s});
    d[0][s] = 1;
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int i : g[y]) {
            if (!d[(x + 1) % 3][i]) d[(x + 1) % 3][i] = d[x][y] + 1, q.push({(x + 1) % 3, i});
        }
    }
    if (d[0][t]) cout << (d[0][t] - 1) / 3;
    else cout << -1;
}


Measured memory_bytes: 6912
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

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

int main(){
  int C,M,N,Y,cmd[110],pay[110];
  double per[110];
  int i,j;

  scanf("%d",&M);
  while(M--){
    scanf("%d",&C);
    scanf("%d",&Y);
    scanf("%d",&N);
    REP(i,N) scanf("%d %lf %d",&cmd[i],&per[i],&pay[i]);

    int res = C;
    REP(i,N){
      if(cmd[i] == 1){
        int tmp = C;
        REP(j,Y){
          tmp *= 1.0 + per[i];
          tmp -= pay[i];
        }
        res = max(res,tmp);
      } else {
        int tmp = C;
        int cache = 0;
        REP(j,Y){
          cache += tmp * per[i];
          tmp -= pay[i];
        }
        res = max(res, tmp + cache);
      }
    }
    printf("%d\n",res);
  }

  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    vll a(n);
    bitset<50> b[n];
    loop(i,0,n)
    {
        IN a[i];
        bitset<50> temp(a[i]);
        b[i]=temp;
    }
    bitset<50> ans(0);
    rloop(i,49,0)
    {
        int countt=0;
        loop(j,0,n)
        {
            if(b[j][i])
            {
                countt++;
            }
            //cout<<"";
        }
        //cout<<"";
        ans[i]=1;
        if((countt*2)<n && ans.to_ullong()<=k)
        {
            //Do Nothing
        }
        else
        {
            ans[i]=0;
        }
    }
    ll fans=0LL;
    //cout<<"";
    ll X=ans.to_ullong();
    loop(i,0,n)
    {
        //cout<<"";
        fans+=(X^a[i]);
    }
    OUT fans<<endl
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void) 
{
	int a, b, tmp, count;
	while (1) {
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			break;
		}
		if(a < b) { 
            		tmp = b; 
            		b = a; 
            		a = tmp; 
            		} 
		count = 0; 
		do {
			a = a % b;
			tmp = b;
			b = a;
			a = tmp;
			count++;
		} while (b != 0);
		printf("%d %d\n", a, count);
	}
	return 0;
}


Measured memory_bytes: 1980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
    else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) cout << "Yes" << endl;
    else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 15;
bool bad[MAX_N][MAX_N];
vector<int> a, b;

void mke(int n, int m) {
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j < n; j ++) {
            bad[i][j] = false;
        }
    }
}

void outputOdd(int off, int n, int m) {
    for(int raz = 0; raz < m; raz ++) {
        cout << raz + off << " " << n - raz - 1 << endl;
    }

}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    if(n & 1) {
        outputOdd(1, n, m);
        return 0;
    }
    for(int raz = 0; raz < m; raz ++) {
        ll now = n - raz - raz - 1;
        if(now * 2 <= n) {
            outputOdd(raz + 1, n - raz, m - raz);
            return 0;
        }
        cout << raz + 1 << " " << n - raz << endl;
    }
    return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n, ans = 1;
	cin >> n;
	vector<char> v(n);
	rep(i, n) {
		cin >> v[i];
	}
	sort(all(v));
	for(int i=1;i<n;i++){
		if (v[i - 1] != v[i]) ans++;
	}
	cout << (ans==3?"Three":"Four") << endl;
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 
#define MODB  998244353

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

int main() {
	ll ans = 0;
	ll tmp;
	int n, m; cin >> n >> m;
	map<ll, int> co, ba;
	REP(i, n){
		cin >> tmp;
		co[tmp]++;
		ba[tmp%m]++;
	}
	REP1(i, m-1){
		if(i != m-i){
			tmp = min(ba[i], ba[m-i]);
			ans += tmp;
			ba[i] -= tmp;
			ba[m-i] -= tmp;
		}
		else{
			ans += ba[i] / 2;
			ba[i] = ba[i] % 2;		
		}
	}
	ans += ba[0] / 2;
	ba[0] = ba[0] % 2;
	REP1(i, 100000){
		if(co[i] >= 2 && ba[i%m] >= 2){
			tmp = min(co[i], ba[i%m]) / 2;
			ans += tmp;
			ba[i%m] -= tmp * 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 16092
#include<iostream>
#include<vector>
#include<utility>
#include<climits>
#include<algorithm>
#define ll long long
#define rep(i, n) for(i=0; i<n; i++)
#define rep1(i, n) for(i=1; i<=n; i++)
#define mp make_pair
#define pb push_back
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n, m, i, count = 0;
	cin >> n >> m;
	ll l, r, lm=0, rm=INT_MAX;
	rep(i, m){
		cin >> l >> r;
		lm = max(l, lm);
		rm = min(r, rm);
	}
	rep1(i, n){
		count = (i>=lm && i<=rm)? count+1 : count;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e3+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
//inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,F[MAXN],dis[MAXN],sz[MAXN],ans=1e9;vector<int>G[MAXN];char s[MAXN];
void dfs(int x,int fa){
	dis[x]=0,sz[x]=s[x]-48,F[x]=0;int Mx=0;
	for(int i=0,len=G[x].size(),y;i<len;i++)if((y=G[x][i])!=fa){
		dfs(y,x),dis[x]+=dis[y]+=sz[y],sz[x]+=sz[y],dis[y]>dis[Mx]?Mx=y:0;
	}if(2*dis[Mx]<=dis[x])F[x]=dis[x]/2;else F[x]=dis[x]-dis[Mx]+min(F[Mx],(2*dis[Mx]-dis[x])/2);
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),scanf("%s",s+1);
	Rep(i,1,n-1){int x=read(),y=read();G[x].push_back(y),G[y].push_back(x);}
	Rep(i,1,n){dfs(i,0);if((!(dis[i]&1))&&(F[i]*2>=dis[i]))ans=min(ans,dis[i]/2);}
	if(ans<1e9)cout<<ans<<"\n";else puts("-1");
	return 0;
}




Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF=1001001;
int main(){
  ll n,m;
  cin>>n>>m;
  if (n==1){
    if (m==1)cout<<1;
    else if (m==2)cout<<0;
    else {
      cout<<m-2;
    }
    return 0;
  }

  else if (m==1){
    if (n==1)cout<<1;
    else if (n==2)cout<<0;
    else {
      cout<<n-2;
    }
    return 0;
  }

  else if (n==2 or m==2){
    cout<<0;
  }

else{
  ll x=n-2;
  ll y=m-2;
  cout<<ll(x*y);
}







}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int dx[] = {-1,0};
int dy[] = {0,-1};
ll mod = 1e9+7;
ll dp[1005][1005];
vector<string>a;
int h,w;
bool isrange(int x,int y){
    return 0<=x and x < h and 0<=y and y < w;
}
ll dfs(int x,int y){
    if(dp[x][y] != -1)return dp[x][y];
    ll res = 0;
    rep(i,2){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if(isrange(xx,yy) and a[xx][yy] != '#'){
            res += dfs(xx,yy);
        }
    }
    return dp[x][y] = res % mod;
}
int main(){
    cin >> h >> w;
    rep(i,h)rep(j,w)dp[i][j] = -1;
    dp[0][0] = 1;
    a.resize(h);
    rep(i,h)cin >> a[i];
    cout << dfs(h-1,w-1) << endl;
}

Measured memory_bytes: 9344
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 105
int n,m;
int main()
{
	scanf("%d %d",&n,&m);
	int t=m/n;
	for(int i=t;i>=1;i--)
		if(m%i==0)
		{
			printf("%d\n",i);
			return 0;
		}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct UnionFind {
	vector<int> par, rank;
	int N;

	UnionFind(int n) {
		N = n;
		par.resize(n);
		rank.resize(n);

		rep(i, n) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x) {
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if(x == y) return;

		if(rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	int size() {
		int cnt = 0;
		rep(i, N) if(find(i) == i) cnt++;
		return cnt;
	}
};

int main() {
	int n, m;
	cin >> n >> m;

	set<int> st[m + 5];
	rep(i, n) {
		int k;
		cin >> k;

		rep(j, k) {
			int l;
			cin >> l;

			st[l].insert(i);
		}
	}

	// cout << "print set" << endl;
	// rep(i, m + 1) {
	// 	cout << i << " |";
	// 	each(it, st[i]) cout << *it + 1 << " ";
	// 	cout << endl;
	// }
	//
	UnionFind uf(n + 5);
	rep(i, m) {
		if(st[i+1].size() <= 1) continue;
		int pre = *(st[i+1].begin());
		each(it, st[i+1]) {
			uf.unite(pre, *it);
		}
	}

	int cnt = 0;
	rep(i, n) {
		if(uf.find(0) == uf.find(i)) cnt++;
	}

	if(cnt == n) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <math.h>
#include <string>
using namespace std;
 
const double PI = acos(-1);
const int M=998244353;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define oo 1e16


int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	
	int n,m,k;
	cin>>n>>m>>k;
	vi a(n);
	vi b(m);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < m; ++i)
	{
		cin>>b[i];
	}
	int depth = 0;
	for (int i = 0; i < n; ++i)
	{
		if(k-a[i]>=0){
			depth++;
			k-=a[i];
		}else{
			break;
		}
	}
	int mxdepth=0;
	int j=0;
	for (int i = depth; i>=0; i--)
	{
		while(k-b[j]>=0){
			if(j==m) break;
			k-=b[j];
			j++;
		}
		mxdepth=max(mxdepth,(i+j));
		if(i==0) 
			break;
		else{ 
			k+=a[i-1];
			//printf("k+=%d\n",a[i-1] );
		}
	}
	printf("%d\n",mxdepth );


	return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, M, Q; cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  rep(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  int A[10];
  int ans = 0;
  for (int i1 = 1; i1 <= M; ++i1){
    for (int i2 = i1; i2 <= M; ++i2){
      for (int i3 = i2; i3 <= M; ++i3){
        for (int i4 = i3; i4 <= M; ++i4){
          for (int i5 = i4; i5 <= M; ++i5){
            for (int i6 = i5; i6 <= M; ++i6){
              for (int i7 = i6; i7 <= M; ++i7){
                for (int i8 = i7; i8 <= M; ++i8){
                  for (int i9 = i8; i9 <= M; ++i9){
                    for (int i10 = i9; i10 <= M; ++i10){
                      A[0] = i1, A[1] = i2, A[2] = i3, A[3] = i4, A[4] = i5, A[5] = i6, A[6] = i7, A[7] = i8, A[8] = i9, A[9] = i10;
                      int sum = 0;
                      for (int q = 0; q < Q; ++q){
                        if (A[b[q]] - A[a[q]] == c[q]) sum += d[q];
                      }
                      ans = max(ans, sum);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int n, k;
//int a[n+1];

int main()
{   
 
    {
    cin>>n;cin>>k;
    int a[n+1];
    for(int i=1;i<=n;++i)
    {
        cin>>a[i]; 
    }
    const int mod = 1000000007;
    long dp[n+1][k+1]={0};
    for(int i=1;i<=n;++i)
    {dp[i][0]=1;}
    for(int j=1;j<=a[1];++j)
        dp[1][j]=dp[1][j-1]+1;
    for(int j=a[1]+1;j<=k;++j)
        dp[1][j]=dp[1][j-1];
    for(int i=2;i<=n;++i)
    {
        for(int j=1;j<=k;++j)
            {   if(j-a[i]-1>=0)
                dp[i][j]=((dp[i-1][j]-dp[i-1][j-a[i]-1]+mod)%mod+dp[i][j-1])%mod;
            
                else
                dp[i][j]= (dp[i-1][j]+dp[i][j-1])%mod;
            }
    }
   if(k==0) cout<<dp[n][k]<<endl;
   else
   cout<<(dp[n][k]-dp[n][k-1]+mod)%mod<<endl;
   /*for(int i=0;i<=n;++i)
    {
        for(int j=0;j<=k;++j)
            {
               cout<<dp[i][j]<<" "; 
            }
    cout<<endl;
    }*/
}
}




Measured memory_bytes: 78592
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll N;
vector<ll> V, C;

int dfs(int i, int value, int cost) {
  if (i == N) return value - cost;
  int cand1 = dfs(i + 1, value + V[i], cost + C[i]);
  int cand2 = dfs(i + 1, value, cost);
  return max(cand1, cand2);
}

int main() {
  cin >> N;
  V.resize(N), C.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  int ans = dfs(0, 0, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612