akhauriyash/Code-Regression huggingface dataset:
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,w;cin>>n>>w;
  vector<ll> weight(n),value(n);
  rep(i,n) cin>>weight[i]>>value[i];
  ll dp[n+1][Svec(value)+1];
  rep(i,Svec(value)+1) dp[0][i]=1e11;
  dp[0][0]=0;
  rep(i,n){
    rep(j,Svec(value)+1){
      if(j>=value[i]) dp[i+1][j]=min(dp[i][j],dp[i][j-value[i]]+weight[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  for(ll i=Svec(value);i>=0;i--){
    if(dp[n][i]<=w){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 79232
import java.util.*;

public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		int R = N;
		char[] S = s.toCharArray();
		for(int i = 0; i < N-1; i++) {
			if(S[i] == S[i+1]) {
				R--;
			}
		}
		System.out.println(R);
	}
}


Measured memory_bytes: 27860
def func(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3*n + 1

s = int(input())
lst = []
i = 1
while True:
    if i == 1:
        a = s
        bef = s
    else:
        a = func(bef)
    if a in lst:
        break
    else:
        lst.append(a)
        bef = a
    i += 1
print(i)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_set>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

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

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

signed main()
{
	fast();

	int n, val = 0;
	cin >> n;
	vector <pair <int, int> > p(n);
	for (int i = 0; i < n; ++i) 
	{
		cin >> p[i].first >> p[i].second;
	}


	pair <int, int> xx = { -INF, -INF }, yy = { -INF, -INF };
	for (int i = 0; i < p.size(); ++i) 
	{
		int x = p[i].first, y = p[i].second;
		xx.first = max(xx.first, x - y);
		yy.first = max(yy.first, y - x);

		xx.second = max(xx.second, x + y);
		yy.second = max(yy.second, -x - y);
	}

	set <int> s;
	for (int i = 0; i < p.size(); ++i) 
	{
		int x = p[i].first, y = p[i].second;
		if (y - x == yy.first) 
		{
			s.insert(i);
			yy.first = -INF;
		}
		if (x + y == xx.second)
		{
			s.insert(i);
			xx.second = -INF;
		}
		if (x - y == xx.first)
		{
			s.insert(i);
			xx.first = -INF;
		}
		if (-x -y == yy.second) 
		{
			s.insert(i);
			yy.second = -INF;
		}
	}
	for (auto e : s) 
	{
		for (auto e1 : s) 
		{
			val = max(val, abs(p[e].first - p[e1].first) + abs(p[e].second - p[e1].second));
		}
	}


	cout << val << '\n';
	return 0;
}

Measured memory_bytes: 6344
/*  -*- coding: utf-8 -*-
 *
 * c.cc: 
 */

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

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii as[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    cin >> as[i].first;
    as[i].second = i;
  }
  sort(as, as + n);

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if ((as[i].second & 1) != (i & 1)) cnt++;
  
  printf("%d\n", cnt / 2);
  return 0;
}


Measured memory_bytes: 1024
MOD = 1000000007
fac = finv = inv = None

def init(n):
    global fac, finv, inv
    fac = [0] * n
    finv = [0] * n
    inv = [0] * n
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in xrange(2, n):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    x, y = map(int, raw_input().split())
    a = 2 * x - y
    b = 2 * y - x
    if a < 0 or b < 0 or a % 3 or b % 3:
        print 0
        return
    a //= 3
    b //= 3
    init(a + b + 1)
    print com(a + b, a)


main()


Measured memory_bytes: 45164
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))

dic=defaultdict(int)
result=0
posi=0

for i in range(N):
    dic[A[i]-(i+1)] +=1

sort_dic=sorted(dic.items())

for j in sort_dic:
    if posi+j[1]>N//2:
        siki=j[0]
        break
    else:
        posi+=j[1]

for k in sort_dic:
    result+=abs(k[0]-siki)*k[1]

print(result)

Measured memory_bytes: 46184
#coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    n = II()
    l = LMIIS()
    a = [l[i] + l[j] for i in range(n) for j in range(i+1, n)]

    a.sort()
    ans = 0
    for ll in l:
        x =  bisect.bisect(a, ll)
        ans += x
    print(n*(n-1)*(n-2)//6 - ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 89536
n = int(input())
ans = {}

for x in range(1,100+1):
    for y in range(1,100+1):
        for z in range(1,100+1):
            tmp=x**2+y**2+z**2+x*y+y*z+z*x
            ans[tmp] = ans.get(tmp, 0) + 1

for i in range(n):
    print(ans.get(i+1,0))


Measured memory_bytes: 72228
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws java.lang.Exception
    {		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		long sum=0;
		for(int i=0; i<s.length(); i++) sum+=s.charAt(i)-48;
		System.out.println(sum%9==0?"Yes":"No");
	}

}

Measured memory_bytes: 36268
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		String ans = "Yay!";
	
		if (a > 8 || b > 8) {
			ans = ":(";
		}
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23508
/*input

*/

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i < b;i++)
#define rrep(i,b,a) for(int i=b ; i > a ; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define check1(a) cerr << a << endl
#define check2(a,b) cerr << a << "|" << b << endl
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
/*----------------------------------------------*/
const int MAX = 100010;
int main()
{
	int n,k;
	vi neg;
	vi pos;
	neg.pb(0);
	pos.pb(0);
	cin >> n >> k;
	rep(i,0,n){
		int x;cin >> x;
		if(x < 0){
			neg.pb(abs(x));
		}
		else{
			pos.pb(x);
		}
	}
	sort(neg.begin(),neg.end());
	sort(pos.begin(),pos.end());
	ll ans = 1e18;
	// cout << neg.size() << " " << pos.size() << endl;
	rep(i,1,k){
		if(neg.size()-1 >= i and pos.size()-1 >= k-i){
			ll tmp = min(1LL*2*neg[i]+pos[k-i],1LL*2*pos[k-i]+neg[i]);
			// cout << 1LL*2*neg[i]+pos[k-i] << " " << 1LL*2*pos[k-i]+neg[i] << endl;
			ans = min(ans,tmp);
		}
	}
	if(pos.size()-1 >= k)ans = min(ans,(long long)pos[k]);
	if(neg.size()-1 >= k)ans = min(ans,(long long)neg[k]);
	cout << ans;

	return 0;
}

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

int main()
{
	int a = 0, b = 0, c = 0;
	cin >> a >> b >> c;

	if ((a < b) && (b < c)) {
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
//mp.reserve(1024);
//mp.max_load_factor(0.25);
bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
       return (a.first > b.first);
}

int main()
{
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output1.txt", "w", stdout);
	ll n;
	cin>>n;
	ll count[4]={};
	while(n--){
		string s;
		cin>>s;
		if(s == "AC")
			count[0]++;
		if(s == "WA")
			count[1]++;
		if(s == "TLE")
			count[2]++;
		if(s == "RE")
			count[3]++;
	}
	cout<<"AC"<<" x "<<count[0]<<endl;
	cout<<"WA"<<" x "<<count[1]<<endl;
	cout<<"TLE"<<" x "<<count[2]<<endl;
	cout<<"RE"<<" x "<<count[3]<<endl;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  vector<char> chr(1,s.at(0));
  vector<int> cnt(1,1);
  for(int i = 1; i < s.size(); i++){
    for(int j = 0; j < chr.size(); j++){
      if(s.at(i) == chr.at(j)){
        cnt.at(j) ++;
        break;
      }
      else if(j == chr.size()-1){
        chr.push_back(s.at(i));
        cnt.push_back(1);
        break;
      }
    }
  }
  string ans = "Yes";
  for(int c : cnt){
    if(c%2 != 0){
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

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


int H,W;
char table[105][105];
char work[105][105];

int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){

		scanf("%s",table[row]);
	}

	int h = 0;

	//行を抜く
	for(int row = 0; row < H; row++){
		bool FLG = false;
		for(int col = 0; col < W; col++){
			if(table[row][col] == '#'){
				FLG = true;
				break;
			}
		}
		if(FLG){
			for(int col = 0; col < W; col++){

				work[h][col] = table[row][col];
			}
			h++;
		}
	}

	//列を抜く
	int w = 0;
	for(int col = 0; col < W; col++){
		bool FLG = false;
		for(int row = 0; row < h; row++){
			if(work[row][col] == '#'){
				FLG = true;
				break;
			}
		}
		if(FLG){
			for(int row = 0; row < h; row++){

				table[row][w] = work[row][col];
			}
			w++;
		}
	}

	for(int row = 0; row < h; row++){
		for(int col = 0; col < w; col++){
			printf("%c",table[row][col]);
		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 3736
#include<cstdio>

int main(){
  int W,H,x,y,r;
  std::scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if(x + r > W || x - r < 0 ){
    std::printf("No\n");
  }
  else if(y - r < 0 || y + r > H){
    std::printf("No\n");
  }
  else {
    std::printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 2676
N = int(input())
Bi  = input().split()
ret = int(Bi[0])
for i in range(1, len(Bi)):
    if(int(Bi[i]) < int(Bi[i - 1])):
        ret += int(Bi[i])
    else:
        ret += int(Bi[i - 1])
print(ret + int(Bi[len(Bi) - 1]))

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

int main (){
  int n,k;
  cin >> n >> k;
  int a[n];
  for (int i=0;i<n;i++) cin >> a[i];
  for (int i=0;i<n-k;i++) {
    if (a[i]<a[k+i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

bool isSecond(int a,int b,int c){
    if((a<=b && b<c) || (c<=b && b<a)){
        return true;
    }else{
        return false;
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> p;
    for (auto i = 0; i < n; i++)
    {
        int p_i;
        cin >> p_i;
        p.push_back(p_i);
    }

    int ans = 0;

    for (auto i = 0; i < n-2; i++)
    {
        if(isSecond(p[i],p[i+1],p[i+2])){
            ans += 1;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	//input
	ll N; cin>>N;
	vector<ll> B(N+1);
	rep1(i,N-1) cin>>B[i];
	B[0]=INF;
	B[N]=INF;

	//solve
	ll ans=0;
	rep1(i,N){
		ans+=min(B[i-1],B[i]);
	}


	//output
	cout<<ans;
}

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

int main(){
	int n;
	bool flag = false;

	while( cin >> n , n ){
		vector<int> vc;
		map<int,vector<string> > f;
		if( flag ){
			cout << endl;
		}else{
			flag = true;
		}

		for(int i=0 ; i < n ; i++ ){
			string name;
			int a,b,c;

			cin >> name >> a >> b >> c;
			int p = -(a*3 + c);
			if( count(vc.begin(),vc.end(),p) == 0 ){
				vc.push_back( p );
			}
			f[p].push_back( name );
		}
		sort( vc.begin() , vc.end() );
		for(int i=0 ; i < vc.size() ; i++ ){
			for(int j=0 ; j < f[vc[i]].size() ; j++ ){
				cout << f[vc[i]][j] << "," << -vc[i] << endl;
			}
		}
	}
}

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

int main(void)
{
    int k, n;
    cin >> k >> n;
    
    int first, last;
    int dis_max = 0;
    int dis;
    int bef = 0;
    int dis_sum = 0;
    for (int i = 0; i <= n; i++) {
        int tmp;
        cin >> tmp;
        if (i == 0) {
            first = tmp;
            dis = 0;
        } else if (i == n) {
            dis = k - tmp + first;
        } else {
            dis = tmp - bef;
        }
        if (dis_max < dis) dis_max = dis;
        dis_sum += dis;
        bef = tmp;
    }

    cout << dis_sum - dis_max << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

vector<ll> tree[200010];
vector<ll> ans;

void dfs(int v, int pair) {
    for(int i = 0; i < tree[v].size(); i++) {
        if(tree[v][i]==pair) continue;
        ans[tree[v][i]] += ans[v];
        dfs(tree[v][i], v);
    }
}
int main() {
    int n, q; cin >> n >> q;
    rep(i,n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x; cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0, -1);

    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 27392
#include<stdio.h>
#include<string.h>
#define MAX 73

char train[MAX],first[MAX],last[MAX],firstR[MAX],lastR[MAX],temporary[MAX];
char variation[1000][MAX];
int kind;

void initialize(void)
{
    int i;
    kind=1;

    for(i=0;i<MAX;i++)
    {
        train[i]=0;
        first[i]=0;
        last[i]=0;
        firstR[i]=0;
        lastR[i]=0;
    }
    return;
}

void initialize2(void)
{
    int i;
    for(i=0;i<MAX;i++)
    {
        first[i]=0;
        last[i]=0;
        firstR[i]=0;
        lastR[i]=0;
    }
    return;
}

void check(void)
{
    int i;

    for(i=0;i<kind;i++)
    {
        if(!strcmp(temporary,variation[i]))
        {
            return;
        }
    }
    strcpy(variation[kind],temporary);
    kind++;
    return;
}

void combine(void)
{
    strcpy(temporary,last);
    strcat(temporary,first);
    check();
    strcpy(temporary,first);
    strcat(temporary,lastR);
    check();
    strcpy(temporary,lastR);
    strcat(temporary,first);
    check();
    strcpy(temporary,firstR);
    strcat(temporary,last);
    check();
    strcpy(temporary,last);
    strcat(temporary,firstR);
    check();
    strcpy(temporary,firstR);
    strcat(temporary,lastR);
    check();
    return;
}

void reverse(void)
{
    int i;
    int length=strlen(first)-1;

    for(i=length;i>=0;i--)
    {
        firstR[length-i]=first[i];
    }

    length=strlen(last)-1;

    for(i=length;i>=0;i--)
    {
        lastR[length-i]=last[i];
    }
    return;
}

void devide(int num)
{
    int i,j,k;

    for(i=0;i<num-1;i++)
    {
        initialize2();
        for(j=0;j<=i;j++)
        {
            first[j]=train[j];
        }
        for(j=i+1;j<num;j++)
        {
            last[j-i-1]=train[j];
        }
        reverse();
        combine();
    }

    return;
}

int main(void)
{
    int m,i;

    scanf("%d",&m);

    for(i=0;i<m;i++)
    {
        int j;
        initialize();
        scanf("%s",train);
        strcpy(variation[0],train);
        devide(strlen(train));
        printf("%d\n",kind);
    }

    /*for(i=0;i<kind;i++)
    {
        printf("%d:%s\n",i,variation[i]);
    }*/

    return 0;
}

Measured memory_bytes: 660
//accepter by 10245
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
class Point{
public:
  double x,y,r;
  bool operator<(const Point & a)const{
    if ( x != a.x)return x < a.x;
    return y < a.y;
  }
  double dist(Point & a){
    return sqrt((a.x-x)*(a.x-x)+(a.y-y)*(a.y-y))-r-a.r;
  }
};
double min_val=10000;//need to insert Largest value
#define MAXPOINT 1e250
Point BigPoint ={MAXPOINT,MAXPOINT};
double maxr;

void Merge(Point *a,int l,int mid,int r,double midx){
  int n1 = mid-l+1,n2 = r-mid,pr=0,pl=0;
  Point L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++)L[i]=a[l+i];
  for(int i=0;i<n2;i++)R[i]=a[mid+1+i];
  L[n1]=R[n2]=BigPoint;
  for(int i=l;i<r+1;i++){
    if ( L[pl].y < R[pr].y)a[i]=L[pl++];
    else a[i]=R[pr++];
  }

  vector<Point> t;
  for(int i=l;i<r+1;i++){
    if ( abs(midx-a[i].x)< min_val+2*maxr){
      t.push_back(a[i]);
    } 
  }
  for(int i=0;i<t.size();i++){
    for(int j=i+1;j<t.size()&&abs(t[i].y-t[j].y)<min_val+2*maxr;j++){
      min_val=min(min_val,t[i].dist(t[j]));
    }
  }


}


void MergeSort(Point *a,int l,int r){//include r that means <=r
  if ( l<r){
    int q = (r+l)/2;
    double midx = a[q].x;
    MergeSort(a,l,q);
    MergeSort(a,q+1,r);
    Merge(a,l,q,r,midx);
  }
}


main(){
int n;
  while(cin >>n && n){
    min_val = 1e250;
    Point a[n];
    maxr=0;
    for(int i=0;i<n;i++){
      cin>>a[i].r>>a[i].x>>a[i].y;
      maxr=max(maxr,a[i].r);
    }
    sort(a,a+n);
    MergeSort(a,0,n-1);
    printf("%.10lf\n",min_val);
  }
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> ans(N, 0);
    // for (int i = 0; i <= N; i++) ans[i] = N - i;
    for (int i = 1; i <= N - 1; i++) {
        for (int j = i + 1; j <= N; j++) {
        int d = abs(j - i);
        int nd = abs(X - i) + 1 + abs(Y - j);
        ans[min(d, nd)]++;
        }
    }
    for (int i = 1; i < N; i++) cout << ans[i] << '\n';
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main()
{
    int n;
    string s;

    cin >> n >> s;

    int k = 0, f;
    REP(i, s.size()){
        if(s[i] == '('){
            k++;
        }
        else{
            if(k > 0){
                k--;
            }
            else{
                s.insert(s.begin(), '(');
                i++;
            }
        }
    }

    REP(i, k){
        s += ')';
    }

    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

using int64 = long long;
using uint64 = unsigned long long;

#define repeat(i, x) for (int64 i = 0; (i) < (x); (i)++)
#define rev_repeat(i, x) for (int64 i = (x) - 1; (i) >= 0; (i)--)
#define countup(i, n) for (int64 i = 0; (i) <= (n); (i)++)
#define countdown(i, n) for (int64 i = (n); (i) >= 0; (i)--)
#define range(i, a, b) for (int64 i = (a); (i) < (b); (i)++)
#define traverse(it, ctn) for (auto it = begin(ctn); (it) != end(ctn); (it)++)
#define rev_traverse(it, ctn) for (auto it = rbegin(ctn); (it) != rend(ctn); (it)++)

template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec)
{
    os << "[";
    repeat (i, vec.size())
    {
        os << (i == 0 ? "" : ", ") << vec[i];
    }
    os << "]";
    return os;
}

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

template<typename T>
ostream& operator<<(ostream& os, set<T>& s)
{
    os << "{";
    traverse (it, s)
    {
        if (it != s.begin()) os << ", ";
        os << *it;
    }
    os << "}";
    return os;
}

template<typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& m) 
{
    os << "{";
    traverse (it, m)
    {
        if (it != m.begin()) os << ", ";
        os << it->first << ": " << it->second;
    }
    os << "}";
    return os;
}

//
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _ _______ 
// |       |     | |  |  | |_____] |______    |      |      |      |    \  /  |______ 
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/   |______ 
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  | |  ____  / 
// |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  | __|__ |  \_| |_____| .  
//

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

    int n;
    cin >> n;

    vector<int64> a(n);
    repeat (i, n)
    {
        cin >> a[i];
    }

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

    int64 grundy = 0;
    int64 h = a.back();
    for (int i = n - 1; i >= 0; i--)
    {
        if (a[i] != h and (h - a[i]) % 2 == 1)
        {
            grundy ^= (n - i - 1);
        }
        h = a[i];
    }
    if (h % 2 == 1) grundy ^= n;

    if (grundy) cout << "first" << endl;
    else cout << "second" << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll k,n;
  cin >> k >> n;
  vector<ll> a(n+1);
  rep(i,n) cin >> a[i];
  a[n]=a[0]+k;
  ll ans=0;
  rep(i,n) {
    //cout << a[i+1]-a[i] << endl;
    chmax(ans,a[i+1]-a[i]);
  }
  cout << k-ans << endl;
  return 0;
}


Measured memory_bytes: 4816
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
using ll=long long;
int main() {

	ll N;
	string S;
	cin >> N;
	cin >> S;
	int count=0;
	for (int i = 0; i < N;i++) {
		if (S[i] == 'A') {
			
			if (S[i+1]=='B') {
				if (S[i + 2] == 'C') {

					count++;
				}

			}
		}

	}
	cout << count;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	map<char, int> m;
	rep(i, n){
		char c = s[i];
		m[c]++;
	}
	ll ans = 1;
	for(auto p : m){
		ans = (ans * (p.second + 1)) % mod;
	}
	ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<numeric>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()
const int INF = 1 << 30;
template<typename T>
ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : ""); return os;
}

template<typename T>
istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

bool is_good_number(ll n){
    while(n){
        if(n % 10 != 2 and n %10 != 8) return false;
        n /= 10;
    }
    return true;
}

pair<int,ll> div2(ll n){
    int cnt = 0;
    while(n % 2 == 0) n /= 2, cnt++;
    return make_pair(cnt, n);
}

vector<pair<int,ll>> calc_good_number(ll upper){
    vector<pair<int,ll>> res;
    set<ll> memo;
    queue<ll> que;
    que.push(2);
    que.push(8);
    while(que.size()){
        ll n = que.front(); que.pop();
        auto p = div2(n);
        if(not memo.count(p.second)){
            res.push_back(div2(n));
            memo.insert(p.second);
        }
        
        if(n < upper){
            que.push(n * 10 + 2);
            que.push(n * 10 + 8);
        }
    }
    return res;
}

map<pair<int,ll>, int> dp;
int dfs(const vector<pair<int,ll>> &good_number, int now, int left2, ll left){
    if(left == 1) return left2;
    if(dp.count(make_pair(left2, left))) return dp[make_pair(left2, left)];
    int ans = -INF;
    while(now < (int)good_number.size()){
        if(left % good_number[now].second == 0 and left2 >= good_number[now].first){
            ans = max(ans, dfs(good_number, now, left2 - good_number[now].first, left / good_number[now].second));
        }
        now++;
    }
    return dp[make_pair(left2, left)] = ans + 1;
}


bool solve(){
    ll n; cin >> n;
    if(n == 1){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<int,ll>> good_number = calc_good_number(sqrt(n) + 1);
    //rep(i, good_number.size()) cerr << good_number[i].second << endl;
    bool flg = false;
    if(is_good_number(n)) flg = true;
    int left2 = 0;
    while(n % 2 == 0) n /= 2, left2++;
    int res = dfs(good_number, 0, left2, n);
    if(flg) res = max(1, res);
    cout << (res < 0 ? -1 : res) << endl;
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

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

  ll ans;
  ll i = 0;
  while(!IsPrime(x+i)){
    i++;
  }

  cout << x+i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, j, n) for (int i = j; i < (n); ++i)
#define SORT(a) sort(a.begin(), a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1001001001;

int Left[2100][2100];
int Right[2100][2100];
int Up[2100][2100];
int Down[2100][2100];

int main()
{
    int H, W;

    cin >> H >> W;
    char map[H][W];
    rep(h, H)
    {
        rep(w, W) cin >> map[h][w];
    }
    

    rep(h, H)
    {
        int cur = 0;
        rep(w, W)
        {
            if (map[h][w] == '#')
                cur = 0;
            else
                cur++;
            Left[h][w] = cur;
        }
    }

    rep(h, H)
    {
        int cur = 0;
        for (int w = W-1; w >= 0; w--)
        {
            if (map[h][w] == '#')
                cur = 0;
            else
                cur++;
            Right[h][w] = cur;
        }
    }

    rep(w, W)
    {
        int cur = 0;
        rep(h, H)
        {
            if (map[h][w] == '#')
                cur = 0;
            else
                cur++;
            Down[h][w] = cur;
        }
    }
    rep(w, W)
    {
        int cur = 0;
        for (int h = H-1; h >= 0; h--)
        {
            if (map[h][w] == '#')
                cur = 0;
            else
                cur++;
            Up[h][w] = cur;
        }
    }
    int ans = 0;
    rep(h,H){
        rep(w,W){
            int Sum = Left[h][w]+Right[h][w]+Down[h][w]+Up[h][w]-3;
            ans = max(ans,Sum);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 72192
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] aA = new int[a];
		for(int i = 0; i < a-1;i++) {
			aA[sc.nextInt()-1] += 1;
		}
		for(int i:aA) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 62488
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int ans = 0;
    for (char c : S) ans += (c == '+') ? 1 : -1;
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;

int N;
ll A[200000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  ll sum = 0;
  REP(i, 0, N) sum += A[i];

  ll s = 0;
  ll ans = INF;
  REP(i, 0, N - 1) {
    s += A[i];
    ans = min(ans, abs(s - (sum - s)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include<stdio.h>
#include<math.h>

int Cp(){
    int N;
    int M;
    scanf("%d", &N);
    scanf("%d", &M);
    
    int L[M+1];
    int R[M+1];
    
    for(int i=1;i<=M;i++){
        scanf("%d", &L[i]);
        scanf("%d", &R[i]);
    }
    
    int Lmax;
    int Rmin;
    
    Lmax=L[1];
    for(int i=2;i<=M;i++){
        Lmax=( (Lmax>L[i]) ? Lmax : L[i]  );
    }
    
    Rmin=R[1];
    for(int i=2;i<=M;i++){
        Rmin=( (Rmin<R[i]) ? Rmin : R[i]  );
    }
    
    
    printf("%d\n",(Rmin-Lmax+1>0) ? Rmin-Lmax+1 : 0);
    
    return 0;
}

int main(){
    Cp();
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    //splitを使うことでStringがそれぞれ入る。
    String S[] = sc.next().split("");
    //＋の位置の場合は２の(n-1)乗
    int n = (int)Math.pow(2,3);
    
    String[] f = new String[3];
    long total = 0;
    for (int i = 0; i < n; i++) {
    	total = Long.parseLong(S[0]);
      for (int j = 0; j < 3; j++) {
        if ((i>>j & 1) == 1) {
            total += Long.parseLong(S[j+1]);
            f[j] = "+";
        } else {
        	
        	total -= Long.parseLong(S[j+1]);
        	f[j] = "-";	
       
        }
      }
      if(total == 7) break;
      
    }
    System.out.print(S[0]);
    for(int i = 0;i<3;i++) {
    	System.out.print(f[i]+S[i+1]); 
    }
    System.out.print("="+7);
  }
}


Measured memory_bytes: 21844
import sys
from heapq import heapify,heappop,heappush
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


ans = 0
left,right = [],[]
heapify(left)
heapify(right)
r = 0

Q = I()
for _ in range(Q):
    q = LI()
    if q[0] == 1:
        a,b = q[1:]
        ans += b
        if r == 0:
            heappush(left,-a)
        elif r == 1:
            x1 = -heappop(left)
            ans += abs(a-x1)
            if x1 < a:
                x1,a = a,x1
            heappush(left,-a)
            heappush(right,x1)
        else:
            x1 = -heappop(left)
            x2 = heappop(right)
            if r % 2 == 0:
                ans += max(0,x1-a,a-x2,0)
                if a <= x2:
                    heappush(left,-x1)
                    heappush(left,-a)
                    heappush(right,x2)
                else:
                    heappush(left,-x1)
                    heappush(left,-x2)
                    heappush(right,a)
            else:
                ans += abs(x1-a)
                if a <= x1:
                    heappush(left,-a)
                    heappush(right,x1)
                    heappush(right,x2)
                else:
                    heappush(left,-x1)
                    heappush(right,a)
                    heappush(right,x2)
        r += 1
    else:
        x = -heappop(left)
        print(x,ans)
        heappush(left,-x)


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if(A>=13){
    cout << B << endl;
  }
  
  else if(A<=12 && A>=6){
    cout << B/2 << endl;
  }
  
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    char op;
    
   while(1){ 
        cin >> a >> op >> b;
        
        if (op == '+'){
            cout << (a+b) << endl;
        }else if (op == '-'){
            cout << (a-b) << endl;
        }else if (op == '*'){
            cout << (a*b) << endl;
        }else if (op == '/'){
            cout << (a/b) << endl;
        }else{
            break;
        }
   }
}
//ITP1_4_C


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e2 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

int n, m, c;
int a[maxn];
int b[maxn];
int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    while (cin >> n >> m >> c) {
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int tmp = 0;
            for (int j = 0; j < m; j++) {
                cin >> a[j];
                tmp += a[j] * b[j];
            }
            if (tmp + c > 0)
                ++ans;
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  double n,t,a,ans;
  cin>>n>>t>>a;
  vector<pair<double,double>> h(n);
  for(int i=0; i<n; i++){
    double x; cin>>x;
    h[i] = make_pair(abs(a-(t-x*0.006)),i+1);
  }
  sort(h.begin(),h.end());
  cout<<h[0].second;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        int i,n,x;
        scanf("%d",&n);
        for(i=1; i<=n; i++){
                x = i;
                if(x % 3 == 0)
                        printf(" %d",i);
                else{
                        do{
                                if(x % 10 == 3){
                                        printf(" %d",i);
                                        break;
                                }
                                x /= 10;
                        }while(x);
                }
        }
        printf("\n");
        return 0;
}

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

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);

using Point = complex<double>;
using Polygon = vector<Point>;

inline int sgn(const double &a) { return (a < -EPS ? -1 : (a > EPS ? 1 : 0)); }

inline bool eq(const Point &a, const Point &b) { return abs(a - b) < EPS; }

namespace std {
inline bool operator<(const Point &a, const Point &b) {
    if (sgn(a.real() - b.real()))
        return sgn(a.real() - b.real()) < 0;
    return sgn(a.imag() - b.imag()) < 0;
}
} // namespace std

double dot(const Point &a, const Point &b) { return real(conj(a) * b); }

double det(const Point &a, const Point &b) { return imag(conj(a) * b); }

struct Line {
    Point p1, p2;

    Line(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}

    bool operator<(const Line &rhs) const {
        if (eq(p2, rhs.p2))
            return p1 < rhs.p1;
        return p2 < rhs.p2;
    }
    bool operator==(const Line &rhs) const {
        return (eq(p1, rhs.p1) && eq(p2, rhs.p2)) ||
               (eq(p1, rhs.p2) && eq(p2, rhs.p1));
    }
};

Point projection(Line line, Point p){
    Point a = line.p2 - line.p1, b = p - line.p1;
    double r = dot(a, b) / norm(a);
    return line.p1 + r * a;
}

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point p1 = Point(x1, y1), p2 = Point(x2, y2);
    Line line = Line(p1, p2);
    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        double x, y;
        cin >> x >> y;
        Point p = Point(x, y);
        Point ans = projection(line, p);
        printf("%.10f %.10f\n", ans.real(), ans.imag());
    }

    return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    string s;cin >>s;
    int q;cin >>q;
    vector<set<int>>is(26);
    for (int i = 0; i < n; ++i) {
        is[s[i]-'a'].insert(i);
    }
    for (int k = 0; k < q; ++k) {
        int a;cin >>a;
        if(a==1){
            int i;char c;cin >>i>>c;
            i--;
            is[s[i]-'a'].erase(i);
            s[i]=c;
            is[c-'a'].insert(i);
        }
        else {
            int l,r;cin >>l>>r;
            l--;
            int ans=0;
            for (int i = 0; i < 26; ++i) {
                auto it=is[i].lower_bound(l);
                if(it!=is[i].end()&&(*it)<r)ans++;
            }
            cout <<ans <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 27184
#include<stdio.h>
int gcd(int a,int b){
  int i;
  if(a==0)
    return b;
  else if(b==0)
    return a;
  while(a!=0 && b!=0){
    i=b;
    b=a%b;
    a=i;
  }
  return a;
}

//小さい順にソート
int c[200002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}


int main(){
  int n,i;
  scanf("%d",&n);
  int x[n+1];
  for(i=0;i<=n;i++)
    scanf("%d",&x[i]);
  merge(0,n,x);
  for(i=0;i<n;i++)
    x[i]=x[i+1]-x[i];
  int a=0;
  for(i=0;i<n;i++)
    a=gcd(a,x[i]);
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,m,s;
	while(~scanf("%d",&n))
	{
		s=0;
		m=2*n;
		int a[m];
		for(i=0;i<m;i++)scanf("%d",&a[i]);
		sort(a,a+m);
		for(i=0;i<m;i+=2)s+=a[i];
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
   
   int N;
   cin >> N;
   vector<long long> L(N);
   
   for(int i = 0; i < N; i++){
       cin >> L[i];
   }
    
    sort(L.begin(), L.end());
    
    long long ans = 0;
    
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            int right = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
            ans += max(right-(j+1), 0);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int i,p,K,A,B;
	1<=K<=1000;
	1<=A<=B<=1000;
	cin>>K;
	cin>>A>>B;
	for(i=A;i<=B;i++)
	{
		p=i%K;
	
	if(p==0)
	{
		cout<<"OK";
		break;
	}
	
}
   if(p!=0) 
   {
   	cout<<"NG";
   }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#define si 400005
#define For(i,a,b) for(i=a;i<b;i++)
#define piv pair<int ,vector<int>>


ll powmod(ll a, ll b){ ll ans = 1; while(b){if(b&1)ans=(ans%M*a%M)%M; a=(a%M*a%M)%M; b=b>>1;}return ans;}

int main(){
    boost
    int n, k, i, j;
    cin>>n>>k;
    vector <int> h(n);
    vector <int> dp(n, INT_MAX);
    For(i, 0, n)
        cin>>h[i];
    dp[n-1] = 0;
    for(i=n-2;i>-1;i--){
        for(j=min(i+k, n-1);j>i;j--)
            dp[i] = min(dp[i], abs(h[i]-h[j]) + dp[j]);
    }
    cout<<dp[0]<<endl;
    return 0;
}


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

int main() {
  int N,sum=0;
  cin >> N;
  vector<int> num(N);
  for(int i=0;i<N;i++){
  cin >> num[i];
  }

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

  for(int i=0;i<N-1;i++){
   sum = sum + num[i];
  }

  if(num[N-1] < sum ){
  cout << "Yes" << endl;
}
   else {
  cout << "No" << endl;
}
  }


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int num;
    scanf("%d",&num);
    int x[num];int i,j;
  for(i=0;i<num;i++){
    scanf("%d",&x[i]);
  }
    int temp=0;

    int count;
    int sumA=0;
    int sumB=0;
    for(i=0;i<num;i++){
        for(j=i;j<num;j++){
            if(x[i]>x[j]){
                temp=x[i];
                x[i]=x[j];
                x[j]=temp;
            }
        }
    }

    for(i=num-1;i>=0;i-=2){
        sumA+=x[i];
    }
    for(i=num-2;i>=0;i-=2){
        sumB+=x[i];
    }
  
    printf("%d",sumA-sumB);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int a = s[0]-'0';
  int b = s[1]-'0';
  int c = s[2]-'0';
  int d = s[3]-'0';
  REP(i, 2) REP(j, 2) REP(k, 2){
    int sum = a;
    sum += (i) ? b : -b;
    sum += (j) ? c : -c;
    sum += (k) ? d : -d;
    if(sum == 7){
      cout << a << ((i)?'+':'-') << b << ((j)?'+':'-') << c << ((k)?'+':'-') << d  << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);

		double r = stdIn.nextDouble();
		
		double s = r * r * Math.PI;
		double l = 2 * r * Math.PI;
		System.out.printf("%.10f %.10f\n", s, l);
	}
}



Measured memory_bytes: 28248
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int a,b,ans=0;cin>>a>>b;
    for(int i=a;i<=b;i++){
        string s=str(i);string t=s;
        reverse(all(s));
        if(s==t)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636