akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


signed main(){
  long long N;
  scanf("%lld",&N);
  vector<int> P(N), Q(N);
  REP(x, N) cin >> P.at(x);
  REP(x, N) cin >> Q.at(x);

  int cnt = 0;
  int pi = 0, qi = 0;
  vector<int> v(0);
  FOR1(x, N){ v.push_back(x); }
  do {
    cnt += 1;
    if (v == P) pi = cnt;
    if (v == Q) qi = cnt;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(pi - qi) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n; i64 k; scanf("%d%lld", &n, &k); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	sort(begin(a), end(a));

	i64 zeros = 0;
	std::vector<i64> A, B, C, D;
	for(auto v: a) {
		if(v < 0) {
			A.push_back(v);
			C.push_back(-v);
		} else if(v > 0) {
			B.push_back(v);
			D.push_back(v);
		} else {
			zeros++;
		}
	}
	sort(begin(C), end(C));
	sort(begin(D), end(D));

	// 絶対値が t 以上
	auto cnt = [&](i64 t, std::vector<i64>& A, std::vector<i64>& B) -> i64 {
		if(t <= 0 or A.empty() or B.empty()) return 0;
		
		i64 ret = 0, it = -1;
		for(int i = (int)A.size() - 1; i >= 0; i--) {
			while(it + 1 < B.size() and A[i] * B[it + 1] < t) it++;
			ret += (i64)B.size() - it - 1;
		}
		return ret;
	};

	auto cnt2 = [&](i64 t, std::vector<i64>& A) -> i64 {
		if(t <= 0 or A.size() == 1)  return 0;

		i64 ret = 0, it = -1;
		for(int i = (int)A.size() - 1; i >= 0; i--) {
			while(it + 1 < A.size() and A[i] * A[it + 1] < t) it++;
			ret += (i64)A.size() - it - 1;
			if(it < i) ret--;
		}
		ret /= 2;
		const i64 n = A.size();
		return n * (n - 1) / 2 - ret;
	};

	auto f = [&](i64 t) -> i64 {
		i64 ret = 0;
		if(t < 0) {
			ret += cnt(-t, C, D);
		} else {
			ret += (i64)A.size() * (i64)B.size();
			ret += cnt2(t + 1, C) + cnt2(t + 1, D);
			ret += zeros * (i64)(A.size() + B.size());
			ret += zeros * (zeros - 1) >> 1;
		}
		return ret;
	};

	i64 ok = -(1LL << 60), ng = 1LL << 60;
	while(std::abs(ok - ng) > 1) {
		i64 mid = (ok + ng) >> 1;

		if(f(mid) < k) ok = mid;
		else ng = mid;
	}

	printf("%lld\n", ok + 1);
	return 0;
}



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

class Main{
    static int[] map = new int[300];
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    fillup(1,0);
	    while(true){
		int n = Integer.valueOf(sc.readLine()), sum = 0;
		if(n==0)
		    break;
		System.out.println(map[n]);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
    static void fillup(int k,int sum){
	if(k==18)
	    return;
	for(int i=k; sum+i*i<300; i++){
	    map[sum+i*i]++;
	    fillup(i,sum+i*i);
	}
    }
}

Measured memory_bytes: 18668
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <type_traits>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15) << std::fixed;

namespace {
	struct input_returnner {
		ll N; input_returnner(ll N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
}

template < typename T >
struct is_vector : std::false_type {};

template < typename T >
struct is_vector<std::vector<T>> : std::true_type {};

template < typename T >
constexpr bool is_vector_v = is_vector<T>::value;

template <typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
	if (!v.empty()) {
		for (int i = 0; i < v.size(); ++i) {
			out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", "));
		}
	}
	return out;
}

ll MOD = 1e9 + 7;

void solve();

signed main() {
	SETUP;
	solve();
#ifdef _DEBUG
	system("pause");
#endif
	return 0;
}

#define int ll

void solve() {
	int a, b; cin >> a >> b;
	cout << a + (a <= b) - 1 << endl;
}



Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    int a, b;
    cin >> a >> b;
    string ans = "Yay!";
    if (a > 8 || b > 8) ans = ":(";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
LL dp[3][qq];

int main(){
	int n;	scanf("%d", &n);
	for (int i = 1; i <= 2; ++i) {
		for (int j = 1; j <= n; ++j) {
			scanf("%lld", &dp[i][j]);
		}
	}
	for (int i = 1; i <= 2; ++i) {
		for (int j = 1; j <= n; ++j) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + dp[i][j];
		}
	}
	printf("%lld\n", dp[2][n]);
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        (n, m): (usize, usize),
        aa: [usize; m]
    }

    let mut sum = 0;
    for a in aa {
        sum += a;
    }

    if n < sum {
        println!("-1");
    } else {
        println!("{}", n-sum);
    }
}


Measured memory_bytes: 2272
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
int a[500];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  for(int i=0;i<n;i++) cin >>a[i];
  map<lol,lol> ma[100];
  ma[0][0]=1000;
  for(int i=0;i<n;i++){
    for(auto o:ma[i]){
      chmax(ma[i+1][o.fi],o.se);//何もしない
      chmax(ma[i+1][o.fi+o.se/a[i]],o.se%a[i]);//株を買う
      chmax(ma[i+1][0],o.se+o.fi*a[i]);//株を売る
      chmax(ma[i+1][o.se/a[i]],o.fi*a[i]+o.se%a[i]);
    }
  }
  lol ans=0;
  for(auto o:ma[n]){
    chmax(ans,o.se);
  }
  cout <<ans<<'\n';
  return(0);
}


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

// ダブリング
// ダブリングについては https://algo-logic.info/doubling/ を参照
class doubling {
   private:
    vector<vector<long long>> next;

   public:
    // コンストラクタ
    // ダブリングの前処理をする
    // maxk: 最大のK
    // next1: i番目の要素から1個先の要素のvector
    doubling(long long maxk, vector<long long> &next1) {
        // nextを初期化 リサイズしてnext[0]を初期化。
        const long long log2k = log2K(maxk);
        next.resize(log2k);
        next.front() = next1;
        const int n = next1.size();
        for (auto &&next_i : next) {
            next_i.resize(n);
        }

        // ダブリングの前処理
        for (int i = 0; i < log2k - 1; i++) {
            for (int j = 0; j < n; j++) {
                next[i + 1][j] = next[i][next[i][j]];
            }
        }
    }

    // ダブリングのクエリに答える
    // p番目の要素からk個先の要素を返す
    long long get(long long p, long long k) {
        const int log2k = log2K(k);
        for (int i = 0; i < log2k; i++) {
            if (k & (1LL << i)) p = next[i][p];
        }
        return p;
    }
    constexpr long long log2K(long long k) {
        int log2k = 1;
        while ((1LL << log2k) < k) log2k++;
        return log2k;
    }
};

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

    // 入力受け取り
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    // Aを0-basedに変換
    for (auto &&i : a) {
        i--;
    }

    // ダブリング前処理
    doubling d(k, a);
    // ダブリングクエリ
    const long long ans = d.get(0, k) + 1;

    cout << ans << "\n";
}


Measured memory_bytes: 98732
// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░░░░░░░░░░░

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

#define  loop(i,m,n)      for(int i=m;i<n;i++)
#define  rloop(i,m,n)     for(int i=m;i>=n;i--)
#define  start()          int main()                           
#define  test(t)          while(t--)
#define  mod              1000000007
#define  push(x)          push_back(x)
#define  pop()            pop_back()

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

start(){
    int a,b;
  	cin>>a>>b;
  	cout<<a*b;
    return 0;
}


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

int main()
{
    int N;
    string S;
    while ( cin >> N, N > 0 ) {
        cin >> S;
        int cnt[15] = {};
        int field = 0;
        for ( int t = 0; t < 100; t++ ) {
            switch ( S[t] ) {
            case 'M' :
                cnt[t % N]++;
                break;
            case 'S' :
                field += cnt[t % N] + 1;
                cnt[t % N] = 0;
                break;
            case 'L' :
                cnt[t % N] += field + 1;
                field = 0;
                break;
            }
        }
        sort(cnt, cnt + N);
        for ( int i = 0; i < N; i++ ) {
            cout << cnt[i] << " ";
        }
        cout << field << endl;
    }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long A, B;
  cin >> A >> B;
  for(int i = 1; i <= B; i++){
    if((A * i) % B == 0){
      cout << A * i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b,l,r,ans = [0]*(n+1),[i for i in range(n+2)],[i for i in range(n+2)],0
for i in range(n): b[a[i]]=i
for i in range(n,0,-1):
	m = b[i]
	x,y = l[m],r[m]
	ans+=i*(m-x+1)*(y-m+1)
	l[y+1],r[x-1] = x,y
print(ans)

Measured memory_bytes: 36752
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] values = new int[n];
		int i = 0;
		while(i < n) {
			values[i] = input.nextInt();
			i++;
		}
		System.out.println(maxLin(n, values));
		
	}
	public static int maxQuad(int n, int[] values) {
		int maxp = -2147000000;
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++)
				if(values[j]-values[i] > maxp)
					maxp = values[j]-values[i];
		}
		return maxp;
	}
	public static int maxLin(int n, int[] values) {
		int maxp = values[1]-values[0];
		int minv = min(values[1], values[0]);
		for(int i = 2; i < n; i++) {
			maxp = max(maxp, values[i] - minv);
			minv = min(minv, values[i]);
		}
		return maxp;
	}
	public static int min(int a, int b) {
		if(a > b){
			return b;
		}
		if(b > a) {
			return a;
		}
		return a;
	}
	public static int max(int a, int b) {
		if(a > b) {
			return a;
		}
		if(b > a) {
			return b;
		}
		return a;
	}
}


Measured memory_bytes: 101224
#include <cstdio>
#include <cmath>
using namespace std;
const int M = 90001;
int H, W, D, Q, Ax[M], Ay[M], sum[M];
int main() {
  scanf("%d %d %d", &H, &W, &D);
  for(int i = 1; i <= H; ++i) {
    for(int j = 1, t; j <= W; ++j) {
      scanf("%d", &t); Ax[t] = i, Ay[t] = j;
    }
  }
  for(int i = 1; i <= H*W; ++i) {
    if(i <= D) continue;
    sum[i] = sum[i-D]+abs(Ax[i]-Ax[i-D])+abs(Ay[i]-Ay[i-D]);
  }
  scanf("%d", &Q);
  for(int i = 1, L, R; i <= Q; ++i) {
    scanf("%d %d", &L, &R);
    printf("%d\n", sum[R]-sum[L]);
  }
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}	
int a[114514],b[114514];
char c[114514];	
signed main(){
	sc(s)
	int n=s.size();
	rep(0,i,n)c[i]=s[n-i-1];
	rep(0,i,n){
		if(c[i]=='r'&&c[i+1]=='e'&&c[i+2]=='s'&&c[i+3]=='a'&&c[i+4]=='r'&&c[i+5]=='e'){
			rep(i,j,i+6){
				c[j]='A';
			}
		}
		if(c[i]=='e'&&c[i+1]=='s'&&c[i+2]=='a'&&c[i+3]=='r'&&c[i+4]=='e'){
			rep(i,j,i+5){
				c[j]='A';
			}
		}	
		if(c[i]=='m'&&c[i+1]=='a'&&c[i+2]=='e'&&c[i+3]=='r'&&c[i+4]=='d'){
			rep(i,j,i+5){
				c[j]='A';
			}
		}
		if(c[i]=='r'&&c[i+1]=='e'&&c[i+2]=='m'&&c[i+3]=='a'&&c[i+4]=='e'&&c[i+5]=='r'&&c[i+6]=='d'){
			rep(i,j,i+7){
				c[j]='A';
			}
		}
	}	
	int sum=0;
	rep(0,i,n)if(c[i]!='A')sum++;
	if(sum==0)c("YES")
	else c("NO")
}	

Measured memory_bytes: 512
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

A, B, K = map(int, input().split())

set_a = set(make_divisors(A))
set_b = set(make_divisors(B))
set_ab = set_a.intersection(set_b)

list_ab = list(set_ab)
list_ab.sort()
# print(list_ab)

print(list_ab[-K])

Measured memory_bytes: 9108
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int dice[6][6] = { {-1,2,4,1,3,-1}, {3,-1,0,5,-1,2}, {1,5,-1,-1,0,4}, {4,0,-1,-1,5,1}, {2,-1,5,0,-1,3}, {-1,3,1,4,2,-1} };

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

	while (cin >> N, N) {
		vector<vector<int>>num(2 * N + 1, vector<int>(2 * N + 1));
		vector<vector<int>>tp(2 * N + 1, vector<int>(2 * N + 1));
		for (int loop = 0; loop < N; loop++) {
			int a, b;
			cin >> a >> b;
			a--, b--;
			int c = dice[a][b];
			int y = N, x = N;
			while (1) {
				if (b == 5) {
					if (num[y][x] > num[y + 1][x]) {
						y++;
						swap(a, b);
						a = 5 - a;
						continue;
					}
				}
				if (b == 0) {
					if (num[y][x] > num[y - 1][x]) {
						y--;
						swap(a, b);
						b = 5 - b;
						continue;
					}
				}
				if (c == 5) {
					if (num[y][x] > num[y][x + 1]) {
						x++;
						swap(a, c);
						a = 5 - a;
						continue;
					}
				}
				if (c == 0) {
					if (num[y][x] > num[y][x - 1]) {
						x--;
						swap(a, c);
						c = 5 - c;
						continue;
					}
				}
				if (b == 4) {
					if (num[y][x] > num[y + 1][x]) {
						y++;
						swap(a, b);
						a = 5 - a;
						continue;
					}
				}
				if (b == 1) {
					if (num[y][x] > num[y - 1][x]) {
						y--;
						swap(a, b);
						b = 5 - b;
						continue;
					}
				}
				if (c == 4) {
					if (num[y][x] > num[y][x + 1]) {
						x++;
						swap(a, c);
						a = 5 - a;
						continue;
					}
				}
				if (c == 1) {
					if (num[y][x] > num[y][x - 1]) {
						x--;
						swap(a, c);
						c = 5 - c;
						continue;
					}
				}
				if (b == 3) {
					if (num[y][x] > num[y + 1][x]) {
						y++;
						swap(a, b);
						a = 5 - a;
						continue;
					}
				}
				if (b == 2) {
					if (num[y][x] > num[y - 1][x]) {
						y--;
						swap(a, b);
						b = 5 - b;
						continue;
					}
				}
				if (c == 3) {
					if (num[y][x] > num[y][x + 1]) {
						x++;
						swap(a, c);
						a = 5 - a;
						continue;
					}
				}
				if (c == 2) {
					if (num[y][x] > num[y][x - 1]) {
						x--;
						swap(a, c);
						c = 5 - c;
						continue;
					}
				}
				break;
			}
			num[y][x]++;
			//cout <<"y x "<< y << " " << x << endl;
			tp[y][x] = a;
		}
		vector<int>ans(6);
		for (int i = 0; i <= 2 * N; i++) {
			for (int j = 0; j <= 2 * N; j++) {
				if (num[i][j])ans[tp[i][j]]++;
			}
		}
		for (int i = 0; i < 6; i++) {
			if (i)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
	return 0;
}


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

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();

            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            for (int i = 0; i < S.length(); i++) {
                sb1.append(0);
                sb1.append(1);
            }
            sb1.substring(0, S.length());
            for (int i = 0; i < S.length(); i++) {
                sb2.append(1);
                sb2.append(0);
            }
            sb2.substring(0, S.length());

            long cnt1 = 0;
            long cnt2 = 0;
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) != sb1.charAt(i)) cnt1++;
                if (S.charAt(i) != sb2.charAt(i)) cnt2++;
            }

            out.println(Math.min(cnt1, cnt2));
        }

    }
}



Measured memory_bytes: 28784
# D
X, Y, Z, K = map(int, input().split())

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

AB_list = [0]*(X*Y)
for i in range(X):
    for j in range(Y):
        AB_list[i*Y+j] = A_list[i] + B_list[j]
AB_list_s = sorted(AB_list)
if len(AB_list_s) > 3000:
    AB_list_s = AB_list_s[-3000:]
W = len(AB_list_s)
ABC_list = [0]*(W*Z)
for i in range(W):
    for j in range(Z):
        ABC_list[i*Z+j] = AB_list_s[i] + C_list[j]
ABC_list_s = sorted(ABC_list)
for i in range(K):
    print(ABC_list_s[-(i+1)])

Measured memory_bytes: 120160
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
const int lb = 60 - 1;
const int LB = lb + 5;

#define bit(x,i) (((x)>>(i))&1)

int n;
ll a[MAXN];

struct Linear_Basis
{
	ll a[LB];
	void clear(void){ memset(a,0,sizeof(a));}
	bool insert(ll x)
	{
		for(int i=lb; i>=0; --i)
		{
			if(!x) return 0;
			if(!bit(x,i)) continue;
			if(a[i]) x^=a[i];
			else
			{
				for(int j=0; j<i; ++j) if(bit(x, j))
					x ^= a[j];
				for(int j=i+1; j<=lb; ++j) if(bit(a[j], i))
					a[j] ^= x;
				a[i] = x;
				return 1;
			}
		}
		return 0;
	}
	
	ll query_max(void)
	{
		ll res=0;
		for(int i=0; i<=lb; ++i) res ^= a[i];
		return res;
	}
}lin;

int main(void)
{
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		scanf("%lld",&a[i]);
	
	ll ans = 0;
	for(int j=0; j<=lb; ++j)
	{
		int tmp = 0;
		for(int i=1; i<=n; ++i)
			if(bit(a[i], j)) ++tmp;
		if(tmp&1)
		{
			ans |= (1ll<<j);
			for(int i=1; i<=n; ++i)
				if(bit(a[i], j))
					a[i] ^= (1ll<<j);
		}
	}
	
	for(int i=1; i<=n; ++i)
		lin.insert(a[i]);
	ans += lin.query_max() * 2;
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2512
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b) {
    if (b > a) return gcd(b, a);
    else if (b == 0) return a;
    else return gcd(b, a % b);
}
int L[100010];
int R[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    L[0] = A[0];
    R[N - 1] = A[N - 1];
    rep(i, N - 2) {
        L[i + 1] = gcd(L[i], A[i + 1]);
        R[N - 2 - i] = gcd(A[N - 2 - i], R[N - 1 - i]);
    }
    int ans = max(L[N - 2], R[1]);
    rep(i, N - 2) {
        ans = max(ans, gcd(L[i], R[i + 2]));
        //cout << L[i] << " " << R[i + 2] << endl;
    }
    /*
    rep(i, N) {
        cout << L[i] << " ";
    }
    cout << endl;
    rep(i, N) {
        cout << R[i] << " ";
    }
    cout << endl;
    */
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>


using namespace std;
int main(void)
{
	int a[3],b = 0,c = 0;
	char z[2];
	while(1)
	{
		if(scanf("%d%c%d%c%d",&a[0],&z[0],&a[1],&z[1],&a[2]) == EOF) break;
		if(a[0] == a[1]) c += 1;
		if(a[2]*a[2] == a[0]*a[0]+a[1]*a[1]) b+= 1;
	}
	printf("%d\n%d\n",b,c);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

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

    bool ok = false;
    for (int i = 0; i < S.size(); i++) {
        if (S == T) {
            ok = true; 
            break;
        }
        S = S.back() + S;
        S.pop_back();
    }

    cout << ((ok) ? "Yes" : "No") << endl;


    return 0;
}

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

struct P
{
    long long x,y,z;

    bool operator<(const P &a)const{
              return x<a.x;
    }

};

vector<int> v[222221];
//bitset<4001000> b;
int a,c,i,b,n,m,k,d;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[222122][2];
long long l[2221][2222];
int j[222221];
int e;
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=1000000007,mod2=1000000009,mod3=2017;
long long z;
double pi=3.14159265;
P u[1];
//stack<int> s;

//set<long long> s;
queue<int> q,q1;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;

//string r,r1;
char r[333336];
//deque<int> de;
//srand((int)time(NULL));
bool as(P a,P b)
{
    if(a.x*b.y!=b.x*a.y)
    return a.x*b.y<b.x*a.y;
    return a.y>b.y;
}



int main()
{
    scanf("%d %d",&a,&b);
    scanf("%s",r+1);
    for(int t=1;t<=a;j[t]=1,r[t]-='A',t++);
    for(int t=1;t<=b;t++)
    {
        scanf("%d %d",&n,&m);
        v[n].push_back(m);
        v[m].push_back(n);
        o[n][r[m]]++;
        o[m][r[n]]++;
    }
    k=a;
    for(int t=1;t<=a;t++)
        if(!o[t][0]||!o[t][1])
        {
            j[t]=0;
        q.push(t);
        }
    for(;q.size();k--,q.pop())
    {
        for(int h=0;h<v[q.front()].size();h++)
        if(j[v[q.front()][h]])
        {
            o[v[q.front()][h]][r[q.front()]]--;
            if(o[v[q.front()][h]][r[q.front()]]==0)
            {
                q.push(v[q.front()][h]);
                j[v[q.front()][h]]--;
            }
        }
    }
    if(k) puts("Yes");
    else puts("No");
}
//1 4 3 2 1


Measured memory_bytes: 14720
(defun lcs (str1 str2 &key (backtrace nil))
  (let* ((dp-table (make-array (list (1+ (length str1)) (1+ (length str2)))
                               :initial-element 0 :element-type 'fixnum)))
    (loop :for k :from 1 :upto (length str1)
          :do(loop :for l :from 1 :upto (length str2)
                   :do (setf (aref dp-table k l) (max (aref dp-table (1- k) l)
                                                      (aref dp-table k (1- l))
                                                      (if (char= (aref str1 (1- k))
                                                                 (aref str2 (1- l)))
                                                          (1+ (aref dp-table (1- k) (1- l)))
                                                          0)))))
    (if backtrace
        (let* ((ret nil)
               (mem (length str2)))
          (loop :for k :from (length str1) :downto 1
                :do(loop :for l :from mem :downto 1
                         :always (= (aref dp-table k l)
                                    (aref dp-table k mem))
                         :never (if (and (not (= (aref dp-table k l) (aref dp-table (1- k) l)))
                                         (not (= (aref dp-table k l) (aref dp-table k (1- l)))))
                                    (progn (push l ret) (setf mem (1- l))))))
          (concatenate 'String (loop :for k :in ret :collect (aref str2 (1- k)))))
        dp-table)))
(princ (lcs (read-line) (read-line) :backtrace t))


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

int main(){
  int N, side1, side2, side3, i;

  scanf("%d", &N);

  for(i = 0; i < N; i++){
    scanf("%d %d %d", &side1, &side2, &side3);
    if(side1 >= side2 && side1 >= side3){
      if(side1 * side1 == side2 * side2 + side3 * side3){
	printf("YES\n");
      }else{
	printf("NO\n");
      }
    }else if(side2 >= side1 && side2 >= side3){
      if(side2 * side2 == side1 * side1 + side3 * side3){
	printf("YES\n");
      }else{
	printf("NO\n");
      }
    }else{
      if(side3 * side3 == side2 * side2 + side1 * side1){
	printf("YES\n");
      }else{
	printf("NO\n");
      }
    }

  }

  return 0;
}

Measured memory_bytes: 1168
N,K,C = map(int,input().split())
S = list(input())

A = [0]*N
B = [0]*N

i = 0
a = 1
while i < N:
    if S[i] == 'o':
        A[i] = a
        a += 1
        i += C+1
    else:
        i += 1
j = N-1
b = K
while j >= 0:
    if S[j] == 'o':
        B[j] = b
        b -= 1
        j -= C+1
    else:
        j -= 1

for i in range(N):
    if A[i] == B[i] and A[i] != 0:
        print(i+1)

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(string, s);
  bool ok = true;
  rep(i, s.size()) {
    if (i % 2 == 1) {
      if (s[i] == 'R') {
        ok = false;
      }
    } else {
      if (s[i] == 'L') {
        ok = false;
      }
    }
  }
  out(ok ? "Yes" : "No");
}


Measured memory_bytes: 256
import math

def main():
    n, k = [int(x) for x in input().split()]
    p = 0
    for i in range(n):
        dice = i + 1
        if dice >= k:
            p += 1
        else:
            p += 0.5 ** (math.ceil(math.log2(k / dice)))
    p /= n
    print(p)

if __name__ == '__main__':
    main()


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


void solve(long long n, std::vector<long long> a){
    vector<int> b;
    for(int i = 0; i < (int)n; ++i){
        if(i % 2 == 0) b.push_back((int)a[i]);
        else b.insert(b.begin(), (int)a[i]);
        //reverse(b.begin(), b.end());
    }
    if(n % 2 != 0) reverse(b.begin(), b.end());
    for(int i = 0; i < (int)n; ++i){
        if(i) cout << " ";
        cout << b[i];
    }
    cout << endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    solve(n, std::move(a));
    return 0;
}


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

int main(){
    vector<int> w, k;
    int b;
    for (int i = 0; i < 10; i++){
	cin >> b;
	w.push_back(b);
    }
    for (int i = 0; i < 10; i++){
	cin >> b;
	k.push_back(b);
    }

    sort(w.begin(), w.end(), greater<int>());
    sort(k.begin(), k.end(), greater<int>());
    int ww = 0, kk = 0;
    for (int i = 0; i < 3; i++) ww += w[i];
    for (int i = 0; i < 3; i++) kk += k[i];

    cout << ww << " " << kk << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, M;
    cin >> N >> M;
    vvc<ll> E(N), R(N);
    vc<ll> inn(N); //根なら0のまま
    rep(i,N-1+M){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        E[a].eb(b);
        inn[b]++;
    }
    ll root;
    rep(i, N) if (inn[i]==0){
        root = i;
        break;
    }

    vl dep(N), ans(N), cnt(N);
    queue<ll> q;
    q.emplace(root);
    while(!q.empty()){
        ll now = q.front();
        q.pop();
        cnt[now]++;
        if (cnt[now] < inn[now]) continue; //親から辿られきられていないなら飛ばす
        for(auto to:E[now]){
            dep[to] = dep[now] + 1;
            ans[to] = now+1;
            q.emplace(to);
        }
    }
    rep(i, N) cout << ans[i] << "\n";
}

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

int main()
{
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int i, j;
  int count = 0;
  for(i = 0; i <= n/r; i++)
  {
    for(j = 0; j <= (n-i*r)/g; j++)
    {
      if((n-(i*r+j*g)) % b == 0)
      {
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int dp[1<<17][11];
vector<int>G[1<<17];
int d[1<<17],c[1<<17],v[1<<17];
void dfs(int u,int dis,int col)
{
	if(dis<0)return;
	else if(dp[u][dis])return;
	dp[u][dis]=col;
	for(int i=0;i<G[u].size();i++)
	{
		dfs(G[u][i],dis-1,col);
	}
}
main()
{
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;cin>>a>>b;
		G[--a].push_back(--b);
		G[b].push_back(a);
	}
	int q;cin>>q;
	for(int i=0;i<q;i++)cin>>v[i]>>d[i]>>c[i];
	for(;q--;)
	{
		for(int i=d[q]+1;i--;)dfs(v[q]-1,i,c[q]);
	}
	for(int i=0;i<n;i++)cout<<dp[i][0]<<endl;
}

Measured memory_bytes: 14072
from collections import defaultdict

def main():
    node_num, edge_num = map(int, input().split())
    graph_data = [list(map(int, input().split())) for i in range(edge_num)]
    inf = -10 ** 15
    length_data = [inf for i in range(node_num + 1)]
    length_data[1] = 0

    ans_data = length_data[node_num]
    for i in range(node_num):
        for a, b, c in graph_data:
            b_lengh = length_data[a] + c
            length_data[b] = max(b_lengh, length_data[b])
        # print(length_data, b_lengh, ans_data, length_data[node_num])
        if i == node_num - 1 and length_data[node_num] > ans_data:
            ans_data = 'inf'
        else:
            ans_data = length_data[node_num]

    print(ans_data)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44904
/**
 *      purpose : ABC 85 D
 *      author  : kyomukyomupurin
 *      created : 2018-11-08 20:06:21
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int64 divide(int64 x, int64 y){
    if (x % y == 0) return x / y;
    else return x / y + 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, H; cin >> N >> H;
    int64 a[N] = {}; int64 b[N] = {};
    for (int i = 0; i < N; ++i) cin >> a[i] >> b[i];

    int64 x = *max_element(a, a + N);

    sort(b, b + N);
    auto it = lower_bound(b, b + N, x);     // a の max(x) より大きい b は投げる

    int64 temp = 0; int cnt = 0;

    for (int i = N - 1; i >= (int) (it - b); --i){
        temp += b[i]; ++cnt;
        if (temp >= H){
            print(cnt); return 0;
        }
    }
    print(cnt + divide((H - temp), x));
    
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
	int i, N, M, A, sum = 0;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		scanf("%d", &A);
		sum += A;
	}
	if (sum <= N) printf("%d\n", N - sum);
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1700
while True:
 h,w=map(int,input().split())
 if h==0 and w==0:
  break
 for i in range(h):
    if i==0 or i==h-1:
        print("#"*w)
    else:
        print("#",end="")
        print("."*(w-2),end="")
        print("#")
 print()


Measured memory_bytes: 5628
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int h=sc.nextInt();
		int w=sc.nextInt();
		pw.println((H-h)*(W-w));
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, M, price;
	ll ans = 0;
	priority_queue<int> A;

	cin >> N >> M;
	rep(i, N) {
		cin >> price;
		A.push(price);
	}

	rep(i, M) {
		price = A.top(); A.pop();
		A.push(price / 2);
	}

	rep(i, N) {
		price = A.top(); A.pop();
		ans += (ll)price;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1020
#include "bits/stdc++.h"
//#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

signed main(){
	int n, m;
	cin >> n >> m;
	int v[n], w[n];
	rep(i, n)cin >> v[i] >> w[i];

	int va[n + 1][m + 1] = {};

	rep(i, n){
		rep(j, m + 1){
			if(j < w[i])
				va[i + 1][j] = va[i][j];
			else
				va[i + 1][j] = max(va[i][j], va[i][j - w[i]] + v[i]);
		}
	}

	cout << va[n][m] << endl;
}

Measured memory_bytes: 7060
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
    int n,k,r,num[100];
    while(cin>>n>>k){
        int i=0,ans=0;
        for(i=0;i<100;i++) num[i]=-1;
        i=0;
        while(n!=0){
            r=n%k;
            num[i]=r;
            n=(n-n%k)/k;
            i++;
        }
        while(num[ans]!=-1) ans++;
        cout<<ans;
    }
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

ll pow_mod(ll x,ll y,ll m){
    if(y==0){
        return 1;
    }
    if(y%2==1){
        return x*pow_mod(x,y-1,m)%m;
    }
    else{
        ll t=pow_mod(x,y/2,m);
        return t*t%m;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    string s;
    cin >> n >> s;
    ll cnt0=0,cnt1=0;
    rep(i,n){
        if(s[i]=='0'){
            cnt0++;
        }
        else{
            cnt1++;
        }
    }
    ll cntp=cnt1+1,cntm=cnt1-1;
    ll bp=0,bm=0;
    if(cnt1==0){
        rep(i,n){
            cout << 1 << endl;
        }
        return 0;
    }
    if(cnt1==1){
        rep(i,n){
            if(s[n-1]=='1'&&i!=n-1){
                cout << 2 << endl;
            }
            else if(s[n-1]=='1'&&i==n-1){
                cout << 0 << endl;
            }
            else{
                if(s[i]=='1'){
                    cout << 0 << endl;
                }
                else if(i==n-1){
                    cout << 2 << endl;
                }
                else{
                  cout << 1 << endl;
                }
            }
        }
        return 0;
    }
    rep(i,n){
        if(s[i]=='1'){
            bp+=pow_mod(2,n-i-1,cntp);
            bp%=cntp;
            bm+=pow_mod(2,n-i-1,cntm);
            bm%=cntm;
        }
    }
    rep(i,n){
        ll cnt=0;
        ll now;
        ll nbp=bp,nbm=bm;
        if(s[i]=='0'){
            nbp+=pow_mod(2,n-i-1,cntp);
            nbp%=cntp;
            cnt++;
            now=nbp;
        }
        else if(s[i]=='1'){
            nbm-=pow_mod(2,n-i-1,cntm);
            nbm+=cntm;
            nbm%=cntm;
            cnt++;
            now=nbm;
        }
        while(now){
            cnt++;
            ll z=0,x=now;
            while(x){
                if(x%2==0){
                    x/=2;
                }
                else{
                    x-=1;
                    z++;
                }
            }
            now%=z;
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;

int main() {
	int MAX = 0;
	cin >> s;
	for (int i = 2; i < s.size(); i += 2) {
		if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
			MAX = max(MAX, i);
		}
	}
	cout << MAX << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i=0; i<n; i++){
		cin >> d.at(i);
	}
	vector<int> vec(110);
	for(int i=0; i<n; i++){
		vec.at(d.at(i))++;
	}
	int num=0;
	for(int i=1; i<=100; i++){
		if(vec.at(i)){
			num++;
		}
	}
	cout << num << endl;
}


Measured memory_bytes: 3560
import java.util.HashMap;
import java.util.Scanner;

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

		HashMap<String, Integer> map = new HashMap<>();

		int i;
		String temp;
		int a;
		int b;
		for(i = 1; i <= n; i++) {
			temp = String.valueOf(i);
			temp = temp.substring(0, 1) + temp.substring(temp.length() - 1);
			if(map.containsKey(temp))
				map.put(temp, map.get(temp) + 1);
			else
				map.put(temp, 1);
		}

		long ans = 0;
		for(i = 1; i <= n; i++) {
			temp = String.valueOf(i);
			temp = temp.substring(temp.length() - 1) + temp.substring(0, 1);
			if(map.containsKey(temp))
				ans += map.get(temp);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 62980