akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long
#define problem ""

template<typename A, typename B, typename C>
struct triple{
    A X;
    B Y;
    C Z;
    triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0){
    return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b){
    if (a.X != b.X)
        return a.X < b.X;
    if (a.Y != b.Y)
        return a.Y < b.Y;
    return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p){
    ofs << "( " << p.F << " , " << p.S << " )";
    return ofs;
}
template<typename T>
void print(T a){
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}
template<typename T>
T max(T a, T b, T c){
    return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c){
    return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a){
    return *min_element(all(a));
}
template<typename T, typename D>
D max(T a){
    return *max_element(all(a));
}
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void solve(){
    string s, t; cin >> s >> t;
	int ans = 0;
  	rngi(i, sz(s)) ans += (s[i]!=t[i]);
    cout << ans;
};
signed main()
{
    if(0){
        freopen(problem".in", "r", stdin);
        freopen(problem".out", "w", stdout);
    }
    srand(time(NULL));
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1; //cin >> t;
    rng(t) solve();
}


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

string S, T;
void input() {
cin >> S >> T;
}

 void solve() {
 T.pop_back();
 if(S == T) cout << "Yes" << endl;
 else cout << "No" << endl;
 }

 int main() {
 input();
 solve();
 return 0;
 }

Measured memory_bytes: 3528
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,j,k,r;
  char s1[1000000],s2[1000000];
  while(scanf("%d",&n),n){
    scanf("%s",s1);
    while(n--){
      j=1;
      for(i=r=0;s1[i];i++){
	if(s1[i]==s1[i+1])j++;
	else{
	  for(k=10000000;j/k==0;k/=10);
	  while(k){
	    s2[r++]=j/k+'0';
	    j%=k;
	    k/=10;
	  }
	  s2[r++]=s1[i];
	  j=1;
	}
      }
      s2[r]=0;
      strcpy(s1,s2);
      //printf("%s\n",s1);
   }
    printf("%s\n",s1);
  }
  return 0;
}

Measured memory_bytes: 680
N = int(input())
T = []
for i in range(N):
    t1 = int(input())
    T.append(t1)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

ans = T[0]
for i in range(1,N):
    ans = lcm(ans, T[i])
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LL               long long
#define PB               push_back
using namespace std;
int main(){
    
        LL n;cin>>n;
        LL a[n];
        for(LL i=0;i<n;i++)
            cin>>a[i];
        LL c=0,mx=0;
        for (int i=0;i<n;i++){
            mx=max(a[i],mx);
            // cout<<mx<<" "<<a[i]<<"\n";
            if (a[i]<mx) c+=mx-a[i];
        }
        cout<<c<<"\n";
    
}

Measured memory_bytes: 5236
#include<bits/stdc++.h>
#define rep(i,n,k) for(long long int i=k; i<n; ++i)
#define drep(i,n,k) for(long long int i=n-1; i>=k; --i)
using namespace std;

vector<long long int> par, rnk, a, b, num, qed;

void def(long long int n, long long int m){
  a.resize(m);
  b.resize(m);
  qed.resize(m);
  num.resize(n);
  par.resize(n);
  rnk.resize(n);
  rep(i,n,0){
    par[i] = i;
    rnk[i] = 0;
    num[i] = 1;
  }
}
  
//木の根を求める
int find(int x){
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}
//x,yの集合を統合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  
  if(rnk[x] < rnk[y]){
    par[x] = y;
    num[y] += num[x];
  }
  else{
    par[y] = x;
    num[x] += num[y];
  }
  if(rnk[x] == rnk[y]){
    rnk[x]++;
  }
}
//x,yが同じ集合に属するか
bool same(int x, int y){
  return find(x) == find(y);
}

int main(){
  long long int n, m;
  cin >> n >> m;
  def(n,m);
  
  rep(i,m,0){
    long long int as, bs;
    cin >> as >> bs;
    as--;
    bs--;
    a[i] = as;
    b[i] = bs;
  }
  long long int ans = n*(n-1)/2;
  
  drep(i,m,0){
    qed[i] = ans;
    if(same(a[i], b[i])) continue;
    else{
      ans -= num[find(a[i])] * num[find(b[i])];
      unite(a[i], b[i]);
    }
  }
  
  rep(i,m,0) cout << qed[i] << endl;
}

Measured memory_bytes: 6016
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Edge:
    def __init__(self,arg_to,arg_cost):
        self.to = arg_to
        self.cost = arg_cost

class Info:
    def __init__(self,arg_node_id,arg_sum_cost):
        self.node_id = arg_node_id
        self.sum_cost = arg_sum_cost

    def __lt__(self,another):
        return self.sum_cost < another.sum_cost


N,R = map(int,input().split())

G = [[] for _ in range(N+1)]
value = [None]*(N+1)
root = 0

for i in range(1,N+1):
    cost,tmp = map(int,input().split())
    G[root].append(Edge(i,cost))
    value[i] = tmp

for _ in range(R):
    to_,from_,cost = map(int,input().split())
    G[from_].append(Edge(to_,cost-1))

min_cost = [BIG_NUM]*(N+1)
min_cost[root] = 0;
Q = []

heappush(Q, Info(root,0))

while len(Q) > 0:
    info = heappop(Q)
    if info.sum_cost > min_cost[info.node_id]:
        continue
    for edge in G[info.node_id]:
        if min_cost[edge.to] > info.sum_cost+edge.cost:
            min_cost[edge.to] = info.sum_cost+edge.cost
            heappush(Q, Info(edge.to,min_cost[edge.to]))

ans = 0
for i in range(1,N+1):
    ans += min_cost[i]*value[i]

print("%d"%(ans))


Measured memory_bytes: 88848
#include <bits/stdc++.h>
#define lol long long
using namespace std;
signed main(){
  int n;
  string s;
  cin>>n>>s;
  size_t size=s.length();
  if(size>n){
    for(int i=0;i<n;i++) cout<<s[i];
    cout<<"...\n";
  }
  else{
    cout<<s<<"\n";
  }
  return(0);
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <map>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 305;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;


int n;

int mp[maxn][maxn];
int vis[maxn][maxn];


int floyd()
{
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        if(i==j||j==k||i==k) continue;
        if(mp[i][k]+mp[k][j]<mp[i][j])
        {
            return -1;
        }
        if(mp[i][k]+mp[k][j]==mp[i][j])
        {
            vis[i][j]=vis[j][i]=1;
        }
    }
}


int main()
{
    scanf("%d",&n);
    ll ans=0;
    mst(vis,0);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {

        scanf("%d",&mp[i][j]);
    }
    int flag=floyd();
    if(flag==-1)
    {
        puts("-1");
        return 0;
    }
    for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    {
        if(vis[i][j]==0)
            ans+=(ll)mp[i][j];
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<math.h>
long long int a,s,d=1,f,g,h;
int main(void)
{
	int i,j;
	scanf("%lld %lld",&a,&s);
	if(a==s){
		for(i=1;i<=a;i++){
			d*=i;
			d%=1000000007;
			d*=i;
			d%=1000000007;
		}
		d*=2;
		d%=1000000007;
	}
	else if(a+1==s){
		for(i=1;i<=s;i++){
			d*=i;
			d%=1000000007;
			if(i!=s){
				d*=i;
				d%=1000000007;
			}
		}
	}
	else if(a==s+1){
		for(i=1;i<=a;i++){
			d*=i;
			d%=1000000007;
			if(i!=a){
				d*=i;
				d%=1000000007;
			}
		}
	}
	else d=0;
	printf("%lld\n",d);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
VI G[maxn]; map<PII,int> W;
int dist[maxn], res[maxn], dp[maxn][2];

int dfs(const int u, const int p, const int c)
{
    int& ans = dp[u][c];
    if (-1 == ans) {
        ans = 0;
        const int w = W[PII(u,p)];
        dist[u] = (dist[p]+w) % 2;
        if (!dist[u]) {
            ans = 1; res[u] = 1;
            FOR_ALL(v,G[u]) if (*v != p)
                ans &= dfs(*v,u,1);
        }
        if (!ans) {
            if (c || !w) {
                ans = 1; res[u] = 0;
                FOR_ALL(v,G[u]) if (*v != p)
                    ans &= dfs(*v,u,0);
            }
        }
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        FOR(i,1,n+1)
            G[i].clear();
        FOR(_,0,n-1) {
            int u,v,w; cin >> u >> v >> w;
            w %= 2;
            G[u].push_back(v);
            G[v].push_back(u);
            W[PII(u,v)] = W[PII(v,u)] = w;
        }
        memset(dp,-1,sizeof(dp));
        dist[1] = 0; res[1] = 1;
        FOR_ALL(v,G[1])
            dfs(*v,1,1);
        FOR(i,1,n+1)
            cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 25088
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>

constexpr long double EPS = 1e-9;
void solve(const int x) {
	long double px{ 0 }, py{ 0 };
	long double dx{ 0 }, dy{ 1 };
	long double sinx{ std::sin(x * std::acos(-1) / 180) }, cosx{ std::cos(x * std::acos(-1) / 180) };
	int degree{ x };
	for (auto i = 1; i < 1000; ++i) {
		px += dx; py += dy;
		const auto ndx = dx * cosx - dy * sinx;
		const auto ndy = dy * cosx + dx * sinx;
		dx = ndx;
		dy = ndy;
		if (px * px + py * py <= EPS) {
			//std::cout << degree << '\n';
			std::cout << i << std::endl;
			return;
		}
		else {
			//std::cout << degree << '\n';
			//std::cout << px * px + py * py << std::endl;
			degree += x;
			degree %= 360;
		}
	}
	std::cout << "fail: " << x << std::endl;
	throw 0;
}
int main() {
	int x; std::cin >> x;
	solve(x);
}

Measured memory_bytes: 3784
#include <stdio.h>

#define Max 10000
#define NIL -1

struct tree{int parent,left,right;};
struct tree T[Max];
int n;

void pre(int u){
	if(u==NIL) return;
	printf(" %d",u);
	pre(T[u].left);
	pre(T[u].right);
}

void mid(int u){
	if(u==NIL) return ;
	mid(T[u].left);
	printf(" %d",u);
	mid(T[u].right);
}

void back(int u){
	if( u == NIL) return;
	back(T[u].left);
	back(T[u].right);
	printf(" %d",u);
}

int main(){
	scanf("%d",&n);
	int i;
	int id,l,r;
	int root;
	for(i=0;i<n;i++) T[i].parent = NIL;
	for(i=0;i<n;i++){
		scanf("%d",&id);
		scanf("%d%d",&l,&r);
		T[id].left = l;
		T[id].right = r;
		if(l != NIL) T[l].parent = id;
		if(r != NIL) T[r].parent = id;
	}

	for(i=0;i<n;i++)if(T[i].parent == NIL) root = i;

	printf("Preorder\n");
	pre(root);
	printf("\n");
	printf("Inorder\n");
	mid(root);
	printf("\n");
	printf("Postorder\n");
	back(root);
	printf("\n");

	return 0;
}

Measured memory_bytes: 2732
n = int(input())
a = list(map(int, input().split()))

ans = 10**10

# 1 -1 1 -1...
cost1 = 0
s = 0
for i in range(n):
    t = 1 if i % 2 == 0 else -1
    c = 0
    if i % 2 == 0:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost1 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost1 += abs(- c - a[i])

cost2 = 0
s = 0
for i in range(n):
    t = -1 if i % 2 == 0 else 1
    c = 0
    if i % 2 == 1:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost2 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost2 += abs(- c - a[i])

print(min(cost1, cost2))
# -1 1 -1 1..


Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll n,k,c;
vector <vector<ll>> g;
vector <ll> v[5005];
vector <ll> cost,vis;
void dfs(ll node)
{
    vis[node]++;
    v[c].pb(cost[node]);
    for(auto u:g[node])
     if(!vis[u])
      dfs(u);
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       ll i,x,j,y;
       cin>>n>>k;
       g.resize(n+1,vector<ll>());
       cost.resize(n+1);
       vis.resize(n+1);
       for(i=1;i<=n;i++)
       {
           cin>>x;
           g[i].pb(x);
       }
       for(i=1;i<=n;i++)
        cin>>cost[i];
       c=0;
       for(i=1;i<=n;i++)
       {
           if(!vis[i])
            dfs(i),c++;
       }
       ll ans=-INF;
    //    cout<<c<<"c=\n";
    //    for(i=0;i<c;i++)
    //    {
    //        for(auto u:v[i])
    //         cout<<u<<" ";
    //        cout<<"\n"; 
    //    }
       for(i=0;i<c;i++)
       {
           ll n1=v[i].size(),sum=0;
           for(auto u:v[i])
            sum+=u;
           for(j=0;j<n1;j++)
            v[i].pb(v[i][j]);
           ll tmax=-INF,mul=0;   
           for(j=1;j<=min(n1,k);j++)
           {
               ll p,tsum=0,tmx;
               for(p=0;p<j;p++)
                tsum+=v[i][p];
               tmx=tsum; 
               for(p=j;p<n1+j-1;p++)
                tsum-=v[i][p-j]-v[i][p],tmx=max(tmx,tsum);
               if(tmax<tmx)
               {
                   tmax=tmx;
                   mul=j;
               }  
           }
           if(sum>=0)
           {
               tmax=max(tmax,tmax+((k-mul)/n1)*sum);
           }
           if(k>n1&&sum>=0)
           {
               //cout<<"yo";
               ll k1=k,tmx=0;
               ll tsum=(k1/n1)*sum,tsum2=0;
               k1%=n1;
               for(j=0;j<k1;j++)
                tsum2+=v[i][j];
               tmx=tsum2;
               for(j=k1;j<n1+k1-1;j++)
                tsum2-=v[i][j-k1]-v[i][j],tmx=max(tsum2,tmx);
               tmax=max(tmax,tmx+tsum);  
               //cout<<tmax<<"\n";
           }
           ans=max(tmax,ans);
       }
       cout<<ans;
   }
}


Measured memory_bytes: 4316
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    while((H != 0) || (W != 0)){
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
 
//  cout <<  << endl;
//  printf("%f\n",x);
}


Measured memory_bytes: 3072
#include <stdio.h>

int main () {
  int i,j,n,minj,N,tmp,count=0;

  scanf("%d",&N);

  int A[N];
  
   for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
  }

  for(i=0;i<=N-1;i++) {
    minj =i;
    for(j=i;j<=N-1;j++) {
      if(A[j] < A[minj]) minj = j;
    }
    if(minj!=i) {
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    count++;
    }
  }

  for(i=0;i<N;i++) {
    if(i==0) printf("%d",A[i]);

    else printf(" %d",A[i]);
    if(i==N-1) printf("\n");
  }
  printf("%d\n",count);

  return 0;
  }



Measured memory_bytes: 2128
class UF():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def size(self, x):
        return self._size[self.find_root(x)]

    def samegroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def groupnum(self):
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans

n,m=map(int,input().split())
UF=UF(n)
for i in range(m):
  x,y,z=map(int,input().split())
  UF.unite(x-1,y-1)
print(UF.groupnum())

Measured memory_bytes: 7856
#include<stdio.h>

int main(void){
    int x,y;
    scanf("%d",&x);
    scanf("%d",&y);
    int result = 0;
    for (int i=1; i<=x; i++){
        if ( y == (i * 2 + (x-i) * 4)){
            result = 1;
            break;
        }
        if ( y == (i * 4 + (x-i) * 2)){
            result = 1;
            break;
        }
    }
    if (result) printf("Yes\n"); 
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1632
import numpy as np
N = int(input())
buf = list(map(int,input().split()))
cnt = 1
flag = True
for i in range(N) :
    if buf[i] == 0 :
        print(0)
        exit()
for i in range(N) :
    cnt = cnt * buf[i]
    if cnt > 10 ** 18 :
        flag = False
        break

if flag == True :
    print(cnt)
else :
    print("-1")

Measured memory_bytes: 40032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <cmath>
#include <sstream>
#include <set>  

using namespace std;

int main()
{
	int n, x, m;
	int a = 0;
	int ans = 0;
	int min = 1000;

	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> m;
		
		if (x >= m) {
			ans += 1;
		}
		x = x - m;

		if (min > m) {
			min = m;
		}
	}
	if (x > 0) {
		a = x / min;
	}

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


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var str = readLine()
    if(str != null) {
        val ary = str.split(Regex("\\s+"))
        val a = ary[0].toInt()
        val b = ary[1].toInt()
        println("${a*b} ${(a+b)*2}")
    }
 }


Measured memory_bytes: 29016
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n,m; cin >> n >> m;
    vi s[m];
    list(i,m){
        int k; cin >> k;
        s[i].eb(k);
        list(j,k){
            int currS; cin >> currS;
            s[i].eb(currS);
        }
    }
    int p[m]; list(i,m) cin >> p[i];

    //2^10 is 1024
    //so just brute force all the possibilities
    int ans = 0;
    for(int i=0;i<(1<<n);i++){
        bool allLighted = true;
        bool isOn[n]; list(k,n) isOn[k] = false;
        for(int j=0;j<n;j++){
            if(i & (1<<j)){
                //this bulb is on
                isOn[j] = true;
            }
        }
        //Now go through all the bulbs one by one...
        list(k,m){
            int currK = s[k][0];
            int currCounter = 0;
            rep(l,1,currK+1){
                int currS = s[k][l];
                if(isOn[--currS]) currCounter++;
            }
            if(currCounter%2!=p[k]){
                allLighted = false;
                break;
            }
        }
        if(allLighted) ++ans;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,m1,m2;
  m1=0;
  m2=0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0;i<N;i++) {
    cin >> A.at(i);
    if (A.at(i)>=m1){
      m2=m1;
      m1=A.at(i);
    } else if (A.at(i)>=m2) {
      m2=A.at(i);
    };
  };
  for (int i = 0;i<N;i++) {
    if (A.at(i)==m1){
      cout << m2 << endl;
    } else {
      cout << m1 << endl;
    };
  };
}

Measured memory_bytes: 2432
#include<iostream>

using namespace std;

int main(){

	int b1, b2, b3;

	cin >> b1 >> b2 >> b3;

	if ((b1 == 1 && b2 == 1)||b3 == 1){
		cout << "Open" << endl;
	} else {
		cout << "Close" << endl;
	}

	return 0;
}

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

int main() {
  uint32_t N, A, B;
  std::cin >> N >> A >> B;

  uint32_t sum = 0;
  for (size_t n = 1; n <= N; n++) {
    uint32_t digit_sum = 0, n_temp = n;
    while (n_temp != 0) {
      digit_sum += n_temp % 10;
      n_temp /= 10;
    }

    if (digit_sum >= A && digit_sum <= B) {
      sum += n;
    }
  }

  std::cout << sum << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int A[4];
   
    int a,b,c,d;
    b=0;
    c=0;
    d=0;
    for(a=0;a<4;a++){
        scanf("%d",&A[a]);

    }
    for(a=0;a<A[3];a++){
        if(b<A[0]){
            c=c+1;
            b=b+1;
        }else{
            if(d<A[1]){
                d=d+1;
            }else{
                c=c-1;
            }
        }

    }
   printf("%d",c);
    
    
    }



Measured memory_bytes: 1712
// https://atcoder.jp/contests/abc141/tasks/abc141_e
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using I = int;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (I i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    I N;
    string S;
    cin >> N >> S;
    I len = S.length(), maxv = 0;
    REP(d, len) {
        I cnt = 0;
        REP(i, len - d) {
            if (S[i] == S[i + d]) {
                cnt++;
            } else {
                cnt = 0;
            }
            maxv = max(maxv, min(cnt, d));
        }
        d = max(d, maxv - 1);
    }
    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
int n,m;
while(cin>>n>>m,n){
  string s1[n],s2[m];
  int a[n],s=0;
  r(i,n)cin>>s1[i]>>a[i];
  r(i,m)cin>>s2[i];
  r(i,m)r(j,n){
    int c=1;
    r(k,8){
      if(s1[j][k]=='*')continue;
      if(s1[j][k]!=s2[i][k])c=0;
    }
    if(c)s+=a[j];
  }
  cout<<s<<endl;
}  
}

Measured memory_bytes: 3220
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n,k,q = MI()

A = [0]*n
for i in range(q):
    c = I()
    A[c-1] += 1

for a in A:
    if q < k + a:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 13704
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    if(n==22) printf("Christmas Eve Eve Eve\n");
    else if(n==23)  printf("Christmas Eve Eve\n");
    else if(n==24)  printf("Christmas Eve\n");
    else if(n==25)  printf("Christmas\n");
    return 0;
}


Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    lis = []
    a = list(map(int, input().split()))
    for j in range(m):
        lis.append(a[j] * b[j])
    if sum(lis) + c > 0:
        ans += 1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //__gnu_pbds::gp_hash_table<int, int> table;
//priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;  //min heap

typedef int OwO;
typedef double UwU;

#define int long long
#define double long double
#define INF 1000000000
#define PI 3.14159265358979323846
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vi vector<int>

using namespace std;



OwO main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K;
  cin >> N >> K;
  vector<int> t;
  for(int x = 0; x<N; x++){
    int a;
    cin >> a;
    t.push_back(a);
  }
  int oup = -INF;
  for(int tl = 0; tl<=min(N,K); tl++){
    for(int tr = 0; tr+tl<min(N, K)+1; tr++){
      int size = tl+tr;
      vi hand = t;
      hand.erase(hand.begin()+tl, hand.end()-tr);
      sort(hand.rbegin(), hand.rend());
      for(int x = 0; hand.size() && x<K-size && hand[size-x-1]<0; x++)
        hand.pop_back();
      oup = max(oup, (int)accumulate(hand.begin(), hand.end(), 0));
    }
  }
  cout << oup << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        h1: usize,
        m1: usize,
        h2: usize,
        m2: usize,
        k: usize,
    }
    println!("{}", (h2 - h1) * 60 + (m2 - m1) - k);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define mod 1000000007
#define pb push_back
#define po pop_back
#define f(i,x,n) for(ll i=x; i<n; i++)
#define all(c) c.begin(),c.end()
#define unique_sort(x) sort(all(x)),x.resize(distance(x.begin(),unique(all(x))))
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    ll arr[n];
    f(i,0,n)
    cin>>arr[i];
    
    ll tt=1,ct=0;
    f(i,0,n)
    {
        if(arr[i]==tt)
        {
            ct++;
            tt++;
        }
    }
    if(ct==0)
    cout<<-1;
    else
    cout<<(n-ct);
}
int main()
{
// fast();
// #ifndef ONLINE_JUDGE
//             freopen("input.txt", "r", stdin);
//             freopen("output.txt","w",stdout);
// #endif
//     int t;
//     cin>>t;
//     while(t--)
//     {
         solve();
//     }
  return 0;
}

Measured memory_bytes: 1920
N = int(input())
H = list(map(int,  input().split()))

cur_count = 0
max_count = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        cur_count += 1
    else:
        cur_count = 0
    if cur_count > max_count:
        max_count = cur_count
print(max_count)


Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = 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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,c;
    string s;
    cin >> n >> k >> c >> s;
    vector<ll> ok(n+1,0);
    rep(i,n){
        if (s[i] == 'o'){
            ok[i+1] = ok[i]+1;
        }
        else{
            ok[i+1] = ok[i];
        }
    }
    vector<ll> ans,b(k);
    ll l = 0;
    rep(i,k){
        while(s[l] != 'o') l++;
        b[i] = l;
        l += c+1;
    }
    ll r = n;
    for (ll i = k-1;i >= 0;i--){
        ll d;
        rep(j,r-b[i]){
            if (s[b[i]+(r-b[i]-j-1)] == 'o'){
                d = b[i]+(r-b[i]-j-1);
                break;
            }
        }
        if (ok[r]-ok[b[i]] == 1){
            ans.push_back(d);
        }
        r = d-c;
    }
    reverse(all(ans));
    rep(i,ans.size()) PRINT(ans[i]+1);
}


Measured memory_bytes: 8552
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b&&b==c){
    cout << 1 << endl;
  }
  else if (a!=b&&b!=c&&c!=a){
    cout << 3 << endl;
  }
  else {
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#define N 44
int i,j,k,n,o,p;long long f[N][N][N],g[N][N][N],x;char a[N][N];
int main()
{
    scanf("%d",&n),n<<=1;
    for(i=1;i<=n;i++)scanf("%s",a[i]+1),f[i][i][i]=1;
    for(i=1;i<=n;i++)for(j=i+1;j<=n;j++)if(a[i][j]==49)g[i][j][i]=1;
    for(i=n;--i>1;)for(j=i+1;j<=n;j++)
    {
        for(o=i;o<j;o++)for(p=o+2;p<=j;p++)
        {
            for(x=0,k=p;k<=j;k++)x+=g[i][k][o]*f[p][k][j];
            for(k=o+1;k<p;k++)f[i][k][j]+=x*f[o+1][k][p-1];
        }
        for(o=i+1;o<j;o++)for(p=j+1;p<=n;p++)if(a[o][p]==49)g[i][p][j]+=f[i][o][j];
    }
    for(i=2,x=0;i<=n;i++)if(a[1][i]==49)x+=f[2][i][n];
    return 0*printf("%lld\n",x);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

    int a[N+1];
    for(int i=1; i<N+1; i++) cin >> a[i];


    int b[N+1], M=0;
    for(int i=N; i>0; i--) {
        if(2 * i > N) {
            b[i] = a[i];
        } else {
            int sum = a[i], j = 2;
            while(j * i <= N) {
                sum += b[j * i];
                j++;
            }

            b[i] = sum % 2;
        }
        M += b[i];
    }

    cout << M << endl;

    ll cnt = 0;
    for(int i=1; i<N+1; i++) {
        if(b[i] == 1) {
            if(cnt != 0) cout << " ";
            cout << i;
            cnt++;
            if(cnt == M) cout << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 2432
H, W = map(int, input().split())

hw = ['.' * (W+2)]
for i in range(H):
  hw.append('.' + input() + '.')
hw.append('.' * (W+2)) 
  
ans = "Yes"

for i in range(1, H+1):
  for j in range(1, W+1):
    if hw[i][j] == "#":
      if hw[i-1][j] == "." and hw[i][j-1] == "." and hw[i][j+1] == "." and hw[i+1][j] == ".":
        ans = "No"
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {
  int H,W;
  cin >> H>>W;
  string S[50];
  fx(H){
  cin>>S[x];	
  }
  
  fx(H){
  	fw(W){
  		if(S[x][w]=='.'){
  			int num=0;
  			fyg(2,-1){
  				fzg(2,-1){
  					if(y==0&&z==0){continue;}
  					if(x+y>=0&&x+y<H&&w+z>=0&&w+z<W&&S[x+y][w+z]=='#'){
  						num++;
  					}
  				}
  			}
  			S[x][w]=num+'0';
  		}
  	}
  }
  
  fx(H){
  	ce(S[x]);
  }
}

Measured memory_bytes: 256
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

N = inputs[0].to_i

i = 1
ans = 0
while i <= N
  if i % 3 == 0 || i % 5 == 0
    # nop
  else
    ans += i
  end
  i += 1
end

puts ans


Measured memory_bytes: 14364
#include <iostream>
#include <cstdio>
using namespace std;
const int inf = 88888888;
int n, m, R, f[300][300], d[10][10], r[10], dp[10][2050][10];

int bts(int p){
	int ans = 0;
	while (p) {
		if (p & 1) ans++;
		p >>= 1;
	}
	return ans;
}

int main(){
	cin >> n >> m >> R;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			f[i][j] = inf;
	for (int i = 1; i <= n; i++) f[i][i] = 0;
	for (int i = 0; i < R; i++) {
		int x; cin >> x;
		r[i] = x;
	}
	for (int i = 1; i <= m; i++) {
		int x, y, z; cin >> x >> y >> z;
		f[x][y] = f[y][x] = min(f[x][y], z);
	}
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
	for (int i = 0; i < R; i++)
		for (int j = 0; j < R; j++)
			d[i][j] = f[r[i]][r[j]];
	for (int i = 1; i <= R; i++)
		for (int j = 0; j < R; j++)
			for (int bt = 1; bt <= (1 << 8) - 1; bt++)
				dp[i][bt][j] = inf;
	for (int i = 0; i < R; i++)
		dp[1][1 << i][i] = 0;
	for (int i = 1; i < R; i++)
		for (int bt = 1; bt <= (1 << R) - 1; bt++) {
			if (bts(bt) != i) continue;
			for (int j = 0; j < R; j++){
				int kkk = bt & (1 << j);
				if (!kkk) continue;
				for (int gt = 0; gt < R; gt++) {
					int rrr = bt & (1 << gt);
					if (rrr) continue;
					dp[i + 1][bt + (1 << gt)][gt] = min(dp[i + 1][bt + (1 << gt)][gt], dp[i][bt][j] + d[j][gt]);
				}
			}
		}
	int ans = inf;
	for (int gt = 0; gt < R; gt++) ans = min(ans, dp[R][(1 << R) - 1][gt]);
	cout << ans << endl;
}


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

using namespace std;

int main(){

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

    int a, b;
    cin >> a >> b;

    for(int i=0;i<max(a,b);++i)
        cout << min(a,b);
    cout << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,h,w;
    cin>>n>>h>>w;
    vector<int>a(n),b(n);
    int ans=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        if(h<=a[i]&&w<=b[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order
from scipy.sparse import csr_matrix, coo_matrix
import sys
input = sys.stdin.readline
N, M = map(int,input().split())
A = []
B = []
for i in range(M):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)
D = [1] * M
csr = coo_matrix((D, (A, B)), (N, N)).tocsr()
Tcsr = breadth_first_order(csr, 0, False, True)
ans = []
for i in Tcsr[1][1:]+1:
    if i == -9998:
        print("No")
        quit()
    ans.append(i)
print("Yes")
for i in ans:
    print(i)

Measured memory_bytes: 64064
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 1e6 + 10;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
     int n;cin >> n;
     int b = n-n/1000*1000-(n-n/1000*1000)/100*100;
     int a = n-b;
     a /= 100;
     bool ok = 0;bool ok1 = 0;
     if(a<=12&&a>0) ok = 1;
     if(b<=12&&b>0) ok1 = 1;
     if(ok&&ok1) cout << "AMBIGUOUS";
     else if(ok) cout << "MMYY";
     else if(ok1) cout <<"YYMM";
     else cout << "NA";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3652
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
tree = [[] for i in range(N+1)]

for _ in range(N-1):
    a,b,c=list(map(int,input().split()))
    tree[a].append([b,c])
    tree[b].append([a,c])
Q,K=list(map(int,input().split()))
    
memo = [-1]*(N+1)
q = collections.deque([K])
memo[K]=0
while q:
    now = q.pop()
    for direct,cost in tree[now]:
        if memo[direct]== -1:
            memo[direct]=memo[now]+cost
            q.append(direct)
for _ in range(Q):
    a,b=map(int,input().split())
    ans =memo[a]+memo[b]
    print(ans)


Measured memory_bytes: 109184
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, Q;
	std::string S;
	in >> N >> Q >> S;
	std::vector<LL>l(Q), r(Q);
	rep(i, Q) in >> l[i] >> r[i];

	std::vector<LL>cnt(S.length()), cnt_imos(N + 1);
	rep(i, N - 1)
	{
		if (S[i] == 'A'&&S[i + 1] == 'C') ++cnt[i + 1];
	}
	rep(i, N) cnt_imos[i + 1] = cnt_imos[i] + cnt[i];

	rep(i, Q)
	{
		out << cnt_imos[r[i]] - cnt_imos[l[i]] << std::endl;
	}
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int min=(int)1e6,max=-1;
	for(int i=0;i<n;++i){
		cin>>a[i];
		if(a[i]>max){
			max=a[i];
		}
		if(a[i]<min)
		{
			min=a[i];
		}

	}
	cout<<max-min<<endl;
	return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro
{
    class MainClass
    {
        public static void Main()
        {
            MainClass mainClass = new MainClass();
            mainClass.Start();
        }

        public void Start()
        {
            int sum = 0, mod = 100;
            for (int i = 0; i < 5;i++){
                var line = int.Parse(Console.ReadLine());
                if(line%10==0){
                    sum += line;
                }else{
                    sum += line + (10 - line % 10);
                    mod = Math.Min(line % 10, mod);
                }
            }

            if (mod == 100) {
                Console.WriteLine(sum);
            }else{
                Console.WriteLine(sum + mod - 10);
            }
        }

        List<List<int>> IntInit()
        {
            int maxindex = int.Parse(Console.ReadLine());

            List<List<int>> array = new List<List<int>>();

            for (int i = 0; i < maxindex; i++)
            {
                array.Add(new List<int>(
                Console.ReadLine().Split(' ').Select(int.Parse)));
            }

            return array;
        }
    }
}




Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

struct P {
	int s;
	bool d[4];
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int h, w, k; cin >> h >> w >> k;

	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	x1--;
	y1--;
	x2--;
	y2--;

	vector<vector<bool>> map(h, vector<bool>(w));
	FOR_LT(x, 0, h) {
		FOR_LT(y, 0, w) {
			char c; cin >> c;
			if (c == '@') map[x][y] = true;
		}
	}

	pair<int, int> kD[4] = {
		{1, 0}, {-1, 0}, {0, 1}, {0, -1}
	};

	vector<vector<P>> ps(h, vector<P>(w));
	queue<pair<int, int>> search;
	search.push({ x1, y1 });
	while (!search.empty()) {
		auto c = search.front();
		//cout << c.first << " " << c.second << endl;
		search.pop();

		auto &cp = ps[c.first][c.second];
		if (c.first == x2 && c.second == y2) {
			cout << cp.s << endl;
			return 0;
		}

		FOR_LT(i, 0, 4) {
			//cout << "d : " << i << " " << cp.d[i] << endl;
			if (cp.d[i]) continue;

			FOR_LE(j, 1, k) {
				int nx = c.first + kD[i].first * j;
				int ny = c.second + kD[i].second * j;
				//cout << "s : " << nx << " " << ny << endl;
				if (nx < 0 || h <= nx || ny < 0 || w <= ny) break;
				if (map[nx][ny]) break;

				if (ps[nx][ny].s != 0 && ps[nx][ny].s < cp.s + 1) break;

				if (ps[nx][ny].s == 0) {
					search.push({ nx, ny });
					ps[nx][ny].s = cp.s + 1;
				}
				ps[nx][ny].d[i ^ 1] = true;
			}
		}
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 19040
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x)
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 2222222222222222222;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

struct Weighted_Graph {
  struct edge { ll node; pll cost; };
  vector<vector<edge>> e;

  Weighted_Graph(ll x = MAX) { e.resize(x + 1); }

  void add_edge(ll u, ll v, ll a, ll b) {
	pll p(a, b);
	edge e1 = { v,p }, e2 = { u,p };
	e[u].pb(e1);
	e[v].pb(e2);
  }

  vll dijkstra1(ll start) {
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll u;
	pll p;
	vll dist(e.size(), inf);
	dist[start] = 0;
	pq.push(pll(0, start));

	while (!pq.empty()) {
	  p = pq.top(); pq.pop();
	  u = p.second;
	  if (dist[u] < p.first) continue;
	  for (edge e1 : e[u]) {
		if (dist[e1.node] > dist[u] + e1.cost.first) {
		  dist[e1.node] = dist[u] + e1.cost.first;
		  pq.push(pll(dist[e1.node], e1.node));
		}
	  }
	}
	return dist;
  }

  vll dijkstra2(ll start) {
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll u;
	pll p;
	vll dist(e.size(), inf);
	dist[start] = 0;
	pq.push(pll(0, start));

	while (!pq.empty()) {
	  p = pq.top(); pq.pop();
	  u = p.second;
	  if (dist[u] < p.first) continue;
	  for (edge e1 : e[u]) {
		if (dist[e1.node] > dist[u] + e1.cost.second) {
		  dist[e1.node] = dist[u] + e1.cost.second;
		  pq.push(pll(dist[e1.node], e1.node));
		}
	  }
	}
	return dist;
  }

};

int main(void) {
  ll start, goal;
  cin >> n >> m >> start >> goal;
  Weighted_Graph wg(n);
  rep(i, m) {
	ll u, v, a, b;
	cin >> u >> v >> a >> b;
	wg.add_edge(u, v, a, b);
  }

  vll sto = wg.dijkstra1(start);
  vll gto = wg.dijkstra2(goal);

  vll answ;
  RFOR(i, 1, n + 1) {
	mi = min(mi, sto[i] + gto[i]);
	answ.pb(1000000000000000 - mi);
  }
  rrep(i, answ.size()) cout << answ[i] << endl;

  return 0;
}

Measured memory_bytes: 13952