akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <numeric>
#include <utility>
#include <set>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0;i<N;i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double sum = (v[0] + v[1])/2;
  for(int i=2;i<N;i++){
    sum = (sum +v[i])/2;
  }
  cout << sum << endl;
  return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n; cin >> n;
    vl a(n);
    rep(i,n)cin >> a[i];
    sort(rall(a));
    ll ma = a[0];
    ll mi = -1;
    ll m_idx = 0;
    rep1(i,n){
        ll num = min(ma - a[i],a[i]);
        if(num > mi)mi = num,m_idx = i;
    }
    cout << ma << " " << a[m_idx] << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static boolean pos(int y1, int m1, int d1, int y2, int m2, int d2){
		
		if(y1<y2){
			return true;
		}
		else if(y1==y2){
			if(m1<m2){
				return true;
			}
			else if(m1==m2){
				if(d1<=d2){
					return true;
				}
			}
		}
		return false;
	}

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

		while(stdIn.hasNext()){
			int y = stdIn.nextInt();
			int m = stdIn.nextInt();
			int d = stdIn.nextInt();

			if(pos(y,m,d,1868,9,7)){
				System.out.println("pre-meiji");
			}
			else if(pos(y,m,d,1912,7,29)){
				System.out.println("meiji "+(y-1867)+" "+m+" "+d);
			}
			else if(pos(y,m,d,1926,12,24)){
				System.out.println("taisho "+(y-1911)+" "+m+" "+d);
			}
			else if(pos(y,m,d,1989,1,7)){
				System.out.println("showa "+(y-1925)+" "+m+" "+d);
			}
			else{
				System.out.println("heisei "+(y-1988)+" "+m+" "+d);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>

int main(){
    int n;
    std::cin>>n;
    std::vector<int> rt(n);
    
    for(int i=0;i<n;i++){
        std::cin>>rt[i];
    }
    int min=rt[0],dmax=rt[1]-rt[0];
    for(int i=1;i<n;i++){
        if(rt[i]-min>dmax){
            dmax=rt[i]-min;
        }
        if(min>rt[i]){
            min=rt[i];
        }
    }
    std::cout<<dmax<<'\n';
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
const int p = 1e6 + 3;
ll fpm(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res *= a;
            res %= p;
        }
        a *= a;
        a %= p;
        b >>= 1;
    }
    return res;
}
ll odw(ll a){
    return fpm(a, p-2);
}

ll odt[p];
ll il[p];
main(){
    ll q;
    cin >> q;
    il[1] = 1;
    for(int i = 2; i <= p; ++i){
        il[i] = il[i-1]*i;
        il[i] %= p;
    }
    while(q--){
        ll x, d, n;
        cin >> x >> d >> n;
        if(x == 0){
            cout << 0 << '\n';
            continue;
        }
        if(d == 0){
            ll ans = fpm(x, n);
            ans %= p;
            cout << ans << '\n';
            continue;
        }
        ll o = odw(d);
        //cerr << x << ' ' << d << ' ' << n << ' ' << o << ' ';
        x *= o;
        x %= p;
        ll u = x + n-1;
        //cerr << u << ' ' << x << ' ';
        if(u >= p){
            cout << 0 << '\n';
        }
        else {
            ll ans = il[u];
            //cerr << il[u] << '\n';
            if(x > 1)
                ans *= odw(il[x-1]);
            ans *= fpm(d, n);
            ans %= p;
            cout << ans << '\n';
        }
    }
}

Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

//#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int N;
int p[100000];

signed main()
{
	cin >> N;
	REP(i, N) cin >> p[i];

	int cnt = 0;
	for (int i = 0; i < N - 1; i++)
	{
		if (p[i] == (i + 1))
		{
			int temp = p[i];
			p[i] = p[i + 1];
			p[i + 1] = temp;
			cnt++;
		}
	}
	if (p[N - 1] == N)
	{
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 640
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

for i in a:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
for j in b:
  if j in d:
    d[j]+=1
  else:
    d[j]=1

e=sorted([[w,v] for v,w in c.items()],reverse=True)
f=sorted([[w,v] for v,w in d.items()],reverse=True)

if len(set(a))==len(set(b))==1 and e[0][1]==f[0][1] and e[0][0]==f[0][0]:
  print(min(len(a),len(b)))
elif e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
elif e[0][0]<f[0][0]:
  print(n-e[1][0]-f[0][0])
elif e[0][0]==f[0][0] and e[0][1]==f[0][1]:
  if e[1][0]>f[1][0]:
    print(n-e[1][0]-f[0][0])
  else:
    print(n-e[0][0]-f[1][0])

Measured memory_bytes: 27104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main() {
    int r, g, b;
    cin >> r >> g >> b;
    cout << ((10*g+b) % 4 == 0 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b;
  scanf("%d%d", &a, &b);
  if (a + b >= a - b && a + b >= a * b) printf ("%d\n", a + b);
  else if (a - b >= a + b && a - b >= a * b) printf ("%d\n", a - b);
  else if (a * b >= a + b && a * b >= a - b) printf ("%d\n", a * b);
  return (0);
}


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

int main(){
	int n;
	int j[110];
	int max,min;
	for(;cin>>n,n!=0;){
		for(int i=0;i<n;i++){
			cin>>j[i];
		}
		max=0;
		min=2000;
		int sum=0;
		for(int i=0;i<n;i++){
			if(max<j[i])max=j[i];
			if(min>j[i])min=j[i];
			sum+=j[i];
		}
		sum-=max+min;
		cout<<sum/(n-2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string str;
int main()
{
	cin>>str;
	if(str.find("AC")!=str.npos)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    // dp[i][j] = i まで見て体力を j にするのに必要な最小のコスト
    vector<vector<int>> dp(N+1, vector<int>(H+1, 1e+9));
    dp[0][0] = 0;
    REP(i, N){
        REP(h, H+1) dp[i+1][h] = dp[i][h];
        REP(h, H+1){
            dp[i+1][h] = min(dp[i+1][h], dp[i+1][max(0, h-A[i])]+B[i]);
        }
    }
    cout << dp[N][H] << endl;

    return 0;
}

Measured memory_bytes: 39424
#include <stdio.h>
#include <stdbool.h>
#define N 8
#define NOT_FREE 1
#define FREE -1
int row[N],col[N],dpos[2*N-1],dneg[2*N-1],p[N][N];
void printBoard(void){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(p[i][j]){
	if(row[i]!=j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE) continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}
int main(){
  int i,j,k,r,c;
  scanf("%d",&k);
  for(i=0;i<N;i++){
    row[i]=col[i]=FREE;
    for(j=0;j<N;j++) p[i][j]=0;
  }
  for(i=0;i<N*2-1;i++) dpos[i]=dneg[i]=FREE;
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      p[i][j]=false;
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    p[r][c]=true;
  }
  putQueen(0);
  return 0;
}

Measured memory_bytes: 572
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#include <bits/stdc++.h>
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, ele;
    cin >>n;
	unordered_set<int> st;
    for(int i = 0; i < n; i++){
		cin >>ele;
		st.insert(ele);
	}
	if(st.size() == n){
		cout <<"YES";
	}
	else{
		cout <<"NO";
	}
	return 0;
}


Measured memory_bytes: 8520
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;
using ll = long long int;

int main(void) {
    int n; cin >> n;
    n %= 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
    else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val (N, A, B) = readLine()!!.split(" ").map { it.toInt() }
    val mod = 1000000007
    val com = COM(mod, 2 * 100000 + 1)
    com.modPow(2, N).let {
        val k = it - com.calculateLarge(N.toLong(), A)
        if(k < 0){
            k + mod
        }else{
            k % mod
        }
    }.let {
        val k = it - com.calculateLarge(N.toLong(), B)
        if(k < 0){
            k + mod
        }else{
            k % mod
        }
    }.let {
        val k = it - 1
        if(k < 0){
            k + mod
        }else{
            k % mod
        }
    }.let { println(it) }
}

class COM(
    val mod: Int,
    val max: Int
) {
    val fac = LongArray(max)
    val finv = LongArray(max)
    val inv = LongArray(max)

    init {
        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1

        for (i in 2 until max) {
            fac[i] = fac[i - 1] * i % mod
            inv[i] = mod - (inv[mod % i] * (mod / i)) % mod
            finv[i] = finv[i - 1] * inv[i] % mod
        }
    }

    fun calculate(n: Int, k: Int): Long {
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod
    }

    fun calculateLarge(n: Long, k: Int): Long {
        var x = n
        var num = 1L
        repeat(k){
            num = (num * x) % mod
            x--
        }
        return num * finv[k] % mod
    }

    fun modPow(x: Int, n: Int): Long {
        if(n == 1){
            return x.toLong()
        }
        if(n % 2 == 0){
            val k = modPow(x, n / 2) % mod
            return k * k % mod
        }else{
            val k = modPow(x, (n - 1) / 2) % mod
            return (x * k * k) % mod
        }
    }
}

Measured memory_bytes: 38892
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <string.h>
#include <string>
#include <complex>
using namespace std;

#define INT_max 2147483647


typedef long long ll;
typedef long double ld;


int mod = 1e9+7;

vector<ll> num;



ll gcd(ll x,ll y){
	if(y > x) return gcd(y,x);
	return x%y ? gcd(y,x%y) : y;
}


ll solve(int x,int y,int z){
	int t = gcd(x,y);
	return gcd(t,z);
}


int main(){
	int N;
	cin>>N;
	ll ans = 0;
	for(int i = 1;i <= N;i++){
		for(int j = 1;j <= N;j++){
			for(int k = 1;k <= N;k++){
				ans += solve(i,j,k);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a[9][9];
    cin>>n;
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            a[i][j]=(i+1)*(j+1);
        }        
    }
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            if(a[i][j]==n){cout<<"Yes";return 0;}
        }        
    }
    cout<<"No";
}




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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int sum = 0;
  int l, r;
  rep(i, N) {
    cin >> l >> r;
    sum += r - l + 1;
  }

  cout << sum << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == b[i] && b[i] == c[i])
            continue;
        if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i])
            res++;
        else
            res += 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    string s;
    cin >> s;
    cout << (char)(s[0] - 'a' + (char)'A');
    cin >> s;
    cout << (char)(s[0] - 'a' + (char)'A');
    cin >> s;
    cout << (char)(s[0] - 'a' + (char)'A');
    cout << endl;
}


Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

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

  int x = 0, mx = 0;
  rep(i, len){
    if(s[i] == 'I') x++;
    else x--;
    chmax(mx, x);
  }
  cout << mx << ln;
}


Measured memory_bytes: 256
import sys
from math import floor,ceil
K=int(input())
A=[int(i) for i in input().split()]
B=A[::-1]
a,b=2,2
for i in range(0,K):
    x=B[i]
    c = ceil(a / x) * x
    if a<=c<=b:
        a = c
        b = floor(b / x) * x + x -1
    else:
        print(-1)
        sys.exit()
    #print(a,b,c,x)
print(a,b)

Measured memory_bytes: 63984
#include <iostream>
#include <math.h>
#define rep(i,n) for(long i=0; i<(n); i++)
using namespace std;

int main(){
  long n,d,count=0;
  cin >> n >> d;
  long x[n],y[n];
  rep(i,n){
    cin >> x[i] >> y[i];
  }
  
  rep(i,n){
    double dis = sqrt(x[i]*x[i] + y[i]*y[i]);
    if(dis <= d){count++;}
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 6772
#include <stdio.h>
int handan(int saki, int ato, int genzai)
{
	int X;		
		
	if(saki<ato){
		X=1;
	}else if(saki>ato){
		X=2;
	}else{
		X=genzai;
	}
	
	return X;
}
int main(void)
{
	int N;
	int a[100000];
	int i,num=1;
	int zougen,genzai;
	
	
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	N--;
	for(i=0;i<N;i++){
		if(a[i]<a[i+1]){
			genzai=1;
			break;
		}else if(a[i]>a[i+1]){
			genzai=2;
			break;
		}
	}
	for(i=i+1;i<N;i++){
		zougen=handan(a[i],a[i+1],genzai);
		if(zougen!=genzai&&genzai!=0){
			num++;
			genzai=0;
		}else{
			genzai=zougen;
		}
	}	
	printf("%d",num);
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#define LEN 100000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int top,tail,n;

void enq(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P deq(){
  P x=Q[top];
  top=(top+1)%LEN;
  return x;
}

int min(int a,int b){
  return a<b ? a:b;
}

int main(){
  int k=0;
  int c;
  int i,q;
  P u;

  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  top=1;
  tail=n+1;

  while(top!=tail){
    u=deq();
    c=min(q,u.t);
    u.t-=c;
    k+=c;
    if(u.t>0)enq(u);
    else{
      printf("%s %d\n",u.name,k);
    }
  }

  return 0;

}



Measured memory_bytes: 11864
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
#include <queue>
const int maxv = 10000050;
bool np[maxv]; int prm[maxv];
inline void sieve() {
  const int n = 10000005;
  int cnt = 0;
  np[1] = true;
  for(int i = 2; i <= n; i ++) {
    if(!np[i]) {
      prm[cnt ++] = i;
    }
    for(int j = 0; j < cnt; j ++) {
      int v = i * prm[j];
      if(v > n) break;
      np[v] = true;
      if(i % prm[j] == 0) break;
    }
  }
}

const int maxn = 305;
int e_siz, o_siz;
bool G[maxn][maxn];
int cp[maxn]; bool vis[maxn];
bool dfs(int x) {
  for(int i = 1; i <= o_siz; i ++) {
    if(G[x][i] && !vis[i]) {
      vis[i] = true;
      if(!cp[i] || dfs(cp[i])) {
        cp[i] = x; return true;
      }
    }
  }
  return false;
}
inline int hungray() {
  int ans = 0;
  for(int i = 1; i <= e_siz; i ++) {
    memset(vis, 0, sizeof(vis));
    if(dfs(i)) ans ++;
  }
  return ans;
}

int C[maxv];
void build_graph() {
  std::vector<int> ep, op;
  for(int i = 1; i < maxv; i ++) {
    if(C[i]) {
      if(i & 1) op.push_back(i);
      else ep.push_back(i);
    }
  }
  e_siz = ep.size(); o_siz = op.size();
  for(int i = 1; i <= e_siz; i ++) {
    for(int j = 1; j <= o_siz; j ++) {
      int dis = ep[i - 1] - op[j - 1];
      if(dis < 0) dis *= -1;
      if(!np[dis]) {
        G[i][j] = true;
      }
    }
  }
}

int main() {
  sieve();
  int n; scanf("%d", &n);
  for(int i = 1; i <= n; i ++) {
    int x; scanf("%d", &x);
    C[x] ^= 1; C[x + 1] ^= 1;
  }
  build_graph();
  int ans = 0;
  int v_1 = hungray(); ans += v_1;
  int e_cnt = e_siz, o_cnt = o_siz;
  if(v_1 < e_cnt || v_1 < o_cnt) {
    e_cnt -= v_1; o_cnt -= v_1;
    ans += (e_cnt >> 1) << 1; e_cnt &= 1;
    ans += (o_cnt >> 1) << 1; o_cnt &= 1;
    if(e_cnt) ans += 3;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 51456
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

int main()
{
    map< string , int > mp;
    string a , b , c;
    cin >> a >> b;
    int k , d; cin >> k >> d;
    mp[a] = k;
    mp[b] = d;
    cin >> c;
    mp[c]--;
    cout << mp[a] << " " << mp[b] << endl;
    return 0;
}
/*



*/



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

using namespace std;

int main() {

	int n;
	cin >> n;

	long long ooldl = 2;
	long long oldl = 1;
	if (n == 1) { cout << 1 << endl; return 0; }
	long long l = 0;
	for (int i = 2; i <= n; i++) {
		l = oldl + ooldl;
		ooldl = oldl;
		oldl = l;
	}
	cout << l << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string s[10001];
string t;

int check(int v){
	for(int i=0;i<min(s[v].size(),t.size());i++){
		if(s[v][i]=='?'){
			if(t[i]!='a')return 2;
		}else{
			if(s[v][i]<t[i])return 2;
			if(s[v][i]>t[i])return 0;
		}
	}
	if(s[v].size()>t.size())return 0;
	if(s[v].size()<t.size())return 2;
	return 1;
}

int check2(int v){
	for(int i=0;i<min(s[v].size(),t.size());i++){
		if(s[v][i]=='?'){
			if(t[i]!='z')return 0;
		}else{
			if(s[v][i]<t[i])return 2;
			if(s[v][i]>t[i])return 0;
		}
	}
	if(s[v].size()>t.size())return 0;
	if(s[v].size()<t.size())return 2;
	return 1;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	cin >> t;
	int cnt=0,l=0;
	for(int i=0;i<n;i++){
		int v=check(i);
		int v2=check2(i);
		if(v==1 || v2==1)cnt++;
		else{
			if(v2==2)l++;
			if(v==2 && v2!=2)cnt++;
		}
	}
	for(int i=l;i<=l+cnt;i++){
		printf("%d%c",i+1,i==l+cnt?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

        long n = sc.nextLong();

        long ans = n-1;
        for (int x = 2; x < Math.sqrt(n)+5; x++) {
            long y = n / x;

            if (x * y == n)
                ans = Math.min(x+y-2, ans);
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 22612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


struct ModInt{
    static const LL MOD = 1e+9 + 7;
    LL v;
    ModInt():v(0){}
    ModInt(LL op):v(op){}
    ModInt operator+(ModInt op) const{ return (v + op) % MOD; }
    ModInt operator-(ModInt op) const{ return (v - op + MOD) % MOD; }
    ModInt operator*(ModInt op) const{ return (v * op) % MOD; }
    ModInt operator/(ModInt op) const{ return (v * op.inverse()) % MOD; }
    ModInt operator%(LL op) = delete;
    ModInt operator+=(ModInt op){ return v = (v + op) % MOD; }
    ModInt operator-=(ModInt op){ return v = (v - op + MOD) % MOD; }
    ModInt operator*=(ModInt op){ return v = (v * op) % MOD; }
    ModInt operator/=(ModInt op){ return v = (v * op.inverse()) % MOD; }
    ModInt operator-() const{ return MOD - v; }
    bool operator==(ModInt op) const{ return v == op.v; }
    bool operator!=(ModInt op) const{ return v != op.v; }
    ModInt inverse() const{ return pow(MOD-2); }
    ModInt pow(LL n) const{
        if(n < 0) return pow(MOD-1 + n);
        if(n == 0) return 1;
        ModInt res = pow(n/2);
        return res * res * ((n&1)?ModInt(v): ModInt(1));
    }
    LL get() const{ return v; }
private:
    operator LL() const{ return v; }
};
istream& operator>>(istream& st, ModInt& m){ st>>m.v; return st; }
ostream& operator<<(ostream& st, const ModInt& m){ st<<m.v; return st; }

vector<ModInt> factorial(LL n){
    vector<ModInt> res(n, 1);
    for(LL i = 2; i < n; ++i) res[i] = res[i-1] * ModInt(i);
    return res;
}



int main(){
    LL n;
    cin >> n;
    vector<LL> x(n);
    for(LL i = 0; i < n; ++i){
        cin >> x[i];
    }
    ModInt base = factorial(n)[n-1];
    ModInt exp = 0;
    ModInt ans = 0;

    for(LL i = 0; i+1 < n; ++i){
        //cerr << "base=" << base.get() << ", exp=" << exp << endl;
        ModInt w = ModInt(x[i+1] - x[i]);
        exp += base;
        ans += w * exp;
        base *= ModInt(i+2).inverse() * ModInt(i+1);
    }
    cout << ans.get() << endl;
    return 0;
}



Measured memory_bytes: 2552
from collections import defaultdict, Counter
import itertools

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    min_num, max_num = min(data.keys()), max(data.keys())

    ans = 0
    for i in range(min_num - 1, max_num + 1):
        kari = data[i - 1] + data[i + 1] + data[i]
        ans = max(kari, ans)
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 57452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	long long n,k;
	cin>>n>>k;
	vector<long long>a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	long long ub=2e18,lb=-2e18;
	while(ub-lb>1){
		ll mid=(ub+lb)/2,cnt=0;
		for(int i=0;i<n-1;i++)
			if(a[i]>0)
				if(a[n-1]*a[i]<=mid)
					cnt+=(n-1)-(i+1)+1;
				else if(a[i+1]*a[i]>mid)
					continue;
				else{
					long long ub2=n-1,lb2=i+1;
					while(ub2-lb2>1){
						long long mid2=(ub2+lb2)/2;
						if(a[i]*a[mid2]<=mid)
							lb2=mid2;
						else
							ub2=mid2;
					}
					cnt+=ub2-(i+1);	  
				}
			else{
				if(a[i+1]*a[i]<=mid)
					cnt+=(n-1)-(i+1)+1;
				else if(a[n-1]*a[i]>mid)
					continue;
				else{
					long long ub2=n-1,lb2=i+1;
					while(ub2-lb2>1){
						long long mid2=(ub2+lb2)/2;
						if(a[i]*a[mid2]>mid)
							lb2=mid2;
						else
							ub2=mid2;
					}
				cnt+=n-1-lb2;
				}
			}
		if(cnt<k)
			lb=mid;
		else
			ub=mid;
	}
	cout<<ub<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int a[200005], b[200005];
int main() {
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int v = 1<<28;
    int ans = 0;
    for ( int v = (1<<28); v; v>>=1) {
        // 上位bitから順に判定
        rep(i, n) a[i] &= (v * 2 - 1);
        rep(i, n) b[i] &= (v * 2 - 1);
        sort(a, a+n); sort(b, b+n);
        int t = 0;
        for ( int i = n - 1, j = 0, k = 0, l = 0; i >= 0; i-- ) {
            while( j < n && a[i]+b[j] < v) j++;
            while( k < n && a[i]+b[k] < 2 * v) k++;
            while( l < n && a[i]+b[l] < 3 * v) l++;
            t += k + ( n - j - l);
            t &= 1;
        }
        if (t) ans |= v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX_N = 10000;

struct UnionFind{
	static const int MAX_UF = MAX_N;

	int pars[MAX_UF];
	int ranks[MAX_UF];

	void init(int n){
		for(int i=0; i<n; i++){
			pars[i] = i;
			ranks[i] = 0;
		}
	}

	int get_root(int x){
		if(pars[x] == x){
			return x;
		}
		else{
			return pars[x] = get_root(pars[x]);
		}
	}

	void merge(int x, int y){
		x = get_root(x);
		y = get_root(y);
		if( x == y ){
			return ;
		}

		if(ranks[x] < ranks[y]){
			pars[x] = y;
		}
		else if(ranks[y] < ranks[x]){
			pars[y] = x;
		}
		else{
			pars[x] = y;
			ranks[y]++;
		}
	}

	bool is_same(int x, int y){
		return get_root(x) == get_root(y);
	}
};

UnionFind uf;

int N, M;
int xs[MAX_N], ys[MAX_N];

int sq(int x){
	return x*x;
}

int sq_dist(int x1, int y1, int x2, int y2){
	return sq(x1-x2) + sq(y1-y2);
}

void init(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++){
		scanf("%d%d", xs+i, ys+i);
	}
}

struct edge{
	int v, u, dist;
};

bool operator<(const edge& lhs, const edge& rhs){
	return lhs.dist < rhs.dist;
}

double solve(){
	vector<edge> es;
	es.reserve(M);

	for(int i=0; i<M; i++){
		int v, u;
		scanf("%d%d", &v, &u);
		v--; u--;
		es.push_back((edge){v, u, sq_dist(xs[v],ys[v],xs[u],ys[u])});
	}

	sort(es.rbegin(), es.rend());

	uf.init(N);

	double ans = 0.0;
	for(int i=0; i<M; i++){
		edge e = es[i];
		if(uf.is_same(e.v, e.u)){
			ans += sqrt(e.dist);
		}
		else{
			uf.merge(e.v, e.u);
		}
	}

	return ans;
}

int main(){
	init();
	printf("%.8f\n", solve());

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* 比較関数 */
int compar(const char *a, const char *b){
    return strcmp(a, b);
}

int main(){
    int N, count;
    char buf;
    char S[300000][20] = {};
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        //ぶち込む
        scanf("%s", S[i]);
    }

    //ソートする
    qsort(S, N, sizeof(char)*20,compar);

    //ひとつ前と違ったらカウント増やす
    count = 1;
    for(int i=1; i<N; i++){
        if(strcmp(S[i-1], S[i]))count++;
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 11280
from collections import defaultdict
from bisect import bisect_left, bisect_right
N = int(input())
dic = defaultdict(list)
for i in range(N):
  F = [int(c) for c in input().split()]
  for j in range(10):
    if F[j]==1:
      dic[j] += [i]

p = {}
for i in range(N):
  P = [int(c) for c in input().split()]
  p[i] = P[:]

ans = []
for i in range(1,2**10):
  log = []
  x = i
  m = 0
  for j in range(10):
    if x%2==1:
      log += dic[j]
    x = x>>1
  
  log.sort()
  for i in range(N):
    l = bisect_left(log, i)
    r = bisect_right(log, i)
    m += p[i][r-l]
#  print(m)
  if ans==[]:
    ans = m
  elif ans<m:
    ans = m

print(ans)

Measured memory_bytes: 45788
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s = input().rstrip()
    t = input().rstrip()

    len_s = len(s)

    for i in range(len_s):
        if s[i] != t[i]:
            print("No")
            exit()

    print("Yes")





if __name__ == "__main__":
    resolve()



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;


int main(){
	
	int n,m;cin >> n >> m;
	set<ll> sa;
	vector<ll> A(n);
	REP(i,n){
		cin >> A[i];
		sa.insert(A[i]);
	}
	set<ll> sb;
	vector<ll> B(m);
	REP(i,m){
		cin >> B[i];
		sb.insert(B[i]);
	}
	
	if(sa.size() != n || sb.size() != m){
		cout << 0 << endl;
		return 0;
	}
	
	sort(ALL(A),greater<ll>());
	sort(ALL(B),greater<ll>());
	
	int placeA = 0;
	int placeB = 0;
	
	ll ans = 1;
	
	SHOW1d(A,n);
	SHOW1d(B,m);
	
	for(ll i = n*m;i > 0;i--){
		int cou = 0;
		if(placeA < n && i == A[placeA])placeA++,cou+=1;
		if(placeB < m && i == B[placeB])placeB++,cou+=2;
		if(cou == 3)continue;
		else if(cou == 2){
			ans *= placeA;
		}
		else if(cou == 1){
			ans *= placeB;
		}
		else {
			ans *= max(0LL, (placeA * placeB - (n*m - i)));
		}
		ans %= MOD;
	}
	
	cout << ans << endl;
	
	
	
	
	return 0;
}


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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n, m, u, v, s, t;
	cin >> n >> m;
	vector<vector<int>> Adj(n + 1);
	while (m--)
	{
		cin >> u >> v;
		Adj[u].pb(v);
	}
	cin >> s >> t;
	vector<vector<bool>> Vis(3, vector<bool>(n + 1));
	vector<vector<int>> Dist(3, vector<int>(n + 1, mod));
	Vis[0][s] = true;
	queue<pair<int, int>> Q;
	Q.push({s, 0});
	Dist[0][s] = 0;
	while (!Q.empty())
	{
		auto top = Q.front();
		Q.pop();
		if (top.s == 0 && top.f == t)
		{
			cout << Dist[0][t] / 3 << '\n';
			return;
		}
		int next = (top.s + 1) % 3;
		for (auto child : Adj[top.f])
			if (!Vis[next][child])
			{
				Vis[next][child] = true;
				Q.push({child, next});
				Dist[next][child] = Dist[top.s][top.f] + 1;
			}
	}
	cout << -1 << '\n';
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
void solve() {
    cin >> n;

    int c = 0;
    int tmp = n;
    while (tmp != 0) {
        ++c;
        tmp /= 10;
    }

    ll ans = 0;
    reps(l, 9) reps(r, 9) {
        ll res1 = 0, res2 = 0;
        rep(i, c) {
            int e = (l + 1) * pow(10, i);
            loop(j, l * pow(10, i), e) {
                if (j > n) break;
                if (j % 10 != r) continue;
                ++res1;
            }
            int e2 = (r + 1) * pow(10, i);
            loop(j, r * pow(10, i), e2) {
                if (j > n) break;
                if (j % 10 != l) continue;
                ++res2;
            }
        }
        ans += res1 * res2;
    }

    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


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

string s,t;

int main()
{
	int n;
	scanf("%d",&n);
	cin>>s>>t;
	for(int i=0;i<n;i++)
	{
		cout<<s[i]<<t[i];
	}
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define p_b push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s[3]==s[2] && s[5]==s[4])
    {
        cout << "Yes";
    }
    else
    {
        cout << "No" ;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef struct{
    int count;
    string s="OUT";
}OUT;
typedef struct{
    int count;
    string s="HOMERUN";
}HOME;
typedef struct{
    int count;
    string s="HIT";
}HIT;
typedef struct{
    int count;
}RUN;
typedef pair<int, int> pii;
int main(){
    int n; cin>>n;
    int ans=0;
    OUT out; HOME home; HIT hit; RUN run;
    out.count=0; home.count=0; hit.count=0; run.count=0;
    string temp;
    while(cin>>temp){
        if(temp==home.s){
            ans+=run.count+1;
            run.count=0;
        }
        if(temp==hit.s){
            run.count++;
            if(run.count>3){ans++; run.count-=1;}
        }
    if(temp==out.s){
        out.count++;
        if(out.count%3==0){cout<<ans<<endl;ans=0;run.count=0;}
        if(out.count==(n*3))return 0;
    }
    }
}

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

long long FloorSum(long long n, long long m, long long a, long long b) {
    long long ret = 0;
    if (a >= m) ret += ((n-1)*n*(a/m))>>1,a%=m;
    if (b >= m) ret += n*(b / m),b%=m;
    long long y = (a * n + b) / m, x = (y * m - b);
    if (y == 0) return ret;
    ret += (n - (x + a - 1) / a) * y;
    ret += FloorSum(y, a, m, (a - x % a) % a);
    return ret;
}

using ll = long long;
int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int Q; cin >> Q;
    while(Q--){
        ll N,M,A,B; cin >> N >> M >> A >> B;
        cout << FloorSum(N,M,A,B) << endl;
    }
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>

using namespace std;
int main(){
    int N;
    string A,B,C;
    cin >> N >> A >> B >> C;

    int cnt = 0;
    for(int i=0; i<N; i++){
        if (A[i]==B[i] && B[i]==C[i])continue;
        else if(A[i] == B[i] || B[i] == C[i] || C[i] == A[i])cnt++;
        else cnt+=2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

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

int main()
{
    int n,i;
    for(i=0;i<50;i++)
    {
        dp[i]=-1;
    }

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

    return 0;
}


Measured memory_bytes: 2112
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll dp[105][100005]={0};
int main(){
	ll n,W;cin>>n>>W;
	ll w[n+1],p[n+1];
	for(ll i=1;i<=n;i++)cin>>w[i]>>p[i];
	for(ll i=0;i<105;i++)for(ll j=1;j<100005;j++)dp[i][j]=1e15;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=100000;j++){
			if(j<p[i])dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=dp[i-1][j];
				dp[i][j]=min(dp[i-1][j-p[i]]+w[i],dp[i][j]);
			}
		}
	}
	ll ans=0;
	for(ll j=1;j<=100000;j++){
		if(dp[n][j]<=W)ans=max(ans,j);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 82432
#include <bits/stdc++.h>
using namespace std;
bool vis[505][505];
int dis[505][505];
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=0;i<n*n;i++){
		int x=i/n, y=i%n;
		dis[x][y]=min({x, y, n-1-x, n-1-y});
	}
	memset(vis, false, sizeof vis);
	long long ans=0;
	for(int i=0;i<n*n;i++){
		int z;
		cin>>z;
		z--;
		int X=z/n, Y=z%n;
		ans+=dis[X][Y];
		vis[X][Y]=true;
		queue<pair<int, int>>q;
		q.push({X, Y});
		while(!q.empty()){
			int x=q.front().first, y=q.front().second;
			q.pop();
			for(int j=0;j<4;j++){
				if(x+dx[j]>=0 && x+dx[j]<n && y+dx[j]>=0 && y+dx[j]<n && dis[x+dx[j]][y+dy[j]]>dis[x][y]+1-(int)(vis[x][y])){
					dis[x+dx[j]][y+dy[j]]=dis[x][y]+1-(int)(vis[x][y]);
					q.push({x+dx[j], y+dy[j]});
				}
			}
		}
		/*for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<dis[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;*/
	}
	cout<<ans;
}

Measured memory_bytes: 4876
from collections import deque
n =int(input())
a = [0]+list(map(int, input().split()))
d = deque()
cnt=0
for i in range(n,0,-1):    
  for j in range(i,n+1,i):
    if a[j]==0:
      continue
    cnt+=1
  b = cnt%2
  a[i] = b
  if b == 1:
    d.appendleft(i)
  cnt = 0
print(len(d))
print(' '.join(map(str,d)))

Measured memory_bytes: 26012
import java.util.*;

public class Main{
	public static void main(String[] args){
		//new Main().printHelloWorld();
		//System.out.println(new Main().ITP1_1_B(Integer.parseInt(new Scanner(System.in).next())));
		//new Main().ITP1_1_C();
		//new Main().ITP1_1_D();
		//new Main().ITP1_2_A();
		//new Main().ITP1_2_B();
		//new Main().ITP1_2_C();
		//new Main().ITP1_2_D();
		//new Main().ITP1_3_A();
		//new Main().ITP1_3_B();
		//new Main().ITP1_3_C();
		new Main().ITP1_3_D();
	}

	public void printHelloWorld(){
		System.out.println("Hello World");
	}

	public int ITP1_1_B(int x){
		return x*x*x;
	}

	public void ITP1_1_C(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println(a*b + " " + 2*(a+b));
	}

	public void ITP1_1_D(){
		int seconds = new Scanner(System.in).nextInt();
		System.out.println(seconds/3600 + ":" + (seconds%3600)/60 + ":" + (seconds%3600)%60);
	}

	public void ITP1_2_A(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println((a==b)?"a == b":(a > b)?"a > b":"a < b");
	}

	public void ITP1_2_B(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		System.out.println((a < b && b < c)?"Yes":"No");
	}

	public void ITP1_2_C(){
		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		for(int i=0;i<a.length-1;i++){
			for(int j=i+1;j<a.length;j++){
				if(a[i] > a[j]){
					int t=a[i];a[i]=a[j];a[j]=t;
				}
			}
		}
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}

	public void ITP1_2_D(){
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int h = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		System.out.println((x+r<=w && x-r>=0 && y+r<=h && y-r>=0)?"Yes":"No");
	}

	public void ITP1_3_A(){
		for(int i=0;i<1000;i++){
			System.out.println("Hello World");
		}
	}

	public void ITP1_3_B(){
		Scanner scan = new Scanner(System.in);
		int i = 1;
		while(scan.hasNext()){
			int x = scan.nextInt();
			if(x == 0){
				break;
			}
			System.out.println("Case " + i + ": " + x);
			i++;
		}
	}

	public void ITP1_3_C(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int x = scan.nextInt();
			int y = scan.nextInt();
			if(x == 0 && y == 0){
				break;
			}
			System.out.println((x < y)?x+" "+y:y+" "+x);
		}
	}

	public void ITP1_3_D(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int count=0;
		for(int i=a;i<=b;i++){
			if(c%i==0){
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 26272
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  ll n; cin >> n;
  int ans = 1e9;
  for(ll i = 1; i*i <= n; ++i) {
    if(n%i == 0) {
      ll a = i;
      ll b = n/i;
      string sa = to_string(a);
      string sb = to_string(b);

      int f = max(sa.length(), sb.length());
      ans = min(ans, f);
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N, K;
    cin >> N >> K;

    cout << min(N%K, K-N%K) << endl;
}


Measured memory_bytes: 256