akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

// #define DEBUG

#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;

const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}

random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

const int N = 5010;
ll dp[N][N];

ll power(ll a, int n){
    ll b = 1LL;

    while(n){
        if(n & 1) b = MUL(b, a, mod);
        a = MUL(a, a, mod);
        n >>= 1;
    }

    return b;
}

int main(void){
    int n; string str; cin >> n >> str;
    int len = str.size();

    rep(i, n + 1) rep(j, n + 1) dp[i][j] = 0LL;
    dp[0][0] = 1LL;

    rep(i, n){
        rep(j, n){
            ll& cur = dp[i][j];

            auto calc = [&](int ni, int nj){
                ll& next = dp[ni][nj];
                next = ADD(next, cur, mod);
            };

            calc(i + 1, j + 1);
            calc(i + 1, j + 1);

            calc(i + 1, max(0, j - 1));
        }
    }

    ll res = DIV(dp[n][len], power(2, len), mod);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 195968
#include <stdio.h>

int main(void)
{
    const int correct[3]= {1,2,3}; /*const var*/
    int A,B; /*user input var*/
    int i; /*loop var*/
    
    scanf("%d %d",&A,&B);
    for(i=0;i<3;i++)    if(correct[i]!=A && correct[i]!=B)  printf("%d",correct[i]);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 1100

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

	long long n, i, j, k, ans, g;
	cin >> n >> g;
	vector<long long> p(n), c(n);
	for (i = 0; i < n; i++) cin >> p[i] >> c[i];
	vector<long long> dp(MAXN, -1LL<<60);
	dp[0] = 0;
	for (i = 0; i < n; i++) {
		for (j = MAXN - 1; j >= 0; j--) {
			for (k = 1; k <= p[i]; k++) {
				if (j + k < MAXN) {
					if (k == p[i]) dp[j + k] = max(dp[j + k], dp[j] + k * (100 * (i + 1)) + c[i]);
					else dp[j + k] = max(dp[j + k], dp[j] + k * (100 * (i + 1)));
				}
			}
		}
	}

	for (i = 0; i < MAXN; i++) {
		if (dp[i] >= g) {
			cout << i << "\n";
			break;
		}
	}


	return 0;
}


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

int main()
{

int k;
cin >> k;
long long sum =0;
for (int i=1; i<=k; i++)
for (int j=1; j<=k; j++)
for (int l=1; l<=k; l++)
sum+= __gcd(i,__gcd(j,l));
cout << sum;
}


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

#define f(i,a,b) for( ll  i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based



using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;



 
const ll MAX = 2e5+10;
const ll inf = 1e15;
const ll mod = 1e9+7;

ll a[MAX];



int main(){
	fastio;
	ll n, x ,k , d;
	cin >> x >> k >> d;
	x = abs(x);
	ll y = x / d;
	if( y > k) cout << x - d*k << endl;
	else{
		if( y%2 == k%2 ) cout << x%d << endl;
		else cout << d - x%d << endl;
	}
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

using namespace std;

typedef long long ll;

typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002
int dp[MAX_N]={};
int dc[MAX_N]={};
//bool d[MAX_N]={};
int pa[MAX_N];

vector<int> G[MAX_N];

vector<int> child[MAX_N];
vector<int> ra[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que2;
queue<pos> que;
int v[MAX_N]={};
int d[MAX_N]={};
int c[MAX_N]={};


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

	rep(i,m){
		int a1,b1;
		cin>>a1>>b1;
		G[a1].push_back(b1);
		G[b1].push_back(a1);
	}
	cin>>q;
	memset(dp,-1,sizeof(dp));
	rep(i,q)cin>>v[i]>>d[i]>>c[i];
	rrep(i,q){
		que.push(pos{v[i],d[i],c[i]});
		while(!que.empty()){
			pos pos1=que.front();que.pop();
			if(dp[pos1.to]>=pos1.cost)continue;
			if(dp[pos1.to]==-1)dc[pos1.to]=pos1.color;
			dp[pos1.to]=pos1.cost;
			for(auto it:G[pos1.to]){
				que.push(pos{it,pos1.cost-1,pos1.color});
			}
		}
	}
	for(int i=1;i<n+1;++i){
		cout<<dc[i]<<endl;
	}
	return 0;

}





Measured memory_bytes: 14328
#include<iostream>
using namespace std;
int main(){
  int N, K;
  int h[100000];
  cin >> N >> K;
  for (int i=0; i<N; i++)
  	cin >> h[i];
  int counter = 0;
  for (int i=0; i<N; i++){
  	if (K <= h[i])
      counter++;
  }
  cout << counter;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> paths[101];
int cost[101][101];
bool used[101][101];
int n, m;
void dijkstra(int a){
   for(int i=1; i<=n; i++){
       int target ;
       int tmp = 1000000000;
       for(int j=1; j<=n; j++){
           if(!used[a][j] && cost[a][j] < tmp  ){
               target=j;
               tmp = cost[a][j];
           }
       }
       used[a][target] = true;
       for(int j=0; j<paths[target].size(); j++){
           pair<int, int> to = paths[target][j];
           cost[a][to.first] = min(cost[a][to.first], cost[a][target]+ to.second);
       }
   }
}

int main(){
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            
            used[i][j] = false;
            if(i!=j){
                cost[i][j] = 1000000000;
            }else{
                cost[i][i] = 0;
            }
        }
    }
    vector<int> as,bs, cs;
    int a,b,c;
    for(int i = 0; i<m; i++){
        cin >> a >> b >> c;
        paths[a].push_back(make_pair(b,c));
        paths[b].push_back(make_pair(a,c));
        as.push_back(a);
        bs.push_back(b);
        cs.push_back(c);
    }
    for(int i = 1; i<=n; i++){
        dijkstra(i);

    }
    int ans = 0;
    for(int i=0; i<m; i++){
        if(cost[as[i]][bs[i]] != cs[i]){
            ans++;
        }
    }
    cout << ans << endl;;


}

Measured memory_bytes: 384
import scipy.misc as scm

h, w, a, b = [int(i) for i in input().split()]

p = 10**9 + 7
ans = 0

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(h+w)
rf = invfact(h+w, f)

for i in range(w-b):
    wi = b + i
    ans += (f[h-a+wi-1] * rf[h-a-1] % p * rf[wi] % p) * (f[a+w-wi-2] * rf[a-1] % p * rf[w-wi-1] % p) % p
    ans %= p 

print(ans)

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

const int NIL = -1;
class Node {
public:
	int p, l, r;
	Node(int pp, int ll, int rr) { p = pp; l = ll; r = rr; }
};

vector<Node> T;
vector<int> D;
vector<int> H;

void depth( int u, int p)
{
	if( u == NIL ) return;
	D[u] = p;
	if( T[u].l != NIL ) depth( T[u].l, p + 1 );
	if( T[u].r != NIL ) depth( T[u].r, p + 1 );
}

int height( int u )
{
	int h1 = 0, h2 = 0;
	if( T[u].l != NIL ) h1 = height( T[u].l ) + 1;
	if( T[u].r != NIL ) h2 = height( T[u].r ) + 1;
	return H[u] = max( h1, h2 );
}

int sibling( int u )
{
	int p = T[u].p;
	if( p == NIL ) return NIL;
	if( T[p].l != NIL && T[p].l != u ) return T[p].l;
	if( T[p].r != NIL && T[p].r != u ) return T[p].r;
	return NIL;
}

int main()
{
	int n;
	cin >> n;
	T = vector<Node>( n, Node( NIL, NIL, NIL ) );
	D = vector<int>( n );
	H = vector<int>( n );
	for( int i = 0; i < n; i++ ) {
		int v, l, r;
		cin >> v >> l >> r;
		T[v].l = l;
		T[v].r = r;
		if( l != NIL ) T[l].p = v;
		if( r != NIL ) T[r].p = v;
	}

	int root;
	for( int i = 0; i < n; i++ ) {
		if( T[i].p == NIL ) root = i;
	}
	depth( root, 0 );
	height( root );

	for( int i = 0; i < n; i++ ) {
		cout << "node " << i << ": ";
		cout << "parent = " << T[i].p << ", ";
		cout << "sibling = " << sibling( i ) << ", ";
		int deg = 0;
		if( T[i].l != NIL ) deg++;
		if( T[i].r != NIL ) deg++;
		cout << "degree = " << deg << ", ";
		cout << "depth = " << D[i] << ", ";
		cout << "height = " << H[i] << ", ";
		if( T[i].p == NIL ) cout << "root";
		else if( T[i].l == NIL && T[i].r == NIL ) cout << "leaf";
		else cout << "internal node";
		cout << endl;
	}
}



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

const int INF = 1e9 + 5;

int main()
{
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) cin >> h[i];
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j <= i+2; j++) {
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n-1] << "\n";
    return 0;
}


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

int main() {
  int N; 
  cin >> N;
  int p[N];
  for (int i = 0; i < N; i++) {cin >> p[i];}
  
  int m[N];
  m[0] = p[0];
  int ans = 1;
  
  for (int i = 0; i < N - 1; i++) {
    m[i+1] = min(p[i+1], m[i]);
    if (p[i+1] == m[i+1]) ans++;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 1792
n = int(input())
restaurants = []
for i in range(n):
    s, p = input().split()
    restaurants.append((s, int(p)))
sorted_list = sorted(restaurants, key=lambda x:x[1], reverse=True)
sorted_list.sort(key=lambda x:x[0])

for i in range(n):
    print(restaurants.index(sorted_list[i]) + 1)

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

int main() {
int n,m,a,b;
  a=0;
  b=0;
  cin>>n>>m;
  for(int i=0;i<m;i++){
  cin>>b;
  a=a+b;}
  if(a>n){cout<<-1<<endl;}
  else{cout<<n-a<<endl;}
}

Measured memory_bytes: 3632
n=int(input())
nums=list(map(int,input().split()))

def maximum_heap(nums,i):
    left_index=2*(i+1)-1
    right_index=2*(i+1)
    if left_index<n and nums[left_index]>nums[i]:
        largest=left_index
    else:
        largest=i
    if right_index<n and nums[right_index]>nums[largest]:
        largest=right_index
    
    if largest!=i:
        nums[largest],nums[i]=nums[i],nums[largest]
        maximum_heap(nums,largest)

for i in range(int(n/2)-1,-1,-1):
    maximum_heap(nums,i)

print(" ",end="")
for i in range(n):
    if i!=n-1:
        print(nums[i],end=" ")
    else:
        print(nums[i])
        



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

int main() {
  int n;
  int ans=0;

  cin >> n;

  int h[n];
  int i=0;
  int c=0;
  int l;

  while(cin >> l) {
    h[i] = l;
    i++;
  }

  for(int i=0;i<n-1;i++) {
    if(h[i]>=h[i+1]){c++;}
    else {c=0;}
    if(c>ans) {ans++;}
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
use std::io::*;
use std::cmp;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    let ans = if v[0] + v[1] >= v[2] {
        "Yes"
    } else {
        "No"
    };
    println!("{}",ans);
}


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

long long MOD = 1e9+7;
int MAX_INT = 1e9;

long long H, W;
vector<vector<long long>> cost_map(1000+1, vector<long long>(1000+1, 0));

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  float D, T, S;
  cin >> D >> T >> S;

  cout << ((D / S <= T) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 11640
import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
def solve(p, v, rs):
    als = G[v]
    cs = g[v]
    c = 0
    for u in als:
        if u in cs:
            c += solve(v, u, rs)
        elif u != p:
            if v < u:
                c += 1
            rs.add((min(u,v), max(u,v)))
    if p == None:
        return
    elif c%2 != 0:
        rs.add((v, p))
        return 0
    else:
        rs.add((p,v))
        return 1

N, M = map(int, readline().split())
if M %2 != 0:
    print(-1)
else:
    G = defaultdict(set)
    for v in range(M):
        a, b = map(int, readline().split())
        G[a].add(b)
        G[b].add(a)

    stack=[1]
    vs = set([1])
    g = defaultdict(set)
    counter = 1
    while True:
        v = stack.pop()
        for u in G[v]:
            if u in vs:
                continue
            vs.add(u)
            g[v].add(u)
            stack.append(u)
            counter += 1
        if counter == N:
            break
    rs = set()
    solve(None,1, rs)
    for r in rs:
        print(r[0], r[1])




Measured memory_bytes: 175212
import numpy as np

n = int(input())
a = np.array([list(map(int, input().split())) for _ in range(n)])
a_sorted = a[a[:, 1].argsort(), :]

a_sorted[:, 0] = np.cumsum(a_sorted[:, 0])
print("Yes" if all(map(lambda x: x[0] <= x[1], a_sorted)) else "No")


Measured memory_bytes: 62476
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Rounding
            var line = ReadLine();
            int x = line[0];
            int a = line[1];

            if (x < a)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(10);
            }

        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}


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

int main() {
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> sum(n+1,0);
  vector<int> l(q),r(q);
  for(int i=0; i<q; i++) {
    cin >> l[i] >> r[i];
  }
  for(int i=1; i<n; i++) {
    if(s[i-1]=='A'&&s[i]=='C') {
      sum[i+1]=sum[i]+1;
    }
    else {
      sum[i+1]=sum[i];
    }
  }
  for(int i=0; i<q; i++) {
    cout << sum[r[i]]-sum[l[i]] << endl;
  }
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};


int main()
{
    int N;
    cin >> N;
    ll a[N];
    ll b[N];
    REP(i,0,N){
        cin >> a[i] >> b[i];
    }
    ll ans=0;
    for (int i = N - 1; i >= 0;i--){
        if((a[i]+ans)%b[i]!=0){
            ans += b[i] - (a[i] + ans) % b[i];
        }
    }
    cout << ans << endl;
}

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

int main(){
  string n; cin>>n;
  char l = n.at(n.size()-1);
  if (l=='3')  cout<<"bon"<<endl;
  else if (l=='0' | l=='1' | l=='6' | l=='8') cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
}

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

int main()
{
	int H, W;
	cin >> H >> W;

	string grid[50];
	
	for (int i = 0; i < H; i++)
		cin >> grid[i];

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			int temp(0);
			if (grid[i][j] == '.')
			{
				temp += (i > 0) && (grid[i - 1][j] == '#');			
				temp += (i > 0 && j > 0) && (grid[i - 1][j - 1] == '#');
				temp += (i > 0 && j < W - 1) && (grid[i - 1][j + 1] == '#');
				temp += (j > 0) && (grid[i][j - 1] == '#');
				temp += (j < W - 1) && (grid[i][j + 1] == '#');
				temp += (i < H - 1) && (grid[i + 1][j] == '#');
				temp += (i < H - 1 && j > 0) && (grid[i + 1][j - 1] == '#');
				temp += (i < H - 1 && j < W - 1) && (grid[i + 1][j + 1] == '#');

				grid[i][j] = to_string(temp)[0];
			}
			else
				grid[i][j] = '#';
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
			cout << grid[i][j];
		cout << endl;
	}

	return 0;
}


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

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

    int n = s.length();
    vector<long long int> a(n+1);
    long long int count = 0;
    for(int i=0; i<n; i++){
        if(s[i] == '<') count += 1;
        else count = 0;

        a[i+1] = max(a[i+1], count);
    }
    count = 0;
    for(int i=n-1; i>=0; i--){
        if(s[i] == '>') count += 1;
        else count = 0;

        a[i] = max(a[i], count);
    }

    long long int ans = 0;
    for(int i=0; i<n+1; i++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int ans=0;
	for (int i = 0;i <= A;i++) {
		for (int j = 0;j <= B;j++) {
			int p = (X - 500 * i - 100 * j) / 50;
			if (0 <= p && p <= C) { ans++; }
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<string,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  int A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;
  int AB_price=min(A+B,2*C);
  int ans=0;
  if(X>Y){
    ans=Y*AB_price+(X-Y)*A;
  }
  else{
    ans=X*AB_price+(Y-X)*B;
  }
  ans=min(ans,max(X,Y)*AB_price);
  print(ans)
}


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

#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define per(i, b, a) for(int i = b; i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (1000*1000*1000+7)
#define inf (2*1000*1000*1000+9)
#define infl ((ll)2*1000*1000*1000*1000*1000*1000+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

/* -------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------*/

const int limit=200005; 
ll dd[limit][17]; 

void pop(vi &a, int n, vll &dp){
	rep(i,0,15) dd[n-1][i]=i; 
	dp[n-1]=0; 
	per(i,n-2,0){
		ll cur=a[i]; 
		ll nxt=a[i+1];
		ll op=0; 
		rep(j,0,15){
			while(cur>nxt) { op++; nxt*=4; }
			dd[i][j]=j+((op<=15)?dd[i+1][op]:dd[i+1][15]+(op-15)*(n-1-i)); 
			cur<<=2; 
		}	
		dp[i]=2*dd[i][0]; 
	}
}

void solve(){
	int n; cin>>n; 
	vi a(n); vll dpl(n), dpr(n); 
	rep(i,0,n-1) cin>>a[i]; 	
	pop(a,n,dpr); 
	// rep(i,0,n-1) cout<<dpr[i]<<" " ; cout<<endl; 
	reverse(all(a)); 
	pop(a,n,dpl); 
	reverse(all(dpl)); 
	// rep(i,0,n-1) cout<<dpl[i]<<" " ; cout<<endl; 
	ll ans=dpr[0]; 
	rep(i,1,n-1){
		ans=min(ans,dpr[i]+dpl[i-1]+i); 		
	}
	cout<<ans; 
}

int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans=-1;
string s[200];
vector<int> v[200];

signed main() {
    cin >> n;
    rep(i,n) cin >> s[i];
    rep(i,n) rep(j,n) if (s[i][j] == '1') v[i].pb(j);
    rep(i,n) {
        int tmpans=0,memo[200]={};
        queue<int> que;
        memo[i] = 2;
        que.push(i);
        while(que.size()) {
            queue<int> tmpque;
            while(que.size()) {
                int qf = que.front();que.pop();
                for(auto j : v[qf]) {
                    if (abs(memo[j]-memo[qf]) == 1) continue;
                    if (memo[j]) goto BREAK;
                    memo[j] = memo[qf]+1;
                    tmpque.push(j);
                }
            }
            que = tmpque;
            tmpans++;
        }
        ans = max(ans, tmpans);
        BREAK:;
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
#![allow(unused_imports)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

fn merge(a: HashMap<usize, u64>, b: HashMap<usize, u64>) -> HashMap<usize, u64> {
    let (c, mut d) = if a.len() < b.len() { (a, b) } else { (b, a) };
    for (k, v) in c {
        let p = d.entry(k).or_insert(0);
        *p += v;
    }
    d
}

fn dfs(
    u: usize,
    p: usize,
    c: &Vec<usize>,
    edge: &Vec<Vec<usize>>,
    ans: &mut Vec<u64>,
) -> (u64, u64, HashMap<usize, u64>) {
    let mut hm: HashMap<usize, u64> = HashMap::new();
    let mut cnt = 0;
    let mut si = 1;
    for v in edge[u].iter().cloned() {
        if v == p {
            continue;
        }
        let (cn, s, h) = dfs(v, u, c, edge, ans);
        cnt += cn;
        si += s;

        match h.get(&c[u]) {
            Some(x) => {
                let si = s - x;           
                ans[c[u]] -= (si + 1) * si / 2;
            }
            None => {
                ans[c[u]] -= (s + 1) * s / 2;
            }
        }
        hm = merge(hm, h);
        
    }
    *hm.entry(c[u]).or_insert(0) = si;

    if u == 0 {
        for i in 1..ans.len() {
            match hm.get(&i) {
                Some(x) => {
                    let si = si - x;
                    ans[i] -= (si + 1) * si / 2;
                }
                None => {
                    ans[i] -= (si + 1) * si / 2;
                }
            }
        }
    }
    return (cnt, si, hm);
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let c: Vec<usize> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![vec![]; n];
    for _i in 0..n - 1 {
        let a: usize = scan.next();
        let b: usize = scan.next();
        let (a, b) = (a - 1, b - 1);
        edge[a].push(b);
        edge[b].push(a);
    }
    let mut ans = vec![n as u64 * (n as u64 + 1) / 2; n + 1];
    dfs(0, 0, &c, &edge, &mut ans);
    for i in 1..ans.len() {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 171784
N = int(input())

def calc(N):
    ret = 2
    M = int(N ** 0.5) + 1
    for i in range(2, M):
        if N % i == 0:
            ret += 2
    return ret

ans = 0
for i in range(1, N + 1, 2):
    if calc(i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N,K;
    cin>>N>>K;
    vector<long long> H(N);
    for(int i=0;i<N;i++){
        long long h;
        cin>>h;
        H[i]=h;
    }
    
    sort(H.begin(),H.end());
    
    long long ans = 0;
    for(int i=0;i<N-K;i++){
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
n, x = gets.split.map(&:to_i)
ls = gets.split.map(&:to_i)
@ret = 0

ls.each_with_index.inject(0) do |sum, (l, i)|
	if sum + l > x
		@ret = i + 1
		break
	end
	sum + l
end
p @ret != 0 ? @ret : ls.size + 1

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 200001
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
void sieve();
int main()
{
	//sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}
ll pr[1001];
vector<ll> prime;
void sieve()
{
	pr[0]=-1;
	pr[1]=-1;
	ll i,j;
	for(i=2;i<1001;i++)
	{
		if(pr[i]!=-1)
		{
			pr[i]=1;
			for(j=2;j<1001/i+1;j++)
			{
				if(i*j<1001)
				pr[i*j]=-1;
			}
		}
	}
	for(i=2;i<1001;i++)
	{
		if(pr[i]==1)
		prime.pb(i);
	}
}
		
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;
	
	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
bool isprime(ll x)
{
	bool flag=true;
	for(ll i=2;i<=sqrt(x)+1;i++)
	{
		if(x%i==0)
		{
			flag=false;
			break;
		}
	}
	if(x==1)
	flag=false;
	
	return flag;
}
void swap(ll& a,ll& b)
{
	ll t=a;
	a=b;
	b=t;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	ll arr[n];
	for(i=0;i<n;i++)
	cin>>arr[i];
	sort(arr,arr+n);
	ll s=0;
	for(i=0;i<k;i++)
	s+=arr[i];
	cout<<s;
}
	
	


Measured memory_bytes: 3692
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    ll back = 0;
    for(ll i = k; i < n; ++i){
        if(a[i-k] < a[i])cout << "Yes\n";
        else cout << "No\n";
    }
}

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

#define ll long long int
#define mod 1000000007

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;


int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x,n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=2;i<=n;i++){
		cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<"\n";
	}
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N;
	vector<int>H(N);
	bool flag = 1;
	for (int i = 0; i < N; i++)cin >> H[i];
	for (int i = 0; i < N; i++) {
		flag = 1;
		for (int j = 0; j < i; j++) {
			if (H[i] < H[j]) {
				flag = 0;
			}
		}
		if (flag)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
count = {}
for c in s:
    if c not in count:
        count[c] = 1
    else:
        count[c] += 1
ret = 1
for _, c in count.items():
    ret *= c + 1
print((ret - 1) % (10**9 + 7))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1000000000;

ll dp[100001][13];

int main()
{
   memset(dp,0,100001*10*sizeof(ll));
   string s;
   cin >> s;
   int n = s.size();
   dp[0][0]=1;
   rep(i,n)
   {
      if(s[i]=='?')
      {
         rep(j,13)
         {
            rep(k,10)
            {
               dp[i+1][(j*10+k)%13]+=dp[i][j];
               dp[i+1][(j*10+k)%13]%=MOD;
            }
         }
      }
      else
      {
         rep(k,13)
         {
            dp[i+1][(k*10+s[i]-'0')%13]=dp[i][k];
            dp[i+1][(k*10+s[i]-'0')%13]%=MOD;
         }
      }
   }

   cout<<dp[n][5]<<endl;
   return 0;
}

Measured memory_bytes: 10624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N;
    long long zen=0LL;
    cin >> N;
    vector<long long> A(N);
    vector<long long> count(N + 1);
    rep(i, 0, N) {
        cin >> A[i];
        count[A[i]]++;
    }
    rep(i, 1, N + 1) {
        // cout << "ci:"<<count[i] << endl;
        zen += count[i] * (count[i] - 1)/2;
    }
    //cout << "zen:" << zen << endl;
    rep(i, 0, N) {
        long long res = zen - count[A[i]] * (count[A[i]] - 1)/2;
        if(count[A[i]] > 0) {
            res += (count[A[i]] - 1) * (count[A[i]] - 2)/2;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
	int n;

	cin >> n;

	char pic[54];
	int num[54];

	for (int i = 0; i < n; i++) {
		cin >> pic[i] >> num[i];
	}

	for (int i = 1; i <= 13; i++) {
		int flag = 0;
		for (int j = 0; j < n; j++) {
			if ( pic[j] == 'S' && num[j] == i) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			printf("S %d\n", i);
		}
	}

	for (int i = 1; i <= 13; i++) {
		int flag = 0;
		for (int j = 0; j < n; j++) {
			if (pic[j] == 'H' && num[j] == i) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			printf("H %d\n", i);
		}
	}

	for (int i = 1; i <= 13; i++) {
		int flag = 0;
		for (int j = 0; j < n; j++) {
			if (pic[j] == 'C' && num[j] == i) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			printf("C %d\n", i);
		}
	}

	for (int i = 1; i <= 13; i++) {
		int flag = 0;
		for (int j = 0; j < n; j++) {
			if (pic[j] == 'D' && num[j] == i) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			printf("D %d\n", i);
		}
	}

	return 0;
}

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

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

    int ans = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i + 1 < n; ++i)
    {
        if (a[i + 1] % a[i] == 0) a[i + 1] = a[i];
        else{
            int b = a[i], r = a[i + 1] % a[i];
            do{
                int tmp;
                tmp = r;
                r = b % r;
                b = tmp;
            } while (r != 0);
            a[i + 1] = b;
        }
    }
    cout << a[n - 1] << endl;
}

Measured memory_bytes: 640
N = int(input())
T = tuple(map(int, input().split()))
M = int(input())

ans = []
for i in range(M):
    p, x = map(int, input().split())
    tmp = list(T)
    tmp[p-1] = x
    ans.append(sum(tmp))
for a in ans:
    print(a)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2e5+5;
int n,a[N],pos[2][N<<2];
int MN(int x,int y){
	return a[x]<a[y]?x:y;
}
void buildtree(int k,int l,int r){
	if(l==r){
		pos[l&1][k]=l;return;
	}
	int mid=l+r>>1;
	buildtree(k<<1,l,mid);buildtree(k<<1|1,mid+1,r);
	pos[0][k]=MN(pos[0][k<<1],pos[0][k<<1|1]);
	pos[1][k]=MN(pos[1][k<<1],pos[1][k<<1|1]);
}
int find(int k,int l,int r,int L,int R,int d){
	if(l>=L&&r<=R) return pos[d][k];
	int mid=l+r>>1;
	if(R<=mid) return find(k<<1,l,mid,L,R,d);
	if(L>mid) return find(k<<1|1,mid+1,r,L,R,d);
	return MN(find(k<<1,l,mid,L,R,d),find(k<<1|1,mid+1,r,L,R,d));
}
struct info{
	int l,r,pos;
	info(int _l,int _r){
		l=_l;r=_r;
		pos=l>r?0:find(1,1,n,l,r,l&1);
	}
	bool operator <(const info &rhs)const{
		return a[pos]<a[rhs.pos];
	}
};
set<info> s;
int main(){
	n=read();
	a[0]=n+1;For(i,1,n) a[i]=read();
	buildtree(1,1,n);
	s.insert(info(1,n));
	For(i,1,n/2){
		info ssw=*s.begin();
		s.erase(s.begin());
		int l=ssw.l,r=ssw.r;
		int pos=ssw.pos,id=find(1,1,n,pos+1,r,(pos&1)^1);
		writep(a[pos]);writep(a[id]);
		s.insert(info(l,pos-1));
		s.insert(info(pos+1,id-1));
		s.insert(info(id+1,r));
	}
}

Measured memory_bytes: 10876
s = [list(map(int,input().split())) for l in range(3)]

for i in range(3):
    a = []
    for j in range(3):
        a.append(s[(i+1)%3][j] - s[i%3][j])

    if a.count(a[0]) == len(a):
        continue
    else:
        print('No')
        exit()
else:
    print('Yes')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, m;
    cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    cin >> m;
    int p, x;
    vector<int> sum(m);
    for (int i = 0; i < m; i++) {
        sum[i] = 0;
        cin >> p >> x;
        for (int j = 0; j < n; j++) {
            if (j == p - 1) {
                sum[i] += x;
            }else{
                sum[i] += t[j];
            }
        }
    }
    for (int i = 0; i < m; i++) {
        cout << sum[i] << endl;
    }
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

int64_t getVal(int64_t d){
  int64_t ans = 1;
  for(int i=1;i<d;i++){
    ans *= 10;
  }
  return ans;
}

signed main() {
  int64_t n;
  cin >> n;
  string s;
  cin >> s;
  if(n%2==1){
    cout << "No" << endl;
    return 0;
  }
  
  for(int i=0;i<s.length()/2;i++){
    if(s[i]!=s[i+s.length()/2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}




Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
#define rep(i,x) for(int i=1;i<=x;i++)
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	bool ok=0;
	for(int i=1;i<=3;i++) if((i*a*b)%2==1) ok=1;
	if(ok) puts("Yes");
	else puts("No"); 
} 

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    int a[3][3];
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    bool used[3][3];
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            used[i][j] = false;
        }
    }
    int n;
    cin >> n;
    int b[n];
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(a[j][k] == b[i])
                {
                    used[j][k] = true;
                }
            }
        }
    }
    for(int i = 0; i < 3; i++)
    {
        bool ok = true;
        for(int j = 0; j < 3; j++)
        {
            if(!used[i][j]){
                ok = false;
            }
        }
        if(ok)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    for(int i = 0; i < 3; i++)
    {
        bool ok = true;
        for(int j = 0; j < 3; j++)
        {
            if(!used[j][i]){
                ok = false;
            }
        }
        if(ok)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    bool ok = true;
    for(int i = 0; i < 3; i++)
    {
        if(!used[i][i])
        {
            ok = false;
            break;
        }
    }
    if(ok)
    {
        cout << "Yes\n";
        return 0;
    }
    ok = true;
    for(int i = 0; i < 3; i++)
    {
        if(!used[i][2 - i])
        {
            ok = false;
            break;
        }
    }
    if(ok)
    {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\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;

int main()
{
    int N;
    cin >> N;
    int H[N];
    rep(i, N) cin >> H[i];

    int ans = 0;
    int i = 0;
    int tmp = 0;
    while (i < N-1) {
        if (H[i] >= H[i+1]) {
            tmp++;
            ans = max(ans, tmp);
        }
        else {
            tmp = 0;
        }
        i++;
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define llrep(i,a,b) for(ll i=a;i<b;i++)
#define llrepd(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
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; }

//---------------------------------------------------------------------------------------------------
void _main() {
    ll N, M; cin >> N >> M;
    vector<vector<ll>> sw(N);
    llrep(i, 0, M) {
        ll k; cin >> k;
        rep(j, 0, k) {
            ll tmp; cin >> tmp;
            sw[tmp-1].push_back(i);
        }
    }
    vector<ll> p(M, 0);
    rep(i, 0, M) cin >> p[i];
    ll count = 0;
    rep(i, 0, 1 << N) {
        vector<ll> res(M, 0);
        rep(j, 0, N) {
            if ((1<<j)&i) {
                rep(k, 0, sw[j].size())  res[sw[j][k]] += 1;
            }
        }
        bool state = true;
        rep(j, 0, M) {
           if (p[j] != (res[j]%2)) state = false;
        }
        if (state) count++;
    }
    cout << count << endl;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

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

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

  queue<ll> q;
  rep(i, 9) {
    q.push(i+1);
  }
  ll ans;
  rep(i, k) {
    ans = q.front(); q.pop();
    ll t = ans % 10;
    ll x = ans * 10;

    if( t != 0 ) {
      q.push(x + t - 1);
    }
    q.push(x + t);
    if( t != 9 ) {
      q.push(x + t + 1);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=100005;
bool cmp(pair<string,pii> a,pair<string,pii> b)
{
      if(a.fi==b.fi) return a.se.fi>b.se.fi;
      return a.fi<b.fi;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      vector<pair<string,pii>> a;
      for(int i=0;i<n;i++)
      {
            string s;
            cin>>s;
            int p;
            cin>>p;
            a.pb({s,{p,i}});
      }
      sort(all(a),cmp);
      for(int i=0;i<n;i++) cout<<a[i].se.se+1<<"\n";
}     


Measured memory_bytes: 256