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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<lli> sumR(N + 10), sumG(N + 10), sumB(N + 10);
	for (int i = 0; i < N; i++) {
		switch (S[i]) {
		case 'R':
			sumR[i]++;
			break;
		case 'G':
			sumG[i]++;
			break;
		case 'B':
			sumB[i]++;
			break;
		}

		sumR[i + 1] = sumR[i];
		sumG[i + 1] = sumG[i];
		sumB[i + 1] = sumB[i];
	}
	lli ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 3; j < N; j++) {
			string y; y.push_back(S[i]); y.push_back(S[j]);
			sort(y.begin(), y.end());
			if (y == "BG") {
				ans += (sumR[j] - sumR[i]);
				if ((j - i) % 2 == 0 && S[i + (j - i) / 2] == 'R') {
					ans--;
				}
			}
			if (y == "BR") {
				ans += (sumG[j] - sumG[i]);
				if ((j - i) % 2 == 0 && S[i + (j - i) / 2] == 'G') {
					ans--;
				}
			}
			if (y == "GR") {
				ans += (sumB[j] - sumB[i]);
				if ((j - i) % 2 == 0 && S[i + (j - i) / 2] == 'B') {
					ans--;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}



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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin>>x;
	if(x >= 30) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//tod-ngen


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
n,m,q = list(map(int,input().split()))
abcd =  [list(map(int,input().split())) for i in range(q)]


def dfs(x,y,z,que):
    ret = 0
    if x == 0:
        for a,b,c,d in abcd:
            if que[b-1] - que[a-1]==c:
                ret+=d
        return ret
    for i in range(y,z+1):
        ret = max(ret,dfs(x-1,i,z,que + [i]))
    return ret

print(dfs(n,1,m,[]))

Measured memory_bytes: 9220
s = gets.chomp

alp = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for i in 1..26 do
  if s == alp[i-1] then
    print alp[i]
  end
end

Measured memory_bytes: 1788
h,w,K=map(int,input().split())
clist=[input() for _ in range(h)]

counter = 0
for i in range(2**w):
    for j in range(2**h):
        read=[]
        for l in range(h):
            if j >> l & 1:
                read.append([True]*w)
            else:
                read.append([False]*w)
        for k in range(w):
            if i >> k & 1:
                for m in range(h):
                    read[m][k] = False
        tmpcounter=0
        for a in range(h):
            for b in range(w):
                if clist[a][b] == '#' and read[a][b]:
                    tmpcounter += 1
        if tmpcounter == K:
            counter += 1
print(counter)

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

ll ans = 0;
int n;
string s;
void dfs (int now, ll sum) {
    if (now == n) {
        ans += sum;
        // cout << sum << "\n";
        return;
    }
    rep (i, now + 1, n + 1) {
        ll m = stoll (s.substr (now, i - now));
        // cout << m << "\n";
        dfs (i, sum + m);
    }
}

int main() {
    cin >> s;
    n = s.size();
    dfs (0, 0);
    cout << ans << "\n";
}


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

string s;

int main() {
	int i, j;
	
	cin >> s;
	for (i = (s.length() - 1) / 2; i > 0; i--) {
		for (j = 0; j < i; j++) {
			if (s[j] != s[i + j]) {
				break;
			}
		}
		if (j == i) break;
	}
	cout << 2 * i << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a[5];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	int k; cin >> k;
	for (int i = 0; i < k; i++)a[2] *= 2;
	cout << a[0] + a[1] + a[2] << endl;
}

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

int main(){

    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL x, k, d;

int main(){
    cin>>x>>k>>d;
    x = abs(x);
    LL o = x / d;
    if(k >= o){
        k -= o;
        if(k & 1) cout<<abs(x - o * d - d)<<endl;
        else cout<<(x - o * d)<<endl;
    }
    else {
        cout<<x - k * d<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  printf("%s\n",b-a==c-b ? "YES" : "NO");
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll q;
  cin >> q;
  REP(i,q){
    ll a,b;
    cin >> a >> b;
    if(a==b){
      cout << 2*(a-1) << endl;
      continue;
    }
    ll rt = floor(sqrt((double)a*b));
    ll ans = 0;
    ans += 2*(rt-1);
    if(a<=rt) ans--;
    if(b<=rt) ans--;
    ans += a*b/rt - (rt-1);
    if(a*b%rt==0) ans --;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
	int n;
	while(cin>>n){
        char s[4444];cin>>s;
        long nr=0,ng=0,nb=0;
        for(int i=0;i<n;i++)nr+=s[i]=='R',ng+=s[i]=='G',nb+=s[i]=='B';
        //cout<<nr<<" "<<ng<<" "<<nb<<" = "<<nr*ng*nb<<endl;
        long ans=nr*ng*nb;
        for(int i=0;i<n;i++)
            for(int d=1;i+d+d<n;d++)
                if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B'))
                    ans--;
        cout<<ans<<'\n';
	}
    //cout<<('R'^'G'^'B')<<endl;
}


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

using namespace std;

#define ll long long 

const int INF = 1e9+5;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> height(n);
	for(int i = 0; i < n; ++i){
		cin >> height[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	int j;
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j <= i+k; ++j){
			if(j < n){
				dp[j] = min(dp[j], dp[i] + abs(height[i]-height[j]));
			}
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
four = [i for i in a if i%4==0]
even = [j for j in a if j%2==0 and j!=2 and j%4!=0]
if n//2 <= len(four) or n//2 <= len(four)+a.count(2)//2 or n//2<=len(four)+a.count(2)//2 + len(even)//2:
    print("Yes")
else:
    print("No")

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int r;

int main(){
  cin >> r;
  cout << r * r <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cs const 
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define drep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
cs int base = 233;
cs int ff = 2e6+1;
cs int mod = 998244353;
cs int inf = 1e9+1;
int n, x, y, ans[ff];
int read(){
	int f=1,re=0;char ch;
	for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
	if(ch=='-'){f=-1,ch=getchar();}
	for(;isdigit(ch);ch=getchar()) re=(re<<3)+(re<<1)+ch-'0';
	return re*f; 
}
int kr(int i, int j)
{
	return min(abs(j-i), min(abs(j-x)+1+abs(i-y), abs(i-x)+1+abs(j-y)));
}
void init()
{
	n=read(),x=read(),y=read();
	if( x > y ) swap(x, y);
	rep(i, 1, n)
		rep(j, 1, n)
			if( i != j )
				ans[kr(i, j)]++;
	rep(i, 1, n-1)
		cout << ans[i] / 2 << endl;
}
signed main()
{
	int T = 1;
	while(T--) 
		init();
}

Measured memory_bytes: 256
// A / B問題

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;
    cout << a / b << ' ' << a % b << ' '
         << fixed << setprecision(5) << (double)a / b << endl;
    return 0;
}


Measured memory_bytes: 3276
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	String s =  sc.next();
	int count =0;
	int n= s.length();

	for(int i=0;i<n/2;i++) {
		if(s.charAt(i)!=s.charAt(n-1-i)) {
			count += 1;
		}
	}

	System.out.println(count);
  }
}

Measured memory_bytes: 23764
#include<cstdio>

int main(){
    long int d;
    int n;
    scanf("%d %ld", &n, &d);
    int ans = 0;
    long int sq_d = d*d;
    for(int i=0;i<n;i++){
        long int x,y;
        scanf("%ld %ld", &x, &y);
        long int dis = x*x + y*y;
        if(dis <= sq_d) ans++;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1732
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
import fractions
a,b,c,d = iim()

def antiDiv(n):
    return n-n//c-n//d+n//(c*d//fractions.gcd(c,d))
print(antiDiv(b)-antiDiv(a-1))

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll A = nextLong();
  int B1, B2;
  scanf("%d.%d", &B1, &B2);

  ll B = B1 * 100 + B2;

  ll ans = A * B;
  ans /= 100;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans=0, idx=1;
    rep(i,n){
        if(a[i] != idx){
            ans++;
        }else{
            idx++;
        }
    }

    if(n == ans){
        cout << -1;
    }else {
        cout << ans;
    }
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
L, R = map(int, input().split())


for i in range(M-1):
      L1, R1 = map(int, input().split())
      if R1 < L or R < L1:
        print(0)
        exit()
      else:
        if L <= L1 <= R:
          L = L1
          
        elif L <= R1 <= R:
          R = R1
        
          
print(R-L+1)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
 
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

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

    int ans = 1;
    while(ans*2 <= N) {
        ans *= 2;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 200000;

int main()
{
  int R[MAX], n;

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

  int maxv = -1000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++)
  {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 3872
import numpy as np
a = int(input())
p =[0]*(a+1)
def cal(n):
    if p[n] !=0:return p[n]
    if n==0:res =  2
    elif n == 1:res = 1
    else: res =  cal(n-1)+cal(n-2)
    p[n] = int(res)
    return p[n]
print(int(cal(a)))

Measured memory_bytes: 12496
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int h, w;
    while (cin >> h >> w, h || w) {
        for (int i = 0; i < h; i++) {
            cout << string(w, '#') << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

//unionFind
class unionFind {
private:
	int* p;   //親配列のポインタ
	int* rank;
	int N;   //要素数
	int* check;   //同値な要素の数
public:
	unionFind(int);   //コンストラクタ
	int parent(int);   //親要素を返す
	void unit(int, int);   //2要素をつなぐ
	int operator[](int);   //parentの省略形
	~unionFind();
	int size(int n);   //頂点nと同値な要素数を返す
};

unionFind::unionFind(int n) {
	N = n;
	p = new int[N];
	rank = new int[N];
	for (int i = 0; i < N; i++) {
		p[i] = i;
		rank[i] = 0;
	}
	check = new int[N];
	for (int n = 0; n < N; n++)check[n] = 1;
	return;
}

int unionFind::parent(int n) {
	if (n < 0 || n >= N)return -1;
	if (p[n] == n)return n;   //自分が一番上の親
	return p[n] = parent(p[n]);   //つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) {
	return parent(n);
}

void unionFind::unit(int x, int y) {
	x = parent(x), y = parent(y);
	if (x == y)return;   //根が同じだから何もせずに帰る
	int sum = check[x] + check[y];
	if (rank[x] < rank[y])p[x] = y;
	else {
		p[y] = x;
		if (rank[x] == rank[y])rank[x]++;
	}
	check[x] = sum;
	check[y] = sum;
	return;
}

unionFind::~unionFind() {
	delete(p);
	delete(rank);
	delete(check);
	return;
}

int unionFind::size(int n) {
	return check[parent(n)];
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N, M;
	cin >> N >> M;
	stack<pll> bridges;
	for (ll m = 0; m < M; m++) {
		ll a, b;
		cin >> a >> b;
		bridges.push(pll(--a, --b));
	}
	unionFind U(N);
	ll cur = 0;
	stack<ll> ans;
	ans.push(cur);
	for (ll m = 0; m < M - 1; m++) {
		pll bri = bridges.top();
		bridges.pop();
		ll a = bri.first, b = bri.second;
		if (U[a] != U[b]) {
			cur += (ll)U.size(a) * (ll)U.size(b);
			U.unit(a, b);
		}
		ans.push(cur);
	}
	while (!ans.empty()) {
		cout << N*(N-1)/2-ans.top() << "\n";
		ans.pop();
	}
	return 0;
}

Measured memory_bytes: 4224
var
 i,n,t,sum:longint;
 b:array[0..9] of longint;
function AK(a:longint):longint;
begin
 if a<400 then exit(1) 
  else if a<800 then exit(2)
   else if a<1200 then exit(3)
    else if a<1600 then exit(4)
     else if a<2000 then exit(5)
      else if a<2400 then exit(6)
       else if a<2800 then exit(7)
        else if a<3200 then exit(8)
         else exit(0);
end;
begin
 readln(n);
 for i:=1 to n do
  begin  
   read(t);
   inc(b[AK(t)]);
  end;
 for i:=1 to 8 do
  if b[i]<>0 then inc(sum);
 if sum<>0 then writeln(sum,' ',sum+b[0])
  else writeln(1,' ',b[0]);
end.

Measured memory_bytes: 128
N,Y = map(int,input().split())
for x in range(N+1):
    for y in range(N - x + 1):
        if 10000*x+5000*y+1000*(N - x - y) == Y:
            print(x,y,N-x-y)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 65052
#ABC129 D
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]
 
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        elif j == 0:
            L[i][j] = 1
        elif L[i][j - 1] == 0:
            L[i][j] = 1            
        else:
            L[i][j] = L[i][j - 1] + 1
            
    for j in range(W - 1, -1, -1):
        if S[i][j] == '#':
            continue
        elif j == W - 1:
            R[i][j] = 1
        elif L[i][j + 1] == 0:
            R[i][j] = 1            
        else:
            R[i][j] = R[i][j + 1] + 1

for j in range(W):
    for i in range(H):
        if S[i][j] == '#':
            continue
        elif i == 0:
            D[i][j] = 1
        elif L[i - 1][j] == 0:
            D[i][j] = 1            
        else:
            D[i][j] = D[i - 1][j] + 1
            
    for i in range(H - 1, -1, -1):
        if S[i][j] == '#':
            continue
        elif i == H - 1:
            U[i][j] = 1
        elif L[i + 1][j] == 0:
            U[i][j] = 1            
        else:
            U[i][j] = U[i + 1][j] + 1
            
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, (L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3))
print(ans)

Measured memory_bytes: 315784
// cpp219 - the 712534
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
using namespace std;
const ll base = 7;
const ll N = 2e3 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,dp[N][N],i,j;
LL a[N];
bool lf(LL x,LL y){
    return x.fs > y.fs;
}
int main(){
    ios_base::sync_with_stdio(false);
   	cin.tie(0); cout.tie(0);
    //freopen("test.inp", "r", stdin);
    cin>>n;
    for (i=1;i<=n;i++){
        cin>>a[i].fs;
        a[i].sc = i;
    }
    sort(a + 1,a + n + 1,lf);
    for (i=0;i<=n;i++){
        for (j=0;i + j <= n;j++){
            if (i == 0&&j == 0) continue;
            if (i == 0) dp[i][j] = dp[i][j - 1] + a[i + j].fs*abs(a[i + j].sc - (n - j + 1));
            else if (j == 0) dp[i][j] = dp[i - 1][j] + a[i + j].fs*abs(a[i + j].sc - i);
            else{
                dp[i][j] = max(dp[i][j],dp[i - 1][j] + a[i + j].fs*(abs(a[i + j].sc - i)));
                dp[i][j] = max(dp[i][j],dp[i][j - 1] + a[i + j].fs*(abs(a[i + j].sc - (n - j + 1))));
            }
        }
    }
    ll maxx = 0;
    for (i=0;i<=n;i++) maxx = max(maxx,dp[i][n - i]);
    cout<<maxx;
}


Measured memory_bytes: 26268
using System;
using System.Collections.Generic;

namespace atCoder
{
    class Program
    {
        enum Type {
            Up,
            Even,
            Down
        }

        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] temp = Console.ReadLine().Split(' ');
            List<int> a = new List<int>();

            for (int i = 0; i < n; i++)
            {
                a.Add(int.Parse(temp[i]));
            }

            KeyValuePair<Type, List<int>> kvp = new KeyValuePair<Type, List<int>>();
            List<int> list = new List<int>();
            int count = 0;

            for (int i = 0; i < n; i++)
            {
                list.Add(a[i]);

                if (list.Count == 1)
                {
                    kvp = new KeyValuePair<Type, List<int>>(Type.Even, list);

                    count++;
                }
                else
                {
                    list.Add(a[i]);

                    if (kvp.Key == Type.Even)
                    {
                        if (a[i - 1] < a[i])
                        {
                            kvp = new KeyValuePair<Type, List<int>>(Type.Up, kvp.Value);
                        }
                        else if (a[i] < a[i - 1])
                        {
                            kvp = new KeyValuePair<Type, List<int>>(Type.Down, kvp.Value);
                        }
                    }

                    if (i + 1 < a.Count)
                    {
                        if (kvp.Key == Type.Up && a[i + 1] < a[i])
                        {
                            list.Clear();
                        }
                        else if (kvp.Key == Type.Down && a[i] < a[i + 1])
                        {
                            list.Clear();
                        }
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 21216
import sys
from itertools import accumulate
stdin = sys.stdin.readlines()
N, M, Q = map(int, stdin[0].split())
LR = [[0 for _ in range(N-i)] for i in range(N)]
for L,R in (map(int, line.split()) for line in stdin[1:M+1]):
  LR[L-1][R-L] += 1
for i in range(N-2,-1,-1):
  acc = accumulate(LR[i])
  next(acc)
  for j in range(1, N-i):
    LR[i][j] = next(acc) + LR[i+1][j-1]

sys.stdout.write("\n".join(map(str, 
  (LR[p-1][q-p] for p,q in (map(int, line.split()) for line in stdin[M+1:]))
)))


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

int main()
{
  int N, K, ans = 1;
  cin >> N >> K;

  for (int i = 0; i < N; i++)
    ans = min(ans * 2, ans + K);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[2*n];
    for(int i=0;i<2*n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+2*n,greater<int>());
    ll sum=0;
    for(int i=0;i<2*n;i+=2)
    {
        sum += min(a[i],a[i+1]);
    }
    cout<<sum<<"\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
    scanf("%s",s+1);
    for(int i=1; i<=strlen(s+1); i++) {
        if(i%2) {
            printf("%c",s[i]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;
ll M = 1e18;

using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 1;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	if (a[0] == 0) {
		cout << "0";
		return 0;
	}
	for (int i = 0;i < n;i++) {
		if (M / ans < 1 or M/ans<a[i]) {
			cout << "-1";
			return 0;
		}
		if(i!=n)ans *= a[i];
	}
	cout << ans;

}


Measured memory_bytes: 4040
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	static int w;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		w = Integer.parseInt(sa[1]);
		int[] a = new int[h];
		int[] b = new int[h];
		for (int i = 0; i < h; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]) - 1;
			b[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		TreeMap<Integer, Integer> map = new TreeMap<>();
		TreeSet<Obj> set = new TreeSet<>();
		for (int i = 0; i < w; i++) {
			map.put(i, i);
			set.add(new Obj(i, i, 0));
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < h; i++) {
			SortedMap<Integer, Integer> sub = map.subMap(a[i], b[i]);
			for (Integer key : sub.keySet()) {
				int s = sub.get(key);
				set.remove(new Obj(s, key, key - s));
			}
			if (!map.containsKey(b[i])) {
				if (!sub.isEmpty()) {
					int s = sub.get(sub.lastKey());
					map.put(b[i], s);
					set.add(new Obj(s, b[i], b[i] - s));
				}
			}
			sub.clear();
			int ans = set.first().d;
			if (ans == Integer.MAX_VALUE) {
				pw.println(-1);
			} else {
				pw.println(set.first().d + i + 1);
			}
		}
		pw.flush();
	}

	static class Obj implements Comparable<Obj> {
		int s, e, d;

		public Obj(int s, int e, int d) {
			this.s = s;
			this.e = e;
			if (e == w) {
				this.d = Integer.MAX_VALUE;
			} else {
				this.d = d;
			}
		}

		@Override
		public int compareTo(Obj o) {
			if (d != o.d) {
				return d - o.d;
			}
			return e - o.e;
		}
	}
}


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

using namespace std;

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == i) {
      swap(a[i], a[i + 1]);
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000, MD = 1000000007;

int aa[N];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	sort(aa, aa + n, greater<>());
	long long ans = 0;
	for (int i = 0; i < n; i++)
		ans = (ans + (long long) (i + 2) * aa[i]) % MD;
	while (--n)
		ans = ans * 4 % MD;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4404
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        System.out.printf("%d %d %.10f\n", a/b,a%b,(double)a/(double)b);
    }
}


Measured memory_bytes: 26292
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
#define INF 1000000007
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;

V eachDigits(string s){
    const int l = s.size();
    V xs(l);
    for(int i = 0; i < l; i++){
        xs[i] = s[i] - '0';
    }
    return xs;
}

long calc(const V& xs, int b){
    long x = 0;
    long y = 0;
    for(int i = 0; i < xs.size() ; i++){
        y = y * 10 + xs[i];
        if(b >> i & 1){
            x += y;
            y = 0;
        }
    }
    x += y;
    return x;
}

long solve(string s){
    const V& xs = eachDigits(s);
    long t = 0;
    int bit = 1 << (s.size() - 1);
    for(int i = 0; i < bit; i++){
        t += calc(xs, i);
    }
    return t;
}

int main (int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int ans = 0;
            if (A == B)
            {
                ans = A + B;
            }
            else if (A > B)
            {
                ans = A + (A - 1);
            }
            else
            {
                ans = B + (B - 1);
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
implicit none
integer(8):: n, i, ans, k
REAL(8),allocatable,dimension(:):: a

ans=0
k=0

read (5,*) n
allocate(a(n))
read(5,*) (a(i),i=1,n)

call heapsort(n,a)

do i=n,1,-1
    if(mod(n-i,2)==0)then
        ans=ans+a(i)
    else
        ans=ans-a(i)
    endif
enddo

write(6,"(i0)") ans

end

!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    double precision,intent(inout) :: array(1:n)

    integer ::i,k,j,l
    double precision :: t

    if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
    endif

    if(n.eq.1)return
        l=n/2+1
        k=n
        do while(k.ne.1)
            if(l.gt.1)then
                l=l-1
                t=array(L)
            else
                t=array(k)
                array(k)=array(1)
                k=k-1
                if(k.eq.1) then
                    array(1)=t
                    exit
                endif
            endif
            i=l
            j=l+l
            do while(j.le.k)
                if(j.lt.k)then
                    if(array(j).lt.array(j+1))j=j+1
                endif
                if (t.lt.array(j))then
                    array(i)=array(j)
                    i=j
                    j=j+j
                else
                    j=k+1
                endif
            enddo
            array(i)=t
    enddo
    return
end subroutine heapsort


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = sum(b)
for i in range(n-1):
  if a[i]+1 == a[i+1]:
    s += c[a[i]-1]
print(s)

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

int main(){
    long n,m,cnt=0;
    cin >> n >> m;
    long a[n]={};
    priority_queue<int> que;
  for(int i=0;i<n;i++){
      cin >> a[i];
     que.push(a[i]);
  }
  for(int i=0;i<m;i++){
    int c = que.top();
    que.pop();
    que.push(c/2);
  }
   while (!que.empty()) {
    int d = que.top();
    cnt += d;
    que.pop();
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1660
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, k = LI()
    dp = [0] * (k + 1)
    for i in range(k, 0, -1):
        if i < 3:
            dp[i] += pow(k // i, n, mod)
            dp[i] %= mod
            if i != 1:
                dp[1] -= dp[i]
                dp[1] %= mod
        else:
            dp[i] += pow(k // i, n, mod)
            dp[i] %= mod
            j = 2
            while j ** 2 <= i:
                if i % j == 0:
                    dp[j] -= dp[i]
                    dp[j] %= mod
                    m = i // j
                    if m != j:
                        dp[m] -= dp[i]
                        dp[m] %= mod
                j += 1
            dp[1] -= dp[i]
            dp[1] %= mod
    ans = 0
    for i in range(k + 1):
        ans += i * dp[i]
        ans %= mod
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 78432
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int n, x, y;
vector<int> a;

int get_min_score(int nowx, int nowy, int index);

/*
//ｘはindex<=i<nのあいだのカードから1枚選ぶ
int get_max_score(int nowx, int nowy, int index)
{
    if (index == n - 1)
    {
        return (abs(a[n - 1] - nowy));
    }
    int tmp = abs(a[n - 1] - nowy);
    for (int i = index; i < n - 1; i++)
    {
        tmp = max(tmp, get_min_score(a[i], nowy, i + 1));
    }
    return tmp;
}

int get_min_score(int nowx, int nowy, int index)
{
    if (index == n - 1)
    {
        return (abs(a[n - 1] - nowx));
    }
    int tmp = abs(a[n - 1] - nowx);
    for (int i = index; i < n - 1; i++)
    {
        tmp = min(tmp, get_max_score(nowx, a[i], i + 1));
    }
    return tmp;
}
*/

int main()
{
    cin >> n >> x >> y;
    rep(i, n)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    if (n >= 2)
    {
        cout << max(abs(y - a[n - 1]), abs(a[n - 1] - a[n - 2]));
    }
    else
    {
        cout << abs(y - a[n - 1]) << endl;
    }
    return 0;
}

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

int N;
int c[4];

double dp[310][310][310];

double solve(int c1, int c2, int c3) {
    if(c1 == 0 && c2 == 0 && c3 == 0) return 0;
    if(dp[c1][c2][c3] > 0) return dp[c1][c2][c3];

    double res = N;
    if(c1 >= 1) res += solve(c1 - 1, c2, c3) * c1;
    if(c2 >= 1) res += solve(c1 + 1, c2 - 1, c3) * c2;
    if(c3 >= 1) res += solve(c1, c2 + 1, c3 - 1) * c3;
    res /= c1 + c2 + c3;
    return dp[c1][c2][c3] = res;
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        c[a]++;
    }

    cout << fixed << setprecision(10) << solve(c[1], c[2], c[3]) << endl;

    return 0;
}

Measured memory_bytes: 225536
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007


int main(){
    int n;cin >> n;
    vector<int>a(100001);
    vector<int>b(100001);
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]!=0)b[a[i]-1]++;
        b[a[i]]++;
        if(a[i]!=100000) b[a[i]+1]++;
    }
    int max=0;
    for(int x:b){
        if(x>max)max=x;
    }
    
    cout << max << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(long i=0;i<(long)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main()
{
  int i=0,N=IN(),Q=IN(),H=N,W=N,col[N],row[N];long b=1l*(N-2)*(N-2);
  while(i<N){row[i]=col[i++]=N;}
  while(Q--)
  {
    int i,type=IN(),x=IN()-1;
    if(type==1){if(x<W){i=x;while(i<W-1){col[i++]=H;}W=x+1;}b-=col[x]-2;}
    else{if(x<H){i=x;while(i<H-1){row[i++]=W;}H=x+1;}b-=row[x]-2;}
  }
  return OUT(b),0;
}

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

void replace(string &str, int a, int b, string r) {
    int a_tmp = a;
    for (int i = a; i <= b;i++) {
        str.at(a_tmp) = r.at(i-a);
        a_tmp++;
    }
}
void print(string &str, int a, int b) {
    for (int i = 0; i <=b-a; i++)
        cout << str.at(i+a);
    cout << endl;
}
void reverse(string &str, int a, int b) {
    //a--;b--;
    auto begin = str.begin();
    auto end = str.begin();

    //advance(begin,a);
    //advance(end, b);
    begin += a;
    end += b+1;
    //auto e = advance(str.begin(),b);
    reverse(begin, end);
}
int main() {
    string str; cin >> str;
    int n; cin >> n;

    rep(i, n) {
        string q, r;
        int a, b;
        cin >> q >> a >> b;
        //a++; b++;
        if (q == "replace") {
            cin >> r;
            replace(str, a, b, r);
            //cout << str << endl;
        }
        else if(q == "print") {
            print(str, a, b);
            //cout << str << endl;
        }
        else if (q == "reverse") {
            reverse(str, a, b);
            //cout << str << endl;
        }
    }
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    char str[10];
    cin>>str;
    for(i=0;str[i]!='\0';i++)
    {
        if(str[i]=='9')
        {
            cout<<"1";
        }
        else
        {
            cout<<"9";
        }
    }
    cout<<endl;
    return 0;
}


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
using V = vector<ll>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll hcnt[300005],wcnt[300005];

int main() {
  ll H,W,M;
  cin>>H>>W>>M;
  map<P,ll> m;
  rep(i,M){
    ll h,w;
    cin>>h>>w;
    h--;
    w--;
    m[make_pair(h,w)]++;
    hcnt[h]++;
    wcnt[w]++;
  }
  ll hmax =0,wmax = 0;
  rep(i,300005){
    chmax(hmax,hcnt[i]);
    chmax(wmax,wcnt[i]);
  }
  map<ll,bool> hcheck,wcheck;
  ll t=0,s=0;
  rep(i,300005){
    if(hcnt[i]==hmax) {
      hcheck[i]=true;
      t++;
    }
    if(wcnt[i]==wmax) {
      wcheck[i]=true;
      s++;
    }
  }
  ll u = 0;
  for(auto x:m){
    if(hcheck[x.first.first]&&wcheck[x.first.second]) u++;
  }
  if(u==t*s) cout<<hmax+wmax-1<<endl;
  else cout<<hmax+wmax<<endl;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, q;
    cin >> n >> q;

    vector<pair<int, pair<int, int>>> events;
    for (int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;

        events.push_back({s - x, {1, x}});
        events.push_back({t - x, {-1, x}});
    }
    sort(events.begin(), events.end());

    multiset<int> st;
    int id = 0;
    for (int i = 0; i < q; i++) {
        int d;
        cin >> d;
        while (events.size() > id and events[id].first <= d) {
            if (events[id].second.first == 1)
                st.insert(events[id].second.second);
            else st.erase(st.find(events[id].second.second));
            id++;
        }
        if (st.empty())cout << -1 << endl;
        else cout << *st.begin() << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 21096
#include<iostream>
using namespace std;
int n,t[4];
int num[10000],h[10000],b[10000];
int ans[1000][4],ans_cnt;
int u[4];
int hcnt,bcnt;
int used[10];
void check(){
  //if(t[0]==0&&t[1]==1&&t[2]==3&&t[3]==2)cout<<'A'<<endl;
  int i;
  for(i=0;i<n;i++){
    u[3]=num[i]%10;
    u[2]=(num[i]/10)%10;
    u[1]=(num[i]/100)%10;
    u[0]=num[i]/1000;
 
    hcnt=bcnt=0;
 
    for(int j=0;j<4;j++){
      if(t[j]==u[j])hcnt++;
      else{
    for(int k=0;k<4;k++){
      if(t[j]==u[k]){
        bcnt++;
        break;
      }
    }
      }
    }
    if(!(hcnt==h[i]&&bcnt==b[i]))break;
  }
  if(i==n){
     
    for(int j=0;j<4;j++){
      ans[ans_cnt][j]=t[j];
       
    }
    ans_cnt++;
 
  }
 
}
 
void compute(int x){
  //cout<<x<<'A'<<endl;
  if(x==4)check();
  else{
    for(int i=0;i<10;i++){
      if(used[i]==1)continue;
      used[i]=1;
      t[x]=i;
      compute(x+1);
      used[i]=0;
    }
  }
}
 
int FLG;
int flg[5][5],v[4];
void check2(){
  // cout<<t[0]<<t[1]<<t[2]<<t[3]<<endl;
  for(int i=0;i<5;i++)for(int j=0;j<5;j++)flg[i][j]=0;
  for(int i=0;i<ans_cnt;i++){
    hcnt=bcnt=0;
    for(int j=0;j<4;j++){
      if(t[j]==ans[i][j])hcnt++;
      else{
    for(int k=0;k<4;k++){
      if(t[j]==ans[i][k]){
        bcnt++;
        break;
      }
    }
      }
    }
    if(flg[hcnt][bcnt]==1)return;
    else flg[hcnt][bcnt]=1;
  }
  if(FLG==0){
    for(int i=0;i<4;i++)v[i]=t[i];
    FLG=1;
  }
}
 
void compute2(int x){
  //cout<<x<<'A'<<endl;
  if(x==4)check2();
  else{
    for(int i=0;i<10;i++){
      if(used[i]==1)continue;
      used[i]=1;
      t[x]=i;
      compute2(x+1);
      used[i]=0;
    }
  }
}
 
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>num[i]>>h[i]>>b[i];
    for(int i=0;i<10;i++)used[i]=0;
    ans_cnt=0;
    compute(0);
    if(ans_cnt==1){
      cout<<ans[0][0]<<ans[0][1]<<ans[0][2]<<ans[0][3]<<endl;
      continue;
    }
    for(int i=0;i<10;i++)used[i]=0;
    FLG=0;
    compute2(0);
     
    if(FLG==0)cout<<"????"<<endl;
    else cout<<v[0]<<v[1]<<v[2]<<v[3]<<endl;
     
  }
  return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
int main()
{
	int X,A,B;
	scanf("%d %d %d",&X,&A,&B);
		if(B<=A) printf("delicious\n");
    	if(X+A>=B&&B>A) printf("safe\n");
    	if(X+A<B) printf("dangerous\n");	 
}
	

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

int main() {
  int N, M; cin >> N >> M;
  int sum = 0;
  for (int i = 0; i < M; i++) {
    int a; cin >> a;
    sum += a;
  }
  cout << max(-1, N - sum) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  string s, t;
  cin >> s >> t;
  s = s + s;
  REP(i, SZ(t)) {
    if (t == s.substr(i, SZ(t))) {
      yes();
    }
  }
  no();
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=[]
for i in range(n):
    p.append(tuple(map(int,input().split())))
c=[]
for i in range(m):
    c.append(tuple(map(int,input().split())))
for e in p:
    ans=0
    mh=float('inf')
    for i,f in enumerate(c,1):
        tmp=abs(e[0]-f[0])+abs(e[1]-f[1])
        if tmp<mh:
            mh=tmp
            ans=i
    print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int A;
    int B;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.nextInt();
        this.B = sc.nextInt();
    }
    
    //解答処理
    private int solve() {
        int answer = -1;
        
        for (int i=1; i<=1000; i++) {
        	double a = Math.floor(i*0.08);
        	double b = Math.floor(i*0.1);
        	if (A==a && B==b) {
        		answer = i;
        		break;
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35744
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	for i := 0; 2*i <= y; i++ {
		for j := 0; 4*j <= y; j++ {
			if 2*i+4*j == y {
				if i+j == x {
					fmt.Println("Yes")
					return
				}
			}
		}
	}
	fmt.Println("No")
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 1010

int N, K;
int dp[MAX_N][MAX_N] = {};

int dfs(int i = 0, int prev = 0) {
    if(i >= N) { return 1; }

    int& ret = dp[i][prev];
    if(~ret) { return ret; }
    ret = 0;

    for(int color = 1; color <= K; ++color) {
        if(prev == color) { continue; }
        ret += dfs(i+1, color);
    }
    return ret;
}

signed main()
{
    cin >> N >> K;
    MINUS(dp);
    printf("%lld\n", dfs());
    return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;


int main(){
    
    int N; cin >> N;
    map<string, int> M;
    for(int i = 0; i < N; i++){
        string x; cin >> x;
        if(M.find(x) == M.end()) M[x] = 1;
        else M[x]++;
    }
    
    int MAX = 0;
    //for(int i = 0; i < M.size(); i++) MAX = max(MAX, M[i]);
    for(auto i = M.begin(); i != M.end(); ++i) MAX = max(i->second, MAX);
    for(auto i = M.begin(); i != M.end(); ++i){
        if(i->second == MAX){
            cout << i->first << endl;
        }
    }
}

Measured memory_bytes: 25216
num = int(input())
S = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" ]
H = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" ]
C = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" ]
D = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" ]
numnum = 0
countnum = 0
while countnum < num:
    z = input()
    for a in z.split():
        if numnum == 0:
            flower = a
            numnum = 1
        else:
            no = a
            numnum = 0
    if flower == "S":
        S.remove(no)
    elif flower == "H":
        H.remove(no)
    elif flower == "C":
        C.remove(no)
    else:
        D.remove(no)
    countnum += 1
for i in S:
    print ( "S " + i )
for i in H:
    print ( "H " + i )
for i in C:
    print ( "C " + i )
for i in D:
    print ( "D " + i )


Measured memory_bytes: 5608
n = int(input())
a = []
flg = False
start = 1
ans = 0
for _ in range(n):
    a.append(int(input()))
for i in range(n):
    if a[start - 1] == 2:
        ans +=1
        flg = True
        break
    else:
        ans +=1
        start = a[start - 1]
if flg:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 51728