akhauriyash/Code-Regression huggingface dataset:
N=int(input())
A_list=list(map(int,input().split()))
B_list=list(map(int,input().split()))
C_list=list(map(int,input().split()))

ans=0
for i in range(N):
    ans+=B_list[i]
    if i<N-1:
        if A_list[i+1]-A_list[i]==1:
            ans+=C_list[int(A_list[i]-1)]

print(ans)

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

int main() {
	double a, b, c, d;
	while (1) {
		scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
		if (a == -1 && b == -1 && c == -1 && d == -1)break;
		a = a / 180 * M_PI; b = b / 180 * M_PI; c = c / 180 * M_PI; d = d / 180 * M_PI;
		double e = sin(a)*sin(c) + cos(a)*cos(c)*cos(b - d);
		e = acos(e);
		printf("%d\n", (int)round(e*6378.1));
	}
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (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; }
typedef long long ll;
typedef pair<int,int> P;

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

int main(){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    rep(i,h)rep(j,w){
        cin >> s[i][j];
    }
    rep(i,h)rep(j,w){
        if(s[i][j]=='.'){
            int t = 0;
            rep(_,8){
                if(i+dx[_]<0||i+dx[_]>=h)continue;
                if(j+dy[_]<0||j+dy[_]>=w)continue;
                if(s[i+dx[_]][j+dy[_]]=='#')t++;
            }
            s[i][j]=t+'0';
        }
    }
    rep(i,h)rep(j,w){
        cout << s[i][j];
        if(j==w-1)cout << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {


	int N, K;

	cin >> N >> K;

	vi h(N + 1);

	REP(i, N)cin >> h[i];

	vector<long long> dp(N);

	long long minmum = 100000000000;

	dp[0] = 0;

	FOR(i,1, N) {
		FOR(j,1, K+1) {
			if (i - j >= 0) {
				if (dp[i - j] + abs(h[i] - h[i - j]) < minmum)minmum = dp[i - j] + abs(h[i] - h[i - j]);
			}
		}
		dp[i] = minmum;

		minmum = 100000000000000;
	}

	cout << dp[N-1] << endl;

	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
// #define int long long
typedef vector<int> vi;
//macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int mod = 1e9+7;
void solution(){
	int k;
	cin >> k;
	int i = 0;
	for(int j = 1;j<10000000;j++){
			i = 10*i + 7;
			i = i%k;
			if(i == 0){
				cout << j << endl;
				return;
			}
	}
	cout << -1 << endl;
	return;
}

// void solution(){ //read a whole line from the input, possibly containing spaces
// 	string s;
// 	getline(cin,s);
// }
int main(){
	
    fio; // fast input output
    int t;
    t = 1;
    // cin >> t;
    while(t--){
    	// cout << "Case #" << t  << ": ";
        solution();
    }
    return 0;
};

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a, b;
    cin>> a >> b;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>

using namespace std;

int main(){
	string Sa, Sb, Sc;
	char player = 'A';
	int count_A = 0;
	int count_B = 0;
	int count_C = 0;
	bool finished_flag = false;

	cin >> Sa >> Sb >> Sc;

	while(1){
		switch(player){
		case 'A':
			if(count_A >= (int)Sa.length()){
				finished_flag = true;
				cout << 'A' << endl;
			}else if(count_A < (int)Sa.length()){
				if(Sa.at(count_A) == 'a'){
					player = 'A';
				}else if(Sa.at(count_A) == 'b'){
					player = 'B';
				}else if(Sa.at(count_A) == 'c'){
					player = 'C';
				}
				count_A++;
			}
			break;
		case 'B':
			if(count_B >= (int)Sb.length()){
				finished_flag = true;
				cout << 'B' << endl;
			}else if(count_B < (int)Sb.length()){
				if(Sb.at(count_B) == 'a'){
					player = 'A';
				}else if(Sb.at(count_B) == 'b'){
					player = 'B';
				}else if(Sb.at(count_B) == 'c'){
					player = 'C';
				}
				count_B++;
				}
			break;
		case 'C':
			if(count_C >= (int)Sc.length()){
				finished_flag = true;
				cout << 'C' << endl;
			}else if(count_C < (int)Sc.length()){
				if(Sc.at(count_C) == 'a'){
					player = 'A';
				}else if(Sc.at(count_C) == 'b'){
					player = 'B';
				}else if(Sc.at(count_C) == 'c'){
					player = 'C';
				}
				count_C++;
			}
			break;
		}
		if(finished_flag){
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    string s; cin >> s;
    int n = s.size();
    int m = n / 2;
    int ans = 0;
    rep(i, m){
        if(s[i] != s[n-i-1]) ans++;
    }
    cout << ans << endl;
}

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

int main()
{
	long long A, B;
	cin >> A >> B;
	long long ans = 0;

	for (int i = 1; i <= min(A,B); i++)
	{
		if ((max(A,B) * i) % A == 0 && (max(A,B) * i) % B == 0)
		{
			ans = (max(A, B) * i);
			break;
		}
	}

	cout << ans << endl;

}

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


int main() {
    string s;
    cin >> s;
    string former = s.substr(0, 2);
    string latter = s.substr(2, 2);
    
    int i_former = stoi(former);
    int i_latter = stoi(latter);

    bool yymm = false;
    bool mmyy = false;

    if (0 < i_latter && i_latter <= 12) yymm = true;
    if (0 < i_former && i_former <= 12) mmyy = true;

    if (yymm && mmyy) {
        cout << "AMBIGUOUS" << endl;
    } else if (yymm) {
        cout << "YYMM" << endl;
    } else if (mmyy) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


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

namespace competitive
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var dict = new Dictionary<char, int>();
            foreach (var c in s)
            {
                if (!dict.ContainsKey(c))
                {
                    dict.Add(c, 1);
                }
                else
                {
                    dict[c]++;
                }
            }
            foreach (var item in dict)
            {
                if (item.Value > 1)
                {
                    System.Console.WriteLine("no");
                    return;
                }
            }
            Console.WriteLine("yes");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int t, lint c = 1) : to(t), cost(c) {
    }
};

struct info {
    int from;
    int now;
    int color;
    info(int _from, int _now,int _color) : from(_from), now(_now),color(_color) {
    }
};

int main() {
    int n;
    cin>>n;
    vector<vector<edge>> g(n);
    for (int i = 0; i < n-1; i++) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(edge(b,i));
        g[b].push_back(edge(a,i));
    }
    vector<int> ans(n-1,-1);
    //first:from,second:now
    queue<info> bfs;
    bfs.push(info(-1,0,0));
    while (!bfs.empty()) {
        info temp=bfs.front();
        bfs.pop();
        int usecolor=1;
        for (int i = 0; i < g[temp.now].size(); i++) {
            int next=g[temp.now][i].to;
            if (next==temp.from) {
                continue;
            }
            if (usecolor==temp.color) {
                usecolor++;
            }
            ans[g[temp.now][i].cost]=usecolor;
            bfs.push(info(temp.now,next,usecolor));
            usecolor++;
        }
    }
    cout<<*max_element(all(ans))<<endl;
    for (int i = 0; i < n-1; i++) {
        cout<<ans[i]<<endl;
    }
}

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

using namespace std;

int main(){
    int taro[100],hanako[100];
    int n,m;
    while(cin >> n >> m,n){
        int t_sum=0,h_sum=0;
        pair<int,int> ret(100,100);
        int a;
        for(int i=0;i<n;i++){
            cin >> taro[i];
            t_sum += taro[i];
        }
        for(int i=0;i<m;i++){
            cin >> hanako[i];
            h_sum += hanako[i];
        }
        int dif = t_sum - h_sum;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(abs(dif) == 2*abs(taro[i] - hanako[j])){
                    if(dif == 0 && taro[i] == hanako[j]){
                        if(ret.first + ret.second > taro[i] + hanako[j]){
                            ret = make_pair(taro[i],hanako[j]);
                        }
                    }
                    if(dif < 0 && taro[i] < hanako[j]){
                        if(ret.first + ret.second > taro[i] + hanako[j]){
                            ret = make_pair(taro[i],hanako[j]);
                        }
                    }
                    if(dif > 0 && taro[i] > hanako[j]){
                        if(ret.first + ret.second > taro[i] + hanako[j]){
                            ret = make_pair(taro[i],hanako[j]);
                        }
                    }
                }
            }
        }
        if(ret.first == 100 && ret.second == 100) cout << -1 << endl;
        else cout << ret.first << " " << ret.second << endl;
    }
    return 0;
}

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

int main(){
	int n, m; // n:konyu m:hukuro
	std::cin >> n >> m;
	while(n != 0 || m != 0){
		std::vector<int> price;
		price.resize(n);
		for(int i = 0; i < n; ++i){
			std::cin >> price[i]; // input
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

		int sum = 0;
		for(int i = 0; i < n; ++i){
			if((i+1) % m != 0){ sum += price[i];}
		}

		std::cout << sum << std::endl;
		std::cin >> n >> m; 
	}

	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b)-1; i >= (a); --i)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 200200;

struct RMQ
{
	PII A[MAX * 4];
	int n;

	void init(int n)
	{
		this->n = n;
		FOR (i, 0, MAX * 4)
		{
			A[i] = MP(INF, INF);
		}
	}

	void add(int tl, int tr, int v, int pos, int val)
	{
		if (tl == tr)
		{
			A[v] = MP(val, pos);
			return;
		}

		int tm = (tl + tr) / 2;
		if (pos <= tm) add(tl, tm, v * 2, pos, val);
		else add(tm+1, tr, v * 2 + 1, pos, val);

		A[v] = min(A[v*2], A[v*2+1]);
	}

	void add(int pos, int val)
	{
		add(0, n-1, 1, pos, val);
	}

	PII get(int tl, int tr, int v, int l, int r)
	{
		if (l == tl && r == tr)
		{
			return A[v];
		}

		if (l > r) return MP(INF, INF);

		int tm = (tl + tr) / 2;
		PII res = get(tl, tm, v*2, l, min(r, tm));
		res = min(res, get(tm+1, tr, v*2+1, max(l, tm+1), r));

		return res;
	}

	PII get(int l, int r)
	{
		return get(0, n-1, 1, l, r);
	}
} R1, R2;

struct segm
{
	int l;
	int r;
	PII v1;
	PII v2;

	segm(int l, int r, PII v1, PII v2)
	{
		this->l = l;
		this->r = r;
		this->v1 = v1;
		this->v2 = v2;
	}

	bool operator <(const segm& s) const
	{
		return MP(v1, v2) < MP(s.v1, s.v2);
	}
};

segm getSegm(int l, int r)
{
	PII v1, v2;

	if (l % 2 == 0)
	{
		v1 = R1.get(l, r);
		v2 = R2.get(v1.second+1, r);
	}
	else
	{
		v1 = R2.get(l, r);
		v2 = R1.get(v1.second+1, r);
	}

	return segm(l, r, v1, v2);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);

	R1.init(n);
	R2.init(n);

	FOR (i, 0, n)
	{
		int x;
		scanf("%d", &x);
		if (i % 2 == 0) R1.add(i, x);
		else R2.add(i, x);
	}

	set<segm> S;


	S.insert(getSegm(0, n-1));

	VI res;

	while(SZ(S))
	{
		segm s = *S.begin();
		S.erase(S.begin());

		res.PB(s.v1.first);
		res.PB(s.v2.first);

		int l = s.l;
		int r = s.r;

		int p1 = s.v1.second;
		int p2 = s.v2.second;

		if (l != p1) S.insert(getSegm(l, p1 - 1));
		if (p1 != p2 - 1) S.insert(getSegm(p1+1, p2 - 1));
		if (p2 != r) S.insert(getSegm(p2+1, r));
	}

	FOR (i, 0, SZ(res))
	{
		printf("%d ", res[i]);
	}

} 


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

int main() 
{
  int N;
  cin >> N;
  N %= 10;
  if(N == 3)
  {
    cout << "bon" << endl;
  }
  else if(N == 0 || N == 1 || N == 6 || N == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for h in range(c+1):
            if 500*i+100*j+50*h==x:
                ans+=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n,s1,s2,s3,a[303];
double f[303][303][303];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
			s1++;
		if(a[i]==2)
			s2++;
		if(a[i]==3)
			s3++;
	}
	f[0][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k<=n;k++)
			{
				if(i)
					f[i][j][k]+=(f[i-1][j+1][k])*i/(i+j+k);
				if(j)
					f[i][j][k]+=(f[i][j-1][k+1])*j/(i+j+k);
				if(k)
					f[i][j][k]+=(f[i][j][k-1])*k/(i+j+k);
				if(i || j || k)
					f[i][j][k]+=(double)n/(i+j+k);
			}
		}
	}
	cout<<fixed<<setprecision(14)<<f[s3][s2][s1]<<endl;
	return 0;
}

Measured memory_bytes: 219412
K,N = map(int, input().split())
house = [int(i) for i in input().split()]

answer = [0]

for index, i in enumerate(house):
  if i == house[-1]:
    X = (K - i) + house[0]
    answer.append(X)
  else:
    X = house[index + 1] - i
    answer.append(X)
print(K - max(answer))

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
void read(int &x){
	char c=getchar();
	int f=1;
	x=0;
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	x*=f;
}
int a[maxn],q[maxn*maxn],t;
bitset<maxn*maxn>f;
int main(){
	int i,j,k,m,n;
	read(n);
	int sum=0;
	f[0]=1;
	for(register int i=1;i<=n;i++){
		read(a[i]);
		sum+=a[i];
		f|=(f<<a[i]);
	}
	//sort(a+1,a+n+1); 
	int tmp=0,lim=1;
	for(register int i=1;i<=sum;i++)
		if(f[i])q[++t]=i;
	cout<<q[(t+1)/2]<<endl;
	//cout<<tmp<<endl;
	return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
int main(){
IOS;
int n,d,i,j,k;
int x;
cin>>n>>d;
int a[n][d];
for(i=0;i<n;i++){
    for(j=0;j<d;j++){
        cin>>a[i][j];
    }
}
int pairs=0;
for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
            x=0;
        for(k=0;k<d;k++){
            x+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
        }
        if(sqrt(x)==(int)(sqrt(x)))
            pairs++;
    }
}
cout<<pairs<<endl;
}


Measured memory_bytes: 256
abcd = input()
s = 0
i = 0
for i in range(8):
    a = abcd[0]
    for j in range(3):
        if (i >> j) & 1:
            a += '+'
        else:
            a += '-'
        a += abcd[j+1]
    s = eval(a)
    if s == 7:
        ans = a + '=' + '7'
        break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ");cout<<endl;
#define pdd(a,n,m)for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define mp make_pair
#define pb push_back
#define ll long long
//#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int dp[1011][1011];

int query(string a,string b){
  int n=a.size();
  int m=b.size();

  rep(i,1011)rep(j,1011)dp[i][j]=0;

  rep(i,n){
    rep(j,m){
      if(a[i]==b[j]){
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
      }
      dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
  }
  int ret=0;
  rep(i,n+1)rep(j,m+1)ret=max(ret,dp[i][j]);

  return ret;
}
int main(){
  int q;
  cin>>q;
  rep(i,q){
    string a,b;
    cin>>a>>b;
    cout<<query(a,b)<<endl;
  }

  return 0;
}



Measured memory_bytes: 7144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		// ??\?????°????????????????????°
		int input = sc.nextInt();

		// ???????????????
		int[][] card = new int[4][13];

		// ?????°????????????????????????????????°????????????
		String mark;
		int num;

		// ?????????????????°?????????
		int cnt;

		// ??????????????????????????????
		for (cnt = 0; cnt < input; cnt++) {

			mark = sc.next();
			num = sc.nextInt();

			switch (mark) {

			case "S":
				card[0][num - 1] = 1;
				break;

			case "H":
				card[1][num - 1] = 1;
				break;

			case "C":
				card[2][num - 1] = 1;
				break;

			case "D":
				card[3][num - 1] = 1;
				break;
			}

		}

		// ???????????????????????\????????????
		for (num = 0; num <= 3; num++) {

			for (cnt = 0; cnt <= 12; cnt++) {

				if (card[num][cnt] == 0) {

					switch (num) {

					case 0:
						System.out.println("S " + (cnt+1));
						break;

					case 1:
						System.out.println("H " + (cnt+1));
						break;

					case 2:
						System.out.println("C " + (cnt+1));
						break;

					case 3:
						System.out.println("D " + (cnt+1));
						break;
					}

				}

			}

		}
		sc.close();
	}

}

Measured memory_bytes: 26376
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long ,long long>
#define gcd __gcd
using namespace std;
int main()
{
	ll n;
	ll a[100];
	ll ct=0;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(ll i=0; i<n;i++)
	{
		if((i+1)%2!=0 && (a[i]%2!=0))
			ct++;
	}
	cout<<ct<<"\n";
}

Measured memory_bytes: 3628
#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 <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

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

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll N;
	inp >>N;
	vl a(N);
	rep(i,N){
		ll v;
		inp >> v;
		v--;
		a[i]=v;
	}
	ll cnt = 0;
	rep(i,N) if(a[a[i]]==i)cnt++;
	assert(cnt%2==0);
	cout <<cnt/2 << endl;
}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 1024
n,l=map(int,input().split())
ans=888
SUM=0
s=0
for i in range(l,l+n):
        SUM+=i
        s=i
        if i<0:
                s=1
                i*=-1
        else:
                s=-1
        if ans>i:
                ans=i
       
y=range(l,l+n)
ANS=SUM+s*ans
print(ANS)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
string S; cin >> S;
  reverse(S.begin(),S.end());
  
  bool flag = true;//誤り検出
  
  while(S.size() > 0){
    if(S.size() >= 5 && S.substr(0,5) == "esare" || S.substr(0,5) == "maerd"){
      S = S.substr(5,S.size() - 5);}
    else if(S.size() >= 6 && S.substr(0,6) == "resare"){
      S = S.substr(6,S.size() - 6);}
    else if(S.size() >= 7 && S.substr(0,7) == "remaerd"){
      S = S.substr(7,S.size() - 7);}
    else{ flag = false; break;}}
  
  if(!flag){cout << "NO" << endl;}
  else{cout << "YES" << endl;}
  return 0;}
       
  

Measured memory_bytes: 512
#include <stdio.h>

int main(){

    int W,H,x,y,r;

    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if((r<=x&&x<=W-r)&&(r<=y&&y<=H-r)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    long long int n;
    scanf("%lld",&n);
    long long int c1=0,c2=0,c3=0,c4=0;
    for(long long int i=0;i<n;i++)
    {
        char string[4];
        scanf("%s",string);
        if(strcmp("AC",string)==0)
        {
            c1++;
        }
        else if(strcmp(string,"WA")==0)
        {
            c2++;
        }
        else if(strcmp(string,"TLE")==0)
        {
            c3++;
        }
        else if(strcmp(string,"RE")==0)
        {
            c4++;
        }
    }
    printf("AC x %lld\nWA x %lld\nTLE x %lld\nRE x %lld",c1,c2,c3,c4);
    return 0;
}


Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  string temp="";int k=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='0'||s[i]=='1')
    {
      temp = temp+s[i];
      k++;
    }
    if(s[i]=='B')
    {
      if(temp.empty())
        continue;
         
      temp = temp.substr(0,k-1);
      k--;
    }
  }
  cout<<temp;
      
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>

using namespace std;

typedef long long LL;
const LL mod=1e9+7;
const int MAXN=3;
const int MAXM=3;

LL pow_mod(LL a,LL e)
{
	LL res=1;
	for (;e;a=a*a%mod,e>>=1) if (e&1) res=res*a%mod;
	return res;
}

int h,w;
LL k;
char s[1100][1100];
int m,a,b,c;
int main()
{
	scanf("%d %d %lld",&h,&w,&k);
	for (int i=1;i<=h;i++)
		scanf("%s",s[i]+1);
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++)
			if (s[i][j]=='#') m++;
	for (int i=1;i<=h;i++)
		if (s[i][1]=='#'&&s[i][w]=='#') b++;
	for (int i=1;i<=w;i++)
		if (s[1][i]=='#'&&s[h][i]=='#') c++;
	if (k<=1||b&&c)
	{
		printf("1\n");
		return 0;
	}
	LL tmp,tmp1=0,tmp2=0;
	if (b)
	{
		tmp2=b;
		for (int i=1;i<=h;i++)
			for (int j=1;j<w;j++)
				if (s[i][j]=='#'&&s[i][j+1]=='#') tmp1++;
	}
	else if (c)
	{
		tmp2=c;
		for (int i=1;i<=w;i++)
			for (int j=1;j<h;j++)
				if (s[j][i]=='#'&&s[j+1][i]=='#') tmp1++;
	}
	LL ans=pow_mod(m,k-1);
	if (m==tmp2) tmp=((k-1)%mod)*pow_mod(m,k-2)%mod;
	else tmp=(pow_mod(m,k-1)-pow_mod(tmp2,k-1)+mod)*pow_mod(m-tmp2,mod-2)%mod;
	tmp=tmp*tmp1%mod;
	ans=(ans-tmp+mod)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;

#define rep(i,beg,end)   for (auto i=(beg);i<(end);i++)
#define rrep(i,beg,end)   for (auto i=(beg);i>=(end);i--)
#define all(cont)           begin(cont), end(cont)
#define rall(cont)           rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	ll c = 0;
	rep(i, 0, 3) {
		if (s[i] == t[i]) c++;
	}
	cout << c << endl;


	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3", "2 3 5", "3 4 1" ].parse.expand.solve == 3 );
	assert( [ "3", "2 3 3", "2 2 1" ].parse.expand.solve == 0 );
	assert( [ "3", "17 7 1", "25 6 14" ].parse.expand.solve == -1 );
	assert( [
		"12",
		"757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604",
		"74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212"
	].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	return tuple( as, bs );
}

auto solve( long[] as, long[] bs )
{
	auto ds = new long[ as.length ];
	auto dt = 0L;
	auto mt = 0L;
	auto mc = 0L;
	foreach( ref d, a, b; lockstep( ds, as, bs ) )
	{
		// 準備度の差を計算して集計
		d = a - b;
		dt += d;
		
		// 準備度の差がマイナスの試験を集計
		if( d < 0 )
		{
			mt += -d;
			mc++;
		}
	}
	
	// 差がマイナスの試験が無かったら元から合格
	if( mc == 0 ) return 0;
	
	// 差の合計がマイナスだったら絶対不合格
	if( dt < 0 ) return -1;
	
	// 差がプラスの試験から差がマイナスの試験へ余分な準備度を移す（準備度が大きい順に使う）
	auto pt = 0L;
	auto pc = 0L;
	ds.sort!( ( a, b ) => b < a );
	foreach( d; ds )
	{
		pt += d;
		pc++;
		if( mt <= pt ) break;
	}
	
	return mc + pc;
}


Measured memory_bytes: 11708
N, M, K = map(int, input().split())

if N * M == K:
    print('Yes')
    exit()

for i in range(N):
    for j in range(M):
        if (N-i)*j+(M-j)*i == K:
            print('Yes')
            exit()
        elif (N-i)*j+(M-j)*i > K:
            break

print('No')

Measured memory_bytes: 3060
N = int(input())
D = list(map(int, input().split()))


D.sort()
ans = [0]
ans = [D[i]
       for i in range(N) if i % 2 == 0] + [24 - D[i] for i in reversed(range(N)) if i % 2 == 1]

ans = [0] + ans + [0]

ans = [abs(ans[i+1] - ans[i]) for i in range(N+1)]

print(min(ans))


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

using namespace std;

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

    int n, k, q;
    cin >> n >> k >> q;
    vector<int> cnt(n);
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        ++cnt[x - 1];
    }
    for (int i = 0; i < n; ++i) {
        cout << (cnt[i] + k > q ? "Yes\n" : "No\n");
    }

    return 0;
}

Measured memory_bytes: 1024
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]
cnt = 0
for i in range(N):
    num = 0
    for j in range(M):
        num += A[i][j] * B[j]
    if num > -C:
        cnt += 1

print(cnt)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  ll x;
  cin >> N >> x;
  ll a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a,a+N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (x >= a[i]) {
      ans++;
      x -= a[i];
    }
  }
  if (x != 0 && ans == N) {
    ans--;
  }
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#define maxn 500005

using namespace std;

struct node{
	long long pos, num;
}a[maxn];

long long n, s, ans = 0;

bool cmp(node x, node y){ return (x.pos < y.pos); }

int main(){
	scanf("%lld%lld", &n, &s);
	
	for (long long i = 1; i <= n; i++) scanf("%lld%lld", &a[i].pos, &a[i].num);
	sort(a + 1, a + n + 1, cmp);
	
	long long left = 1, right = n;
	
	while (left <= right){
		if (a[right].pos <= s){
			ans += (s - a[left].pos);
			break;
		}
		if (a[left].pos >= s){
			ans += (a[right].pos - s);
			break;
		}
		
		ans += (a[right].pos - a[left].pos);
		if (a[left].num >= a[right].num){
			while (left < right && a[left].num >= a[right].num) a[left].num += a[right--].num;
		}
		else{
			while (left < right && a[right].num > a[left].num) a[right].num += a[left++].num;
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{ //input->compute->output
        int N, K;
        cin >> N >> K;
        string S;
        cin >> S;
        vector<int> Nums;
        int now = 1;
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
                if (S[i] == (char)('0' + now))
                {
                        cnt++;
                }
                else
                {
                        Nums.push_back(cnt);
                        now = 1 - now;
                        cnt = 1;
                }
        }

        if (cnt != 0)
        {
                Nums.push_back(cnt);
        }

        if (Nums.size() % 2 == 0)
        {
                Nums.push_back(0);
        }

        int Add = 2 * K + 1;

        vector<int> sum(Nums.size() + 1);
        for (int i = 0; i < Nums.size(); i++)
        {
                sum[i + 1] = sum[i] + Nums[i];
        }

        int ans = 0;

        for (int i = 0; i < Nums.size(); i += 2)
        {
                // 次のleft,rightを計算する
                int left = i;
                int right = min(i + Add, (int)Nums.size());
                int tmp = sum[right] - sum[left];

                ans = max(ans, tmp);
        }

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


Measured memory_bytes: 1272
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	if(n%2==1)
	x=0;
	else
	x=a[n/2]-a[n/2-1];
	
	cout<<x;
	return 0;
	
 
 	
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

    int N;
    cin >> N;
    
    int cnt = 0;
    for (int i = 1; i < N; ++i)
        cnt += (N - 1) / i;
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

int main()
{
    long long N, K;
    scanf("%lld %lld", &N, &K);
    std::vector<long long> A(N);
    for(int i=0; i<N; i++) scanf(" %lld", &A[i]);

    long long sum = 0;
    for(int i=0; i<N; i++) sum += A[i];
    std::priority_queue<long long> d;
    for(int i=1; i*i<=sum; i++){
        if(sum % i != 0) continue;
        d.push(i);
        if(i * i != sum) d.push(sum / i);
    }

    int gcd = 0;
    std::vector<long long> r(N), r1(N), r2(N);
    while(!d.empty()){
        gcd = d.top(); d.pop();

        for(int i=0; i<N; i++) r[i] = A[i] % gcd;
        std::sort(r.begin(), r.end());
        r1[0] = r[0]; r2[N-1] = (gcd - r[N-1]) % gcd;
        for(int i=1; i<N; i++){
            r1[i] = r1[i-1] + r[i];
            r2[N-1-i] = r2[N-i] + (gcd - r[N-1-i]) % gcd;
        }
        for(int i=0; i<N-1; i++){
            if(r1[i] == r2[i+1] && r1[i] <= K){
                std::cout << gcd << std::endl; return 0; 
            }
        }
    }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  if(u == NIL || k == u ->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else if(k > u->key) u = u->right;
  }
  return u;
}


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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)  x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL)   root = z;
  else if(z->key < y->key) y->left = z;
  else y ->right = z;
}


void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}



int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      t = treeSearch(root,x);
      if( t != NIL) printf("yes\n");
      else printf("no\n");
    }
if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
     else if( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }    
  }

  return 0;
}

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


void solve() {
  int a[3];
  int sum = 0;
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 0; i < 3; i++) {
    if(sum - a[i] == a[i]) {
      cout << "Yes";
      return;
    }
  }
  cout << "No";
}

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


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {


  val Array(s,t) = readLine().split(" ")
  val Array(a,b) = readLine().split(" ").map(_.toInt)
  val u = readLine()

  def solve() = {
    if(u == s) s"${a-1} $b"
    else s"$a ${b-1}"
  }

  println(solve())

}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

int main(){
	ll A,B; cin>>A>>B;
  if(A==B) cout<<A+B;
  else{
  	cout<<max(A,B)+max(A-1,B-1);
  }
    
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**6)

def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n-2)

def g(n):
    m = int(str(n)[:-1])
    ans = 0
    for i in range(30):
        tmp = m//pow(5, i)
        if tmp == 0:
            break
        ans += tmp
    return ans


def main():
    N = int(input())
    if N < 10:
        print(0)
        return
    if N%2==1:
        print(0)
        return
    print(g(N))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cmath>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
const double EPS = 1e-10;
const double PI = atan(1)*4;
struct Vec2 {
  double x;
  double y;

  Vec2() : x(0.0),y(0.0){} 
  Vec2(double _x,double _y) :x(_x),y(_y){}  
  
  Vec2 operator+(const Vec2& other) const { return { x + other.x , y + other.y }; }
  Vec2 operator-(const Vec2& other) const { return { x - other.x , y - other.y }; }
  bool operator==(const Vec2& other) const { return (abs(x - other.x) < EPS && abs(y - other.y) < EPS ); }
  
  double dot(const Vec2& other) const { return x * other.x + y * other.y; }
  double cross(const Vec2& other) const { return x * other.y - y * other.x; }
  double length() const { return sqrt(x * x + y * y); }
};
// A とB のなす角θ cosθ, sinθ を返す
double Cos(const Vec2 A, const Vec2 B) { return A.dot(B) / (A.length()*B.length()); }
double Sin(const Vec2 A, const Vec2 B) { return A.cross(B) / (A.length()*B.length()); }

// 線分の交差判定
bool CrossCheck(const Vec2 a, const Vec2 b, const Vec2 c, const Vec2 d) {
  Vec2 AB = b - a, AC = c - a, AD = d - a;
  Vec2 CA = a - c, CB = b - c, CD = d - c;
  double s = AB.cross(AC) * AB.cross(AD);
  double t = CD.cross(CA) * CD.cross(CB);

  if(abs(Sin(CA, CB)) < EPS) return false;
  if(abs(Sin(a - d, b - d)) < EPS) return false;
  
  if(abs(Sin(AB, CD)) < EPS) { // 平行のとき
    return false;
  }
  else return s < EPS && t < EPS;
}


int main()
{
  int n; cin >> n;
  vector<Vec2> v(n);
  rep(i,n) cin >> v[i].x >> v[i].y;
  int q; cin >> q;
  while(q-- > 0) {
    Vec2 w;
    cin >> w.x >> w.y;
    bool f = false;
    rep(i,n) {
      if(abs(Sin(v[i] - w, v[(i+1)%n] - w)) < EPS && Cos(v[i] - w, v[(i+1)%n] - w) < EPS) f = true;
      if(v[i] == w) f = true;
    }
    if(f) {
      cout << 1 << "\n";
      continue;
    }
    Vec2 u(10001, w.y);
    int cnt = 0;
    rep(i,n) {
      if(CrossCheck(w, u, v[i], v[(i+1)%n])) cnt++;
      else if(abs(Sin(w - v[(i+1)%n], u - v[(i+1)%n])) < EPS && Cos(w - v[(i+1)%n], u - v[(i+1)%n]) < EPS) {
	if((v[(i+1)%n].y - v[i].y) * (v[(i+2)%n].y - v[(i+1)%n].y) > EPS ) cnt++;
	else if((v[(i+1)%n].y - v[i].y) > 0 && abs(v[(i+2)%n].y - v[(i+1)%n].y) < EPS) cnt++;
	else if(abs(v[(i+1)%n].y - v[i].y) < EPS && (v[(i+2)%n].y - v[(i+1)%n].y) < 0) cnt++;	
      }
    }
    if(cnt % 2 == 0) cout << 0 << "\n";
    else cout << 2 << "\n";
  }
  return 0;
}



Measured memory_bytes: 3196
a, b, c, d = gets.split.map(&:to_i)
a -= 1
ans = 0
if c == d
  ans = b - a
  ans -= b / c - a / c
elsif c != 0 && d != 0
  ans = b - a
  ans -= b / c - a / c
  ans -= b / d - a / d
  ans += b / c.lcm(d) - a / c.lcm(d)
end
puts ans

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        A.at(i) = a;
    }
    vector<int> ans(N);
    for (int i = 0; i < N; i++){
        ans.at(A.at(i) - 1) = i + 1; 
    }
    
    for (int i = 0; i < N; i++){
        cout << ans.at(i) << ' ';
    }
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<string> S(N);
    for(auto& in:S) cin >> in;
    set<string> st(S.begin(),S.end());
    res = st.size();
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 25112
N = int(input())
status={'AC':0, 'WA':0, 'TLE':0, 'RE':0}
results = [input() for n in range(N)]
for result in results:
     if result in status.keys():
         status[result] += 1
for k, v in status.items():
    print('{} x {}'.format(k, v))

Measured memory_bytes: 16332
#include <iostream>

using namespace std;

int main(void) {
	int num, i, j, k;
	cin >> num;
	k = num;
	if (!(num & 1)) {
		k++;
		printf("%d\n", num * (num - 2) / 2);
	}
	else
		printf("%d\n", (num - 1) * (num - 1) / 2);
	for (i = 1; i <= num; i++) {
		for (j = i + 1; j <= num; j++) {
			if (j != k - i)
				printf("%d %d\n", i, j);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,mod;
int f[3005],ans;
int S[3005][3005],C[3005][3005];
int ksm(int x,int y,int mod){
    int res=1;
    while(y){
        if(y&1) res=1ll*res*x%mod;
        x=1ll*x*x%mod,y/=2;
    }
    return res;
}
void init(){
    C[0][0]=S[0][0]=1;
    for(int i=1;i<=n+1;i++){
        C[i][0]=1,S[i][0]=0;
        for(int j=1;j<=i;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
            S[i][j]=(S[i-1][j-1]+1ll*j*S[i-1][j]%mod)%mod;
        }
    }
}
int main(){
    scanf("%d%d",&n,&mod);
    init();
    for(int i=0;i<=n;i++){
        int add=ksm(2,ksm(2,n-i,mod-1),mod);
        int ret=1,rett=ksm(2,n-i,mod);
        for(int j=1;j<=i+1;j++){
            (f[i]+=1ll*S[i+1][j]*ret%mod*add%mod)%=mod;
            ret=1ll*ret*rett%mod;
        }
        f[i]=1ll*f[i]*C[n][i]%mod;
    }
    for(int i=0;i<=n;i++){
        if(i&1) (ans+=mod-f[i])%=mod;
        else (ans+=f[i])%=mod;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 58872
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

int main(){
	int N,M,X; cin>>N>>M>>X;
	vector<int> mny(N);
	vvi power(N,vi(M));
	rep(i,0,N){
		int c;cin>>c;
		mny[i]=c;
		rep(j,0,M){
			int a; cin>>a;
			power.at(i).at(j)=a;
		}
	}
	ll ans=-1; 
	for (ll tmp=0;tmp<(1<<12);tmp++){
		bitset<12> s(tmp);
		vi v(M);
		ll cnt=0;
		rep(i,0,N){
			if(s.test(i)){
				cnt+=mny[i];
				rep(j,0,M){
					v[j]+=power.at(i).at(j);
				}
			}
		}
		sort(all(v));
		if(v[0]>=X && ans==-1){
			ans=cnt;
		}
		else if(v[0]>=X){
			ans = min(ans,cnt);
		}
	}
	cout<<ans;
	return 0;
					
		
	
}

Measured memory_bytes: 3640