akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

long long gcd(long long a, long long b){
    if(a < b) swap(a, b);
    if(a % b == 0) return b;
    return gcd(a % b, b); 
}
long long lcm(long long a,long long b){
    return (a / gcd(a, b)) * b;
}

map<ll,ll> prime_factorization(ll n){
    map<ll, ll> res;
    ll div = 2;
    for(ll i = 2; i*i <= n; i++){
        if(n % i != 0){
            continue;
        }else{
            while(n % i == 0){
                n /= i;
                res[i]++;
            }
        }
    }
    if(n != 1){
        res[n]++;
    }

    return res;
}


int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll a, b;
    cin >> a >> b;

    ll tmp = gcd(a,b);
    map<ll,ll> ans;
    //prime_factorization(a);
    //prime_factorization(b);
    ans = prime_factorization(tmp);
    
    cout << ans.size() + 1 << endl;

    /*
    ll tmp = min(a,b);

    if(tmp == 1){
        cout << 1 << endl;
        return 0;
    }

    map<ll, ll> ans;
    ans = prime_factorization(a);
    for(auto i: ans){
        cout << i.first << " " << i.second << endl;  //key
    }
    */

    
    /*
    //ll ans = 1; //1は絶対ある
    map<ll,ll> ans;
    ans[1]++;

    bool is_prime[1000001];
    //for(ll i = 0; i*i <= tmp; i++){
    for(ll i = 0; i <= 1000001; i++){
        is_prime[i] = true;
    }

    for(ll i = 2; i*i <= a; i++){
        if(is_prime[i]){
            cout << "i = " << i << endl;
            if(a % i == 0 && b % i == 0){
                ans[i]++;
            }
            for(ll j = i*2; j*j <= a; j += i){
                is_prime[j] = false;
            }
        }    
    }


    bool is_prime2[1000001];
    //for(ll i = 0; i*i <= tmp; i++){
    for(ll i = 0; i <= 1000001; i++){
        is_prime2[i] = true;
    }

    for(ll i = 2; i*i <= b; i++){
        if(is_prime2[i]){
            if(a % i == 0 && b % i == 0){
                ans[i]++;
            }
            for(ll j = i*2; j*j <= b; j += i){
                is_prime2[j] = false;
            }
        }    
    }
    

    cout << ans.size() << endl;
    */
}

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

#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

signed main(){
 int n;
 int count[26];
 int ncount[26];
 cin>>n;
	string s;
	REP(i,n)
	{
		cin>>s;
		REP(j,26)ncount[j]=0;
		REP(j,s.size())ncount[s[j]-97]++;
		REP(j,26)
        {
          
          count[j]=i?
            count[j]<ncount[j]?
            count[j]:ncount[j]
            :ncount[j];
        }          
    }
	REP(i,26)
	{
     REP(j,count[i])cout<<char(i+97);
	}
	cout<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
A = True
while A:
  n, k = map(int,input().split())
  if n == 0 and k == 0:
    break

  S = [-1 for _ in range(n)]
  for i in range(n):
    temp = int(input())
    if i == 0:
      S[i] = temp
    else:
      S[i] = S[i-1]+temp

  ans = S[k-1]
  for i in range(n-k): #0かあn-k-1まで。
    temp = S[i+k]-S[i]
    ans = max(ans,temp)
  print(ans)



Measured memory_bytes: 9664
fun main(args: Array<String>) {
  val split = readLine()!!.split(" ")
  val n = Integer.parseInt(split[0])!!
  val a = Integer.parseInt(split[1])!!
  var b = Integer.parseInt(split[2])!!
  var result = if (a * n > b) b else a * n
  println(result)
}

Measured memory_bytes: 36120
#include<iostream>
#include<string>
using namespace std;
int main(){
	string n;
	while(getline(cin,n)){
		string tmp=n;
		for(int i=0;i<26;i++){
			if(tmp.find("the")!=-1||tmp.find("that")!=-1||tmp.find("this")!=-1)break;
			for(int j=0;j<tmp.size();j++){
				if(tmp[j]==' '||tmp[j]=='.')continue;
				if(tmp[j]=='z')tmp[j]='a';
				else tmp[j]++;
			}
		}
		cout<<tmp<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#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>;

const int INF = 1001001001;

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

  int n, k; cin >> n >> k;
  vector<int> h(n); rep(i, n) cin >> h[i];
  vector<int> dp(n, INF);
  dp[0] = 0;

  
  rep(i, n) {
    rep(j, k) {
      if(j <= i) {
	  dp[i+1] = min(dp[i+1], dp[i-j] + abs(h[i-j] - h[i+1]));
	} else break;
    }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
from collections import defaultdict
import math

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

d=defaultdict(int)
N=int(input())
A=list(map(int,input().split()))

for x in A:
    d[x]+=1
s=0
for v in d.values():
    if v>1:
        s+=comb(v,2)

for j in range(N):
    num=A[j]
    z=d[num]-1
    print(s-z)

Measured memory_bytes: 114764
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Network{
	private:
	int V;
	struct edge{
		int to,cap,cost,rev;
	};
	vector<vector<edge> > g;
	vi h,d,pv,pe;
	public:
	Network(int v){
		V=v;
		g=vector<vector<edge> >(v);
	}
	void add_edge(int s,int t,int cap,int cost){
		g[s].push_back(edge{t,cap,cost,(int)g[t].size()});
		g[t].push_back(edge{s,0,-cost,(int)g[s].size()-1});
	}
	int min_cost_flow(int s,int t,int f){
		int res=0;
		h=pv=pe=vi(V);
		while(f>0){
			priority_queue<P> q;
			d=vi(V,inf);
			d[s]=0;
			q.push({0,s});
			while(!q.empty()){
				P p=q.top();
				q.pop();
				int v=p.second;
				if(d[v]<-p.first) continue;
				for(int i=0;i<g[v].size();i++){
					edge &e=g[v][i];
					if(e.cap>0&&d[e.to]>d[v]+e.cost+h[v]-h[e.to]){
						d[e.to]=d[v]+e.cost+h[v]-h[e.to];
						pv[e.to]=v;
						pe[e.to]=i;
						q.push({-d[e.to],e.to});
					}
				}
			}
			if(d[t]==inf) return -1;
			for(int i=0;i<V;i++) h[i]+=d[i];
			int D=f;
			for(int i=t;i!=s;i=pv[i]) D=min(D,g[pv[i]][pe[i]].cap);
			f-=D;
			res+=D*h[t];
			for(int i=t;i!=s;i=pv[i]){
				edge &e=g[pv[i]][pe[i]];
				e.cap-=D;
				g[i][e.rev].cap+=D;
			}
		}
		return res;
	}
};

int n;
vi a,b;

int main(){
	cin>>n;
	a=b=vi(n);
	map<int,int> m;
	int S=0,sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		sum+=a[i]+b[i];
		if(m.find(a[i])==m.end()) m[a[i]]=S++;
		if(m.find(b[i])==m.end()) m[b[i]]=S++;
	}
	Network nt(n+S+3);
	for(int i=0;i<n;i++){
		nt.add_edge(i+1,n+m[a[i]]+1,1,a[i]);
		nt.add_edge(i+1,n+m[b[i]]+1,1,b[i]);
		nt.add_edge(i+1,n+S+1,1,a[i]+b[i]);
	}
	for(int i=0;i<n;i++) nt.add_edge(0,i+1,1,0);
	for(int i=0;i<S;i++) nt.add_edge(n+i+1,n+S+2,1,0);
	nt.add_edge(n+S+1,n+S+2,inf,0);
	cout<<sum-nt.min_cost_flow(0,n+S+2,n)<<endl;
}

Measured memory_bytes: 3536
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, s;
	P[] ps;
	TreeSet<P> set;

	// boolean[][] map;

	void run(){
		for(;;){
			s=5001;
			n=sc.nextInt();
			if(n==0){
				break;
			}
			ps=new P[n];
			// map=new boolean[s][s];
			for(int i=0; i<n; i++){
				int x=sc.nextInt();
				int y=sc.nextInt();
				ps[i]=new P(x, y);
				// map[y][x]=true;
			}
			solve();
		}
	}

	void solve(){
		int max=0;
		set=new TreeSet<P>();
		for(P p : ps){
			set.add(p);
		}
		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				if(i==j){
					continue;
				}
				P p1=ps[i];
				P p2=ps[j];
				P d=p2.sub(p1);
				P e=new P(d.y, -d.x);
				P p3=p2.add(e);
				P p4=p1.add(e);
				if(c(p3)&&c(p4)){
					max=max(max, d.abs2());
				}
			}
		}
		println(max+"");
	}

	boolean c(P p){
		return p.x>=0&&p.x<s&&p.y>=0&&p.y<s&&set.contains(p);
	}

	class P implements Comparable<P>{
		int x, y;

		P(int x, int y){
			this.x=x;
			this.y=y;
		}

		P add(P p){
			return new P(x+p.x, y+p.y);
		}

		P sub(P p){
			return new P(x-p.x, y-p.y);
		}

		int abs2(){
			return x*x+y*y;
		}

		@Override
		public int compareTo(P p){
			if(y!=p.y){
				return y-p.y;
			}else{
				return x-p.x;
			}
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <stdio.h>

int main(void){
	char b[2];
	scanf("%s",&b);
	if(b[0]=='A'){
		printf("T");
	}
	if(b[0]=='T'){
		printf("A");
	}
	if(b[0]=='C'){
		printf("G");
	}
	if(b[0]=='G'){
		printf("C");
	}
	return 0;
}

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

int main(){
  int n, tmp, d=0;
  vector<int> v, dtmp;
  cin >> n;
  v.resize(n);
  dtmp.resize(n+1);
  for(int i=0;i<n;i++){
    cin >> v[i];
    if(i==0){
      tmp = v[i];
      if(tmp<0)tmp *= -1;
      dtmp[i] = tmp;
      d += tmp;
    }
    else{
      tmp = v[i] - v[i-1];
      if(tmp < 0)tmp *= -1;
      dtmp[i] = tmp;
      d += tmp;
    }
  }
  tmp = v[n-1];
  if(tmp < 0)tmp *= -1;
  dtmp[n] = tmp;
  d += tmp;
  for(int i=0;i<n;i++){
    int d2;
    if(i==0){
      d2 = d - dtmp[i] - dtmp[i+1];
      tmp = v[1];
      if(tmp < 0)tmp *= -1;
      cout << d2 + tmp << endl;
    }
    else if(i==n-1){
      d2 = d - dtmp[i] - dtmp[i+1];
      tmp = v[n-2];
      if(tmp < 0)tmp *= -1;
      cout << d2 + tmp << endl;
    }
    else{
      d2 = d - dtmp[i] - dtmp[i+1];
      tmp = v[i-1] - v[i+1];
      if(tmp < 0)tmp *= -1;
      cout << d2 + tmp << endl;
    }
  }
  return 0;
}


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

struct Node{
    int key;
    Node *p,*l,*r;
};

Node *root,*NIL;

void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node*)malloc(sizeof(Node));
    z->key=k;
    z->l=z->r=NIL;
    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->l;
        }
        else{
            x=x->r;
        }
    }
    z->p=y;
    if(y==NIL){
        root=z;
    }
    else if(z->key<y->key){
        y->l=z;
    }
    else{
        y->r=z;
    }
}

Node* find(int k){
    Node *x;
    x=root;
    while(x!=NIL&&(x->key)!=k){
        if(k<x->key){
            x=x->l;
        }
        else{
            x=x->r;
        }
    }
    return x;
}

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->l);
    cout<<' '<<(u->key);
    inorder(u->r);
}

void preorder(Node *u){
    if(u==NIL) return;
    cout<<' '<<(u->key);
    preorder(u->l);
    preorder(u->r);
}

int main(){
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        char com[10];
        int a;
        scanf("%s%d",com,&a);
        if(com[0]=='p'){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
        else if(com[0]=='i'){
            insert(a);
        }
        else{
            if(find(a)==NIL) cout<<"no"<<endl;
            else cout<<"yes"<<endl;
        }
    }
}


Measured memory_bytes: 21856
#include<bits/stdc++.h>
using namespace std;
int DP[21][(1<<21)];
bool Pei[21][21];
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			cin>>Pei[i][j];
	for(int i=0;i<N;i++)
		if(Pei[0][i])
			DP[0][(1<<i)]=true;
	for(int i=0;i<N-1;i++)
		for(int j=0;j<(1<<N);j++)
			if(DP[i][j])
				for(int k=0;k<N;k++)
					if(!(j>>k&1)&&Pei[i+1][k])
						DP[i+1][j|(1<<k)]=(DP[i+1][j|(1<<k)]+DP[i][j])%1000000007;
	cout<<DP[N-1][(1<<N)-1]<<endl;
	return 0;
}

Measured memory_bytes: 160000
#include<bits/stdc++.h>
using namespace std;
 
inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
int ans,t;
long long i,a,b,u,c,d,e,f,g,h;
int main()
{
//	freopen("3.in","r",stdin);
//	freopen("4.out","w",stdout);
	t=read();
	while(t--){
		a=read(); b=read();
		if(a<b)swap(a,b);
		u=(a*b-1)/(b+1);
		if(u<=b+1)ans=u; else
		{
 
		h=u+b+1;
		if((h/2*(h-h/2))<=a*b-1)ans=u;else{
//			g=sqrt(a*b-0.9);


//tepan//da xiao// 0 1 2 ... //
           // g=sqrtl((long double)a*b-0.9);
 g=sqrt((long double)a*b-0.9); //(a*b) (...) //ll -4//()
            //sqrt//(long double) //noi linux
			
//二分套三分 

			ans=min(u-g+1,g-(b+1)+1);
			if(u-g+1>g-(b+1)+1 && g*(g+1)<=a*b-1)++ans;
            
//            int v=b+1;
//            for(long long i=u; i>=g; --i){
//            	if(i*v<=a*b-1)
//            	{
//            	    ++ans;
//            	    ++v;
//            	    if(v==292703660)
//					int hh=0; 
//                }
//			}
            
			ans+=g-1;
		}
		
	    }
		ans+=b-1;
		printf("%d\n",ans);
	} 
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    int N,x=0,y=0,n;
    scanf("%d",&N);
    while(N--)
    {
        scanf("%d",&n);
        if(n%2==0)
            x++;
        else
            y++;
    }
    if(y%2!=0)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}

Measured memory_bytes: 128
com = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
n = int(input())
for _ in range(n):
    s = input()
    com[s] += 1
print("AC x " + str(com['AC']))
print("WA x " + str(com['WA']))
print("TLE x " + str(com['TLE']))
print("RE x " + str(com['RE']))

Measured memory_bytes: 9200
import sys

N, A = map(int, sys.stdin.readline().strip().split())
X = list(map(int, sys.stdin.readline().strip().split()))

# iまでのカードをj枚使って、合計でkである組み合わせ数
MAX_N = N*50 + 1
dp = [[[0 for _ in range(MAX_N)] for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for k in range(MAX_N):
            if dp[i][j][k] > 0:
                # i+1番目のカードを選ばない
                dp[i+1][j][k] += dp[i][j][k]
                # i+1番目のカードを選ぶ
                dp[i+1][j+1][k+X[i]] += dp[i][j][k]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A*i]
print(ans)

Measured memory_bytes: 95324
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int a = sc.nextInt();
      String op = sc.next();
      int b = sc.nextInt();
      if(op.equals("+")){
        System.out.println(a+b);
      }else if(op.equals("-")){
        System.out.println(a-b);
      }else if(op.equals("*")){
        System.out.println(a*b);
      }else if(op.equals("/")){
        System.out.println(a/b);
      }else if(op.equals("?")){
        break;
      }
  }
    sc.close();
  }
}



Measured memory_bytes: 26276
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import itertools
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  S=[]
  T=[]
  for _ in [0]*N:
    s,t=pin().split()
    S.append(s)
    T.append(int(t))
  U=list(itertools.accumulate(T))
  X=pin()[:-1]
  print(sum(T)-U[S.index(X)])
  return 

main()

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

//int _; 

int n,ans=0,a[3];
string s;
 
int main()
{
	//for(scanf("%d",&_);_;_--)
	long long n,k;
	long long ans=0;
	cin >> n >> k;
	for(long long i=k;i <= n+1;i++)
	{
		ans += (n-i+1)*i+1;
	}
	
	cout << ans%(long long)(10e8+7) << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n,z,w;
    cin >> n >> z >> w;
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    if (n == 1) {
        cout << abs(c[0] - w) << endl;
    }
    else {
        cout << max(abs(c[n - 1] - c[n - 2]), abs(c[n - 1] - w)) << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if sortdictV1[0][0] != sortdictV2[0][0]:
    a = N - sortdictV1[0][1] - sortdictV2[0][1]
else:
  if len(dictV1) == len(dictV2) == 1:
    a = N // 2
  else:
    if len(dictV1) == 1:
      a = N - sortdictV1[0][1] - sortdictV2[1][1]
    elif len(dictV2) == 1:
      a = N - sortdictV1[1][1] - sortdictV2[0][1]
    else:
      a = min(N - sortdictV1[0][1] - sortdictV2[1][1], N - sortdictV1[1][1] - sortdictV2[0][1])
print(a)


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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll h, w;
  cin >> h >> w;
  char s[h][w];
  REP(i,h){
    REP(j, w)
      cin >> s[i][j];
  }

  ll edge[h*w][h*w];
  REP(i, h*w){
    REP(j, h*w){
      edge[i][j] = INF;
      if(i==j)
        edge[i][j] = 0;
    }
  }

  REP(i, h){
    REP1(j, w){
      if(s[i][j] == '.' && s[i][j-1]=='.')
        edge[i*w+j][i*w+j-1] = edge[i*w+j-1][i*w+j] = 1;
    }
  }

  REP(j, w){
    REP1(i, h){
      if(s[i][j] == '.' && s[i-1][j]=='.')
        edge[i*w+j][(i-1)*w+j] = edge[(i-1)*w+j][i*w+j] = 1;
    }
  }

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

  ll ans = 0;
  REP(j, h*w)REP(i, h*w){
    if(edge[i][j]!=INF)
      ans = max(ans,edge[i][j]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1536
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
//<< setprecision(5)
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	llint n,A,B;cin>>n>>A>>B;
	deque<pair<llint,llint>>aset;//数字,個数 一番近いのをAに入れた
	//int apot=0;//sumにどこまで加算されたか
	deque<pair<llint,llint>>bset;//一番近いのをBに入れた
	//int bpot=0;//sumにどこまで加算されたか
	llint asum=0,bsum=0;
	aset.pub(mp(-big,1));
	bset.pub(mp(-big,1));
	llint mae=-big;//前の数字
	for(int i=0;i<=n;i++){
		llint s;if(i<n){cin>>s;}else{s=big+big;}
		while(!bset.empty()&&bset.front().fir+A<=s){
			bsum+=bset.front().sec;bset.pof();
		}
		while(!aset.empty()&&aset.front().fir+B<=s){
			asum+=aset.front().sec;aset.pof();
		}
		asum%=mod;
		bsum%=mod;
		aset.pub(mp(mae,bsum));
		bset.pub(mp(mae,asum)); 
		/*
		cout<<"de"<<asum<<"naka";
		for(auto it:aset){cout<<" "<<it.sec;}cout<<endl;
		cout<<"de"<<bsum<<"naka";
		for(auto it:bset){cout<<" "<<it.sec;}cout<<endl;*/
		if(s-mae<A){
			while(aset.size()>1){
				aset.pof();
			}asum=0;
		}
		if(s-mae<B){
			while(bset.size()>1){
				bset.pof();
			}bsum=0;
		}
		mae=s;
	}
	llint ans=aset.back().sec+bset.back().sec;
	if(ans%2==1){ans+=mod;}
	ans/=2;
	ans%=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//(x)(x-2)(x-4)
//1 0 0 0 0
//1 1 1 1 1
//1 2 4 3 1
//1 3 4 2 1
//1 4 1 4 1
int main(void){
	llint p,i,j;cin>>p;
	vector<int>a(p);
	for(i=0;i<p;i++){cin>>a[i];}
	vector<llint>ans(p);
	vector<llint>gya(p);
	gya[0]=1;
	for(i=1;i<p;i++){
		llint now=1;
		for(j=0;j<p-2;j++){now*=i;now%=p;}
		gya[i]=now;
	}
	for(i=0;i<p;i++){
		ans[0]+=a[i];
		llint now=p-a[i];
		for(j=p-1;j>=0;j--){
			ans[j]+=now;ans[j]%=p;
			now*=(p-i)*j*gya[p-j];now%=p;
			
		}
	}
	for(i=0;i<p;i++){cout<<ans[i]%p<<" ";}
	cout<<endl;
	return 0;
}
//1-(x-a)^p-1 = x=aのとき1 それ以外0
//1 0 0 0 0 0 0
//1 1 1 1 1 1 1
//1 2 4 1 2 4 1
//1 3 2 6 4 5 1
//1 4 2 1 4 2 1
//1 5 4 6 2 3 1
//1 6 1 6 1 6 1


Measured memory_bytes: 384
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ac,n,m,ind,pen;
map<ll,ll> mp;
void solve()
{
    cin>>n>>m;
    for(ll i=1;i<=m;i++)
    {
        string s;
        cin>>ind>>s;
        if(s=="WA")
        {
            if(mp[ind]!=-1)
                mp[ind]++;
        }
        else if(mp[ind]!=-1)
        {
            pen+=mp[ind];
            mp[ind]=-1;
            ac++;
        }
    }
    cout<<ac<<" "<<pen<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

#define rep(i,N)  for(int i=0; i<N; i++)
#define ol(a) cout << a << endl;
#define PI 3.14159265359
using namespace std;

int main(){
  int n; cin >> n;
  int a = n/1000;
  int b = n%1000;
  if(b==0){
    ol(0)
  }
  else{
    ol(1000-b)
  }
  
}

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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f

int main(){
    fcin;
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a >= 13){
        ans = b;
    } else if(a >= 6 && a <= 12) ans = b/2;
    else ans = 0;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
  ll n,m; cin >> n >> m;
  vector<ll> l(m),r(m);
  rep(i,m) cin >> l[i] >> r[i];
  ll mx=100001,mn=0;
  rep(i,m) mn=max(mn,l[i]);
  rep(i,m) mx=min(mx,r[i]);
  if(mx<mn){
    cout << 0 << endl;
  }else{
    if(n>=mx) cout << mx-mn+1 << endl;
    else if(n>=mn) cout << n-mn+1 << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 200050
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
double pi = acos(-1);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,a;
    cin>>n>>m;
    ll sum = 0;
    for(int i=0;i<m;i++){
        cin>>a;
        sum+=a;
    }
    sum = n-sum;
    if(sum<0)sum = -1;
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
using namespace std;

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

	cout << ceil((double)n / 2);
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    

    cin >>N;
    vector<ll>T(N);
    ll sum=0;
    rep(i,N){
        cin>>T[i];
        sum+=T[i];
    }
    cin>>M;
    vector<ll>P(M),X(M);

    rep(i,M){
        cin>>P[i]>>X[i];
        P[i]--;
    }

    rep(i,M){
        cout<<sum-T[P[i]]+X[i]<<endl;;
    }
    


    return 0;
    

}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAX = 1e9;

int main()
{
	lld n,a,b;
	vector<lld> h;

	cin >> n >> a >> b;
	h.resize(n);
	for(int i = 0; i < n; i++)
	{
		cin >> h[i];
	}

	lld up = MAX , low = 0;
	lld mid = 0;

	while(up - low > 1)
	{
		mid = (up + low) / 2;
		//cout << "mid = " << mid << endl;
		lld t = 0;
		for(int i = 0; i < n; i++)
		{
			lld x = h[i];
			x -= b * mid;
			if (x > 0)
			{
				t += ceil((double)x / (a-b));
			}
		}


		if (t <= mid)
		{
			up = mid;
		}else
		{
			low = mid;
		}
	}

	cout << up << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n, m, a[100][100] = { {} }, b[100] = {}, c[100] = {};
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int j = 0; j < m; j++) {
        cin >> b[j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            c[i] += a[i][j] * b[j];
        }
        cout << c[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
n, m = map(int, input().split())
l = [[] for i in range(n)]
o = []
ans = 0

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    l[a].append(b)
    l[b].append(a)
    o.append([a, b])

def dfs(f):
    if vis[f] == 1:
        return
    vis[f] = 1
    for t in l[f]:
        if f != a or t != b:
            dfs(t)

for a, b in o:
    vis = [0]*n
    dfs(a)
    if vis[b] == 0:
        ans += 1

print(ans)

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

using namespace std;

typedef long long ll;

int N, M;
int num[26];
multiset<int> S;

inline int toInt(char c) {return c - 'a';}

void solve()
{
  for (int i = 0; i < 26; ++i) {
    if (num[i]) S.insert(num[i]);
  }
  int n4 = (N / 2) * (M / 2);
  int n2 = (N / 2) * (M % 2) + (M / 2) * (N % 2);
  int n1 = (M % 2) * (N % 2);
  for (int i = 0; i < n4; ++i) {
    if (*S.rbegin() >= 4) {
      int ma = *S.rbegin();
      int tmp = ma - 4;
      S.erase(S.find(ma));
      if (tmp) S.insert(tmp);
    } else {
      printf("No\n");
      return;
    }
  }
  for (int i = 0; i < n2; ++i) {
    if (*S.rbegin() >= 2) {
      int ma = *S.rbegin();
      int tmp = ma - 2;
      S.erase(S.find(ma));
      if (tmp) S.insert(tmp);
    } else {
      printf("No\n");
      return;
    }
  }
  for (int i = 0; i < n1; ++i) {
    if (*S.rbegin() >= 1) {

    } else {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
}

int main()
{
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      char c; scanf(" %c", &c);
      num[toInt(c)]++;
    }
  }
  solve();
  return 0;
}


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

int main() {
    int a,b;
    cin >> a >> b;
    // cout << x * x * x << endl;
    if (a % 2 == 0 || b % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n int
	var S string

	fmt.Scan(&n, &S)

	cnt := 0
	for i := 1; i < n; i++ {
		if S[i] == 'E' {
			cnt++
		}
	}
	ans := cnt

	for i := 1; i < n; i++ {
		if S[i-1] == 'W' {
			cnt++
		}
		if S[i] == 'E' {
			cnt--
		}
		ans = min(ans, cnt)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack> 
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
//const int MAX_V=105;
const long double pi = 3.14159265;
const long long mod =1e9+7;


int main(){
    int a, b;
    cin >> a >> b;
    int ans = (a+b+1)/2;
    cout << ans << endl;

    return 0;
}
 

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

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(10)
#define fi first
#define se second
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
template <typename T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
};
template <typename T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
};
void Pvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Ps(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}


ll  n, m, r, l, k, h, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;

void INIT() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << DOUBLE;
}

ll e(int n){
  ll ans=n;
  for(int i=2;i*i<=n;i++){
	if(n%i==0){
	  ans-=ans/i;
      while(n%i==0)n/=i;
    }
  }
  if(n>1)ans-=ans/n;
  return ans;
}

int main() {
    INIT();
    int n;cin>>n;
    cout<<e(n)<<endl;
    return 0;
}



Measured memory_bytes: 3228
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int wx[100],wy[100],r[100];

main(){
  int n;
  while(cin>>n,n){
    rep(i,n)cin>>wx[i]>>wy[i]>>r[i];

    int m;
    cin>>m;
    while(m--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      bool safe=false;
      rep(i,n){
	if(a==c && b==d)break;
	int e=wx[i],f=wy[i],g=r[i];
	bool myin=(e-a)*(e-a)+(b-f)*(b-f)<g*g;
	bool enin=(e-c)*(e-c)+(f-d)*(f-d)<g*g;
	if(myin!=enin){
	  safe=true;
	  break;
	}
	if(myin && enin)continue;

	int varxy=(a*a-2*a*c+b*b-2*b*d+c*c+d*d);
	double xx=(a*a*e-a*b*d+a*b*f-2*a*c*e+a*d*d-a*d*f+b*b*c-b*c*d-b*c*f+c*c*e+c*d*f);
	xx=xx/varxy;
	double yy=(a*a*d-a*b*c+a*b*e-a*c*d-a*d*e+b*b*f+b*c*c-b*c*e-2*b*d*f+c*d*e+d*d*f);
	yy=yy/varxy;
	//cout<<xx<<' '<<yy<<endl;
	if((e-xx)*(e-xx)+(f-yy)*(f-yy)>g*g)continue;

	if((a<=xx && xx<=c) || (c<=xx && xx<=a)){
	  safe=true;
	  break;
	}

	continue;

	
	int var1=(-2*a*a*e+2*a*b*d-2*a*b*f+4*a*c*e-2*a*d*d+2*a*d*f-2*b*b*c+2*b*c*d+2*b*c*f-2*c*c*e-2*c*d*f);
	int var2=var1*var1-4*(a*a-2*a*c+b*b-2*b*d+c*c+d*d)*
	  (a*a*d*d-2*a*a*d*f+a*a*e*e+a*a*f*f-a*a*g*g-2*a*b*c*d+2*a*b*c*f+2*a*c*d*f
	   -2*a*c*e*e-2*a*c*f*f+2*a*c*g*g+b*b*c*c-2*b*c*c*f+c*c*e*e+c*c*f*f-c*c*g*g);
	if(var2<0)continue;
	int var3=2*a*a*e-2*a*b*d+2*a*b*f-4*a*c*e+2*a*d*d-2*a*d*f+2*b*b*c-2*b*c*d-2*b*c*f+
	  2*c*c*e+2*c*d*f;
	int var4=2*(a*a-2*a*c+b*b-2*b*d+c*c+d*d);
	double x1=double(sqrt(var2)+var3)/var4;
	double x2=double(-sqrt(var2)+var3)/var4;
	while(isnan(x1) || isnan(x2));
	if((a<=x1 && x1<=c) || (c<=x1 && x1<=a) || (a<=x2 && x2<=c) || (c<=x2 && x2<=a)){
	  safe=true;
	  break;
	}
      }
      if(safe)cout<<"Safe"<<endl;
      else cout<<"Danger"<<endl;
    }
  }
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var P = int.Parse(inputs[0]);
        var Q = int.Parse(inputs[1]);
        var R = int.Parse(inputs[2]);

        var sum = P + Q;
        var min = Math.Min(P + Q, Q + R);
        min = Math.Min(min, R + P);
        Console.WriteLine(min);
    }
}



Measured memory_bytes: 11092
x,k,d = map(int,input().split())
check = []
if abs(x) // d > k :
    print(abs(abs(x)- k*d))
else:
    if (k - x//d) % 2 == 0:
        print(abs(x - d*(x//d)))
    else:
        print(min(abs(x - d*(x//d - 1)), abs(x - d*(x//d + 1))))


Measured memory_bytes: 8976
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q, r, p, S;
U_MAP yatta;

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

  cin >> n >> k >> r >> S >> p >> s;
  rrep(i, 0, n) {
    if (s[i] == 'r') {
      if (i >= k && yatta[i - k] == 1 && s[i] == s[i - k]) continue;
      yatta[i] = 1;
      ans += p;
    } else if (s[i] == 's') {
      if (i >= k && yatta[i - k] == 1 && s[i] == s[i - k]) continue;
      yatta[i] = 1;
      ans += r;
    } else {
      if (i >= k && yatta[i - k] == 1 && s[i] == s[i - k]) continue;
      yatta[i] = 1;
      ans += S;
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 4468
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <functional>
#include <stack>
#include <set>
#include <map>
#include <ctype.h>
#include <cstring>
#include <string>
#include <iostream>

#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;

typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef pair<lli,lli> pll;

int n,m,arr[100001],pa[100001];
vector<int> val[100001],idx[100001];

int find(int cur){
	return cur==pa[cur] ? cur : pa[cur] = find(pa[cur]);
}
void merge(int u,int v) {
	int pu=find(u),pv=find(v);
	pa[pv] = pu;
}

int main() {
	int ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",arr+i),pa[i]=i;
	for(int i=0;i<m;i++) {
		int a,b;
		scanf("%d%d",&a,&b);
		merge(a,b);
	}
	for(int i=1;i<=n;i++) {
		val[find(i)].push_back(arr[i]);
		idx[find(i)].push_back(i);
	}
	for(int i=1;i<=n;i++) {
		sort(val[i].begin(),val[i].end());
		sort(idx[i].begin(),idx[i].end());
		int li=0,ri=0;
		while(li<sz(val[i]) && ri<sz(idx[i])) {
			if(val[i][li]==idx[i][ri]) {
				ans++; li++; ri++;
			} else if(val[i][li]<idx[i][ri]) li++;
			else ri++;
		}
	}
	printf("%d\n",ans);

	return 0;
}


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

using namespace std;

int main(){
	int N; cin >> N;
	bool flag = true;
	vector<int> A(N);
	for(int i = 0; i < N; ++i) cin >> A[i];

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

	int before, now;
	before = A[0];
	for(int i = 1; i < N; ++i){
		now = A[i];
		if(before == now) {
			flag = false;
			break;
		}
		before = now;
	}

	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

long long f(long long a){
	if(a==0){
		return 1;
	}
	return (f(a-1)*a);
}

int main(void){
	int n;
	scanf("%d",&n);

	if(1<=n&&n<=20){
		printf("%lld\n",f(n));
	}
	return 0;
}

Measured memory_bytes: 592
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = long.Parse(Console.ReadLine());
        long[] nm = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long ans = 0;
        var q = new PriorityQueue<long>(n);
        for (long i = 0; i < n; i++)
        {
            q.Enqueue(a[i]);
        }


        for (long i = 0; i < m; i++)
        {
            q.Enqueue((long)Math.Floor((decimal)q.Dequeue() / (decimal)2));
        }

        // 出力
        while (q.Count > 0)
        {
            ans += q.Dequeue();
        }
        
        Console.WriteLine(ans);
    }
}

public class PriorityQueue<T> where T : IComparable<T>
{
    public readonly T[] Array;
    public readonly bool Greater;
    public long Count { get; private set; } = 0;

    public PriorityQueue(long capacity, bool greater = true)
    {
        this.Array = new T[capacity];
        this.Greater = greater;
    }

    public void Enqueue(T item)
    {
        this.Array[this.Count] = item;
        this.Count += 1;
        this.UpHeap();
    }

    public T Dequeue()
    {
        // 先頭要素を末尾にして再構成
        this.Swap(0, this.Count - 1);
        this.Count -= 1;
        this.DownHeap();

        return this.Array[this.Count];
    }


    private void UpHeap()
    {
        var n = this.Count - 1;
        while (n != 0)
        {
            // 親要素の座標
            var parent = (n - 1) / 2;

            if (this.Compare(this.Array[n], this.Array[parent]) > 0)
            {
                this.Swap(n, parent);
                n = parent;
            }
            else
            {
                break;
            }
        }
    }

    private void DownHeap()
    {
        var parent = 0;
        while (true)
        {
            var child = 2 * parent + 1;
            if (child > this.Count - 1) break;

            if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0)
            {
                // 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
                child += 1;
            }

            if (this.Compare(this.Array[parent], this.Array[child]) < 0)
            {
                this.Swap(parent, child);
                parent = child;
            }
            else
            {
                break;
            }
        }
    }

    private long Compare(T a, T b)
    {
        var c = a.CompareTo(b);
        if (!this.Greater)
        {
            c = -c;
        }
        return c;
    }

    private void Swap(long a, long b)
    {
        var tmp = this.Array[a];
        this.Array[a] = this.Array[b];
        this.Array[b] = tmp;
    }
}

Measured memory_bytes: 32092