akhauriyash/Code-Regression huggingface dataset:
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		cout << n + n*n + n*n*n;
	}
}



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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    v_string s(3);

    irep(i, 3) {
        cin >> s[i];
    }

    irep(i, 3) {
        cout << s[i][0];
    }
    
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

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

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

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

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

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

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

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

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

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        mut N: usize,
        K: usize,
    }
    let mut ans = 0;
    while N != 0 {
        N /= K;
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<limits.h>

#define SIZE 100000

void quicksort(int, int);
int partition(int, int);
void merge(int, int, int);
void mergesort(int, int);

struct Card
{
  char suit;
  int num;
};

struct Card A[SIZE], B[SIZE];
  
int main()
{
  int i, n, num, s = 0;
  char suit;

  scanf("%d",&n);
  for(i = 0; i < n; i++)
    {
      scanf(" %c %d",&suit,&num);
      A[i].suit = B[i].suit = suit;
      A[i].num = B[i].num = num;
    }

  quicksort(0, n-1);
  mergesort(0, n);

  for(i = 0; i < n; i++)
    {
      if(A[i].suit != B[i].suit)s = 1;
    }

  if(s == 0)printf("Stable\n");
  else printf("Not stable\n");
  
  for(i = 0; i < n; i++)
    {
      printf("%c %d\n",A[i].suit,A[i].num);
    }

  return 0;
}

void quicksort(int p, int r)
{
  int q;
  
  if(p < r)
    {
      q = partition(p, r);
      quicksort(p, q-1);
       quicksort(q+1, r);
    }
}

int partition(int p, int r)
{
  int x, i, j;
  struct Card temp;
  
  x = A[r].num;
  i = p-1;
  
  for(j = p; j < r; j++)
    {
      if(A[j].num <= x)
	{
	  i++;
	  temp = A[i];
	  A[i] = A[j];
	  A[j] = temp;
	}
    }
  
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  
  return i+1;
}

void merge(int left, int mid, int right)
{
  int i, j, k, n1, n2;
  struct Card L[SIZE/2+2], R[SIZE/2+2];

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++)
    {
      L[i] = B[left + i];
    }

  for(i = 0; i < n2; i++)
    {
      R[i] = B[mid + i];
    }

  L[n1].num = INT_MAX;
  R[n2].num = INT_MAX;

  i = 0;
  j = 0;

  for(k = left; k < right; k++)
    {
      if(L[i].num <= R[j].num)
	{
	  B[k] = L[i];
	  i++;
	}
      else
	{
	  B[k] = R[j];
	  j++;
	}
    }
}

void mergesort(int left, int right)
{
  int mid;
  
  if(left+1 < right)
    {
      mid = (left + right)/2;
      mergesort(left, mid);
      mergesort(mid, right);
      merge(left, mid, right);
    }
}



Measured memory_bytes: 4036
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector <int> v[100005];

int dfs(int node, int par, int d) {
	if (v[node].size()==1 and par) {
		return 0;
	}
	int sol = 0;
	for (int i=0 ; i<v[node].size() ; i++) {
		if (v[node][i] == par) continue ;
		sol ^= dfs(v[node][i], node, d+1)+1;
	}
	return sol;
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<n-1 ; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	if (dfs(1, 0, 0)) printf("Alice\n");
	else printf("Bob\n");
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (auto &e : b) cin >> e;
  int r = b.front() + b.back();
  for (int i = 0; i + 1 < n - 1; i++) r += min(b[i], b[i + 1]);
  cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[111], n, i, t=0, x;
	cin >> n;
	for (i=1; i<=100; i++) a[i]=0;
	for (i=1; i<=n; i++)
	{
		cin >> x;
		a[x]=1;
	}
	for (i=1; i<=100; i++) t+=a[i];
	cout << t << endl;
	return 0; 
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int n; cin >> n;
    vector<ll> s(n);
    rep(i, n) cin >> s[i];

    ll res = 0;
    int q; cin >> q;
    rep(i, q){
        int a; cin >> a;
        // res += distance(lower_bound(all(s), a), upper_bound(all(s), a));
        if(lower_bound(all(s), a) != upper_bound(all(s), a)) res++;
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}



Measured memory_bytes: 7708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.nextLine());
		int b = Integer.parseInt(sc.nextLine());
		int c = Integer.parseInt(sc.nextLine());
		int x = Integer.parseInt(sc.nextLine());

		int ans = 0;
		int tmp = 0;
		int tmp2 = 0;
		for (int i = 0; i <= a; i++) {
			if (500 * i <= x) {
				tmp = x - 500 * i;
			} else {
				break;
			}

			for (int j = 0; j <= b; j++) {
				if (100 * j <= tmp) {
					tmp2 = tmp - 100 * j;
				} else {
					break;
				}

				if (tmp2 / 50 <= c) {
					ans++;
				}

			}

			if (500 * i >= x) {
				break;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

long long n, a, x, u;
 
int main(){
    unordered_map<long long, long long> m;
    vector< pair<long long, long long> > v;

    cin >> n;

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

    unordered_map<long long, long long>:: iterator it = m.begin();

    for(int i = 0; i < m.size(); i++){
        if((*it).second > 1){
            v.push_back(make_pair((*it).first, (*it).second));
        }
        it++;
    }

    if(v.empty()){
        cout << 0;
    } else{
        sort(v.rbegin(), v.rend());

        if(v[0].second > 3){
            cout << v[0].first * v[0].first;
        } else{
            cout << v[0].first * v[1].first;
        }
    }



}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

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

using namespace std;
using ll = long long;

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream &operator>>(istream &is, __int128_t &a){
    string s;
    is>>s;
    a = parse(s);
    return (is);
}
using Int = __int128_t;


int main()
{
    int n;
    cin >> n;
    vector<Int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    if(count(a.begin(), a.end(), Int(0))) {
        cout << 0 << endl;
        return 0;
    }
    Int t = 1;
    for(int i = 0; i < n; i++) {
        if(t * a[i] > Int(1000000000000000000)) {
            cout << -1 << endl;
            return 0;
        }
        t *= a[i];
    }
    cout << t << endl;
}


Measured memory_bytes: 4752
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int a,b;
int main(){
	cin>>a>>b;
	cout<<6-a-b;
	return 0;
}


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

using namespace std;
using ll = long long;

int main(void){
	int a = 0;
	int ans = 0;
	cin >> a;
	ans = a + a*a + a*a*a;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int pfs[maxn];
int pft[maxn];
signed main() {
    string s,t;
    cin>>s>>t;
    pfs[0]=0;
    for(int i=0 ; i<=s.length() ; i++) {
        if(s[i]=='A') pfs[i+1]=pfs[i]+1;
        else pfs[i+1]=pfs[i]+2;
        //cout<<"pfs "<<i<<" = "<<pfs[i]<<endl;
    }
    pft[0]=0;
    for(int i=0 ; i<=t.length() ; i++) {
        if(t[i]=='A') pft[i+1]=pft[i]+1;
        else pft[i+1]=pft[i]+2;
        //cout<<"pft "<<i<<" = "<<pft[i]<<endl;
    }
    int q;
    cin>>q;
    while(q--) {
        int a1,b1,a2,b2;
        cin>>a1>>b1>>a2>>b2;
        int s1=pfs[b1]-pfs[a1-1];
        int s2=pft[b2]-pft[a2-1];
        //cout<<s1<<" "<<s2<<endl;
        if(s1%3==s2%3) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

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

const int MOD = 1e9+7;

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

	string s, t; cin >> s >> t;
	if(s == t.substr(0, s.size()))
		cout << "Yes\n";
	else
		cout <<"No\n";
 	return 0;
}

Measured memory_bytes: 3648
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,M=map(int,input().split())
ans=((g1[M]*g2[M-N]%mod)**2)%mod
#print(ans)
for i in range(1,N+1):
    ans+=(-1)**i*cmb(N,i,mod)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2)
    #print((-1)**i*cmb(N,i,mod)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2))
    ans%=mod

print(ans)


Measured memory_bytes: 162716
#include <iostream>
#include <vector>
#include <deque>
#include <climits>

typedef long long ll;

using namespace std;

ll Dx[] = {1, -1, 0, 0};
ll Dy[] = {0, 0, 1, -1};

int main() {
    ll H, W;
    cin >> H >> W;
    ll Ch, Cw;
    cin >> Ch >> Cw;
    ll Dh, Dw;
    cin >> Dh >> Dw;
    --Ch; --Cw; --Dh; --Dw;

    vector<vector<char>> S(H, vector<char>(W));
    for (ll h = 0; h < H; ++h) {
        string s;
        cin >> s;
        for (ll w = 0; w < W; ++w) {
            S[h][w] = s.at(w);
        }
    }

    vector<vector<ll>> cost(H, vector<ll>(W, LLONG_MAX));
    deque<pair<ll, ll>> q;
    q.push_front({Ch, Cw});
    cost[Ch][Cw] = 0;
    while (! q.empty()) {
        pair<ll, ll> m = q.front();
        q.pop_front();

        for (int i = 0; i < 4; ++i) {
            ll x = m.second + Dx[i];
            ll y = m.first + Dy[i];
            if (0 <= x && x < W && 0 <= y && y < H && S[y][x] == '.' && cost[m.first][m.second] != cost[y][x]) {
                q.push_front({y, x});
                cost[y][x] = cost[m.first][m.second];
            }
        }

        for (int _x = -2; _x <= 2; ++_x) {
            for (int _y = -2; _y <= 2; ++_y) {
                ll x = m.second + _x;
                ll y = m.first + _y;
                if (0 <= x && x < W && 0 <= y && y < H && S[y][x] == '.') {
                    if (cost[m.first][m.second] + 1 < cost[y][x]) {
                        q.push_back({y, x});
                        cost[y][x] = cost[m.first][m.second] + 1;
                    }
                }
            }
        }
    }

    cout << (cost[Dh][Dw] == LLONG_MAX ? -1 : cost[Dh][Dw]) << endl;

    return 0;
}

Measured memory_bytes: 12680
#include<iostream>
#include<cmath>
#include<math.h>
#include<algorithm>
using namespace std;
double sq(double a, double b) {
	double c;
	c = sqrt(a*a+b*b);
	return c;
}
int main() {
	int n,d;
	cin >> n >> d;
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		double x, y;
		cin >> x >> y;
		double a;
		a = sq(x, y);
		if (d >= a)cnt++;
	}
	cout << cnt << endl;
	return 0;

}


Measured memory_bytes: 3804
import sys; readline = sys.stdin.readline
from collections import deque

H, W, K = map(int, readline().split())
S = [readline().rstrip() for i in range(H)]


se = [0 for i in range(H)]
for y in range(H):
    se[y] = S[y].count('#') > 0

ans = [list(range(W)) for i in range(H)]

firstY = se.index(True)
k = 0
for y in range(firstY, H):
    if se[y]:
        k += 1
        _k = k - 1
        for x in range(W):
            if S[y][x] == '#':
                _k += 1
            ans[y][x] = max(k, _k)
        k = _k
    else:
        for x in range(W):
            ans[y][x] = ans[y - 1][x]

for y in range(firstY - 1, -1, -1):
    for x in range(W):
        ans[y][x] = ans[y + 1][x]

for low in ans:
    print(*low)


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef unordered_map<ll, ll> ump;

const ll mod = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<vector<ll>> c(3, vector<ll>(3));
	REP(i, 3){
		REP(j, 3){
			cin >> c[i][j];
		}
	}
	ll ans = true;
	ll b2_b1 = c[0][1]-c[0][0];
	ll b3_b2 = c[0][2]-c[0][1];
	FOR(i, 1, 3){
		if ((c[i][1]-c[i][0] != b2_b1) || (c[i][2]-c[i][1] != b3_b2)){
			cout << "No" << endl; return 0;
		}
	}
	ll a2_a1 = c[1][0]-c[0][0];
	ll a3_a2 = c[2][0]-c[1][0];
	FOR(j, 1, 3){
		if ((c[1][j]-c[0][j] != a2_a1) || (c[2][j]-c[1][j] != a3_a2)){
			cout << "No" << endl; return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    string S;
    cin >> S;
    int zero = 0;
    int one = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '0') {
            zero++;
        } else {
            one++;
        }
    }

    cout << S.size() - abs(zero - one) << endl;
}


Measured memory_bytes: 512
import java.io.*;
class Main
{
    public static void main(String args[]) throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        int ans=n-(n/1000)*1000;
        if(ans!=0) ans=1000-ans;
        System.out.print(ans);
    }
}

Measured memory_bytes: 32568
n = int(input())
ans = 0
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

t = num_divisors_table(n)
for i in range(1,n+1):
  ans += t[i]*i

print(ans)

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

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ok = false;
    for (int d = 0; d < 100; d++) {
        for (int c = 0; c < 100; c++) {
            if (d*4 + c*7 == n) {
                ok = true;
            }
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int main(){
  int n, k, dp[100010], a[100010];
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> a[i];
    dp[i]=1000000010;
  }
  dp[0]=0;
  for(int i=1;i<n;i++){
    for(int j=1;j<=i&&j<=k;j++){
      dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
    }
  }

  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N, W;
    cin >> N >> W;
    vector<ll> wis;
    vector<ll> vis;
    for (ll i = 0; i < N; i++) {
        ll wi, vi;
        cin >> wi >> vi;
        wis.push_back(wi);
        vis.push_back(vi);
    }
    const ll value_sum_max = 100000;
    auto dp = make_vec_nd(numeric_limits<ll>::max()/2, N+1, value_sum_max + 1);
    dp[0][0] = 0;
    for (ll n = 0; n <= N-1; n++) {
        for (ll v = 0; v <= value_sum_max; v++) {
            dp[n+1][v] = min(dp[n+1][v], dp[n][v]);
            if (v+vis[n] <= value_sum_max) {
                dp[n+1][v+vis[n]] = min(dp[n+1][v+vis[n]], dp[n][v]+wis[n]);
            }
        }
    }
    for (ll v = value_sum_max; v >= 0; v--) {
        if (dp[N][v] <= W) {
            cout << v << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 80256
import java.util.*;

class Main{
    public static void main(String[] args){
	
	int much,num;
	Scanner s = new Scanner(System.in);
	
	while( s.hasNextInt() ){
	    
	    much=0;
	    num=s.nextInt();
	    
	    for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
		    for(int k=0;k<10;k++){
			for(int l=0;l<10;l++){
			    if( num==i+j+k+l ){
				much++;
			    }
			}
		    }
		}
	    }
	    
	    System.out.println( much );
	    
	}
	
    }
}

Measured memory_bytes: 18848
#include <iostream>

using namespace std;

int n, maxim, r, sum, a[101];

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxim = max (maxim, a[i]);
  }
  r = 2000000;
  for (int i = 1; i <= maxim; i++) {
    sum = 0;
    for (int j = 1; j <= n; j++)
      sum += (a[j] - i) * (a[j] - i);
    r = min (r, sum);
  }
  cout << r;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;


int main() {
  for (int n, m; cin >> n >> m, (n | m) != 0; ) {
    int taro[100], hanako[100];
    int t_sum = 0, h_sum = 0;
    rep(i, n) {
      cin >> taro[i];
      t_sum += taro[i];
    }
    rep(i, m) {
      cin >> hanako[i];
      h_sum += hanako[i];
    }

    int ans_t, ans_h;
    int min = INF;
    rep(i, n) rep(j, m) {
      int t = t_sum - taro[i] + hanako[j];
      int h = h_sum - hanako[j] + taro[i];

      if (t == h && min > taro[i] + hanako[j]) {
        min = taro[i] + hanako[j];
        ans_t = taro[i];
        ans_h = hanako[j];
      }
    }

    if (min == INF) cout << -1 << endl;
    else cout << ans_t << ' ' << ans_h << endl;
  }
  
  
  return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K % 2 == 1) {
    int cnt = N / K;
    ans += (ll)cnt * cnt * cnt;
  } else {
    int cnt = N / K;
    ans += (ll)cnt * cnt * cnt;
    int cnt2 = (N + K / 2) / K;
    ans += (ll)cnt2 * cnt2 * cnt2;
    dump(cnt, cnt2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val mod = 1000000007L
    val S = readString()
    var ans = ""
    for (c in S) {
        ans += when (c) {
            '1' -> '9'
            '9' -> '1'
            else -> ""
        }
    }
    println(ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt).toList()
fun readLongList() = readLine()!!.split(" ").map(String::toInt).toList()


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

string fuck(vector<pair<int,int>>&xs) {
  int i0 = INF;
  int j0 = INF;
  int i1 = -INF;
  int j1 = -INF;
  bool zero = false;

  rep (k, 4) {
    int i = car(xs[k]);
    int j = cdr(xs[k]);
    i0 = min(i0, i);
    j0 = min(j0, j);
    i1 = max(i1, i);
    j1 = max(j1, j);
    if (!i && !j) zero = true;
  }

  if (i1 == 3) return "B";
  if (j1 == 3) return "C";
  if (i1 == 1 && j1 == 1) return "A";

  if (i1 == 2) {
    if (zero) return "F";
    return "D";
  }

  if (zero) return "E";
  return "G";
}

int main() {

  loop {
    string ln[8];
    rep (i, 8) cin >> ln[i];
    if (!cin) break;

    vector<pair<int,int>> xs;
    int mi = INF;
    int mj = INF;
    rep (i, 8) {
      rep (j, 8) {
        if (ln[i][j] == '1') {
          xs.push_back(cons(i, j));
          mi = min(mi, i);
          mj = min(mj, j);
        }
      }
    }

    rep (i, 4) {
      xs[i] = cons(car(xs[i]) - mi, cdr(xs[i]) - mj);
    }

    cout << fuck(xs) << endl;

  }

  return 0;
}

Measured memory_bytes: 1184
import math
import sys
n = int(input())

if n == 1:
    print(1)
    sys.exit()

yakusu = []

sq = math.ceil(math.sqrt(n))
for i in range(1, sq + 1):
    if n % i == 0:
        yakusu.append(i)
        yakusu.append(n // i)

yakusu.sort()
for i in range(len(yakusu) // 2 + 1):
    if len(yakusu) - i * 2 <= 1:
        if len(yakusu) - i * 2 == 0:
            ans = yakusu[len(yakusu) - i]
        else:
            ans = yakusu[i]
        for j in range(1, 11):
            if ans // 10 == 0:
                print(j)
                break
            ans //= 10
        sys.exit(0)

Measured memory_bytes: 3316
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    ll h,w;
    cin>>h>>w;
    string str[h];
    ll chk[h][w];
    deque<pair<ll,ll>> q;
    rep(i,h) cin>>str[i];
    rep(i,h){
        rep(j,w){
            chk[i][j]=0;
            if(str[i][j]=='#'){
                chk[i][j]=1;
                q.push_back(make_pair(i,j));
            }
        }
    }
    //sum++;
    q.push_back(make_pair(-100,-100));
    while(q.size()!=1){
        pair<ll,ll> p=q.front();
        q.pop_front();
        if(p.first==-100){
            q.push_back(make_pair(-100,-100));
            sum++;
        }else{
            rep(i,4){
                if(p.first+dy[i]<0||p.second+dx[i]<0||p.first+dy[i]>h-1||p.second+dx[i]>w-1) continue;
                //cout<<p.first+dy[i]<<" "<<p.second+dx[i]<<endl;

                if(chk[p.first+dy[i]][p.second+dx[i]]==0){
                    q.push_back(make_pair(p.first+dy[i],p.second+dx[i]));
                    chk[p.first+dy[i]][p.second+dx[i]]=1;
                }
            }
        }
        //cout<<"loop";
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 28412
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rng(i,a,b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define repd(i, n) for(ll i = (ll)(n)-1;i>=0;--i)
#define rngd(i,b,a) for(ll i = (ll)(b);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define ctoi(x) ((x)-'0')

int main() {
  int n,x;
  int ans=0;
  while(cin>>n>>x){
    if(n==0&&x==0){
      break;
    }
    rng(i,1,n+1){
      rng(j,i+1,n+1){
        rng(k,j+1,n+1){
          if(i+j+k==x){
            ans++;
          }
        }
      }
    }
    cout<<ans<<endl;
    ans=0;
  }
  return 0;
}


Measured memory_bytes: 3076
# -*- coding: utf-8 -*-
"""
Created on Wed May 29 22:59:58 2019

@author: Yamazaki Kenichi
"""

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

ans = 0
for pickup_n in range(min(K, N)+1):
    for start in range(pickup_n + 1):
        tmp = [0]
        for i in range(pickup_n):
            tmp.append(V[i - start])
        tmp.sort()
        for i in range(K - pickup_n):
            if tmp[i] < 0:
                tmp[i] = 0
            else:
                break
        ans = max(ans,sum(tmp))
print(ans)



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

ll d[101][101][101];
ll H[101][101];
ll ref[101];
bool cnt[101][101];

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

	ll N;

	cin >> N;

	vector<ll> x(N), y(N), h(N);
	rep(i, N) {
		cin >> x[i] >> y[i] >> h[i];
	}

	ll cx, cy;
	rep(i, 101) {
		rep(j, 101) {
			rep(n, N) {
				d[n][i][j] = abs(x[n] - i) + abs(y[n] - j);
				if (h[n] >= 1) {
					H[i][j] = h[n] + d[n][i][j];
				}
			}
		}
	}

	bool is_correct = false;
	rep(i, 101) {
		rep(j, 101) {
			is_correct = true;
			rep(n, N) {
				if (h[n] != max(H[i][j] - d[n][i][j], 0LL)) {
					is_correct = false;
					break;
				}
			}
			if (is_correct) {
				cout << i << " " << j << " " << H[i][j] << "\n";
				return 0;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 8320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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 N,D,A,ans=0;
  cin>>N>>D>>A;
  D*=2;
  
  ll PLUS[N];
  vector<pair<ll,ll>> X;
  REP(i,N){
    ll x,h;
    cin>>x>>h;
    X.PB(MP(x,(h-1)/A+1));
    PLUS[i]=0;
  }
  SORT(X);
  
  ll cnt=0,now=0;
  queue<pair<ll,ll>> Q;
  REP(i,N){
    if(i>0){
      while(!Q.empty() && Q.front().first+D<X[i].first){
        cnt-=PLUS[now];
        now++;
        Q.pop();
      }
    }
    Q.push(MP(X[i].first,X[i].second));
    PLUS[i]=max(X[i].second-cnt,0ll);
    ans+=PLUS[i];
    cnt+=PLUS[i];
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 11312
/*
 * @Author: Kaizyn
 * @Date: 2020-03-21 19:58:04
 * @LastEditTime: 2020-03-22 13:28:20
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 1e6+7;
const int MOD = 1e9+7;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

int n;
string a;

inline int C(const int &n, const int &k)
{
    return (n&k) == k;
}

inline void solve()
{
    cin >> n >> a;
    for (int i = 0; i < n; ++i) a[i] -= '1';
    int flag = 0, res = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 1) {
            flag = 1;
            res ^= C(n-1, i);
        }
    }
    if (!flag) {
        for (int i = 0; i < n; ++i) {
            if (a[i] == 2 && C(n-1, i)) res = 2-res;
        }
    }
    cout << res << endl;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& w : a) cin >> w;
  sort(begin(a), end(a));
  int x = a[n - 1];
  int i = lower_bound(begin(a), end(a), x / 2) - a.begin();
  int y;
  if (i == 0)
    y = a[0];
  else
    y = ((x - 2 * a[i - 1]) <= (2 * a[i] - x)) ? a[i - 1] : a[i];

  cout << x << " " << y << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2);
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

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

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

  double sq1 = sqrt(a);
  vec div;
  for(int i=1; i<=sq1; i++){
    if(a%(i)==0){
      div.push_back(i);
      if((a/i)!=i){
        div.push_back(a/i);
      }
    }
  }
  sort(all(div), greater<int>());

  vec ans;
  rep(i,div.size()){
    if(b%div[i]==0){
      ans.push_back(div[i]);
    }
  }

  //prtall(div);
  //prtall(ans);
  prt(ans[k-1]);

}


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


int p[310][310];
int s[310][310];

int calc(int x1,int x2,int y1,int y2){
	return s[y2][x2] + s[y1-1][x1-1] - s[y1-1][x2] - s[y2][x1-1];
}

int main(){
	int N;
	cin >> N;
	for(int i = 1 ; i <= N ; i++){
		for(int j = 1 ; j <= N ; j++){
			cin >> p[i][j], s[i][j] = p[i][j];
		}
	}
	for(int i = 0 ; i <= N ; i++)
		for(int j = 1 ; j <= N ; j++)
			s[i][j] += s[i][j-1];
	for(int i = 1 ; i <= N ; i++)
		for(int j = 0 ; j <= N ; j++)
			s[i][j] += s[i-1][j];
	int ans = -2e9;
	for(int i = 1 ; i <= N ; i++){
		for(int j = i ; j <= N ; j++){
			if( i == j ){
				for(int k = 1 ; k <= N ; k++)
					for(int l = k ; l <= N ; l++)
						ans = max(ans,calc(k,l,i,j));
				continue;
			}else{
				int mn = 0;
				int sum = 0;
				for(int k = 1 ; k <= N ; k++){
					ans = max(ans,sum + calc(k,k,i,j) - mn);
					mn = min(mn,sum-calc(k,k,i+1,j-1));
					sum += p[i][k] + p[j][k];
					//cout << sum + calc(k,k,i,j) - mn << "|" << i << " " << j << " " << k << "(" << sum << " " << mn << " " << calc(k,k,i,j)	 << " " << p[i][k] + p[j][k] << endl;
				}
			}
			
		 
		}
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 1892
#include <bits/stdc++.h>
using namespace std;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
int n;
double p[2999], dp[2999][3000];
bool vis[2999][3000];
double calc(int i, int head) {
	if(i >= n) return (head > n - head) ? 1.0 : 0.0;
	if(vis[i][head]) return dp[i][head];
	double res = 0.0;
	res += calc(i + 1, head + 1) * p[i];
	res += calc(i + 1, head) * (1.0 - p[i]);
	vis[i][head] = 1;
	return dp[i][head] = res;
}
int main() {
	R(n);
	for(int i = 0; i < n; i++) R(p[i]);
	memset(vis, 0, sizeof(vis));
	double ans = calc(0, 0);
	W(ans);
	return 0;
}

Measured memory_bytes: 79616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------head-------
const int N = 1e3 + 7;
const double EPS = 1e-9;
struct Node {
	ll x, y, r;
	Node() {
	}
	Node(ll _x, ll _y, ll _r) {
		x = _x, y = _y, r = _r;
	}
} a[N];
inline ll sqr(ll x) {
	return x * x;
}
ll dis2(const Node &p, const Node &q) {
	return sqr(p.x - q.x) + sqr(p.y - q.y);
}
int n, xs, ys, xt, yt;
bool v[N];
double d[N];
#define mp make_pair
bool bfs() {
	rep(i, 0, n + 1)
		v[i] = false, d[i] = 1e18;
	priority_queue<pair<double, int> > que;
	que.push(mp(0, 0));
	while (!que.empty()) {
		double D = -que.top().first;
		int i = que.top().second;
		que.pop();
		if (v[i])
			continue;
		v[i] = true, d[i] = D;
		rep(j, 0, n + 1) {
			double dij = 0;
			if (sqr(a[i].r + a[j].r) < dis2(a[i], a[j]))
				dij = sqrt(dis2(a[i], a[j])) - a[i].r - a[j].r;
			if (d[j] > D + dij + EPS)
				d[j] = D + dij, que.push(mp(-d[j], j));
		}
	}
}
int main() {
	scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
	scanf("%d", &n);
	rep(i, 1, n + 1) {
		int x, y, r;
		scanf("%d%d%d", &x, &y, &r);
		a[i] = Node(x, y, r);
	}
	a[0] = Node(xs, ys, 0), a[++n] = Node(xt, yt, 0);
	bfs();
	printf("%.12f", d[n]);
	return 0;
}

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

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

using namespace std;

#define F first
#define S second 


#ifdef __debug_leywar
#include <debug/debugger.h>
#else
#define db(...) ;
#endif


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int n , q ;

    cin >> n >> q ; 

    vector<int> ar( n + 1 ) , freq( n + 1 , n + 1 ) , acc( n + 1 ); 

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

    for( int i = n ; i > 0 ; i-- )
    {
        acc[i] = freq[ar[i]] ;
        freq[ar[i]] = i ;
    }

    vector<pair<pair<int, int>, int>> querys( q ) ; 

    int cont = 1 ; 
    for( auto &i : querys ) 
    {
        cin >> i.F.F >> i.F.S ; 
        i.S = cont++ ;
    }

    sort( querys.begin() , querys.end() ,
        []( pair<pair<int, int>, int> a , pair<pair<int, int>, int> b )
        {
            return a.F.F < b.F.F ; 
        }
    ) ;

    vector<int> bit( n + 2 ) ; 

    function<void(int)> add = [&]( int pos ) 
    {
        for( ; pos > 0 ; pos -= ( pos & -pos ) )
            bit[pos]++ ; 
    } ;

    function<int(int)> query = [&]( int pos ) 
    {
        int Qans = 0 ; 
        for( ; pos <= n + 1 ; pos += ( pos & -pos ))
            Qans += bit[pos] ; 
        return Qans ;
    } ;

    vector<int> ans( q ) ; 

    int pos = 0 ; 

    for( int i = 0 ; i < q ; i++ )
    {
        while( ( pos + 1 ) < querys[i].F.F ) 
            add( acc[++pos] ) ; 
        ans[querys[i].S - 1] = -query( querys[i].F.S + 1 ) ; 
    }  

    for( int i = 1 ; i <= n + 1 ; i++ ) 
        bit[i] = 0 ; 
    pos = 0 ; 

    sort( querys.begin() , querys.end() , 
        []( pair<pair<int, int>, int> a , pair<pair<int, int>, int> b ) 
        {
            return a.F.S < b.F.S ;
        }
    ) ;

    for( int i = 0 ; i < q ; i++ ) 
    {
        while( pos < querys[i].F.S ) 
            add( acc[++pos] ) ;
        ans[querys[i].S - 1] += query( querys[i].F.S + 1 ) ; 
    }

    for( auto i : ans ) 
        cout << i << endl ; 

    return 0;
}

Measured memory_bytes: 19384
#include<iostream>
using namespace std;
int main()
{
	int n, x;
	int a, b, c;
	int count;
	while(true)
	{
		count = 0;
		cin >> n >> x;
		if(n == 0 && x == 0)
			break;
		if(x < 6 || 3 * (n - 1) < x)
		{
			cout << count << endl;
			continue;
		}
		a = 1;
		b = 2;
		c = x - 3;
		if (c > n)
		{
			int tmp = c - n;
			b += tmp;
			c = n;
			if (b > c - 1)
			{
				a += b - c + 1;
				b = c - 1;
				if (a <= b - 1)
					count++;
			}
			else
				count++;
		}
		else
			count++;
		if(count != 0)
		{
			while(true)
			{
				b += 1;
				c -= 1;
				if (c > b)
				{
					count++;
				}
				else
				{
					a += 1;
					int tmp = x - (2 * a + 1);
					c = tmp >= n ? n : tmp;
					b = x - c - a;
					if(c > b && b > a)
					{
						count++;
					}
					else
					{
						break;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}


Measured memory_bytes: 3052