akhauriyash/Code-Regression huggingface dataset:
// Aizu Vol-1 0199: Chairs Where Demanding People Sit
// 2017.8.29 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct { int w, p, h; } T;
T t[110]; int len;

char a[110]; 

int cmp(T *a, T *b) 
{
	int d, wa, wb;
	wa = a->w, wb = b->w;
	if (a->h) wa = (wa - 1)/2;
	else wa--;
	if (b->h) wb = (wb - 1)/2;
	else wb--;
	if (d = wb - wa) return d;
	return a->p - b->p;
}

int main()
{
	int n, m;
	int i, k, x, p;
	char buf[10], c;

	while (scanf("%d%d", &n, &m) && n) {
		memset(a, '#', n), a[n] = 0; k = 0;
		while (m-- > 0) {
			scanf("%s", buf), c = *buf;
			if (c == 'A') {
				for (i = 0; i < n; i++) 
					if (a[i] == '#') { a[i] = 'A';	break; }
			} else if (c == 'B') {
				for (i = n-1; i >= 0; i--) {
					if (a[i] == '#') {
						if ((i == n-1 || a[i+1] != 'A') && (i == 0 || a[i-1] != 'A')) {
							a[i] = 'B';	break;
						}
					}
				}
				if (i < 0) for (i = 0; i < n; i++)
					if (a[i] == '#') { a[i] = 'B';	break; }
			} else if (c == 'C') {
				if (k == 0) {
					i = (n & 1) ? (n+1)/2 : n/2+1;
					a[i-1] = 'C';
				} else for (i = 0; i < n; i++) {
					if (a[i] != '#') {
						if (i < n - 1 && a[i+1] == '#') { a[i+1] = 'C'; break; }
						if (i > 0 && a[i-1] == '#') { a[i-1] = 'C'; break; }
					}
				}
			} else {  // c == 'D'
				if (k == 0) a[0] = 'D';
				else {
					for (len = 0, x = 0, i = 0; i < n; i++) {
						if (a[i] == '#') {
							if (x == 0) p = i;
							x++;
						} else if (x > 0) {
							t[len].p = p, t[len].h = (p > 0), t[len++].w = x, x = 0;
						}
					}
					if (x > 0) t[len].p = p, t[len].w = x, t[len++].h = 0;
					qsort(t, len, sizeof(T), cmp);
					if (t[0].h) a[t[0].p+(t[0].w-1)/2] = 'D';
					else if (t[0].p == 0) a[0] = 'D';
					else a[n-1] = 'D';
				}
			}
			k++;
//			puts(a);
		}
		puts(a);
	}
	return 0;
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    string s,t;
    cin>>n>>m>>s>>t;
    ll g=__gcd(n,m),x=n*m/g;
    for(int i=0;i<=g;i++){
    	if(s[n*i/g]!=t[m*i/g]){
    		cout <<-1<<endl;
    		return 0;
    	}
    }
    cout <<x<<endl;
    return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt {
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M& set_v(uint _v)
	{
        v = (_v < MD) ? _v : _v - MD;
        return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M& r) const { return M().set_v(v + r.v); }
	M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M& r) const { return *this * r.inv(); }
	M& operator+=(const M& r) { return *this = *this + r; }
	M& operator-=(const M& r) { return *this = *this - r; }
	M& operator*=(const M& r) { return *this = *this * r; }
	M& operator/=(const M& r) { return *this = *this / r; }
	bool operator==(const M& r) const { return v == r.v; }
	M pow(ll n) const
    {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
	M inv() const { return pow(MD - 2); }
	friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt;
//head

int main()
{
    ios::sync_with_stdio(false);
#ifdef RG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
#endif
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a <<" " << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, s, g) for(int i = s; i < g; i++)
#define FORR(i, s, g) for(int i = s - 1; i >= g; i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define DMP(a) std::cerr << #a << " = " << std::a << "\n"
using namespace std;
typedef long long ll;
struct aaa{
    aaa(){
        std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout<<std::fixed<<std::setprecision(20);
    };
}aaaaaaa;

int main() {
    ll r, d, x, y;
    cin >> r >> d >> x;
    REP(i, 10) {
        y = r * x - d;
        cout << y << "\n";
        x = y;
    }

    return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> v(h, IINF);
    rep(i, n){
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        v[x] = min(v[x], y);
    }
    int right = 0, ans = h;
    rep(i, h - 1){
        if(v[i + 1] <= right){
            ans = i + 1;
            break;
        }else if(right + 1 < v[i + 1]){
            ++right;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n, W = map(int, input().split())
w = []
v = []
for i in range(n):
    x,y = map(int,input().split())
    v.append(x)
    w.append(y)
dp = [[0 for i in range(W+1)] for j in range(n+1)]

for i in range(n-1,-1,-1):
    for j in range(W+1):
        if j < w[i]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j],dp[i+1][j-w[i]]+v[i])
print(dp[0][W])


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

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	
	int ans = 0, tmp = 0;
	for (int i = 0; i < n-1; i++) {
		if (h[i] >= h[i+1]) tmp++;
		else {
			ans = max(ans, tmp);
			tmp = 0;
		}
		if (i == n-2)
			ans = max(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3776
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int M = sc.nextInt();
    int a[] = new int[A];
    int b[] = new int[B];
    
    int amin = 1000000;
    int bmin = 1000000;
    //Aのなかで最安値を求める
    for(int i=0; i<A; i++){
      a[i]=sc.nextInt();
      if(a[i]<amin){
        amin=a[i];
      }
      }
    //Bのなかで最安値を求める
    for(int i= 0;i<B;i++){
      b[i]=sc.nextInt();
      if(b[i]<bmin){
        bmin=b[i];
      }
      }
    
    int[] x  = new int[M];
    int[] y  = new int[M];
    int[] c  = new int[M];
    
    for(int i=0; i<M; i++){
      x[i]=sc.nextInt();
      y[i]=sc.nextInt();
      c[i]=sc.nextInt();
    }
    
    int price = amin + bmin;
    int dis;
    
    for(int i=0; i<M; i++){
      dis = a[x[i]-1] + b[y[i]-1] -c[i];//要素数は「0」スタート
      if(dis < price){
       price = dis; 
      }
      }
    System.out.println(price);
    sc.close();
  }
}

Measured memory_bytes: 134320
#include <cstdio>
#include <cstring>

const int N = 55;
const char EMPTY = '.', BOMB = '#';
char grid[N][N];

int bomb_count(int row, int column)
{
    const int NO_OF_NEIGHBOURS = 8;
    int x[NO_OF_NEIGHBOURS] = {-1, 0, 1, 1, 1, 0, -1, -1};
    int y[NO_OF_NEIGHBOURS] = {1, 1, 1, 0, -1, -1, -1, 0};

    int bombs = 0;
    for(int i = 0; i < NO_OF_NEIGHBOURS; i++)
        bombs += (grid[row + x[i]][column + y[i]] == BOMB);

    return bombs;
}

int main()
{
    int height, width;
    scanf("%d %d", &height, &width);

    memset(grid, 0, sizeof(grid));
    for(int i = 1; i <= height; i++)
       scanf("%s", grid[i] + 1);

    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            if(grid[i][j] == EMPTY)
                grid[i][j] = bomb_count(i, j) + '0';

            printf("%c", grid[i][j]);
        }

        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<string.h>
#include<map>
#include<set>
//#include <boost/multiprecision/cpp_int.hpp>

//namespace mp = boost::multiprecision;

using namespace std;


int n,A[50];

int solve(int i, int m) {
	if (m == 0)return 1;
	if (i >= n)return 0;
	int res = solve(i + 1, m) || 
		solve(i + 1, m - A[i]);
	return res;
}

int main() {
	int M;
	scanf("%d",&n);

	for (int i = 0; i < n; i++){
		scanf("%d",&A[i]);
    }
	int q; scanf("%d",&q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &M);
		if (solve(0, M))printf("yes\n");
		else printf("no\n");
	}
	
}



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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int g[10][10];

int main(){
	//IO();
	ll n;
	scanf("%lld",&n);
	ll cnt=1;
	ll ans=0;
	while(n){
		ans+=cnt;
		cnt*=2;
		n/=2;
	}
	printf("%lld\n",ans);
}


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

using namespace std;

int main() {
    string input;
    string day_of_week[7]= {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"}; // 曜日

    cin >> input;

    int days_until_sunday = 0; // 日曜日までの日数
    for(int i = 0; i < 7; i++) {
        if(input == day_of_week[i]) {
            days_until_sunday = i + 1;
        }
    }
    // inputに対して、次の日曜日が何日後なのか出力
    cout << days_until_sunday << endl;

    return 0;
}

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

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



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    string s;
    cin >> s;
    int sun = 0;
    for(int i = 0; i<3; i++){
        if(s[i] == 'S')sun++;
    }
    if(sun == 0){
        cout << "3\n";
    } else if(sun == 2){
        cout << "1\n";
    } else if(sun == 3){
        cout << "0\n";
    } else{
        if(s[1] == 'S'){
            cout << "1\n";
        } else{
            cout << "2\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int width, height;
int ans = 0;
char map[20][20];
int checked[20][20];

void search(int x, int y);
int main(){
	while (1) {
		ans = 0;
		for (int y=0; y<20; y++) {
			for (int x=0; x<20; x++) {
				map[y][x] = '#';
				checked[y][x] = 0;
			}
		}
		cin >> width >> height;
		if (width==0 && height==0) {
			break;
		}

		int startX, startY;
		for (int y=0; y<height; ++y) {
			for (int x=0; x<width; ++x) {
				cin >> map[y][x];
				if (map[y][x] == '@') {
					map[y][x] = '.';
					startX = x;
					startY = y;
				}
			}
		}
		search(startX, startY);
		cout << ans << endl;
	}
	return 0;
}
void search(int x, int y) {
	ans++;
	static const int diffX[] = {0,-1,1,0};
	static const int diffY[] = {-1,0,0,1};
	checked[y][x] = 1;
	for (int ite=0; ite<4; ++ite) {
		int nowX = x + diffX[ite];
		int nowY = y + diffY[ite];
		if (nowX < 0 || nowX >= 20 || nowY < 0 || nowY >= 20) continue;
		if (checked[nowY][nowX] == 0 && map[nowY][nowX] == '.') {
			search(nowX, nowY);
		}
	}
}

Measured memory_bytes: 3024
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef int  i32;
typedef long long i64,ll;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


class Main{
public:
	void run(){
	//	ifstream cin("in");
	//	ofstream cout( "out" );
		int D,N;cin >> D >> N;
		vector<int> ds(D);
		REP(i,D)cin >> ds[i];

		vector<int> as(N),bs(N),cs(N);
		REP(i,N)cin >> as[i] >> bs[i] >> cs[i];

		vector<vector<int> > dp(D,vector<int>(N,-1));
		REP(i,N){
			if(!IN(as[i],ds[0],bs[i]+1))continue;
			dp[0][i]=0;
		}
		for(int d=1;d<D;d++){
			REP(i,N){
				if(!IN(as[i],ds[d],bs[i]+1))continue;
				REP(j,N){
					if(dp[d-1][j]==-1)continue;
					dp[d][i]=max(dp[d][i],dp[d-1][j]+abs(cs[i]-cs[j]));				
				}
			}
		}
		int res=0;
		REP(i,N)res=max(res,dp[D-1][i]);

		cout << res <<endl;
	}
};
 int main(){
ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

Measured memory_bytes: 1352
n, a = gets.split.map(&:to_i)
x = gets.split.map(&:to_i).map{|s| s-a}
t = Array.new(10000){0}
t[0] = 1
x.each{|s|
  t = t.rotate(s).zip(t).map{|u,v| u+v}
}
p t[0]-1

Measured memory_bytes: 8984
import java.util.*;
//import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();
        int i, count = 0;

        for (i = L; i <= R; i++) {
            if (i % d == 0)
                count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35596
package main

import "fmt"

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)

	for i := 0; i <= n; i++ {
		for j := 0; j <= m; j++ {
			black := i*m + j*n
			white := i * j * 2
			count := black - white
			if count == k {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main(){
    ll a,b;cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> xy(n);
    for (int i = 0; i < n; ++i) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy.begin(), xy.end());
    vl xd(n * n), yd(n * n);
    ll idx = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            xd[idx] = xy[i].first - xy[j].first;
            yd[idx] = xy[i].second - xy[j].second;
            idx++;
        }
    }
    ll ret = INF;
    for (int z = 0; z < n * n; ++z) {
        ll temp = 0;
        for (int i = 0; i < n; ++i) {
            ll tt = 1;
            for (int j = i + 1; j < n; ++j) {
                if (xy[j].first - xy[i].first == xd[z] &&
                    xy[j].second - xy[i].second == yd[z]) {
                    tt = 0;
                    break;
                }
            }
            temp += tt;
        }
        chmin(ret, temp);
    }
    cout << ret << "\n";
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    // std::greater<type>
    // (x,y) := x > y と等価
    // 降順ソート
    sort(a.begin(),a.end(),greater<int>());
    ll w = 0;
    ll h = 0;
    rep(i,n-1) {
        if (a[i] == a[i+1]) {
            if (w == 0) w = a[i];
            else if (h == 0) h = a[i];
            i++;
        }
        if (h != 0) break;
    }
    cout << h*w << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  //for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      //if(i==j)
        {
          if(graph[start][j]<INF/2 && graph[j][j]<0)
        {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
        }
        }
    }
    }
   
    for(int i=0;i<vertex;i++)
      {
    if(graph[start][i]>=INF/2)
      {
        cout << "INF" << endl;
      }
    else
      {
    cout << graph[start][i] << endl;
      }
      }
  return 0;
}
 
int fastmin(int a, int b)
{
    int c = a-b;
  return (((c)>>31)&(c))+b;
}
 
void check()
{
  //  int next;
  //int here = start;
  //for(int i=0;i<vertex;i++)
   
  for(int k=0;k<vertex;k++)//v=4
    {
      for(int i=0;i<vertex;i++)
    {
      int gik= graph[i][k];
      for(int j=0;j<vertex;j++)
        {
            
          //if(graph[i][k] !=INF && graph[k][j]!=INF)
        {
          graph[i][j]= fastmin(gik+graph[k][j], graph[i][j]);
        }
        }
    }
    }
   
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
      {
    if(i==j)
      {
        graph[i][j]=0;
      }
    /*else
      {
        graph[i][j]=INF;
        }*/
      }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
      dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
    {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
   }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }  
      cout << endl;    
      }*/
   
 
}

Measured memory_bytes: 5300
l, r = gets.split.map &:to_i
if r - l >= 2019
    ans = 0
else
    ans = 1000000
    for i in l..r
        for j in (i+1)..r
            k = (i * j) %2019
            ans = k if ans > k
        end
    end
end
p ans

Measured memory_bytes: 1788
import sys
import bisect


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    l = list(map(int, readline().split()))
    l.sort()
    cnt = 0
    for i in range(n):
        for j in range(i + 1, n):
            p = bisect.bisect_left(l, l[j] + l[i])
            cnt += max(0, p - j - 1)
    print(cnt)


if __name__ == '__main__':
    solve()


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);



int main(void)
{
    IOS
    int n,q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<int> l(q);
    vector<int> r(q);
    for(auto i = 0; i < q; i++) cin >> l[i] >> r[i];
    
    vector<int> ac(n);
    for(int i = 1; i < n; i++)
    {
        string ss = s.substr(i-1,2);
        if (ss == "AC") {
            ac[i] = ac[i-1] + 1;
        } else {
            ac[i] = ac[i-1];
        }
        //cerr << ac[i] << endl;
    }

    for(auto i = 0; i < q; i++)
    {
        auto sum = ac[r[i]-1] - ac[l[i]-1];
        cout << sum << endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 2256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int count0=0;//0個
  int count1=0;//1個
  int count2=0;//2個
  long long A;
  long long N;
  cin>>N;
  rep(i,N){
    cin>>A;
    if(A%2==1){
      count0++;
    }
    else if(A%4==0){
      count2++;
      continue;
    }
    else if(A%2==0){
      count1++;
    }
  }
  if(count2>=count0){
    cout<<"Yes"<<endl;
  }else if(count1==0&&count2>=count0-1){
    cout<<"Yes"<<endl;
  }
  
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
ans=chk=0
for i in a:
    if x>=i:
        ans+=1
        x-=i
    else:
        x=0
if (x>0): ans=max(0,ans-1)
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
// #include <string>
// #include <set>

using namespace std;
typedef unsigned long long ull;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (const auto i : v) {
        os << i << " ";
    }
    os << "]";
    return os;
}

int main(int argc, char const *argv[]) {
    int H, W;
    cin >> H >> W;

    vector<vector<char>> C(H);
    for (int i = 0; i < H; i++) {
        C[i].resize(W);
        for (int j = 0; j < W; j++) {
            cin >> C[i][j];
        }
    }

    for (int i = 0; i < H*2; i++) {
        for (int j = 0; j < W; j++) {
            cout << C[i/2][j];
        }
        cout << endl;
    }

    return 0;
}


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


N,M=map(int,input().split())
adj=[[] for _ in range(N)]
inf = 10**9+1
x=[inf]*N

L=[0]*M
R=[0]*M
D=[0]*M
fro=[0]*N#何個入ってくる？

for i in range(M):
    L[i],R[i],D[i]=map(int,input().split())
    L[i]-=1
    R[i]-=1
    adj[L[i]].append([R[i],D[i]])
    fro[R[i]]+=1
    #adj[R[i]].append([L[i],-1*D[i]])
    
    
roots=[]
for i in range(N):
    if fro[i]==0:
        roots.append(i)

queue=[]
#距離の設定
for root in roots:
    if x[root]==inf:
        queue.append([root,-1])#node,pare
        x[root]=0
        while queue:
            node,par=queue.pop()
            num=len(adj[node])
            for i in range(num):
                to,cost=adj[node][i]
                if x[to]==inf:#見たことがなければ
                    x[to]=x[node]+cost
                    queue.append([to,node])
            
    
f=1
#判定
for i in range(M):
    d=x[R[i]]-x[L[i]]
    if d!=D[i]:
        f=0
            
    
    
            
            
            
if f==1:
    print("Yes")
else:
    print("No")
        
    




Measured memory_bytes: 89904
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

r = 10**9+7
s = inp[0]
dpbef = na(s+1,0)
dpaf  = na(s+1,0)
dpbef[0] = 1
ans = 0
(s/3).times do |i|
  nowsum0 = 0
  nowsum1 = 0
  nowsum2 = 0
  (0..s).each do |j|
    dpaf[j] = nowsum2%r
    nowsum2 = nowsum1
    nowsum1 = nowsum0
    nowsum0 = (nowsum0 + dpbef[j])%r
  end
  ans += dpaf[s]%r

  dpbef,dpaf = dpaf, dpbef
end
p ans %r


Measured memory_bytes: 14352
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>

struct Point { double x, y; };

void koch(int n, Point a, Point b) {
	if (!n) return;

	Point s, t, u;
	double th = M_PI * 60.0 / 180.0;

	s.x = (2.0*a.x + 1.0*b.x) / 3.0;
	s.y = (2.0*a.y + 1.0*b.y) / 3.0;
	t.x = (1.0*a.x + 2.0*b.x) / 3.0;
	t.y = (1.0*a.y + 2.0*b.y) / 3.0;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;

	koch(n - 1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n - 1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n - 1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n - 1, t, b);
}

int main() {
	Point a, b;
	int n;

	scanf("%d", &n);

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);
}


Measured memory_bytes: 2732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();

        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = ni() - 1;
        }

        int[] a = new int[n];
        int[] b = new int[n];

        int[] da = new int[n];
        int[] db = new int[n];
        for (int i = 0; i < n; i++) {
            if (p[n - 1 - i] > 0) {
                db[p[n - 1 - i] - 1] += i;
            }
            if (p[n - 1 - i] < n - 1) {
                da[p[n - 1 - i] + 1] += i;
            }
        }

        for (int i = 1; i < n; i++) {
            da[i] += da[i - 1];
            db[n - 1 - i] += db[n - i];
        }

        for (int i = 0; i < n; i++) {
            a[i] = i + 1 + da[i];
            b[i] = n - i + 1 + db[i];
        }

        for (int i = 0; i < n; i++) {
            out.print(a[i] + " ");
        }
        out.println();
        for (int i = 0; i < n; i++) {
            out.print(b[i] + " ");
        }
        out.println();
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 18728
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws java.io.IOException {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
      final String input = reader.readLine();
      System.out.println(input.contains("2") ? "No" : "Yes");
    }
  }

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
vector<int> G[201];
vector<int> rG[201];
ll fie[205][205][205];
ll dp[205][205];
ll nxt[205];
int pa;
int siz[205];

void solve(int v,int p){
	int ns=0;
	dp[v][0]=1;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv!=p){
			solve(nv,v);
			memset(nxt,0,sizeof(nxt));
			for(int j=0;j<=ns;j++){
				for(int k=0;k<=siz[nv];k++){
					for(int l=0;l<=min(j,k);l++){
						ll val=dp[v][j]*dp[nv][k]%MOD;
						val=(val*fie[j][k][l])%MOD;
						//printf("%d %d %d %lld %lld %lld\n",j,k,l,dp[v][j],dp[nv][k],val);
						nxt[j+k-l]+=val;
						nxt[j+k-l]%=MOD;
					}
				}
			}
			ns+=siz[nv];
			for(int j=0;j<=ns;j++){
				dp[v][j]=nxt[j];
			}
		}
	}
	for(int i=ns;i>=0;i--){
		dp[v][i+1]=dp[v][i];
	}
	dp[v][0]=0;
}

void dfs(int v,int p){
	pa=v;
	for(int i=0;i<rG[v].size();i++){
		int nv=rG[v][i];
		if(nv!=p){
			dfs(rG[v][i],v);
		}
	}
}
int dfs2(int v,int p){
	int ans=1;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv!=p){
			ans+=dfs2(G[v][i],v);
		}
	}
	return (siz[v]=ans);
}

void init(){
	fie[0][0][0]=1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++){
				fie[i+1][j][k]+=fie[i][j][k];
				fie[i+1][j][k]%=MOD;
				fie[i+1][j+1][k+1]+=fie[i][j][k];
				fie[i+1][j+1][k+1]%=MOD;
				fie[i][j+1][k]+=fie[i][j][k];
				fie[i][j+1][k]%=MOD;
			}
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		rG[b].push_back(a);
	}
	init();
	dfs(0,-1);
	dfs2(pa,-1);
	solve(pa,-1);
	ll ans=0;
	for(int i=0;i<=n;i++){
		ans+=dp[pa][i];
		ans%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 69780
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\n"
int vis[100005]={0};
using namespace std;
void solve1();
void solve()
{
    int t;cin>>t;
    while(t--)
    {
        solve1();
    }
}
signed main()
{
    solve1();
}
void solve1()
{
    int n;cin>>n;
    int arr[n];int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];ans+=arr[i];vis[arr[i]]++;
    }
    int q,x,y;cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        ans+=((y-x)*vis[x]);vis[y]+=vis[x];vis[x]=0;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
const int maxn=3e5+10;
char s[maxn];
int sum[maxn];
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n,q;
  scanf("%d %d",&n,&q);
  scanf("%s",s+1);
  sum[1]=0;
  for(int i=1;i<n;i++){
    if(s[i]=='A'&&s[i+1]=='C'){
      sum[i+1]=sum[i-1]+1;
    }
    else sum[i+1]=sum[i];
  }
  while(q--){
    int l,r,num=0;
    scanf("%d %d",&l,&r);
    cout<<sum[r]-sum[l]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1408
def sim(n, a):
    ans = 0
    for i in range(n):
        div = a[i] / n
        ans += div
        for j in range(n):
            a[j] += div
            if i == j:
                a[j] -= div + div * n
    return ans, a

    

N = input()
A = map(int, raw_input().split())

final_ans = 0
ans, a = sim(N, A)
final_ans = ans
while True:
    ans, a = sim(N, a)
    if ans == 0:
        break
    else:
        final_ans += ans

print final_ans    

Measured memory_bytes: 2692
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

lli gcd(lli x, lli y) {
  while (true) {
    if (x >= y) {
      x %= y;
      if (x == 0) return y;
    } else {
      y %= x;
      if (y == 0) return x;
    }
  }
}

lli n, x;
vector<lli> v, u;
int main() {
  cin >> n >> x;
  read_n(v, n);
  v.push_back(x);
  sort(begin(v), end(v));
  u = vector<lli>(n);
  for (int i=0; i<n; ++i) {
    u[i] = v[i+1] - v[i];
  }
  lli ans = u[0];
  for (int i=1; i<n; ++i) {
    ans = gcd(ans, u[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
/*⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
//#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int PREC=(1<<10)-1;

int n,q;
int v[300005];
int w[300005];

vector<ii> knap[PREC+5];

vector<ii> clean(vector<ii> &v){
	sort(all(v),[](ii &i, ii &j){
		if (i.fi!=j.fi) return i.fi<j.fi;
		else return i.se>j.se;
	});
	
	vector<ii> res;
	res.push_back(v[0]);
	
	for (auto &it:v){
		if (res.back().fi<it.fi && res.back().se<it.se) res.push_back(it);
	}
	
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	rep(x,1,n+1) cin>>v[x]>>w[x];
	
	knap[0].push_back(ii(0,0));
	
	rep(x,1,min(n,PREC)+1){
		for (auto &it:knap[x>>1]){
			knap[x].push_back(it);
			knap[x].push_back(ii(it.fi+w[x],it.se+v[x]));
		}
		
		knap[x]=clean(knap[x]);
	}
	
	cin>>q;
	int node,l;
	
	vector<ii> v1;
	
	while (q--){
		cin>>node>>l;
		
		v1.clear();
		
		v1.push_back(ii(0,0));
	
		while (PREC<node){
			int temp=sz(v1);
			rep(x,0,temp){
				v1.push_back(ii(v1[x].fi+w[node],v1[x].se+v[node]));
			}
			
			node>>=1;
		}
		
		v1=clean(v1);
		
		auto iter=--knap[node].end();
		
		ll ans=0;
		
		for (auto &it:v1){
			if (it.fi>l) break;
			
			while ((*iter).fi+it.fi>l) iter--;
			
			ans=max(ans,(*iter).se+it.se);
		}
		
		cout<<ans<<endl;
	}
	
}


Measured memory_bytes: 16360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    int dp[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
            if(i==0)
            {
                dp[i][j]=arr[i][j];
            }
            else
            dp[i][j]=-100000;
        }
    }
    
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(j==0)
            {
                dp[i+1][j+1]=max(dp[i+1][j+1],arr[i+1][j+1]+dp[i][j]);
                dp[i+1][j+2]=max(dp[i+1][j+2],arr[i+1][j+2]+dp[i][j]);
            }
            if(j==1)
            {
                dp[i+1][j-1]=max(dp[i+1][j-1],arr[i+1][j-1]+dp[i][j]);
                dp[i+1][j+1]=max(dp[i+1][j+1],arr[i+1][j+1]+dp[i][j]);
            }
            if(j==2)
            {
                dp[i+1][j-1]=max(dp[i+1][j-1],arr[i+1][j-1]+dp[i][j]);
                dp[i+1][j-2]=max(dp[i+1][j-2],arr[i+1][j-2]+dp[i][j]);
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 2560
let shift s i =
  String.map (fun c ->
      let cc = (Char.code c) in
      if cc >= 97 && cc <= 122 then (cc - 71+i) mod 26 |> (+) 97 |> Char.chr
      else c) s;;
let reg_a = Array.init 26 (fun n-> shift ".*\\(this\\|the\\|that\\).*" n |> Str.regexp);;

let rec read u =
  try let line = read_line () in
      let rec find i =
        if i < 0 then ()
        else
          Array.iteri (fun j r -> if Str.string_match r line 0 then shift line (-j) |> print_endline) reg_a
      in find 26;read u
  with
    End_of_file -> ()
    in read ();;

Measured memory_bytes: 2176
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#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++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    int64_t sum = 0;
    rep(i, N)
    {
        int64_t input;
        cin >> input;
        v[i] = input;
        sum += input;
    }

    int64_t mini = 1001001001001;

    int64_t flont = 0;

    int flag = 1;

    rep(i, N - 1)
    {
        flag = 0;
        flont += v[i];
        sum -= v[i];
        mini = min(mini, abs(sum - flont));
    }
    if (flag)
    {
        cout << abs(v[1] - v[0]) << endl;
        return 0;
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int N;
bool ans = false;

int main()
{
	cin >> N;

	for(int i = 0; i < 100; i++)
	{
		for (int j = 0; j < 100; j++)
		{
			if ( i * 4 + j * 7 == N )
			{
				ans = true;
			}
		}
	}

	if(ans)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string s;
    int ans = 0;
    cin >> s;
    for(auto c:s)ans += c == '+' ? 1 : -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
//07/03/2020
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
struct OverloadedNode{
    ll val,pos;
    bool operator < (const OverloadedNode &rhs) const {
        if(val==rhs.val) return pos<rhs.pos;
        else return val<rhs.val;
    }
};

template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//typedef tree<OverloadedNode,null_type,less<OverloadedNode>,rb_tree_tag,tree_order_statistics_node_update>OverloadedPbds;

/*Containers*/
//vector<ll>v;
//deque<ll>dq;
//stack<ll>stk;
//map<ll,ll>mp;
//unordered_map<ll,ll>ump;
//set<ll>st;
//multiset<ll>mst;
//unordered_set<ll>ust;
//unordered_multiset<ll>umst;
//priority_queue<ll,deque<ll>,greater<ll>>pq;
//Pbds<ll>ost;
/*OverLoaded Containers*/
//vector<OverloadedNode>v;
//deque<OverloadedNode>dq;
//stack<OverloadedNode>stk;
//map<OverloadedNode,OverloadedNode>mp;
//set<OverloadedNode>st;
//multiset<OverloadedNode>mst;
//priority_queue<OverloadedNode>pq;
//OverloadedPbds oost;
/*Global Variables*/

int main(){
    _fastio
    ll a,b;
    cin>>a>>b;
    bool f=false;
    ll ans;
    for(ll i=1;i<=60000000;i++){
        double x=i*1.00;
        double p,q;
        p=x*.08;
        q=x*.1;
        ll s,t;
        s=(ll)p;
        t=(ll)q;
        if(s==a&&t==b){
            f=true;
            ans=i;
            break;
        }
    }

    if(f) cout<<ans<<endl;
    else cout<<-1<<endl;




    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n,cnt=0;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll p=1;
  bool f=false;
  rep(i,n){
    if(a[i]==p){
      cnt++;p++;
      f=true;
    }
  }
  if(f)cout << n-cnt << endl;
  else cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

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

  ll t = T[0], a = A[0];
  rep(i, 1, n) {
    ll ti = T[i], ai = A[i];
    if(ti == ai) {
      umax(t,a);
      umax(a,t);
    }
    else {
      if(t%ti) t = ti * ((t / ti) + 1);
      if(a%ai) a = ai * ((a / ai) + 1);
      ll ut = t / ti, ua = a / ai;;
      t = ti * max(ut, ua);
      a = ai * max(ut, ua);
    }
  }
  cout << t + a << endl;
}


Measured memory_bytes: 3580
n,y = map(int, input().split())
x = y
for i in range(x//10000 + 1):
    x_af_1m = x - 10000*i
    count_af_1m = i
    for j in range(x_af_1m//5000 + 1):
        x_af_5s = x_af_1m - 5000*j
        count = count_af_1m + j + (x_af_5s//1000)
        if count == n:
            ans = [i,j,(x_af_5s//1000)]
            break
    else:
        continue
    break

try:
    for i in range(3):
        ans[i] = str(ans[i])
    print(" ".join(ans))
except NameError:
    print(-1,-1,-1)


Measured memory_bytes: 3064