akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int i,j,k,p,ans;
 
int calc(){
  char c=s[p++];
  if('0'<=c&&c<='9')return (c-'0');
  else if(c=='P')return i;
  else if(c=='Q')return j;
  else if(c=='R')return k;
  else if(c=='-'){
    return 2-calc();
  }else if(c=='('){
    int a=calc();
    char ch=s[p++];
    int b=calc();
    p++;
    if(ch=='*')return min(a,b);
    else if(ch=='+')return max(a,b);
  }
  return 0;
}
 
 
void solve(){
  p=0;
  if(calc()==2)ans++;
}
int main(){
  while(1){
    cin>>s;
    if(s==".")break;
    ans=0;
    for(i=0;i<3;i++)
      for(j=0;j<3;j++)
        for(k=0;k<3;k++)
          solve();
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
const int mx = 5e5;
const ll mod = 998244353;
ll res[mx + 5];
int main() {
	res[1] = 1;
	int n, k;
	cin >> n >> k;
	vector <pair <int, int>> vec(k);
	for (int i = 0; i < k; ++i) {
		cin >> vec[i].first >> vec[i].second;
	}
	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j < k; ++j) {
			if (i - vec[j].first < 1)
				continue;
			if (i - vec[j].second < 1)
				res[i] += res[i - vec[j].first];
			else
				res[i] += res[i - vec[j].first] - res[i - vec[j].second - 1];
			res[i] %= mod;
			/*if (i == 4)
				cout << j << " " << res[i] << endl;*/
		}
		if (i != n)
			res[i] += res[i - 1];
	}
	cout << res[n] << endl;
}

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

class Program
{
    static bool Solve(string S)
    {
        return (S.Contains('N') == S.Contains('S')) && (S.Contains('E') == S.Contains('W'));
    }
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        Console.WriteLine(Solve(S) ? "Yes" : "No");
    }
}


Measured memory_bytes: 2904
from functools import lru_cache
import sys

sys.setrecursionlimit(10 ** 7)


@lru_cache(maxsize=None)
def dfs(h):
    if h == 1:
        return 1
    return 1 + dfs(h // 2) * 2


def main():
    h = int(input())
    print(dfs(h))


if __name__ == '__main__':
    main()

#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3940
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		
		sc.close();
		
		x = x - z;
		System.out.println(x/(y+z));
	}

}


Measured memory_bytes: 23764
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define s(v)       sort(v.begin(),v.end())
#define r(v)       reverse(v.begin(),v.end())
#define pf         printf
#define sf         scanf
#define GCD(x,y)   __gcd(x, y)
#define pb         push_back
#define ll         long long
#define vs         v.size()
#define ss         s.size()
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<"3"<<endl;
    else if((s[0]=='R' && s[1]=='R')|| (s[1]=='R' && s[2]=='R')) cout<<"2"<<endl;
    else if(s[0]=='S' && s[1]=='S' && s[2]=='S') cout<<"0"<<endl;
    else cout<<"1"<<endl;
    return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <string.h>
#include <algorithm>
typedef long long ll;
using namespace std;

int main()
{
    ll a,b,c,d,e;
    cin >> a >> b >> c;
    d = c-a-b;
    e = a*b;
    if(4*e >= d*d || d <=0){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 256
S = list(map(int, input().split('/')))

if S[0] < 2019:
    print('Heisei')
elif S[0] == 2019:
    if S[1] < 4:
        print('Heisei')
    elif S[1] == 4:
        if S[2] <= 30:
            print('Heisei')
    else:
        print('TBD')

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int K, A, B;
        cin >> K >> A >> B;
        if (B - A <= 1) {
            cout << K + 1 << endl;
            return;
        }

        Int rest = K;
        Int ans = 1;
        Int add = min(rest, A - 1);
        rest -= add;
        ans += add;

        if (rest > 0) {
            if (rest % 2) {
                rest--;
                ans++;
            }
            ans += (rest / 2) * (B - A);
        }
        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
from functools import lru_cache

def main():
	n=int(input())
	k=int(input())
	
	@lru_cache(None)
	def f(n,k):
		if n<10:
			if k==0:
				return 1
			if k==1:
				return n
			return 0
		q, r = divmod(n, 10)
		ret = 0
		if k>=1:
			ret+=f(q,k-1)*r
			ret+=f(q-1,k-1)*(9-r)
		ret+=f(q,k)
		return ret
	print(f(n,k))
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 3940
#include <cstdio>
#include <iostream>
using namespace std;
int prime[1000005];
bool is_prime[1000005];
int seve(int n)
{
    int p=0;
    for(int i=0;i<=n;i++)
        is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i)
                is_prime[j]=false;
        }
    }
    return p;
}
int main(void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",seve(n));
    }
    return 0;
}

Measured memory_bytes: 2468
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int a; cin >> a;
	cout << (a >= 30 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] num = new int[3000];
		int[] num2 = new int[3000];
		for (int i = 0; i < 3000; i++) {
			String line = sc.nextLine();
			String[] ss = line.split(" ");
			num[i] = Integer.parseInt(ss[0]);
			num2[i] = Integer.parseInt(ss[1]);
			if (num[i] == 0 && num2[i] == 0) {
				break;
			}
		}
		for (int i = 0; i < num.length; i++) {
			if (num[i] == 0 && num2[i] == 0) {
				break;
			}
			if (num[i] < num2[i]) {
				System.out.println(num[i] + " " + num2[i]);
			}
			if (num[i] > num2[i]) {
				System.out.println(num2[i] + " " + num[i]);
			}
			if (num[i] == num2[i]) {
				System.out.println(num[i] + " " + num2[i]);
			}
		}
	}
}

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

int main(void) {
	int N, A, B, C, X, Y, count;

	cin.tie(0);

	while (cin >> N >> A >> B >> C >> X, N | A | B | C | X) {
		count = 0;

		for (int i = 0; i < N; i++) {
			cin >> Y;
			while (X != Y) {
				X = (A * X + B) % C;
				count++;
				if (count > 10000) break;
			}

			if (i != N - 1) {
			X = (A * X + B) % C;
			count++;
			}
		}
		if(count > 10000) count = -1;
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

using pi = pair<int,int>;
using edge = pair<int,pi>;

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

    vector<edge> e(n-1);
    rep(i,n-1){
        int a,b,c;
        cin >>a >>b >>c;
        e[i] = {c,{a,b}};
    }
    sort(all(e));

    UF uf(n);
    ll ans = 0;
    rep(i,n-1){
        ll c = e[i].fi;
        int u = e[i].se.fi, v = e[i].se.se;

        ans += c*uf.size(u)*uf.size(v);
        uf.unite(u,v);
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main()
{
	long N;
	cin >> N;
	
	vector<long> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		A[i] -= (i + 1);
	}
	
	// abs(A1 - (b + 1)) + abs(A2 - (b + 2)) + ... + abs(AN - (b + N))
	// abs((A1 - 1) - b) + abs((A2 - 2) - b) + ... + abs((AN - N) - b)
	// Bi = Ai - iと考える。
	// abs(B1 - b) + abs(B2 - b) + ... + abs(BN - b)
	// bがBの中にある中央値を取るときに、悲しさの値の最小値になるのではないか
	// B = A[i] -= (i + 1)で計算している
	// そのため、Aを昇順にソートする
	sort(A.begin(), A.end());
	// Aの中から中央値を取得するには、indexをN/2
	int middleA = A[N/2];
	
	long answer = 0;
	// 悲しさの値の計算
	for (int i = 0; i < N; i++)
	{
		answer += abs(A[i] - middleA);
	}
	
	cout << answer << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if ( n<3 )
    {
        cout<<0;
        return 0;
    }
    int l[n];
    for (int i=0;i<n;i++)
    {
        cin>>l[i];
    }
    int x=0;
    int a,b,c;
    int i,j,k;
    for(int i=2;i<n;i++)
    {
        c = l[i];
        for (j=1;j<i;j++)
        {
            b = l[j];
            for(k=0;k<j;k++)
            {
                a = l[k];
                if ( a!=b && b!=c && a!=c )
                {
                    if (a+b>c&&a+c>b&&b+c>a)
                    {
                        x++;
                    }
                }
            }
        }
    }
    
    cout<<x;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    int n;cin>>n;
    vector<int>a(n);
    rep(i,n){
        int b;cin>>b;
        a[i]=-b;
    }
    vector<int>dp(n,inf);
    rep(i,n){
        *upper_bound(all(dp),a[i])=a[i];
    }
    cout<<lower_bound(all(dp),inf)-dp.begin()<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int n; cin >> n;
        map<int, int> mp;
        for (int i = 1; i<= 100; i++) {
                for (int j = 1; j<= 100; j++) {
                        for (int k = 1; k<= 100; k++) {
                                mp[i*i + j*j + k*k + i*j + i*k + k*j]+= 1;
                        }
                }
        }
        for (int i = 1; i<= n; i++) {
                cout << mp[i]<< "\n";
        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 6044
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let words = vec!['A', 'C', 'G', 'T'];
    let text = read::<String>().chars().collect::<Vec<char>>();
    let mut results = vec![];
    let mut tmp = Vec::with_capacity(text.len());

    for chr in text.iter() {
        tmp.push(words.iter().any(|&word| chr == &word));
    }

    let mut counter: usize = 0;
    for boolean in tmp.iter() {
        if *boolean {
            counter += 1;
        } else {
            results.push(counter);
            counter = 0;
        }
    }

    if counter != 0 {
        results.push(counter);
    }

    match results.iter().max() {
        Some(max) => println!("{:?}", max),
        _ => panic!()
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
#ifdef KEV
#define debug(i) cerr << #i << ' ' << i << '\n'
#else
#define debug(i) 
#endif
using ll = long long;
const int maxn = 1<<19;
int n, k, a[maxn], pos[maxn];
struct sgt {
	int val[maxn<<1];
	void modify(int i, int v) {
		i += maxn;
		val[i] = v;
		for (;i>>=1;)
			val[i] = max(val[i<<1], val[i<<1|1]);
	}
	int query(int l, int r) {
		int res = 0;
		l = max(l, 1), r = min(r, n+1);
		l += maxn, r += maxn;
		for (;l < r;l>>=1, r>>=1) {
			if (l&1) res = max(res, val[l++]);
			if (r&1) res = max(res, val[--r]);
		}
		return res;
	}
}tree;
void bf(int l, int r) {
	bool c = true;
	while (c) {
		c = false;
		for (int j = l+1;j <= r;++j)
			if (abs(pos[j] - pos[j-1]) >= k && pos[j] < pos[j-1])
				c = true, swap(pos[j], pos[j-1]);//, swap(a[ pos[j] ], a[ pos[j-1] ]), c = true;
		for (int j = r;j >= l+1;--j)
			if (abs(pos[j] - pos[j-1]) >= k && pos[j] < pos[j-1])
				c = true, swap(pos[j], pos[j-1]);//, swap(a[ pos[j] ], a[ pos[j-1] ]), c = true;
	}
}
set<int> st;
void solve(int l, int r) {
	static int cp[maxn], pri[maxn];
	static vector<int> q[maxn];
	if (r <= l) return;
	if (r-l+1 <= 500) 
		bf(l, r);
	else {
		int m = l + r >> 1;
		solve(l, m);
		solve(m+1, r);
		for (int i = l;i <= m;++i)
			tree.modify(pos[i], i), st.insert(pos[i]);//,cerr << "modify " << pos[i] << " : " << i << '\n';
		int lst = l-1;
		for (int i = m+1;i <= r;++i) {
			int p = tree.query(1, pos[i]);
			auto invalid = [&]() {
				auto it = st.lower_bound(pos[i]);
				return it != end(st) && *it - pos[i] < k;
			};
			while (lst < p || (lst < m && invalid())) {
				st.erase(pos[++lst]);
//				if (lst != l-1) st.erase(pos[lst]);
//				++lst;
			}
			debug(p) ;

			q[lst].pb(pos[i]);
			//if (l == 1 && r == 4) cerr << lst << '\n' << "P " << p << '\n';
		}
		for (int i = l;i <= m;++i)
			tree.modify(pos[i], 0);
		st.clear();

		int h = l;
		for (int i = l-1;i <= m;++i) {
			if (i != l-1) cp[h++] = pos[i];
			for (int u : q[i]) cp[h++] = u;
			q[i].clear();
		}
		copy(cp+l, cp+r+1, pos+l);
	}
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	for (int i = 1;i <= n;++i)
		cin >> a[i], pos[a[i]] = i;
	solve(1, n);
  
	for (int i = 1;i <= n;++i) a[pos[i]] = i;
	for (int i = 1;i <= n;++i)
		cout << a[i] << '\n';
}


Measured memory_bytes: 54784
from collections import Counter


def check(n, a):
    aa = Counter(a)
    if n & 1 and (0 not in aa or aa[0] != 1):
        return False
    for i in range(1 + (n & 1), n + 1, 2):
        if i not in aa or aa[i] != 2:
            return False
    return True


def solve():
    n = int(input())
    a = list(map(int, input().split()))

    if not check(n, a):
        return 0

    exp = n // 2
    if exp < 30:
        return 2 ** exp
    c = 2 ** 29
    d = int(1e9) + 7
    exp -= 29
    for _ in range(exp):
        c = c * 2 % d
    return c


print(solve())


Measured memory_bytes: 14820
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1001

int LCSLength(char *X,char *Y){
  int m,n,i,j;
  int c[N][N];
  m=strlen(X);
  n=strlen(Y);
  for(i=1;i<=m;i++)
    c[i][0]=0;
  for(j=0;j<=n;j++)
    c[0][j]=0;
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(X[i-1]==Y[j-1])
        c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1])
        c[i][j]=c[i-1][j];
      else
        c[i][j]=c[i][j-1];
    }
  }
  return c[m][n];
}

int main(){
  int q,i;
  char X[N],Y[N];
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf(" %s %s",X,Y);
    LCSLength(X,Y);
    printf("%d\n",LCSLength(X,Y));
  }
  return 0;
}



Measured memory_bytes: 5648
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define mod (ll)(1000000007)
#define inf (ll)(3e18+7)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  ll n, k, c[2002][2002];
  cin >> n >> k;
  for(int i = 0; i <= n+1; i++)  {
    c[i][0] = 1;
    for(int j = 1; j <= i; j++) {
      c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
    }
  }
  REP(i, k) {
    int ans = 1LL*c[n-k+1][i]*c[k-1][i-1]%mod;
    cout << ans << endl;
  }
}

Measured memory_bytes: 31488
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
//		try{
				int h=sc.nextInt();
				int w=sc.nextInt();
				int m=sc.nextInt();
				int fr[]=new int[h];
				int fc[]=new int[w];
				HashSet<String> s=new HashSet<>();
				for(int i=0;i<m;i++) {
					int x=sc.nextInt()-1;
					int y=sc.nextInt()-1;
					fr[x]++;
					fc[y]++;
					String ss=x+","+y;
					s.add(ss);
			
				}
				
				int max=Integer.MIN_VALUE;
				int r=0;
				ArrayList<Integer> xx=new ArrayList<>();
				ArrayList<Integer> yy=new ArrayList<>();
				for(int i=0;i<fr.length;i++) {
					max=Math.max(max,fr[i]);
				}	int c=0;
				int maxq=Integer.MIN_VALUE;
				for(int i=0;i<fc.length;i++) {
					maxq=Math.max(maxq,fc[i]);
				}
				for(int i=0;i<h;i++) {
					if(max==fr[i]) {
						xx.add(i);
					}
				}
				for(int i=0;i<w;i++) {
					if(maxq==fc[i]) {
						yy.add(i);
					}
				}
					
				int ans=maxq+max;
//				for(int i:xx) {
//					System.out.print(i+" ");
//				}
//				System.out.println();
//				
//				for(int i:yy) {
//					System.out.print(i+" ");
//				}
//				System.out.println();
		boolean b=true;
		s:for(int i:xx) {
			for(int j:yy) {
				if(!s.contains(i+","+j)) {
					b=false;
					break s;
				}
			}
		}
		
		if(b==true) {
			ans--;
		}
			
			System.out.println(ans);
			
			
			
//		}catch(Exception e){
//		    return;
//		}
	}


	

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

Measured memory_bytes: 97240
# -*- coding: utf-8 -*-
import sys
import copy
from bisect import bisect_left

def main():
	N = list(input())
	
	ans = ""
	for i in range(len(N)):
		if N[i] == "1":
			ans += "9"
		else:
			ans += "1"
			
	print(ans)
	
		
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 3444
//BUGSBUNNY
//IIT ROORKEE
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (ll i = 0; i < n; i++)
#define repp(i,a,b) for(ll i = a ; i<b ; i++)
#define reppr(i,a,b) for(ll i = a-1 ; i>=b ; i--)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }


void solve();
signed main()
{
    //-------------------------------------------------------------------------------   
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();
    //-------------------------------------------------------------------------------   
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;       
        rep(i,t)
        {
            // cout << "Case #" << i+1 << ": ";
            solve();
        }
    //-------------------------------------------------------------------------------
        clk = clock() - clk;
        cerr << fixed << setprecision(12) << "Time: " << ((double)clk)/CLOCKS_PER_SEC;
    //-------------------------------------------------------------------------------
}

void solve()
{
    int n , k ;
    cin >> n >> k;
    set<int> s;
    repp(i,1,n+1)
        s.insert(i);
    rep(i,k)
    {
        int d;
        cin >> d;
        rep(j,d)
        {
            int temp;
            cin >> temp;
            s.erase(temp);
        }
    }
    cout << s.size() << endl;
}   

Measured memory_bytes: 3768
//  test.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    long int j,s[1000000]={0},d=1,i,n,k;
    
    s[0]=s[1]=1;
    
    for(i=2;i<1000000;i++){
        if(s[i]==0){
            
            for(j=2;j*j<=i;j+=2){
                if(i%j==0)
                    break;
                if(j==2)
                    j=1;
            }
            
            
            if(j*j>i){
                d++;
                if(i<1000){
                    for(k=2;k*i<1000000;k++){
                        s[k*i]=-1;
                    }
                }
            }
        }
        s[i] = d;
    }
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]-1);
    }
    
    
    return 0;
}

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

#define MOD 1000000007
  
long int solve(vector<vector<char>>&grid,int r,int c){
   
    
    int l2r[r][c];
    int r2l[r][c];
    int t2b[r][c];
    int b2t[r][c]; 
    int i,j;
    
    
    for(i=0;i<r;i++){
        l2r[i][0] = 0;
        for(j=0;j<c;j++){
            if(j==0 &&  grid[i][j] == '.')
                l2r[i][j] = 1;
            else if(grid[i][j] == '.')
                l2r[i][j] = l2r[i][j-1]+1;
             else 
                l2r[i][j]=0;
        }
    }
   
     
    for(i=0;i<r;i++){
        r2l[i][c-1] = 0;
        for(j=c-1;j>=0;j--){
            if(j==c-1 &&  grid[i][j] == '.')
                r2l[i][j] = 1;
            else if(grid[i][j] == '.')
                r2l[i][j] = r2l[i][j+1]+1;
             else 
                r2l[i][j]=0;
        }
    }
      
    for(i=0;i<c;i++){
        t2b[0][i] = 0;
        for(j=0;j<r;j++){
            if(j==0 &&  grid[j][i] == '.')
                t2b[j][i] = 1;
            else if(grid[j][i] == '.')
                t2b[j][i] = t2b[j-1][i]+1;
             else 
                t2b[j][i]=0;
        }
    }
     
    for(i=0;i<c;i++){
        b2t[r-1][i] = 0;
        for(j=r-1;j>=0;j--){
            if(j==r-1 &&  grid[j][i] == '.')
                b2t[j][i] = 1;
            else if(grid[j][i] == '.')
                b2t[j][i] = b2t[j+1][i]+1;
             else 
                b2t[j][i]=0;
        }
    }
            
    
    int ans=-1;
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            int cnt=1;
            if(grid[i][j]=='.'){
                if(i>0)
                    cnt += t2b[i-1][j];
                if(i<r-1)
                    cnt += b2t[i+1][j];
                if(j>0)
                    cnt += l2r[i][j-1];
                if(j<c-1)
                    cnt += r2l[i][j+1];
            }
            ans = max(ans,cnt);
        }
    }
            
     return ans;               
}

int main() 
{   
    int r,c,i,j;
    cin>>r>>c;
    vector<vector<char>>grid(r,vector<char>(c));
    string g;
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++)
            cin>>grid[i][j];
    }
    cout<<solve(grid,r,c);
    return 0; 
} 

Measured memory_bytes: 68352
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    int aa = 1, ans = 0;
    while(aa < b) {
        aa += a - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int n,m,k,num[10010],mp[110][110],x,y;

inline void solve(int c,bool dic)
{
	if(num[c])
	{
		mp[x][y]=c;
		num[c]--;
		if(dic==0&&y==m-1) x++,solve(c,1);
		else if(dic==1&&y==0) x++,solve(c,0);
		else if(dic==0) y++,solve(c,0);
		else y--,solve(c,1);
	}
}

int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++) cin>>num[i];
	
	for(int i=1;i<=k;i++) if(x%2==0) solve(i,0); else solve(i,1);
	
	for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++) cout<<mp[i][j]<<' ';
			cout<<endl;
		}
	
	return 0;
}

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  ll A, B, N;
  scanf("%lld%lld%lld", &A, &B, &N);

  ll X = min(B - 1, N);
  ll ans = (A * X) / B - A * (X / B);
  printf("%lld\n", ans);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}

Measured memory_bytes: 3804
def main():
    a, b, c = input().split()
    k = input()

    a = int(a)
    b = int(b)
    c = int(c)
    lst = [a,b,c]
    k = int(k)


    M = max(lst)
    lst.remove(M)

    for i in range(k):
        M = M * 2
    ans = sum(lst) + M

    print(ans)

if __name__ == "__main__":
        main()


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

long long n, dp[100005][3], x, y;
bool visited[100005];
vector<int> AdjList[100005];
const int MOD = 1e9 + 7;

void DFS(int now)
{
    visited[now] = true;
    long long white = 1, black = 1;

    for(int i=0; i<AdjList[now].size(); i++) {
        int next = AdjList[now][i];
        if(!visited[next]) {
            DFS(next);
            white = (white * (dp[next][1] + dp[next][2])) % MOD;
            black = (black * dp[next][1]) % MOD;
        }
    }
    dp[now][1] = white;
    dp[now][2] = black;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n-1; i++) {
        cin >> x >> y;
        AdjList[x].push_back(y);
        AdjList[y].push_back(x);
    }
    DFS(1);
    cout << (dp[1][1] + dp[1][2]) % MOD << endl;

    return 0;
}


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

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

  ll x;
  cin >> x;

  ll val = 100;
  int ans = 1;
  while(true) {
    val = val * (1.01);
    if(val >= x) break;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	FOR(h,1,3501) FOR(n,1,3501){
		double tmp1 = (double)N*h*n;
		double tmp2 = 4.0*h*n -(double)N*h - (double)N*n;
		double w = tmp1 / tmp2;
		if(w>0 && lround(w)==w){
			cout << h << " " << n << " " << lround(w) << '\n';
			return 0;
		}
	}
	return 0;
}



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

N=int(input())
L=list(map(int,input().split()))

L.sort()

import bisect

ANS=0
for i in range(N-1):
    for j in range(i+1,N):
        x=L[i]+L[j]

        r=bisect.bisect_right(L,x-1)

        ANS+=max(0,(r-j-1))

        #print(i,j,x,r,max(0,(r-j-1)))

print(ANS)


Measured memory_bytes: 43996
/*
  AOJ 0318
  @kankichi573
 */
#include <stdio.h>
#include <string.h>
int n;
char flag[101];
char table[8];

int main()
{
  int x,m,i,ret;

  memset(flag,0,sizeof(flag));
  memset(table,0,sizeof(table));

  table[4]=table[6]=table[7]=1;
  
  scanf("%d",&n);
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      scanf("%d",&x);
      flag[x] |= 1;
    }
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      scanf("%d",&x);
      flag[x] |= 2;
    }
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      scanf("%d",&x);
      flag[x] |= 4;
    }

/*
  for(i=1,ret=0;i<=n;i++)
    printf("%d ",flag[i]);
  printf("\n");
*/
  for(i=1,ret=0;i<=n;i++)
    ret += table[flag[i]];
  printf("%d\n",ret);
  return(0);
  }

Measured memory_bytes: 600
#include <stdio.h>
#define MAX 100

int main(){
  int M[MAX][MAX];
  int i,j;
  int n,u,k,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
      printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
char a[20],b[20]={"CODEFESTIVAL2016"};int ans,i;
int main(){
	scanf("%s",a);
	for(i=0;i<16;i++)
		if(a[i]!=b[i])
			ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	static Map<Long,Long> map= new TreeMap<>();
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  long a=sc.nextLong(),b=sc.nextLong();
	  long gcd=GCD(Math.min(a, b),Math.max(a, b));
	  primeEnum(gcd);
	  long res=map.size()+1;
	  //System.out.println(res*(res-1)/2+" "+gcd);
	  System.out.println(map.size()+1);
  }
	public static Map<Long,Long> primeEnum(long n) {
		for(long i=2;i<=Math.sqrt(n);i++) {
			if(n%i!=0)continue;
			long e=0;
			while(n%i==0) {
				e++;
				n/=i;
			}
			if(map.containsKey(i)) {
				map.put(i, e+map.get(i));
			}else {
				map.put(i, e);
			}
		}
		if(n!=1) {
			if(map.containsKey(n)) {
				map.put(n, 1+map.get(n));
			}else {
				map.put(n, 1L);
			}
		}
		return map;
	}
	public static long GCD(long min,long max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
}



Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second


void dfs(vector<int> graph[],vector<ll> &dp,vector<int> &vis,int u)
{
  vis[u]=1;
  for(int i=0;i<graph[u].size();i++)
  {
    if(vis[graph[u][i]]==0)
      dfs(graph,dp,vis,graph[u][i]);

    dp[u]=max(dp[u],1+dp[graph[u][i]]);
  }
}
int main()
{
  ll n,m;
  cin>>n>>m;
  vector<int> graph[n];
  for(int i=0;i<m;i++)
  {
    ll x,y;
    cin>>x>>y;
    graph[x-1].push_back(y-1);
  }
  vector<int> vis(n,0);
  vector<ll> dp(n,0);
  for(int i=0;i<n;i++)
  {
    if(vis[i]==0)
      dfs(graph,dp,vis,i);
  }

  ll maxi=0;
  for(int i=0;i<n;i++)
    maxi=max(maxi,dp[i]);

  cout<<maxi<<endl;
}


Measured memory_bytes: 13068
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
const int N =  2e4 + 10;
int cnt[2*N];
int32_t main()
{
	fast;
 int n; cin >> n; 
 vi s;
 auto gt = [](int x){return x*x;};
 rep(i,1,10000){
 	rep(j,1,10000){
 		rep(k,1,10000){
 			int val = gt(i)+gt(j)+gt(k)+i*j + j*k + k*i;
 			if(val>n) break;
 		    s.emplace_back(val);
 		}
 	}
 } 
 for(int x: s) cnt[x] ++;
 rep(i,1,n) cout << cnt[i] << "\n";
}

Measured memory_bytes: 5304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
ll dp[1<<18],cop[1<<18];
int n,X,Y,Z;
bool Is575(ll i){
    int cnt=0;
    if(1&(i>>(Z-1)))cnt++;
    if(1&(i>>(Y+Z-1)))cnt++;
    if(1&(i>>(X+Y+Z-1)))cnt++;
    if(cnt==3)return 1;
    return 0;
}
int main(){
    cin>>n>>X>>Y>>Z;
    ll K=(1<<(X+Y+Z));
    lol(i,K)dp[i]=0;dp[0]=1;
    lol(u,n){
	lol(i,K)cop[i]=0;
	lol(i,K){
	    if(Is575(i))continue;
	    for(int j=1;j<=10;j++){
		ll t=(i<<j)+(1<<(j-1));
		t%=K;
		cop[t]+=dp[i],cop[t]%=mod;
	    }
	}
	lol(i,K)dp[i]=cop[i];
    }
    ll sum=0;
    lol(i,K){
	if(Is575(i)==false){
	    sum+=dp[i];
	    sum%=mod;
	}
    }
    ll ans=1;
    lol(i,n)ans*=10,ans%=mod;
    cout<<(ans-sum+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int A[N];
  rep(i,N) cin >> A[i];
  cout << ((N-1)%(K-1)==0 ? (N-1)/(K-1) : (N-1)/(K-1)+1) << endl;
 return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ret = 1;
    for(ll i = 0; i < b; i++) {
        ret *= (a - i);
        ret %= mod;
        ret *= beki(i + 1, mod - 2);
        ret %= mod;
    }
    return ret;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = beki(2, n) - 1;
    ans -= combination(n, a);
    ans -= combination(n, b);
    ans += 2 * mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector<int> isFavorite(M, 0);
    for(int i = 0; i < N; i++){
        int k;
        std::cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            std::cin >> a;
            a--; // to 0 origin
            isFavorite[a]++;
        }
    }

    // 好きな人が何人いるか
    int cnt = 0;
    for(int i = 0; i < M; i++){
        if(isFavorite[i] == N) cnt++;
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  int X, Y;
  cin >> X >> Y, X--, Y--;
  vector<int> A(N + 1);
  REP(i, N - 1) for (int j = i + 1; j < N; j++) {
    int dis1 = j - i;
    int dis2 = abs(i - X) + 1 + abs(j - Y);
    int dis3 = abs(i - Y) + 1 + abs(j - Y);
    A[min(dis1, min(dis2, dis3))]++;
  }
  REP(i, N-1) { cout << A[i+1] << endl; }
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll x, y;
	cin>>x>>y;
	ll res = 0;
	ll d = abs(y)-abs(x);
	if(d>0){
		if(x<0){
			x *= -1;
			res++;
		}
		if(y<0) res++;
	} else if(d<0){
		if(x>0){
			x *= -1;
			res++;
		}
		if(y>0) res++;
	} else if(x!=y) res++;
	res += abs(d);
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    import scala.collection.immutable.BitSet
    val NumAry = readLine.split("").filterNot(_ == "").map(_.toInt)
    for (i <- 0 until 8) {
      val ans1 = if((i & 0x4) != 0) (NumAry(0) + NumAry(1)) else (NumAry(0) - NumAry(1))
      val ans2 = if((i & 0x2) != 0) (ans1      + NumAry(2)) else (ans1      - NumAry(2))
      val ans3 = if((i & 0x1) != 0) (ans2      + NumAry(3)) else (ans2      - NumAry(3))

      if (ans3 == 7) {
        val op1 = if((i & 0x4) != 0) "+" else "-"
        val op2 = if((i & 0x2) != 0) "+" else "-"
        val op3 = if((i & 0x1) != 0) "+" else "-"

        println(NumAry(0) + op1 + NumAry(1) + op2 + NumAry(2) + op3 + NumAry(3) + "=7")
        return;
      }
    }
  }
}


Measured memory_bytes: 27200
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;

int main() 
{
	LL q,h,s,d;
	int n;
	scanf("%lld %lld %lld %lld %d",&q,&h,&s,&d,&n);
	LL bst1=min(4*q,min(2*h,s));
	LL bst2=min(d,2*bst1);
	LL cst=(n/2)*bst2;
	if(n%2)
	{
		cst+=bst1;
	}
	printf("%lld\n",cst);
	return 0;
}

Measured memory_bytes: 256
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict as dd
n=int(input())
a=nl()
a.sort()

d=dd(int)
for aa in a:
    d[aa]+=1
counter=0
for k,v in d.items():
    if v%2==0:
        counter+=v-1
if counter%2==0:
    print(len(d))
else:
    print(len(d)-1)



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

int main(void){
  int i=100,x,y,ans;
  char m;
  for(i=0;i<=1000;i++){
  scanf("%d %c %d",&x,&m,&y);
  if(m=='+'){
      ans=x+y;
      printf("%d\n",ans);
  }
  if(m=='-'){
      ans=x-y;
      printf("%d\n",ans);
  }
  if(m=='*'){
      ans=x*y;
      printf("%d\n",ans);
  }
  if(m=='/'){
      ans=x/y;
      printf("%d\n",ans);
  }
  if(m=='?'){
      i=10000;
  }
  }
  return 0;
}

Measured memory_bytes: 600
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    
    ll count=0;
    while(B <= A){
        B *= 2;
        count++;
    }
    // cout << B << endl;

    while(C <= B){
        C *= 2;
        count++;
    }
    // cout << C << endl;

    if(count <= K){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}




Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
  int x,a,b;
  cin>>x>>a>>b;
  int c=a-x;
  int d=b-x;
  if(c<0){
    c=-1*c;
    if(d<0){
      d=-1*d;
      if(c>=d){
        cout<<"B";
      }
      else{
        cout<<"A";
      }
    }
    else{
      if(c>=d){
        cout<<"B";
      }
      else{
        cout<<"A";
      }
    }
  }
  else{
    if(d<0){
      d=-1*d;
      if(c>=d){
        cout<<"B";
      }
      else{
        cout<<"A";
      }
    }
    else{
      if(c>=d){
        cout<<"B";
      }
      else{
        cout<<"A";
      }
    }
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;

bool DD_Rolling_Hash(int P, int Q, const vector<vector<char>>& a, vector<vector<ull>>& res) {
	const ull B1 = 9973;
	const ull B2 = 100000007;
	if (a.size() < P || a[0].size() < Q) return false;
	vector<vector<ull>> tmp(a.size(), vector<ull>(a[0].size() - Q + 1));
	res = vector<vector<ull>>(a.size() - P + 1, vector<ull>(a[0].size() - Q + 1));

	ull t1 = 1;
	for (int j = 0; j < Q; j++) t1 *= B1;

	for (int i = 0; i < a.size(); i++) {
		ull e = 0;
		for (int j = 0; j < Q; j++) e = e * B1 + a[i][j];

		for (int j = 0; j + Q <= a[0].size(); j++) {
			tmp[i][j] = e;
			if (j + Q < a[0].size()) e = e * B1 - t1 * a[i][j] + a[i][j + Q];
		}
	}

	ull t2 = 1;
	for (int i = 0; i < P; i++) t2 *= B2;

	for (int j = 0; j + Q <= a[0].size(); j++) {
		ull e = 0;
		for (int i = 0; i < P; i++) e = e * B2 + tmp[i][j];

		for (int i = 0; i + P <= a.size(); i++) {
			res[i][j] = e;
			if (i + P < a.size()) e = e * B2 - t2 * tmp[i][j] + tmp[i + P][j];
		}
	}
	return true;
}

int main()
{
	int H, W, R, C;
	cin >> H >> W;
	vector<vector<char>> a(W, vector<char>(H));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[j][i];
		}
	}
	cin >> R >> C;
	vector<vector<char>> b(C, vector<char>(R));
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			cin >> b[j][i];
		}
	}
	vector<vector<ull>> res;
	DD_Rolling_Hash(C, R, b, res);
	ull f = res[0][0];

	if (DD_Rolling_Hash(C, R, a, res)) {
		for (int i = 0; i < res[0].size(); i++) {
			for (int j = 0; j < res.size(); j++) {
				if (res[j][i] == f) {
					cout << i << ' ' << j << endl;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;

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

    vector<int> b(n);

    for (int i = 0; i < n;i++){
        cin >> b.at(i);
    }
    int sum = b.at(0)+b.at(n-2);
    for (int i = 0; i < n - 1; i++){
        sum += min(b.at(i), b.at(i + 1));
    }
    cout << sum << endl;

    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  int rem;
  rem = N % 500;
  
  if (rem <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
class Array
  def cumsum; s = 0; map{|k| s += k } end
  def abs; map{|k| k.abs } end  
  def diff; (size-1).times.map { |i| self[i + 1] - self[i] } end
end

n = gets.to_i
a = [0] + gets.split.map(&:to_i) + [0]
# p a
d = a.diff.abs

r = [0] + d.cumsum + [0]
l = [0] + d.reverse.cumsum.reverse + [0]

# p r
# p l

n.times do |i|
  d = (a[i+2] - a[i]).abs + r[i] + l[i+3]
  p d
end


Measured memory_bytes: 24972
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

solve :: Int -> Int -> [(Int,Int)] -> Int
solve n c xvs = answer where
  xs = map fst xvs
  vs = map snd xvs
  xsR = map (c -) (reverse xs)
  vsR = reverse vs
  answer = max (solveSub xs vs xsR vsR) (solveSub xsR vsR xs vs)

solveSub :: [Int] -> [Int] -> [Int] -> [Int] -> Int
solveSub xs vs xsR vsR = answer where
  calcG val cost = tail $ scanl' max 0 $
                        zipWith (-) (scanl' (+) 0 val) (0:cost)
  gainA = calcG vs (map (* 2) xs)
  gainB = calcG vsR xsR
  answer = maximum $ zipWith (+) gainA (reverse gainB)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_c]:remLines1 = remLines0
      n = readBInt bs_n
      c = readBInt bs_c
      xvs = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve n c xvs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 78076