akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;


long long modpow(long long x, long long n) { 
  if (n == 0) return 1%mod; 
  long long u = modpow(x,n/2); 
  u = (u*u)%mod; 
  if (n%2 == 1) u = (u*x)%mod; 
  return u;
}
long long n, a, b, c, d;
bool memoo[1001][1001];
long long memo[1001][1001];
long long shortmod(long long num){
    if (num >= mod){
        num -= mod;
    }
    return num;
}
void EE(int a, int b, int& x, int& y)
{
    if(a%b == 0)
    {
        x=0;
        y=1;
        return;
    }
    EE(b,a%b,x,y);
    int temp = x;
    x = y;
    y = temp - y*(a/b);
}
int inverse(int a)
{
    int x,y;
    EE(a,mod,x,y);
    if(x<0) x += mod;
    return x;

}
long long facts[1001];
long long invfacts[1001];
long long inverses[1001];
long long func(int left, int grpsze){
  
    if (left == 0 && grpsze > b){
        return 1;
    }
    if (left < 0 || grpsze > b){
        return 0;
    }
    
    if (memoo[left][grpsze]){
        return memo[left][grpsze];
    }
    long long res = 0;
    
    long long choose = 1;
    int templeft = left;
 
    templeft -= grpsze*(c-1);
    choose *= modpow(invfacts[grpsze], c-1);
    choose %= mod;
    choose *= invfacts[c-1];
    choose %= mod;
    for (int i=c; i <= d; i++){
        if (templeft <= 0){
            break;
        }
        choose *= invfacts[grpsze];
        choose %= mod;
        choose *= inverses[i];
        choose %= mod;
        templeft -= grpsze;
        res += (choose*func(templeft, grpsze+1))%mod;
        res = shortmod(res);
        
    }
    res += func(left, grpsze+1);
    res = shortmod(res);
    memoo[left][grpsze] = true;
    memo[left][grpsze] = res;
    return res;
}
int main ()
{
  prep();
  
  cin >> n >> a >> b >> c >> d;
 
  long long cur = 1;
  for (int i=1; i<=1000; i++){
      cur *= i;
      cur %= mod;
      facts[i] = cur;
  }
  facts[0] = 1;
  invfacts[0] = 1;
  inverses[0] = 1;
  cur = 1;
  for (int i=1; i<=1000; i++){
      cur *= inverse(i);
      cur %= mod;
      invfacts[i] = cur;
  }
  for (int i=1; i<=1000; i++){
      inverses[i] = inverse(i);
  }
  cout << (facts[n]*func(n, a))%mod;
  
  return 0; 
}


Measured memory_bytes: 9216
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    h,w=map(int, input().split())
    l=[]
    for i in range(h):
        ll=list(input())
        l.append(ll)
    # lはl[列番号][行番号]になってる
    # 行と列のチェックリストを作る。行が縦で列が横
    gyou= [False] * w
    retu= [False] * h
    # 列番号をずらしていく
    for retunum in range(h):
        # 行番号をずらしていく
        for gyounum in range(w):
            # 同じ行or列に１個でも'#'があればその時点でその行or列は消えない
            # '#'があった列と行をTrueにしていく
            if l[retunum][gyounum]=='#':
                retu[retunum]=True
                gyou[gyounum]=True
    # 列も行もTrue→行と列の両方のどこかに'#'があるから、行と列の交点のマスは消えない
    for retunum in range(h):
        if retu[retunum]:
            for gyounum in range(w):
                if gyou[gyounum]:
                    # 同じ列の出力が終わるまでは改行しない
                    print(l[retunum][gyounum],end='')
            # １個の列が終わったら改行
            print('')
resolve()

Measured memory_bytes: 4596
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  int N;cin >> N;
  map<int,int> S;
  repeat(i,N){
    int D;cin >> D;
    S[D]++;
  }
  int M;cin >> M;
  bool isok = true;
  repeat(i,M){
    int T;cin >> T;
    isok &= S.count(T)&&(S[T]--)>0;
  }
  cout << (isok? "YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 9600
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    # 最大公約数
    import fractions
    from functools import reduce

    n, k = ns()
    a = na()

    gcdans = reduce(fractions.gcd, a)

    maximum = max(a)
    if maximum - k >= 0 and (maximum - k) % gcdans == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == '__main__':
    main()


Measured memory_bytes: 16164
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
  
int main(void)
{
    char num[1001] = {0} ;
    int i=0 ;
    int number=0 ;

  
    while (1){
  
        scanf("%s",num);
  
        if (num[0]=='0' && num[1]=='\0') break;
  
        for (i=0 ;i<1001 ;i++){
  
            if (num[i]=='\0') break;
  
            number=number+(num[i]-'0');
  
        }
  
        printf("%d\n",number);
        memset(num ,'\0' ,sizeof num);
        number=0;
  
    }
  
    return 0;
}


Measured memory_bytes: 2092
#include <iostream>
using namespace std;
bool dfs(int,int);
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char s[50][50];
int h,w;
int main(){
  bool flag=true;
  cin >> h>> w;
  int d=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> s[i][j];
      if(s[i][j]!='.') d++;
    }
  }
  if(d==0) cout <<"Yes" << endl;
  else{
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
      if(!dfs(i,j)) {
        flag=false;
        break;
      }
    }
  }
    if(!flag) break;
  }
  if(!flag) cout << "No" << endl;
  else cout <<"Yes" << endl;
}
}
bool dfs(int y,int x){
  int c=0;
  for(int i=0;i<4;i++){
    int ny=y+dy[i];int nx=x+dx[i];
    if(nx<0||ny<0||nx>w||ny>h) continue;
    if(s[ny][nx]==s[y][x]) c++;
  }
  if(c==0) return false;
  return true;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		while(scanner.hasNextLine()) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();

			if(x == 0 && y == 0) {
				break;
			}

			if(x >= 0  && x <= 10000) {
				if(x > y) {
					int tmp = x;
					x = y;
					y = tmp;
				}
				System.out.println(x + " " +y);
			}
		}

    	scanner.close();
    }
}



Measured memory_bytes: 43340
#include <iostream>

using namespace std;

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

    int n, m;
    cin >> n >> m;
    int t = 0;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        t += a[i];
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (4 * m * a[i] >= t) c++;
    }
    if (c >= m) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
int H[100000];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    int ans = 0;
    int tmp = 0;
    for(int i = N-2; i >= 0; i--){
        if(H[i+1] <= H[i]) tmp++;
        else{
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    ans = max(ans, tmp);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,pll> ppll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
# define INF 0x3f3f3f3f
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
const ll M = 1000000007; 
ll ni[100005] , fi[100005] , fac[100005];
	
void numinv () {
	ni[0] = 1;
	ni[1] = 1;
	for ( ll i = 2 ; i < 100005 ; i ++ ){
		ni[i] = ( ni[M%i] * (M - M/i) ) % M;
	}
}

void facinv () {
	fi[0] = 1;
	fi[1] = 1;
	for ( ll i = 2 ; i < 100005 ; i ++ ){
		fi[i] = ( ni[i] * fi[i - 1] ) % M;
	}
}

void facc() {
	fac[0] = 1;
	fac[1] = 1;
	for ( ll i = 2 ; i < 100005 ; i ++ ){
		fac[i] = ( fac[i - 1] * i ) % M;
	}
}

ll ncr( ll n , ll r ){
	if ( n == r ) return 1;
	if ( r == 1 ) return n;
	return ((fac[n]*fi[n - r])%M*fi[r])%M;
}

int main(){
	FAST;
    ll n, k, m, z = 0, ans = 0, j, t = 0, x = 0, y = 0, c = 0, i;
    cin >> n >> k;  
    ll a[n];
    numinv();
    facinv();
    facc();
    for ( i = 0 ; i < n ; i ++ ){
    	cin >> a[i];
    }
    sort (a , a+n);
    for ( i = 0 ; i <= n-k ; i ++ ){
    	ans = ( ans + ( a[i] * ncr(n-i-1 , k-1) ) % M + M ) % M ;
    }
    for ( i = n - 1 ; i >= k - 1 ; i -- ){
    	c = ( c + ( a[i] * ncr(i , k-1) ) % M  + M ) % M ;
        //cout << c << " " << a[i] <<" " << i << " " << k-1 <<  "\n";
    }
    cout << ( c - ans + M) % M; 
}


Measured memory_bytes: 3328
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())

    cnt = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                total = 500 * a + 100 * b + 50 * c
                if total == X:
                    cnt += 1

    print(cnt)




main()

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

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    double max_nodo = -1.0;
    int max_water = 0;
    int max_suger = 0;

    for(int i_a = 0; i_a <= 110; i_a++){
        for(int i_b = 0; i_b <= 110; i_b++){
            for(int i_c = 0; i_c <= 110; i_c++){
                for(int i_d = 0; i_d <= 110; i_d++){
                    if(i_a * a * 100 + i_b * b * 100 + i_c * c + i_d * d <= f){
                        if(i_c * c + i_d * d <= e * (i_a * a + i_b * b)){
                            if((100 * (i_a * a + i_b* b) + i_c * c + i_d * d) == 0){
                                continue;
                            }
                            double tmp_nodo = (10000 * (i_c * c + i_d * d))/ (i_a * a * 100 + i_b * b * 100 + i_c * c + i_d * d);
                            if(tmp_nodo > max_nodo){
                                max_nodo = tmp_nodo;
                                max_water = i_a * a + i_b * b;
                                max_suger = i_c * c + i_d * d;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ((max_water*100) + max_suger) << " " << max_suger << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll g = __gcd(c, d);
    ll l = c * d / g;
    ll ans = b - a + 1;
    ans -= (b/c - a/c);
    if (a % c == 0) ans--;
    ans -= (b/d - a/d);
    if (a % d == 0) ans--;
    ans += (b/l - a/l);
    if (a % l == 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3576
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
sentinel = pow(10,9) + 1
def merge(target_list, left_index, mid_index,right_index):
    l = target_list[left_index:mid_index] + [sentinel]
    r = target_list[mid_index:right_index] + [sentinel]
    l_target = 0
    r_target = 0
    count = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1

    return count
    #print(target_list)
            
def merge_sort(target_list, left_index, right_index):
    count = 0
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        count += merge_sort(target_list, left_index, mid_index)
        count += merge_sort(target_list, mid_index, right_index)
        count += merge(target_list, left_index, mid_index,right_index)
        
    return count
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    count = merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)

Measured memory_bytes: 69048
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  int n,l;
  cin >> n >> l;
  vector<pint> v;
  int ans=0;
  for(int i=1;i<=n;i++){
    ans+=l+i-1;
    v.push_back({abs(l+i-1),i});
  }
  sort(v.begin(),v.end());
  cout << ans-(l+v[0].second-1) << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  ll t = 0;
  ll n = s.size();
  REP(i, n) t += s[i]-'0';
  if(t%9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3712
# -*- coding: utf-8 -*-
from bisect import bisect_left, insort
from math import pi
 
def inpl(): return tuple(map(int, input().split()))
sx, sy, gx, gy = inpl()
 
yrev = False
if sx > gx:
    sx, sy, gx, gy = gx, gy, sx, sy
 
if sy > gy:
    sy, gy = 10**8 - 1 - sy, 10**8 - 1 - gy 
    yrev = True
 
N = int(input())
fountains = []
 
for _ in range(N):
    x, y = inpl()
    if yrev:
        y = 10**8 - 1 - y
    if (sx <= x <= gx) & (sy <= y <= gy):
        fountains.append([x, y])

fountains.sort()
 
L = []
if len(fountains):
    L.append(fountains[0][1])
 
for f in fountains: # 最長増加部分列
    x, y = f
    if L[-1] < y:
        L.append(y)
    else:
        L[bisect_left(L, y)] = y
 
if min(gx - sx, gy - sy) + 1 == len(L):
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*(len(L)-1) + (10*pi - 20))
else:
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*len(L))

Measured memory_bytes: 38708
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, ll> pil;
#define mp make_pair

const ll INF = (ll)1e18;
const int N = 200200;
int n, m;
vector<pil> g[N];
bool used[N];
ll min1, min2;
ll val[N];

void read()
{
	int k;
	scanf("%d%d%d", &n, &m, &k);
	while(k--)
	{
		int v, u;
		ll x;
		scanf("%d%d%lld", &v, &u, &x);
		v--;
		u--;
		u += n;
		g[v].push_back(mp(u, x));
		g[u].push_back(mp(v, x));
	}
	return;
}

void dfs(int v)
{
	used[v] = 1;
	for (pil e : g[v])
	{
		int u = e.first;
		ll w = e.second - val[v];
		if (used[u])
		{
			if (w != val[u])
			{
				min1 = min2 = -INF;
			}
			continue;
		}
		val[u] = w;
		if (u < n)
			min1 = min(min1, w);
		else
			min2 = min(min2, w);
		dfs(u);
	}
	return;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	read();
	for (int i = 0; i < n; i++)
	{
		if (used[i]) continue;
		min1 = 0;
		min2 = INF;
		val[i] = 0;
		dfs(i);
		if (min1 + min2 < 0)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  rep(i,5){
    int a;cin>>a;
    if(a==0){
      cout<<i+1<<endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 3560
#include<stdio.h>
int main()
{
    int N,K,X,Y,sum1,sum2,sum;
    scanf("%d %d %d %d",&N,&K,&X,&Y);
    if (N<=K){
        sum=N*X;
    }
    else if(N>K){
        sum1=(N-K)*Y;
        sum2=K*X;
        sum=sum1+sum2;
    }
    printf("%d\n",sum);

    return 0;

}


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

using i64 = long long;
using P = pair<i64, i64>;


void solve(long long r){
    int a = 1;
    cout << r * r << endl;
}

int main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


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

int main(void)
{
	char s[11], t[11], u[11];
	int sNum, tNum;

	scanf("%s%s", s, t);
	scanf("%d%d", &sNum, &tNum);
	scanf("%s", u);

	/* s = uまたはt = u、かつsとtは異なるので、s = uとそれ以外に場合分けする */
	if (strncmp(s, u, 11) == 0)
	{
		sNum--;
	}
	else
	{
		tNum--;
	}

	printf("%d %d\n", sNum, tNum);

	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> V(N), C(N), A(N);
    REP(i, N){
    	cin >> V[i];
    }
    REP(i, N){
    	cin >> C[i];
    }
    REP(i, N){
    	A[i] = V[i] - C[i];
    }
    ll res = 0;
    REP(i, N){
    	if(A[i]>0) res += A[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define MN 200001
using namespace std;

const int MOD=1e9+7;
int n,m,a[MN],b[MN],A=0,B=0;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);sort(a+1,a+1+n);
	for (int i=1;i<=m;i++) scanf("%d",&b[i]);sort(b+1,b+1+m);
	for (int i=1;i<n;i++) A=(1LL*(a[i+1]-a[i])*i%MOD*(n-i)+A)%MOD;
	for (int i=1;i<m;i++) B=(1LL*(b[i+1]-b[i])*i%MOD*(m-i)+B)%MOD;
	printf("%lld\n",1ll*A*B%MOD);
}

Measured memory_bytes: 896
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pll >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}


const ll N =2e5+6;

ll arr[N],brr[N];
void solve(){
	int n;
	cin>>n;
	memset( arr,0,sizeof ( arr));
	for (int i=0;i<n;i++){
		ll aa;
		cin>>aa;
		brr[i]=aa;
		arr[aa]++;
	}
	ll total=0;
	for ( int i=1;i<=n;i++){
		total+=( arr[i]*( arr[i]-1)/2);
	}
	for ( int i=1;i<=n;i++){
		int j=brr[i-1];
		cout<<total+((arr[j]-1)* (arr[j]-2)/2)-(arr[j]*(arr[j]-1)/2)<<'\n';
	}
	cout<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	// #ifndef ONLINE_JUDGE
	// 	cin.tie(NULL);
	// 	freopen ("INPUT.txt" , "r" , stdin);
	// 	freopen ("OUTPUT.txt", "w" , stdout);
	// #endif	
    ll t=1;
   // cin>>t;
    for (ll i=1;i<=t;i++){
    //	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}

Measured memory_bytes: 6784
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N, Q = nm()
board = ns()
assert len(board) == N
spells = []
for i in range(Q):
    t, d = ns().split()
    spells.append((t, d))


def solve():
    head, tail = -1, N
    for i in range(Q - 1, -1, -1):
        t, d = spells[i]
        if d == "L":
            if head + 1 < N and t == board[head + 1]:
                head += 1
            if tail < N and t == board[tail]:
                tail += 1
        if d == "R":
            if tail - 1 >= 0 and t == board[tail - 1]:
                tail -= 1
            if head >= 0 and t == board[head]:
                head -= 1
    return N - (head + 1) - (N - tail)


print(solve())


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

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	int a[m];
	REP(i,m) cin >> a[i];
	int cnt = 0;
	REP(i,m){
		if(a[i] < x)cnt++;
	}
	cout << min(cnt, m - cnt) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int R, G;
    cin >> R >> G;
    cout << G * 2 - R;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int ans = 0;
		for(int i = 0; i < n-1; i++) {
			ans += a[i];
		}
		ans += a[n-1]/2;
		System.out.println(ans);
		sc.close();
	}

}


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

const long long INFF = 1e18;

const int MAX_N = 11000;
using TYPE = long long; // ?????¢???????????\??????
vector<pair<int, TYPE> > G[MAX_N];

vector<TYPE> dijkstra(int start){
	vector<TYPE> dist(MAX_N, INFF);
	dist[start] = 0;//dist[i] :=???start->i?????§??????????????¢
	priority_queue<pair<TYPE, int>, vector<pair<TYPE, int> >, greater<pair<TYPE, int> > >  que;
	que.push(make_pair(0, start));
	while(!que.empty()){
		TYPE cost; int u;//????????§???????????£????????? ?????¨?????????
		cost = que.top().first, u = que.top().second;
		que.pop();
		if(dist[u] < cost) continue;
		for (auto tmp : G[u]){
			int v = tmp.first; TYPE time = tmp.second;//??£??\???????????? ?????????????????§????????????
			if(dist[v] > dist[u] + time){//u->v
				// if(dist[v] != INFF) printf("%f %fa\n", dist[v], dist[u] + time);
				dist[v] = dist[u] + time;
				que.push(make_pair(dist[v], v));
			}
		}
	}
	return dist;
}


int main(void) {
	int n; cin >> n;
	rep(q, n) {
		int u, k; cin >> u >> k;
		vector<int> v(k); vector<long long> c(k);
		rep(i, k) cin >> v[i] >> c[i];
		rep(i, k) G[u].push_back(make_pair(v[i], c[i]));
	}
	auto dist = dijkstra(0);
	rep(i, n) printf("%d %d\n", i, dist[i]);
	return 0;
}

Measured memory_bytes: 12176
n = int(input())
a = [int(input()) for i in range(n)]

a_max = max(a)
idx = [i for i, x in enumerate(a) if x==a_max]

if len(idx) > 1:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if a[i] == a_max:
            print(max(a[0:i]+a[i+1:]))
        else:
            print(a_max)

Measured memory_bytes: 20456
n,m = gets.chomp.split(" ")
n = n.to_i
m = m.to_i
h = gets.chomp.split(" ")
for i in 0..m-1 do
  n = n - h[i].to_i
  if n<0 then
    puts(-1)
    return
  end
end
puts(n)

Measured memory_bytes: 14692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=2e5+5;
int n,k,ans[N];
int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int x;scanf("%d",&x);
        ans[x]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
}


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

using namespace std;

int n;

const long long MOD=998244353;

long long add_mod(long long x,long long y){
	return (x+y)%MOD;
}

long long sub_mod(long long x,long long y){
	return (x-y+MOD)%MOD;
}

long long mul_mod(long long x,long long y){
	return x*y%MOD;
}

void solve(){
    int i,j,k;
    string str;
    cin >> n;
    cin >> str;
    long long ans = 0;
    for(i = 0;i < str.length();i++){
        ans = mul_mod(ans,2);
        if(str[i] == '1'){
            ans++;
        }
    }
    ans++;
    ans = mul_mod(ans,2*n);
    vector<pair<int,long long> > vfa;
    if(n%2) i=n; else i=n-1;
    for(;i > 2;i-=2){
        if(n%i == 0){
            int s = n/i;
            long long sv = 0;
            string os = str.substr(0,s);
            string es = str.substr(0,s);
            for(j = 0;j < s;j++){
                if(os[j]=='1') os[j] = '0';
                else os[j] = '1';
            }
            for(j = 0;j < s;j++){
                sv = mul_mod(sv,2);
                if(str[j] == '1') sv++;
            }
            sv++;
            for(j = s;j < n;j+=s){
                if((j/s)%2){
                    k = str.compare(j,s,os);
                }
                else{
                    k = str.compare(j,s,es);
                }
                if(k < 0) sv--;
                if(k != 0) break;
            }
            for(j = 0;j < vfa.size();j++){
                if(vfa[j].first%i==0){
                    sv -= vfa[j].second;
                }
            }
            ans = sub_mod(ans,mul_mod(sv,2*(n-s)));
            vfa.push_back(make_pair(i,sv));
        }
    }
    cout << ans << endl;
}

int main(){
    solve();
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("hard1.txt","r",stdin)
#define OUT freopen("hard1.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 1000005
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii ;

#define maxn 1000005
#define mod 1000000007LL
#define lim 1000000000
#define INF 4500000000000000000LL

vector <int> g[maxn] ;
vector <i64> e[maxn] ;

int n ;
int sub[maxn] ;

i64 ans = 0 ;

void dfs(int u, int par)
{
    sub[u] = 1 ;
    for(int i=0 ; i<g[u].size() ; i++)
    {
        int v = g[u][i] ;
        if(v==par) continue ;

        dfs(v,u) ;
        if( 2*sub[v] == n ) ans += ( 1LL*(2*sub[v]-1)*e[u][i] ) ;
        else ans += ( 2LL*min(n-sub[v],sub[v])*e[u][i] ) ;

        sub[u] += sub[v] ;
    }
}

int findCentroid(int u, int par)
{
    for(int v: g[u])
    {
        if(v==par) continue;
        if( sub[v] > n/2 ) return findCentroid(v,u) ;
    }
    return u ;
}



int main()
{
    scanf("%d",&n) ;
    for(int i=1 ; i<n ; i++)
    {
        int u , v ; i64 c ;
        scanf("%d %d %lld",&u,&v,&c) ;
        g[u].pb(v) ; g[v].pb(u) ;
        e[u].pb(c) ; e[v].pb(c) ;
    }

    dfs(1,0) ;

    int c = findCentroid(1,0) ;

    ans = 0 ;
    dfs(c,0) ;

    int fl = 0 ;
    i64 mn = INF ;

    for(int i=0 ; i<g[c].size() ; i++)
    {
        int v = g[c][i] ;
        if( 2*sub[v] == n ) fl = 1 ;
        mn = min( mn , e[c][i] ) ;
    }

    if( !fl ) ans -= mn ;

    printf("%lld\n",ans) ;

    return 0 ;
}


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

const int N = 105;

set<int> adj[N];
vector<pair<int, int> > vec;
int n, m;
bool visited[N];

void ddfs(int u) {
  visited[u] = true;
  for (int v : adj[u]) if (!visited[v]) ddfs(v);
}

int dfs() {
  for (int i = 0; i < N; i++) {
    visited[i] = false;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      cnt++;
      ddfs(i);
    }
  }
  return cnt;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v;
    vec.push_back({u, v});
    adj[u].insert(v);
    adj[v].insert(u);
  }
  int num = dfs();
  int ans = 0;
  for (auto p : vec) {
    adj[p.first].erase(p.second);
    adj[p.second].erase(p.first);
    int cnt = dfs();
    if (cnt > num) ans++;
    adj[p.first].insert(p.second);
    adj[p.second].insert(p.first);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invL(s, a, n):
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L

class Comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD



N, A, B, C = list(map(int, input().split()))
MOD = 10 ** 9 + 7
com = Comb(2 * N, MOD)
inv = Inv(MOD)
IL = inv.invL(A + B, 2 * N)
IC = inv.invx(100 - C)
PA = [1] * (N + 1)
PB = [1] * (N + 1)
for i in range(1, N + 1):
  PA[i] = PA[i - 1] * A % MOD
  PB[i] = PB[i - 1] * B % MOD

ans = 0
for i in range(N):
  ans = ans + (N + i) * IC * 100 * PA[N] * PB[i] * IL[N + i] * com.com(N + i - 1, i) % MOD
  ans = ans + (N + i) * IC * 100 * PB[N] * PA[i] * IL[N + i] * com.com(N + i - 1, i) % MOD

print(ans % MOD)

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

int main() {
  int h1, h2, m1, m2, k;
  cin >> h1 >> h2 >> m1 >> m2 >> k;
  int start = h1 * 60 + h2;
  int end = m1 * 60 + m2;
  cout << end - start - k << endl;

  return 0;
}

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

using namespace std;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;

#define PI 3.14159265358979323846

double solve() {
    int A, B, H, M; cin >> A >> B >> H >> M;
    double angle = 30 * H - 5.5 * M;
    if (angle < 0.0) {
        angle += 360.0;
    }
    if (angle > 180.0) {
        angle = 360.0 - angle;
    }
    double res = sqrt(A*A + B*B - 2 * A * B * cos(angle * PI / 180.0));
    return res;
}

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

	cout << std::setprecision(10) << solve() << endl;
}


Measured memory_bytes: 4144
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	N, M := nextInt(), nextInt()
	// a, b := 1, 2
	if N%2 == 1 {
		for i := 1; i <= M; i++ {
			fmt.Println(i, N+1-i)
		}
	} else {
		for i := 1; i <= M; i++ {
			if i <= N/4 {
				fmt.Println(i, N+1-i)
			} else {
				fmt.Println(i+1, N+1-i)
			}
		}
	}

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    ll h,n,A[200001];
    cin>>h>>n;
    rep(i,n) cin>>A[i];
    ll sum=0;
    rep(i,n) sum+=A[i];
    if(sum>=h) cout<<"Yes";
    else cout<<"No";
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin >> s;
	sort (s.begin(),s.end());
	cout << (s=="abc"?"Yes":"No")<<endl;
	return 0;
}


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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e5 + 1;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

int fastmod(int e, int x) {
    int res = 1;
    e %= mod;
    if (e == 0) return 0;
    while (x > 0) {
        if (x & 1) res = (res * e) % mod;
        x >>= 1;
        e = (e * e) % mod;
    }
    return res;
}

int32_t main() {
    IOS int Q = 1;
    // cin >> Q;
    while (Q--) {
        int n;
        cin >> n;
        int temp = (n * (n - 1)) % mod;
        int ans = (fastmod(10, n) - 2*fastmod(9,n) + fastmod(8, n))%mod;
        ans = (ans+mod)%mod;
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

#define endl "\n"
typedef long long ll;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
inline void setPrecision(int n){cout.precision(n);}

ll INF = 1e10;
ll MOD = 1e9+7;

int n;
int a[21][21];

ll done[1<<21];

ll pairs(int state){
    int idx = __builtin_popcount(state);
    if(idx == n) return 1;
    if(done[state] != -1) return done[state];
    ll ans = 0;
    for(int i=0;i<n;++i)
        if(a[idx][i] && !(state&(1<<i)))
            ans = (ans + pairs(state|(1<<i)))%MOD;
    done[state] = ans;
    return ans;
}

int main(){
    fastio;
    cin>>n;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            cin>>a[i][j];
    memset(done, -1, sizeof(done));
    cout<<pairs(0);
    return 0;
}


Measured memory_bytes: 20020
#include<iostream>
#include<map>
#include<algorithm>
#include<numeric>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin>>N;
    long  numerator=1,denominator=1;
    long  tmpd;
	double ans=0;

    for (int i = 0; i < N; i++)
    {
    long  tmpn=1;

        cin>>tmpd;
		ans+=1.0/tmpd;

    }
    

  
    printf("%.6f\n",1/ans);

}


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

struct Point{
  double x,y;
};

void koch(int n,struct Point a,struct Point b){
  if(n==0)return;
  struct Point s,t,u;
  double th=M_PI*60.0/180.0;

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  struct Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}
  



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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int LOGN = 30;
const int BUF = 2100;
const int PWS = 2000;
const int ZERO = 3000;

bool read () {
	if (false)
		return false;
	return true;
}

void repr(int num, int pos){
	int BUF2 = BUF + 100;
	int BUF3 = BUF2 + 100;
	printf("< %d %d %d\n", BUF2, ZERO, BUF2);
	for (int i = LOGN - 1; i >= 0; --i){
		printf("+ %d %d %d\n", PWS + i, BUF2, BUF);
		printf("< %d %d %d\n", num, BUF, BUF);
		printf("< %d %d %d\n", BUF, PWS, BUF);
		printf("+ %d %d %d\n", BUF, ZERO, pos + i);
		printf("+ %d %d %d\n", pos + i, PWS + i, BUF3);
		printf("< %d %d %d\n", PWS + i, BUF3, BUF3);
		forn(j, i) printf("+ %d %d %d\n", BUF3, BUF3, BUF3);
		printf("+ %d %d %d\n", BUF2, BUF3, BUF2);
	}
}

void solve() {
	int a_bits = 100;
	int b_bits = 200;
	int ab_bits = 300;
	
	puts("30123");
	printf("+ 0 1 %d\n", PWS);
	printf("< %d %d %d\n", ZERO, PWS, PWS);
	fore(i, 1, LOGN) printf("+ %d %d %d\n", PWS + i - 1, PWS + i - 1, PWS + i);
	repr(0, a_bits);
	repr(1, b_bits);
	//printf("? %d %d %d\n", a_bits, a_bits + LOGN, 0);
	//printf("? %d %d %d\n", b_bits, b_bits + LOGN, 0);
	forn(i, LOGN) forn(j, LOGN){
		int pos = ab_bits + i * LOGN + j;
		printf("+ %d %d %d\n", a_bits + i, b_bits + j, pos);
		printf("< %d %d %d\n", PWS, pos, pos);
		forn(k, i + j) printf("+ %d %d %d\n", pos, pos, pos);
		printf("+ 2 %d 2\n", pos);
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	if(read()) {
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 3732
X, K, D = map(int, input().split())


def Repetition(X, K, D):
    if K%2 == 0:
        return X
    else:
        return abs(abs(X) - D)

X = abs(X)
if X < D:
    print(Repetition(X, K, D))
    exit()

n = X//D
if n >= K:
    print(X - D*K)
else:
    X = X - D*n
    K = K - n
    print(Repetition(X, K, D))




Measured memory_bytes: 9092
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 105 A "AtCoder Crackers"
 *   https://abc105.contest.atcoder.jp/tasks/abc105_a/
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		Task task = new Task();
		task.run(in, out);

		in.close();
		out.close();
	}

	static class Task {

		public void run(InputScanner in, PrintWriter out) {

			int N = in.nextInt();
			int K = in.nextInt();
			
			if (N % K == 0) {
				out.println("0");
			} else {
				out.println("1");
			}
		
		}
	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner {

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public boolean hasNext() {
			return scanner.hasNext();
		}

		public int nextInt() {
			return Integer.parseInt(scanner.next());
		}

		public long nextLong() {
			return Long.parseLong(scanner.next());
		}

		public double nextDouble() {
			return Double.parseDouble(scanner.next());
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public int[][] nextIntArray(int h, int w) {
			int[][] ret = new int[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextInt();
				}
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public long[][] nextlongArray(int h, int w) {
			long[][] ret = new long[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public double[] nextDoubleArray(int n) {
			double[] ret = new double[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextDouble();
			}
			return ret;
		}

		public double[][] nextDoubleArray(int h, int w) {
			double[][] ret = new double[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String split) {
			String[] ret = scanner.next().split(split);
			return ret;
		}

		public String[][] nextStringArray(int h, int w) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.next();
				}
			}
			return ret;
		}

		public String[][] nextStringArray(int h, String split) {
			String[][] ret = new String[h][];
			for (int i = 0; i < h; i++) {
				ret[i] = scanner.next().split(split);
			}
			return ret;
		}

		public void close() {
			scanner.close();
		}

	}

}


Measured memory_bytes: 21972
#include <iostream>
using namespace std;
int main(void){
    int n,y;
    cin >> n >> y;
    
    int total = 0;
    for(int man=0;man<=n;man++){
        for(int gosen=0;gosen<=(n-man);gosen++){
            int sen = (n - man - gosen);
            total = (10000 * man) + (5000 * gosen) + (1000 * sen) ;
            if(total == y) {
                cout << man << " " << gosen << " " << sen << endl;
                return 0;
            }
        }
    }
    
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<deque>
 
using namespace std;
typedef long long ll;
 
int main(void)
{
    int N;
    cin >> N;

    vector<ll> d(N);
    for(int i = 0; i < N; i++)
    {
        cin >> d[i];
    }

    sort(d.begin(), d.end());

    if(N % 2 == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    if(d[N/2 - 1] != d[N/2])
    {
        cout << d[N/2] - d[N/2 - 1] << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
}

Measured memory_bytes: 1024