akhauriyash/Code-Regression huggingface dataset:
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N - 1)]
C = sorted([int(_) for _ in input().split()])
Pairs = [set() for _ in range(N)]
for a, b in AB:
    #0-indexed
    a -= 1
    b -= 1
    Pairs[a].add(b)
    Pairs[b].add(a)
visited = [False] * N
visited[0] = True
count = [0] * N
stack = [0]
start = []
parent = [0] * N
while stack:
    fr = stack.pop()
    updated = False
    for to in Pairs[fr]:
        if not visited[to]:
            visited[to] = updated = True
            stack += [to]
            count[fr] += 1
            parent[to] = fr
    if not updated:
        start += [fr]
order = []
while start:
    fr = start.pop()
    if count[fr]:
        continue
    order += [fr]
    to = parent[fr]
    count[to] -= 1
    start += [to]
ans = [0] * N
for i in range(N):
    ans[order[i]] = C[i]
score = 0
for a, b in AB:
    #0-indexed
    a -= 1
    b -= 1
    score += min([ans[a], ans[b]])
print(score)
print(*ans)


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

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

using namespace std;

int64_t a[100010];

int main() {
  int N; int64_t x; cin >> N >> x;
  int64_t sum = 0;
  int64_t tmp = 0;
  rep(i, N) {
    cin >> a[i];
  }
  if (a[0] > x) {
    sum += a[0] - x;
    a[0] = x;
  }
  REP(i, 1, N) {
    auto sa = a[i] + a[i - 1];
    if (sa > x) {
      sum += sa - x;
      a[i] -= sa - x;
    }
  }
  cout << sum << "\n";
}


Measured memory_bytes: 1024
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
x,y = map(int,input().split())
kai = []
for i in range(x+1):
    if x-i == (y-2*i)*2:
        kai.append(i)
        kai.append(y-2*i)
        break
m = 10**9 + 7
if len(kai) == 0:
    print(0)
else:
    ans = 1
    b = kai[0]+kai[1]
    for i in range(kai[0]):
        #print(ans)
        ans = ans*(b-i)%m
        ans = ans*mod_inv(i+1,m)%m
    print(ans)

Measured memory_bytes: 41580
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3620
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e7 + 10, mod = 998244353;

ll fact[N], finv[N], p2[N];

ll pwr(ll x, ll e);
ll choose(int n, int k);

int main() {
	fast_cin();
	int n; cin >> n;
	fact[0] = finv[0] = p2[0] = 1;
	for (int i = 1; i <= n; ++i) {
		p2[i] = (2 * p2[i - 1]) % mod;
		fact[i] = (i * fact[i - 1]) % mod;
		finv[i] = pwr(fact[i], mod - 2);
	}
	ll ans = pwr(3, n);
	for (int k = n / 2 + 1; k <= n; ++k) {
		ll temp = choose(n, k) * p2[n - k + 1];
		temp %= mod;
		ans += mod - temp;
		ans %= mod;
	}
	cout << ans << endl;
}

ll pwr(ll x, ll e) {
	ll res = 1;
	while (e) {
		if (e & 1) {
			res = (res * x) % mod;
		}
		e /= 2;
		x = (x * x) % mod;
	}
	return res;
}

ll choose(int n, int k) {
	ll ans = fact[n] * finv[k];
	ans %= mod;
	ans *= finv[n - k];
	return ans % mod;
}

Measured memory_bytes: 234624
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int n,c;
int a[31],b[31];
int dp[31][1<<16];

int dfs(int x,int bit){
	if(dp[x][bit]>=0)return dp[x][bit];
	if(x==n)return 0;
	int nbit = a[x] | bit;
	int res=0;
	for(int j=0;j<c;j++){
		int plu=__builtin_popcount(nbit & b[j]);
		int kbit=nbit-(nbit & b[j]);
		res=max(dfs(x+1,kbit)+plu,res);
	}
	return dp[x][bit]=res;
}

int main(void){
	while(1){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(dp,-1,sizeof(dp));
		scanf("%d%d",&n,&c);
		if(n==0 && c==0)break;
		for(int i=0;i<n;i++){
			for(int j=0;j<16;j++){
				int q;
				scanf("%d",&q);
				if(q==1)a[i] |= 1<<j;
			}
		}
		for(int i=0;i<c;i++){
			for(int j=0;j<16;j++){
				int q;
				scanf("%d",&q);
				if(q==1)b[i] |= 1<<j;
			}
		}
		printf("%d\n",dfs(0,0));
	}
	return 0;
}

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

int main() {
    int x[] = {25, 10, 5 , 1};
    int res = 0;
    int n; cin >> n;
    for (int i = 0; n; i++) {
        res += n / x[i];
        n %= x[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main(void)
{
	int i,j,k,n,m,l;
	char s[200];
	scanf("%s",s);
	l=strlen(s);
	printf("%c%d%c\n",s[0],l-2,s[l-1]);
	return 0;
 } 

Measured memory_bytes: 128
// G++ MACro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#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) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  SCIN(s);
  int n=s.size();
  S tflag;
  V sflag;
  REP(i,s.size()){
    if(s[i]=='S')sflag.pb(i);
    else tflag.insert(i);
  }
  REP(i,sflag.size()){
    auto it = tflag.lower_bound(sflag[i]);
    if(it!=tflag.end())tflag.erase(it);
  }
  COUT(tflag.size()*2);

  return 0;
}


Measured memory_bytes: 5764
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
ll mod=1e9+7;
int main(){
    ll h,w;
    cin>>h>>w;
    char grid[h+1][w+1];
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>grid[i][j];
        }
    }
    dp[1][1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(i==1&&j==1) continue;
            if(grid[i][j]=='.'){
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=mod;
            }
        }
    }
    cout<<dp[h][w];


    return 0;

}

Measured memory_bytes: 9088
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<set>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=200005;
int n,m,k,S[N];
priority_queue< int,vector<int>,greater<int> >q;
struct ex{int x,y;}d[N];
inline bool operator < (const ex &a,const ex &b) {return a.x<b.x;}
int main( )
{
  int i,j,t=0;
  n=read( );m=read( );
  for(i=1;i<=n;i++) d[i].x=read( ),d[i].y=read( );
  sort(d+1,d+n+1);
  for(i=1;i<=n&&!d[i].x;i++) S[++k]=d[i].y;
  for(j=1;j<=m;j++)
    {
      while(i<=n&&d[i].x==j) q.push(d[i].y),t++,i++;
      while(t>j) S[++k]=q.top( ),q.pop( ),t--;
    }
  sort(S+1,S+k+1);
  for(j=t+1,i=1;i<=k;i++,j++)
    {
      while(j<=m&&S[i]>j) j++;
      if(j>m) break;
    }
  printf("%d",k-i+1);
  return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long l;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SONI ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn=5e5+15;
const int maxm=5000+15;
const int mod=1e9+9;
const int inf=0x3f3f3f3f;
const int MOD=1000000007;

void add_self(int &a,int b)
{
    a+=b;
    if(a>=MOD)
    a=a-MOD;
}

int main()
{
    SONI;
    int h,w;
    cin>>h>>w;
    char table[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>table[i][j];
        }
    }
    
    vector<vector<int>> dp(h,vector<int>(w));
    dp[0][0]=1;
    for(int row=0;row<h;row++)
    {
        for(int col=0;col<w;col++)
        {
            for(int r2:{row,row+1})
            {
                int c2=col;
                if(r2==row)
                c2=col+1;
                
                if(r2<h && c2<w && table[r2][c2]=='.')
                add_self(dp[r2][c2],dp[row][col]);
                
            }
        }
    }
    
    cout<<dp[h-1][w-1];
    return 0;
    
}

Measured memory_bytes: 5248
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

template<typename T>
vector<T> getVector(int N) {
    vector<T> v(N);
    REP(i, N) cin >> v[i];
    return v;
}

int main(void)
{
    string s, t;
    cin >> s;
    cin >> t;
    if (s.size()+1 == t.size()) {
        if (t.substr(0, s.size()) == s) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}

	vector<int> dp(n+1);
	dp[0] = 3;

	long long res = 1;
	for(int i=0; i<n; i++){
		res = res*dp[a[i]];
		res = res % 1000000007;
		dp[a[i]]--;
		dp[a[i]+1]++;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#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) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
class UnionFind{
private:
    vector<int> vec;
public:
    void init(int N){
        vec.resize(N);
        for(int a = 0;a < N;a++)
        {
            vec[a]=-1;
        }
    }
    int root(int a)
    {
        if(vec[a] < 0)return a;
        else return vec[a] = root(vec[a]);
    }
    bool connect(int a,int b)
    {
        a = root(a);
        b = root(b);
        if(a==b)return false;
        if(vec[a] > vec[b])swap(a,b);
        vec[a] += vec[b];
        vec[b] = a;
        return true;
    }
    bool check(int a,int b){
        a = root(a);
        b = root(b);
        if(a==b)return true;
        else return false;
    }
};


int main(){
    CIN(N);CIN(M);
    I vec;
    UnionFind uni;
    uni.init(N+1);
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    REP(a,M){
        CIN(b);CIN(c);
        uni.connect(b,c);
    }
    int ans=0;
    for(int a = 1;a < N+1;a++){
        if(uni.check(a,vec.at(a-1)))ans++;
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 1276
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int n;
int r[101],b[101];
int memo[101];
P h[101];
int ans;
int rec(int s)
{
    if(memo[s]>0)return memo[s];
    if(r[s]==0&&b[s]==0)
    {
        memo[s]=h[s].fi+h[s].sec;
        return memo[s];
    }
    else if(r[s]==0&&b[s]!=0)
    {
        memo[s]=rec(b[s])/__gcd(h[s].fi,rec(b[s]))*(h[s].fi+h[s].sec);
        return memo[s];
    }
    else if(r[s]!=0&&b[s]==0)
    {
        memo[s]=rec(r[s])/__gcd(h[s].sec,rec(r[s]))*(h[s].fi+h[s].sec);
        return memo[s];
    }
    else
    {
        int tp,tq;
        tp=h[s].fi;tq=h[s].sec;
        int k=rec(b[s])/__gcd(rec(b[s]),tp);
        tp*=k;tq*=k;
        k=rec(r[s])/__gcd(rec(r[s]),tq);
        tp*=k;
        tq*=k;
        memo[s]=tp+tq;
        return memo[s];
    }
}
int main()
{
    while(1)
    {
        memset(r,0,sizeof(r));
        memset(b,0,sizeof(b));
        memset(memo,0,sizeof(memo));
        ans=0;
        for(int i=0;i<101;i++)
        {
            h[i].fi=0;
            h[i].sec=0;
        }
        cin >> n;
        if(n==0)break;
        for(int i=1;i<=n;i++)
        {
            int p,q,re,bl;
            cin >> p >> q >> re >> bl;
            int k=__gcd(p,q);
            p/=k;
            q/=k;
            h[i]=mp(p,q);
            r[i]=re;
            b[i]=bl;
        }
        for(int i=1;i<=n;i++)
        {
            ans=max(ans,rec(i));
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import numpy as np
import copy
n = int(input())
a = list(map(int, input().split()))
a_copy = copy.copy(a)
count = np.zeros(2)


i = 0
sum_before = 0
sum_after = 0    
    
if a[0] <= 0:
    count[0] += abs(a[0]) + 1
    a[0] = 1
while i < n:
    sum_after = sum_before + a[i]
    if sum_after * sum_before > 0 or sum_after == 0:
        if sum_after < 0:
            a[i] = a[i] - sum_after + 1
        elif sum_after > 0:
            a[i] = a[i] - sum_after - 1
        elif sum_before < 0:
            a[i] += 1
        else:
            a[i] -= 1
        count[0] += abs(sum_after) + 1
        sum_after = sum_before + a[i]
    i += 1
    sum_before = sum_after

i = 0
sum_before = 0
sum_after = 0    

if a_copy[0] >= 0:
    count[1] += abs(a_copy[0]) + 1
    a_copy[0] = -1

while i < n:
    sum_after = sum_before + a_copy[i]
    if sum_after * sum_before > 0 or sum_after == 0:
        if sum_after < 0:
            a_copy[i] = a_copy[i] - sum_after + 1
        elif sum_after > 0:
            a_copy[i] = a_copy[i] - sum_after - 1
        elif sum_before < 0:
            a_copy[i] += 1
        else:
            a_copy[i] -= 1
        count[1] += abs(sum_after) + 1
        sum_after = sum_before + a_copy[i]
    i += 1
    sum_before = sum_after

print(int(min(count[0], count[1])))
 




Measured memory_bytes: 23276
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
  cin>>n>>k;
  int j=0;
  int a[100001];
    for (int i=0 ;i<n; i++)
    {
      cin>>a[i];
      if (a[i]>=k)
         j++;
      else 
        continue;
    
    
    }


cout<<j;




return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,ans;
int main () {
	scanf("%d",&n);
	if (n<10) {printf("%d\n",n);}
	else if (n<100) {printf("%d\n",9);}
	else if (n<1000) {printf("%d\n",9+n-100+1);}
	else if (n<10000) {printf("%d\n",909);}
	else if (n<100000) {printf("%d\n",909+n-10000+1);}
	else {printf("%d\n",90909); }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
using namespace std;
typedef long long ll;

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

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int x = abs(B-A) + abs(C-B), y = abs(C-B) + abs(A-C), z = abs(A-C) + abs(B-A);
  
  cout << min({x, y, z}) << endl;
  
}

Measured memory_bytes: 3608
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_5_B/review/2709881/arsenic28/Rust
trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main(){
    let n:usize = read();
    let mut buf = VecDeque::new();
    let mut end = true;

    for _ in 0..n {
        let a:u32 = read();
        if end {
            buf.push_back(a);
        }else{
            buf.push_front(a);
        }
        end = !end;
    }
    if end {
        println!("{}",buf.iter().join(" "));
    }else{
        while !buf.is_empty(){
            print!("{}",buf.pop_back().unwrap());
            if !buf.is_empty(){
                print!(" ");
            }
        }
        println!();
    }
}


Measured memory_bytes: 16636
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, A, B, As[110] = {}, Bs[110] = {}, MAX = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		As[i + 1] = As[i] + A;
	}
	for (int i = 0; i < N; i++) {
		cin >> B;
		Bs[i + 1] = Bs[i] + B;
	}
	for (int i = 1; i <= N; i++) {
		int count = 0;
		count += As[i];
		count += Bs[N] - Bs[i - 1];
		MAX = max(MAX, count);
	}
	cout << MAX;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int gcd(int a,int b){
  if(a%b==0){
    return b;
  }else{
    return(gcd(b,a%b));
  }
}
int main(){
  int n;
  cin>>n;
  int a[n];
  int b=1;
  int sum=0;
  REP(i,n){
    cin>>a[i];
    if(a[i]!=b){
      sum++;
    }else{
      b++;
    }
  }
  if(sum==n){
    cout<<-1<<endl;
  }else{
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1024
h, w = map(int, input().split()); a = [input() for _ in range(h)]; z = 0
for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            if a[i+1][j] == "#" and a[i][j+1] == "#": print("Impossible"); z = 1; break
        elif i == h-1 and j == w-1:
            if a[i-1][j] == "#" and a[i][j-1] == "#": print("Impossible"); z = 1; break
        else:
            if a[i][j] == "#":
                x = y = 0
                if i != 0:
                    if a[i-1][j] == "#": x += 1
                if j != 0:
                    if a[i][j-1] == "#": x += 1
                if i != h-1:
                    if a[i+1][j] == "#": y += 1
                if j != w-1:
                    if a[i][j+1] == "#": y += 1
                if x != 1 or y != 1: print("Impossible"); z = 1; break
    if z == 1: break
else: print("Possible")

Measured memory_bytes: 9180
import Data.Either (either, isLeft, isRight, lefts, partitionEithers, rights)
import Data.Maybe
    ( catMaybes
    , fromJust
    , fromMaybe
    , isJust
    , isNothing
    , listToMaybe
    , mapMaybe
    , maybe
    , maybeToList
    )

import           Data.Array.IArray (IArray, (!))
import qualified Data.Array.IArray as I (Array, array, assocs, elems, listArray)
import           Data.Array.MArray (MArray)
import qualified Data.Array.MArray as M
    ( freeze
    , getAssocs
    , getElems
    , newArray
    , newListArray
    , readArray
    , writeArray
    )

import Data.Array.IO      (IOArray, IOUArray)
import Data.Array.ST      (STArray, STUArray)
import Data.Array.Unboxed (UArray)

import Data.Bifunctor (bimap, first, second)
import Data.Foldable  (and, or, product, sum)
import Data.Function
import Data.Monoid    ((<>))

import qualified Data.List as L

import Control.Applicative
import Control.Monad
import Control.Monad.ST    (ST, runST)

main :: IO ()
main = do
    (n, m) <- getPair
    xs     <- replicateM m getPair
    print $ solve n xs

type Pair a = (a, a)
getPair = (\(x:y:_) -> (x, y)) . map read . words <$> getLine :: Read a => IO (Pair a)

type STUArrayM s i e = ST s (STUArray s i e)
type STUArrayIx s e  = STUArray s Int e

solve :: Int -> [Pair Int] -> Int
solve n xs = runST $ do
    num <- M.newArray (1, n) 1     :: STUArrayM s Int Int
    col <- M.newArray (1, n) False :: STUArrayM s Int Bool
    M.writeArray col 1 True
    forM_ xs $ \(x, y) -> do
        k <- M.readArray num x
        c <- M.readArray col x
        let (stay, red) = case (k, c) of
                (_, False) -> (False, False)
                (1, True)  -> (False, True)
                (_, True)  -> (True,  True)
        M.writeArray num x $ pred k
        M.writeArray num y . succ =<< M.readArray num y
        M.writeArray col x   stay
        M.writeArray col y . (red ||) =<< M.readArray col y
    L.length . L.filter id <$> M.getElems col


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

int main() {
    int i, N, count=0;
    vector<long long> X(100);
    int x, y, z;
    
    cin >> N;
    
    for(i=0; i<N; i++)
    cin >> X.at(i);
    
    
    
    
    
    
    for(x=0; x<N-2; x++) {
        for(y=x+1; y<N-1; y++) {
            for(z=y+1; z<N; z++) {
                if(X.at(x) != X.at(y) && X.at(y) != X.at(z) && X.at(z) != X.at(x) && X.at(x)+X.at(y)>X.at(z) && X.at(x)+X.at(z)>X.at(y) && X.at(z)+X.at(y)>X.at(x)) {
                    count += 1;
                }
            }
        }
    }
    cout << count;
}
            
            
            



Measured memory_bytes: 3636
#include <bits/stdc++.h>
        #define INF 0x7fffffffffffffff
        typedef long long LL;
        LL n,a[200010],pre[200010],ans=1e17;
        LL k1,k2,p;
        int main(){
         	scanf("%lld",&n);
           	for(LL i=1;i<=n;i++) scanf("%lld",&a[i]);
           	pre[0]=0;
           	for(LL i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
           	LL aa=0,ab=0,ac=0,ad=0,l=1,r=3;
           	for(LL i=2;i<n-1;++i){
           		while(l<i&&std::abs(pre[l]-(pre[i]-pre[l]))>=std::abs(pre[l+1]-(pre[i]-pre[l+1])))l++;
           		while(r<n&&std::abs(pre[r]-pre[i]-(pre[n]-pre[r]))>=std::abs(pre[r+1]-pre[i]-(pre[n]-pre[r+1])))r++;
           		aa=pre[l];ab=pre[i]-pre[l];ac=pre[r]-pre[i];ad=pre[n]-pre[r];
           		ans=std::min(ans,std::max(std::max(aa,ab),std::max(ac,ad))-std::min(std::min(aa,ab),std::min(ac,ad)));
           	}
            	printf("%lld\n",ans);
            return 0;
            }

Measured memory_bytes: 3328
import math

def all_points(x, y):
	return max(one_point(x, y, _x, _y) for _x, _y in points)

def one_point(x0, y0, x1, y1):
	return math.pow(x0-x1, 2) + math.pow(y0-y1, 2)

def two():
	for i in range(N):
		for j in range(i+1, N):
			yield (points[i], points[j])

def three():
	for i in range(N):
		for j in range(i+1, N):
			for k in range(j+1, N):
				yield (points[i], points[j], points[k])

def process_two():
	minimum = 1e18
	for (a, b), (c, d) in two():
		x, y = (a+c)/2, (b+d)/2
		minimum = min(minimum, all_points(x, y))
	return minimum

def process_three():
	minimum = 1e18
	for (a,b), (c,d), (e,f) in three():
		try:
			if b==d==f:
				continue
			if d==b:
				a, b, c, d, e, f = e, f, a, b, c, d
			if f==b:
				a, b, c, d, e, f = c, d, e, f, a, b
			m0x, m0y = (a+c)/2, (b+d)/2
			m0 = -(c-a)/(d-b)
			b0 = m0y - m0*m0x
			
			m1x, m1y = (a+e)/2, (b+f)/2
			m1 = -(e-a)/(f-b)
			b1 = m1y - m1*m1x

			x = (b1-b0) / (m0-m1)
			y = m0*x + b0

			minimum = min(minimum, all_points(x, y))
		except ZeroDivisionError:
			continue
	return minimum


N = int(input())
points = []
for i in range(N):
	x, y = map(int, input().split())
	points.append((x, y))


print(math.sqrt(min(process_two(), process_three())))


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	double a, b, h, m;
	cin >> a >> b >> h >> m;

	double k1 = 2*M_PI * h/12.0 + 2*M_PI/12.0 /60.0 * m;
	double k2 = 2*M_PI * m/60.0;
	double kaku = fabs(k1 - k2);

	printf("%.15lf\n", sqrt(a*a + b*b - 2*a*b * cos(kaku))); 

	return 0;
}


Measured memory_bytes: 4228
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
	{
		cout<<"Left"<<endl;
	}
	if(c+d>a+b)
	{
		cout<<"Right"<<endl;
	}
	if(a+b==c+d)
	{
		cout<<"Balanced"<<endl;
	}
	return 0;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<ll> x(n),y(n),z(n);
	rep(i,n){
		cin >> x[i] >> y[i] >> z[i];
	}
	ll ans(0);
	rep(i,1<<3){
		vector<ll> score(n,0);
		int xs = (i>>0) & 1;
		int ys = (i>>1) & 1;
		int zs = (i>>2) & 1;
		rep(j,n){
			score[j] += (2*xs-1) * x[j];
			score[j] += (2*ys-1) * y[j];
			score[j] += (2*zs-1) * z[j];
		}
		sort(score.rbegin(),score.rend());
		ll mx(0);
		rep(j,m){
			mx += score[j];
		}
		if(mx > ans) ans = mx;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  	int n,m,ans=0;
  	cin>>n>>m;
  	long long a,b;
  	for(int i=1;i<=n;++i){
      scanf("%lld%lld",&a,&b);
      a=a*a;
      b=b*b;
      a=a+b;
      if(a<=1ll*m*m){
      	ans++;
      }
    }
  	cout<<ans;
	return 0;
}

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

int main() {
  int N,sum,i;
  cin >> N;
  sum = 0;
  i = 1;

  while (1){
    int count;
    count = N % (i * 10);
    sum += count / i;
    if(N == count){
      break;
    }
    i *= 10;
  }
  if(N % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int func(long long n) {
	if (n < 10)return 1;
	return func(n/10)+1;
}
string S, T;
int sLen, tLen;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	int ans = 1;
	REP (i,M) {
		ans *= 2;
	}
	ans *= (1900 * M + 100 * (N-M));

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


Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
s = ''.join(sorted([i for i in rs()]))
t = ''.join(sorted([i for i in rs()], reverse=True))
print('Yes' if s < t else 'No')

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

def calc_temp(x):
    return T - x * 0.006

min_diff = 10 ** 9
i = 1
ans_i = 1
for Hi in H:
    diff = abs(A - calc_temp(Hi))
    if diff < min_diff:
        min_diff = diff
        ans_i = i
    i += 1

print(ans_i)

Measured memory_bytes: 3060
def solve(string):
    m = 10**9 + 7
    a, b = 1, 2
    for l in string[1:]:
        a, b = ((3 * a + b) % m, (2 * b) % m) if int(l) else (3 * a % m, b)
    return str((a + b) % m)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3188
#include <stdio.h>
#include <vector>
 
using namespace std;
 
struct Node{
    Node(){
        parent = -1;
        depth = num_of_children = 0;
    }
    int parent;
    int depth;
    vector<int> children;
    int num_of_children;
};
 
void calcDepth(Node nodes[],int root_id){
    for(int i = 0;i < nodes[root_id].num_of_children;i++){
        nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
        calcDepth(nodes,nodes[root_id].children[i]);
    }
}
 
int main(){
    int n,id,k,child_id,root_id;
    scanf("%d",&n);
    Node nodes[n];
 
    for(int i = 0; i < n; i++){
        scanf("%d %d",&id,&k);
        for(int j = 0; j < k; j++){
            scanf("%d",&child_id);
            nodes[id].children.push_back(child_id);
            nodes[id].num_of_children++;
            nodes[child_id].parent = id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(nodes[root_id].parent == -1) break;
    }
 
    calcDepth(nodes,root_id);
 
    for(int i = 0; i < n; i++){
        if(nodes[i].parent == -1){
            printf("node %d: parent = -1, depth = 0, root, ",i);
        }else if(nodes[i].num_of_children == 0){
            printf("node %d: parent = %d, depth = %d, leaf, ",i,nodes[i].parent,nodes[i].depth);
        }else{
            printf("node %d: parent = %d, depth = %d, internal node, ",i,nodes[i].parent,nodes[i].depth);
        }
        printf("[");
        for(int j = 0; j < nodes[i].num_of_children-1; j++){
            printf("%d, ",nodes[i].children[j]);
        }
        if(nodes[i].num_of_children > 0){
            printf("%d",nodes[i].children[nodes[i].num_of_children-1]);
        }
        printf("]\n");
    }
}


Measured memory_bytes: 7368
import java.util.*;

class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args){
		int x;
		HashMap<String, String> conversions = new HashMap<>();
		StringBuilder sb = new StringBuilder();
		while((x=Integer.parseInt(s.next()))!=0) {
			conversions.clear();
			sb.delete(0, sb.length());
			for(int i=x;i>0;--i) {
				conversions.put(s.next(), s.next());
			}
			for(int i=Integer.parseInt(s.next());i>0;--i) {
				String str = s.next();
				if(conversions.get(str)!=null)
					str=conversions.get(str);
				sb.append(str);
			}
			System.out.println(sb);
		}
	}
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin>>k;
    queue<ll> que;
    FOR(i,1,9) que.push(i);
    while(true){
        ll x = que.front(); que.pop();
        if (--k==0){
            cout<<x<<"\n";
            break;
        }
        if (x%10>0) que.push(x*10+x%10-1);
        que.push(x*10+x%10);
        if (x%10<9) que.push(x*10+x%10+1);
    }
    return 0;
}


Measured memory_bytes: 1792
import itertools
while True:
  n,x = map(int,input().split())

  if n==0:break

  Candi = [i for i in range(1, n + 1)]
  count = 0

  for j in itertools.combinations(Candi, 3):
    if sum(list(j)) == x:
      count += 1

  print(count)


Measured memory_bytes: 5648
n,m=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(m):
    b.append(int(input()))
for i in range(n):
    ans=0
    for j in range(m):
        ans+=a[i][j]*b[j]
    print(ans)


Measured memory_bytes: 6008
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();

//		int n = sc.nextInt();


		//-------------------------------------------------------------------------------------

		ans = n / (a + b);
		ans *= a;

		if(n % (a + b) > 0) {
			if(n % (a + b) > a) {
				ans += a;
			} else
				ans += n % (a + b);
		}

		//-------------------------------------------------------------------------------------

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}
}

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

int main(){
  int N,Q;
  string S;
  cin>>N>>Q>>S;
  unordered_set<int> A;
  vector<int> B(0);
  for(int i=0;i<N-1;i++){
    if(S.at(i)=='A' && S.at(i+1)=='C')
      A.insert(i);
  }
  int j=0;
  B.push_back(0);
  for(int i=0;i<N;i++){
    if(A.count(i))
      j++;
    B.push_back(j);
  }
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    cout<<B.at(r-1)-B.at(l-1)<<endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    vector<LL> x(N);
    vector<LL> y(N);
    vector<LL> z(N);

    int ind = 0;
    rep(i,N){
        cin >> x[i] >> y[i] >> z[i];
        if(z[i] > 0)ind = i;
    }

    int xp = -1;
    int yp = -1;
    LL ans = 0;
    int d = x[ind];
    int e = y[ind];
    int f = z[ind];

    rep(i,N){




    
    }

    rep(xx,101)rep(yy,101){
        LL h = abs(xx-d) + abs(yy-e) + f;

        bool ok = true;
        rep(i,N){
            int a = x[i]; int b = y[i]; int c = z[i];
            int dx,dy;
            dx = abs(xx-a);
            dy = abs(yy-b);
            if(c > 0 && h != dx + dy + c)ok = false;
            if(c == 0 && h > dx + dy + c)ok = false;
        }

        if(ok){
            xp = xx;
            yp = yy;
            ans = h;
        }
    }

    
    cout << xp << " " << yp << " " << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = 10000;
    rep(i,n+1)rep(j,n+1){
        string res = s.substr(0,i) + t.substr(n-j,j);
        show(res);
        if(res.substr(0,n) == s and res.substr(res.size()-n,n) == t){
            ans = min(ans, (int)res.size());
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -----------------------------------------------------------------------

// -----------------------------------------------------------------------

int fre[26];
void solve(){
	int n;
	cin>>n;
	int pre=n%10;
	int cnt=1;
	n/=10;
	while(n!=0){
		int np=n%10;
		if(np==pre){
			cnt++;
			if(cnt==3){
				cout<<"Yes";
				return ;
			}
		}else{
			pre=np;
			cnt=1;
		}
		n/=10;
	}
	cout<<"No";
}


// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int n,t,a,h,p;
  cin >> n >> t >> a;
  
  double ave,mn = 100000000;
  
  for ( int i = 0; i < n; i++){
    cin >> h;
    ave = t - h * 0.006;
    if ( mn  > abs(a-ave) ){
      mn = abs(a-ave);
      p = i + 1;
    }
  }
  
  cout << p << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long 
int max(int a,int b){if(a>b) return a; else return b;}
int pos;
void addEdge(vector<int> adj[],int u,int v){
	adj[u].push_back(v);
}


void dfs(int u, vector<int> adj[], vector<bool> &visited, int topo[]){
	visited[u]=true;
	for(int i=0;i<adj[u].size();i++)
		if(visited[adj[u][i]] == false)
			dfs(adj[u][i], adj, visited, topo);
	topo[pos--]=u;
}



int main(){
	int n,m;
	cin >> n >> m;
	vector<int> adj[n+1];
	for(int i=1;i<=m;i++){
		int a,b;
		cin >> a >> b;
		addEdge(adj,a,b);
	}
	vector<bool> visited(n+1,false);
	int topo[n+1];
	pos=n;
	for(int i=1;i<=n;i++){
		if(visited[i]==false){
			dfs(i,adj,visited,topo);
		}
	}
	int length[n+1];
	for(int i=0;i<=n;i++)length[i]=0;
	for(int i=n;i>=1;i--){
		int u=topo[i];
		int maxi=-1;
		for(int j=0;j<adj[u].size();j++)
			maxi=max(maxi,length[adj[u][j]]);
		length[u]=maxi+1;
	}		
	int maxi=-1;
	for(int i=1;i<=n;i++)
		maxi=max(maxi,length[i]);

	cout << maxi;


return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int minCostToReachN(vector<int>& stones, int k) {
	int stonesCount = stones.size();
	vector<int> dp(stonesCount);

	dp[stonesCount - 1] = 0;
	for (int i = stonesCount - 2; i >= 0; --i) {
		dp[i] = INT_MAX;
		for(int j = i + 1; j < stonesCount && j <= i + k; ++j)
			dp[i] = min(dp[i], dp[j] + abs(stones[i] - stones[j]));
	}

	return dp[0];
}

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

	vector<int> stones(n);
	for (auto& stone : stones)
		cin >> stone;

	cout << minCostToReachN(stones, k) << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

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

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef pair<int,int> P;

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

//------------------HEAD---------------------

int dp[100][3][3]; //dp[N][n-2 pasta][n-3 pasta]

int N;

int pastas[102];

int solve(int n, int p1, int p2){
    if(n==N)return 1;
    //cerr<<n<<" "<<p1<<" "<<p2<<" "<<dp[n][p1][p2]<<endl;
    if(p1!=-1&&p2!=-1&&dp[n][p1][p2]!=INF){
        return dp[n][p1][p2];
    }
    int t=0;
    if(pastas[n]!=-1){ //already decided
        if(p1!=p2||p2!=pastas[n])t=solve(n+1, p2, pastas[n]);
    }else{
        rep(i,3){
            if(p1!=p2||p2!=i)t+=solve(n+1,p2,i);
        }
    }
    t=t%10000;
    //<<t<<endl;
    dp[n][p1][p2]=t;
    return t;
}

int main(void){
    // Here your code !
    int K;
    cin>>N>>K;
    rep(i,N)pastas[i]=-1;
    rep(i,K){
        int a,b;
        cin>>a>>b;
        pastas[a-1]=b-1;
    }
    rep(i,N)rep(j,3)rep(k,3)dp[i][j][k]=INF;
    int ans=0;
    
    ans=solve(0,-1,-1);
    
    cout<<ans%10000<<endl;
    /*rep(i,N){
        rep(j,3)rep(k,3)cerr<<dp[i][j][k]<<"\t";
        cerr<<endl;
    }*/
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N; cin>>N;
    ll ans = 0ll;

    for (int i = 1; i <= N; ++i) {
        if(i%3!=0 && i%5!=0) ans+=i;
    }
    cout<<ans<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(1);
#endif
    return 0;
}


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

bool is_uruu(int y) {
	bool uruu = false;
	if (!(y % 4))uruu = true;
	if (!(y % 100))uruu = false;
	if (!(y % 400))uruu = true;
	return uruu;
}
int main() {
	int y1, m1, d1, y2, m2, d2;
	int m[]{ 31,28,31,30,31,30,31,31,30,31,30,31 }, uruu_m[]{ 31,29,31,30,31,30,31,31,30,31,30,31 };
	while (cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2, y1 >= 0 && m1 >= 0 && d1 >= 0 && y2 >= 0 && m2 >= 0 && d2 >= 0) {
		int cnt = 0;
		for (int i = y1; i < y2; i++) {
			cnt += 365;
			if (is_uruu(i))cnt++;
		}
		if (is_uruu(y1)) {
			for (int i = 0; i < m1 - 1; i++)cnt -= uruu_m[i];
			cnt -= d1 - 1;
		}
		else {
			for (int i = 0; i < m1 - 1; i++)cnt -= m[i];
			cnt -= d1 - 1;
		}
		if (is_uruu(y2)) {
			for (int i = 0; i < m2 - 1; i++)cnt += uruu_m[i];
			cnt += d2;
		}
		else {
			for (int i = 0; i < m2 - 1; i++)cnt += m[i];
			cnt += d2;
		}
		cout << cnt - 1 << endl;
	}
}

Measured memory_bytes: 3012