akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(isize);
    let v = get!([isize]);
    let c = get!([isize]);

    println!("{}", v.into_iter().zip(c.into_iter()).map(|(x,y)|x-y).filter(|&e| e > 0).sum::<isize>());
}


Measured memory_bytes: 8572
#include<iostream>
using namespace std;
int main(){
int x,y;
cin>>x>>y;
if(x> 20|| x<0 || y>20 || y<0)
    return 0;
if(x>9|| x<0 || y>9 || y<0)
    cout<<-1;
else cout<<x*y;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b/a, c) << endl;
	return 0;
 }

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    ll n;
    cin >> n;

    for (ll i = 1e5; ; i--) {
        if (i*i <= n) {
            cout << i*i << endl;
            return 0;
        }
    }

    return 0;
}

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

int main() {
    int n;cin>>n;
    int a[n];
    int mx=0,mx2=0;
    for (int i=0;i<n;i++) {
        cin>>a[i];
        if (a[i]>mx) {
            mx2=mx;
            mx=a[i];
        } else if (a[i]>mx2)
            mx2=a[i];
    }
    for (int i=0;i<n;i++) {
        if (a[i]==mx)
            cout<<mx2<<endl;
        else
            cout<<mx<<endl;
    }
}

Measured memory_bytes: 2432
n = input()
for i in range(n):
    h,m = map(int, raw_input().split(":"))
    sangle = 1.0 * 360 * (h * 60 + m) / 720
    langle = 1.0 * 360 * m / 60
    angle = abs(sangle - langle)
    if angle > 180:
        angle = 360 - angle
    if (0 <= angle < 30):
        print "alert"
    elif (90 <= angle <= 180):
        print "safe"
    else:
        print "warning"

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int count(int n)
{
    int cnt = 0;
    while (n / 2)
    {
        cnt++;
        n /= 2;
    }
    return cnt;
}

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

    rep(i, s.size())
    {
        if (!(i & 1))
        {
            cout << s[i];
        }
    }

    cout << endl;
    return 0;
}


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

int main(){
	int L, num;
	cin >> L;
	int cat_list[101];
	for(int i=0; i<101; ++i){cat_list[i] = -1;}
	int  count=1;
	bool ok=true;
	
	int i = 0;
    while(i<L){
	    ++i;
		cin >> num;
		if(num>0){
			if(cat_list[num] != -1){ok=false; break;}
			else{cat_list[num] = count; ++count;}
		}
		else{
			num *= -1;
			if(cat_list[num] == -1 || cat_list[num] != count-1){ok=false; break;}
			else{cat_list[num]=-1; --count;}
		}
	}
	
	(i==L && ok) ? cout << "OK" << endl : cout << i << endl;

	return 0;
}



Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  string A, B, C;
  cin >> N >> A >> B >> C;

  long ans = 0;
  rep (i, N) {
    unordered_set<char> st;
    st.insert(A[i]);
    st.insert(B[i]);
    st.insert(C[i]);
    ans += st.size() - 1;
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lll;
struct data
{
    bool a,b,c;
    lll x,y,z;
    data() {}
    data(lll aa,lll bb,lll cc,lll xx,lll yy,lll zz)
    {
        a=aa,b=bb,c=cc,x=xx,y=yy,z=zz;
    }
    long long val()const
    {
        return a*x+b*y+c*z-(!a)*x-(!b)*y-(!c)*z;
    }
    bool operator<(data d)const
    {
        return val()<d.val();
    }
};
int main()
{
    lll n,m,x,y,z,i,sum,ans=0;
    priority_queue<struct data> pq[9];
    for(scanf("%lld%lld",&n,&m); n--;) for(scanf("%lld%lld%lld",&x,&y,&z),i=8; i--;) pq[i].push(data(1&i,2&i,4&i,x,y,z));
    for(i=8; i--; ans=max(ans,sum)) for(n=m,sum=0; n--; pq[i].pop()) sum+=pq[i].top().val();
    printf("%lld\n",ans),exit(0);
}

Measured memory_bytes: 512
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();

    int[][] cost = new int[10][10];
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cost[i][j] = scanner.nextInt();

    for (int k = 0; k < 10; k++)
      for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
          if (cost[i][k] + cost[k][j] < cost[i][j]) cost[i][j] = cost[i][k] + cost[k][j];

    int mp = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int a = scanner.nextInt();
        if (a >= 0) mp += cost[a][1];
      }
    }
    System.out.println(mp);
  }
}


Measured memory_bytes: 44592
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll H,W;
    cin>>H>>W;
    if(H%3==0 || W%3==0){
        cout<<0<<endl;
        return 0;
    }

    //残っているものについてはT字区切り、3等分区切りにする
    ll split=W/2;
    ll min_subt=1e9;
    rep(i,H+1){
        ll Sc=W*i;
        ll Sa=(H-i)*split;
        if(W%2){
            ll Sb=(H-i)*(split+1);
            min_subt = min(min_subt, abs(max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc))));    
        }else{
            min_subt = min(min_subt, abs(max(Sa,Sc)-min(Sa,Sc)));
        }

    }
    split=H/2;
    rep(i,W+1){
        ll Sc=H*i;
        ll Sa=(W-i)*split;
        if(H%2){
            ll Sb=(H-i)*(split+1);
            min_subt = min(min_subt, abs(max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc))));    
        }else{
            min_subt = min(min_subt, abs(max(Sa,Sc)-min(Sa,Sc)));
        }

    }
    rep(i,H+1){
        ll Sc=W*i;
        ll Sa=W*((H-i)/2);
        if((H-i)%2){
            ll Sb=W*(((H-i)/2)+1);
            min_subt = min(min_subt, abs(max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc))));    
        }else{
            min_subt = min(min_subt, abs(max(Sa,Sc)-min(Sa,Sc)));
        }
    }
    rep(i,W+1){
        ll Sc=H*i;
        ll Sa=H*((W-i)/2);
        if((W-i)%2){
            ll Sb=H*(((H-i)/2)+1);
            min_subt = min(min_subt, abs(max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc))));    
        }else{
            min_subt = min(min_subt, abs(max(Sa,Sc)-min(Sa,Sc)));
        }
    }
    cout<<min_subt<<endl;
}


Measured memory_bytes: 256
s = list(input())

left = int(s[0]) * 10 + int(s[1])
right = int(s[2]) * 10 + int(s[3])

if 1 <= left <= 12 and 1 <= right <= 12:
    print("AMBIGUOUS")
elif 1 <= left <= 12:
    print("MMYY")
elif 1 <= right <= 12:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).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; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int n;
	cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = INF;
    for (int p = 1; p <= 100; p++) {
        int tmp = 0;
        rep(i,n) tmp += (x[i]-p) * (x[i]-p);
        ans = min(ans, tmp);
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*---------------Go Code GO---------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using Order_Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define PI acos(-1.0)
#define O_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define precision(a) fixed << setprecision(a)
#define endl '\n'
#define Flush cout << flush
#define LLMX 0x3fffffffffffffff

long long N;

int main()
{
    O_O;

    string S;
    cin >> S;
    string mask1;
    string mask2;

    for (int i = 0; i < S.size(); i++)
    {
        if (i % 2 == 0)
            mask1.push_back('0'), mask2.push_back('1');
        else
            mask1.push_back('1'), mask2.push_back('0');
    }
    long long ans = S.size(), x = 0, y = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != mask1[i])
            x++;
        if (S[i] != mask2[i])
            y++;
    }
    cout << min(x, y) << endl;

    return 0;
}

Measured memory_bytes: 3932
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

int count(int K){
	if(K<=1){
		return 0;
	}else{
		return int(K*(K-1)/2);
	}
}

int main()
{
    int N,M;
    cin >> N >>M;
	cout << count(N)+count(M) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e5+7;
const int N=1e4+5;
ll l[105];

int main(){
    int n;cin>>n;
    int cnt=0;
    for(int i=0;i<n;i++) {
        cin>>l[i];
    }
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        for(int k=j+1;k<n;k++)
        if(l[i]!=l[j]&&l[i]!=l[k]&&l[j]!=l[k]&&l[i]+l[j]>l[k]&&l[k]+l[i]>l[j]&&l[j]+l[k]>l[i])
            cnt++;
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3628
import static java.lang.System.*;
import java.util.*;

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

        int n = sc.nextInt();
        ArrayList<Integer> b = new ArrayList<Integer>();
		for(int i=0; i<n; i++) b.add(sc.nextInt());
		
		ArrayList<Integer> ans = new ArrayList<Integer>();
		while(b.size() > 0) {
			for(int i=b.size()-1; i>=0; i--) {
				if(b.get(i) > i+1) {
					ans.clear();
					ans.add(-1);
					break;
				}
				else if(b.get(i) == i+1) {
					ans.add(b.get(i));
					b.remove(i);
					break;
				}
			}
			
			if(ans.get(0) < 0) break;
		}
		
		for(int i=ans.size()-1; i>=0; i--)
	        out.println(ans.get(i));
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map<string, int> all;
	string buf;
	int maxlength = 0;
	string maxstring;
	while(cin>>buf){
		if(!all.count(buf)){
			all.insert( map<string, int>::value_type(buf, 1) );
			if(maxlength < buf.size()){
				maxlength = buf.size();
				maxstring = buf;
			}
		} else {
			all[buf]++;
		}
	}
	map<string, int>::iterator it = all.begin();
	int maxf = 0;
	string maxsf;
	while( it != all.end() )
	{
		if(maxf < (*it).second){
			maxf = (*it).second;
			maxsf = (*it).first;
		}
		++it;
	}
	cout<<maxsf<<" "<<maxstring<<endl;
	return 0;
}

Measured memory_bytes: 0
//# pragma GCC optimize ("O2")
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<climits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<iomanip>
#include<sstream>
#define out(i,a,now) for(int i=a.be[now],to=a.v[i];i;i=a.ne[i],to=a.v[i])
#define fo(i,a,b) for(i=a;i<=b;i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define mp(a,b) make_pair(a,b)
#define qk(x) memset(x,0,sizeof(x))
#define RG register
#define gs(x) (tr[tr[x].f].son[1]==x)
#define lb(x) (x&(-x))
#define mid ((l+r)>>1)
#ifdef Mogician
#endif
using namespace std;
typedef long long LL;
typedef double DB;
template <class T> void cmax(T &a,T b)
{
    a=max(a,b);
}
template <class T> void cmin(T &a,T b)
{
    a=min(a,b);
}
template <class T> void swp(T &a,T &b)
{
	T temp=a; a=b; b=temp;
}
int main()
{
	LL a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	printf("%lld",min(a,b)+min(c,d));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
char s[20];
long long num[200];
long long sum=0;

int main(){
    int n;
    long long k;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        getchar();
        scanf("%s",s);
        if(s[0]=='M'){
            num[0]++;
        }
        else if(s[0]=='A'){
            num[1]++;
        }
        else if(s[0]=='R') num[2]++;
        else if(s[0]=='C') num[3]++;
        else if(s[0]=='H') num[4]++;

    }
    sum+=num[0]*num[1]*num[2];
    sum+=num[0]*num[1]*num[3];
    sum+=num[0]*num[1]*num[4];
    sum+=num[0]*num[2]*num[3];
    sum+=num[0]*num[2]*num[4];
    sum+=num[0]*num[3]*num[4];
    sum+=num[1]*num[2]*num[3];
    sum+=num[1]*num[2]*num[4];
    sum+=num[1]*num[3]*num[4];
    sum+=num[2]*num[3]*num[4];
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	static void main() throws Exception{
		int l=sc.nextInt(),r=sc.nextInt(),d=sc.nextInt();
		int ans=0;
		for(int i=l;i<=r;i++) {
			ans+=i%d==0?1:0;
		}
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


Measured memory_bytes: 32816
n = int(input())
dic = {}
set = set()
for i in range(n):
    s = input()
    if s not in set:
        set.add(s)
        dic[s] = 1
    else:
        dic[s] += 1
vmax = max(dic.values())
maxkey = []
for i in dic.keys():
    if dic[i] == vmax:
        maxkey.append(i)
maxkey.sort()
for i in maxkey:
    print(i)

Measured memory_bytes: 40356
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cx, cyは0~100, hは1以上
    
    cin >> n;
    int x[n], y[n], h[n];
    rep(i, n){
        cin >> x[i] >> y[i] >> h[i];
    }
    
    int tmp_h = 0, rec = 0;
    rep(i, n){
        if(tmp_h < h[i]){
            rec = i;
            tmp_h = h[i];
        }
    }
    swap(x[0], x[rec]);
    swap(y[0], y[rec]);
    swap(h[0], h[rec]);
    //cout << rec << endl;
    
    if(n == 1){
        cout << x[0] << " " << y[0] << " " << h[0] << endl;
        return 0;
    }
    int tmp_H, pre_H, H, tmp;
    bool judge;
    rep_eq(cx, 100){
        rep_eq(cy, 100){
            judge = true;
            rep(k, n){
                if(k){
                    tmp = max(H - abs(x[k] - cx) - abs(y[k] - cy), 0);
                    if(tmp != h[k]) judge = false;
                }else{
                    H = abs(x[k] - cx) + abs(y[k] - cy) + h[k];
                }
                
                if(!judge)  break;
                //cout << cx << " " << cy << " " << pre_H << " " << tmp_H << endl;
            }
            if(judge){
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
}

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



int main(int argc, const char * argv[]) {
    long long n = 0;
    long long a = 0;
    long long b = 0;
    cin >> n >> a >> b;

    long long repeatNum = n / (a+b);
    long long amari = n % (a+b);
    long long addNum = 0;
    if(amari > a)addNum = a;
    else addNum = amari;

    cout << repeatNum * a + addNum << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1000000000; 
int main(){
   double w, h, x, y,s;
   cin>>w>>h>>x>>y;
   if(2*x-w==0 or 2*y-h==0){
      s = w * h / 2;
      if(2*y-h==0 and 2*x-w==0){
         cout << s << " 1" << endl;
      }else{
         cout <<s << " 0" << endl;
      }
   }else{
      s=(2*w*h*y-w*h*h)/(4*y-2*h);
      cout << min(s, w * h - s) << " 0" <<endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
const int MOD = (int)1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()

unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<unsigned long long> T(N);
  REP(i, N) { cin >> T[i]; }
  sort(ALL(T));
  unsigned long long before = T.back();
  for (int i = T.size() - 1; i > 0; i--) {
    before = gcd(T[i - 1], before);
  }
  unsigned long long ans = T[0];
  FOR(i, 1, N) {
    ll temp = T[i] / gcd(ans, T[i]);
    ans = ans * temp;
    cerr << i << "'s ans=" << ans << endl;
  }
  cout << ans << endl;

  return 0;
}


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



int main() {
    int R, G, B, N; cin >> R >> G >> B >> N;
    int ans = 0;
    rep(i, 3000) rep(j, 3000)
        if ((N - (i*R+j*G)) % B == 0 && (N - (i*R+j*G)) >= 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] ruiseki = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ruiseki[i - 1] + sc.nextInt();
        }

        int min = Integer.MAX_VALUE;

        for (int i = 1; i < ruiseki.length - 1; i++) {
            int left = ruiseki[i] - ruiseki[0];
            int right = ruiseki[ruiseki.length - 1] - ruiseki[i];
            min = Math.min(min, Math.abs(left - right));
        }

        out.println(min);

        out.flush();

    }

    static class Toi {
        public int x;
        public int y;

        public Toi(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }

            if (this == obj) {
                return true;
            }

            if (this.getClass() != obj.getClass()) {
                return false;
            }

            Toi toi = (Toi) obj;
            return x == toi.x && y == toi.y;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h){
		string in;
		cin >> in;
		s.at(i) = in;
	}
	priority_queue<tuple<int, int, int, bool>, vector<tuple<int, int, int, bool>>, greater<tuple<int, int, int, bool>>> pq;//count, x, y, t:. f:#
	vector<vector<int>> vc(h, vector<int>(w, 105));
	bool fm = true;
	int fc = 0;
	if(s.at(0)[0] == '#'){
		fm = false;
		fc++;
	}
	vc.at(0).at(0) = true;
	pq.push(make_tuple(fc, 0, 0, fm));
	while(!pq.empty()){
		auto nt = pq.top(); pq.pop();
		int count, x, y;
		bool mode;
		tie(count, x, y, mode) = nt;
		if(x == w-1 && y == h-1){
			cout << count << endl;
			return 0;
		}
		if(x+1 < w){
			int ad = 0;
			bool nm = mode;
			if(mode == false){
				if(s.at(y)[x+1] == '.') nm = true;
			}else{
				if(s.at(y)[x+1] == '#'){
					nm = false;
					ad++;
				}
			}
			if(vc.at(y).at(x+1) > count + ad){
				pq.push(make_tuple(count + ad, x+1, y, nm));
				vc.at(y).at(x+1) = count + ad;
			}
		}
		if(y+1 < h){
			int ad= 0;
			bool nm = mode;
			if(mode == false){
				if(s.at(y+1)[x] == '.') nm = true;
			}else{
				if(s.at(y+1)[x] == '#'){
					nm = false;
					ad++;
				}
			}
			if(vc.at(y+1).at(x) > count + ad){
				pq.push(make_tuple(count + ad, x, y+1, nm));
				vc.at(y+1).at(x) = count + ad;
			}
		}
	}
	return 1;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	vector <ll> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
	}
	sort(arr.begin(),arr.end());
	ll ans = 0;
	for (int z=0;z<n-k;z++){
		ans += arr[z];
	}
	cout << ans << endl;
}
 


Measured memory_bytes: 1792
//file_name:ABC112_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */


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

    int x = m/n;

    while(true){
        if(m%x==0){
            cout << x << endl;
            return 0;
        }else{
            x--;
        }
    }



    int ans = 0;

    cout << ans << endl;

    return 0;
}



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




static int x = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();




int main()
{

    ll t ;
    cin>>t;

    ll count = 0 ;
    for( ll x = 1 ; x<=t ; x++ )
        {
        if(x%3!=0 && x%5!=0)
        {

            count+=x ;

         }
    }


    cout<< count <<endl ;


    return 0 ;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;

ll n, k;
const int D = 18;

struct Db {
    vector<vector<ll>> d, s;
    Db(vector<ll> x) {
        d.resize(n+1, vector<ll>(D, n));
        s.resize(n+1, vector<ll>(D, 0));
        int jj = n;
        rrep(i, n) {
            while (x[i]+k<=x[jj-1]) jj--;
            d[i][0] = jj;
            s[i][0] = jj;
        }
        rep(j, D) {
            if (j==0) continue;
            rep(i, n) {
                d[i][j] = d[d[i][j-1]][j-1];
                s[i][j] = s[i][j-1] + s[d[i][j-1]][j-1];
            }
        }
        //debug(d[0][0]);
    }
    ll cnt = 0;
    ll get(int l, int r) {
        ll res = l;
        cnt = 1;
        rrep(i, D) {
            ll now = 1<<i;
            if (d[l][i]>r) continue;
            res += s[l][i];
            l = d[l][i];
            cnt += now;
            //debug(res);
        }
        return res;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    cin >> n >> k;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    Db db1(x);
    
    vector<ll> y(n);
    rep(i, n) {
        y[i] = -x[n-1-i];
    }
    
    Db db2(y);
    
    ll q;
    cin >> q;
    rep(qi, q) {
        ll l, r;
        cin >> l >> r;
        l--; r--;
        ll sum1 = db1.get(l, r);
        //debug(sum1);
        ll ans = db1.cnt;
        //debug(db1.cnt);
        ll sum2 = db2.get(n-1-r, n-1-l);
        //debug(sum2);
        //debug(db2.cnt);
        sum2 = db2.cnt*(n-1) - sum2;
        ans += (sum2-sum1);
        pr(ans);
    }
    
    return 0;
}


Measured memory_bytes: 151800
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int v[20][20];
signed main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int matsubi = i % 10;
        int sentou;
        int copy = i;
        while (copy>9)
        {
            copy /= 10;
        }
        sentou = copy;
        v[sentou][matsubi]++;
    }
    int cnt = 0;
    for (int i = 1; i < 10; i++)
    {
        for (int j = i; j < 10; j++)
        {
           
            if(i==j)cnt += v[i][j] * v[j][i];
            else
                cnt += 2 * v[i][j] * v[j][i];
           // cerr << i << " " << j << endl;
           // cerr << cnt << endl;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
ll w,h,x,y;

int main()
{
    scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
    printf("%.6f ",(double)w*h/2);
    if (2*x==w&&2*y==h) printf("1");
    else printf("0");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>

bool isPalindrome(std::string s)
{
    std::string rev_s{s};
    std::reverse(rev_s.begin(), rev_s.end());
    //std::cout << rev_s << std::endl;

    return s == rev_s;
}

int main()
{
    std::string str;
    std::cin >> str;
    int n = str.length();
    bool flag = true;

    flag = flag && isPalindrome(str);
    flag = flag && isPalindrome(str.substr(0, (n - 1) / 2));
    flag = flag && isPalindrome(str.substr((n + 1) / 2));

    if (flag)
        std::cout << "Yes\n";
    else
    {
        std::cout << "No\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace::std;
#define int long long int 
#define MOD 1000000007LL

int dp[10005][100][2];

main(){
	ios_base::sync_with_stdio(0);
	string s;
	int d;
	cin>>s>>d;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.length();i++)
		for(int m=0;m<d;m++){
			dp[i][m][1]=(i?dp[i-1][(m+s[i]-'0')%d][1]:((m+s[i]-'0')%d)==0);
			for(int k=0;k<=9;k++){
				dp[i][m][0]=(dp[i][m][0]+(i?dp[i-1][(m+k)%d][0]:((m+k)%d)==0))%MOD;
				if(k<s[i]-'0')
					dp[i][m][1]=(dp[i][m][1]+(i?dp[i-1][(m+k)%d][0]:((m+k)%d)==0))%MOD;
			}
		}
	// for(int j=0;j<2;cout<<'\n',j++)
	// 	for(int m=d-1;m>-1;cout<<'\n',m--)
	// 		for(int i=0;i<s.length();i++)
	// 			cout<<dp[i][m][j]<<' ';
	cout<<(dp[s.length()-1][0][1]-1+MOD)%MOD<<'\n';
}

Measured memory_bytes: 15872
#include <stdio.h>

int main(void)
{
	int tate;
	int yoko;
	int i;  /*繰り返し用の変数*/
	int n;
	char gazou[1000][1000];
	int k;
	int j;
	int x;
	int y;
	int z = 0;
	
	scanf("%d %d",&tate,&yoko);
	
	for(i = 0;i < tate;++i){
//		for(n = 0;n < yoko;++n){
			scanf("%s",&gazou[i]);
			++z;
//		}
	}
	for(k = 0;k < yoko+2;++k){
		printf("#");
	}
	printf("\n");
	
	for(j = 0;j < z;++j){
		printf("#");
				printf("%s",gazou[j]);
		printf("#");
		printf("\n");
	}	
	
	for(x = 0;x < yoko+2;++x){
		printf("#");
	}
	printf("\n");
	
	
	return(0);
}

	

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

using namespace std;

#define MAX_N 100000
const double INF = 1e50;

typedef pair<double,double> P;

int N;
P A[MAX_N]; 

bool compare_y(const P &a,const P &b){
  return a.second < b.second;
}
 
double closest_pair(P *a,int n){
  if(n <= 1) return INF;
  int m = n / 2;
  double x = a[m].first;
  double d = min(closest_pair(a,m),closest_pair(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare_y);
 
  vector<P> b;
  for(int i = 0 ; i < n ; i++){
    if(fabs(a[i].first - x) >= d) continue;
    for(int j = 0 ; j < (int)b.size() ; j++){
      double dx = a[i].first - b[b.size()-j-1].first;
      double dy = a[i].second - b[b.size()-j-1].second;
      if(dy >= d) break;
      d = min(d,sqrt(dx * dx + dy * dy));
    }
    b.push_back(a[i]);
  }
  return d;
}

void solve(){
  sort(A,A+N);
  printf("%.8f\n",closest_pair(A,N));
}

int main(){
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    scanf("%lf%lf",&A[i].first,&A[i].second);
  }
  solve();
  return 0;
}

Measured memory_bytes: 6080
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s; cin >> s;
    bool ans = false;
    for(int i = 0; i<3; i++){
        if(s[i] == '9') ans =true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << 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);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();

        System.out.println(func(a, b, Math.min(b -1, n)));
    }
    static long func(long a, long b, long n){
        return ((a * n) / b) - (a * (n / b));
    }
}

Measured memory_bytes: 35856
#include <stdio.h>

int main(void) {
	char linebuffer[200];
	long long q1,b,c1,c2,q2;
	long long result1,result2;
	while(fgets(linebuffer,sizeof(linebuffer),stdin)) {
		if(linebuffer[0]=='0' && (linebuffer[1]=='\n' || linebuffer[1]==0))break;
		sscanf(linebuffer,"%lld%lld%lld%lld%lld",&q1,&b,&c1,&c2,&q2);
		if(q1<=0)break;
		if(c1<=c2) {
			result1=b/c1;
			result2=0;
			if(result1<q1)result1=result2=-1;
			else if(result1>q2) {
				result1=q2;
				result2=(b-q2*c1)/c2;
				if(result1+result2<q1)result1=result2=-1;
			}
		} else {
			long long left,right,mid;
			left=0;right=(b/c1<=q2?b/c1:q2);
			while(left<=right) {
				mid=(left+right)/2;
				if(mid+(b-c1*mid)/c2>=q1)left=mid+1; else right=mid-1;
			}
			result1=left-1;
			result2=(b-c1*result1)/c2;
		}
		if(result1<=0)puts("NA"); else printf("%lld %lld\n",result1,result2);
	}
	return 0;
}

Measured memory_bytes: 616
sub g{
	($x,$y)=@q[$_[0],$_[0]+1];
	($d[$x]-$d[$y])/($H[$y]-$H[$x])-$H[$x]-$H[$y]
}
($n,$C,@H)=glob`dd`;
map{
	shift@q while@q>1&&g(0)>-2*$H[$_];
	$d[@d]=$X=$d[$q[0]]+$C+($H[$q[0]]-$H[$_])**2;
	$q[@q]=$_;
	$q[--$#q]=$_ while@q>2&&g(-2)>g(-3);
}0..$n-1;
print$X-$C

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

int main(){
	int n,m,l,i,j,p;
	int f[1000][1000];
	int D[1000] = {};
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> m;
		cin >> p;
		for(j = 0; j < p; j++){
			cin >> l;
			f[m][l] = 1;
		}
	}
	queue<int> Q;
	Q.push(1);
	while(!Q.empty()){
		int c = Q.front();
		Q.pop();
		for(i = 2; i <= n; i++){
			if(f[c][i] == 1 && D[i] == 0){
				D[i] = D[c] + 1;
				Q.push(i);
			}
		}
	}				
	for(i = 1; i <= n; i++){
		if (D[i] == 0 && i !=1)
			D[i] = -1;
		cout << i << " " << D[i] << endl;
	}
}	

Measured memory_bytes: 1596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


int main(int argc, char* argv[])
{
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }

  vector<vector<int>> ans;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] % 2 == 0) continue;
      if (i > 1 && a[i-1][j] % 2 == 1) {
        a[i][j]--;
        a[i-1][j]++;
        vector<int> a = {i, j, i-1, j};
        ans.emplace_back(a);
      } else if (j > 1 && a[i][j-1] % 2 == 1) {
        a[i][j]--;
        a[i][j-1]++;
        vector<int> a = {i, j, i, j-1};
        ans.emplace_back(a);
//      } else if (i < h-1 && a[i+1][j] % 2 != 0) {
//        a[i][j]--;
//        a[i+1][j]++;
//        vector<int> a = {i, j, i+1, j};
//        ans.emplace_back(a);
      } else if (j < w-1) {
        a[i][j]--;
        a[i][j+1]++;
        vector<int> a = {i, j, i, j+1};
        ans.emplace_back(a);
      } else if (i < h - 1) {
        a[i][j]--;
        a[i+1][j]++;
        vector<int> a = {i, j, i+1, j};
        ans.emplace_back(a);
      }
    }
  }
  cout << ans.size() << endl;
  for (auto& v : ans) {
    cout << v[0]+1 << " " << v[1]+1 << " " << v[2]+1 << " " << v[3]+1 << endl;
  }

  int num = 0;
  rep(i, h) rep(j, w) {
    if (a[i][j] % 2 == 0) num++;
  }

  cerr << num << endl;

  return 0;
}


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

bool is_acgt(char c)
{
    switch (c)
    {
    case 'A':
    case 'C':
    case 'G':
    case 'T':
        return true;
    default:
        return false;
    }
}

int main()
{
    string S;
    cin >> S;

    int max = 0;
    int strlen = sizeof(S) / sizeof(S[0]);
    int start = -1;
    for (int i = 0; i < strlen; i++)
    {
        char c = S[i];
        if (is_acgt(c))
        {
            if (start == -1)
            {
                start = i;
            }
        }
        else
        {
            if (start != -1)
            {
                if (i - start > max)
                {
                    max = i - start;
                }
                start = -1;
            }
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#define INF 1e8
using namespace std;
int main(void){
int  n,m;
cin>>n;

string str1,str2;
for(int i=0;i<n;++i){
    char a;
    cin>>a;
    str1+=a;
    
}

for(int i=0;i<n;++i){
    char a;
    cin>>a;
    str2+=a;
    
}
string a;
for(int i=1;i<=n;++i){
    char c=i+'0';
    a+=(char)c;
    
}

int i=0;
do{
      i++;
    if(a==str1)
    {
        break;
    }    
}while(next_permutation(a.begin(), a.end()));


string b;
for(int i=1;i<=n;++i){
    char c=i+'0';
    b+=(char)c;
    
}

int j=0;
do{
     j++;
    if(b==str2)
    {
        break;
    }    
   
}while(next_permutation(b.begin(), b.end()));

cout<<abs(i-j);
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
int v[N],n,s;
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int main(){
    cin>>n;
    for (int i=2; i<=30000; ++i)
	if (i%2==0||i%3==0){
	    v[i]=1,s+=i,--n;
	    if (n==1) break;
	}
    for (int i=2; i<=30000; ++i)
	if (!v[i]&&(s+i)%2==0&&(s+i)%3==0&&gcd(s,i)!=1)
	    { v[i]=1; break; }
    for (int i=2; i<=30000; ++i)
	if (v[i])
	    printf("%d ",i);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  int n;
  std::cin >> n;

  std::vector<int> a(n);
  std::vector<int> b(n);
  std::vector<int> c(n - 1);

  for (auto&& ai : a) std::cin >> ai;
  for (auto&& bi : b) std::cin >> bi;
  for (auto&& ci : c) std::cin >> ci;

  int sum = std::accumulate(b.begin(), b.end(), 0);

  for (int i = 0; i < n - 1; ++i)
    if (a[i + 1] == a[i] + 1) sum += c[a[i] - 1];

  std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, M;
  cin >> N >> M;
  vector<long> dp(N + 1, 0);
  int a;
  for(int i = 0; i < M; i++){
    cin >> a;
    dp.at(a) = -1;
  }
  if(dp.at(0) != -1) dp.at(0)++;
  if(dp.at(1) != -1) dp.at(1)++;
  for(int i = 2; i <= N; i++){
    if(dp.at(i) == -1)continue;
    if(dp.at(i - 2) == -1 && dp.at(i - 1) == -1)dp.at(i) = 0;
    else if(dp.at(i - 1) == -1)dp.at(i) = dp.at(i - 2);
    else if(dp.at(i - 2) == -1)dp.at(i) = dp.at(i - 1);
    else dp.at(i) = dp.at(i - 1) + dp.at(i - 2);
    dp.at(i) %= 1000000007;
  }
  cout << dp.at(N) << endl;
  return 0;
}

Measured memory_bytes: 1024