akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<20;



vector<LL> u,v;
map<LL,vector<LL>> f;
map<LL,set<P>> ff;
map<LL,vector<LL>> g;
map<LL,set<P>> gg;
int n,d;
LL ans;

void dfs(int k){
    ff[u[k]].erase(P(v[k],k));
    gg[v[k]].erase(P(u[k],k));
    ans+=lower_bound(ALL(f[u[k]+d]),v[k]+d+1)-lower_bound(ALL(f[u[k]+d]),v[k]-d);
    ans+=lower_bound(ALL(f[u[k]-d]),v[k]+d+1)-lower_bound(ALL(f[u[k]-d]),v[k]-d);
    ans+=lower_bound(ALL(g[v[k]+d]),u[k]+d)-lower_bound(ALL(g[v[k]+d]),u[k]-d+1);
    ans+=lower_bound(ALL(g[v[k]-d]),u[k]+d)-lower_bound(ALL(g[v[k]-d]),u[k]-d+1);

    while(1){
        auto p = ff[u[k]+d].lower_bound(P(v[k]-d,-INF));
        if(p!=ff[u[k]+d].end()&&p->fs<=v[k]+d){
            dfs(p->sc);
        }
        else break;
    }
    while(1){
        auto p = ff[u[k]-d].lower_bound(P(v[k]-d,-INF));
        if(p!=ff[u[k]-d].end()&&p->fs<=v[k]+d){
            dfs(p->sc);
        }
        else break;
    }
    while(1){
        auto p = gg[v[k]+d].lower_bound(P(u[k]-d+1,-INF));
        if(p!=gg[v[k]+d].end()&&p->fs<u[k]+d){
            dfs(p->sc);
        }
        else break;
    }
    while(1){
        auto p = gg[v[k]-d].lower_bound(P(u[k]-d+1,-INF));
        if(p!=gg[v[k]-d].end()&&p->fs<u[k]+d){
            dfs(p->sc);
        }
        else break;
    }
}


int main(){
    int a,b;cin >> n >> a >> b;
    a--,b--;
    for (int i = 0; i < n; i++) {
        int x,y;cin >> x >> y;
        u.pb(x+y),v.pb(x-y);
        ff[u[i]].insert(P(v[i],i));
        gg[v[i]].insert(P(u[i],i));
        f[u[i]].emplace_back(v[i]);
        g[v[i]].emplace_back(u[i]);
    }
    d = max(abs(u[a]-u[b]),abs(v[a]-v[b]));
    for(auto &p:f) sort(ALL(p.sc));
    for(auto &p:g) sort(ALL(p.sc));
    dfs(a);
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 90216
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	int *A = new int[N];
	int max = -1;
	int second = -1;
	for (int i = 0; i < N; i++) {
		scanf("%d", A + i);
		if (i==0) {
			max = 0;
		}
		else if (i==1) {
			if (A[0] > A[1]) {
				second = 1;
			}
			else {
				max = 1;
				second = 0;
			}
		}
		else if (A[i] >= A[max]) {
			second = max;
			max = i;
		}
		else if (A[i] > A[second]) {
			second = i;
		}
	}
	for (int i = 0; i < N; i++) {
		if (i == max) {
			printf("%d\n", A[second]);
		}
		else {
			printf("%d\n", A[max]);
		}
	}
	return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


class point_t {
public:
  bool operator<(const point_t& p) const {
    if (x == p.x)
      return y < p.y;

    return x < p.x;
  };
                                          
public:
  int x;
  int y;
};


class bipartite_matching_fn_t {
public:
  bipartite_matching_fn_t(int N) : N_(N), G_(N) {
    match_ = new int [N_];
    used_ =  new bool[N_];
  };

  ~bipartite_matching_fn_t() {
    delete[] match_;
    delete[] used_;
  };

public:
  void add_edge(int u, int v) {
    assert(0 <= u && u < N_);
    assert(0 <= v && v < N_);
    
    G_[u].push_back(v);
    G_[v].push_back(u);
  };

private:
  bool dfs(int v) {
    used_[v] = true;

    for (int i = 0, size = G_[v].size(); i < size; i ++) {
      int u = G_[v][i], w = match_[u];

      if (w < 0 || (! used_[w] && dfs(w))) {
        match_[v] = u;
        match_[u] = v;

        return true;
      }
    }

    return false;
  };

public:
  int match() {
    int c = 0;

    memset(match_, -1, sizeof(int) * N_);

    for (int v = 0; v < N_; v ++) {
      if (match_[v] < 0) {
        memset(used_, 0, sizeof(bool) * N_);

        if (dfs(v))
          c ++;
      }
    }
    
    return c;
  };

private:
  int N_;
  
  std::vector<std::vector<int>> G_;

  int* match_;

  bool* used_;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, c = 0;

  std::cin >> N;

  std::vector<point_t> reds(N), blues(N);

  for (auto& p : reds)
    std::cin >> p.x >> p.y;

  for (auto& p : blues)
    std::cin >> p.x >> p.y;

  std::sort(ALL(reds));
  std::sort(ALL(blues));

  bipartite_matching_fn_t fn(N + N);

  for (int i = 0; i < N; i ++) {
    const auto& p = reds[i];
    
    for (int j = 0; j < N; j ++) {
      const auto& q = blues[j];

      if (p.x < q.x && p.y < q.y)
        fn.add_edge(i, j + N);
    }
  }

  std::cout << fn.match() << std::endl;

  return 0;
}


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

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public int[] gen = new int[]{ 10, 20, 30, 40, 50, 60 };
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> Ans = new ArrayList<Integer>();
		String line;
		
		while((line = in.readLine()) != null){
			int size = Integer.parseInt(line);
			if(size == 0) break;
			int[] dis = new int[]{ 0, 0, 0, 0, 0, 0, 0 };
			
			for(int i=0; i<size; i++){
				line = in.readLine();
				int age = Integer.parseInt(line);
				int over60 = 0;
				for(int j=0; j<6; j++){
					if(age < gen[j]){
						dis[j]++;
						over60 = 1;
						break;
					}
				}
				
				if(over60 == 0){
					dis[6]++;
				}
			}
			
			for(int i=0; i<7; i++){
				Ans.add(dis[i]);
			}
		}
		
		for(int i=0; i<Ans.size(); i++){
			System.out.println(Ans.get(i));
		}
	}
}

Measured memory_bytes: 11000
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n;
  cin >> n;
  cout << (n%2 == 0 ? (n*n)/4 : (n/2)*((n/2)+1)) << endl;

  return 0;
}




//


Measured memory_bytes: 256
#include <stdio.h>

int main () {
     int x[3000], y[3000], n;
     for (n = 0; n < 3000; n++) {
          scanf ("%d %d\n", &x[n], &y[n]);

          if (x[n] == 0 && y[n] == 0)
               break;
     }

     for (n = 0; n < 3000; n++) {
          if (x[n] == 0 && y[n] == 0)
               break;
          if (x[n] < y[n]) {
                printf ("%d %d\n", x[n], y[n]);
          } else {
                printf ("%d %d\n", y[n], x[n]);
          }
      }

     return 0;

}

Measured memory_bytes: 628
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if (s.size()==2) cout<<s<<endl;
    else
    {
        reverse(s.begin(), s.end());
        cout<<s<<endl;
    }
    return 0;
}


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

int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st = -1;
const int CYCLE = 42;

int dfs(int x, int p) {
	cycle[x] = 1;
	for(int i : out[x]) {
		if(i != p) {
			if(cycle[i] == 1) {
				st = i;
				cycle[x] = CYCLE;
				return CYCLE;
			}
			else if(cycle[i] == 0) {
				if(dfs(i, x) == CYCLE) {
					cycle[x] = CYCLE;
					if(x == st) return 0;
					else return CYCLE;
				}
			}
		}
	}
	cycle[x] = 2;
	return 0;
}

int getgrundy(int x) {
	set<int> s;
	for(int i : out[x])
		if(cycle[i] != CYCLE)
			s.insert(getgrundy(i));
	int ans = 0;
	auto it = s.begin();
	while(it != s.end()) {
		if(*it == ans) {
			++ans;
			++it;
		}
		else return grundy[x] = ans;
	}
	return grundy[x] = ans;
}

bool chk(int x, int val, int res) {
	if(x == st) return res == val;
	int nxt = -1;
	for(int i : out[x]) {
		if(cycle[i] == CYCLE) {
			nxt = i;
		}
	}
	if(nxt == -1) return false;
	return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	memset(cycle, 0, sizeof cycle);
	for(int i = 0; i < n; ++i){
		int x;
		cin >> x;
		--x;
		out[x].push_back(i);
		in[i] = x;
		if(x < i and in[x] == i) {
			st = i;
			cycle[x] = cycle[i] = CYCLE;
		}
	}
	for(int i = 0; st == -1 and i < n; ++i) if(cycle[i] == 0) dfs(i, -1);
	for(int i = 0; i < n; ++i) {
		if(cycle[i] == CYCLE) getgrundy(i);
	}
	int nxt;
	for(int i : out[st]) {
		if(cycle[i] == CYCLE) {
			nxt = i;
		}
	}
	if(st == nxt or chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
	else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;

}


Measured memory_bytes: 22912
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;cnt = 0 ;pro = 1

n = int(input())
for i in range(1, n+1):
    y = n//i
    ans += y*(y+1)*i//2
print(ans)

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

int main() {
    int N;
    cin >> N;
    int A[N+2];
    A[0] = 0;
    for(int i=1;i<=N;i++) cin >> A[i];
    long long sum =0;
    A[N+1] = 0;
    for(int i=1;i<=N+1;i++){
        sum += abs(A[i] - A[i-1]);
    }
    long long c = sum;

    for(int i=1;i<=N;i++){
        sum = c;
        if(A[i] > A[i-1] && A[i-1] > A[i+1]) sum -= 2*abs(A[i] - A[i-1]);
        if(A[i] > A[i+1] && A[i+1] > A[i-1]) sum -= 2*abs(A[i] - A[i+1]);
        if(A[i] <A[i-1] && A[i-1] < A[i+1]) sum -= 2* abs(A[i] - A[i-1]);
        if(A[i] < A[i+1] && A[i+1] < A[i-1]){
            sum -= 2*abs(A[i] - A[i+1]);
            //cout << A[i] << " " << A[i+1] << "\n";
        }
        if(A[i-1]==A[i+1]) sum -= 2*abs(A[i-1] - A[i]);
        cout << sum <<"\n";
    }


}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <cstdio>
typedef long long ll;
const int maxn = 1e5 + 5;

inline ll get(const int &l,const int &r)
{
    extern ll sum[];
    return sum[r] - sum[l - 1]; 
}//get sum

ll n, m, v, p;
ll a[maxn], sum[maxn];
ll res;

int main(void)
{
    scanf("%lld %lld %lld %lld", &n, &m, &v, &p);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    std::sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + a[i];
    for (ll i = 1; i <= n - p; i++)
    {
        ll vote = m * v - m * (p - 1) - m; //总投票 - 投给前p - 1个 - 投给a[i]的 = 投给 < a[i] | a[i + 1] ~ a[p]
        ll had = a[i] + m; 
        if (had >= a[n - p + 1] && vote <= (i - 1) * m + had * (n - p + 1 - i) - get(i + 1, n - p + 1)) res++; // (i - 1) * m 投给 < a[i], 后半段投给a[i] ~ a[n - p + 1], 若 >= vote 则可能;
    }
    res += p; 
    std::cout << res << std::endl;
}

Measured memory_bytes: 5272
#include<bits/stdc++.h>
using namespace std;
int N,M,D[100100],R[100100],x,y,ans;
vector<int> G[100100],Q;
int main()
{
	cin>>N>>M;
	for (int i=0;i<M;i++)
	{
		cin>>x>>y;
		G[x].push_back(y);
		R[y]++;
	}
	for (int i=1;i<=N;i++) if (R[i]==0) Q.push_back(i);
	while (!Q.empty())
	{
		int x=Q.back(); Q.pop_back();
		if (ans<D[x]) ans=D[x];
		for (auto &y : G[x])
		{
			if (D[y]<D[x]+1) D[y]=D[x]+1;
			if (--R[y]==0) Q.push_back(y);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

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

using namespace std;


int main(){

    string s;
    cin >> s;

    int n = s.length();
    bool flg = true;
    if(s[0]!='A')flg = false;
    int cnt = 0;
    rep(i,2,n-1){
        if(s[i]=='C')cnt++;
        else if(s[i]>'z' || s[i]<'a')flg = false;
    }
    if(cnt!=1)flg = false;
    if(s[1]>'z' || s[1]<'a' || s[n-1]>'z' || s[n-1]<'a')flg = false;

    if(flg)cout << "AC" << endl;
    else cout << "WA" << endl;

}


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

int main(){
    string S;//文字列型変数Sを宣言
    cin >> S;//変数Sに入力
    int counter = 0;//int型変数counterを宣言
    if (S[0] == 'o') ++counter;//1文字目にoがあればcounterをインクリメント
    if (S[1] == 'o') ++counter;//2文字目にoがあればcounterをインクリメント
    if (S[2] == 'o') ++counter;//3文字目にoがあればcounterをインクリメント
    cout << 700 + 100 * counter << endl;//合計を算出し出力
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ; cin >> n ;
    vs v ( n ) ;
    for ( int i=0 ; i < n ; i++ )
    {
        cin >> v[i] ;
        sort ( all ( v[i] ) ) ;
    }

    sort ( all ( v ) ) ;

    ll ans = 0 ;
    int indx = 0 ;

    // for ( auto i  : v ) cout << i << " " ; line

    for ( int i=0 ; i < n ; i++ )
    {
        for ( ; i < n && v[i] == v[indx] ; i++ ) ;
        i-- ;

        ll temp = i-indx + 1 ;
        ans += ( ( temp * ( temp-1 ) ) >> 1 ) ;
        if ( i == n ) break ;
        indx = i + 1 ;
    }

    cout << ans ; line
}

int main()
{fast
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  ll n = s.length()+1;
  vector<ll> a(n, 0);

  ll t = 0;
  for (int i=0; i<n-1; i++) {
    if (s[i] == '<') {
      t++;
      a[i+1] = t;
    } else {
      t = 0;
    }
  }
  t = 0;
  for (int i=n-1; i>=0; i--) {
    if (s[i] == '>') {
      t++;
      a[i] = max(a[i], t);
    } else {
      t = 0;
    }
  }
  ll ans = 0;
  for (auto v:a) {
    ans+=v;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans;
    ll temp;

    temp = n % k;
    ll half = k / 2;

    if (temp > half) {
        ans = abs(temp - k);
    } else {
        ans = temp;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  int d[128];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> d[i];
  int num[128] = {0};
  for (int i = 0; i < N; i++) num[d[i]]++;
  int res = 0;
  for (int i = 1; i <= 100; i++) {
    if (num[i]) {
      res++;
    }
  }
  cout << res << endl;
}


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

constexpr int inf = 1e9;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> dp(n + 1, vector<int>(2, inf)); // 0: #
    if(s[0] == '#') {
        dp[1][0] = 0, dp[1][1] = 1;
    } else {
        dp[1][0] = 1, dp[1][1] = 0;
    }
    for(int i = 1; i < n; ++i) {
        if(s[i] == '#') {
            dp[i + 1][0] = min(dp[i][0], dp[i][1]);
            dp[i + 1][1] = dp[i][1] + 1;
        } else {
            dp[i + 1][0] = min(dp[i][0], dp[i][1]) + 1;
            dp[i + 1][1] = dp[i][1];
        }
    }

    cout << min(dp[n][0], dp[n][1]) << endl;
}

Measured memory_bytes: 11396
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

ll x;


ll fastPower(ll b , ll p){
    if(p == 0)
        return 1;
    
    ll ret = fastPower(b,p/2);
    return (p&1 ? ret*ret*b : ret*ret);

}

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	
	scanf("%lld", &x);
	map < ll , ll > vis;
	for(ll i = -3000 ; i <= 3000 ; ++i)
		vis[fastPower(i , 5)] = i;
	
	for(ll j = 0 ; j <= 3000 ; ++j)
		if(vis[fastPower(j , 5) - x])
			return printf("%lld %lld\n" , j , vis[fastPower(j , 5) - x]) , 0;
	
	
	
    return 0;
}




Measured memory_bytes: 4112
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        x: usize,
    }

    for (i, t) in (400..2000).step_by(200).rev().enumerate() {
        if x >= t {
            println!("{}", i+1);
            return;
        }
    }
}


Measured memory_bytes: 2164
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*A = map(int, read().split())

    cnt = [0] * N
    ans = 1
    for a in A:
        if a == 0:
            cnt[0] += 1
            continue
        ans *= cnt[a - 1] - cnt[a]
        ans %= MOD
        cnt[a] += 1
        
    if cnt[0] == 1:
        ans *= 3
    elif cnt[0] <= 3:
        ans *= 6
    else:
        ans = 0
    
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13956
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	l := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&l[i])
	}

	d := 0
	count := 0
	for i := 1; i <= n + 1; i++ {
		if d <= x {
			count++
		}
		if i == n + 1 {
			break
		}
		d = d + l[i - 1]
 	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
char s[100][100];
int dx[]={0,-1,1,0};
int dy[]={-1,0,0,1};

int main(){
    int h,w;
    cin>>h>>w;
    for(int i=0;i<100;i++){
        s[0][i]='.';
        s[h+1][i]='.';
        s[i][w+1]='.';
        s[i][0]='.';
    }
    for(int j=1;j<=h;j++){
        for(int i=1;i<=w;i++){
            cin>>s[j][i];
        }
    }
    /*for(int j=0;j<=h+1;j++){
        for(int i=0;i<=w+1;i++){
            cout<<s[j][i];
        }
        cout<<endl;
    }*/
    for(int j=1;j<=h;j++){
        for(int i=1;i<=w;i++){
            bool f=false;
            if(s[j][i]=='#'){
                for(int v=0;v<4;v++){
                    if(s[j-dy[v]][i-dx[v]]=='#') f=true;
                }
                if(!f){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

//関数
//main関数
int main() {
    
    
    //入力
    string s,t;
    cin>>s>>t;
    
    //計算
    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1,0));
    
    
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s.at(i-1)==t.at(j-1)){
                dp.at(i).at(j)=dp.at(i-1).at(j-1)+1;
            }else if(dp.at(i-1).at(j)<dp.at(i).at(j-1)){
                dp.at(i).at(j)=dp.at(i).at(j-1);
            }else{
                dp.at(i).at(j)=dp.at(i-1).at(j);
            }
        }
    }
    
 //   cout<<"dp表示はじめ"<<endl;
    for(int i=0;i<=s.size();i++){
        //cout<<"sの"<<i<<"文字まで"<<endl;
        for(int j=0;j<=t.size();j++){
     //       cout<<dp.at(i).at(j)<<" ";
        }
   //     cout<<endl;
    }
  //  cout<<"dp表示終わり"<<endl;
    
    vector<char> ans(0);
    
    long i=s.size(),j=t.size();
    while(i>0 && j>0){
        if(dp.at(i).at(j)==dp.at(i-1).at(j)){
            i--;
        }else if(dp.at(i).at(j)==dp.at(i).at(j-1)){
            j--;
        }else{
            ans.push_back(s.at(i-1));
            i--;
            j--;
        }
    }
    
    
    //出力
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans.at(i);
    }
    cout<<endl;
}

Measured memory_bytes: 35584
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int visited[100000];
    int repeation=0;
    int numbers=0;
    int a;
    for (int i=0;i<100000;i++){
        visited[i]=0;
    }
    for (int i=0;i<n;i++){
        cin>>a;
        if (visited[a]==1){
            repeation++;
        }else{
            numbers++;
            visited[a]=1;
        }
    }
    if (repeation%2==1){
        numbers--;
    }
    cout<<numbers<<endl;
    return 0;
}


Measured memory_bytes: 640
// -------------------------------------------------------
#include <iostream>
#include <string>
#include <stdio.h>
#include <cassert>
#include <vector>
using namespace std;

int main() {
	int A, B, C;
	// string s;
#ifdef DEBUG
	int a = 5;
	int b = 7;
	int c = 5;
    A = a; B = b; C = c;
#else
	cin >> A >> B >> C;
#endif

	vector<int> vec{ A, B, C };
	// cin >> s;
	vector<int> five;
	vector<int> seven;

	for (int i : vec) {
		if (i == 5) {
			five.push_back(1);
		}
		else if (i == 7) {
			seven.push_back(1);
		}
	}
	if (five.size() == 2 && seven.size() == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

#ifdef DEBUG
	cin >> A;
#endif
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;


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

	int total = 0;
	int mi = 10000;

	for (int i = 0; i < N; ++i)
	{
		total += L + i;
		if (abs(L + i) < abs(mi))
		{
			mi = L + i;
		}
	}

	cout << total - mi << endl;

	return 0;
}

Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split(" "))
A, B, C = [list(map(int, input().split(" "))) for _ in range(3)]
# X, Y, Z, K = 1000, 1000, 1000, 3000
# A, B, C = [[i*j for j in range(1000)] for i in range(3)]

ab_cakes = []
for a in A:
    for b in B:
        ab_cakes.append(a+b)

ab_cakes = sorted(ab_cakes, reverse=True)[:K]

abc_cakes = []
for ab in ab_cakes:
    for c in C:
        abc_cakes.append(ab + c)

abc_cakes = sorted(abc_cakes, reverse=True)[:K]

for abc in abc_cakes:
    print(abc)

Measured memory_bytes: 147844
//O(N^4)解のアイディアに加え
//各iについて「すでに使うことが確定している数のみを使ってa[i]から作れる数たち」を記録し
//「k以下の数だけを使ってxからyを作れるか」をO(N^3)で前計算しておけば
//残りがうまくいくかを各O(1)で判定できるので全体でO(N^3)

#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)(((n)>>(m))&1)

int memo[60][60][60];//memo[i][j][k]=(k以下の数のみの操作でiからjを作れるか？　Yesなら1、Noなら-1)

int f(int a,int b,int k){
	if(a<b)return -1;
	if(k==0)return a==b?1:-1;
	if(memo[a][b][k])return memo[a][b][k];

	int t=f(a,b,k-1);
	if(t==1)return memo[a][b][k]=1;
	t=f(a%k,b,k-1);
	if(t==1)return memo[a][b][k]=1;
	return memo[a][b][k]=-1;
}

int a[60],b[60];
ll d[60];//d[i]=(既に使うことが決まっている数のみを使って、a[i]から作ることができる数の集合(bit))
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%d",a+i);
	rep(i,0,n)scanf("%d",b+i);
	rep(i,0,n)d[i]=1LL<<a[i];
	
	rep(i,0,n)if(f(a[i],b[i],50)==-1){
		puts("-1");
		return 0;
	}
	
	ll ans=0;
	for(int k=50;k>0;k--){
		int flag=0;
		rep(i,0,n){
			int t=0;
			rep(j,0,51)if(bit(d[i],j)&&f(j,b[i],k-1)==1)t=1;
			if(t==0){
				flag=1;
				break;
			}
		}
		if(flag){
			ans|=1LL<<k;
			rep(i,0,n)rep(j,0,51)if(bit(d[i],j))d[i]|=1LL<<(j%k);
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
        int n;
        cin>>n;
        int a[n];
        for(int k=0;k<n;k++){
                cin>>a[k];
        }
        for(int f=n-1;f>=0;f--){
                cout<<a[f];
                if(f!=0)cout<<" ";
        }
        cout<<endl;
}

Measured memory_bytes: 3096
/*
*ID: juryc
*LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t; cin>>s>>t;
int mi=0x3f3f3f3f; 
int n1=s.length(),n2=t.length();
for(int i=0;i<=n1-n2;i++){
int st=i; int cnt=0; 
for(int j=0;j<n2;j++){
if(s[st]!=t[j]) cnt++; 
st++;
}
mi=min(mi,cnt); 
}
cout<<mi<<endl;
return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#define WALL "####################"

int main(void) {
    int n, b, f, r, v, tbl[4][3][10] = {};
    for(scanf("%d", &n); n--; tbl[~-b][~-f][~-r] += v) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
    }
    for(n = 0; n < 120; n++) {
        n % 30 || !n || printf("%s\n", WALL);
        printf("%2d", tbl[n / 30][n % 30 / 10][n % 10]);
        -~n % 10 || printf("\n");
    }
    return 0;
}

Measured memory_bytes: 620
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,k,w[10],s[10],sw;
string f[10];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>f[i]>>w[i]>>s[i];
for(sw=0,i=0;i<n;i++)sw+=w[i];
for(k=0;k<n;k++){
for(j=-1,i=0;i<n;i++){
if(sw-w[i]<=s[i]){
if(j==-1)j=i;else if(w[j]<w[i])j=i;
}
}
cout<<f[j]<<endl;
sw-=w[j];w[j]=0;
}
}
return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    int a,b,k;
    int i;
    int r;
        int l;

    int j=1;
    int x[101] = {0};
    int y[101] = {0};
    int z[101] = {0};

    // スペース区切りの整数の入力
    scanf("%d %d %d",&a,&b,&k);

   for(i=1;i<=100;i++){
        if(a % i == 0){
              x[i]++;
              //printf("x %d\n",i);
        }
   }

   for(i=1;i<=100;i++){
        if(b % i == 0){
              y[i]++;
             //printf("y %d\n",i);
        }
   }

   for(i=1;i<=100;i++){
        if(x[i] == y[i]){
            if(x[i] == 0){
                continue;
            }
              z[j] = i;
              j++;
        }
   }
   
    // 出力
    printf("%d\n",z[j-k]);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int s[3],a;
int main(){
    for(int i=0;i<3;i++)cin>>s[i];
    sort(s,s+3);
    a = s[0]*s[1];
    a/=2;
    cout<<a<<endl;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: ι⊥
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) puts("YES");
  else puts("NO");
  return 0;
}


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


#define SIZE 1000001

typedef struct node{
    char num;
    struct node *next;//後の要素へのポインタ
}stack;



void push(stack **first,  char number){
    stack *new = calloc(1,sizeof(stack));//メモリ確保
    if(new == NULL){
        exit(1);
    }
    new->num = number;//newの指すアドレスのnumの要素にnumber代入
    new->next = *first;//新しく作ったノードの次のノードをfirstが指すノードにする。
    *first = new;//一番手前のノードをfirstとして更新
    
}

char pop(stack **first){
    char elem;
    stack *tmp = *first;//保存場所用意。

    if(tmp == NULL){//メモリ確保
        exit(1);
    }

    elem = tmp->num;
    *first = tmp->next;//firstの値を、今指すノード(先頭だったもの)の次のノードに変える。
    free(tmp);//メモリ開放

    return elem;
    
}


int main(void){
    char sentence[SIZE];
    int i;
    int collected = 0;
    stack *stk;

    stk = NULL;//初めはNULLを指すようにする。

    scanf("%s", sentence);
    for(i=0; sentence[i] != '\0'; i++){
        if(stk == NULL){//1文字目だった時の処理
            push(&stk, sentence[i]);
        }
        else{
            if(sentence[i] != stk->num){//異なる色だった時⇒一回取り出し、収集数+2
                pop(&stk);
                collected+=2;
            }
            else{//同じ色だった時⇒その要素を入れる
                push(&stk, sentence[i]);
            }
        }
    }      
    
    printf("%d\n", collected);

    return 0;
}

Measured memory_bytes: 4916
#include <vector>
#include <iostream>
#include <set>

int main() {
	int n;
	std::cin >> n;
	std::set<int> set;
	for (auto i = 0; i < n; ++i) {
		int o, x, r;
		std::cin >> o >> x;
		switch (o) {
		case 0: set.insert(x); std::cout << set.size() << std::endl; break;
		case 1: std::cout << set.count(x) << std::endl; break;
		case 2: set.erase(x); break;
		default:
			std::cin >> r;
			auto end = set.upper_bound(r);
			for (auto begin = set.lower_bound(x); begin != end; ++begin) {
				std::cout << *begin << std::endl;
			}
		}
	}
}


Measured memory_bytes: 12332
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b % 2) == 1) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


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

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

    int fbsum=0,fwsum=0;
    for(int i=0;i<S.size();i++){
        if(i%2==0){
            if(S[i]=='1') fbsum++;
            if(S[i]=='0') fwsum++;
        }else{
            if(S[i]=='1') fwsum++;
            if(S[i]=='0') fbsum++;
        }
    }

    cout<<min(fbsum,fwsum)<<endl;
}

Measured memory_bytes: 512
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {

	string s;
	cin >> s;
	ll ans = 0;
	rep(i, 3) if (s[i] == '1') ++ans;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<functional>
#include<limits.h>

using namespace std;

struct Edge{
	int to,cost;
	Edge(){}
	Edge(int to,int cost):to(to),cost(cost){}
};

int dijkstra(const vector< vector<Edge> > vve,int s,int t){
	priority_queue<pair<int,int>, vector< pair<int,int> >, greater< pair<int,int> > > que;
	pair<int,int> pii;
	pii.first = 0;
	pii.second = s;
	que.push(pii);

	vector<int> dist(vve.size(), INT_MAX);
	
	while(!que.empty()){
		int cost = que.top().first;
		int now = que.top().second;
		que.pop();

		if(dist[now] <= cost){
			if(dist[t] < cost){
				break;
			}
			continue;
		}

		dist[now] = cost;

		for(int i=0;i<vve[now].size();i++){
			que.push( make_pair(vve[now][i].cost + cost, vve[now][i].to) );
		}
	}

	return dist[t];
}

int main(){
	int n,m;
	while(true){
		cin >> n >> m;
		if(n == 0 && m==0){
			break;
		}

		vector< vector<Edge> > coin(m);
		vector< vector<Edge> > time(m);

		for(int i=0;i<n;i++){
			int a,b,c,t;
			cin >> a >> b >> c >> t;
			coin[a-1].push_back(Edge(b-1,c));
			coin[b-1].push_back(Edge(a-1,c));
			time[a-1].push_back(Edge(b-1,t));
			time[b-1].push_back(Edge(a-1,t));
		}

		int k;
		cin >> k;
		for(int i=0;i<k;i++){
			int p,q,r;
			cin >> p >> q >> r;
			int ans;
			if(r){
				ans = dijkstra(time,p-1,q-1);
			}else{
				ans = dijkstra(coin,p-1,q-1);
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1456
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], K = I[1], M = Max(2 * K, N);
		var dp = new double[M + 1];
		for (var i = K; i <= M; i++) dp[i] = 1;
		for (var i = K - 1; i >= 1; i--) dp[i] = dp[2 * i] / 2;
		var s = 0.0;
		for (var i = 1; i <= N; i++) s += dp[i];
		WriteLine(s / N);
	}
}
static class Func { }


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

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i = 0; i < N; i++){
        cin >> S.at(i);
    }

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

    for(int i = 0; i < N; i++){
        cout << S.at(i);
    }

    cout << endl;

}

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

int main(){
    int n, nn;
    cin >> n;
    nn = n;
    int order = 1;
    while(nn >= 10){
        order++;
        nn /= 10;
    }
    
    int i = 1;
    long long sum = 0;
    while ((2*i - 1) < order){
        int ten = 1;
        for (int j=1;j<=(2*i-1);j++) ten *= 10;
        sum += 9 * ten / 10;
        i++;
    }
    if ((2*i - 1) == order){
        int ten = 1;
        for (int j=1;j<=(2*i-1);j++) ten *= 10;
        sum += n - (ten / 10) + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
use std::io;
use std::collections::BTreeSet;

fn main() {
    let (n, mut h) = {
        let v = read_values::<usize>();
        (v[0], v[1] as i64)
    };
    let mut vec = Vec::new();
    for _ in 0..n {
        let v = read_values::<i64>();
        vec.push((v[0], true));
        vec.push((v[1], false));
    }
    vec.sort();

    let mut ans = 0;
    for i in (0..vec.len()).rev() {
        let (atk, inf) = vec[i];
        if inf {
            ans += (h + atk - 1) / atk;
            break;
        } else {
            ans += 1;
            h -= atk;
        }
        if h <= 0 {
            break;
        }
    }
    println!("{}", ans);
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read_values<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 9284
def solve(H, W, N, sr, sc, S, T):
    # Up
    i = sr
    for s, t in zip(S, T):
        if s == "U":
            i -= 1
        if i < 1:
            return False
        if t == "D" and i + 1 <= H:
            i += 1
    # Down
    i = sr
    for s, t in zip(S, T):
        if s == "D":
            i += 1
        if i > H:
            return False
        if t == "U" and i - 1 >= 1:
            i -= 1

    # Right
    i = sc
    for s, t in zip(S, T):
        if s == "R":
            i += 1
        if i > W:
            return False
        if t == "L" and i - 1 >= 1:
            i -= 1

    # Left
    i = sc
    for s, t in zip(S, T):
        if s == "L":
            i -= 1
        if i < 1:
            return False
        if t == "R" and i + 1 <= W:
            i += 1

    return True

if __name__ == "__main__":
    H, W, N = tuple(map(int, input().split(" ")))
    sr, sc = tuple(map(int, input().split(" ")))
    S = input()
    T = input()
    print("YES" if solve(H, W, N, sr, sc, S, T) else "NO")

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

#define cal(i, n, x) for(int i = x; i < n; i++)

using namespace std;

int main(){
    int n, d[50];
    cin >> n;
    cal(i, n, 0) cin >> d[i];
    int total = 0;
    cal(i, n, 0) cal(j, n, i + 1) total += d[i] * d[j];
    cout << total;
    return 0;
}

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

int main(){
    while(true){
        int n;
        double s,sum=0,sum2=0;
        cin >> n;
        if (n==0) break;
        
        for (int i=0; i<n; i++){
            cin >> s;
            sum += s;
            sum2 += pow(s,2);
        }
        double m1=sum/n,m2=sum2/n;
        double a = sqrt(m2-pow(m1,2));
        cout << fixed << setprecision(15) << a << "\n";
    }
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, n, a;
  scanf("%d %d", &h, &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a);
    h -= a;
  }
  if(h > 0) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import math

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
def drawKoch(p1, p2, N):
    s = Point((2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3)
    t = Point((p1.x+2*p2.x)/3,(p1.y+2*p2.y)/3)
    xx = t.x - s.x
    yy = t.y - s.y
    u = Point(s.x + xx/2 - yy*math.sqrt(3)/2, s.y + xx*math.sqrt(3)/2 + yy/2)
    if N > 1:
        drawKoch(p1, s, N-1)
        drawKoch(s, u, N-1)
        drawKoch(u, t, N-1)
        drawKoch(t, p2, N-1)
    else:
        printPoint(p1)
        printPoint(s)
        printPoint(u)
        printPoint(t)

def printPoint(p):
    print("{0:.8f} {1:.8f}".format(p.x, p.y))

n = int(input().rstrip())
p1 = Point(0,0)
p2 = Point(100,0)
if n == 0:
    printPoint(p1)
    printPoint(p2)
else:
    drawKoch(p1, p2, n)
    printPoint(p2)


Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,doe;
int fa[101010],id[101010];
int pre[202020],son[202020],now[101010];
ll a[101010],b[101010],f[101010],sum[101010];
bool br[101010];
int find(int x)
{
	if (fa[x]==x) return fa[x];
	fa[x]=find(fa[x]);
	return fa[x];
}
void add(int x,int y)
{
	++doe;
	pre[doe]=now[x];
	now[x]=doe;
	son[doe]=y;
}
bool cmp(int u,int w)
{
	return a[u]<a[w];
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) scanf("%lld%lld",&a[i],&b[i]),a[i]=max(a[i]-b[i],0ll);
	int x,y;
	for (int i=1;i<=m;++i) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	
	for (int i=1;i<=n;++i) id[i]=i,fa[i]=i,f[i]=a[i],sum[i]=b[i];
	sort(id+1,id+1+n,cmp);

	for (int i=1;i<=n;++i)
	{
		x=id[i];
		br[x]=1;
		int p=now[x];
		while (p)
		{
			int y=son[p];
			if (br[y])
			{
				int xx=find(x),yy=find(y);
				if (xx!=yy)
				{
					fa[yy]=xx;
					sum[xx]+=sum[yy];
					f[xx]=min(f[xx],max(f[yy],a[xx]-sum[yy]));
				}
			}
			p=pre[p];
		}
	}
	printf("%lld\n",sum[id[n]]+f[id[n]]);
	return 0;
}



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

int main(){
  int a,b;
  std::cin >> a>>b;
  if(a<=5){
    std::cout << 0 << std::endl;
  }else if(a<=12){
    std::cout << b/2 << std::endl;
  }else{
    std::cout << b << std::endl;
  }
}

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

int main() {

	int x, y; cin >> x >> y;
	string ans = "No";
	if (y % 2 == 1) {
		cout << ans << endl;
		return 0;
	}
	if (2 * x <= y && y <= 4 * x) ans = "Yes";
	cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int ans = N;
  
  sort(vec.begin(), vec.end());
  
  if(N == 1){
    cout << ans << endl;
  }
  else{
   for(int j=0; j<N-1; j++){
    if(vec.at(j) == vec.at(j+1)){
      ans--;
    }
   }
  cout << ans << endl;
  }
}

Measured memory_bytes: 256
import itertools
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

for v in itertools.combinations([a, b, c, d, e], 2):
    if v[1]-v[0] > k:
        print(':(')
        exit()
print('Yay!')


Measured memory_bytes: 9128
let nil = -1

type tree = {
  mutable parent : int;
  mutable child : int;
  mutable bro : int;
  mutable depth : int;
}

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1)
  in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1);
  in
  doit (root 0) 0

let print_tree t =
  let print i =
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).parent;
    print_string ", depth = "; print_int t.(i).depth;
    print_string (if t.(i).parent = nil then ", root, " else if t.(i).child = nil then ", leaf, " else ", internal node, ");
    print_string "[";
    let rec print_children c =
      if c <> nil then begin
        if c <> t.(i).child then print_string ", ";
        print_int c;
        print_children t.(c).bro
      end
    in
    print_children t.(i).child;
    Printf.printf "]\n";
  in
  Array.iteri (fun i _ -> print i) t

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  let rec read i =
    if i < n then begin
      let id, k = Scanf.scanf "%d %d " (fun id k -> id, k) in
      let rec read_node j left_child =
        if j < k then begin
          let c = Scanf.scanf "%d " (fun i -> i) in
          t.(c).parent <- id;
          if j = 0 then t.(id).child <- c else t.(left_child).bro <- c;
          read_node (j + 1) c
        end
      in
      read_node 0 0;
      read (i + 1)
    end
  in
  read 0;
  set_depth t n;
  print_tree t

Measured memory_bytes: 13236
s=input()
t=input()

r="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

j=0
for i in range(len(s)):
  if s[i].islower():
    s = s.replace(s[i],r[j])
    j += 1

j=0
for i in range(len(t)):
  if t[i].islower():
    t = t.replace(t[i],r[j])
    j += 1

print('Yes' if s==t else 'No')


Measured memory_bytes: 3632
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    string t; cin >> t;
    cout << (s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]) << '\n';
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int mx(int x, int n);
int euc(int x, int y);
int solve(int p, int q, int a, int n, int down);
int main(){
  int p,q,a,n;
  while(cin >>p>>q>>a>>n,p||q||a||n){
    int ans = 0;
    for(int i=1; i<=n; i++) ans+=solve(p,q,a,i,q/p);
    cout <<ans<<endl;
  }
  return 0;
}
int mx(int x, int n){
  if(n == 1) return x;
  return mx(x,n-1)*x;
}
int euc(int x, int y){
  if(y == 0) return x;
  return euc(y,x%y);
}
int solve(int p, int q, int a, int n, int down){
  if(n == 1 && q%p == 0 && q/p<=a && down<=q/p) return 1;
  int ans = 0;
  for(int i=down,up=n*q/p; i<=up; i++){
    if(i == 0) continue;
    if(mx(i,n) > a) break;
    int M = q*i/euc(q,i);
    if(M/i<p*M/q) ans+=solve(p*M/q-M/i,M,a/i,n-1,i);
  }
  return ans;
}

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

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

using namespace std;

struct Point {
    int x;
    int y;
    Point(){}
    Point(int x, int y){
        this->x = x;
        this->y = y;
    }
};

struct BluePoint : Point{
    using Point::Point;
};
struct RedPoint : Point{
    using Point::Point;
};

bool operator<(const BluePoint& p1, const BluePoint& p2){
    return p1.x < p2.x;
}
bool operator>(const RedPoint& p1, const RedPoint& p2){
    return p1.y > p2.y;
}

int main(){
    int n; cin >> n;
    vector<RedPoint> r(n);
    vector<BluePoint> b(n);
    int x,y;
    rep(i, n) {
        cin >> x >> y;
        r[i] = RedPoint(x,y);
    }
    rep(i, n) {
        cin >> x >> y;
        b[i] = BluePoint(x,y);
    }
    sort(r.begin(), r.end(), greater<RedPoint>());
    sort(b.begin(), b.end());
    int ans = 0;
    for(auto bit = b.begin(); bit != b.end(); bit++){
        for(auto rit = r.begin(); rit != r.end(); rit++){
            if(bit->x > rit->x && bit->y > rit->y){
                ans++;
                r.erase(rit);
                break;
            }
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
void swap(int& x, int& y){
    int tmp = x;
    x=y;
    y=tmp;
}
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    if(a>b) swap(a,b);
     
    cout << a << " " << b << " "  << c << endl;
}


Measured memory_bytes: 3084