akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 19191919;

int main(){
    int r,c;
    cin >>r >>c;
    vector<string> s(r);
    vector<int> L(r);
    rep(i,r){
        cin >>s[i];
        L[i] = s[i].size();
    }

    int U = (1<<c)-1;
    vector<int> cm(c), pm(c);
    rep(i,c){
        rep(j,i) cm[i] |= (1<<j);
        pm[i] = cm[i]^U;
    }

    vector<int> dp(1<<c, -INF);
    dp[0] = 0;
    rep(i,r)rep(j,c){
        int nr = i;
        int nc = j+1;
        if(nc == c){
            ++nr;
            nc = 0;
        }

        vector<int> nx(1<<c,-INF);
        rep(mask,1<<c)if(dp[mask]>=0){
            // printf(" %d %d %d\n",i,j,mask);
            int idx = __builtin_popcount(mask&cm[j]);
            if(idx<=L[i]){
                // not put
                int nmask = (mask<<1)&U;
                if( !(i!=nr && idx<L[i]) ) nx[nmask] = max(nx[nmask], dp[mask]);

                // put
                if(idx<L[i]){
                    nmask |= 1;

                    int add = 0;
                    // left
                    if(idx>0 && j>0 && (mask&1)) add += (s[i][idx]==s[i][idx-1]);
                    // up
                    if( (mask>>(c-1))&1 ){
                        int ct = __builtin_popcount(mask&pm[j]);
                        int pre_idx = L[i-1]-ct;
                        if(pre_idx<0) continue;

                        add += (s[i][idx]==s[i-1][pre_idx]);
                    }

                    if( !(i!=nr && idx<L[i]-1) ) nx[nmask] = max(nx[nmask], dp[mask]+add);
                }
            }
        }

        dp = nx;
    }

    int ans = 0;
    rep(i,1<<c) ans = max(ans, dp[i]);
    cout << ans*2 << endl;
    return 0;
}



Measured memory_bytes: 3484
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <map>

using namespace std;

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

    vector<pair<long, long>> balls(n);
    for(pair<long, long>& ball: balls){
        cin >> ball.first >> ball.second;
    }

    map<pair<long, long>, int> vecs;
    for(int i = 0 ; i < n - 1 ; i++){
        for(int j = i + 1 ; j < n ; j++){
            long p = balls[i].first - balls[j].first;
            long q = balls[i].second - balls[j].second;
            if(p < 0){
                p *= -1;
                q *= -1;
            }
            if((p == 0) && (q < 0)){
                q *= -1;
            }
            pair<long,long> vec = make_pair(p,q);

            if(vecs.find(vec) == vecs.end()){
                vecs[vec] = 1;
            } else {
                vecs[vec]++;
            }
        }
    }
    
    int max = 0;
    for(auto itr = vecs.begin(); itr != vecs.end(); itr++){
        if(max < itr->second){
            max = itr->second;
        }
    }

    cout << n - max << endl;

    return 0;
}



Measured memory_bytes: 384
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
ll m1 = 1000000007, m2 = 998244353;
ll t1 = 555522277, t2 = 895612782;
ll p1[505050], p2[505050];
ll ip1[505050], ip2[505050];
typedef pair<ll, ll>pii;
ll po(ll a, ll b, ll m)
{
	if (b == 0)return 1;
	ll z = po(a, b / 2, m);
	z = z*z%m;
	if (b & 1)z = z*a%m;
	return z;
}
ll inv(ll a, ll m)
{
	return po(a, m - 2, m);
}
int main()
{
	int num;
	scanf("%d", &num);
	string s;
	cin >> s;
	p1[0] = p2[0] = ip1[0] = ip2[0] = 1;
	for (int i = 0; i < 505000; i++)p1[i + 1] = p1[i] * t1%m1, p2[i + 1] = p2[i] * t2%m2;
	ll it1 = inv(t1, m1), it2 = inv(t2, m2);
	for (int i = 0; i < 505000; i++)ip1[i + 1] = ip1[i] * it1%m1, ip2[i + 1] = ip2[i] * it2%m2;
	ll n1 = 0, n2 = 0;
	vector<pii>v;
	vector<int>pl;
	v.push_back(make_pair(0, 0));
	pl.push_back(num + 10);
	int now = num + 10;
	for (int i = 0; i < num; i++)
	{
		if (s[i] == '+')n1 = (n1 + p1[now]) % m1, n2 = (n2 + p2[now]) % m2;
		else if (s[i] == '-')n1 = (n1 + m1 - p1[now]) % m1, n2 = (n2 + m2 - p2[now]) % m2;
		else if (s[i] == '>')now++;
		else now--;
		v.push_back(make_pair(n1, n2)), pl.push_back(now);
	}
	ll ans = 0;
	map<pii, int>ma;
	for (int i = num; i >= 0; i--)
	{
		int dif = pl[i] - (num + 10);
		ll mk1, mk2;
		if (dif >= 0)mk1 = (v[i].first + n1*p1[dif]) % m1, mk2 = (v[i].second + n2*p2[dif]) % m2;
		else mk1 = (v[i].first + n1*ip1[-dif]) % m1, mk2 = (v[i].second + n2*ip2[-dif]) % m2;
		ans += ma[make_pair(mk1, mk2)];
		ma[v[i]]++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 52464
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const int INF = 1001001001;

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> A(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> A[i][j];
        }
    }
    vector<vector<int>> dist(H,vector<int>(W,INF));

    queue<pair<int,int>> que;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(A[i][j] == '#'){
                que.push(make_pair(i,j));
                dist[i][j] = 0;
            }
        }
    }

    int ans = 0;
    while(!que.empty()){
        int x = que.front().second,y = que.front().first;
        que.pop();
        for(int i=0;i<4;i++){
            int d_x = x+dx[i],d_y = y+dy[i];
            if(d_x<0 || d_x>=W || d_y<0 || d_y>=H) continue;
            if(dist[d_y][d_x] != INF || A[d_y][d_x]=='#') continue;
            A[d_y][d_x] = '#';
            dist[d_y][d_x] = dist[y][x]+1;            
            que.push(make_pair(d_y,d_x));
        }
        ans = max(ans,dist[y][x]);
    }
    cout << ans << endl;

}


Measured memory_bytes: 13456
import java.util.Scanner;

class Main {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            long a = scan.nextInt();
            long b = scan.nextInt();
            long x = a;
            long y = b;
            long z;
            while (x % y != 0) {
                z = x;
                x = y;
                y = z % x;
            }
            System.out.println(y + " " + a / y * b);
        }
    }
}



Measured memory_bytes: 25900
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> F(n, vector<int>(10));
    vector<vector<int>> P(n, vector<int>(11));
    REP(i,n)REP(j,10) cin >> F[i][j];
    REP(i,n)REP(j,11) cin >> P[i][j];
    // REP(i,n){REP(j,10) cout << F[i][j];cout << endl;}
    // REP(i,n){REP(j,11) cout << P[i][j];cout << endl;}
    int ma = -1e9;
    for(int mask=0; mask < (1<<10); mask++){
        if(mask==0) continue;
        int m=0;
        REP(i,n){
            int cnt=0;
            REP(j,10)
                if(F[i][j] & (mask >> j))cnt++;
            
            m+=P[i][cnt];
        }
        ma=max(ma,m);
    }
    cout << ma << endl;
    return 0;

}

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

#define INF 1e9
typedef long long ll;
typedef pair<int,int> P;
int dist(P a,P b){
    return abs(a.first-b.first)+abs(a.second-b.second);
}

int main(void){
    int n,m;
    cin>>n>>m;
    vector<P> p(n+1),c(m+1);
    rep1(i,n){
        cin>>p[i].first>>p[i].second;
    }
    rep1(i,m){
        cin>>c[i].first>>c[i].second;
    }
    rep1(i,n){
        int mdist = INF;
        int id = 0;
        rep1(j,m){
            if(mdist > dist(p[i],c[j])){
                mdist = dist(p[i],c[j]);
                id = j;
            }
        }
        cout<<id<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,b=0,c=0,n,x;
	cin>>n;
	while(n--)
	{
		cin>>x;
		if(x%4==0) a++;
		else if(x%2==0) b++;
		else c++;
	}
	a-=c;
	if(a>=0||(a==-1&&b==0)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

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

  long long N;
  cin >> N;

  long long ans = N;
  for(long long i = 1; i <= sqrt(N); i++) {
    if(N % i == 0) {
      ans = min(ans, (i - 1) + ((N / i) - 1));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3664
use proconio::input;

#[proconio::fastout]
pub fn main() {
    input! {
    mut abc:[isize;3],
    mut k:isize,
    }
    while !(abc[0] < abc[1]) {
        abc[1] *= 2;
        k -= 1;
    }
    while !(abc[1] < abc[2]) {
        abc[2] *= 2;
        k -= 1;
    }
    let ans = if k >= 0 { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 2192
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

vpint line[60];

int main() {
	int n,m;
	for(;;){
		cin>>n;
		if(n==0)return 0;
		pint buf,frst;
		rep(i,n+1){
			line[i].clear();
			cin>>m;
			cin>>frst.X>>frst.Y;
			line[i].PB(MP(0,0));
			rep(j,m-1){
				cin>>buf.X>>buf.Y;
				buf.X-=frst.X;
				buf.Y-=frst.Y;
				line[i].PB(buf);
			}
		}
		repn(i,1,n){
			if(sz(line[0])!=sz(line[i]))continue;
			rep(r,4){
				if(line[0]==line[i]){
					cout<<i<<endl;
					break;
				}
				rep(j,sz(line[0])){
					pint buf;
					buf.X=line[i][j].Y;
					buf.Y=-line[i][j].X;
					line[i][j]=buf;
				}
			}
			vpint rev;
			rep(j,sz(line[0])){
				rev.PB(line[i][sz(line[0])-j-1]);
			}
			repd(j,sz(line[0])){
				rev[j].X-=rev[0].X;
				rev[j].Y-=rev[0].Y;
			}
			rep(r,4){
				if(line[0]==rev){
					cout<<i<<endl;
					break;
				}
				rep(j,sz(line[0])){
					pint buf;
					buf.X=rev[j].Y;
					buf.Y=-rev[j].X;
					rev[j]=buf;
				}
			}
		}
		cout<<"+++++\n";
	}
}

Measured memory_bytes: 0
N = gets.to_i

cases = N.times.flat_map.with_index(1) { |_, id|
  gets.to_i.times.map {
    other, b = gets.chomp.split(' ').map(&:to_i)
    [id, other, b]
  }
}

puts 0.upto(('1'*N).to_i(2)).map {|n|
  pattern = sprintf("%0#{N}d", n.to_s(2)).chars.map(&:to_i)
  f = cases.any? do |(id, other, b)|
    pattern[id-1] == 1 && pattern[other-1] != b
  end
  pattern.select { |s| s == 1 }.size unless f
}.compact.max

Measured memory_bytes: 2488
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int a = sc.nextInt();
                String op = sc.next();
                int b = sc.nextInt();
                int answer;

            switch(op){
                case "+":
                    answer = a + b;
                    break;
                case "-":
                    answer = a-b;
                    break;
                case "*":
                    answer = a * b;
                    break;
                case "/":
                    answer = a / b;
                    break;
                default:
                    return;
            }
            System.out.println(answer);
           // sc.close();
        }
    }
    }
}


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

int main() {
  int a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl; 
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder.ABC042
{
    class ProblemB
    {
        static void Main()
        {
            var nl = ReadIntArray();
            var texts = new string[nl[0]];
            for (var i = 0; i < texts.Length; i++)
            {
                texts[i] = ReadLine();
            }
            Console.WriteLine(string.Concat(texts.OrderBy(v => v)));
        }

        public static string ReadLine() => Console.ReadLine();

        public static int ReadInt() => int.Parse(ReadLine());

        public static int[] ReadIntArray() => ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
    }
}


Measured memory_bytes: 11616
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<int>G[5001],vs;
bool used[5001];
int cmp[5001];

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    if(!used[G[v][i]])dfs(G[v][i]);
  }
  vs.push_back(v);
}

bool dfs2(int v,int g){
  if(v==g)return true;
  used[v]=true;
  bool fg=false;
  for(int i=0;i<G[v].size();i++){
    if(!used[G[v][i]])fg|=dfs2(G[v][i],g);
  }
  return fg;
}

int main(void){

  int n,m;

  cin >> n >> m;

  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
  }
  bool fg=true;
  fill(used,used+5001,false);
  for(int i=1;i<=n;i++)if(!used[i])dfs(i);
  reverse(vs.begin(),vs.end());

  for(int i=0;i<n-1;i++){
    fill(used,used+5001,false);
    fg&=dfs2(vs[i],vs[i+1]);
  }

  for(int i=0;i<n;i++)cout << vs[i] << endl;
  cout << !fg << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
vector<int> g[N], pre[N], suf[N];
int dp[N], sol[N], n, mod;

int add(int a, int b)
{
	a = (a + mod) % mod;
	b = (b + mod) % mod;
	return (a + b) % mod;
}

int mul(int a, int b)
{
	a = (a + mod) % mod;
	b = (b + mod) % mod;
	return (1ll * a * b) % mod;
}

void dfs(int node, int parent)
{
	pre[node].resize(g[node].size());
	suf[node].resize(g[node].size());
	int cur = 1;
	for(int i = 0; i < g[node].size(); i++)
	{
		int child = g[node][i];
		if(child != parent)
		{
			dfs(child, node);
			cur = mul(cur, dp[child]);
		}
		pre[node][i] = cur;
	}
	cur = 1;
	for(int i = g[node].size() - 1; i >= 0; i--)
	{
		int child = g[node][i];
		if(child != parent)
		{
			cur = mul(cur, dp[child]);
		}
		suf[node][i] = cur;
	}
	dp[node] = add(cur, 1);
}

//dp[child] = (dp[child] - 1) * val_parent + 1

void dfs2(int node, int parent, int val_parent)
{
	dp[node] = add(mul(add(dp[node], -1), val_parent), 1);
	sol[node] = dp[node];
	for(int i = 0; i < g[node].size(); i++)
	{
		int child = g[node][i];
		if(child != parent)
		{
			int p = 1, s = 1;
			if(i)
				p = pre[node][i - 1];
			if(i + 1 < g[node].size())
				s = suf[node][i + 1];
			dfs2(child, node, add(mul(mul(p, s), val_parent), 1));
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> mod;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 1);
	dfs2(1, 1, 1);
	for(int i = 1; i <= n; i++)
		cout << add(sol[i], -1) << '\n';
	return 0;
}


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

int gcd(int m,int n)
{
	if((m == 0) || (n == 0)) return 0;

	while(m != n)
	{
		if(m > n) m = m -n;
		else n = n -m;
	}

	return m;
}

int lcm(int m,int n)
{
	if((m == 0) || (n == 0)) return 0;
	return ((m / gcd(m,n)) * n);
}


int main()
{
	int a,b,c,x,y;
	while(cin >> a >> b)
	{
		cout << gcd(a,b) << " " << lcm(a,b)<< endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  int x, y;
  cin >> x >> y;
  if (y % 2 == 0 && y >= 2 * x && 4 * x >= y) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    double L; cin >> L;
    ll ans=0;
    double tmp=L/3;
    cout << fixed << setprecision(15) << pow(tmp,3) << endl;
}

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

int main(){
    ll N;
    cin >> N;
    if(N % 10 == 1 || N % 10 == 0 || N % 10 == 6 || N % 10 == 8){
        cout << "pon" << endl;
    }else if(N % 10 ==3){
        cout << "bon" << endl;
    }else{
        cout << "hon" << endl;
    }
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    vector<int> a(3);
    cin >> a;
    cout << ((a[0] + a[1] + a[2] < 22) ? "win" : "bust");
    return 0;
}


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

int main()
{
    string s, t;

    cin >> s >> t;

    bool ans = true;

    for(int i=0;i<s.length();i++){
        if (s[i] != t[i])ans = false;
    }

    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}




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

int main(){
    int n, i, buf, h = 0, w = 0, count = 0;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    buf = a[0];
    for(i=1; i<n; i++){
        if(buf == a[i]){
            count++;
        }else{
            count = 0;
            buf = a[i];
        }
        if(count == 1 || count == 3){
            h = w;
            w = a[i];
        }
    }

    cout << (long int)h*w;
    return 0;
}

Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main() {

    long long N, X;
    cin >> N >> X;

    vector<long long> x(N);
    for (int i = 0; i < N; i++)cin >> x[i];

    vector<long long> dist(N);
    for (int i = 0; i < N; i++) dist[i] = abs(x[i] - X);

    long long ans = dist[0];
    for (int i = 0; i < N; i++) ans = gcd(ans, dist[i]);

    cout << ans << endl;

}
















































Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n < 1200) cout << "ABC\n";
    else cout << "ARC\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


ll n;
ll a[200002];
vector<ll> v[200002];
ll ans[200002];
ll dp[200002];
ll maxi;

void hoge(ll x){
    ll l=0;
    ll r=n;
    while(r-l>1){
        ll mid=(r+l)/2;
        if(dp[mid]<a[x]){
            l=mid;
        }else{
            r=mid;
        }
    }
    ll k=l+1;
    ll memo=dp[k];
    if(memo==inf){
        maxi++;
    }
    ans[x]=maxi;
    dp[k]=a[x];
    rep(i,0,(ll)v[x].size()-1){
        if(ans[v[x][i]]==0){
            hoge(v[x][i]);
        }
    }
    dp[k]=memo;
    if(memo==inf){
        maxi--;
    }
}

int main(){fastio
    ll u,t;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
    }
    rep(i,0,n-2){
        cin>>u>>t;
        v[u].pb(t);
        v[t].pb(u);
    }
    rep(i,0,n){
        dp[i]=inf;
    }
    dp[0]=0;
    maxi=0;
    hoge(1);
    rep(i,1,n){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 30600
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;

ll INF = 114514191919119;

//数学的に解こうとするとハマった
//制約を見ると全探査でも良さそう
//とりあえず適当な場所で折ると2等分問題になる
//2等分はなるべく真中付近で折ると良い
int main(){

    ll H, W;
    cin >> H >> W;
    //3の倍数ならそりゃうまくいく
    if(H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = INF;
    //とりあえず縦に割る
    for(ll k = 0; k < 2; k++){
        for(ll i = 1; i <= H - 1; i++){
            //縦縦
            ll t1 = ((H - i) / 2) * W;
            ll t2 = ((H - i) / 2 + (H - i) % 2)  *  W;
            ll tmx = max(W * i, max(t1, t2));
            ll tmn = min(W * i, min(t1, t2));
            ans = min(ans, tmx - tmn);
            
            //縦横
            ll w1 = (H - i) * (W / 2);
            ll w2 = (H - i) * (W / 2 + W % 2);
            ll wmx = max(W * i, max(w1, w2));
            ll wmn = min(W * i, min(w1, w2));
            //cout << wmx - wmn << endl;
            ans = min(ans, wmx - wmn);

        }
        swap(H , W);
    }

    //横に割る
    /*
    for(ll i = 1; i <= W - 1; i++){
        //横横
        ll t1 = ((W - i) / 2) * H;
        ll t2 = ((W - i) / 2 + (W - i) % 2)  *  H;
        ll tmx = max(H * i, max(t1, t2));
        ll tmn = min(H * i, min(t1, t2));
        ans = min(ans, tmx - tmn);
        //cout << tmx - tmn << endl;
        
        //縦縦
        ll w1 = (W - i) * (H / 2);
        ll w2 = (W - i) * (H / 2 + H % 2);
        ll wmx = max(H * i, max(w1, w2));
        ll wmn = min(H * i, min(w1, w2));
        //cout << wmx - wmn << endl;
        ans = min(ans, wmx - wmn);

    }
    */

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<cstdio>
int main(){
    char ch[21];
    int sum;
    scanf("%s",ch);
    for(sum=0; ch[sum]!='\0'; sum++){}
    for(sum=sum-1; sum>=0; sum--)
        printf("%c", ch[sum]);
    printf("\n");
    return 0;
}



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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  LL A, B, C, D;
  cin >> A >> B >> C >> D;
  --A;
  auto f = [=](LL n) {
    auto LCM = [](LL a, LL b) {
      return a * b / __gcd(a, b);
    };
    return n - n / C - n / D + n / LCM(C, D);
  };
  cout << f(B) - f(A) << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
int x,a,b,d1,d2;
	scanf("%d %d %d",&x,&a,&b);
	
	if(x>a){
		d1=x-a;
	}else{
		d1=a-x;
	}
	if(x>b){
		d2=x-b;
	}else{
		d2=b-x;
	}
	if(d1<d2){
		printf("A\n");
	}else{
		printf("B\n");
	}

return 0;
}

Measured memory_bytes: 128
from itertools import accumulate

def main():
    N=int(input())
    L=list(map(int,input().split()))
    long=[0 for i in range(0,1001)]
    for i in range(0,N):
        long[L[i]]+=1
    netlong=[]
    for i in range(1,1001):
        if long[i]>=1:
            netlong.append(i)
    X=list(accumulate(long))
    subans=[0 for i in range(0,2001)]
    ans=0
    for i in range(0,len(netlong)):
        a=netlong[i]
        for j in range(netlong[i]+1,2*netlong[i]-1):
            ans+=subans[j]*long[a]
        ans=ans+X[a-1]*long[a]*(long[a]-1)//2+long[a]*(long[a]-1)*(long[a]-2)//6
        for j in range(0,i):
            subans[a+netlong[j]]+=long[a]*long[netlong[j]]
        subans[2*a]+=long[a]*(long[a]-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-

n = input()
digit = len(n)
n = int(n)

def make753(num):
    cand = [""]
    endj = 0
    for i in range(num):
        for j in range(endj,3 ** i + endj):
            cand.append(cand[j] + "7")
            cand.append(cand[j] + "5")
            cand.append(cand[j] + "3")
            endj = j + 1
    del cand[0]
    return cand

cand = make753(digit)

delete = []
for i in range(len(cand)):
    if "3" not in cand[i] or "5" not in cand[i] or "7" not in cand[i]:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del cand[delete[i] - diff]
    diff += 1

for i in range(len(cand)):
    cand[i] = int(cand[i])

cand.sort()

for i in range(len(cand)):
    if n < cand[i]:
        print(i)
        break
else:
    print(len(cand))

Measured memory_bytes: 5292
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=(a+b)*c;
    cout<<ans/2<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3660
function main(input: string): void {
  const nums: number[] = input.split(' ').map(n => parseInt(n, 10))

  const A: number = nums[0]
  const B: number = nums[1]
  const X: number = nums[2]

  if (A + B >= X && A <= X) {
    console.log('YES')
  } else {
    console.log('NO')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
use std::io::Read;

const MOD : u64 = 1_000_000_007;
enum State { X(u64), Y1(u64), Y2(u64), }
use State::*;
impl State {
  fn init(up: u8, down: u8) -> State {
    if up == down { X(3) } else { Y1(6) }
  }
}

fn main(){
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).expect("fail to read");
  let mut lines = buf.lines();
  
  let n : usize = lines.next().unwrap().parse().unwrap();
  let L1 = lines.next().unwrap().as_bytes();
  let L2 = lines.next().unwrap().as_bytes();
  
  let s0 = State::init(L1[0], L2[0]);
  let ans = (1 .. n).fold(s0, |s, i| {
    if L1[i] == L2[i] {
      match s {
        X(u) => X(u * 2 % MOD),
        Y2(u) => X(u),
        _ => unreachable!(),
      }
    } else {
      match s {
        X(u) => Y1(u * 2 % MOD),
        Y2(u) => Y1(u * 3 % MOD),
        Y1(u) => Y2(u),
      }
    }
  });
  
  match ans {
    X(v) => println!("{}", v),
    Y2(v) => println!("{}", v),
    _ => unreachable!(),
  }
}

Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)


void solve(){
  string s;
  cin >> s;
  bool b;
  b = (s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) || (s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]) || (s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]);
  if(b) cout << "Yes" << endl;
  else cout << "No" << endl; 
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <map>
using std::set;
using std::sort;
using std::vector;
using std::array;
using std::cin; 
using std::cout;
using std::map;
using std::min;
using std::max;
using std::pair;
#define fastio std::ios_base::sync_with_stdio(false);std::cin.tie(0);
using ll = long long;
int main () {
    fastio;
    ll n;
    cin >> n;
    ll currem = 0;
    for (ll i = 1; i <= 2000000; i++) {
        currem = (currem * 10 + 7) % n; 
        if(currem == 0) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}



Measured memory_bytes: 3608
def main():
    import sys
    input = sys.stdin.buffer.readline
    # from heapq import heappop, heappush
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    BC = [[int(i) for i in input().split()] for j in range(M)]
    BC.sort(key=lambda p: p[1], reverse=True)
    p = 0
    flag = False
    for b, c in BC:
        for i in range(b):
            if A and A[-1] < c:
                A.pop()
                p += c
            else:
                flag = True
                break
        if flag:
            break
    print(sum(A) + p)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65080
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

const int logs = 17;
int skip[17][100000];

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

    vector<int> xs(n);
    for (auto &x: xs) scanf("%d", &x);

    int l, q;
    scanf("%d%d", &l, &q);

    // vector<vector<int>> skip(17, vector<int>(n));

    for (int j = 0; j < n; j++) {
        if (j == n - 1) skip[0][j] = n;
        else skip[0][j] = prev(upper_bound(xs.begin(), xs.end(), xs[j] + l)) - xs.begin();
    }

    for (int i = 1; i < logs; i++) {
        for (int j = 0; j < n; j++) {
            skip[i][j] = skip[i - 1][j];
            if (skip[i][j] < n) skip[i][j] = skip[i - 1][skip[i][j]];
        }

    }

    // for (int i = 0; i < skip.size(); i++) {
    //     for (int j = 0; j < n; j++) {
    //         cerr << i << ", " << j << ": " << skip[i][j] << endl;
    //     }
    //     cerr << endl;
    // }

    //for (auto &q: qs) {
    while (q--) {
        // vector<pair<int, int>> qs(q);
        // for (auto &q: qs) scanf("%d%d", &q.first, &q.second), q.first--, q.second--;
        int ans = 0, cur, goal;
        scanf("%d%d", &cur, &goal);
        cur--, goal--;

        if (cur > goal) swap(cur, goal);

        int span = logs - 1;

        while (cur < goal) {
            // cerr << "* " << cur << endl;
            // int longest = 0, next = cur;

            while (span > 0 && skip[span][cur] > goal) span--;
            cur = skip[span][cur];
            ans += 1 << span;
        }

        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  v.push_back(0);
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  vector<int> ret(N+1, 0);
  for(int i=N; i>0; i--){
    int cnt = 0;
    for(int j=0; i*j<=N; j++){
      cnt += ret[i*j];
    }
    if(v[i] == 0){
      if(cnt%2 == 0) ;
      else ret[i] = 1;
    }else{
      if(cnt%2 == 0) ret[i] = 1;
      else ;    
    }
  }

  vector<int> ret2;
  rep(i,N+1){
    if(ret[i]==1) ret2.push_back(i);
  }

  cout << ret2.size() << endl;
  rep(i,ret2.size()){
    if(i>0) cout << " ";
    cout << ret2[i];
  }
  if(ret2.size() > 0) cout << endl;
  
  return 0;
}


Measured memory_bytes: 3444
from collections import Counter
import sys
input = sys.stdin.readline

def Solve(N:int,S:str) -> int:
    total = Counter(S)
    counter1 = {"R":0,"G":0,"B":0}
    ans = 0

    for i in range(N-2):
        RGB = {"R","G","B"} - {S[i]}
        counter1[S[i]]+=1
        counter2 = {"R":0,"G":0,"B":0}
        for j in range(i+1,N-1):
            counter2[S[j]]+=1
            tmp = list(RGB - {S[j]})
            if len(tmp)==1:
                target = tmp[0]
                ans+=total[target]-counter1[target]-counter2[target]
                if((j - i)+ j <= N -1 and S[(j - i)+ j] == target):
                    ans-=1
    return ans

def main():
    N = int(input())
    S = input()
    print(Solve(N,S))

if __name__ == "__main__":
    main()


Measured memory_bytes: 83172
#include <stdio.h>

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int t;
		scanf("%d",&t);
		n-=t;
	}
	if(n<0)puts("-1");
	else printf("%d",n);
}

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

int main() {
  string S;
  cin >> S;
  bool flag = false;
  int N = S.size();
  string a = S.substr(0, (N - 1) / 2);
  string b = S.substr((N + 3) / 2 - 1, N - (N + 3) / 2 + 1);
  if (a == b) {
    N = a.size();
    for (int i = 0; i < (N + 1) / 2; i++) {
      if (a.at(i) == a.at(N - 1 - i)) {
        if (i == (N + 1) / 2 - 1) {
          flag = true;
        }
      }
      else break;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [-1] + list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(1, N + 1):
    ans += B[A[i] - 1]
    if A[i] == A[i - 1] + 1:
        ans += C[A[i] - 2]

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);

		String str = scan.next();
		String str2 = scan.next();
		int a =0;
		a= Integer.parseInt(str)+Integer.parseInt(str2);
		if(a>=24)
			System.out.println(a-24);
		else
			System.out.println(a);


	}
}

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

int main(int argc, char const *argv[])
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a * b < c * d)	cout << c * d << endl;
	else cout << a * b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n; cin>>n;
    cout<<(n-1)/2<<endl;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = Console.ReadLine().ToCharArray();

            if (c[0] == 'a' || c[0] == 'e' || c[0] == 'i' || c[0] == 'o' || c[0] == 'u')
                Console.WriteLine("vowel");
            else
                Console.WriteLine("consonant");
        }
    }
}

Measured memory_bytes: 13140
n=int(input())
a=list(map(int,input().split()))

mo=10**9+7
an=0
wk=0
ru=[]
for i in a:
    wk+= i
    ru.append(wk%mo)
for i in range(n-1):
    an+=a[i]*(ru[n-1]-ru[i])
    an%=mo

print(an)

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

int main(){
	int a[100], n, cnt = 0, minj, tmp;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
		minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj]) minj = j;
		}
		if (i != minj) {
			tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			cnt++;
		}
	}
	for (int i = 0; i < n; i++){
		cout << a[i];
		if (i != n - 1) cout << " ";
	}
	cout << endl << cnt << endl;
	return 0;
}

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

int main()
{
    string s, t;

    int res = INT_MAX;
    cin >> s >> t;

    for(int i = 0; i <= s.size() - t.size(); ++i)
    {
        int cnt = 0;
        for(int j = i; j < i + t.size(); ++j)
        {
            // cout << "s[j]: " << s[j] << "\t  s[j - i]: " << t[j - i] << endl;
            if(s[j] != t[j - i])
                cnt++;

        }
        res = min(cnt, res);
    }
    cout << res << "\n";
}

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


int main(){
    int i, j, W, H;
    while(1){
        cin >> H >> W;
        if (W==0 && H==0) break;
        for (j = 1; j < H+1; j++){
            for (i = 1; i < W+1; i++){
            cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    } 
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

vector<pii> prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pii> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}
vector<pli> prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pli> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================

ll power_mod(ll k, int n, int mod){
  if(n == 0) return 1;
  ll tmp = power_mod(k, n / 2, mod);
  tmp = (tmp * tmp) % mod;
  if(n % 2 == 0) return tmp;
  return (k * tmp) % mod;
}

ll v_p(int n, int p){
  int res = 0;
  while(n >= p){
    res += (n / p);
    n /= p;
  }
  return res;
}


int main(){
  int n; cin >> n;
  vb prime_judge = Primes(n);
  ll res = 1;
  for(int i = 2; i <= n; i++){
    if(prime_judge[i]){
      res = res * (v_p(n, i) + 1) % MOD;
    }
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,a,max,count=0;
  scanf("%d",&n);
  scanf("%d",&max);
  for(i=0;i<n-1;i++){
    scanf("%d",&a);
    if(max<=a){
      max=a;
      count++;
    }
    else;
    //printf("%d\n",max);
  }
  printf("%d",count+1);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt(), total = 0;
			if (n == 0) break;
			boolean finish = false;
			for (int i = 0; i < 12; i++)
			{
				total += sc.nextInt() - sc.nextInt();
				if (!finish && total >= n)
				{
					System.out.println(i + 1);
					finish = true;
				}
			}
			if (!finish)
			{
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)1e9+10;
const int MOD=(int)1e9+7;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a,b;
    cin>>a>>b;
    cout<<a/__gcd(a,b)*b;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.Iterator;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Random;
    import java.util.Map;
    import java.util.HashMap;
     
    class Main{
    	public static void main(String args[]){
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
    		int K = sc.nextInt();
    		int[] num = new int[N];
    		int one=0,count=0;
    		for(int i=0; i<N; i++){
    		    num[i] = sc.nextInt();
    		    if(num[i] == 1){
    		        one = i; 
    		    }
    		}
    		count = (N-1)/(K-1);
    		if((N-1)%(K-1)!=0)count++;
    		System.out.println(count);
    		
    		
    		/*
    		if(N == K){
    		    System.out.println(1);
    		}else{
        		if(one != 0){
        		    count += one / (K-1);
        		    if(one % (K-1) != 0)count ++;
        		}
        		if(one != N-1){
        		    count += (N - (one + 1)) / (K-1);
        		    if((N - (one + 1)) % (K-1) != 0)count++;
        		}
        		System.out.println(count);
    		}
    		*/
    	}
    }

Measured memory_bytes: 51196
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int h, w, n;
    cin >> h >> w >> n;
    cout << n/max(h, w) + (n%max(h, w) != 0) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int dptw[50];

int fibonacci(int n){
  if(n==0||n==1)return dptw[n]=1;
  if(dptw[n]!=-1)return dptw[n];
  return dptw[n] = fibonacci(n-1)+fibonacci(n-2);
}

int main(){
  int Ntw,i;
  for(i=0;i<50;i++)dptw[i]=-1;

  scanf("%d",&Ntw);
  printf("%d\n",fibonacci(Ntw));

  return 0;
}

    



Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
bool ispa(string s){
    string t = s;
    reverse(s.begin(),s.end());
    bool flag = 1;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) flag = 0;
    }
    return flag;
}
int main(){
   string s;
   cin >> s;
   int n= s.size();
   string s1 = s.substr(0,(n-1)/2);
   string s2 = s.substr((n+3)/2-1,n-1);
   if(ispa(s)&&ispa(s1)&&ispa(s2)) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
	long long int X;
	long long int A= 0;
	long long int B = 0;
	cin >> X;
	int rec = 0;
	for (int i = -1000; i <=1000; i++) {
		for (int j = -1000; j <= 1000; j++) {
			if (X == (i-j) * (pow(i, 4) + pow(i, 3) * j + pow(i * j, 2) + i * pow(j, 3) + pow(j, 4))) {
				A = i;
				B = j;
				rec++;
				break;
			}
		}
		if (rec == 1) {
			break;
		}
	}
	cout << A << " " <<  B << endl;
	return 0;
}

Measured memory_bytes: 3988