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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

lint mod = 1e9 + 7;

void comb(vector<vector<long long int>> &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int k = 1; k < v.size(); k++)
    {
        for (int j = 1; j < k; j++)
        {
            v[k][j] = (v[k - 1][j - 1]% mod + v[k - 1][j]% mod);
        }
    }
}

int main()
{
    lint n, k;
    cin >> n >> k;

    lint ans;
    lint x,N;
    N = n - k + 1;
    vector<vector<long long int>> v(N + 1, vector<long long int>(N + 1, 0));
    comb(v);
    N = k - 1;
    vector<vector<long long int>> v2(N + 1, vector<long long int>(N + 1, 0));
    comb(v2);

    FOR(i, 0, k)
    {
        x = i + 1;
        ans = (v[n - k + 1][x] % mod) * (v2[k - 1][x - 1] % mod) % mod;
        if(x>n-k+1){
            ans = 0;
        }
        cout << ans << "\n";
    }

    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = max(a, b);
  if(a > b) ans += a - 1;
  else if(a == b) ans += a;
  else ans += b - 1;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){

    int a, b;
    cin>> a>> b;

    if(a>0) cout<<"Positive"<< endl;
    else if(b<0){
        if((b-a+1)%2==1)cout<< "Negative"<< endl;
        else cout<<"Positive"<< endl;
    }
    else cout<< "Zero"<< endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
conditions = [tuple(map(int, input().split())) for j in range(m)]
exist = False
for i in range(1000):
    if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in conditions):
        ans = i
        exist = True
        break
print(ans if exist else -1)

Measured memory_bytes: 9192
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
    A[i] -= i+1
A.sort()
#for i in range(N):
#    B.append(A[i]-i-1)
#B.sort()
med = N // 2
grief = 0
for i in range(N):
    grief += abs(A[i]-A[med])
#for i in range(N):
#    grief += abs(B[i]-B[med])
print(str(grief))

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

int main(void) {
	int n;
	cin >> n;
	int ans = 0;
	vector<int> b(n-1);

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

	vector<int> a(n);
	a[0] = b[0];
	for (int i = 1; i <= n-2; i++) {
		a[i] = min(b[i], b[i-1]);
	}
	a[n-1] = b[n-2];
	
	for (int i = 0; i < n; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N,M;
    cin >> N >> M;

    ll ok = 100 * (N-M);
    ll ng = 1900 * M;
    ll s = ok + ng;

    ll t = 1;
    rep(i,M) t *= 2;

    cout << s * t << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	char p;
	cin>>p;
	if(p=='A') cout<<'T';
	else if(p=='T') cout<<'A';
	else if(p=='C') cout<<'G';
	else if(p=='G') cout<<'C';
	
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n;
    cin >> n;
    std::vector<std::vector<int>> xy;
    for(int i = 0; i < n; i++){
        std::vector<int> temp(2);
        cin >> temp[0] >> temp[1];
        if(temp[0] != 0 || temp[1] != 0){
            xy.pb(temp);
        }
    }
    std::sort(xy.begin(), xy.end(),
          [](const std::vector<int>& a, const std::vector<int>& b) {
    return atan2(a[0],a[1]) < atan2(b[0],b[1]);
    });
    double out = 0;
    int l = xy.size();
    for(int i = 0; i < 2 * l; i++){
        for(int j = i; j < 2 * l; j++){
            double tempx = 0;
            double tempy = 0;
            for(int k = i; k <= min(j, i + l - 1); k++){
                tempx += xy[k % l][0];
                tempy += xy[k % l][1];
            }
            chmax(out,sqrt(tempx * tempx + tempy*tempy));
        }
    }
    cout << fixed << setprecision(30) << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
int compare(const void *a, const void *b){
	long long int *A = (long long int *)a;
	long long int *B = (long long int *)b;
	if (*A > *B) return 1;
	if (*A < *B) return -1;
	return 0;
}
int main()
{   long long n,a[200001],cnt=0,ss=1;
    long long sub[200004]={0};
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        sub[i+1]=0;
        sub[i+1]=sub[i]+a[i];
        //printf("sub[%d]=%lld\n",i+1,sub[i+1]);
    }
    qsort(sub,n+1,sizeof(long long),compare);
    //printf("sorted succesfully!\n");
    for(int i=0;i<n;i++){
        //printf("sub[%d]=%lld,ss=%d\n",i,sub[i],ss);
            if(sub[i]==sub[i+1]){
                ss++;
                }else{
                    cnt+=ss*(ss-1)/2;
                    ss=1;
                }
    }
    cnt+=(ss*(ss-1)/2);
    printf("%lld",cnt);
    
    return 0;
}


Measured memory_bytes: 4860
#include<stdio.h>
#include<string.h>
int main(void){
  char s[1000000];
  scanf("%s",&s);
  int cnt = 0;
  for(int i = 1;i < strlen(s);i++){
    if(s[i] == s[i - 1]){
      cnt++;
      if(s[i] == '0'){
        s[i] = '1';
      }else{
        s[i] = '0';
      }
    }
  }
  if(strlen(s) < 2 * cnt)cnt = strlen(s) - cnt;
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = int(5e6);
bool isprime[MAXN + 10];
vector<int> primes;

int main() {
  fill(isprime, isprime+MAXN+10, true);
  for(int i = 2; i <= MAXN; i++) {
    if(isprime[i]) {
      primes.push_back(i);
      for(int j = 2*i; j <= MAXN; j += i) {
        isprime[j] = false;
      }
    }
  }

  while(1) {
    int n;
    scanf("%d", &n);
    long long ans = 1;
    for(int p : primes) {
      int cur = 0;
      for(int m = n; m > 0; m /= p) cur += m / p;
      ans = (ans * (cur + 1)) % (int(1e9) + 7);
    }
    printf("%lld\n", ans);break;
  }
  return 0;
}


Measured memory_bytes: 7284
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<x86intrin.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

int64_t MtDist(int64_t a,int64_t b,int64_t c,int64_t d){
    return abs(a-c)+abs(b-d);
}

int main(){
    int N,M;
    int64_t a[50],b[50],c[50],d[50];
    int nearest[50];

    scanf("%d %d%*c",&N,&M);
    for(int i=0;i<N;i++)
        scanf( "%lld %lld", &(a[i]), &(b[i]) );
    for(int i=0;i<M;i++)
        scanf( "%lld %lld", &(c[i]), &(d[i]) );
    
    for(int i=0;i<N;i++){
        int64_t dist=800000000;
        for(int j=0;j<M;j++){
            if(dist > MtDist(a[i],b[i],c[j],d[j])){
                dist=MtDist(a[i],b[i],c[j],d[j]);
                nearest[i]=j;
            }
        }
    }
    for(int i=0;i<N;i++)
        printf("%d\n",nearest[i]+1);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
constexpr double PI = atan2(0, -1);
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, x;
    cin >> a >> b >> x;
    double y = 1.0 * x / a;
    double g;
    if (2 * y <= a * b)
        g = atan2(b, 2 * y / b);
    else
        g = atan2(2 * (a * b - y) / a, a);
    cout << setprecision(10) << fixed << g / PI * 180 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  ll n, ans = 0;
  cin >> n;
  for(ll i = 1;  i*i <= n; i++) {
    // cout << n/m << " " << n%m << endl;
    if (n%i == 0) {
      if (i > 1) {
        if (n%(i-1) == n/(i-1)) {
          ans += i-1;
        }
      }
      if (n/i-1 > 1) {
        if (n%(n/i-1) == n/(n/i-1)) {
          ans += (n/i-1);
        }
      }
      // cout << (n/i)-1 << endl;
    }
  }
  cout << ans << endl;
}


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

int main(){
    string o,e;
    cin>>o>>e;
    int l=0,r=0;
    for(int i=0;i<o.length()+e.length();i++){
        if(i%2==0)
            cout<<o[l++];
        else
            cout<<e[r++];
    }
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  int a = 1;
  int b = 1;
  int c = 1;
  int i;
  int div = 0;

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

  for(i = 0; i <= b - a; i++)
    if(c % (a + i) == 0)
      div++;

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

  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] W = new int[N];
		int s1 = 0, s2 = 0, min = Integer.MAX_VALUE;
		for(int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
			s2 += W[i];
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			s1 += W[i];
			s2 -= W[i];
			int abs = Math.abs(s1 - s2);
			if(abs < min) min = abs;
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,A;
  A=0;
  cin>>N>>K;
  for(int i=0; i<N; i++){
    int x;
    cin>>x;
    if(x<K-x+1){
      A +=2*x;
    }
    else if(x>K-x){
      A +=2*(K-x);
    }
  }
  cout<<A<<endl;
}
      

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc144_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = Convert.ToInt32(input[0]);
            int B = Convert.ToInt32(input[1]);
            int Kake = 0;

            if (A <= 9 && B <= 9)
            {
                Kake = A * B;
            }
            else
            {
                Kake = -1;
            }

            Console.WriteLine(Kake);
            Console.Read();
        }
    }
}


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

int main()
{
    int n, m, k = 0, sum = 0, a[1001], b[1001];
    vector<int> v;
    
    cin >> n >> m;

    for( int i = 0; i < n; i++ )
        cin >> a[i];

    for( int i = 0; i < n; i++ )
        b[i] = 0;

    bool j = true;
    while( j )
    {
        for( int i = 0; i < m; i++ )
        {
            v.push_back(a[k]);
            b[k]++;
            k++;
            if( k == n )
                k = 0;
        }

        int min = 10000000, max = 0;
        for( int i = 0; i < v.size(); i++ )
        {
            if( min > v[i] )
                min = v[i];
            if( max < v[i] )
                max = v[i];
        }

        sum += max - min;

        j = false;
        for( int i = 0; i < n - 1; i++ )
            if( b[i] != b[i+1] )
            {
                j = true;
                break;
            }
        v.clear();
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
			var NK = Console.ReadLine().Split().Select(int.Parse);
			int N = NK.First(), K = NK.Last();
			var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int ans = int.MaxValue;
			for (int i = K - 1; i < N; i++)
			{
				int l = x[i - (K - 1)], r = x[i];
				ans = Math.Min(ans, Math.Abs(r - l) + Math.Min(Math.Abs(l), Math.Abs(r)));
			}
			Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 23264
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);

#define csh(a,n) memset(a,n,sizeof(a));
ll arr[51];
int main(){
	for(int i=0;i<51;i++){
		arr[i]=i;
	}
	ll n;
	cin>>n;
	ll c=0;
	c=n/50;
		cout<<"50"<<endl;
		for(int i=0;i<50-n%50;i++){
			if(i!=0){
				cout<<' ';
			}
			cout<<arr[i]+c;
		}
		for(int i=50-n%50;i<50;i++){
			if(i!=0){
				cout<<' ';
			}
			cout<<arr[i]+1+c;
		}
}

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

#define int long long

signed main(){
    int n;
    cin >> n;

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

    int x[100010] = {};

    for(int i = 0;i < n;i++){
        if(i % 2 == 0){
            x[0] += a[i];
        }else{
            x[0] -= a[i];
        }
    }

    for(int i = 1;i < n;i++){
        x[i] = (a[i-1] - (x[i-1]/2))*2;
    }

    cout << x[0];
    for(int i = 1;i < n;i++){
        cout << " " << x[i];
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 2816
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;

typedef long long ll;

ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(int argc, char const *argv[])
{
    int n;scanf("%d",&n);
    vector<ll> t(n);for(int i = 0;i < n;i++)scanf("%lld",&t[i]);
    vector<ll> a(n);for(int i = 0;i < n;i++)scanf("%lld",&a[i]);
    if(n==1){
        if(t[0] == a[0])cout << 1 << endl;else cout << 0 << endl;
        return 0;
    }
    vector<ll> MIN(n,INT_MAX);
    int l,r;
    for(int i = 0;i < n;i++){
        if(!i)MIN[i] = 1;
        else{
            if(t[i] > t[i-1]){r = i;MIN[i] = 1;if(t[i] > a[i])MIN[i] = 0;}
            else MIN[i] = min(MIN[i],t[i]);
        }
    }
    for(int i = n-1;i >= 0;i--){
        if(i == n-1)MIN[i] = 1;
        else{
            if(a[i] > a[i+1]){l = i;MIN[i] = 1;if(a[i] > t[i])MIN[i] = 0;}
            else MIN[i] = min(MIN[i],a[i]);
        }
    }
    if(r > l){
        cout << 0 << endl;return 0;
    }
    mint ans = 1;
    for (int i = 0; i < n; ++i)
    {
        ans *= (mint)MIN[i];   
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 2560
def c_2D_plane_2N_points(N, R, B):
    red = sorted(R)  # 赤い点の座標(x座標で昇順ソート)
    blue = sorted(B)  # 青い点の座標(x座標で昇順ソート)
    ans = 0
    for c, d in blue:
        # 注目している青い点より"左下"にある赤い点の座標のリスト
        r = [z for z in red if z[0] < c and z[1] < d]
        if r:  # 左下に赤い点があれば
            r.sort(key=lambda x: x[1])  # y座標で昇順ソート
            # 後の青い点のことを考えると、"より左下"にある赤い点を残したほうがよい。
            # x座標でソートしていることを考えると、なるべくy座標が小さな赤い点を
            # あとに残すほうがよい。(y座標が大きな赤い点を先にペアにする)
            red.remove(r[-1])  # r[-1]が指す赤い点とペアにする。もう選べないので削除
            ans += 1
    return ans
N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
B = [[int(i) for i in input().split()] for j in range(N)]
print(c_2D_plane_2N_points(N, R, B))

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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //



int main(){

  ll N, K;
  cin >> N >> K;
  string S = is();

  ll hp = N - 1;
  ll maxhp = hp;

  rep(i, N-1){
    if (S[i]!=S[i+1]) hp--;
  }


  rep(i, K){
    if (maxhp - hp >= 2) hp += 2;
    else if (maxhp - hp == 1) hp++;
    else{
      assert(maxhp==hp);
      break;
    }
  }

  cout << hp << endl;


  
}

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

int main(){

int year;

cin>>year;

int c, a, n;
int num;

while(year>0){

cin>>c>>a>>n;

num=0;

while(c>0 && a>0 && n>0){

num++;
c--;
a--;
n--;

}

while(c>1 && a>0){

num++;
c=c-2;
a--;

}

while(c>2){

num++;
c=c-3;

}

cout<<num<<endl;
year--;

}


return 0;

}

Measured memory_bytes: 1164
n = int(input())
s = input()
ans = 0

for i in range(1,len(s)):
  s1 = s[:i]
  s2 = s[i:]
  cnt = set()
  for j in s1:
    if j in s2:
      cnt.add(j)
  ans = max(ans,len(cnt))
print(ans)


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

int main(){
    long long S;
    long long digit, pow;
    long long ans = 0;
    vector<int> N;

    cin >> S;
    digit = floor(log10(S)+1);

    while(S != 0){
        int i = S%10;
        N.push_back(i);
        S /= 10; 
    }

    for(int bit=0; bit<(1<<digit-1); bit++){
        pow = 1;
        for(int i=0; i<digit-1; i++){
            ans += N[i]*pow;
            if(bit  & (1<<i)){
                pow = 1;
            }else{
                pow *= 10;
            }
        }
        ans += N[digit-1]*pow;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
typedef pair<int, int> P;
int main() {
	queue<P> que;
	int n, x, y,culx, culy, cnt = 0;
	char map[10][10];
	int tox[12] = { 1,0,2,0,3,0,-1,0,-2,0,-3,0 }, toy[12] = { 0,1,0,2,0,3,0,-1,0,-2,0,-3 };
	cin >> n;
	while (n != cnt) {
		cnt++;
		for (int i = 1; i <= 8; ++i) {
			for (int j = 1; j <= 8; ++j) {
				cin >> map[j][i];
				map[j][i]=(map[j][i] == '1' ? true : false);
			}
		}
		cin >> x >> y;
		que.push(P(x, y));
		map[x][y] = 0;
		while (que.size()) {
			for (int i = 0; i < 12; ++i) {
				culx = que.front().first + tox[i];
				culy = que.front().second + toy[i];
				if (culx <= 0 || 9 <= culx||culy<=0||9<=culy)continue;
				if (map[culx][culy]) {
					map[culx][culy] = false;
					que.push(P(culx, culy));
				}
			}
			que.pop();
		}
		cout << "Data " << cnt << ":" << endl;
		for (int i = 1; i <= 8; ++i) {
			for (int j = 1; j <= 8; ++j) {
				cout<< (map[j][i]?1:0);
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3016
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - items[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j - items[i][0]] + items[i][1])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])


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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    int d = b - a;
    d = (d + 1) * d / 2;
    cout << d - b;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  if(a>b)cout<<(a*2)-1<<endl;
  else if(a<b)cout<<(b*2)-1<<endl;
  else if(a==b)cout<<a*2<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// Union-Find木
struct UnionFind {
    vector<int> par;
    vector<int> rank;

    // コンストラクタ 親の初期値は自分
    UnionFind(int n) : par(n) ,rank(n,1){
        REP(i,n) par[i] = i;
    }

    // 親を返す
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // 木の統合
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        rank[ry] += rank[rx];
        par[rx] = ry;
    }

    // 同じ木に属しているか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return rank[root(x)];
    }
};

int main(void)
{
    IOS
    auto nc2 = [](ll n){return n * (n-1) / 2;};
    int n, m;
    cin >> n >> m;
    vector<pii> ab(m);
    REP(i,m) cin >> ab[i].first >> ab[i].second;
    reverse(ALL(ab));
    UnionFind uf(n);
    ll cur = nc2(n);
    vector<ll> ans;
    ans.push_back(cur);

    REP(i,m) {
        int a = ab[i].first-1;
        int b = ab[i].second-1;
        if (uf.same(a,b)) {
            cur += nc2(uf.size(a));
        } else {
            cur += nc2(uf.size(a)) + nc2(uf.size(b));
        }
        uf.unite(a,b);
        cur -= nc2(uf.size(a));
        ans.push_back(cur);
    }
    ans.pop_back();

    reverse(ALL(ans));
    REP(i,ans.size()) OUT(ans[i])

    return 0;
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector< pair<int64_t,int> > p(N);
    for(int i=0; i<N; i++) {
        cin >> p[i].first;
        p[i].second = i;
    }
    p.emplace_back(0, 0);
    sort(p.rbegin(), p.rend());

    vector<int64_t> ans(N);
    int m = numeric_limits<int>::max();
    for(int i=0; i<N; i++) {
        m = min(m, p[i].second);
        ans[m] += (i+1L) * (p[i].first - p[i+1].first);
    }

    for(auto e: ans) {
        cout << e << endl;
    }
    return 0;
}


Measured memory_bytes: 4836
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
if n == 1:
	print("Hello World")
else:
	a = i()
	b = i()
	print(a+b)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int b, r, g, c, s, t;
    while(cin >> b >> r >> g >> c >> s >> t, b|r|g|c|s|t){
        cout << 100 + 15*(b*6+r*4)+7*g+2*c-3*(t-b*5-r*3-s)-2*(b*5+r*3) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  if(N>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3592
import math
n,d = list(map(int,input().split()))
cnt = 0
x_list = []
for i in range(n):
	x = list(map(int,input().split()))
	x_list.append(x)

for j in range(n):
	for k in range(1,n-j):
		l = 0
		for m in range(d):
			l += (x_list[j][m]-x_list[j+k][m])**2
		if(math.sqrt(l).is_integer()):
			cnt+=1

print(cnt)




Measured memory_bytes: 3064
#include<cstdio>

using namespace std;

int main(){
	static bool era[10001];
	era[1]=true;
	for(int i=2;i<=100;i++){
		if(!era[i])	for(int j=i*i;j<=10000;j+=i)	era[j]=true;
	}

	for(int n;~scanf("%d",&n);){
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(!era[i] && !era[n-i+1])	cnt++;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0
#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 PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# 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 dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

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 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

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

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

ll fact ( ll n )
{
    ll ans = 1 ;

    for ( int i = n ; i > 0 ; i -- )
        ans *= i , ans %= mod ;

    return ans ;
}

void solve ( int test_case )
{
    ll a , b ;
    cin >> a >> b ;

    if ( a > b )
        swap ( a , b ) ;

    int diff = b - a ;
    if ( diff > 1 ) { cout << 0 ; line ; return ; }

    ll ans = fact ( a ) * fact ( b ) ;
    ans %= mod ;

    if ( a == b )
        ans <<= 1LL , ans %= mod ;

    cout << ans ; line ;
}

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

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

map<int, int> t;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll ans = 0;
	int N; gi(N);
	rep1(i, N) {
		int k; gi(k);
		ans += t[i-k];
		t[i+k]++;
	}
	print(ans);
}


Measured memory_bytes: 22120
/**
>>> In The Name Of GOD
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define bs binary_search
#define smin(x,y) (x) = min((x) ,(y))
#define smax(x,y) (x) = max((x) ,(y))
#define sz(x) (int)(x).size()
#define ssz(x) (int)(x).length()
#define all(x) (x).begin(),(x).end()

//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

///ifstream fin("input.txt");
///ofstream fout("output.txt");


bool cmp_pair_F_2(pair <int,int> x, pair <int,int> y)
{
    return x.F>y.F;
}
bool cmp_pair_S_2(pair <int,int> x, pair <int,int> y)
{
    return x.S>y.S;
}
bool cmp_pair_S_1(pair <int,int> x, pair <int,int> y)
{
    return x.S<y.S;
}

bool cmp(int x, int y)
{
	return x>y;
}

const int N=12;
vector <int> v[N];
bool a[N], p[N];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //int i,j;
	int n,m;
	cin >> n >> m;
	for (int i=0;i<m;i++)
    {
        int k;
        cin >> k;
        for (int j=0;j<k;j++)
        {
            int x;
            cin >> x;
            x--;
            v[i].pb(x);
        }
    }
    for (int i=0;i<m;i++)
        cin >> p[i];
    int c=0;
    for (int mask=0;mask<(1<<n);mask++)
    {
        for (int i=0;i<n;i++)
            a[i]=(mask&(1<<i));
        int ch=0;
        for (int i=0;i<m;i++)
        {
            int co=0;
            for (auto j:v[i])
                if (a[j])
                    co++;
            if (co%2!=p[i])
                ch=1;
        }
        if (!ch)
            c++;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
int main() {
    int x, y, k;
    cin >> x >> y >> k;
    int c = 0;
    for(int i =  min(x,y); i >= 1; i--){
        if(x % i == 0 && y % i == 0)
            c++;
        if (k==c) {
            cout << i;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
sc_ls = [list(map(int, input().split())) for _ in range(m)]

for num in range(10**n):
    if len(str(num)) != n:
        continue

    for s, c in sc_ls:
        if str(num)[s-1] != str(c):
            break
    else:
        print(num)
        break
else:
    print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  const int N = 200005;

int32_t main()
{


    IOS

    


    int n,m;
    cin >> n >> m;

    vector<int> h(n);

    for(int i = 0; i < n; i++)cin >> h[i];


    set<int> s;

    for(int i = 1; i <= n; i++)s.insert(i);


    for(int i = 1; i <= m; i++)
    {
      int x,y;
      cin >> x >> y;

      if(h[x-1] <=h[y-1])
      {
        s.erase(x);
      }

      if(h[y-1] <=h[x-1])
      {
        s.erase(y);
      }
    }



    cout << s.size();






    
    return 0;
}



Measured memory_bytes: 8740
#include<stdio.h>
#include<stdlib.h>
long long CO[100010];
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMAX）
long long hyouka(long long a,long long b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  long long i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
long long hout(){
  long long rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
long long i,id[400010],ta[400010],nt[400010],to[400010],co[400010],f[400010]={0};
void prls(long long v){
  long long i,j;
  for(i=0;i<v;i++){
    printf("%lld:",i);
    for(j=ta[i];j+1;j=nt[j])printf("%lld-%lld ",to[j],co[j]);
    printf("\n");
  }
  printf("\n");
}
void mkls(long long v,long long e,long long *a,long long *b,long long *c){
  long long i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[b[i]]=i+e]=co[ta[a[i]]=i]=c[i];
  }
}
void dijk(long long v,long long mi){
  for(i=0;i<v;i++)CO[i]=1000000000;
  CO[mi]=0;
  while(f[mi]-1){
    f[mi]=1;
    for(i=ta[mi];i+1;i=nt[i]){
      if(CO[to[i]]>CO[mi]+co[i])hin(CO[id[R]=to[i]]=CO[mi]+co[i]);
    }
    while(f[mi]&&C-1)mi=id[hout()];
  }
}
int main(){
  long long n,m,i,j,a[200010],b[200010],c[200010];
  scanf("%lld",&n);
  for(i=0;i<n-1;i++){
    scanf("%lld %lld",&a[i],&b[i]);
    c[i]=1;
  }
  scanf("%lld",&m);
  for(i=0;i<m;i++){
    scanf("%lld %lld",&b[i+n-1],&c[i+n-1]);
    a[i+n-1]=0;
  }
  mkls(n+1,n+m-1,a,b,c);
  //prls(n+1);
  dijk(n+1,0);
  //for(i=0;i<n;i++)printf("%lld\n",CO[i+1]);
  for(i=0;i<m;i++){
    if(CO[b[i+n-1]]-c[i+n-1]){
      printf("No\n");
      return 0;
    }
  }
  for(i=1;i<n;i++){
    for(j=ta[i];j+1;j=nt[j]){
      if(to[j]==0)continue;
      if(labs(CO[i]-CO[to[j]])-1){
	printf("No\n");
	return 0;
      }
    }
  }      
  printf("Yes\n");
  for(i=0;i<n;i++)printf("%lld\n",CO[i+1]);
  return 0;
}
    


Measured memory_bytes: 19584
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

vector<int> to[200005];
int visited[100005];
int root[100005];
int dis[100005];
int co=0;

void dfs(int u){
    for(int v:to[u]){
        if(dis[v]>=dis[u]+1){
            root[v]=u;
            dis[v]=dis[u]+1;
            dfs(v);
        }
    }
    if(visited[u]==0){
        visited[u]=1;
        co++;
    }
}

int main(){
    int n,m;
    cin >> n>> m;
    rep(i,m){
        int a,b;
        cin >> a>> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n){
        root[i]=i;
        dis[i]=INF;
    }
    dis[0]=0;
    qu.push(0);
    while(!qu.empty()){
        int u=qu.front();
        qu.pop();
        for(int v:to[u]){
            if(dis[v]>dis[u]+1){
                dis[v]=dis[u]+1;
                root[v]=u;
                qu.push(v);
            }
            if(visited[v]==0){
                co++;
                visited[v]=1;
            }
        }
    }

    if(co!=n){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    rep2(i,n-1){
        cout<<root[i]+1<<endl;
    }
    return 0;
}



Measured memory_bytes: 13652
//Created Time:2019年12月02日 星期一 21时16分28秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 100005

using namespace std;

long long ans;
int a[N][2];
long long sum1[N], sum2[N];

int main(){
	int n; scanf("%d", &n);
	scanf("%d", &a[1][0]); sum1[1] = sum2[1] = a[1][0];
	for(int i = 1; i < n; ++i){
		int x = 0; bool flag = false; char ch = getchar();
		for(; !isdigit(ch); ch = getchar()) flag |= (ch == '-');
		for(; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
		a[i + 1][0] = x; a[i + 1][1] = flag; 
		sum1[i + 1] = sum1[i] + (flag ? -x : x);
		sum2[i + 1] = sum2[i] + x;
	}
	ans = sum1[n];
	for(int i = 1; i <= n; ++i)
		if(a[i][1]){
			int pos = i + 1; long long tmp = 0;
			while(!a[pos][1] && pos <= n) tmp += a[pos++][0];
			ans = max(ans, sum1[i] - tmp + sum2[n] - sum2[pos - 1]);
			i = pos - 1;
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
def resolve():
    n = int(input())
    x_list = list(map(int, input().split()))
    mn = 10**9
    for i in range(1, max(x_list)+1):
        sm = 0
        for x in x_list:
            sm += (x-i)**2
        if mn > sm:
            mn = sm  
    print(mn)
resolve()


Measured memory_bytes: 9068
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    s64 d[n][n];
    s64 ans = 0;
    rep (i, n) rep (j, n) { cin >> d[i][j]; }

    rep (i, n) rep (j, n)
    {
        bool ok = true;
        rep (k, n)
        {
            if (d[i][j] > d[i][k] + d[k][j])
            {
                cout << "-1\n";
                return 0;
            }
            else if (!(i == k || j == k) && d[i][j] == d[i][k] + d[k][j])
            {
                ok = false;
            }
        }
        if (ok) ans += d[i][j];
    }

    cout << ans / 2 << "\n";
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int a = sc.nextInt();
			int b = sc.nextInt();

			if ( (a+b)  % 2 == 0 ) {
				System.out.println((a+b)/2);
			}
			else {
				System.out.println("IMPOSSIBLE");
			}
			
		}
	}
}

Measured memory_bytes: 21844
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int A = sc.nextInt();
	    int B = sc.nextInt();
		int C = 0;
	    if(A >= 13){
			C = B;
	    }
	    	if(A >= 6 && A <= 12){
			C = B / 2;
	    	}
		       if(A <= 5){
			C = 0;
	    }
			
	    System.out.println(C);
	}
}	

Measured memory_bytes: 21844
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans = 1;
    ll n;
    cin >> n;
    for(ll i=1;i<=n;++i){
        ans*=i;
        ans%=mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256