akhauriyash/Code-Regression huggingface dataset:
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

void solve(){
	ll n;cin>>n;
	ll h[n],i;

	rep(i,n) cin>>h[i];

	ll dp[n+1]={0};
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	dp[2]=min(dp[0]+abs(h[0]-h[2]),dp[1]+abs(h[1]-h[2]));
	fr(i,3,n-1)
	{
		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
	}

	cout<<dp[n-1]<<"\n";
}

int main(){
	//fio();
	fast

	solve();
	return 0;
}

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

int main(){
  int s;
  cin >> s;
  
  int m = 0;
  vector<int> a;
  a.push_back(s);
  for (int i=1 ; ; i++){
    if (a.at(a.size()-1)%2 == 0)
      a.push_back(a.at(a.size()-1)/2);
    else
      a.push_back(3*a.at(a.size()-1) + 1);
    for (int j=0 ; j<a.size()-1 ; j++){
      if (a.at(a.size()-1) == a.at(j)){
        m = i+1;
        break;
      }
    }
    if (m != 0)
      break;
  }
  
  cout << m << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(char a){
  putchar_unlocked(a);
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int H, W, h, res, w;
  rd(H);
  rd(W);
  rd(h);
  rd(w);
  res = (H-h)*(W-w);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190227-1 [beta]

// --- original code ---
// {
//   int H, W, h, w, res;
//   rd(H,W,h,w);
//   res = (H-h)*(W-w);
//   wt(res);
// }


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define INF (1<<24)

int n,m,a,b,c,R;
int r[1001];
char ch;
int t[201][201];
int u[201][201];
int dp[201][1001];
 
void init();
int solve();
  
int main(){
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    init();
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>ch;
      a--;b--;
      if(ch=='L'){
	t[a][b]=min(t[a][b],c);
	t[b][a]=min(t[b][a],c);
      }else {
	u[a][b]=min(u[a][b],c);
	u[b][a]=min(u[b][a],c);
      }
    }
    cin>>R;
    for(int i=0;i<R;i++){
      cin>>r[i];
      r[i]--;
    }
 
    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  u[i][j]=min(u[i][j],u[i][k]+u[k][j]);
	  t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	}
      }
    }
    cout<<solve()<<endl;
  }
  return 0;
}
  
int solve(){
  dp[r[0]][0]=0;
  for(int i=0;i<R-1;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	dp[k][i+1]=min(dp[k][i+1],dp[j][i]+t[r[i]][j]+u[j][k]+t[k][r[i+1]]);
      }
      dp[j][i+1]=min(dp[j][i+1],dp[j][i]+t[r[i]][r[i+1]]);
    }
  }
  int res=INF;
  for(int i=0;i<n;i++)res=min(res,dp[i][R-1]);
  return res;
}
  
void init(){
  for(int i=0;i<201;i++){
    for(int j=0;j<201;j++){
      if(i==j)u[i][j]=0;
      else u[i][j]=INF;
      t[i][j]=u[i][j];
    }
    for(int j=0;j<1001;j++)dp[i][j]=INF;
  }
}

Measured memory_bytes: 2268
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;

int main(int argc, char *argv[])
{
	ll n, d=0;
	string s;

	cin >> n >> s;
	char c = s[0];
	for (int i=1; i<n; i++)
	{
		if (c==s[i]) d++;
		c=s[i];
	}
	cout << (n-d) << endl;
	return 0;
}



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

using namespace std;

map <int, vector <string> > votos;
map <string, int> cantidad;

int main(){
	int N;
	scanf("%d", &N);
	int m = -1;
	while(N--) {
		string aux;
		cin >> aux;
		cantidad[aux]++;
		votos[cantidad[aux]].push_back(aux);
		m = max(m , cantidad[aux]);
	}
	vector <string> ans = votos[m];
	sort(ans.begin(), ans.end());

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << "\n";
	}
}

Measured memory_bytes: 31488
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, Y) = (input[0], input[1])
var flag = true
loop: for x in 0...N {
    for y in 0...N-x {
        let z = N - (x + y)
        if 10000*x + 5000*y + 1000*z == Y{
            print("\(x) \(y) \(z)")
            flag = false
            break loop
        }
    }
}
if flag {
    print("-1 -1 -1")
}

Measured memory_bytes: 4080
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();

        int[] A = new int[N];
        int[] B = new int[N-1];
        for(int i=0; i<N-1; i++){
            B[i] = nextInt();
        }

        int count = 0;
        A[0] = B[0];
        count += A[0];
        A[N-1] = B[N-2];
        count += A[N-1];
        int min = B[0];
        for(int i=1; i<N-1; i++){
            min = Math.min(B[i-1], B[i]);
            A[i] = min;
            count += A[i];
        }

        println(count);
    }

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

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

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 23764
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
double xa,ya,ra;
double xb,yb,rb;
int main()
{
  int n;
  cin>>n;
  for(int i = 0;i < n;i++){
    cin>>xa>>ya>>ra>>xb>>yb>>rb;
    double dp =sqrt(pow(abs(xa-xb),2)+pow(abs(ya-yb),2));
    double dr = ra+rb;
    if(dp >dr){
      cout <<0<<endl;
    }else if(dp+ra <rb){
      cout <<-2<<endl;
    }else if(dp +rb < ra){
      cout <<2<<endl;
    }else if(dp <=dr){
      cout <<1<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
  int K,S; cin >> K >> S;
  int X,Y = 0,Z;
  int pattern = 0;
  Z = K;
  //cout <<"X  Y  Z" << endl;
  for(X = 0; X <= K; ++X){
      for(Y = 0,Z = S - X; Z >= 0; --Z,++Y){

        if(X<= K && Y<=K && Z<=K){ pattern++; /*cout << X << "  " << Y << "  " << Z << endl;*/}
      }
    }
    cout << pattern << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    int sum = 0;
    rep(i,0,N)cin >> A[i];
    rep(i,0,N)cin >> B[i];
    rep(i,0,N){
        sum += max(0, A[i] - B[i]);
    }
    cout << sum << endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(4005);


void solve()
{
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	for(int i = 2; i <= k; ++i)
	{
		// cout << k-1 << "C" << k-i << " * " << n-k+1 << "C" <<  i << endl;
		cout << c(k-1, k-i) * c(n-k+1, i) << endl;
	}
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#include <map>
#define tNow chrono::duration_cast<msec>(chrono::system_clock::now().time_since_epoch())
#define INF (1 << 30)
using namespace std;

typedef chrono::milliseconds msec;

int d, lastVal = -INF, bestVal = -INF, times = 0, groups = 0, updates = 0, positiveUpdates = 0;
vector<int> c(27), cur, ans;
vector< vector<int> > s;

int calc() {
    int sum = 0;
    vector<int> last(27, 0);
    for (int i = 1; i <= d; ++i) {
        sum += s.at(i).at(cur.at(i));
        last.at(cur.at(i)) = i;
        for (int j = 1; j <= 26; ++j) sum -= c.at(j) * (i - last.at(j));
    }
    return sum;
}

void update(int curVal) {
    lastVal = curVal;
    if (bestVal < curVal) {
        bestVal = curVal;
        ans = cur;
        ++positiveUpdates;
    }
    ++updates;
}

int main() {
    random_device r;
    msec st = tNow;
    msec lm = st + chrono::milliseconds(1900);
    cin >> d;
    s = vector< vector<int> >(d + 1, vector<int>(27));
    cur.resize(d + 1);
    for (int i = 1; i <= 26; ++i) cin >> c.at(i);
    for (int i = 1; i <= d; ++i) for (int j = 1; j <= 26; ++j) cin >> s.at(i).at(j);
    mt19937 m(r());
    for (int i = 1; i <= d; ++i) cur.at(i) = m() % 26 + 1;
    update(calc());
    // cur = {0, 1, 17, 13, 14, 13};
    // update(calc());
    // cout << bestVal << endl;
    // for (int i = 1; i <= d; ++i) cout << ans.at(i) << endl;

    while (tNow < lm) {
        ++groups;
        mt19937 m(r());
        for (int i = 0; i < 100; ++i) {
            int changeAt = m() % d + 1, changeTo = m() % 26 + 1, changedFrom = cur.at(changeAt);
            if (changedFrom == changeTo) continue;
            cur.at(changeAt) = changeTo;
            int curVal = calc();
            if (curVal > lastVal) update(curVal);
            else cur.at(changeAt) = changedFrom;
            ++times;
        }
    }

    for (int i = 1; i <= d; ++i) cout << ans.at(i) << endl;
    msec ed = tNow;
    #ifdef ___DEBUG
    cout << "Best Value: " << bestVal << endl;
    cout << "Best Score: " << max(bestVal + 1000000, 0) << endl;
    cout << "Tried: " << times << "times, " << groups << "groups\n";
    cout << "Updated: " << updates << "times\n";
    cout << (ed - st).count() << "ms\n";
    #endif
    return 0;
}


Measured memory_bytes: 3700
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  n = n % 10;
  if(n == 3) fin("bon");
  else if(n == 0||n == 1 ||n == 8 || n == 6) fin("pon");
  else fin("hon");
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 3692
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(string, "s", long, "p");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto guide = new Pair[](n);
    foreach (i; iota(n))
    {
        string s;
        long p;
        scan(s, p);
        guide[i] = Pair(s, p);
    }
    auto book = guide.dup.sort!"a.s == b.s ? a.p > b.p : a.s < b.s"().array();
    // book.each!(x => x.writeln());
    foreach (e; book)
    {
        foreach (i, f; guide)
        {
            if(e == f)
                writeln(i + 1);
        }
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2720
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;



int main(int argc, const char* argv[]){
    int d, t, s;
    cin >> d >> t >> s;
    if((float)d / (float)s <= (float)t)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

using namespace std;

int n;


long long sum;

int main()
{
	cin >> n;
	for(int a = 1; a <= n; ++a)
	{
		for(int b = 1; b <= n; ++b)
		{
			for(int c = 1; c <= n; ++c)
			{
				sum += __gcd(a, __gcd(b, c));
			}	
		}
		
	}
	cout << sum << endl;
	return 0;
}

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

#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

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

    VVL rec(10, VL(10, 0));
    rep(i, 1, N+1){
        string s = to_string(i);
        rec[s[0]-'0'][s[s.size()-1]-'0']++;
    }

    ll ans = 0;
    rep(a, 1, 10){
        rep(b, 1, 10){
            ans += rec[a][b] * rec[b][a];
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define ff first
#define ss second
typedef long long ll;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = 1e5 + 10;

vector<int> adj[N];
int dis[N], in[N], vis[N];

void dfs(int u) {
  vis[u] = 1;
  for (auto v: adj[u]) {
    dis[v] = max(dis[v], dis[u] + 1);
    in[v]--;
    if (in[v] == 0) dfs(v);
  }
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    in[v]++;
  }  
  for (int i = 1; i <= n; ++i) {
    if (!vis[i] && !in[i]) {
      dfs(i);
    }
  }
  int answer = 0;
  for (int i = 1; i <= n; ++i) answer = max(answer, dis[i]);
  printf("%d\n", answer);
}


Measured memory_bytes: 9984
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        n: usize,
        a: [i32; n],
    }

    let mut ans = std::i32::MAX;
    for x in a {
        let mut y = x;
        let mut cnt = 0;
        while y%2 == 0 {
            cnt += 1;
            y = y/2;
        }
        ans = min(ans, cnt);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
#define INF (2147483647)
#define mod (1000000007)

int main(void){
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    bool ans = true;

    rep(i,n){
        if(i == 1){
            if(h[i]>h[i+1]) h[i]--;
        }
        else if(i == n-1){
            if(h[i] < h[i-1] - 1) {
                ans = false;
                break;
            }
        }
        else if(h[i]>=h[i+1] && h[i] - 1 >=h[i-1]) h[i]--;
        else if(h[i]<=h[i+1] && h[i-1] <= h[i]) {}
        else {
            ans = false;
            break;
        } 
    }

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

Measured memory_bytes: 640
#include <stdio.h>
void swap_int(int* x, int* y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void swap_char(char* x, char* y) {
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

void asc_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] > array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

void dec_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] < array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

int max(int x, int y) {
    if (x > y) {
        return x;
    } else {
        return y;
    }
}

int min(int x, int y) {
    if (x > y) {
        return y;
    } else {
        return x;
    }
}

int main(void) {
    int a, p;
    scanf("%d %d", &a, &p);
    printf("%d\n", (a * 3 + p) / 2);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff(i,n) for(i=0;i<n;i++)
ll bg=1000000000000000000;
int main()
{ 
       ll n,i,vertex = 0;
		cin>>n;
		ll a[n+1],b[n+1];
		ff(i,n+1)
		   cin>>a[i];
		b[0] = 1-a[0];
		if(b[0]<0)
		{
			cout<<"-1";
			return 0;	
		}   
		for(i=1;i<=n;i++)
		{
			b[i] = min(bg,2*b[i-1]-a[i]);
			if(b[i]<0)
			{
				cout<<"-1";
				return 0;
			}
		}
		b[n] = 0;
		for(i=n-1;i>=0;i--)
			b[i]=min(b[i],a[i+1]+b[i+1]);
		for(i=0;i<=n;i++)
			vertex+=(a[i]+b[i]);
		cout<<vertex;	
	return 0;
}

Measured memory_bytes: 5196
#include <iostream>

using namespace std;

int mod2019(int l, int r)
{
    int ans = 2019;

    for(long long i = l; i < r; ++i)
        for(long long j = i + 1; j <= r; ++j) {
            ans = min(ans, (int)((i * j) % 2019));
            if(!ans) return ans;
        }

    return ans;
}

int main()
{
    int l, r;
    cin >> l >> r;

    cout << mod2019(l, r) << '\n';
}


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

int main(){
  int *data, cnt, min_data, max=-1000000000, i;

  //input data number
  scanf("%d",&cnt);
  data=(int *)malloc(cnt*sizeof(int));
  for(i=0;i<cnt;i++)scanf("%d",&data[i]);

  //judge
  min_data=data[0];
  for(i=1;i<cnt;i++){
    if(max<data[i]-min_data) max=data[i]-min_data;
    if(min_data>data[i]) min_data=data[i];
  }

  //output max value
  printf("%d\n",max);

  free(data);
  return 0;
}



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

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < (S.size() - 1)/2; i++) {
    if (S.at(i) != S.at(S.size() - i - 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < (S.size() - 1)/2; i++) {
    if (S.at(i) != S.at((S.size()-1)/2 - i - 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int n; cin >> n;
    int table[26][n + 1]; rep(i, 26) rep(j, n + 1) table[i][j] = 0;
    rep(i, n) {
        string s; cin >> s;
        rep(j, s.size()) {
            table[s[j] - 'a'][i]++;
        }
    }
    rep(i, 26) {
        int mc = inf;
        rep(j, n) {
            mc = min(mc, table[i][j]);
        }
        table[i][n] = mc;
    }
    rep(i, 26) {
        while (table[i][n]) {
            cout << (char)(i + 'a');
            table[i][n]--;
        }
    }
    cout << endl;
}


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

#define ff        first
#define ss        second
#define int       long long
#define pb        push_back
#define mp        make_pair
#define vi        vector<int>
#define pii       pair<int,int>
#define mii       map<int,int>
#define w(x)      int x; cin>>x; while(x--)
#define all(x)      (x).begin(),(x).end()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define mod       1000000007

void 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();
    int r,c; cin>>r>>c;
    int dp[r+1][c+1];
    char x;
    rep(i,1,r+1)
        rep(j,1,c+1)
        {
            cin>>x;
            if(x=='.')
                dp[i][j]=0;
            else 
                dp[i][j]=-1;   
        }

    rep(i,1,r+1)
        {
            if(dp[i][1]==0)
                dp[i][1]=1;
            else
                break;
        }

    rep(j,2,c+1)
        {if(dp[1][j]==0)
                    dp[1][j]=1;
                else
                    break;}

    rep(i,2,r+1)
        rep(j,2,c+1)
        {
            if(dp[i][j]==-1)
                continue;

            dp[i][j] = (dp[i-1][j]!=-1 ?dp[i-1][j]:0)%mod + (dp[i][j-1]!=-1?dp[i][j-1]:0)%mod;
            dp[i][j]%=mod; 
        }
    //rep(i,1,r+1)
    //{
    //    rep(j,1,c+1)
    //        cerr<<dp[i][j]<<" ";
    //    cerr<<"\n";
    //}

    cout<<dp[r][c];
    return 0;
}   

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< ul > a(n);
  vector< ul > ans(n);
  for (int i=0; i<n; ++i) cin >> a[i];
  ul sum = 0;
  for (int i=0; i<n; ++i) sum += a[i];
  sum /= 2;
  for (int i=1; i<n; i+=2) sum -= a[i];
  ans[0] = sum;
  for (int i=1; i<n; ++i) ans[i] = a[i-1]-ans[i-1];
  for (int i=0; i<n; ++i) cout << ans[i]*2 << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7;
using namespace std;
ll t;
ll arr[200005];
int main()
{
    ll a,b,c,d,e,f,i,j;
    cin>>a;
    b=a;
    c=1;
    while(b>0)
    {
        b=b/2;
        c=c*2;
    }
    d=c/2;
    cout<<c-1<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  int x,y;
  cin>>x>>y;
  int sub=0;
  long double a=y/(2.0*x);
  int g=gcd(x,y);
  int newx=x/g;
  int newy=y/g;
  for(int i=1;i<x;i++){
    if(i%newx==0)sub++;
  }

  cout <<x+y-sub<<endl;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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


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

	int ret = 111;
	while (N > ret) {
		ret += 111;
	}

	cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main() {
	// your code goes here
	string a,b; cin >> a >> b; a+=b;
	int n=stoi(a);
	int counter=0;
	for(int i=1; i*i<=n; i++)
	{
	   if(n==i*i) {
	   	counter=1;
	   	break;
	   }	
	}
	if(counter) 
         cout <<"Yes"<<endl;
	else
	cout <<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a;
  long long t=0;
  int fmax=INT_MIN;
  for(int i=0;i<n;i++){
    cin>>a;
    fmax=max(fmax,a);
    if(a<fmax) t+=fmax-a;
  }
  cout<<t<<endl;
}

Measured memory_bytes: 3616
# https://atcoder.jp/contests/abc156/submissions/10277689

# コンテスト中に通せたけどmodintクラスで実装してみる
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        self.mod = MOD
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.mod)
        else:
            return ModInt(self.x - other, self.mod)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x, self.mod)
        else:
            return ModInt(self.x * other, self.mod)

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, self.mod - 2, self.mod))
        else:
            return ModInt(self.x * pow(other, self.mod - 2, self.mod))

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.mod))
        else:
            return ModInt(pow(self.x, other, self.mod))

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x * pow(self.x, self.mod - 2, self.mod))
        else:
            return ModInt(other * pow(self.x, self.mod - 2, self.mod))

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.mod))
        else:
            return ModInt(pow(other, self.x, self.mod))


def combination_mod(n, r, mod):
    if r > n:
        return 0  # このような通りの数は無いため便宜上こう定義する
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i) % mod
        rf = rf * (i + 1) % mod
    return nf * pow(rf, mod - 2, mod) % mod


def combination(n, r):
    if r > n:
        return 0  # このような通りの数は無いため便宜上こう定義する
    r = min(r, n - r)
    nf = rf = ModInt(1)
    for i in range(r):
        nf = nf * (n - i)
        rf = rf * (i + 1)
    return nf / rf


# すべての通り(2^n-1)からnCa,nCbを引けば良い
MOD = 10**9 + 7
n, a, b = read_ints()
# tmp = pow(2, n, MOD) - 1
# ans = tmp - combination_mod(n, a, MOD) - combination_mod(n, b, MOD)
# print(ans % MOD)

tmp = ModInt(2)**n - 1
ans = tmp - combination(n, a) - combination(n, b)
print(ans)


Measured memory_bytes: 39664
def c_Traveling(N, P):
    t_old = x_old = y_old = 0
    for t, x, y in P:
        t1 = t - t_old
        x1 = x - x_old
        y1 = y - y_old
        cond1 = abs(x1) + abs(y1)
        cond2 = t1 % 2
        cond3 = cond1 % 2
        if t1 >= cond1 and cond2 == cond3:
            pass
        else:
            return 'No'
        t_old, x_old, y_old = t, x, y
    return 'Yes'

N = int(input())
P = [[int(i) for i in input().split()] for j in range(N)]
print(c_Traveling(N, P))

Measured memory_bytes: 21052
#include <stdio.h>
#define MAX 500001

int h;

void maxheapify(int *A,int i)
{
  int l,r,a,b,largest;
  
  l=i*2;
  r=i*2+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){ // i の子の方が値が大きい場合
    a=A[i];
    b=A[largest];
    A[i]=b;
    A[largest]=a;
    maxheapify(A,largest);
  }
}

void buildmaxheap(int *A)
{
  int i;
  for(i=h/2;i>0;i--) maxheapify(A,i);
}

int main(){
  int i,k[MAX];
  
  scanf("%d",&h);
  for(i=1;i<=h;i++){
    scanf("%d",&k[i]);
  }
  
  buildmaxheap(k);

  for(i=1;i<=h;i++){
    printf(" %d",k[i]);
  }
  printf("\n");
 
  return 0;
}



Measured memory_bytes: 3692
#include <iostream>
#include <cmath>

using namespace std;

int N;

int main()
{
    int ans = 1;
    cin >> N;

    for (int i = 2; i * i <= N; i++)
    {
        int j = i * i;
        while (j * i <= N)
        {
            j *= i;
        }
        if (j > ans)
            ans = j;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int s[100010];

signed main(){
	int Q;
	cin>>Q;
	vector<int>a(Q);
	REP(i,Q)cin>>a[i];
	FOR(i,1,100001){
		int sum = 1;
		for(int j = 2;j * j<=i;j++){
			if(i%j)continue;
			sum *= j;
			if(j != i/j)sum *= i/j;
			sum = min(200002ll,sum);
		}
		if(sum>=i*2)s[i]++;
	}
	REP(i,100001)s[i+1]+=s[i];
	REP(i,Q){
		cout<<s[a[i]]<<endl;
	}
}


Measured memory_bytes: 4348
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

typedef vector<vector<Edge>> Graph;

signed main(void) {
	int n;
	cin >> n;
	vector<ll> a(n);
	ll os = 0;
	REP(i, n) {
		cin >> a[i];

		if (i % 2) {
			os -= a[i];
		}
		else
			os += a[i];
	}

	cout << os;
	
	rep(i, 0, n - 1) {
		os = (a[i] - os/2)*2;
		cout <<" "<<os;
	}


	return 0;
}


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

int main(){
	int H,W;
	cin >> H >> W;
	int h,w;
	cin >> h >> w;
	cout << (H-h)*(W-w) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int r;
    cin >> r;
    if(r < 1200){
        cout << "ABC" << endl;
    }
    else if(r < 2800){
        cout << "ARC" << endl;
    }
    else{
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let S = read string
    let n =
        match S with
        | "SUN" -> 7
        | "MON" -> 1
        | "TUE" -> 2
        | "WED" -> 3
        | "THU" -> 4
        | "FRI" -> 5
        | "SAT" -> 6
    if S = "SUN" then
        printfn "7"
    else
        printfn "%i" (7 - n)
    0

Measured memory_bytes: 13648
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

// 0-indexed, 半開
template <typename T> struct BIT {
  private:
    int n;
    vector<T> dat;

  public:
    BIT(vector<T> v) : n(v.size()) {
        dat.assign(n + 1, 0);
        for(int i = 0; i < n; i++)
            dat[i + 1] = v[i];
        for(int i = 1; i < n; i++)
            if(i + (i & -i) <= n) dat[i + (i & -i)] += dat[i];
    }
    BIT(int n) : n(n) { dat.assign(n + 1, 0); }
    void add(int k, T a) {
        for(k++; k <= n; k += k & -k)
            dat[k] += a;
    }
    // [0,a)
    T sum(int a) {
        T ret = 0;
        for(; a > 0; a -= a & -a)
            ret += dat[a];
        return ret;
    }
    // [a,b)
    T sum(int a, int b) { return sum(b) - sum(a); }
    int lowerBound(int w) {
        if(w <= 0) return 0;
        int x = 0;
        for(int k = 1 << int(log2(n)); k; k /= 2) {
            if(x + k <= n && dat[x + k] < w) {
                x += k;
                w -= dat[x];
            }
        }
        return x + 1;
    }
};

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

    string s;
    int cnt[26] = {};
    cin >> s;
    int n = s.size();

    rep(i, n) cnt[s[i] - 'a']++;
    string left, mid;
    rep(i, 26) if(cnt[i] & 1) mid.push_back('a' + i);
    if(mid.size() > 1) {
        cout << -1 << endl;
        return 0;
    }
    int cnt2[26] = {};
    rep(i, n) if(cnt2[s[i] - 'a']++ < cnt[s[i] - 'a'] / 2) left.push_back(s[i]);
    string t = left + mid;
    reverse(ALL(left));
    t += left;

    ll ans = 0;
    int id[26] = {};

    BIT<int> bit(n + 1);

    rep(i, n) {
        int c = s[i] - 'a';
        while(t[id[c]] != s[i])
            id[c]++;
        ans += id[c] - bit.sum(id[c]);
        bit.add(id[c], 1);
        id[c]++;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int a,b;
  cin >> a;
  b=0;
  for (int i=1; i<10; i++) {
    for (int j=1; j<10; j++) {
      if (a==i*j) {
        b=1;
      }
    }
  }
  if (b) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
#define chmin(x,y) x=min(x,y)
int dp[41][4],p[41],t[41],inf=1e8;
void solve(int N){
	rep(i,N+1) rep(j,4) dp[i][j]=inf;
	dp[0][0]=0;
	rep(i,N){
		cin>>p[i+1]>>t[i+1];
		rep(j,4){
			if(j!=3) if((j+1)*abs(p[i]-p[i+1])<=t[i+1]-t[i]) chmin(dp[i+1][j+1],dp[i][j]+abs(p[i]-p[i+1]));
			if((j+1)*p[i]+p[i+1]<=t[i+1]-t[i]) chmin(dp[i+1][1],dp[i][j]+p[i]+p[i+1]);
		}
		int tmp=inf;
		rep(j,4) chmin(tmp,dp[i+1][j]);
		if(tmp==inf){
			rep(j,N-1-i) cin>>tmp>>tmp;
			printf("NG %d\n",i+1);
			return;
		}
	}
	int tmp=inf;
	rep(j,4) chmin(tmp,dp[N][j]+p[N]);
	printf("OK %d\n",tmp);
}
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		solve(N);
	}
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <string.h>
#define ms(a) memset(a,'\0',sizeof(a))

int x,y,ans,l,p,m;
char map[105][105];

void dfs(int xx,int yy,char c)
{
	if(xx>=0 && xx<x && yy>=0 && yy<y && map[xx][yy]==c)
	{
		map[xx][yy]='.';
	}
	else
		return ;
	dfs(xx-1,yy,c);
	dfs(xx+1,yy,c);
	dfs(xx,yy+1,c);
	dfs(xx,yy-1,c);
}

int main()
{
	//freopen("Aizu0118.txt","r",stdin);
	scanf("%d %d",&x,&y);
	while(!(x==0&&y==0))
	{
		l=p=m=0;
		ans=0;
		getchar();
		for(int i=0;i<x;i++)
		{
			gets(map[i]);
		}
		for(int i=0;i<x;i++)
		{
			for(int j=0;j<y;j++)
			{
				if(map[i][j]!='.')
				{
					dfs(i,j,map[i][j]);
					ans++;
				}
			}
		}
		printf("%d\n",ans);
		scanf("%d %d",&x,&y);
	}
	return 0;
}

Measured memory_bytes: 1352
#include <iostream>

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

int main() {
    int n;
    while (std::cin >> n && n) {
        int sc1 = 0, sc2 = 0;
        rep(i, n) {
            int p1, p2;
            std::cin >> p1 >> p2;
            if (p1 == p2)
                sc1 += p1, sc2 += p2;
            else if (p1 > p2)
                sc1 += p1 + p2;
            else
                sc2 += p1 + p2;
        }
        std::cout << sc1 << ' ' << sc2 << std::endl;
    }
}

Measured memory_bytes: 2972
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val A, B = sc.nextInt()

    def gcd(a: Long, b: Long): Long =
      if (a % b == 0) b
      else gcd(b, a % b)

    def lcm(a: Long, b: Long): Long =
      a * (b / gcd(a, b))

    println(lcm(A, B))
  }

}


Measured memory_bytes: 25528
#include<iostream>
using namespace std;
int N,C[3<<17],D[3<<17],F[3<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int A;cin>>A;C[A]++;
	}
	for(int i=0;i++<N;)D[C[i]]++;
	long L=0,R=0;
	for(int i=1;i<=N;i++)R+=D[i];
	for(long X=1;X<=N;X++)
	{
		R-=D[X];
		L+=X*D[X];
		F[X]=(L+R*X)/X;
	}
	int id=N;
	for(int K=1;K<=N;K++)
	{
		while(id>0&&F[id]<K)id--;
		cout<<id<<endl;
	}
}

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

int main(){
    int n,m;
    int a,b,ans=0;
    cin>>n>>m;
    vector<int> h(n);
    vector<vector<int>> v(n);
    rep(i,n) cin>>h[i];
    rep(i,m){
        cin>>a>>b;
        a--;b--;
        v[a].push_back(h[b]);
        v[b].push_back(h[a]);
    }
    rep(i,n){
        if(v[i].empty()){
            ans++;
            continue;
        }
        sort(v[i].begin(),v[i].end(),greater<int>());
        if(h[i]>v[i][0]) ans++;
    }
    cout<<ans<<endl;
}


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

int main() {
  int d;
  cin >>d;
  if(d==25)cout<<"Christmas"<<endl;
  else if(d==24)cout<<"Christmas"<<" "<<"Eve"<<endl;
  else if(d==23)cout<<"Christmas"<<" "<<"Eve"<<" "<<"Eve"<<endl;
  else cout<<"Christmas"<<" "<<"Eve"<<" "<<"Eve"<<" "<<"Eve"<<endl;
}


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

using namespace std;

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

    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        } else if (i % 2 == 1 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
def read():
    return raw_input()


def write(message):
    import sys
    print message
    sys.stdout.flush()


if __name__ == '__main__':
    n, c = map(int, read().split())
    # n < 500
    # 3 < c < 30
    D = []
    C = []
    for _ in range(c):
        D.append(map(int, read().split()))
    for _ in range(n):
        C.append(map(int, read().split()))

    import numpy as np
    g = [[],[],[]]
    for i in range(n):
        for j in range(n):
            g[(i+j)% 3].append(C[i][j] - 1)
    p0 = sorted([(tc, sum(D[d][tc] for d in g[0])) for tc in range(c)], key=lambda x:x[1])[:3]
    p1 = sorted([(tc, sum(D[d][tc] for d in g[1])) for tc in range(c)], key=lambda x:x[1])[:3]
    p2 = sorted([(tc, sum(D[d][tc] for d in g[2])) for tc in range(c)], key=lambda x:x[1])[:3]

    min_w = p0[2][1] + p1[2][1] + p2[2][1]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                w = p0[i][1] + p1[j][1] + p2[k][1]
                colors = (p0[i][0], p1[j][0], p2[k][0])
                if len(set(colors)) == 3 and w < min_w:
                    min_w = w
    write(min_w)




Measured memory_bytes: 20436