akhauriyash/Code-Regression huggingface dataset:
d = {"Male" : 1, "Female" : 2, "Vacant" : 0}

def check(l, r, a, b):
	if (a != b):
		return ((r - l + 1) % 2 == 1)
	else:
		return ((r - l + 1) % 2 == 0)

def get(k):
	print(k - 1)
	return d[input()]

def main():
	n = int(input())
	left = get(1)
	if (left == 0): return
	right = get(n)
	if (right == 0): return

	l, r = 1, n
	while (l + 2 < r):
		m = (l + r) // 2
		med = get(m)
		if (med == 0): return
		if (check(l, m, left, med)):
			right, r = med, m
		else:
			left, l = med, m
	get(l + 1)

main()

Measured memory_bytes: 3660
N = int(input())
data = [int(input()) for i in range(N)]
i = 0
a_i = None
res = 1
pre_i = 0
time = -1
while data[i] != 2:
    a_i = data[i]
    if pre_i == a_i or time == N:
        res = -1
        break

    pre_i = i + 1
    i = data[i] -1
    time += 1
    res += 1
print(res)


Measured memory_bytes: 7084
// She is Pretty pretty!
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int N = 1e6 + 100;
int n, c, h[N], dp[N], r, l, path[N];
int sq(int x) { return x * x; }
double calc(int i, int j) {
    return (dp[i] - dp[j] + sq(h[i]) - sq(h[j])) / 2.0 / (h[i] - h[j]);
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> c;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    path[0] = 0, path[1] = 1;
    l = r = 1;
    for (int i = 2; i <= n; i++) {
        while (l < r && calc(path[l], path[l + 1]) <= h[i]) l++;
        dp[i] = dp[path[l]] + sq(h[i] - h[path[l]]) + c;
        while (l < r && calc(path[r - 1], path[r]) >= calc(path[r], i)) r--;
        path[++r] = i;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;

int main(){
	IOS
	int n;
	cin >> n;
	int huruf=n%10;
	if(huruf==3){
		cout << "bon" << '\n';
	}
	else if(huruf== 0 or huruf== 1 or huruf== 6 or huruf==8){
		cout << "pon" << '\n';
	}
	else{
		cout << "hon" << '\n';
  	}
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  int n,k;
  string s;
  cin>>n>>s>>k;
  k--;
  char c=s[k];
  fr(i,n){
    if(s[i]==c) cout<<s[i];
    else cout<<"*";
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)    \
    vl v;               \
    rep(i, n)           \
    {                   \
        ll x;           \
        cin >> x;       \
        v.push_back(x); \
    }
const ll INF = 999999999999999;
const ll MOD = 998244353;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main()
{
    cin>>k;
    cin>>x;
    if(500*k>=x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int k;
    scanf("%d", &k);
    int sum = 0;
    queue <ll> que;
    for(ll i = 1; i <= 9; i++) que.push(i);
    while(!que.empty()) {
        ll x = que.front();
        que.pop();
        sum++;
        //printf("x = %lld\n", x);
        if(sum == k) {
            printf("%lld\n", x);
            break;
        }
        for(ll i = -1; i <= 1; i++) {
            if((x % 10) + i >= 0 && (x % 10) + i <= 9) {
                //printf("%lld\n", x * 10 + (x % 10) + i);
                que.push(x * 10 + (x % 10) + i);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;
static const int INF = 999999999;
typedef pair<int, int> P;
struct SEdge
{
	int To;
	int Cost;
};
vector<int> d;
vector<SEdge> G[10];

void Dijkstra(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > PQue;
	PQue.push(P(0, s));
	while(!PQue.empty())
	{
		P p = PQue.top();
		PQue.pop();
		if(d[p.second] < p.first)
		{
			continue;
		}
		int v = p.second;
		for(int i = 0; i < G[v].size(); ++i)
		{
			SEdge e = G[v][i];
			if(d[e.To] > d[v] + e.Cost)
			{
				d[e.To] = d[v] + e.Cost;
				PQue.push(P(d[e.To], e.To));
			}
		}
	}
}

void solve()
{
	int E;
	while(cin >> E, E)
	{
		int V = 0;
		for(int i = 0; i < 10; ++i)
		{
			G[i].clear();
		}
		for(int i = 0; i < E; ++i)
		{
			int From, To, Cost;
			cin >> From >> To >> Cost;
			V = max(V, max(From, To));
			SEdge e1, e2;
			e1.To = To;
			e2.To = From;
			e1.Cost = e2.Cost = Cost;
			G[From].push_back(e1);
			G[To].push_back(e2);
		}
		++V;
		d.clear();
		d.resize(V);
		unsigned long long int Min = INF;
		int pos = 0;
		for(int i = 0; i < V; ++i)
		{
			Dijkstra(i);
			unsigned long long int sum = 0;
			for(int j = 0; j < V; ++j)
			{
				sum += d[j];
			}
			if(Min > sum)
			{
				Min = sum;
				pos = i;
			}
		}
		cout << pos << " " << Min << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
void counts(int h,int w);
int check[31][31]={0};
char s[31][31];
int dh[4]={-1,0,1,0};
int dw[4]={0,1,0,-1};
int ww,hh;
int counta=0;
main(){
  int sw,sh,countx;
  while(1){
    cin>>ww>>hh;
    if(ww==0&&hh==0) break;
    for(int i=1;i<=hh;i++){
      for(int j=1;j<=ww;j++){
	cin>>s[i][j];
	if(s[i][j]=='@'){
	  sh=i;
	  sw=j;
	}
      }
    }
    counts(sh,sw);
    cout<<counta<<endl;
    for(int i=0;i<=30;i++){
      for(int j=0;j<=30;j++){
	check[i][j]=0;
      }
    }
    counta=0;
  }
}
void counts(int h,int w){
  check[h][w]=1;
  counta++;
  for(int i=0;i<8;i++){
    int nh=h+dh[i];
    int nw=w+dw[i];
    if(nh>=1&&nh<=hh&&nw>=1&&nw<=ww&&s[nh][nw]=='.'&&check[nh][nw]==0){
      counts(nh,nw);
    }
  }
  return;
}

Measured memory_bytes: 1176
N, K = map(int, input().split())
A = tuple( map(int, input().split()) )

L = [0 for i in range(N+1)]
L[1] = 1
x = 1
t = 1
while K>0:
  t += 1
  K -= 1
  x = A[x-1]
  if L[x] != 0:
    p = t - L[x]
    K %= p
    break
  else:
    L[x] = t
    
while K>0:
  x = A[x-1]
  K -= 1
print(x)


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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

const int N = 100005;

int n, k;
vector<int> g[N];
int l[N], r[N];
bool ok = 1;
int col[N];
int ans[N];

void dfs(int u, int p) {
    for (int e : g[u]) {
        if (e == p) continue;
        dfs(e, u);
        l[u] = max(l[u], l[e] - 1);
        r[u] = min(r[u], r[e] + 1);
        if (col[e] != -1) {
            if (col[u] == col[e]) ok = 0;
            else col[u] = 1 - col[e];
        }
        if (l[u] > r[u]) ok = 0;
    }
}

void dfs2(int u, int p, int res) {
    ans[u] = res;
    for (int e : g[u]) {
        if (e == p) continue;
        if (res - 1 >= l[e] && res - 1 <= r[e]) dfs2(e, u, res - 1);
        else dfs2(e, u, res + 1); 
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) l[i] = -1e9, r[i] = 1e9, col[i] = -1;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    cin >> k;
    for (int i = 1; i <= k; i++) {
        int u, v;
        cin >> u >> v;
        col[u] = v % 2;
        l[u] = v;
        r[u] = v;
    }
    dfs(1, 0);
    if (!ok) return cout << "No", 0;
    dfs2(1, 0, l[1]);
    cout << "Yes\n";
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;
#define split 1000000007
//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

ll N,M=26;
string S;

int main(void){
  cin >> N;
  cin >> S;
  int i,j,k;
  vector<ll> num(M,0);
  REP(i,N){
    num[S[i]-'a']++;
  }
  sort(num.begin(),num.end(),greater<ll>());
  while(!num[num.size()-1]) num.erase(num.begin()+num.size()-1);

  ll dp[num.size()][num.size()];
  ll sum;
  REP(i,num.size()) REP(j,num.size()) dp[i][j] = 0;
  REP(i,num.size()){
    REP(j,num.size()){
      if(j>i) break;
      if(j==0) dp[i][j] = num[i];
      else{
        sum = 0;
        REP(k,i)sum += dp[k][j-1]; 
        dp[i][j] = num[i]*sum%split;
      }
    }
  }
  sum = 0;
  REP(i,num.size()){
    REP(j,num.size()){
      sum += dp[i][j];
      sum %= split;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 512
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])
if A+B+C+D==7:
    print(S[0]+'+'+S[1]+'+'+S[2]+'+'+S[3]+'=7')
elif A+B+C-D==7:
    print(S[0]+'+'+S[1]+'+'+S[2]+'-'+S[3]+'=7')
elif A+B-C+D==7:
    print(S[0]+'+'+S[1]+'-'+S[2]+'+'+S[3]+'=7')
elif A+B-C-D==7:
    print(S[0]+'+'+S[1]+'-'+S[2]+'-'+S[3]+'=7')
elif A-B+C+D==7:
    print(S[0]+'-'+S[1]+'+'+S[2]+'+'+S[3]+'=7')
elif A-B+C-D==7:
    print(S[0]+'-'+S[1]+'+'+S[2]+'-'+S[3]+'=7')
elif A-B-C+D==7:
    print(S[0]+'-'+S[1]+'-'+S[2]+'+'+S[3]+'=7')
else :
    print(S[0]+'-'+S[1]+'-'+S[2]+'-'+S[3]+'=7')


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long
#define ld long double
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e5 + 10;
const ll inf = 1e15 + 7;

int n;
int a[3*N];
ll ans;

main()
{
    scanf("%d", &n);
    n *= 3;
    for(int i = 1 ; i <= n ; i ++)
        scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    for(int i = n - 1 ; i >= n / 3 + 1 ; i -= 2)
        ans += a[i];
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vector<int> a(n);
	FOR(i, 0, n){
		int z; cin >> z;
		a[z-1] = i+1;
	} 
	printv(a);
	
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define inf 2147483647
#define llinf 9223372036854775807
#define ll long long
using namespace std;
const int maxn = 2e5 + 10;

int n;
int a[maxn];
map<int, int> cnt;
int tot, num[maxn];
int rua[4];

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int main()
{
    //freopen("C:/Users/MACHENIKE/Desktop/data.in","r",stdin);
    n = read();
    for (int i = 1; i <= n ; i++)
    {
        a[i] = read();
        if(cnt[a[i]] == 0)
        {
            cnt[a[i]] = ++tot;
            if (tot > 3) return puts("No"), 0;
            rua[tot] = a[i];
        }
        num[cnt[a[i]]]++;
    }
    if (tot == 1 && rua[1] == 0) return puts("Yes"), 0;
    else if (tot == 1) return puts("No"), 0;
    if (n % 3 != 0) return puts("No"), 0;
    if (tot == 2)
    {
        if ((num[1] == 2 * num[2] && rua[2] == 0) || (num[2] == num[1] * 2 && rua[1] == 0))
            return puts("Yes"), 0;
        else
            return puts("No"), 0;
    }
    if (tot != 3) return puts("No"), 0;
    if (num[1] != num[2] || num[2] != num[3]) return puts("No"), 0;
    if ((rua[1] ^ rua[2]) != rua[3]) return puts("No"), 0;
    puts("Yes");
    return 0;
}


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

int main(){
  ll n,a,b;
  cin >>n >>a >>b;
  if(a>b){
    cout << 0 << endl;
    return 0;
  }
  if(n==1){
    if(a!=b) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }
  cout << (b-a)*(n-2)+1 << endl;
  return 0; 
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b)
{
  if(a%b == 0) return (2*(a/b)-1)*b;
  return 2*(a/b)*b + solve(b, a%b);
}
int main()
{
  long long N, X;
  scanf("%lld%lld", &N, &X);
  printf("%lld\n", solve(N-X, X)+N);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;



int main(){
    int N,K;cin >> N >> K;
    vector<LL> vec;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    vec.push_back(0);
   // vec.push_back(1e18);
    sort(vec.begin(),vec.end());
    for(int a = 0;a < vec.size();a++){
    //    cout<<vec.at(a)<<" ";
    }
    //cout<<endl;
    auto calc = [&](int i){
        if(vec.at(i) >= K)return true;
        //K-iとK-1の間に入れるかを判定
        vector<bool> dp(K,false);
        dp[0] = true;
        for(int a = 0;a < vec.size();a++){
            if(i == a)continue;
            for(int b = dp.size()-1;b >= 0;b--){
                if(dp[b] && b + vec.at(a) < K){
                    dp[b+vec.at(a)]=true;
                }
            }
        }
        for(int a = K-vec.at(i);a < K;a++){
            if(dp[a])return true;
        }
        return false;
    };
    int ok = vec.size();
    int ng = 0;
    while (ok - ng > 1) {
        int mid = (ok+ng)/2;
      //  cout<<ok<<" "<<ng<<" "<<mid<<endl;
        if(calc(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout<<ng<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
  int n,k;
  int a[100005];
  ll ans,sum;
  while(cin>>n>>k){
    if(n==0&&k==0)break;
    ans=0;
    rep(i,n)cin>>a[i];
    rep(i,k)ans+=a[i];
    sum=ans;
    REP(i,k,n){
      sum=sum-a[i-k]+a[i];
      ans=max(sum,ans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3392
#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  int n;cin>>n;
  int a[n];for(int& i:a)cin>>i;
  map<pair<int,pair<int,int>>,bool> used;
  int ans=0;
  sort(a,a+n);
  map<int,int> mp;
  for(int i:a)mp[i]++;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(!used[{a[i],{a[j],a[k]}}]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]){
          ans+=mp[a[i]]*mp[a[j]]*mp[a[k]];
          used[{a[i],{a[j],a[k]}}]=1;
          //cerr<<a[i]<<" "<<a[j]<<" "<<a[k]<<ans<<"---\n";
         }
        }
      }
    }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 16212
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int s;
	cin >> s;

	lint cnt = 0;
	while (s != 4 && s != 2 && s != 1) {
	
		if (s % 2 == 0) s /= 2;
		else s = 3 * s + 1;

		cnt++;
	}

	cout << cnt + 4 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);



signed main(){
    ll n,sum2=0,mn=INF,sum=0;cin>>n;
    bool allsame=true;
    rep(i,0,n){
        ll a,b;cin>>a>>b;
        
        if(a<b)sum2+=b;
        else{
            if(a>b)chmin(mn,b);
            sum+=b;
        }
    }

    if(sum2==0)cout<<0<<endl;
    else cout<<sum2+sum-mn<<endl;
}



Measured memory_bytes: 256
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 C = sc.nextLong();
		long K = sc.nextLong();
		long A[]= new long[N];
		for (int i=0;i<N;i++) {
			A[i]= sc.nextLong();
		}
		int count =1;
		Arrays.sort(A);
		long start =A[0];
		long num =1;
		for (int i=1;i<N;i++) {
			if (start+K>=A[i]&&num<C) {
				num ++;
			} else {
				start=A[i];
				num =1;
				count ++;
			}
		}
		System.out.println(count);
	}
}

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

int main(){
  string s;
  int posA=-1, posZ=-1;
  cin >> s;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='A' && posA==-1) posA=i;
    if(s[i]=='Z') posZ=i;
  }
  cout << posZ-posA+1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

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

typedef long long int int64;

const long long INF = (long long) 1e18;
const int N = (int) 1e5 + 100;
long long x[N];

long long ans[N];
long long upd[N];


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

    int n, e, t;
    scanf("%d%d%d", &n, &e, &t);
    for (int i = 0; i < n; i++)
        scanf("%lld", &x[i]);
    x[n] = e;

    for (int i = 0; i <= n; i++)
        upd[i] = INF;

    for (int i = 0; i <= n; i++)
    {
        upd[i + 1] = min(upd[i + 1], upd[i]);
        long long cur = 0;
        if (i > 0)
        {
            cur = upd[i - 1] + 2LL * x[i - 1];
            
            long long z = x[i - 1] - t / 2;
            int pos = lower_bound(x, x + n + 1, z) - x;
            long long ccur = t;
            ccur += ans[pos];

            eprintf("i = %d, ccur = %lld\n", i, ccur);
            cur = min(cur, ccur);
        }
        ans[i] = cur;
        int pos = lower_bound(x, x + n + 1, x[i] + (t + 1) / 2) - x;
        upd[pos] = min(upd[pos], ans[i] - 2 * x[i]);

        eprintf("upd from %d with %lld\n", pos, upd[pos]);

        eprintf("%d) %lld\n", i, ans[i]);
    }

    printf("%lld\n", ans[n] + e);

	return 0;
}




Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>

int main()
{
    int i,k,j,len,len1;
    char a[105],b[105],c[210];
    scanf("%d",&len);
    getchar();
    for(i=0;i<len;i++)
    {
        scanf("%c",&a[i]);
    }

    getchar();
    for(i=0;i<len;i++)
    {
        scanf("%c",&b[i]);
    }
    j=0;
    for(i=0;i<len*2;i=i+2)
    {
        c[i]=a[j];
        c[i+1]=b[j];
        j++;
    }
    c[2*len]='\0';
    printf("%s\n",c);
    return 0;
}


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

int main() {
  string S;
  ll k;
  cin>>S>>k;
  int n=S.size();

  ll ans=0;
  int tmp=1;

  if (S[0]==S[n-1]) {
    int l=0,r=0;
    for (int i=0; i<n; i++) {
      if (S[0]==S[i]) l++;
      else break;
    }
    for (int i=n-1; i>=0; i--) {
      if (S[n-1]==S[i]) r++;
      else break;
    }
    if (l==n) ans=n*k/2;
    else {
      for (int i=l; i<n-r-1; i++) {
        if (S[i]==S[i+1]) tmp++;
        else {
          ans+=tmp/2;
          tmp=1;
        }
      }
      ans+=tmp/2;
      ans*=k;
      ans+=(l+r)/2*(k-1);
      ans+=l/2;
      ans+=r/2;
    }
  } 
  else {
    for (int i=0; i<n-1; i++) {
      if (S[i]==S[i+1]) tmp++;
      else {
        ans+=tmp/2;
        tmp=1;
      }
    }
    ans+=tmp/2;
    ans*=k;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
loop do
    n, m, p = gets.split.map(&:to_i)
    break if n == 0 && m == 0 && p == 0
    x = n.times.map{gets.to_i}
    t = x.inject(:+) * (100 - p)
    puts x[m-1] != 0 ? t / x[m-1] : 0
end

Measured memory_bytes: 6112
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	const int SZ = N;
	int ok = 0;
	vector <int> H(SZ);
	for (int i = 0;i < SZ;i++)  cin >> H.at(i) ;
	for (int i = 0;i < N;i++)   if ( K <= H.at(i)) ok++;
	cout << ok;	
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int x; cin >> x;
    cout << (x < 1200 ? "ABC" : "ARC");
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include <sstream>
#include <math.h>

using namespace std;

int main(){
    double r;
    cin >> r ;
    double nagasa;
    double area;
    nagasa = M_PI * r  * 2 ;
    area = M_PI * r * r;
    printf("%f %f\n", area, nagasa);
    return 0;

}


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

int main() {
	// your code goes here
	long long int a,b,c,d;
	cin >> a >> b >> c >> d;
	vector<long long int> ans;
	ans.push_back(a*c);
	ans.push_back(a*d);
	ans.push_back(b*c);
	ans.push_back(b*d);
	sort(ans.begin(),ans.end());
	cout << ans[ans.size()-1] << endl;
	
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
static const int N = 10;
int main(){
  int H,i,j,k,l,com,cnt,start,score,flag;//com=compare
  char c;
  string str[N],cp[N];
  while(1){
    score=0;
    cin >> H;
    if(H==0) break;
    for(i=0;i<H;i++){
      str[i]="";
      for(j=0;j<5;j++){
    cin >> c;
    str[i]+=c;
      }
    }
    while(1){
      for(i=0;i<H;i++){
    cnt=0;
    com=str[i][0];
    start=0;
    for(j=0;j<5;j++){
      if(com==str[i][j]) cnt++;
      else{
        if(cnt>=3){
          if(com!='e'){
        score+=cnt*(com-'0');
          }
          for(k=start;k<=j-1;k++){
        str[i][k]='e';//e=end
          }
          com=str[i][j];
          start=j;
          cnt=1;
        }else{
          com=str[i][j];
          start=j;
          cnt=1;
        }
      }
    }
    if(cnt>=3){
      if(com!='e'){
        score+=cnt*(com-'0');
      }
      for(k=start;k<=j;k++){
        str[i][k]='e';//e=end
      }
    }
      }
      for(i=0;i<5;i++){
    for(j=H-1;j>=0;j--){
      if(j-1>=0&&str[j][i]=='e'){
        l=j;
        while(1){
          l--;
          if(l==-1) break;
          if(str[l][i]!='e'){
        str[j][i]=str[l][i];
        str[l][i]='e';
        break;
          }
        }
      }
    }
      }
      flag=0;
      for(i=0;i<H;i++) if(cp[i]!=str[i]) flag=1;
      if(flag==0) break;
      for(i=0;i<H;i++) cp[i]=str[i];
    }
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

class UnionFind {
public:
    ll S;
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
        S = n;
    }
 
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
 
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
 
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	ll allsize() {return S;}
};

vector<int> tree[100005];
int ans[100005];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k; cin >> n >> m >> k;
    UnionFind fri(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        fri.merge(a,b);
        tree[a].push_back(b);
        tree[b].push_back(a);
    }


    rep(i,k) {
        int c, d; cin >> c >> d;
        c--; d--;
        if(fri.issame(c,d)) {
            ans[c]++;
            ans[d]++;
        }
    }

    rep(i,n) {
        cout << fri.size(i) - 1 - tree[i].size() - ans[i] << endl;
    }






    return 0;
}

Measured memory_bytes: 8684
s = gets.chomp!
if (s.include?('N') && s.include?('S') && !s.include?('W') && !s.include?('E')) ||
   (!s.include?('N') && !s.include?('S') && s.include?('W') && s.include?('E')) ||
   (s.include?('N') && s.include?('S') && s.include?('W') && s.include?('E'))
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include <stdio.h>
int main(void){
	int a[31],b[29],i,j;
	for(i=1;i<=30;i++)a[i]=i;
	for(i=1;i<=28;i++)scanf("%d",&b[i]);
	for(i=1;i<=30;i++)
	for(j=1;j<=28;j++)if(a[i]==b[j])a[i]=0;
	for(i=1;i<=30;i++)
	if(a[i]!=0)printf("%d\n",a[i]);
	return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define u(x, a, b) for(ll x = a; x < b; x++)
#define d(x, a, b) for(ll x = a; x > b; x--)

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 1000000007

int main(){
	string s;
	
	ll q;
	
	cin >> s >> q;
	
	deque<char> c;
	u(one, 0, s.size()){c.push_back(s[one]);}
	
	ll cdir = 1;
	u(one, 0, q){
		ll cs;
		cin >> cs;
		
		if(cs == 1){cdir*=(-1);}
		else{
			ll f;
			char ci;
			cin >> f >> ci;
			
			if(f==1 && cdir==1){
				c.push_front(ci);
			}
			else if(f==1 && cdir==-1){
				c.push_back(ci);
			}
			else if(f==2 && cdir==1){
				c.push_back(ci);
			}
			else if(f==2 && cdir==-1){
				c.push_front(ci);
			}
			
			
			
		}
	}
	
	if(cdir==1){
		u(one, 0, c.size()){cout << c[one];}
	}
	else{
		d(one, c.size()-1, -1){cout << c[one];}
	}
}


Measured memory_bytes: 3984
import sys


def solve():
    N, *H = map(int, sys.stdin.read().split())
    dp = [0] * N
    dp[1] = abs(H[1] - H[0])
    h_2 = H[0]
    h_1 = H[1]
    for i, h in enumerate(H[2:], start=2):
        dp[i] = min(dp[i - 1] + abs(h - h_1), dp[i - 2] + abs(h - h_2))
        h_2 = h_1
        h_1 = h
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)


Measured memory_bytes: 13876
#include <iostream>
using namespace std;
int main(){
    int h, w;
    while (1)
    {
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


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

int main() {
  ll n, a;
  cin >> n;
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a;
    if (mp[a]) {
      mp[a]--;
    } else {
      mp[a]++;
    }
  }
  ll cnt = 0;
  for (auto x : mp)
    if (x.second == 1) cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cassert>
#include <vector>

int main() {
  size_t N;
  scanf("%zu", &N);

  size_t M = 55555;
  std::vector<bool> prime(M+1, true);
  prime[0] = prime[1] = false;
  for (size_t i = 2; i*i <= M; ++i) {
    if (!prime[i]) continue;
    for (size_t j = i*i; j <= M; j += i) 
      prime[j] = false;
  }

  std::vector<int> res;
  for (size_t i = 1; i <= M; i += 5)
    if (prime[i])
      res.push_back(i);

  for (size_t i = 0; i < N; ++i)
    printf("%d\n", res[i]);
}


Measured memory_bytes: 504
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	if (k == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	rep(i, n) {
		rep(j, m) {
			if (i*j + (n - i)*(m - j) == k) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int k;
    cin >> k;
    int cnt = 0;
    rep(i,k-1) rep2(j,i+1,k) if((i+j)%2==1) cnt++;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n;
	int a[100];
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i)
		scanf(" %d", &a[i]);

	for(int i=n-1; i>=0; --i) {
		printf("%d", a[i]);
		if(i!=0) printf(" ");
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;

char a[2000][2000];
int h, w, dp[2000][2000];

void pri() {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) cout << dp[i][j] << " ";
		cout << "\n";
	}
}

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j], dp[i][j] = 0;
	
	dp[0][0] = (a[0][0] == '.'? 1:0);
	for (int i = 1; i < h; i++) {
		if (a[i][0] == '#') dp[i][0] = 0;
		else dp[i][0] = dp[i-1][0];
	}
	for (int i = 1; i < w; i++) {
		if (a[0][i] == '#') dp[0][i] = 0;
		else dp[0][i] = dp[0][i-1];
	}
	for (int i = 1; i < h; i++) 
		for (int j = 1; j < w; j++) 
			if (a[i][j]=='#') dp[i][j] = 0; else 
			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
			
	cout << dp[h-1][w-1] << endl;
	
	return 0;
}

Measured memory_bytes: 12544
import java.util.*;
import java.io.*;

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

	Scanner stdIn = new Scanner(System.in);
	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	
	int a1 = stdIn.nextInt();
	int a2 = stdIn.nextInt();
	int a3 = stdIn.nextInt();

	int min = a1;
	int max = a1;

	if(min > a2)
		min = a2;
	if(min > a3)
		min = a3;

	if(max < a2)
		max = a2;
	if(max < a3)
		max = a3;

	int ans = max - min;
	System.out.println(ans);
		



	}
}

Measured memory_bytes: 22996
class Card:
    def __init__(self, label):
        suits = ['S', 'H', 'C', 'D']
        suit, value = list(label)
        assert(suit in suits and 0 < int(value) < 10)

        self.suit = suit
        self.value = int(value)

    def __eq__(self, other):
        """equal

        >>> Card('S1') == Card('D9')
        False
        >>> Card('D9') == Card('S1')
        False
        >>> Card('C5') == Card('C5')
        True
        """
        return self.value == other.value

    def __lt__(self, other):
        """less than

        >>> Card('S1') < Card('D9')
        True
        >>> Card('D9') < Card('S1')
        False
        """
        return self.value < other.value

    def __gt__(self, other):
        """greater than

        >>> Card('S1') > Card('D9')
        False
        >>> Card('D9') > Card('S1')
        True
        """
        return self.value > other.value

    def __hash__(self):
        return hash((self.suit, self.value))

    def __str__(self):
        return self.suit + str(self.value)


def bubble_sort(deck):
    """sort deck by bubble sort

    >>> deck = [Card('H4'), Card('C9'), Card('S4'), Card('D2'), Card('C3')]
    >>> print(" ".join([str(c) for c in bubble_sort(deck)]))
    D2 C3 H4 S4 C9
    """
    size = len(deck)
    for i in range(size):
        for j in reversed(range(i+1, size)):
            if deck[j] < deck[j-1]:
                deck[j-1], deck[j] = deck[j], deck[j-1]

    return deck


def selection_sort(deck):
    """sort deck by selection sort

    >>> deck = [Card('H4'), Card('C9'), Card('S4'), Card('D2'), Card('C3')]
    >>> print(" ".join([str(c) for c in selection_sort(deck)]))
    D2 C3 S4 H4 C9
    """
    size = len(deck)
    for i in range(size):
        mini = i
        for j in range(i, size):
            if deck[mini] > deck[j]:
                mini = j
        deck[i], deck[mini] = deck[mini], deck[i]

    return deck


def is_stable_sorted(org, deck):
    """check if deck is sorted by stable manner

    >>> c1 = Card('S1')
    >>> c2 = Card('D1')
    >>> is_stable_sorted([c1, c2], [c1, c2])
    True
    >>> is_stable_sorted([c1, c2], [c2, c1])
    False
    """
    idx = {c:i for (i, c) in enumerate(org)}
    return all([c1 < c2 or idx[c1] < idx[c2]
                for (c1, c2) in zip(deck[:-1], deck[1:])])


def check_stable(org, deck):
    if is_stable_sorted(org, deck):
        return "Stable"
    else:
        return "Not stable"


def run():
    _ = int(input()) # flake8: noqa
    deck = []
    for lb in input().split():
        deck.append(Card(lb))

    db = bubble_sort(deck[:])
    print(" ".join([str(c) for c in db]))
    print(check_stable(deck, db))

    ds = selection_sort(deck[:])
    print(" ".join([str(c) for c in ds]))
    print(check_stable(deck, ds))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5640
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 100000;

int main() {
	int N, H;
	int m = 0;
	vector<pair<int, int>> s;

	cin >> N >> H;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		s.push_back(make_pair(b,a));
		m = max(a, m);
	}

	sort(s.begin(), s.end(), greater<pair<int,int>>());

	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (m >= s[i].first || H <= 0)break;
		H -= s[i].first;
		cnt++;
	}

	if (H > 0) {
		cnt += H / m;
		if (H % m)cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1400
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
using namespace std; 
int main()
{
	int s;
	cin >> s;
	vector<int> a(100000000);
	vector<int> b(100000000);
	int ans = 0;
	
	for (int i=0;i<1000004;i++)
	{
		if (i==0)
		{
			a.at(i) = s;

		}
		else if((a.at(i-1)%2)==0)
		{
			a.at(i) =a.at(i-1) / 2;
		}
		else
		{
			a.at(i) = a.at(i-1) * 3 + 1;
		}
		
		int f = 0;
		for (int j = 0; j<i; j++)
		{
			if (i == j)
			{
				continue;
			}
			else if (a.at(i) == a.at(j))
			{
				ans = i + 1;
				f = 1;
				break;

			}
			else
			{
				continue;
			}
		}
		if (f == 1)
		{
			break;
		}
	}
	
		cout << ans << endl;
	
}


Measured memory_bytes: 781568
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600123456789

int main(){
  long a,b,n;
  cin>>a>>b>>n;

  long ans = INF;
  repl(i,1,n+1) repl(j,1,n+1) if(__gcd(i,j)==1){
    if(b%j!=0) continue;
    long aa = b/j*i;
    ans = min(ans, abs(aa-a));
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3112
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
	nums = input().split(" ")
	a , b= int(nums[0]),int(nums[1])
	if a < b:
		return "a < b"
	elif a == b:
		return "a == b"
	else:
		return "a > b"
if __name__ == '__main__':
  print(main())

Measured memory_bytes: 7688
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

pointList = dict();

for temp in s:
  pointList[temp] = 0
for temp in t:
  pointList[temp] = 0
  
for temp in s:
  pointList[temp] += 1
for temp in t:
  pointList[temp] -= 1
  
ans = max(0, max(pointList.values()))

print(ans)

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

double sum_route(vector<int> &v, const vector<vector<int>> xy){
   double sum = 0;
   for (size_t i=0; i<v.size()-1; i++){
      int x1 = xy.at(v.at(i)).at(0);
      int y1 = xy.at(v.at(i)).at(1);
      int x2 = xy.at(v.at(i+1)).at(0);
      int y2 = xy.at(v.at(i+1)).at(1);
      double r = sqrt(pow(x2-x1, 2)+pow(y2-y1, 2));
      sum = sum + r;
   }
   return sum;
}

void print(const vector<int>& v) {
   for_each(v.begin(), v.end(), [](int x) {
      cout << x << " ";
   });
   cout << endl;
}

int main(){
   int N;
   cin >> N;
   vector<vector<int>> xy(N, vector<int> (2));
   for (int i=0; i<N; i++){
      cin >> xy.at(i).at(0);
      cin >> xy.at(i).at(1);
   }
   vector<int> city(N);
   for (int i=0; i<N; i++){
      city.at(i) = i;
   }
   double sum = 0;
   int cnt = 0;
   do {
      //print(city);
      sum = sum + sum_route(city, xy);
      cnt++;
      //cout << sum_route(city, xy) << " " << cnt << endl;
   } while(next_permutation(city.begin(), city.end()));

   cout << setprecision(11) << sum/cnt << endl;
}



Measured memory_bytes: 256
(defun solver ()
  (let* ((a (read)) (b (read)) (c (read))
         (x (read)) (y (read)))
    (if (< (+ a b) (* 2 c))
        (format t "~a~%" (+ (* x a) (* y b)))
        (progn
          (cond ((> x y)
                 (if (> (* 2 c) a)
                     (format t "~a~%"
                             (+ (* y (* 2 c)) (* (- x y) a)))
                     (format t "~a~%"
                             (+ (* y (* 2 c)) (* (- x y) (* 2 c))))))
                ((>= y x)
                 (if (> (* 2 c) b)
                     (format t "~a~%"
                             (+ (* x (* 2 c)) (* (- y x) b)))
                     (format t "~a~%"
                             (+ (* x (* 2 c)) (* (- y x) (* 2 c)))))))))))

(solver)


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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct BIT{
    ll N;
    vector<ll> bit;
    BIT(ll N) : bit(N+1),N(N){};

    ll sum(ll i){
        ll s = 0;
        while(i>0){
           s += bit[i];
           i -= i& -i;
        }
        return s;
    }

    void add(ll i,ll x){
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

//反転数を求める
ll inverse_number(vector<ll> z){
    ll n = z.size();
    ll inv_num = 0;

    BIT b(n);
    for(ll i = 0; i <= n; i++){
        b.bit[i] = 0;
    }

    for(ll i = 0; i < n; i++){
        inv_num += i - b.sum(z[i]);
        b.add(z[i],1);
    }

    return inv_num;
}

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

	ll n = s.length();
	vector<vector<ll> > al_pos(26);  //initial position

	for(ll i = 0; i < n; i++){
		al_pos[s[i]-'a'].push_back(i);
	}

	ll odd_al = -1;
	for(ll i = 0; i < 26; i++){
		if(al_pos[i].size() % 2 != 0){
			if(odd_al >= 0){
				cout << -1 << endl;
				return 0;
			}else{
				odd_al = i;
			}
		}
	}

	if((odd_al>=0 && n%2==0) || (odd_al<0 && n%2!=0)){
		cout << -1 << endl;
		return 0;
	}

	ll al_now[26] = {0};

	string front,back,center;
	for(ll i = 0; i < n; i++){
		if(n%2!=0 && al_now[s[i]-'a'] == al_pos[odd_al].size()/2 && s[i]-'a' == odd_al){
			center.push_back(s[i]);
			al_now[s[i]-'a']++;
		}else if(al_now[s[i]-'a']+1<= al_pos[s[i]-'a'].size() / 2){
			front.push_back(s[i]);
			al_now[s[i]-'a']++;
		}else{
			back.push_back(s[i]);
			al_now[s[i]-'a']++;
		}
	}

	for(ll i = 0; i < 26; i++) al_now[i]=0;

	vector<ll> kaibun_index; //回文にしたあとのindex
	for(ll i = 0; i < front.length(); i++){
		kaibun_index.push_back(al_pos[front[i]-'a'][al_now[front[i]-'a']]);
		al_now[front[i]-'a']++;
	}
	for(ll i = 0; i < center.length(); i++){
		kaibun_index.push_back(al_pos[center[i]-'a'][al_now[center[i]-'a']]);
		al_now[center[i]-'a']++;
	}
	for(ll i = front.length()-1; i >= 0; i--){
		kaibun_index.push_back(al_pos[front[i]-'a'][al_now[front[i]-'a']]);
		al_now[front[i]-'a']++;
	}

	for(ll i = 0; i < n; i++) kaibun_index[i]++;

	cout << inverse_number(kaibun_index) << endl;

	return 0;
}

Measured memory_bytes: 8052
x, n = map(int, input().split())
plist = list(map(int, input().split()))

if n == 0:
    print(x)
    exit()

for i in range(100):
    if (x - i) not in plist:
        print(x - i)
        exit()
    if (x + i) not in plist:
        print(x + i)
        exit()

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

int main(){
  int A,B;
  cin >> A >> B;
  if(13<=A){
    cout << B << endl;
  }else if(6<=A){
    cout << B/2 << endl;
  }else{
    cout << 0<< endl;
  }
}

Measured memory_bytes: 256
N = input()
M = input()

sorted_asc = sorted(list(N))
sorted_desc = sorted(list(M), reverse=True)
res = ""

for (x, y) in zip(sorted_asc, sorted_desc):
    if x < y:
        res = "Yes"
        break
    elif x > y:
        res = "No"
        break

if res == "" and len(N) == len(M):
    res = "No"
elif res == "" and len(N) < len(M):
    res = "Yes"
elif res == "" and len(N) > len(M):
    res = "No"

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	map<ll, ll> mp;
	ll n, p;
	cin >> n >> p;
	REP(i, n)
	{
		int t;
		cin >> t;
		mp[t % 2]++;
	}
	if (!mp[1]) {
		if (p) {
			cout << 0 << endl;
			return 0;
		}
		else n++;
	}
	ll ans = 1;
	REP(i, n - 1) ans *= 2;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<vector>
using namespace std;

const int MAX_N = 2e5;
int n, k;
int sum[MAX_N];
map<int, vector<int>> m;

int main() {
    scanf("%d %d", &n, &k);
    long ans = 0;
    scanf("%d", sum);
    sum[0] = (sum[0] - 1) % k;
    if (k > 1 && sum[0] == 0) ans++;
    for (int i = 1; i < n; i++) {
        int a;
        scanf("%d", &a);
        sum[i] = (sum[i - 1] + a - 1) % k;
        if (i < k - 1 && sum[i] == 0) ans++;
    }

    for (int i = 0; i < n; i++) m[sum[i]].push_back(i);
    for (auto &x : m) {
        vector<int> v = x.second;
        int s = v.size();
        int i = 0, j = 0;
        while (i < s - 1) {
            if (j < s && v[j] - v[i] < k) {
                j++; continue;
            }
            ans += j - ++i;
        }
    }

    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 22912
#include <iostream>


using namespace std;
int a[100000], b[100000];

int main()
{
    int n, k =0, q, com, x, y;
    long long s = 0;
    cin >> n >> q;

    for (int i = 0; i < n; i++){
        a[i] = 0;
    }

    for (int i = 0; i < q; i++){

        cin >> com >> x >> y;

        if (com == 0){
            a[x] += y;
        } else {
            for (int j = x; j < y + 1; j++)
                s += a[j];

            b[k] = s;
            k++;
            s = 0;
        }
    }
       for (int i = 0; i <k; i++)
            cout << b[i] << endl;

    return 0;
}

Measured memory_bytes: 3652