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

int main() {
  long long int a, b, c;

  long long int k;

  cin >> a >> b >> c >> k;

  if(abs(a-b) > pow(10, 18)) {
    cout << "Unfair" << endl; 
  } else {
    if(k % 2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
  }
}

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

int main()
{
    int h, w, n, sr, sc;
    string s, t;

    cin >> h >> w >> n >> sr >> sc;
    cin >> s;
    cin >> t;

    int left = sc - 1, right = sc - 1, up = sr - 1, down = sr - 1;
    bool yes = true;

    for (int i = 0; i < n; i++)
    {
        switch (s[i])
        {
        case 'L':
            left--;
            break;
        case 'R':
            right++;
            break;
        case 'U':
            up--;
            break;
        case 'D':
            down++;
            break;
        default:
            break;
        }

        if (left < 0 || right > w - 1 || up < 0 || down > h - 1)
        {
            yes = false;
            break;
        }

        switch (t[i])
        {
        case 'L':
            if (right != 0)
            {
                right--;
            }
            break;
        case 'R':
            if (left != w - 1)
            {
                left++;
            }
            break;
        case 'U':
            if (down != 0)
            {
                down--;
            }
            break;
        case 'D':
            if (up != h - 1)
            {
                up++;
            }
            break;
        default:
            break;
        }
    }

    if (yes)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


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


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> b(n);
    for(int i = 1 ; i<=n;++i){
        b[i-1]=a[i-1]-i;
    }
    sort(b.begin(),b.end());
    ll mean;
    if(b.size()%2==1) mean = (b.size()-1)/2;
    else mean = b.size()/2;

    ll ans = 1<<20;
    ll count = 0;
    rep(i,n){
        count+=abs(b[i]-b[mean]);
    }
    cout << count << endl;


}

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int w[4];


int main(){

  rep(i,3){
    int a,b;
    cin >> a >> b;
    w[a-1]++;
    w[b-1]++;
  }
  rep(i,4){
    if(w[i] > 2){
      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() {
    ios::sync_with_stdio(false), cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;
    cin>>n;
    ll d;
    cin>>d;
    int ans = 0;
    for(int i = 0; i< n; i++){
        ll x, y;
        cin>>x>>y;
        if(x*x + y*y <= d*d) ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll a;
	scanf("%lld",&a);
	int i,j;
	for(i=-1000;i<=1000;++i)
	{
		for(j=-1000;j<=1000;++j)
		{
			ll x = 1ll*i*i*i*i*i;
			ll y = 1ll*j*j*j*j*j;
			if(x-y==a)
			{
				printf("%d %d",i,j);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3788
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;
     
using namespace std;

int q, n, k, a[maxn];
set <int> s;
bool was[maxn];

void rec(int pos, int ans){
	if (ans >= n){
		s.insert(ans);
		return;
	}
	for (int i = (pos == 1); i <= 9; i++)
		if (!was[i])
			rec(pos + 1, ans * 10 + i);
}

void solve(){ 
	cin >> n >> k;
    
    for (int i = 1; i <= k; i++){
    	int x;
    	cin >> x;
    	was[x] = true;
    }

    rec(1, 0);

    cout << *s.begin();
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int int_sort(const void *a, const void *b){
  if(*(int *)a < *(int *)b){
    return -1;
  }else if(*(int *)a == *(int *)b){
    return 0;
  }
  return 1;
}

int main(void){
  int n, d[100], i, t=-1, c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&d[i]);
  qsort((void *)d, n, sizeof(d[0]), int_sort);
  for(i=0;i<n;i++) if(t!=d[i]){c++; t=d[i];}
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

long cnts[26];

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

  string s;
  cin >> s;

  long res = ((s.size()+1) * s.size()) / 2 + 1;

  rep(i, s.size()) {
    cnts[s[i]-'a']++;
  }

  rep(i, 26) {
    res -= (cnts[i]+1) * cnts[i] / 2;
  }

  cout << res << endl;
}

Measured memory_bytes: 832
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vin x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    ld sum=0;
    rep(i,n-1){
        rep2(j,i+1,n){
            sum+=(ld)sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    cout<<fixed<<setprecision(7);
    cout<<(ld)2*sum/n<<endl;
}

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

int main() {
	string st;
	cin >> st;
	char c = 'a';
	bool ok = true;
	vector<int> alp(26);
	for (int i = 0; i < 26; i++) {
		alp[i] = 0;
	}

	for (int i = 0; i < 26; i++) {
		c++;
	}
	for (int i = 0; i < st.size(); i++) {
		if (st.at(i) == 'a') alp.at(0)++;
		if (st.at(i) == 'b') alp.at(1)++;
		if (st.at(i) == 'c') alp.at(2)++;
		if (st.at(i) == 'd') alp.at(3)++;
		if (st.at(i) == 'e') alp.at(4)++;
		if (st.at(i) == 'f') alp.at(5)++;
		if (st.at(i) == 'g') alp.at(6)++;
		if (st.at(i) == 'h') alp.at(7)++;
		if (st.at(i) == 'i') alp.at(8)++;
		if (st.at(i) == 'j') alp.at(9)++;
		if (st.at(i) == 'k') alp.at(10)++;
		if (st.at(i) == 'l') alp.at(11)++;
		if (st.at(i) == 'm') alp.at(12)++;
		if (st.at(i) == 'n') alp.at(13)++;
		if (st.at(i) == 'o') alp.at(14)++;
		if (st.at(i) == 'p') alp.at(15)++;
		if (st.at(i) == 'q') alp.at(16)++;
		if (st.at(i) == 'r') alp.at(17)++;
		if (st.at(i) == 's') alp.at(18)++;
		if (st.at(i) == 't') alp.at(19)++;
		if (st.at(i) == 'u') alp.at(20)++;
		if (st.at(i) == 'v') alp.at(21)++;
		if (st.at(i) == 'w') alp.at(22)++;
		if (st.at(i) == 'x') alp.at(23)++;
		if (st.at(i) == 'y') alp.at(24)++;
		if (st.at(i) == 'z') alp.at(25)++;
	}
	for (int i = 0; i < 26; i++) {
		if (alp[i] % 2 != 0) {
			ok = false;
		}
	}
	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
	int a[3],b=1;
	cin >> a[0] >> a[1] >> a[2];
	sort (a,a+3);
	if (a[0]!=a[1]) b++;
	if (a[1]!=a[2]) b++;
	cout << b;
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 1e5;
const LL mod = 998244353;

int main(){
	int N; cin >> N;
	vector<int> a(N);
	repp(i,0,N) cin >> a[i];
	vector<LL> dp(MC,0),c(MC,0);
	LL S = 0;
	dp[0] = 1;
	LL ans = 1;
	repp(i,0,N){
		(ans *= 3) %= mod;
		(dp[0] *= 2) %= mod;
	}
	ans -= dp[0]*3-3;
	const LL inv2 = (mod+1)/2;
	c[0] = 1;
	repp(i,0,N){
		repm(k,S,-1){
			(dp[k+a[i]] += dp[k]*inv2) %= mod;
			(c[k+a[i]] += c[k]) %= mod;
		}
		S += a[i];
	}
	repp(i,(S+1)/2,S){
		(ans -= dp[i]*3-c[i]*6) %= mod;
	}
	if(ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 1001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 1e9;
const ll INF = 1e18;
const int size = 3002;
#define B 100

int n, dy[4] = {0, -1, 1, 0}, dx[4] = {-1, 0, 0, 1};
queue<P> q;
int X1[MAX], X2[MAX], Y1[MAX], Y2[MAX];

int compress1(int w){
	vector<int> xs;
	for(int i = 0;i < n;i++){
		for(int j = -1;j <= 1;j++){
			int t1 = X1[i]+j, t2 = X2[i]+j;
			if(0 <= t1 && t1 <= w)xs.push_back(t1);
			if(0 <= t2 && t2 <= w)xs.push_back(t2);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for(int i = 0;i < n;i++){
		X1[i] = find(xs.begin(), xs.end(), X1[i])-xs.begin()+1;
		X2[i] = find(xs.begin(), xs.end(), X2[i])-xs.begin()+1;
	}
	return xs.size()-1;
}

int compress2(int h){
	vector<int> xs;
	for(int i = 0;i < n;i++){
		for(int j = -1;j <= 1;j++){
			int t1 = Y1[i]+j, t2 = Y2[i]+j;
			if(0 <= t1 && t1 <= h)xs.push_back(t1);
			if(0 <= t2 && t2 <= h)xs.push_back(t2);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for(int i = 0;i < n;i++){
		Y1[i] = find(xs.begin(), xs.end(), Y1[i])-xs.begin()+1;
		Y2[i] = find(xs.begin(), xs.end(), Y2[i])-xs.begin()+1;
	}
	return xs.size()-1;
}

bool a[size][size];
int b[size][size];
void paint(int w, int h){
	fill((int*)b, (int*)(b+size), 0);
	for(int i = 0;i < n;i++){
		for(int y = Y1[i];y < Y2[i];y++){
			b[y][X1[i]]++;
			b[y][X2[i]]--;
		}
	}
	for(int y = 1;y <= h;y++){
		for(int x = 1; x <= w;x++){
			b[y][x] += b[y][x-1];
			//printf("%d ", b[y][x]);
			if(b[y][x] > 0)a[y][x] = 1;
		}
		//printf("\n");
	}
}

int bfs(int w, int h){
	int ans = 0, tx, ty, yy, xx;
	for(int y = 1;y <= h;y++){
		for(int x = 1;x <= w;x++){
			if(a[y][x])continue;
			q.push(dmp(y, x));
			ans++;
			while(!q.empty()){
				P p = q.front();q.pop();
				yy = p.fi;xx = p.se;
				a[yy][xx] = true;
				for(int i = 0;i < 4;i++){
					ty = yy+dy[i];tx = xx+dx[i];
					if(!a[ty][tx]){
						a[ty][tx] = true;
						q.push(dmp(ty, tx));
					}
				}
			}
		}
	}
	return ans;
}

int main(){
	int w, h;
	while(1){
		scanf("%d%d", &w, &h);
		if(!w)break;
		scanf("%d", &n);
		fill((bool*)a, (bool*)(a+size), true);
		rep(i,n){
			scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
		}
		
		w = compress1(w);
		h = compress2(h);
		rrep(i,h)rrep(j,w)a[i][j] = false;
		paint(w, h);
		int ans = bfs(w, h);
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 47276
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  if (N < 1200) cout << "ABC" << endl;
  else if (N < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;

  return 0;
}


Measured memory_bytes: 892
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //MitsuiSumitomo2019 d
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        char[] s = in.ns().toCharArray();
        int[][] place = new int[n][10];
        for (int i = 0; i < n; i++) for (int j = 0; j < 10; j++) place[i][j] = -1;
        for (int i = n-2; i >= 0; i--) {
            for (int j = 0; j < 10; j++) {
                place[i][j] = place[i+1][j];
            }
            place[i][s[i+1]-'0'] = i+1;
        }
        int ans = 0;
        for (int i = 0; i < 10; i++) {
            int next = place[0][i];
            if(s[0]-'0'==i) next = 0;
            if(next==-1) continue;
            for (int j = 0; j < 10; j++) {
                int next2 = place[next][j];
                if(next2==-1) continue;
                for (int k = 0; k < 10; k++) {
                    int next3 = place[next2][k];
                    if(next3==-1) continue;
                    ans++;
                }
            }
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 23636
#include <stdio.h>

int N;
int old;
int cnt = 0;

int main(){
        scanf("%d",&N);
        int now;
        for(int i = 0; i < N; i++){
                 scanf("%d",&now);
                if(now == old){
                        cnt++;
                        old = 0;
                }else{
                        old = now;
                }
        }
        printf("%d\n",cnt);
}

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

#define N_MAX 100

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

    long A[n][m] = {};
    for (long i = 0; i < n; i++) {
        long k;
        cin >> k;
        for (long j = 0; j < k; j++) {
            long a;
            cin >> a;
            a--;
            A[i][a] = 1;
        }
    }

    // for (long i = 0; i < n; i++) {
    //     for (long j = 0; j < m; j++) {
    //         cout << " " << A[i][j];
    //     }
    //     cout << endl;
    // }

    long ans = 0;
    for (long i = 0; i < m; i++) {
        bool is_favo = true;
        for (long j = 0; j < n; j++) {
            if (A[j][i] != 1) {
                is_favo = false;
                break;
            }
        }
        if (is_favo == true) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>
#include <iomanip>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

ll mod;
const int max_N = 2100;
ll memo[3*max_N][3*max_N+3*max_N/2];
ll rec(ll n, ll b){
	if(n<0)return 0;
	if(n==0){
		if(b>=0)return 1;
		else return 0;
	}
	ll &ret = memo[n][b+3*max_N/2];
	if(ret!=-1)return ret;
	return ret= ( rec(n-1,b+1) + rec(n-2,b-1)*(n-1) + rec(n-3,b)*(n-1)*(n-2) )%mod;
}

void _main(istream &inp){
	memset(memo,-1,sizeof(memo));
	ll N;
	inp >> N >> mod;
	ll res = rec(3*N,0);
	cout << res << endl;
}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 465792
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int h = S/3600;
    int m = (S%3600)/60;
    int s = S%60;
    System.out.println(h+":"+m+":"+s);
  }
}


Measured memory_bytes: 26196
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,x,n) for (int i = x; i < n; i++)
using ll = long long int;
int main() {
    ll mod = 1000000007;
    int n; cin >> n;
    ll ten=1,nine=1,eight=1;
    rep(i,n) {
        ten*=10;
        nine*=9;
        eight*=8;
        if (ten>mod) ten%=mod;
        if (nine>mod) nine%=mod;
        if (eight>mod) eight%=mod;
    }
    ll ans = ten-nine-nine+eight;
    ans %= mod;
    if(ans<0) ans += mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int gdc(int a, int b) {
	if (!b) return a;
	return gdc(b, a % b);
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n), r(n), l(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	l[0] = a[0];
	r[n - 1] = a[n - 1];
	for (int li = 1; li < n; li++) {
		int ri = n - li - 1;
		r[ri] = gdc(r[ri + 1], a[ri]);
		l[li] = gdc(l[li - 1], a[li]);
	}
	int ans = max(l[n - 2], r[1]);
	for (int i = 1; i < n - 1; i++) {
		ans = max(ans, gdc(r[i + 1], l[i - 1]));
	}
	cout << ans << endl;
}

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

int main(){
	long long s;
	cin>>s;
	
	int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x)
#define CMIN(m, x)  m = min(m,x)
#define itn int
typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;


int main(){
    int n, q;
    cin >> n >> q;
    vector<vector<int>> ki(n);
    vector<int> point(n);
    queue<pair<int,int>> que;
    int c = 0;int p = 0;
    REP(i,n - 1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        ki[b].push_back(a);
        ki[a].push_back(b);
    }
    REP(i,q){
        int pos,ap;
        cin >> pos >> ap;
        pos--;
        point[pos] += ap;
    }

que.push(make_pair(0,0));
while(!que.empty()){
    c = que.front().first;
    p = que.front().second;
    que.pop();
    for(auto i : ki[c]){
        if(i != p){  
            point[i] += point[c];
            que.push(make_pair(i,c));
        }
    }
    if(que.empty()) break;
}
    REP(i,n)
        cout << point[i] << " ";
    cout << endl;
}

Measured memory_bytes: 16372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    
    int n;
    cin >> n;
    int h[n];
    rep(i, n) cin >> h[i];
    
    int ans = 0;
    int now = 0;
    rep3(i, 1, n) {
        if (h[i - 1] >= h[i]) {
            now++;
        } else {
            chmax(ans, now);
            now = 0;
        }
    }
    chmax(ans, now);
    cout << ans << endl;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int,int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define error(x) cerr << #x << " = " << x << endl
#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int INF = 1e9 + 7;
int n, arr[100005];

ll f() {
    ll res = 0;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        if (i&1) {
            if (sum + arr[i] >= 0) {
                res += llabs(sum + arr[i] - (-1));
                sum = -1;
            } else {
                sum += arr[i];
            }
        } else {
            if (sum + arr[i] <= 0) {
                res += llabs(sum + arr[i] - 1);
                sum = 1;
            } else {
                sum += arr[i];
            }
        }
    }
    return res;
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> arr[i];
    ll res = f();
    for (int i = 0; i < n; ++i) arr[i] *= -1;
    res = min(res,f());
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string ab("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
	while(cin >> n , n){
		vector<int> k(n);
		for(int i=0;i<n;i++){
			cin >> k[i];
		}
		string s;
		cin >> s;
		for(int unsigned i = 0;i<s.size();i++){
			int x = 0;
			for(int j=0;j<52;j++){
				if(ab[j] == s[i]) x = j;
			}
			cout << ab[(x - k[i%n] + 52)%52];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3220
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int n, m;
char dp[5001][1<<12];
main(){
	int i,j;
	while(cin >> n >> m, n){
		string t;
		vector<string> s(n);
		REP(i, n) cin >> s[i];
		REP(i, m){
			string s;
			cin >> s;
			t += s;
		}
		vector< vector<int> > g(t.size()+1);
		REP(i, t.size()){
			REP(j, n){
				if(i+s[j].size()-1 >= t.size()) continue;
				int f = 1;
				REP(k, s[j].size()) f &= t[i+k] == s[j][k];
				if(f) g[i].push_back(j);
			}
		}
		

		memset(dp, 0, sizeof(dp));
		ll ans = 0;
		REP(i, t.size()+1){
			dp[i][0] = 1;
			REP(j, 1 << n){
				if(dp[i][j]) FOR(k, g[i]){
					if(1&(j>>*k)) continue;
					dp[i+s[*k].size()][j|(1<<*k)] = 1;
				}
			}
			ans += dp[i][(1<<n)-1];
//			printf("%c ans[%d] = %lld\n", t[i], i, dp[i][(1<<n)-1]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
   long long a, b, c, d, mx=-1e18+10;
   cin>>a>>b>>c>>d;
   mx=max(mx,a*c);
   mx=max(mx,a*d);
   mx=max(mx,b*c);
   mx=max(mx,b*d);
   cout<<mx<<endl;
}


Measured memory_bytes: 3608
#include<stdio.h>
#define INFTY 2000000000
#define MAX 200000

int L[MAX / 2 + 2],R[MAX / 2 + 2];

long long merge(int A[], int left, int mid,int right)
{
	long long count = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	int i,j,k;
	for(i = 0; i < n1; i++){
		L[i] = A[left + i];
	}
	for(i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = INFTY;
	R[n2] = INFTY;
	i = 0;
	j = 0;
	for(k = left; k < right; k++){
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
			count += n1 - i;
		}
	}
	return count;
}

long long mergeSort(int A[], int left, int right)
{
	long long v1,v2,v3;
	if(left + 1 < right){
		int mid = (left + right)/2;
		v1 = mergeSort(A,left,mid);
		v2 = mergeSort(A,mid,right);
		v3 = merge(A,left,mid,right);
		return v1 + v2 + v3;
	}
	else{
		return 0;
	}
}

int main(void)
{
	int i, n;
	scanf("%d",&n);
	int S[200000];
	for(i=0; i<n; i++){
		scanf("%d", &S[i]);
	}
	long long ans = mergeSort(S, 0, n); 
	printf("%lld\n", ans);
	return 0;
}





Measured memory_bytes: 3412
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;


int main(int argc, char *argv[])
{
	int n;

	//input
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	for (int i = 0; i < n; i++){
		int c;
		cin >> c;
		p[i] = c;
	}

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



	//calc
	vector<int> permutation(n);
	for (int i = 0; i < n; i++){
		permutation[i] = i + 1;
	}
	sort(permutation.begin(), permutation.end());

	int permutation_count = 1;
	int p_index = 0;
	int q_index = 0;
	do{
		if (permutation == p){
			p_index = permutation_count;
		}
		if (permutation == q){
			q_index = permutation_count;
		}

		permutation_count++;
	} while (next_permutation(permutation.begin(), permutation.end()));



	//ans
	int ans = abs(p_index - q_index);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#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 main()
{
  int N,X;
  cin >> N >> X;
  vector<int> L(N);
  REP(i,N) cin >> L[i];
  vector<int> bounce(N+1);
  bounce[0] = 0;
  int count = 1;
  if(X==0) return 1;
  for(int i = 0;i<N;i++){
    bounce[i+1] = bounce[i]+L[i];
    if(bounce[i+1] <=X) count+=1;
  }
  //  REP(i,N+1) cout << bounce[i] << endl;                                                                                                                                                                                                                           
  cout << count	<< endl;
  return 0;
}


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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===


int dp1[3030][3030], dp2[3030][3030];


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

	int N, T;
	cin >> N >> T;

	vector<Pii> items(N);
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		items[i].first = a;
		items[i].second = b;
	}

	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= T - 1; ++j) {
			dp1[i][j] = dp2[i][j] = -I_INF;
		}
	}
	for (int i = 0; i < N; ++i) {
		dp1[i][0] = dp2[i][0] = 0;
	}

	
	for (int i = 1; i <= N; ++i) {
		int ai, bi;
		tie(ai, bi) = items[i - 1];
		for (int j = 0; j <= T - 1; ++j) {
			if (j - ai >= 0) {
				dp1[i][j] = max(dp1[i - 1][j - ai] + bi, dp1[i - 1][j]);
			}
			else {
				dp1[i][j] = dp1[i - 1][j];
			}
			if (j - 1 >= 0) {
				dp1[i][j] = max(dp1[i][j], dp1[i][j - 1]);
			}
		}
	}


	for (int i = 1; i <= N; ++i) {
		int ai, bi;
		tie(ai, bi) = items[N - i];
		for (int j = 0; j <= T - 1; ++j) {
			if (j - ai >= 0) {
				dp2[i][j] = max(dp2[i - 1][j - ai] + bi, dp2[i - 1][j]);
			}
			else {
				dp2[i][j] = dp2[i - 1][j];
			}
			if (j - 1 >= 0) {
				dp2[i][j] = max(dp2[i][j], dp2[i][j - 1]);
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		int tmp = 0;
		for (int j = 0; j <= T - 1; ++j) {
			tmp = max(tmp, dp1[i - 1][j] + dp2[N - i][T - 1 - j]);
		}
		ans = max(ans, tmp + items[i - 1].second);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 71936
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 75;
using namespace std;
int n, a[N];
long long ans;
struct Node {
    int a, b;
} ji[N], ou[N];
inline bool cmp(Node a, Node b) {return a.b > b.b;}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i += 2)
        ji[a[i]].b++, ji[a[i]].a = a[i], ou[a[i + 1]].b++, ou[a[i + 1]].a = a[i + 1];
    sort(ou + 1, ou + N + 1, cmp);
    sort(ji + 1, ji + N + 1, cmp);
    if (ou[1].a == ji[1].a)
        printf("%d\n", min(n - ji[2].b - ou[1].b, n - ji[1].b - ou[2].b));
    else
        printf("%d\n", n - ji[1].b - ou[1].b);
    return 0;
}

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

int main(){
    int N,B,count;
    cin>>N;
    count=0;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        for(int j=1;j<N-i;j++){
            if(A[j]<A[j-1]){
                B=A[j];
                A[j]=A[j-1];
                A[j-1]=B;
                count++;
            }
        }
    }
    for(int i=0;i<N;i++){
        if(i==N-1){
            cout<<A[i]<<endl;
        }
        else{
            cout<<A[i]<<" ";
        }
    }
    cout<<count<<endl;
}



Measured memory_bytes: 3092
n = int(input())
A = list(map(int, input().split()))
A.sort()
res = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):            
            if A[i] + A[j] > A[k] and len(set([A[i], A[j], A[k]])) == 3:
                res += 1

print(res)

Measured memory_bytes: 9196
N,M = map(int,input().split())

G = []
for i in range(N):
    A = list(map(int,input().split()))
    if A[0] != 0:
        for j in range(1,len(A)):
            G.append(A[j])

cnt = 0
for k in range(1,M+1):
    if G.count(k) == N:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int dp[100005], h[100005];

int ryougitabs(int x)
{
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    dp[0] = 0;
    dp[1] = ryougitabs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(ryougitabs(h[i] - h[i - 1]) + dp[i - 1], ryougitabs(h[i] - h[i - 2]) + dp[i - 2]);
    cout << dp[n - 1] << endl;
    return 0;
}

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

int main(){
  string str_i; cin >> str_i;
  string str_o;
  if(str_i == "Sunny"){
    str_o = "Cloudy";
  }
  else if(str_i == "Cloudy"){
    str_o = "Rainy";
  }
  else{
    str_o = "Sunny";
  }
  
  cout << str_o << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1000000000000000000
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

void getPrimeFactors(lli n) {
	map<lli, int> pf;
	while(~n & 1) pf[2]++, n >>= 1;
	for (lli i = 3; i * i <= n; i += 2)
		while (!(n % i)) pf[i]++, n /= i;
	if (n > 1) pf[n]++;

	int ans = 0;
	for(auto &i: pf) {		
		int aux = i.se, cont = 1;
		while(aux - cont >= 0) {
			ans++;
			aux -= cont;
			cont++;
		}
	}
	cout << ans << endl;
}
int main() {
	optimizar_io
	lli n; cin >> n;
	getPrimeFactors(n);
}

Measured memory_bytes: 3640
H, W, A, B = map(int, input().split())
mat=[[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i >= B and A > j:
            mat[i][j] = 1
        elif i < B and j >= A:
            mat[i][j] = 1
    print("".join(map(str, mat[i])))

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

int main(){
  int N;
  cin>>N;
  int ans = 0,num,order;

  for(int i=1;i<=N;i++){
    num = i;
    order = 0;
    while(num!=0){
      num /= 10;
      order++;
    }
    if(order%2 == 1){
      ans++;
    }

  }
  cout<<ans<<endl;
}


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

int main() {
	string s;
	cin >> s;
	string sa;
	for (int i = 0; i < s.size(); i++) {
		if (i & 1)sa.push_back('p');
		else sa.push_back('g');
	}

	int a = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == sa[i])a += 0;
		else if (s[i] == 'g'&&sa[i] == 'p')a++;
		else a--;
	}
	cout << a << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    set<int> st;
    int ans = 0;
    imfor(i, n) {
        int s;
        cin >> s;
        ans += s;
        st.insert(s);
    }
    if (ans % 10 != 0) {
        cout << ans << endl;
    }
    else {
        for (auto x : st) {
            if (x % 10 != 0) {
                ans -= x;
                break;
            }
        }
        if (ans % 10 != 0) {
            cout << ans << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
#define DEBUG(x,y) cout<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl;
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf=1e9+7;

int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	if(min(b,d)-max(a,c)>0)p(min(b,d)-max(a,c));
	else p(0);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner teclado = new Scanner(System.in);
		int d, r, x2000;
		r = teclado.nextInt();
		d = teclado.nextInt();
		x2000 = teclado.nextInt();
		
		if (r >= 2 && r <= 5 && d >= 1 && d <= 100 && x2000 > d && x2000 <= 200) {
			
				 int a = ((r*x2000)-d);
				System.out.println(a);
				int b = ((r*a)-d);
				System.out.println(b);
				int c = ((r*b)-d);
				System.out.println(c);
				int e = ((r*c)-d);
				System.out.println(e);
				int f = ((r*e)-d);
				System.out.println(f);
				int g = ((r*f)-d);
				System.out.println(g);
				int h = ((r*g)-d);
				System.out.println(h);
				int i = ((r*h)-d);
				System.out.println(i);
				int j = ((r*i)-d);
				System.out.println(j);
				int k = ((r*j)-d);
				System.out.println(k);
			}

		}
	}




Measured memory_bytes: 22740
n,l = map(int,input().split())

ll = []
p = []
for i in range(n):
    ll.append(l + i)
    p.append(abs(l + i))

res = -1
tmp = 10 ** 100
sm = sum(ll)

for i in ll:
    dif = abs(sm - (sm - i))
    if dif < tmp:
        tmp = dif
        res = sm - i
    # print(dif, sm)

print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,x=0;
    cin>>a;
    int b[a*2];
    for(int i=0;i<a*2;i++){
        cin>>b[i];
    }
    sort(b,b+a*2);
    for(int i=0;i<a*2;i+=2){
        x+=b[i];
    }
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
  long int N,D;
  long int i,j;
  int kekka = 0;
  scanf("%ld",&N);
  scanf("%ld",&D);

  long int X[200000];
  long int Y[200000];

  for(i=0;i<N;i++){
    scanf("%ld", &X[i]);
    scanf("%ld", &Y[i]);
  }

  for(j=0;j<N;j++){
    long int ans = X[j]*X[j]+ Y[j]*Y[j];
    if(sqrt(ans) <= D){
      kekka += 1;
    }
  }

  printf("%d", kekka);

  return 0;
}


Measured memory_bytes: 5172
#include <bits/stdc++.h>
#define MAX 1000000
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

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

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

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

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

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

void solve() {
	int a, b;
	cin >> a >> b;
	if(a <= b) {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
		cout << endl;
	} else {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
		cout << endl;
	}
}

int main() {
	solve();

	// __test {
	// 	solve();
	// }
}

Measured memory_bytes: 3520
import sys
input = sys.stdin.readline

k, q = map(int, input().split())
D = tuple(map(int, input().split()))
for _ in range(q):
  n, x, m = map(int, input().split())
  E = tuple(d%m for d in D)
  temp = n-1
  b = x
  for i, e in enumerate(E, 1):
    c = -(-(n-i)//k)
    if e == 0:
      temp -= c
    b += e*c
  temp -= b//m - x//m
  print(temp)

Measured memory_bytes: 108920
#include <iostream>
#include <ostream>
#include <fstream>
#include <set>
#include <queue>
#include <time.h>
#include <ctime>
#include <vector>
#include <bitset>
#include <algorithm>
using namespace std;
#define It(q) for (auto elem :q)
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define read(vec, n) for(int (i)=0;(i)<(int)(n);++(i)) cin >> vec[i];
#define print(q) for(auto it = (q).begin(); it != (q).end();++(it)) cout << *it << ' '; cout << endl;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

constexpr int maxn = 2000 * 2000 + 1;
bitset<maxn> sums;

int main() {
    int n;
    cin >> n;
    vi a(n);
    read(a, n);
    sums[0] = 1;
    int sum = 0;
    rep(i, n) {
        sum += a[i];
        sums |= (sums << a[i]);
    }
    sum = (sum + 1) / 2;
    while (!sums[sum])
        sum++;
    cout << sum;
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<stack>

using namespace std;

int main(void){
	stack<int> st;
	int n,a;

	while(cin>>n){
		
		if(n!=0){
			st.push(n);
		}else{
			a=st.top();
			cout<<a<<endl;
			st.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 0