akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	LL year, month, date;
	scanf("%lld/%lld/%lld", &year, &month, &date);
	if(year < 2019)	puts("Heisei");
	else if(year == 2019) {
		if(month < 4)	puts("Heisei");
		else if(month == 4) {
			if(date <= 30)	puts("Heisei");
			else if(date > 30)	puts("TBD");
		}
		else if(month > 4)	puts("TBD");
	}
	else if(year > 2019)	puts("TBD");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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 T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int n; cin >> n;
    vector<pair<int,int>> p(n);
    rep(i,n) {
        int a; cin >> a;
        p[i] = {a,i+1};
    }
    sort(all(p));
    rep(i,n) cout << p[i].second << " ";
}


Measured memory_bytes: 4000
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    /* もしa_iに奇数が含まれていたら、先手は奇数のa_iのみから1つずつ食べることですべてのりんご
       を偶数個にできる。すると後手が何種類のりんごを食べたとしても先手のターンにはまた奇数個の
       りんごがあるので奇数個の種類のりんごを1つずつ食べることですべてのりんごを偶数個にして
       後手のターンにし続けることができる。この操作は最終的にすべてのりんごが0個になるまで
       繰り替えせるので先手の勝ちである。a_iがすべて偶数だったら後手必勝であることもわかる。 */

    int gote = 1;  // 後手必勝なら1
    rep(i, n) {
        int a;
        cin >> a;
        if(a%2 == 1) {  // aに奇数が含まれていたら先手必勝
            gote = 0;
            break;
        }
    }

    if(!gote) {
        cout << "first";
    }
    else {
        cout << "second";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double EPS = 1e-7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double x, y; cin >> x >> y;
	double a, b; a = min(x, y); b = max(x, y);
	//cin >> a >> b;
	double t = min(360 - (b - a), (b - a));


	t = t / 2;
	dump(t);

	if (360 - (b - a) > b - a) {

		cout << fixed << setprecision(4) << (a + b) / 2 << endl;
	}


	else {
		double ans = (a + 360 + b) / 2;
		if (ans - 360.0> EPS)ans -= 360;
		cout << fixed << setprecision(4) << ans << endl;
	}


	/*if (t - a> EPS)cout << t << endl;
	else cout << a + t << endl;
*/

//if (t > 90.0) {
//	t = 180 - t;
//	a -= t;
//	if (a < 0)a += 360;
//}
//

//cout << a + t << endl;



	return 0;
}

Measured memory_bytes: 3216
n=int(input())
a=list(map(int,input().split()))
money = 1000
kabu = 0
for i in range(1, n):
  up   = a[i-1] < a[i]
  down = a[i-1] > a[i]
  if(up and money >= a[i-1]):
    kabu = money//a[i-1]
    money -= kabu*a[i-1]
  if(down):
    money += kabu*a[i-1]
    kabu = 0
  #print(kabu, money)
print(money + kabu*a[n-1])

Measured memory_bytes: 61856
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<ll> A(N);
  cin>>A;
  sort(A.begin(),A.end());
  for(int i=1;i<N;i++){
    if(A[i]==A[i-1]){cout<<"NO"<<endl; return 0;}
  }
  cout<<"YES"<<endl;

  return 0;
}


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

int M=1e9+7;
int ans=0;
vector<int>v;
int recur(vector<int>&arr, int m, int N) 
{ 
   int count[N + 1]; 
   memset(count, 0, sizeof(count)); 
   count[0] = 1; 
   for (int i = 1; i <= N; i++) 
      for (int j = 0; j < m; j++) 
         if (i >= arr[j]) 
               count[i] =(count[i]%M + count[i - arr[j]]%M)%M; 
   
   return count[N]%M;  
      
} 
// void recur(int s,int sum){
//    if(s==sum){
//       ans=(ans+1)%M;
//       return;
//    }
//    if(sum>s)
//    return;
//    int st=3;
//    if(v.size())
//    st=v.back();
//    for(int i=st;i<=s;i++){
//       v.push_back(i);
//       recur(s,sum+i);
//       v.pop_back();
//    }
// }

int main() {
   int s;
   cin>>s;
   vector<int>arr;
   for(int i=3;i<=s;i++){
      arr.push_back(i);
   }
   ans=recur(arr,arr.size(),s);
   // recur(s,0);
   cout<<ans<<endl;
}

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

int main() {
	int N, l, r;
	int sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> l >> r;

		if (l > r) {
			sum += (l - r) + 1;
		}
		else {
			sum += (r - l) + 1;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    long long K;
    cin >> K;

    bool changed_S[S.size()];
    for(int i = 0; i < S.size(); i++){
        changed_S[i] = false;
    }
    for(int i = 1; i < S.size(); i++){
        if(changed_S[i-1] != true && S[i-1] == S[i]){
            changed_S[i] = true;
        }
    }
    long long cnt_1 = 0;
    for(int i = 0; i < S.size(); i++){
        if(changed_S[i] == true){
            cnt_1++;
        }
    }
    // cout << "cnt_1 " << cnt_1 << endl;


    string T2 = S + S;
    bool changed_T2[T2.size()];
    for(int i = 0; i < T2.size(); i++){
        changed_T2[i] = false;
    }
    for(int i = 1; i < T2.size(); i++){
        if(changed_T2[i-1] != true && T2[i-1] == T2[i]){
            changed_T2[i] = true;
        }
    }
    long long cnt_2 = 0;
    for(int i = 0; i < T2.size(); i++){
        if(changed_T2[i] == true){
            cnt_2++;
        }
    }
    // cout << "cnt_2 " << cnt_2 << endl;


    string T3 = S + S + S;
    bool changed_T3[T3.size()];
    for(int i = 0; i < T3.size(); i++){
        changed_T3[i] = false;
    }
    for(int i = 1; i < T3.size(); i++){
        if(changed_T3[i-1] != true && T3[i-1] == T3[i]){
            changed_T3[i] = true;
        }
    }
    long long cnt_3 = 0;
    for(int i = 0; i < T3.size(); i++){
        if(changed_T3[i] == true){
            cnt_3++;
        }
    }
    // cout << "cnt_3 " << cnt_3 << endl;


    long long d1 = cnt_2 - cnt_1;
    long long d2 = cnt_3 - cnt_2;
    
    long long ans = 0;
    if(K == 1){
        ans = cnt_1;
    }else{
        ans += cnt_1;
        if(K-1 % 2 == 0){
            ans += (d1+d2)*(K-1)/2;
        }else{
            ans += (d1+d2)*(K-2)/2+d1;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
package main
import (
        "bufio"
        "fmt"
        "os"
        "strings"
        "strconv"
)

//入力
var sc = bufio.NewScanner(os.Stdin)

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

//型変換
func Atoi2(c string) int {
  tmp, _ := strconv.Atoi(c)
  return tmp
}

func Itoa2(a []int) string{
  var str []string
  for _, i := range a{
    str = append(str,strconv.Itoa(i))
  }
  return strings.Join(str, " ")
}


func insertionSort(a []int, n int) []int {
    fmt.Println(Itoa2(a))
    for i:=1; i < n; i++{
      v := a[i]
      j := i - 1

      for j >= 0 && a[j]> v{
        a[j+1] = a[j]
        j--
      }

      a[j+1]= v
      fmt.Println(Itoa2(a))
    }
    return a
  }

//main
func main() {
	length := Atoi2(nextLine())
	str := strings.Split(nextLine(), " ")
  var origin []int
  for _, c := range str{
    origin = append(origin, Atoi2(c))
  }

  insertionSort(origin, length)
}



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

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

    for (int i = 0; A > 0 && C > 0; i++)
    {
        if (i % 2 == 0)
        {
            C -= B;
        }
        else
        {
            A -= D;
        }
    }
    if (A > C)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    int ans = 0;
    while (n != 0) {
        ans++; n /= k;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

const int INF = 1e9 + 7;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto&& i : a) {
    cin >> i;
    --i;
  }
  int now = 0, ans = 0;
  bool s[100000] = {};
  while(now != 1) {
    if(s[now]) {
      cout << "-1\n";
      return;
    }
    s[now] = true;
    now = a[now];
    ans++;
  }
  cout << ans << "\n";
}

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

Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

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

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	string ans = "Yes";
	for (int i = K; i < N; i++) {
		if (A[i - K] >= A[i])
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
	//cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<edge>>;
std::vector<int> ans;
void dfs(const Graph &g,int p){
    erep(i,g[p]){
        if(ans[i.to]!=-1)continue;
        if(ans[i.to]==-1){
            if(ans[p]==0){
                if(i.weight%2==0)ans[i.to]=0;
                else ans[i.to]=1;
            }
            else{
                if(i.weight%2==0)ans[i.to]=1;
                else ans[i.to]=0;
            }
            dfs(g,i.to);
        }
    }
}

int main(){
    int n;
    std::cin >> n;
    ans.as(n,-1);
    Graph g(n);
    //std::cout << 123 << std::endl;
    rep(i,n-1){
        int a,b,c;
        std::cin >> a>>b>>c;
        a--;b--;
        g[a].pb(edge(b,c));
        g[b].pb(edge(a,c));
    }
    ans[0]=0;
    dfs(g,0);
    rep(i,n){
        std::cout << ans[i] << std::endl;
    }
}

Measured memory_bytes: 8192
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        String judge;
        int[] score = new int[3];
        
        while (true) {
            line = br.readLine();
            
            String ary[] = line.split(" ");
            score[0] = Integer.parseInt(ary[0]);
            score[1] = Integer.parseInt(ary[1]);
            score[2] = Integer.parseInt(ary[2]);
            
            if(score[0] == -1 && score[1] == -1 && score[2] == -1){
                break;
            }
            
            judge = judgeScore(score[0], score[1], score[2]);
            
            System.out.println(judge);
        }
        
    }
    
    static String judgeScore(int tyukan, int kimatu, int sai){
        int sum = tyukan + kimatu;
        String judge;
        
        if(tyukan == -1 || kimatu == -1){
            judge = "F";
        }else if(sum >= 80){
            judge = "A";
        }else if(sum >= 65){
            judge = "B";
        }else if(sum >= 50){
            judge = "C";
        }else if(sum >= 30){
            judge = "D";
        }else{
            judge = "F";
        }
        
        if(sai >= 50){
            judge = "C";
        }
        
        return judge;
    }
}

Measured memory_bytes: 24252
def examA():
    S = SI()
    if S=="AAA" or S=="BBB":
        print("No")
    else:
        print("Yes")
    return

def examB():
    N, A, B = LI()
    loop = N//(A+B)
    ans = loop*A + min(A,N%(A+B))
    print(ans)
    return

def examC():
    A, B = LI()
    ans = -1
    for i in range(1,20000):
        if i*8//100==A:
            if i*10//100==B:
                ans = i
                break
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

Measured memory_bytes: 4848
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;


int main(){
    ll n; cin >> n;
    vpl e(n-1);
    rep(i,n-1){
        ll u,v; cin >> u >> v;
        if(u > v) swap(u,v);
        e[i] = P(u,v);
    }
    ll ans = 0;
    REP(i,1,n+1){
        ans += i * (n-i+1);
    }
    rep(i,n-1){
        ans -= e[i].first * (n-e[i].second+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int maxlong(int x){ //最大の木の長さ(親の数を数える)
      int ans=0;
      int a[x]={};
      rep(i,x){
      a[root(i)]++;
      }
      rep(i,x){chmax(ans,a[i]);}
      return ans;
    }

};

int main() {
  int n,m;
  cin >>n >>m;
  UnionFind tree(n);
  rep(i,m){
    int a,b;
    cin >> a >>b;
    a--,b--;
    tree.unite(a,b);
  }
  int ans=0;
  rep(i,n){
    if(!tree.same(0,i)){
      ans++;
      tree.unite(0,i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int aa, bb;
int rd() {
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int MAXN = 3;
int n, a[MAXN][MAXN];
bool vis[MAXN][MAXN];
inline void work() {
  for(reg int i = 0; i < 3; ++i)
    for(reg int j = 0; j < 3; ++j)
      a[i][j] = rd();
  n = rd();
  memset(vis, 0, sizeof(vis));
  for(reg int i = 0; i < n; ++i) {
    int x = rd();
    for(reg int j = 0; j < 3; ++j)
      for(reg int k = 0; k < 3; ++k)
        if(a[j][k] == x)
          vis[j][k] = 1;
  }
  bool ok = 0;
  for(reg int i = 0; i < 3; ++i) {
    ok |= vis[i][0] && vis[i][1] && vis[i][2];
    ok |= vis[0][i] && vis[1][i] && vis[2][i];
  }
  ok |= vis[0][0] && vis[1][1] && vis[2][2];
  ok |= vis[2][0] && vis[1][1] && vis[0][2];
  if(ok)
    printf("Yes\n");
  else
    printf("No\n");
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}



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

#define MOD 100000007LL


int main(){
	int rz,wz,c,r;
	while(1){
		scanf("%d%d%d%d",&rz,&wz,&c,&r);
		if(rz==0 && wz==0)break;
		int rest=wz*c-rz;
		rest=(rest+r-1)/r;
		printf("%d\n",max(0,rest));
	}
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
int main(){
  string t;
  while(cin>>t){
    string s;
    if(t=="#")break;
    for(int i=t.size()-1;i>=0;i--){
      if(t[i]=='n')s+="north";
      if(t[i]=='w')s+="west";
    }
    
    int m=1,i,c;
    char t=s[0];
    if(t=='n')c=0,i=5;
    else c=90,i=4;
    int f=1;
    while(i!=s.size()){
      c*=2;
      m*=2;
      //cout<<c<<" "<<m<<endl;
      if(t==s[i]&&f){
	if(s[i]=='n')i+=5;
	else i+=4;
	continue;
      }
      f=0;
      if(s[i]=='n')c-=90,i+=5;
      else c+=90,i+=4;
    }
    int g=__gcd(c,m);
    cout<<c/g;
    if(m/g!=1)cout<<"/"<<m/g;
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3080
hoketsu_1 = [0, 100]
hoketsu_2 = [0, 100]
for x in range(3) :
    Time = []
    for i in range(8) :
        p, t = input().split()
        Time.append([p, t])
    Time.sort(key = lambda x: x[1])
    print(*Time[0])
    print(*Time[1])
    
    if float(Time[2][1]) < float(hoketsu_1[1]) :
        hoketsu_2 = hoketsu_1
        hoketsu_1 = Time[2]
    elif float(Time[2][1]) < float(hoketsu_2[1]) :
        hoketsu_2 = Time[2]
    if float(Time[3][1]) < float(hoketsu_2[1]) :
        hoketsu_2 = Time[3]
print(*hoketsu_1)
print(*hoketsu_2)




Measured memory_bytes: 5576
#include<stdio.h>

int main(){
int b1[9]={},b2[9]={};

int x1=0,x2=0;

//double x1,x2=0;
//int y1=0,y2=0;
/*
while(scanf("%lf",&x)!=EOF){
x2=x1*10000;
y2=(int)x1;y2*=10000;
y2=(int)x2-(int)x1*10000;
y1=(int)x1;
if(y1>255||y2>9375||b2)

*/

//while(scanf("%d.%d",&x1,&x2)!=EOF){
double p;
while(1){
	scanf("%lf",&p);
	
	if(p<0)break;
	x1=(int)p;p=p*10000;x2=(int)p-10000*x1;
//x2*=1000;
//if(x1>255||x2>9375||x2<625)printf("NA\n");

//else 
{
if(x1>=128){x1=x1-128;b1[0]=1;}
if(x1>=64){x1=x1-64;b1[1]=1;}
if(x1>=32){x1=x1-32;b1[2]=1;}
if(x1>=16){x1=x1-16;b1[3]=1;}
if(x1>=8){x1=x1-8;b1[4]=1;}
if(x1>=4){x1=x1-4;b1[5]=1;}
if(x1>=2){x1=x1-2;b1[6]=1;}
if(x1>=1){x1=x1-1;b1[7]=1;}

if(x2>=5000){x2=x2-5000;b2[0]=1;}
if(x2>=2500){x2=x2-2500;b2[1]=1;}
if(x2>=1250){x2=x2-1250;b2[2]=1;}
if(x2>=625){x2=x2-625;b2[3]=1;}

if(x1==0&&x2==0)
{
for(int i=0;i<8;i++)
printf("%d",b1[i]);

printf(".");

for(int i=0;i<4;i++)
printf("%d",b2[i]);

printf("\n");

}

else printf("NA\n");


for(int i=0;i<9;i++)
{
b1[i]=0;b2[i]=0;
}


}
}
return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

struct HashPair {

    static size_t m_hash_pair_random;

    template<class T1, class T2>
    size_t operator()(const pair<T1, T2> &p) const {

        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);

        size_t seed = 0;
        seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        seed ^= m_hash_pair_random + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};

size_t HashPair::m_hash_pair_random = (size_t) random_device()();

int main(int argc, char const *argv[])
{
    int A, B, m;
    cin >>A>>B>>m;
    vector<int> a(A), b(B);
    int a_min = INT_MAX, b_min = INT_MAX;
    rep(i, A) {
        cin >> a[i];
        amin(a_min, a[i]);
    }
    rep(i, B) {
        cin >> b[i];
        amin(b_min, b[i]);
    }
    int min = a_min + b_min;
    // unordered_map<pii, int, HashPair> um;
    rep(j, m) {
        int x, y, c;
        cin >> x>>y>>c;
        x--; y--;
        // amax(um[pii(x,y)], c);
        amin(min, a[x] + b[y] - c);
    }
    
    // rep(i, A) {
    //     rep(j, B) {
    //         int x;
    //         try
    //         {
    //             x = um.at(pii(i,j));
    //         }
    //         catch(const std::exception& e)
    //         {
    //             x = 0;
    //         }
    //         amin(min, a[i] + b[j] - x);
    //     }
    // }
    cout << min << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 100005
#define mod 1000000007

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

   string s;
   cin>>s;

   int re=1;

   char a=s[0];

   for(int i=1;i<n;i++)
   {
       if(a!=s[i])re++,a=s[i];
   }

    cout<<re<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main(){
  long long int N,i,S=0;
  scanf("%lld",&N);
  for(i=1;i<N+1;i++){
    if(i%3!=0 && i%5!=0){
      S+=i;
    }
  }
  printf("%lld\n",S);
  return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
double a,b,x,tmp,c;
int main(){
	cin>>a>>b>>x;
	if((x/a/a)>b/2){
		c=2.00*x/a/a-b;
		tmp=atan((b-c)/a);
		tmp=tmp*180.0/pi;
		printf("%.10lf",tmp);
		return 0;
	}else{
		c=x*2.00/a/b;
		tmp=atan(b/c);
		tmp=tmp*180.0/pi;
		printf("%.10lf",tmp);
		return  0;
	}
}

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


int main(){
    ll A, B;
    cin >> A >> B;
    if(A * B < 0 || A == 0 || B == 0){
        cout << "Zero" << endl;
    }else if(A < 0 && B < 0 && (abs(A) - abs(B) + 1) % 2 == 1 ){
        cout << "Negative" << endl;
    }else{
        cout << "Positive" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<ll> a(N), b(N);
  for (int i=0; i<N; i++) cin >> a[i];
  for (int i=0; i<N; i++) cin >> b[i];
  ll dif1 = 0, dif2 = 0; // a[i]<b[i]の時の差の合計とa[i]>b[i]の時の差の合計
  for (int i=0; i<N; i++) {
    if (a[i]<b[i]) dif1 += (b[i]-a[i])/2;
    else if (a[i]>b[i]) dif2 += a[i]-b[i];
  }
  if (dif1>=dif2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  string s, t;
  cin >> s >> t;
  int len = t.size();
  int ans = len;
  for (int i = 0; i < s.size() - len + 1; i++) {
    string sub = s.substr(i, len);
    int cnt = 0;
    for (int j = 0; j < len; j++) {
      cnt += (sub[j] != t[j]);
    }
    cerr << sub << " " << cnt << endl;
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <cstdio>

int main (int argc, char *argv[]) {
	using namespace std;
	int a, b, c, d, e, f;
	while (EOF != fscanf(stdin, "%d %d %d %d %d %d\n", &a, &b, &c, &d, &e, &f)) {
		float tmp1 = static_cast<float>(f)-(static_cast<float>(c)*static_cast<float>(d)/static_cast<float>(a));
		float tmp2 = static_cast<float>(e)-(static_cast<float>(b)*static_cast<float>(d)/static_cast<float>(a));
		float y = tmp1/tmp2;
		float x = (static_cast<float>(c) - static_cast<float>(b) * y) / static_cast<float>(a);
		printf("%.3f %.3f\n", x, y);		
		//printf("y=%f\n", (f-(c*d/a))/(e-(b*d/a)));
	}
	
	return 0;
}

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

const int N = 1e5 + 5, mod = 1e9 + 7, inf = INT_MAX;

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    int n, m, c, x, ans = inf;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (x == 1)
            c = i + 1;
    }
    for (int i = max(1, c - m + 1); i <= n; i++)
    {
        int l = i, r = i + m - 1;
        ans = min(ans, 1 + (l - 1) / (m - 1) + ((l - 1) % (m - 1) == 0? 0: 1) +
                           (n - r) / (m - 1) + ((n - r) % (m - 1) == 0? 0: 1));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3576
n = int(input())
a = [int(i) for i in input().split()]

ans1 = ans2 = 0
s = s2 = a[0]
if a[0] <= 0:
    s = 1
    ans1 = -a[0] + 1
if a[0] >= 0:
    s2 = -1
    ans2 = a[0] + 1

for i in range(1, len(a)):
    s += a[i]
    if i % 2 == 1 and s >= 0:
        ans1 += s + 1
        s = -1
    elif i % 2 == 0 and s <= 0:
        ans1 += -s + 1
        s = 1
    s2 += a[i]
    if i % 2 == 0 and s2 >= 0:
        ans2 += s2 + 1
        s2 = -1
    elif i % 2 == 1 and s2 <= 0:
        ans2 += -s2 + 1
        s2 = 1

print(min(ans1, ans2))


Measured memory_bytes: 14468
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define endl "\n"
#define pii pair<int,int>
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const int N=1e5+5;
ll a[N];
void amfetamin()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
int main()
{
amfetamin();
ll n;
ll smurf;
cin>>n;
smurf=n;
int sol=0;
for (ll i=2; i<=sqrt(n); i++)
{
    int ct=0;
    int prev=0;
    int raz=1;
    while (smurf%i==0)
    {
        ct++;
        smurf/=i;
        if (ct-prev==raz)
        {
            sol++;
            prev=ct;
            raz++;
        }
    }
}
if (smurf>1)
    sol++;
cout<<sol;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int a[10];
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	int n;
	n = 4;
	int x;
	rep(i,n){
		cin >> x;
		a[x]++;
	}
	if(a[1] && a[9] && a[7] && a[4])cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

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

    int n;
    double m;
    cin >> n >> m;
    int a[n+1];
    double sum = 0;
    for(int i=0; i<n; i++){
		cin >> a[i];
		sum += a[i];
    }
    double d = sum*(1/(4*m));
    //cout << d << endl;
    int ans = 0;
    for(int i=0; i<n; i++){
		if(a[i] >= d) ans++;
    }

    if(ans >= m) cout << "Yes";
    else cout << "No";

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M, L) = readLine()!!.split(" ").map{it.toInt()}
    val INF = 1e15.toLong()
    val d = Array(N + 1) { i -> LongArray(N + 1) {
        if (i == it) 0L else INF
    } }

    for (i in 1..M) {
        val (A, B, C) = readLine()!!.split(" ").map{it.toInt()}
        d[A][B] = C.toLong()
        d[B][A] = C.toLong()
    }

    for (k in d.indices) for (i in d.indices) for (j in d.indices) {
        d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
    }

    for (i in d.indices) for (j in d.indices) {
        if (i == j) continue

        d[i][j] = if (d[i][j] <= L) 1 else INF
    }

    for (k in d.indices) for (i in d.indices) for (j in d.indices) {
        d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
    }

    val Q = readLine()!!.toInt()
    for (i in 1..Q) {
        val (s, t) = readLine()!!.split(" ").map{it.toInt()}

        if (d[s][t] == INF) {
            println(-1)
        } else {
            println(d[s][t] - 1)
        }
    }
}

Measured memory_bytes: 69012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		StringBuilder buider = new StringBuilder();

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String n = br.readLine();

		String[] Snums = br.readLine().split(" ");

		int[]  nums = new int[Integer.parseInt(n)];

		for(int i= 0; i<Integer.parseInt(n); i++){
			nums[i]  = Integer.parseInt(Snums[i]);
		}
		int key =0;
		int j=0;
		for(int i=1; i<nums.length; i++){
			key = nums[i];
			j = i-1;
			for(int k=0; k<nums.length; k++){
				buider.append(nums[k]);
				if(k != nums.length-1){
				buider.append(" ");
				}
			}
			System.out.println(buider.toString());
			buider.setLength(0);
			while (j>=0 && nums[j]>key) {
				nums[j+1] =nums[j];
				j--;
			}
			nums[j+1] =key;
		}
		for(int k=0; k<nums.length; k++){
			buider.append(nums[k]);
			if(k != nums.length-1){
			buider.append(" ");
			}
		}
		System.out.println(buider.toString());



	}

}

Measured memory_bytes: 26632
def a_triangle(S, M=10**9):
    q, r = divmod(S, M)
    y = q if r == 0 else q + 1
    x = M * y - S
    return '0 0 {0} 1 {1} {2}'.format(M, x, y)

S = int(input())
print(a_triangle(S))

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define fi first
#define se second

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())

#define PF(a) push_front(a)
#define PB(a) push_back(a)
#define EMPF(...) emplace_front(__VA_ARGS__)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))

#define PW(n) (1LL << (n))
#define NUM(x) char(x + '0')
#define ALP(x) char(x + 'a')

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> void SORT(vector<T> &a) { sort(a.begin(), a.end()); }
template <class T> void SORTR(vector<T> &a) { sort(a.rbegin(), a.rend()); }
template <class T> void UNIQUE(vector<T> &a) { a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int A, B;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> A >> B;
  cout << (B % A == 0 ? A + B : B - A) << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int n;
	cin >> n;
	vector<int>p(n);
	REP(i, n)cin >> p[i];
	int cnt = 0;

	FOR(i, 1, n - 1) {
		vector<int> v;
		FOR(j, -1, 2)v.push_back(p[i + j]);
		sort(v.begin(), v.end());
		if (v[1] == p[i])cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,ss="keyence";
    cin>>s;
    bool flag=false;
    for(int i=0;i<=7;i++)
        if(s.substr(0,i)+s.substr(s.size()-(7-i),7-i)==ss) {flag=true;break;}
    if(flag) printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
class Fenwick{
private:
    int length;
    long long *vec;
public:
    Fenwick(int l);
    ~Fenwick();
    void add(int a,long long x);
    long long sum(int a);
    long long sum(int a,int b);
    long long operator[](int i);
    void init();
    void set(int a,long long x);
    void debug();
};
Fenwick::Fenwick(int l){
    length=l;
    vec=new long long[l+1];
    init();
}
Fenwick::~Fenwick(){
    delete[] vec;
}
// v[1]+...+v[a], O(log N)
long long Fenwick::sum(int a){
    if(a<0)return 0;
    if(a>length)a=length;
    long long sum=0;
    while(a>0){
        sum+=vec[a];
        a-=a&(-a);
    }
    return sum;
}
// v[a+1]+v[a+2]+...+v[b], O(log N)
long long Fenwick::sum(int a,int b){
    return sum(b)-sum(a);
}
// v[a]+=x, O(log N)
void Fenwick::add(int a,long long x){
    if(a<=0||a>length)return;
    while(a<=length){
        vec[a]+=x;
        a+=a&(-a);
    }
}
// v[a]=x, O(log N)
void Fenwick::set(int a,long long x){
    add(a,x-operator[](a));
}
long long Fenwick::operator[](int i){
    return sum(i)-sum(i-1);
}
void Fenwick::init(){
    for(int i=0;i<=length;i++){
        vec[i]=0;
    }
}
void Fenwick::debug(){
    for(int i=0;i<=length;i++)printf("%lld ",vec[i]);
    printf("\n");
}
int main(){
    int n;
    scanf("%d",&n);
    std::vector<std::pair<int,int>> v,w;
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        v.push_back({a,i});
    }
    //数列Aを転倒数が等しい{1,...,n}の置換に書き換える
    std::sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        w.push_back({v[i].second,i+1});
    }
    std::sort(w.begin(),w.end());
    Fenwick f(n);
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=i-f.sum(w[i].second);
        f.add(w[i].second,1);
        //f.debug();
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7364
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

char s[112345];

int main(){
	scanf("%s" , s);
	if(s[2] == 0){
		if(s[0] == s[1]){
			printf("1 2\n");
		} else {
			printf("-1 -1\n");
		}
	} else {
		for(int i = 2 ; s[i] != 0 ; ++i){
			if(s[i - 2] == s[i - 1] || s[i - 1] == s[i] || s[i - 2] == s[i]){
				printf("%d %d\n" , i - 1 , i + 1);
				return 0;
			}
		}
		printf("-1 -1\n");
	}
	return 0;
}


Measured memory_bytes: 256
#n = input()
a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#c = list(map(int, input().split()))
r = 1
c = 0
if a[1] == 1:
    print(0)
elif a[0] == a[1]:
    print(1)
else:
    while r < a[1]:
        c += 1
        r -= 1
        r += a[0]
    print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main() {
    int n;
    cin >> n;
    vector<ll> a(n),b(n),c(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) cin >> c[i];
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        auto it_low = lower_bound(a.begin(),a.end(),b[i]);
        auto it_up = upper_bound(c.begin(),c.end(),b[i]);

        ll d1 = distance(a.begin(),it_low);
        ll d2 = distance(it_up,c.end());
        ans += d1*d2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
x, k, d = map(int, input().split())
x = abs(x)
a = x//d
k2 = k-a
if x-k*d > 0:
    print(x-k*d)
    exit()

if k2%2 == 0:
    print(x%d)
else:
    print(abs(x%d-d))


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
const int MX = 20111111;
int A[MX];
int B[MX];
int C[MX];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(MX);
	int H,W,k; cin>>H>>W>>k;
	int ans=0;
	for(int S=1;S<=k;S++)
	{
		/*
		for(int h=0;h<=min(H,S);h++)
		{
			ans=add(ans,mult(h+1,mult(S-h+1,mult(choose(S,h),choose(H+W-S,H-h)))));
		}
		*/
		int c0 = choose(H+W,H);
		int c1 = mult(S, choose(H+W-1,H-1));
		int c2 = mult(S, mult(MOD+S-1, choose(H+W-2,H-2)));
		//cerr<<c0<<' '<<c1<<' '<<c2<<'\n';
		int res=0;
		res=add(res,mult(S,c0));
		res=add(res,mult(S,c1));
		res=add(res,MOD-c2);
		res=add(res,MOD-c1);
		res=add(res,c0);
		//cerr<<S<<' '<<res<<'\n';
		ans=add(ans,res);
	}
	ans=mult(ans,fact[H]);
	ans=mult(ans,fact[W]);
	ans=mult(ans,ifact[H+W-k]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 314624