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

void solve() {
    int n; cin >> n;
    vi length(n);
    for (int& i : length) cin >> i;
    sort(length.begin(), length.end());

    int answer = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (length[i] != length[j] && length[j] != length[k] &&
                    length[k] != length[i] && length[i] + length[j] > length[k])
                    answer++;
            }
        }
    }
    cout << answer;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;
/*
class Manachar{
    string Odd_str,Even_str;
    vector<int> Even_leng, Odd_leng;
public:
    Manachar(string str){
        Odd_str = str;
        for(int a = 0;a < str.size();a++){
            Even_str.push_back(str.at(a));
            Even_str.push_back('#');
        }
        Even_str.pop_back();
        Odd_leng = vector<int>(Odd_str.size());
        Even_leng = vector<int>(Even_str.size());
        int i = 0, j = 0;
        while (i < Odd_str.size()) {
            while (i-j >= 0 && i+j < Odd_str.size() && Odd_str[i-j] == Odd_str[i+j]) ++j;
            Odd_leng[i] = j;
            int k = 1;
            while (i-k >= 0 && i+k < Odd_str.size() && k+Odd_leng[i-k] < j) Odd_leng[i+k] = Odd_leng[i-k], ++k;
            i += k; j -= k;
        }
        i = 0, j = 0;
        while (i < Even_str.size()) {
            while (i-j >= 0 && i+j < Even_str.size() && Even_str[i-j] == Even_str[i+j]) ++j;
            Even_leng[i] = j;
            int k = 1;
            while (i-k >= 0 && i+k < Even_str.size() && k+Even_leng[i-k] < j) Even_leng[i+k] = Even_leng[i-k], ++k;
            i += k; j -= k;
        }
        vector<int> vec;
        for(int a = 1;a < Even_leng.size();a+=2){
            vec.push_back(Even_leng.at(a)/2);
        }
        Even_leng = vec;
    }
    int getEven(int i){
        return Even_leng[i];
    }
    int getOdd(int i){
        return Odd_leng[i];
    }
    void show(){
        for(int a : Odd_leng)cout<<a<<" ";
        cout<<endl;
        for(int a : Even_leng)cout<<a<<" ";
        cout<<endl;
    }
};
*/
int main(){
    string s;cin >> s;
    map<char,LL> mp;
    for(char c : s)mp[c]++;
    LL ans = (s.size()*(s.size()+1))/2+1;
    for(auto c : mp){
        ans -= (c.second*(c.second+1)/2);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    size_t           n, m;
    map<string, int> data;
    cin >> n;
    for (auto i = 0u; i < n; ++i) {
        string s;
        cin >> s;
        ++data[s];
    }
    cin >> m;
    for (auto i = 0u; i < m; ++i) {
        string s;
        cin >> s;
        --data[s];
    }
    auto it = max_element(cbegin(data), cend(data), [](auto a, auto b){
        return a.second < b.second;
    });
    cout << (it->second <= 0 ? 0 : it->second) << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
import sys

lower_bound = bisect.bisect_left
upper_bound = bisect.bisect_right
INF = 0x3fffffff

n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]

X = {-INF, INF}
Y = {-INF, INF}
for i in a:
    Y.add(i[2])
for i in b:
    X.add(i[0])

X = list(sorted(X))
Y = list(sorted(Y))
n = len(X) - 1
m = len(Y) - 1
wallx = [[False] * m for i in range(n)]
wally = [[False] * m for i in range(n)]

for x1, x2, y1 in a:
    x1 = lower_bound(X, x1)
    y1 = lower_bound(Y, y1)
    x2 = upper_bound(X, x2) - 1
    for i in range(x1, x2):
        wally[i][y1] = True

for x1, y1, y2 in b:
    x1 = lower_bound(X, x1)
    y1 = lower_bound(Y, y1)
    y2 = upper_bound(Y, y2) - 1
    for i in range(y1, y2):
        wallx[x1][i] = True

cow = [[False] * m for i in range(n)]
cx = upper_bound(X, 0) - 1
cy = upper_bound(Y, 0) - 1
cow[cx][cy] = True
q = [(cx, cy)]
ans = 0

while q:
    x, y = q.pop()
    if not x or not y:
        print("INF")
        sys.exit()
    ans += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y])
    if x and not wallx[x][y] and not cow[x - 1][y]:
        cow[x - 1][y] = True
        q.append((x - 1, y))
    if y and not wally[x][y] and not cow[x][y - 1]:
        cow[x][y - 1] = True
        q.append((x, y - 1))
    if x + 1 < n and not wallx[x + 1][y] and not cow[x + 1][y]:
        cow[x + 1][y] = True
        q.append((x + 1, y))
    if y + 1 < m and not wally[x][y + 1] and not cow[x][y + 1]:
        cow[x][y + 1] = True
        q.append((x, y + 1))

print(ans)

Measured memory_bytes: 103616
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int n=s.length();
  int m=t.length();
  int dp[n+1][m+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=m;j++)
    {
      if(i==0 || j==0)
      {
        dp[i][j]=0;
      }
      else if(s[i-1]==t[j-1])
        dp[i][j]=dp[i-1][j-1]+1;
      else
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
  string ans="";
  int i=n,j=m;
  while(i!=0 && j!=0)
  {
    if(s[i-1]==t[j-1])
    { ans+=s[i-1];
     i--;j--;}
    else
    {
      if(dp[i][j-1]>dp[i-1][j])
      	j--;
      else
        i--;
    }
  }
  reverse(ans.begin(),ans.end());
  cout<<ans;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 != 0 && b % 2 != 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
   long long n,a,b,sum,max,min;
   cin >> n >> a >>b;
   if(a>b){
       cout << 0<<endl;
   }else if(n==1){
       if(a==b) cout << 1<<endl;
       else cout  << 0 << endl;
   }else{
       sum = (b-a)*(n-2) + 1;
       cout << sum <<endl;
   }
}

Measured memory_bytes: 256
import sys

#N = I()
#A = [LI() for _ in range(N)]

a, b = list(map(int,sys.stdin.readline().rstrip().split()))

if a > 0:
    print('Positive')
elif a <= 0 and b >= 0:
    print('Zero')
else:
    if (a+b)%2 == 0:
        print('Negative')
    else:
        print('Positive')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
struct Po{int x,y;}a[1010];
int f[5],n;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {scanf("%d %d",&a[i].x,&a[i].y);f[(((a[i].x+a[i].y)%2)+2)%2]++;}
	if (f[0]==0||f[0]==n){
		if (f[0]==n){
			cout<<"32"<<endl;cout<<"1 ";
			for (int i=30;i>=0;i--)cout<<(1<<i)<<' ';cout<<endl;
			for (int i=1,j;i<=n;i++){
				cout<<"U";a[i].y--;
				for (int j=30;j>=0;j--){
					if (abs(a[i].x)<abs(a[i].y)){
						if (a[i].y>0){cout<<"U";a[i].y-=(1<<j);}else{cout<<"D";a[i].y+=1<<j;}
					}else{
						if (a[i].x>0){cout<<"R";a[i].x-=(1<<j);}else{cout<<"L";a[i].x+=1<<j;}						
					}
				}
				cout<<endl;
			}
		}else{
			cout<<"31"<<endl;
			for (int i=30;i>=0;i--)cout<<(1<<i)<<' ';cout<<endl;
			for (int i=1,j;i<=n;i++){
				for (int j=30;j>=0;j--){
					if (abs(a[i].x)<abs(a[i].y)){
						if (a[i].y>0){cout<<"U";a[i].y-=(1<<j);}else{cout<<"D";a[i].y+=1<<j;}
					}else{
						if (a[i].x>0){cout<<"R";a[i].x-=(1<<j);}else{cout<<"L";a[i].x+=1<<j;}						
					}
				}
				cout<<endl;
			}
		}
	}else{
		cout<<"-1"<<endl;
	}	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define M 1000000007
int main(){
	int N;
	int i,j,k;
	cin>>N;
	vector<int> T(N),A(N);
	//cin>>N;
	for(i=0;i<N;i++) cin>>T[i];
	for(i=0;i<N;i++) cin>>A[i];
	vector<pair<int,int>> r(N);
	int maxx=0;
	long long int res=1;
	for(i=N-1;i>=0;i--){
		if(i==0||T[i]>T[i-1]) {
			r[i]=make_pair(T[i],T[i]);
			
		}
		else{
			
			r[i]=make_pair(1,T[i]);
		}
	}

	bool flag=true;
	maxx=0;
	for(i=0;i<N&&flag;i++){
		if(i==N-1||A[i]>A[i+1]){
			if(A[i]<r[i].first||A[i]>r[i].second) flag=false;
			else {
				r[i]=make_pair(A[i],A[i]);
				
			}
		}
		else{
			pair<int,int> t(1,A[i]);
			if(r[i].first==r[i].second&&(r[i].first>A[i])) flag=false;
			else {
				if(r[i].first!=r[i].second) r[i].second=min(t.second,r[i].second);
			}
		}
	}

	if(flag==false) cout<<0<<endl;
	else{

		for(i=0;i<N;i++){
			res*=(r[i].second-r[i].first+1);
			res%=M;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n;cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    vector<int> v;
    repi(i,1,n+1)v.emplace_back(i);
    int pidx=0;
    int qidx=0;
    int idx=0;
    do{
        bool flag=true;
        rep(i,n)if(v[i]!=p[i])flag=false;
        if(flag==true)pidx=idx;
        flag=true;
        rep(i,n)if(v[i]!=q[i])flag=false;
        if(flag==true)qidx=idx;
        idx++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(qidx-pidx)<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N, M = [int(x) for x in stdin.readline().rstrip().split()]
# 展望台iの標高
H = [int(x) for x in stdin.readline().rstrip().split()]
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]

dic = {}
for i in range(N):
    dic[i+1] = []

for A, B in AB:
    dic[A].append(B)
    dic[B].append(A)

ans = 0
i = len(dic)
while i > 0:
    key = i
    values = set(dic[i])
    near_H = [H[value-1] for value in values]
    if near_H:
        if H[key-1] > max(near_H):
            ans += 1
    else:
        ans += 1
    i -= 1

print(ans)


Measured memory_bytes: 116636
def gen(X):
    x = X
    yield x
    d = 1
    while True:
        yield X - d
        yield X + d
        d += 1
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))

    for x in gen(X):
        if x not in P:
            print(x)
            return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
#include <cstdio>
#include <cmath>
int n;
int main(){
scanf("%d",&n);
for(int i=0,j=11,k=0;i<n;i++){
 for(k=0;k!=2;j+=10)
  for(k=round(sqrt(j));k>2;k--)
   if(j%k==0) break;
 printf("%d ",j-10);
}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

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

	int n = 0;
	int count = 0;
	bool yn = true;
	string w;
	string memo[100];
	cin >> n;
	rep(i, n) {
		cin >> w;
		memo[i] = w;
		for (int j = 0; j < i; j++) {
			if (w == memo[j]) {
				count++;
			}
		}
		if (count >= 1) {
			yn = false;
		}
		if (i >= 1) {
			if (memo[i][0] != memo[i - 1][memo[i - 1].length() - 1]) {
				yn = false;
			}
		}
		count = 0;
	}
	if (yn == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
int main()
{
	int n;
	cin>>n;
	int a[n];
	long long sm=0;
	for(int i=0;i<n;i++)
	{cin>>a[i];
	cnt[a[i]]++;
	sm+=a[i];
	}
	int q;
	cin>>q;
	while(q--)
	{
	int x,y;
	cin>>x>>y;
	sm+=(y-x)*cnt[x];
	cnt[y]+=cnt[x];
	cnt[x]=0;
	cout<<sm<<endl;
	}	
	
    return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

vector<ll> pickdiv(ll n){
    vector<ll> res;
    for(ll i=1; i*i <=n;i++){
        if(n%i)continue;
        res.emplace_back(i);
        ll q = n/i;
        if(q != i){
            res.emplace_back(q);
        }
    }
    return res;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> v = pickdiv(N);
    vector<ll> u = pickdiv(N-1);
    //ll ans = 0;
    map<ll,ll> mp;
    for(auto& k:v){
        if(k == 1) continue;
        ll cur = N;
        while(cur >= 1){
            if(cur % k == 0){
                cur /= k;
            }else if(cur % k == 1){
                mp[k]++;
                break;
            }else{
                break;
            }
        }
    }
    for(auto& k:u){
        if(k == 1) continue;
        ll cur = N;
        while(cur >= 1){
            if(cur % k == 0){
                cur /= k;
            }else if(cur % k == 1){
                mp[k]++;
                break;
            }else{
                break;
            }
        }
    }
    cout << mp.size() << endl;
    /*REP(k,3,M+1){
        ll cur = N;
        while(cur >= 1){
            if(cur % k == 0){
                cur /= k;
            }else if(cur % k == 1){
                ans++;
                break;
            }else{
                break;
            }
        }
    }
    cout << ans << endl;*/
}

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

using namespace std;

#define MAXN 100010
#define PI acos(-1.0)
#define mo 1000000007
#define INF 0x3f3f3f3f
#define eps 1e-8
typedef long long LL;

int h, w, n, a[MAXN];
int ans[110][110];

int main()
{
    int i, j, k;
    scanf("%d %d", &h, &w);
    scanf("%d", &n);
    for(k = 1, i = 1, j = 1; k <= n; ++k)
        for(scanf("%d", a + k); a[k]; --a[k]){
            ans[i][j] = k;
            if(i & 1){
                if(j == w) ++i;
                else ++j;
            }
            else{
                if(j == 1) ++i;
                else --j;
            }
        }
    for(i = 1; i <= h; ++i){
        for(j = 1; j < w; ++j) printf("%d ", ans[i][j]);
        printf("%d\n", ans[i][j]);
    }
    return 0;
}


Measured memory_bytes: 384
import math

n = int(input())
for i in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    d = math.sqrt((xb - xa) ** 2 + (yb - ya) ** 2)
    if d < ra - rb:
        print(2)
    elif d < rb - ra:
        print(-2)
    elif d <= ra + rb:
        print(1)
    else:
        print(0)

Measured memory_bytes: 7636
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 1){
        cout << "IMPOSSIBLE";
    }
    else {
        int ans = (a + b)/2;
        cout << ans;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3

n = int(input())
ai = list(map(int, input().split()))
assert len(ai) == n
ai = sorted(ai, reverse=True)

ali = 0
bob = 0
for i in range(n):
    if i % 2 == 0:
        ali += ai[i]
    else:
        bob += ai[i]

print(ali - bob)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
int main()
{
    ll a,b,c,i,j,k;
    string s,d;
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cin>>ar[i];
    }
    j=999999999999;
    k=0;
    for(i=1;i<=a;i++)
    {
        j=min(j,ar[i]);
        if(j==ar[i])
        {
            k++;
        }
    }
    cout<<k<<endl;
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main(){
   int  a,b,n;
    cin >> a >> b;
n=(a+b)/2; 
if((a+b)%2==0){ 

    cout << n <<endl;
}
else cout << "IMPOSSIBLE" <<endl;
    return 0;   
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;
int main(int argc,char** argv){
  int K;
  cin >> K;
  int o,e;
  e = K / 2;
  o = ( K + 1) / 2;
  cout << e * o << endl;
  
  return 0;
}


Measured memory_bytes: 256
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 500000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int d[505][505];
int v[505][505];
bool used[505][505]={};
int val[100005][2];
int main()
{
	srand((unsigned int)time(NULL));
	while(1)
	{
		int lim; scanf("%d",&lim); if(!lim) return 0;
		for(int q=0;q<2;q++)
		{
			for(int i=0;i<505;i++) for(int j=0;j<505;j++) d[i][j]=INF;
			for(int i=0;i<100005;i++) val[i][q]=INF;
			int w,h,x,y;
			scanf("%d%d%d%d",&w,&h,&x,&y);
			x--; y--;
			for(int i=0;i<h;i++)
			{
				for(int j=0;j<w;j++)
				{
					scanf("%d",&v[i][j]);
				}
			}
			memset(used,0,sizeof(used));
			priority_queue<P1,vector<P1>,greater<P1> >que;
			int cur=0;
			val[cur++][q]=0;
			que.push(mp(v[y][x],mp(y,x)));
			while(!que.empty())
			{
				P1 p=que.top(); que.pop();
				int num=p.f; int x=p.s.f; int y=p.s.s;
				if(used[x][y]) continue;
				used[x][y]=true;
				val[cur][q]=max(val[cur-1][q],num);
				cur++;
				int dx[4]={0,1,0,-1};
				int dy[4]={1,0,-1,0};
				for(int i=0;i<4;i++)
				{
					int nx=x+dx[i];
					int ny=y+dy[i];
					if(!(0<=nx && nx<h)) continue;
					if(!(0<=ny && ny<w)) continue;
					if(used[nx][ny]) continue;
					que.push(mp(v[nx][ny],mp(nx,ny)));
				}
			}
		}
		int ret=INF;
		for(int i=0;i<=lim;i++)
		{
			ret=min(val[i][0]+val[lim-i][1],ret);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 4844
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S,T; cin >> S >> T;
    S += T;
    int a = stoi(S);
    rep(i,1000) {
        if (i*i==a) {
            cout << "Yes" << ln;
            return 0;
        }
    }

    cout << "No" << ln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;

int w[110];

main(){
  cin>>n;
  int sum=0;
  rep(i,n){
    cin>>w[i];
    sum+=w[i];
  }

  int ans=INF;
  int sum2=0;
  rep(i,n){
    sum2+=w[i];
    sum-=w[i];
    ans=min(ans,abs(sum-sum2));
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        n: usize,
        v: [i32; n],
        c: [i32; n],
    }
    let mut ret = 0;
    for i in 0..n {
        ret += (v[i] - c[i]).max(0);
    }
    println!("{}", ret);
}


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

using namespace std;

int main(){
    long long int N,mx=0;
    cin >> N;
    vector<long long int> a(N);
    map<long long int,long long int> mp;

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

    for(int i=0;i<N;i++){
        long long int tmp = a[i],now=0;
        if(tmp==0){
            continue;
        }
        while(0<tmp){
            if(tmp%2==1){
                mp[now]++;
            }
            tmp /= 2;
            now++;
        }
        mx = max(mx,now);
    }

    for(int i=0;i<N;i++){
        long long int ans = 0;
        for(int j=0; j<mx; j++){

            if(a[i] != 0 && a[i]%2==1){

                if(mp[j]%2==0){
                    ans += pow(2,j);
                }

            }else{

                if(mp[j]%2==1){
                    ans += pow(2,j);
                }

            }

            a[i] /= 2;
        }

        if(i==0){
            cout << ans;
        }else{
            cout << " " << ans;
        }
        
    }

    cout << endl;


}

Measured memory_bytes: 4792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

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

    int64_t A;
    std::string B;
    std::cin >> A >> B;

    int64_t ip, dp;
    std::string b="";
    for(int i=0; i<B.size(); i++){
        if(B[i]=='.'){
            ip = std::stoi(b);
            b = "";
        }else{
            b.push_back(B[i]);
        }
    }
    dp = std::stoi(b);

    std::cout << A*ip + A*dp/100;

    return 0;
}


Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException, NumberFormatException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine().trim());
        int[] arr = new int[n];
        String[] s = br.readLine().trim().split("\\s+");
        for(int i=0 ; i<n ; i++)
            arr[i] = Integer.parseInt(s[i]);

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(arr[0] - arr[1]);
        for(int i=2 ; i<n ; i++)
        {
            int x = dp[i-1] + Math.abs(arr[i] - arr[i-1]);
            int y = dp[i-2] + Math.abs(arr[i] - arr[i-2]);
            dp[i] = Math.min(x, y);
        }

        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 34008
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        /*
        int N = 6;
        int[] A = {382253568,723152896,37802240,379425024,404894720,471526144};
        */

        boolean even = true;

        int cnt = 0;

        while (true) {

            for (int i = 0; i < N; i++) {

                if (A[i] % 2 != 0) {
                    even = false;
                }

            }

            if (even) {
                for (int i = 0; i < N; i++) {
                    A[i] = A[i] / 2;
                }

                cnt++;

            } else {
                break;
            }
        }

        System.out.println(cnt);

    }

}


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

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	int ans = 0;
	sort(p.begin(), p.end());
	rep(i, n) {
		if (i == n - 1) ans += p[i] / 2;
		else ans += p[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int n, k, ans = 0;
    cin>>n>>k;
    while(n > 0){
        ans++;
        n /= k;
    }
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
res = int()
co = 0
now = -1
flg = 0

while True:
    now += 1
    if now == n-1 and flg == 1:
        res += (co+1)//2
        break
    if now == n-1:
        break
    if l[now] == l[now+1]:
        co += 1
        flg = 1
        continue
    else:
        res += (co+1) // 2
        co = 0

print(res)


Measured memory_bytes: 3060
n, k = list(map(int, input().split()))
k -= 1
s = input()

if s[k] == 'A':
    sr = 'a'
elif s[k] == 'B':
    sr = 'b'
else:
    sr = 'c'
    
s1 = s[:k] + sr + s[k+1:]

print(s1)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
int main(void)
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        for (int j = i+1; j < s.size(); j++) {
            if (s[i] == s[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
    }
    
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
for h in range(1,3501):
    for n in range(1,h):
        if (4*h*n-N*h-N*n)>0 and (h*n)%(4*h*n-N*h-N*n)==0:
            print(h,n,h*n*N//(4*h*n-N*h-N*n))
            exit()


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    if(s == "Sunny")
        cout << "Cloudy\n";
    if(s == "Cloudy")
        cout << "Rainy\n";
    if(s == "Rainy")
        cout << "Sunny\n";
    return 0;
}


Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;

int main(){
	vector<ll> time;
	for(ll i1=0;i1<3;i1++){
		ll temp;
		cin>>temp;
		time.push_back(temp);
	}
	sort(time.begin(),time.end());
	cout<<time[0]+time[1]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int aa[123456], bb[123456], cc[123456];
int main() {
	long long n, a, b, c = 0, sum = 0, num = 0, gum = 0, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; sum += a;	aa[h] = a;
	}
	for (int h = 0; h < n; h++) {
		cin >> b; num += b; bb[h] = b;
	}
	if (sum < num) {
		cout << -1 << endl;
		cin >> n; return 0;
	}
	for (int h = 0; h < n; h++) {
		if (aa[h] < bb[h]) {
			gum += bb[h] - aa[h]; ans++;
		}
		else{
			cc[c] = aa[h] - bb[h]; c++;
		}
	}
	sort(cc, cc + n);
	if (gum <= 0) {
		cout << ans << endl;
		cin >> n; return 0;
	}
	for (int h = n; h > 0; h--) {
		gum = gum - cc[h - 1]; ans++;
		if (gum <= 0) {
			cout << ans << endl;
			cin >> n; return 0;
		}
	}
	cin >> n;
}

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

N = INT()

print(0.5 if N%2 == 0 else ceil(N/2)/N)

Measured memory_bytes: 62572
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main(){
  int N;
  cin >> N;
  rep(i,8){
    int div = 9 - i;
    if(N%div == 0){
      N/=div;
      break;
    }
  }
  // cout << N << endl;
  rep(i,8){
    int div = 9 - i;
    if(N%div == 0){
      N/=div;
      break;
    }
  }
  bool f = false;
  if(N==1) f = true;
  answer(f);
  return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i % 2 == 0 && a % 2 == 1)
      ans++;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int main() {
  int stack[10];
  int num = 0;
  int input;
  while (cin >> input) {
    if (input == 0) {
      cout << stack[--num] << endl;
    } else {
      stack[num++] = input;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_N = 100000;



int main(int argc, char *args[]) {
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	int score = 0;
	rep(i, n - 1) {
		if (s[i] == s[i + 1])score++;
	}
	int ans = min(score + 2 * k, n - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <functional>
#include <stack>

int main (){
	int n;

	std::cin >> n;

	int odd = n / 2 + n % 2;

	std::cout << 1.0 * odd / n << std::endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    ret = 0
    magni = 1
    for j in range(60):
        bin_cnt = [0, 0]
        for i in range(n):
            a[i], b = divmod(a[i], 2)
            bin_cnt[b] += 1
        x, y = bin_cnt
        ret += x * y * magni % mod
        magni = magni * 2 % mod

    ret %= mod

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125624
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        double x=0.0,y=0.0;
        double angle = Math.PI/2.0;
        while(true){
            String[] str = sc.nextLine().split(",");
            if(str[0].equals("0")&&str[1].equals("0"))break;
            int r=Integer.parseInt(str[0]);
            int t=(-1)*Integer.parseInt(str[1]);
            x+=(double)r*Math.cos(angle);
            y+=(double)r*Math.sin(angle);
            angle += (double)t*Math.PI/180;
        }
        System.out.println((int)x);
        System.out.println((int)y);
    }
}

Measured memory_bytes: 17148
#include<stdio.h>
#include<algorithm>
int a[10000],n;
int F(int k,int x)
{
	int i,j,r=0,t=a[k];
	a[k]=x;
	for(i=k;i>0&&a[i]==a[i-1];--i);
	for(j=k;j+1<n&&a[j]==a[j+1];++j);
	a[k]=t;
	if(j-i<3)return 0;
	r=j-i+1;
	for(;;)
	{
		if(--i<0||++j>=n||a[i]-a[j])break;
		t=2;
		for(;i>0&&a[i]==a[i-1];--i)++t;
		for(;j+1<n&&a[j]==a[j+1];++j)++t;
		if(t<4)break;
		r+=t;
	}
	return r;
}
int main()
{
	int i,r;
	while(scanf("%d",&n),n)
	{
		for(r=i=0;i<n;++i)scanf("%d",a+i);
		for(i=0;i<n;++i)
		{
			r=std::max(r,F(i,(a[i])%3+1));
			r=std::max(r,F(i,(a[i]+1)%3+1));
		}
		printf("%d\n",n-r);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
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; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;


int main(){
    int x,y;cin >> x >> y;
    for(int i=0;i<1000;i++){
        for(int j=0;j<1000;j++){
            if(i*2+j*4==y && i+j==x){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
# python3

#===============================================================================
from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil
from sys import stdin, stdout

def ilist():
    return [int(x) for x in stdin.readline().strip().split(" ")]
def iint():
    return int(stdin.readline().strip())
def istr():
    return stdin.readline().strip()
##==============================================================================


def solve():
    pass


if __name__ == '__main__':
    N, M = ilist()
    H = ilist()
    AdjList = [set() for _ in range(N)]
    for _ in range(M):
        A, B = ilist()
        A -= 1
        B -= 1
        AdjList[A].add(B)
        AdjList[B].add(A)
    res = [0] * N
    for u in range(N):
        c = 1
        for v in AdjList[u]:
            if H[u] <= H[v]:
                c = 0
                break
        res[u] = c
    print(sum(res))


Measured memory_bytes: 104412
#include <bits/stdc++.h>
  #define endl "\n"
  #define ll long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define mod 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define pb push_back
  #define f first
  #define se second
  
  using namespace std;
  ll arr[1000000]={0};
  ll arr2[1000000]={0};

  ll func(ll n,ll cur){
    if(cur==n)
      return 0;
    if(cur>n)
      return inf;
    if(arr2[cur]!=-1)
      return arr2[cur];

    ll sum=0;

    sum=min(func(n,cur+1)+abs(arr[cur]-arr[cur+1]),  func(n,cur+2)+abs(arr[cur]-arr[cur+2]));

    // cout<<"cur is: "<<cur<<" and sum is: "<<sum<<endl;
    arr2[cur]=sum;
    return sum;
  }


  int main()
  {
    std::ios::sync_with_stdio(false);
    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;
    mem(arr2,-1);

    cin>>n;

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

    cout<<func(n-1,0);

    return 0;
  }

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9 + 7;

template <typename T>
T pow_mod( T n, T p )  // n^p % m
{
    if( p == 0 ) return 1;
    if( p%2 == 1 ) return pow_mod(n, p-1) * n % MOD;
    else{
        T tmp = pow_mod(n, p/2) % MOD;
        return tmp*tmp % MOD;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    REP(i, n+1) cin >> a[i];

    int duplicate;
    vector<int> num_appeared(n+1, 0);
    REP(i, n+1){
        ++num_appeared[a[i]];
        if(num_appeared[a[i]] == 2) duplicate = a[i];
    }

    int l = 1e+9, r = 0; // l, r: 同じ数字が現れる位置 (l < r)
    REP(i, n+1){
        if(a[i] == duplicate){
            l = min(l, i);
            r = max(r, i);
        }
    }

    int m = l + n-r;
    vector<long long> mCk(m+1);
    mCk[0] = 1;
    FOR(i, 1, m+1){
        mCk[i] = (mCk[i-1] * (m-i+1)) % MOD * pow_mod<long long>(i, MOD-2) % MOD;
        mCk[i] %= MOD;
    }

    long long ans = 1;
    FOR(i, 1, n+2){ // i 枚取るとき
        ans *= (n+1-(i-1)) * pow_mod<long long>(i, MOD-2) % MOD;
        ans %= MOD;
        if(m < i-1) cout << ans << endl;
        else{
            cout << (ans-mCk[i-1]+MOD)%MOD << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int table[105];

int main(){

	for(int i = 0; i < 105; i++){

		table[i] = 0;
	}

	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);

	table[a]++,table[b]++,table[c]++;

	int ans = 0;
	for(int i = 0; i < 105; i++){

		if(table[i] != 0){
			ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,n; cin>>x>>n;
	set<int> st;
	for(int i=0;i<n;i++){
		int val; cin>>val;
		st.insert(val);
	}
	int mn=INT_MAX, ret=-1;
	for(int i=0;i<=200;i++){
		if(st.count(i)) continue;
		int diff = abs(x-i);
		if(mn > diff){
			ret = i;
			mn=diff;
		}
	}
	cout<<ret<<endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	string a, b;
	cin >> a >> b;
	bool ans = false;
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) ans = true;
	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


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

MOD = 10 ** 9 + 7


def main():
    W, H, x, y = map(int, input().split())

    # if (W % 2 == 0 and x == W // 2 and y != H and y != 0) or (H % 2 == 0 and y == H // 2 and x != W and x != 0):
    if (W % 2 == 0 and x == W // 2) and (H % 2 == 0 and y == H // 2):
        print(W*H/2, 1)
    else:
        print(W*H/2, 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38728
#include<iostream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>

#define ll long long

using namespace std;

int N, sum;
vector<int> a;

int main()
{
    cin >> N;
    a.resize(N);
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    for (int i=0; i<N; i++) {
        if (i % 2 > 0) {
            sum -= a[N - i - 1];
        } else {
            sum += a[N - i - 1];
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int q;cin>>q;
  int l[q+10];
  int r[q+10];
  int max_r=0;
  REP(i,q) {
    cin>>l[i]>>r[i];
    max_r=max(max_r,r[i]);
  }
  int max_i=(max_r-1)/2;

  int S[max_i+10];

  bitset<1000000> is_primary(0);
  for(int i=2;i<=max_r;++i) is_primary.set(i);
  for(int i=2;i<=max_r;++i) {
    if(is_primary[i]) {
      for(int j=2*i;j<=max_r;j+=i) {
        is_primary.reset(j);
      }
    }
  }

  // pr("====");

  S[0]=0;
  for(int i=1;i<=max_i;++i) {
    if(is_primary[2*i+1]&&is_primary[i+1]) S[i]=S[i-1]+1;
    else S[i]=S[i-1];
    // pr(2*i+1,i+1,S[i],is_primary[2*i+1]&&is_primary[i+1]);
  }

  // pr("====");

  // for(int i=1;i<=max_i;++i) {
  //   pr(2*i+1,S[i]);
  // }

  REP(i,q) {
    int R = (r[i]-1)/2;
    int L = max((l[i]-1)/2,1);
    // pr(S[R],S[L-1],S[R]-S[L-1]);
    pr(S[R]-S[L-1]);
  }

  return 0;
}


Measured memory_bytes: 1792
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)

	const items = args.slice(1, n + 1).map((arg, index) => [arg[0], arg[1], index + 1]).sort((a, b) => {
		const t1 = parseInt(a[1], 10)
		const t2 = parseInt(b[1], 10)

		if (a[0] < b[0]) return -1
		else if (a[0] > b[0]) return 1
		else if (t1 > t2) return -1
		else if (t1 < t2) return 1
		return 0
	})

	for (let i = 0; i < items.length; i++) {
		console.log(items[i][2])
	}
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7800
#include <iostream>
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
using namespace std;


int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,n,m,k;
    ll t;
    cin>>n;
 ll s=0;
   
        s=(n/500)*1000;
        n=n%500;
        s+=(n/5)*5;
    
   cout<<s;
}

Measured memory_bytes: 256