akhauriyash/Code-Regression huggingface dataset:
N = int(input())

dp = [[[[0 for _ in range(5)] for _ in range(5)] for _ in range(5)] for _ in range(N+1)]

dp[0][0][0][0] = 1

# Aを1、Gを2、Cを3、Tを4とする
# k は３つ前、jは２つ前、iは１つ前の情報
for n in range(N):
    for i in range(5):
        for j in range(5):
            for k in range(5):
                # tは今の情報
                for t in range(1, 5):
                    #AGC
                    if i == 2 and j == 1 and t == 3:
                        continue
                    #ACG
                    if i == 3 and j == 1 and t == 2:
                        continue
                    #GAC
                    if i == 1 and j == 2 and t == 3:
                        continue
                    #A?GC
                    if i == 2 and k == 1 and t == 3:
                        continue
                    #AG?C
                    if j == 2 and k == 1 and t == 3:
                        continue
                        
                    dp[n+1][t][i][j] += dp[n][i][j][k]

sums = 0
for i in range(1, 5):
    for j in range(1, 5):
        for k in range(1, 5):
            sums += dp[N][i][j][k]

print(sums % (10**9 + 7))


Measured memory_bytes: 3700
#include<stdio.h>
#include<string.h>

#define MAX 1000

int top,bottom;

typedef struct{
	int x;
	int y;
	int cost;
}queue;
queue q[500000];
char map[MAX+2][MAX+2];
int visited[MAX+2][MAX+2];

void init(){
	int i,j;
	for(i=0;i<MAX+2;i++){
		for(j=0;j<MAX+2;j++){
			visited[i][j]=0;
		}
	}
}
void push(int x,int y,int cost){
	q[top].x=x;
	q[top].y=y;
	q[top].cost=cost;
	top++;
}
queue* pop(void){
	if(top==bottom){return NULL;}
	return &q[bottom++];
}




int main(){
	int h,w,n;
	int i;
	int ans=0;
	int list[10][2];//探索リスト
	int vector[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
	scanf("%d %d %d",&h,&w,&n);
	for(i=0;i<h+2;i++){
		if(i==0||i==h+1){
			memset(map[i],'X',w+2);
		}else{
			int j;
			scanf("%s",&map[i][1]);
			map[i][0]='X';
			map[i][w+1]='X';
			if(strchr(map[i],'S')!=NULL){
				list[0][0]=i;
				list[0][1]=(strchr(map[i],'S')-map[i]);
			}
			for(j=0;j<w+2;j++){
				char* p=(strchr(map[i],'0'+j));
				if(p!=NULL){
					list[j][0]=i;
					list[j][1]=p-map[i];
				}
			}
		}
	}
	/*
	for(i=0;i<h+2;i++){	
		puts(map[i]);
	}
	for(i=0;i<10;i++){	
		printf("%d =%d,%d\n",i,list[i][0],list[i][1]);
	}
	*/
	for(i=0;i<n;i++){
		init();
		top=0;bottom=0;
		push(list[i][0],list[i][1],0);//スタート地点
		while(1){
			int j;
			queue* now;
			now=pop();
			//printf("%d %d %d |\n",now->x,now->y,now->cost);
			if(now->x==list[i+1][0]&&now->y==list[i+1][1]){//到達したか否か
				ans+=now->cost;
			//	printf("%d=%d\n",i,now->cost);
				
				break;
			}
			for(j=0;j<4;j++){
				int next_x=now->x+vector[j][0];
				int next_y=now->y+vector[j][1];
				if(map[next_x][next_y]!='X'&&visited[next_x][next_y]!=1){
					visited[next_x][next_y]=1;
					push(next_x,next_y,now->cost+1);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

void solve() {
    int ha, sa, hb, sb;
    cin >> ha >> sa >> hb >> sb;
    int rounds_b = hb/sa;
    if (hb%sa == 0) 
        rounds_b--;
    int rounds_a = ha/sb;
    if (ha%sb == 0)
        rounds_a--;
    
    if (rounds_b-rounds_a >= 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 700;
  rep(i,3){
    if(s.at(i) == 'o') ans += 100;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  ll n;cin>>n;
  ll ans=0;
  vector<ll>l(n);
  rep(i,n)cin>>l[i];
  rep(i,n)rep(j,n)rep(k,n){
    if(!(i<j and j<k))continue;
    if(l[i]==l[j] or l[j]==l[k] or l[k]==l[i])continue;
    if(!(abs(l[i]-l[j]) < l[k] and abs(l[i]+l[j]) > l[k]))continue;
    ans++;
  }
  cout<<ans<<endl;
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 3620
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const db pi = acos(-1.);
const int N = 2e5 + 10;
int sx , sy , tx , ty;
int n , x[N] , y[N];

int main(){
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    scanf("%d",&n);
    rep(i,0,n) scanf("%d%d",x + i,y + i);
    if(sx > tx) {
        sx = -sx , tx = -tx;
        rep(i,0,n) x[i] = -x[i];
    }
    if(sy > ty) {
        sy = -sy , ty = -ty;
        rep(i,0,n) y[i] = -y[i];
    }
    if(tx - sx < ty - sy) {
        swap(sx , sy);swap(tx , ty);
        rep(i,0,n) swap(x[i] , y[i]);
    }
    db ans = 100. * (tx + ty - sx - sy);
    if(sy == ty) {
        bool fd = false;
        rep(i,0,n) fd |= y[i] == sy && sx <= x[i] && x[i] <= tx;
        if(fd) ans += 10 * pi - 20;
    } else {
        vector<pii> pts;
        rep(i,0,n) if(sx <= x[i] && x[i] <= tx && sy <= y[i] && y[i] <= ty)
            pts.pb(mp(x[i] , y[i]));
        sort(all(pts));
        vi best;
        for(auto e : pts) {
            int y = e.se;
            auto it = lower_bound(all(best) , y);
            if(it == best.end()) best.pb(y);
            else *it = y;
        }
        if(sz(best) == ty - sy + 1){
            ans += (5 * pi - 20) * (sz(best) - 1);
            ans += 10 * pi - 20;
        } else {
            ans += (5 * pi - 20) * sz(best);
        }
    }
    printf("%.16f\n",ans);
    return 0;
}


Measured memory_bytes: 5232
#include<stdio.h>
int main(){
  int a[4][3][10]={{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}}};
 int n,b,f,r,v,i,j,k;
  scanf("%d",&n);
  for(i=0;i < n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
  a[b-1][f-1][r-1] = a[b-1][f-1][r-1] + v;
  }
  if(0 < b <= 4 && 0 < f <= 3 && 0 < r <= 10 && 0 < v < 10){
  for(i=0;i < 4;i++){
    for(j=0;j < 3;j++){
      for(k=0;k < 10;k++){
	if(i != 4){
	  printf(" ");
	}
	printf("%d",a[i][j][k]);
      }
      printf("\n");
    }if(i != 3){
    printf("####################\n");
    } 
  }
  }
  return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <cstdlib>
#include <iomanip>

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

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100100];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    
    for (int i = 2; i < N; i++) {
        long long tmp = dp[i-1] + abs(h[i] - h[i - 1]);
        chmin(tmp, dp[i-2] + abs(h[i] - h[i - 2]));
        dp[i] = tmp;
    }
    
    cout << dp[N - 1] << endl;
}



Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    vector<int> hya(3);

    rep(i,0,3) cin >> hya[i];
    sort(all(hya));

    ll ans = hya[2] * 10 + hya[1] + hya[0];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
// Name: Kanisht Agarwal Copyright Think before u copy //
//Connect with me at LinkedIn

#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.1415926535897932
#define nui 100
#define INF 100000000000
using namespace std;

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}

ll fermat_inv(ll y) {return binpow(y, mod - 2);}

clock_t time_p = clock();

void TLE()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

struct point
{
    int x; int y;
};
bool segment(point p, point q, point r)
{
    if (q.x <= max(p.x, r.x) && q.y <= max(p.y, r.y) && q.x >= min(p.x, r.x) && q.y >= min(p.y, r.y))
        return true;

    return false;
}
int orientation(point p, point q, point r)
{
    int o = (r.x - q.x) * (q.y - p.y) - (r.y - q.y) * (q.x - p.x);
    if (o == 0)return 0;
    return (o > 0) ? 1 : 2;
}
bool intersection(point p, point q, point r, point s)
{
    int o1 = orientation(p, q, r);
    int o2 = orientation(p, q, s);
    int o3 = orientation(r, s, p);
    int o4 = orientation(r, s, q);
    if (o1 != o2 && o3 != o4)return true;
    if (o1 == 0 && segment(p, r, q))return true;
    if (o2 == 0 && segment(p, s, q))return true;
    if (o3 == 0 && segment(r, p, s))return true;
    if (o4 == 0 && segment(r, q, s))return true;

    return false;
}

bool prime[10000001];
vector<ll>v;
void seive()
{
    memset(prime, 1, sizeof(prime));
    for (ll i = 2; i * i <= 10000001; i++)
    {
        if (prime[i] == 1)
        {
            for (ll j = i * i; j <= 10000001; j += i)
            {
                prime[j] = 0;
            }
        }
    }
    for (ll i = 2; i <= 10000001; i++)
    {
        if (prime[i])
        {
            v.pb(i);
        }
    }

}


ll dp[101][100001];
int main()
{


    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


    ll n;
    cin>>n;
    ll W;
    cin>>W;
    ll v[n],w[n];
    vector<pair<ll,ll> >ve;
    for(ll i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        ve.pb(mp(w[i],v[i]));
    }
    sort(ve.begin(), ve.end());
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=W;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(j>=ve[i-1].ff)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-ve[i-1].ff]+ve[i-1].ss);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W]<<"\n";

    return 0;
}



Measured memory_bytes: 82560
#-------------------------------------------------------------------------------
#関数定義
def f(a,d,T):
    try:
        return T[d+1:].index(a)+(d+1)
    except ValueError:
        return len(T)

def g(a,d,T):
    try:
        return (d-1)-T[d-1::-1].index(a)
    except ValueError:
        return 0
#-------------------------------------------------------------------------------
#インポート
from math import inf,exp
from random import random,randint
import time
from copy import copy
#-------------------------------------------------------------------------------
#定数
TIME_LIMIT=1.864 #ループの時間制限  
A=26 #アルファベットの数
START=time.time()

ALPHA=15
ep=10**(-6) #アニーリングの微小温度
#-------------------------------------------------------------------------------
#読み込み部
D=int(input())

C=[True]+list(map(int,input().split())) #減る満足度のベース
S=[True]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))           
#-------------------------------------------------------------------------------
#貪欲部
L=[0]*(A+1)
T=[0]
for d in range(1,D+1):
    Y=-inf
    E=0
    for a in range(1,A+1):
        X=S[d][a]
        for s in range(1,A+1):
            if a!=s:
                X-=C[s]*(d-L[s])

        if X>Y:
            Y=X
            E=a
    L[E]=d
    T.append(E)
#-------------------------------------------------------------------------------
#調節部
t=time.time()-START
while t<TIME_LIMIT:
    d=randint(1,D)
    p=T[d]
    q=randint(1,A)

    Delta=(S[d][q]-S[d][p])+(d-g(q,d,T))*(f(q,d,T)-d)*C[q]-(d-g(p,d,T))*(f(p,d,T)-d)*C[p]
    if (Delta>=0) or (Delta<0 and random()<exp(Delta/(ALPHA*(TIME_LIMIT-t)+ep))):
        T[d]=q
    
    t=time.time()-START

for i in range(1,D+1):
    print(T[i])


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

#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

using namespace std;
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
     prime[1]=false;
     prime[0]=false;
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout<<p<<" ";
}
int main()
{
          ios_base::sync_with_stdio(0);
          cin.tie(0);

          int t=1;
          //cin>>t;
          while(t--)
          {
                    int a;
                    cin>>a;
                    cout<<!a;
          }
          return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>

int main (void)


{


int a,b,c;


int count=0;


int i;


scanf("%d %d %d",&a,&b,&c);


for(i=a;i<=b;i++)


{


if(c%i==0)  count++;


}


printf("%d\n",count);


return 0;


}

Measured memory_bytes: 596
//先从左边先行扫描一遍，再从右边扫描一遍，两边加起来直接用总人数相减
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <string>

    using namespace std;

    const int maxn=1e6+10;

    int n;
    int l[maxn],r[maxn];
    char str[maxn];
    int maxx=0;

    int main()
    {
        scanf("%d",&n);
        scanf("%s",str);

        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));

        for(int i=0;i<n;i++)
        {
            l[i]=l[i-1];
            if(str[i]=='E') {
                    l[i]++;
            }
        }

        for(int i=n-1;i>=0;i--)
        {
            r[i]=r[i+1];
            if(str[i]=='W') {
                    r[i]++;
            }
        }


         for(int i=0;i<n;i++) {
            r[i]=r[i]+l[i];
            maxx=max(r[i],maxx);
         }

         cout<<n-maxx<<endl;




        return 0;
    }


Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

using P = pair<ll, int>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  ll K;
  cin >> H >> W >> K;
  vector<int> X(2), Y(2);
  rep(i, 2) {
    cin >> X[i] >> Y[i];
    X[i]--; Y[i]--;
  }
  vector<string> S(H);
  rep(i, H) cin >> S[i];

  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, -1, 0, 1};
  auto pos2int = [&](int x, int y, int v) {
    return (x * W + y) * 4 + v;
  };

  int N = H*W*4;
  priority_queue<P, vector<P>, greater<P>> q;
  vector<ll> dis(N, longinf);
  rep(k, 4) {
    int s = pos2int(X[0], Y[0], k);
    dis[s] = 0;
    q.push(P(0, s));
  }
  while(!q.empty()) {
    P p = q.top();
    q.pop();
    int v = p.second;
    if(dis[v] != p.first) continue;
    int x = v/W/4;
    int y = v/4%W;
    int d = v%4;
    rep(k, 4) {
      int ne = pos2int(x, y, k);
      if((dis[v]+K-1)/K*K < dis[ne]) {
        dis[ne] = (dis[v]+K-1)/K*K;
        q.push(P(dis[ne], ne));
      }
    }
    {
      int nx = x+dx[d];
      int ny = y+dy[d];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(S[nx][ny] == '@') continue;
      int ne = pos2int(nx, ny, d);
      if(dis[v]+1 < dis[ne]) {
        dis[ne] = dis[v]+1;
        q.push(P(dis[ne], ne));
      }
    }
  }
  ll ans = longinf;
  rep(k, 4) ans = min(dis[pos2int(X[1], Y[1], k)], ans);
  cout << (ans == longinf ? -1 : (ans+K-1)/K) << endl;
  return 0;
}


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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for(int n = 0; n < N; ++n) {
        cin >> V[n];
    }
    sort(V.begin(), V.end());
    int ans = 0;
    for(int n = 0; n < K; ++n) {
        ans += V[n];
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
 
class Program {
    static void Main(string[] args) {
        var S = Console.ReadLine();
        var K = long.Parse(Console.ReadLine());
        int count = 0;
        while(count < S.Length && S[count] == '1'){
            count++;
        }
        
        if(count >= K){
            Console.WriteLine(1);
        }else{
            Console.WriteLine(S[count]);
        }             
     }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = 998244353;

vector<int> factor(int N) {
  vector<int> res;
  for (int d = 1; d * d <= N; d++) {
    if (N % d == 0) {
      res.push_back(d);
      if (d != N / d) res.push_back(N / d);
    }
  }
  sort(ALL(res));
  return res;
}

int main2() {
  int N = nextInt();
  string X; cin >> X;
  vector<int> ds;
  {
    vector<int> tmp = factor(N);
    for (int d : tmp) if ((N / d) % 2) ds.push_back(d);
  }

  map<ll, ll> multi_d;
  for (int d : ds) {
    ll val = 0;
    REP(i, d) val = (val * 2 + (X[i] - '0')) % MOD;

    bool ok = true;
    REP(i, N) {
      int y = X[i % d]-'0';
      if (i % (2*d) >= d) y = 1 - y;
      if (y > (X[i]-'0')) { ok = false; break; }
      if (y < (X[i]-'0')) { ok = true; break; }
    }
    if (ok) {
      val = (val + 1) % MOD;
    }
    multi_d[d] = val;
  }
  map<ll, ll> just_d;
  for (auto p : multi_d) {
    const ll d = p.first;
    ll res = p.second;
    for (int dd : ds) if (d % dd == 0) {
      res -= just_d[dd];
      res = (res % MOD + MOD) % MOD;
    }
    just_d[d] = res;
  }

  ll ans = 0;
  for (auto p : just_d) {
    ans += p.first * p.second * 2 % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        cin >> r[i]; r[i]--;
    }
    vector<vector<int>> G(N, vector<int> (N, inINF));
    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }
    int a, b, c;
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c; a--; b--;
        G[a][b] = c;
        G[b][a] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if(G[i][k] == inINF || G[k][j] == inINF) continue;
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    vector<int> v(R);
    for (int i = 0; i < R; i++) {
        v[i] = i;
    }
    int ans = inINF;
    do{
        int tmp = 0;
        for (int i = 0; i < R-1; i++) {
            tmp += G[r[v[i]]][r[v[i+1]]];
        }
        ans = min(ans, tmp);
    }while(next_permutation(ALL(v)));

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

}   

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

using namespace std;

signed main() {
  IOS;
  string S, ans;
  cin >> S;
  int wins=0, loses=0;
  for (char c: S) {
    if (c == 'o') wins++;
    else loses++;
  }

  cout << ((wins >= 8 or loses <= 7) ? "YES":"NO") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int x = stdIn.nextInt();
		int answer = 1;

		for (int i = 0; i < 3; i++) {
			answer *= x;
		}

		System.out.println(answer);

	}
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

string s;

int main(){
	cin >> s;
	Int ans = 0;
	for(int i = 0; i < (1 << s.size()-1); i++){
		Int cnt = 0, sum = 0;
		for(int j = 0; j < s.size(); j++){
			if(i & (1 << (j-1)) && j != 0){
				sum += cnt;
				cnt = 0;
			}
			cnt = cnt * 10 + (s[j] - '0');
		}
		sum += cnt;
		ans += sum;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.split.map(&:to_i)

$cnt = 0
$INF = 10**9

def marge(s, left, mid, right)
  l = s[left..(mid-1)].push($INF) #左側の配列, $INFは番兵
  r = s[mid..(right-1)].push($INF) #右側の配列, $INFは番兵

  i, j = [0, 0]
  left.upto(right-1) do |k|
    if l[i] < r[j]
      s[k] = l[i]
      i += 1
    else
      s[k] = r[j]
      j += 1
      $cnt += mid + j - k - 1
      #↑ゴチャゴチャやった結果、これが反転数
      #要素がどれくらい動いたか、添字の差を取ることで反転数が出る。
    end
  end
end

def marge_sort(s, left, right)
  #left:部分配列の先頭, right:部分配列の末尾+1
  #要素数が1以上のときマージソート
  if right - left > 1
    mid = (left + right)/2
    #配列の左側をソート
    marge_sort(s, left, mid)
    #配列の右側をソート
    marge_sort(s, mid, right)
    #左の配列と右の配列をマージする
    marge(s, left, mid, right)
  end
end

marge_sort(s, 0, n)

#puts s.join(" ")
puts $cnt


Measured memory_bytes: 36300
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

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

    int first = stoi(s.substr(0, 2));
    int second = stoi(s.substr(2, 2));
    string out = "AMBIGUOUS";

    if ((first > 12 && second == 0) ||
        (second > 12 && first == 0) ||
        (first == 0 && second == 0) ||
        (first > 12 && second > 12))
        out = "NA";
    else if (first > 12 || first == 0)
        out = "YYMM";
    else if (second > 12 || second == 0)
        out = "MMYY";

    cout << out << endl;

    return 0;
}

int main()
{
     solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct segtree{
	static const int N=1<<18;
	int dp[1<<19];
	int dp2[1<<19];
	int lazy[1<<19];
	segtree(){
		memset(dp,0,sizeof(dp));
		memset(dp2,0,sizeof(dp2));
		memset(lazy,0,sizeof(lazy));
	}
	void add(int k,int v){
		k+=N-1;
		dp[k]+=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=dp[k*2+1]+dp[k*2+2];
		}
	}

	void lazy_eval(int k){
		if(lazy[k]%2==1){
			swap(dp[k],dp2[k]);
		}
		if(k<N-1){
			lazy[k*2+1]+=lazy[k];
			lazy[k*2+2]+=lazy[k];
		}
		lazy[k]=0;
	}

	void lazy_upd(int k){
		dp[k]=dp[k*2+1]+dp[k*2+2];
		dp2[k]=dp2[k*2+1]+dp2[k*2+2];
	}

	void update(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return;
		if(a<=l && r<=b){
			lazy[k]++;
			lazy_eval(k);
			return;
		}
		update(a,b,k*2+1,l,(l+r)/2);
		update(a,b,k*2+2,(l+r)/2,r);
		lazy_upd(k);
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int vl=query(a,b,k*2+1,l,(l+r)/2);
		int vr=query(a,b,k*2+2,(l+r)/2,r);
		lazy_upd(k);
		return vl+vr;
	}
};

int n,q;
vector<int> G[110001];

segtree seg;
int l[100005],r[100005];
int cnt=0;


void dfs(int v,int c){
	l[v]=cnt++;
	for(int i=0;i<G[v].size();i++){
		if(G[v][i]!=c){
			dfs(G[v][i],v);
		}
	}
	r[v]=cnt++;
}

int main(void){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n-1;i++){
		int a;
		scanf("%d%*c",&a);
		a--;
		G[a].push_back(i+1);
		G[i+1].push_back(a);
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		seg.add(l[i],1);
	}
	for(int i=0;i<n;i++){
		char c;
		scanf("%c%*c",&c);
		if(c=='G'){
			seg.update(l[i],l[i]+1);
		}
		//printf("%d\n",seg.query(l[i],l[i+1]));
	}
	int val=seg.query(l[0],r[0]);
	for(int i=0;i<q;i++){
		int a;
		scanf("%d",&a);
		a--;
		seg.update(l[a],r[a]);
		int val=seg.query(l[0],r[0]);
		printf("%s\n",val>n/2?"cauliflower":"broccoli");
	}
	return 0;
}


Measured memory_bytes: 20516
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll x[5];
	cinf(x,5);
	rep(i,5){
		if(x[i]==0){
			cout << i+1 << endl;
		}
	}
}

Measured memory_bytes: 3548
n, a, b = map(int, input().split())

mod = 10 ** 9 + 7
def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

N = 2 * 10 ** 5 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
    fact[i] = (fact[i-1] * i) % mod

def comb(n, b):
    bunbo = 1
    for i in range(n-b+1, n+1):
        bunbo *= i
        bunbo %= mod
    return moddiv(bunbo, fact[b])

pow2 = [1] * 64
pow2[1] = 2
for i in range(2, 64):
    pow2[i] = pow2[i-1] ** 2 % mod

def pow(b):
    ret = 1
    for i in range(1, 64):
        if b & 1:
            ret *= pow2[i]
            ret %= mod
        b //= 2
    return ret

ans = pow(n) - 1

ans -= comb(n, a)
ans -= comb(n, b)
ans %= mod
print(ans)

Measured memory_bytes: 10868
s = input()

ans = 0
for i in range(2 ** (len(s) - 1)):
    js = []
    for j in range(len(s) - 1):
        if (i >> j) & 1:
            js.append(j)

    if js == []:
        ans += int(s)
    else:
        prev = 0
        for j in range(len(js)):
            ans += int(s[prev:js[j] + 1])
            prev = js[j] + 1
        ans += int(s[prev:])
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int n;
    cin>>n;
    vector<int> v(n);
    int ans=0;
    bool flag=0;
    int cnt=1;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++)
    {
      if(v[i]==cnt)
      {
        flag=1;
        cnt++;
      }
      else
      {
        ans++;
      }      
    }
    if(flag)
      cout<<ans<<endl;
    else
    {
      cout<<"-1"<<endl;
    }
    
  }
  //time("");
  return 0;
}

Measured memory_bytes: 1792
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ans = 0
x = []

for i in [a,b,c,d,e]:
  if i % 10 != 0:
    ans += (i//10)*10 + 10
    x.append(i%10)
  else:
    ans += i

if x != []:
  ans -= 10-min(x)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>

using namespace std;

int main(){
    int n,T,A;
    cin >> n >> T >> A;

    T *= 1000;
    A *= 1000;

    int ansPlace;
    int bestdeff = 1e9;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        int tmp = T - h * 6;
        if(bestdeff > abs(A - tmp)){
            ansPlace = i + 1;
            bestdeff = abs(A-tmp);
        }

    }

    cout << ansPlace << endl;   

    return 0;
    
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll x,k,d,a;
  cin>>x>>k>>d;
  a=(ll)ceil((double)abs(x)/d);
  if(x==0){
    k%=2;
    x+=k*d;
    cout<<abs(x);
    return 0;
  }
  if(a>k) a=k;
  if(x<0) x+=a*d;
  else if(x>0) x-=a*d;
  k=(k-a)%2;
  if(x<0) x+=k*d;
  else x-=k*d;
  cout<<abs(x);
  return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#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 SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long
#define pb push_back
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;


string O,E;




signed main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//
//
//
    getline(cin, O);
    getline(cin, E);

    for(int i = 0;i < E.length();i++){
        cout<< O[i]<< E[i];
    }
    if(E.length()!=O.length()){
        cout<< O[O.length()-1]<< "\n";
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
struct p
{
	long long a;
	long long b;
}s[100000];
int change(p x, p y)
{
	return x.a<y.a;
}
int main()
{
	long long t, sum=0, money=0, n, m,cnt=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>s[i].a>>s[i].b;
	}
	sort(s,s+n,change);
	for(t=0;t<n;t++)
	{
		sum+=s[t].b;
		if(sum>=m)
		{
			break;
		}
	}
	for(int i=0;i<t;i++)
	{
		money+=s[i].a*s[i].b;
		cnt+=s[i].b;
	}
	money+=(m-cnt)*s[t].a;
	cout<<money;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> a(n),b(n),c(n);
    rep (i,0,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n][3];
    rep (i,0,n)
    {
        dp[i][0]=0;
        dp[i][1]=0;
        dp[i][2]=0;
    }
    dp[n-1][0]=a[n-1];
    dp[n-1][1]=b[n-1];
    dp[n-1][2]=c[n-1];
    rev (i,n-1,0)
    {
        dp[i][0]=max(dp[i+1][1]+a[i],dp[i+1][2]+a[i]);
        dp[i][1]=max(dp[i+1][0]+b[i],dp[i+1][2]+b[i]);
        dp[i][2]=max(dp[i+1][0]+c[i],dp[i+1][1]+c[i]);
    }
    ll x= max(dp[0][0],dp[0][1]);
    cout<<max(dp[0][2],x)<<endl;
    
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
}

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



int main(){
  string s,t;
  cin >> s >> t;
  int ns = s.size();
  int nt = t.size();
  
  static int dp[3001][3001] = {0};
  
  rep(i,ns){
    rep(j,nt){
      if(s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
    }
  }

  string ans = "";
  while(ns > 0 && nt > 0) {
    if(dp[ns][nt] == dp[ns-1][nt]) ns--;
    else if(dp[ns][nt] == dp[ns][nt-1]) nt--;
    else {ans = s[ns-1]+ans; ns--; nt--;} 
  }
  cout<< ans << endl;
}


Measured memory_bytes: 38816
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

struct edge{
	int from;
	int to;
	double cost;
	edge(){}
	edge(int f, int t, double c){
		from = f;
		to = t;
		cost = c;
	}
};

bool comp(const edge &a, const edge &b){
	return a.cost > b.cost;
}

const int MAX_N = 10000;

//input
int N, M;
int X[MAX_N], Y[MAX_N];
vector<edge> v;

//kruskal
int par[MAX_N];
int rank[MAX_N];

double compute(double x1, double y1, double x2, double y2){
	//compute the cost
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

void init(){
	memset(par, -1, sizeof(par));
	memset(rank, 0, sizeof(rank));
}

int find(int x){
	if(par[x] == -1)return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y)return;
	if(rank[x] < rank[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
		if(rank[x] == rank[y])
			rank[x] ++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

double kruskal(){
	sort(v.begin(), v.end(), comp);
	init();
	double ans = 0;
	for(int i = 0; i < v.size(); i ++){
		if(!same(v[i].from, v[i].to)){
			unite(v[i].from, v[i].to);
			ans += v[i].cost;
		}
	}
	return ans;
}

void solve(){
	double ans = 0;
	for(int i = 0; i < v.size(); i ++){
		ans += v[i].cost;
	}
	ans -= kruskal();
	printf("%.3lf\n", ans);
}

int main(int argc, char const *argv[]){

	scanf("%d %d", &N, &M);
	for(int i = 0; i < N; i ++)
		scanf("%d %d", &X[i], &Y[i]);
	for(int i = 0; i < M; i ++){
		int f, t;
		scanf("%d %d", &f, &t);
		f --, t--;
		v.push_back(edge(f, t, compute(X[f], Y[f], X[t], Y[t])));
	}
	solve();
	
	return 0;
}

Measured memory_bytes: 1716
def main():
    N = int(input())
    dp = [N] * (N + 1)
    dp[0] = 0
    for n in range(1, N + 1):
        i = 1
        while n >= i:
            dp[n] = min(dp[n], dp[n - i] + 1)
            i *= 6
        j = 1
        while n >= j:
            dp[n] = min(dp[n], dp[n - j] + 1)
            j *= 9
    print(dp[N])


main()


Measured memory_bytes: 3828
N, M = map(int, input().split())
N = input().split()
N = [int(n) for n in N]
A = []
soutoku = 0
for i in N:
    soutoku += int(i)
N = sorted(N, reverse=True)
for i in range(M):
    A.append(N[i])
b = soutoku / (4*M)

if int(N[int(M-1)]) < b:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;

ll fsum(ll x){
    ll a = 0;
    while(x){
        a += (x % 10);
        x /= 10;
    }
    return a;
}
int main(){
    vector<ll>v;
    for(int i = 1;i < 10;i++){
        v.push_back(i);
    }
    v.push_back(19);
    ll K;
    cin>>K;
    ll last = 19;
    while(v.size() < K){
        ll p = fsum(last);
        ll add = 1;
        while((last+add)*fsum(last+add*2) > (last+2*add)*fsum(last+add)){
            add *= 10;
        }
        last += add;
        v.push_back(last);
    }
    for(int i = 0;i < K;i++){
        cout<<v[i]<<endl;
    }
    return 0;
}

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

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

	long long ma = 1000000000;
	long long mod = S % ma;
	long long x1 = 0;
	long long y1 = 0;
	long long x2 = ma;
	long long y2 = 1;
	long long x3 = ma - mod;
	long long y3 = S / ma + 1;
	if( S == ma * ma ) {
		x2 = ma;
		y2 = 0;
		x3 = ma;
		y3 = ma;
	}

	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {

	long long int n, m;
	cin >> n >> m;

	vector<long long int> a(n);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (long long int i = 1; i < n; i++) {
		a[i] = a[i] + a[i - 1];
	}
	
	set<long long int> st;
	map<long long int, long long int> mp;

	for (long long int i = 0; i < n; i++) {
		long long int p = a[i] % m;
		st.insert(p);
		mp[p]++;
	}
	
	long long int ans = 0;

	for (set<long long int>::iterator ite = st.begin(); ite != st.end(); ite++) {
		long long int k = mp[(*ite)];
		ans += k * (k - 1) / 2;
		if ((*ite) == 0) {
			ans += k;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7936
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	int n;
	boolean[] color;
	int[][] map;
	int INF = 1 << 24;

	private void run() {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		map = new int[n][n];
		for (int[] a : map)
			Arrays.fill(a, INF);
		for (int i = 0; i < n; i++) {
			int u = scanner.nextInt();
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int v = scanner.nextInt();
				int c = scanner.nextInt();
				map[u][v] = c;
			}

		}
		dijkstra();
	}

	private void dijkstra() {
		int[] d = new int[n];
		color = new boolean[n];
		Arrays.fill(d, INF);
		d[0] = 0;
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(0);
		while (!deque.isEmpty()) {
			int u = deque.poll();
			color[u] = true;
			int minv = INF;
			int next = -1;
			for (int i = 0; i < n; i++) {
				if (d[i] > d[u] + map[u][i]) {
					d[i] = d[u] + map[u][i];
				}
				if (!color[i] && minv > d[i]) {
					minv = d[i];
					next = i;
				}

			}
			if (next != -1)
				deque.push(next);
		}
		for (int i = 0; i < n; i++) {
			System.out.printf("%d %d\n", i, d[i] == INF ? -1 : d[i]);
		}

	}
}

Measured memory_bytes: 34700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long gcd(long long a, long long b) {
	if (a % b == 0) {
		return (b);
	}
	else {
		return (gcd(b, a % b));
	}
}
int main() {
	int n;
	cin >> n;
	long long ans;
	cin >> ans;
	for (int i = 0; i < n - 1; i++) {
		long long a;
		cin >> a;
		ans = gcd(ans, a);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define inc(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
long long KSM(long long a,long long b,long long p){
	long long res=1;
	while(b){
		if(b&1) res=res*a%p;
		a=a*a%p;
		b/=2;
	}
	return res%p;
}
long long c[3010][3010],s[3010][3010];
int main(){
	long long n,p;
	cin>>n>>p;
	c[0][0]=s[0][0]=1;
	inc(i,1,n+1){
		c[i][0]=1;
		inc(j,1,i){
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
			s[i][j]=(s[i-1][j-1]+(long long)j*s[i-1][j]%p)%p;
		}
	}
	long long ans=0;
	inc(i,0,n){
		long long sum=(i&1)?p-1:1;
		sum=sum*KSM(2,KSM(2,n-i,p-1),p)%p;
		sum=sum*c[n][i]%p;
		long long tmp=0;
		inc(j,0,i){
			tmp=(tmp+s[i+1][j+1]*KSM(KSM(2,(n-i),p)%p,j,p))%p;
		}
		sum=sum*tmp%p;
		ans=((ans+sum)%p+p)%p;
	}
	cout<<ans;
}

Measured memory_bytes: 95804
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#define inf 0x3fffffff

int n;
char s[11000];

int main()
{
    scanf("%s",s);
    int n=strlen(s);
    for (int i=0;i<n;i++)
        s[i]='x';
    printf("%s\n",s);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

ll f(ll n) {
    if (n < 0) return 0;
    ll count = ceil((double)n/2);
    // (0 xor 1) xor ... (n-1 xor n)
    if (n % 2 == 1) {
        return count % 2;
    }
    // (0 xor 1) xor ... (n-2 xor n-1) xor n
    else {
        return n ^ (count % 2);
    }
}

int main() {
    ll A, B; cin >> A >> B;
    ll ans = f(B) ^ f(A-1);
    cout << ans << endl;
}

Measured memory_bytes: 256