akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	}
}

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

int main(int argc, char *argv[]){
  int N;
  cin>>N;
  int A[N];
  for(int i=0; i<N; i++){
    int a;
    cin>>a;
    A[i]=a;
  }
  int count=0,uppred=0;
  bool hai=false,tya=false,midori=false,mizu=false,ao=false,ki=false,ora=false,red=false;
  for(int i=0; i<N; i++){
    if(A[i]<400&&hai==false){count++;hai=true;}
    if(A[i]>=400&&A[i]<800&&tya==false){count++;tya=true;}
    if(A[i]>=800&&A[i]<1200&&midori==false){count++;midori=true;}
    if(A[i]>=1200&&A[i]<1600&&mizu==false){count++;mizu=true;}
    if(A[i]>=1600&&A[i]<2000&&ao==false){count++;ao=true;}
    if(A[i]>=2000&&A[i]<2400&&ki==false){count++;ki=true;}
    if(A[i]>=2400&&A[i]<2800&&ora==false){count++;ora=true;}  
    if(A[i]>=2800&&A[i]<3200&&red==false){count++;red=true;}
    if(A[i]>=3200) uppred++;
  }
  if(count==0){
    cout<<count+1<<" "<<uppred<<endl;
    return 0;
  }
  cout<<count<<" "<<count+uppred<<endl;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int ans=1;
  for(int i=0;i<n-1;i++){
    if(a.at(i)>a.at(i+1)){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
using namespace std;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int Bv[N][2];
int B[2*N][2],A[N],B0;
bool z[N];
void dfs(int q)
{
	z[q]=1;
	efo(i,q)if(!z[B[i][1]])dfs(B[i][1]);
}
int main()
{
	int q,w;
	read(n),read(m);
	fo(i,1,n)
	{
		int qa,qb,qc,qd;
		read(qa),read(qb),read(qc),read(qd);
		if(qc==0)
		{
			q=m+qa;
		}else q=qc;
		if(qd==0)w=qb;
		else w=m+qd;
		++Bv[q][0];++Bv[w][1];
		B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;
	}
	ans=0;q=0;
	fo(i,1,m)
	{
		if(Bv[i][0]>Bv[i][1])++ans;
		if(Bv[i][0]<Bv[i][1])++q;
	}
	if(ans||!q)return printf("NO\n"),0;
	q=0;
	fo(i,m+1,m*2)
	{
		if(Bv[i][0]<Bv[i][1])++ans;
		if(Bv[i][0]>Bv[i][1])++q;
	}
	if(ans||!q)return printf("NO\n"),0;
	fo(i,m+1,2*m)if(Bv[i][0]>Bv[i][1]&&!z[i])dfs(i);
	fo(i,1,m*2)if(A[i]&&!z[i])return printf("NO\n"),0 ;
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
		public static int exception(int h,int w){
			int result = 0;
			if(1 <= h && h <= 300 && 1 <= w && w <= 300){ //??????????????????(??\????¶???????)
				result = 2;
			}
			else if(h == 0 && w == 0){
				result = 1; //0,0??\?????§??\???????????????
			}
			else{
				System.out.println("1~300????????§.???????????????.");
				result = 0;
			}
			return result;
		}
		public static void main(String[] args) {
			/**
			 * ?????°?????£?¨?
			 */
			int a = 0;
			int t = 0, inc = 0;
			int h = 0,w = 0; //height:h width:w
			int x = 0;
			/**
			 * ???????????£?¨?
			 */
			ArrayList<String> st = new ArrayList<String>();
			ArrayList<Integer> parse = new ArrayList<Integer>();
			/**
			 * ????¨???????????????\???
			 */
			Scanner scan = new Scanner(System.in);
			while(a == 0){
			for (t = 0; t < 2; t++){ //??´??°2???????????????
			st.add(scan.next());
			}
			h = Integer.parseInt(st.get(inc));
			w = Integer.parseInt(st.get(inc+1));
			parse.add(h);
			parse.add(w);
			if(exception(h,w) == 1){ //h=w=0?????¨??????????????????????????????
				break;
			}
			else if(exception(h,w) == 0){ //??????????????????????????????.
				System.exit(0);
			}
			inc = inc + 2; //???????????§?????°
			}
			/**
			 * ??????
			 */
			for(int n= 1; n < ((parse.size())/2) ; ++n){ //???????????°??????
			 for(int i = 1; i < parse.get(2*(n-1))+1; ++i){ //hight
				for(int j = 1; j < parse.get(2*n-1)+1; ++j){ //width
				if((i + j) % 2 == 0){
					System.out.print("#");
				}
				else if((i + j) % 2 != 0 ){
					System.out.print(".");
				}
				}
				System.out.println("");
			 }
			 System.out.println("");
			}
		}
	}

Measured memory_bytes: 33880
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int K, X;
	cin >> K >> X;
	for (int i = X - K + 1; i < X + K; i++) {
		cout << i << " ";
	}
	cout << endl;
}

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

int main(void) {
  string N;
  cin >> N;
  int sum = 0;
  for (size_t i = 0; i < N.size(); i++) sum += (N[i] - '0');
  cout << ((sum % 9) ? "No" : "Yes") << endl;
  return 0;
}

Measured memory_bytes: 3696
s=input()
t=s*2
k=int(input())
c,d=1,0
if len(set(s))==1:
    print((len(s)*k)//2)
else:
    for i in range(1,len(s)):
        if s[i-1]==s[i]:
            c+=1
        else:
            d+=c//2
            c=1
    d+=c//2
    l,r,p,q=t[0],t[-1],0,0
    while s[0]==l:
        s=s[1:]
        p+=1
        if len(s)==0:
            break
    if len(s)!=0:
        while s[-1]==r:
            s=s[:-1]
            q+=1
            if len(s)==0:
                break
    if t[0]==t[-1]:
        print((k-1)*((p+q)//2)+d*k-(k-1)*(p//2+q//2))
    else:
        print(d*k)

Measured memory_bytes: 3064
N = int(input())
ss = []
for i in range(N):
  s = int(input())
  ss.append(s)
maxs = sum(ss)
if maxs%10 != 0:
  print(maxs)
  exit()
r = 0
for i in range(N):
  s = maxs-ss[i]
  if s%10 == 0:
    s = 0
  r = max(r, s)
print(r)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c,d,e;
    cin>>a>>b>>c;
    e=c;
    for(int i=0;i<10;i++)
    {
        d=a*e-b;
        e=d;
        cout<<d<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define yes(n) cout << ((n) ? "Yes" : "No") << endl
int main()
{
    vector<int> map;
    for(int i = 1;i < 10;i++)
    {
        for(int j = 1;j < 10;j++)
        {
            map.push_back(i * j);
        }
    }
    int n;cin >> n;
    bool ans = false;
    for(int i= 0;i < 81;i++)
    {
        if(map[i] == n)
            ans = true;
    }
    yes(ans);

}

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

int main() {
	int A,B,C,D;
	cin >> A >> B >> C >>D;
	bool flag;
	
	for(int i = 0;i>-1;i++){
		C = C - B;
		if(C<1){
			flag = true;
			break;
		}
		
		A = A - D;
		if(A<1){
			flag = false;
			break;
		}
	
	}
	
	if(flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}	


Measured memory_bytes: 3636
/*
Author: Deep Chaklasiya
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> data_set;
#define fbo find_by_order
#define ook order_of_key




#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define piiii       pair<pii,pii>
#define viiii       vector<pair<pii,pii>>
#define mi          map<int,int>
#define mii         map<pii,int>
#define piii           pair<int,pair<int,int> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define ef else if





int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}


template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}

void set_min(int &m,int a){
    if(m==-1||m>a)m=a;
}


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int i,j,x,n,m,k,t;
     cin>>n>>m;
     if(n>m)
     {
     	int temp=n;
     	n=m;
     	m=temp;
	 }int count=1;
	 while(1)
	 {
	 	if((count*m)%n==0)
	 	{
	 		cout<<count*m;
	 		break;
		 }
		 else count++;
	 }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]float64, n)
	s := 0.0
	for i:=0; i<n; i++ {
		fmt.Scan(&a[i])
		s += 1.0/a[i]
	}
	fmt.Println(1.0/s)
}

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

int main() {
    int H, W;
    cin >> H >> W;
    char a;
    for (int i = 0; i <= W + 1; i++){
        cout << '#' ;
    }
    cout << endl;
    for (int i = 0; i < H; i++ ){
        cout << '#';
        for (int j = 0; j < W; j++){
            cin >> a;
            cout << a;
        }
        cout << '#' << endl;
    }
    for (int i = 0; i <= W + 1; i++){
        cout << '#' ;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int n, h, w; cin >> n >> h >> w;
   cout << (n-h+1)*(n-w+1) << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> c(m);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        c.emplace_back(a,b);
    }
    reverse(c.begin(), c.end());
    UnionFind uf(n);
    vector<ll> ans(m);
    ll mx = (ll)n*(n-1)/2;
    ans[0] = mx;
    rep(i,m-1) {
        int a = c[i].first, b = c[i].second;
        if (uf.same(a,b)) {
            ans[i+1] = ans[i];
            uf.unite(a,b);
            continue;
        }
        ans[i+1] = ans[i] - ll(uf.size(a))*uf.size(b);
        uf.unite(a,b);
        if (ans[i+1] == 0) break;
    }
    reverse(ans.begin(), ans.end());
    rep(i,m) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 6044
import sys
n = int(input())
a = [int(i) for i in input().split()]
tmp = 10**18
if 0 in a:
    print(0)
    sys.exit()
else:
    acc = 1
    for i in a:
        acc *= i
        if acc > tmp:
            print(-1)
            sys.exit()
print(acc)


Measured memory_bytes: 84828
li = list(input())
pm = []
for i in range(8):
    l = []
    for j in range(3):
        if ((i>>j) & 1):
            l.append('+')
        else:
            l.append('-')
    pm.append(l)
lia = [0]*4
lisans =[0]
for i in range(4):
    lia[i] = int(li[i])
def search(lis):
    k = lia[0]
    for i in range(3):
        if lis[i] == '+':
            k += lia[i+1]
        if lis[i] == '-':
            k -=lia[i+1]
    return k
for i in range(8):
    lis = pm[i]
    ans = search(lis)
    if ans == 7:
        lisans = lis
        break
vic = [li[0]]
for i in range(3):
    vic.append(lisans[i])
    vic.append(li[i+1])
vic.append('=')
vic.append('7')
print(''.join(vic))

Measured memory_bytes: 3064
program test
implicit none
integer::N,i,c
integer,allocatable::p(:)
	c=0
	read*,N
	allocate(p(N))
	read(*,*)(p(i),i=1,N)
    	do i=1,N
        	if(i==p(i)) then
				c=c
        	else 
        		c=c+1
        	end if
        end do
    if(c==0)then
    	print*,'YES'
    else if(c==2)then
    	print*,'YES'
    else 
    	print*,'NO'
    end if
end program test

Measured memory_bytes: 256
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int A[110];
	cin >> N;
	rep(i, 0, N)cin >> A[i];

	sort(A, A + N);

	cout << A[N - 1] - A[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T> void read(T &x){
	char c=getchar();x=0;int f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}
int k,x;
int main(){
	read(k);read(x);
	for(int i=max(-100000,x-k+1);i<=min(100000,x+k-1);i++)
		cout<<i<<' ';
	cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long int
signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans=(n/(a+b))*a;
  if((n%(a+b))>a)	ans+=a;
  else	ans+=(n%(a+b));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H, W = map(int, input().split())

ignore = "".join(["." for _ in range(W)])

A = list(filter(lambda x : x != ignore, [input() for _ in range(H)]))
H = len(A)
B = [[] for _ in range(H)]

for w in range(W):
    if list(filter(lambda x: x[w] == "#", A)):
        for i in range(H):
            B[i].append(A[i][w])

for h in range(H):
    print("".join(B[h]))


Measured memory_bytes: 9668
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,as=0,bs=0;cin>>n;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i],as+=a[i];
    ll b[n];for(ll i=0;i<n;i++)cin>>b[i],bs+=b[i];
    if(as>bs)return cout<<"No" , 0;
    ll x=0,y=0;
    for(ll i=0;i<n;i++){
        if(a[i]<b[i])y+=(b[i]-a[i]+1)/2;
        else x+=a[i]-b[i];
    }
    if(x<=(bs-as) && y<=(bs-as))cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 384
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[1229];int sz;}Template;
struct T{int fact[1000001],inv[1000001];};
Template P;struct T MODINV;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x){P.Primes[P.sz++]=x;}if(x*x>MAX)break;
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
static inline void init(void)
{
  MODINV.fact[0]=1;rep(i,MAX)MODINV.fact[i+1]=1l*MODINV.fact[i]*(i+1)%MOD;
  MODINV.inv[MAX]=MPow(MODINV.fact[MAX],MOD-2);
  rep(i,MAX)MODINV.inv[MAX-1-i]=1l*MODINV.inv[MAX-i]*(MAX-i)%MOD;
}
int main(void)
{
  int N=IN(),A=0,flag=0,invsum=0,k=0,lcm=1,x=0,unique[9999],box[168]={0};ready();init();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MODINV.fact[A-1]*MODINV.inv[A]%MOD)%MOD;
    rep(j,168){x=0;while(A%P.Primes[j]==0){A/=P.Primes[j];if(box[j]<++x)box[j]=x;}}
    if(A!=1){rep(j,k){if(unique[j]==A)flag=1;continue;}if(!flag)unique[k++]=A;}flag=0;
  }
  rep(i,168){rep(j,box[i]){lcm=1l*lcm*P.Primes[i]%MOD;}}
  rep(i,k){lcm=1l*lcm*unique[i]%MOD;}
  x=1l*lcm*invsum%MOD;return printf("%d\n",x),0;
}

Measured memory_bytes: 13312
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
int l;
map <string,int> m;

int main(){
  cin >> n;
  REP(i,n){
    string s;
    cin >> s;
    m[s] ++;
  }
  cin >> l;
  REP(i,l){
    string s;
    cin >> s;
    m[s] --;
  }
  int ans = 0;
  for(map<string,int>::iterator it = m.begin();it!= m.end();it++){
    ans = max(ans,it->second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
g = [None]*n
for i in range(n):
    g[i] = readints()
# print(g)
G = [None]*n
for i in range(n):
    G[i] = []
# print(G)
for i in range(n):
    if len(g[i]) >= 3:
        for j in range(2, len(g[i])):
            # print(g[i][j])
            G[i].append(g[i][j])
#print('G', G)
dist = [-1]*n
dist[0] = 0
d = deque()
d.append(0)
# print(d)
while(len(d) != 0):
    v = d.popleft()
    if G[v] != []:
        for nv in G[v]:
            if dist[nv-1] != -1:
                continue
            dist[nv-1] = dist[v]+1
            d.append(nv-1)
for i in range(n):
    print(i+1, dist[i])



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

using namespace std;

int n,x[100005];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	long long cost = abs(0-x[0]);
	for(int i = 1; i < n; i++){
		cost += abs(x[i] - x[i-1]);
	}
	cost += abs(0-x[n-1]);
	long long sol[100005];
	for(int i = 0; i < n; i++){
		sol[i] = cost;
	}
	sol[0] = sol[0] - abs(0-x[0]) - abs(x[0]-x[1]) + abs(0-x[1]);
	for(int i = 1; i < n-1; i++){
		sol[i] = sol[i] - abs(x[i-1] - x[i]) - abs(x[i] - x[i+1]) + abs(x[i-1] - x[i+1]);
	}
	sol[n-1] = sol[n-1] - abs(x[n-2] - x[n-1]) - abs(x[n-1] - 0) + abs(x[n-2] - 0);
	for(int i = 0; i < n; i++){
		cout << sol[i] << endl;
	}
}

Measured memory_bytes: 2432
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    a = I()
    ans = a + a**2 + a**3
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
import numpy
import math
N=int(input())
S=[list(map(int,input().split()))for _ in range(N)]

ans=0

for i in range(N-1):
    for j in range(i+1,N):

        a=numpy.array(S[i])
        b=numpy.array(S[j])
        u=b-a
        ans+=numpy.linalg.norm(u)*math.factorial(N-1)*2

print(ans/math.factorial(N))

Measured memory_bytes: 12500
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int n, s=0, count=0;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  rep(i,n) {
    if(s <= a.at(i)) {
      count++;
    }
    s = max(s,a.at(i));
  }
    cout << count;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int W,H,N,x,y,w,h,sum=0;
  cin >> W >> H >> N;
  cin >> x >> y;
  for(int i=1;i<N;i++){
    cin >> w >> h;
    if((x<=w && y<=h)||(x>=w && y>=h))
      sum+=max(abs(w-x),abs(h-y));
    else
      sum+=abs(w-x)+abs(h-y);
    x=w;
    y=h;
  }
  cout << sum << endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

bool hantei1(string s) {
	int judge = 0;
	if (s.size() == 1) {
		return true;
	} else {
	for (int i = 0; i <= (s.size()-2) / 2; i++) {
		if (s[i] != s[s.size()-1-i]) {
			judge = 1;
			break;
		}
	}

	if (judge == 0) {
		return true;
	} else {
		return false;
	}
	}
}

bool hantei2 (string s) {
	int judge = 0; 
	if (s.size() == 1) {
		return true;
	} else {
	for (int i = 0; i <= (s.size()-3) / 2; i++) {
		if (s[i] != s[s.size()-1-i]) {
			judge = 1;
			break;
		}
	}
	if (judge == 0) {
		return true;
	} else {
		return false;
	}
	}
}

int main() {
	string ss;
	stringstream sout;
	int n;
	int a;

	cin >> a;

	sout << a;

	sout >> ss;

	n = ss.size();

	if (n % 2 == 0) {
		if (hantei1(ss)) {
			cout << ss << endl;
		} else {
			for (int i = 1; true; i++) {
				sout.str("");
				sout.clear();
				sout << ss;
				sout >> a;
				if (i % 2 == 0) {
					a += i;
				} else {
					a -= i;
				}
				sout.str("");
				sout.clear();
				sout << a;
				sout >> ss;
				if (hantei1(ss)) {
					cout << ss << endl;
					break;
				}
			}
		}
	} else {
		if (hantei2(ss)) {
			cout << ss << endl;
		} else {
			for (int i = 1; true; i++) {
				sout.str("");
				sout.clear();
				sout << ss;
				sout >> a;
				if (i % 2 == 0) {
					a += i;
				} else {
					a -= i;
				}
				sout.str("");
				sout.clear();
				sout << a;
				sout >> ss;
				if (hantei2(ss)) {
					cout << ss << endl;
					break;
				}
			}
		}
	}

	return 0;
}

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

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

int F[100][10];
int P[100][11];

int main2() {
  int N; cin >> N;
  REP(i, N) REP(j, 10) cin >> F[i][j];
  REP(i, N) REP(j, 11) cin >> P[i][j];
  ll best = -(1LL << 58);
  for (int set = 1; set < (1 << 10); set++) {
    vector<int> same(N);
    for (int i = 0; i < 10; i++) if (set >> i & 1) {
      REP(n, N) if (F[n][i]) same[n]++;
    }
    ll here = 0;
    REP(n, N) here += P[n][same[n]];
    chmax(best, here);
  }
  cout << best << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();  
  return 0;
}



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

int main(){
  int N,K;
  cin >> N >> K;
  vector<char> S(N);
  for(int i = 0;i<N;i++){
    cin >> S.at(i);
  }
  if(S.at(K-1) == 'A')
    S.at(K-1) = 'a';
  else if(S.at(K-1) == 'B')
    S.at(K-1) = 'b';
  else if(S.at(K-1) == 'C')
    S.at(K-1) = 'c';
  
  for(int i = 0;i<N;i++){
    cout << S.at(i);
  }
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename A>
void UNIQUE(vector< A > &a,int mode=0){
    if(mode==0){ sort(ALL(a),greater< A >());}else{ sort(ALL(a));}
    a.erase(unique(ALL(a)),a.en());
}

LL GCD(LL a,LL b){
    LL t; LL r;
    if(a<b){t=a;a=b;b=t;}
    if(b==0){return a;}
    while(a%b!=0){r=a%b;a=b;b=r;}
    return b;
}

int main(){
    int N,X;
    cin>>N>>X;
    Vi x(N);
    Vi dist(N);
    REP(i,N){
        cin>>x[i];
        dist[i] = abs(X-x[i]);
    }
    LL ans = 0;
    REP(i,N){
        ans = GCD(ans,dist[i]);
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
const MOD: i64 = 998244353;

fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let mut ys = Vec::with_capacity(n);
	let mut coord = Vec::with_capacity(n);
	for _ in 0..n {
		let x: i32 = s.next().unwrap().parse().unwrap();
		let y: i32 = s.next().unwrap().parse().unwrap();
		ys.push(y);
		coord.push((x, y));
	}
	ys.sort();
	coord.sort();
	for (_, y) in coord.iter_mut() {
		let i = ys.binary_search(y).unwrap();
		*y = i as i32;
	}

	let mut cnt = vec![[0; 4]; n];
	{
		let mut bit = BIT::new(n);
		for (i, &(_, y)) in coord.iter().enumerate() {
			let y = y as usize;
			let bt = bit.sum(y);
			let tp = i as u32 - bt;
			cnt[i][0] += bt;
			cnt[i][1] += tp;
			bit.add(y, 1);
		}
	}
	{
		let mut bit = BIT::new(n);
		for (i, &(_, y)) in coord.iter().rev().enumerate() {
			let y = y as usize;
			let bt = bit.sum(y);
			let tp = i as u32 - bt;
			cnt[n - 1 - i][2] += bt;
			cnt[n - 1 - i][3] += tp;
			bit.add(y, 1);
		}
	}

	fn some(cnt: u32) -> i64 {
		pow_mod(2, cnt, MOD) + MOD - 1
	}
	fn any(cnt: u32) -> i64 {
		pow_mod(2, cnt, MOD)
	}
	let mut ans = 0;
	for t in cnt.into_iter() {
		let a = some(t[0]) * some(t[3]) % MOD * any(t[1] + t[2]) % MOD;
		let b = some(t[1]) * some(t[2]) % MOD * any(t[0] + t[3]) % MOD;
		let ab = (some(t[0]) * some(t[1]) % MOD) * (some(t[2]) * some(t[3]) % MOD) % MOD;
		ans = (ans + any(t[0] + t[1] + t[2] + t[3]) + a + b + MOD - ab) % MOD;
	}
	println!("{}", ans);
}

pub fn pow_mod<T, U>(a: T, mut b: U, modulus: T) -> T
where
	T: num::PrimInt,
	U: num::PrimInt + num::Integer + num::Unsigned,
{
	let mut r = T::one();
	let mut a = a % modulus;
	while b > U::zero() {
		if b.is_odd() {
			r = r * a % modulus;
		}
		a = a * a % modulus;
		b = b / (U::one() + U::one());
	}
	r
}

pub struct BIT<T> {
	data: Vec<T>,
}

impl<T> BIT<T>
where
	T: Clone + Default + std::ops::Add<Output = T>,
{
	pub fn new(n: usize) -> Self {
		Self {
			data: vec![T::default(); n],
		}
	}

	pub fn construct(a: Vec<T>) -> Self {
		let mut a = a;
		for i in 0..a.len() {
			if i | (i + 1) >= a.len() {
				continue;
			}
			let v = a[i].clone();
			a[i | (i + 1)] = a[i | (i + 1)].clone() + v;
		}
		Self { data: a }
	}

	pub fn sum(&self, i: usize) -> T {
		let mut r = T::default();
		let mut i = i;
		while i > 0 {
			r = r + self.data[i - 1].clone();
			i &= i - 1;
		}
		r
	}

	pub fn add(&mut self, i: usize, value: T) {
		let mut i = i;
		while i < self.data.len() {
			self.data[i] = self.data[i].clone() + value.clone();
			i |= i + 1;
		}
	}
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if(A + B < C + D){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

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

int main(void){
    int N,K;
    cin>>N>>K;
    int ans=0;
    rep(i,N){
        int h;
        cin>>h;
        if(h>=K){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(n):
    for j in range(a[i]):
        ans.append(i+1)
for i in range(h):
    tar = ans[i * w:(i+1) * w]
    if i % 2 == 0:
        print(*tar)
    else:
        tar.reverse()
        print(*tar)




Measured memory_bytes: 42736
import copy

N, Ma, Mb = map(int, input().split())
ABC = [tuple(map(int, input().split())) for _ in range(N)]

INF, W = 10 ** 10, 10 * 10 * N
dp = [[INF] * (2 * W + 1)]

for a, b, c in ABC:
    dp.append(copy.deepcopy(dp[-1]))
    df = a * Mb - b * Ma
    dp[-1][df] = min(c, dp[-1][df])
    for d in range(-W, W + 1):
        dp[-1][df + d] = min(c + dp[-2][d], dp[-1][df + d])

print("-1" if dp[N][0] == INF else dp[N][0])


Measured memory_bytes: 6508
import numpy as np
N, C = map(int, input().split())
XV = [list(map(int, input().split())) for i in range(N)]


V_minus_X = [XV[i][1]-(XV[i][0]-XV[i-1][0])
             for i in range(1, N)]  # i==0なら見ない それ以外ならXV[i-1][0]足して上げる
V_minus_X.insert(0, XV[0][1]-XV[0][0])
cum_ = np.cumsum(V_minus_X)


V_minus_X_reverse = [XV[i][1]-(XV[i+1][0]-XV[i][0])
                     for i in range(0, N-1)]
V_minus_X_reverse.append(XV[-1][1]-(C-XV[-1][0]))
V_minus_X_reverse.reverse()
cum_reverse = np.cumsum(V_minus_X_reverse)

m_ = []
m_reverse = []
maxim = 0
maxim_reverse = 0
maxim_where = 0
maxim_reverse_where = 0
# print("print")
for i in range(N-1):
    if maxim < cum_[i]:
        maxim = cum_[i]
        maxim_where = XV[i][0]
    if maxim_reverse < cum_reverse[i]:
        maxim_reverse = cum_reverse[i]
        maxim_reverse_where = C - XV[-i - 1][0]
    m_.append((maxim, maxim_where))
    m_reverse.append((maxim_reverse, maxim_reverse_where))

ans = 0

for i in range(N - 1):
    next = m_[i][0] + m_reverse[-i - 1][0] - \
        min(m_[i][1], m_reverse[-i - 1][1])
    ans = max(next, ans)

print(max(ans, max(cum_), max(cum_reverse)))


Measured memory_bytes: 66968
#include<bits/stdc++.h>
using namespace std;
#define    For(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    nl     "\n"
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int

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

    //test
    {
        int n,x,t;
        cin>>n>>x>>t;
        int p=n/x;
        if(n%x!=0)p++;
        cout<<p*t;
    }
}


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

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int res = 0, Max = 0;
		for (int i = 1, p; i <= n; ++i)
		{
			scanf("%d", &p);
			res += p;
			Max = max(Max, p);
		}
		printf("%d\n", res - Max / 2);
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int h[10],i,j,hoge;
    for(i=0;i<10;i++){
        scanf("%d",&h[i]);
    }
    for(i=0;i<=9;i++){
        for(j=9;j>0;j--){
            if(h[j]>h[j-1]){
                hoge=h[j];
                h[j]=h[j-1];
                h[j-1]=hoge;
            }
        }
    }
    printf("%d\n%d\n%d\n",h[0],h[1],h[2]);
    return 0;
}

Measured memory_bytes: 600
#include"iostream"
#include"algorithm"
using namespace std;

int main()
{
  int a,b,c;
  int count=0;
  int acute=0,right=0,obtuse=0;
  while(cin>>a>>b>>c){
    if(b<c){
      swap(b,c);
    }
    if(a<b){
      swap(a,b);
    }
    if(a>=b+c){
      cout<<count<<" "<<right<<" "<<acute<<" "<<obtuse<<endl;
      break;
    }
    if(a*a<b*b+c*c){
      acute++;
    }else if(a*a==b*b+c*c){
      right++;
    }else{
      obtuse++;
    }
    count++;
  }
  return 0;
}



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

bool isprime(int a)
{
	if (a == 2 || a == 3) return true;
	int len = round(sqrt(a)) + 1;
	for (int i = 2; i < len; i++) {
		if (a % i == 0) return false;
	}
	return true;
}

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

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

	int counter = 0;
	for (int i = 0; i < n; i++)
		if (isprime(a[i])) counter++;

	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1208
#!/usr/bin/env python3
import sys
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):

    def __init__(self, graph, start):
        self.g = graph.graph

        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def solve(N: int, M: int, L: "List[int]", R: "List[int]", C: "List[int]"):
    graph= Graph()
    for i in range(M):
        graph.add_edge(L[i]-1,R[i]-1,C[i])
    for i in range(N-1):
        graph.add_edge(i+1,i,0)
    d = Dijkstra(graph,0)
    shortest = d.shortest_distance(N-1)
    
    if shortest == float('inf'):
        print(-1)
    else:
        print(shortest)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, L, R, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 75764
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
 
 
int main(){
	int n,a=114514,b=-1,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c;
		a=min(a,c);
		b=max(b,c);
	}
	cout<<b-a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef tuple<int,int,int> T;

int main(){
    int N;cin>>N;
    T X[2*N];
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        X[i]=(T){a,0,b};
    }
    for(int i=N;i<2*N;i++){
        int c,d;cin>>c>>d;
        X[i]=(T){c,1,d};
    }
    sort(X,X+2*N);
    int ans=0;
    map<int,int> mp; mp[pow(10,9)]++;
    for(int i=0;i<2*N;i++){
        if(get<1>(X[i])==0){
            mp[get<2>(X[i])]++;
        }
        else{
            auto itr=mp.upper_bound(get<2>(X[i]));
            if(itr==mp.begin()) continue;
            itr--;
            itr->second--;
            if(itr->second==0) mp.erase(itr->first);
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = gets.chomp.split(" ").map(&:to_i)

PYs = M.times.map do |_|
  gets.chomp.split(" ")
end

prefs = PYs.inject({}) do |m, v|
  m[v[0]] = [] unless m.key?(v[0])
  m[v[0]].push(v)
  m
end

prefs.each do |pref, v|
  v.sort_by { |v| v[1].to_i }.each.with_index(1) do |v2, i|
    v2.push("#{pref.rjust(6, "0")}#{i.to_s.rjust(6, "0")}")
  end
end

PYs.each do |v|
  puts v[2]
end


Measured memory_bytes: 55420
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>> N;
    ll x[N], y[N], h[N];
    rep(i,0,N) cin >>x[i]>>y[i]>>h[i];
    ll H;
    rep(i,0,101){
        rep(j,0,101){
            bool t=true;
            rep(k,0,N){
                if(h[k]!=0){
                    H=h[k]+abs(i-x[k])+abs(j-y[k]);
                }
            }
            rep(k,0,N){
                if(h[k]!=max(H-abs(i-x[k])-abs(j-y[k]),ll(0))) {
                    t=false;
                    break;
                }
            }
            if(t) {
                cout<< i<<" "<<j<<" "<<H<<"\n";
            }
        }
    }
}

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

#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
typedef long double ld;
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
const int N=2e5+5;
int mod=100000000;
/*int k1, k2;
ll dp[10][10][100][100];
ll solve(int n1, int n2, int last1, int last2)
{
    if(n1==0&&n2==0)
        return 1;
    if(dp[last1][last2][n1][n2]!=-1)
        return dp[last1][last2][n1][n2];

    ll &ans=dp[last1][last2][n1][n2];
    ans=0;
    if(last1<k1&&n1)
    {
        ans=(ans+solve(n1-1,n2,last1+1,0))%mod;

    }
    if(last2<k2&&n2)
    {
         ans=(ans+solve(n1,n2-1,0,last2+1))%mod;
    }
    // cout<<n1<<" "<<n2<<" "<<last1<<" "<<last2<<" "<<ans<<endl;
    return ans;

}*/
    ll n,arr[N], co[N], ans=0;

int main()
{
    FIO
    int x1,x2,y1,y2;
    int d1,d2;
    cin>>x1>>y1>>x2>>y2;
    d1=x2-x1;
    d2=y2-y1;
    int ans1=x2,ans2=y2;
    swap(d1,d2);
    d1*=-1;
    ans1+=d1;
    ans2+=d2;
    cout<<ans1<<" "<<ans2<< " ";
    swap(d1,d2);
    d1*=-1;
    ans1+=d1;
    ans2+=d2;
    cout<<ans1<<" "<<ans2;


return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<pii>> g(n);
	for (int i = 0; i < m;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].emplace_back(make_pair(c, b));
		g[b].emplace_back(make_pair(c, a));
	}

	vector<vector<int>>d(n, vector<int>(n, BIG_INT));

	for (int i = 0; i < n;i++) {
		priority_queue<pii, vector<pii>, greater<pii>>pq;
		d[i][i] = 0;
		pq.push(make_pair(0, i));
		
		vector<bool> isChecked(n, false);
		while (!pq.empty()) {
			int v = pq.top().second;
			pq.pop();
			if (!isChecked[v]) {
				for (pii e:g[v]) {
					if (d[i][v] + e.first < d[i][e.second]) {
						d[i][e.second] = d[i][v] + e.first;
						pq.push(make_pair(d[i][e.second], e.second));
					}
				}

				isChecked[v] = true;
			}
		}
	}
	/*
	for (int i = 0; i < n;i++) {
		for (int j = 0;j < n;j++) {
			cout << d[i][j] << " ";
		}
		cout << endl;
	}
	*/

	int cnt = 0;
	for (int i = 0; i < n;i++) {
		for (pii e : g[i]) {
			if (d[i][e.second] != e.first) {
				cnt++;
			}
		}
	}
	cout << cnt/2 << endl;
}


Measured memory_bytes: 384
import re

n = int(input())
s = input()
left = 0
right = len(re.findall('\.', s))

cnt = [left + right]
for i in range(n):
    if s[i] == '#':
        left += 1
    else:
        right -= 1
    cnt.append(left + right)

print(min(cnt))









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

vector<string> split(string str, string sep) {
  vector<string> result;
  int index = 0;
  while (1) {
    int pos = str.find(sep, index);
    if (pos == string::npos) {
      result.push_back(str.substr(index));
      return result;
    }
    result.push_back(str.substr(index, pos - index));
    index = pos + sep.size();
  }
}

long long func(string s, int n) {
  if (n == 0) {
    vector<string> result = split(s, "+");
    long long sum = 0;
    for (string v : result) sum += stoll(v);
    return sum;
  }
  string copy_s = s;
  return func(copy_s, n-1) + func(s.insert(n, "+"), n-1);
}

int main() {
  string S;
  cin >> S;
  cout << func(S, S.size()-1) << endl;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

using Position = pair<ll,ll>;
using Distance = pair<ll,ll>;

class Node
{
    public:
    Position P;
    vector<Distance> Dis;
};

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

    Node nodes[N];
    for(int i=0;i<N;i++)
    {
        cin >> nodes[i].P.first >> nodes[i].P.second;
    }
    for(int i=0;i<N;i++)
    {
        nodes[i].Dis.resize(N);
        for(int j=0;j<N;j++)
        {
            Distance ADD;
            ADD.first = nodes[j].P.first - nodes[i].P.first;
            ADD.second = nodes[j].P.second - nodes[i].P.second;
            nodes[i].Dis[j] = ADD;
        }
    }

    map<Distance,ll> Map;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            Map[nodes[i].Dis[j]]++;
        }
    }

    Map[{0,0}] = 0;

    pair<Distance,ll> Most;
    Most.first = {0,0};
    Most.second = 0;

    for(auto x : Map)
    {
        if(x.second > Most.second)
        {
            Most.second = x.second;
            Most.first = x.first;
        }
    }

    cout << N-Most.second << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double i; cin >> i;
    cout << fixed << setprecision(12) << i * M_PI * 2 << '\n';
    return 0;
}


Measured memory_bytes: 3788
def main():
    N, M = map(int, input().split())
    island = []
    for i in range(M):
        a, b = map(int, input().split())
        island.append(tuple((a, b)))
    
    s = sorted(island, key=lambda x:x[1])
    
    base = s[0][1]
    cnt = 1
    for i in range(1, len(s)):
        if(s[i][0] >= base):
            base = s[i][1]
            cnt += 1
    print(cnt)
    
main()

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

long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int K;
  cin>>K;
  long long sum = 0;
  for (int i=1; i<=K; i++) {
    for (int j=1; j<=K; j++) {
      for (int k=1; k<=K; k++) {
        sum += gcd(i, gcd(j, k));
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
void swap(int * , int *);

main()
{
  int i,j,A[100];
  int mini,N,count=0;
  scanf("%d",&N);
  for(i=0 ; i<N ; i++){
    scanf("%d",&A[i]);
  }
  for(i=0 ; i<N-1 ; i++){
    mini = i;
    for(j=i ; j<N ; j++){
      if(A[j] < A[mini]){
	mini = j;
      }
    } 
    swap(&A[i],&A[mini]);
    if(mini != i){
      count++; 
    }
  }
  for(i=0 ; i<N ; i++){
    if(i == N-1){
      printf("%d\n",A[i]);
      break;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",count);
  return 0;
}

void swap(int *a , int *b){

  int change;
  change = *a;
  *a = *b;
  *b = change;
}

Measured memory_bytes: 600