akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  ll a[26]{};
  while(t--)
  {
      ll n;
      cin>>n;
      map<string,ll> m;
      string s;
      REP(k,n)
      {
          cin>>s;
          sort(s.begin(),s.end());
          m[s]++;
      }
      ll count=0;
      for(auto i:m)
      {
          count+=i.second * (i.second - 1)/2;
      }
      cout<<count<<"\n";  
  }
  return 0;
}

Measured memory_bytes: 11264
def main():
    k,n = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    mx = 0

    for i,a in enumerate(A):
        if i == 0:
            continue
        if abs(A[i] - A[i-1]) > mx:
            mx = abs(A[i] - A[i-1])

    delta = max(A) - min(A)



    print(min(delta,k-mx))




if __name__ == '__main__':
    main()


Measured memory_bytes: 26444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}



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

    cin >> a >> b >> c;

    for(ll i = b; i < c+1;i++){
        if(i%a == 0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'001;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  cin >> n >> m;
  vector<int64> d(1 << n, inf64);
  vector<int> cost(m), mask(m);
  for (int i = 0; i < m; ++i) {
    cin >> cost[i] >> k;
    for (int j = 0; j < k; ++j) {
      int x;
      cin >> x;
      --x;
      mask[i] |= 1 << x;
    }
  }
  d[0] = 0;
  for (int i = 0; i < (1 << n); ++i) {
    for (int j = 0; j < m; ++j) {
      d[i | mask[j]] = min(d[i | mask[j]], d[i] + cost[j]);
    }
  }
  if (d.back() == inf64) {
    cout << "-1\n";
    return;
  }
  cout << d.back() << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

int main() {
  int N; cin >> N;
  int A[N], X[N][N], Y[N][N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) cin >> X[i][j] >> Y[i][j];
  }
  int res = 0;
  for (int y = 0; y < (1<<N); y++) {
    int set_bit_num = 0;
    bool contradiction = false;
    for (int i = 0; (i < N) && !contradiction; i++)
      if (y & (1<<i)) {
        set_bit_num++;
        for (int j = 0; (j < A[i]) && !contradiction; j++)
          contradiction |= (Y[i][j] != ((y>>(X[i][j]-1)) & 1));
      }
    if (!contradiction) res = max(res, set_bit_num);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)
#define PC __builtin_popcountll
#define BL(a) (a ? 64 - __builtin_clzll(a) : 0)

int main() {
	const int M = 200'000;
	
	vector<int> memo(M + 1);
	inc1(i, M) {
		assert(i % PC(i) < i);
		memo[i] = memo[i % PC(i)] + 1;
	}
	
	IN(int, n);
	IN(string, s);
	int m = 0;
	RF(c, s) { if(c == '1') { m++; } }
	int vp = 0, vm = 0;
	RF(c, s) {
		vp = (vp * 2 + (c - '0')) % (m + 1);
		if(m == 1) { continue; }
		vm = (vm * 2 + (c - '0')) % (m - 1);
	}
	
	reverse(ALL(s));
	vector<int> ans(n);
	int ep = 1, em = m - 1 - 1;
	inc(i, n) {
		if(s[i] == '0') {
			ans[i] = memo[(vp + ep) % (m + 1)] + 1;
		} else {
			ans[i] = (m == 1 ? 0 : memo[(vm + em) % (m - 1)] + 1);
		}
		
		(ep *= 2) %= (m + 1);
		if(m == 1) { continue; }
		(em *= 2) %= (m - 1);
	}
	dec(i, n) { OUT(ans[i]); }
}


Measured memory_bytes: 5236
#include <stdio.h>
#include <algorithm>

#define MAX_N 105
#define MAX_W 100005

using namespace std;

int N, W;

int inp[MAX_N][2];
long long dp[MAX_N][MAX_W];

long long knap(int, int);		// max value

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

	int i, j;
	for(i = 0; i<N; i++) {
		scanf(" %d %d", &inp[i][0], &inp[i][1]);
	}

	long long erg = knap(0, W);

	printf(" %lld", erg);
	return 0;
}

long long knap(int index, int volume) {

	if(volume < 0) return numeric_limits<int>::min();
	if(index == N) return 0;

	if(dp[index][volume] != 0) return dp[index][volume];

	long long a = knap(index+1, volume-inp[index][0]) + inp[index][1];
	long long b = knap(index+1, volume);

	long long erg = max(a, b);

	dp[index][volume] = erg;

	return erg;

}

Measured memory_bytes: 77952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;


template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< mod >;

const int N = 1005;

ll L,R,a[N],b[N],dp[70][2][2][2];

ll solve(ll x, bool booll, bool boolr, bool ch = 0) {
    if(x<0) return 1;
    if(dp[x][booll][boolr][ch] != -1) return dp[x][booll][boolr][ch];
    ll &res=dp[x][booll][boolr][ch];
    res=0;
    if(!boolr||b[x])
        (res+=solve(x-1, booll&&a[x], boolr, 1)) %= mod;

    if((!boolr||b[x]) and (!booll||!a[x]) and ch)
        (res+=solve(x-1, booll&&!a[x], boolr, 1)) %= mod;
    if(!booll||!a[x])
        (res+=solve(x-1, booll&&!a[x], boolr&&!b[x], ch)) %= mod;
    return res;
}

int main() {
    cin>>L>>R;
    rep(re,61){
        int i=60-re;
        a[i] = (L>>i)&1;
        b[i] = (R>>i)&1;
    }
    rep(i,70) rep(j,2) rep(k,2) rep(l,2) dp[i][j][k][l]=-1;
    cout<<solve(60,1,1)<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var s = consoleReader.String;
            var K = consoleReader.Long;

            var first = s.IndexOfAny(Enumerable.Range(2, 8).Select(i => (char)(i + '0')).ToArray());
            if (K <= first || first < 0) return 1;

            return s[first];
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> Split { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    string s,t;
    cin >> s >> t;
    int ret = 0;
    for(i=0;i<3;i++){
        if(s[i]==t[i])ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char x){
    int y;
    if(x=='E'){
      y=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=y;
    }
    if(x=='W'){
      y=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=y;
    }
    if(x=='N'){
      y=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=y;
    }
    if(x=='S'){
      y=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=y;
    }
  }
  int ue() {
    return s[0];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  string t;cin >> t;
  for(int i=0;i<t.size();i++) d.roll(t[i]);
  cout << d.ue() << endl;
  return 0;
}



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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int ans = 0;
    int count = 0;
    int N, X, T;
    cin >> N >> X >> T;
    while(true) {
        count += X;
        ans += T;
        if(count >= N) {
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])


ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):

    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]: 
            lst.append(S[h + 1])
        else: 
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
    L = len(lst)

    sum_lst = [0] * L
    for w in range(W):

        if max(lst[i][w] for i in range(L)) > K:
            # print("break")
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        # print("w=",w,tmp)
        if max(tmp) > K:
            cnt += 1
  
            sum_lst = [lst[i][w] for i in range(L)]
            # print(sum_lst)
        else:
            sum_lst = tmp
    else: 
        ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 49372
#INPUT
#N K
#S

#1≤N≤50
#1≤K≤N
#Sは A, B, C からなる長さNの文字列

#ex
#3 1
#ABC

#OUTPUT
#文字列SのK文字目を小文字に書き換え、新しくできたSを出力せよ。

N, K =  map(int, input().split())
S = input()

if K==1 :
    str1 = ''
else :
    str1 = S[0:K-1]

if K==N:
    str3 = ''
else :
    str3 = S[K:N]

before = S[K-1]
str2 = before.lower()

print(str1+str2+str3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define em emplace
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = 1<<30;
constexpr ll LINF = 1LL<<58;
constexpr int mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> G[101010];
    vector<int> dp(101010, 0);
    vector<int> in(101010, 0);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        in[b]++;

    }
    vector<int> T;
    queue<int> que;
    for (int i = 0; i < n; i++) {
        if(in[i] == 0) {
            que.emplace(i);
        }
    }
    while(!que.empty()){
        int v = que.front(); que.pop();
        T.emplace_back(v);
        for(auto x : G[v]){
            in[x]--;
            if(in[x] == 0) que.emplace(x);
        }
    }

    for(auto v : T){
        for(auto x : G[v]){
            chmax(dp[x], dp[v] + 1);
        }
    }

    cout << *max_element(all(dp)) << endl;
    return 0;
}

Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string N;
  cin >> N;
  int M = N.size();
  int ans = 0;
  int X;
  rep(i, M) {
    X = (N.at(i) - 3) % 9;
    ans += X;
  }
  if(ans % 9 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 1e4, M = 7 + 1e9;
int n, d, a[N], dp[N][101][2];
string s;
vector<vector<int> > moves;
int cal(int i, int sum, bool clicked){
	if( i == n )
		return sum % d == 0;
	int &ret = dp[i][sum][clicked];
	if(~ret)
		return ret;
	ret = 0;
	if(!clicked){
		f(j, 0, s[i]-'0')
			ret = (ret + cal(i+1, (sum+j)%d, 1))%M;
		ret = (ret + cal(i+1, (sum+s[i]-'0')%d, 0))%M;
	}
	else
	f(j, 0, 10)
		ret = (ret + cal(i+1, (sum+j)%d, 1))%M;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(0);
   	cin.tie(0);
	memset(dp, -1, sizeof dp);
	cin >> s >> d;
	n = (int)s.size();
	cout << (cal(0, 0, 0) - 1 + M) % M;
}

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

signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c<=21)cout<<"win"<<endl;
	else cout<<"bust"<<endl;
}


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

#define MAX_P 10
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main() {
	int n, m;
	int d, p;
	int i;
	int ans;
	int dist[MAX_P + 1];

	while(scanf("%d %d", &n, &m) == 2 && n) {
		memset(dist, 0, sizeof(dist));

		for(i = 0; i < n; ++i) {
			scanf("%d %d", &d, &p);
			dist[p] += d;
		}

		ans = 0;

		for(p = MAX_P; p >= 0; --p) {
			const int len = MIN(dist[p], m);
			ans += p * (dist[p] - len);
			m -= len;
		}

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

	return EXIT_SUCCESS;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, d; cin >> a >> b >> c >> d;
	int n; cin >> n;
	cout << (n / 2) * min({ 8 * a,4 * b,2 * c,d }) + (n % 2)*min({ 4 * a,2 * b,c }) << endl;
	return 0;
}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 200005;
const int mod = 1e9 + 7;

int n, s, ans, sub, a[N], d[N], bit[N], cnt[N], lst[N];

inline int Qow(int x, int y) {
  int r = 1;
  for (; y; y >>= 1, x = 1LL * x * x % mod) {
    if (y & 1) {
      r = 1LL * r * x % mod;
    }
  }
  return r;
}

inline void Modify(int x, int v) {
  for (; x <= n; x += x & -x) {
    bit[x] = (bit[x] + v) % mod;
  }
}

inline int Query(int x) {
  int r = 0;
  for (; x; x -= x & -x) {
    r = (r + bit[x]) % mod;
  }
  return r;
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), s = 1;
  for (int i = 1; i <= n; ++i) {
    Read(a[i]), ++cnt[a[i]];
  }
  for (int i = n; i; --i) {
    cnt[i] = (cnt[i] + cnt[i + 1]) % mod;
  }
  for (int i = 1; i <= n; ++i) {
    cnt[i] -= n - i;
    if (cnt[i] <= 0) {
      puts("0");
      return 0;
    }
    s = 1LL * s * cnt[i] % mod;
    if (cnt[i] > 1) {
      d[i] = 1LL * (cnt[i] - 1) * Qow(cnt[i], mod - 2) % mod;
      if (d[i - 1]) {
        d[i] = 1LL * d[i] * d[i - 1] % mod;
      }
      lst[i] = lst[i - 1];
    } else {
      lst[i] = i;
    }
  }
  memset(bit, 0, sizeof bit);
  for (int i = 1; i <= n; ++i) {
    ans = (1LL * s * (Query(a[i]) - Query(lst[a[i]]) + mod) % mod * d[a[i]] + ans) % mod;
    Modify(a[i], Qow(d[a[i]], mod - 2));
  }
  ans = 1LL * ans * (mod + 1 >> 1) % mod;
  memset(bit, 0, sizeof bit);
  for (int i = 1; i <= n; ++i) {
    ans = (1LL * s * (i - 1 - Query(a[i])) + ans) % mod;
    Modify(a[i], 1);
  }
  memset(bit, 0, sizeof bit);
  for (int i = n; i; --i) {
    if (d[a[i]]) {
      sub = (1LL * s * (Query(a[i] - 1) - Query(lst[a[i]]) + mod) % mod * d[a[i]] + sub) % mod;
      Modify(a[i], Qow(d[a[i]], mod - 2));
    }
  }
  sub = 1LL * sub * (mod + 1 >> 1) % mod;
  printf("%d\n", (ans - sub + mod) % mod);
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 4096
N = int(input())
K = int(input())
x = list(map(int,input().split()))
distance = 0

for i in range(N):
    if abs(K - x[i]) >= x[i]:
        distance += 2 * x[i]
    else:
        distance += 2 * abs(K - x[i])
print(distance)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a>b){
    for(int i=0;i<a;i++){
      cout << b;
    }
    cout << endl;
  }else{
    for(int i=0;i<b;i++){
      cout << a;
    }
    cout << endl;
  }
  return 0;
}


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

int main()
{
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  
  ll ac=a*c;
  ll ad=a*d;
  ll bc=b*c;
  ll bd=b*d;
  
  ll M1=max(ac,ad);
  ll M2=max(M1,bc);
  ll M3=max(M2,bd);
  
  cout << M3 << endl;
    
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e15+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
float pie=3.14159265358979323846;
float r;cin>>r;
float ans=2*pie*r;
cout<<setprecision(20)<<fixed<<ans<<endl;
    return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;

bool cmp(pair<long long,long long>a,pair<long long,long long>b){
    return a.first<b.first;
}

int main(){
    long long N,D,A;
    cin>>N>>D>>A;

    vector<pair<long long ,long long>>enemy;
    vector<long long>v(N);
    rep(i,N){
        long long x,h;
        cin>>x>>h;
        enemy.emplace_back(make_pair(x,h));
        v[i]=x;
    }

    sort(enemy.begin(),enemy.end(),cmp);
    sort(v.begin(),v.end());
    //各地点のダメージの累積和
    long long tot=0;
    //攻撃回数
    long long  cnt=0;
    //ダメージの累積和を保つためのqueue
    queue<pair<long long,long long>>q;
    int stage=0;
    //ダメージの累積和<座標,蓄積ダメージ>
    vector<pair<long long,long long>>sum_damage;
    rep(i,N){
        long long left=enemy[i].first;
        while(q.size() && q.front().first<left){
            //有効期限が切れた攻撃分をダメージから引く
            tot-=q.front().second;
            q.pop();
        }
        
        enemy[i].second-=tot;
        
        if(enemy[i].second<=0)continue;
        
        
        //現在の左端のenemyを倒すための攻撃回数
        int tmp=ceil((double)enemy[i].second/A);
        long long damage=tmp*A;
        tot+=damage;
        q.emplace(left+2*D,damage);
        cnt+=tmp;
    }


    cout<<cnt<<endl;
    
    

}
/*

3 3 2
1 2
5 4
9 2

2

9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5

5

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

3000000000

*/


Measured memory_bytes: 7920
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define MAX_N (100000L)
#define MAX_XY (100000L)

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(int argc, char *argv[]) {
  // read inputs
  long N, xs[MAX_N], ys[MAX_N];
  scanf("%ld", &N);
  for (long i = 0; i < N; i++) {
    scanf("%ld %ld", &xs[i], &ys[i]);
  }

  // cnt
  UnionFind uf(N);
  vector<set<long>> is_with_xs(MAX_XY + 1, set<long>()),
      is_with_ys(MAX_XY + 1, set<long>());
  for (long i = 0; i < N; i++) {
    const long x = xs[i], y = ys[i];
    if (is_with_xs[x].size() > 0) {
      uf.unite(i, *is_with_xs[x].begin());
    }
    if (is_with_ys[y].size() > 0) {
      uf.unite(i, *is_with_ys[y].begin());
    }
    is_with_xs[x].insert(i);
    is_with_ys[y].insert(i);
  }

  vector<set<long>> grp_to_is(MAX_N + 1, set<long>()),
      grp_to_xs(MAX_N + 1, set<long>()), grp_to_ys(MAX_N + 1, set<long>());
  for (long i = 0; i < N; i++) {
    const long root = uf.root(i);
    grp_to_is[root].insert(i);
    grp_to_xs[root].insert(xs[i]);
    grp_to_ys[root].insert(ys[i]);
  }

  // count for each group
  long ans = 0;
  for (long i = 0; i < N; i++) {
    ans += grp_to_xs[i].size() * grp_to_ys[i].size() - grp_to_is[i].size();
  }

  // print answer
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 44416
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    while (n) {
        if (n % 10 == 7) {
            cout << "Yes\n";
            exit(0);
        }
        n /= 10;
    }
    cout << "No\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int func(int x, int s) {
	if (s == 0 || s == 4) return x;
	if (s == 1 || s == 3) return x == 0 ? 2 : x % 2;
	return x == 0 ? 1 : (x - 1) % 2;
}

int main() {
	int L;
	cin >> L;
	
	vector<int> A(L);
	REP(i, L) scanf("%d", &A[i]);
	
	vector<vector<ll> > dp(L + 1, vector<ll>(5, longINF));
	dp[0][0] = 0;
	
	REP(i, L) {
		REP(j, 5) {
			if (dp[i][j] == longINF) continue;
			FOR(k, j, 5) chmin(dp[i + 1][k], dp[i][j] + func(A[i], k));
		}
	}
	
	ll ans = longINF;
	REP(i, 5) chmin(ans, dp[L][i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15104
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    tree = UnionFind(H * W)
    for i in range(H):
        for j in range(W):
            if S[i][j] != "#": continue
            for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == "#":
                    tree.union(W * i + j, W * ni + nj)

    accomp = True
    for root in tree.roots():
        i, j = root // W, root % W
        if S[i][j] == "#" and tree.size(root) == 1:
            accomp = False
            break
    if accomp: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()


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

int main()
{
  int n;
  cin >> n;
  int a;
  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> a;
    int na = 0;
    while (a % 2 == 0) {
      na++;
      a /= 2;
    }
    ans = min(ans, na);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		while(true){
			int a=s.nextInt(),b=s.nextInt();
			if(a==0&&b==0)System.exit(0);
			int day=b;
			switch(a){
				case 12:day+=30;
				case 11:day+=31;
				case 10:day+=30;
				case 9: day+=31;
				case 8: day+=31;
				case 7: day+=30;
				case 6: day+=31;
				case 5: day+=30;
				case 4: day+=31;
				case 3: day+=29;
				case 2: day+=31;
			}
			String [] ans={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
			System.out.println(ans[day%7]);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define make_pair(a, b) mp(a, b)
typedef pair<int, int> pii; 
typedef long long ll;
const int maxn = 1e6 + 10;
int cnt[maxn];
ll ans;
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		for(int j = i; j <= n; j += i)
			++cnt[j];
	for(int i = 1; i < n; ++i)
		ans += cnt[i];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        int K = cin.Int();
        var x = cin.ArrayInt(N);
        Array.Sort(x);

        int ans = int.MaxValue;
        for (int i = 0; i <= N - K; i++) {
            int tmp = Math.Min(Math.Abs(x[i]) + x[i + K - 1] - x[i], Math.Abs(x[i + K - 1]) + x[i + K - 1] - x[i]);
            ans = Math.Min(ans, tmp);
        }

        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 25824
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = []
2.times do
  a.push gets.chomp.split.map(&:to_i)
end

ans = 0
n.times do |i|
  tmp = 0
  n.times do |j|
    if i == j
      tmp += a[0][j]
      tmp += a[1][j]
    elsif j < i
      tmp += a[0][j]
    else
      tmp += a[1][j]
    end
  end
  ans = tmp if ans < tmp
end

puts ans

Measured memory_bytes: 2172
#include<stdio.h>

int main(){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0) break;

        if(x < y){
            printf("%d %d\n",x,y);
        }else
        {
            printf("%d %d\n",y,x);
        }
        
    }
}


Measured memory_bytes: 2052
#include<iostream>

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  char c = 'A';
  rep(i,(int)s.size()) {
    if( (c-'A') >= (s[i]-'A') ) ++cnt;
    c = s[i];
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3180
#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 int main(){
 int i;
 char token[300]={};
 fgets(token, sizeof(token), stdin);
 for (i=0; i<4; i++) {
 if (token[i]=='7'){
 printf("Yes");
 return 0;
 }
 }
 printf("No");
 return 0;
 }

Measured memory_bytes: 1644
double s;n,k,i,y;d['   '];c(int*z){i=*1[&z]-*z;}main(x){for(scanf("%*d");~scanf("%d%d%d",&n,&k,&y);printf("%.f\n",s)){for(i=--n;i;y=x)scanf("%d",&x),d[--i]=x-y;qsort(d,n,4,c);for(s=0;n>=k;s+=d[--n]);}}

Measured memory_bytes: 1200
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function func(x)
	s = 0
	while x > 0
		s += x%10
		x = div(x,10)
	end
	s
end

function main()
	h,w = readline() |> split |> parseMap
	c = Array{Int}(10,10)
	for i in 1:10
		c[:,i] = readline() |> split |> parseMap
	end
	a = Array{Int}(w,h)
	for i in 1:h
		a[:,i] = readline() |> split |> parseMap
	end
	
	for k in 1:10
		for i in 1:10
			for j in 1:10
				c[i,j] = min(c[i,j],c[i,k]+c[k,j])
			end
		end
	end
	
	total = 0
	for i in 1:w
		for j in 1:h
			if a[i,j] != -1
				total += c[2,a[i,j]+1]
			end
		end
	end
	println(total)
end

main()


Measured memory_bytes: 117028
s = list(input())
n = len(s)
t = list("10"*((n+1)//2))
if len(t) != n : t = t[:-1]
a = len(list(filter(lambda x: x[0] != x[1], [(s[i],t[i]) for i in range(n)])))
print(min(a, n-a))

Measured memory_bytes: 12588
#include <bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\n"
#define setpri(x) setprecision(x)
#define vp(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define forf(i,a,b) for(int i=a;i<b;i++)

#define INF 1e17+4
#define MINF 
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) { n %= MOD; if (n < 0) return n + MOD; else return n;}
// vector<int> adj[1000002];
// int vis[1000002],dep[1000002],siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b) 
// { 
//     return ;
// }

void solve()
{
    int n;cin>>n;
    int cur=100,y=0,in=1;
    while(cur<n)
    {
        cur=cur*(1.01);
        y++;
    }
    cout<<y;
}



signed main()
{
    FAST;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

Measured memory_bytes: 3640
n=int(input())
a=list(map(int,input().split()))
ans=[]
judge='APPROVED'
for i in range(n):
    if(a[i]%2==0):
        ans.append(a[i])
for j in range(len(ans)):
    if((ans[j]%3!=0)and(ans[j]%5!=0)):
        judge='DENIED'
print(judge)
        


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int gi()
{
	char c; int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
	return x*f;
}
int a[105],n;
int main()
{
	scanf("%d",&n); int sum=0,ans=1<<30;
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),sum+=a[i];
	for(int i=1;i<=n;++i)
	{
		a[i]+=a[i-1];
		ans=min(ans,abs(a[i]-(sum-a[i])));
	}
	printf("%d",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
int a[114514];
using namespace std;
signed main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(a[a[i]-1]==i+1){
            sum++;
        }
    }
    cout<<sum/2<<endl;
}

Measured memory_bytes: 1024