akhauriyash/Code-Regression huggingface dataset:
N = map(int, input().split())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_ave = 1000000

for i in range(len(H)):
    tem = T - (H[i]*0.006)
    if min_ave > abs(A-tem):
        min_ave = abs(A-tem)
        min_num = i+1

print(min_num)
        

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define pb push_back
#define all(V) V.begin(),V.end()
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%I64d",&x)
#define pii pair<int,int>
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x)  cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};

void solve(){
    LL a; cin >> a;
    cout << (a) * (a + 1) / 2 << endl;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("Local.in","r",stdin);
    freopen("ans.out","w",stdout);
    #endif
    solve();
    return 0;
}

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

int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]=='#'){
				row[i]=true;
				col[j]=true;
			}
		}
	}
	for(int i=0;i<h;i++){
		if(row[i]){
			for(int j=0;j<w;j++){
				if(col[j]){
					cout<<a[i][j];
				}
			}
			cout<<endl;
	}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

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

    int s = 0;
    int ma;
    for (int i = 1;; ++i) {
        s += i;
        if (n <= s) {
            ma = i;
            break;
        }
    }

    for (int i = 1; i <= ma; ++i) {
        if (i != s - n)
            printf("%d\n", i);
    }

    return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll n, x;

vector<ll> a;

ll mans = 1e9*1e8;

vector<vector<ll> > mmin;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n >> x;

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

  mmin.resize(n);
  for (int i = 0; i < n; i++) {
    mmin[i].resize(n);
  }

  for (int i = 0; i < n; i++) {
    mmin[i][i] = a[i];
    for (int j = (i+1)%n; j != i; j = (j+1)%n) {
      mmin[i][j] = min(mmin[i][(j-1+n)%n], a[j]);
    }
  }

  /*for (int i =0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << mmin[i][j] << ' ';
    } cout << endl;
  }*/

  for (int i = 0; i < n; i++) {
    ll cans = x*i;
    for (int j = 0; j < n; j++) {
      cans += mmin[j][(j+i)%n];
    }

    mans = min(mans, cans);
    //cerr << "for  " << i << " " << cans << endl;
  }

  cout << mans << endl;
}



Measured memory_bytes: 31616
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
        long N = scan.nextLong();
long N500=N-N%500;
long N5=N-N500-N%5;

long p=N500*2+N5;
System.out.println(p);


    }

}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if(A >= B){
    cout << "delicious" << endl;
  }else if(X+A < B){
    cout << "dangerous" <<endl;
  }else{
    cout << "safe" <<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String args[]){
			Scanner in = new Scanner(System.in);
			int a = in.nextInt();
			int b = in.nextInt();

			int area = 0;
			int perimeter = 0;

			area = a * b;
			perimeter = a * 2 + b * 2;
			System.out.println(area + " " + perimeter);
	}
}

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

typedef long long ll;

const int Maxn = 200005;

char str[Maxn];
int slen;
ll res;

int main()
{
    scanf("%s", str);
    slen = strlen(str);
    int cur = slen - 1;
    for (int i = slen - 1; i >= 0; i--)
        if (str[i] == 'B') {
            res += cur - i;
            cur--;
        }
    cout << res << endl;
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*GRAPH_TEMPLATE=============================================*/
template<typename T>
class Edge {
public:
    int srch; //searched?探索状態記録「null = -1」
    int to; //辺の行き先
    T cost; //辺の重み
    Edge(int t, T w) : srch(-1), to(t), cost(w) {}
    Edge(int src, int t, T w) : srch(src), to(t), cost(w) {}
};
template<typename T>
using W_Graph = vector<vector<Edge<T>>>;   //重み付きグラフ
using Graph = vector<vector<int>>;         //通常グラフ
template<typename T>
using Matrix = vector<vector<T>>;          //隣接行列(使わなさそう...)

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    W_Graph<ll> g(n);
    rep(i,n-1) {
        int a,b,c; cin >>a>>b>>c;
        --a;--b;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }
    int q,k; cin >> q >> k;
    --k;
    vec<PII> xy(q);
    rep(i,q) {
        cin >> xy[i].first >> xy[i].second;
        --xy[i].first;
        --xy[i].second;
    }

    //dijkstraでｋからの距離を前計算
    vll dist(n, infll);
    using P = pair<ll, int>;
    priority_queue<P, vec<P>, greater<P>> que;
    dist[k] = 0;
    que.emplace(0,k);
    while(que.size()) {
        ll d; int u;
        tie(d,u) = que.top(); que.pop();
        for(auto v : g[u]) {
            if(!chmin(dist[v.to], dist[u]+v.cost)) continue;
            que.emplace(dist[v.to], v.to);
        }
    }

    //query
    rep(i,q) {
        int x, y;
        tie(x,y) = xy[i];
        cout << dist[x] + dist[y] << endl;
    }
}

Measured memory_bytes: 11888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  int dig[4];
  rep(i,4) dig[i] = -1;
  int N,M;
  cin >> N >> M;
  bool f = true;
  rep(i,M){
    int s,c;
    cin >> s >> c;
    if(s == 1 && c == 0 && N!=1){
      cout << -1 << endl;
      return 0;
    }
    
    if(dig[s] == -1 || dig[s] == c) dig[s] = c;
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  if(N == 1 && M == 0){
    cout << 0 << endl;
    return 0;
  }
  if(dig[1] == 0 && N == 1 && f) cout << 0 << endl;
  else{
    rep(i,N){
      if(i == 0 && dig[i+1] == -1) cout << 1;
      else if(dig[i+1]>0) cout << dig[i+1];
      else cout << 0;
    }
    cout << endl;
  }
  return 0;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	deque<int> dq;
	int n,a; cin>>n;
	for (int i=0; i<n; i++) {
		cin>>a;
		if(i%2) dq.push_front(a);
		else dq.push_back(a);
	}
	if(n%2) {
		while(!dq.empty())
			cout << dq.back() << " ", dq.pop_back();
	} else {
		while(!dq.empty())
			cout << dq.front() << " ", dq.pop_front();
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3072
n = int(input())
l = list(map(int, input().split()))

ans = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      x, y, z = l[i], l[j], l[k]
      if x != y and y != z and z != x and x + y > z and x + z > y and y + z > x:
        ans += 1

print(ans)

Measured memory_bytes: 9152
#include<stdio.h>

long long dp[100];

long long fib(int n) {
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n-1) + fib(n-2);
}

int main() {
  int n,i;
  for(i = 0; i<100; i++) dp[i] = -1;

  scanf("%d\n", &n);
  printf("%lld\n", fib(n));

  return 0;
}

Measured memory_bytes: 600
#include <iostream>

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))

using namespace std;

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

    int cost = max_3(A, B, C) - min_3(A, B, C);
    cout << cost;

    return 0;
}


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

int n, m;
int pos[100010];
int si, ai;
int ans = 0;

signed main()
{
	cin >> n >> m;
	
	pos[1] = 0;
	rep(i,n-1) {
		cin >> si;
		pos[2+i] = pos[1+i] + si;
	}

	int now = 1;
	rep(i,m) {
		cin >> ai;
		ans += abs(pos[now] - pos[now + ai]) % 100000;
		ans %= 100000;
		now += ai;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define LL long long

int main() {
	int n, k, t = 0, cur = 1;
	scanf("%d %d", &n, &k);
	while(cur < n) {
		cur = cur * k;
		t++;
	}
	if(cur == n) t++;
	printf("%d", t);
	return 0;
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.math.*;
import java.util.*;
public class Main
{
	static Scanner sc=new Scanner(System.in);
	static final int MAX=1000000+5;
	public static void main(String[] args)
	{
		int n=sc.nextInt();
		int ans=0,M=0;
		for(int i=1;i<=n;i++)
		{
			int x=sc.nextInt();
			M=Math.max(M, x);
			ans+=x;
		}
		M/=2;
		System.out.println((ans-M));
	}
}

Measured memory_bytes: 23636
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
	int N = to!int(chomp(readln()));
	int K = to!int(chomp(readln()));
	int X = to!int(chomp(readln()));
	int Y = to!int(chomp(readln()));
	
	int fee;
	if(N < K) {
		fee = N*X;
		fee.writeln;
		return;
	}
	fee += K*X;
	if(!N-K < 1) fee += (N-K)*Y;
	fee.writeln;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;

    input!{
        a: usize,
        b: usize,
        c: usize,
        x: usize,
    }
    let mut ans = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                if i*500+j*100+k*50 == x {
                    ans = ans + 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
m = 1 
mindis = abs(A-(T-H[0]*0.006))
for i in range(1,N):
  cd = abs(A-(T-H[i]*0.006))
  if mindis > cd:
    m = i+1
    mindis = cd
print(m)

Measured memory_bytes: 9264
#include<bits/stdc++.h>
using namespace std;
int a,b,n;
vector<int> v;
bool prime[501010];
void SieveOfEratosthenes()
{
    int n=401010;

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=3; p<=101010; p++)
    {
        if (prime[p] && prime[(p+1)/2])
        {
            v.push_back(p);
        }
    }
}
void init()
{
    SieveOfEratosthenes();
    /*cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<endl;
    }*/
}
int bcount(int l,int r)
{
    std::vector<int>::iterator low,up;
    low=std::lower_bound (v.begin(), v.end(), l); //          ^
    up= std::upper_bound (v.begin(), v.end(), r); //                   ^
    return (up-v.begin())-(low-v.begin());
}
int main()
{
    init();
    int q,l,r;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>l>>r;
        cout<<bcount(l,r)<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>

/*
.1
4235
.6
*/

// prototype declaration
void vdRollE(int* iDice);
void vdRollW(int* iDice);
void vdRollS(int* iDice);
void vdRollN(int* iDice);
void vdSlideL(int* iDice);

// 展開図から得られるサイコロシミュレーションを行うプログラム

int main() {
    int iDice[7];   // ダイスの整数
    int iCount;     // counter
    int iCount2;    // counter
    int iSwapTmp;   // 転がした際に目を変更するためのテンポラリ
    int iQuestion;  // 質問数
    int iTop;       // 上面の整数
    int iFront;     // 前面の整数

    // In: ダイスに書かれた整数
    for (iCount = 1; iCount <= 6; iCount++) {
        scanf("%d", &iDice[iCount]);
    }
    // In: 質問数
    scanf("%d", &iQuestion);
    // 質問数分繰り返す
    for (iCount = 0; iCount < iQuestion; iCount++) {
        // In: 上面と前面の整数
        scanf("%d%d", &iTop, &iFront);

        // 上面が合うまで転がす
        iCount2 = 0;
        while (iDice[1] != iTop) {
            if (iCount2 < 4) vdRollE(iDice);
            else vdRollN(iDice);
            iCount2++;
        }
        // 前面が合うまで転がす
        while (iDice[2] != iFront) {
            vdSlideL(iDice);
        }
        printf("%d\n", iDice[3]);
    }

    return 0;
}

void vdRollE(int* iDice) {
    int iSwapTmp;        // 転がした際に目を変更するためのテンポラリ
    iSwapTmp = iDice[1]; // 上面を退避
    iDice[1] = iDice[4]; // 左面->上面
    iDice[4] = iDice[6]; // 下面->左面
    iDice[6] = iDice[3]; // 右面->下面
    iDice[3] = iSwapTmp; // 上面->右面
    return;
}

void vdRollW(int* iDice) {
    int iSwapTmp;        // 転がした際に目を変更するためのテンポラリ
    iSwapTmp = iDice[1]; // 上面を退避
    iDice[1] = iDice[3]; // 右面->上面
    iDice[3] = iDice[6]; // 下面->右面
    iDice[6] = iDice[4]; // 左面->下面
    iDice[4] = iSwapTmp; // 上面->左面
    return;
}

void vdRollS(int* iDice) {
    int iSwapTmp;        // 転がした際に目を変更するためのテンポラリ
    iSwapTmp = iDice[1]; // 上面を退避
    iDice[1] = iDice[5]; // 奥->上
    iDice[5] = iDice[6]; // 下->奥
    iDice[6] = iDice[2]; // 手前->下
    iDice[2] = iSwapTmp; // 上->手前
    return;
}

void vdRollN(int *iDice) {
    int iSwapTmp;        // 転がした際に目を変更するためのテンポラリ
    iSwapTmp = iDice[1]; // 上面を退避
    iDice[1] = iDice[2]; // 手前->上
    iDice[2] = iDice[6]; // 下->手前
    iDice[6] = iDice[5]; // 奥->下
    iDice[5] = iSwapTmp; // 上->奥
    return;
}

void vdSlideL(int *iDice) {
    int iSwapTmp;        // 転がした際に目を変更するためのテンポラリ
    iSwapTmp = iDice[2]; // 前を退避
    iDice[2] = iDice[3]; // 右->前
    iDice[3] = iDice[5]; // 奥->右
    iDice[5] = iDice[4]; // 左->奥
    iDice[4] = iSwapTmp; // 前->左
}


Measured memory_bytes: 2032
#include<stdio.h>

int main(){
        int n, t;
        scanf("%d %d", &n, &t);
        int mincost=1001;
        for(int i=0; i<n; i++){
                int c, nt;
                scanf("%d %d", &c, &nt);
                if(nt<=t && c<=mincost) mincost = c;
        }
        if(mincost>1000) puts("TLE");
        else printf("%d\n", mincost);
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		// String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		ArrayList<Integer> cube = new ArrayList<Integer>();
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == '1')
				cube.add(1);
			else
				cube.add(0);
		}

		for (int idx = 0; cube.size() > idx + 1;) {
			if (cube.get(idx) != cube.get(idx + 1)) {
				cube.remove(idx);
				cube.remove(idx);
				idx--;
				if (idx < 0)
					idx = 0;
			} else
				idx++;
		}
		System.out.println(str.length() - cube.size());

	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 27220
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FI          freopen("input.txt", "r", stdin)
#define FO          freopen("output.txt", "w", stdout)
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 2e3 + 50;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {0, -1}, dy[] = {-1, 0};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n;
ll dp[N];
ll f(int sum){
    if(sum < 0)return 0;
    if(sum == 0){
        return 1;
    }

    ll &ans = dp[sum];
    if(ans == -1){
        ans = 0;
        for(int i = 3; i <= n; i++)
            ans = (ans + f(sum - i)) % mod;
    }
    return ans;
}
void solve(){
    cin >> n;
    cls(dp, -1);
    cout << f(n) % mod << '\n';
}  
int main(){
    FIN;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        solve(); 
    }
    //EjecuteTime;
    return 0;
}  

Measured memory_bytes: 3656
// 2019/04/27 Tazoe

#include <iostream>
using namespace std;

void c2d(int c[8], int d[8], int n)
{
	for(int i=0; i<8; i++){
		d[i] = c[(n+i)%8];
	}
}

void prd(int d[8])
{
	for(int i=0; i<8; i++){
		cout << d[i];

		if(i==7){
			cout << endl;
		}
		else{
			cout << ' ';
		}
	}
}

int cnt(int p[8], int d[8])
{
	int c = 0;

	for(int i=0; i<8; i++){
		if(p[i]>=d[i]){
			c += d[i];
		}
		else{
			c += p[i];
		}
	}

	return c;
}



int main()
{
	int c[8] = {1, 2, 1, 2, 1, 4, 1, 4};

	while(true){
		int p[8];
		cin >> p[0];

		if(cin.eof())
			break;

		for(int i=1; i<8; i++){
			cin >> p[i];
		}

		int d[8];
		int n = -1;
		int m = -1;

		c2d(c, d, 0);  // prd(d);
		if(m<cnt(p, d)){
			n = 0;
			m = cnt(p, d);
		}

		c2d(c, d, 2);  // prd(d);
		if(m<cnt(p, d)){
			n = 2;
			m = cnt(p, d);
		}

		c2d(c, d, 6);  // prd(d);
		if(m<cnt(p, d)){
			n = 6;
			m = cnt(p, d);
		}

		c2d(c, d, 4);  // prd(d);
		if(m<cnt(p, d)){
			n = 4;
			m = cnt(p, d);
		}

		c2d(c, d, 1);  // prd(d);
		if(m<cnt(p, d)){
			n = 1;
			m = cnt(p, d);
		}

		c2d(c, d, 3);  // prd(d);
		if(m<cnt(p, d)){
			n = 3;
			m = cnt(p, d);
		}

		c2d(c, d, 7);  // prd(d);
		if(m<cnt(p, d)){
			n = 7;
			m = cnt(p, d);
		}

		c2d(c, d, 5);  // prd(d);
		if(m<cnt(p, d)){
			n = 5;
			m = cnt(p, d);
		}


		c2d(c, d, n);
		prd(d);
	}

	return 0;
}



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

int main(){
	int n; cin >> n;
	vector<int> a(n);
	int amax=0;
	for(int i=0;i<n;i++) {
		cin >> a[i];
		amax=max(amax,a[i]);
	}
	int center=0;
	for(int i=0;i<n;i++) {
		if(abs(amax/2-a[i])<abs(amax/2-center)) center=a[i];
	}
	cout << amax << " " << center << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

// 素因数分解O(sqrt(n))
map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;

    ll ans = 0;

    for (ll c = 1; c < n; c++)
    {
        ll temp = n - c;
        auto p = prime_factor(temp);

        ll t = 1;
        for (auto m : p)
        {
            t *= m.second + 1;
        }

        ans += t;
        // for (ll a = 1; a <= sqrt(temp); a++)
        // {
        //     ll b = temp / a;
        //     ll r = temp % a;

        //     if (r == 0)
        //     {
        //         if (a == b)
        //         {
        //             ans++;
        //         }
        //         else
        //         {
        //             ans += 2;
        //         }
        //     }
        // }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, a, b; cin >> n >> a >> b;
	cout << min(b, n * a) << endl;
	
	return 0;
}

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

template<typename T> T square(T val)
{
	return val * val;
}

int main()
{
	int N = 0;
	cin >> N;
	int a[N];
	double mean = 0;
	for(int i = 0; i < N; i++){
		cin >> a[i];
		mean = (double)(i) / (i + 1) * mean + 1.0/(i + 1) * a[i];
	}
	int target = round(mean);
	int cost = 0;
	for(int i = 0; i < N; i++){
		cost += square(a[i] - target);
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
V,E=map(int,input().split())
dp=[[float('inf')]*V for _ in range(V)]
for i in range(V):
    dp[i][i]=0
for _ in range(E):
    s,t,d=map(int,input().split())
    dp[s][t]=d

for k in range(V):
    for i in range(V):
        for j in range(V):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])

nega=0
for i in range(V):
    if dp[i][i]<0:
        nega=1
if nega:
    print("NEGATIVE CYCLE")
else:
    for i in range(V):
        if dp[i][0]==float('inf'):
            print("INF",end='')
        else:
            print(dp[i][0],end='')
        for j in range(1,V):
            if dp[i][j]==float('inf'):
                print(" INF",end='')
            else:
                print(" {}".format(dp[i][j]),end='')
        print()



Measured memory_bytes: 6284
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
int main(){
    int N;
    scanf("%d",&N);
    int h[102],table[102]={0};
    for(int i=0;i<N;i++)
        scanf("%d",h+i);
    int ans=0;
    int f=0,changed=0; //f=1なら前のやつでも水やりできるf=0ならむりぽ
    do{
       changed = 0;
       for(int j=0;j<N;j++){
           if(f==0 && table[j]<h[j]){
               f=1;
               table[j]++;
               changed = 1;
           } 
           else if(f==1 && table[j]<h[j])
               table[j]++;
           else if(f==1 && table[j]>=h[j]){
               f=0;
               ans++;
           }
       }
       if(f==1){
           ans++;
           f=0;
       }
   }while(changed);
   printf("%d",ans);
}

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

using namespace std;

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k, n, ans;
    cin >> k >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ans = a[n - 1] - a[0];
    for (int i = 1; i < n; ++i) {
        ans = min(ans, k - a[i] + a[i - 1]);
    }
    cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"
int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n;y=64;
	for(ll i=1;i<=n;i++)
	{
		cin>>x;cnt=0;
		while(x==((x>>1)<<1)) cnt++,x>>=1;
		if(y>cnt) y=cnt;
	}
	cout<<y<<nw;
}


Measured memory_bytes: 3544
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);

        var a = (K - 1) * K / 2;
        var b = (2 * N - K + 1) * K / 2;

        var ans = 0L;

        for (long i = K; i <= N + 1; i++)
        {
            ans += b - a + 1;
            a += i;
            b += N - i;

            ans %= 1000000007;
        }

        WriteLine(ans);

        // 実験
        //foreach (var g in GetC(10, 0, 0, 10).OrderBy(x => x).GroupBy(x => x))
        //{
        //    WriteLine($"{g.Key} {g.Count()}");
        //}

    }

    static IEnumerable<int> GetC(int a, int n, int s, int d)
    {
        if (d == 0)
        {
            yield return s;
        }
        else
        {
            for (int i = n; i < a; i++)
            {
                foreach (var c in GetC(a, i + 1, s + i, d - 1))
                {
                    yield return c;
                }
            }
        }
    }
}


Measured memory_bytes: 28220
# ABC 131 E

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

M=(N-1)*(N-2)//2
if K<=M:
    # OK
    print(N-1+M-K)
    for i in range(1,N):
        print(i,N)
    i,j=1,2
    for _ in range(M-K):
        print(i,j)
        j+=1
        if j==N:
            i+=1
            j=i+1
else:
    # NG
    print(-1)

Measured memory_bytes: 9100
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Maybe as Maybe
import qualified Data.Char as Char
import Control.Monad

-------------------------------------------------------------------------------

main :: IO ()
main = do
    input <- runParser parseInput <$> B.getContents
    let (x, y, z) = (solve input)
    putStrLn $ show x ++ " " ++ show y ++ " " ++ show z

parseInput :: Parser (Int, Int)
parseInput =
    (,) <$> parseInt <*> parseInt

solve :: (Int, Int) -> (Int, Int, Int)
solve (n, total) =
    case bruteForce n total of
        []    -> (-1, -1, -1)
        (x:_) -> x

bruteForce :: Int -> Int -> [(Int, Int, Int)]
bruteForce n total = do
    x <- [0..n]
    y <- [0..(n-x)]
    let z = n-y-x
    guard $ 10000*x + 5000*y + 1000*z == total
    return (x, y, z)

-------------------------------------------------------------------------------

newtype Parser a =
    Parser (B.ByteString -> (a, B.ByteString))

instance Functor Parser where
    fmap f (Parser parser) =
        Parser $ \input ->
            let (v, remainder) = parser input in
                (f v, remainder)

instance Applicative Parser where
    pure v =
        Parser $ \input ->
            (v, input)

    (Parser parser1) <*> (Parser parser2) =
        Parser $ \input ->
            let
                (f, remainder1) = parser1 input
                (v, remainder2) = parser2 remainder1
            in
                (f v, remainder2)

instance Monad Parser where
    return = pure

    (Parser parser1) >>= f =
        Parser $ \input ->
            let
                (v, remainder) = parser1 input
                Parser parser2 = f v
            in
                parser2 remainder

consumeSpace :: Parser ()
consumeSpace =
    Parser $ \input ->
        ((), B.dropWhile Char.isSpace input)

lexeme :: Parser a -> Parser a
lexeme parser =
    consumeSpace *> parser

parseInt_ :: Parser Int
parseInt_ =
    Parser $ \input ->
        Maybe.fromJust (B.readInt input)

parseInt :: Parser Int
parseInt =
    lexeme parseInt_

parseChar :: Parser Char
parseChar =
    Parser $ \input ->
        Maybe.fromJust (B.uncons input)

runParser :: Parser a -> B.ByteString -> a
runParser (Parser parser) input =
    fst $ parser input

-------------------------------------------------------------------------------


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define IMAX 0x3f3f3f3f
#define LLMAX 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef double db;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

int k, a, b;

signed main() {
  k = read(), a = read(), b = read();
  if (a % k == 0 || b % k == 0) {
    puts("OK");
    return 0;
  }
  if (a / k < b / k) {
    puts("OK");
    return 0;
  }
  puts("NG");
  return 0;
}


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

using namespace std;

int main()
{
    int n,ans,x;
    x=1000;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        int c=0;
        while(k%2==0)
        {
            k=k/2;
            c++;
        }
        x=min(x,c);
    }
    cout<<x;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] argd) {
    Scanner sc = new java.util.Scanner(System.in);
    int A = Integer.parseInt(sc.nextLine());
    int B = Integer.parseInt(sc.nextLine());
    int C = Integer.parseInt(sc.nextLine());
    int X = Integer.parseInt(sc.nextLine());
    int count = 0;
    for (int a = 0; a <= A; a++) {
      for (int b = 0; b <= B; b++) {
        for (int c = 0; c <= C; c++) {
          int total = 500 * a + 100 * b + 50 * c;
          if (total == X) { count++; }
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23636
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    string s, t;
    cin >> s >> t;
    ll ans = INF;
    for(ll i = 0; i <= s.size() - t.size(); i++){
        ll cnt = 0;
        for(ll j = 0; j < t.size(); j++){
            if(s[j + i] != t[j]) cnt++;
        }
        ans = min(ans, cnt);

    }
    cout << ans << endl;
}   

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100];

bool ask(LL v) {
	string s;
	cout << "? " << v << endl;
	cin >> s;
	return (s == "Y");
}

void ans(LL v) {
	cout << "! " << v << endl;
	exit(0);
}

LL ex(LL x, LL y) {
	return (y == 0 ? 1 : x * ex(x, y - 1));
}

int main() {
	int e = -1;
	inc(i, 10) {
		if(! ask(ex(10, i))) { e = i; break; }
	}
	
	if(e == -1) {
		inc(i, 10) { 
			if(ask(2 * ex(10, i))) { ans(ex(10, i)); }
		}
	}
	
	LL L = ex(10, e - 1) * 10, H = ex(10, e) * 10;
	while(H - L > 1) {
		LL M = (L + H) / 2;
		(ask(M) ? H : L) = M;
	}
	ans(H / 10);
	
	return 0;
}


Measured memory_bytes: 700
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  ll n,l[1010],r[1010];
  cin>>n;
  ll ans=0;
  rep(i,n){
    cin>>l[i]>>r[i];
    ans+=r[i]-l[i]+1;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(10);
		   //端を決めるO(n^4)
           //何個含まれているか数えるO(n)
           //O(n^5)
           int n,K;
           cin>>n>>K;
           vector<P> x(n);
		   rep(i,0,n)cin>>x[i].first>>x[i].second;
           ll ans=INF;
           //cout<<ans<<endl;
           rep(i,0,n){
            rep(j,0,n){
              rep(k,0,n){
               rep(l,0,n){
                 if(i==j||k==l)continue;
                 ll xmin=min(x[i].first,x[j].first);
                 ll xmax=max(x[i].first,x[j].first);
                 ll ymin=min(x[k].second,x[l].second);
                 ll ymax=max(x[k].second,x[l].second);
                 ll num=0;
                 rep(p,0,n){
                   if(x[p].first<=xmax&&x[p].first>=xmin){
                     if(x[p].second<=ymax&&x[p].second>=ymin){
                       num++;
                     }
                   }
                 }
                 ll cnt=(xmax-xmin)*(ymax-ymin);
                 if(num>=K){
                   chmin(ans,cnt);
                 }
                 //cout<<k<<endl;
                 //if(ans==2)cout<<num<<endl;
               }
              }
            }
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cctype>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef unsigned long long ULL;
int n,m,ans;
bool flag[410][410],kill[410];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void add(int u,int v)
{
    repu(i,1,n)
        if (flag[i][v])
            flag[i][v]=flag[v][i]=1;
}

int main()
{
    scanf("%d%d",&n,&m);
    while (m--)
    {
        int u=getint(),v=getint();
        repu(i,1,n)
        {
            if (flag[v][i] && !flag[u][i])
                add(u,i);
            if (flag[u][i] && !flag[v][i])
                add(v,i);
        }
        add(u,v),add(v,u);
        repu(i,1,n)
            flag[u][i]|=flag[v][i],flag[v][i]|=flag[u][i];
        flag[u][v]=flag[v][u]=1;
        kill[u]|=kill[v],kill[v]|=kill[u];
        kill[u]|=flag[u][u],kill[v]|=flag[v][v];
    }
    repu(i,1,n)
        repu(j,i+1,n)
            ans+=!flag[i][j] && !flag[j][i] && !kill[i] && !kill[j];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
const ll INF=1e7;
vector<int> E[100000];
vector<int> F[100000];
int d[100000];
void dfs(int x){
    if(E[x].size()==0) d[x]=0;
    else{
        int res=0;
        rep(i,0,E[x].size()){
            if(d[E[x][i]]==INF) dfs(E[x][i]);
            res=max(res,d[E[x][i]]);
        }
        d[x]=res+1;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin>>N>>M;
    rep(i,0,M){
        int x,y;
        cin>>x>>y;
        E[x-1].pb(y-1);
        F[y-1].pb(x-1);
    }
    rep(i,0,N) d[i]=INF;
    rep(i,0,N){
        if(F[i].size()==0){
            dfs(i);
        }
    }
    int ans=0;
    rep(i,0,N){
        ans=max(ans,(d[i]==INF?0:d[i]));
    }
    cout <<ans<<"\n";
}

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

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

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

ll v[100][100];

int main()
{
	while (1) {
		cin >> n;
		if (n == 0) {
			return 0;
		} else {
			memset(v, 0, sizeof(v));
			REP(i, n)
			{
				cin >> m;
				REP(j, m)
				{
					ll a;
					cin >> a;
					v[i][a] = 1;
				}
			}
			cin >> k;
			vi a(k);
			REP(i, k)
			{
				cin >> a[i];
			}

			ans = -1;
			vi vans;
			REP(i, n)
			{
				cnt = 0;
				ans = -1;
				REP(t, k)
				{
					if (v[i][a[t]] == 1) {
						cnt++;
						if (cnt == k) {
							ans = i + 1;
							vans.push_back(ans);
						}
					}
				}
			}
			if (vans.size() == 1) {
				cout << vans[0] << endl;
			} else {
				cout << -1 << endl;
			}
		}
	}
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll ans = inf;
    vector<ll> v, vv;
    for(ll i = 0; i < 5; i++)
    {

        ll x;
        cin >> x;
        vv.pb(x);
    }
    for(ll i = 0; i < 5; i++) v.pb(i);
    do
    {

        ll a=vv[v[0]],b = vv[v[1]], c = vv[v[2]], d = vv[v[3]], e = vv[v[4]];
        ll x, y, z;
        x = a;
        if(x%10) x+=10-(x%10);
        x+=b;
        if(x%10) x+=10-(x%10);
        x+=c;
        if(x%10) x+=10-(x%10);
        x+=d;
        if(x%10) x+=10-(x%10);
        x+=e;
        //if(x%10) x+=10-(x%10);
        ans = min(ans, x);
    }while(next_permutation(v.begin(), v.end()));
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

struct Op{
  char ch;
  int i;
  int j;
  int k;
};
std::vector<Op> sol;
int const nmax = 200000;
int real[1 + nmax] = {0};

void add(int i, int j, int k) {
  sol.push_back({'+', i, j, k});
  real[k] = real[i] + real[j];
}

void compare(int i, int j, int k) {
  sol.push_back({'<', i, j, k});
  real[k] = (real[i] < real[j]);
}

/*
v[j] is guaranteed to be 0 or 1
*/

int ptr = 3;
int const lgmax = 30;

void quick_raise(int x, int p){
  for(int h = 1; h <= p; h++)
    add(x, x, x);
}

int const sure_zero = 200000 - 1;
int const sure_one =  200000 - 2;
int const sure_use =  200000 - 3;

void compare_equal(int x, int y, int k) {
  add(y, sure_one, sure_use);
  compare(x, sure_use, k);
}

void multiply_simple(int i, int j, int k) {
  add(sure_one, sure_zero, ptr);
  for(int h = 1; h < lgmax; h++) 
    add(ptr + h - 1, ptr + h - 1, ptr + h);
  

  int aux = ptr + lgmax;
  int total = ptr + lgmax + 1;
  for(int h = lgmax - 1; 0 <= h; h--) {
    add(total, ptr + h, aux);    
    compare_equal(aux, i, aux);
    add(aux, j, aux);
    compare(sure_one, aux, aux);
    quick_raise(aux, h);
    add(total, aux, total);
  }
  ptr += lgmax + 2;
  add(total, sure_zero, k);
}

void multiply_hard(int i, int j, int k) {
  int start_ptr = ptr;
  add(sure_one, sure_zero, start_ptr);
  
  for(int h = 1; h < lgmax; h++)
    add(start_ptr + h - 1, start_ptr + h - 1, start_ptr + h);
  
  int aux = ptr + lgmax, aux2 = ptr + lgmax + 3;
  int total = ptr + lgmax + 2, coef = ptr + lgmax + 1;
  ptr += lgmax + 4;

  for(int h = lgmax - 1; 0 <= h; h--) {
    add(coef, start_ptr + h, aux);
    compare_equal(aux, j, aux);

    add(aux, sure_zero, aux2);
    quick_raise(aux, h);
    multiply_simple(i, aux2, aux2);
    quick_raise(aux2, h);
    add(aux, coef, coef);
    add(aux2, total, total);
  }
  add(total, sure_zero, k);
}

int main() {
  real[0] = 10;
  real[1] = 20;

  add(0, 1, sure_use); 
  compare(2, sure_use, sure_one);
  
  ptr = 3; 
  multiply_hard(0, 1, 2);

  std::cout << sol.size() << '\n';
  for(int i = 0; i < sol.size(); i++)
    std::cout << sol[i].ch << " " << sol[i].i << " " << sol[i].j << " " << sol[i].k << '\n';

  return 0;
}


Measured memory_bytes: 3676
N = int(input())
ans = 0
for n in range(1, N+1):
    if n % 3 == 0 and n % 5 == 0:
        pass
    elif n % 3 == 0:
        pass
    elif n % 5 == 0:
        pass
    else:
        ans += n % (10**9+7)
print(ans)

Measured memory_bytes: 9192
N=int(input())
a=list(map(int, input().split()))

i=0             
while i<N:
        if a[i]%2==0 and (a[i]%3 !=0 and a[i]%5 !=0):
                print('DENIED')
                break
        i+=1
if i==N:
        print('APPROVED')
                
        
                                        
        


Measured memory_bytes: 2940