akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H - h) * (W - w) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,w,i,j,ans[105][105];
	char ch[105][105];
	cin>>h>>w;
	for(i=0;i<h;i++) cin>>ch[i];
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(ch[i][j]=='.'){
				int hr=0;
				if(i-1>=0&&j-1>=0&&ch[i-1][j-1]=='#')
					hr++;
				if(i-1>=0&&ch[i-1][j]=='#')
					hr++;
				if(i-1>=0&&j+1<w&&ch[i-1][j+1]=='#')
					hr++;
				if(j-1>=0&&ch[i][j-1]=='#')
					hr++;
				if(j+1<w&&ch[i][j+1]=='#')
					hr++;
				if(i+1<h&&j-1>=0&&ch[i+1][j-1]=='#')
					hr++;
				if(i+1<h&&ch[i+1][j]=='#')
					hr++;
				if(i+1<h&&j+1<w&&ch[i+1][j+1]=='#')
					hr++;
				ans[i][j]=hr;
			}
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(ch[i][j]=='.'){
				cout<<ans[i][j];
			}
			else{
				cout<<"#";
			}
		}
		cout<<endl;
	}
	return 0;
}

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

int main()
{
  int N;
  long long H[110000];
  int res=0;
  cin >> N;

  for(int i=0;i<N;i++) cin >> H[i];
  reverse(H,H+N);

  int nhops=0;
  for(int i=1;i<N;i++){
    if(H[i]>=H[i-1]) nhops+=1;
    else nhops = 0;
    if(nhops > res) res = nhops;
  }
  
  cout << res << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[][] matrix = new int[n][63];
		for (int i = 0; i < n; i++) {
		    matrix[i][0] = sc.nextInt() - 1;
		}
		for (int i = 1; i < 63; i++) {
		    for (int j = 0; j < n; j++) {
		        matrix[j][i] = matrix[matrix[j][i - 1]][i - 1];
		    }
		}
		int idx = 0;
		for (int i = 62; i >= 0; i--) {
		    if (k >= (1L << i)) {
		        idx = matrix[idx][i];
		        k -= (1L << i);
		    }
		}
		System.out.println(idx + 1);
	}
}


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

using namespace std;

void Main()
{
    int a, b;
    cin >> a >> b;

    int ret = -1;
    if (a < 10 && b < 10)
        ret = a * b;

    cout << ret;
}

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

    std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

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

int main(){
    int n;
    string s,t1,t2;
    cin >> n;
    cin >> s;
    if(s.size()%2 == 1) cout << "No" << endl;
    else{
    t1 = s.substr(0,s.size()/2);
    t2 = s.substr(s.size()/2,s.size()/2);
    if(t1 == t2) cout << "Yes" << endl;
    else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

ll a, b, x, ans;

int main()
{
    cin >> a >> b >> x;
    ans += b/x;
    ans -= ((a==0)?-1:(a-1)/x);
    cout << ans << endl;
    return 0;
}

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

const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int n, dp[N][3], pts[N][3];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for(int i = 1; i <= n; i++) 
    cin >> pts[i][0] >> pts[i][1] >> pts[i][2];
  
  dp[1][0] = pts[1][0];
  dp[1][1] = pts[1][1];
  dp[1][2] = pts[1][2];
  for(int i = 2; i <= n; i++) {
    dp[i][0] = pts[i][0] + 
      max({dp[i-1][1], dp[i-1][2], (i-2 >= 0 ? dp[i-2][0] : 0)});
    dp[i][1] = pts[i][1] + 
      max({dp[i-1][0], dp[i-1][2], (i-2 >= 0 ? dp[i-2][1] : 0)});
    dp[i][2] = pts[i][2] + 
      max({dp[i-1][0], dp[i-1][1], (i-2 >= 0 ? dp[i-2][2] : 0)});
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
}


Measured memory_bytes: 2560
// https://atcoder.jp/contests/agc024/tasks/agc024_a

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long a, b, c, k;
    cin >> a >> b >> c >> k;
    int sgn = k & 1 ? 1 : -1;
    cout << (sgn * (b - a)) << endl;
    return 0;
}


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



int main()
{
    
   int n,m,sum=0;
   cin>>n>>m;
   int a[n];
   for (int i = 0; i < n; ++i)
   {
       cin>>a[i];
       sum+=a[i];
   }
   sort(a,a+n);
   if(a[n-m]>=(double(sum)/4)/m)
   {
    cout<<"Yes"<<endl;
   }
   else
   {
    cout<<"No"<<endl;
   }
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


N = INT()
e = [[] for _ in range(N)]

for _ in range(N-1):
    t = LIST()
    e[t[0]-1].append([t[1]-1, t[2]%2])
    e[t[1]-1].append([t[0]-1, t[2]%2])

a = [0] * N
f = [0] * N

"""
for edge in G:
    if edge[2]%2 == 1:
        a[edge[1]-1] = 1 - a[edge[0]-1]
    else:
        a[edge[1]-1] = a[edge[0]-1]
"""
def r(n):
    f[n] = 1
    for nn in e[n]:
        if f[nn[0]] == 0:
            if nn[1] == 0:
                a[nn[0]] = a[n]
                r(nn[0])
            else:
                a[nn[0]] = 1 - a[n]
                r(nn[0])

r(0)
for item in a:
    print(item)


Measured memory_bytes: 85668
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int a[100];
	f(i, 100)a[i] = 0;
	int k, s;
	int n, m;
	int x, y, z;
	int ans = 1;
	scanf("%d", &n);
	x = 1;
	f(i, n){
		ans = ans * 3;
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0)x=x * 2;
	}

	ans -= x;

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

	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
	static int []segmentTree;

	static void build(int []nums) {
		int n = nums.length;
		for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i];
		for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		}
	}

	static int query(int l, int r, int n) {
		int sum = 0;
		for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		}
		return sum;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;
		n = in.nextInt();
		int []nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = in.nextInt();
		int dp[] = new int[n+1];
		for (int i=1; i<n; i++) {
			dp[i] = dp[i-1]+Math.abs(nums[i] - nums[i-1]);
			if (i-2 >= 0) 
				dp[i] = Math.min(dp[i],dp[i-2] +Math.abs(nums[i] - nums[i-2]));
		}
		// for (int i=0; i<n; i++)
		// 	System.out.print(dp[i]+" ");
		// System.out.println();
		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 50488
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;
//ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	//t %= mod;
	if (n % 2 == 1)t *= a;
	return t /*% mod*/;
}

//const int INF = 1001001001;
const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll, ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0;
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


int main() {
	int n;
	cin >> n;
	n %= 1000;
	if (n == 0)n = 1000;
	cout << 1000 - n << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

ll inf = pow(10,9)+7;
ll mpow(ll x, ll n){
  if(n==0){ return 1; }
  if(n%2==0){
    ll t = mpow(x,n/2);
    return (t*t) % inf;
  }
  return (x * mpow(x,n-1))%inf;
}
ll kaijo(ll x){
  if(x==1){ return 1; }
  else{ return (kaijo(x-1)*x)%inf; }
}
ll combination(ll n, ll a){
  ll r = 1;
  REP(i,a){
    r *= (n-i);
    r %= inf;
  }
  r *= mpow(kaijo(a), inf-2);
  r %= inf;
  return r;
}

int main(){
  ll N,a,b; cin>>N>>a>>b;
  
  ll ans = mpow(2,N)-1;
  ans -= combination(N,a);
  ans -= combination(N,b);
  while(ans<0){ ans += inf; }
  cout << ans <<"\n";
}



Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        boolean first = false;
        boolean second = false;
        long firstNum = 0;
        long secondNum = 0;
        long tmp = a[0];
        int count = 1;
        for (int i = 1; i < n; i++) {
            if (tmp == a[i]) {
                count++;
                if (count % 2 == 1)
                    continue;
                if (!first && !second) {
                    firstNum = tmp;
                    first = true;
                } else if (first && !second) {
                    secondNum = tmp;
                    second = true;
                } else if (first && second) {
                    long x = secondNum;
                    secondNum = a[i];
                    firstNum = x;
                }
            } else {
                tmp = a[i];
                count = 1;
            }
        }
        long ans = firstNum * secondNum;
        System.out.println(ans);
    }
}

Measured memory_bytes: 50172
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int A, B, H, M;
	cin >> A >> B >> H >> M;
	double Ad = (double)A, Bd = (double)B;

	double s = abs((((double)H + ((double)M / 60.f)) / 12.f) - ((double)M / 60.f)) * 2 * acos(-1);
	double ans = pow(Ad, 2) + pow(Bd, 2) - 2 * Ad * Bd * cos(s);
	ans = sqrt(ans);

	printf("%.12lf\n", ans);

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

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

	vector<int> A(N);
	rep(i, N) {
		cin >> A.at(i);	
	}	

	bool can = true;
	int cnt = 0;
	while (can) {
		rep(i, N) {
			if (A.at(i) % 2 != 0) {
				can = false;
			}
		}

		if (can) {
			cnt++;
			rep(i, N) {
				A.at(i) = A.at(i) / 2;
			}
		}	
	}	

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<string>v;
int main()
{
	string s;
	int k;
	cin>>s>>k;
	for(int i=0;i<s.size();i++)
	{
		string cur;
		for(int j=i;j<s.size()&&j<i+k;j++)
			cur+=s[j],
			v.push_back(cur);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	cout<<v[k-1];
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int h, w, n;
	cin>>h>>w>>n;
	if(h > w) swap(h, w);
	cout<<(n + w - 1) / w<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
    ll a,b,c;
    string s,t;
    cin>>a>>b;
    rep(i,b){
    	cin>>c;
    	a-=c;
    }
    cout<<(a>=0?a:-1);
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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 cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int x, a, b;
void in(){
    cin >> x >> a >> b;
}

void solve(){

    print((x - a) % b);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

int main()
{
  int N=0;
  int count=0;
  cin >> N;
  vector<int> data(N);
  for(int i=0; i<N; i++)
  {
    cin >> data.at(i);
  }
  for(int i=0; i<data.size(); i+=2)
  {
	if(data.at(i) % 2 != 0) count++;
  }
  cout << count << endl;
  return 0;
}

      

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];
ll B[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, T;
    cin >> N >> M >> T;
    ll am = INF, bm = INF;
    REP(i, N) {
        cin >> A[i];
        am = std::min(am, A[i]);
    }
    REP(i, M) {
        cin >> B[i];
        bm = std::min(bm, B[i]);
    }

    ll ans = am + bm;
    REP(i, T) {
        ll x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ans = std::min(ans, A[x] + B[y] - c);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	ll a, b, w;
	cin >> w >> a >> b;
	if (a > b)swap(a, b);
	ll ans = (b - (a + w));
	ans = max(ans, (ll)0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

//istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
//ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int N;
	cin >> N;
	ll mx = 0;
	ll ac = 0;	
	rep(i,N) {
		ac += i+1;
		mx = i+1;
		if(ac >= N) break;
	}
	ac = N;
	for(int i = mx; i > 0; i--) {
		if(ac - i >= 0) {
			ac -= i;
			cout << i << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    int sx, sy, tx, ty;
    std::cin >> sx >> sy >> tx >> ty;

    //↑
    for (size_t i = 0; i < ty - sy; ++i) {
        std::cout << "U";
    }
    //→
    for (size_t i = 0; i < tx - sx; ++i) {
        std::cout << "R";
    }

    //↓
    for (size_t i = 0; i < ty - sy; ++i) {
        std::cout << "D";
    }

    //←
    for (size_t i = 0; i < tx - sx; ++i) {
        std::cout << "L";
    }

    //← 1
    std::cout << "L";

    //↑ +1
    for (size_t i = 0; i < ty - sy; ++i) {
        std::cout << "U";
    }
    std::cout << "U";

    //→ +1
    //↓ 1
    //→ 1
    for (size_t i = 0; i < tx - sx; ++i) {
        std::cout << "R";
    }
    std::cout << "RDR";

    //↓ + 1
    for (size_t i = 0; i < ty - sy; ++i) {
        std::cout << "D";
    }
    std::cout << "D";

    //← +1
    for (size_t i = 0; i < tx - sx; ++i) {
        std::cout << "L";
    }
    std::cout << "L";

    //↑ 1
    std::cout << "U";

    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

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

	ll n = 0;
	cin >> n;
	ll sum = 0, tmp = n;
	
	while(tmp > 0)
	{
		sum += tmp % 10;
		tmp /= 10;
	}
	if(n % sum == 0)	cout << "Yes" << endl;
	else	cout << "No" << endl;
	#ifdef LOCAL_DEFINE
		cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}



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

using namespace std;

int main(){

	int d[31];
	d[2]=0;
	d[3]=1;
	for(int i = 4; i < 31; i++){
		d[i]=d[i-1]+(int)pow(3.0,i-3);
	}

	int n;
	while(cin>>n){
		if(n==1)
			cout<<1<<endl;
		else if(n==2)
			cout<<2<<endl;
		else if(n==3)
			cout<<5<<endl;
		else if(n==4)
			cout<<8<<endl;
		else if(n%2==1){
			int t=((n)/2);
			int sum=0;
			while(t>=2){
				if(t==n/2){
					int m = d[t];
					if(m!=0){
						sum += (2*(m+pow(3.0,t-3)*4*3))+1;
					}
					else{
						sum+=8+1;
					}
				}
				else{
					int m=d[t];
					if(m!=0)
						sum+=((2*(m+pow(3.0,t-3)*4*3))+1)*2;
					else
						sum+=(8+1)*2;
				}
				t--;
			}
			cout<<sum+2*4<<endl;
		}
		else{
			int t=((n-1)/2);
			int sum=0;
			while(t>=2){
				int m=d[t];
				if(m!=0)
					sum+=((2*(m+pow(3.0,t-3)*4*3))+1)*2;
				else
					sum+=(8+1)*2;
				t--;
			}
			cout<<sum+2*4<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a, b;
  cin >> a>> b;
  cout << a - 1+ (a <= b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int a[22][22];
int dp[22][(1<<22)];
int solve(int n,int x,int mask){
    if(x==n+1){
        if(mask==0){
            return 1;
        }
        else{
            return 0;
        }
    }
    if(dp[x][mask]!=-1){
        return dp[x][mask];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if( ((1<<i)&mask)!=0 && a[x][i+1]==1){
            ans=(ans+solve(n,x+1,mask^(1<<i)))%mod;
        }
    }
    return dp[x][mask]=ans;
}
int32_t main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }
    int mask=(1<<n)-1;
    memset(dp,-1,sizeof dp);
    cout<<solve(n,1,mask)<<endl;
    return 0;
}

Measured memory_bytes: 721280
#include<bits/stdc++.h>
#define MAXN 200005
#define LL long long
using namespace std;

int N;
int M0 = 2e9, M1 = -1;
int A0,A1,B0,B1,id0,id1;

struct Node{
	int x,y;
	Node(int x=0, int y=0):x(x), y(y){}
	
	bool operator < (const Node& n1) const{
		return min(x,y) < min(n1.x,n1.y);
	}
} n[MAXN];

LL solve0(){
	if(id0==id1) return 1e18;
	A0 = M0;
	A1 = M1;
	
	static int py0[MAXN], py1[MAXN];
	py0[0] = 1e9;
	py1[0] = 0;
	int x,y,ans = 1e9;
	for(int i=1;i<N;i++){
		x = n[i].x; y = n[i].y;
		py0[i] = min(py0[i-1], y);
		py1[i] = max(py1[i-1], y);
		ans = min(ans, max(n[N].x, py1[i]) - min(n[i+1].x, py0[i]));
	}
	return (LL)ans*(A1-A0);
}

LL solve1(){
	A1 = M1;
	B0 = M0;
	
	if(n[id0].x == M0) A0 = n[id0].y;
	else A0 = n[id0].x;
	if(n[id1].x == M1) B1 = n[id1].y;
	else B1 = n[id1].x;

	int x,y;
	for(int i=1;i<=N;i++){
		if(i==id0 || i==id1) continue;
		x = n[i].x; y = n[i].y;
		
		B1 = max(B1, min(x, y));
		A0 = min(A0, max(x, y));
	}
	return (LL)(A1-A0)*(B1-B0);
}

void work(){
	scanf("%d", &N);
	
	int x,y;
	for(int i=1;i<=N;i++){
		scanf("%d%d", &x, &y);
		n[i].x = min(x, y);
		n[i].y = max(x, y);
	}
	sort(n+1, n+1+N);
	
	M0 = 2e9, M1 = -1;
	for(int i=1;i<=N;i++){
		x = n[i].x; y = n[i].y;
		if(M0 > min(x, y)){
			id0 = i;
			M0 = min(x, y);
		}
		if(M1 < max(x, y)){
			id1 = i;
			M1 = max(x, y);
		}
	}

	printf("%lld\n", min(solve0(), solve1()));
}

int main(){
	//freopen("01.in", "r", stdin);
	//freopen("01.ans", "w", stdout);
	int T;
	//scanf("%d", &T);
	T = 1; 
	while(T--){
		work();
	}
	
	return 0;
}


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

using namespace std;

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) {
				ret *= a;
			}
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

template <class T> T fastpow(T a, long long p) {
	T tmp = a;
	T ret = 1;
	while (p) {
		if (p & 1) ret *= tmp;
		p >>= 1;
		tmp = tmp * tmp;
	}
	return ret;
}

class Solution {
public:
	void solve() {
		int n, k;
		cin >> n >> k;
		vector<mint> dp(k + 1);
		mint ans;
		for (int i = k; i >= 1; i--) {
			dp[i] = fastpow(mint(k / i), n);
			for (int j = 2 * i; j <= k; j += i) dp[i] -= dp[j];
			ans += dp[i] * i;
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;cin >> n;
    n--;
    cout << a[n] << endl;
}

Measured memory_bytes: 256
def base4(x):
    if int(x/4):
        return base4(int(x/4)) + str(x%4)
    return str(x%4)

N,A,B,C = list(map(int,input().split()))
l = []
for n in range(N):
    l.append(int(input()))

res = 99999999
for i in range(4**N):
    c = [[0,0,0],[0,0,0]]
    for j,b in enumerate(base4(i).zfill(N)):
        if int(b) != 0:
            c[0][int(b)-1] += l[j]
            c[1][int(b)-1] += 1
    if c[1][0] > 0 and c[1][1] > 0 and c[1][2] > 0:
        res = min(res,abs(c[0][0]-A)+abs(c[0][1]-B)+abs(c[0][2]-C)+(sum(c[1])-3)*10)

print(res)

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define aint(v) v.begin(),v.end()
#define endl "\n"
#define all(v) v.begin(),v.end()
#define clr(n, r) memset(n,r,sizeof(n))
typedef bitset<15> MASK;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;

void fast() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
    fast();
    int n;cin>>n;
    string arr[n];
    ll freq[200]={0};
    string march="MARCH";
    for (int i = 0; i < n; ++i) {
        cin>>arr[i];
        freq[arr[i][0]]++;
    }
    ll ans=0;
    for (int j = 0; j < 5; ++j) {
        for (int i = j+1; i <5 ; ++i) {
        for (int k = i+1; k <5 ; ++k) {
            ans += (freq[march[j]] * freq[march[i]]*freq[march[k]]);
        }   }
    }
    cout<<ans;
}


Measured memory_bytes: 6612
import java.io.*;
import java.util.Arrays;

public class Main {

	//ツ　2260 (iwi)
	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		String s = reader.readLine();
		
		int cnt = 0;
		for(int i = 0; i < (s.length()+1) / 2; i++) {
			int c1 = s.charAt(i);
			int c2 = s.charAt(s.length() - 1 - i);
			boolean eq = false;
			if ((c1 == 'i' || c1 == 'w') && c1 == c2) {
				eq = true;
			}
			if (c1 == '(' && c2 == ')') {
				eq = true;
			}
			if (c2 == '(' && c1 == ')') {
				eq = true;
			}
			if (!eq) {
				//System.out.printf("%c %c\n", s.charAt(i), s.charAt(s.length() - 1 - i));
				cnt++;
			}
		}		
		System.out.printf("%d\n", cnt);
		reader.close();
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    printf("%Lf ",(long double)w*h/2.0);
    if(2*x-w==0 && 2*y-h==0){
        cout << 1 << endl;
    }
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> svec;

int main() {
	int n, m;
	cin >> n >> m;
	vecint dp(n + 10, 0);
	vecint ban(n + 10, 0);
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		ban[a] = 1;
	}
	dp[0] = 1;
	if (ban[1] != 1)dp[1] = 1;
	for (int i = 2; i < n + 1; i++) {
		if (ban[i] == 1)continue;
		dp[i] = dp[i - 1] + dp[i - 2];
		dp[i] %= mod;
	}
	cout << dp[n] << endl;
}

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

int main(){
    int A, B;
    std::cin >> A >> B;
    if(A >= 10 || B >= 10 || A < 1 || B < 1){
        std::cout << "-1" << std::endl;
    }else{
        std::cout << A*B << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X;
  cin >> X;
  
  long long P = 100, step = 0;
    while(P < X) {
      P += P/ 100;
      step++;
    }
    cout << step << endl;
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int n;


int main() {
    //cout.precision(10);
    cin >> n;
    vector<l_l> field;
    for(int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        field.push_back({a + b, a});
    }
    sort(field.begin(), field.end());
    ll ans = 0;
    ll checker = -1;
    for(int i = 0; i < n; i++) {
        checker = -checker;
        ll now;
        if(i % 2 == 0) now = field[n - 1 - i].second;
        else now = -field[n - 1 - i].first + field[n - 1 - i].second;
        ans += now;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    ll n,k;cin>>n>>k;
    co(min(abs(n%k-k), n%k));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N;
ll K;
ll ret;

void calc(int i, const vector<int>& cnt, ll X, ll sum){
  for(; i>=0; i--){
    ll a = 1LL << i;
    int one = cnt[i];
    int zero = N - cnt[i];

    if(one <= zero){
      sum += zero * a;
    }else{
      sum += one * a;
    }
  }
  ret = max(ret, sum);
}
void dfs(int i, const vector<int>& cnt, ll X, ll sum){
  if(i < 0){
    ret = max(ret, sum);
    return;
  }
  ll a = 1LL << i;
  int one = cnt[i];
  int zero = N - cnt[i];
  
  if(X + a > K){
    // 0 only
    dfs(i-1, cnt, X, sum + one * a);
  }else{
    // 0 or 1
    calc(i-1, cnt, X, sum + one * a); // 0
    dfs(i-1, cnt, X + a, sum + zero * a); // 1
  }
}


int main(){
  cin >> N;
  cin >> K;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<int> cnt(63, 0);
  rep(i,N){
    ll a = v[i];
    int ii = 0;
    while(a > 0){
      if(a&1) cnt[ii]++;
      ii++;
      a >>= 1;
    }
  }

  ret = 0;
  dfs(62, cnt, 0, 0);

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long N;
  long a = 0,b = 0,sum = 1000,temp = 0;
  cin >> N;
  for(int i = 1;i < N;i++)
  { 
    a = i%10 + (i/10)%10 + (i/100)%10 +(i/1000)%10 + (i/10000)%10 + (i/100000)%10;
    b = (N - i)%10+((N-i)/10)%10+((N-i)/100)%10+((N-i)/1000)%10+((N-i)/10000)%10+((N-i)/100000)%10;
    temp = a+b;
    if(temp < sum){sum = temp;}
  }
  cout << sum << endl;
  return 0;
}
    

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long N;

int main()
{
	scanf("%lld", &N);
	if(N % 2 == 0) {
		printf("%lld\n", N);
	}
	else {
		printf("%lld\n", N * 2);
	}

	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

typedef struct {
  double x, y;
} Point;

void print(Point p){ printf("%.8f %.8f\n", p.x, p.y); }

void plot(int n, Point p1, Point p2){
  Point s, t, u;
  double th = 60.0*(acos(-1)/180.0);
  if ( n == 0 ) return;
  s.x = (2.0 * p1.x + 1.0 * p2.x)/3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y)/3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x)/3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y)/3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y ) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y ) * cos(th) + s.y;
  
  plot(n-1, p1, s);
  print(s);
  plot(n-1, s, u);
  print(u);
  plot(n-1, u, t);
  print(t);
  plot(n-1, t, p2);
}

main(){
  Point p1, p2;
  int n;
  scanf("%d", &n);

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  print(p1);
  plot(n, p1, p2);
  print(p2);

  return 0;
}


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



int main ()
{
    vector<int>a(10000);
    vector<int>b(10000);

    int cnt=0;

    for(int i=0;i<30000;i++)
    {
        cin>> a.at(i) >> b.at(i);
        if(a.at(i)==0 && b.at(i)==0) break;
        cnt++;  
    }

    for(int i=0;i<cnt;i++){
        cout << min(a.at(i),b.at(i)) << " " << max(a.at(i),b.at(i)) << endl;
    }

}



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

const int N = 110;

bool dp[N];
int a, b, c;

int main(){
	while(~scanf("%d %d %d", &a, &b, &c)){
		if(c == 0){
			puts("YES");
			continue;
		}
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
        for(int i=1; i<b; i++){
			int r = a * i % b;
            for(int j=0; j+r < b; j++){
				dp[j+r] = dp[j+r] | dp[j];
            }
            if(dp[c]){
				break;
            }
        }
        puts(dp[c]?"YES":"NO");
	}
	return 0;
}


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

int main(){
  
    string S;
    cin>>S;
    vector<char> A={'1','2','3','4','5','6','7','8','9'};
    vector<char> B={'0','1','2'};
    bool ans=false,ans2=false;
    if(S.at(0)=='0'){
    for(int i=0;i<9;i++){
        if(S.at(1)==A[i]) ans=true;
    }
    }
    if(S.at(0)=='1'){
        for(int i=0;i<3;i++){
            if(S.at(1)==B[i]) ans=true;
        }
    }
    if(S.at(2)=='0'){
        for(int i=0;i<9;i++){
            if(S.at(3)==A[i]) ans2=true;
        }
    }
    if(S.at(2)=='1'){
        for(int i=0;i<3;i++){
            if(S.at(3)==B[i]) ans2=true;
        }
    }
    if(ans&&ans2) cout<<"AMBIGUOUS"<<endl;
    else if(ans&&!ans2) cout<<"MMYY"<<endl;
    else if(!ans&&ans2) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
}
    


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

int main(){
  int Nlen,P;
  string S;
  cin >> Nlen >> P >> S;

  if(P==2 || P==5){
    int64_t ans= 0;
    for(int i=Nlen; i>0; i--){
      int dig_i= S.at(i-1)- '0';
      if(dig_i % P==0){
        ans+= (int64_t) i;
      }
    }

    cout << ans << endl;
    return 0;
  }
  else{
    int64_t ans= 0;
    vector<int64_t> mod(P);
    int modP= 0;
    mod.at(modP)++;
    for(int i=Nlen, t=1; i>0; i--, t= t*10 % P){
      int dig_i= S.at(i-1)- '0';
      modP= (modP+ t*dig_i) % P;
      mod.at(modP)++;
    }

    for(int i=0; i<P; i++){
      ans+= mod.at(i)*(mod.at(i)- 1)/2;
    }

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

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

int main() {
  int value;
  int v1;
  int v2;
  int v3;
  int v4;
  
  cin >> value;
  
  v1 = value / 1000;
  value = value - (v1 * 1000);
  v2 = value / 100;
  value = value - (v2 * 100);
  v3 = value / 10;
  value = value - (v3 * 10);
  v4 = value;

  if ((v1 == v2 && v1 == v3) || (v2 == v3 && v2 == v4))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
 }



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

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

  vi oks(N+1,true);
  rep(i,M) {
    int a; cin >> a;
    oks[a] = false;
  }

  vll dp(N+1);
  dp[0]=1;
  for(int now=0; now<N; now++) {
    for(int next=now+1; next<=min(N,now+2); ++next) {
      if(oks[next]) {
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }

  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] lengths = new int[n];
        for (int i = 0; i < n; ++i) {
            lengths[i] = scanner.nextInt();
        }
        int i;
        for (i = 1; i < n; ++i) {
            if (lengths[i] <= lengths[i - 1]) {
                break;
            }
        }
        if (i == n) {
            System.out.println(1);
            return;
        }
        int a = 1; // cannot
        int b = n; // can
        while (a + 1 < b) {
            int m = (a + b) / 2;
            boolean isOk = check(m, lengths);
            //   System.out.println("m: " + m + " isOk: " + isOk);
            if (isOk) {
                b = m;
            } else {
                a = m;
            }
        }
        System.out.println(b);
    }
    public static class Element {
        int pos;
        int value;

        public Element(int pos, int value) {
            this.pos = pos;
            this.value = value;
        }
    }

    public static boolean check(int m, int[] lengths) {
        Stack<Element> stack = new Stack<>();
        for (int i = 1; i < lengths.length; ++i) {
            if (lengths[i] > lengths[i - 1]) {
                continue;
            }
            while (!stack.isEmpty()) {
                Element end = stack.peek();
                if (end.pos > lengths[i]) {
                    stack.pop();
                } else {
                    break;
                }
            }
            int carry = 1;
            int targetPos = lengths[i];
            while (!stack.isEmpty()) {
                Element end = stack.peek();
                if (end.pos == targetPos) {
                    stack.pop();
                    if (end.value + carry < m) {
                        stack.push(new Element(targetPos, end.value + carry));
                        carry = 0;
                        break;
                    }
                    targetPos--;
                } else if (end.pos < targetPos) {
                    stack.push(new Element(targetPos, 1));
                    carry = 0;
                    break;
                }
            }
            if (carry > 0) {
                if (targetPos >= 1) {
                    stack.push(new Element(targetPos, 1));
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}


Measured memory_bytes: 96068
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<tuple<int, int, int>> t(n);
	rep(i,n){
		int a, b;
		cin >> a >> b;
		t[i] = make_tuple(a + b, a, b);
	}
	sort(all(t), greater<tuple<int,int,int>>());

	int ans = 0;
	rep(i,n){
		if(i % 2) ans -= get<2>(t[i]);
		else  ans += get<1>(t[i]);
	}

	cout << ans << endl;
}

signed main(){
	solve();
	return 0;
	int n;
	cin >> n;

	vector<tuple<int, int, int, int>> d(n);
	priority_queue<pair<int,int>> l, r;
	rep(i,n){
		int a, b;
		cin >> a >> b;
		d[i] = make_tuple(a - b, i, a, b);
		l.emplace(a,i);
		r.emplace(b,i);
	}
	sort(all(d));

	vector<bool> used(n, false);
	int ans = 0;
	int top = 0, bot = n - 1;
	rep(i,n){
		while(used[top]) top++;
		while(used[bot]) bot++;

		if(n % 2){
			if(d[top] == d[bot]){
				while(true){
					int num, idx;
					tie(num, idx) = r.top(); r.pop();
					if(used[idx]) continue;
					used[idx] = true;
					ans += num;
					break;
				}
			}else{
				used[bot] = true;
				ans -= get<3>(d[bot]);
				bot++;
			}
		}else{
			if(d[top] == d[bot]){
				while(true){
					int num, idx;
					tie(num, idx) = l.top(); l.pop();
					if(used[idx]) continue;
					used[idx] = true;
					ans += num;
					break;
				}
			}else{
				used[top] = true;
				ans += get<2>(d[top]);
				top++;
			}
		}
	}
}


Measured memory_bytes: 2560
A,B,C,D = map(int,input().split())

ans = "Yes"
turn = 1
while(1):
    if turn == 1:
        C -= B
        if C <= 0:
            break
    else:
        A -= D
        if A <= 0:
            ans = "No"
            break
    turn *= -1

print(ans)

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

int main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(a*b>c*d) cout<<a*b<<endl;
	else if(a*b<c*d) cout<<c*d<<endl;
	else cout<<a*b<<endl;
}

Measured memory_bytes: 3644
# https://atcoder.jp/contests/abc111/tasks/arc103_a

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

f_l = v[::2]
s_l = v[1::2]


def count_and_sort(l):
    dict = {}
    for f in l:
        if f not in dict:
            dict[f] = 1
        else:
            dict[f] += 1
    return sorted(dict.items(), key=lambda x: -x[1])


f_sorted = count_and_sort(f_l)
s_sorted = count_and_sort(s_l)

f1 = f_sorted[0]
s1 = s_sorted[0]

f2 = f_sorted[1] if len(f_sorted) > 1 else (0, 0)
s2 = s_sorted[1] if len(s_sorted) > 1 else (0, 0)

if f1[0] == s1[0]:  # 同じ値だったら使えない
    print(min(n - f1[1] - s2[1], (n - f2[1] - s1[1])))
else:
    print(n - f1[1] - s1[1])


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const vector<ii> dxy = {{1,0}, {-1,0}, {0,1}, {0,-1}};
const int N = 55;
int h, w, cnt;
char a[N][N];
int dist[N][N];

int main() {
    memset(dist, 255, sizeof dist);
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
            if (a[i][j] == '.')
                ++cnt;
        }
    }
    queue<ii> que;
    que.push({0, 0});
    dist[0][0] = 1;
    while (que.size()) {
        auto [x, y] = que.front();
        que.pop();
        for (auto [dx, dy] : dxy) {
            int nx = dx + x;
            int ny = dy + y;
            if (nx < 0 || ny < 0 || nx == h || ny == w) continue;
            if (a[nx][ny] == '.' && dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    if (dist[h - 1][w - 1] == -1)
        cout << -1 << endl;
    else
        cout << cnt - dist[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 3608