akhauriyash/Code-Regression huggingface dataset:
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k;
string s,ss,sss;
vector<lo> v;

inline lo solve(){
	fio();
	cin>>s>>ss>>sss;
	if(s[s.size()-1]==ss[0] && ss[ss.size()-1]==sss[0]) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}

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


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

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;



int main(){
	int N, Q;
	cin >> N >> Q;

	string S;
	cin >> S;
	vector<int> num(N);
	rep(i, N) num[i] = 0;
	int cnt = 0;
	rept(i, 1, N) {
		if (S[i-1] == 'A' && S[i] == 'C') {
			cnt++;
		}
		num[i] = cnt;
	}

	int l, r;
	int ans = 0;
	vector<int> vec(Q);
	rep(i, Q) {
		cin >> l >> r;
		ans = num[r-1] - num[l-1];
		vec[i] = ans;
	}
	rep(i, Q) {
		cout << vec[i] << endl;
	}



	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    int n;
    cin >> n;
    int s = 1000;
    while(s<n){
        s+=1000;
    }
    cout << s- n <<endl;
    return 0;
}

Measured memory_bytes: 3592
R = 1000000
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
while True:
    try:print sum(p[:int(raw_input())+1])
    except:break

Measured memory_bytes: 37044
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    if (a < b) swap(a, b);

    cout << a + max(a - 1, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n,l;
    cin >> n >> l;
    int r = l+n-1;
    int eat;
    if(r<=0)eat=r;
    else if(l>=0)eat=l;
    else eat=0;
    int ans = (r+l)*(r-l+1)/2-eat;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


r,c,k = list(map(int, input().split()))
d = {}
for i in range(k):
    rr,cc,vv = list(map(int, input().split()))
    d[rr,cc] = vv
dp0 = [[0]*(c+1) for _ in range(r+1)]
dp1 = [[0]*(c+1) for _ in range(r+1)]
dp2 = [[0]*(c+1) for _ in range(r+1)]
dp3 = [[0]*(c+1) for _ in range(r+1)]
for i in range(1, r+1):
    for j in range(1, c+1):
        dp0[i][j] = max(dp0[i][j-1], dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
        dp1[i][j] = dp1[i][j-1]
        dp2[i][j] = dp2[i][j-1]
        dp3[i][j] = dp3[i][j-1]
        if (i,j) in d:
            v = d[i,j]
            dp1[i][j] = max(dp1[i][j], dp0[i][j-1]+v, dp0[i-1][j]+v, dp1[i-1][j]+v,dp2[i-1][j]+v, dp3[i-1][j]+v)
            dp2[i][j] = max(dp2[i][j], dp1[i][j-1]+v)
            dp3[i][j] = max(dp3[i][j], dp2[i][j-1]+v)
ans = max(dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c])
print(ans)

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

ll pow(ll m, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            res = res * m % mod;
        }
        m = m * m % mod;
        n = n >> 1;
    }

    return res;
}

int main()
{
    ll m, n;
    cin >> m >> n;
    ll mod = 1000000007;
    cout << pow(m, n, mod) << endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int d = scanner.nextInt();
        
        if(a>=c){
            if(a-c<=d){
                System.out.println("Yes");
            }
            else if(a-b<=d && b-c<=d){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
            
        }
        
        else{
            if(c-a<=d){
                System.out.println("Yes");
            }
            else if(c-b<=d && b-a<=d){
                System.out.println("Yes");
            }
            
            else{
                System.out.println("No");
            }
        }
    }
}

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

const int
	MAX = 405,
	MOD = 1e9 + 7;
int n, k, a[MAX], b[MAX], t[MAX][MAX], dp[MAX][MAX];

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

	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	for(int i = 1; i <= n; i++)
		scanf("%d", &b[i]);

	for(int p = 0; p <= 400; p++) {
		for(int i = 1; i <= 400; i++) {
			int x = 1;
			for(int it = 1; it <= p; it++)
				x = 1LL * x * i % MOD;

			t[p][i] = (t[p][i - 1] + x) % MOD;
		}
	}

	dp[n + 1][0] = 1;

	for(int i = n; i > 0; i--) {
		for(int c = 0; c <= k; c++) {
			for(int p = 0; p <= c; p++) {
				int v = (t[p][b[i]] - t[p][a[i] - 1] + MOD) % MOD;
				v = 1LL * v * dp[i + 1][c - p] % MOD;
				dp[i][c] = (dp[i][c] + v) % MOD;
			}
		}
	}

	printf("%d\n", dp[1][k]);
	return 0;
}

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

int main(){
    int n,q;
    while(cin >> n >> q, n&&q)
    {
        int m,d,date[110]={0};
        for(int k=0;k < n;k++){
            cin >> m;
            for(int i=0;i < m;i++){
                cin >> d;
                date[d]++;
            }
        }
        int maxi=0;
        int ans;
        for(int i=0;i < 110;i++){
            if(date[i] >= q && maxi < date[i]){
                maxi = date[i];
                ans = i;
            }
        }
        if(maxi) cout << ans << endl;
        else cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3032
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n,ans,i,j,cnt,flag;
string s;
char c;
int main(){
  cin>>n>>s;
  for(i=1;i<n-1;i++){
    cnt=0;
    for(c='a';c<='z';c++){
      flag=0;
      for(j=0;j<i;j++)if(s[j]==c)flag|=1;
      for(j=i;j<n;j++)if(s[j]==c)flag|=2;
      if(flag==3)cnt++;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
#define AC ios::sync_with_stdio(0),cin.tie(0);

int main()
{
    AC
    string s,t;
    cin>>s>>t;
    vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1));
    vector<vector<int>> v(s.size()+1,vector<int>(t.size()+1));
    for(int i=1;i<=s.size();i++)
        for(int j=1;j<=t.size();j++)
            if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1,v[i][j]=1;
            else if(dp[i-1][j]>dp[i][j-1]) dp[i][j]=dp[i-1][j],v[i][j]=2;
            else dp[i][j]=dp[i][j-1],v[i][j]=3;
    int x=s.size(),y=t.size();
    stack<char> r;
    while(x&&y)
    {
        if(v[x][y]==1) r.emplace(s[x-1]),x--,y--;
        else if(v[x][y]==2) x--;
        else y--;
    }
    while(r.size()) cout<<r.top(),r.pop();
    cout<<'\n';
}

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

int main() {
  string S,T;
  int A,B;
  string U;
  cin >> S >> T >> A >> B >> U;
  
  if (S == U){
    cout << A-1 << ' ' << B << endl;
  }
  else {
    cout << A << ' ' << B-1 << endl;
  }
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
int f[502][502];
int main()
{
	int n,m,p,i,j,x,y,ans;
	//freopen("express.in","r",stdin);
	//freopen("express.out","w",stdout);
	scanf("%d%d%d",&n,&m,&p);
	for(i=1;i<=m;i++)
	{
	   scanf("%d%d",&x,&y);
	   for(j=y;j<=n;j++)f[x][j]++;
	}
	for(i=1;i<=p;i++)
	{
		ans=0;
		scanf("%d%d",&x,&y);
		for(j=x;j<=y;j++)
		 ans+=f[j][y];
		printf("%d\n",ans);
	}
	return 0;
}/*
10 3 2
1 5
2 8
7 10
1 10
2 10
*/

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<< endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, K);
  double ans = 0;
  rep(i, 0, N) {
    int cnt = 0;
    ll p = i + 1;
    while (p < K) {
      p *= 2;
      cnt++;
    }
    ans += 1/pow(2, cnt);
  }
  printf("%.12f", ans / (double)N);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;

using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;


const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int n;
  cin >> n;
  v d1(n, 0);
  v d2(n, 0);
  rep(i, n) {
    cin >> d1[i] >> d2[i];
  }
  rep(i, n - 2) {
    if (d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<cstring>
#include<set>
using namespace std;
const int N = 2e5;
vector<int> adj1[N+1];
vector<int> adj2[N+1];
int color[N+1];
void dfs1(int u, int c)
{
    color[u] = c;
    for(const int& v : adj1[u])
        if(color[v]==-1)
            dfs1(v,c);
}
int ans[N+1];
bool vis[N+1];
set<int> has_answer;
vector<int> cc[N+1];
void dfs2(int u)
{
    vis[u] = true;
    has_answer.insert(color[u]);
    cc[color[u]].push_back(u);

    for(const int& v : adj2[u])
        if(!vis[v])
            dfs2(v);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k, l; cin >> n >> k >> l;
    for(int i = 0; i < k; i++)
    {
        int u, v; cin >> u >> v;
        adj1[u].push_back(v);
        adj1[v].push_back(u);
    }
    for(int i = 0; i < l; i++)
    {
        int u, v; cin >> u >> v;
        adj2[u].push_back(v);
        adj2[v].push_back(u);
    }
    memset(color,-1,sizeof color);
    int sz = 0;
    for(int u = 1; u <= n; u++)
        if(color[u]==-1)
            dfs1(u,++sz);

    memset(vis,false,sizeof vis);
    for(int u = 1; u <= n; u++)
        if(!vis[u])
        {
            dfs2(u);
            for(const int& c : has_answer)
            {
                for(const int& v : cc[c])
                    ans[v] = cc[c].size();
                vector<int>().swap(cc[c]);
            }
            set<int>().swap(has_answer);
        }
    for(int u = 1; u <= n; u++)
        cout<<ans[u]<<" ";
    cout<<endl;

    cout<<flush;
    return 0;
}

Measured memory_bytes: 28820
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;



int main(){

  int n; cin >> n;
  vector<int> a(n+1),b(n+1),c(n+1);

  for (int i=1; i<=n; i++){ cin >> a[i]; }
  for (int i=1; i<=n; i++){ cin >> b[i]; }
  for (int i=1; i<=n-1; i++){ cin >> c[i]; }

  int ans = 0;

  for (int i=1; i<=n; i++){ ans += b[i]; }

  for (int i=2; i<=n; i++){
    if (a[i]-a[i-1]==1) { ans += c[a[i-1]]; }
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}


immutable real EPS = 1e-8;

struct Point {
    real x, y;
    Point opBinary(string op)(in Point p) const if (op == "+" || op == "-") {
        return Point(mixin("x" ~ op ~ "p.x"), mixin("y" ~ op ~ "p.y"));
    }
    Point opBinary(string op)(real k) const if (op == "*" || op == "/") {
        return Point(mixin("x" ~ op ~ "k"), mixin("y" ~ op ~ "k"));
    }
};
real dot(in Point a, in Point b) { return a.x * b.x + a.y * b.y; }
real cross(in Point a, in Point b) { return a.x * b.y - a.y * b.x; }
real norm(in Point a) { return sqrt(dot(a, a)); }
Point rot90(in Point p) { return Point(-p.y, p.x); }
real angle(in Point a) { return atan2(a.y, a.x); }

const int CW = -1;
const int CCW = 1;
int ccw(Point a, Point b, Point c){
    b = b - a; c = c - a;                                          
    if (cross(b, c) > EPS) return +1;      // a,b,c????????????????¨???¨???
    if (cross(b, c) < -EPS) return -1;     // a,b,c?????????????¨???¨???                       
    if (dot(b, c) < 0) return +2;          // c--a--b ??´???                       
    if (norm(b) < norm(c)) return -2;      // a--b--c ??´???                       
    return 0;                              // a--c--b ??´???
}

struct Segment {
    Point a, b;
};
bool contains(in Segment s, in Point p) {
    return ccw(s.a, s.b, p) == 0;
}
bool intersects(in Segment s, in Segment t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

struct Polygon {
    Point[] vs;
}
bool contains(in Polygon polygon, in Point p) { // ?????????p???????????´????????????
    auto vs = polygon.vs;
    int N = cast(int)vs.length;
    int next(int i) { return (i + 1) % N; }
    int count = 0;
    foreach (int i; 0 .. N) {
        auto a = vs[i] - p;
        auto b = vs[next(i)] - p;
        if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return true; // ?????????p
        if (a.y > b.y) swap(a, b);
        if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) {
            count++;
        }
    }
    return count % 2 == 1;
}

void main() {
    int N; readf("%d\n", &N);
    auto vs = new Point[N];
    foreach (ref v; vs) {
        readf("%s %s\n", &v.x, &v.y);
    }
    int Q; readf("%d\n", &Q);
    auto poly = Polygon(vs);
    foreach (q; 0 .. Q) {
        Point p; readf("%s %s\n", &p.x, &p.y);
        int f() {
            foreach (i, v; vs) {
                if (Segment(v, vs[(i + 1) % N]).contains(p)) return 1;
            }
            if (poly.contains(p)) {
                return 2;
            }
            return 0;
        }
        writeln(f());
    }
}

Measured memory_bytes: 2520
#include<stdio.h>

int main()
{
  int d[6];
  int test[6];
  int n;
  int up, s;
  int temp;
  int m;
  for(int i = 0; i < 6; i++)
    {
      scanf("%d", &d[i]);
      test[i] = d[i];
    }
  scanf("%d", &n);

  for(int i = 0; i < n; i++)
    {
      for(int k = 0; k < 6; k++)
	{
	  test[k] = d[k];
	}
      scanf("%d%d", &up, &s);
      while(1)
	{
	  for(int j = 0; j < 6; j++)
	    {
	      if(test[j] == s)
		{
		  m = j;
		  break;
		}
	    }
	  if(test[1] == s)
	    {
	      break;
	    }
	  temp = test[0];
	  if(m == 3)
	    {
	      test[0] = test[3];
	      test[3] = test[5];
	      test[5] = test[2];
	      test[2] = temp;
	    }
	  if(m == 2)
	    {
	      test[0] = test[2];
	      test[2] = test[5];
	      test[5] = test[3];
	      test[3] = temp;
	    }
	  if(m == 4 || m == 0)
	    {
	      test[0] = test[4];
	      test[4] = test[5];
	      test[5] = test[1];
	      test[1] = temp;
	    } 
	  if(m == 5)
	    {
	      test[0] = test[1];
	      test[1] = test[5];
	      test[5] = test[4];
	      test[4] = temp;
	    }
	}
      while(1)
	{
	  for(int j = 0; j < 6; j++)
	    {
	      if(test[j] == up)
		{
		  m = j;
		  break;
		}
	    }
	  if(test[0] == up)
	    {
	      break;
	    }
	  temp = test[0];
	  if(m == 3)
	    {
	      test[0] = test[3];
	      test[3] = test[5];
	      test[5] = test[2];
	      test[2] = temp;
	    }
	  if(m == 2)
	    {
	      test[0] = test[2];
	      test[2] = test[5];
	      test[5] = test[3];
	      test[3] = temp;
	    }
	  if(m == 5)
	    {
	      test[0] = test[5];
	      test[5] = temp;
	      temp = test[2];
	      test[2] = test[3];
	      test[3] = temp;
	    }
	}
      printf("%d\n", test[2]);
    }
}



Measured memory_bytes: 2060
import java.util.*;

public class Main {

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

		while(sc.hasNext()){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();

			for(int i=1;i<=n;i++){
				if(a<=c*i && b<=d*i){
					System.out.println(n-i);
					break;
				}
			}
			
		}
	}
}

Measured memory_bytes: 17168
N = int(input())

ans = 'No'
k = 2
while True:
    kk = k*(k-1)
    if kk > N*2:
        ans = 'No'
        break
    elif kk == N*2:
        ans = 'Yes'
        break
    k += 1

print(ans)
if ans == 'Yes':
    print(k)
    psum = (k-1)*k//2
    tops = []
    for i in range(k):
        ntop = psum - (k-1-i)*(k-i)//2 + 1
        tops.append(ntop)
    for i in range(k):
        print(k-1, end=" ")
        # 1st
        for j in range(i):
            print(tops[j]+(i-j-1), end=" ")
        # 2nd
        for j in range(k-1-i):
            print(tops[i]+j, end=" ")
        print('')


# 1 2 3 4
# 1 5 6 7
# 2 5 8 9


Measured memory_bytes: 4432
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
  int N, W;
  cin >> N >> W;
  vector <int> w(N);
  vector <int> v(N);  
  vector <vector<ll> > dp(N+1, vector<ll>(W+1, -1));
  
  for( int i=0;i<N;i++ )
    cin >> w[i] >> v[i];

  dp[0][0] = 0;
  for( int i=0;i<N;i++ )
    {
      for( int j=0;j<W+1;j++ )
	if(dp[i][j] >= 0)
	  {
	    if( j+w[i]<=W )
	      dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
	    dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
	  }
    }

  ll mv = 0;
  for( int i=0;i<W+1;i++ )
    {
      mv = max(mv, dp[N][i]);
    }
  cout << mv << endl;
}


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

int main()
{
  int ans=0;
  vector<int> A(3);
  cin >> A.at(0) >> A.at(1) >> A.at(2);
  sort(A.begin(), A.end());
  if((A.at(2)-A.at(0))%2==0 && (A.at(2)-A.at(1))%2==0){
    ans=(A.at(2)-A.at(0))/2+(A.at(2)-A.at(1))/2;
  }
  else if((A.at(2)-A.at(0))%2!=0 && (A.at(2)-A.at(1))%2!=0){
    ans=(A.at(2)-A.at(0))/2+(A.at(2)-A.at(1))/2+1;
  }
  else{
    ans=(A.at(2)-A.at(0))/2+(A.at(2)-A.at(1))/2+2;
  }
  cout << ans << endl;
}

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

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

int color[101];

int main()
{
	int ans = 0;
	int a, b, c;
	cin >> a >> b >> c;
	color[a] = 1; color[b] = 1; color[c] = 1;
	rep(i, 101)
	{
		ans += color[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left

class SegTree:
    def __init__(self, a):
        self.padding = -float('inf')
        self.n = len(a)
        self.N = 2 ** (self.n - 1).bit_length()
        self.data = [self.padding]*(self.N - 1) + a + [self.padding]*(self.N - self.n)
        for i in range(2 * self.N - 2, 0, -2):
            self.data[(i - 1) // 2] = max(self.data[i], self.data[i - 1])
    
    def __len__(self):
        return self.n
    
    def __getitem__(self, key):
        return self.data[self.N - 1 + key]

    def __setitem__(self, i, value):
        self._update(i, value)
    
    def _update(self, i, x):
        idx = self.N - 1 + i
        self.data[idx] = x
        while idx != 0:
            idx = (idx - 1) // 2
            self.data[idx] = max(self.data[2 * idx + 1], self.data[2 * idx + 2])
    
    def max(self, i, j):
        # [i, j)
        if i == j: #今回のみの措置
            return self.data[self.N - 1 + i]
        else:
            idx1 = self.N - 1 + i
            idx2 = self.N - 2 + j # 閉区間にする
            result = self.padding
            while idx1 + 1 < idx2:
                if idx1 % 2 == 0: # idx1が偶数
                    result = max(result, self.data[idx1])
                if idx2 % 2 == 1: # idx2が奇数
                    result = max(result, self.data[idx2])
                    idx2 -= 1
                
                idx1 //= 2
                idx2 = (idx2 - 1)//2
            
            if idx1 == idx2:
                result = max(result, self.data[idx1])
            else: # idx1 + 1 == idx2
                result = max(result, self.data[idx1], self.data[idx2])
            
            return result

n = int(input())
x_d = []
for _ in range(n):
    x_d.append(tuple(map(int, input().split())))
x_d.sort(key=lambda t: t[0])
x = [t[0] for t in x_d]
xplusd = [t[0] + t[1] for t in x_d]
shortright = [bisect_left(x, xpdi) for xpdi in xplusd]
right = SegTree([t for t in shortright])
for i in range(n - 1, -1, -1):
    right[i] = right.max(i, right[i])
dp = [None] * n
dp.append(1)
for i in range(n - 1, -1, -1):
    dp[i] = (dp[i + 1] + dp[right[i]]) % 998244353
print(dp[0])

Measured memory_bytes: 127656
line1 = input().split()
price_a = input().split()
price_b = input().split()
min_a = int(min(price_a))
min_b = int(min(price_b))
n = int(line1[2])
candidate = [min_a+min_b]
for i in range(n):
  discount_data = input().split()
  target_a = int(discount_data[0])
  target_b = int(discount_data[1])
  discount = int(discount_data[2])
  total = int(price_a[target_a -1]) + int(price_b[target_b -1]) -discount
  candidate.append(total)
print(min(candidate))

Measured memory_bytes: 20888
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int M=1e5+5;
long long s=0;
int main() {
	int n;
	cin >> n;
	int a[M] ,b[M];
	for(int i=0;i<=n;i++) {
		scanf("%d",&a[i]) ;
	}
	for(int i=0;i<n;i++) {
		scanf("%d",&b[i]);
 	}
 	int t;
 	for(int i=0;i<n;i++){
 		if(b[i]>a[i]) {
 			s+=a[i];
 			b[i]-=a[i];	
 			t=min(b[i],a[i+1]) ;
 			a[i+1]-=t;
 			s+=t;
		}
		else {
			s+=b[i] ;
		}
	}
	cout <<s<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;


string s, ans;
int k;

int main(void) {
    cin >> k >> s;
    int n = sz(s);
    if (n<=k) {
        cout << s << "\n";
    } else {
        rep(i, 0, k) {

                ans += s[i];
            
        }
        ans += "...";
        cout << ans << "\n";

    }
    

	return 0;
}


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

const int64_t MOD = 1e+09;

int main() {
    int64_t A;
    long double B;
    
    cin >> A >> B;
    
    int64_t C = A * B;
    
    cout << C << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3728
package main

import (
    "fmt"
)

func main() {

  var a, b, c, x int

  fmt.Scanln(&a)
  fmt.Scanln(&b)
  fmt.Scanln(&c)
  fmt.Scanln(&x)

  var ans int
  for i := 0; i <= a; i++ {
    for j := 0; j <= b; j++ {
      for k := 0; k <= c; k++ {
        if (500*i + 100*j + 50*k) == x {
          ans += 1
        }
      }
    }
  }
  
  fmt.Print(ans)

}

Measured memory_bytes: 512
A,B = map(int, input().split())


if A == B:
    print(B)
    exit()
elif B - A == 1:
    print(A ^ B)
    exit()

"""
1 xor 1 = 0
0 xor AAA = AAA
(2*n) xor ((2*n)+1) = 1

とか。

"""
if A % 2 == 0:
    if B % 2 == 1:
        cnt_1 = (B - A + 1) // 2
        if cnt_1 % 2 == 0:
            ans = 0
        else:
            ans = 1
    else:
        cnt_1 = (B-1 - A + 1) // 2
        if cnt_1 % 2 == 0:
            ans = B
        else:
            ans = 1 ^ B
else:
    if B % 2 == 1:
        cnt_1 = (B - (A+1) + 1) // 2
        if cnt_1 % 2 == 0:
            ans = A
        else:
            ans = 1 ^ A
    else:
        cnt_1 = (B-1 - (A+1) + 1) // 2
        if cnt_1 % 2 == 0:
            ans = A ^ B
        else:
            ans = A ^ 1 ^ B
print(ans)

Measured memory_bytes: 3064
board = []

def detect():
    if sum([board[0], board[4], board[8]]) == 0:
        return True

    if sum([board[2], board[4], board[6]]) == 0:
        return True

    for i in range(3):
        if sum([board[i], board[i + 3], board[i + 6]]) == 0:
            return True

    for i in range(0, 3 * 3, 3):
        if sum([board[i], board[i + 1], board[i + 2]]) == 0:
            return True

    return False


for i in range(3):
    row = [int(v) for v in input().rstrip().split()]
    board.extend(row)


N = int(input().rstrip())
for i in range(N):
    b = int(input().rstrip())
    try:
        j =  board.index(b)
        board[j] = 0
    except ValueError:
        pass

r = 'Yes' if detect() else 'No'
print(r)



Measured memory_bytes: 9224
#include<iostream>
using namespace std;
int main(){
int a[10001],b[10001],sum=0;
int n,z;
cin>>n;
for(int i=0;i<n;i++){
    cin>>z;
   a[i]=z;
}
int m,x;
cin>>m;
for(int j=0;j<m;j++){
    cin>>x;
   b[j]=x;
}
for(int i=0;i<m;i++){
    for(int j=0;j<n;j++ ){
        if(a[j]==b[i]){
            sum++;
            break;
        }
        
    }
}

cout<<sum<<endl;


return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    string S;
    cin >> S;

    string ans;
    if (S == "ABC")
    {
        ans = "ARC";
    }
    else
    {
        ans = "ABC";
    }

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

Measured memory_bytes: 3600
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
	int N, i, sum = 0, count = 0, ans = 0;
	scanf("%d", &N);
	for (i = N; i >= 1; i--) {
		count = i;
		while (count != 0) {
			count = count / 10;
			sum++;
		}
		if (sum % 2 != 0) {
			sum = 0;
			ans++;
		}
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ALL(a) a.begin(),a.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 1010
using namespace std;

int mp[MAX][MAX],dp[MAX][MAX];

void solve(){
 int h,w,n;
 for(;;){
  cin>>h>>w>>n;
  if(!h&&!w&&!n) break;
  FOR(i,h) FOR(j,w) cin>>mp[i][j];
  ZERO(dp);
  dp[0][0]=n-1;
  FOR(i,h){
   FOR(j,w){
    if(i+1!=h) dp[i+1][j]+=(dp[i][j]+(mp[i][j]^1))>>1;
    if(j+1!=w) dp[i][j+1]+=(dp[i][j]+mp[i][j])>>1;
   }
  }
  FOR(i,h) FOR(j,w) if(dp[i][j]&1) mp[i][j]^=1;
  int x=0,y=0;
  while(x<h&&y<w){
   if(mp[x][y]) y++;
   else x++;
  }
  x++; y++;
  cout<<x<<" "<<y<<endl;
 }
}

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

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define pi pair<int, int>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = a; i >= n; i--)
#define REP(i, a, n) for(int i = a; i < n; i++)
#define Y "YES"
#define N "NO"
using namespace std;

string n;

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

	cin >> n;
	int l = n.length();
	if (n[l-1] == 's') cout << n << "es";
	else cout << n << 's';
}

Measured memory_bytes: 3608
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>


using namespace std;

using ll = long long int;
using lln = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()
const long MOD = pow(10, 9) + 7;

char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

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

unsigned GetDigit(double num) {
	return log10(num) + 1;
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

class Mod {
public:
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}

	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};



template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

int parmitation(ll N) {
	ll ans = 1;
	for (ll i = 1; i <= N; i++) {
		ans *= i;
	}

	return ans;
}

inline void Main() {
	ll X, Y, N;
	vector<ll> A;
	ll M1 = 1, D1=0, M2=1, D2=0;
	ll ans;
	ll sum = 0, count = 0, a = 0;
	string S;
	string T;
	string Ans = "";
	bool b[8];
	bool flag = false;

	

	cin >> N;


	for (ll j = 0; j < 8; j++) {
		b[j] = true;
	}
	for (ll i = 0; i < N; i++) {
		cin >> X;
		count = 0;
		b[X - 1] = false;
		for (ll j = 1; j <= N;j++) {
			if (b[j-1] &&  j > X) {
				count++;
			}
		}
		M1 += count* parmitation(N-i-1);
	}

	for (ll j = 0; j < 8; j++) {
		b[j] = true;
	}

	for (ll i = 0; i < N; i++) {
		cin >> Y;
		count = 0;
		b[Y - 1] = false;
		for (ll j = 1; j <= N; j++) {
			if (b[j - 1] && j > Y) {
				count++;
			}
		}
		M2 += count * parmitation(N - i-1);
	}

	cout << abs(M1 - M2);
}



Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	static final boolean debugMode = false;

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

		long n = sc.nextLong();
		long k = sc.nextLong();
		n = n - k * (n / k);

		System.out.println(Math.min(n, k - n));

	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

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

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	string p,q="";
	cin>>p;
	for(int i=0;i<(int)p.length();++i){
		if(p[i]=='0') q+="0";
		else if(p[i]=='1') q+="1";
		else {
			if(q.size()) q.pop_back();
		}
	}
	cout<<q<<"\n";
	return 0;
}


Measured memory_bytes: 3576
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	n, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	var n, a, b int

	n = nextInt()
	a = nextInt()
	b = nextInt()
	
	if n * a < b {
		fmt.Println(n * a)
	} else {
		fmt.Println(b)
	}
	
}

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

#define mp              make_pair
#define pb              push_back
#define ff              first
#define ss              second
#define inc(A,B)        A=(A+(B))%MOD
#define mul(A,B)        (ll(A)*ll(B)%ll(MOD))
#define sub(a,b)        (((a)-(b)+MOD)%MOD)

typedef long long ll;
typedef pair < ll ,int > pli;
typedef pair < int ,int > pii;
typedef complex < ll > pt;

const int MAX_N = 500;
const int MOD = 1e9 + 7;

int n, c;
int col[MAX_N][MAX_N];
int mat[MAX_N][MAX_N];
int cost[3][MAX_N];
vector <pii> groups[3];

void floydWarshall () {
  for ( int k = 0; k < c; ++k )
    for ( int i = 0; i < c; ++i )
      for ( int h = 0; h < c; ++h )
        col[i][h] = min ( col[i][h], col[i][k] + col[k][h] );
}

void divide () {
  for ( int i = 0; i < n; ++i )
    for ( int h = 0; h < n; ++h )
      groups[(i+h+2)%3].pb ( mp ( i, h ) );
}

void doCostFor ( int ind ) {
  for ( pii &it : groups[ind] )
    for ( int i = 0; i < c; ++i )
      cost[ind][i] += col[mat[it.ff][it.ss]][i];
}

int genRes () {
  int res = INT_MAX;
  for ( int i = 0; i < c; ++i ){
    for ( int h = 0; h < c; ++h ) {
      if ( h == i ) continue;
      for ( int j = 0; j < c; ++j ) {
        if ( j == h or j == i ) continue;
        res = min ( res, cost[0][i]+cost[1][h]+cost[2][j] );
      }
    }
  }
  return res;
}

int main() {

//  freopen ( "in.txt" , "r" , stdin );
//  freopen ( "out.txt" , "w" , stdout );

  scanf ( "%d%d", &n, &c );
  for ( int i = 0; i < c; ++i )
    for ( int h = 0; h < c; ++h )
      scanf ( "%d", &col[i][h] );

  for ( int i = 0; i < n; ++i ) {
    for ( int h = 0; h < n; ++h ) {
      scanf ( "%d", &mat[i][h] );
      --mat[i][h];
    }
  }

  for ( int i = 0; i < c; ++i )
    col[i][i] = 0;

//  floydWarshall ();
  divide ();
  for ( int i = 0; i < 3; ++i )
    doCostFor ( i );

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


  return 0;

}


Measured memory_bytes: 3632
#include<stdio.h>

int main(){
	int a;
	
	scanf("%d",&a);
	if(a==19 or a==29 or a==39 or a==49 or a==59 or a==69 or a==79 or a==89 or a==90 
	or a==91 or a==92 or a==93 or a==94 or a==95 or a==96 or a==97 or a==98 or a==99){
		printf("Yes");
	}
	else{
		printf("No");
	}
}


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

int main(){
    int n;
    cin >> n;
    int n_real = n;
    int sum=0;
    while(n>0){
        sum += n % 10;
        n /= 10;
    }
    if(n_real % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int n, m, k;
int d[108000];
int rev[108000];
int v[108][108];
vector<int> edge[108000];
int dist[108000];
int main(){
	fill(dist, dist + 108000, -1);
	cin >> n >> m >> k;
	for(int i = 0;i < n;i++)rev[i] = -1;
	for(int i = 0;i < m;i++){
		cin >> d[i];d[i]--;
		rev[d[i]] = i;
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < k;j++){
			cin >> v[i][j];v[i][j]--;
		}
	}
	for(int i = 0;i < (1<<m);i++){
		for(int l = 0;l < k;l++){
			int to = 0;
			for(int j = 0;j < m;j++){
				if((i >> j) % 2 == 0)continue;
				if(rev[v[d[j]][l]]== -1)continue;
				to |= 1 << rev[v[d[j]][l]];
			}
			edge[i].push_back(to);
		}
	}

	queue<int> q;
	q.push((1<<m)-1);
	dist[(1 << m)-1] = 0;
	while(!q.empty()){
		int now = q.front();q.pop();
		for(int i = 0;i < edge[now].size();i++){
			int to = edge[now][i];
			if(dist[to] != -1)continue;
			dist[to] = dist[now] + 1;
			q.push(to);
		}
	}

	cout << dist[0] << endl;
	return 0;
}

Measured memory_bytes: 39964
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {//xの親を求める
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {//xとyが連結しているか判定
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {//xとyを連結
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {//xを含む木のサイズを求める
        return -par[root(x)];
    }
};

int main() {
    int N;
    cin>>N;
    UnionFind uf(N);
    vector<P> points(N);
    vector<P> X(N),Y(N);
    rep(i,N){
        cin>>points.at(i).first>>points.at(i).second;
        X.at(i).first=points.at(i).first;
        X.at(i).second=i;
        Y.at(i).first=points.at(i).second;
        Y.at(i).second=i;
    }
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    rep(i,N-1){
        if(X.at(i).first==X.at(i+1).first){
            uf.merge(X.at(i).second,X.at(i+1).second);
        }
    }
    rep(i,N-1){
        if(Y.at(i).first==Y.at(i+1).first){
            uf.merge(Y.at(i).second,Y.at(i+1).second);
        }
    }
    vector<set<int>> x(N),y(N);
    rep(i,N){
        int p=uf.root(i);
        x.at(p).insert(points.at(i).first);
        y.at(p).insert(points.at(i).second);
    }
    ll ans=-N;
    rep(i,N){
        ll now=x.at(i).size()*y.at(i).size();
        ans+=now;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 20152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

class unionfind {
    VI par, rank;
    int forest_num;
public:
    unionfind(int n) : par(n), rank(n, 1) {
        forest_num = n;
        for (int i = 0; i < n; i++)par[i] = i;
    }
    void init(int n) {
        par.clear(); par.resize(n);
        rank.clear(); rank.resize(n, 1);
        forest_num = n;
        for (int i = 0; i < n; i++)par[i] = i;
    }
    int root(int x) {
        if (par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    int size(int x) {
        if (par[x] == x)return rank[x];
        return size(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
            rank[ry] += rank[rx];
        }
        else {
            par[ry] = rx;
            rank[rx] += rank[ry];
        }
        forest_num--;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int fnum() {
        return forest_num;
    }
};

int main() {
    init();

    int n, m; cin >> n >> m;
    unionfind uf(n + m);
    FOR(i, 0, n) {
        int k; cin >> k;
        FOR(j, 0, k) {
            int l; cin >> l;
            --l;
            uf.unite(i, n + l);
        }
    }

    bool ok = true;
    FOR(i, 0, n - 1)ok &= uf.same(i, i + 1);

    cout << (ok ? "YES\n" : "NO\n");
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c,d,e,f,g;cin>>a>>b>>c;
  d=max({a,b,c});
    e=min({a,b,c});
  f=a+b+c-d-e;
  if(a%2==0||b%2==0||c%2==0)cout<<0;
  else cout<<e*f;
}


Measured memory_bytes: 256
def selectionSort(arr)
  n = 0
  for i in 0..(arr.size - 1)
    min_i = i
    for j in i..(arr.size - 1)
      if arr[j] < arr[min_i]
        min_i = j
      end
    end
    if i != min_i
      x = arr[min_i]
      arr[min_i] = arr[i]
      arr[i] = x
      n = n + 1
    end
  end
  puts arr.join(' ')
  puts n
end

n= STDIN.gets.to_i
arr = STDIN.gets.split(' ').map{|x| x.to_i}
selectionSort(arr)

Measured memory_bytes: 8652
def inpl(): return [int(i) for i in input().split()]
def minich(A, plus):
    ans = 0
    back = 0
    for i in A:
        if plus:
            if back + i < 0:
                back = back + i
            else:
                ans += back + i + 1
                back = -1
        else:
            if back + i > 0:
                back = back + i
            else:
                ans += 1 - back - i
                back = 1
        plus = not plus
    return ans
N = int(input())
A = inpl()
print(min(minich(A, True), minich(A, False)))

Measured memory_bytes: 14212
n = int(input())
A = [int(input()) for i in range(n)]

def getG(n):
    gn = 1
    G = [1]
    while 3*gn + 1 < n:
        gn = G[-1]*3 + 1
        G.append(gn)
    return G[::-1]

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
            A[j+g] = v
    return A, cnt

def shellSort(A, n):
    G = getG(n)
    m = len(G)
    cnt = 0
    for i in range(m):
        A, cnt_l = insertionSort(A, n, G[i], cnt)
        cnt = cnt_l
    return A, m, G, cnt

A, m, G, cnt = shellSort(A, n)
print(m)
print(" ".join([str(s) for s in G]))
print(cnt)
for a in A:
    print(a)


Measured memory_bytes: 45524
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#define int long long
using namespace std;

struct UF {
	int par[100000];
	UF() { for (int i = 0; i < 100000; i++) par[i] = i; }
	int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); }
	void unit(int x, int y) { x = root(x); y = root(y); par[x] = y; }
	bool isSame(int x, int y) { return root(x) == root(y); }
}uf;

int n, m;
int a[100000];
vector<int> costs[100000];

signed main() {
	int i;
	
	cin >> n >> m;
	int k = n - m;
	if (k == 1) { cout << 0 << endl; return 0; }
	if (2 * k - 2 > n) { cout << "Impossible" << endl; return 0; }
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		uf.unit(x, y);
	}
	
	for (i = 0; i < n; i++) {
		costs[uf.root(i)].push_back(a[i]);
	}
	for (i = 0; i < n; i++) sort(costs[i].begin(), costs[i].end());
	
	int ans = 0;
	priority_queue<int, vector<int>, greater<int> > que;
	for (i = 0; i < n; i++) {
		if (costs[i].size() == 0) continue;
		ans += costs[i][0];
		for (int j = 1; j < costs[i].size(); j++) {
			que.push(costs[i][j]);
		}
	}
	
	for (i = 0; i < k - 2; i++) {
		ans += que.top(); que.pop();
	}
	cout << ans << endl;
	return 0;
}

//結んだ頂点を黒く塗ってみると…？
//連結成分数K = N - Mのとき、「2K - 2個黒くぬる. 各成分1個以上ぬる」が満たされる塗り方は全て「ありえる」。（2K - 2 > Nのときは解なし)
//スコアは, 黒く塗った頂点のコスト和になるので、各連結成分で最小コストの頂点を黒く塗ったあと、最小コストの頂点から優先して塗ればよい。
//これはヒープなどを用いるとO(NlogN)で実現できる。
//-> K = 1のケース（最初から連結なケース）に注意。この場合に限り「各成分1個以上塗る」が満たされなくても「ＯＫ」。K=1の場合は0を出力しよう。
//
//問題概要の図を分かりやすく書く（結んだ頂点を黒く塗るなどする）と吉。
//一つの連結成分を「大きな頂点」と見るのもポイントですね。

Measured memory_bytes: 6904
from collections import deque
q = deque([0])
Dequeue = lambda: q.popleft()
Enqueue = lambda x: q.append(x)

n, m = map(int, input().split())
g = [[] for _ in [0]*n]

for _ in [0]*m:
    a, b = map(int, input().split())
    a -= 1;b -= 1
    g[a] += [b]
    g[b] += [a]

p = [0]*n
while q:
    v = Dequeue()
    for c in g[v]:
        if p[c] < 1:
            p[c] = v+1
            Enqueue(c)
if 0 in p:
    print("No")
else:
    print("Yes")
    for i in p[1:]:
        print(i)

Measured memory_bytes: 37608
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**20
eps = 10**-7

N,K = map(int,readline().split())

P = [tuple(map(int,readline().split())) for i in range(N)]

X = []
Y = []
for (xi,yi) in P:
    X.append(xi)
    Y.append(yi)
X.sort()
Y.sort()
from itertools import combinations

ans = INF
def count(xmin,xmax,ymin,ymax):
    ret = 0
    for (xi,yi) in P:
        if (xmin <= xi <= xmax) and (ymin <= yi <= ymax):
            ret += 1
    return ret

for (xmin,xmax) in combinations(X,2):
    for (ymin,ymax) in combinations(Y,2):
        if count(xmin,xmax,ymin,ymax) >= K:
            ans = min(ans,(xmax-xmin)*(ymax-ymin))
print(ans)



Measured memory_bytes: 75568