akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int A, B;
int main() {
    while (cin >> A >> B) {
        if (A == 1) A = 14;
        if (B == 1) B = 14;
        if (A > B) puts("Alice");
        else if (A < B) puts("Bob");
        else puts("Draw");
    }
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int,input().split()))

A_list=[]
for i in range(N):
    A = list(map(int,input().split()))
    A_list.append(A)

count=0
for A in A_list:
    ans = [a*b for a, b in zip(A, B)]
    if sum(ans)+C > 0:
        count+=1
print(count)


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

inline perm Unrank(int n, int r){
  perm p(n);
  for(int i=0;i<n;i++)p[i] = i;
  
  for(int i=n;i>0;i--){
    swap(p[i-1], p[r%i]);
    r /= i;
  }
  return p;
}

inline int Rank(perm p){
  int n = p.size();
  perm inv(n);
  for(int i=0;i<n;i++)inv[p[i]] = i;

  stack<int> s;
  for(int i=n;i>0;i--){
    s.push(p[i-1]);
    swap(p[i-1], p[inv[i-1]]);
    swap(inv[s.top()], inv[i-1]);
  }
  int r = 0;
  for(int i=1;i<=n;i++){
    r = s.top() + i * r;
    s.pop();
  }
  return r;
}

const int fact[] = {1,1,2,6,24,120,720,5040};
int dp[2][5040];

int main(){
  int n,d[110],a[110];
  cin >> n;
  rep(i,n)cin >> d[i];
  rep(i,n)cin >> a[i];

  rep(i,n){
    int cur = i&1, nxt = 1-cur;
    int len = min(n-i, 7), nxtlen = min(n-i-1, 7);
    rep(j,fact[nxtlen])dp[nxt][j] = 0;

    rep(j,fact[len]){
      perm p = Unrank(len,j);
      
      stack<perm> s;
      s.push(p);
      while(s.size()){
	perm tp = s.top();
	int tl = tp.size();
	s.pop();

	if(tl == nxtlen+1){
	  bool f = 0;
	  int score = 0;
	  rep(k,tl){
	    if(tp[k] == 0)f=1;
	    else if(f && tp[k]<=d[i])score += a[i];
	    else if(!f && tp[k]<=d[i+tp[k]])score += a[i+tp[k]];
	  }

	  perm np;
	  rep(i,tl){
	    if(tp[i]>0)np.push_back(tp[i]-1);
	  }
	  int nxthash = Rank(np);
	  dp[nxt][nxthash] = max(dp[nxt][nxthash], dp[cur][j]+score);
	}else{
	  perm np = tp;
	  np.push_back(tl);
	  s.push(np);
	  rep(i,tl){
	    swap(np[tl-i],np[tl-1-i]);
	    s.push(np);
	  }
	}
      }

    }
  }

  cout << dp[n&1][0] << endl;
}

Measured memory_bytes: 1264
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#include <math.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int x, y;
    cin >> x >> y;
    ll res = 0;
    if(x == 1){
        res += 300000;
    }
    else if(x == 2){
        res += 200000;
    }
    else if(x == 3){
        res += 100000;
    }
    if(y == 1){
        res += 300000;
    }
    else if(y == 2){
        res += 200000;
    }
    else if(y == 3){
        res += 100000;
    }
    if(x == 1&& y==1){
        res += 400000;
    }
    cout << res << endl;
    
    
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    int d[3000000];

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

    int D=0;
    for(int i=0;i<N-1;i++){
        D=max(D,d[i]);
        if(D<10){
            cout<<"no"<<endl;
            return 0;
        }
        D-=10;
    }

    D=0;
    for(int i=N-1;i>0;i--){
        D=max(D,d[i]);
        if(D<10){
            cout<<"no"<<endl;
            return 0;
        }
        D-=10;
    }
    cout<<"yes"<<endl;
	return 0;	
}


Measured memory_bytes: 4276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int N;
vector<vector<int>> A;

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

int dfs(int h, int w, int sum) {
    sum += A[h][w];

    int ans = sum;
    for (int dir = 0; dir < 2; dir++) {
        int nh = h + dy[dir];
        int nw = w + dx[dir];

        if (nh < 0 || nh >= 2 || nw < 0 || nw >= N) continue;
        chmax(ans, dfs(nh, nw, sum));
    }

    return ans;
}

int main() {
    cin >> N;
    A.resize(2, vector<int>(N));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    cout << dfs(0, 0, 0) << endl;
    return 0;
}

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

ll mypow(ll x, ll n){
  if(n == 0)
    return 1;
 
  if(n % 2 == 0)
    return mypow(x * x, n / 2);
  else
    return x * mypow(x, n - 1);
}

int main() {
  ll n;
  cin >> n;
  n--;
  ll cn = 1;
  ll tmp = n;
  string ans = "";
  while (n >= 0){
    int num = n % 26;
    char b = num + 'a';
    ans += b;
    n /= 26;
    n--;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main(){
        int n;
		string ans;
        cin>>n;
		if((n%10)==2 || (n%10)==4 || (n%10)== 5 || (n%10)== 7 || (n%10)==9)ans="hon";
		else if((n%10)==0 || (n%10)==1 || (n%10)== 8 || (n%10)==6)ans="pon";
		else if ((n%10)==3)ans="bon";
        cout<<ans<<endl;
        return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int main(){
  int t,p,r,a,b,c;
  string d;
  while(cin>>t>>p>>r,t){
    int th[55][2]={},w[55][11]={};
    for(int i=0;i<r;i++){
      cin>>a>>b>>c>>d;
      if(d=="WRONG")w[a][b]++;
      else{
	th[a][0]++;
	th[a][1]+=w[a][b]*1200+c;
      }
    }
    priority_queue<pair<int,pair<int,int> > > ans;
    for(int i=1;i<=t;i++){
      ans.push(make_pair(th[i][0],make_pair(-th[i][1],-i)));
    }
    while(!ans.empty()){
      cout<<-1*ans.top().second.second<<" "<<ans.top().first<<" "<<-1*ans.top().second.first<<endl;
      ans.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  int k;
  cin>>k;
  for(int i=0;i<k;i++){
      a.at(2)*=2;
  }
  cout<<a.at(0)+a.at(1)+a.at(2)<<endl;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
if n:
    p = list(map(int, input().split()))
    s = set(p)
else:
    s = set()
ans = 0
for i in range(-1, 200):
    if i not in s and abs(i - x) < abs(ans - x):
        ans = i
print(ans)

Measured memory_bytes: 61892
import java.util.Scanner;

    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();
            if(a<b) {
                if (b < c) {
                    System.out.println(a + " " + b + " " + c);
                } else if (a<c) {
                    System.out.println(a + " " + c + " " + b);
                }else{
                    System.out.println(c+ " " + a + " " + b);

                }
            }else if(a<c){
                System.out.println(b + " " + a + " " + c);
            }else if(b<c) {
                System.out.println(b + " " + c + " " + a);
            }else{
                System.out.println(c + " " + b + " " + a);

            }
        }

}





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

# 数列Aを格納
A = [int(input()) for _ in range(N)]

# 数列Aの最大の値、個数、位置を取得
a_max = max(A)
a_max_count = A.count(a_max)
a_max_index = A.index(a_max)

# 最大値が1つの場合、最大値の箇所は2番目に大きい値
if a_max_count == 1:
    # 最大値が1つしかない場合、2番目に大きい値を取得
    A.remove(a_max)
    a_second_max = max(A)

    for i in range(N):
        if i == a_max_index:
            print(a_second_max)
        else:
            print(a_max)
# 最大値が2つ以上の場合、常に最大値が解
else:
    for _ in range(N):
        print(a_max)


Measured memory_bytes: 12512
#include<bits/stdc++.h>
#define LL long long
#define MAX 100005
using namespace std;
int num[MAX],red[MAX];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,m;
	cin>>n>>m;
	for (int i=1;i<=n;i++) num[i]=1;
	red[1]=1;
	for (int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		if (!num[x]) continue;
		if (red[x]) red[y]=1;
		num[x]--;num[y]++;
		if (!num[x]) red[x]=0;
	}
	int ans=0;
	for (int i=1;i<=n;i++) ans+=red[i];
	cout<<ans<<'\n';
	return 0;
} 

Measured memory_bytes: 1024
while true
n, x = gets.split.map(&:to_i)
break if n == 0 && x == 0

range = 1..n
box = Array.new
range.each{|number| box << number}

cnt = 0
box.combination(3) {|a, b, c| cnt += 1 if x-a-b-c == 0}

puts cnt
end

Measured memory_bytes: 6096
#include <stdio.h>

int main(){
  long long n, q, s[100001], t, i, min, max, mid, c = 0;

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

  scanf("%lld", &q);
  while(q--){
    scanf("%lld", &t);
    min = 0;
    max = n - 1;
    while(min <= max){
      mid = (min + max) / 2;
      if(s[mid] == t){ c++; break;}
      else if(s[mid] > t) max = mid - 1;
      else if(s[min] < t) min = mid + 1;
    }
  }
  printf("%lld\n", c);
  return 0;
}

Measured memory_bytes: 1380
// ------------------------------------
// Date:2018/ 3/23
// Problem:_ _ _ a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

int main()
{
  CIN(X, A, B);
  string ans;
  if (B <= A) ans = "delicious"; 
  else if (X >= B - A) ans = "safe";
  else ans = "dangerous";

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



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import sys
import os
import math
 
for s in sys.stdin:
    d, w, h = map(int, s.split())
    if d == w == h == 0:
        break
 
    lst = [d, w, h]
    lst.sort()
    diameter = math.sqrt(lst[0] ** 2 + lst[1] ** 2)
 
    n = int(input())
 
    for i in range(n):
        r = int(input())
        if 2 * r > diameter:
            print('OK')
        else:
            print('NA')

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

int main()
{
	int n;  cin >> n;
	vector<int> b(n); for (int i = 1; i <= n - 1; i++) { cin >> b[i]; }
	
	int ans = 0;

	ans += b[1];

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

	ans += b[n -1];

	cout << ans << endl;

	return 0;
}

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

max_v = p[0]  # 現在注目している値より前に出てきた値の中で一番大きな値
min_v = p[0]
ans = 1
for i in range(1, len(p)):
    # print(f"i: {i}  p[i]: {p[i]}  max_v: {max_v}  min_v: {min_v}  ans: {ans}")
    if p[i] <= max_v and p[i] <= min_v:
        ans += 1
        # print("Plus ONE")
    if p[i] > max_v:
        max_v = p[i]
    if p[i] < min_v:
        min_v = p[i]
    
print(ans)


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

int main() 
{
    int change = 'a' - 'A';
    string str;

    getline( cin, str );                                             //空白を含めて一行まるまる読み込む

        for( int i = 0; i < str.size(); i++ )
        {
            if( str[i] >= 'A' && str[i] <= 'Z' )                     //ASCIIコードではA~Z,記号,a ~ z,記号の順に並んでいる
                str[i] += change;
            else if( str[i] >= 'a' && str[i] <= 'z' )
                str[i] -= change;
            else;
        }

    cout << str << endl;

    return 0;
}


Measured memory_bytes: 3216
package main

import "fmt"

func main() {
        var n int
        fmt.Scanf("%d", &n)
        for i := 1; i < 10; i++ {
                if div := n / i; n%i == 0 && div < 10 {
                        fmt.Println("Yes")
                        return
                }
        }
        fmt.Println("No")
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int,input().split()))
num = [i for i in A if i % 2 == 0]
count = 0
for i in num:
    if i % 3 != 0 and i % 5 != 0:
        print('DENIED')
        count = 1
        break
if count == 0:
    print('APPROVED')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long

int main(){

    unsigned long long int n, k;
    cin >> n >> k;

    if(n==k || (k==1) || n==0){
        cout << 0 << "\n";
    }
    else
    {   unsigned long long int x=n;
        if(x>k){
            x=min(x%k,k-(x%k));
        }else{
            x=min(x,(k-x));
        }
        cout << x << "\n";
    }
    

    return 0;
}

Measured memory_bytes: 256
w = gets.to_i
n = gets.to_i

p = (1..w).to_a

n.times do
  x, y = gets.chomp.split(',').map(&:to_i)
  p[x-1], p[y-1] = p[y-1], p[x-1]
end

p.each {|x| puts x}

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<ll> cnt(3,0);
    ll ans=1;
    rep(i,N){
        ll a=0;
        rep(j,3) if (cnt[j]==A[i]) ++a;
        ans=ans*a%MOD;
        if (a==0) break;
        rep(j,3) if (cnt[j]==A[i]){
            ++cnt[j];
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll w,a,b;
  cin >> w >> a >> b;
  cout << max(abs(b-a)-w,(ll)0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b;
	string date[11111][3],x,ans;
	while (1) {
		cin >> a;
		if (a == 0) {
			goto a;
		}
		for (int i = 1; i <= a; i++) {
			cin >> date[i][1];
			cin >> date[i][2];
		}
		cin >> b;
		ans = "";
		for (int i = 1; i <= b; i++) {
			cin >> x;
			for (int z = 1; z <= a; z++) {
				if (x == date[z][1]) {
					ans = ans + date[z][2];
					goto b;
				}
			}
			ans = ans + x;
		b:;
		}
		cout << ans << endl;
	}
a:;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;   // K is y location of type B

  vector<int> x(N);   // 0 < x_i < K;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    assert(0 < x[i] && x[i] < K);
  }

  int d_sum = 0;     // sum of distance
  int B_dist;        // x_i's distance from B
  for (int i = 0; i < N; i++) {
    B_dist = abs(x[i] - K);
    if (x[i] > B_dist) d_sum += 2 * B_dist;
    else d_sum += 2 * x[i];
  }

  cout << d_sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  ll a, b, c;

  cin >> a >> b >> c;

  ll d = c - a - b;

  if(d > 0 && d * d > 4 * a * b) cout << "Yes\n";
  else cout << "No\n";

  return 0;
}
/*

*/


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=200007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
vector<int> g[maxn];
int aa[maxn],pre[maxn];
int a[maxn];
int lowbit(int x){return  x&(-x);}
int ans[maxn];
map<int,int> aaa;
void dfs(int u,int fa){
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(v^fa){
           ans[v]=1;
           queue<int> G;
           for(int i=a[v];i;i-=lowbit(i)) ans[v]=max(ans[v],aa[i]);
           int x=ans[v];aaa[ans[v]]++;
           for(int i=a[v]+1;i<=200000;i+=lowbit(i))
           G.push(aa[i]),aa[i]=max(aa[i],ans[v]+1); 
           ans[v]=(*aaa.rbegin()).first;
           dfs(v,u);    
           aaa[x]--;
           if(!aaa[x]) aaa.erase(x);        
           for(int i=a[v]+1;i<=200000;i+=lowbit(i))
           aa[i]=G.front(),G.pop();
        }
    }
}
int A[maxn];
int main(){
    int n=read();
    for(int i=1;i<=n;i++) A[i]=read(),a[i]=A[i];
    sort(A+1,A+n+1);
    int len=unique(A+1,A+n+1)-A-1;
    for(int i=1;i<=n;i++) a[i]=lower_bound(A+1,A+len+1,a[i])-A;
    for(int i=1;i<n;i++){
        int u=read(),v=read();
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ans[1]=1;
    for(int i=a[1]+1;i<=200000;i+=lowbit(i)) aa[i]=max(aa[i],ans[1]+1);
    aaa[1]++;
    dfs(1,0);
    for(int i=1;i<=n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 169664
w,h,n=map(int,input().split())
wx=[0]*w
hy=[0]*h
for i in range(n):
  x,y,a=map(int,input().split())
  x-=1
  y-=1
  if a==1:
    for j in range(x+1):
      wx[j]=1
  if a==2:
    for j in range(x+1,w):
      wx[j]=1
  if a==3:
    for j in range(y+1):
      hy[j]=1
  if a==4:
    for j in range(y+1,h):
      hy[j]=1
print(wx.count(0)*hy.count(0))
#print(wx)
#print(hy)

Measured memory_bytes: 9152
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,d;
    cin>>A>>B>>C;
    d=A+B+C;
    if(17 == d){ 
    cout<<"YES"<<endl;
    }else
    cout<<"NO"<<endl;
return 0;
}


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

if A+2*K>=B+2:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
  ll sai[n];
  sai[0]=a[0];
  for(ll i=1;i<n;i++)sai[i]=max(sai[i-1],a[i]);
  vector<ll> v;
  for(ll i=0;i<n;i++)v.push_back(sai[i]);
  v.erase(unique(v.begin(),v.end()),v.end());
  ll tai[v.size()];
  ll now=0;
  for(ll i=0;i<n;i++){
    if(now==v.size())break;
    if(sai[i]==v[now]){
      tai[now]=i;
      now++;
    }
  }
  ll ko[v.size()];
  ll wa[v.size()];
  vector<ll> w;
  for(ll i=0;i<n;i++)w.push_back(a[i]);
  sort(w.begin(),w.end());
  for(ll i=0;i<n;i++){
    if(w[i]==v[0]){
      now=i;
      break;
    }
  }
  for(ll i=0;i<v.size();i++){
    if(i<v.size()-1){
      ll sum=0;
      for(ll j=now;;j++){
        if(w[j]==v[i+1]){
          ko[i]=j-now-1;
          wa[i]=sum;
          now=j;
          break;
        }
        sum+=w[j]-v[i];
      }
    }
    else{
      ko[i]=n-now;
      wa[i]=0;
    }
  }
  ll ans[n];
  fill(ans,ans+n,0);
  ll hav=ko[v.size()-1];
  for(ll i=v.size()-1;i>0;i--){
    ans[tai[i]]=wa[i-1]+hav*(v[i]-v[i-1]);
    hav=hav+ko[i-1]+1;
  }
  ll ss=0;
  for(ll i=0;i<n;i++){
    ss+=min(v[0],a[i]);
  }
  ans[0]=ss;
  for(ll i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
}
  
    
  

Measured memory_bytes: 7412
// https://atcoder.jp/contests/abc176/tasks/abc176_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int minv = A[0], ans = 0;
    REP(i, N) {
        // 高さ更新
        if (minv < A[i]) {
            minv = A[i];
        } else {
            ans += minv - A[i];
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4724
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            } else {
                for (int i = 0; i < H; i++) {
                    for (int j = 0; j < W; j++) {
                        System.out.print("#");
                    }
                    System.out.print("\n");
                }
                System.out.print("\n");
            }
        }
    }
}


Measured memory_bytes: 36560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int n,m;
  cin >> n >> m;
  vector<string> a(n),b(m);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,m){
    cin >> b[i];
  }
  rep(i,n-m+1){
    rep(j,n-m+1){
      bool flag = true;
      rep(ni,m){
        rep(nj,m){
          if(a[i+ni][j+nj] != b[ni][nj]){
            flag = false;
          }
        }
      }
      if(flag){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int add(int i, int j) { return ((i += j) < mod ? i : i -= mod); }
int mult(int i, int j) { return (ll) i * j % mod; }
int pwr(int i, int k) {
    int r = 1;
    while(k) {
        if(k & 1)
            r = mult(r, i);
        i = mult(i, i);
        k >>= 1;
    }
    
    return r;
}

int fac[200002];
int invfac[200002];
int bin(int i, int j) { return mult(mult(fac[i], invfac[j]), invfac[i - j]); }


int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    fac[0] = 1;
    for(int i = 1; i < 200002; ++i)
        fac[i] = mult(i, fac[i - 1]);
    invfac[200001] = pwr(fac[200001], mod - 2);
    for(int i = 200000; i > -1; --i)
        invfac[i] = mult(i + 1, invfac[i + 1]);
    
    int mx = 0;
    for(int i = 0 ; i < b; ++i)
        mx = (mx - mult(bin(w - 2 - i + a, a - 1), bin(h - a - 1 + i, i)) + mod) % mod;
        
    mx = add(mx, bin(h + w - 2, w - 1));
    
    cout << mx;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int a, b;
    cin >> a;
    cin >> b;
    cout << a * b << ' ' << a * 2 + b * 2 << endl;
    return 0;
}




Measured memory_bytes: 3024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if(a <= b) {
        rep(i, b) {
            cout << a;
        }
    }
    else {
        rep(i, a) {
            cout << b;
        }
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC171A
{
    class Program
    {
        static void Main(string[] args)
        {
            string alpha = Console.ReadLine();
            char a = alpha[0];
            if (char.IsUpper(a))
            {
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("a");
            }

        }
    }
}


Measured memory_bytes: 25800
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
ll n, l;
cin >> n >> l;
ll min = l+1-1;
ll minimum;
ll sum =min;
for(int i=2; i<=n; i++){
	minimum = l+i-1;
	if(abs(minimum)<abs(min))
		min=minimum;
	sum+=minimum;

}
cout << sum-min;
return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int[]nq=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n=nq[0];
        int q=nq[1];

        int[]prt=new int[n];
        for(int i=0;i<n;i++){
            prt[i]=-1;
        }
        Func<int,int>find=null;
        find=x=>prt[x]<0?x:prt[x]=find(prt[x]);
        for(int i=0;i<q;i++){
            int[]query=Console.ReadLine().Split().Select(int.Parse).ToArray();
            if(query[0]==0){
                int u=find(query[1]);
                int v=find(query[2]);
                if(u!=v)prt[u]=v;
            }else{
                Console.WriteLine(find(query[1])==find(query[2])?1:0);
            }
        }
    }
}




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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// Range系のライブラリ
struct RangeIterator {
	ll v;
	const ll operator*() { return v; }
	RangeIterator& operator++() { ++v; return *this; }
	bool operator!=(const RangeIterator& rhs) { return v != rhs.v; }
};
template<bool INCLUSIVE> struct EndType {};
template<> struct EndType<false> {
	ll end;
	ll operator()() { return end; }
};
template<> struct EndType<true> {
	ll end;
	ll operator()() { return end + 1; }
};
template<bool INCLUSIVE>
struct Range {
	ll s; EndType<INCLUSIVE> e;
	Range(ll end) : s(0), e(EndType<INCLUSIVE>{end}) {}
	Range(ll start, ll end) : s(start), e(EndType<INCLUSIVE>{end}) {}
	RangeIterator begin() { return { s }; }
	RangeIterator end() { return { e() }; }
};
inline Range<false> range(ll start) { return Range<false>(start); }
inline Range<false> range(ll start, ll end) { return Range<false>(start, end); }
inline Range<true> irange(ll start) { return Range<true>(start); }
inline Range<true> irange(ll start, ll end) { return Range<true>(start, end); }

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T & container, typename T::key_type & key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法
ll N, A, B, C, D;
string S;

int main(void) {
	std::ios_base::sync_with_stdio(false);

	cin >> N >> A >> B >> C >> D;
	S.resize(N + 1);
	for (ll i = 1; i <= N; ++i) cin >> S[i];

	auto solve = [&]()
	{
		for (ll i = A + 1; i <= C; ++i)
			if (S[i] == '#' && S[i - 1] == '#') return false;
		for (ll i = B + 1; i <= D; ++i)
			if (S[i] == '#' && S[i - 1] == '#') return false;

		if (C > D)
		{
			bool swap = false;
			for (ll i = B; i <= D; ++i)
			{
				if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') swap = true;
			}
			return swap;
		}
		return true;
	};
	cout << (solve() ? "Yes" : "No") << endl;

	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;

int main(){
    int A,B;
    cin >> A >> B;





    
    cout << max(A+B,max(A-B,A*B)) <<endl;
    return 0;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ull, ull> P; //ペア　タイプでふ
constexpr ll bigNum = 1000000007;

int main(void)
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    //ここから本体
    string str;
    cin >> str;
    int n = str.length();
    vector<int> numPeople(n, 0);
    vector<int> change;
    char now = 'R';
    int temp = 0;
    for (int i = 0; i < n; i++)
    {
        if (str[i] != now)
        {
            if (now == 'R')
            {
                now = 'L';
            }
            else
            {
                now = 'R';
            }
            change.push_back(i);
        }
    }
    change.push_back(n);
    int Rnum = 0;
    int Lnum = 0;

    int init = 0;
    int RtoL = 0;
    int LtoR = 0;
    for (int i = 0; i < (change.size() + 1) / 2; i++)
    {
        int w = 2 * i;
        RtoL = change[w];
        LtoR = change[w + 1];
        Rnum = RtoL - init;
        Lnum = LtoR - RtoL;
        if ((Rnum + Lnum) % 2 == 0)
        {
            numPeople[RtoL] = (Rnum + Lnum) / 2;
            numPeople[RtoL - 1] = (Rnum + Lnum) / 2;
        }
        else
        {
            if (Rnum < Lnum)
            {
                if (Rnum % 2 == 0)
                {
                    numPeople[RtoL] = (Rnum + Lnum + 1) / 2;
                    numPeople[RtoL - 1] = (Rnum + Lnum - 1) / 2;
                }
                else
                {
                    numPeople[RtoL] = (Rnum + Lnum - 1) / 2;
                    numPeople[RtoL - 1] = (Rnum + Lnum + 1) / 2;
                }
            }
            else
            {
                if (Lnum % 2 == 0)
                {
                    numPeople[RtoL] = (Rnum + Lnum - 1) / 2;
                    numPeople[RtoL - 1] = (Rnum + Lnum + 1) / 2;
                }
                else
                {
                    numPeople[RtoL] = (Rnum + Lnum + 1) / 2;
                    numPeople[RtoL - 1] = (Rnum + Lnum - 1) / 2;
                }
            }
        }
        init = change[w + 1];
    }

    for (int i = 0; i < n; i++)
    {
        cout << numPeople[i] << " ";
    }
}


Measured memory_bytes: 1480
a = int(input())
A = [input() for _ in range(a)]
b = int(input())
B = [input() for _ in range(b)]
a = list(set(A) | set(B))
c = []
for i in range(len(a)):
  c.append(A.count(a[i]) - B.count(a[i]))
if max(c) < 0:
  print(0)
else:
  print(max(c))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18+9
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	string st;
	cin >> st;
	int q;
	string b="",e="";
	cin >> q;
	int fl=0;
	while(q--){
		int t;
		cin >> t;
		if(t==1){
			swap(b,e);
			fl=fl^1;
		}
		else{
			int f;
			char c;
			cin >> f >> c;
			if(f==1)b+=c;
			else e+=c;
		}
	}
	reverse(b.begin(),b.end());
	if(fl)reverse(st.begin(),st.end());
	cout << b << st << e;
}

Measured memory_bytes: 1040
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            // 初期状態をt[0], x[0], y[0]とすることで便利になります
            var t = new int[N + 1];
            var x = new int[N + 1];
            var y = new int[N + 1];
            y[0] = x[0] = y[0] = 0;
            for (int i = 1; i <= N; ++i)
            {
                t[i] = cin.ReadInt;
                x[i] = cin.ReadInt;
                y[i] = cin.ReadInt;
            }

            var flag = true;
            for (int i = 0; i < N; ++i)
            {
                var time = t[i + 1] - t[i];
                var dist = Abs(x[i + 1] - x[i]) + Abs(y[i + 1] - y[i]);
                if (time < dist) flag = false;
                if (Abs(time - dist) % 2 != 0) flag = false;
            }

            if (flag) WriteLine("Yes");
            else WriteLine("No");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 17428
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int abs_xa = Math.abs(x - a);
		int abs_xb = Math.abs(x - b);

		if (abs_xa < abs_xb) {
			System.out.print("A");

		} else {
			System.out.print("B");
		}
	}
}

Measured memory_bytes: 20688
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

const int NUM = 10000;

using namespace std;

int main()
{
    long long n, m;
    while(1){
        cin >> n;
        cin >> m;
        if(n == 0 && m ==0){
            break;
        }

        vector<pair <long long, long long>> data(NUM);
        long long total_encounter = 0;
        long long d, p;
        for(long long i = 0 ; i < n; i++){
            cin >> d;
            cin >> p;
            data[i] = make_pair(p, d);
            total_encounter += d * p;
        }
        
        sort(data.begin(), data.end());
        reverse(data.begin(), data.end());
        
        long long index = 0;
        for(int i = 0; i < n; i++){
            if(m < data[i].second){
                total_encounter -= m * data[i].first;
                break;
            }
            m -= data[i].second;
            total_encounter -= data[i].first * data[i].second;
        }
        cout << total_encounter << endl;
    }
    return 0;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  
  char a[H][W];
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a[i][j];
    }
  }
  for(int i=0; i<W+2; i++)
    cout << '#';
  cout << endl;
  for(int i=0; i<H; i++){
    cout << '#';
    for(int j=0; j<W; j++){
      cout << a[i][j];
    }
    cout << '#' << endl;
  }
  for(int i=0; i<W+2; i++)
    cout << '#';
  cout << endl;
}

Measured memory_bytes: 256
A, B, K = map(int, raw_input().split());

r = B % A;
ans = [];

while(r != 0):
	B = A;
	A = r;
	r = B % A;

for i in range(1,A+1):
	if A%i == 0:
		ans.append(i);
print(ans[-K]);

Measured memory_bytes: 2568
#include<bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int N=1e2+5;

ll n,m;

int main()
{
	// freopen("test.in","r",stdin);
	// scanf("%d",&T);
	// while(T--)
	// {
	scanf("%lld%lld",&n,&m);
	n%=m;
	printf("%lld\n",std::min(n,m-n));
	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
dp = [0, abs(L[0] - L[1])]
if N == 2:
    print(dp[1])
else:
    for i in range(2, N):
        dp.append(min(dp[i - 2] + abs(L[i] - L[i - 2]), dp[i - 1] + abs(L[i] - L[i - 1])))
    print(dp[N - 1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  string s;
  cin >> s;
  int N = s.size();
  bool A = false;
  
  for(int i = 0; i <= (N - 3) / 4 ; i++){
    if(s.at(i) == s.at((N - 1) / 2 - 1 - i)){
    }
    else{
      A = true;
      break;
    }
  }
  
  if(A == true){
    cout << "No" << endl;
    return 0;
  }
  
  A = false;
  
  for(int i = 0; i <= (N - 1) / 4 ; i++){
    if(s.at((N + 3) / 2 - 1 + i) == s.at(N - 1 - i)){
    }
    else{
      A = true;
      break;
    }
  }
  
  if(A == true){
    cout << "No" << endl;
    return 0;
  }
  
  A = false;
  
  for(int i = 0; i <= (N - 1) / 2 ; i++){
    if(s.at(i) == s.at(N - 1 - i)){
    }
    else{
      A = true;
      break;
    }
  }
  
  if(A == true){
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int n1=0,m1=0,tn1,t;
		if (n>1){
            n=n*(n-1)/2;
            n1+=n;
		}else 
		    n1=0;
		
		if (m>1){
		    m=m*(m-1)/2;
		    m1+=m;
		}else
		    m1=0;
		  
		System.out.println(n1+m1);
		    
	}
}


Measured memory_bytes: 35592
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    
   ll tests=1;
   
  // cin>>tests;
    while(tests--)
    {
      // ll n,i,j;
      // cin>>n;
      // vector<pair<ll,ll>>v(n);
      // for(i=0;i<n;i++) cin>>v[i].first;
      // rep(i,0,n-1) cin>>v[i].second;
      // sort(v.begin(),v.end());

      ll n,k,i;
      cin>>n>>k;
      vector<ll>a(n+1);
      rep(i,1,n) cin>>a[i];
      // cin>>k;
      ll len=k;
      ll ans=-1;
      vector<ll>vis(n+1,0);
      ll cur=1;
      ll index=-1;
      while(len>0)
      {
        vis[cur]=1;
        cur=a[cur];
        len--;
        if(vis[cur]) {index=cur;break;}
        
      }
      // cout<<"check1"<<"\n";
      if(len<1) {cout<<cur; return 0;}

      ll cyl_len=0;
       cur=index;
      while(true)
      {
        cyl_len++;
        cur=a[cur];
        if(cur==index) break;
      }
      len=len%cyl_len;
      cur=index;
      while(len>0)
      {
        cur=a[cur];
        len--;
      }
      cout<<cur;



    }
    return 0;
   }

Measured memory_bytes: 17432
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = B[A[0]-1]


for i in range(1, N):
  total += B[A[i]-1]
  if A[i] == A[i-1]+1:
    total += C[A[i-1]-1]
print(total)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using vvv = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define VVI(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVI(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * POW(n, m - 1)) % MOD;
  }
}

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

ll f(ll b, ll n) {
  if (n < b)
    return n;
  else
    return f(b, n / b) + (n % b);
}

int main() {
  ll N, S;
  ll ans = llINF;
  cin >> N >> S;
  if (N == S) {
    cout << N + 1 << endl;
    return 0;
  }
  for (ll i = 2; i * i <= N; i++) {
    if (f(i, N) == S) {
      ans = i;
      break;
    }
  }
  if (ans == llINF) {
    for (ll i = 1; i * i <= N; i++) {
      ll b = ((N - S) / i) + 1;
      if (b < 2)
        continue;
      if (f(b, N) == S) {
        if (ans > b)
          ans = b;
      }
    }
  }
  if (ans == llINF)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256