akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int> > indset(26);
    FOR(i, 0, N)
        indset[S[i] - 'a'].insert(i);

    while (Q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;char c;
            cin >> i >> c;
            i--;
            if (S[i] == c)
                continue;
            char p = S[i];
            S[i] = c;
            set<int>& st = indset[p - 'a'];
            st.erase(st.lower_bound(i));
            indset[c - 'a'].insert(i);
        } else {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int ret = 0;
            for(set<int>& st : indset) {
                auto pos = st.lower_bound(l);
                if (pos == st.end())
                    continue;
                if (*pos <= r)
                    ret++;
            }

            cout << ret << endl;
        }
    }

    return 0;
};

Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cout<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

const double EPS = 1e-9;
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
#define X real()
#define Y imag()

// 2????????????
VP crosspointCC(Point a, double ar, Point b, double br) {
  VP ps;
  Point ab = b-a;
  double d = abs(ab);
  double crL = (norm(ab) + ar*ar - br*br) / (2*d);
  if (EQ(d, 0) || ar < abs(crL)) return ps;

  Point abN = ab * Point(0, sqrt(ar*ar - crL*crL) / d);
  Point cp = a + crL/d * ab;
  ps.push_back(cp + abN);
  ps.push_back(cp - abN);
  return ps;
}

// VP crosspointCC(Point p1, double r1, Point p2, double r2){
//   double d = abs(p2-p1);
//   double t = acos(double((d*d+r1*r1-r2*r2)/(2*d*r1)));
//   return Line(p1+polar(r1,arg(p2-p1)+t), p1+polar(r1,arg(p2-p1)-t));
// }

double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// ?????????cross(a,b) = |a||b|sin??
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// ??????????????????
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on ps
  if (norm(b) < norm(c)) return -2;  // a--b--c on ps or a==b
  return 0;                          // a--c--b on ps or a==c or b==c
}

bool isecSS(Point a1, Point a2, Point b1, Point b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
  ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}


int main(void){
    int n;
    while(cin>>n, n){
        VP c(n);
        vector<double> r(n);
        rep(i,n){
            double x,y;
            cin>>x>>y>>r[i];
            c[i] = {x,y};
        }

        vector<VP> ps(n+1);
        ps[0] = {c[0],c[0]};
        ps[n] = {c[n-1],c[n-1]};
        rep(i,n-1){
            ps[i+1] = crosspointCC(c[i],r[i],c[i+1],r[i+1]);
        }

        double d[210][210]={};
        rep(i,210)rep(j,210)d[i][j]=1e8;
        rep(i,n) FOR(j,i+1,n+1) rep(i2,2) rep(j2,2) {
            bool connect=true;
            FOR(k,i+1,j) {
                connect &= isecSS(ps[i][i2],ps[j][j2],ps[k][0],ps[k][1]);
            }
            if(connect){
                d[i*2+i2][j*2+j2] = abs(ps[i][i2]-ps[j][j2]);
            }

        }

        rep(k,n*2+2)rep(i,n*2+2)rep(j,n*2+2)
            d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

        printf("%.9f\n",d[0][n*2]);
    }
    return 0;
}

Measured memory_bytes: 3704
#前の問題で、戻り値とかIDとか変更したつもりのリストが変わっていないことが
#頻発していたはずだがとりあえず並び替え自体は終わる。countどうしようか。
#いじると並び替え前の配列が返ってくることがある。

n=int(input())
A1=input().split( )
A=[int(A1[i]) for i in range(n)]
###疑似コードのコピペ
def merge(A, left, mid, right):
    n1 = mid - left;
    n2 = right - mid;
#いちいち[0 for i...]を作るのやめた
    L=A[left:mid]+[10000000000]
    R=A[mid:right]+[10000000000]
    
    i = 0
    j = 0
    count=0

    for k in range(left,right):
        count+=1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1

#count+=1の位置を変更,比較ってinfinityとの比較も含めるのか
#計算量的には当然か。
    return(count)

def mergeSort(A, left, right):
    count=0
    mid=0
    if left+1 < right:
        mid = int((left + right)/2)
#この辺で新しい変数をmergeSortの戻り値として定義
        countL=mergeSort(A, left, mid)
        countR=mergeSort(A, mid, right)
        countM=merge(A, left, mid, right)
        count=countL+countR+countM
    return(count)
c=mergeSort(A,0,n)
print(*A)
print(c)



Measured memory_bytes: 67656
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i,H) cin >> A.at(i);
    for (auto i = A.begin(); i != A.end();) {
        if (count(i->begin(), i->end(), '#') == 0) {
            A.erase(i);
        } else i++;
    }
    vector<int> toErase;
    rep(i, W) {
        bool found = false;
        rep(j, A.size()) {
            if (A.at(j).at(i) == '#') {
                found = true;
                break;
            }
        }
        if (found) continue;
        toErase.push_back(i);
    }
    rep(j, A.size()) {
        string s;
        rep(i,W) {
            if (find(begin(toErase), end(toErase), i) == end(toErase)) s.push_back(A[j].at(i));
        }
        A[j] = s;
    }
    rep(i,A.size()) {
        cout << A.at(i) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
#include<stdio.h>

using namespace std;

//flagを用いたバブルソート
int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; ++i) {
		flag = 0;
		for (int j = N - 1; j >= i + 1; --j) {
			if (A[j] < A[j - 1]) {
				//隣接行列交換
				swap(A[j], A[j - 1]);
				flag = 1;
				++sw;
			}
		}
	}
	return sw;
}

int main() {
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];

	sw = bubbleSort(A, N);

	for (int i = 0; i < N; ++i) {
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define popb pop_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define rep0(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define reprev(i,n) for(ll i=n;i>=0;i--)
#define all(c) c.begin(),c.end()
// #define int long long

const int mod = 1e9+7;

using namespace std;

int gcd(int a, int b){
	if(a==0) return b;
	return gcd(b%a, a);
}

ll power(ll x, ll y, ll m){
	if(y==0) return 1;
	ll p = power(x,y/2,m) % m;
	p = (p*p)%m;
	return (y%2==0) ? p : (x*p)%m;
}

void solve(){

	int n;
	cin >> n;
	vector <int> a(n,0);
	rep0(i,n) cin >> a[i];

	int sum = 0;
	rep0(i,n) sum += a[i];

	ll ans = 0, tmp = 0, var = 0, min = 1e8;
	rep0(i,n){
		ans += a[i];
		tmp = sum - ans;
		var = abs(tmp-ans);
		if(var<min) min = var;
	}

	cout << min;
	
	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (n,m) = {
        let t = read_vec::<i64>();
        (t[0],t[1])
    };
    let ans = if m == 0{
        0
    } else if n > m / 2 {
        m /2
    } else {
       n + (m - n*2) /4
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
ll a[maxn];
ll n;
int main()
{
    ios::sync_with_stdio(false);
    int n ; cin >> n;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    sort(a + 1 , a + 1 + n);
    reverse(a + 1 , a + 1 + n);
    ll ans = 0;
    ll ptr = 1 , times = 1;
    for (int i = 2 ; i <= n ; i++){
        ans += a[ptr];
        times++;
        if (times == 2) times = 0 , ptr++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5220
def main():
    import sys
    input = sys.stdin.readline

    k = int(input())
    a, b = map(int, input().split())
    f = 0
    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            f = 1
            break

    if f == 0:
        print("NG")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9192
#include <iostream>

struct Watchs{
    int hour;
    int minute;
    int second;
};

void HelloWorld(){
    std::cout << "Hello World" << std::endl;
}

int Cubic(int X){
    return X*X*X;
}

int Rectangle(int A, int B){
    return A*B;
}

int Circumference(int A, int B){
    return 2*A + 2*B;
}

Watchs Watch(int secs){
    int h, m, s;
    h = secs / 3600;
    m = secs % 3600 / 60;
    s = secs % 3600 % 60;
    return {h, m, s};
}

int main() {
    // ---------------------------
    // ITP_1_1_A: Hello World
    // HelloWorld();
    // ---------------------------

    // ---------------------------
    // ITP_1_1_B: X Cubic
//    int x;
//    std::cin >> x;
//    std::cout << Cubic(x) << std::endl;
    // ---------------------------

    // ---------------------------
    // ITP_1_1_C: Rectangle
//    int a, b;
//    std::cin >> a >> b;
//    std::cout << Rectangle(a,b) << " " << Circumference(a,b) << std::endl;
    // ---------------------------

    // ---------------------------
    // ITP_1_1_D: Watch
    int secs;
    std::cin >> secs;
    Watchs hms = Watch(secs);
    std::cout << hms.hour << ":" << hms.minute << ":" << hms.second << std::endl;
    // ---------------------------

    // ---------------------------
    // ITP_1_1_B
    // ---------------------------

    // ---------------------------
    // ITP_1_1_B
    // ---------------------------

    return 0;
}


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

struct team {
	char n[2];
	int w = 0, l = 0, t = 0;

	bool operator < (const team & rhs) const {
		return w > rhs.w || (w == rhs.w && l < rhs.l);
	}
};

int main()
{	
	int n;

	cin >> n;

	while (n > 0) {
		team tm[10];

		for (int i = 0; i < n; i++) {
			cin >> tm[i].n;
			for (int j = 0; j < n - 1; j++) {
				int r;
				cin >> r;

				if (r == 0)
					tm[i].w++;
				else if (r == 1)
					tm[i].l++;
				else if (r == 2)
					tm[i].t++;
			}
		}

		sort(tm, tm + n);

		for (int i = 0; i < n; i++)
			cout << tm[i].n << endl;

		cin >> n;
	}
	
	return 0;
}



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

int main(){
	int n,m;
	int s,t;
	int flag=0;
	cin>>n>>m;
	vector<vector<int>> graph(3*n);
	int tu,tv;
	for (int i = 0; i < m; i++) {
		cin>>tu>>tv;
		for (int j = 0; j < 3; j++) {
			graph[(tu-1+j*n)%(3*n)].push_back((tv-1+(j+1)*n)%(3*n));
		}
	}
//	for (int i = 0; i < 3*n; i++) {
//		cout<<i<<" ";
//		for (int j = 0; j < graph[i].size(); j++) {
//			cout<<graph[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	cin>>s>>t;
	int len=0;
	int temp;
	vector<int> reach(3*n,0);
	queue<int> q;
	q.push(s-1);
	while (len<3*n&&q.size()>0&&flag==0) {
		temp=q.size();
		len++;
		for (int i = 0; i < temp; i++) {
			for (int j  = 0; j  < graph[q.front()].size(); j++) {
				if (reach[graph[q.front()][j]]==0) {
					q.push(graph[q.front()][j]);
					reach[graph[q.front()][j]]=1;
					if (graph[q.front()][j]==t-1) {
						flag=1;
					}
				}
			}
			q.pop();
		}
	}
//	cout<<"ok"<<endl;
//	while (len<3*n&&q.begin()!=q.end()&&flag==0) {
//		temp=q.size();
//		len++;
//		for (int i = 0; i < temp; i++) {
//			
//		}
////		for (auto itr = itr1; itr !=itr2; itr++) {
////			for (int i = 0; i < graph[*itr].size(); i++) {
////				q.push_back(graph[*itr][i]);
////				if (graph[*itr][i]==t-1) {
////					flag=1;
////				}
//////				cout<<i<<" "<<flag<<" "<<len<<endl;
////			}
////			q.pop_front();
////		}
//	}
	if(flag==0){
		cout<<-1<<endl;
	}else {
		cout<<len/3<<endl;
	}
}

Measured memory_bytes: 17792
#include<cstdio>
#include<iostream>
using namespace std;
void dfs(int t);
int solve();

int senbei[10][10000];
int keel[10];
int r,c;
int ma;

int main(void){
   while(scanf("%d%d",&r,&c),r+c){
      for(int i = 0;i < r;i++){
         for(int j = 0;j < c;j++){
            scanf("%d",&senbei[i][j]);
         }
      }
      dfs(0);
      printf("%d\n",ma);
   }
   return 0;
}

void dfs(int t){
   if(t == r){
      ma = max(solve(),ma);
      return;
   }
   keel[t] = 1;
   dfs(t+1);
   keel[t] = 0;
   dfs(t+1);
   return;
}

int solve(){
   int ma = 0;
   for(int i = 0;i < r;i++)
      if(keel[i] == 1)
         for(int j = 0;j < c;j++) senbei[i][j] = 1-senbei[i][j];

   for(int i = 0;i < c;i++){
      int a = 0;
      for(int j = 0;j < r;j++){
         a += senbei[j][i];
      }
      ma += max(r-a,a);
   }

   for(int i = 0;i < r;i++)
      if(keel[i] == 1)
         for(int j = 0;j < c;j++) senbei[i][j] = 1-senbei[i][j];

   return ma;
}

Measured memory_bytes: 1572
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>
#include <cmath>

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

const int MAXN = 33;

char maze[MAXN][MAXN];

const int MAXG = 400;

int dst[MAXN][MAXN];
int usd[MAXN][MAXN];

int h, w;

int go(int x, int y){
    if (maze[x][y] == '#')
        return 0;
    for (int i = 0; i < h; ++ i) {
        for (int j = 0; j < w; ++j) {
            dst[i][j] = 1e9;
            usd[i][j] = false;
        }
    }

    dst[x][y] = 0;

    queue<pair<int ,int>> q;

    q.push({x, y});
    usd[x][y] = true;

    while (!q.empty()){
        auto cr = q.front();
        q.pop();

        int cr_x = cr.first;
        int cr_y = cr.second;

        for (int dx = -1; dx <= 1; ++dx){
            for (int dy = -1; dy <= 1; ++dy){
                if (dx * dx + dy * dy == 1){
                    int n_x = cr_x + dx;
                    int n_y = cr_y + dy;

                    if (n_x >= 0 && n_x < h && n_y >= 0 && n_y < w && maze[n_x][n_y] != '#'){

                        dst[n_x][n_y] = min(dst[n_x][n_y], dst[cr_x][cr_y] + 1);
                        if (!usd[n_x][n_y]){
                            usd[n_x][n_y] = true;
                            q.push({n_x, n_y});
                        }

                    }
                }
            }
        }
    }


    int ret = 0;
    for (int i = 0; i < h; ++ i) {
        for (int j = 0; j < w; ++j) {
            if (maze[i][j] != '#') {
                ret = max(ret, dst[i][j]);
            }
        }
    }

    return ret;
}

void solve() {

    cin >> h >> w;


    for (int i = 0; i < h; ++ i) {
        for (int j = 0; j < w; ++j) {
            cin >> maze[i][j];
        }
    }

    int answr = 0;
    for (int i = 0; i < h; ++ i){
        for (int j = 0; j < w; ++ j){
            answr = max(answr, go(i, j));
        }
    }

    cout << answr << "\n";
}


int main() {
    ios_base::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(5);

    solve();
}

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

int main(){
    int A;
    int B;
    string ans;

    cin >> A;
    cin >> B;

    ans = "Yes";

    if ( A == 2 ) ans = "No";
    else if ( B == 2 ) ans = "No";

    cout << ans;



    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE;
ll m;
ll arr[MAXN];
ll suf[MAXN];

bool check(ll x) {
    ll tot = 0;
    for (int i = 1; i <= n; i++) {
        ll need = x - arr[i];
        auto p = lower_bound(arr + 1, arr + n + 1, need) - arr;
        tot += n - p + 1;
    }
    return tot >= m;
}

ll getAns(ll x) {
    ll ans = 0;
    ll num = 0;
    for (int i = n; i >= 1; i--) {
        ll need = x - arr[i];
        auto p = lower_bound(arr + 1, arr + n + 1, need) - arr;
        num += n - p + 1;
        ans += arr[i] * (n - p + 1) + suf[p];
    }
    ans -= (num - m) * x;
    return ans;
}

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    for (int i = n; i >= 1; i--) {
        suf[i] = suf[i + 1] + arr[i];
    }
    ll l = 0, r = arr[n] * 2;
    ll ans = l;
    while (l <= r) {
        ll mid = (l + r) / 2;
        if (check(mid)) {
            ans = max(ans, mid);
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    cout << getAns(ans) << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

int main()
{
    std::vector<int> num{-1, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};

    int x, y;
    std::cin >> x >> y;
    std::cout << (num[x] == num[y] ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define ll long long
using namespace std;

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    ll N,ans=1;
    string S;
    cin >> N;
    vector<ll> A(N+4,0);
    for(ll i=0; i<N; i++){
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(ll i=0; i<N; i++){
        ans *= A[i];
        // cout << ans << endl;
        if(ans <= 0 || ans > 1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS; 
      
   int x;
   cin>>x;
   if(x >= 400 && x<=599)
   {
      cout<< 8;
   }
   else if(x >=600 && x<=799)
   {
    cout<<7 ;
   }
   else if(x>=800 && x <=999)
   {
cout<<6 ;
   }
   else if(x>=1000 && x<=1199)
   {
cout<< 5;
   }
   else if(x >= 1200 && x<= 1399)
   {
cout<< 4;
   }
   else if(x>= 1400 && x<= 1599)
   {
cout<< 3;
   }
   else if(x >= 1600 && x<= 1799)
   {
cout<< 2;
   }
   else if(x >=1800 && x<= 1999)
   {
cout<<1 ;
   }

 
   
   
  
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

int main() {
      ios_base::sync_with_stdio(0);
      cin.tie(nullptr);

      int a, b, c;
      cin >> a >> b >> c;
      swap(a, b);
      swap(a, c);

      cout << a << " " << b << " " << c;

      return 0;
}

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

int main() {
    int k,s,cnt=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int sum=i+j;
            if(s-sum<=k && s-sum>=0)cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 3636
h,w = map(int,input().split())

tmps = 0
ans = 10**18
for i in range(1,h):
	k = (h-i)//2
	t = [i*w, k*w, (h-i-k)*w]
	tmp = max(t)-min(t)
	ans = min(tmp, ans)
	k = w//2
	t = [i*w, (h-i)*k, (h-i)*(w-k)]
	tmp = max(t)-min(t)
	ans = min(tmp, ans)
for i in range(1,w):
	k = (w-i)//2
	t = [i*h, k*h, (w-i-k)*h]
	tmp = max(t)-min(t)
	ans = min(tmp, ans)
	k = h//2
	t = [i*h, (w-i)*k, (w-i)*(h-k)]
	tmp = max(t)-min(t)
	ans = min(tmp, ans)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    vector<long long> p(n),q(n),perm(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    for(int i=0;i<n;i++){
        perm[i]=i+1;
    }
    long long a,b,cnt=0;
	do{
		cnt++;
		if(p==perm) a=cnt;
		if(q==perm) b=cnt;
	}while(next_permutation(perm.begin(),perm.end()));
	cout<<abs(a-b)<<endl;
    return 0;
}


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

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    string ans = "YES";
    rep(i, m)
    {
        int s, t;
        cin >> s >> t;
        a[s]++;
        a[t]++;
    }

    rep(i, n + 1)
    {
        if (a[i] % 2 == 1)
            ans = "NO";
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
n = int(input())
alst = [int(input()) for _ in range(n)]
max_2 = [0, 0]
for a in alst:
  if a > max_2[0]:
    max_2[1] = max_2[0]
    max_2[0] = a
  elif a > max_2[1]:
    max_2[1] = a

for a in alst:
  if a == max_2[0]:
    print(max_2[1])
  else:
    print(max_2[0])

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

int main() {
  int N;
  cin >> N;
  vector<int> cakes(N); 
  for(int i = 0; i < N; i++) {
    int v = 0;
    cin >> v;
    cakes.at(i) = v;
  }
  sort(cakes.begin(), cakes.end());
  int prev = cakes.at(0);
  int level = 1;
  for(int i = 1; i < N; i++) {
    int curr = cakes.at(i);
    if(prev < curr) {
      prev = curr;
      level++;
    }
  }
  cout << level << endl;
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define INF 		2000000007
#define MOD			10e9+7
#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

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

	cout << (X<A ? 0 : 10) << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w;
vector<int> adj[405];
vector<int> dist(405);
vector<int> vis(405);
int m1=INT_MAX;
vector<string> v[21];
 
void dijkstra(int s){
	for(int i=0;i<=400;i++){
	 dist[i]=m1;
	 vis[i]=0;
     }
	dist[s]=0;
	for (int i = 0; i < 401; i++) {
        int v = -1;
        for (int j = 0; j < 401; j++) {
            if (vis[j]==0 && (v == -1 || dist[j] < dist[v]))
                v = j;
        }

        if (dist[v] == m1)
            break;

        vis[v] = 1;
        for (auto edge : adj[v]) {
            
            //int len = edge.second;

            if (dist[v] + 1 < dist[edge]) {
                dist[edge] = dist[v] +1;
                //p[to] = v;
            }
        }
    }
}
			
	
int solve(int s){
	//fill(dist.begin(),dist.end(),0);
	//fill(vis.begin(),vis.end(),0);
	dijkstra(s);
	int m2=-1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(v[i][0][j]!='#' && dist[i*w+j]>m2)
			 m2=dist[i*w+j];
		 }
	}
	  
	return m2;
}
	
int main(){
 
  cin>>h>>w;
 
  for(int i=0;i<h;i++){
	  string s;
	  cin>>s;
	  v[i].push_back(s);
  }
  for(int i=0;i<h;i++){
	  for(int j=0;j<w;j++){
		  if(v[i][0][j]!='#'){
			  if(j+1<w && v[i][0][j+1]=='.'){
				  int v1=(i*w)+j;
				  int v2=(i*w)+j+1;
				  adj[v1].push_back(v2);
				  adj[v2].push_back(v1);
			  }
			  if(j-1>=0 && v[i][0][j-1]=='.'){
				  int v1=(i*w)+j;
				  int v2=(i*w)+j-1;
				  adj[v1].push_back(v2);
				  adj[v2].push_back(v1);
			  }
			  if(i-1>=0 && v[i-1][0][j]=='.'){
				  int v1=(i*w)+j;
				  int v2=((i-1)*w)+j;
				  adj[v1].push_back(v2);
				  adj[v2].push_back(v1);
			  }
			  if(i+1<h && v[i+1][0][j]=='.'){
				  int v1=(i*w)+j;
				  int v2=((i+1)*w)+j;
				  adj[v1].push_back(v2);
				  adj[v2].push_back(v1);
			  }
		  }
	  }
  }
   
  int h1=-1,h2;
  //h2=solve(10);
  for(int i=0;i<h;i++){
	  for(int j=0;j<w;j++){
		  if(v[i][0][j]!='#')
		    h2=solve(i*w+j);
		  //cout<<h<<endl;
		  h1=max(h1,h2);
	  }
  }
  cout<<h1;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
  ll t;
  if (a < b){ t = a; a = b; b = t; }
  while (( t = a % b ) != 0){ a = b; b = t; }
  return b;
}
int main() {
  ios::sync_with_stdio(false);
  ll K;
  cin >> K;
  ll ret = 0;
  for (ll i=1; i<=K; i++) {
    for (ll j=1; j<=K; j++) {
      ll g = gcd(i, j);
      for (ll k=1; k<=K; k++) {
        ret += gcd(g, k);
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 3648
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

//A[i] := SとSのi文字目以降の最長共通接頭辞の長さ
//としたものを返す
//参考:http://snuke.hatenablog.com/entry/2014/12/03/214243
vector<ll> Z_algorithm(const string& S) {
    vector<ll> A(S.size());
    A[0] = S.size();
    ll i = 1, j = 0;
    while (i < S.size()) {
        while (i + j < S.size() && S[j] == S[i + j]) {
            j++;
        }
        A[i] = j;
        if (j == 0) {
            i++;
            continue;
        }
        ll k = 1;
        while (i + k < S.size() && k + A[k] < j) {
            A[i + k] = A[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return A;
}

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

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        vector<ll> Z = Z_algorithm(S.substr(i));
        for (ll j = 0; j < Z.size(); j++) {
            ans = max(ans, min(j, Z[j]));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,ans;
char s[500111];
int pre[500111],suf[500111];
vector<pair<int,int> >v[500111];
int dp[500111];
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)s[i]=getreal();
	for(int i=1;i<=n;i++)pre[i]=s[i]=='1'?pre[i-1]:i;
	suf[n+1]=n+1;
	for(int i=n;i>=1;i--)suf[i]=s[i]=='1'?suf[i+1]:i;
	for(int i=2;i<n;i++)
	{
		if(s[i]=='0'&&s[i-1]=='1'&&s[i+1]=='1')
		{
			v[i+1].PB(MP(pre[i-1],i-1-pre[i-1]));
			if(i-2!=pre[i-1])v[i+1].PB(MP(pre[i-1]+1,i-2-pre[i-1]));
			
			v[suf[i+1]-1].PB(MP(i-2,suf[i+1]-1-i));
			if(i+2!=suf[i+1])v[suf[i+1]-2].PB(MP(i-2,suf[i+1]-2-i));
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
//			cerr<<v[i][j].FF<<"->"<<i<<":"<<v[i][j].SS<<endl;
			dp[i]=max(dp[i],dp[v[i][j].FF]+v[i][j].SS);
		}
		dp[i]=max(dp[i],dp[i-1]);
		mx=max(mx,dp[i]);
	}
	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 23808
#include <cstdlib>
#include <iostream>
#include <unordered_map>
using namespace std;

unordered_map<string, int> converter{
	{"yotta", 24},
	{"zetta", 21},
	{"exa", 18},
	{"peta", 15},
	{"tera", 12},
	{"giga", 9},
	{"mega", 6},
	{"kilo", 3},
	{"hecto", 2},
	{"deca", 1},
	{"deci", -1},
	{"centi", -2},
	{"milli", -3},
	{"micro", -6},
	{"nano", -9},
	{"pico", -12},
	{"femto", -15},
	{"ato", -18},
	{"zepto", -21},
	{"yocto", -24}};

inline string next_string() {
	string res;
	cin >> res;
	return res;
}

void solve() {
	string value = next_string(), prefix = next_string(), unit;
	int exp;
	if(converter.count(prefix)) {
		exp = converter[prefix];
		unit = next_string();
	}
	else {
		exp = 0;
		unit = prefix;
	}

	if(value[0] == '0') {
		for(unsigned i = 2; i < value.size(); ++i) {
			if('1' <= value[i] && value[i] <= '9') {
				exp -= i - 1;
				value = value[i] + string(1, '.') + value.substr(i + 1);
			}
		}
	}
	else {
		if(value.find('.') == string::npos) value += '.';
		for(unsigned i = 0; i < value.size(); ++i) {
			if(value[i] == '.') {
				exp += i - 1;
				value = value[0] + string(1, '.') + value.substr(1, i - 1) + value.substr(i + 1);
			}
		}
	}

	if(value.back() == '.') value = value.substr(0, value.size() - 1);
	cout << value << " * 10^" << exp << " " << unit << endl;
}

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

	int t;
	cin >> t;
	while(t--) solve();

	return EXIT_SUCCESS;
}

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

using namespace std;
using ll = long long;

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

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

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

    if (A + B < 24) { cout<< A+B << endl; }
    else { cout << A + B - 24 << endl; }
}

Measured memory_bytes: 256
coin500 = int(input())
coin100 = int(input())
coin50 = int(input())
x = int(input())

ans = 0
for c1 in range(coin500 + 1):
    for c2 in range(coin100 + 1):
        for c3 in range(coin50 + 1):
            if 500 * c1 + 100 * c2 + 50 * c3 == x:
                ans += 1

print(ans)


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  vi a(3), b(3);
  for (ll i = 0; i < 3; i++) {
    cin >> a[i] >> b[i];
    a[i] -= 1;
    b[i] -= 1;
  }

  vi v(4);
  for (ll i = 0; i < 3; i++) {
    v[a[i]] += 1;
    v[b[i]] += 1;
  }

  for (ll i = 0; i < 4; i++) {
    if (v[i] == 3) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}

Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
DP=[0]*N
DP[0]=0
DP[1]=abs(h[1]-h[0])+DP[0]
i=2
while i<N:
  DP[i]=min(abs(h[i]-h[i-1])+DP[i-1],abs(h[i]-h[i-2])+DP[i-2])
  i+=1
print(DP[-1])

Measured memory_bytes: 13980
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
now = list(mapint())
from itertools import accumulate
iteration = min(N.bit_length()*4, K)
for k in range(iteration):
    nx = [0]*N
    for i, a in enumerate(now):
        nx[max(0, i-a)] += 1
        if i+a+1<N:
            nx[i+a+1] -= 1
    nx = list(accumulate(nx))
    now = nx[:]
print(*now)

Measured memory_bytes: 182908
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    string S;
    cin >> S;
    int K = inputValue();
    int L = S.length();
    int st = -1;
    ll ct = 0;
    int begin = 1;
    REP(i, L){
        if(st == -1 && S[i] == S[(i+1)%L]){
            st = i;
        }
        if(st > -1 && S[i] != S[(i+1)%L]){
            ct += (i - st + 1) / 2;
            if(st == 0)
                begin = i+1;
            st = -1;
        }
    }
    if(st > -1){
        if(begin % 2 == 0){
            ct += (L - st) / 2;
        }else{
            ct += (L - st + 1) / 2;
        }
    }
    ll ans = ct * K;
    if(st > -1 && begin % 2 == 1 && (L - st + 1) % 2 == 0){
        ans--;
    }
    if(st == 0){
      ans = ((ll)L * K) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define MOD 1000000007
typedef long long ll;
using namespace std;
int main()
{
	ll N, K, sum = 0; cin >> N >> K;
  	for (ll i = K; i <= N + 1; i++) {
    	ll min, max;
      	min = i * (i - 1) / 2;
      	max = N * (N + 1) / 2 - (N - i) * (N - i + 1) / 2;
      	sum += max - min + 1;
    }
  	cout << sum % MOD << endl;
}

Measured memory_bytes: 3632
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, a[MAXN][MAXN], b[MAXN][MAXN];
bool dp[MAXN][MAXN][30010];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) FOR(j,1,m) cin >> a[i][j];
    FOR(i,1,n) FOR(j,1,m) cin >> b[i][j];
    dp[1][1][15000 + a[1][1] - b[1][1]] = true;
    dp[1][1][15000 + b[1][1] - a[1][1]] = true;
    FOR(i,1,n)
        FOR(j,1,m) {
            if (i == n && j == m) continue;
            FOR(k,0,30000) {
                if (dp[i][j][k]) {
                    if (i+1 <= n) {
                        int p = abs(a[i+1][j] - b[i+1][j]);
                        if (k + p <= 30000) dp[i+1][j][k+p] = true;
                        if (k - p >= 0) dp[i+1][j][k-p] = true;
                    }
                    if (j+1 <= m) {
                        int p = abs(a[i][j+1] - b[i][j+1]);
                        if (k + p <= 30000) dp[i][j+1][k+p] = true;
                        if (k - p >= 0) dp[i][j+1][k-p] = true;
                    }
                }
            }
        }
    int res = 1000000000;
    FOR(i,0,30000)
        if (dp[n][m][i]) res = min(res, abs(15000-i));
    cout << res;
    return 0;
}


Measured memory_bytes: 260480
#include<stdio.h>
int main(void) {
	int n;
	int p[21];
	int c = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&p[i]);
	}
	for (int i = 0; i < n-2; i++) {
			if ((p[i + 1] > p[i + 2] && p[i + 1] < p[i]) || (p[i + 1] > p[i] && p[i + 1] < p[i + 2])) {
				c++;
			}
		}
	printf("%d\n", c);
	return 0;
}



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

class UnionFind {
public:
    vector<int> par;  // 各ノードの親
    vector<int> rank;  // 各ノードの深さ
    int sz;  // 独立した集合の個数

    // コンストラクタ
    UnionFind(int n) {
        for (int i = 0; i < n; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
        sz = n;
    }

    // 木の根を求める
    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 (rank[x] < rank[y]) par[x] = y;
        else if (rank[x] > rank[y]) par[y] = x;
        else {
            par[y] = x;
            ++rank[x];
        }
        --sz;
    }

    // x と y が同じ木に属するかの判定
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }

    // 独立した集合の個数
    int size() {
        return sz;
    }
};

class edge {
public:
    int from, to;
    edge(int f, int t) {
        from = f;  to = t;
    }
};

int main() {
    int N, M;  cin >> N >> M;
    vector<edge> G;
    for (int i = 0; i < M; ++i) {
        int a, b;  cin >> a >> b;
        G.push_back(edge(a - 1, b - 1));
    }

    // 各辺に対して取り除く場合を考える
    int ans = 0;
    for (int i = 0; i < M; ++i) {
        UnionFind uf(N);
        for (int j = 0; j < M; ++j) {
            if (j != i) {
                edge e = G[j];
                uf.unite(e.from, e.to);
            }
        }
        bool connected = true;
        for (int j = 0; j < N - 1; ++j) {
            if (!uf.is_same(j, j + 1)) {
                connected = false;
            }
        }
        if (!connected) ++ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long int

int main()
{
	int d,n,i;
	scanf("%i %i",&d,&n);
	if(n==100) n++;
	while(d--) n*=100;
	printf("%i\n",n);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
        int d,n;
        int i,t = 1;

        scanf("%d %d",&d,&n);
        for(i = 0;i < d; ++i)   t *= 100;
        if(n != 100){
			printf("%d\n",t * n);
		}
        else{
			printf("%d\n",t * (n + 1));
		}
		return 0;
}

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

int main(){
  int N;
  cin >> N;
  map<string,int> mp;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  
  long long ans = 0;
  
  for(auto &i : mp){
    int a = i.second;
    ans += (long long)a*(a-1)/2;
  }

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


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

VVI E(202);
VI col(202, -1);
bool ng = 0;
void dfs(int cu, int c, int pa = -1) {
    // v[cu]=0;
    for (int to : E[cu]) {
        if (to != pa) {
            //
            if (col[to] >= 0 && col[to] == c) {
                ng = 1;
                return;
            }
            if (col[to] == -1) {
                col[to] = 1 - c;
                dfs(to, 1 - c, cu);
            }
            //
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    VVI d(n, VI(n, INF));
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            char r;
            cin >> r;
            if (r == '1') {
                d[i][j] = 1;
                E[i].pb(j);
                E[j].pb(i);
            }
        }
    }
    dfs(0, 0);
    if (ng)
        cout << -1 << endl;
    else {
        for (int k = 0; k < n; k++) {
            for (i = 0; i < n; i++) {
                for (j = 0; j < n; j++) {
                    chmin(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        ll m = -1;
        for (i = 0; i < n; i++) {
            for (j = i+1; j < n; j++) {
                if (d[i][j] != INF) chmax(m, d[i][j]);
            }
        }
        cout << 1 + m << endl;
    }
}

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

int main(){
  string S;
  int sum = 0;
  cin >> S;
  for(int i = 0; i < 3; i++){
    if(S[i] == 'o') sum++;
  }
  int ans = 700 + 100 * sum;
  cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int x[3];
    cin>>x[0]>>x[1]>>x[2];
    sort(x,x+3);
    cout<<x[0]+x[1]<<endl;
}


Measured memory_bytes: 256
read N
s=$(seq $N | paste -s -d+ - | bc)
s3=$(seq 3 3 $N | paste -s -d+ - | bc)
s5=$(seq 5 5 $N | paste -s -d+ - | bc)
s15=$(seq 15 15 $N | paste -s -d+ - | bc)
echo $((s-s3-s5+s15))

Measured memory_bytes: 18808
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}
int n;
int arr[1010], R[1010], T[10100];
int s = 10000;

int solvisitede()
{
    int ans = 0;
    bool visited[10100];
    int B[1010];

    for (int i = 0; i < n; ++i)
        visited[i] = false;
    for (int i = 0; i < n; ++i)
    {
        B[i] = arr[i];
    }
    sort(B, B + n);

    for (int i = 0; i < n; ++i)
        T[B[i]] = i;

    for (int i = 0; i < n; ++i)
    {
        if (visited[i])
            continue;
        int cur = i;
        int S = 0;
        int m = 10000;
        int an = 0;
        while (1)
        {
            visited[cur] = true;
            an++;
            int v = arr[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (visited[cur])
                break;
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    return ans;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        s = min(s, arr[i]);
    }

    int ans = solvisitede();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3240
#include <stdio.h>

int cnt=1;
int oya[500010];
int ko[2][500010];
int val[500010];

int f(int v,int mode){
    if(mode==0)printf(" %d",val[v]);
    if(ko[0][v])f(ko[0][v],mode);
    if(mode==1)printf(" %d",val[v]);
    if(ko[1][v])f(ko[1][v],mode);
    if(mode==2)printf(" %d",val[v]);
}
void push(int v,int va){
	//初回
	if(cnt==1){
		val[cnt]=va;
		cnt++;
		return;
	}
	if(ko[val[v]<va][v])push(ko[val[v]<va][v],va);
	else{
		ko[val[v]<va][v]=cnt;
		oya[cnt]=v;
		val[cnt]=va;
		cnt++;
	}
}

int find(int v,int va){
	if(val[v]==va)return 1;
	if(ko[val[v]<va][v])return find(ko[val[v]<va][v],va);
	return 0;
}

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		char s[10];
		scanf("%s",s);
		if(s[0]=='p'){
			f(1,1);
			puts("");
			f(1,0);
			puts("");
		}else if(s[0]=='i'){
			int t;
			scanf("%d",&t);
			push(1,t);
		}else{
			int t;
			scanf("%d",&t);
			puts(find(1,t)?"yes":"no");
		}
	}
}


Measured memory_bytes: 7972