akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define siz 100005

typedef pair< pair<int,int> , pair<int,int> > ppp;

ll dp[105][siz],wight[105],value[105];

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

  // freopen("street.in","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,w;
    scanf("%d%d",&n,&w);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&wight[i],&value[i]);

    for(int i=1;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(wight[i]>j) dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wight[i]]+value[i]);
            }
        }
    }
    printf("%lld",dp[n][w]);

return 0;

}




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

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

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

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

int main(){
    int a;
    int b;
    int c;
    int cnt=0;
    int n;
    cin >> a;
    cin >> b;
    cin >> c;
    if(a==b){
        cnt++;
    }
    if(a==c){
        cnt++;
    }
    if(a!=b || a!=c){
        if(b==c){
            cnt++;
    }
    }

    c= 3-cnt;

    cout << c;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define all(v) v.begin(), v.end()
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int cnt=0;
int main(){
    fast_io
    
    string s;
    int q;
    cin>>s>>q;
    string front="";
    rep(i,q){
        int ti;
        cin>>ti;
        if(ti==1) {
            cnt++;
            cnt%=2;
        }
        else if(ti==2){
            int fi;
            char ci;
            cin>>fi>>ci;
            if(fi==1){
                if(cnt%2==0){
                    front+=ci;
                }else{
                    s+=ci;
                }
            }else if(fi==2){
                if(cnt%2==0) s+=ci;
                else{
                    front+=ci;
                }
            }
        }
    }
    reverse(all(front));
    s=front+s;
    if(cnt%2!=0) reverse(all(s)); 
    cout<<s<<endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

Measured memory_bytes: 3620
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0
S = ""
K = 0


def set_inputs():
    global N, S, K
    N = get_int()
    S = get_str()
    K = get_int()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    ans = []
    C = S[K - 1]
    for c in S:
        if c != C:
            ans.append("*")
        else:
            ans.append(c)
    print("".join(ans))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5652
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k)
{
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL)
	{
		y = x;
		if(z->key < x->key){
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL){
		root = z;
	} else {
		if(z->key < y->key){
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u)
{
	if(u == NIL) return;
		inorder(u->left);
		printf(" %d",u->key);
		inorder(u->right);
}

void preorder(Node *u)
{
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main()
{
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i = 0; i < n; i++)
	{
		cin >>com;
		if(com == "insert")
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(com == "print")
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 26652
<?php
    fscanf(STDIN, '%d', $x);
    $base = 100;
    $year = 1;
    while(true){
        $base = floor($base * 1.01);
        if($base >= $x){
            break;
        }
        ++$year;
    }
    echo $year.PHP_EOL;
?>

Measured memory_bytes: 16164
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
	#include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
	#define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
	#define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
	#define debug(x...)
	#define light_debug(x) 
#endif

#define int ll

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int MOD = 1000000007;

int modpow(int a, int n){
	while(n < 0) n += MOD - 1;
	ll v = 1;
	for(int i = 31; i >= 0; i--){
		(v *= v) %= MOD;
		if(n & (1 << i))
			(v *= a) %= MOD;
	}
	return (int)v;
}

ll fact[500005], ifact[500005];

void init(){
	fact[0] = ifact[0] = 1;
	rep1(i, 500000)
		fact[i] = fact[i - 1] * i % MOD, ifact[i] = ifact[i - 1] * modpow(i, -1) % MOD;
}

inline int nCr(int n, int r){
	return fact[n] * ifact[n - r] % MOD * ifact[r] % MOD;
}

inline int nPr(int n, int r){
	return fact[n] * ifact[n - r] % MOD;
}


signed main(){

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

	#ifdef DEBUG
		freopen("debug", "w", stderr);
	#endif

	init();
	ll N, M;
	cin >> N >> M;
	
	ll ans = nPr(M, N);
	rep1(i, N){
		ll k = nCr(N, i) * nPr(M - i, N - i) % MOD;
		if(i & 1)
			(ans += MOD - k) %= MOD;
		else
			(ans += k) %= MOD;
	}

	debug(ans);
	(ans *= nPr(M, N)) %= MOD;

	cout << ans << '\n';

	#ifdef DEBUG
		dbg::dout << "\nExecution time: " << clock() << "ms\n";
	#endif

	return 0;
}
	


Measured memory_bytes: 11464
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

double r;

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> r;
	printf("%.11f\n", 2 * r * 3.14159265358979);
	
	return 0;
}

Measured memory_bytes: 3788
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, i, A[100001], sum=0;

    cin >> N;

    A[0] = 0;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    sum += abs(A[1]);
    for(i=2; i<=N; i++){
        sum += abs(A[i-1]-A[i]);
    }
    sum += abs(A[N]);

    for(i=1; i<=N; i++){
        if(i<=N-1){
            cout << sum-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]) << endl;
        }
        else{
            cout << sum-abs(A[N-1]-A[N])-abs(A[N])+abs(A[N-1]) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
struct aa {
	int id;
	int score;
	int num;
	aa() {
		id = 0;
		score = 0;
		num = 0;
	};
};
bool operator<(const aa&l, const aa&r) {
	return l.num == r.num ? l.score == r.score ? l.id<r.id : l.score<r.score : l.num >r.num;
}
int main() {
	while (1) {
		int T, P, R; cin >> T >> P >> R;
		if (!T)break;
		int miss[100][100];
		memset(miss, 0, sizeof(miss));
		int score[100][100];
		memset(score, 0, sizeof(score));
		for (int i = 0; i < R; ++i) {
			int a, b, c; cin >> a >> b >> c;
			a--; b--;
			string st; cin >> st;
			if (st == "WRONG") {
				miss[a][b]++;
			}
			else {
				score[a][b] += miss[a][b] * 1200 + c;
			}
		}
		vector<aa>scores(T);
		for (int i = 0; i < T; ++i) {
			scores[i].id = i;
			for (int j = 0; j < P; ++j) {
				scores[i].score += score[i][j];
				if (score[i][j])scores[i].num++;
			}
		}
		sort(scores.begin(), scores.end());
		for (auto s : scores) {
			cout << s.id+1 << " " << s.num << " " << s.score << endl;
		}
	}
	return 0;
}

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

int main(){
	ll N,K,Q;
	cin >> N >> K >> Q;
	
	vector<ll> A(Q);
	rep(i,Q){
		cin >> A[i];
		A[i]--;
	}
	
	vector<ll> point(N);
	point.assign(N, K-Q);
	
	rep(i,Q){
		point[A[i]]++;
	}
	
	rep(i,N){
		if(point[i] > 0){
			cout << "Yes" << endl;
		} else{
			cout << "No" << endl;
		}
	}
	
    return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll n,m;
    cin>>n>>m;
    V h(n);
    rep(i,n)cin>>h[i];
    vector<bool> good(n,true);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        if(h[a-1]>h[b-1]){
            good[b-1]=false;
        }else if(h[a-1]<h[b-1]){
            good[a-1]=false;
        }else{
            good[a-1]=false;
            good[b-1]=false;
        }
    }
    ll ans=0;
    rep(i,n)if(good[i])ans++;
    cout<<ans<<endl;
}


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

int main() {
	string s;
	cin >> s;
	int ans = 0, i = 0, j = s.size()-1;
	while(i < j) {
		if(s[i] != s[j]) ans++;
		
		i++;j--;
	}
	cout << ans << endl;
	return 0;
}

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

int x[51],y[51],n;

int ans;
int p,q;

set<pair<int,int>>s;
map<pair<int,int>,int>vis;

int solve(){
	int res=0;
	vis.clear();
	pair<int,int> v;
	for (int i=1;i<=n;++i){
		v=mp(x[i]-p,y[i]-q);
		vis[v]++;
	}
	for (int i=1;i<=n;++i){
		v=mp(x[i],y[i]);
		if (vis[v]) vis[v]=0;
	}
	for (int i=1;i<=n;++i){
		v=mp(x[i]-p,y[i]-q);
		res+=vis[v];
	}
	return res;
}

int main(){
	cin>>n;
	ans=n;
	for (int i=1;i<=n;++i)
	cin>>x[i]>>y[i],
	s.insert(mp(x[i],y[i]));
	int ans=s.size();
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j){
			p=x[i]-x[j],q=y[i]-y[j];
			if ((!p)&&(!q)) continue;
			ans=min(ans,solve());
		}

	cout<<ans<<endl;	
}

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

int a[3][3];
int x[3];
int y[3];

int main()
{
    for (int i = 0; i < 3; i++)
    {
        int c_i1, c_i2, c_i3;
        cin >> c_i1 >> c_i2 >> c_i3;

        a[i][0] = c_i1;
        a[i][1] = c_i2;
        a[i][2] = c_i3;
    }

    x[0] = 0;
    for (int i = 0; i < 3; i++)
    {
        y[i] = a[0][i] - x[0];
    }
    for (int i = 0; i < 3; i++)
    {
        x[i] = a[i][0] - y[0];
    }

    bool good = true;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (x[i] + y[j] != a[i][j])
            {
                good = false;
            }
        }
    }

    if (good)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using int64 = long long;
using vint = vector<int>;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, init, n) for (int i = (init); i < (n); ++i)
#define RepLong(i, n) for (int64 i = 0; i < (n); ++i)
#define InitRepLong(i, init, n) for (int64 i = (init); i < (n); ++i)
#define RepItr(it, itBegin, itEnd) for (auto it = (itBegin); it != (itEnd); ++it)

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

	if (n % 2 == 1)
	{
		cout << "No" << endl;
		return 0;
	}
	int m = n / 2;
	Rep(i, m)
	{
		if (s[i] != s[m + i])
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

typedef long long ll;
 
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> G(n, vector<bool>(n, false));
  int a[m], b[m], ans=0;
  for(int i=0; i<m; i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]][b[i]] = true;
    G[b[i]][a[i]] = true;
  }
  
  bool visit[n];
  for(int i=0; i<m; i++){
    G[a[i]][b[i]] = false;
    G[b[i]][a[i]] = false;
    
    for(int j=0; j<n; j++){
      visit[j] = false;
    }
    
    queue<int> que;
    int now;
    que.push(0);
    while(!que.empty()){
      now = que.front();
      que.pop();
      visit[now] = true;
      for(int j=0; j<n; j++){
        if(G[now][j]&&!visit[j]){
          que.push(j);
        }
      }
    }
    bool ok = true;
    for(int j=0; j<n; j++){
      ok &= visit[j];
    }
    if(!ok){
      ans++;
    }
    
    G[a[i]][b[i]] = true;
    G[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	final static long MOD = 1000000007L;
	public static void main(String[] args) {
		Reader in = new Reader();
		int n = in.nextInt();
		int[] a = in.na(n);
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 0; i<n; i++) {
			for(int j = 1; j<3; j++) {
				if(i+j<n) 
					dp[i+j] = Math.min(dp[i+j], dp[i]+Math.abs(a[j+i]-a[i]));
			}
		}
		System.out.println(dp[n-1]);
	}
	static class Reader {
		static BufferedReader br;
		static StringTokenizer st;
		private int charIdx = 0;
		private String s;

		public Reader() {
			this.br = new BufferedReader(new InputStreamReader(System.in));
		}

		public int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public char nextChar() {
			if (s == null || charIdx >= s.length()) {
				if (st == null || !st.hasMoreTokens())
					try {
						readLine();
					} catch (Exception e) {
					}
				s = st.nextToken();
				charIdx = 0;
			}
			return s.charAt(charIdx++);
		}

		public long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[] nca() {
			return next().toCharArray();
		}

		public String[] nS(int n) {
			String[] a = new String[n];
			for (int i = 0; i < n; i++)
				a[i] = next();
			return a;
		}

		public int nextInt() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Integer.parseInt(st.nextToken());
		}

		public double nextDouble() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Double.parseDouble(st.nextToken());
		}

		public Long nextLong() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Long.parseLong(st.nextToken());
		}

		public String next() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return st.nextToken();
		}

		public static void readLine() {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
			}
		}
	}
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int64 N, D, A;
  cin >> N >> D >> A;
  vector< pair< int64, int64 > > uku;
  for(int i = 0; i < N; i++) {
    int64 x, h;
    cin >> x >> h;
    uku.emplace_back(x, h);
  }
  sort(begin(uku), end(uku));
  vector< int64 > add(N + 1);
  int64 diff = 0, ret = 0;
  int ptr = 0;
  for(int i = 0; i < N; i++) {
    while(ptr < N && uku[i].first + D + D >= uku[ptr].first) {
      ++ptr;
    }
    diff += add[i];
    int64 need = max(0LL, (uku[i].second - diff + A - 1) / A);
    diff += need * A;
    add[ptr] -= need * A;
    ret += need;
  }
  cout << ret << endl;
}


Measured memory_bytes: 6512
#include <iostream>

int main() {
    int N, Q, s, e;
    std::string S;
    std::cin >> N >> Q;
    std::cin >> S;
    int check[100000] = {};
    
    for(int i=0; i<N-1; ++i) {
        if (S[i]=='A' && S[i+1]=='C') {
            check[i+1] = check[i]+1;
        } else {
            check[i+1] = check[i];
        }
    }
    
    for (int i=0; i<Q; ++i) {
        std::cin >> s >> e;
        std::cout << check[e-1]-check[s-1] << std::endl;
    }
}

Measured memory_bytes: 1408
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x,i=1;
		while(true){
			x=sc.nextInt();
			if(x==0)break;
			System.out.println("Case "+ i +": "+ x);
			i++;
		}
	}
}



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

int main(){

	int n, x;

	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0) break;
		int count = 0;
		for(int i = 1; i < n - 1; i++){
			for(int j = i + 1; j < n; j++){
				for(int k = j + 1; k < n + 1; k++){
					if(i + j + k == x) count++;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
n = gets().to_i()
(1..n).map do 
    gets().split(' ').map{|x| x.to_i()}
end.reduce do |prev, curr|
    ratio = [0, 1].map{|i| Rational(prev[i], curr[i]).ceil()}.max()
    curr.map{|votes| votes * ratio}
end.tap do |result|
    puts(result[0] + result[1])
end

Measured memory_bytes: 2044
#include <cstdio>
int main(){
	int a,b;
	char op;
	while(scanf("%d %c %d",&a,&op,&b)){
		if(op=='?')break;

		if(op=='+')printf("%d\n",a+b);
	
		if(op=='-')printf("%d\n",a-b);

		if(op=='*')printf("%d\n",a*b);
	
		if(op=='/')printf("%d\n",a/b);

	}
return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  for(int i=0;i<t.size();i++) cout << s.at(i) << t.at(i);
  if(t.size()<s.size()) cout << s.at(s.size()-1);
  cout << endl;
}

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

int main()
{
    int a[1000],i,n;
    cin >> n;
    for(i=0 ; i<n ; i++)
    {
        cin >> a[i];
    }
    sort(a+0,a+n);
    int sum=0;
    for(i=0 ; i+1<n ; i++)
    {
        sum+=abs(a[i+1]- a[i]);
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#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 range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int mod = 1e9 + 7;

int N;
int counter[100010];

signed main()
{
	cin >> N;

	vi A(N);

	rep(i, N) {
		cin >> A[i];
	}

	sort(all(A));

	rep(i, N) {
		counter[A[i]]++;
	}

	int one = 0, two = 0;
	range(i, 1, 100001) {
		if (counter[i] > 0) {
			counter[i] = 2 - counter[i] % 2;
			if (counter[i] == 1) one++;
			else two++;
		}
	}

	one += two / 2 * 2;

	cout << one << endl;
}



Measured memory_bytes: 1792
///.... In the name of ALLAH .....///

  #include<bits/stdc++.h>

   using namespace std;

/// type define part

  typedef long long ll ;
  typedef double dl;

/// define Part

    #define fast()          ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define PB              push_back
    #define F               first
    #define S               second
    #define MP              make_pair
    #define all(a)          (a).begin(),(a).end()
    #define rall(a)         (a).rbegin(),(a).rend()
    #define sz(x)           (int)x.size()
    #define endl             '\n'
    #define mem(a,b)         memset(a, b, sizeof(a) )
    #define MOD              1000000007
    #define fraction(a)      cout<<fixed; cout<<setprecision(a);
/// value
   const double PI = acos(-1);
   const double eps = 1e-9;
   const int inf = 2000000000;
   const ll infLL = 9000000000000000000;

// debugger

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

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}

 int main(){

  fast();

  bool x;
  cin >> x;

  cout<<!x<<endl;



  return 0;
 }



Measured memory_bytes: 3628
#include <queue>
#include <iostream>

using namespace std;

int main()
{
	int N;
	queue<int> tmpq;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int A_i;
		cin >> A_i;
		tmpq.push(A_i);
	}
	while ((int)tmpq.size() > 1) {
		int a = tmpq.front();
		tmpq.pop();
		int b = tmpq.front();
		tmpq.pop();
		if (a < b) {
			int ws = a;
			a = b;
			b = ws;
		}
		int r;
		while ((r = a % b)) {
			a = b;
			b = r;
		}
		tmpq.push(b);
	}
	cout << tmpq.front() << endl;
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

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

	int ans = 0;
	REP(i, s.size()) {
		if (s[i] == '1') ans++;
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        for (int i = 0; i < n; i++)
        {
            if (b[i] > i + 1)
            {
                Console.WriteLine(-1);
                break;
            }
            if (i == n - 1)
            {
                var ans = new List<int>();
                for (int j = 0; j < n; j++)
                {
                    int skip = j - b[j] + 1;
                    ans.Insert(ans.Count() - skip, b[j]);
                }
                foreach (var c in ans) Console.WriteLine(c);
            }
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  n=abs(n);
  int ans=360/n;
  int k=1;
  while(n*ans!=360*k)
  {
    k++;
    ans=(360*k)/n;
  }
 
  cout<<ans;
}


Measured memory_bytes: 3636
def find_atob(str, a, b)
  str_atob = str[a..b]
  return str_atob
end

def reverse_atob(str, str_atob)
  str.gsub!(str_atob, str_atob.reverse)
  return str
end

def replace_atob(str, str_atob, p, a, b)
  str[a..b] = p
  return str
end

def execute_orders(str, q, order_array)
  for i in 0..(q-1)
    str_atob = find_atob(str, order_array[i][1].to_i, order_array[i][2].to_i)
    if order_array[i][0] == "replace"
      replace_atob(str, str_atob, order_array[i][3], order_array[i][1].to_i, order_array[i][2].to_i)
    elsif order_array[i][0] == "reverse"
      reverse_atob(str, str_atob)
    elsif order_array[i][0] == "print"
      puts str_atob
    else
      puts "error"
    end
  end
end

str = gets.chomp
q = gets.chomp.to_i
order_array = []
for i in 0..(q-1)
  order = gets.chomp.split
  order_array.push(order)
end

execute_orders(str, q, order_array)

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

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& (a) : (x))
#define all(x) (x).begin (), (x).end ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair<int, int> pii;
#define f first
#define s second
#define mkp(x) make_pair ((x))

typedef vector<int> vi;
#define pb(x) push_back ((x))

#define DEBUG 0
#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

#define ddprintfv(v) if (DEBUG) { trav (a, v) cout << a << " "; cout << "\n"; }

#define EXIT ddprintf ("Time elapsed %lf\n", 1.0 * clock() / CLOCKS_PER_SEC); exit (0)

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x3f3f3f3f3f3f3f3f;
const int  INFi  =  0x3f3f3f3f;
const ll   MAXN  =  1e+6+7;

int main ()
{
    int i, j, t;
    int N, K;
    scanf ("%d %d", &N, &K);
    vector <ll> H (N + 2);
    vector <vector <ll> > dp (N + 2, vector <ll> (N + 2, INF));
    dp[0][0] = 0;
    for (i = 0; i != N; i++)
        scanf ("%lld", &H[i + 1]);
    for (i = 0; i < N + 1; i++)
        for (j = 0; j < min (i + 1, K + 1); j++)
            for (t = 0; t < j + 1; t++)
                dp[i + 1][j] = min(dp[i + 1][j], dp[i - t][j - t] + max(0LL, H[i + 1] - H[i - t]));
    printf ("%lld\n", dp[N + 1][K]);

    EXIT;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
int main(){
  int L,R,d; cin >> L >>R>>d;
  int ans = 0;
  for(int i=L;i<=R;++i){
    if(i%d==0){++ans;}
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;


int main(){
    int H, W,h , w;
    cin >>H>>W>> h >> w;
    cout << (H-h)*(W-w) << endl;
    



    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
int main()
{
	int n,first = 1;
	scanf("%d",&n);
	int t,x,y,t0,x0,y0,sum;
	t0 = x0 = y0 = 0;
	while(n--){
		sum = 0;
		scanf("%d%d%d",&t,&x,&y);
		sum = fabs(x-x0) + fabs(y-y0);
		sum = (t-t0)-sum;
		if(sum <0||sum%2)  first = 0;
		t0 = t;
		x0 = x;
		y0 = y;
	}
	if(first)  printf("Yes");
	else printf("No");
	return 0;
 } 

Measured memory_bytes: 128
N, K, L = [int(_) for _ in input().split()]


def find(a, x):
    if a[x] != x:
        a[x] = find(a, a[x])
    return a[x]


def unite(a, x, y):
    x = find(a, x)
    y = find(a, y)
    if x != y:
        a[x] = max(x, y)
        a[y] = a[x]


a_road = [i for i in range(N)]
for _ in range(K):
    p, q = [int(_) - 1 for _ in input().split()]
    unite(a_road, p, q)
a_railway = [i for i in range(N)]
for _ in range(L):
    r, s = [int(_) - 1 for _ in input().split()]
    unite(a_railway, r, s)
memo = {}
for i in range(N):
    memo[find(a_road, i), find(a_railway, i)] = memo.get(
        (find(a_road, i), find(a_railway, i)), 0) + 1

print(' '.join(str(memo[find(a_road, i), find(a_railway, i)])
               for i in range(N)))


Measured memory_bytes: 55052
#include <bits/stdc++.h>
using namespace std;
#define N 210000
#define mod 1000000007
#define ll long long
int n,X,Y,cnt;
int c[N],w[N],a[N],pos[N],num[N],jc[N],njc[N];
vector<int>v1[N],v2[N];
int cmp(int x,int y){return v1[x][0]<v1[y][0];}
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(ll)ret*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}
	return ret;
}
void init()
{
	jc[0]=njc[0]=1;
	for(int i=1;i<=n;i++)jc[i]=(ll)jc[i-1]*i%mod;
	njc[n]=qpow(jc[n],mod-2);
	for(int i=n-1;i>=1;i--)njc[i]=(ll)njc[i+1]*(i+1)%mod;
}
int C(int x,int y){return (ll)jc[x]*njc[y]%mod*njc[x-y]%mod;}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d%d%d",&n,&X,&Y);
	init();
	for(int i=1;i<=n;i++)
		scanf("%d%d",&c[i],&w[i]),a[++cnt]=c[i];
	sort(a+1,a+1+cnt);
	cnt=unique(a+1,a+1+cnt)-a-1;
	for(int i=1;i<=n;i++)
	{
		c[i]=lower_bound(a+1,a+1+cnt,c[i])-a;
		v1[c[i]].push_back(w[i]);
	}
	for(int i=1;i<=cnt;i++)
	{
		sort(v1[i].begin(),v1[i].end());
		pos[i]=i;
	}
	sort(pos+1,pos+1+cnt,cmp);
	for(int i=1;i<=cnt;i++)
		v2[i]=v1[pos[i]];
	num[1]=upper_bound(v2[1].begin(),v2[1].end(),X-v2[1][0])-v2[1].begin();
	if(cnt>1)num[1]=max(num[1],
	(int)(upper_bound(v2[1].begin(),v2[1].end(),Y-v2[2][0])-v2[1].begin()));

	for(int i=2;i<=cnt;i++)
	{
		num[i]=upper_bound(v2[i].begin(),v2[i].end(),X-v2[i][0])-v2[i].begin();
		num[i]=max(num[i],
		(int)(upper_bound(v2[i].begin(),v2[i].end(),Y-v2[1][0])-v2[i].begin()));
	}
	int sum=num[1],ans=1;
	for(int i=2;i<=cnt;i++)
	{
		if(v2[i][0]+v2[1][0]>Y)break;
		ans=(ll)ans*C(sum+num[i],sum)%mod;
		sum+=num[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 24448
import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  l[i].sort()

ans=[]
l.sort()
B1=[];R1=[]
for i in range(n):
  B1.append(l[i][0])
  R1.append(l[i][1])
ans.append((max(B1)-min(B1))*(max(R1)-min(R1)))

Bleft=[]
Bright=[]
Rleft=[]
Rright=[]

M=B1[0];m=B1[0]
Bleft.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bleft.append([m,M])

B1.reverse()
M=B1[0];m=B1[0]
Bright.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bright.append([m,M])

M=R1[0];m=R1[0]
Rleft.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rleft.append([m,M])

R1.reverse()
M=R1[0];m=R1[0]
Rright.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rright.append([m,M])

for i in range(n-1):
  M1=max(Bleft[i][1],Rright[n-2-i][1])
  m1=min(Bleft[i][0],Rright[n-2-i][0])
  M2=max(Rleft[i][1],Bright[n-2-i][1])
  m2=min(Rleft[i][0],Bright[n-2-i][0])
  ans.append((M1-m1)*(M2-m2))

print(min(ans))

Measured memory_bytes: 139668
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    h, w, n = int(input()), int(input()), int(input())
    print(min((n - 1) // h + 1, (n - 1) // w + 1))
resolve()

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

int main() {
    int a[4];
    rep(i,4)cin>>a[i];
    int ans=0;
    if(abs(a[2]-a[0])<=a[3])ans=1;
    if(abs(a[1]-a[0])<=a[3] && abs(a[2]-a[1])<=a[3])ans=1;
    if(ans==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3624
def selectionSort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        flag = 0
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
                flag = 1
        A[i], A[minj] = A[minj], A[i]
        if flag:
            count += 1
    return A, count

N = int(input())
A = list(map(int, input().split()))
A, count = selectionSort(A, N)
print(*A)
print(count)


Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>

using namespace std;

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

    vector<int> a(N, 0);
    vector<int> index(N+1);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        index[a[i]] = i;
    }

    map<int, bool> tree;
    tree.insert(tree.begin(), make_pair(index[1], true));

    long sum = 0;
    vector<long> min_sum(N, 0);
    sum = min_sum[index[1]] = N - index[1];
    for (long a = 2; a <= N; ++a) {
        const auto& pos = index[a];
        const auto& e = tree.lower_bound(pos);
        min_sum[pos] = (e == tree.end()) ? 
            (a*(N - pos)) : (min_sum[e->first] + a*(e->first - pos));
        tree.insert(e, make_pair(pos, true));
        sum += min_sum[pos];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 12800
#%%
from itertools import product

#%%
def resolve():
    h,w=map(int,input().split())
    A=['.'+input()+'.' for _ in range(h)]
    A=['.'*(w+2)]+A+['.'*(w+2)]
    flag = 1

    for i,j in product(range(1,h+2),range(1,w+2)):
        if A[i][j]=='#':
            flag = min(flag,A[i-1][j]=='#' or A[i+1][j]=='#' or A[i][j-1]=='#' or A[i][j+1]=='#')

    print("Yes" if flag else "No")
resolve()

Measured memory_bytes: 39280
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
template<typename T> inline T gcd(T&a,T&b){return b==0?a:gcd(b,a%b);}
template<typename T> inline T lcm(T&a,T&b){return a/gcd(a,b)*b;}
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int n;
ll a[maxn],mx,Min;
map<ll,int>mp;
int main(){
    read(n);
    mx=-1,Min=-1;
    for (int i=1;i<=n;i++){
        read(a[i]),mp[a[i]]++;
        if (mp[a[i]]>=2){
            if (mx<a[i]){
                Min=a[i];
                mx=a[i];
            }
        }
    }
    if (mx!=-1){
        if (Min==-1){
            if (mp[mx]>=4) cout<<mx*mx<<endl;
            else puts("0");
        }
        else if (mx!=Min){
            if (mp[mx]>=4) cout<<mx*mx<<endl;
            else cout<<mx*Min<<endl;
        }
        else{
            if (mp[mx]>=4) cout<<mx*mx<<endl;
            else{
                ll tmp=-1;
                for (int i=1;i<=n;i++){
                    if (mp[a[i]]>=2 && a[i]!=mx){
                        tmp=max(tmp,a[i]);
                    }
                }
                if (tmp==-1) cout<<0<<endl;
                else cout<<tmp*mx<<endl;
            }
        }
    }
    else puts("0");
    return 0;
}


Measured memory_bytes: 7296
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong p) {
  int i = 0;
  for ( int j = 0; j < k; j++ ) {
    llong s = 0;
    while( s + T[i] <= p ) {
      s += T[i];
      i++;
      if ( i == n ) return n;
    }
  }
  return i;
}

llong solve() {
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while ( right - left > 1 ) {
    mid = (left + right) / 2;
    int v = check(mid);
    if ( v >= n ) right = mid;
    else left = mid;
  }

  return right;
}

int main() {
  cin >> n >> k;
  for ( int i = 0; i < n; i++ ) cin >> T[i];
  llong ans = solve();
  cout << ans << endl;
}

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

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

  vector<int> next_a(n);
  rep(cnt, k) {
    bool ended = true;
    vector<int> min_map(n);
    vector<int> max_map(n);
    rep(i, n) {
      int val = a[i];
      if(val < n) {
        ended = false;
      }
      int mn = max(i - val, 0);
      int mx = min(i + val, n-1);
      min_map[mn]++;
      max_map[mx]++;
    }
    int cur = 0;
    rep(i, n) {
      if(min_map[i]) {
        cur += min_map[i];
      }
      a[i] = cur;
      if(max_map[i]) {
        cur -= max_map[i];
      }
    }

    if(ended) {
      break;
    }
  }

  rep(i, n) {
    cout << a[i];
    if(i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;
 
void visit(int u) {
  int i,j,v;
  T++;  
  d[u] = T;
 
  for(v=0;v<n;v++) {
    if(G[u][v] == 1 && d[v] == 0 ) {
      visit(v);
    }
  }
   
  T++;
  F[u] = T;
 
}
 
 
 
int main() {
   
   
  int i,j,k,l,u,a,t;
 
  for(i=0;i<n;i++) d[i] = 0;
 
  scanf("%d",&n);
 
  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      G[i][j] = 0;
 
    }
 
  for(i=0;i<n;i++){
 
    scanf("%d %d ",&k,&u);
    //    printf("u = %d\n",u);
 
    for(j=0;j<u;j++) {
      scanf("%d",&a);
      G[k -1][a-1] = 1;
      // printf("G[%d][%d] = 1\n",i,k-1);
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0) 
    visit (i);
  }
     
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;
 
     
     
}

Measured memory_bytes: 1228
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = input()
if A[-1] != "s":
    print(A+"s")
else:
    print(A+"es")

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

int main(){
   int a, b, d, r, f_int;
   char f_deci[16], f[16];
   scanf("%d %d",&a,&b);
   d=a/b;
   r=a%b;
   f_int=d;
   sprintf(f_deci,"%05d",(int)(100000*r/(double)b+0.5));
   if(strcmp(f_deci,"100000")==0){
      f_int+=1;
      strcpy(f_deci,"00000");
   }
   sprintf(f,"%d.%s",f_int,f_deci);
   printf("%d %d %s\n",d,r,f);
   return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int A, B; cin >> A >> B;




cout << max(0, A - 2*B) << "\n";
}

// 境界，出力文字列 チェック



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

int main(){
    string S; cin >> S;
    int N = S.length();
    int a = 0; int b=0;
    for(int i=0;i<N;i++){
        if(S[i] == '0') a++;
        else b++;
    }
    int ans = min(a,b) * 2;
    cout << ans << endl;
}

Measured memory_bytes: 512
n = int(input())
x = list(map(int, input().split()))
g = [x[i+1]-x[i] for i in range(n-1)]
m, k = map(int, input().split())
A = list(map(int, input().split()))
t = list(range(n-1))
for a in A:
	t[a-2], t[a-1] = t[a-1], t[a-2]
s = list(range(n-1))
while k > 0:
	if k&1:
		s = [s[t[i]] for i in range(n-1)]
	t = [t[t[i]] for i in range(n-1)]
	k >>= 1
new_g = [g[s[i]] for i in range(n-1)]
ans = [x[0]]
for i in range(n-1):
	ans.append(ans[-1] + new_g[i])
print(*ans, sep="\n")

Measured memory_bytes: 30972