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

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

    vector<P> AB(N);
    for (int i = 0; i < N; i++) {
        ll Atmp, Btmp;
        cin >> Atmp >> Btmp;
        AB.at(i) = make_pair(Atmp, Btmp);
    }
    sort(AB.begin(), AB.end());
    ll ans = 0, cnt = 0;
    for (int i = 0; i < N; i++) {
        if (cnt + AB.at(i).second >= M) {
            int C = M - cnt;
            ans += AB.at(i).first * C;
            break;
        } else {
            ans += AB.at(i).first * AB.at(i).second;
            cnt += AB.at(i).second;   
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <bitset>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

#define ALL(obj) (obj).begin(), (obj).end() 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)

int main(){
    int h,w;
    cin >> h >> w;
    char p[h][w+1], r[h][w+1], b[h][w+1];
    rep(i,h) cin >> p[i];
    //make red table
    rep(i,h){
        rep(j,w+1){
            if(j==w) r[i][j] = '\0';
            else if(j==0) r[i][j] = '#';
            else if(i%2==0){
                if(i==0||i==h-1) r[i][j] = '#';
                else if(j!=w-1) r[i][j] = '#';
                else r[i][j] = '.';
            }else r[i][j] = '.';
        }
    }
    //make blue table
    rep(i,h){
        rep(j,w+1){
            if(j==w) b[i][j] = '\0';
            else if(r[i][j]=='#') b[i][j] = '.';
            else b[i][j] = '#';
        }
    }
    rep(i,h){
     rep(j,w){
         if(p[i][j]=='#'){
             if(r[i][j]=='#') b[i][j] = '#';
             else r[i][j] = '#';
         }
     }
    }
    rep(i,h) cout << r[i] << endl;
    cout << endl;
    rep(i,h) cout << b[i] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int 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()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll N; cin >> N;
  vector<ll> a(N);
  REP(i, N) cin >> a[i];

  ll ans = INF;
  ll mini = *min_element(ALL(a));
  ll maxi = *max_element(ALL(a));
  FOR(x, mini, maxi+1){
    ll cost = 0;
    REP(i, N){
      cost += (x - a[i]) * (x-a[i]);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N, K;
    cin >> N >> K;
    K++;
    vec a(N);
    loop(i, N)
    {
        cin >> a[i];
        a[i]--;
    }
    vector<ll> route;
    route.push_back(0);
    ll now = 0;
    vector<bool> seen(N, false);
    while (true)
    {
        if (seen[now])
            break;
        seen[now] = true;
        route.push_back(a[now]);
        now = a[now];
    }
    ll siz = route.size();
    vec looop;
    ll point = route[siz - 1];
    bool flag = false;
    loop(i, siz)
    {
        if (flag)
            looop.push_back(route[i]);
        if (route[i] == point)
            flag = true;
    }
    ll Siz = looop.size();
    if (K < siz)
    {
        putout(route[K - 1] + 1);
        return 0;
    }
    else
    {
        ll amari = K - siz;
        amari %= Siz;
        if (amari == 0)
        {
            putout(looop[Siz - 1] + 1);
            return 0;
        }
        else
            putout(looop[amari - 1] + 1);
    }
    return 0;
}


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

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

   if (n[0] == n[2]) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
}

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

int main() {
    ll N;cin >> N;
    ll sum = 0;
    for (ll i = 1;i < N + 1;i++){
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }
    cout << sum << endl;
}

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

int main(){ 
    int a,b,cnt,i,j;

    while(cin>>a>>b){
        int add=a+b;
        cnt = 1;
        j = 10; 
        while(1){
            i = add - j;
            if(i>=0)cnt++;
            else break;
            j *= 10;
        }       
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    double t = Double.parseDouble(str[0]);
    double x = Double.parseDouble(str[1]);
    System.out.println(t/x);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;
	   string s;cin>>s;
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
		cout << "Bad" << endl;
	}else{
		cout << "Good" << endl;
	}
	return 0;
}


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

ll dp[51][51][2501];

int main(){
    ll N, A;
    cin >> N >> A;
    vector<ll> x(N+1);
    rep(i, 1, N+1) cin >> x[i];

    ll X = max(A, *max_element(x.begin(), x.end()));
    rep(j, 0, 51){
        rep(k, 0, 51){
            rep(s, 0, 2501) dp[j][k][s] = 0;
        }
    }
    dp[0][0][0] = 1;

    for(ll j = 1; j <= N; j++){
        for(ll k = 0; k <= N; k++){
            for(ll s = 0; s <= k*X; s++){
                if(s < x[j]){
                    dp[j][k][s] = dp[j-1][k][s];
                }else if(k > 0 && s >= x[j]){
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
                }
            }
        }
    }

    ll ans = 0;
    rep(k, 1, N+1) ans += dp[N][k][k*A];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51072
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#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 <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int ans;
    switch (a+b)
    {
    case 3:
        ans = 3;
        break;

    case 4:
        ans = 2;
        break;

    case 5:
        ans = 1;
        break;
    
    default:
        break;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
using System;
class Program
    {
        static void Main()
        {
            var b = Console.ReadLine();
            var result = "";
            switch (b)
            {
                case "A":
                    result = "T";
                    break;
                case "T":
                    result = "A";
                    break;
                case "C":
                    result = "G";
                    break;
                case "G":
                    result = "C";
                    break;
            }
            Console.WriteLine(result);
        }
    }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
//#define max(a,b) ((a>b)?a:b)
//#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
// #define assmin(a,b) if(b<=a) { a=b; }
// #define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
#define side 1e9
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
struct node
{
	vll adj;
    ll height;
};

ll find(ll n, ll wt, ll nm)
{
    ll st = 1;
    ll en = nm;
    ll mid = (st) + (en - st)/2;
    while(st<=en)
    {
        if(wt+3*(nm+mid)>=n && wt+2*(nm+mid)<=n)
        {
            return mid;
        }
        else if(wt+3*(nm+mid)<n)
        {
            st = mid+1;
        }
        else
        {
            en = mid-1;
        }
        mid = (st) + (en - st)/2;
    }
    if(wt+3*(nm+mid)>=n && wt+2*(nm+mid)<=n)
    {
            return mid;
     }
    return 0;
}
bool my(pair<ll, char> p1, pair<ll, char> p2)
{
    return p1.first > p2.first;
}
ll f(ll a)
{
    return (a*a*a*a*a);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    REP(i,-500,501)
    {
        REP(j,-500,501)
        {
            if(f(i) - f(j) == x)
            {
                cout<<i<<" "<<j<<"\n";
                exit(0);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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; }

ll f(ll b, ll n) {
  ll res = 0, k = n;
  do {
    res += k % b;
    k /= b;
  } while (k);
  return res;
}

int main() {
  ll n, s;
  cin >> n >> s;

  if (n == s) {
    cout << n + 1 << endl;
    return 0;
  }

  const ll INF = 1e18;
  auto find = [&](ll k, ll l, ll r) {
    ll vl = f(r, n);
    if (vl % k != s % k) return INF;
    ll vr = f(l + 1, n);
    if (vl <= s && s <= vr) return r - (s - vl) / k;
    return INF;
  };

  ll ans = INF;
  ll i = 1;

  while (n / (i + 1) != 0 && n / (i + 1) != n / i) {
    chmin(ans, find(i, n / (i + 1), n / i));
    ++i;
  }
  for (ll j = n / i; j >= 2; --j) {
    if (f(j, n) == s) ans = j;
  }

  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}


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



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

  sort(a.begin(), a.end());
  int ans=0, pre=a[0], tmp=1;
  for(int i=1; i<n; i++){
    if(a[i]==pre) tmp++;
    else{
      if(tmp%2==1) ans++;
      tmp = 1;
    }
    pre=a[i];
  }
  if(tmp%2==1)ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;
int x[1000001];
int main(){
    int n, x, t,a;
    cin >> n >> x >> t;
    if(n%x==0) a = n/x;
    else a = n/x +1;
    cout << a*t;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n), cnt(n+1);
    rep(i,n) cin>>a[i];
    map<ll,ll> mp;
    rep(i,n) cnt[a[i]]++;
    rep(i,n+1) if (cnt[i]>0) mp[cnt[i]]++;


    rep(i,n) {
        ll m = cnt[a[i]];
        mp[m]--;
        mp[m-1]++;

        ll ans = 0;
        for (auto &&e: mp) {
            if (e.second == 0) continue;
            ans += (e.first*(e.first-1)/2)*e.second;
        }
        cout << ans << '\n';

        mp[m-1]--;
        mp[m]++;
    }

    return 0;
}

Measured memory_bytes: 5760
def resolve():
    rate = int(input())
    if rate < 600:
        print('8')
    elif rate < 800:
        print('7')
    elif rate < 1000:
        print('6')
    elif rate < 1200:
        print('5')
    elif rate < 1400:
        print('4')
    elif rate < 1600:
        print('3')
    elif rate < 1800:
        print('2')
    else:
        print('1')

if __name__ == "__main__":
    resolve()

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

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w,k;
  cin >>h>>w>>k;
  bool c[h][w];
  char s;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> s;
      if(s=='#')
        c[i][j] = true;
      else
        c[i][j] = false;
    }
  }

  ll ans=0L;
  for(int i=0; i<1<<h; ++i){
    for(int j=0; j<1<<w; ++j){
      int num = 0;
      for(int l=0; l<h; ++l){
        if((i>>l)%2 == 1) continue;
        for(int m=0; m<w; ++m){
          if((j>>m)%2 == 1) continue;
          if(c[l][m]) num++;
        }
      }
      if(num==k) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

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

    const size_t move_num = 5;

    uint64_t num;
    cin >> num;
    assert(1 <= num && num <= pow(10, 15));

    uint64_t min_cost = pow(10, 15);
    for(size_t i = 0; i < move_num; ++i)
    {
        uint64_t tmp_cost;
        cin >> tmp_cost;
        min_cost = min(tmp_cost, min_cost);
    }

    uint64_t answer = move_num; // 最低限5回の移動は必要.
    if (min_cost < num) {
        double rest_num = num - min_cost;
        //cout << rest_num << " " << min_cost << " " << rest_num / min_cost << " " << ceil(rest_num / min_cost) << endl;
        answer += static_cast<uint64_t>(ceil(rest_num / min_cost)); // 残り人数を最小移動コストで割った回数分だけ追加の移動が必要になるはず.
    } else {
        
    }

    cout << answer << endl;

    // 以下､愚直に現象を実装した例.
    // nの要素数が多すぎて､数人しか移動できないケースだと､計算量が多すぎてNG.
    // const size_t cities_num = 6;
    // auto move_cost_table = vector<uint64_t>(cities_num, 0);

    // uint64_t n, a, b, c, d, e;
    // cin >> n;
    // assert(1 <= n && n <= pow(10, 15));
    // for(size_t i = 1; i < cities_num; ++i)
    // {
    //     cin >> move_cost_table[i];
    //     assert(1 <= move_cost_table[i] && move_cost_table[i] <= pow(10, 5));
    // }

    // size_t turn_count = 0;
    // auto move_table = vector<uint64_t>(cities_num, 0);
    // move_table[0] = n;
    // cout << move_table[0] << endl;

    // while(true) {
    //     for(size_t i = cities_num - 1; i >= 1; --i)
    //     {
    //         size_t move_num = min(move_table[i-1], move_cost_table[i]);
    //         move_table[i-1] -= move_num;
    //         move_table[i]   += move_num;
    //         assert(0 <= move_table[i-1]);
    //         assert(move_table[i] < pow(10, 15));
    //     }

    //     turn_count++;
    //     if (move_table[cities_num - 1] == n) {
    //         for(size_t i = 0; i < cities_num - 1; ++i) { assert(move_table[i] == 0); }
    //         break;
    //     }
    // }

    // cout << turn_count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    string s[x];
    for(int i=0;i<x;i++) cin>>s[i];
    for(int i=0;i<x+2;i++){
        for(int j=0;j<y+2;j++){
            if(i==0||i==x+1||j==0||j==y+1) cout<<'#';
            else cout<<s[i-1][j-1];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// Union find
struct uf {
  vector<int> d, l, r;
  uf(){}
  uf(int mx):d(mx,-1) {
    l = r = vi(mx);
    rep(i,mx) l[i] = r[i] = i;
  }
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    mins(l[x],l[y]);
    maxs(r[x],r[y]);
    return true;
  }
  int size(int x) { return -d[root(x)];}
};
//


int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  rep(i,n) scanf("%d",&a[i]), a[i]--;
  vi b(n);
  rep(i,n) b[a[i]] = i;
  uf t(n);
  ll ans = 0;
  drep(ai,n) {
    int i = b[ai];
    if (i > 0 && a[i-1] > a[i]) t.unite(i-1,i);
    if (i < n-1 && a[i+1] > a[i]) t.unite(i+1,i);
    int x = t.root(i);
    int l = i-t.l[x]+1, r = t.r[x]-i+1;
    // cout<<i<<" "<<l<<" "<<r<<endl;
    ans += (ll)l*r*(ai+1);
  }
  cout<<ans<<endl;
  return 0;
}







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


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

	int cnt = 0;
  bool unko = false;
	for (int i = 1, j = n - 1; i < j; ++i, --j) {
      if (!unko && n % 2 == 0 && i + n / 2 >= j) --j, unko = true;
		cout << i << " " << j << '\n';
		++cnt;
		if (cnt == m) break;
	}
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

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

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

    if(s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	int N;
	cin >> N;

	vector<int> a(N, 0);

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

	int ans = 0;
	for (int i = 0; i < N; i += 2) {
		if (a[i] % 2 == 1) {
			ans += 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;

// Combination Table
ll C[51][51]; // C[n][k] -> nCk
void comb_table(int N){
for(int i=0;i<=N;++i){
for(int j=0;j<=i;++j){
 if(j==0 or j==i){
 C[i][j]=1LL;
 }else{
 C[i][j]=(C[i-1][j-1]+C[i-1][j]);
 }
 }
 }
 }
int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end(), greater<ll>());
    double sum = 0.;
    rep(i,A) {
        sum += v[i];
    }
    double ave = sum / A;
    cout.precision(20);
    print(ave);
    ll A_cnt_all = 0;
    ll A_cnt = 0;
    comb_table(N);
    rep(i, N)
    {
        if (v[i] == v[A-1]) {
            A_cnt_all++;
            if (i < A)
                A_cnt++;
        }
    }
    ll cnt = 0LL;
    if (v[0] != v[A - 1])
    {
        cnt += C[A_cnt_all][A_cnt];
    } else {
        for (ll i = A; i <= B; ++i) {
            cnt += C[A_cnt_all][i];
        }
    }
    print(cnt);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(((N+1)//2)/N)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 100003


int sink, source, dist[mx], q[mx], work[mx], idx;
const int INF = 1e9;
struct edge{
  int to, rev;
  int flow, cap;
};
vector<edge> G[mx];
inline void add(int s, int t, int cap) {
  edge a = {t, G[t].size(), 0, cap};
  edge b = {s, G[s].size(), 0, cap};
  G[s].push_back(a);
  G[t].push_back(b);
}
inline bool search() {
  for(int i = 0; i < idx; i++) dist[i] = -1;
  dist[source] = 0;
  int tail = 0;
  q[tail] = source;
  for(int head = 0; head <= tail; head++) {
    int u = q[head];
    int sz = G[u].size();
    for(int i = 0; i < sz; i++) {
      int v = G[u][i].to;
      if (dist[v] < 0 && G[u][i].flow < G[u][i].cap) {
        dist[v] = dist[u] + 1;
        q[++tail] = v;
      }
    }
  }
  return dist[sink] >= 0;
}
int dinic(int now, int flo) {
  if (now == sink)
    return flo;
  int size = G[now].size();
  for(int &i = work[now]; i < size; i++) {
    int to = G[now][i].to, flow = G[now][i].flow, cap = G[now][i].cap, rev = G[now][i].rev;
    if (flow >= cap) continue;
    if (dist[to] == dist[now] + 1) {
      int fflow = dinic(to, min(flo, cap - flow));
      if (fflow) {
        G[now][i].flow += fflow;
        G[to][rev].flow -= fflow;
        return fflow;
      }
    }
  } 
  return 0;
}
inline int maxflow() {
  int ans = 0;
  while(search()) {
    for(int i = 0; i < idx; i++) work[i] = 0;
    while(true) {
      int res = dinic(source, INF);
      if (res == 0) break;
      ans += res;
    }
  }
  return ans;
}

int n, m, row[103], col[103];
string ss[103];

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> ss[i];
	for(int i = 0; i < n; i++)
		row[i] = idx++;
	for(int i = 0; i < m; i++)
		col[i] = idx++;
	source = idx++;
	sink = idx++;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(ss[i][j] == 'o'){
				add(row[i], col[j], 1);
			}
			else if(ss[i][j] == 'S'){
				add(source, row[i], 1e8);
				add(source, col[j], 1e8);
			}
			else if(ss[i][j] =='T'){
				add(row[i], sink, 1e8);
				add(col[j], sink, 1e8);
			}
		}
	}
	auto jaw = maxflow();
	if(jaw >= 1e8)
		jaw = -1;
	cout << jaw << endl;
}

Measured memory_bytes: 3072
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

    int k=S.size();

    int j=0,jj=0;

    if(S[0]=='A'){
      for(int a=2;a<k-1;++a){
        if(S[a]=='C'){++j;}
      }
      if(j==1){
        for(int a=0;a<k;++a){
          if(S[a]!='A' && S[a]!='C'){
            if(S[a]>='a' && S[a]<='z') {++jj;}
          }
        }
        if(jj==k-2){cout<<"AC"<<endl;}
        else {cout<<"WA"<<endl;}
      }
      else {cout << "WA" << endl;}
    }
    else {cout << "WA" << endl;}
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int tab[200005];
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	int k,n;
	cin>>k>>n;
	for (int i = 0; i < n; ++i)
		cin>>tab[i];
	int ans=INF;
	for (int i = 0; i < n; ++i)
		ans=min(ans,tab[i]-tab[0]+((i!=(n-1))?(k-tab[i+1]+tab[0]):0));
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  string s;
  cin>>s;
  switch(s[0]){
    case 'A':
    s[0] = 'T';break;
    case 'T':
    s[0] = 'A';break;
    case 'C':
    s[0] = 'G';break;
    case 'G':
    s[0] = 'C';break;
  }
  cout<<s[0]<<endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := intScanner(), intScanner()
	r := make([]int, 26)
	for i := 0; i < h; i++ {
		for _, v := range Scanner() {
			r[int(v)-97]++
		}
	}
	x := (h % 2) * (w % 2)
	y := w*(h%2) + h*(w%2) - x*2
	z := (h - h%2) * (w - w%2)
	for i := 0; i < 26; i++ {
		for r[i] >= 4 && z != 0 {
			r[i] -= 4
			z -= 4
		}
	}
	for i := 0; i < 26; i++ {
		for r[i] >= 2 && y != 0 {
			r[i] -= 2
			y -= 2
		}
	}
	for i := 0; i < 26; i++ {
		for r[i] >= 1 && x != 0 {
			r[i]--
			x--
		}
	}
	if x == 0 && y == 0 && z == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long
 
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
 
const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX;
const int INF = INT_MAX;
 
inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
 
signed main()
{
	double R;
	cin >> R;
 
	printd(2.0 * PI * R);
	
	return 0;
}

Measured memory_bytes: 3780
s = input().strip()

if (s[0] == "R") and (s[1] =="R") and (s[2] =="R"):
  print(3)
elif (s[0] == "R" and s[1] == "R" and s[2] == "S")or(s[0] == "S" and s[1] == "R" and s[2] == "R"):
  print(2)
elif s[0] == "S" and s[1] == "S" and s[2] == "S":
  print(0)
else:
  print(1)
  

Measured memory_bytes: 8884
N,K =map(int,input().split())
A=list(map(int,input().split()))

n=[1]
t=1
ord=[-1]*(N+1)
ord[0]=0

while True:
    t=A[t-1]
    if ord[t] != -1:
        f=n.index(t)
        break
    n.append(t)
    ord[t]=0

k=len(n)-f

if K>=f:
    print(n[f+(K-f)%k])

else:
    print(n[K])
  

Measured memory_bytes: 32332
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int bit[1<<15], N;
inline int sum(int i){
	int s=0;
	while(i){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
inline void add(int i,int x){
	i++;
	while(i<=N){
		bit[i]+=x;
		i+=i&-i;
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	int n,k,m;
	while(cin>>n>>k>>m && n){
		memset(bit,0,sizeof(bit));
		N=2*n;
		rep(i,2*n){
			add(i,1);
		}
		int cur = m-1;
		rep(i,n-1){
			add(cur,-1);
			add(cur+n,-1);
			int step = k % (n-1-i);
			if(step==0) step = n-1-i;
			int lo = cur, hi = cur+n;
			while(lo+1 < hi){
				int mi = lo+hi >> 1;
				if(sum(mi+1) - sum(cur+1) >= step) hi = mi;
				else lo = mi;
			}
			cur = hi % n;
		}
		cout<<cur+1<<endl;
	}
}

Measured memory_bytes: 1328
fun main(args: Array<String>) {
    val (x, n) = readLine()!!.split(' ').map(String::toLong)
    if(n==0L){
        println(x)
        return
    }
    val pList = readLine()!!.split(' ').map(String::toLong)

    for(i in 0..100){
        if(pList.contains(x-i).not()){
            println(x-i)
            return
        }
        if(pList.contains(x+i).not()){
            println(x+i)
            return
        }

    }
}


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,n,k,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll a[100005],dp[100005];

ll fn(ll pos,ll n)
{
    if(pos==n)
    {
        return 0;
    }
    ll &z=dp[pos];
    if(z!=-1)return z;
    z=inf;
    if(pos+1<=n)
    {
        z=min(z,abs(a[pos]-a[pos+1])+fn(pos+1,n));
    }
    if(pos+2<=n)
    {
        z=min(z,abs(a[pos]-a[pos+2])+fn(pos+2,n));
    }
    return z;
}

int main()
{
    SPEED;
    ll var;
    mem(dp,-1);
    sfl(n);
    for(i=1;i<=n;i++)sfl(a[i]);
    z=fn(1,n);
    cout<<z<<endl;
}


Measured memory_bytes: 6528
#include<stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d", &a, &b);
  c = a * b;
  for(int i = 1; i < 4; i++) {
    if((c * i) % 2 != 0) {
      printf("Yes\n");
      return;
    }
  }
  printf("No\n");
  return;
}
  

Measured memory_bytes: 1648
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] c=new int[n];
		int[] s=new int[n];
		int[] f=new int[n];
		for(int i=0;i<n-1;i++) {
			c[i]=sc.nextInt();
			s[i]=sc.nextInt();
			f[i]=sc.nextInt();
		}

		for(int i=0;i<n-1;i++) {
			int now=0;
			for(int j=i;j<n-1;j++) {
				if(now<=s[j]) {
					now=s[j]+c[j];
				}else {
					int buf=s[j];
					while(now>buf) {
						buf+=f[j];
					}
					now=buf+c[j];
				}
			}
			System.out.println(now);
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 26168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> s(n);
	int res = 0;
	rep(i, n) {
		cin >> s[i];
		res += s[i];
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n; ++i) {
		if (res % 10 != 0) break;
		if (s[i] % 10 == 0) continue;
		res -= s[i];
	}
	if (res % 10 == 0) dunk(0);
	else dunk(res);
	return 0;
}


Measured memory_bytes: 256
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
mi = 0
ma = max(a)
m = ma//2
while ma-mi>1:
  temp = 0
  for i in range(n):
    temp += ceil(a[i]/m)-1 
    #if a[i]%m==0:
    #  temp-=1
  if temp<=k:
    ma=m
    m=(ma+mi)//2
  else:
    mi = m
    m=(ma+mi)//2
  #print("temp " + str(temp))
  #print("ma " + str(ma)+ " mi " + str(mi) + " m " + str(m))
#print(m)
print(m+1)

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


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

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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
int a[100009],b[100009];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	vector<pii> v,z;
	ll s=0;
	rep(i,n) cin>>a[i]>>b[i],v.pb({a[i]+max(0,b[i]-a[i]),i}),s+=max(0,b[i]-a[i]);
	sort(all(v));
	reverse(all(v));
	int x=0;
	ll r=0;
	while(x<n&&(r+v.back().fst<=s)){
			x++;
			r+=a[v.back().snd];
			s-=max(0,b[v.back().snd]-a[v.back().snd]);
			z.pb(v.back());
			v.pop_back();
	}
			
	ll st = s-r;
	r+=a[v.back().snd];
			s-=max(0,b[v.back().snd]-a[v.back().snd]);
			z.pb(v.back());
	ll g1=x,g2=n;
	if(x<n){
		ll x1 = 0,x2=1;
		trav(j,v){
				if(b[j.snd]>=a[j.snd]){
					ll gg1 = (st);
					ll gg2= j.fst;
					if(gg1*x2>x1*gg2) {
						x1=gg1,x2=gg2;
					}
				}
				else{
					ll gg1 = (st-a[j.snd]+b[j.snd]);
					ll gg2=b[j.snd];
					if(gg1*x2>x1*gg2) {
						x1=gg1,x2=gg2;
					}
				}
		}
		trav(j,z){
			if(s-r+j.fst>=0){
				if(b[j.snd]>=a[j.snd]){
					ll gg1 = (s-r+j.fst);
					ll gg2= j.fst;
					if(gg1*x2>x1*gg2) {
						x1=gg1,x2=gg2;
					}
				}
				else{
					ll gg1 = (s-r-a[j.snd]+b[j.snd]+j.fst);
					ll gg2=b[j.snd];
					if(gg1*x2>x1*gg2) {
						x1=gg1,x2=gg2;
					}
				}
			}
		}
		g1=x1+x2*g1;
		g2=x2*g2;
	}
	ll g = __gcd(g1,g2);
	g1/=g,g2/=g;
	cout<<g1<<' '<<g2;
	return 0;
}



Measured memory_bytes: 3316
a = [0]*30; b = [1,0,0];
for i in range(30):
    a[i] = sum(b)
    b.pop(); b.insert(0,a[i]);
while 1:
    n = input()
    if n==0: break;
    print ((a[n-1] if a[n-1]>=10 else 10)//10+364)//365

Measured memory_bytes: 4212
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInts  :: IO [Int]
strToInts  = map read . words <$> getLine

main = do
    n <- readLn :: IO Int
    fs <- replicateM n strToInts
    ps <- replicateM n strToInts
    let cd = [0,1]
    let css = [[c0,c1,c2,c3,c4,c5,c6,c7,c8,c9]|c0 <- cd , c1 <- cd , c2 <- cd , c1 <- cd , c3 <- cd , c1 <- cd , c4 <- cd , c5 <- cd , c6 <- cd , c7 <- cd , c8 <- cd , c9 <- cd ,[c0,c1,c2,c3,c4,c5,c6,c7,c8,c9] /= [0,0,0,0,0,0,0,0,0,0] ]
    let ans = [profit fs ps cs n | cs <- css]
    print (maximum ans)
    
profit fs ps cs n  = sum [profita fs ps cs i | i <- [1..n]]
profita fs ps cs i = (ps !! (i-1)) !! n
                     where n = count (fs !! (i-1)) cs 0


count :: [Int] -> [Int] -> Int -> Int
count [] bn n = n
count (a:an) (b:bn) n = if (a==1) && (b==1)
                        then 1 + (count an bn n)
                        else (count an bn n)

Measured memory_bytes: 1916
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
int a, b;
cin >> a >> b;
if (a == 1) a = 14;
if (b == 1) b = 14;
string s;
if ( a> b) s = "Alice";
if (b > a) s = "Bob";
if (a == b) s = "Draw";
cout << s << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int a,b;
	cin>>a>>b;
	if(max(a,b)<=8)cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
	return 0;
}


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


int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	for(int i = 0;i < n;i++){
		cout << a[i] << b[i];
	}
	
}


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    int a, b, h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2<<"\n";
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd

l, r, x, y = map(int, input().split())
lcm = int(x * y / gcd(x, y))

xn = r // x - (l - 1) // x
yn = r // y - (l - 1) // y
xyn = r // lcm - (l - 1) // lcm
ans = int(r - l + 1 - xn - yn + xyn)
print(ans)


Measured memory_bytes: 5048