akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int x1 = 0;
		int x2 = w;
		int y1 = 0;
		int y2 = h;
		int ret = 0;
		for (int i = 0;i < n;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			if (a==1) {
				x1 = Math.max(x1,x);
			} else if (a==2) {
				x2 = Math.min(x2,x);
			} else if (a==3) {
				y1 = Math.max(y1,y);
			} else if (a==4) {
				y2 = Math.min(y2,y);
			}

			if (x1>=x2||y1>=y2) {
				ret = 0;
			} else {
				ret = (x2-x1)*(y2-y1);
			}
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n,p;cin >> n >>p;
     string s;cin >> s;
    if(p==2){
        ll ans=0;
        rep(i,n){
            if((s[i]-'0')%2==0)ans+=i+1;
        }
        cout << ans <<endl;
    }
    else if(p==5){
        ll ans=0;
        rep(i,n){
            if((s[i]-'0')%5==0)ans+=i+1;
        }
        cout << ans <<endl;
    }
    else{
        ll pre=0;
        ll rem=1;
        map<ll,ll> mp;
        mp[0]++;
        per(i,n){
            pre+=((s[i]-'0')*rem)%p;
            pre%=p;
            mp[pre]++;
            rem=(rem*10)%p;
            //cout << pre <<endl;
        }
        ll ans=0;
        for(auto p:mp){
            ans+=p.se*(p.se-1)/2;
        }
        cout << ans <<endl;
    }
}

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

int main() {
  long long N, K;
  cin >> N >> K;

  //Nが0だったら0を出力
  if (N==0) {
    cout << 0 << endl;
    return 0;
  }

  //剰余を求める
  N = N%K;

  //NがKで割り切れるなら最小値は0
  if (N==0) {
    cout << 0 << endl;
    return 0;
  }
  
  long long llbuff=1000000000000000000;
  while(1) {
    //0は最小
    if (N==0) {
      break;
    } else if (N>llbuff) {
      N = llbuff;
      break;
    }
    llbuff = N;
    //絶対値を求める
    if (N < K) {
      N = K - N;
    } else {
      N = N - K;
    }
  }
  
  cout << N << endl;
    
  return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		
		Integer[] calledPon = {0,1,6,8};
		
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int num = sc.nextInt()%10;

		if(num == 3) {
			System.out.println("bon");
		} else if (Arrays.asList(calledPon).contains(num)) {
			System.out.println("pon");
		} else {
			System.out.println("hon");
		}
		
	}
}

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

using namespace std;

signed main(){	
	int h, w;
	cin >> h >> w;
	int alp[26];
	for (int i = 0;i < 26;i++)
		alp[i] = 0;
	for (int i = 0;i < h;i++){
		string ai;
		cin >> ai;
		for (int j = 0;j < w;j++){
			alp[ai[j] - 'a']++;
		}
	}
	/*
		c0 : 4の倍数文字の文字数
		c1 : 4の倍数+1文字の文字数
		c2 : 4の倍数+2文字の文字数
		c3 : 4の倍数+3文字の文字数
	*/
	int c[4];
	for (int i = 0;i < 4;i++) c[i] = 0;
	for (int i = 0;i < 26;i++)
		c[alp[i] & 3]++;
	if (((h & 1) == 0) && ((w & 1) == 0)){ // hもwも偶数
		/* alpすべて4の倍数じゃないとだめ */
		bool f = c[1] == 0 && c[2] == 0 && c[3] == 0;
		if (f){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else if (h & w & 1){ // hもwも奇数
		if (c[2] <= h / 2 + w / 2 && c[1] == 1 && c[3] == 0){
			cout << "Yes" << endl;
		}
		else if (c[2] <= h / 2 + w / 2 - 1 && c[1] == 0 && c[3] == 1){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else if (h & 1){ // hのみ奇数
		if (c[1] == 0 && c[3] == 0 && c[2] <= w / 2){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else{ // wのみ奇数
		if (c[1] == 0 && c[3] == 0 && c[2] <= h / 2){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	long long int a, b, c, d, n, m, num[2000][2] = {}, result = 0;
	char str[200005];
	scanf("%lld", &n);
	if (n >= 64) { printf("64"); }
	else if (n >= 32) { printf("32"); }
	else if (n >= 16) { printf("16"); }
	else if (n >= 8) { printf("8"); }
	else if (n >= 4) { printf("4"); }
	else if (n >= 2) { printf("2"); }
	else if (n >= 1) { printf("1"); }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long A, B, K;
    cin >> A >> B >> K;

    if (A - K < 0)
    {
        B -= abs(A - K);
        A = 0;
        if (B < 0)
        {
            B = 0;
        }
    }
    else
    {
        A -= K;
    }

    cout << A << " " << B << endl;
}

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

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
const int MOD = 998244353;

ll gcd(ll a, ll b, ll &x, ll &y) {
	if (a == 0) {
		x = 0;
		y = 1;
		return b;
	}
	ll x1, y1;
	ll g = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return g;
}

vector<ll> f;

ll poww(ll a, int b) {
	if (b == 0) return 1;
	if (b & 1) return (a * poww(a, b - 1)) % MOD;
	ll tmp = poww(a, b >> 1);
	return (tmp * tmp) % MOD;
}

ll c(int n, int k) {
	return (f[n] * poww((f[n - k] * f[k]) % MOD, MOD - 2)) % MOD;
}

int main() {
	ios::sync_with_stdio(false);
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	f.resize(n + 1);
	f[0] = 1;
	for (ll i = 1; i <= n; ++i) {
		f[i] = (f[i - 1] * i) % MOD;
	}
	ll x, y;
	ll g = gcd(a, b, x, y);
	if (k % g) {
		cout << 0 << endl;
		return 0;
	}
	x *= k / g;
	y *= k / g;
	ll addx = b / g;
	ll addy = a / g;
	// 0 <= x, y <= n
	// x += b / g; y -= a / g;
	if (x < 0) {
		ll mult = (-x + addx - 1) / addx;
		x += addx * mult;
		y -= addy * mult;
	}
	else {
		ll mult = x / addx;
		x -= addx * mult;
		y += addy * mult;
	}
	if (y < 0) {
		ll mult = (-y + addy - 1) / addy;
		y += addy * mult;
		x -= addx * mult;
	}
	else if (y > n) {
		ll mult = (y - n + addy - 1) / addy;
		y -= addy * mult;
		x += addx * mult;
	}
	ll ans = 0;
	while (x >= 0 && x <= n && y >= 0 && y <= n) {
		ans = (ans + (c(n, x) * c(n, y)) % MOD) % MOD;
		x += addx;
		y -= addy;
	}
	cout << ans << endl;
}


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

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){

    ll n;
    cin >> n;
    ll a[1000];
    FOR(i,n){
      cin >> a[i];
    }
    ll sum=0,ans=10000000000000000;
    for(ll i=-100;i<101;i++){
      sum=0;
      FOR(j,n){
        sum+=abs(i-a[j])*abs(i-a[j]);
      }
      chmin(ans,sum);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c,d,e,f,g;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    if((a<=b)&&(a<=c))
        f=a;
    else if(b<=c)
        f=b;
    else
        f=c;
    if(d<=e)
        g=d;
    else
        g=e;
    int h=f+g-50;
    printf("%d\n", h);
}


Measured memory_bytes: 2768
use std;
use std::collections::VecDeque;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

/*
ここまでテンプレ
*/

fn main() {
    let N = read::<i64>();
    let mut A: Vec<(i64, i64)> = vec![(0, 0); N as usize];
    let mut Node = vec![(0, 0); N as usize]; //頻値
    let mut Edge: Vec<Vec<i64>> = vec![Vec::new(); N as usize];
    for i in 0..N {
        Node[i as usize] = (0, i);
    }
    for i in 0..N - 1 {
        let mut v = read_vec::<i64>();
        v[0] -= 1;
        v[1] -= 1;
        Node[v[0] as usize] = (Node[v[0] as usize].0 + 1, Node[v[0] as usize].1);
        Node[v[1] as usize] = (Node[v[1] as usize].0 + 1, Node[v[1] as usize].1);
        A[i as usize] = (v[0], v[1]);
        Edge[v[0] as usize].push(v[1]);
        Edge[v[1] as usize].push(v[0]);
    }
    Node.sort_unstable_by(|a, b| b.cmp(a));
    let mut c = read_vec::<i64>();
    c.sort_unstable_by(|a, b| a.cmp(b));
    let mut boolian = vec![false; N as usize];
    let mut que: VecDeque<i64> = VecDeque::new();
    que.push_back(Node[0].1);
    boolian[Node[0].1 as usize] = true;
    let mut Ans: Vec<i64> = vec![-1; N as usize];
    while (!que.is_empty()) {
        let t = que.front().unwrap().clone();
        que.pop_front();
        Ans[t as usize] = c.last().unwrap().clone();
        c.pop();
        for i in 0..Edge[t as usize].len() {
            if boolian[Edge[t as usize][i as usize] as usize] == true {
                continue;
            }
            boolian[Edge[t as usize][i as usize] as usize] = true;
            que.push_back(Edge[t as usize][i as usize]);
        }
    }
    let mut M: i64 = 0;
    for i in 0..N - 1 {
        M += std::cmp::min(Ans[A[i as usize].0 as usize], Ans[A[i as usize].1 as usize]);
    }
    println!("{}", M);
    for i in 0..N {
        print!("{}", Ans[i as usize]);
        if i != N - 1 {
            print!(" ");
        } else {
            println!("");
        }
    }
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_V = (int)1e5 + 5;
struct edge{
	int to;
	ll cost;
};

vector<edge> tree[MAX_V];
ll depth[MAX_V];

void dfs(int v, int p, ll d){
	depth[v] = d;
	for (int i = 0; i < (int)tree[v].size(); ++i){
		edge e = tree[v][i];
		if (e.to == p) continue;
		dfs(e.to, v, d + e.cost);
	} // end for
}

int main()
{
	memset(depth, 0LL, sizeof(depth));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	rep (i, N) tree[i].clear();

	rep (i, N - 1){
		int a, b; ll c; cin >> a >> b >> c;
		--a, --b;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	} // end rep

	int Q, K; cin >> Q >> K;
	--K;
	dfs(K, -1, 0);
	rep (i, Q){
		int x, y; cin >> x >> y;
		--x, --y;
		ll res = depth[x] + depth[y];
		cout << res << endl;
	} // end rep


	return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
 
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
 
using namespace std;
#define prime 1000000007
 
#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

ll n, v[100];

int main(){
	cin >> n;

	for (int i = 0; i < n; ++i){
		cin >> v[i];
	}
	ll sum = 0;
	for (int i = 0; i < n; ++i){
		for (int j = i+1; j < n; ++j){
			sum+=v[i]*v[j];
		}
	}

	cout << sum << endl;
	
	return 0;
}

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

tmp = s
for _ in range(50):
  tmp = tmp.replace("()", "")

l = tmp.count("(")
r = tmp.count(")")

for _ in range(l):
  s = s+")"
  
for _ in range(r):
  s = "(" + s
  
  
print(s)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

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

int N;
pii w[100000],s[100000];

bool Check(int d){
	int a[100000],b[100000];
	fill_n((int*)a,100000,0);
	fill_n((int*)b,100000,0);
	
	int mi=w[0].first,mx=w[N-1].first;
	REP(i,0,N){
		if(abs(mi-w[i].first)>d&&abs(mx-w[i].first)>d) return false;
		if(abs(mi-w[i].first)>d) a[w[i].second]=2;
		if(abs(mx-w[i].first)>d) a[w[i].second]=1;
	}
	mi=s[0].first;
	mx=s[N-1].first;
	REP(i,0,N){
		if(abs(mi-s[i].first)>d&&abs(mx-s[i].first)>d) return false;
		if(abs(mi-s[i].first)>d) b[s[i].second]=2;
		if(abs(mx-s[i].first)>d) b[s[i].second]=1;
	}
	
	int both=0,either=0;
	REP(i,0,N){
		if(a[i]==0||b[i]==0) ++both;
		else if(a[i]!=b[i]) ++either;
	}
	
	return either==0||both+either==N;
}

void Solve(){
	cin >> N;
	REP(i,0,N){
		int x,y;
		cin >> x >> y;
		w[i]=MP(x+y,i);
		s[i]=MP(x-y,i);
	}
	sort(s,s+N);
	sort(w,w+N);
	
	int lb=0,ub=600000;
	while(true){
		if(ub-lb<=1){
			if(Check(lb)) ub=lb;
			break;
		}
		int mid=(lb+ub)/2;
		if(Check(mid)) ub=mid;
		else lb=mid;
	}
	
	cout << ub << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

ll h, w, a, b, fct[200005], rfct[200005];
ll xpowy(ll x, ll y)
{
    ll res = 1LL;
    while (y > 0)
    {
        if ((y & 1))
            res = res * x % MOD;
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}

ll comb(ll x, ll y) {
    return ((fct[x] * rfct[y] % MOD) * rfct[x-y]) % MOD;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> a >> b;
    erep(i, 0, h + w) {
        if (i == 0) 
            fct[i] = 1;
        else
            fct[i] = i * fct[i-1] % MOD;
    }
    erep(i, 0, h + w) {
        if (i == 0) rfct[i] = 1;
        else rfct[i] = xpowy(fct[i], MOD-2) % MOD;
    }
    ll ans = 0LL;
    erep(i, 1, h-a) {
        ans += (comb(b+i-2, i-1) * comb(h-i+w-b-1, h-i)) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin>>c;
    if(c=='T')
    cout<<'A';
    if(c=='A')
    cout<<'T';
    if(c=='G')
    cout<<'C';
    if(c=='C')
    cout<<'G';
    return 0;
}

Measured memory_bytes: 256
fn solve(a: String) -> String {
    let d = a
        .chars()
        .map(|x| x.to_digit(10).unwrap() as i32)
        .collect::<Vec<_>>();
    let a = a.chars().collect::<Vec<_>>();
    for i in 0..8 {
        let mut x = d[0];
        for j in 0..3 {
            if (i >> j) & 1 == 0 {
                x += d[j + 1];
            } else {
                x -= d[j + 1];
            }
        }
        if x == 7 {
            let mut s = String::new();
            s.push(a[0]);
            for j in 0..3 {
                if (i >> j) & 1 == 0 {
                    s.push('+');
                } else {
                    s.push('-');
                }
                s.push(a[j + 1]);
            }
            s.push_str("=7");
            return s;
        }
    }
    unreachable!();
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let a = s.trim().to_string();
    let ans = solve(a);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
  int s,i,j;
  int a[1000]={0};
  scanf("%d",&s);
  a[1]=s;
  for(j=2;j<=1000;j++){
    if(s%2==0) s=s/2;
    else s=3*s+1;
    a[j]=s;
  }
  j=2;
  for(i=1;i<j;i++){
    for(j=i+1;j<=1000;j++){
      if(a[i]==a[j]) {
        printf("%d",j);
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
n,m = map(int, input().split())

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n%i == 0:
      divisors.append(i)
      if i != n//i:
        divisors.append(n//i)
  divisors.sort(reverse=True)
  return divisors

numbers = make_divisors(m)
for i in range(len(numbers)):
  if numbers[i] <= m/n:
    print(numbers[i])
    break

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n, m;
  while (cin >> n >> m, n) {
    vi a(n);
    cin >> a;
    vi v;
    v.reserve(n * n);
    rep(i, n) loop(j, i + 1, n) v.push_back(a[i] + a[j]);
    int maxi = -1;
    for (auto &x : v) {
      if (x <= m) cmax(maxi, x);
    }
    cout << (maxi == -1 ? "NONE" : to_string(maxi)) << endl;
  }
}

Measured memory_bytes: 9380
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

bool is_prime[100010];
int a[100010];
int sm[100010];
int prime[10010];

int sieve(int n, int prime[], bool is_prime[]) {
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    sieve(100000, prime, is_prime);
    fill_n(a, 100000, 0);
    for(int i=0; i<=100000; i++){
        if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    sm[0] = sm[1] = 0;
    for(int i=2; i<=100000; i++){
        sm[i] = sm[i-1] + a[i];
    }

    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        int l, r;
        cin >> l >> r;
        cout << sm[r] - sm[l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int ans = 0;
            if (n % 10 == 0) {
                ans = 10;
            } else {
                ans = digsum(n);
            }

            // 出力
            out.println(ans);

        }

        int digsum(int n) {
            int res = 0;
            while (n > 0) {
                res += n % 10;
                n /= 10;
            }
            return res;
        }

    }
}



Measured memory_bytes: 23124
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
      
      	int red = scanner.nextInt();
      	int green = scanner.nextInt();
      	int blue = scanner.nextInt();
      	int count = scanner.nextInt();
            
        while(!((blue > green) && (green > red))) {
        	if(blue > green) {
              green *= 2;
            } else {
              blue *= 2;
            }
          
          	count -= 1;
        }
      
      	if(count >= 0) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");        
        }
    
    }
}




Measured memory_bytes: 35624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

import static java.lang.Integer.parseInt;

/**
 * Problem 03: Selecting Teams Advanced to Regional
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int selected = 0;
			int[] groups = new int[1001];
			int[][] teams = new int[n][4];

			for (int i = 0; i < n; i++) {
				words = br.readLine().split(" ");
				for (int j = 0; j < words.length; j++) {
					teams[i][j] = parseInt(words[j]);
				}
			}

			Arrays.sort(teams, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					int ret1, ret2;
					ret1 = Integer.compare(o2[2], o1[2]);
					if (ret1 == 0) {
						ret2 = Integer.compare(o1[3], o2[3]);
						if (ret2 == 0) {
							return Integer.compare(o1[0], o2[0]);
						} else {
							return ret2;
						}
					} else {
						return ret1;
					}
				}
			});

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				boolean select = false;
				if (selected < 10) {
					if (groups[teams[i][1]] < 3) {
						select = true;
					}
				} else if (selected < 20) {
					if (groups[teams[i][1]] < 2) {
						select = true;
					}
				} else if (selected < 26) {
					if (groups[teams[i][1]] < 1) {
						select = true;
					}
				}
				if (select) {
					sb.append(teams[i][0]).append("\n");
					groups[teams[i][1]]++;
					selected++;
				}
			}
			System.out.print(sb.toString());
		} //end while
	} //end main
}

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


int main() {
    int n;
    scanf("%d", &n);
    vector<int> dp(3);
    
    for(int day = 0; day < n; ++day) 
    {
        vector<int> new_dp(3, 0);
        vector<int> c(3);
        for(int i = 0; i < 3; ++i)
            scanf("%d", &c[i]);

        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 3; ++j) {
                if(i != j) 
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
            }
        }
        dp = new_dp;        
    }
    printf("%d\n", max(dp[0], max(dp[1], dp[2])));
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#include <vector>
#include <map>
#define rep(i,n) for (int i=0; i < int(n); i++)


// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

int main(void){
    
    int n,k,l;
    
    cin >> n >> k >> l;
    
    UnionFind uf1(n);
    UnionFind uf2(n);
    
    for(int i = 0; i < k ;i++){
        int p,q;
        cin >> p >> q;
        uf1.unite(p-1,q-1);
    }
    
    vector<int> ans(n);
    
    for(int i = 0; i < l ;i++){
        int p,q;
        cin >> p >> q;
        uf2.unite(p-1,q-1);
    }
    
    map<pair<int,int> , int > M;
    
    for(int i = 0; i < n; i++){
        M[pair<int,int>(uf1.find(i),uf2.find(i))]++;
    }
    
    for(int i = 0; i < n; i++){
        cout << M[pair<int,int>(uf1.find(i),uf2.find(i))] << ((i+1 ==n ) ? '\n' : ' ');
    }
    
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <math.h>
typedef long long int ll;
#define pb(b) push_back(b)
vector<ll> inc,dec;
  
int main()
{
    cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    ll n,k,ans=0,a,b,c;
    string s,t;
    bool found = false;
 
  cin>>s;
  cin>>t;
  if(t.size()-s.size() != 1)
        cout<<"No\n";
   else
   {
       for(int i = 0; i < s.size(); i++)
       {
           if(s[i] != t[i])
           {
               cout<<"No\n";
                found = true;
                break;
           }
       }
       if(!found)
        cout<<"Yes\n";
   }

    return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    char a[100];
    while(~scanf("%s",a)){
        if(a[0]=='a'||a[0]=='e'||a[0]=='i'||a[0]=='o'||a[0]=='u'){
            printf("vowel\n");
        }
        else{
            printf("consonant\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
char s[205];
int main(){
    int n;
    ll m=0,a=0,r=0,c=0,h=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[0]=='M') m++;
        if(s[0]=='A') a++;
        if(s[0]=='R') r++;
        if(s[0]=='C') c++;
        if(s[0]=='H') h++;
    }
    ll res=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h;
    cout<<res;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int num[3];

	scanf("%d", &n);

	for (i = 0; i < 3; i++)
	{
		num[i] = n % 10;
		n /= 10;
	}

	for (i = 0; i < 3; i++)
	{
		if (num[i] == 7)
		{
			printf("Yes\n");
			break;
		}
		else if (i == 2)
		{
			printf("No\n");
		}
		
	}

	return 0;
}

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

using ll = long long;
#define int ll

int32_t main()
{
	int n,k;
	scanf("%lld%lld",&n,&k);
	vector<int> a(n);
	for(int& x : a)
	{
		scanf("%lld",&x);
	}
	vector<bool> dp(k + 1, false);
	for(int stone=0;stone<=k;stone++)
	{
		for(int x : a)
		{
			if(stone>=x && !dp[stone - x])
			{
				dp[stone] = true;
			}
		}
	}
	puts(dp[k] ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int x;
	cin>>x;
	int AA=x/500;
	x-=AA*500;
	int BB=x/5;
	cout<<AA*1000+BB*5;
	return 0;
}

Measured memory_bytes: 256
#70b
a,b,c,d=map(int,input().split())
if a<=c<=b:
    if b<=d:
        print(b-c)
    else:
        print(d-c)
elif b<c or d<=a:
    print(0)
elif c<a and b<d:
    print(b-a)
else:
    print(d-a)
    

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

int main() {
  int n; cin >>n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >>a.at(i);
  
  int cost=0, costmin=999999999;
  
  for (int i=-100; i<=100; i++){
    int cost = 0;
    for (int j=0; j<n; j++) cost += (a.at(j)-i)*(a.at(j)-i);
    if (cost < costmin) costmin = cost;
  }
  
  cout <<costmin <<endl;
  
  //cout <<ans <<endl;
  
  //if (ans) cout <<"YES" <<endl;
  //else cout <<"NO" <<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main()
{
  int a,b;cin>>a>>b;
  int aa = 0;
  int bb = 0;
  for (int i=0;i<b;i++)
  {
    aa *= 10;
    aa += a;
  }
  for (int i=0;i<a;i++)
  {
    bb *= 10;
    bb += b;
  }
  if (aa>bb) cout<<aa<<endl;
  else cout<<bb<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <deque>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

deque<int> q;
int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int v;
    scanf("%d", &v);
    if(i % 2 == 0) {
      q.push_back(v);
    } else {
      q.push_front(v);
    }
  }
  if(n % 2 == 0) {
    REP(i, n) {
      printf("%d%c", q.front(), i == n-1 ? '\n' : ' ');
      q.pop_front();
    }
  } else {
    REP(i, n) {
      printf("%d%c", q.back(), i == n-1 ? '\n' : ' ');
      q.pop_back();
    }
  }
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef pair <ll,ll> Pll;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> s(n); rep (i, n) cin >> s[i];
    // vector<ll> m(n), e(n);
    vector<Pll> mep, mem;
    ll sum = 0, sum_p = 0;
    rep (i, n) {
        ll k = 0, mm = 0;
        rep (j, s[i].size()) {
            if (s[i][j] == '(') k++;
            else k--;
            chmin(mm, k);
        }
        if (mm < 0) {
            if (k >= 0) mep.emplace_back(mm, k);
            else if (mm != k) mem.emplace_back(mm, k);
        } else {
            sum_p += k;
        }
        sum += k;
    }
    // rep (i, n) eprintf("%lld ", me[i].first); eprintf("\n");
    // rep (i, n) eprintf("%lld ", me[i].second); eprintf("\n");
    // sort(all(n), [](Pll a, Pll b) {return }
    if (sum != 0) {
        cout << "No\n";
        return 0;
    }
    sort(all(mep)); reverse(all(mep));
    sort(all(mem), [](Pll a, Pll b){return (a.second - a.first) > (b.second - b.first);});
    for (auto i : mep) {
        if (sum_p + i.first < 0) {
            cout << "No\n";
            return 0;
        }
        sum_p += i.second;
    }
    for (auto i : mem) {
        if (sum_p + i.first < 0) {
            cout << "No\n";
            return 0;
        }
        sum_p += i.second;
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 34556
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   bool ok=true;
   int x;
   while(n--)
   {
       cin>>x;
       if(x%2==0&&x%3!=0&&x%5!=0)
        ok=false;
   }
   if(ok)   cout<<"APPROVED";
   else cout<<"DENIED";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
void solve(){
    int n;
    cin>>n;
    while (n>0)
    {
        if(n%10==7){
            cout<<"Yes\n";
            return;
        }
        n/=10;
    }
    cout<<"No\n";
    return;
       
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3636
import math
import numpy as np

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = input()
x = int(x)

while np.logical_not(is_prime(x)):
  x += 1

print(str(x))

Measured memory_bytes: 12496
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, p;
    cin>>n>>p;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    vector<ll> ans0(n+1);
    vector<ll> ans1(n+1);
    ans0[0]=0;
    ans1[0]=0;
    ll nowans0 = 0;
    ll nowans1 = 0;
    rep(i, n){
        nowans0 += ans0[i];
        nowans1 += ans1[i];
        if(v[i]%2==0){
            ans0[i+1] = nowans0+1;
            ans1[i+1] = nowans1;
        }
        else{
            ans0[i+1] = nowans1;
            ans1[i+1] = nowans0+1;
        }
    }
    if(p) cout<<accumulate(ans1.begin(), ans1.end(), 0LL)<<endl;
    else cout<<accumulate(ans0.begin(), ans0.end(), 0LL)+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>


using namespace std;

int main(){
    int A, B, K;
    vector<int> x(100);
    int cnt = 0;
    cin >> A >> B >>K;
    
    for (int i = 1; i <= min(A,B); i++)
    {
        if (A%i==0 && B%i==0)
        {
            x[cnt] = i;
            cnt++;
        }
        
    }
    
    cout << x[cnt-K] << endl;

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll pow_mod(ll n, ll k, ll mod) {
    if(k == 0) {
        return 1;
    } else if(k % 2 == 1) {
        return pow_mod(n, k - 1, mod) * n % mod;
    } else {
        ll t = pow_mod(n, k / 2, mod);
        return t * t % mod;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n=s.size();
    ll p=2019;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        a[i] = (ll)(s[i] - '0');
    }
    reverse(ALL(a));
    vector<int> sum(n + 1, 0);
    for(ll i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + a[i] * pow_mod(10, i, p) % p;
        sum[i + 1] %= p;
    }
    map<ll, ll> mp;
    for(ll i = 0; i < n + 1; i++) {
        // cout << sum[i] << " ";
        mp[sum[i]]++;
    }
    // cout << endl;
    ll ans = 0;
    if(p == 2 || p == 5) {
        for(int i = 0; i < n; i++) {
            if(a[i] % p == 0) {
                ans += n - i;
            }
        }
        cout << ans << endl;
        return 0;
    }
    for(const auto &p : mp) {
        ans += (p.second - 1) * p.second / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5944
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<climits>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll n, l;
	cin >> n >> l;
	if (l<=0&&0<=l+n-1) {
		cout << n * (l+l+ n - 1) / 2 << endl;
	}
	else if (l + n - 1 < 0) {
		cout << (n - 1)*(l + (l + n - 2)) / 2 << endl;
	}
	else {
		cout << (n - 1)*(l+1+(l+n-1)) / 2 << endl;
	}
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,r;
    scanf("%d",&n);
    r=n%10;
    if(r==2 || r==4 || r==5 || r==7 || r==9)
    {
        printf("hon\n");
    }
    else if(r==0 || r==1 || r==6 || r==8)
    {
        printf("pon\n");
    }
    else
    {
        printf("bon\n");
    }
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


void Dijkstra(int s, const vector<vector<P>> &g, vector<int> &dis) {
  priority_queue<P, vector<P>, greater<P>> que; // pair = (cost, v);
  dis[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int now = p.second;
    if(dis[now] < p.first) continue;
    for(P np : g[now]) {
      int next = np.second;
      if(dis[next] > dis[now] + np.first) {
        dis[next] = dis[now] + np.first;
        que.emplace(dis[next], next);
      }
    }
  }
}


int main(){
    
    int n;
    cin >> n;
    V<V<P>> g(n); // pair = (cost, to);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        rep(j,k) {
            int b, v;
            cin >> b >> v;
            g[a].emplace_back(v,b);
        }
    }

    V<int> d(n, inf);
    Dijkstra(0,g,d);
    rep(i,n) {
        printf("%d %d\n", i, d[i]);
    }
}


Measured memory_bytes: 3148
def e_logs():
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    def ceil_int(p, q):
        """p/q の切り上げ"""
        return (p + q - 1) // q

    def calc(x):
        """K 回以内のカットですべての丸太の長さを x 以下にできるか？"""
        return sum(ceil_int(a, x) - 1 for a in A) <= K

    # 全丸太の長さは、0 以下にはできないし、max(A) には必ずできる (どれも切らない)
    reject, accept = 0, max(A)
    while accept - reject > 1:
        mid = (accept + reject) // 2
        if calc(mid):
            accept = mid
        else:
            reject = mid
    return accept

print(e_logs())

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  cout << n * 800 - n / 15 * 200 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (true) {

            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();

            if (op.equals("?"))
                break;
            if (op.equals("+"))
                System.out.println(a + b);
            if (op.equals("-"))
                System.out.println(a - b);
            if (op.equals("*"))
                System.out.println(a * b);
            if (op.equals("/"))
                System.out.println(a / b);

        }

        sc.close();
    }
}


Measured memory_bytes: 26300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0); cin.tie(0);

  int x; cin >> x; cout << !x << endl;
  
  return 0;
}


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

int main() {
	int n, m;
	int sum = 0;

	cin >> n >> m;

	vector<vector<int>> A(n, vector<int>(m));
	vector<int> k(n);
	vector<int> counter(m+1);

	for (int i = 0; i < n; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> A[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k[i]; j++) {
			counter[A[i][j]]++;
		}
	}

	for (int i = 1; i < m+1; i++) {
		if (counter[i] == n) {
			sum++;
		}
	}

	cout << sum;

	return 0;
}

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

int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  vector<long long int> vec(4);
  vec.at(0) = a * c;
  vec.at(1) = a * d;
  vec.at(2) = b * c;
  vec.at(3) = b * d;
  
  sort(vec.begin(),vec.end());
  cout << vec.at(3) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    int sum = 0;
    REP (i, 0, n) {
        a[i] = l + i;
        sum += a[i];
    }
    int ans = 1 << 30;
    int diff = sum;
    REP (i, 0, n) {
        int tmp = 0;
        REP (j, 0, n) {
            if (i == j) continue;
            tmp += a[j];
        }
        if (abs(sum - tmp) < ans) {
            ans = abs(sum - tmp);
            diff = tmp;
        }
    }
    cout << diff << endl;

    return 0;
}


Measured memory_bytes: 256