akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a);
    rep(i,a){
        cin >> p[i];
    }
    vector<ll> q(b);
    rep(i, b)
    {
        cin >> q[i];
    }
    vector<ll> r(c);
    rep(i, c)
    {
        cin >> r[i];
    }
    priority_queue<ll> ans;
    sort(p.begin(),p.end(),greater<ll>());
    sort(q.begin(),q.end(),greater<ll>());
    rep(i,x){
        ans.push(p[i]);
    }
    rep(j,y){
        ans.push(q[j]);
    }
    for(int i=0;i<c;i++){
        ans.push(r[i]);
    }
    ll res=0;
    for(int i=0;i<x+y;i++){
        ll it = ans.top();
        ans.pop();
        res+=it;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8560
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <cassert>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int N;
	int ave=0;
	int ans = 0;
	cin >> N;
	vector<int> X(N);
	rep(i, N) {
		cin >> X[i];
		ave += X[i];
	}
	ave =round(ave/double(N));
	rep(i, N) {
		ans += pow(ave - X[i], 2);
	}
	cout << ans;
	}

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

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	SegmentTree(vector<T> data_, T id_, func_t merge_) :
		n(size(data_.size())), id(id_), merge(merge_), data(size(data_.size()) * 2, id_) {
		for (int i = 0; i < data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Add(int p, T val) {
		assert(0 <= p && p < n);
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};


int main()
{
	int n, q;
	int com, x, y;
	cin >> n >> q;
	SegmentTree<int> st(n, 0, [](int a, int b) { return a + b; });
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com)
			cout << st.Find(x - 1, y - 1) << endl;
		else
			st.Add(x - 1, y);
	}
	return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>

int main() {

	int N, K;

	scanf("%d %d",&N,&K);

	int i;

	int ans = K;

	for (i = 0; i < N-1; i++) {
		ans *= (K - 1);
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	static int res = 0;

	public static void main(String[] args) throws Exception {

		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = sc.nextInt();
		for (int i = 0; i < a.length; i++)
			b[i] = sc.nextInt();
		for (int i = 0; i < a.length; i++)
			c[i] = sc.nextInt();

		System.out.println(helper(a, b, c));

	}

	private static long helper(int[] a, int[] b, int[] c) {
		// TODO Auto-generated method stub
		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);

		long[] A = new long[a.length];
		long[] B = new long[a.length];
		Arrays.fill(A, -1);
		Arrays.fill(B, -1);
		int j=a.length-1;
		for (int i = a.length-1; i >=0; i--) {
			for (; j >=0; j--) {
				if (a[j] < b[i]) {
					A[i] =j+1;
					break;
				}
			}
			if (j < 0)
				break;
		}
		j = 0;
		for (int i = 0; i < a.length; i++) {
			for (; j < b.length; j++) {
				if (c[j] > b[i]) {
					B[i] = a.length - j;
					break;
				}
			}
			if (j > b.length)
				break;
		}
		long res = 0;

		for (int i = 0; i < a.length; i++) {
			if(A[i]>0&&B[i]>0)
				res+=A[i]*B[i];
		}
		return res;
	}

	private static void out(int[] c) {
		for(int i=0;i<c.length;i++)
			System.out.print(c[i]+" ");
		System.out.println();
	}
}

Measured memory_bytes: 95672
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
using namespace std;

int k=1, i=0, preoneflag=1, indx=1;
string s;

int main(){
  cin >> s;
  while(indx<s.size()){
    if(s[indx]==s[indx-1] && preoneflag){
      indx+=2;
      preoneflag=0;
    } else {
      indx++;
      preoneflag=1;
    }
    k++;
  }
  if(indx==s.size()+1)k--;
  cout << k << endl;
}


Measured memory_bytes: 640
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A,B,C,D=map(int, readline().split())
    print(max(A*B,C*D))

if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin >> N;
  if(N<105){
    cout << 0 << endl;
  }
  else if(N<135){
    cout << 1 << endl;
  }
  else if(N<165){
    cout << 2 << endl;
  }
  else if(N<189){
    cout << 3 << endl;
  }
  else if(N<195){
    cout << 4 << endl;
  }
  else{
    cout << 5 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		long ans=(a*b>c*d)?a*b:c*d;
		System.out.println(ans);

	}

}


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

int main() {
  int N;
  string S;
  cin>>N>>S;
  vector<int> lW(N,0),rE(N,0);
  for(int i=0;i<N;i++){
    char c=S.at(i);
    if(c=='W'){lW.at(i)=1;}
    else{rE.at(i)=1;}
  }
  for(int i=1;i<N;i++){lW.at(i)+=lW.at(i-1);}
  for(int i=N-2;i>=0;i--){rE.at(i)+=rE.at(i+1);}
  int l_edge=rE.at(1);
  int r_edge=lW.at(N-2);
  int minp=min(l_edge,r_edge);
  for(int i=1;i<N-2;i++){
    int p=lW.at(i-1)+rE.at(i+1);
    minp=min(p,minp);
  }
  cout<<minp<<endl;
}

Measured memory_bytes: 3076
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	/**
	 * @param args
	 */

	static class Cmp implements Comparator<Integer> {
		 
	    /** ソート対象のカラムの位置 */
	    public int compare( Integer n1, Integer n2 ) {
	    	int	st = (n2/10000) - (n1/10000);
	    	if (st == 0) {
	    		st = (n1%10000) - (n2%10000);
	    	}
	        return st;
	    }
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int			n = 0;
		Integer[]	t = new Integer[40];

		while((n = parseNum()) != 0) {
			for (int i = 0; i < n; i++) {
				t[i] = score();
			}

			Arrays.sort(t, 0, n, new Cmp());

			for (int i = 0; i < n; i++) {
				System.out.println((t[i]%10000)+" "+(t[i]/10000));
			}
		}
	}

	private static int score() {
		int		sno = parseNum();
		int		sum = 0;
		int[]	inp = new int[21+1];
		int[]	scr = new int[21];

		for (int i = 0, cnt = 1; i < 10; i++) {
			inp[cnt]   = parseNum();
			scr[i*2+0] = cnt++;

			if (i < 9) {
				if (inp[scr[i*2+0]] == 10) continue;
				inp[cnt]   = parseNum();
				scr[i*2+1] = cnt++;
			} else {
				if (inp[scr[i*2+0]] == 10) {
					inp[cnt]   = parseNum();
					scr[i*2+1] = cnt++;
					inp[cnt]   = parseNum();
					scr[i*2+2] = cnt++;
				} else {
					inp[cnt]   = parseNum();
					scr[i*2+1] = cnt++;
					if (inp[scr[i*2+0]] + inp[scr[i*2+1]] == 10) {
						inp[cnt]   = parseNum();
						scr[i*2+2] = cnt++;
					}
				}
			}
		}

		for (int i = 0; i < 10; i++) {
			int	tmp = 0;

			if (i < 9) {
				if (inp[scr[i*2+0]] == 10) {
					tmp += inp[scr[i*2+0]] + inp[scr[i*2+0]+1] + inp[scr[i*2+0]+2];
				} else if (inp[scr[i*2+0]] + inp[scr[i*2+1]] == 10) {
					tmp += inp[scr[i*2+0]] + inp[scr[i*2+1]] + inp[scr[i*2+1]+1];
				} else {
					tmp += inp[scr[i*2+0]] + inp[scr[i*2+1]];
				}
			} else {
				tmp += inp[scr[i*2+0]] + inp[scr[i*2+1]] + inp[scr[i*2+2]];
			}

			sum += tmp;
		}

		return sum*10000+sno;
	}

	private static int parseNum() {
		try {
			int	buf = 0;
			int	num = 0;
			int	mns = 0;
			int	skp = 1;

			// -,0〜9以外は読み飛ばす
			while (true) {
				buf = System.in.read();
				if (buf == '-') {
					mns = 1;
					skp = 0;
				} else if (buf >= '0' && buf <= '9') {
					num = num * 10 + (buf - '0');
					skp = 0;
				} else if ((skp == 0 || buf == -1) && buf != '.') {
					return (mns == 0)?num:num*(-1);
				}
			}
		} catch (IOException e) {}
		return -1;
	}
}

Measured memory_bytes: 15096
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;
#define ll long long

int main() {
    int n;
    cin >> n;
    ll a[100000], b[100000];
    for (int i = 0; i<n; i++) {
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if ((a[i] + ans) % b[i] != 0) {
            ans = ans + b[i] - (a[i] + ans) % b[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        char[] s = ns().toCharArray();

        for (int i = 0; i < s.length - 1; i++) {
            if (s[i] == s[i + 1]) {
                out.println((i + 1) + " " + (i + 2));
                return;
            }
            if (i < s.length - 2 && s[i] == s[i + 2]) {
                out.println((i + 1) + " " + (i + 3));
                return;
            }
        }

        out.println("-1 -1");
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 11092
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn reach(n: usize, s: &[char], a: usize) -> Vec<bool> {
    let mut ret = vec![false; n];
    ret[a] = true;
    let mut pos = a;
    while pos < n {
        if s[pos] != '#' {
            ret[pos] = true;
        }
        if pos + 1 < n && s[pos + 1] == '.' {
            pos += 1;
            continue;
        }
        if pos + 2 < n && s[pos + 2] == '.' {
            pos += 1;
            continue;
        }
        break;
    }
    ret
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    macro_rules! fail {
        () => {
            puts!("No\n");
            return;
        }
    }
    input! {
        n: usize, a: usize1, b: usize1, c: usize1, d: usize1,
        s: chars,
    }
    let ra = reach(n, &s, a);
    let rb = reach(n, &s, b);
    //eprintln!("ra = {:?}, rb = {:?}", ra, rb);
    if !ra[c] || !rb[d] {
        fail!();
    }
    let swap = c > d;
    if swap {
        // check for space with width >= 3
        let mut found = false;
        for i in 0..min(n - 3, d - 1) + 1 {
            if ra[i] && rb[i + 1] && rb[i + 2] {
                found = true;
                break;
            }
        }
        if !found {
            fail!();
        }
    }
    puts!("Yes\n");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
#define inf 20021225
#define pa pair<int,int>
#define mp make_pair
#define fs first
#define se second
using namespace std;
bool vis[1100][1100]; char ch[1100];
int h,w,id[1100][1100]; queue<pa> que;
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	{
		scanf("%s",ch+1);
		for(int j=1;j<=w;j++)
		{
			vis[i][j]=(ch[j]=='#');
			if(vis[i][j])	que.push(mp(i,j));	
		}
	}
	int ans=0;
	while(!que.empty())
	{
		pa tmp=que.front(); que.pop();
		int x=tmp.fs,y=tmp.se; ans=max(ans,id[x][y]);
		if(x+1<=h && !vis[x+1][y])
			vis[x+1][y]=1,id[x+1][y]=id[x][y]+1,que.push(mp(x+1,y));
		if(y+1<=w && !vis[x][y+1])
			vis[x][y+1]=1,id[x][y+1]=id[x][y]+1,que.push(mp(x,y+1));
		if(x-1 && !vis[x-1][y])
			vis[x-1][y]=1,id[x-1][y]=id[x][y]+1,que.push(mp(x-1,y));
		if(y-1 && !vis[x][y-1])
			vis[x][y-1]=1,id[x][y-1]=id[x][y]+1,que.push(mp(x,y-1));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int dp[100002];
signed main() {
    REP(i, 100002) dp[i] = INF;
    int n, K;
    cin >> n >> K;
    vector<int> h(n);
    cin >> h;
    dp[0] = 0;
    REP(i, n) {
        REPF(k, 1, K + 1) {
            if (i + k < n) chmin(dp[i + k], dp[i] + abs(h[i] - h[i + k]));
        }
    }
    cout << dp[n - 1] << endl;
    return (0^_^0);
}



Measured memory_bytes: 1792
fun main(args: Array<String>) {
    while(true)
    {
        val n:Int = readLine()!!.toInt()
        var list = readLine()!!.split(" ").map(String::toInt)
        list = list.reversed()
        for ( i in 0..n-2)
        {
            print(list[i].toString().plus(" "))
        }
        print(list[n-1].toString())
        println()
        return
    }
}


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

int main()
{
	char c;
	int H, W;
	cin >> H >> W;
	map<char, int> cnt;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> c; cnt[c]++;
		}
	}
	if (H % 2 == 1 && W % 2 == 1) {
		int one = 0, two = 0;
		for (auto p : cnt) {
			if (p.second % 2 == 1) one++;
			else if (p.second % 4 == 2) two++;
		}
		cout << (one <= 1 && two <= H / 2 + W / 2 ? "Yes" : "No") << endl;
	}
	else if (H % 2 == 1 || W % 2 == 1) {
		int one = 0, two = 0;
		for (auto p : cnt) {
			if (p.second % 2 == 1) one++;
			else if (p.second % 4 == 2) two++;
		}
		cout << (one <= 1 && two <= (H & 1 ? W : H) / 2 ? "Yes" : "No") << endl;
	}
	else {
		int fo = 0;
		for (auto p : cnt) {
			if (p.second % 4) fo++;
		}
		cout << (fo == 0 ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n
    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]

def main():
    n,m = tuple([int(t)for t in input().split()])
    
    uf = UnionFind(n)

    for _ in range(m):
        a,b = tuple([int(t)-1 for t in input().split()])
        uf.unite(a,b)

    ans = 0
    for i in uf.par:
        if i == -1:
            ans += 1

    print(ans if ans==0 else ans-1)
if __name__ == "__main__":
    main()

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

int main(){
    int n;
    cin>>n;
    
    vector<int> dp(101);

    for(int i=1;i<=n;i++){
        if(i%2==0) dp[i] = dp[i/2]+1;
        else dp[i] = 0;
    }

    int res = 0;
    int ans = 1;
    for(int i=1;i<=n;i++) if(res<dp[i]){res = dp[i];ans=i;}
    cout<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,ans,i,ansc,kk=0;
    while(1){
        ansc=0;
        scanf("%d%d",&a,&b);
        if(a==0&&b==0){
            break;
        }
        if(kk!=0){
            printf("\n");
        }
        for(i=a;i<=b;i++){
            if (i%4==0 && i%100!=0||i%400==0){
                printf("%d\n",i);
                ansc++;
            }else if(i==b&&ansc==0){
                printf("NA\n");
            }
        }
        kk++;
    }
    return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
ll kamenje[100010];
ll dp[100010];

int main()
{
	ios::sync_with_stdio(false);	
	cin.tie(0);
	
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>kamenje[i];
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(kamenje[2]-kamenje[1]);
	for(int i=3;i<=n;i++)
		dp[i]=min(dp[i-1]+abs(kamenje[i]-kamenje[i-1]),dp[i-2]+abs(kamenje[i]-kamenje[i-2]));
	cout<<dp[n];

	
	return 0;
}


Measured memory_bytes: 1792
P, N = list(map(int, input().split()))
arr = list(map(int, input().split()))
mn = 100000000
l, r = 0, len(arr) - 1
for i in range(N):
    if (arr[r] - arr[l]) < mn:
        mn = arr[r] - arr[l]
    arr[l] += P
    l = (l + 1) % N
    r = (r + 1) % N
print(mn)



Measured memory_bytes: 26444
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A_s, B_s = sorted(A), sorted(B)
if any(a > b for a, b in zip(A_s, B_s)):
    print("No")
    quit()
A_idx = [(a, i) for i, a in enumerate(A)]
A_idx.sort()
B = [B[idx] for _, idx in A_idx]
B_idx = [(b, i) for i, b in enumerate(B)]
B_idx.sort()
perm = [0] * N
for i, (_, idx) in enumerate(B_idx):
    perm[idx] = i
cycle_len = 0
used = [False] * N
for i in range(N):
    if used[i]:
        continue
    cnt = 0
    now = i
    while not used[now]:
        used[now] = True
        cnt += 1
        now = perm[now]
    cycle_len += cnt - 1
if cycle_len < N - 1:
    print("Yes")
    quit()

if all(B_idx[i][0] < A_idx[i+1][0] for i in range(N-1)):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 38388
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int i = Integer.parseInt(s);
		int n = 0;
		for(int j = 1; j <= 100;j = 10 * j) {
			if((i / j) % 2 == 0) { 
				
			}else {
				n++;
			}
		}
		System.out.println(n);
	}
}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main(){
  int a,b;
  while( cin >> a >> b ){
    if(a < b)swap(a,b);
    int c;
    while(1){
      c=a%b;
      a = b;
      b = c;
      if(c == 0)break;
    }
    cout << a << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int H, W;
int c[26];

int main()
{
  cin >> H >> W;
  for(int i=0;i<H;i++){
    string s; cin >> s;
    for(int j=0;j<W;j++) c[s[j]-'a']++;
  }

  int c1 = 0;
  if(H%2 && W%2) c1 = 1;
  int c2 = 0;
  if(H%2 || W%2)
    c2 = (H%2)*(W/2) + (W%2)*(H/2);
  int c4 = (H/2*2) * (W/2*2);

  int m1 = 0;
  int m2 = 0;
  for(int i=0;i<26;i++){
    if(c[i]%2) m1++;
    if(c[i]%4 == 2) m2++;
  }

  //  cout << "c1 " << c1 << endl;
  //  cout << "c2 " << c2 << endl;
  //  cout << "m1 " << m1 << endl;
  //  cout << "m2 " << m2 << endl;
  if(m1 == c1 && m2 <= c2 && m2%2 == c2%2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<bool> prime;
int main(){
int n,c;
cin>>n>>c;
vector<vector<ll>> d(c,vector<ll>(c)),a(3,vector<ll>(30,0));
for(int i=0;i<c;i++)for(int j=0;j<c;j++)cin>>d[i][j];
for(int i=0;i<n;i++)for(int j=0;j<n;j++){int m;cin>>m;a[(i+j)%3][m-1]++;}
int ans=INT_MAX;
for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
        if(i==j)continue;
        for(int k=0;k<c;k++){
            if(i==k||j==k)continue;
            int res=0;
            //ある色lからそれぞれi,j,kに塗り替える時のコストと塗られているlの個数の積
            for(int l=0;l<c;l++)res+=d[l][i]*a[0][l];
            for(int l=0;l<c;l++)res+=d[l][j]*a[1][l];
            for(int l=0;l<c;l++)res+=d[l][k]*a[2][l];
            ans=min(ans,res);
        }
    }
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

int h,w,n;
char board[1005][1005];
int x[10],y[10];
bool check(int i, int j) {
	return (i >= 1) && (i <= h) && (j >= 1) && (j <= w) && (board[i][j] == '.');
}
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(void){
    cin>>h>>w;
    int sx = 1,sy=1;
    int gx =h,gy=w;
    int ans = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>board[i][j];
            if(board[i][j]=='.')ans++;
            d[i][j]=1000000;
        }
    }
    d[1][1]=0;
    queue<P>que;
    que.push(P(1,1));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int nx = p.first;
        int ny = p.second;
        for(int i=0;i<4;i++){
            int x=nx+dx[i];
            int y=ny+dy[i];
            if(check(x,y)){
                if(d[x][y]>d[nx][ny]+1){
                    d[x][y]=d[nx][ny]+1;
                    que.push(P(x,y));
                }
            }
        }
    }
    if(d[h][w]==1000000)cout<<-1<<endl;
    else cout<<ans-d[h][w]-1<<endl;
    return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


    class Program
    {
        static void Main(string[] args)
        {
            int line = int.Parse(Console.ReadLine());
            int count = 0;
            int num = 0;
            while(true){
                count++;
                if(count * 1000 >= line){
                    num = 1000 * count - line;
                    break;
                }
            }
            
            Console.WriteLine(num);
        }
    }

Measured memory_bytes: 17596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for (int i = 0; i < r; i++)
#define repeq(i,r) for (int i = 0; i <= r; i++)
#define isc(n) scanf("%d", &n)

int main() {
  int N; isc(N);
  long res = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) res += i;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3660
n = int(input())

def getFirstLast(n):
    digs = []
    while n:
        digs.append(n % 10)
        n //= 10
    return digs[-1], digs[0]

cnt = [[0 for _ in range(10)] for _ in range(10)]
for val in range(1, n + 1):
    first, last = getFirstLast(val)
    cnt[first][last] += 1
ret = 0
for first in range(1, 10):
    for last in range(1, 10):
        ret += cnt[first][last] * cnt[last][first]
print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i = 0; i < (n); ++i)

using namespace std;

int main(){
    int N(0);
    cin >> N;

    vector<int> A(N);
    
    rep(i, N) cin >> A.at(i);
    
    sort(A.begin(), A.end(), greater<int>());
    
    long long C(0);
    int time = N - 1;
    
    rep(i, N){
        int limit = 2;
        if(i == 0) limit = 1;
        rep(j, limit){
            if(time > 0)
                C += A[i];
            --time;
        }
    }
    
    cout << C << endl;
    
    return 0;
}


Measured memory_bytes: 4032
#include<bits/stdc++.h>
 
using lint = long long int;
using pii = std::pair<int, int>;
 
using std::vector;
using std::priority_queue;
 
vector<pii> ve;
vector<int> ve2;
priority_queue<int, vector<int>, std::greater<int> > pq;
 
int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		ve.push_back(pii(t1, t2));
	}
 
	sort(ve.begin(), ve.end());
 
	int cou = 0;
	for (int i = 0; i < N; i++) {
		pq.push(ve[i].second);
		if (ve[i].first <= cou) {
			ve2.push_back(pq.top());
			pq.pop();
		}
		else {
			cou++;
		}
	}
 
	sort(ve2.begin(), ve2.end(), std::greater<int>());
 
	int cou2 = cou;
	cou = 0;
	int ans = 0;
	for (int i = 0; i < ve2.size(); i++) {
		if (M - cou == cou2) {
			ans++;
		}
		else if (M + 1 - ve2[i] <= cou) {
			ans++;
		}
		else {
			cou++;
		}
	}
 
	printf("%d", ans);
 
	return 0;
}

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

int main() {
  ll n, w;
  cin >> n >> w;
  vl c(n), v(n);
  rep(i, n) cin >> c[i] >> v[i];
  ll dp[500][101] = {};
  rep(j, 500) rep(k, 101) dp[j][k] = -1;
  dp[0][0] = 0;
  rep(i, n) for(int j = 400; j >= 0; j--) for(int k = 100; k >= 0; k--) {
    if(dp[j][k] == -1) continue;
    ll nj = j + c[i] - c[0];
    dp[nj][k + 1] = max(dp[nj][k + 1], dp[j][k] + v[i]);
  }
  ll ans = 0;
  rep(j, 410) rep(k, 101) if(j + k * c[0] <= w) ans = max(ans, dp[j][k]);
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex<double> point;
int n,ans;
vector <point> xy;
bool used[5001][5001];

void check(point a,point b){
  point d=b-a;
  point e=point(0,abs(d)),f=point(abs(d),abs(d));
  e=e*d/abs(d)+a;
  f=f*d/abs(d)+a;
  complex <int> E=e,F=f;
  e-=E,f-=F;
  if(E.x<0||E.y<0||F.x<0||F.y<0||5000<E.x||5000<F.x||5000<E.y||5000<F.y)return;
  if(e==point(0,0)&&f==point(0,0)&&used[E.x][E.y]&&used[F.x][F.y])ans=max(ans,(int)(d.x*d.x+d.y*d.y));
}

int main(){
  while(cin>>n,n){
    xy.clear();
    memset(used,0,sizeof(used));
    for(int i=0,a,b;i<n;i++){
      cin>>a>>b;
      used[a][b]=1;
      xy.push_back(point(a,b));
    }
    ans=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)if(i!=j)check(xy[i],xy[j]);
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 25764
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const long long INF=1e16;
struct node{
	int x,y,z;
}a[100100];
bool cmp(const node &A,const node &B){
	return A.y-A.z>B.y-B.z;
}
long long dp1[100100],dp2[100100];
priority_queue<int,vector<int>,greater<int> > q;
int main(){
//	freopen("C.in","r",stdin);
	int X,Y,Z;
	scanf("%d%d%d",&X,&Y,&Z);
	int n;
	n=X+Y+Z;
	long long ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
		a[i].y-=a[i].x,a[i].z-=a[i].x;
		ans=ans+a[i].x;
	}
	sort(a+1,a+n+1,cmp);
	while(!q.empty()) q.pop();
	long long st=0;
	for(int i=1;i<=n;i++)
	{
		q.push(a[i].y);
		st=st+a[i].y;
		if(i>Y){
			st=st-q.top();
			q.pop();
		}
		dp1[i]=st;
	}
	while(!q.empty()) q.pop();
	st=0;
	for(int i=n;i>=1;i--)
	{
		q.push(a[i].z);
		st=st+a[i].z;
		if(i+Z<=n){
			st=st-q.top();
			q.pop();
		}
		dp2[i]=st;
	}
	long long sum=-INF;
	for(int i=(Y>=1?Y:1);i+Z<=n&&i<=n-1;i++)
	{
		if(dp1[i]+dp2[i+1]>sum)
			sum=dp1[i]+dp2[i+1];
	}
	printf("%lld\n",ans+sum);
	return 0;
}


Measured memory_bytes: 3448
#include <algorithm>
#include <iostream>
#include <cstdint>

int main() {
  std::int64_t N;
  std::cin >> N;
  std::int64_t sum = 0;
  for (std::int64_t i = 1; i <= N; ++i) {
    sum += i * (i + 1) / 2;
  }
  for (int i = 0; i < N - 1; ++i) {
    std::int64_t u, v;
    std::cin >> u >> v;
    const auto [left, right] = std::minmax(u, v);
    sum -= left * (N - right + 1);
  }
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3648
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,p,s,a[100005];
queue<LL>Q;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>k;
	for(i=0;i++<9;)Q.push(i);
	for(;k--;)
	{
		s=Q.front();
		p=s%10;
		if(p)Q.push(s*10+p-1);
		Q.push(s*10+p);
		if(p<9)Q.push(s*10+p+1);
		Q.pop();
	}
	cout<<s;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
signed main(){
        int a;
        while( scanf("%lld", &a) != EOF ){
                if(a==0) break;
                vector<vector<int>> m(a+1,vector<int>(a+1,0));
                for(int i=0;i<a;i++){
                        int s = 0;
                        for(int j=0;j<a;j++){
                                int b;
                                scanf("%lld", &b);
                                m[i][j] = b;
                                s += b;
                        }
                        m[i][a] = s;
                }
                for(int j=0;j<a+1;j++){
                        int s = 0;
                        for(int i=0;i<a;i++){
                                s += m[i][j];
                        }
                        m[a][j] = s;
                }
                for(int i=0;i<a+1;i++){
                        for(int j=0;j<a+1;j++){
                                printf("%5lld", m[i][j]);
                        }
                        printf("\n");
                }
        }
        return 0;
}

Measured memory_bytes: 3160
[h,w]=[int(i) for i in input().split()]

li=[]
for i in range(h):
    li.append(list(input()))

p=[]
count=0
for j, i in enumerate(li):
    if "#" not in i:
        p.append(j)
        h-=1
for i in p:
    temp=i-count
    del li[temp]
    count+=1


tli=[]
for i in range(w):
    temp=[]
    for j in li:
        temp.append(j[i])
    tli.append(temp)

count=0
p=[]
for k, i in enumerate(tli):
    if "#" not in i:
        p.append(k)
        w-=1
for i in p:
    temp=i-count
    del tli[temp]
    count+=1

for i in range(h):
    for j in range(w):
        print(tli[j][i], end="")
    print()


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string S;
	cin >>S;
	string A="AKIHABARA";
	int is=0;
	int ia=0;
	bool R=false;
	while (is<S.size()) {
		if (ia==A.size()) {
			cout <<"NO" <<endl;
			return 0;
		}
		if (S.at(is)==A.at(ia)) {
			if ('R'==S.at(is))
				R=true;
			is++;
			ia++;
		} else if (A.at(ia)=='A') {
			ia++;
		} else {
			cout <<"NO" <<endl;
			return 0;
		}
	}
	if (R)
		cout <<"YES" <<endl;
	else
		cout <<"NO" <<endl;
	return 0;
}



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

using namespace std;
typedef long long LL;

int main(){
	int N;
	cin >> N;
	int A[1010];
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<N; i++){
		if(A[i]%2==0){
			if(A[i]%3!=0&&A[i]%5!=0){
				cout << "DENIED" << endl;
				break;
			}
		}
		if(i==N-1) cout << "APPROVED" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  int flag;
  while(1){
    C=C-B;
    if(C<=0){
      flag=0;
      break;
    }
    A=A-D;
    if(A<=0){
      flag=1;
      break;
    }
  }
  if(flag==0)
    printf("Yes");
  else if(flag==1)
    printf("No");
  return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define N 200010
using namespace std;

int n,a[N],n1,n2;
map <int,int> M;
pair<int,int> p1[N],p2[N];
int main()
{
	scanf("%d",&n);
	n1=(n+1)/2;
	n2=n/2;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int Ans=0;
	for(int i=1;i<=n;i+=2)
		M[a[i]]++;
	for(int i=1;i<=n;i+=2)
		p1[(i+1)/2]=make_pair(M[a[i]],a[i]);
	M.clear();
	for(int i=2;i<=n;i+=2)
		M[a[i]]++;
	for(int i=2;i<=n;i+=2)
		p2[i/2]=make_pair(M[a[i]],a[i]);
	sort(p1+1,p1+1+n1); sort(p2+1,p2+1+n2);
	n1=unique(p1+1,p1+1+n1)-p1;
	n2=unique(p2+1,p2+1+n2)-p2;
	p1[n1]=make_pair(0,0);
	p2[n2]=make_pair(0,0);
	n1--; n2--;
	if(p1[n1].second!=p2[n2].second)
		Ans=n-p1[n1].first-p2[n2].first;
	else 
		Ans=n-max(p1[n1-1].first+p2[n2].first,p1[n1].first+p2[n2-1].first);
	cout << Ans << endl;

	return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int N, M, Q;
// 先にアクセスできるようにする Aは数列用
vector<int> A(11, 0), a(50), b(50), c(50), d(50);

int ans = 0;

void dfs(int n) {
    // 先に数列が完成した時の処理をかく
    if (n == N) {
        int sum = 0;
        rep(i, Q) {
            if (A[b[i]] - A[a[i]] == c[i])
                sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }
    for (int i = min(A[n], M); i <= M; i++) {
        A[n + 1] = i;
        dfs(n + 1);
    }
}

int main() {
    // グローバル変数なので新しく宣言しない。必要な場合はresizeする。
    cin >> N >> M >> Q;
    rep(i, Q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }

    A[0] = 1;
    dfs(0);

    cout << ans << endl;
}

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

int main(){
    vector<int> ABCDE(5);
    for(int i=0;i<5;i++){
        cin >> ABCDE[i];
    }
    int min = 10;
    for(int i=0;i<5;i++){
        if(ABCDE[i]%10 != 0 && ABCDE[i]%10 < min){
            min = ABCDE[i]%10;
        }
    }
    int ans = 0;
    for(int i=0;i<5;i++){
        if(ABCDE[i]%10 != 0){
            ans += ABCDE[i]+10-ABCDE[i]%10;
        }else{
            ans += ABCDE[i];
        }
    }
    cout << ans-(10-min) << endl;
}


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

#define ll long long

using namespace std; 

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = n / 2, j = i + 1, k = 1; k <= m; k++, i--, j++) {
        if (n % 2 == 0 && (j - i == n / 2 || j - i == n / 2 + 1)) j++;
        cout << i << ' ' << j << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr ll MOD = 1e9 + 7;
int last[300000], c[300000];
ll dp[300000];
int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    cin >> c[i];
  }
  dp[0] = 1;
  for (int i = 1; i <= n; ++i)
  {
    dp[i] = dp[i - 1];
    if (last[c[i - 1]] != 0)
    {
      if (last[c[i - 1]] != i - 1)
      {
        dp[i] += dp[last[c[i - 1]]];
      }
      //cout << 10 << endl;
    }
    dp[i] %= MOD;
    last[c[i - 1]] = i;
    //cout << dp[i] << endl;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int h[200001];
long long t[600001];
long long query(int index,int lb,int rb,int lq,int rq)
{
	if((lb==lq&&rb==rq)||lb==rb)
		return t[index];
	int mid=(lb+rb)/2;
	if(rq<=mid)
		return query(index*2,lb,mid,lq,rq);
	else if(lq>mid)
		return query(index*2+1,mid+1,rb,lq,rq);
	else
		return max(query(index*2,lb,mid,lq,mid),query(index*2+1,mid+1,rb,mid+1,rq));
}
long long  update(int index,int lb,int rb,int id,long long value)
{
	if(lb==rb&&lb==id)
		return t[index]=max(t[index],value);
	int mid=(lb+rb)/2;
	if(id<=mid)
		return t[index]=max(t[index],update(index*2,lb,mid,id,value));
	else
		return t[index]=max(t[index],update(index*2+1,mid+1,rb,id,value));
}
int main()
{
	int n,i;
	long long tmp;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&tmp);
		update(1,1,n,h[i],query(1,1,n,1,h[i]-1)+tmp);
	}
	printf("%lld",t[1]);
	return 0;
}

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

#define int long long

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

	int all = a + b;
	int ans = a * (n/all); 
	n -= (n/all)*all;

	ans += min(a, n); 

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N,M,X=map(int,input().split())
B=[list(map(int,input().split())) for i in range(N)]
ANS=1<<60
for i in range(1<<N):
    SCORE=[0]*M
    MONEY=0
    for j in range(N):
        if (1<<j) & i != 0:
            MONEY+=B[j][0]
            for k in range(M):
                SCORE[k]+=B[j][k+1]
    if min(SCORE)>=X:
        ANS=min(ANS,MONEY)
if ANS==1<<60:
    print(-1)
else:
    print(ANS)

Measured memory_bytes: 9220
n, k = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]


last = 0
for i in range(k):
    last += arr[i]

for i in range(k, len(arr)):
    curr = (last + arr[i]) - arr[i-k]
    if curr>last:
        print('Yes')
    else:
        print('No')
    last= curr
    
    


Measured memory_bytes: 105460
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <limits.h>
#include <string.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

typedef long long int lld;

#define F first
#define S second

#define ERR 1e-9

int main(){
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

   int N, M, X, Y, maxX = -200, minY = 200, tmp;

   cin >> N >> M >> X >> Y;

   while(N--){ cin >> tmp; maxX = max(maxX, tmp); }
   while(M--){ cin >> tmp; minY = min(minY, tmp); }

   maxX = max(maxX, X);
   minY = min(minY, Y);

   if(maxX < minY)cout << "No War";
   else cout << "War";

   return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
tmps = [[] for _ in range(n)]
pyxs = []

for i in range(m):
    p, y = list(map(int, input().split()))
    pyxs.append([p, y, i])

pyxs.sort(key = lambda x: x[1])

num = [0] * (n+1)
ans = [None]*m

for p, y, x in pyxs:
    ans[x] = '{:06}'.format(p) + '{:06}'.format(num[p]+1)
    num[p] += 1

for s in ans:
    print(s)

Measured memory_bytes: 39620
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int result = g * 2 - r;
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 22868
#include <iostream>
using namespace std;
typedef long long ll;
ll k, a, b;
int main(void){
    // Your code here!
    cin >> k >> a >> b;
    if (b > a + 2 && k > a){
        cout << a + (b - a) * ((k - a + 1) / 2) + ((k - a + 1) % 2) << endl;
    } else {
        cout << 1 + k << endl;
    }
}


Measured memory_bytes: 256
import Control.Applicative
import Data.List

strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    [b, c] <- map read . words <$> getLine
    -- スペース区切り整数の入力
    l <- map strToInt . words <$> getLine
    let l' = map length $ group $ sort l
    let l'' = sort l'
    -- 出力
    putStrLn $ show . sum $ take (length l'' - c) l''


Measured memory_bytes: 63868
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            //??°?????????
            while (true)
            {
                //????????¨??????????????????
                string[] s = Console.ReadLine().Split(' ');
                //????????¨????????´??°?????????
                int h = int.Parse(s[0]);
                int w = int.Parse(s[1]);
                //????????¨????????¨???????????????????????????
                if (h == 0 && w == 0)
                    break;

                int row;//???
                int col;//???

                //???????????°?????????????????????
                for (row = 0; row < h; row++)
                {
                    //????????°?????????????????????
                    for (col = 0; col < w; col++)
                    {
                        //????\???°??????????\???°????????????????????¶??°???????????¶??°????????????????????????????????????
                        if ((row % 2 == 0 && col % 2 == 00) || (row % 2 == 1 && col % 2 == 1))
                        {
                            Console.Write("#");
                        }
                        else
                        { Console.Write("."); }

                    }

                    Console.Write("\n");
                }
                Console.Write("\n");

            }

        }
    }
}

Measured memory_bytes: 15448
// Alapan
// IIITH

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

// data types
#define ll long long int
#define ld long double

//funtion macros


// stl
#define lp(var,start,end) for (ll var = start; var <=end ; ++var)
#define ilp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))

#define mod 1000000007

// utility functions
ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

ll min(ll a, ll b){
	if(a<b)return a;
    return b;
}

ll power(ll x, ll y, ll m=mod){
	if(y<0){
		x = power(x,m-2);
		y = -y;
	}
	ll ans=1;
	x = x % m;
	while(y){
		if(y&1) ans = (ans*x)%m;
		y=y/2;
		x=(x*x)%m;
	}
	return ans;
}

ll factorial(ll n, ll m=mod){
    ll ans = 1;
	ll i = 1;
    while(i<=n){
        ans = (ans*i)%m;
        i++;
    }
    return ans;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll dp[n+1];
    for(ll i=1;i<=n;i++){
        if(i<3) dp[i]=0;
        else{
            dp[i]=1;
            for(ll j=3;i-j>=3;j++){
                dp[i]=(dp[i]+dp[i-j])%mod;
            }
        }
    }
    // for(ll i=1;i<=10;i++) cout << dp[i] << " "; cout << "\n";
    cout << dp[n] << "\n";
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int check(string s)
{
	for(int i=0; i<s.size()/2; i++)
		if(s[i]!=s[s.size()-i-1]) return 0;
	return 1;
}
inline void solve()
{
	string s;
	cin>>s;
	int len = s.size();
	string a = s.substr(0,len/2);
	string b = s.substr(len/2+1,len/2);
//	cout<<s<<endl<<a<<endl<<b<<endl;
	if(check(s) && check(a) && check(b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main()
{
	IOS();
	solve();
	return 0;
}




Measured memory_bytes: 888