akhauriyash/Code-Regression huggingface dataset:
#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) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N;
int A[3002];
ll dp[3002][3002][2];
ll sagasu(int L, int R, int T) {
	if (dp[L][R][T] != 1e18) return dp[L][R][T];
	if (L > R) dp[L][R][T] = 0;
	else {
		ll a = sagasu(L + 1, R, (T + 1) % 2);
		ll b = sagasu(L, R - 1, (T + 1) % 2);
		if (T) dp[L][R][T] = min(a - A[L], b - A[R]);
		else dp[L][R][T] = max(a + A[L], b + A[R]);
	}
	return dp[L][R][T];
}


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


	cin >> N;
	rep1(i, N) cin >> A[i];
	
	rep(i, 3002) rep(j, 3002) rep(k, 2) dp[i][j][k] = 1e18;

	co(sagasu(1, N, 0));

	Would you please return 0;
}

Measured memory_bytes: 141184
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

if s.count('o')+15-len(s) >= 8:
   print('YES')
else:
   print('NO')

Measured memory_bytes: 38256
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 300010
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
        
        signed main()
        {
        	 int n;
        	 cin>>n;
        map<int,int> mp1;
        int sum=0;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            sum+=x;
            mp1[x]++;
        }
        int q;cin>>q;
        while(q--){
            int a,b;
            cin>>a>>b;
            int x=mp1[a];
            sum-=(x*a);
            mp1[a]=0;
            mp1[b]+=x;
            sum+=(x*b);
            cout<<sum<<endl;
        }
        	
		}

Measured memory_bytes: 9524
#include<iostream>

using namespace std;

int main(){

    long long int n,a,b;

    cin >> n;
    cin >> a;
    cin >> b;

    if(n%(a+b) <= a)
        cout << (n/(a+b))*a + (n%(a+b)) << endl;
    else
        cout << a + (n/(a+b))*a << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = n - 1; i>= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;

const double pi = 3.14159265359;
const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double theta1 = ((6*m));
	double theta2 = ((30*h) + (m/2));
	double angle = abs(theta1 - theta2);
	angle = min(angle, 360 - angle);
	double ans = sqrt(a*a + b*b - 2*a*b*cos(angle*pi/180));
	printf("%.15f",ans);
 	return 0;
}



Measured memory_bytes: 4244
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
  string n;
  string hon = "24579";
  string pon = "0168";
  string bon = "3";
  cin >> n;

  if (hon.find(n[n.length() - 1]) != std::string::npos)
  {
    cout << "hon";
  }
  else if (pon.find(n[n.length() - 1]) != std::string::npos)
  {
    cout << "pon";
  }
  else
  {
    cout << "bon";
  }

  return 0;
}

Measured memory_bytes: 3132
n = int(input())
inf = 1000000000 + 7
a=1; b=1;c=1
if n==2: ans=2
elif n==1: ans=0
elif n>2:
    for i in range(n):
        a = (10*a) % inf
        b = (9*b) % inf
        c = (8*c) % inf
    ans = int(a%inf - int(2*b)%inf + int(c)%inf)%inf
print(int(ans))

Measured memory_bytes: 62592
#include<iostream>

using namespace std;

typedef long long ll;

int main(){
    ll a, b, x, d;
    cin >> a >> b >> x;
    ll c = b / x;
    if(a % x == 0){
         d = a / x - 1;
    }
    else{
        d = a / x;
    }    
    cout << c - d << endl;
    return 0;
}

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

using namespace std;

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

    string S;
    cin >> S;

    vector<int> count(N);
    vector<int> count2(N);

    int i = 0;
    int k = 0;
    while(S[k] == '1'){
        count[i]++;
        k++;
    }

    while(S[k] != '\0'){
        while(S[k] == '0'){
            count[i]++;
            k++;
        }
        while(S[k] == '1'){
            count[i]++;
            count2[i]++;
            k++;
        }
        i++;
    }

    while(S[k] == '0'){
        count[i]++;
        k++;
    }

    vector<int> ans(N);
    for(int j = 0; j < K; j++)
        ans[0] += count[j];

    int temp = ans[0];
    for(int j = K; j < N; j++){
        ans[j-K+1] = temp;
        ans[j-K+1] -= count[j-K];
        ans[j-K+1] += count[j];
        temp = ans[j-K+1];
        ans[j-K+1] += count2[j-K];
    }
 
    sort(ans.begin(), ans.end(), greater<int>());

    cout << ans[0] << endl;

    return 0;
}

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

using ll = long long;

int main() {
    int N;  cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    ll ans = 0;
    priority_queue<ll> q;
    q.push(0);
    for (int i = 0; i < N; ++i) {
        ll q_top = q.top();  q.pop();
        ans += q_top;
        q.push(A[i]);
        if (i != 0) q.push(A[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 6828
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    char s[101];

    if(scanf("%s", s) == 1);

    if(strlen(s) == 20 && s[0] == 'i' && s[19] == 'n') {
        printf("i18n");
    } else {
        printf("%c%d%c", s[0], strlen(s) - 2, s[strlen(s) - 1]);
    }

    return 0;
}

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

lli d, t, s;

int main(void){
    cin >> d >> t >> s;
    if(t*s >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <set>
using namespace std;

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main() {
	int N, Q;
	scanf("%d %d", &N, &Q);
	UnionFind uf(N);
	for (int n = 0; n < Q; ++n) {
		int t, u, v;
		scanf("%d %d %d", &t, &u, &v);
		if (0 == t) {
			uf.merge(u, v);
		}
		else {
			if (uf.issame(u,v)) {
				printf("1\n");
			}
			else {
				printf("0\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4064
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  string s;
  cin >> s;

  ll stack = 0LL;
  ll ans = s.size();
  REP(i, s.size()){
    if(s[i] == 'S'){
      stack++;
    }
    else {
      if(stack>0){
	stack--;
	ans -= 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int white[4002][2000];
int black[4002][2000];
int dp[2002][2002][2];
int n;
char c[4005];
int  a[4005];
int bb[2002];
int dpw[2002];
int dpb[2002];
int bw[2002];
int main()
{
	cin>>n;
	rep(i,2*n)
	{
		cin>>c[i];
		cin>>a[i];
		a[i]--;
		if(c[i]=='B')
		{
			bb[a[i]]=i;
		}
		else bw[a[i]]=i;
	}
	rep(i,2*n)
	{
		rep(j,n)
		{
			if(c[i]=='W')
			{
				if(i!=0)
				{
					if(j>=a[i])
					{
						white[i][j]=white[i-1][j]+1;
					}
					else white[i][j]=white[i-1][j];
				}
				else 
				{
					if(j>=a[i])white[i][j]=1;
					else white[i][j]=0;
				}
				if(i==0)black[i][j]=0;
				else
				{
					black[i][j]=black[i-1][j];
				}
			}
			else
			{
				if(i==0)white[i][j]=0;
				else
				{
					white[i][j]=white[i-1][j];
				}
				if(i!=0)
				{
					if(j>=a[i])
					{
						black[i][j]=black[i-1][j]+1;
					}
					else black[i][j]=black[i-1][j];
				}
				else 
				{
					if(j>=a[i])black[i][j]=1;
					else black[i][j]=0;
				}
			}
		}
	}
	/*rep(i,2*n)
	{
		rep(j,n)
		{
			cout<<black[i][j]<<' ';
		}
		cout<<endl;
	}*/
	rep(i,n)
	{
		if(i==0)
		{
			dpw[i]=bw[i];
			dpb[i]=bb[i];
		}
		else
		{
			int w=i;
			int now=w;
			int noww;
			if(bw[i]==0)noww=now;
			else noww=bw[i]+(w-white[bw[i]-1][w-1]);
			dpw[i]=dpw[i-1]+(noww-now);
			int b=i;
			int nowb;
			if(bb[i]==0)nowb=now;
			else nowb=bb[i]+(b-black[bb[i]-1][b-1]);
			dpb[i]=dpb[i-1]+(nowb-now);
		}
	}
	rep(b,n)
	{
		rep(w,n)
		{
			//0:black 1:white
			//black
			if(b==0)
			{
				if(w==0)
				{
					if(bw[w]<bb[b]) dp[b][w][0]=bb[b]+bw[w]-1;
					else dp[b][w][0]=bb[b]+bw[w];
				}
				else
				{
				int now=w+1;
				int nowb=bb[b]+(w+1-white[bb[b]-1][w]);
				dp[b][w][0]=dpw[w]+(nowb-now);
				}
			}
			else
				{int now=b+w+1;
				int nowb=bb[b]+(b+w+1-black[bb[b]-1][b-1]-white[bb[b]-1][w]);
				int k=dp[b-1][w][0];
				if(k>dp[b-1][w][1])k=dp[b-1][w][1];
				dp[b][w][0]=k+(nowb-now);
				}
			//white
			if(w==0)
			{
				if(b==0)
				{
					if(bb[b]<bw[w])dp[b][w][1]=bb[b]+bw[w]-1;
					else dp[b][w][1]=bb[b]+bw[w];
				}
				else
				{
					int now=b+1;
					int noww=bw[w]+(b+1-black[bw[w]-1][b]);
					dp[b][w][1]=dpb[b]+(noww-now);
				}
			}
			else
			{int now=b+w+1;
			int noww=bw[w]+(b+w+1-black[bw[w]-1][b]-white[bw[w]-1][w-1]);
			int kk=dp[b][w-1][0];
			if(kk>dp[b][w-1][1])kk=dp[b][w-1][1];
			dp[b][w][1]=kk+(noww-now);
			}
		}
	}
	/*rep(i,n)
	{
		cout<<dp[i][0][1]<<' ';
		cout<<dpb[i]<<endl;
	}*/
	int ans=dp[n-1][n-1][1];
	if(ans>dp[n-1][n-1][0])ans=dp[n-1][n-1][0];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 94080
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n,a[200010],x;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=2;i<=n;i++){
		cin>>x;
		x--;
		a[x]++;
	}
	for(int i=0;i<n;i++)cout<<a[i]<<'\n';
	return 0;
}


Measured memory_bytes: 5172
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

int main() {
	string s;
	cin >> s;

	// yyyy/mm/dd -> s[5],s[6]がmmのはずだ 

	string mm = s.substr(5, 2);
	int mm_int = stoi(mm);

	string ans;
	if (mm_int > 4) {
		ans = "TBD";
	} else {
		ans = "Heisei";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
a,b,ab,x,y=map(int,input().split())
m=min(x,y)
if a+b >= 2*ab:
  if x <= y:
    if ab*2 > b:
      print(ab*2*m + (y-x)*b)
    else:
      print(y*ab*2)
  else:
    if ab*2 > a:
      print(ab*2*m + (x-y)*a)
    else:
      print(ab*2*x)
else:
  print(a*x + b*y)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n;
  double ans = 0.0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double a;
    string s;
    cin >> a >> s;
    if (s == "JPY") {
      ans += a;
    } else {
      ans += a * 380000.0;
    }
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    string s;
    cin>>s;
    
    int cnt0=0;
    for(int i=0;i<s.length();i++){
        if('0'==s[i]){
            cnt0++;
        }
    }
    int cnt1=s.length()-cnt0;
    cout<<2*min(cnt0,cnt1)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;
const int N = 210000, mod = 1e9 + 7;

int n, c[N], ans;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n);
    for (R int i = 1; i <= n; ++i) read(c[i]);
    sort(c + 1, c + 1 + n);
    for (R int i = 1; i <= n; ++i)
        ans = (ans + (ll) c[i] * (n - i + 2)) % mod;
    for (R int i = 1; i <= 2 * n - 2; ++i)
        ans = (ans << 1) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
extern crate core;

use std::io::{self, Read};
use std::collections::HashMap;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn l(i: i32, map: &mut HashMap<i32, i64>) -> i64 {
    match map.get(&i) {
        Option::Some(&x) => x,
        Option::None => {
            let x = l(i - 1, map) + l(i - 2, map);
            map.insert(i, x);
            x
        }
    }
}

fn lucas(i: i32) -> i64 {
    let mut map = HashMap::new();
    map.insert(0, 2);
    map.insert(1, 1);
    l(i, &mut map)
}

fn run(input: String) -> String {
    let i = input.trim().parse::<i32>().unwrap();

    lucas(i).to_string()
}

#[test]
fn test() {
    let tests = vec![("5", "11"), ("86", "939587134549734843")];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll rr = 998244353;

int main(){
    int n;
    cin >> n;
    if(n%2 != 0 ){
        cout << "No"; return 0;
    }
    string s;
    cin >> s;
    string half1 = s.substr(0, s.length()/2);
    string half2 = s.substr(s.length()/2, s.length()/2);
    if(half1 == half2) cout << "Yes";
    else cout << "No";
 }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  string s;
  cin>>s;
  if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<3;
  else if((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R')) cout<<2;
  else if(s[0]=='R' || s[1]=='R' || s[2]=='R') cout<<1;
  else cout<<0;
  nline;
  return 0;
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(a*c>0){
    c-=b;
    if(c<=0){
      cout << "Yes";
      return 0;
    }
    a-=d;
    if(a<=0){
      cout << "No";
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3104
#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;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << std::min(A * N, B) << endl;
    return 0;
}

Measured memory_bytes: 256
s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
  if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i]
if tmp>0:
  ss.append(tmp)
if len(ss)==1:
  print(n*k//2)
else:
  if s[0]==s[-1]:
    ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
  for i in ss:
    ans+=i//2*k
  print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    int S; cin>>S;
    int h=0,m=0,s=0;
    if(S>=3600){
        h = S/3600;
        S -= 3600*h;
    }
    if(S >= 60){
        m = S/60;
        S -= 60*m;
    }
    s = S;

    cout<<h<<":"<<m<<":"<<s<<endl;

    return 0;
}


Measured memory_bytes: 3104
N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(N):
    t[i+1], x[i+1], y[i+1] = map(int, input().split())

f = True
for i in range(N):
    dt = t[i+1] - t[i]
    dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    if dt < dist:
        f = False
    if dist%2 != dt%2:
        f = False

print('Yes' if f else 'No')

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

int main()
{
	int a[3];
	scanf("%d%d%d", a, a + 1, a + 2);
	std::sort(a, a + 3);
	if (a[0] == a[2]) printf("1\n");
	else if (a[0] == a[1] || a[1] == a[2])
		printf("2\n");
	else
		printf("3\n");

	return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())

graph = [0] + [0] * h
for i in range(h):
    graph[i + 1] = '0' + input().strip()

from collections import deque

def bfs(graph, queue, dist):
    while queue:
        current_h, current_w = queue.popleft()

        for dh, dw in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            next_h, next_w = current_h + dh, current_w + dw
            if not ((1 <= next_h <= h) and (1 <= next_w <= w)):
                continue
            if graph[next_h][next_w] == '#':
                continue
            if dist[next_h][next_w] != -1 and dist[next_h][next_w] <= dist[current_h][current_w]:
                continue
            else:
                dist[next_h][next_w] = dist[current_h][current_w]
                queue.appendleft((next_h, next_w))

        for dh in range(-2, 3):
            for dw in range(-2, 3):
                next_h, next_w = current_h + dh, current_w + dw
                if not ((1 <= next_h <= h) and (1 <= next_w <= w)):
                    continue
                if graph[next_h][next_w] == '#':
                    continue
                if dist[next_h][next_w] != -1:
                    continue
                else:
                    dist[next_h][next_w] = dist[current_h][current_w] + 1
                    queue.append((next_h, next_w))

queue = deque([(ch, cw)])
dist = [-1] + [0] * h
for i in range(h):
    dist[i + 1] = [0] + [-1] * w
dist[ch][cw] = 0
bfs(graph, queue, dist)
print(dist[dh][dw])

Measured memory_bytes: 98864
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int n = Integer.parseInt(br.readLine());
    char[] s = br.readLine().toCharArray();
    
    for (int i=0; i<s.length; i++) {
      s[i] = (char) ((s[i]-'A'+n)%26+'A');
    }
    System.out.println(new String(s));
  }
}


Measured memory_bytes: 21204
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const LL mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int r,c,n;
	cin>>r>>c>>n;
	vector<LL> x(n),y(n),x2(n),y2(n);
	auto on = [r,c](LL a, LL b) { return a==0||a==r||b==0||b==c; };
	priority_queue<pll> pq;
	FOR(i,0,n){
		cin>>x[i]>>y[i]>>x2[i]>>y2[i];
		if(on(x[i],y[i])&&on(x2[i],y2[i])){
			if(x[i]==0){
				pq.push(MP(y[i],i));
			}else if(y[i]==c){
				pq.push(MP(mod+x[i],i));
			}else if(x[i]==r){
				pq.push(MP(2*mod-y[i],i));
			}else{
				pq.push(MP(3*mod-x[i],i));
			}
			if(x2[i]==0){
				pq.push(MP(y2[i],i));
			}else if(y2[i]==c){
				pq.push(MP(mod+x2[i],i));
			}else if(x2[i]==r){
				pq.push(MP(2*mod-y2[i],i));
			}else{
				pq.push(MP(3*mod-x2[i],i));
			}
		}
	}
	stack<LL> st;
	while(pq.size()){
		LL t=pq.top().ND;
		pq.pop();
		if(st.size()&&st.top()==t){
			st.pop();
		}else{
			st.push(t);
		}
	}
	if(st.size()){
		cout<<"NO";
	}else{
		cout<<"YES";
	}

	return 0;
}


Measured memory_bytes: 9712
N, K = list(map(int, input().split()))

ans = 0

for i in range(1,N + 1) :
    kakuritu  = 1 / N
    while i < K :
        i = i * 2
        kakuritu = kakuritu * 0.5
    else :
        ans += kakuritu 

print(ans)

Measured memory_bytes: 2940
import java.util.Scanner;



public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] array = new int[6];
		for (int i = 0; i < array.length; i++) {
			array[i] = scan.nextInt();
		}
		String order = scan.next();
		scan.close();
		Dice dice = new Dice(array);
		dice.roll(order);
		System.out.println(dice.getNumber(0));
	}
}
	

class Dice {
	int[] num = new int[6];
	Dice() {
	}

	Dice(int[] array) {
		for (int i = 0; i < array.length; i++) {
			this.num[i] = array[i];
		}
	}
	
	public void setNum(int[] array) {
		this.num = array;
	}
	
	public int[] getNum() {
		return this.num;
	}
	
	public int getNumber(int i) {
		return this.num[i];
	}
	
	public void roll(String order) {
		int now_1 = 0;	int now_2 = 1;	int now_3 = 2;	int tmp;
		int[] array = getNum();
		char[] check = {'N', 'E', 'S', 'W'};
		for (int i = 0; i < order.length(); i++) {
			for (int j = 0; j < check.length; j++) {
				if (order.charAt(i) == check[j]) {
					switch (j + 1) {
						case 1:
							tmp = now_1;
							now_1 = now_2;
							now_2 = 5 - tmp;
							break;
						case 2:
							tmp = now_1;
							now_1 = 5 - now_3;
							now_3 = tmp;
							break;
						case 3:
							tmp = now_1;
							now_1 = 5 - now_2;
							now_2 = tmp;
							break;
						case 4:
							tmp = now_1;
							now_1 = now_3;
							now_3 = 5 - tmp;
							break;
					}
				}
			}
		}
		int[] cp_array = new int[array.length];
		cp_array[0] = array[now_1]; cp_array[1] = array[now_2];
		cp_array[2] = array[now_3]; cp_array[3] = array[5 - now_3];
		cp_array[4] = array[5 - now_1]; cp_array[5] = array[5 -now_2];
		setNum(cp_array);
	}
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

template <class T> inline T square(T x) {
  T result;
  result = x * x;
  return result;
};

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;

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

  auto start = chrono::steady_clock::now();
#endif

  ll a, b, n;
  cin >> a >> b >> n;

  auto x = min(b - 1, n);

  ll ans = (a * x) / b - a * (x / b);
  print(ans);

#ifdef LOCAL
  auto end = chrono::steady_clock::now();
  auto diff = end - start;

  cout << "Duration: " << chrono::duration<double, milli>(diff).count() << " ms"
       << '\n';
#endif

  return 0;
}


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

int main(){
	int n,d,x;
	cin >> n;
	cin >> d >> x;
	int a[100];
	int ans=0;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++){
		ans+=(d-1)/a[i]+1;
	}
	cout << ans+x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
int main () {

    int A;
    int B;

    std::cin >> A >> B;

    if( B%A == 0) {
        std::cout << A + B << std::endl;
    } else {
        std::cout << B - A << std::endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll h,w,ans=0;
    cin >> h >> w;
    string s[h];
    for (ll i=0;i<h;i++)cin >> s[i];
    ll dist[h][w];
    for (ll i=0;i<h;i++){
        fill(dist[i],dist[i]+w,-1);
    }
    queue<pair<ll,ll>> que;
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (s[i][j]=='#'){
                que.push(make_pair(i,j));
                dist[i][j]=0;
            }
        }
    }
    while(!que.empty()){
        ll y=que.front().first,x=que.front().second;
        que.pop();
        for (ll i=0;i<4;i++){
            if (x+dx[i]>=0 and x+dx[i]<w and y+dy[i]>=0 and y+dy[i]<h and s[y+dy[i]][x+dx[i]]=='.' and dist[y+dy[i]][x+dx[i]]==-1){
                dist[y+dy[i]][x+dx[i]]=dist[y][x]+1;
                que.push(make_pair(y+dy[i],x+dx[i]));
            }
        }
    }
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            ans=max(ans,dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25524
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "\n";
 
    
    }
    return 0;

}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const ll inf = (ll)1e16;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
ll dp[3][40],n,t,ans;
bool compare(pii a, pii b)
{
	return a.fi*(b.se+1) > b.fi*(a.se+1);
}
int main()	
{
	//freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>t;
	vector<pii> arr;
	vector<ll> zero;
	for(int i=0;i<n;i++)
	{
		pii temp;
		cin>>temp.fi>>temp.se;
		if(temp.fi == 0)
			zero.eb(temp.se);
		else
			arr.eb(temp);
	}
	sort(arr.begin(),arr.end(),compare);
	for(int i=0;i<2;i++)
		for(int j=0;j<33;j++)
			dp[i][j] = inf;
	dp[0][0] = 0;
	for(int i=0;i<arr.size();i++)
	{
		for(int j=0;j<33;j++)
			dp[(i+1)&1][j] = inf;
		auto s = arr[i];
		for(int j=0;j<33;j++)
		{
			if(dp[i&1][j]==inf)
				continue;
			dp[(i+1)&1][j] = min(dp[(i+1)&1][j],dp[i&1][j]);
			ll check = (dp[i&1][j]+1)*(s.fi+1)+s.se;
			if(check<=t and j+1<33)
				dp[(i+1)&1][j+1] = min(dp[(i+1)&1][j+1],check);	
		}	
	}
	sort(zero.begin(),zero.end());
	vector<ll> pref(zero.size()+1);
	pref[0] = 0;
	for(int i=0;i<zero.size();i++)
		pref[i+1] = pref[i]+zero[i]+1;
	for(int j=0;j<33;j++)
	{
		ll res = t-dp[arr.size()&1][j];
		if(res<0)
			continue;
		ans = max(ans,(ll)(upper_bound(pref.begin(),pref.end(),res)-pref.begin()+j-1));
	}
	cout<<ans;
}


Measured memory_bytes: 3568
#include <stdio.h>

int main(void){

  char s[11];
  scanf("%s", s);
	int check[11];
	for (int i = 0; i < 11; i++) {
		check[i] = 1;
	}
	for (int i = 0; i < 11; i++) {
		if (s[i] != '0' && s[i] != '1' && s[i] != 'B') {
			break;
		}
		if (s[i] == 'B') {
			for (int j = i-1; j >= 0; j--) {
				if (s[j] != 'B' && check[j] == 1) {
					check[j] = 0;
					break;
				}
			}
		}
	}
	for (int i = 0; i < 11; i++) {
		if (s[i] != '0' && s[i] != '1' && s[i] != 'B') {
			break;
		}
		if (s[i] != 'B' && check[i] == 1) {
			printf("%c", s[i]);
		}
	}
	printf("\n");

  return 0;
}

Measured memory_bytes: 128
N, P = list(map(int, input().split()))
if N == 1:
    print(P)
    exit()
elif P == 1:
    print("1")
    exit()

ans = 1
tmp = P

for i in range(2, int(pow(P, 1 / N)) + 1):
    po = pow(i, N)
    while tmp % po == 0:
        tmp = tmp // po
        ans = ans * i
        # print(i, tmp, ans)

    if tmp < po:
        break

print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define REP(i, n) FOR(i, 0, n)
#define max(a, b) ((a)>(b)?(a):(b))
#define min(a, b) ((a)>(b)?(b):(a))
#define abs(a) max((a), -(a))

int n;
int w[304];

int dp[303][303];

int main() {

    while(cin>>n,n) {
        REP(i, n)cin>>w[i];

        REP(i, n) {
            dp[i][i] = 1;
            if(i<n-1) {
                dp[i][i+1] = abs(w[i]-w[i+1])<=1?0:2;
            }
        }

        FOR(i, 2, n) { // 幅
            FOR(j, 0, n-i) {
                dp[j][j+i] = i+1;

                if(dp[j+1][j+i-1]==0 && abs(w[j]-w[j+i])<=1) {
                    dp[j][j+i] = 0;
                    continue;
                }

                REP(k, i) {
                    int a = dp[j][j+k]+dp[j+k+1][j+i];
                    dp[j][j+i] = min(a, dp[j][j+i]);
                    if(a==0)break;
                }

            }
        }

        cout<<(n-dp[0][n-1])<<endl;
    }

    return 0;
}


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

int a[5], k;

int main()
{
    for (int i = 0; i < 5; i++)
        cin >> a[i];
    cin >> k;
    cout << (a[4] - a[0] > k ? ":(" : "Yay!") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int A = sc.nextInt();
    int count = 0;
    
    while (H > 0) {
      count = count + 1 ;
      H -= A;
    }
    System.out.print(count);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e3 + 5;
const ll LINF = 1e18 + 5;
const int mod = 1e9 + 7;
int s[N], t[N];
int n, m;
ll dp[N][N], sum[N][N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m;
 	for(int i=1; i<=n; i++) cin >> s[i];
 	for(int i=1; i<=m; i++) cin >> t[i];
 	dp[0][0] = 1;
 	for(int i=0; i<=n; i++) sum[i][0] = 1;
	for(int i=0; i<=m; i++) sum[0][i] = 1; 
 	for(int i=1; i<=n; i++)
 	{
 		for(int j=1; j<=m; j++)
 		{
 			if(s[i]==t[j]) (dp[i][j] += sum[i-1][j-1])%=mod;
 			(sum[i][j] += (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j])%mod)%=mod;
 		}
 	}
 	ll ans = sum[n][m];
 	ans = (ans + mod)%mod;
 	cout << ans;
	return 0;
}

Measured memory_bytes: 62848
#include<algorithm>
#include<iostream>
using namespace std;
int n,m,f[100001],ans;
struct at{int x,y,id;}a[100001];
struct edge{int u,v,l;bool operator<(edge b){return l<b.l;}}e[200001];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
bool cmp1(at a,at b){return a.x<b.x;}
bool cmp2(at a,at b){return a.y<b.y;};
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i].x>>a[i].y,a[i].id=i,f[i]=i;
	sort(a+1,a+n+1,cmp1);
	for(int i=2;i<=n;i++)
		e[++m].u=a[i-1].id,e[m].v=a[i].id,e[m].l=a[i].x-a[i-1].x;
	sort(a+1,a+n+1,cmp2);
	for(int i=2;i<=n;i++)
		e[++m].u=a[i-1].id,e[m].v=a[i].id,e[m].l=a[i].y-a[i-1].y;
	sort(e+1,e+m+1);
	for(int i=1;i<=m;i++)
	{
		int x=find(e[i].u),y=find(e[i].v);
		if(x!=y)
			f[x]=y,ans+=e[i].l;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    int cnt = 0;
    for(auto q : mp) cnt += q.second - 1;
    cout << mp.size() - cnt % 2 << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    size_t n;
    cin >> n;
    vector<size_t> p_vec(n + 1);
    size_t num = 0;
    for(size_t i = 1; i <= n; ++i){
        cin >> p_vec[i];
        if(i != p_vec[i]){
            num++;
        }
    }

    if(num <= 2){
        puts("YES");
    }else{
        puts("NO");
    }    
    return 0;
}

Measured memory_bytes: 888
miti = [0, 0, 0, 0]
d = [[] for _ in range(4)]

for i in range(3):
    a, b = map(int, input().split())
    d[a - 1].append(b - 1)
    d[b - 1].append(a - 1)

miti[0] = 1
index = 0
for i in range(3):
    for j in range(len(d[index])):
        if j < len(d[index]) and miti[d[index][j]] != 1:
            miti[d[index][j]] = 1
            index = d[index][j]

if sum(miti) == 4:
    print('YES')
else:
    print('NO')

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Sqrt Inequality
            
            if(IsMatch())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        
        static bool IsMatch()
        {
            var line = ReadLine();
            var a = line[0];
            var b = line[1];
            var c = line[2];

            if(c - a - b >= 0)
            {
                if(4 * a * b < (c - a - b) * (c - a - b))
                {    
                    return true;
                }
            }
            
            return false;
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => long.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 11348
import sys
sys.setrecursionlimit(100000000)

def trace(i, j, S, col, num_color):
    next_col = 1 - col
    num_color[col] += 1
    S[i][j] = 2
    if S[i-1][j] == next_col:
        trace(i-1, j, S, next_col, num_color)
    if S[i][j-1] == next_col:
        trace(i, j-1, S, next_col, num_color)
    if S[i+1][j] == next_col:
        trace(i+1, j, S, next_col, num_color)
    if S[i][j+1] == next_col:
        trace(i, j+1, S, next_col, num_color)
    return num_color[0] * num_color[1]

def main():
    H, W = map(int, input().split())
    # 黒0，白1，padding2
    S = [[2] * (W+2)]
    for _ in range(H):
        S.append([2] + [0 if s == '#' else 1 for s in input()] + [2])
    S.append([2] * (W+2))
    num_comb = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            if S[i][j] == 0:
                num_color = [0, 0]
                num_comb += trace(i, j, S, 0, num_color)
    print(num_comb)

main()

Measured memory_bytes: 138612
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/



int main()
{
     int k,t;
     cin>>k>>t;
     int a[t];
     for(int i=0;i<t;i++)cin>>a[i];
     int mx=0;
     for(int i=0;i<t;i++)
     {
          int t=k-a[i];
          if(a[i]>t)
          {
               mx=max(mx,abs(a[i]-t-1));
          }
     }
     cout<<mx;
}















 














 
 

















Measured memory_bytes: 256
import java.util.Scanner;
import java.awt.Point;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h= sc.nextInt();
		int w = sc.nextInt();
		int d=sc.nextInt();
		Point[] ar=new Point[h*w+1];
		int[] ans=new int[h*w];
		for(int i = 1; i<=h; i++){
			for(int j = 1; j<=w; j++){
				ar[sc.nextInt()]=new Point(i,j);
			}
		}
		for(int i = 1; i<h*w+1; i++){
			if(i<=d){
				ans[i-1]=0;
			}else{
				ans[i-1]+=ans[i-1-d]+Math.abs(ar[i].x-ar[i-d].x)+Math.abs(ar[i].y-ar[i-d].y);
			}
		}
		int q=sc.nextInt();
		int[] ans1=new int[q];
		for(int i = 0; i<q; i++){
			int l=sc.nextInt();
			int r=sc.nextInt();
			ans1[i]=ans[r-1]-ans[l-1];
		}
		for(int i = 0; i<q; i++){
			System.out.println(ans1[i]);
		}
	}
}

Measured memory_bytes: 98580
#include<iostream>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){
    int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0;
    char st;
    while(scanf("%c", &st) != EOF){
        st = tolower(st);
        if(st=='a') a++;
        else if(st=='b') b++;
        else if(st=='c') c++;
        else if(st=='d') d++;
        else if(st=='e') e++;
        else if(st=='f') f++;
        else if(st=='g') g++;
        else if(st=='h') h++;
        else if(st=='i') i++;
        else if(st=='j') j++;
        else if(st=='k') k++;
        else if(st=='l') l++;
        else if(st=='m') m++;
        else if(st=='n') n++;
        else if(st=='o') o++;
        else if(st=='p') p++;
        else if(st=='q') q++;
        else if(st=='r') r++;
        else if(st=='s') s++;
        else if(st=='t') t++;
        else if(st=='u') u++;
        else if(st=='v') v++;
        else if(st=='w') w++;
        else if(st=='x') x++;
        else if(st=='y') y++;
        else if(st=='z') z++;
    }
    
    cout << "a : " << a << endl;
    cout << "b : " << b << endl;
    cout << "c : " << c << endl;
    cout << "d : " << d << endl;
    cout << "e : " << e << endl;
    cout << "f : " << f << endl;
    cout << "g : " << g << endl;
    cout << "h : " << h << endl;
    cout << "i : " << i << endl;
    cout << "j : " << j << endl;
    cout << "k : " << k << endl;
    cout << "l : " << l << endl;
    cout << "m : " << m << endl;
    cout << "n : " << n << endl;
    cout << "o : " << o << endl;
    cout << "p : " << p << endl;
    cout << "q : " << q << endl;
    cout << "r : " << r << endl;
    cout << "s : " << s << endl;
    cout << "t : " << t << endl;
    cout << "u : " << u << endl;
    cout << "v : " << v << endl;
    cout << "w : " << w << endl;
    cout << "x : " << x << endl;
    cout << "y : " << y << endl;
    cout << "z : " << z << endl;

    return 0;
}



Measured memory_bytes: 3144
n = gets.to_i
as = []
for i in 0..n-1
  as[i]=gets.to_i
end

max=as.max
asc = as.clone
asc.delete_if{|i|i==max}
max_2=asc.max
s = asc.size

for i in 0..n-1
  puts max if s!=n-1
  puts max if as[i]!=max && s==n-1
  puts max_2 if as[i]==max && s==n-1
end


Measured memory_bytes: 7240
#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n,x = (int(i) for i in input().split())  


# リストに入れる
l = [int(i) for i in input().split()] 
a=0
answer = 1
for i in range(n):
    if l[i]+a > x:
        break
    else:
        answer += 1
        a += l[i]

print(answer)


Measured memory_bytes: 21448