akhauriyash/Code-Regression huggingface dataset:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True

n=input1()

count=0
for i in range(1,n+1):
	if len(str(i))%2==1:
		count+=1
print(count)
















Measured memory_bytes: 12376
#include <stdio.h>
#define INF 1000000
#define min(a,b) ((a)<(b)?(a):(b))

void print(void);

int n;
int d[150][150];

int main(){

  int i,j,u,k,v,c;

  for(i=0;i<150;i++){
    for(j=0;j<150;j++){
      d[i][j]=INF;
    }
    d[i][i]=0;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      d[u][v]=c;
    }
  }

  for(k=0;k<n;k++){
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }

  print();

  return 0;
}

void print (void){

  int i;

  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[0][i]);
  }

}

Measured memory_bytes: 688
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0
for a in range(min((A+1, X//500+1))):
    for b in range(min((B+1, (X-500*a)//100+1))):
        if (X - 500 * a - 100 * b) // 50 <= C: res += 1

print(res)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n, a, b, c;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d", &a, &b, &c);
            if ((a == 100 || b == 100 || c == 100) || ((a + b)/2 >= 90) || ((a+b+c)/3 >= 80)) printf("A\n");
            else if (((a+b+c)/3 >= 70) || ((a+b+c)/3 >= 50 && (a >= 80 || b >= 80))) printf("B\n");
            else printf("C\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n;
    cin>>n;
    double ans=0;
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        p[i]={x,y};
    }
    sort(p,p+n);
    do{
        for(int i=0;i<n-1;i++){
            double dx=p[i].first-p[i+1].first;
            double dy=p[i].second-p[i+1].second;
            ans+=sqrt(dx*dx+dy*dy);
        }
    }while(next_permutation(p,p+n));
    for(int i=1;i<=n;i++){
        ans/=i;
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
import sys

n, x = map(int, input().split())
A = list(map(int, input().split()))
#print(A)

B = sorted(A)
s = sum(A)

if x > s:
    #i = A.index(B[0])
    #print(' '.join(map(str, A[0:i])) + ' ' + str(x-s+B[0]) + ' ' + ' '.join(map(str, A[i+1:n])))
    print(n-1)
    sys.exit(0)
elif x == s:
    #print(' '.join(A))
    print(n)
    sys.exit(0)

for i in range(n-1,0,-1):
    #print(B[0:i])
    v = sum(B[0:i])
    #print(v, x)
    if v <= x: break

if i == 1:
    if B[0] == x:
        print(1)
    else:
        print(0)
    sys.exit(0)

print(i)


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, X, T;
    cin >> N >> X >> T;
    int ans = ((N + X - 1) / X) * T;
    cout << ans << '\n';
    return 0;
}

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

map<string,int> mp;
int main() {
    int n, mx = 0;
    cin >> n;
    for(int i=1; i<=n; i++) {
        string s;
        cin >> s;
        if(mp.find(s) == mp.end())
            mp[s] = 0;
        mp[s]++;
        mx = max(mx, mp[s]);
    }
    for(auto a:mp) {
        if(a.second == mx)
            cout << a.first << "\n";
    }
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
ll n;

void solve()
{
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; ++i)
        ans += i * (n - i + 1);
    for (int i = 1; i < n; ++i)
    {
        ll u, v;
        cin >> u >> v;
        if (u > v)
            swap(u, v);
        ans -= u * (n - v + 1);
    }
    cout << ans << endl;
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3600
# E
N, D = map(int, input().split())
A_list = list(map(int, input().split()))

# minimum spanning tree

res = 0

# Prim based
B_list = [0]*N
for i in range(N):
    B_list[i] = A_list[i] + D*i
    
C_list = [0]*N
for i in range(N):
    C_list[i] = A_list[i] + D*(N-i)
    
# cummin seen from left
B_cummmin = [0]*N
R = B_list[N-1]
BA = N-1
for i in range(N-1, -1, -1):
    if B_list[i] <= R:
        R = B_list[i]
        BA = i
    B_cummmin[i] = BA

# cummin seen from right
C_cummmin = [0]*N
R = C_list[0]
CA = 0
for i in range(N):
    if C_list[i] <= R:
        R = C_list[i]
        CA = i
    C_cummmin[i] = CA

# start from 0
start = 0
while start < N-1:
    end = B_cummmin[start+1]
    target = C_cummmin[start]
    res += D*(end - target) + A_list[target] + A_list[end]
    for i in range(start+1, end):
        ds = D*(i - target) + A_list[target] + A_list[i]
        de = D*(end - i) + A_list[end] + A_list[i]
        res += min(ds, de)
    start = end

print(res)

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

int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  
  if (N % (A + B) < A){
    cout << (N / (A + B)) * A + N % (A + B) << endl;
  }
  else {
    cout << (N / (A + B)) * A + A << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,L;
	scan(N>>L);
	int sum=N*(N-1)/2+L*N;
	if(L+N-1<0) prin(sum-(L+N-1));
	else if(L>0) prin(sum-L);
	else prin(sum);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int d[8][8][8][8];
int sx,sy;
int gx,gy;
int dist[10][10];
int n;

#define MAX 10000

int solve(int now, int flag){
  if(now == n-1) return 0;
  int ret = MAX;
  REP(i,n) if((flag & 1<<i) == 0){
    if(dist[now][i] < 6){
      ret = min(ret, dist[now][i] + solve(i, flag | (1<<i)));
    }
  }
  return ret;
}

int main(){
  int w,h;
  while((w = getInt()) + (h = getInt())){
    int b[h][w];
    deque<pair<int,int> > v;

    REP(i,h) REP(j,w){
      int t = getInt();
      if(t == 2){
	t = 1;
	sx = j; sy = i;
      }else if(t == 3){
	t = 1;
	gx = j; gy = i;
      }else if(t == 4){
	t = 1;
	v.push_back(mp(j,i));
      }
      b[i][j] = t;
    }

    v.push_back(mp(gx,gy));
    v.push_front(mp(sx,sy));

    REP(i,h) REP(j,w) REP(k,h) REP(l,w)
      d[i][j][k][l] = MAX;

    REP(i,h) REP(j,w) d[i][j][i][j] = 0;

    REP(i,h) REP(j,w){
      if(b[i][j] == 0) continue;
      if(i < h-1) if(b[i+1][j] == 1)
	d[i][j][i+1][j] = d[i+1][j][i][j] = 1;
      if(j < w-1) if(b[i][j+1] == 1)
	d[i][j][i][j+1] = d[i][j+1][i][j] = 1;
    }

    REP(k,w*h) REP(i,w*h) REP(j,w*h)
      d[i/w][i%w][j/w][j%w]
      = min(d[i/w][i%w][j/w][j%w],
	    d[i/w][i%w][k/w][k%w] + d[k/w][k%w][j/w][j%w]);

    //REP(i,h) { REP(j,w) printf("%d ",d[sy][sx][i][j]==10000?-1:d[sy][sx][i][j]); puts(""); }

    n = v.size();

    if(n == 0){
      if(d[sy][sx][gy][gx] == MAX)
	print(-1);
      else
	print(d[sy][sx][gy][gx]);
      continue;
    }

    REP(i,n) REP(j,n)
      dist[i][j] = d[v[i].s][v[i].f][v[j].s][v[j].f];
    
    int ans = solve(0,0);

    if(ans >= MAX){
      print(-1);
      continue;
    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 0
from functools import reduce

# 入力
N = int(input())
A = [int(input()) for _ in range(N)]

# 貪欲法に基づき、小さい整数から順にペアを作成
ans, _ = reduce(
    lambda acc, a: (
        acc[0] + (a + acc[1]) // 2,
        max(0, a - acc[1]) % 2
    ),
    A,
    (0, 0)
)

# 出力
print(ans)


Measured memory_bytes: 7564
#include<algorithm>
#include<cstdio> 
#include<cmath> 

using namespace std;

int n,m;
int ans;

int main(){
    scanf("%d",&n);
    for(;n--;)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        ans+=r-l+1;
    }
    printf("%d\n",ans);
    return 0;
}

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

int main() {
    int N; cin >> N;
    if (N/100 == 7 || (N%100)/10 == 7 || (N%10) == 7) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
N ,X = map(int, input().split())
difs = list(map(int, input().split()))
steps = [0]
for i in range(N):
    steps.append(steps[i] + difs[i])
for i in range(N+1):
    if steps[i] > X:
        print(i)
        break
    elif i == N:
        print(N+1)

Measured memory_bytes: 3060
using System;

namespace Adarsh
{
    class Code
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if(s[0] == '7' || s[1] == '7' || s[2] == '7')
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


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


int main() {
  int N, K;
  cin >> N >> K;
  int l[N];
  rep(i, N) cin >> l[i];
  sort(l, l + N, greater<int>());
  int sum = 0;
  rep(i, K) sum +=l[i];
  cout << sum << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

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

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

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

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

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

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

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

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/


vector<int> idx[maxn];

int main()
{
	FASTIO
	/*
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
//*/
	int T;
	//scanf("%d", &T);
	T = 1;
	for (int cs = 1; cs <= T; cs++) {
		int n, m;
		cin >> n >> m;
		for (int i = 0; i < n; i++) {
			int d, r;
			cin >> d >> r;
			if (m - d >= 0)idx[m - d].push_back(r);
		}
		int ans = 0;
		priority_queue<ll> PQ;
		for (int i = m; i >= 0; i--) {
			for (auto x : idx[i]) PQ.push(x);
			if ((int)PQ.size()) {
				ans += PQ.top();
				PQ.pop();
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <stdio.h>
using namespace std;

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

    int temp[10];

    for (int i = 0; i < 10; i++)
    {
        temp[i] = N-i;
    }

    int frag;

    for (int i = 0; i < 10; i++)
    {
        if(temp[i]%10==0) frag=i;
    }

    if(frag==3){
        cout << "bon" << endl;
    }else if((frag==0)||(frag==6)||(frag==1)||(frag==8)) {
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int D=N%10;
  int C=(N/10)%10;
  int B=(N/100)%10;
  int A=N/1000;
  char p, q, r;
  if(A+B+C+D==7){
    p='+';
    q='+';
    r='+';
  }
  else if(A+B+C-D==7){
    p='+';
    q='+';
    r='-';
  }
  else if(A+B-C+D==7){
    p='+';
    q='-';
    r='+';
  }
  else if(A-B+C+D==7){
    p='-';
    q='+';
    r='+';
  }
  else if(A+B-C-D==7){
    p='+';
    q='-';
    r='-';
  }
  else if(A-B+C-D==7){
    p='-';
    q='+';
    r='-';
  }
  else if(A-B-C+D==7){
    p='-';
    q='-';
    r='+';
  }
  else if(A-B-C-D==7){
    p='-';
    q='-';
    r='-';
  }
  cout << A << p << B << q << C << r << D << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m,i,j,tmp=0,ans=0;
  cin>>n>>m;
  vector<ll> a(n);
  vector<pair<ll,ll>> b(m);
  for(i=0;i<n;i++){
	cin>>a[i];
  }
  for(i=0;i<m;i++){
	cin>>b[i].second>>b[i].first;
  }
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  int flag=0;
  for(i=0;i<m;i++){
    for(j=tmp;j<tmp+b[i].second;j++){
      	if(j>n-1){
          cout<<ans+b[i].first*(n-tmp)<<endl;
         return 0;
        }
		if(a[j]>=b[i].first){
          	ans+=(j-tmp)*b[i].first;
            tmp=j;
          	flag=1;
          	goto loopend;
        }
    }
    ans+=b[i].second*b[i].first;
    tmp=j;
  }
  loopend:
  
  for(j=tmp;j<n;j++){
  	 ans+=a[j];
    }
 
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
n=int(input())
a=[int(i) for i in input().split()]
d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2
for i in a:
    print(ans-(d[i]*(d[i]-1))//2+((d[i]-1)*(d[i]-2)//2))


Measured memory_bytes: 86476
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<bitset>
#define INF 0x3f3f3f3f
#define LL long long
#define MOD1 998244353
#define MOD2 1000000007
#define MAXN 1000005
using namespace std;
// struct Edge{
// 	int to,nex;
// 	Edge(){}
// 	Edge(int a,int b){
// 		to=a,nex=b;
// 	}
// }e[MAXN<<1];
int n,m;
char s1[10],s2[10];
int rd(){
	int x=0,tp=1;char c;
	c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*tp;
}
int main(){
	// freopen("nmsl.in","r",stdin); 
	// freopen("nmsl.out","w",stdout);
	scanf("%s",s1);
	scanf("%s",s2);
	int ans=0;
	for(int i=0;i<3;i++)if(s1[i]==s2[i])ans++;
	printf("%d\n",ans);
	return 0;
}

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

char map[51][51];
int res;
int w,h;

int dfs(int sx, int sy) {
    if(sx<0 || sx>w-1 || sy<0 || sy>h-1) return 0;
    if(map[sy][sx] == '0') return 0;

    map[sy][sx] = '0';

    dfs(sx+1,sy);
    dfs(sx,sy+1);
    dfs(sx-1,sy);
    dfs(sx,sy-1);
    dfs(sx+1,sy+1);
    dfs(sx+1,sy-1);
    dfs(sx-1,sy+1);
    dfs(sx-1,sy-1);
    return 1;
}

int main(void)
{
    int px,py;

    while(true)
    {
        res = 0;
        scanf("%d%d", &w, &h);
        if(!w && !h) break;
        for(int j=0; j < h; j++)
        for(int i=0; i < w; i++)
            scanf("%s", &map[j][i]);

        for(int j=0; j < h; j++)
        for(int i=0; i < w; i++)
            res += dfs(i, j);

        printf("%d\n", res);
    }

    return 0;
}

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

typedef long long int lli;

using namespace std;

const int MAX_VALUE = (1 << 30) + (1 << 30 - 1);

const int MODULO = 1000000007;


int main() {
	// your code goes here
	//cout << MAX_VALUE << endl;
	int H, W, i, j, k;
	cin >> H >> W;
	char grid[H][W];
	int ans[H][W];
	for (i = 0; i < H; i++)
	{
		for(j = 0; j < W; j++)
		{
			cin >> grid[i][j];
			ans[i][j] = 0;
		}
	}
	ans[0][0] = 1;
	
	for (i = 0; i < H; i++)
	{
		for (j = 0; j < W; j++)
		{
			if ((j+1 < W) && (grid[i][j+1] == '.'))
			{
				ans[i][j+1]+=ans[i][j];
				ans[i][j+1] = ans[i][j+1] % MODULO;
			}
			if ((i+1 < H) && (grid[i+1][j] == '.'))
			{
				ans[i+1][j]+=ans[i][j];
				ans[i+1][j] = ans[i+1][j] % MODULO;
			}
		}
	}
	/*
	for (i = 0; i < H; i++)
	{
		for(j = 0; j < W; j++)
		{
			cout << ans[i][j];
		}
		cout << endl;
	}
	*/
	cout << ans[H-1][W-1];
	
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


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

    ll res=LINF;
    REP(bit, 1<<n){
        ll maxi=0, sum=0, cnt=0;
        REP(j, n){
            if(bit & 1<<j){
                ll x = max(maxi-a[j]+1, 0LL);
                sum +=  x; cnt += 1;
                if(0<x) maxi += 1;
            }
            maxi = max(a[j], maxi);
            //cout << sum << ' ';
        }
        //cout << bit << ' ' << sum << endl;
        if(k<=cnt)
            res = min(res, sum);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
def integral(d):
    n = 600//d
    s = 0.0
    for i in range(n):
        s += (d*i)**2
    return(s*d)

if __name__ == '__main__':
    while True:
        try:      
            d = int(input())
            print(int(integral(d)))
        except:
            break

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t = (B + C - 1) / B;
    int a = (A + D - 1) / D;
    if (t <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	string S;
	cin >> S;
	S.at(5) = ' ';
	S.at(13) = ' ';
	cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

vector<Pi> Q(100100);

signed main() {
  int N, M; cin >> N >> M;
  priority_queue<int, vector<int>, greater<int> > PQ;
  
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    PQ.push(a);
  }


  auto comparator = [](const Pi &l, const Pi &r) {
                      return l.second  > r.second; 
                    };

  for (int i = 0; i < M; i++) {
    int b, c; cin >> b >> c;
    Q.push_back(Pi(b, c));
  }

  sort(Q.begin(), Q.end(), comparator);

  // for (int i = 0; i < M; i++) {
  //   auto x = Q[i];
  //   cout << x.first << " " << x.second << endl;
  // }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    int limit = Q[i].first;
    int constant = Q[i].second;
    
    while (!PQ.empty() && limit != 0){
      int top = PQ.top();
      PQ.pop();
      if (top >= constant) {
        ans += top;
      } else {
        ans += constant;
        limit--;
      }
    }

    if (PQ.empty()) {
      break;
    }
  }

  while (!PQ.empty()) {
    int x = PQ.top();
    PQ.pop();
    ans += x;
  }

  cout << ans << endl;
}


Measured memory_bytes: 5876
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), M = in.nextInt();
        int[] X = new int[M];
        for (int i = 0; i < M; i++) {
            X[i] = in.nextInt();
        }
        Arrays.sort(X);
        int[] d = new int[M - 1];
        for (int i = 1; i < M; i++) {
            d[i - 1] = X[i] - X[i - 1];
        }
        Arrays.sort(d);
        int ans = 0;
        for (int i = 0; i < M - N; i++) {
            ans += d[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50556
#include<iostream>
#include<complex>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const double eps = 1e-10;
const double AREA=10000*10000;
#define RIGHT 1
#define LEFT -1

typedef complex<double> P;
typedef vector<P> Polygon;
typedef pair<P,P> Line;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

P intersection_ll(P a1,P a2,P b1,P b2){
  P a=a2-a1,b=b2-b1;
  return a1+a*cross(b,b1-a1)/cross(b,a);
}


int ccw(P a,P b){
  if ( cross(a,b)<0)return RIGHT;
  else if ( cross(a,b)>0)return LEFT;
  return 2;
}

vector<P> Convex_Cut(Polygon in,int n,P a1,P a2,int cutpos){
  vector<P> ret;
  rep(i,n){
    P now = in[i],next=in[(i+1)%n];
    if( ccw(a1-a2,now-a2)==cutpos)ret.push_back(now);
    if ( ccw(a1-a2,now-a1)*ccw(a1-a2,next-a2)<0)
      ret.push_back(intersection_ll(a1,a2,now,next));
  }
  return ret;
}

//cutpos ha mondai izon. which side will remain
Line make_line(P ori,P b,int cutpos){
  P tmp=(ori+b);
  tmp.real()/=2;tmp.imag()/=2;
  P ret=b-tmp;
  swap(ret.real(),ret.imag());
  ret.real()*=-1;
  if ( ccw(ret,ori-tmp)!= cutpos)return make_pair(tmp,ret+tmp);
  return make_pair(ret+tmp,tmp);
}

double Polygon_Area(vector<P> a,int n){
  double sum=0;
  rep(i,n){
    sum+=(a[i%n].real()-a[(i+1)%n].real())*(a[i%n].imag()+a[(i+1)%n].imag());
  }
  if( sum<0)sum*=-1;
  return sum/2;
}


void solve(Polygon in,vector<P> CutLine){
  vector<Line> ver;
  ver.push_back(make_line(CutLine[0],CutLine[1],RIGHT));
  ver.push_back(make_line(CutLine[0],CutLine[2],RIGHT));
  
  rep(i,ver.size())
    in=Convex_Cut(in,in.size(),ver[i].first,ver[i].second,RIGHT);
  
  printf("%.6lf\n",Polygon_Area(in,in.size())/AREA);
}

main(){
  int n,m,te=1;
  Polygon data;
  data.push_back(P(0,0));
  data.push_back(P(0,10000));
  data.push_back(P(10000,10000));
  data.push_back(P(10000,0));
  while(true){
    vector<P> CutPoint;
    rep(i,3){
      P tmp;cin>>tmp.real()>>tmp.imag();CutPoint.push_back(tmp);
    }
    if ( CutPoint[0].real()<eps && CutPoint[0].imag()<eps && 
	 CutPoint[1].real()<eps && CutPoint[1].imag()<eps &&
	 CutPoint[2].real()<eps && CutPoint[2].imag()<eps)break;
    printf("%d ",te++);
    solve(data,CutPoint);
  }
}

Measured memory_bytes: 0
n = int(input())

FB_list = []
FB_all = 0

for i in range(1,n+1):
    FB_all += i
    if (i % 3 == 0 and i % 5 == 0) or (i % 3 != 0 and i % 5 == 0) or (i % 3 == 0 and i % 5 != 0):
        FB_list.append(0)
    else:
        FB_list.append(i)
FB_non = sum(FB_list)
print(FB_non)

Measured memory_bytes: 33736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static class Task {
        public void solve(InputReader in, PrintWriter out) {
        	int n = in.nextInt();
        	int ans = 0;
        	int prev = in.nextInt();
        	for(int i=1; i<n; i++) {
        		int curr = in.nextInt();
        		if(prev > curr)
        			ans+=prev-curr;
        		if(i==n-1)
        			ans+=curr;
        		prev = curr;
        	}
        	out.println(ans);
        }
        
        public void solve_again(InputReader in, PrintWriter out) {
        	int n = in.nextInt();
        	int curr = in.nextInt();
        	int ans = curr;
        	for(int i=1; i<n; i++) {
        		int next = in.nextInt();
        		if(next > curr)
        			ans+=next-curr;
        		curr = next;
        	}
        	out.println(ans);
        }
        
    }
	
    public static void main(String argds[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve_again(in, out);
        out.close();
    }

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
        public long nextLong() {
            return Long.parseLong(next());
        }
    }	
}

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

int main()
{
    int N;
    scanf("%d",&N);
    int mul=10,cnt=0,n=N,i=0;
    while(n>0)
    {
        n=n/10;
        i++;
    }
    if(i==2||i==4||i==6)
    {
        if(i==2)
            cout<<9<<endl;
        else if(i==4)
            cout<<909<<endl;
        else
            cout<<90909<<endl;
    }
    else
    {
        if(i==1)
            cout<<N<<endl;
        else if(i==3)
            cout<<9+N-99<<endl;
        else
            cout<<909+N-9999<<endl;
    }
    return 0;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll lcm(ll a, ll b)  
{  
	ll ga = gcd(a,b);
    return (a*b)/ga;  
} 
int main()
{
    fast;
    
    ll n,i,wa=0;
    cin>>n;
    ll a[n+2];
    for(i=1;i<=n;i++) cin>>a[i];
    ll req = 0;
    for(i=1;i<=n;i++)
    {
    	if(a[i]==(req+1))
    	{
    		req++;
    	}
    }
    if(req==0) cout<<"-1";
    else cout<<n-req;
}
    


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

const long long MOD=1000000000+7;

int main(){
    long long N, K; cin >> N >> K;
    long long ans=0;
    for(long long i=K; i<=N+1; i++){
        ans=(ans+i*(2*N-i+1)/2-i*(i-1)/2+1)%MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int h, w;
	while(1){
		cin >> h >> w;
		if(h==0 && w==0) break;
		for(int i=1; i<=h; i++){
			for(int x=1; x<=w; x++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){
   int ans = 0;
   string S;
   cin >> S;

   for(int i=0;i<4;i++){
      if(S[i]=='+'){
         ans++;
      }
      if(S[i]=='-'){
         ans--;
      }
   }
   cout << ans <<endl;
   return 0;
}


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

int main() {
    deque<char> q;
    string s;
    cin >> s;
    for (char c : s) {
        q.push_back(c);
    }
    int queries;
    cin >> queries;
    bool forward = true;
    while (queries--) {
        int cmd;
        cin >> cmd;
        if (cmd == 1) forward = !forward;
        else {
            int beginning;
            char c;
            cin >> beginning >> c;
            bool front = (beginning-1);
            if (forward) front = !front;

            if (front) q.push_front(c);
            else q.push_back(c);
        }
    }

    if (forward) {
        while (q.size()) {
            cout << q.front();
            q.pop_front();
        }
    } else {
        while (q.size()) {
            cout << q.back();
            q.pop_back();
        }
    }
    cout << endl;
}

Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    string s; cin >> s;
    string t; cin >> t; 
    int ans=0;
    
    rep(i,s.size()){
        if(s[i]==t[i]) ans++;
    }

    cout << ans << ln;
    return 0;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    s=input()
    t=input()
    ans=0
    for i in range(len(s)):
        ans+=(s[i]!=t[i])
    print(ans)



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

int main(){
  int h,w;

  while(1){
    cin >> h >> w;
    if (h==0 && w==0){
      break;
    }
    for (int i=0; i < h; i++){
      if (i == 0 || i == (h-1)){
        for (int j=0; j < w; j++){
          cout << "#";
       	}
        cout << endl;
      }
      else{
        cout << "#";
        for (int k=0; k < (w-2); k++){
          cout << ".";
	}
        cout << "#" << endl;
      }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>

int main(void){
    
    char S[3];
    char T[3];
    int sum = 0;
    int i;
    
    scanf("%s",S);
    scanf("%s",T);
    
    for(i=0;i<3;i++){
        if(S[i]==T[i]){
            sum += 1;
        }
    }
    
    printf("%d\n", sum);
    
    return 0;
}


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

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

	vector<int> v;
	while(q--){
		int query;cin>>query;
		if(query==0){
			//pb
			int x;cin>>x;
			v.push_back(x);
		}else if(query==1){
			//random access
			int p;cin>>p;
			cout<<v[p]<<endl;
		}else{
			v.pop_back();
		}
	}
	
  return 0;
}



Measured memory_bytes: 3876
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
s = 0 
for i in range(N):
    s = s + A[i]
    
c = 0
for i in range(N):
    if s/(4*M) <= A[i]:
        c = c + 1
print('Yes' if c >= M else 'No')


Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

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)*}
    };
}

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)*}
    };
}

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")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize1,
        x: [i32; n],
    }
    let mut min = i32::max_value();
    for i in 0..(n - k) {
        let mut neg = 0;
        if x[i].is_negative() {
            neg = 0 - x[i];
        }
        let mut pos = 0;
        if x[i + k].is_positive() {
            pos = x[i + k] - 0;
        }
        let mut count;
        if neg == 0 {
            count = pos;
        } else if pos == 0 {
            count = neg;
        } else {
            count = cmp::min(neg * 2 + pos, neg + pos * 2);
        }
        min = cmp::min(min, count);
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=998244353;
const int N=405;
int n,a[N],b[N];
int fac[N],inv[N],pa[N];
int S1,S2,ans,tr[N];
int f[N][N][N];
int power(int x,int y)
{
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
void init(){
	fac[0]=1;
	For(i,1,N-1) fac[i]=1ll*fac[i-1]*i%mo;
	For(i,0,N-1) inv[i]=power(fac[i],mo-2);
}
int main()
{
	scanf("%d",&n);
	init();
	For(i,1,n) scanf("%d%d",&a[i],&b[i]);
	S1=S2=0;
	f[0][0][0]=mo-1;
	For(i,1,n)
	{
		For(j,0,S1) For(k,0,S2)
			f[i][j][k]=f[i-1][j][k];
		tr[0]=1;
		For(j,1,b[i]-1) tr[j]=1ll*tr[j-1]*a[i]%mo;
		For(j,0,b[i]-1) tr[j]=1ll*tr[j]*inv[j]%mo;
		For(j,0,S1) For(k,0,S2) For(v,0,b[i]-1)
			f[i][j+v][k+a[i]]=(f[i][j+v][k+a[i]]+mo-1ll*f[i-1][j][k]*tr[v]%mo)%mo;		
		S1+=b[i]-1; S2+=a[i];
	}
	int ans=0;
	For(i,0,S1) For(j,1,S2)
	{
		int val=1ll*f[n][i][j]*fac[i]%mo;
		val=1ll*val*power(j,mo-1-i)%mo;
		ans=(ans+1ll*val*S2%mo*power(j,mo-2))%mo;
	}
	printf("%d\n",ans);
}
/*
For(S \in T) -1^(|S|-1)
	For(x[i] in S)
orz zyy	
*/


Measured memory_bytes: 256256
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define mxn 2005
#define mod 998244353
#define ld long double
#define pb push_back
#define inf 1e9+5
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main(void){
		#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	ll n,i,j,ans=0,k;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	if(n<3)
	cout<<0<<endl;
	else{
		sort(a,a+n);
		for(i=0;i<n-2;i++){
			for(j=i+1;j<n-1;j++){
				for(k=j+1;k<n;k++){
					if(a[i]+a[j]>a[k]&&(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]))
					ans++;
				}
			}
		}
		cout<<ans;
	}
	
}


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

int f(int x){
	return x*x;
}

int main(){
	int d;
	int area=0;
	while(cin >> d){
		int w = 600/d;
		for(int i=0;i<w;i++){
			area += d*f(i*d);
		}
		cout << area << endl;
		area = 0;
	}

}


Measured memory_bytes: 3052
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] w = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            w[i] = scanner.nextInt();
            sum += w[i];
        }

        int s1 = 0;
        int s2 = sum;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            s1 += w[i];
            s2 -= w[i];
            min = Math.min(min, Math.abs(s1 - s2));

        }
        System.out.println(min);
    }
}

Measured memory_bytes: 22996
#include <iostream>

using namespace std;
typedef long long ll;

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

char S[22][22];
int check[22][22];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int H, W;

void disp()
{
    REP(i, H) {
        REP(j, W) {
            printf("%3d ", check[i][j]);
        }
        printf("\n");
    }
}


int rec(int x, int y)
{
    int nx, ny;
    int m = 0;
    int cnt = 0;
    int np;
    int step=0;

//    cout << x << " " << y << endl;
    if(S[y][x] != '.') {
        return 0;
    }
    check[y][x] = 0;
    do  {
        np = 0;
        REP(y1, H) {
            REP(x1, W) {
                if(check[y1][x1]==step) {
                    REP(i, 4) {
                        nx=x1+dx[i];
                        ny=y1+dy[i];
                        if(nx>=0 && nx<W && ny>=0 && ny <H) {
                            if(check[ny][nx] == -1&&S[ny][nx] == '.') { 
                                check[ny][nx] = step + 1;
                                np = 1;
                            }
                        }
                    }
                }
            }
        }
        if(np == 1) step ++;
    } while(np == 1);
//        printf("s:%d\n", step);
//        disp();
    return step;
}
             



int main(void)
{
    int ms  = 0;
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }
    REP(y, H) REP(x, W) {
        REP(i,H) REP(j,W) check[i][j] = -1;    
        ms = max(rec(x,y),ms);
    }
    cout << ms << endl;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (a, b) = input_tuple();
    if a > b {
        println!("{}", a - 1);
    } else {
        println!("{}", a)
    }
}


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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

inline void upmax(int &x,const int &y){if(y>x) x=y;}
inline void upmin(int &x,const int &y){if(y<x) x=y;}

const int N=200010;
struct Edge{int to,next;} e[N];
int h[N],sum=0,n;
int fa[N],mex[N];
bool vis[N],loop[N];
bool have[N];

void add_edge(int u,int v)
{
    e[++sum].to=v;
    e[sum].next=h[u];
    h[u]=sum;
}

void dfs(int u)
{
    for(int t=h[u];t;t=e[t].next)
        if(!loop[e[t].to]) dfs(e[t].to);
    for(int t=h[u];t;t=e[t].next)
        if(!loop[e[t].to]) have[mex[e[t].to]]=1;
    while(have[mex[u]]) mex[u]++;
    for(int t=h[u];t;t=e[t].next)
        if(!loop[e[t].to]) have[mex[e[t].to]]=0;
}

int main()
{
    int n,x=1;
    n=read();
    for(int i=1;i<=n;i++)
    {
        fa[i]=read();
        add_edge(fa[i],i);
    }
    while(!vis[x]) vis[x]=1,x=fa[x];
    while(!loop[x]) loop[x]=1,x=fa[x];
    int mx=-1,mn=n+1,cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!loop[i]) continue;
        dfs(i);cnt++;
        upmax(mx,mex[i]);
        upmin(mn,mex[i]);
    }
    puts(mx==mn&&(cnt&1)?"IMPOSSIBLE":"POSSIBLE");
    return 0;
}

Measured memory_bytes: 5504
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


def main():
    n,m=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(m)]
    l.reverse()
    res = [(n*(n-1))//2]
    u = UnionFind(n)
    for sl in l:
        a = sl[0]-1
        b = sl[1]-1
        if u.find(a) == u.find(b):
            res.append(res[-1])
        else:
            res.append(res[-1] - u.size(a) * u.size(b))
            u.union(a,b)
    res.pop()
    res.reverse()
    print("\n".join(map(str,res)))
main()

Measured memory_bytes: 41668
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n;
      cin >> n;
      string s;
      cin >> s;
      int ans=0;
      rep(i,n){
        int subans=0;
        for(char c='a';c<='z';c++){
          bool ok[2];
          ok[0]=false;
          ok[1]=false;
          rep(j,i){
           if(s[j]==c)ok[0]=true; 
          }
          REP(k,i,n){
           if(s[k]==c)ok[1]=true; 
          }
          if(ok[0] && ok[1])subans++;
        }
        ans=max(ans,subans);
      }
      cout << ans << endl;
      return 0;}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
A ,B, H, M =  [int(i) for i in input().split()]

kakudo = (H * 60.0 + M*1.0)/720 * 360
B_kakudo = M*1.0 / 60 * 360
#if kakudo < 180 or (180 <= kakudo and kakudo < 270):
Ax = A * math.sin(math.radians(kakudo))
Ay = A * math.cos(math.radians(kakudo))

#else:
#Ax = -A * math.sin(math.radians(kakudo))
#Ay = -A * math.cos(math.radians(kakudo))

#if B_kakudo < 180 or (180 <= B_kakudo and B_kakudo < 270):
Bx = B * math.sin(math.radians(B_kakudo))
By = B * math.cos(math.radians(B_kakudo))

#else:
#Bx = -B * math.sin(math.radians(B_kakudo))
#By = -B * math.cos(math.radians(B_kakudo))

#print(Ax,Ay,Bx,By,kakudo, B_kakudo)
print(math.sqrt(((Bx- Ax)**2 + (By -Ay)**2)))


Measured memory_bytes: 9576
n = int(input());
a = [[0]*n for i in range(2)]
for i in range(2) :
	s = input().split(" ");
	for j in range(n) :
		a[i][j] = int(s[j]);

ans = 0;
for i in range(n) :
	point = 0;
	for j in range(n) :
		if j <= i :
			point += a[0][j];
		if j >= i :
			point += a[1][j];
	if point > ans :
		ans = point;
print(ans);

Measured memory_bytes: 3064
L = input()
MOD = 10**9 + 7

eqDp = 1
lessDp = 0

for l in L:
    if l == '1':
        eqDp, lessDp = eqDp * 2, lessDp * 3 + eqDp
    else:
        eqDp, lessDp = eqDp, lessDp * 3

    eqDp %= MOD
    lessDp %= MOD

print((eqDp + lessDp) % MOD)


Measured memory_bytes: 3188