akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
int main()
{


   ll a,b;

   cin>>a>>b;

   if(b%2!=0)
   {
       cout<<"No"<<endl;
       return 0;
   }

    if((a*2)>b||(a*4)<b)cout<<"No"<<endl;

   else cout<<"Yes"<<endl;

}




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

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long N, M, dp[3009][3009], nr[3009][3009], power[9000009];

void init() {
	dp[0][0] = 1;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			dp[i + 1][j] += dp[i][j] * (j + 1); dp[i + 1][j] %= M;
			dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= M;
		}
	}
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % M;
		}
	}
	power[0] = 1; for (int i = 1; i <= 9000000; i++) power[i] = (power[i - 1] * 2) % M;
}
long long Ramen(long long a, long long b) {
	return dp[a][b];
}
long long ncr(long long a, long long b) {
	if (b < 0 || a < b) return 0;
	return nr[a - b][b];
}
long long solve(long long p) {
	long long ret = 0, Free = modpow(2, N - p, M - 1);
	for (int i = 0; i <= p; i++) {
		long long D = Ramen(p, i);
		ret += (D*power[(N - p)*i]); ret %= M;
	}
	ret *= modpow(2, Free, M); ret %= M;
	return ret;
}

int main() {
	cin >> N >> M;
	init();
	long long ans = 0;
	for (int i = 0; i <= N; i++) {
		long long K = solve(i);
		long long L = ncr(N, i);
		if (i % 2 == 0) ans += K*L;
		else ans -= K*L;
		ans += M*M; ans %= M;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 211840
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

const int INF = 1001001001;
vector<int> to[1005];
int n;

vector<int> bfs(int sv)
{
    vector<int> dist(n, INF), pre(n, -1);
    queue<int> q;
    dist[sv] = 0;
    q.push(sv);

    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int u : to[v])
        {
            if (dist[u] != INF)
                continue;
            pre[u] = v;
            dist[u] = dist[v] + 1;
            q.push(u);
        }
    }

    pair<int, int> best(INF, -1);
    REP(v, n)
    {
        if (v == sv)
            continue;
        for (int u : to[v])
        {
            if (u == sv)
            {
                best = min(best, make_pair(dist[v], v));
            }
        }
    }

    if (best.first == INF)
        return vector<int>(n + 1);
    int v = best.second;
    vector<int> res;
    while (v != -1)
    {
        res.push_back(v);
        v = pre[v];
    }
    return res;
}

int main()
{

    int m;
    cin >> n;
    cin >> m;

    REP(i, m)
    {
        int s, t;
        cin >> s;
        cin >> t;
        --s, --t;
        to[s].push_back(t);
    }

    vector<int> ans(n + 1);
    REP(s, n)
    {
        auto now = bfs(s);
        if (now.size() < ans.size())
            ans = now;
    }
    if (ans.size() == n + 1)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;

    for (int v : ans)
    {
        cout << v + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 384
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll n;
  cin >> n;
  vll a1(n),a2(n);

  rep(i,n) cin >> a1[i];
  rep(i,n) cin >> a2[i];

  vll r1(n+1,0),r2(n+1,0);

  rep(i,n)
  {
    r1[i+1] = r1[i] + a1[i];
    r2[i+1] = r2[i] + a2[i];
  }

  ll ans = 0;
  rep(i,n)
  {
    ans = max(ans,r1[i+1] + r2[n] - r2[i]);
  }

  cout << ans << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(abs(a-b)%2 == 0){
        cout << min(a,b) + abs(a-b)/2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M, *A = map(int, read().split())
A = list(map(list, map(reversed, zip(*[iter(A)] * M))))

# 各スポーツに参加している人数
p = [0] * (M + 1)
canceled = set()
answer = []


def solve(s, n):
    # nは開催しているスポーツの数
    # sは新たに開催をやめるスポーツ
    if n == 1:
        answer.append(N)
    elif n == M:
        for i in A:
            p[i[-1]] += 1
        p_max = max(p)
        answer.append(p_max)
        cancel = p.index(p_max)
        solve(cancel, n - 1)
    else:
        canceled.add(s)
        p[s] = 0
        for i in range(N):
            if A[i][-1] in canceled:
                while A[i][-1] in canceled:
                    A[i].pop()
                p[A[i][-1]] += 1
        p_max = max(p)
        answer.append(p_max)
        cancel = p.index(p_max)
        solve(cancel, n - 1)


solve(0, M)
print(min(answer))


Measured memory_bytes: 10092
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int main()
{
    LL k,a,b;
    LL ans=0;
    while(cin>>a>>b>>k)
    {
        LL ans=0;

        if(a<0&&b<0)
        {
            ans+=(-a)/k-(-b)/k;
            if((-b)%k==0)
            {
                ans++;
            }
        }
        else if(a<0&&b==0)
        {
            ans+=(-a)/k;
            ans++;
        }
        else if(a<0&&b>0)
        {
            ans+=(b)/k+(-a)/k;
            ans++;
        }
        else if(a==0&&b>0)
        {
            ans+=(b)/k;
            ans++;
        }
        else if(a>0&&b>0)
        {
            ans+=(b)/k-(a)/k;
            if(a%k==0)
            {
                ans++;
            }
        }
        else if(a==0&&b==0)
        {
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

M = [[0 for _ in range(W)] for _ in range(H)]
i = 0
j = 0
dj = 1
k = 0
l = 0
while(l<H*W):
  if A[k] == 0:
    k += 1
  M[i][j] = k+1
  A[k] -= 1
  j += dj
  if j > W-1:
    j = W-1
    dj = -1
    i += 1
  elif j < 0:
    j = 0
    dj = 1
    i += 1
  l += 1
for m in M:
  print(*m)

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
vector<int> S,T;

ll dp[2005][2005];
bool memo[2005][2005];
ll f(int x,int y){
    if(memo[x][y]) return dp[x][y];
  	memo[x][y]=true;
    if(x==0||y==0) dp[x][y]=1;
    else{
        dp[x][y]=(f(x-1,y-1)+(f(x,y-1)-f(x-1,y-1))+(f(x-1,y)-f(x-1,y-1)))%mod;
        if(S[x-1]==T[y-1]) dp[x][y]=(dp[x][y]+f(x-1,y-1))%mod;
    }
    return dp[x][y];
}

int main() {
    int N,M;
    cin>>N>>M;
    S.resize(N);
    T.resize(M);
    for(int i = 0; i < N; i++) cin>>S[i];
    for(int j = 0; j < M; j++) cin>>T[j];
    ll ans = f(N,M);
  	if(ans<0) ans+=mod;
  	cout<<ans<<endl;
}

Measured memory_bytes: 39036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n), b(n);
  REP(i, n) { cin >> a[i] >> b[i]; }
  vector<vector<ll>> dp(n + 1, vector<ll>(t, -1));
  vector<vector<ll>> pre(n + 1, vector<ll>(t, -1));
  dp[0][0] = 0;
  REP(i, n) {
    REP(j, t) if (dp[i][j] != -1) {
      if (dp[i + 1][j] < dp[i][j]) {
        pre[i + 1][j] = pre[i][j];
        dp[i + 1][j] = dp[i][j];
      }
      if (dp[i + 1][j] == -1) {
        pre[i + 1][j] = pre[i][j];
        dp[i + 1][j] = dp[i][j];
      }
      ll x = j + a[i];
      if (x < t && dp[i][x] < dp[i][j] + b[i]) {
        pre[i + 1][x] = i;
        dp[i + 1][x] = dp[i][j] + b[i];
      }
    }
  }
  // REP(i, n + 1) REP(j, t) if (dp[i][j] != -1) {
  //   DUMP(i);
  //   DUMP(j);
  //   DUMP(dp[i][j]);
  // }

  ll ans = 0;
  REP(i, t) if (dp[n][i] != -1) {
    set<ll> st;
    REP(i, n) st.insert(i);
    ll x = n, y = i, val = dp[n][i];
    while (pre[x][y] != -1) {
      st.erase(pre[x][y]);
      x = pre[x][y];
      val -= b[x];
      y -= a[x];
    }

    ll maxi = 0;
    FOREACH(p, st) { chmax(maxi, b[p]); }
    chmax(ans, maxi + dp[n][i]);
    // DUMP(maxi);
    // DUMP(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 143232
n,*a=map(int,open(0).read().split())
dp=[[0]*(n+1) for _ in range(n+1)]
for l in range(n)[::-1]:
	for r in range(n)[::-1]:
		if l+r<=n-1:
			dp[l][r]=max(a[l]-dp[l+1][r],a[n-1-r]-dp[l][r+1])
print(dp[0][0])

Measured memory_bytes: 112348
#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
typedef long long LL;
#define int LL
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
signed main(){
	int a=readint(),b=readint(),n=readint();
	int x=min(n,b-1);
	printf("%lld",(a*x)/b-a*(x/b));
	return 0;
}

Measured memory_bytes: 3696
n,d=map(int,input().split())
x = [[0 for i in range(d)] for j in range(n)]
for i in range(n):
  x[i] = list(map(int,input().split()))
count=0
for i in range(n-1):
  for j in range(i+1,n):
    r2=0
    for k in range(d):
      r2+=(x[i][k]-x[j][k])**2
    r=r2**(1/2)
    if r.is_integer():
      count+=1
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int flg = 0;
  if(A == B) ++flg;
  if(B == C) ++flg;
  if(C == A) ++flg;
  if(flg == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

h,w=(int(x) for x in input().split())

sl=[]

for _ in range(h):
    s = input()
    sl.append(s[:-1])

for i in range(h):
    for j in range(w):
        mc=0
        #print("in j:",i,j,":sl:",sl[i][j])
        if sl[i][j]!="#":
            for k in range(-1,2):
                #print("in k:",k)
                for l in range(-1,2):
                    if (i==0 and k==-1) or (j==0 and l==-1) or (i==h-1 and k==1) or (j==w-1 and l==1):
                        continue
                    #print("in l:",k,l,":sl:",sl[i+k][j+l])
                    if sl[i+k][j+l]=="#":
                        mc+=1
                        #print("mc",str(mc))
                if (i==0 and k==-1) or (j==0 and l==-1) or (i==h and k==1) or (i==w and l==1):
                        continue
        if j == 0:
            sl[i]=sl[i][j].replace('.',str(mc))+sl[i][j+1:]
        elif j == w-1:
            sl[i]=sl[i][:j]+sl[i][j].replace('.',str(mc))
        else:
            #print("else",sl[i][:j-1])
            sl[i]=sl[i][:j]+sl[i][j].replace('.',str(mc))+sl[i][j+1:]
        #print("replaced:",sl[i],"sl:",sl)

#print(sl)

for i in range(h):
    print(sl[i])

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

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000;
const double PI = acos(-1);
const int mod = 1000000007;


int main()
{
    int x;
    cin >> x;
    if (x > 2100) {
        cout << 1 << endl;
        return 0;
    }

    int ans[100000] = {};
    for (int i = 1; i <= 20; i++) {
        for (int j = 0; j <= 5 * i; j++) {
            ans[100 * i + j] = 1;
        }
    }
    cout << ans[x] << endl;
    return 0;
}


Measured memory_bytes: 4040
import math
n = int(input())
a = list(map(int, input().split()))

l = [0 for i in range(n+1)]
for i in range(n, 0, -1):
    if i > n//2 and a[i-1] == 1:
        l[i] = 1
    elif i <= n//2:
        tmp = 2
        cnt = 0
        while tmp*i <= n:
            cnt += l[tmp*i]
            tmp += 1
        if cnt%2 != a[i-1]:
            l[i] = 1
l2 = []
for i in range(len(l)):
    if l[i] == 1:
        l2.append(i)
print(len(l2))
print(" ".join(map(str, l2)))

Measured memory_bytes: 20276
from heapq import*
I=float("inf")
def m():
 n=int(input())
 A=[]
 for _ in range(n):
  e=list(map(int,input().split()))
  A+=[zip(e[2::2],e[3::2])]
 d=[0]+[I]*n
 H=[(0,0)]
 while H:
  u=heappop(H)[1]
  for v,c in A[u]:
   t=d[u]+c
   if d[v]>t:
    d[v]=t
    heappush(H,(t,v))
 print('\n'.join(f'{i} {d[i]}'for i in range(n)))
m()


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

int main(){

  int n;
 
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    
    int tbl[11][11]={{0}};
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	scanf("%d",&tbl[i][j]);
	tbl[i][n] += tbl[i][j];
	tbl[n][j] += tbl[i][j];
	tbl[n][n] += tbl[i][j];
      }
    }
    
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	printf("%5d",tbl[i][j]);
      }
      printf("\n");
    }
  }

  return 0;

}

Measured memory_bytes: 1204
#include <stdio.h>

int main() {
    const int MAX = 9;

    for (int i = 1; i <= MAX; ++i) {
        for (int j = 1; j <= MAX; ++j) {
            int result = i * j;
            printf("%dx%d=%d\n", i, j, result);
        }
    }
}

Measured memory_bytes: 924
fn main() {
	let mut s = [false; 13];
	let mut h = [false; 13];
	let mut c = [false; 13];
	let mut d = [false; 13];
	
	let n = readLine::<usize>();
	for _ in 0..n {
	    let mut line = String::new();
	    std::io::stdin().read_line(&mut line).ok();
		let v : Vec<&str> = line.trim().split_whitespace().collect();
		let (suit, i) = (v[0], v[1].parse::<usize>().ok().unwrap() - 1);
		
		match suit {
			"S" => s[i] = true,
			"H" => h[i] = true,
			"C" => c[i] = true,
			"D" => d[i] = true,
			_   => panic!(),
		}
	}
	print_card("S", s);
	print_card("H", h);
	print_card("C", c);
	print_card("D", d);
}

fn print_card(suit: &str, xs: [bool; 13]) {
	for i in 0..13 {
		if !xs[i] {
			println!("{} {}", suit, i + 1);
		}
	}
}

fn readLine<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint h,n;cin >>h>> n;
    vector<lint> a(n),b(n);
    REP(i, n) {
       cin >> a[i] >> b[i];
    }

    lint XXX = 100000000;
    vector<lint> d(XXX,XXX); //ダメージiでの最小消費魔力
    lint ans=XXX;
    d[0] = 0;
    REP(i,n){
        REP(j,h){
            d[j + a[i]] = min(d[j+a[i]],d[j]+b[i]);
            if(j+a[i]>=h){
                ans = min(ans, d[j + a[i]]);
            }
        }
    }
    REP(i,2*h){
      //cout <<i<<" "<< d[i] << "\n";
    }
    FOR(i,h, XXX)
    {
        if(d[i]!=XXX){
            //ans = d[i];
            break;
        }
    }

    cout << ans <<"\n";

    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n; double d;
    cin>>n>>d;
    int c=0;
    while(n--){
        double x, y;
        cin>>x>>y;
        double dis = sqrt( pow(x,2) + pow(y, 2) );
        if( dis <= d) c++;

    }
    cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 3832
import java.io.*;

class Main
{
 public static void main(String[] args) throws IOException
 {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
  String[] str = br.readLine().split(" "); 
  int x=Integer.parseInt(str[0]);
  int y=Integer.parseInt(str[1]);
  
  System.out.println(x*y + " " + (2*x+2*y));
 }
}

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


#define INF 1000000000000


signed main()
 {
   int n,c;
   cin>>n>>c;
   int d[c][c];
   int iro[n][n];
   rep(i,c){
     rep(j,c){
       cin>>d[i][j];
     }
   }
   rep(i,n){
     rep(j,n){
       cin>>iro[i][j];
     }
   }

   int mod1[c],mod2[c],mod0[c];
   rep(i,c){
     mod1[i]=0;
     mod2[i]=0;
     mod0[i]=0;
   }
   rep(i,n){
     rep(j,n){
       if((i+j)%3==0){
         mod0[iro[i][j]-1]++;
       }
       else if((i+j)%3==1){
         mod1[iro[i][j]-1]++;
       }
       else mod2[iro[i][j]-1]++;
     }
   }
int ans=INF;
   rep(i,c){
     rep(j,c){
       rep(k,c){
         if(i==j||j==k||i==k){continue;}
         int iwa=0;
         rep(l,c){
           iwa+=d[l][i]*mod0[l];
         }
         rep(l,c){
           iwa+=d[l][j]*mod1[l];
         }
         rep(l,c){
           iwa+=d[l][k]*mod2[l];
         }
         ans=min(iwa,ans);
       }
     }
   }
   cout<<ans;


 }


Measured memory_bytes: 2176
#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++)

vector<ll> yakusu(ll n){
    vector<ll> ret;
    for(ll i = 1; i*i <= n; i++){
        if(n % i != 0) continue;
        ret.push_back(i);
        if(i*i != n) ret.push_back(n/i);
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    ll N;
    cin >> N;
    ll ans = yakusu(N-1).size() - 1;
    auto t = yakusu(N);
    for(auto tt : t){
        if(tt == 1) continue;
        ll n = N;
        while(n % tt == 0){
            n /= tt;
        }
        if(n % tt == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
    vector<int> A(3);
    rep(i,3) cin >> A[i];

    vector<vector<int>> order = {{0,1,2}, {1,2,0}, {2,1,0}, {0,2,1}, {2,1,0}, {1,0,2}};
    int ans = 10e5;
    rep(i,6) {
        int tmp = abs(A.at(order.at(i).at(1)) - A.at(order.at(i).at(0))) + abs(A.at(order.at(i).at(2)) - A.at(order.at(i).at(1)));
        ans = min(ans, tmp);
    }
    cout << ans << endl;
} 


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            List<int> scales;
            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                scales = new List<int>();

                int weight = int.Parse(input);
                int scale = 512;

                while (scale > 0)
                {
                    if (weight >= scale)
                    {
                        weight -= scale;
                        scales.Add(scale);
                    }
                    scale /= 2;
                }

                scales.Reverse();

                sb.Append(scales[0]);
                for (int i = 1; i < scales.Count; i++) sb.Append(" " + scales[i]);
                sb.Append("\n");
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9112
#include <stdio.h>

int main(){
  int n;
  int e,o;
  int even[100001];
  int odd[100001];
  int even_max=0,even_max_n=0;
  int even_second=0,even_second_n=0;
  int odd_max=0,odd_max_n=0;
  int odd_second=0,odd_second_n=0;
  
  for(int i=1;i<=100000;i++)
    even[i]=odd[i]=0;
  
  scanf("%d",&n);
  for(int i=0;i<n/2;i++){
    scanf("%d %d",&o,&e);
    odd[o]++;
    even[e]++;
  }
  
  for(int i=1;i<=100000;i++){
    if(even[i]>even_max){
      even_second=even_max;
      even_second_n=even_max_n;
      even_max=even[i];
      even_max_n=i;
    }else if(even[i]>even_second){
      even_second=even[i];
      even_second_n=i;
    }
    if(odd[i]>odd_max){
      odd_second=odd_max;
      odd_second_n=odd_max_n;
      odd_max=odd[i];
      odd_max_n=i;
    }else if(odd[i]>odd_second){
      odd_second=odd[i];
      odd_second_n=i;
    }
  }

  if(odd_max_n!=even_max_n)
    printf("%d\n",n-odd_max-even_max);
  else
    if(even_second<odd_second)
      printf("%d\n",n-odd_second-even_max);
    else
      printf("%d\n",n-odd_max-even_second);

  return 0;
}


Measured memory_bytes: 896
x, y = map(int, input().split())
if x in (4, 6, 9, 11) and y in (4, 6, 9, 11):
    print("Yes")
elif x in (1, 3, 5, 7, 8, 10, 12) and y in (1, 3, 5, 7, 8, 10, 12):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         long A=gl();
         long B=gl();
         long N=gl();
         
         long ans=Math.floorDiv(A*(B-1), B);
         if(N<B-1)ans=Math.floorDiv(A*N, B);

         System.out.println(ans);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 35324
using System;
using System.Text.RegularExpressions;

// (5-(6/2/2+50*3/2/3*6/4)/9*2-(6/2/2+50*3/2/3*6)-36)*2-1=

class AOJ0109{
	static Regex addsub = new Regex("^(.*?)(-?\\d+)([+Z])(-?\\d+)(.*)$",RegexOptions.Compiled);
	static Regex muldiv = new Regex("^(.*?)(-?\\d+)([*/])(-?\\d+)(.*)$",RegexOptions.Compiled);

	static String process(String s){
		//analyze parens
		int bidx=s.IndexOf("(");
		while(bidx!=-1){
			int count=1,eidx=bidx+1;
			for(;count!=0;eidx++){
				if(s[eidx]=='(')count++;
				if(s[eidx]==')')count--;
			}
			s=s.Substring(0,bidx)+process(s.Substring(bidx+1,eidx-1-(bidx+1)))+s.Substring(eidx);
			bidx=s.IndexOf("(");
		}

		//calc without parens
		MatchCollection m=muldiv.Matches(s);
		while(m.Count>0){
			if(m[0].Groups[3].Value=="*")
				s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)*int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value;
			else
				s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)/int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value;
			m=muldiv.Matches(s);
		}

		m=addsub.Matches(s);
		while(m.Count>0){
			if(m[0].Groups[3].Value=="+")
				s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)+int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value;
			else
				s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)-int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value;
			m=addsub.Matches(s);
		}
		return s;
	}

	public static void Main(string[]z){
		int n=int.Parse(Console.ReadLine());
		for(;n>0;n--){
			string s=Console.ReadLine().Replace("-","Z");
			Console.WriteLine(process(s.Substring(0,s.Length-1)));
		}
	}
}

Measured memory_bytes: 8024
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)998244353, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int cvf(ll& n) {
    int t = 0;
    ll k = 0;
    while (k < n) {
        k = (k + 1) * 26;
        t++;
    }
    k = k / 26 - 1;
    n -= k + 1;
    return t;
}

int main(void) {
    int t, i;
    ll n;
    string ans;

    scanf("%lld", &n);

    t = cvf(n);

    for (i = 0; i < t; i++) {
        ans.push_back('a' + n % 26);
        n /= 26;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3692
function max(array){
  var result = -1 * Infinity;
  for(num of array){
    if(result < num){result = num;}
  }
  return result;
}

function main(input){
  const lines = input.split('\n')
  const nums = lines.map(line => line.split(' ').map(x => parseInt(x)));

  var n_c= nums.shift();
  const N = n_c[0];
  const C = n_c[1];
  const t = Array(200002);
  const max_recorders = Array(200002);
  max_recorders.fill(0);

  for(var c=1;c<=C;c++){
    t.fill(0)

    for(var n=0;n<N;n++){
      if(nums[n][2]==c){
        t[nums[n][0]*2-1]++;
        t[nums[n][1]*2]--;
      }
    }

    for(var i=1;i<200002;i++){
      t[i] += t[i-1];
    }

    for(var i=1;i<200002;i++){
      if(t[i]>0){
        max_recorders[i]++;
      }
    }


  }

//  console.log(nums);
//  console.log(t);
  console.log(max(max_recorders));
//  console.log((max_recorders));
}



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

Measured memory_bytes: 55436
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

e = [[] for _ in range(n)]
for a, b in ab:
    e[a].append(b)
    e[b].append(a)

t = [0] * n
a = [0] * n

def dfs(x, p, d, c):
    if len(e[x]) == 1:
        if e[x][0] == p:
            return
    for y in e[x]:
        if y == p:
            continue
        if c == 0:
            t[y] = d
        else:
            a[y] = d
        dfs(y, x, d+1, c)

dfs(u, -1, 1, 0)
dfs(v, -1, 1, 1)
ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(a[i], ans)

print(ans-1)

Measured memory_bytes: 108192
n = int(input())
ls = list(map(int, input().split()))

curr = 1000
stock = 0

for i in range(n - 1):
    if ls[i] < ls[i + 1] and curr >= ls[i]:
        stock += curr // ls[i]
        curr -= stock * ls[i]
    elif ls[i] > ls[i + 1]:
        curr += stock * ls[i]
        stock = 0 

curr += stock * ls[i + 1]
stock = 0

print(curr)


Measured memory_bytes: 9016
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL dp[10][12]; //dp[i][j]代表以i开头的j位数有多少个lun number 
LL k, ans[12]; //ans[i]表示i位lun number的个数
int bit;

void dfs(int num, int alter) { //第一个参数表示第几位(层数), 第二个参数表示变化方式(-1/不变/+1)
	if(num > bit) return ;
	if(num == 1) { //第一位直接枚举1 ~ 9
		for(int i = 1; i <= 9; i++) { //后缀共bit - num + 1位
			if(k > dp[i][bit - num + 1]) k -= dp[i][bit - num + 1];
			else {
				cout << i; //最高位的值
				dfs(num + 1, i); //这时候dfs进入下一层看第二高位是几, 进入else特判内, 记忆化搜索
				break;
			}
		}
	}
	else {
		for(int i = alter - 1; i <= alter + 1; i++) {
			if(!(i >= 0 && i <= 9)) continue;
			if(k > dp[i][bit - num + 1]) k -= dp[i][bit - num + 1];
			else {
				cout << i;
				dfs(num + 1, i);
				break;
			}
		}
	}
}

int main() {
	cin >> k;
	for(int i = 0; i < 10; i++) dp[i][1] = 1;
	ans[1] = 9LL;
	for(int j = 2; j <= 10; j++) { //位数:2 ~ 10
		for(int i = 0; i < 10; i++) { //最高位:0 ~ 9
			if(i == 0) dp[i][j] = dp[i][j - 1] + dp[i + 1][j - 1];
			//最高位i = 0时的j位数只能以i和i + 1作最高位的j - 1位数作为后缀
			else if(i == 9) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
			//最高位i = 9时的j位数只能以i - 1和i作最高位的j - 1位数作为后缀
			else dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + dp[i + 1][j - 1]; 
			//最高位非0非9时, 以i - 1、i本身、i + 1作最高位的j - 1位数均可作为最高位是i的j位数的后缀
			if(i) ans[j] += dp[i][j]; //没有前导0时就将dp[i][j]表示的个数存入ans[j]
		}
	}
	for(int i = 1; i <= 20; i++) {
		if(k > ans[i]) k -= ans[i];
		else {
			bit = i; //所求转化为:位数为bit位的所有数中的第k小的那个(将当前k定位在bit位)
			break;
		}
	}
	dfs(1, 0);
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;

double max_r(const vector<int> &xs, const vector<int> &ys, double x, double y){
    double r_max = 0;
    for(int i=0;i<xs.size();i++){
        r_max = max(r_max, hypot(x - xs[i], y - ys[i]));
    }
    return r_max;
}

double min_circle_r(const vector<int> &xs, const vector<int> &ys, double x){
    double lo = -1000, hi = 1000;
    for(int i=0;i<70;i++){
        double side = (hi - lo) / 3;
        double a = lo + side;
        double b = hi - side;
    
        double fa = max_r(xs, ys, x, a);
        double fb = max_r(xs, ys, x, b);
        
        if(fa < fb){
            hi = b;
        } else {
            lo = a;
        }
    }
    
    return max_r(xs, ys, x, lo);
}

double min_circle_r(const vector<int> &xs, const vector<int> &ys){
    double lo = -1000, hi = 1000;
    for(int i=0;i<70;i++){
        double side = (hi - lo) / 3;
        double a = lo + side;
        double b = hi - side;
    
        double fa = min_circle_r(xs, ys, a);
        double fb = min_circle_r(xs, ys, b);
        
        if(fa < fb){
            hi = b;
        } else {
            lo = a;
        }
    }
    
    return min_circle_r(xs, ys, lo);
}


int n, m;
int r[111];

double R[111];
bool used[111];

int main(){
    cin >> n;
    vector<int> xs(n), ys(n);
    for(int j=0;j<n;j++){
        cin >> xs[j] >> ys[j];
    }
    double ans=min_circle_r(xs,ys);
    cout << fixed << setprecision(15);
	cout<<ans<<endl;
    return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 60;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;
  vll cnt(3, 0);
  for (char c : s) {
    ll idx = c - 'a';
    cnt[idx]++;
  }
  Sort(cnt);
  string ans = "NO";
  if (cnt[2] <= cnt[0] + 1 && cnt[2] <= cnt[1] + 1 ) ans = "YES";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL

	int a[4];
	scanf("%d %d %d", &a[0],  &a[1], &a[2]);
	sort(a, a + 3);
	int ans = 0;
	for (int i = 1; i <= 2; ++i) {
		ans += abs(a[i] - a[i - 1]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
S = int(input())
s12 = S // 100
s34 = S % 100

if s34 >=1 and s34 <= 12:
    yymm = True
else:
    yymm = False

if s12 >=1 and s12 <= 12:
    mmyy = True
else:
    mmyy = False

if yymm and mmyy:
    ans = 'AMBIGUOUS'
elif yymm:
    ans = 'YYMM'
elif mmyy:
    ans = 'MMYY'
else:
    ans = 'NA'

print(ans)


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

int main(){
	int n,i;
	int shcd[52];
	string mark[5]={"S","H","C","D"};
	cin>>n;
	string str[n];
	int a[n];
	for(i=0; i<n; i++){
		cin>>str[i]>>a[i];
	}
	for(i=0; i<52; i++){
		shcd[i]=i%13+1;
	}
	for(i=0; i<n; i++){
		if(str[i]=="S"){
			shcd[a[i]-1]=0;
		}else if(str[i]=="H"){
			shcd[a[i]+12]=0;
		}else if(str[i]=="C"){
			shcd[a[i]+25]=0;
		}else{
			shcd[a[i]+38]=0;
		}
	}
	int m=0;
	for(i=0; i<52; i++){
		if(shcd[i]!=0) cout<<mark[m]<<" "<<shcd[i]<<"\n";
		if((i+1)%13==0) m++;
	}
	return 0;
}


Measured memory_bytes: 3108
#include <math.h>       /* cos */
double last_turn;
#define PI 3.14159265

double walk(double go,double turn,double* x,double* y) {
			*x -= go * sin(last_turn* PI / 180.0);
			*y += go * cos(last_turn* PI / 180.0);
			return -turn; 

}
int main()
{
	double gx = 0,gy = 0,now_x = 0, now_y = 0;
	double go = 0, turn = 0;

	last_turn = 0;
	now_x = 0, now_y = 0;
	for(;;){
		go = 0, turn = 0;
		scanf("%lf,%lf",&go,&turn);
		last_turn += walk(go,turn,&now_x,&now_y);
		if(go==0 && turn==0) break;
	}

		printf("%d\n%d\n",(int)now_x,(int)now_y);
	return 0;
}

Measured memory_bytes: 664
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 1010;
int A[maxn],cnt = 0,
B[maxn],C[maxn],ans=0;
int check(int x)
{
    memset(A,0,sizeof(A));
    cnt = 0;
    if(x != 0)
    while(x)
    {
       A[cnt++] = x%10;
       x/=10;
    }
    else{
        A[0] = 0;
        cnt++;
    }
    for(int i=0;i<cnt;i++){
        for(int j=0;j<ans;j++ ){
            if(A[i] == C[j])
                return 0;
        }

    }
    return 1;

}
int main()
{
    int n,sum;
    scanf("%d %d",&sum,&n);
    memset(B,0,sizeof(B));
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp;
        B[temp] = 1;
    }
    ans = 0;
    for(int i=0;i<10;i++)
    {
        if(B[i]==1)
            C[ans++]=i;
    }
    for(int i=sum;i<100010;i++)
    {
        if(check(i)){
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int dp[101][4][4][4];
int main() {
    int n; cin >> n;

    dp[0][3][3][3] = 1;

    int mod = 1000000007;
    rep(len,n){
        rep(i,4){
            rep(j,4){
                rep(k,4){
                    if(dp[len][i][j][k]==0) continue;

                    rep(a,4){
                        if(a == 2 && i == 1 && j==0) continue;
                        if(a == 2 && i == 0 && j==1) continue;
                        if(a == 1 && i == 2 && j==0) continue;
                        if(a == 2 && i == 1 && k==0) continue;
                        if(a == 2 && j == 1 && k==0) continue;

                        dp[len+1][a][i][j] += dp[len][i][j][k];
                        dp[len+1][a][i][j] %= mod;
                    }
                }
            }
        }
    }

    int ans = 0;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                ans += dp[n][i][j][k];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

    vector <int> P(N);
    vector <long long> C(N);

    for (int i = 0; i < N; ++i) {
        cin >> P[i];
        --P[i];
    }

    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }

    const long long INF = 1000000000LL * 1000000000LL;
    long long ans = -INF;
    vector <int> idx(N);
    vector <long long> acc(N);

    for (int i = 0; i < N; ++i) {
        int now = i;
        long long sum = 0;
        long long maxSum = -INF;
        long long cycleSum = 0;
        int cnt = 0;
        int cycleLength = 1;

        fill(idx.begin(), idx.end(), -1);
        fill(acc.begin(), acc.end(), 0);
        idx[now] = 0;
        acc[cnt] = sum;

        while (cnt < K) {
            now = P[now];
            if (idx[now] != -1) {
                // detect cycle
                cycleLength = (cnt+1) - idx[now];
                sum += C[now];
                cycleSum = idx[now] > 0 ? C[now] + acc[cnt] - acc[idx[now]-1] : C[now] + acc[cnt];
                // cout << i << " COLLISION IDX " << now << " " << cnt << " " << idx[now] << " " << acc[cnt] << endl;
                maxSum = max(maxSum, sum);
                ++cnt;
                break;
            }

            sum += C[now];
            idx[now] = cnt++;
            acc[cnt] = sum;
            // cout << "DEBUG GOGO " << now << " " << sum << endl;
            maxSum = max(maxSum, sum);
        }

        for (int s = 0; s < cycleLength && cnt < K; ++s) {
            now = P[now];
            sum += C[now];
            ++cnt;
            maxSum = max(maxSum, sum);
        }

        // loop sum
        int goStep = max(0, (K-cnt) / cycleLength - 1);
        sum += goStep * cycleSum;
        maxSum = max(maxSum, sum);

        int remain = K - cnt - goStep * cycleLength;
        // cout << "GOSTEP " << goStep << " " << sum << " " << remain << endl;

        for (int r = 0; r < remain; ++r) {
            now = P[now];
            sum += C[now];
            maxSum = max(maxSum, sum);
        }

        ans = max(ans, maxSum);
        // cout << "START " << i << " " << sum << endl;
        // cout << "DEBUG " << cycleSum << " " << cycleLength << endl;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    for (int i = 0; i < A; i++) {
        cin >> p.at(i);
    }
    for (int i = 0; i < B; i++) {
        cin >> q.at(i);
    }
    for (int i = 0; i < C; i++) {
        cin >> r.at(i);
    }
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    sort(r.begin(), r.end());
    ll psum = 0, qsum = 0;
    ll pk = A - X, qk = B - Y, rk = C - 1;
    for (int i = 0; i < C; i++) {
        ll P, Q, R = r.at(rk);
        if (pk < A) P = p.at(pk);
        else P = inf;
        if (qk < B) Q = q.at(qk);
        else Q = inf;
        ll low = min(P, Q);
        if (low == P && P < R && pk < A) {
            swap(p.at(pk), r.at(rk));
            pk++;
            rk--;
        }
        else if (low == Q && Q < R && qk < B) {
            swap(q.at(qk), r.at(rk));
            qk++;
            rk--;
        }
        if (rk < 0) break;
    }
    for (int i = A - 1; i >= A - X; i--) {
        psum += p.at(i);
    }
    for (int i = B - 1; i >= B - Y; i--) {
        qsum += q.at(i);
    }
    cout << psum + qsum << endl;
}

Measured memory_bytes: 2560
import itertools
import math
import fractions
import functools
import copy

n = int(input())
sp = []
for i in range(n):
    s, p= input().split()
    sp.append([s,int(p),i])

sp.sort(key=lambda x: x[1], reverse=True)

sp.sort(key=lambda x: x[0])

for i in range(n):
    print(sp[i][2]+1)

Measured memory_bytes: 63980
N, M = map(int, input().split())
stairs = [1 for i in range(N)]
for i in range(M):
  kari = int(input())
  stairs[kari-1] = 0
mod = 1000000007
if N <= 2:
  ans = sum(stairs)
else:
  if stairs[0]==1 and stairs[1]==1:
    stairs[1] = 2
  for i in range(2, N):
    stairs[i] = (stairs[i] * (stairs[i-1] + stairs[i-2])) % mod
  ans = stairs[N-1]
print(ans)

Measured memory_bytes: 7064
import java.util.Scanner;
     
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n = sc.nextInt();
    		int m = sc.nextInt();
    		int[] h = new int[n];
    		int[] mi = new int[n];
    		for (int i = 0; i < n; i++) {
    			h[i] = sc.nextInt();
    			
    		}
    		int cnt = 0;
    		for (int i = 0; i < m; i++) {
    			int a = sc.nextInt();
    			int b = sc.nextInt();
    			mi[a - 1] = Math.max(mi[a - 1], h[b - 1]);
    			mi[b - 1] = Math.max(mi[b - 1], h[a - 1]);
    		}
    		for (int i = 0; i < n; i++) {
    			if (h[i] > mi[i]) {
    				cnt++;
    			}
    		}
    		
    		System.out.println(cnt);
    	}
     
    }

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

void replace(int a, int b, string p, string& str){
  for(int i=a; i<=b; i++){
    str[i]= p[i-a];
  }
}

void reverse(int a, int b, string& str){
  string temp; 
  for(int i=0; i<=b-a; i++){
    temp[i]=str[b-i];
  }
  for(int i=0; i<=b-a; i++){
    str[i+a] = temp[i];
  }
}

void print_range(int a, int b, string& str){
  for(int i=a; i<=b; i++){
    cout << str[i];
  }
  cout << endl;
}

int main(){
  string str, command, p;
  int q, a, b;
  cin >> str;
  cin >> q;
  for(int i=0; i<q; i++){
    cin >> command;
    if(command == "replace"){
        cin >> a >> b >> p; replace(a,b,p,str);
    }else if(command =="reverse"){
        cin >> a >> b; reverse(a,b,str);
    }else if(command =="print"){
        cin >> a >> b; print_range(a, b, str);
    }
  }
  return 0;
}


Measured memory_bytes: 3180
N,W=map(int,input().split(' '))
w=[0]*N ; v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split(' '))
dp=[[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if j<w[i-1]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1])
print(dp[N][W])

Measured memory_bytes: 121564
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

// ll modpow(ll x, ll n) {
//   if (n == 0) return 1;
//   if (n % 2 == 0) {
//     return modpow((x % MOD) * (x % MOD), n / 2);
//   } else {
//     return (x % MOD) * modpow((x % MOD) * (x % MOD), n / 2);
//   }
// }

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, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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

  ll zero = 0;

  map<pair<ll, ll>, P> mp;

  rep(i, n) {
    ll x, y;
    cin >> x >> y;

    if (x == 0 && y == 0) {
      ++zero;
      continue;
    }

    ll g = gcd(x, y);
    x /= g;
    y /= g;

    if (y < 0) { x = -x, y = -y; }
    if (y == 0 && x < 0) x = -x, y = -y;
    bool rot = x <= 0;
    if (rot) {
      ll temp = x;
      x = y;
      y = -temp;
    }

    if (rot)
      ++mp[{x, y}].first;
    else
      ++mp[{x, y}].second;
  }

  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;

    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }

  ans -= 1;
  ans += zero;

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 16084
#include<bits/stdc++.h>
#define mod 1000000007
#define p pair<int,int>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	 double res=0.0;
	for(int i=1;i<=n;i++){
		if(i>=k){
			res+=(1.0/n);
		}else{
				int power=ceil(log2(ceil(1.0*k/i)));
			    double temp=pow(2,power);
				// cout<<temp<<"\n";
				res+=(1.0/(temp*n));
			}
	}
	// res/=n;
	// cout<<res;
	printf("%.12f\n", res);
	return 0;
}

Measured memory_bytes: 256