akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);++i)
const long long INF = 1LL<<60;
const long long mod=1e9+7;

int main(){
    int N,K;
    cin >> N >> K;
    int res = 1;
    REP(i,N){
        int a = res * 2;
        int b = res + K;
        res = min(a,b);
    }
    cout << res << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
  int n, p, d1, d2, mp, md, i;

  while(scanf("%d", &n) && n){
    mp = md = 0;
    for(i = 0; i < n; ++i){
      scanf("%d%d%d", &p, &d1, &d2);
      if(md < d1 + d2){
        mp = p;
        md = d1 + d2;
      }
    }

    printf("%d %d\n", mp, md);
  }
  return 0;

}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,a,b,s,max,min;
	while(cin>>n>>a>>b)
	{
		if(b<a)
		{
			cout<<'0'<<endl; 
			continue;
		}
		if(b==a)
		{
			cout<<'1'<<endl; 
			continue;
		}
		if(n==1&&a!=b)
		{
			cout<<'0'<<endl; 
			continue;
		}
		else{
			max=a+b+(n-2)*b;
			min=a+b+(n-2)*a;
			s=max-min+1;
			cout<<s<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
// Problem : C - Vacation
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector< vi >
#define vpii vector< pii >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
void printv(vector<int>  v){ for(int i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;   }
int bem(int m , int n, int mod) { int res=1; while(n){
	     			        if(n%2!=0) { res*=m; res%=mod; }
	    			        m*=m;   m%=mod;   n/=2;
			                          }
				return res;	}
int be(int a, int b) { int res=1; 	while(b){
				if(b%2!=0) res*=a;
				a*=a; b/=2;
				}
			return res;	}
void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}
struct tr{
	int a, b, c;
};
/*void solve()
  {
int n; cin>>n;
vector< tr > v(n);
f(i, 0, n-1) { int x, y, z; cin>>x>>y>>z; v[i]={x, y, z};}
vector< vector< int > >dp(n, vi (3));
dp[0][0]=v[0].a;
dp[0][1]=v[0].b;
dp[0][2]=v[0].c;
for( int i=1; i<=n-1; i++)
{
	for( int j=0; j<=2; j++)
	{
		if(j==0)
		dp[i][j]=max(dp[i-1][1], dp[i-1][2])+v[i].a;
		if(j==1)
		dp[i][j]=max(dp[i-1][0], dp[i-1][2])+v[i].b;
		if(j==2)
		dp[i][j]=max(dp[i-1][1], dp[i-1][0])+v[i].c;		
		
	}
}
cout<<*max_element(dp[n-1].begin(), dp[n-1].end())<<endl;
  }*/
  
 
 
 vvi v, dp;
 int fun( int a, int b)
 {
 	if(dp[a][b]!=-1) return dp[a][b];
 	if(a==0) return dp[a][b]=v[a][b];
 	else 
 	{
 		if(b==0) dp[a][b]=max(fun(a-1, 1), fun(a-1, 2))+v[a][b];
 		else if(b==1) dp[a][b]=max(fun(a-1, 0), fun(a-1, 2))+v[a][b];
 		else if(b==2) dp[a][b]=max(fun(a-1, 1), fun(a-1, 0))+v[a][b];
 		return dp[a][b];
 	}
 }
 
 
 
void solve()
{
	int n; cin>>n;
	v.resize(n, vi(3));
	f(i, 0, n-1){ int x,y,z; cin>>x>>y>>z; v[i]={x,y,z}; }
	dp.resize(n, vi(3, -1));
	// for(auto x:v) cout<<x[0]<<' '<<x[1]<<' '<<x[2]<<endl;
	// for(auto x:dp) cout<<x[0]<<' '<<x[1]<<' '<<x[2]<<endl;
	cout<<max(fun(n-1, 0), max(fun(n-1, 1), fun(n-1, 2)));	
	
	
} 
  
  
  
  
  
  
  
  
  

int32_t main ()
{
//fio
int t=1; 
//cin>>t; 
while(t--){
	solve();
}
 
}








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

using namespace std;

#define ok puts("ok");


const int N = (int)1e5 + 7;

int go[N], n, l;
int x[N];
int dp[20][N];

main() {
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", x + i);
    }
    scanf ("%d", &l);
    int cur = 1;

    for (int i = 1; i <= n; i++) {
        while (cur <= n && x[cur] - x[i] <= l) {
            cur++;
        }
        cur--;
        dp[0][i] = cur;
    }
    for (int i = 1; i <  17; i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }
    int q; scanf ("%d", &q);
    while (q--) {
        int a, b; scanf ("%d %d", &a, &b);
        int ans = 0;
        if (a > b) swap(a, b);
        int res = 0;
        for (int i = 16; i >= 0; i--) {
            if (dp[i][a] < b) {
                res += (1 << i);
                a = dp[i][a];
            }
        }
        printf ("%d\n", res + 1);
    }
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int h,w,n,m,x[100005],y[100005];
ll ans[10],sum;
map<pair<int,int>,int > mp;
map<pair<int,int>,int >vis;
void solve(int x,int y){
	if(vis[{x,y}]) return ;
	vis[{x,y}]++;
	if(x+2>h) return ;
	if(y+2>w) return ;
	if(x<1) return ;
	if(y<1) return ;
	int cnt=0;
	for(int i=x;i<=x+2;i++)
		for(int j=y;j<=y+2;j++)
			if(mp[{i,j}]) cnt++;
	ans[cnt]++;
}
int main(){
	int i,j,k;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);
	h=read(),w=read(),n=read();
	for(i=1;i<=n;i++) {
		x[i]=read(),y[i]=read();
		mp[{x[i],y[i]}]=1;
	}
	int cnt;
	for(i=1;i<=n;i++){
		solve(x[i],y[i]);
		solve(x[i],y[i]-1);
		solve(x[i],y[i]-2);
		solve(x[i]-1,y[i]);
		solve(x[i]-1,y[i]-1);
		solve(x[i]-1,y[i]-2);
		solve(x[i]-2,y[i]);
		solve(x[i]-2,y[i]-1);
		solve(x[i]-2,y[i]-2);
	}
	for(i=1;i<=9;i++) sum+=ans[i];
	sum=(h-2ll)*(w-2ll)-sum;
	printf("%lld\n",sum);
	for(i=1;i<=9;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 217012
import math
MOD = 1000000007
m,n=map(int,input().split())
f=abs(m-n)
if f == 0:
  ans=2*math.factorial(m)*math.factorial(n)%MOD
  print(ans)
  exit()
elif f == 1:
  ans=math.factorial(m)*math.factorial(n)%MOD
  print(ans)
  exit()
else:
  print(0)
  exit()


Measured memory_bytes: 5184
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

main = do
  n <- readLn :: IO Int
  a <- getIntListBC
  let ra = reverse a
      sumf = sum $ take n a
      suml = sum $ take n ra
      fHalf = foldl (flip push) Empty $ take n a
      lHalf = foldl (flip push) Empty $ map (negate) $ take n ra
      first = ((:)sumf) . solveMax fHalf sumf (fromJust $ pop fHalf) $ take n $ drop n a
      latter = ((:)suml) . solveMin lHalf suml (fromJust $ pop lHalf) $ take n $ drop n ra
      ans = zipWith (-) first $ reverse latter
  print $ maximum ans
  return ()

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine

solveMax :: SkewHeap Int -> Int -> Int -> [Int] -> [Int]
solveMax _    _   _ []     = []
solveMax heap sum m (a:as) =
  let heap' = if a > m
                then push a $ deleteMin heap
                else heap
      sum' = if a > m then sum + a - m
                      else sum
      m' = if a > m then fromJust $ pop heap'
                    else m
  in sum' : (solveMax heap' sum' m' as)

solveMin :: SkewHeap Int -> Int -> Int -> [Int] -> [Int]
solveMin _    _   _ []     = []
solveMin heap sum m (a:as) =
  let a' = negate a
      heap' = if a' > m
                then push a' $ deleteMin heap
                else heap
      sum' = if a' > m then sum + a - (negate m)
                       else sum
      m' = if a' > m then fromJust $ pop heap'
                     else m
  in sum' : (solveMin heap' sum' m' as)

data SkewHeap a = Empty | Node a (SkewHeap a) (SkewHeap a) deriving (Show, Read, Eq)

merge :: Ord a => SkewHeap a -> SkewHeap a -> SkewHeap a
merge Empty h = h
merge h Empty = h
merge h1@(Node x1 l1 r1) h2@(Node x2 l2 r2)
  | x1 <= x2  = Node x1 (merge h2 r1) l1
  | otherwise = Node x2 (merge h1 r2) l2


singleton :: Ord a => a -> SkewHeap a
singleton x = Node x Empty Empty

push :: Ord a => a -> SkewHeap a -> SkewHeap a
push x heap = merge (singleton x) heap

pop :: Ord a => SkewHeap a -> Maybe a
pop Empty = Nothing
pop (Node x l r) = Just x

deleteMin :: Ord a => SkewHeap a -> SkewHeap a
deleteMin Empty = Empty
deleteMin (Node _ l r) = merge l r


Measured memory_bytes: 129532
# input
N = int(input())
A = list(map(int, input().split()))

# process
result = True
for a in A:
    if a%2 == 0:
        if not (a%3 == 0 or a%5 == 0):
            result = False
            break

# output
print("APPROVED" if result else "DENIED")


Measured memory_bytes: 2940
# 1以上N以下の整数のうち、 1 <= N <= 10^4
# 10進法で各桁の和が
# A以上B以下であるものについて、 1 <= A <= B <= 36
# 総和を求めよ

# N, A, Bを取得
input = gets.chomp.split
n = input[0].to_i
a = input[1].to_i
b = input[2].to_i

# 扱いうる整数を配列に格納
nums_all = Array.new
n.times do |i|
  nums_all[i] = i + 1
end

# 条件を満たす整数を格納する配列を定義
nums = Array.new

# 条件を満たす整数を配列に格納
n.times do |i|
  
  # 各桁の和を代入する変数を定義
  digit_sum = 0
  
  # # 整数が1桁か2桁か、で条件分岐
  # if nums_all[i].to_s.length == 2
  #   digit_10 = nums_all[i].to_s
  #   digit_1 = nums_all[i].to_s
  #   digit_sum = digit_10[0].to_i + digit_1[1].to_i
  # else
  #   digit_sum = nums_all[i]
  # end

  nums_all[i].to_s.length.times do |j|
    digit_sum += nums_all[i].to_s[j].to_i
  end
  
  # 各桁の和が条件を満たすか判定
  if a <= digit_sum && digit_sum <= b
    nums << nums_all[i]
  end
end

# 条件を満たす整数の和を求める
sum = 0
nums.length.times do |i|
  sum += nums[i]
end

# 結果を出力
puts sum


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

typedef long long ll;

using namespace std;

const int N = 2e5 + 100;

 
int main()
{
//	freopen("input.txt", "r", stdin);
	//提交时注释，调试时取消注释！！！ 
	int n;
	int k;
	cin >> n >> k;
	for(int i = n - 1; i >= 1; i -- )
	{
		cout << k - i << " ";
	}
	cout << k << " ";
	for(int i = 1; i < n; i ++ )
	{
		cout << k + i << " ";
	}
	
		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define sqr(x) (x)*(x)
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,k,ans=0;
    cin>>n>>k;
    for(ll i=k;i<=(n+1);i++){
        ll lo=(i*(i-1))/2;
        ll hi=n*(n+1)/2;
        ll x=n-i;
        hi-=(x*(x+1))/2;
        hi=(hi-lo+1);
        hi%=mod;
        //cout<<i<<" "<<lo<<" "<<hi<<endl;
        ans=(ans+hi)%mod;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3668
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int ice[15]={0},X;
        while(N--){
            cin>>X;
            ice[X]++;
        }
        for(int i=0;i<10;i++){
            if(ice[i]==0)cout<<"-";
            else{
                while(ice[i]--){
                    cout<<"*";
                }
            }
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten52];
//priority_queue<ll> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,d,pre=0,now;
    string s;
    cin>>n;
    cin>>pre;
    for(i=1;i<n;i++)
    {
        cin>>now;
        if(pre>now)
            k+=pre-now;
        pre=max(pre,now);
    }
    cout<<k;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	int N,i;
	cin>>N>>i;
	
	cout<<N-i+1<<endl;
	
    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
sum_a = sum(a)
a.sort()
if sum_a%10:
    print(sum_a)
else:
    for i in a:
        if i%10:
            print(sum_a - i)
            break
    else:
        print(0)


Measured memory_bytes: 38748
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n, k;
  cin >> n >> k;
  vi h(n+10);
  rrep(i,n){
    cin >> h[i];
  }
  int dp[n+10];
  dp[1]=0;
  srep(i,2,n+1){
    int dis=1;
    dp[i] = INF;
    while(dis<=k && dis<i){
      dp[i] = min(dp[i], dp[i-dis]+abs(h[i]-h[i-dis]));
      dis++;
    }
  }
  cout << dp[n] << endl;
  return 0;
  
}

Measured memory_bytes: 1024
#include <cstdio>
int n, cnt1, cnt2, c[100005];
int main() {
	int i, t;
	scanf("%d", &n);
	while(n--) scanf("%d", &t), c[t]++;
	for(i=1; i<=100000; i++) {
		if(c[i]) {
			cnt1++;
			if(c[i]%2==0) cnt2++;
		}
	}
	if(cnt2%2==1) cnt1--;
	printf("%d", cnt1);
	return 0;
}


Measured memory_bytes: 512
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int h = sc.nextInt();
		int[][] data = new int[n][2];
		for (int i = 0; i < n; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}
		System.out.println(solve(h, data));
	}

	private static int solve(int h, int[][] data) {
		// TODO Auto-generated method stub
		List<int[]> l = new ArrayList<int[]>();
		for (int[] i : data)
			l.add(i);
		Collections.sort(l, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				// TODO Auto-generated method stub
				if (o1[0] != o2[0])
					return o2[0] - o1[0];
				return o1[1] - o2[1];
			}
		});
		int[] tmp = l.get(0);
		l.remove(0);
		Collections.sort(l, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				// TODO Auto-generated method stub
				return o2[1] - o1[1];
			}
		});
		int count = 0;
		for (int i = 0; i < l.size(); i++) {
			if (l.get(i)[1] >= tmp[0]) {
				h = h - l.get(i)[1];
				++count;
			} else {
				break;
			}
			if (h <= 0)
				return count;
		}
		if (tmp[1] < tmp[0])
			tmp[1] = tmp[0];
		++count;
		h = h - tmp[1];
		if (h <= 0)
			return count;

		count = count + h / tmp[0];
		if (h % tmp[0] != 0)
			count++;
		return count;

	}

}

Measured memory_bytes: 94348
from itertools import product


def solve(string):
    n, a, b, c, *l = map(int, string.split())
    ans = 3000
    for p in product(range(4), repeat=n):
        if not ({0, 1, 2} <= set(p)):
            continue
        sums = [0, 0, 0, 0]
        for _p, _l in zip(p, l):
            sums[_p] += _l
        mp12 = sum(abs(_s - _abc) for _s, _abc in zip(sums, [a, b, c]))
        mp3 = sum(1 for _p in p if _p < 3) - 3
        ans = min(ans, mp12 + mp3 * 10)
    return str(ans)


if __name__ == '__main__':
    n, a, b, c = map(int, input().split())
    print(solve('{} {} {} {}\n'.format(n, a, b, c) + '\n'.join([input() for _ in range(n)])))


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



int main(){
  int N; cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++) cin>>d.at(i);
  
  sort(d.begin(),d.end());
  
  int res=-d.at(N/2-1)+d.at(N/2);
  
  cout<<res;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>


int main(int argc, const char * argv[]) {
    double x1,x2,y1,y2,ans;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    ans = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    printf("%lf",ans);
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int N; cin >> N;
    vector<int> P(N); REP(i, N) cin >> P[i];
    vector<int> Q(N); REP(i, N) cin >> Q[i];

    int a = 0;
    int b = 0;
    int cnt = 0;

    vector<int> v(N);
    int num = 0;
    REP(i, N) {
        v[num] = num + 1;
        num++;
    }

    do{
        for(int i = 0; i < N; ++i){
            if(v == P) {
                a = cnt + 1;
            }

            if(v == Q) {
                b = cnt + 1;
            }
        }
        cnt++;
    } while(next_permutation(v.begin(), v.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
grid=[[0]*3 for i in range(3)]
for i in range(3):
    row=[int(k) for k in input().split()]
    for j in range(3):
        grid[i][j]=row[j]
sum1=grid[0][0]+grid[1][1]+grid[2][2]
sum2=grid[0][1]+grid[1][0]+grid[2][2]
sum3=grid[0][2]+grid[1][1]+grid[2][0]
sum4=grid[0][0]+grid[1][2]+grid[2][1]
if sum1==sum2 and sum2==sum3 and sum3==sum4:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,h,w,a[100010],b[100010];
    ll ans=0;
    cin>>n>>h>>w;
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,n){
        ans+=min(a[i]/h,b[i]/w);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200000
#define LL long long
int stk[MAXN+5];
int n,top;
LL a[MAXN+5],d[MAXN+5],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		while(a[stk[top]]>=a[i])top--;
		d[i]=stk[top];stk[++top]=i;
	}
	top=0,stk[0]=n+1;
	for(int i=n;i>=1;i--)
	{
		while(a[stk[top]]>=a[i])top--;
		ans+=a[i]*(i-d[i])*(stk[top]-i);stk[++top]=i;
	}
	printf("%lld",ans);//
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

vector<P> vs;
P solve(P p){
	printf("%lld:", p.fi);
	if(p.se < 10)printf("0%lld", p.se);
	else printf("%lld", p.se);
}

signed main(){
	int n, m;
	scanf("%lld", &n);
	rep(i,n){
		int x, y;
		scanf("%lld%lld", &x, &y);
		vs.pb(P(x, y));
	}
	scanf("%lld", &m);
	rep(i,m){
		int x, y;
		scanf("%lld%lld", &x, &y);
		vs.pb(P(x, y));
	}
	ZIP(vs);
		
	rep(i,vs.size()){
		solve(vs[i]);
		printf("%c", i == vs.size()-1 ? '\n' : ' ');
	}
	return 0;
}








Measured memory_bytes: 3236
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    string x,y;
    cin>>x>>y;
    pair<int,pair<int,int> > dp[x.size()+1][y.size()+1];
    memset(dp,0,sizeof dp);
    dp[0][0].second={-1,-1};
    for(int i=1;i<=x.size();i++){
        for(int j=1;j<=y.size();j++){
            if(x[i-1]==y[j-1]){
                dp[i][j].first=1+dp[i-1][j-1].first;
                dp[i][j].second.first=i-1;dp[i][j].second.second=j-1;
            }else{ dp[i][j].first=max(dp[i-1][j].first,dp[i][j-1].first);
            if(dp[i-1][j].first>dp[i][j-1].first)dp[i][j].second=dp[i-1][j].second;
            else  dp[i][j].second=dp[i][j-1].second;
            }
        }
    }
    int k=dp[x.size()][y.size()].first;
    pair<int,int>p=dp[x.size()][y.size()].second;
    string ans="";
    while(k--){
        ans+=x[p.first];
        p=dp[p.first][p.second].second;
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i];

    return 0;
}


Measured memory_bytes: 105856
#include <iostream>

int main(int argc, char const *argv[])
{
	int a, b, c;
	std::cin >> a >> b >> c;
	if ((a < b) && (b < c))
	{
		std::cout << "Yes\n";
	}else
	{
		std::cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3068
# A
N = int(input())
a_list = list(map(int, input().split()))
res = 0
cnt = 1
for i in range(1, N):
    if a_list[i] == a_list[i-1]:
        cnt += 1
    else:
        res += cnt // 2
        cnt = 1
res += cnt // 2
print(res)

Measured memory_bytes: 3060
// Sliding Minimum Elements

#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
 
const int inf = INT_MAX;
int* d;
int n = 1;
 
void initRMQ(int n) {
    for(int i=0; i<2*n-1; i++) d[i] = inf;
}
 
void update(int k, int a) {
    k += n-1;
    d[k] = a;
    while(k > 0) {
        k = (k-1)/2;
        d[k] = min(d[k*2+1], d[k*2+2]);
    }
}
 
int query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return d[k];
 
    return min(query(a,b,k*2+1,l,(l+r)/2), query(a,b,k*2+2,(l+r)/2,r));
}
 
int findMin(int a, int b) {
    return query(a, b+1, 0, 0, n);
}
 
int main() {
    int a, com, n_,l;
    cin >> n_ >> l;
    while(n < n_) n *= 2;
    d = new int[2*n-1];
    initRMQ(n);
 
    for(int i=0; i<n_; i++) {
        cin >> a;
        update(i,a);
    }
 
    cout << findMin(0,l-1);
    for(int i=1; i+l <= n_; i++) {
        cout << " " << findMin(i,i+l-1);
    }
    cout << endl;
    delete[] d;
    return 0;
}


Measured memory_bytes: 10996
N = int(input())
c = list(input())

ans = 0
w = 0
r = 0
j = N-1
for i in range(N):
    if c[i] == "W":
        while i < j:
            if c[j] == "R":
                ans += 1
                j -= 1
                break
            j -= 1
    if j - i == 1:
        break
print(ans)

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

using namespace std;

int calc(int a, int b, char c){

  if(c == '+') return a+b;
  if(c == '-') return a-b;
  if(c == '*') return a*b;
  if(c == '/') return a/b;

}

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

  char c;
  while(1){
    cin >> c;
    if(c == '=') break;
    int a;
    cin >> a;
    ans = calc(ans,a,c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int dp[5005];
vector<int>dp2;

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[3];
    int b[3];
    for(int i=0;i<3;i++)
        cin>>a[i];
    for(int i=0;i<3;i++)
        cin>>b[i];
    for(int i=n;i>=0;i--)
    {
        for(int j=0;j<3;j++)
        {
            if(i-a[j]>=0)
                dp[i-a[j]]=max(dp[i-a[j]],dp[i]+(b[j]-a[j]));
        }
    }
    int mx=0;
    for(int i=0;i<=n;i++)
    {
        mx=max(mx,n+dp[i]);
    }
    n=mx;
    dp2.assign(n+5,0);
    for(int i=n;i>=0;i--)
    {
        for(int j=0;j<3;j++)
        {
            if(i-b[j]>=0)
                dp2[i-b[j]]=max(dp2[i-b[j]],dp2[i]+(a[j]-b[j]));
        }
    }
    mx=0;
    for(int i=0;i<=n;i++)
    {
        mx=max(mx,n+dp2[i]);
    }
    cout<<mx;

 
} 



Measured memory_bytes: 195584
nu = gets.to_i
ar = Array.new(500, 0)
for i in 0..499
  ar[i] = (i + 1)*(i + 2)
end
count = 0
for i in 0..499
  if nu*2 == ar[i]
    count = i + 2
    break
  end
  if i == 499
    puts "No"
    exit
  end
end

puts "Yes"
puts count
count2 = 0
array = Array.new(count - 1).map{Array.new(count - 1, 0)}
for i in 0..count - 2
  for j in 0..i
    count2 += 1
    array[i][j] = count2
  end
end
for i in 0..count - 2
  print "#{count - 1}"
  check1 = 0
  check2 = 0
  for j in 0..count - 2
    print " #{array[i + check2][check1]}"
    if check1 < i
      check1 += 1
    else
      check2 += 1
    end
  end
  puts ""
end
print "#{count - 1}"
for i in 0..count - 2
  print " #{array[i][i]}"
end


Measured memory_bytes: 4476
import java.util.Scanner;
public class Main{
	int [] data =new int[3];
	int hozon;
	
	public void Input(){
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<data.length;i++){
			data[i]= sc.nextInt();
		}
	}
	
	public void Output(){
		for(int n =0;n<data.length;n++){
			System.out.print(data[n]);
			if(n!=data.length-1){
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	
	public void SortA(){
		for(int j=data.length-1;j>=1;j--){
			for(int k=0;k<j;k++){
				if(data[k]>data[k+1]){
					hozon=data[k+1];
					data[k+1]=data[k];
					data[k]=hozon;
				}
			}
		}
	}
					
	public static void main(String[] args){
		Main obj = new Main();
		obj.Input();
		obj.SortA();
		obj.Output();
	}
}

Measured memory_bytes: 26320
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;
using std::complex;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

namespace MySpace{
    struct Small_Segment_Tree{
        vector<int> a;
        int l, r;

        private:
        int __summ(int L, int R, int l, int r, int v)
        {
            if (L <= l && r <= R)
                return a[v];
            if (R <= l || r <= L)
                return 0;
            int m = (l + r) / 2;
            return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);
        }

        void __set(int P, int l, int r, int v, int V)
        {
            if (l + 1 == r)
            {
                a[v] = V;
                return;
            }
            int m = (l + r) / 2;
            if (P < m)
            {
                __set(P, l, m, 2 * v + 1, V);
                a[v] = a[2 * v + 1] + a[2 * v + 2];
            }
            else
            {
                __set(P, m, r, 2 * v + 2, V);
                a[v] = a[2 * v + 1] + a[2 * v + 2];
            }
        }

        public:
        int Summ(int L, int R)
        {
            if (R < L)
                return 0;
            return __summ(L, R + 1, l, r, 0);
        }

        void Set(int P, int V)
        {
            __set(P, l, r, 0, V);
        }

        Small_Segment_Tree(int _n)
        {
            a.resize(4 * _n);
            l = 0, r = _n;
        }
    };
    long long inq(long long x, long long q, long long MOD)
    {
        if (q == 0)
            return 1;
        long long l = inq(x, q / 2, MOD);
        if (q % 2)
            return l * l % MOD * x % MOD;
        return l * l % MOD;
    }
};


using namespace MySpace;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long
const ll MOD = 998244353;

int n;

signed main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int x = 0, a = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        x ^= a;
    }
    if (x == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;

class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		Deque<Integer> stack = new ArrayDeque<>();
		String[] line = scanner.nextLine().split(" ");
		int a,b;

		for(int i = 0; i < line.length; i++){
			switch(line[i]){
				case "+":
					a = stack.pollLast();
					b = stack.pollLast();
					stack.offer(b + a);
					break;

				case "-":
					a = stack.pollLast();
					b = stack.pollLast();
					stack.offer(b - a);
					break;

				case "*":
					a = stack.pollLast();
					b = stack.pollLast();
					stack.offer(b * a);
					break;

				default :
					stack.offer(Integer.parseInt(line[i]));
					break;
			}
		}

		System.out.println(stack.poll());
	}
}

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

int main(){

	int N,X;
  	cin >> N >> X;
  	int m[N];
  	int sum = X;
  	int a;
  	for(int i = 0; i < N; i++){
      	cin >> a;
      	sum -= a;
      	m[i] = a;
    }
  	sort(m,m+N);
  	
  	int cnt = N;
  	
  	while(true){
    	sum -= m[0];
      	if(sum < 0 ){
        	break;
        }
      	cnt++;
    
    }
  	cout <<cnt<<endl;
  	









}

Measured memory_bytes: 256
s = input()
flag = True
l = len(s)
if s != s[::-1]:
    flag = False
    #print('a')
#print(s,s[::-1])
if s[:(l-1)//2] != s[:(l-1)//2][::-1]:
    flag = False
    #print('b')
#print(s[:(l-1)//2],s[:(l-1)//2][::-1])
if s[(l+3)//2-1:] != s[(l+3)//2-1:][::-1]:
    flag = False
    #print('c')
#print(s[(l+3)//2-1:],s[(l+3)//2-1:][::-1])
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();

		if ((a * b) % 2 == 0) {
			System.out.println("Even");

		} else {
			System.out.println("Odd");

		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
bool huiwen(string s){
	int i=0,j=s.size()-1;
	while(i<=j&&s[i]==s[j]) i++,j--;
	if(i<=j) return false;
	return true;
}
int main(){
	string s;
	cin>>s;
	string a=s.substr(0,s.size()/2),b=s.substr(s.size()/2+1,s.size()/2);
	if(huiwen(s)&&huiwen(a)&&huiwen(b)) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int MAX_N=3010;
const int MOD=998244353;
int dp[MAX_N],a[MAX_N];
int main(void){
	int n,s,i,j;
	scanf("%d%d",&n,&s);
	for(i=1;i<=n;i++)
	scanf("%d",&a[i]);
	int ans=0;
	for(i=1;i<=n;i++){
		for(j=s;j>=a[i];j--){
			dp[j]=(dp[j]+dp[j-a[i]])%MOD;	
		}
		if(a[i]<=s)
			dp[a[i]]=(dp[a[i]]+i)%MOD;
			ans=(ans+dp[s])%MOD;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
 char s[100001];
 char f[1000000];
 char b[1000000];
 int flength=0,blength=0,slength=0;
 int q;
 int q1,q2,state=0,i;
 char q3;
 scanf("%s",s);
 scanf("%d",&q);
 for(i=0;i<q;i++){
   scanf("%d",&q1);
   if(q1==1){
     if(state){
       state=0;
     }else{
       state=1;
     }
   }else{
     q2=' ';
     q3=' ';
     while(q2==' '||q2=='\n')
      scanf("%d",&q2);
     while(q3==' '||q3=='\n')
      scanf("%c",&q3);
     q2+=state;
     if(q2%2==0){
       b[blength++]=q3;
     }else{
       f[flength++]=q3;
     }
   }
 }
 //printf("state=%d\n",state);
 if(state){
   for(i=blength-1;i>=0;i--){
     printf("%c",b[i]);
   }
   for(i=0;i<100001;i++){
     if(s[i]==0){
       slength=i;
       break;
     }
   }
   for(i=slength-1;i>=0;i--){
     printf("%c",s[i]);
   }
   printf("%s\n",f);
 }else{
   for(i=flength-1;i>=0;i--){
     printf("%c",f[i]);
   }
    printf("%s%s\n",s,b);
 }
 return 0;
}


Measured memory_bytes: 768
"use strict";

const main = arg => {
  const input = arg.trim().split("\n")[0];
  const H = parseInt(input.split(" ")[0])
  const A = parseInt(input.split(" ")[1])
  console.log(Math.floor((H + A - 1)/ A));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int N, K;
vector<int> A;

int main() {
  while (cin >> N >> K) {
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    int res = 0;
    int right = 0;
    while (true) {
      if (res == 0) right += K;
      else right += K-1;
      ++res;

      if (right >= N) break;
    }
    cout << res << endl;
  }
}

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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,x;
    cin>>a>>b;
    
	if(b%a==0)
     x=a+b;
    else
     x=b-a;
     
     cout<<x;
	

	
	return 0; 
} 

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

using namespace std;

int main()
{
  int N;  cin >> N;
  vector<int> heights(N);

  for (int& i: heights)
    cin >> i;

  int second_last = 0;
  int last = abs(heights[1] - heights[0]);

  for (int i = 2; i < N; i++)
  {
    int min_cost = min(last + abs(heights[i] - heights[i-1]), second_last + abs(heights[i] - heights[i-2]));

    second_last = last;
    last = min_cost;
  }

  cout << last << '\n';
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==b)
		{
			printf("a == b\n");
		}
	if(a>b)
		{
			printf("a > b\n");
		}
	if(a<b)
		{
			printf("a < b\n");
		}
	return 0;
}

Measured memory_bytes: 576
import sys
input = sys.stdin.readline

N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)

leaf = []
for i in range(N):
    if len(adj[i]) == 1:
        leaf.append(i)

if len(leaf) == 2:
    print(1)
    sys.exit()

par = {}
for v in leaf:
    while True:
        v_list = adj[v]
        if len(v_list) == 1:
            v_prev = v
            v = v_list[0]
        else:
            v1, v2 = v_list
            v, v_prev = v1 + v2 - v_prev, v
        if len(adj[v]) > 2:
            par[v] = 0
            break
print(len(leaf) - len(par))


Measured memory_bytes: 63408
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
class UF{
public:
	vector<int> par,num;
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UF(int N):par(N),num(N,1){
		iota(all(par),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return;
		if(num[u]<num[v])swap(u,v);
		num[u]+=num[v];
		par[v]=u;
	}
	bool same(int u,int v){
		return find(u)==find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
const int Max=1e5;
int main(){
  int n;
  cin>>n;
  UF uf(Max*2);
  V<int> x(n),y(n);
  for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
      x[i]--;y[i]--;
      uf.unite(x[i],y[i]+Max);
  }
  ll ans=0;
  ll cntx[Max*2]={},cnty[Max*2]={};
  //完全二部グラフになるまで辺を足せる
  for(int i=0;i<Max;i++)cntx[uf.find(i)]++;
  for(int i=Max;i<2*Max;i++)cnty[uf.find(i)]++;
  for(int i=0;i<2*Max;i++)ans+=cntx[i]*cnty[i];
  cout<<ans-n<<"\n";
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int main() {
  int N, M;
  cin >> N >> M;
  cout << (100 * (N - M) + 1900 * M) * (int)pow(2, M) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int D,G;
  cin>>D>>G;
  vector<int>p(D),c(D);
  for(int i=0;i<D;i++){
    cin>>p[i]>>c[i];
  }

  int ans=9999;
  for(int q=0;q<(1<<D);q++){
    int sum=0,cnt=0;
    vector<bool>use(D,true);
    for(int i=0;i<D;i++){
      if((q>>i)&1){
        sum=sum+100*(i+1)*p[i]+c[i];
        cnt+=p[i];
        use[i]=false;
      }
    }
    int r=0;
    for(int i=D-1;i>=0;i--){
      if(use[i]){
       r=i;break;
      }
    }
    for(int i=0;i<p[r];i++){
      if(sum<G){sum+=(r+1)*100;cnt++;}
    }
    if(sum<G){continue;}
    chmin(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

// 反転回数の記録用
ll rp = 0;

// 連長圧縮（ランレングス圧縮）：sの連長部分を{文字,個数}の配列で返す
vector<pair<char, long long>> rle(string s){
    vector<pair<char, long long>> ret;
    long long i = 0, n = s.size();
    while(i<n){
        char tmp = s[i];
        long long cnt = 1;
        while(i<n){
            i++;
            if(tmp == s[i]) cnt++;
            else break;
        }
        if(tmp == '0') rp++;
        ret.push_back(make_pair(tmp, cnt));
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, k, ans = 0; string s; cin >> n >> k >> s;

    // ランレングス圧縮
    auto rlev = rle(s);

    // 全部反転できる場合
    if(k >= rp){ cout << n << endl; return 0; }

    // 0の列をk個反転させた場合の長さを全探索
    ll rcnt, sum, cur, prev_sum = 0;
    rep(i, rlev.size()){
        // 初回のみ先頭から0の列をk個反転させた場合の長さ
        if(i == 0) rcnt = 0, sum = 0, cur = i;
        else{
            // 2回目以降は先頭の列分を引いて計算時間を短縮
            if(rlev[i-1].first == '0') rcnt--;
            sum -= rlev[i-1].second;
        }
        // k回反転するまで長さを足し合わせる
        while(cur<rlev.size()){
            if(rlev[cur].first == '0' && rcnt >= k) break;
            else{
                sum += rlev[cur].second;
                if(rlev[cur].first == '0') rcnt++;
                cur++;
            }
        }
        // 最大値を出力用変数に格納
        chmax(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2744
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

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

    }

    private void solve() {
        String r = sc.next();
        String g = sc.next();
        String b = sc.next();

        int rgb = Integer.parseInt(r + g + b);

        if (rgb % 4 == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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



ll clac(ll n){
    ll sum = 1;
    ll before = 1;
    while(1){ 
        if(n == 1){
            //sum += before;
            break;
        }
        else {
            //cout << sum << endl;
            before *=2;
            sum += before;
            n/=2.0;
        }
    }
    return sum;
}

int main() {
    ll h;
    cin >> h;
    /*if(h == 1){
        sum ++;
    }else{
        sum += clac(h);
    }*/
    cout << clac(h)<< endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String pre = s.substring(0, 1);
		int ans = 1;
		int i = 1;
		while(i < s.length()) {
			String next = s.substring(i, i + 1);
			if(pre.equals(next)) {
				if(i + 1 < s.length()) {
					pre = s.substring(i, i + 2);
					i += 2;
				} else {
					ans--;
					i += 2;
				}
			} else {
				pre = next;
				i++;
			}
			ans++;
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 36588
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 262144
int main() {
	long long n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	n -= 1;
	for (int i = 0;i <= n;++i) {
		long long upper = a + i*d - c*(n - i);
		long long downer = a + c*i - d*(n - i);
		if (downer <= b&&b <= upper) {
			cout << "YES" << endl;
				return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

using namespace std;
const long long  MOD=2019;
long long  L,R,ans=2018;
 main()
{
    std::cin>>L>>R;
    for (long long  i=L;i<R;i++){
            long long  a=i%MOD;
        for (long long  j=i+1;j<=R;j++){
            long long  b=j%MOD;
            ans=min(ans,a*b%MOD);
            if (ans==0){
                std::cout<<ans;
                return 0;
            }
        }
    }
    std::cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N=ii()
    d = defaultdict(int)
    for i in range(1, N+1):
        i = str(i)
        a, b = i[0], i[-1]
        if a != 0 != b:
            d[(a, b)] += 1
    ans = 0
    for i in range(1, N+1):
        i = str(i)
        a, b = i[0], i[-1]
        ans += d[(b, a)]
    print(ans)


main()


Measured memory_bytes: 5972
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n, d = 0, ans = 0;
bool bo[40], tr = true;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		d ^= a;
		REP(i, 40) {
			if (a & (1ll << i)) {
				bo[i] = true;
				break;
			}
		}
	}
	REPR(i, 37) {
		if ((!(d & (1ll << i)) and (d & (1ll << (i + 1)))) or ((d & (1ll << i)) and !(d & (1ll << (i + 1))))) {

			if (bo[i])ans++;
			else tr = false;
		}
	}
	cout << (tr ? ans : -1) << endl;
}



Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [0]*(K+1)
for i in range(K):
    if dp[i]: continue
    for a in A:
        if i+a > K: break
        dp[i+a] = 1
print('First' if dp[-1] else 'Second')

Measured memory_bytes: 40048