akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v;
    int now = 0;
    v.push_back(0);
    int n;
    cin >> n;
    int x;
    cin >> x;

    rep(i, n) {
        int l;
        cin >> l;
        now += l;
        v.push_back(now);
    }

    int cnt = 0;
    for (auto a : v) {
        if (a > x) break;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 384
A,B,C,D = map(int, input().split())

if A <= C <= B <= D:
    print(B-C)
elif A <= C <= D <= B:
    print(D-C)
elif C <= A <= D <= B:
    print(D-A)
elif C <= A <= B <= D:
    print(B-A)
else:
    print(0)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  cout << 180*(N-2) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S1 = sc.next();
		String S2 = sc.next();
		sc.close();
		
		int mod = (int)1e9+7;
		
		long ans = 0;
		boolean before_vertical = false;
		for(int i=0;i<N;i++) {
			if(S1.charAt(i)==S2.charAt(i)) {
				//縦置き
				if(i==0) {
					ans = 3;
				}else {
					if(before_vertical) {
						ans *= 2;
						ans %= mod;
					}else {
						ans *= 1;
						ans %= mod;
					}
					
				}
				
				before_vertical = true;
				
			}else {
				//横置き
				if(i==0) {
					ans = 6;
				}else {
					if(before_vertical) {
						ans *= 2;
						ans %= mod;
					}else {
						ans *= 3;
						ans %= mod;
					}
				}
				before_vertical = false;
				i++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 2e5 + 55;

ll md[maxN];

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

    int n, p;

    string s;

    cin >> n >> p >> s;

    auto specialCase = [&](int mod) -> ll {
        ll ans = 0;
        for(int i = 0; i < n; i++) {
            if((s[i] - '0') % mod == 0) {
                ans += (i + 1);
            }
        }

        return ans;
    };

    if(p == 2 || p == 5 || p == 10) {
        cout << specialCase(p) << '\n';
        return 0;
    }

    s = ' ' + s;

    md[n] = 1;

    for(int i = n - 1; i >= 1; i--) {
        md[i] = (md[i + 1] * 10) % p;
    }

    for(int i = 1; i <= n; i++) {
        md[i] = (md[i] * (s[i] - '0')) % p;
    }

    for(int i = 1; i <= n; i++) {
        md[i] += md[i - 1];
        md[i] %= p;
    }

    map<ll, ll> mp;

    ll ans = 0;

    for(int i = 0; i <= n; i++) {
        ans += mp[md[i]];
        mp[md[i]]++;
        p *= 10;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2640
#include<cstdio>

int main(){
  int a,b,c;
  char op;
  while(1){
    scanf("%d %c %d", &a, &op, &b);
    if(op == '?') break;
    if(op =='+'){
      c = a + b;
    }else if(op == '-'){
      c = a - b;
    }else if(op == '*'){
      c = a * b;
    }else if(op == '/'){
      c = a / b;
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long lint;

lint x, y, z, k;
int i, j;

vector <lint> s, ans;

int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    cin >> x >> y >> z >> k;

    vector <lint> a(x), b(y), c(z);

    for(i = 0; i < x; i ++) { cin >> a[i]; }
    for(i = 0; i < y; i ++) { cin >> b[i]; }
    for(i = 0; i < z; i ++) { cin >> c[i]; }

    for(i = 0; i < x; i ++) {
        for(j = 0; j < y; j ++) {
            s.push_back(a[i] + b[j]);
        }
    }
    sort(s.rbegin(), s.rend());

    lint limit = min(k, 1LL * ((int)s.size()));
    for(i = 0; i < limit; i ++) {
        for(j = 0; j < z; j ++) {
            ans.push_back(s[i] + c[j]);
        }
    }
    sort(ans.rbegin(), ans.rend());

    for(i = 0; i < k; i ++) {
        cout << ans[i] << '\n';
    }

    return 0;
}


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

int main(){
  int A, B, C, x;
  cin >> A >>B;
  C = A - 1;
  for(int i = C;i < B;i++){
    int a, b, c, d;
    C++;
    a = C / 10000;
    b = C / 1000 % 10;
    c = C / 10 % 10;
    d = C % 10;
    if(a == d && b == c){
      x++;
    }
  }
  cout << x <<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    long[][] vertexes = new long[n][];
    bool answer = true;
    long sum = 0;
    for(long i = 0; i < n; i++)
    {
      vertexes[i] = new long[2];
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      vertexes[i][0] = nums[0];
      vertexes[i][1] = nums[1];
    }
    Array.Sort(vertexes, (a, b) => a[1].CompareTo(b[1]));
    
    for(int i = 0; i < n; i++)
    {
      sum += vertexes[i][0];
      if(sum > vertexes[i][1])
      {
        answer = false;
        break;
      }
    }

		Console.WriteLine(answer?"Yes":"No");
	}
}

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

Measured memory_bytes: 3624
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst.sort()

cost = 0
drink = 0
for i in range(n):
  if drink + lst[i][1] <= m:
    cost += lst[i][0]*lst[i][1]
    drink += lst[i][1]
  else:
    cost += lst[i][0]*(m - drink)
    break
print(cost)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int n, m;
	cin >> n >> m;
	int city[n] = {0};

	REP(i, m){
		int a, b;
		cin >> a >> b;
		city[a - 1]++;
		city[b - 1]++;

	}

	REP(i, n) cout << city[i] << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class UnionFind
{
public:
	int par[30], rank[30];
	void init()
	{
		for (int i = 0; i < 30; ++i)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x)
	{
		if (x == par[x])
		{
			return(x);
		}
		else
		{
			return(par[x] = find(par[x]));
		}
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (rank[a] < rank[b])
		{
			par[a] = b;
		}
		else
		{
			par[b] = a;
			if (rank[a] == rank[b])
			{
				++rank[a];
			}
		}
	}
	bool same(int a, int b)
	{
		return(find(a) == find(b));
	}
};

void solve()
{
	int n;
	while (cin >> n, n)
	{
		UnionFind uf;
		uf.init();
		vector<int> cntFirst(26);
		vector<int> cntLast(26);
		for (int i = 0; i < n; ++i)
		{
			string s;
			cin >> s;
			++cntFirst[s[0] - 'a'];
			++cntLast[s[s.size() - 1] - 'a'];
			uf.unite(s[0] - 'a', s[s.size() - 1] - 'a');
		}
		bool isSameCharacter = true;
		for (int i = 0; i < 26; ++i)
		{
			if (cntFirst[i] != cntLast[i])
			{
				isSameCharacter = false;
				break;
			}
		}
		int root;
		for (int i = 0; i < 26; ++i)
		{
			if (cntFirst[i] != 0 && cntLast[i] != 0)
			{
				root = uf.find(i);
				break;
			}
		}
		bool isClosed = true;
		for (int i = 0; i < 26; ++i)
		{
			if (cntFirst[i] != 0 && cntLast[i] != 0)
			{
				if (root != uf.find(i))
				{
					isClosed = false;
				}
			}
		}
		if (!isSameCharacter || !isClosed)
		{
			cout << "NG" << endl;
		}
		else
		{
			cout << "OK" << endl;
		}
	}
}

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

Measured memory_bytes: 1200
s = input()
l = {}
for i in s:
    l.setdefault(i, 0)
    l[i] += 1
ans = float("inf")
for i in l.keys():
    count = 0
    s0 = ""
    for j in s:
        if i == j:
            s0 += i
        else:
            s0 += "."
    while "." in s0:
        count += 1
        s1 = ""
        for j in range(len(s0) - 1):
            if s0[j] == i or s0[j + 1] == i:
                s1 += i
            else:
                s1 += "."
        s0 = s1
    else:
        ans = min(ans, count)
print(ans)

Measured memory_bytes: 8936
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int a[100111],n;
int main()
{
	get1(n);
	int t1=0,t2=0;
	for(int i=1;i<=n;i++)
	{
		get1(a[i]);
		if(a[i]%4==0)t1++;
		else if(a[i]%2==1)t2++;
	}
	if(t1>=t2||(t1==t2-1&&t1+t2==n))puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
  int a,b,k;
  scanf("%d%d",&a,&b);
  if ((a+b)%2 == 0){
    k = (a+b)/2;
    printf("%d",k);
  } else {
    printf("IMPOSSIBLE");
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int i,N,a,total=0,d[100],j,s;
	scanf("%d",&N);
	scanf("%d",&a);
	for(i=0;i<N;i++){
		scanf("%d",&d[i]);
		total+=d[i];
	}
	for(i=0;i<N-1;i++){
		for(j=i+1;j<N;j++){
			if(d[i]<d[j]){
				s=d[i];
				d[i]=d[j];
				d[j]=s;
			}
		}
	}
	if(d[a-1]*4*a<total)printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define enum(i,x,y) for(int i=(x);i<=(y);++i)
#define try(i,x,y) for(int i=(x);i>=(y);--i)
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=105;
const double pi=atan(1)*4;

int n;
double x[MAXN],y[MAXN];
double ang[MAXN];
double solve(int cur)
{
//cerr<<cur<<":";
	enum(i,1,n)
	{
		if(i==cur){ang[i]=0;continue;}
		double x0=x[i]-x[cur],y0=y[i]-y[cur];
		if(fabs(x0)<1e-8)ang[i]=y0>0?pi/2:-pi/2;
		else ang[i]=atan(y0/x0)+(x0<0?pi:0);
		if(ang[i]<0)ang[i]+=2*pi;
//cerr<<ang[i]/pi*180<<" ";
	}
//cerr<<endl;
	sort(ang+1,ang+n+1);
	ang[1]=ang[n]-2*pi;
	double ans=0;
	enum(i,2,n)
		chkmax(ans,ang[i]-ang[i-1]);
	return ans<pi?0:(ans/pi-1)*0.5;
}

int main()
{
	readint(n);
	enum(i,1,n)scanf("%lf%lf",&x[i],&y[i]);
	enum(i,1,n)printf("%.10lf\n",solve(i));
    return 0;
}

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


int main(){
    ll N, K; cin >> N >> K;
    long double ans = 0.0;


    if(K <= N) ans = 1.0 - (long double)(K-1)/N;

    for(int i=1; i<=min(K-1, N); i++){
        int cnt = 0;
        ll r = i;
        while(r < K){
            r *= 2;
            cnt++;
        }
        ans += pow((long double)0.5, cnt)/(long double)N;
    }

    printf("%.12Lf\n", ans);
}

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

using namespace std;

//vector<int> prime;
int prime[50001];
int psize;
bool isPrime[50001];

void erats(){
	fill(isPrime,isPrime+50001,true);
	isPrime[0]=false;
	isPrime[1]=false;
	for(int i = 2; i < 50001; i++){
		if(isPrime[i]){
//			prime.push_back(i);
			prime[psize]=i;
			psize++;
			for(int j = i*2; j < 50001; j+=i){
				isPrime[j]=false;
			}
		}
	}
}

int main(){
	psize=0;
	erats();
	int n;
	while(cin>>n&&n!=0){
		int cnt=0;
		for(int i = 2; i<=n/2; i++){
			if(isPrime[i]&&isPrime[n-i])
				cnt++;
		}

		//for(int i = 0; i < psize; i++){
		//	if(prime[i]+prime[i]>n)
		//		break;
		//	for(int j = i; j < psize; j++){
		//		int sum=prime[i]+prime[j];
		//		if(sum>n)
		//			break;
		//		if(sum==n)
		//			cnt++;
		//	}
		//}
		cout<<cnt<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 936
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int a, b;
    cin >> a >> b;
    string sa, sb;
    rep(i,b){
        char s = '0' + a;
        sa.psb(s);
    }
    rep(i,a){
        char s = '0' + b;
        sb.psb(s);
    }
    if(sa < sb) cout << sa << endl;
    else cout << sb << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;   cin >> s;
    for (int bit = 0; bit < (1<<3); bit++) {
        vector<int> v;
        int tmp = s[0]-'0';
        for (int i = 0; i < 3; i++) {
            if (bit & (1<<i))
                tmp += s[i+1]-'0';
            else 
                tmp -= s[i+1]-'0';
        }
        if (tmp == 7) {
            cout << s[0];
            for (int i = 0; i < 3; i++) {
                if (bit & (1<<i))
                    cout << "+" << s[i+1];
                else 
                    cout << "-" << s[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r) {
  if (l>=r) {
    return;
  }
  int root=pre[pos++];
  int m=distance(in.begin(),find(in.begin(),in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}
void solve() {
  pos=0;
  rec(0,n);
  for (int i=0; i<n; i++) {
    if (i) {
      cout<<" "<<flush;
    }
    cout<<post[i]<<flush;
  }
  cout<<endl;
}
int main() {
  cin>>n;
  int k;
  for (int i=0; i<n; i++) {
    cin>>k;
    pre.push_back(k);
  }
  for (int i=0; i<n; i++) {
    cin>>k;
    in.push_back(k);
  }
  solve();
  return 0;
}



Measured memory_bytes: 3160
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int a,b;
    int count;
    int count8 = 0;
    for(int i = 1; i <= n; i = i + 2){
        count = 0;
        for(int j = 1; j <= n; j++){
            if(i % j == 0){
                a = j;
                b = i / j;
                if(a < b){
                    count += 2;
                }else if(a == b){
                    count++;
                }else{
                    if(count == 8){
                        count8++;
                    }
                    break;
                }
            }
        }
    }
    printf("%d\n",count8);

    return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.NoSuchElementException;

 
public class Main{
	
	public static void main(String args[])throws Exception{
		FastScanner sc = new FastScanner();
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<b){
			System.out.println("a < b");
		}else if(a>b){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
		
	}
}









class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}





Measured memory_bytes: 24100
N = int(input())
list = list(map(int,input().split()))
kosuu = [0] * N
kosuuu = [0] * N
total = 0
listed = sorted(list)
listed.append(-1)
i = 0
count = 1
while i < N:
    a = listed[i]
    if a == listed[i+1]:
        count += 1
    else:
        kosuu[a-1] = count
        total += ( count * (count-1) ) //2
        count = 1
    i += 1
for i in range(N):
    a = kosuu[list[i]-1]
    print(total-a*(a-1)//2 + (a-1)*(a-2)//2)

Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int n;
vector<int> a;

//k進数
//ほとんどの場所が0であり，0じゃなくなる場所はだいたいnのオーダーなので
//0じゃないところを管理すればいい
bool f(int k){
    //0じゃない部分のindex，値
    stack<pair<int,int>> st;
    for(int i=1;i<n;i++){
        if(a[i]<=a[i-1]){
            while(!st.empty() and st.top().first>a[i]) st.pop();
            if(!st.empty() and st.top().first==a[i]) st.top().second++;
            else st.push(make_pair(a[i],1));
            //繰り上がりの処理
            while(st.top().second==k){
                auto p=st.top();st.pop();
                if(p.first==1)return false;
                if(!st.empty() and st.top().first==p.first-1) st.top().second++;
                else st.push(make_pair(p.first-1,1));
            }
        }
    }
    return true;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>n;
    a.resize(n);
    rep(i,n) cin>>a[i];

    bool ans1=true;
    rep(i,n-1)if(a[i]>=a[i+1])ans1=false;
    if(ans1){
        cout<<1<<endl;
        return 0;
    }

    int lw=2,hi=n,ans=n;
    while(lw<=hi){
        int mid=(lw+hi)/2; 
        if(f(mid)){
            chmin(ans,mid);
            hi=mid-1;
        }else{
            lw=mid+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


/*
7
3 2 4 3 2 2 3

15
5 4 3 2 1 5 4 3 2 1 5 4 3 2 1
*/

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
typedef long long int LL;


vector<int >ve[N];
map< LL , int >ma;
LL a[N];
LL b=10e2+7;
LL ans;
void dfs(int u)
{
    a[u]=1;
    for(int i=0;i<ve[u].size();i++)
    {
        int v=ve[u][i];
        dfs(v);
        a[u]+=a[v]*b;
    }
    ans+=ma[a[u]];
    ma[a[u]]++;
    return ;
}

int main()
{
    int n;
        cin>>n;
        int u,v;
        for(int i=0;i<n-1;i++)
        {
            cin>>u>>v;
            ve[u].push_back(v);
        }
        ans=0;
        dfs(1);
        cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 21892
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
struct Stu{
    int x, y;
}stu[55];
struct Check{
    int x, y;
}che[55];
int main(){
    int n, m;
    cin>>n>>m;
    for(int i = 0; i < n; i++){
        cin>>stu[i].x>>stu[i].y;
    }
    for(int i = 0; i < m; i++){
        cin>>che[i].x>>che[i].y;
    }
    for(int i = 0; i < n; i++){
        int minn = 999999999;
        int num = 0;
        for(int j = 0; j < m; j++){
            int c = abs(stu[i].x-che[j].x)+abs(stu[i].y-che[j].y);
            if(c < minn){
                minn = c;
                num = j+1;
            }
        }
        cout<<num<<endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    for(int i=0; i<s.size()-1; i++){
        if(s[i]==s[i+1]){
            cout<<(i+1)<<" "<<(i+2);
            return 0;
        }
    }
    for(int i=0; i<s.size(); i++){
        if(s[i]==s[i+2]){
            cout<<(i+1)<<" "<<(i+3);
            return 0;
        }
    }
    cout<<"-1 -1";




    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N,D; cin >> N >> D;
    vector<vector<int>> v(N, vector<int>(D));
    int count = 0;
    for(int i=0;i<N;i++){for(int j=0;j<D;j++) cin >> v[i][j];}

    for(int i=1;i<N;i++){
        for(int j=0;j<i;j++){
            int p=0;
            for(int d=0;d<D;d++){
                p+=pow(v[i][d]-v[j][d],2);
            }
            if(sqrt(p) == int(sqrt(p))) count++;
        }
    }

    cout << count << endl;
}



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

int main(){
    string stack[N];
    string str;
    int i=0;
    string b;
    while(cin >> str){
       if(str == "+"){
            stack[i-2] = to_string(stoi(stack[i-2]) + stoi(stack[i-1]));
            i--;
        }
       else if(str == "-"){
            stack[i-2] = to_string(stoi(stack[i-2]) - stoi(stack[i-1]));
            i--;
        }
       else if(str == "*"){
            stack[i-2] = to_string(stoi(stack[i-2]) * stoi(stack[i-1]));
            i--;
        }
       else {
         stack[i] = str;
         i++;
       }
       if(cin.get() =='\n') break;        
    }

    cout << stack[0] <<"\n";
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    if(n<=599) cout << 8 << endl;
    else if(n<=799) cout << 7 << endl;
    else if(n<=999) cout << 6 << endl;
    else if(n<=1199) cout << 5 << endl;
    else if(n<=1399) cout << 4 << endl;
    else if(n<=1599) cout << 3 << endl;
    else if(n<=1799) cout << 2 << endl;
    else if(n<=1999) cout << 1 << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int,int> > A(n);
    rep(i,n) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.rbegin(), A.rend());
    rep(i,n){
        if(A[0].second == i) cout << A[1].first << endl;
        else cout << A[0].first << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
long long int minimum(long long int a, long long int b) {
	if (a > b)return b;
	if (b > a)return a;
	return a;
}
int main(void) {
	long long int N, K;
	long long int a = 0;
	long long int b = 0;
	scanf("%lld%lld", &N, &K);
	a = N % K;
	b = K - a;
	printf("%lld", minimum(a, b));
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>




int main(){
  int N; cin >> N;
  ll A[N+1], B[N+1], C[N+2];
  for (int d=0; d<=N; d++) cin >> A[d];

  C[N+1] = 0;
  for (int d=N;d>=0;d--) C[d] = C[d+1] + A[d];
  

  for (int d=0;d<=N;d++){
    if (d==0) B[0] = 1 - A[0];
    else B[d] = min(2*B[d-1], C[d]) - A[d];

    if (B[d]<0) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  if (B[N]<0) cout << -1 << endl;
  else {
    ll retval = 0;
    rep(i,N+1) retval += A[i]+B[i];
    cout << retval << endl;
  }

  // rep(i,N+1) cout << B[i] << endl;
  



  
  // cout << fixed << setprecision(6);
  return 0;
}


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

int main(){
  int K, X;
  cin >> K >> X;
  if(500*K >= X){
    cout<<"Yes"<<endl;
  }
  else cout<< "No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  const uint32_t mod = 1'000'000'007;
  uint32_t N = 0;
  std::cin >> N;
  uint64_t value = 1;
  for (size_t i = 2; i <= N; i++) {
    value *= i;
    value %= mod;
  }

  std::cout << value << std::endl;
  return 0;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int X, Y; cin >> X >> Y;
    if(__gcd(X, Y) == Y) cout << -1 << endl;
    else cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i,j,k,l;
        int[] give = new int [n];
        for(i=0;i<n;i++){
            give[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int[] num = new int [m];
        for(j=0;j<m;j++){
            num[j] = sc.nextInt();
        }
        int cnt=0;
        for(k=0;k<m;k++){
            for(l=0;l<n;l++){
                if(num[k]==give[l]){
                    cnt++;
                    break;
                }
            }       
        }
        System.out.println(cnt);
    }
}



Measured memory_bytes: 68496
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int R = scanner.nextInt();
        int G = scanner.nextInt();
        int B = scanner.nextInt();
        int N = scanner.nextInt();
        int count = 0;
        for (int i = 0; i <= N / R; ++i) {
            for (int j = 0; j <= (N - i * R) / G; ++j) {
                int remain = N - i * R - j * G;
                if (remain % B == 0) {
                    ++count;
                }
            }
        }
        System.out.println(count);
    }
}


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

signed main() {
    string n;
    cin >> n;
    char c = n[n.size() - 1];
    char c1[] = {'2', '4', '5', '7', '9'};
    char c2[] = {'3'};
    for (int i = 0; i < 5; i++) {
        if (c == c1[i]) {
            cout << "hon" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 1; i++) {
        if (c == c2[i]) {
            cout << "bon" << endl;
            return 0;
        }
    }
    cout << "pon" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    string s;
    cin >> s;
    cout << "2018";
    for(int i = 4;i<s.size();i++){
        cout << s[i];
    }   
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
// Problem : B - Collecting Balls (Easy Version)
// Contest : AtCoder - AtCoder Beginner Contest 074
// URL : https://atcoder.jp/contests/abc074/tasks/abc074_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
int k;cin>>k;
vi v(n);cin>>v;
int ans=0;
for(int i:v)
ans+=min2(2*i,2*abst(k-i));
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

int main(void){

	int s, m, h;

	scanf("%d", &s);

	h = (s / 3600);
	s = s - (h * 3600);
	m = s / 60;
	s = s - (m * 60);

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long long n, a[(1<<20)];

long long getS ( long long y ) {
    long long ret = 0;
    for ( long long i = 0 ; i < n ; i ++ ) {
        ret += abs ( a[i] - y );
    }
    return ret;
}

int main () {
    cin >> n;
    for ( long long i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
        a[i] -= i;
        a[i] --;
    }
    sort( a, a+n );

    long long ans = getS( a[n/2] );
    for ( long long kk = max(0LL, n/2-2 ) ; kk < min( n, n/2+2 ) ; kk ++ ) {
        ans = min( ans, getS(kk) );
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!

A = list(map(int,input().split()))


point = 0
for i in range(2):
    if A[0] >= A[1]:
        point += A[0]
        A[0] -= 1
    else:
        point += A[1]
        A[1] -= 1

print(point)
    
    

Measured memory_bytes: 2940
using System;
namespace ABC
{
    public class A
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int ans = A * B;

            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n;
	string s;

	cin>>n>>s;

	lli cnt = 1;
	REP(i,1,n){
		if(s[i-1]!=s[i])cnt++;
	}

	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	ll N,K;
	cin>>N>>K;
	cout<<min(N%K,K-N%K)<<'\n';
}


Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
    private static void Main()
    {
        string readLine;
        while (!string.IsNullOrEmpty(readLine = Console.ReadLine()))
        {
            var line = readLine.Split().Select(double.Parse).ToList();
            var a = line[0];
            var b = line[1];
            var c = line[2];
            var d = line[3];
            var e = line[4];
            var f = line[5];
            Console.WriteLine("{0:0.000} {1:0.000}", Math.Round((b * f - c * e) / (b * d - a * e), 3), Math.Round((a * f - c * d) / (a * e - b * d), 3));
        }
    }
}

Measured memory_bytes: 9860
//author: Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ld a=0,b=0,h=0,m=0;
    cin>>a>>b>>h>>m;
    ld theta = 5.5*(h*(60.0)+m);
    theta*=(3.1415926535897);
    theta/=(180.0);
    ld t1=b*sin(theta);
    ld t2=b*cos(theta);
    ld ans=sqrt((t1*t1+(a-t2)*(a-t2)));
    cout<<fixed<<setprecision(20)<<ans;
    return 0;
}


Measured memory_bytes: 4168
# include <stdio.h>

int main(){
    int n;
    int a, b, vazio = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; ++i){
        scanf("%d %d", &a, &b);
        vazio += (b-a) + 1;
    }

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


    return 0;
}


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

int main(){
	int N, D1, D2, i, j, k, l, f, g;
	scanf("%d%d%d", &N, &D1, &D2);
	for(k = 0; (D1 & 1) == 0; D1 >>= 1, k++){}
	for(l = 0; (D2 & 1) == 0; D2 >>= 1, l++){}
	int num = 0;
	for(i = 0; i < 2 * N; i++){
		for(j = 0; j < 2 * N; j++){
			if(num == N * N){
				return 0;
			}
			if((((k & 1) == 0 && (((i >> (k >> 1)) ^ (j >> (k >> 1))) & 1) == 0) || ((k & 1) == 1 && ((i >> (k >> 1)) & 1) == 0)) && (((l & 1) == 0 && (((i >> (l >> 1)) ^ (j >> (l >> 1))) & 1) == 0) || ((l & 1) == 1 && ((i >> (l >> 1)) & 1) == 0))){
				printf("%d %d\n", i, j);
				num++;
			}
/*			if(k % 2 == 0){
				i >> (k >> 1)
				if(((i / (1 << (k / 2))) + (j / (1 << (k / 2)))) % 2 == 0){
					f = 0;
				}
				else{
					f = 1;
				}
			}
			else{
				if((i / (1 << (k / 2))) % 2 == 0){
					f = 0;
				}
				else{
					f = 1;
				}
			}
			if(l % 2 == 0){
				if(((i / (1 << (l / 2))) + (j / (1 << (l / 2)))) % 2 == 0){
					g = 0;
				}
				else{
					g = 1;
				}
			}
			else{
				if((i / (1 << (l / 2))) % 2 == 0){
					g = 0;
				}
				else{
					g = 1;
				}
			}
			if(f == 0 && g == 0){
				printf("%d %d\n", i, j);
				num++;
			}
*/		}
	}
	return 0;
}

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

const long long mod = 1000000007;

long long mpow(long long x, long long y){
  long long ret = 1;
  for(int i=0;i<y;i++){
    ret *= x;
    ret %= mod;
  }
  return ret;
}

int main(){
  long long N;
  cin >> N;
  
  vector<long long> A(N),B(N),fugou(N);
  map<pair<long long,long long>,long long> M;
  vector<long long> zero(3,0);
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i];
    pair<long long,long long> P;
    if(A[i]==0 || B[i]==0){
      fugou[i] = 0;
      if(A[i]==0 && B[i]==0) zero[2]++;
      else if(A[i]==0) zero[0]++;
      else zero[1]++;
    }
    else{
      if((A[i]>0 && B[i]>0)||(A[i]<0 && B[i]<0)) fugou[i] = 1;
      else fugou[i] = -1;
      A[i] = abs(A[i]);
      B[i] = abs(B[i]);
      long long g = gcd(A[i],B[i]);
      A[i] /= g;
      B[i] /= g;
      
      P = make_pair(A[i],B[i]*fugou[i]);
      M[P]++;
    }
  }
  
  long long ans=1;
  for(auto x : M){
    long long a = x.first.first, b = x.first.second, nX = x.second;
    pair<long long,long long> P;
    if(b>0) P = make_pair(b,a*(-1));
    else P = make_pair(b*(-1),a);
    long long nY = M[P];
    
    long long z = mpow(2,nX) + mpow(2,nY) - 1;
    z %= mod;
    ans *= z;
    ans %= mod;
    
    M[x.first] = 0;
    M[P] = 0;
  }
  
  long long z = mpow(2,zero[0]) + mpow(2,zero[1]) - 1;
  z %= mod;
  ans *= z;
  ans %= mod;
  ans += zero[2];
  ans %= mod;
  
  ans = ans + mod - 1;
  ans %= mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 32616
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

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;
}

typedef long long ll;
typedef unsigned long long ull;

int solve(int n, int m, vector<int> &a, vector<int> &b) {
    auto d = dsu(n);
    for (int i = 0; i < m; i++) {
        d.merge(a.at(i), b.at(i));
    }
    set<int> x;
    for (int i = 0; i < n; i++) {
        x.insert(d.leader(i));
    }
    return x.size() - 1;
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    cout << solve(n, m, a, b) << endl;
    return 0;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<vector<bool>> rectangle(W, vector<bool>(H, true));

  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    
    switch (a) {
      case 1:
        for (int i = 0; i < x; i++) {
          for (int j = 0; j < H; j++) rectangle.at(i).at(j) = false;
        }
        break;
      case 2:
        for (int i = x; i < W; i++) {
          for (int j = 0; j < H; j++) rectangle.at(i).at(j) = false;
        }
        break;
      case 3:
        for (int i = 0; i < W; i++) {
          for (int j = 0; j < y; j++) rectangle.at(i).at(j) = false;
        }
        break;
      case 4:
        for (int i = 0; i < W; i++) {
          for (int j = y; j < H; j++) rectangle.at(i).at(j) = false;
        }
        break;
    }
  }
  
  int area = 0;
  
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (rectangle.at(i).at(j)) area++;
    }
  }
  
  cout << area << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
cards = [[ s+' '+str(n) for n in range(1,14)] for s in ['S','H','C','D']]
for _ in range(n):
    suit,num = input().split()
    if   suit=='S': cards[0][int(num)-1] = 0
    elif suit=='H': cards[1][int(num)-1] = 0
    elif suit=='C': cards[2][int(num)-1] = 0
    elif suit=='D': cards[3][int(num)-1] = 0
for s in cards:
    for n in s:
        if n!=0: print(n)

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

int main(){
  
 long long int n,sh,sl,p=1,k=1;
  scanf("%lld",&n);
 int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  sh=a[n-1];
  sl=a[0];
  
  while(p+k<n){
    if(sl<=sh){
      sl+=a[p];
      p++;
    }
    else{
      sh+=a[n-k-1];
      k++;
    }
  }
  
  printf("%lld",abs(sh-sl));
  
  return 0;
}

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int ll
//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int n, k;cin>>n>>k;
	int cnt2{};double ans{};

	for(int i = n; i > 0; --i){
		cnt2 = 0;
		for(int j = 0;; ++j){
			if(i*(1 << j) >= k)break;
			cnt2++;//cout << i << j << endl;
		}//このときのcnt2はコインを振る回数

		ans += (double)1/n/(1 << cnt2);
//		cout << ans << endl;
	}



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

/*	int kk = k;

	while(kk--){
		ans = 1/n*(1<<(kk+1));
		if((1<<(kk+1)) >= k);

		k--;
	}*/

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

int main(){
  int N, maxnum, x, sum;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }
  maxnum = 1;
  x = 1;
  sum = 0;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if (a.at(maxnum) < a.at(j))
        maxnum = j;
    }
    sum += a.at(maxnum)*x;
    a.at(maxnum) = 0;
    x *= -1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf ll(1e12);
//bool comp(pair<int,int> p1,pair<int,int> p2)
//{
//	if((((float)p1.first)/p1.second)>(((float)p2.first)/p2.second))return true;
//	else return false;
//}
int main()
{
	int n,h,a,b;
	cin>>h>>n;
	ll cst=0;
	vector < pair<ll,ll> > v(n);
	int i,j;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		v[i].first=a;
		v[i].second=b;
	}
//	while(h>=v[0].first)
//	{
//		h-=v[0].first;
//		cst=cst+v[0].second;ct++;
//	}
//	cout<<cst<<endl;
	ll dp[h+1];dp[0]=0;
	for(i=1;i<=h;i++)dp[i]=inf;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=h;j++)
		{
			if(j>=v[i-1].first)
			dp[j]=min(dp[j],dp[j-v[i-1].first]+v[i-1].second);
			else
			dp[j]=min(dp[j],v[i-1].second);
		}
	}
	cst=dp[h];cout<<cst<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define EPB emplace_back
#define MP make_pair
#define d(x) cerr << #x << ":" << x << endl;
#define da(x) cerr << #x << endl; for (auto a : x) cerr << a << " "; cerr << endl;
const int MOD = 1000000007;

int main() {
	fastio();
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a, a+n);
	int total = 0;
	for(int i=0;i<k;i++)
		total += a[i];
	cout << total << "\n";
	return 0;
}



Measured memory_bytes: 3616
#include<stdio.h>
int a[200010];
int ans[200010];
int main(void){
  int n;
  scanf("%d",&n);
  for(int i=2;i<=n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=2;i<=n;i++){
    ans[a[i]]++;
  }
  for(int i=1;i<=n;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}

Measured memory_bytes: 3292