akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

const int N = 105;
const int INF = 1e9 + 7;
int n, m;
char c[N][N];
int f[N][N];

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> c[i][j];

	f[1][1] = (c[1][1] != '.');
	for (int s = 3; s <= n + m; s++) {
		for (int x = max(s - m, 1); x <= n && x < s; x++) {
			int y = s - x;
			f[x][y] = 1e9 + 7;
			if (x > 1) f[x][y] = min(f[x][y], f[x - 1][y] + (c[x - 1][y] != c[x][y]));
			if (y > 1) f[x][y] = min(f[x][y], f[x][y - 1] + (c[x][y - 1] != c[x][y]));
		}
	}
	cout << (((c[n][m] != '.') + f[n][m] + 1) >> 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (ll i = (srt); i < (ll)(end); i++)
#define INF 1001001001

int main()
{
    string s;
    cin>>s;
    ll num;
    ll ans=INF;
    rep(i,0,s.size()-2){
        num = 100*(s[i]-'0') + 10*(s[i+1]-'0') + s[i+2]-'0';
        ans = min(abs(num-753),ans);
    } 
    cout<<ans<<endl;
    return 0;
}

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

void Main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<int> mh(n, 0);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        mh[a-1] = max(mh[a-1], h[b-1]);
        mh[b-1] = max(mh[b-1], h[a-1]);
    }
    
    int n_good = 0;
    for (int i = 0; i < n; i++)
    {
        if(h[i] > mh[i]){
            n_good++;
        }
    }
    
    cout << n_good << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

signed main()
{
//	freopen("CASTEL.inp", "r", stdin); freopen("CASTEL.out", "w", stdout);
    fastio();

    ll n; cin >> n;

    ll x = 100;
    int cnt = 0;
    while (x < n) {
        x = x + x / 100;
        cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

#define MAX 1000000

int H, A[MAX+1];

void maxHeapify(int i){

  int l, r, largest;
  int tmp;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A [i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int main() {

  int i;
  
  scanf("%d", &H);

  for(i=1; i<=H; i++) scanf("%d", &A[i]);

  for(i=H/2; i>=1; i--) maxHeapify(i);

  for(i=1; i<=H; i++){
    if(i == H) printf(" %d\n", A[i]);
    else printf(" %d", A[i]);
  }
}



Measured memory_bytes: 3696
#include<stdio.h>
int main() {
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) {
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=0;i--) {
        printf("%d",a[i]);
        if(i!=0) printf(" ");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2660
#include<bits/stdc++.h>
using namespace std;
string s;
int n,a[101],b[101];
 
void kk(int x,int p){
  for(int i=0;i<x;i++){
    if(s[p]!='z')s[p]++;
    else s[p]='a';
  }
}
 
int main(){
  while(cin>>n,n){
    cin>>s;
 
    for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
    }
    reverse(a,a+n);
    reverse(b,b+n);
     
    for(int i=0;i<n;i++){
       
      swap(s[a[i]-1],s[b[i]-1]);
      int x=abs(a[i]-b[i]);
       
      kk(x,a[i]-1);
      kk(x,b[i]-1);
       
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 3040
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int main(void){
  int ans=1;
  char letter[2][4]={"No","Yes"};
  char s[100];
  scanf("%s",s);
  int l=strlen(s);
  FOR(i,l/2){
    if(s[i]!=s[l-1-i])ans=0;
  }
  for(int i=(l+3)/2-1;i<l-1;i++){
    if(s[i]!=s[(l+3)/2-i+l-2])ans=0;
  }
  PRS(letter[ans]);
  return 0;
}

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

vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll a=2; a*a<=N; a++) {
        if (N%a != 0) continue;
        ll ex = 0; // 指数

        while (N%a == 0) {
            ex++;
            N /= a;
        }
        
        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;    
}

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

    ll n; cin >> n;

    auto pf = prime_factorize(n);
    ll res = 0;

    for (auto p : pf) {
        ll e = p.second;
        ll tmp = 0, cur = 1;
        while (e >= cur) e -= cur++, ++tmp;
        res += tmp;
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,f,t) for (int i=(f);i<=(t);++i)
#define per(i,f,t) for (int i=(f);i>=(t);--i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fr first
#define sc second
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<int> vi;

const int W = (int)1e5+10;
const int N = 111;
int w[N], v[N];
ll dp[N][W];
int n;
int m;

int main() {
    scanf("%d %d", &n, &m);
    rep(i,1,n){
        scanf("%d%d",&w[i],&v[i]);
    }
    rep(i,0,m){
        dp[0][i]=0;
    }
    rep(i,1,n){
        rep(j,0,m){
            dp[i][j]=dp[i-1][j];
            if(j>=w[i] && (dp[i-1][j-w[i]]+v[i]>dp[i][j])) {
                dp[i][j]=dp[i-1][j-w[i]]+v[i];
            }
        }
    }
    printf("%lld\n", dp[n][m]);
}



Measured memory_bytes: 80128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int x;
  cin >> x;
  if(x%7==0){
    cout << "thu" << endl;
  }else if(x%7==1){
    cout << "fri" << endl;
  }else if(x%7==2){
    cout << "sat" << endl;
  }else if(x%7==3){
    cout << "sun" << endl;
  }else if(x%7==4){
    cout << "mon" << endl;
  }else if(x%7==5){
    cout << "tue" << endl;
  }else if(x%7==6){
    cout << "wed" << endl;
  }
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;


int main() {
    long long N, M;
    cin >> N >> M;

    if (N>M) {
        long long X=N;
        N=M;
        M=X;
    }

    if ( N==1 && M==1) {
        cout << 1 << endl;
    } else if (N==1 && M==2) {
        cout << 0 << endl;
    } else if (N==1 && M>=3) {
        cout << M-2 << endl;
    } else if (N==2 && M==1) {
        cout << 0 << endl;        
    } else if (N==2 && M==2) {
        cout << 0 << endl;                
    } else if (N==2 && M>=3) {
        cout << 0 << endl;                        
    } else if (N>=3 && M==1) {
        cout << N-2 << endl;                        
    } else {
        cout << (N-2)*(M-2) << endl;                                
    }

}


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

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,x,l,ans=0,c=-1e9;
    cin>>n;
    pair<int,int> v[n];
    for (int i=0;i<n;++i)
    {
        cin>>x>>l;
        v[i]={x+l,x-l};
    }
    sort(v,v+n);
    for (int i=0;i<n;++i)
    {
        if (v[i].second<c)
            continue;
        ++ans;
        c=v[i].first;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

int main() {
	int K;
	scanf("%d", &K);
	if (K == 1) return !puts("1\n1");
	int n = (K + 3) / 4 * 2;
	printf("%d\n", n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			printf("%d%c", (i % 2 && n + (i + j) % n < K ? n : 0) + (i + j) % n + 1, " \n"[j + 1 == n]);
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

class modint {
  private:
    ll m_val;
    ll m_mod;
  public:
    constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
    constexpr modint(const ll x) : m_val(0), m_mod(0) { m_mod = MOD; m_val = x % m_mod; }
    constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) { m_mod = mod; m_val = x % m_mod; }
    constexpr ll val() const { return m_val; }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) {
      m_val += rhs.m_val;
      if (m_val >= m_mod) m_val -= m_mod;
      return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
      if (m_val < rhs.m_val) m_val += m_mod;
      m_val -= rhs.m_val;
      return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
      m_val = m_val * rhs.m_val % m_mod;
      return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
      *this *= rhs.pow(m_mod - 2);
      return *this;
    }
    constexpr modint pow(ll n) const {
      if (n == 0) return 1;
      modint o = pow(n >> 1);
      o *= o;
      if (n & 1) o *= *this;
      return o;
    }
    friend ostream& operator<<(ostream& os, const modint &a) { os << a.val(); return os; }
};

int main() {
  ll x, y;
  cin >> x >> y;

  ll n = 0, m = 0;
  n = (2*x-y)/3;
  m = (2*y-x)/3;

  if (n < 0 || m < 0 || (x+y)%3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  modint a = 1;
  modint b = 1;
  modint c = 1;
  for (ll i = 1; i <= n+m; ++i) {
    a = a * i;
  }
  for (ll i = 1; i <= n; ++i) {
    b = b * i;
  }
  for (ll i = 1; i <= m; ++i) {
    c = c * i;
  }

  cout << a/(b*c) << endl;

  return 0;
}


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

int main() {
  int n, k; cin >> n >> k;
  int dp[n], h[n];
  for(int i = 0; i < n; i++) cin >> h[i];

  dp[0] = 0;
  for(int i = 1; i < n; i++) {
    dp[i] = INT_MAX;
    for(int j = 1; j <= k; j++) {
      int cost = i-j >= 0 ? dp[i-j] + abs(h[i-j]-h[i]) : INT_MAX;
      dp[i] = min(dp[i], cost); 
    }
  } 
  
  cout << dp[n-1];
  return 0;
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
mat=[]
v=[]
for i in range(n):
    a=list(map(int,input().split()))
    mat.append(a)

for j in range(m):
    v.append(int(input()))

for i in range(n):
    w = 0
    for j in range(m):
        w += mat[i][j]*v[j]
    print(w)



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

#define INF 2e9
#define ll long long

using namespace std;

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int h,w;
    cin>>h>>w;
    
    for(int i=0;i<w+2;i++)cout<<'#';
    cout<<endl;

    for(int i=0;i<h;i++){
        string s;
        cin>>s;
        cout<<'#'<<s<<'#'<<endl;
    }

    for(int i=0;i<w+2;i++)cout<<'#';
    cout<<endl;

    return 0;
}




Measured memory_bytes: 256
h,w = map(int,input().split())
A = [list(input()) for _ in range(h)]
B = []
C = []
for Row in A:
    if set(Row)!={'.'}: B.append(Row)
B = [Row for Row in zip(*B)]
for Row in B:
    if set(Row)!={'.'}: C.append(Row)
for Row in zip(*C):
    print(''.join(Row))

Measured memory_bytes: 38256
def count(value, P):
    cnt = 0
    for p in P:
        if p & value == value:
            cnt += 1
    return cnt


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    P = []
    for i in range(N):
        s = 0
        for j in range(i, N):
            s += A[j]
            P.append(s)
    retval = 0
    for idx in range(40, -1, -1):
        tmp = retval + 2**idx
        if count(tmp, P) >= K:
            retval = tmp
    print(retval)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65788
def solution():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k, n+2):
        smallest = (i-1) * i // 2
        largest = (n-i+1) * i + smallest
        ans += largest - smallest + 1
    ans %= 10 ** 9 + 7
    print(ans)

solution()


Measured memory_bytes: 63212
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] L = new int[N];
		for(int i = 0; i < N; i++) L[i] = sc.nextInt();
		int ans = 1;
		int sum = 0;
		
		for(int i = 0; i < N; i++) {
			sum += L[i];
			if(sum <= X){
				++ans;
			}
		}
			System.out.println(ans);
	}
}

Measured memory_bytes: 24916
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if(N == 1){
    cout << 0 << endl;
    return 0;
  }

  ll sqN = (ll)sqrt(N);
  queue<ll> que;
  vl prime(sqN + 2, 1);
  prime[0] = 0;
  prime[1] = 0;

  rep2(i, 2, sqN + 2){
    if(prime[i] == 0) continue;

    ll cnt = 0;
    while(N % i == 0){
      cnt++;
      N /= i;
    }
    if(cnt > 0) que.push(cnt);
    
    ll j = 2*i;

    while(j <= sqN + 1){
      prime[j] = 0;
      j += i;
    }
  }

  if(que.empty()){
    cout << 1 << endl;
    return 0;
  }

  ll ans = 0;

  if(N > 1) ans++;
  
  while(!que.empty()){
    ll front = que.front();
    que.pop();

    ll n = 1;
    while(n*(n + 1) / 2 < front) n++;

    if(front == n*(n + 1)/2){
      ans += n;
    } else{
      ans += n - 1;
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 11244
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std::chrono; 

int main()
{ 
  // input_from_file
  fastIO
  ll l,r,n,ans=0;cin>>l>>r>>n;
  if(l%n==0)  ans++;
  l=(l/n)*n;
  cout<<ans+(r-l)/n;
  return 0;
}  



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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string W=in<string>(),S;
	map<string,int> C;
	while(cin>>S){
		if(S=="END_OF_TEXT") break;
		for(int i=0;i<S.size();i++){
			S[i] = tolower(S[i]);
		}
		C[S]++;
	}
	out(C[W]);
	return 0;
}



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

using namespace std;



int main() {

    int n;
    cin >> n;

    int a[n];

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

    int color[9] = {};

    for (int i = 0; i<n; ++i) {
        if (a[i] >= 1 && a[i] <= 399) {
            color[0] = 1;
        }
        if (a[i] >= 400 && a[i] <= 799) {
            color[1] = 1;
        }
        if (a[i] >= 800 && a[i] <= 1199) {
            color[2] = 1;
        }
        if (a[i] >= 1200 && a[i] <= 1599) {
            color[3] = 1;
        }
        if (a[i] >= 1600 && a[i] <= 1999) {
            color[4] = 1;
        }
        if (a[i] >= 2000 && a[i] <= 2399) {
            color[5] = 1;
        }
        if (a[i] >= 2400 && a[i] <= 2799) {
            color[6] = 1;
        }
        if (a[i] >= 2800 && a[i] <= 3199) {
            color[7] = 1;
        }
        if (a[i] >= 3200) {
            color[8]++;
        }
    }

    int min = 0;
    for (int i = 0; i<=7; ++i) {
        if (color[i] == 1) min++;
    }

    int max = 0;
    if (color[8] != 0) max = min + color[8]; else max = min;

    if (min == 0) {
        min = 1;
    }

    cout << min << " " << max << '\n';

    return 0;
}

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

#define int long long
#pragma GCC optimize ("O3")
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359


/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")



#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n,p,q;
pii arr[55];
int ans=0,temp=0;
bool vis[55];

void explore(int so)
{
	vis[so]=true;

	rep(i,0,n)
	{
		if (vis[i])continue;
		if ((arr[so].ff-arr[i].ff==p)&&(arr[so].ss-arr[i].ss==q))explore(i);
		else if ((arr[so].ff-arr[i].ff==-p)&&(arr[so].ss-arr[i].ss==-q))explore(i);
	}

}
void solve()
{
	cin>>n;ans=n;
	rep(i,0,n)cin>>arr[i].ff>>arr[i].ss;

	rep(i,0,n)
	{
		rep(j,i+1,n)
		{
			p=arr[j].ff-arr[i].ff;
			q=arr[j].ss-arr[i].ss;
			memset(vis,0,sizeof vis);temp=0;
			rep(i,0,n)
			{
				if (!vis[i])explore(i),temp++;
			}
			ans=min(temp,ans);
		}
	}
	cout<<ans<<"\n";

}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    #ifdef local
    freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    #endif

    clock_t qwertyuiop = clock();
    int t=1;
    ///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


Measured memory_bytes: 256
n, k = map(int, input().split())
d = []
A = []
for i in range(k):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

b = [False] * n
for lst in A:
    for i in lst:
        b[i - 1] = True

print(n - sum(b))

Measured memory_bytes: 67500
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  static String s, t;

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    s = br.readLine();
    t = br.readLine();

    br.close();

    int n = s.length();
    int ans = 0;

    for (int i = 0; i < n; i++) {
      if(s.charAt(i) != t.charAt(i)){
        ans++;
      }
    }

    out.println(ans);

    out.flush();

  }
}

Measured memory_bytes: 36688
N = input()
A = map(int, raw_input().split())
p = 0
ans = 1
for i in range(1, N):
    if p*(A[i]-A[i-1])<0:
        ans += 1
        p = 0
    elif A[i]-A[i-1] != 0:
        p = A[i]-A[i-1]
print ans


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define MP make_pair
#define PB emplace_back
#define all(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int nax = 6e3 + 5;
vector<int> dst(nax);

int32_t main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    IOS;
    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j) continue;
            int d = min({abs(i - j), abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j)});
            dst[d]++;
        }
    }
    for (int i = 1; i <= n - 1; i++)
    {
        cout << dst[i] / 2 << "\n";
    }
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 MRINF = 5000000000000000;

int main() {


  ll N;
  cin >> N;
  vector<ll> X(N), X_c(N);
  ll ans = 0;
  REP(i, N){
    cin >> X[i];
    ans += X[i];
  }
  X_c = X;
  sort(X.begin(), X.end());

  REP(i, N){
    ll ans = 0;
    if(X_c[i] <= X[N/2-1]) ans = X[N/2];
    else ans = X[N/2-1];

    cout << ans << endl;
  }







    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 6424
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=1;i<=(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 
int32_t main()
{
    c_p_c();
    int n , m ; cin>>n>>m;
    int weights[n+1]; weights[0]=0;
    from(i,n)cin>>weights[i];
    int ans[n+1]; ans[0]=0;
    from(i,n)ans[i]=1;
    while(m--){
        int a,b; cin>>a>>b;
        if(weights[a]>weights[b])ans[b]=0;
        else if(weights[b]>weights[a])ans[a]=0;
        else{
            ans[b]=0; ans[a]=0;
        }
    }
    int count =0;
    from(i,n){
        if(ans[i])count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 5176
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>

int main() {
	int n; std::cin >> n;
	std::vector<int> hotels(n); for (auto& h : hotels) std::cin >> h;
	int l; std::cin >> l;
	std::vector<std::vector<int>> step{ std::vector<int>(n, n) };
	for (auto i = 0; i < n; ++i) {
		step[0][i] = std::distance(hotels.begin(), std::upper_bound(hotels.begin(), hotels.end(), hotels[i] + l)) - 1;
	}
	while (1 << step.size() <= n) {
		std::vector<int> next(n);
		for (auto i = 0; i < n; ++i) {
			next[i] = step.back()[step.back()[i]];
		}
		step.emplace_back(std::move(next));
	}
	int q; std::cin >> q;
	for (auto i = 0; i < q; ++i) {
		int a, b; std::cin >> a >> b; --a; --b;
		if (a > b) std::swap(a, b);
		int day{ 1 };
		for (int i = step.size() - 1; i >= 0; --i) {
			if (step[i][a] < b) {
				day += 1 << i;
				a = step[i][a];
			}
		}
		std::cout << day << '\n';
	}
}


Measured memory_bytes: 10188
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=1e5+5;

struct DSU{
	vi par,siz;
	ll cntt=0;
	DSU(int n){
		for(int i=0; i<n+1; i++){
			par.pb(i);
			siz.pb(1);
		}
		cntt = ll(ll(n)*ll(n-1)/2);
	}
	ll cnt(){
		return cntt;
	}
	int rt(int u){
		if(par[u]!=u)par[u]=rt(par[u]);
		return par[u];
	}
	void merge(int u, int v){
		u=rt(u); v=rt(v);
		if(u==v)return;
		if(siz[v]<siz[u])swap(u,v);
		par[u]=v;
		cntt -= ll(siz[u] * siz[v]);
		siz[v] += siz[u];
		return;
	}
	bool sameset(int u, int v){
		if(rt(u)==rt(v))return 1;
		return 0;
	}
};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m,u,v;
	cin >> n >> m;
	vll ans; DSU dsu(n);
	vector<ii>edge;
	for(int i=0; i<m; i++){
		cin >> u >> v;
		edge.pb({u,v});
	}
	ans.pb(dsu.cnt());
	for(int i=m-1; i>0; i--){
		u = edge[i].fi;
		v = edge[i].se;
		if(!dsu.sameset(u,v)){
			dsu.merge(u,v);
		}
		ans.pb(dsu.cnt());
	}
	reverse(all(ans));
	for(ll x:ans)cout << x << endl;
}	


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

int main() {
  vector<vector<int>> bingo(3,vector<int>(3)),tbingo(3,vector<int>(3));
  rep(i,3){rep(j,3){cin>>bingo[i][j];}}
  int N;
  cin>>N;
  bool flag=false;
  vector<int> b(N),zero={0,0,0},cross(3),tcross(3);
  rep(i,N){cin>>b[i];}
  rep(i,3){
    rep(j,3){
      rep(k,N){
        if(bingo[i][j]==b[k]){
          bingo[i][j]=0;
        }
      }
    }
  }
  rep(i,3){rep(j,3){tbingo[i][j]=bingo[j][i];}}
  rep(i,3){cross[i]=bingo[i][i]; tcross[i]=bingo[2-i][i];}
  rep(i,3){if(bingo[i]==zero||tbingo[i]==zero||cross==zero||tcross==zero){flag=true;}}
  if(flag){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256
from bisect import bisect_left
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
    for j in range(i+1,n):
        r =bisect_left(l,l[i]+l[j])
        ans+=max((r-j-1),0)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

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

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2e5 + 5;
const int INF = 1e9 + 5;

int n;
string a[N];
map <string, int> cnt;
vector <string> ans;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		++cnt[a[i]];
	}
	int mx = 0;
	for (auto it : cnt) {
		mx = max(mx, it.S);
	}
	for (auto it : cnt) {
		if(it.S == mx) {
			ans.pb(it.F);
		}
	}
	for (auto it : ans)
		cout << it <<'\n';
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/

Measured memory_bytes: 27120
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int num = 0;
    long int dis = LONG_MAX;
    long int sum = 0;
    for(int i=0; i<n; i++){
        long int a;
        cin >> a;
        sum += labs(a);
        if(a < 0){
            num++;
        }
        if(labs(a) < dis){
            dis = labs(a);
        }
    }
    
    long int ans;
    if(num%2 == 0){
        ans = sum;
    }else{
        ans = sum - 2*dis;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  	int a,b;
  	cin>>a>>b;
  	ostringstream s,t;
  	s<<a;
    t<<b;
  	string S="",T="";
  	for(int i=0; i<b; i++) S+=s.str();
  	for(int i=0; i<a; i++) T+=t.str();
  	if(S<=T) cout<<S<<endl;
  	else     cout<<T<<endl;
}

Measured memory_bytes: 256
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(Q)]

G = [[] * N for _ in range(N)]
for a, b, c in ABC:
  G[a - 1].append((b - 1, c))
  G[b - 1].append((a - 1, c))

D = [-1] * N
s = [(K - 1, 0)]
while s:
  v, c = s.pop()
  D[v] = c
  for vv, cc in G[v]:
    if D[vv] < 0:
      s.append((vv, cc + c))
  
for x, y in XY:
  print(D[x - 1] + D[y - 1])

Measured memory_bytes: 87476
# -*- coding: utf-8 -*-
# import bisect
# import heapq
# import math
# import random
# from collections import Counter, defaultdict, deque
# from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
# from fractions import Fraction
# from functools import lru_cache, reduce
# from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
# from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(L):
    M = 10**9 + 7
    ans = 1
    m = 0
    for b in map(int, L):
        m *= 3
        if b == 1:
            m += ans
            ans *= 2

        ans %= M
        m %= M
    ans += m
    ans %= M
    return ans


def main():
    L = read_str()
    print(slv(L))


if __name__ == '__main__':
    main()


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define INF 10000000000000

typedef long long LL;

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n==0) return 0;
    vector<vector<LL>> riku(n,vector<LL>(n,INF));
    vector<vector<LL>> kai(n,vector<LL>(n,INF));
    for(int i=0;i<n;i++){
      riku[i][i]=kai[i][i]=0;
    }
    LL x,y,t;
    char c;
    for(int i=0;i<m;i++){
      cin >> x >> y >> t >> c;
      x--;
      y--;
      if(c=='L'){
        riku[x][y]=min(riku[x][y],t);
        riku[y][x]=min(riku[y][x],t);
      }else{
        kai[x][y]=min(kai[x][y],t);
        kai[y][x]=min(kai[y][x],t);
      }
    }
    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          if(riku[i][j]>riku[i][k]+riku[k][j]) riku[i][j]=riku[i][k]+riku[k][j];
          if(kai[i][j]>kai[i][k]+kai[k][j]) kai[i][j]=kai[i][k]+kai[k][j];
        }
      }
    }
    // for(int i=0;i<n;i++){
    //   for(int j=0;j<n;j++){
    //     cout << kai[i][j] << " ";
    //   }
    //   cout << endl;
    // }
    int r;
    cin >> r;
    vector<LL> z(r);
    for(int i=0;i<r;i++){
      cin >> z[i];
      z[i]--;
    }
    vector<vector<LL>> dp(r,vector<LL>(n,INF));
    dp[0][z[0]]=0;
    for(int i=1;i<r;i++){
      for(int j=0;j<n;j++){
        dp[i][j]=dp[i-1][j]+riku[z[i-1]][z[i]];
        for(int k=0;k<n;k++){
          dp[i][j]=min(dp[i][j],dp[i-1][k]+riku[z[i-1]][k]+kai[k][j]+riku[j][z[i]]);
        }
        if(dp[i][j]>INF) dp[i][j]=INF;
      }
    }
    // for(int i=0;i<r;i++){
    //   for(int j=0;j<n;j++){
    //     cout << dp[i][j] << " ";
    //   }
    //   cout << endl;
    // }
    LL ans=INF;
    for(int i=0;i<n;i++) ans=min(ans,dp[r-1][i]);
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 5224
#include <stdio.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807
#define array(N, t) (t*)calloc(N, sizeof(t))

int main() {
  long long X, K, D;
  scanf("%lld%lld%lld", &X, &K, &D);

  X = labs(X);
  long long ans = 0;

  // 繰り返しを行わない判定
  // X - (K * D) >= 0
  // X >= (K * D)
  // X / D >= K
  if (X / D >= K) {
    // X - (K * D) >= 0 なので overflow は心配しなくて良い
    ans = X - (K * D);
  } else {
    // X / D は繰り返すまでの操作回数
    // X / D 回 D ずつ操作した数が、繰り返し直前までの差分
    // その差分を X から引くことで、繰り返し直前の値がわかる
    ans = X - ((X / D) * D);
    // 繰り返すまでの操作回数を K から引いた残りの数について
    // 偶数なら、繰り返すだけなので答えはそのまま
    // 奇数なら、|繰り返し直前の値 - D| だけ原点から離れる
    if ((K - (X / D)) % 2 == 1) {
      ans = labs(ans - D);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)
int main(){
	int n,sum=0;
	rd(n);
	VI a(n);
	fr(i,0,n){
		rd(a[i]);
		sum+=a[i];
	}
	int avg=ceil((double)sum/(double)n);
	//wd(avg);
	int avg2=((double)sum/(double)n);
	//int avg2=
	ll cost=0,cost2=0;
	fr(i,0,n){
		cost+=pow(abs(avg-a[i]),2);
	}
	fr(i,0,n){
		cost2+=pow(abs(avg2-a[i]),2);
	}
	wl(min(cost,cost2));
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p[i];
  sort(p.begin(), p.end());
  int64 sum = 0;
  for (int i = 0; i < N; i++) {
    if (i == N - 1) sum += (p[i] / 2);
    else sum += p[i];
  }
  cout << sum << endl;
}


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

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

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  int t;
  while(cin >> t) {
    if(t == 0) return 0;
    int n;
    cin >> n;
    int ans = 0;
    rep(i, 0, n) {
      int a, b;
      cin >> a >> b;
      ans += b - a;
    }

    if(t <= ans) cout << "OK" << endl;
    else cout << t - ans << endl;
  }
}

Measured memory_bytes: 3140
def main():

    H, W = map(int, input().split())

    if H == 1: return 1
    if W == 1: return 1

    ans = 0
    if W % 2 == 0:
        return (W * H) // 2
    else:
        if H % 2 == 0:
            return W * (H // 2)
        else:
            return (H+1) // 2 * ((W+1) // 2) + (H//2) * (W//2)

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

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

int bfs(vector<std::set<int>>& G, int N, vector<int>& group, int s, int newg) {
    std::queue<int> q;
    if (group[s] != 0) return 1;
    auto F = G[s];
    for (auto itr = F.begin(); itr != F.end(); itr++) {
        q.push(*itr);
    }
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        if (group[now] != 0) continue;
        group[now] = newg;
        auto f = G[now];
        for (auto itr = f.begin(); itr != f.end(); itr++) {
            q.push(*itr);
        }
    }
    return 0;
}

int main() {
    
    int N, M;
    cin >> N >> M;
    if (M == 0) {
        cout << 1 << endl;
        return 0;
    }
    vector<std::set<int>> G(N);
    vector<int> group(N);
    
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].insert(b);
        G[b].insert(a);
    }
    int newg = 1;
    REP(i, N) {
        auto ok = bfs(G, N, group, i, newg);
        if (ok == 0) newg++;
    }
    REP(i, N) {
        //cerr << group[i] << endl;
    }
    vector<int> num(N);
    REP(i, N) {
        if (group[i] != 0) {
            num[group[i]-1]++;
        }
    }
    int ans = 0;
    REP(i, N) {
        //cerr << num[i] << endl;
        ans = std::max(ans, num[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 33352
#include <bits/stdc++.h>
#define NMAX 1000005

using namespace std;
typedef long long ll;
ll dp[NMAX];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,ans=0; cin>>n;
    for(ll i=1;i<NMAX;i++){
        for(ll j=i;j<NMAX;j+=i){
            dp[j]++;
        }
    }
    for(ll i=0;i<n;i++)
        ans+=dp[i];
    cout<<ans;
    return 0;
}


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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
   return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}


int main(){
  ll n,m;

  cin>>n>>m;

  ll ans;
  for(ll i=m/n+1;i>=0;i--){
    if(m%i==0 && m/i>=n) {
      ans = i;
      break;
    }
    
  }
  
  cout << ans<<endl;
  
  
}


Measured memory_bytes: 256