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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

void Main() {
	ll N, M; cin >> N >> M;
	vvll dp(3*N+1, vll(4*N+1, 0));
	dp[0][N] = 1;

	for (int i = 0; i < 3*N; i++) {
		for (int j = 0; j < 4*N; j++) {
			//3
			if (i < 3*N-2) (dp[i+3][j] += dp[i][j] * (3*N-i-1) % M * (3*N-i-2)) %= M;
			//2
			if (i < 3*N-1 && j > 0) (dp[i+2][j-1] += dp[i][j] * (3*N-i-1)) %= M;
			//1
			(dp[i+1][j+1] += dp[i][j]) %= M;
		}
	}
	ll sum = 0;
	for (int i = N; i <= 4*N; i++) {
		(sum += dp[3*N][i]) %= M;
	}
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}

Measured memory_bytes: 375680
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,b) for (ll i=a;i<=ll(b);i++)
using namespace std;
ll ctoi(const char c){if('0'<=c&&c<='9') return (c-'0');return -1;}
#define ALL(x) begin(x),end(x)
  
int main(){
  ll n,m; cin >> n >> m;
  vector<pair<ll,ll>> v;
  rep(i,n){
    ll a,b; cin >> a >> b;
    v.push_back(make_pair(a,b));
  }
  sort(ALL(v));
  
  ll purchaseNum = m;
  ll sum = 0;
  rep(i,n){
    if(purchaseNum>=v[i].second) sum += v[i].first*v[i].second;
    else sum += v[i].first*purchaseNum;
    purchaseNum -= v[i].second;
    if(purchaseNum<=0) break;
  }
  cout << sum << endl;
} 

Measured memory_bytes: 5292
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

class ArticulationPoints {
public:
	ll V;
	vector<vector<ll>> G;
	vector<ll> prenum, parent, lowest;
	vector<int> visited;
	set<ll> AP;
	ll timer;

	ArticulationPoints(ll V) :V(V){
		prenum.assign(V, 0); parent.assign(V, -1); lowest.assign(V, -1);
		visited.assign(V, 0);
		G.resize(V);
	}

	void add_edge(ll u, ll v, bool undirected = false) {
		G[u].emplace_back(v);
		if (undirected) {
			G[v].emplace_back(u);
		}
	}

	void dfs(ll u, ll rev) {
		prenum[u] = lowest[u] = timer++;
		visited[u] = 1;
		for (auto v : G[u]) {
			if (visited[v] == 0) {
				parent[v] = u;
				dfs(v, u);
				lowest[u] = min(lowest[u], lowest[v]);
			}
			else if (v != rev) {
				lowest[u] = min(lowest[u], prenum[v]);
			}
		}
	}

	void depthFirstSearchScheme() {
		for (int i = 0; i < V;i++)visited[i] = 0;
		ll root = 0;
		timer = 1;

		// lowest????¨????
		dfs(root, -1);
	}

	void solve() {
		AP.clear();

		ll cnt = 0;
		for (int i = 0; i < V;i++) {
			if (parent[i] == 0)cnt++;
			if (cnt >= 2) {
				AP.insert(0); break;
			}
		}
		for (int i = 1; i < V;i++) {
			for (ll v : G[i]) {
				ll p = parent[v];
				if (p > 0) {
					if (prenum[p] <= lowest[v])AP.insert(p);
				}
			}
		}
	}

	set<ll> get_AP() const { return AP; }
};

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll V, E; cin >> V >> E;
	ArticulationPoints ap(V);
	for (int i = 0; i < E;i++) {
		ll s, t; cin >> s >> t;
		ap.add_edge(s, t, true);
	}

	ap.depthFirstSearchScheme();
	ap.solve();
	
	auto ans = ap.get_AP();
	for (auto x : ans) {
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 4960
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut a: Vec<i64> = (0..n).map(|_| input()).collect();
    a.sort_by_key(|a| -a);

    let mut b = vec![];
    let mut i = 0;
    while i < n {
        let mut cnt = 0;
        let cur = a[i];
        while i < n && a[i] == cur {
            cnt += 1;
            i += 1;
        }
        if cnt >= 4 {
            b.push(cur);
            b.push(cur);
        } else if cnt >= 2 {
            b.push(cur);
        }
    }

    println!("{}", if b.len() >= 2 { b[0] * b[1] } else { 0 });
}


Measured memory_bytes: 6396
#include <stdio.h>

int main(){
  int H,W,N;
  scanf("%d\n%d\n%d",&H,&W,&N);
  if(H<W) H=W;
  int c=0;
  while(N>0){
    N-=H;
    c++;
  }
  
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int x = h + w - 1;
        int[][] a = new int[h][w];
        int[][] b = new int[h][w];
        int[][] d = new int[h][w];
        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                b[i][j] = sc.nextInt();
            }
        }
        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                d[i][j] = Math.abs(a[i][j] - b[i][j]);
            }
        }
        int m = x * 80;
        int n = m * 2 + 1;
        boolean[][] prev = new boolean[w][x * 80 * 2 + 1];
        boolean[][] next;
        prev[0][m + d[0][0]] = true;
        prev[0][m - d[0][0]] = true;
        for(int j=1; j<w; j++) {
            for(int k=0; k<n; k++) {
                if(prev[j-1][k]) {
                    prev[j][k+d[0][j]] = true;
                    prev[j][k-d[0][j]] = true;
                }
            }
        }
        for(int i=1; i<h; i++) {
            next = new boolean[w][x * 80 * 2 + 1];
            for(int j=0; j<w; j++) {
                for (int k = 0; k < n; k++) {
                    if (prev[j][k]) {
                        next[j][k + d[i][j]] = true;
                        next[j][k - d[i][j]] = true;
                    }
                }
                if (j > 0) {
                    for (int k = 0; k < n; k++) {
                        if (next[j - 1][k]) {
                            next[j][k + d[i][j]] = true;
                            next[j][k - d[i][j]] = true;
                        }
                    }
                }
            }
            prev = next;
        }

        int res = m;
        for(int k=0; k<n; k++) {
            if(prev[w-1][k]) {
                res = Math.min(res, Math.abs(k-m));
            }
        }

        System.out.println(res);


    }


}




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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> ans(N, -1);
    rep(i, 0, M){
        int s, c;
        cin >> s >> c;
        if(ans.at(s - 1) != -1){
            if(ans.at(s - 1) != c){
                cout << -1 << endl;
                return 0;
            }
        }
        else{
            ans.at(s - 1) = c;
        }
    }
    int sum = 0;
    rep(i, 0, N){
        if(ans.at(i) == -1){
            if(i == 0 && N != 1){
                ans.at(i) = 1;
            }
            else{
                ans.at(i) = 0;
            }
        }
        sum += pow(10, N - i - 1) * ans.at(i);
    }
    if(to_string(sum).size() != N) cout << - 1<< endl;
    else cout << sum << endl;
}


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

int main()
{
  string s;
  cin >> s;
  if (s == "Sunny")
  {
    printf("Cloudy\n");
  }else if(s == "Cloudy"){
    printf("Rainy\n");
  }else if(s == "Rainy"){
    printf("Sunny\n");
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
ls_a = list(map(int, input().split()))

ls_cnt = [0] * n

for i in range(n):
    for j in range(2**10):
        if ls_a[i] % 2 == 0:
            ls_a[i] = ls_a[i] / 2
            ls_cnt[i] += 1
        else:
            break

print(min(ls_cnt))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		
		Scanner input = new Scanner(System.in);
		int numberOfDatasets = input.nextInt();
		
		for(int i = 0; i < numberOfDatasets; i++) {
			
			String first = input.next();
			String second = input.next();
			
			System.out.println(compare(first, second));
			
		}
		
	}
	
	public static int compare(String first, String second) {
		
		String firstBlank = " " + first;
		String secondBlank = " " + second;
		
		int length1 = firstBlank.length();
		int length2 = secondBlank.length();
		
		
		int[][] LCS = new int[length1][length2];
		
		for(int i = 1; i < length1; i++) {
			
			for(int j = 1; j < length2; j++) {
				
				char one = firstBlank.charAt(i);
				char two = secondBlank.charAt(j);
				
				if(one == two) {
					
					LCS[i][j] = 1 + LCS[i - 1][j - 1];
					
				}else {
					
					LCS[i][j] = Math.max(LCS[i-1][j], LCS[i][j-1]);
					
				}
				
			}
			
		}
		
		
		return LCS[length1 - 1][length2 - 1];
		
	}

}



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

bool judge_Yes_1char(char a, bool odd) {
	if (odd) {
		if (a == 'R' || a == 'U' || a == 'D') return true;
	}
	else {
		if (a == 'L' || a == 'U' || a == 'D') return true;
	}

	return false;
}

int main() {

	string S;
	cin >> S;

	for (unsigned int i = 0; i < S.size(); i++) {
		if (judge_Yes_1char(S.at(i), i % 2 == 0) == false) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int N, T;
    cin >> N >> T;
    int ans = 1e9;
    rep(i, 0, N) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            ans = min(ans, c);
        }
    }

    if (ans == 1e9) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
	int A,B,C;
	cin>>A>>B>>C;
	if(A==5&&B==5&&C==7)
	{
		cout<<"YES"<<endl;
	} 
	
	else if (A==5&&B==7&&C==5)
	{
		cout<<"YES"<<endl;
	}
	else if(A==7&&B==5&&C==5)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl; 
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(ALL(a));
    int m = *max_element(ALL(a));
    int d1 = 0, d2 = 0;
    int k = (m % 2 == 0 ? m / 2 : (m + 1) / 2);
    rep(i, n)
    {
        if (a[i] <= k)
        {
            d1 = a[i];
        }
        else
        {
            d2 = a[i];
            break;
        }
    }
    int ans;
    if (d1 < m - d2)
        ans = d2;
    else
        ans = d1;
    cout << m << " " << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =2e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }

	  
	 void solve() {		 
			int n,m;
			cin>>n>>m;
			int sm=0;
			sm+=(n*(n-1))/2;
			sm+=(m*(m-1))/2;
		
			cout<<sm<<endl;
	     
	   
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

typedef long long ll;
using namespace std;

int main() {

    string S;
    cin >> S;
    string non_x;
    int size_S = S.size();
    for (int i = 0; i < size_S; i++) {
        if (S[i] != 'x') non_x.push_back(S[i]);
    }

    bool isPalindrome = true;
    int size_non_x = non_x.size();
    for (int i = 0; i < size_non_x / 2; i++) {
        if (non_x[i] != non_x[size_non_x - i - 1]) isPalindrome = false;
    }

    if (!isPalindrome) {
        cout << -1 << '\n';
        return 0;
    }
    
    int ind_non_x = 0;
    vector<int> cnt_x;
    int temp = 0;
    for (int i = 0; i < size_S; i++) {
        if (S[i] == 'x') {
            temp++;
        }
        else {
            cnt_x.push_back(temp);
            ind_non_x++;
            temp = 0;
        }
    }
    cnt_x.push_back(temp);

    int ans = 0;
    int size_cnt_x = cnt_x.size();
    for (int i = 0; i < size_cnt_x / 2; i++) {
        ans += abs(cnt_x[i] - cnt_x[size_cnt_x - 1 - i]);
    }
    cout << ans << '\n';

}


Measured memory_bytes: 1216
N = int(input())
A = []

for i in range(N):
    A.append(int(input()))

A = sorted(A)

B = [0] * N
m = int(N/2)
B[m] = A[0]

si = 1
bi = 0
ci = 1

for i in range(1, N):
    si *= -1
    ii = int(i/2 + 0.5)

    if i % 4 == 1 or i % 4 == 2:
        B[m+si*ii] = A[N-bi-1]
        bi += 1
    if i % 4 == 3 or i % 4 == 0:
        B[m+si*ii] = A[ci]
        ci += 1

C = [0] * N
m = int(N/2)
C[m] = A[N-1]

si = 1
bi = 1
ci = 0

for i in range(1, N):
    si *= -1
    ii = int(i/2 + 0.5)

    if i % 4 == 1 or i % 4 == 2:
        C[m+si*ii] = A[ci]
        ci += 1
    if i % 4 == 3 or i % 4 == 0:
        C[m+si*ii] = A[N-bi-1]
        bi += 1

cntB = 0
cntC = 0
for i in range(N-1):
    cntB += abs(B[i] - B[i+1])
    cntC += abs(C[i] - C[i+1])


print(max(cntB, cntC))


Measured memory_bytes: 8544
n = int(input())
while n >= 10:
    n = n % 10

if n == 2 or n==4 or n == 5 or n==7 or  n== 9:
    print('hon')
elif n == 0 or n==1 or n == 6 or n==8:
    print('pon')
elif n== 3:
    print('bon')

Measured memory_bytes: 9180
lis = list(input())
n=len(lis)

a = 0
for i in range(0,n,2):
  if lis[i] == "L":
    a+=1

for i in range(1,n,2):
  if lis[i] == "R":
    a+=1

if a == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
n = gets.to_i
rooms = Array.new(4){Array.new(3){Array.new(10, 0)}}
n.times do
  b,f,r,v= gets.split.map(&:to_i)
  rooms[b-1][f-1][r-1] += v
end

puts rooms.map{|x|x.map{|y|' '+y.join(' ')}.join("\n")}.join("\n"+"#"*20+"\n")




Measured memory_bytes: 6892
import java.util.*;
public class Main {
  public static int sumDigits(int c){
  	int sum = 0;
        //自然数の各桁の和を計算
        while(c > 0){
          //最右端のけたの獲得
          sum += c % 10;
          //最右端の桁を取り除く
          c = c / 10;
        }
    return sum;
  }
  
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
	  //整数の上限 
      int n= sc.nextInt();
      //和の下限
      int a = sc.nextInt();
      //和の上限
      int b = sc.nextInt();
      
      int total = 0;
      
      for(int i = 1; i <= n; i++){
        int sum = sumDigits(i);
        if(sum >= a && sum <= b){
          total += i;
        }
      }
      System.out.print(total);
    }
}

Measured memory_bytes: 21844
program main
	implicit none
    integer::a,b,m,min2,i,x,y,z
    integer::min1
    integer,allocatable::c(:),d(:)
    read(*,*) a,b,m
    min2=200000
    allocate(c(a))
    allocate(d(b))
    read(*,*) c
    read(*,*) d
    
    min1=minval(c)+minval(d)
    do i=1,m
    	read(*,*) x,y,z
        if(c(x)+d(y)-z<min2)then
        	min2=c(x)+d(y)-z
        end if
    end do
    
    if(min1<min2)then
    	write(*,*) min1
    else
    	write(*,*) min2
    end if
    deallocate(c)
    deallocate(d)
    
    stop
end program main


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    2019;
vector<int> g[N];
int n,m;
int arr[N];
int main()
{  fast
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>arr[i];
  for(int i=1;i<=m;i++)
  {
  	int x,y;
  	cin>>x>>y;
  	g[x].emplace_back(y);
  	g[y].emplace_back(x);
  }
  int ans=0;
  for(int i=1;i<=n;i++)
  {
	bool bo=true;
	for(auto x: g[i])
	if(arr[x]>=arr[i])
	bo=false;
	ans+=(bo==true);
  }
  cout<<ans;

}


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

signed main () {
    int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector < int > val = {a, b, c};
	vector < string > q(n);
	for (int i = 0; i < n; ++i)
		cin >> q[i];
	string ans;
	for(int i = 0; i < n; ++i) {
		int v1 = q[i][0] - 'A', v2 = q[i][1] - 'A';
		if(val[v1] == 0 && val[v2] == 0) {
			cout << "No" << endl;
			return 0;
		}
		if (val[v1] == 1 && val[v2] == 1) {
			if (i + 1 < n) {
				int v11 = q[i + 1][0] - 'A', v22 = q[i + 1][1] - 'A';
				if (v11 == 3 - v1 - v2 || v22 == 3 - v1 - v2){
					if (v22 == v1 || v11 == v1)
						ans += (char)(v1 + 'A'), val[v1]++, val[v2]--;
					else
						ans += (char)(v2 + 'A'), val[v2]++, val[v1]--;
				}
				else
					ans += (char)(v1 + 'A'), val[v1]++, val[v2]--;
			}
			else
				ans += (char)(v1 + 'A'), val[v1]++, val[v2]--;
		}
		else if (val[v1] > val[v2])
			val[v1]--, val[v2]++, ans += (char)(v2 + 'A');
		else
			val[v2]--, val[v1]++, ans += (char)(v1 + 'A');
	}
	cout << "Yes" << '\n';
	for(auto i: ans)
		cout << i << '\n';
}


Measured memory_bytes: 6708
#include<stdio.h>
int ab (int a,int i);
int main(void)
{
    int a,b,i,j,A[5],B[5],hit,blow;
    while(1){
        scanf("%d%d",&a,&b);
        if(a==0&&b==0)break;
        hit=0,blow=0;
        for(i=0;i<4;i++){
            A[i]=ab(a,i);
            B[i]=ab(b,i);
        }
        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                if(A[i]==B[j]){
                    if(i==j){
                        hit++;
                    }
                    else blow++;
                }
            }
        }
        printf("%d %d\n",hit,blow);
    }
    return 0;
}

int ab (int a,int i)
{
    if(i==0){
        return a/1000;
    }
    else if(i==1){
        return a%1000/100;
    }
    else if(i==2){
        return a%1000%100/10;
    }
    else if(i==3){
        return a%10;
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	ll n; cin >> n;
	cout << n*(n-1)/2 << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int mod = 1e9 + 7;
const int maxM = 2e5 + 7;
const int maxN = 8e3 + 7;
const int N = 2000;

inline int pls(int x, int y) {return (x + y) % mod;}
inline int mns(int x, int y) {return pls(x, mod - y);}
inline int mul(int x, int y) {return 1LL * x * y % mod;}
inline void Add(int &x, int y) {x = pls(x, y);}
inline void Mul(int &x, int y) {x = mul(x, y);}
inline void Minus(int &x, int y) {x = mns(x, y);}
inline int pwr(int x, int tms) {
	int res = 1;
	for (; tms > 0; tms >>= 1) {
		if (tms & 1) Mul(res, x);
		Mul(x, x);
	}
	return res;
}
inline int inv(int x) {return pwr(x, mod - 2);}

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, A[maxM], B[maxM];
int fac[maxN], ifac[maxN], iv[maxN];
int f[maxN][maxN];

void init() {
	iv[1] = 1; For (i, 2, maxN) iv[i] = mul(mod - mod / i, iv[mod % i]);
	fac[0] = 1; For (i, 1, maxN) fac[i] = mul(fac[i - 1], i);
	ifac[0] = 1; For (i, 1, maxN) ifac[i] = mul(ifac[i - 1], iv[i]);
}

inline int C(int x, int y) {return (y <= x) ? mul(mul(fac[x], ifac[y]), ifac[x - y]) : 0;}

inline int ways(int x, int y) {return C(x + y, x);}

int main() {
	
	init();

	n = ri();
	rep (i, 1, n) A[i] = ri(), B[i] = ri();

	rep (i, 1, n) ++f[N - A[i]][N - B[i]];
	rep (i, 0, N << 1) rep (j, 0, N << 1) {
		if (i > 0) Add(f[i][j], f[i-1][j]);
		if (j > 0) Add(f[i][j], f[i][j-1]);
	} 

	int res = 0;
	rep (i, 1, n) Add(res, f[N + A[i]][N + B[i]]);
	rep (i, 1, n) Minus(res, ways(A[i] << 1, B[i] << 1));
	Mul(res, iv[2]);

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

	return 0;
}


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

int main() {
  ll n,m,mod=1000000007;
  cin >> n >> m;
  if(n==1) {
    cout << (m+1)%mod << endl;
    return 0;
  }
  m++;
  ll k=ceil((double)m/(n-1));
  n%=mod;
  m%=mod;
  ll x=(2+(k-1)*2)/2%mod*(k%mod)%mod;
  ll y=((2+(k-1)*2)/2%mod*(k%mod)%mod-(2+(k-2)*2)/2%mod*((k-1+mod)%mod)%mod+mod)%mod;
  ll ans=(x*((n-1+mod)%mod)%mod-y*(k%mod*((n-1+mod)%mod)%mod-m+mod)%mod+mod)%mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string a = "CODEFESTIVAL2016",b;
	cin >> b;
	int x = 0;
	rep(i,b.size()){
		x += a[i] != b[i];
	}
	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		//int z = b - a;
		int cnt = 0;
		for (int i = a; i <= b; i++) {
		    if (c % i == 0) {
		        cnt++;
		    }
		    
		}
		System.out.println(cnt);
    }
}


Measured memory_bytes: 26336
r, g, b, n = map(int, raw_input().split())
count = 0
for i in xrange(n+1):
    if i*r > n:
        break	
    for j in xrange(n+1):
        if i*r + j*g > n:
            break
        if (n- i*r - j*g) % b == 0:
      		count += 1
print count

Measured memory_bytes: 2568
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N,D;
    cin>>N>>D;
    vector<vector<int>> X(N,vector<int>(D,0));
    REP(i,N){
        REP(j,D){
            cin>>X[i][j];
        }
    }
    int counter;
    REP(i,N-1){
        REPi(j,i+1,N){
            double dist=0;
            REP(k,D){
                dist+=pow(X[i][k]-X[j][k],2);
            }
            dist=sqrt(dist);
            if(floor(dist)==ceil(dist)){
                counter+=1;
            }

        }
    }
    cout<<counter<<endl;
}

Measured memory_bytes: 256
#define dbg(...) "amit_dwivedi"
#define db(...)  "Too OP"
#include "bits/stdc++.h"        
using namespace std;using ll=long long;
int n,m,h[100001],ans;
vector<int> g[100001];
void sol(){
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        cin>>h[i];
    }
    for(int i=0,u,v; i<m; i++) {
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=1; i<=n; i++) {
        bool f = 1;
        for(auto ch:g[i]){
            if(h[i] <= h[ch]){
                f = 0;
            }
        }
        ans+= f;
    }
    cout << ans << endl;

}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    // int t;cin>>t;while(t--)
    sol();
}
 

Measured memory_bytes: 9112
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        long K = sc.nextLong();
	        int N = sc.nextInt();
	        long[] a = new long[N];
	        for (int i=0 ; i<N; i++) {
	            a[i] = Long.parseLong(sc.next());
	        }
	        
	        long max=a[0]+(K-a[N-1]);
	        for(int i=0;i<N-1;i++) {
	        	max=Math.max(max, a[i+1]-a[i]);
	        }
	        long ans= K-max;
        	System.out.println(ans);
	        	        
	 }
}

Measured memory_bytes: 62004
#include <bits/stdc++.h>
#define e erase
#define PB push_back
#define elif else if
#define forn(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
using namespace std;
	
typedef long long int lli;
typedef long int li;
typedef vector <int> vi;
typedef vector <long long int> vii;
	
	
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a, b, c;

	cin>>a>>b>>c;

	if(a >= c && b <= c){
		cout<<"Yes"<<endl;
	}elif(a <= c && b >= c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}


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

using namespace std;

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

    vector<int> data(N);
    int i = 0;
    while(i < N ){
        cin >> data[i];
        i++;
    }

    sort(data.begin() , data.end() );
    int ans;
    for(i = 0 ; i + K -1 < N ; i++ ){
        if(i == 0) ans = data[i + K -1] - data[i] ;
        if(ans > data[i + K -1] - data[i]) ans = data[i + K -1] - data[i] ;    
    }

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...
int N, M, K;

// x is row and y is colouo
bool check(int x,int y,vector<string>  v){
	for(int i = 0;i<N;++i){
		if(x & (1 << i))
			for(int j  = 0;j<M;++j)
				v[i][j] = '.';
	}
	for(int i = 0;i<M;++i)
		if(y & (1 << i))
			for(int j = 0;j<N;++j)
				v[j][i] = '.';
	
	int res = 0;
	for(int i = 0;i<N;++i)
		for(int j = 0;j<M;++j)
			if(v[i][j] == '#') ++res;
	return res == K;
}
			

void test_case(){
	cin >> N >> M >> K;
	vector<string> v(N);
	for(auto & str : v)
		cin >> str;
	
	int cnt = 0;
	for(int i = 0;i<(1ll << N);++i){
		for(int j = 0;j<(1ll << M);++j){
			if(check(i,j,v)) ++cnt;
		}
	}
	cout <<cnt;
					
}
	
	


	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3644
def main():
    N = int(input())
    A = list(map(int,input().split()))
    now = A[0]
    count = 0
    upflag = False
    downflag = False
    for i in range(1,N):
        if upflag:
            if A[i] - now < 0:
                upflag = False
                downflag = False
        elif downflag:
            if A[i] - now > 0:
                downflag = False
                upflag = False
        else:
            if A[i] - now > 0:
                upflag = True
                count += 1
            elif A[i] - now < 0:
                downflag = True
                count += 1
        now = A[i]
    if not (upflag or downflag):
        count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 62704
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()
	s := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			s += A[i] * A[j]
		}
	}
	fmt.Println(s)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import sys
import bisect
sys.setrecursionlimit(10**6)

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

graph = [[] for _ in range(n)]
for i in range(n - 1):
    u, v = map(lambda x: int(x) - 1, input().split())
    graph[u].append(v)
    graph[v].append(u)

rooted = [[] for _ in range(n)]
que = [(0, -1)]
while que:
    node, parent = que.pop()
    for child in graph[node]:
        if child != parent:
            rooted[node].append(child)
            # rooted[child].append(node)
            que.append((child, node))
            # print(child + 1, node + 1)

table = [float('inf')] * n
lis = [None] * n
def dfs(node, length=0):
    p = bisect.bisect_left(table, a[node])
    table[p], old = a[node], table[p]
    length = max(p + 1, length)
    for child in rooted[node]:
        dfs(child, length)
    table[p] = old
    lis[node] = length

dfs(0)
print(*map(str, lis), sep="\n")


Measured memory_bytes: 286260
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int palindrome(string S){
    int N=S.size();
    for (int i = 0; i < N/2; i++){
        if(S[i]!=S[N-1-i])return 0;
    }
    return 1;
}

int main() {
    string S;
    cin >> S;
    int N=S.size();
    if(palindrome(S.substr(0,(N-1)/2))==1){
        if(palindrome(S.substr((N+3)/2-1,(N-1)/2))==1){
            if(palindrome(S)==1){
                cout <<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout <<"No"<<endl;
}

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

int main() {
  int N;
  cin>>N;
  int64_t A,Z=0;
  cin>>A;
  for(int i=0;i<N-1;i++){
    int64_t B;
    cin>>B;
    if(A>=B){
      Z+=(A-B);
    }
    else{
      A=B;
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>

#define int64 long long int

using namespace std;

int main()
{
	int a[4], b[4], hit, blow;
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
		hit = blow = 0;
		for(int i=0; i<4; i++){
			if(b[i] == a[i]) hit++;
			for(int j=0; j<4; j++){
				if(j != i){
					if(b[i] == a[j]) blow++;
				}
			}
		}
		cout << hit << ' ' << blow << '\n';
	}
	return 0;
}

Measured memory_bytes: 1160
import collections

N=int(input())
A=[int(_) for _ in input().split(" ")]
Q=int(input())

c = collections.Counter(A)

ans=0
for v in c:
  ans += v*c[v]

#print(c)
#d['k10'] = d.pop('k1')    
    
for i in range(Q):
  B,C=map(int,input().split(" "))
  
  if C in c:
    ans=ans-B*c[B]+C*c[B]
    c[C] += c[B]
    del c[B]
  else:
    ans=ans-B*c[B]+C*c[B]
    c[C] = c[B]
    del c[B]
  
  print(ans)

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
const int p = 1000000007;
const int NMAX = 50000;
ll fac[NMAX],finv[NMAX],inv[NMAX];
void combinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;

	FORq(i,2,NMAX-1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}
long long comb(int n,int r){
	if (n<r) return 0;
	if (n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n-r] % p) % p;
}

int main(){
	ll N,K;
	cin >> N >> K;

	ll R = N - K;
	combinit();

	FORq(i,1,K){
		if (i == 1){
			if (K != N){
				cout << R+1 << "\n";
				continue;
			}
			else{
				cout << 1 << "\n";
				continue;
			}
		}

		ll ans = 0;
		ll ans1,ans2;
		ans1 = comb(K-1,i-1) % MOD;
		ans2 = 0;
		for(ll l = 1; l <= R; l++){
			if (l < i-1) continue;
			ans2 = (ans2 + (comb(l-(i-1)+(i-2),i-2) * (R-l+1)) % MOD)%MOD;
		}
		//cout << ans1 << ", " << ans2 << endl;
		ans = (ans1 * ans2) % MOD;
		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <math.h>

using namespace std;
int main (void){
	long long n, k;
	cin >> n >> k;
	long long o;
	do{
		o=n;
		n = n>k? abs(n-k*(n/k)) : abs(n-k);
	}while(n<o);
	cout << o << endl;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main()
{
	long long int n;
	char s[11];
	long long int mozi[5] = {0};
	long long int ans = 1;
	long long int zenbu = 0;
	int i, j, k;

	scanf("%lld", &n);
	for (i= 0; i < n; i++) {
		scanf("%s", s);

		if (s[0] == 'M')
			mozi[0]++;
		else if (s[0] == 'A')
			mozi[1]++;
		else if (s[0] == 'R')
			mozi[2]++;
		else if (s[0] == 'C')
			mozi[3]++;
		else if (s[0] == 'H')
			mozi[4]++;
	}

	for (i = 0; i < 3; i++) {
		for (j = i+1; j < 4; j++) {
			for (k = j+1; k < 5; k++) {
				ans = mozi[i] * mozi[j] * mozi[k];
				zenbu += ans;
			}
		}
	}

	printf("%lld", zenbu);
	return 0;
}


Measured memory_bytes: 128
while True:
    W,H=map(int,input().split())
    if (W == 0 and H == 0):
        break
    for j in range(W):
        for i in range(H):
            if (j == 0 or i == 0 or i == H-1 or j == W-1):
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7008
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int N,M;
set <pair<int,int>>E;
string solve(){
    for(int i=1;i<N-1;++i){
        if(E.count({0,i}) && E.count({i, N-1})) return "POSSIBLE";
    }
    return "IMPOSSIBLE";
}

int main(){
    cin >> N >> M;
    
    for(int i=0;i<M;++i)
    {
        int a,b;
    cin >> a >> b;
    a--;
    b--;
    E.insert({a,b});
    E.insert({b,a});
    }
    cout << solve() << endl;
}

Measured memory_bytes: 18944
//#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
#define AC 0
#define mod 1000000007
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	int d;
	cin >> s >> d;
	vector< vector<int> > dp(d, vector<int>(2));
	dp[0][1] = 1;
	for (int i = 0; i < s.size(); i++) {
		vector< vector<int> > new_dp(d, vector<int>(2));
		for(int j=0;j<d;j++)
			for (int k = 0; k < 2; k++) {
				int mx = k ? s[i] - '0' : 9;
				for (int l = 0; l <= mx; l++) new_dp[(j + l) % d][k && l == mx] = (new_dp[(j + l) % d][k && l == mx] + dp[j][k]) % mod;
			}
		for (int j = 0; j < d; j++)
			for (int k = 0; k < 2; k++)
				dp[j][k] = new_dp[j][k];
	}
	cout << (dp[0][0] + dp[0][1] - 1 + mod) % mod << '\n';
	return AC;
}

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

int main(int argc , char** argv){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> fact;
	for(int i = 1 ; i * i <= m ; ++i){
		if(m%i == 0){
			fact.push_back(i);
			fact.push_back(m/i);
		}
	}
	sort(fact.begin() , fact.end());
	int ite = lower_bound(fact.begin() , fact.end() , m/n) - fact.begin();
	for(int i = ite ; i >= 0 ; --i){
		int val = fact[i];
		int rem = m - fact[i]*n;
		if(rem < 0)continue;
		int last = rem + fact[i];
		if(last % fact[i] == 0){
			cout << fact[i] << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int ans = 0;
  while (X > 0 || Y > 0) {
    if ((X != 0 && Y != 0) && (2 * C < A + B)) {
      ans += 2 * C;
      X--, Y--;
    } else if (X != 0 && Y != 0) {
      ans += A + B;
      X--, Y--;
    } else if (X > 0) {
      if (2 * C < A) {
        ans += 2 * C;
      } else {
        ans += A;
      }
      X--;
    } else {
      if (2 * C < B) {
        ans += 2 * C;
      } else {
        ans += B;
      }
      Y--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

h, w, k = inpl()
s = [input()[:-1] for _ in range(h)]
ans = 10 ** 4
for t in itertools.product([0, 1], repeat=h-1):
    cnt = t.count(1)
    tmp = s[0]
    SW = []  # 縦方向に圧縮したマップを格納
    tmp = [int(s) for s in s[0]] # tmp[j]=横方向に切ったブロックのj列目の総和
    for i, c in enumerate(t):
        if c: #横に切る
            SW.append(tmp) # SWが確定する
            tmp = [int(s) for s in s[i + 1]] # 次弾装填
        else:
            tmp = [tmp[j] + int(s[i + 1][j]) for j in range(w)]
    SW.append(tmp)
    new_h = len(SW)  #圧縮後の高さ
    sums = [0] * new_h
    if max(itertools.chain.from_iterable(SW)) > k:
        # itertools.chain.from_iterable([[A,B],[C,D]]) -> A,B,C,D
        # 各マスの時点でダメだったらこの横の切り方ではだめ
        continue
    for j in range(w):
        sumtmp = [sums[i] + SW[i][j] for i in range(new_h)]
        if max(sumtmp) > k:
            # 左から足してみてどこかがkを超えるようなら切る
            cnt += 1
            sums = [SW[i][j] for i in range(new_h)]  #新しいSW[i][j]で上書き
        else:
            sums = sumtmp
    ans=min(ans,cnt)
print(ans)


Measured memory_bytes: 60380
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

int n;
int b[114514];

int main(){
  cin >> n;
  for(int i=0;i+1<n;i++) cin >> b[i];
  int ans = b[0] + b[n-2];
  for(int i=0;i+2<n;i++) ans += min(b[i], b[i+1]);
  cout << ans << endl;  
  return 0;
}
  

Measured memory_bytes: 256
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const width = Number(lines[0]);
  let one: any[] = lines[1].split(" ");
  let two: any[] = lines[2].split(" ");

  for (let i = 0; i < width; i++) {
    one[i] = Number(one[i]);
    two[i] = Number(two[i]);
  }

  let max = 0;

  for (let i = 0; i < width; i++) {
    const curve = i;
    let tempMax = 0;
    for (let j = 0; j < width; j++) {
      if (j <= i) {
        tempMax += one[j];
      }
      if (j >= i) {
        tempMax += two[j];
      }

      if (tempMax > max) {
        max = tempMax;
      }
    }
  }

  console.log(max);
});


Measured memory_bytes: 7756
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            int sumA = b - a;
            int sumB = c - b;

            if (sumA == sumB) {
                out.println("YES");
            } else {
                out.println("NO");
            }


        }

    }
}



Measured memory_bytes: 21844