akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int n; cin>>n;
  map<int,int> mp;
  rep(i,n){
    int a; cin>>a;
    if(a%4==0) mp[2]++;
    else if(a%2==0) mp[1]++;
    else mp[0]++;
  }
  bool ans=false;
  if(mp[2]>=n/2){
    ans=true;
  }else if(mp[1]==n){
    ans=true;
  }else{
    rep(i,n){

      if(i%2==0)
        mp[0]--;
      else if(mp[2]>0)
        mp[2]--;
      
      if(mp[0]<=0&&mp[2]>0){
        ans=true;
        break;
      }else if(mp[2]<=0){
        ans=false;
        break;
      }
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3608
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		int num = N*3;
		int a[] = new int[num];
		for (int i = 0; i < num; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		long result = 0;
		Arrays.sort(a);
		for (int i = num-2; N > 0; i-=2) {
			result += a[i];
			N--;
		}
		out.println(result);
		out.flush();
	}
}

Measured memory_bytes: 61644
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int i = 1;
        int n = scn.nextInt();
        while(n > (int)Math.ceil(Math.pow(3, i))) {
            i++;
        }
        System.out.println(i);
    }
}

Measured memory_bytes: 26172
// バブルソート
#include<iostream>
#include<algorithm>
using namespace std;

static const int MAX_N = 100;

void bubbleSort(int A[], int n);

int main(void)
{
    int N;
    int ary_sequence[MAX_N];

    cin >> N;

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

    bubbleSort(&ary_sequence[0], N);

    return 0;
}

// バブルソートを実施する関数
void bubbleSort(int A[], int n)
{
    int count = 0, j = 0, tmp;
    bool flag = true;

    while( flag )
    {
        flag = false;

        for(int i = n - 1; i > j; i--)
        {
            if( A[i - 1] > A[i] )
            {
                // 値の入れ替え
                tmp = A[i];
                A[i] = A[i - 1];
                A[i - 1] = tmp;

                flag = true;

                // 交換回数の保存
                count++;
            }
        }

        j++;
    }

    // 結果表示用
   for(int i = 0; i < n; i++)
   {
       if( i )
       {
           cout << ' ';
       }

       cout << A[i];
   }

   cout << endl;
   cout << count << endl;

    return;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;

int main() {
    string s;
    string t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> is(26);
    //部分列として判定
    //文字のindexのリストを作成する
    REP(i, n) { is[s[i] - 'a'].push_back(i); }
    REP(i, n) { is[s[i] - 'a'].push_back(i + n); }
    ll ans = 0;
    int p = 0; // p以降
    REP(i, m) {
        int c = t[i] - 'a';
        if(is[c].size() == 0) {
            cout << "-1" << endl;
            return 0;
        }
        p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
        if(p >= n) {
            p -= n;
            ans += n;
        }
    }
    ans += p;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1724
/* 
	Author: ankrypt
*/

#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;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;

ll ans[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
	scanf("%lld", &N);
	printf("%lld\n", ans[N - 1]);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

int main() {
  ll N;
  bool judge = 1;
  cin >> N;
  vector<ll> t(N), x(N), y(N);
  for(ll i = 0; i < N; i++) {
    cin >> t.at(i) >> x.at(i) >> y.at(i);
    if(i == 0) {
        if((x.at(i) + y.at(i) > t.at(i)) || ((t.at(i) - (x.at(i) + y.at(i))) % 2 == 1)) {
          judge = 0;
        }
    }
    else {
      if((abs(x.at(i) - x.at(i - 1)) + abs(y.at(i) - y.at(i - 1)) > t.at(i) - t.at(i - 1)) || (((t.at(i) - t.at(i - 1)) - (abs(x.at(i) - x.at(i - 1)) + abs(y.at(i) - y.at(i - 1)))) % 2 == 1)) {
        judge = 0;
      }
    }
  }
  if(judge == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
N = int(input())
S = input().rstrip()
Q = int(input())
qs = [input().split() for i in range(Q)]

def ctoi(c):
    return ord(c) - ord('a')

class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w):
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x):
        x += 1
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r):
        return self._sum(r-1) - self._sum(l-1)
bits = [BinaryIndexedTree(N) for _ in range(26)]

for i,c in enumerate(S):
    bits[ctoi(c)].add(i,1)

s = list(S)
ans = []
for a,b,c in qs:
    if a=='1':
        x = int(b)-1
        bits[ctoi(c)].add(x,1)
        bits[ctoi(s[x])].add(x,-1)
        s[x] = c
    else:
        b,c = int(b)-1,int(c)
        tmp = 0
        for i in range(26):
            if bits[i].sum(b,c) > 0:
                tmp += 1
        ans.append(tmp)
print(*ans, sep='\n')

Measured memory_bytes: 176500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,D,X;
    cin >> N >> D >> X;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A.at(i);
    int sum3=0;
    for(int i=0;i<N;i++){
        int sum2=1;
        int sum1=1;
        while(sum1+A.at(i)<=D){
            sum1+=A.at(i);
            sum2++;
        }
        sum3+=sum2;
    }
    cout << sum3+X << endl;
}

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

int main()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll y = max(0, (int)ceil(log2((a * 1.00) / b)));
	if (b * pow(2, y) == a)
		y++;
	// cout << "Y: " << y << endl;
	ll x = k - y;
	if (x < 0)
	{
		cout << "No";
		return 0;
	}
	if ((c * pow(2, x)) > (b * pow(2, y)))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i,a,b,c) for (ll i=a;(c>0?i<b:i>b) and c!=0;i+= c)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(name) (name.begin(), name.end())
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) power(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
double max(double s)
{
    double l= s/3;
    s -= l;
    double b= s/2;
    double h= s-b;
    return l*b*h;
}

int main()
{
    double s;
    cin>>s;
    cout<<fixed<<setprecision(12)<<max(s)<< endl;
    return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=1e5+5;
int n,m,tl;
ll q[maxn],p[maxn],f[maxn];

inline ll rd(){
	ll ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

void pre(){
	tl=0;
	go(i,m+1,1){
		while(tl > 0 && q[tl] >= q[i]) tl--;
		q[++tl]=q[i];
	}
}

inline int get(ll x){
	int l=1,r=tl,res=0;
	while(l <= r){
		int mid=l+r>>1;
		if(q[mid] <= x) l=mid+1,res=mid;
		else r=mid-1;
	}
	return res;
}

inline void work(ll k,ll las){
	if(las == 0) return ;
	if(las <= q[1]){
		f[1]+=k; f[las+1]-=k;
		return ;
	}
	int np=get(las);
	p[np]+=k*(las/q[np]);
	work(k,las%q[np]);
}

int main(){
	n=rd(); m=rd()+1; q[1]=n;
	go(i,m+1,2) q[i]=rd(); pre();
	p[tl]=1;
	for(rg int i=tl;i>=2;i--){
		ll tmp=q[i]/q[i-1],las=q[i]%q[i-1];
		p[i-1]+=tmp*p[i];
		work(p[i],las);
	}
	go(i,q[1]+1,1) f[i]+=f[i-1];
	go(i,n+1,1)
		if(i <= q[1]){
			printf("%lld\n",p[1]+f[i]);
		}else puts("0");
	return 0;
}//Faze


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

  int top ,S[1000];

void push(int a){
    top++;
    S[top] = a;
  }

int pop(){
    top--;
    return S[top + 1];
  }

int main(){
  int x, a, b;
  top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-' ){
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push (a * b);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  cout << pop() << endl;
  return 0;
}



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

typedef long long ll;
using namespace std;
typedef long double ld;
typedef pair<ld,ld> pii;
const ll mod = 1e9+7;

ll lt(ll x,ll y)
{
    ll res=1;
    x=x%mod;
    while (y>0)
    {
        if (y&1) res=(res*x) %mod;
        x=(x*x)%mod;
        y=y>>1;
    }
    return res;
}

ll choose(ll x, ll y)
{
    ll k1=1,k2=1,k3=1;
    for(ll i=1; i<=x+y; ++i)
    {
        if (i<=x) k1=(k1*i)%mod;
        if (i<=y) k2=(k2*i)%mod;
        k3 =(k3*i)%mod;
    }
    k1 = lt(k1,mod-2);
    k2 = lt(k2,mod-2);
    k1=(k1*k2)%mod;
    return (k3*k1)%mod;
}

int main()
{
#ifndef RICARDO
    //freopen("input.inp", "r", stdin);
#endif // RICARDO
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll x,y;
    cin >> x >> y;
    ll n,m;
    if ((2*x-y)%3==0) n = (2*x - y)/3; else n=-1;
    if ((2*y-x)%3==0) m = (2*y - x)/3; else m=-1;
    if (n<0 || m<0) cout << 0; else
    {
        cout << choose(m,n);
    }
    return 0;
}


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

int main()
{
    string s1,s2;
    cin >> s1 >> s2;
    reverse(s1.begin(),s1.end());
    if(s1 == s2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll r,d,x;
	cin >>r >>d >>x;
	
	rep(i, 10){
		 x = r * x  -d;
		cout << x <<"\n";
	}
	return 0;
}


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

using namespace std;

struct StronglyConnectedComponents
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};

int main()
{
  int N, M, S, P[100], T[100], K[100];
  bool mine[100];
  int deq[10001], deqv[10001];

  while(scanf("%d %d %d", &N, &M, &S), N) {
    for(int i = 0; i < N; i++) {
      scanf("%d %d %d", &P[i], &T[i], &K[i]);
    }
    StronglyConnectedComponents g(N);
    memset(mine, false, sizeof(mine));
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      g.add_edge(--x, --y);
      if(x == y) mine[x] = true;
    }

    vector< vector< int > > dag;
    g.build(dag);
    vector< vector< int > > component(dag.size());
    for(int i = 0; i < N; i++) component[g[i]].push_back(i);

    int dp[100][10001] = {{}};
    int ret = 0;

    for(int i = 0; i < dag.size(); i++) {
      if(component[i].size() == 1 && !mine[component[i][0]]) K[component[i][0]] = 1;
      for(int j : component[i]) {
        for(int k = 0; k < T[j]; k++) {
          int s = 0, t = 0;
          for(int l = 0; l * T[j] + k <= S; l++) {
            int val = dp[i][l * T[j] + k] - l * P[j];
            while(s < t && deqv[t - 1] <= val) --t;
            deq[t] = l;
            deqv[t++] = val;
            dp[i][l * T[j] + k] = deqv[s] + l * P[j];
            if(deq[s] == l - K[j]) ++s;
          }
        }
      }
      for(int k = 0; k <= S; k++) {
        ret = max(ret, dp[i][k]);
        for(int j : dag[i]) dp[j][k] = max(dp[j][k], dp[i][k]);
      }
    }

    printf("%d\n", ret);
  }
}

Measured memory_bytes: 7200
#include <bits/stdc++.h>
 
using namespace std;
 
string query(int x) {
  cout << x << endl;
  fflush(stdout);
  string res;
  cin >> res;
  if (res == "Vacant") {
    exit(0);
  }
  return res;
}
 
int main() {
  int n;
  cin >> n;
  int i = 0;
  int j = n - 1;
  string x = query(0);
  string y = query(n - 1);
  while (true) {
    int k = (i + j) >> 1;
    string z = query(k);
    if ((z == x) != (i % 2 == k % 2)) {
      j = k;
    } else {
      i = k;
      x = z;
    }
  }
  return 0;
}

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

const ll mod = 1000000007;
const int INF = 1001001001;

ll dp[3002][3002][4];

ll max(ll a, ll b, ll c){
	return max(max(a, b), c);
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int R, C, K; cin >> R >> C >> K;
	vector<vector<ll>> mp(R, vector<ll> (C));
	for(int i = 0; i < K; i++){
		int r, c; cin >> r >> c;
		--r; --c;
		cin >> mp[r][c];

	}
	for(int i = 0; i <= R; i++){
		for(int j = 0; j <= C; j++){
			for(int k = 0; k < 4; k++){
				dp[i][j][k] = (k == 0 ? 0 : -INF);
			}
		}
	}
	//dp[i][j][k] : you are at (i, j) and you've picked up k items on the i-th row until the coordinate(i, j).
	for(int i = 0; i < R; i++){
		for(int j = 0; j < C; j++){
			for(int k = 0; k < 3; k++){
				if(mp[i][j]){
					if(j == 0){
						dp[i][j][1] = dp[i][j][0] + mp[i][j];
					}
					else{
						if(dp[i][j-1][k] == -INF) break;
					    dp[i][j][1] = max(dp[i][j][0] + mp[i][j], dp[i][j-1][1]);
						if(k >= 1) dp[i][j][k+1] = max(dp[i][j-1][k] + mp[i][j], dp[i][j-1][k+1]);
					}
				}
				else{
					if(j >= 1) dp[i][j][k+1] = dp[i][j-1][k+1];
				}
			}
			dp[i+1][j][0] = max(dp[i][j][0], max(dp[i][j][1], dp[i][j][2], dp[i][j][3]));
		}
	}
	cout << max(max(dp[R-1][C-1][1], dp[R-1][C-1][2], dp[R-1][C-1][3]), dp[R-1][C-1][0]) << endl;
} 

Measured memory_bytes: 354828
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,m;
	cin >> n >> m;
	int k[m + 1] = {},s[11][11] ={};
	for(int i = 1; i <= m; i++){
		cin >> k[i];
		for(int j = 1; j <= k[i]; j++){
			cin >> s[i][j];
		}
	}
	int p[m + 1] = {};
	for(int i = 1; i <= m; i++) cin >> p[i];
	int S[11] = {};
	int cnt = 0;
	for(S[1] = 0; S[1] <= 1; S[1]++){
		for(S[2] = 0; S[2] <= 1; S[2]++){
			for(S[3] = 0; S[3] <= 1; S[3]++){
				for(S[4] = 0; S[4] <= 1; S[4]++){
					for(S[5] = 0; S[5] <= 1; S[5]++){
						for(S[6] = 0; S[6] <= 1; S[6]++){
							for(S[7] = 0; S[7] <= 1; S[7]++){
								for(S[8] = 0; S[8] <= 1; S[8]++){
									for(S[9] = 0; S[9] <= 1; S[9]++){
										for(S[10] = 0; S[10] <= 1; S[10]++){
											int cnt_s[11] = {};
											for(int i = 1; i <= m; i++){
												for(int j = 1; j <= k[i]; j++){
													if(S[s[i][j]] == 1)cnt_s[i]++; 
												}
											}
											bool light = true;
											for(int i = 1; i <= m; i++){
												if((cnt_s[i] % 2) != p[i]) light = false;
											}
											if(light == true) cnt++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout << cnt / pow(2, 10 - n) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    while (cin >> n && n){
        int ans = 0;
        bool l = 0, r = 0, f = 0;
        while (n--){
            string s;
            cin >> s;
            if (s[0] == 'l') l ^= 1;
            else r ^= 1;
            if (!f && l && r){
                ans++;
                f ^= 1;
            }else if (f && !l && !r){
                ans++;
                f ^= 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3148
#include <stdio.h>

int main(){
    int a,b, sum = 0;
    scanf ("%d%d", &a, &b);
    if (a>=b){
        sum+=a;
        a--;
    } else {
        sum+=b;
        b--;
    }
    if (a>=b){
        sum+=a;
        a--;
    } else {
        sum+=b;
        b--;
    }
    printf ("%d\n", sum);
}

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

string S, T;
vector<string> L;

int main(void){
    
    cin >> S >> T;
    
    for(int i = 0; i + T.size() <= S.size(); ++i){
        string temp = S.substr(i, T.size());
        for(int j = 0; j < temp.size(); ++j){
            if(temp[j] != '?' && temp[j] != T[j]){
                temp = "";
                break;
            }
        }
        if(temp.size()){
            string copy;
            for(int j = 0; j < S.size(); ++j){
                if(S[j] == '?') copy.push_back('a');
                else copy.push_back(S[j]);
            }
            string left = copy.substr(0, i);
            string right = copy.substr(i + T.size());
            L.push_back(left + T + right);
        }
    }
    
    if(L.size()){
        sort(L.begin(), L.end());
        cout << L[0] << endl;
    }
    else cout << "UNRESTORABLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (998244353ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

vector<int> v;
queue<P> q;
bool done[123456];

int main(void){
	int n,i,l,a,b;
	P tmp;
	fill(done,done+123456,false);
	q.push(P(0,0));
	v.push_back(1);
	cin >> n;
	i = 6;
	while(i <= n){
		v.push_back(i);
		i *= 6;
	}
	i = 9;
	while(i <= n){
		v.push_back(i);
		i *= 9;
	}
	l = v.l_ength();
	while(!q.empty()){
		tmp = q.front();
		a = tmp.first;
		b = tmp.second;
		q.pop();
		if(a == n){
			cout << b << endl;
			break;
		}
		if(done[a]){
			continue;
		}
		done[a] = true;
		for(i=0; i<l; ++i){
			if(a+v[i] <= n){
				q.push(P(a+v[i],b+1));
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    char a;
    cin >> a;
    if ('A' <= a && a <= 'Z') cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}

Measured memory_bytes: 3596
A, B, C, X, Y = map(int, input().split())

if 2 * C < A + B:
    if X <= Y:
        if 2 * C > B:
            cost = 2*C*X + (Y-X)*B
        else:
            cost = 2*C*Y
    else:
        if 2 * C > A:
            cost = 2*C*Y + (X-Y)*A
        else:
            cost = 2*C*X
else:
    cost = A*X + B*Y
print(cost)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(){
  char A[10],B[10],C[10];
  scanf("%s %s %s",A,B,C);
  int a,b,c;
  a=strlen(A);
  b=strlen(B);
  c=strlen(C);
  if(*(A+a-1)==*B&&*(B+b-1)==*C){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

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

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n =scanner.nextInt();
        int k = scanner.nextInt();
        int[] balls = new int[n + 1];

        for (int i = 0; i < n; i++) balls[scanner.nextInt()]++;


        Arrays.sort(balls);
        int totalK = 0;
        for (int i = n; i >= n + 1 - k; i--) totalK += balls[i];
        System.out.println(n - totalK);
    }
}


Measured memory_bytes: 65588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
ll ans=0;
void Main(){
    ll n;cin>>n;
    vector<ll> a(n);
    map<ll,int> mp;
    For(i,0,n) {
        cin>>a[i];
        ans+=mp[i-a[i]];
        mp[a[i]+i]++;
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}


Measured memory_bytes: 27360
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b;
	while(~scanf("%d%d",&a,&b))
	{
		int sum1=0;
		int sum2=0;
		int i;
		for(i=1;i<=a;i++)
		{
			sum1+=i;
		}
		for(i=1;i<=a;i++)
		{
			sum2+=b+i-1;
		}
		if(b>=1)
		{
			printf("%d\n",sum2-b);
		}
		else
		{
			int min=210,k,kk;
			for(i=1;i<=a;i++)
			{
				k=fabs(b+i-1);
				if(k<min)
				{
					min=k;
					kk=b+i-1;
				}
			}
			printf("%d\n",sum2-kk);
		}
	}return 0;
}

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

public class Main {
	private static BufferedReader br = null;
	
	public static void main(String[] args) {
		String[] strs = read(1)[0].split(" ");
		int a = Integer.parseInt(strs[0]);
		int b = Integer.parseInt(strs[1]);
		
		String result = "No";
		
		for (int i = 1; i <= 3; i++) {
			if ((a * b * i) % 2 == 1) {
				result = "Yes";
				break;
			}
		}
		
		System.out.println(result);
		
		close();
	}
	
	private static String[] read(int len) {
		List<String> strList = new ArrayList<>();
		
		try {
			if (br == null) {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
			
			for (int i = 0; i < len; i++) {
				strList.add(br.readLine());
			}
		} catch (IOException e) {
		}
		
		return strList.toArray(new String[0]);
	}
	
	private static void close() {
		try {
			if (br != null) {
				br.close();
			}
		} catch (IOException e) {
		}
	}
}


Measured memory_bytes: 21332
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n, a, b = MI()
print(min(n*a, b))


Measured memory_bytes: 65900
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N,M = map(int, input().split())

# (x,y)みたいな構造体をN個まとめてリストにするとき
L = []
R = []
for i in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

print(max(min(R)-max(L)+1,0))

Measured memory_bytes: 20068
N, M, X = list(map(int, input().split()))
C = []
A = []
for i in range(N):
    L = list(map(int, input().split()))
    C.append(L[0])
    A.append(L[1:])
# print(C)
# print(A)

bestmoney = float("inf")
for i in range(2**N):
    U = []
    for j in range(M):
#         print(j, [(((1<<k)&i)!=0)*A[k][j] for k in range(N)])
        u = sum([(((1<<k)&i)!=0)*A[k][j] for k in range(N)])
        U.append(u)
    flag = True
    for j in range(M):
        if U[j] < X:
            flag = False
            
#     print(bin(i),U,flag)
    if flag:
        bestmoney = min(sum([(((1<<k)&i)!=0)*C[k] for k in range(N)]), bestmoney)

if bestmoney == float("inf"):
    print(-1)
else:
    print(bestmoney)

Measured memory_bytes: 9280
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll a[100005];
ll b[100005];
int main(){
   ll c;
   cin>>c;
   ll cn=0;
   ll s=0;
   ll n=1ll;
   while(n<=c){
   	 if(n%3 && n%5)s+=n;
   	 n++;
    }
   cout<<s;
   
   
   
}

Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
using namespace std;
static const int MAX = 100;

void trace (int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort (int A[], int N) {
    int i, j, seq;
    for (i = 1; i < N; i++) {
        seq = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > seq) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = seq;
        trace(A, N);
    }
}

int main() {
    int N;
    scanf("%d", &N);
    
    int A[MAX];
    for (int i = 0;i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    trace(A, N);
    insertionSort(A, N);

    return 0;
}



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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(a.begin(), a.end());
    rep(i, n) cout << a[i].second << ' ';
    cout << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];
    unordered_set<int> bad;
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        if (h[a-1] >= h[b-1]) bad.insert(b);
        if (h[a-1] <= h[b-1]) bad.insert(a);
    }
    cout << N - bad.size() << endl;
    return 0;
}

Measured memory_bytes: 5996
#include <stdio.h>

int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, mini;
  for(i=0; i<N-1; i++) {
    mini = i;
    for(j=i; j<N; j++) {
      if(A[j] < A[mini]) mini = j;
    }

  	t = A[i];
  	A[i] = A[mini];
  	A[mini] = t;

  	if(i != mini) sw++;
  }
  return sw;
}

int main(void) {
  int A[100], N, i, sw;
  scanf("%d", &N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for(i=0;i<N;i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}



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

int n, rt, fl[101000], col[101000], ans;
vector<int>G[101000], tr[101000];
char s[101000];

void dfs(int x,int fff){
  fl[x]|= s[x]=='W';
  for (auto y:G[x])
    if (y!=fff){
      dfs(y,x);
      if (fl[y]){
	ans+=2; fl[x]|=1;
	tr[x].push_back(y); tr[y].push_back(x);
      }
    }
}

int f[101000][3], res;
void sfd(int x,int fff){
  for (auto y:tr[x])
    if (y!=fff){
      sfd(y,x);
      f[x][2]=f[y][0];
      sort(f[x],f[x]+3,greater<int>());
    }
  f[x][0]+=col[x];
  res=max(res,f[x][0]+f[x][1]);
}

int main(){
  cin>>n; int x, y;
  for (int i=1;i<n;++i){
    cin>>x>>y;
    G[x].push_back(y); G[y].push_back(x);
  }
  cin>>s+1;
  if (*max_element(s+1,s+n+1)=='B') return puts("0"), 0;
  rt=max_element(s+1,s+n+1)-s;
  dfs(rt,0);
  for (int i=1;i<=n;++i)
    if (fl[i]){
      col[i]= (s[i]=='W')^(tr[i].size()&1);
      ans+=col[i];
    }
  sfd(rt,0);
  cerr<<ans<<' '<<res<<endl;
  cout<<max(1,ans-res*2);
}


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

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

	int ans=0;

	int cd[5]= {105, 135, 165, 189, 195};

	for(int i=0; i<5; i++)
		if(n>= cd[i])
			ans++;

	cout<< ans<<endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [int(i) for i in input().split()]
current = 0
ans = float('inf')
while current < len(w):
    left = 0
    right = 0
    for index,value in enumerate(w):
        if current < index:
            left += value
        else:
            right += value
    temp = abs(left-right)
    if temp <= ans:
        ans = temp
        current += 1
    else:
        print(ans)
        break
if current == len(w):
    print(ans)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!
n=int(input())
k=str(n)
K=list(k)
count=True
for i in range(len(K)):
    if i==0:
        if K[i]!='1':
            break
    else:
        if K[i]!='0':
            break
    if i==len(K)-1:
        count=False
    #print(i)
#print(K)
for j in range(len(K)):
    K[j]=int(K[j])
if count==True:
    print(sum(K))
else:
    print(10)


Measured memory_bytes: 3060
n = int(input())
l = list(map(int, input().split()))
d = dict()
mod = 10**9 + 7
for i in l:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d2 = dict()
for i in range(1+n%2,n,2):
  d2[i] = 2
if n%2:
  d2[0] = 1
if d == d2:
  print(2**(n//2)%mod)
else:
  print(0)

Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
  	scanf("%d%d%d",&a,&b,&c);
  	if(a+b+c>=22)
      	printf("bust\n");
  	else
      	printf("win\n");
  	return 0;
}

Measured memory_bytes: 256
def solve(s):
    d = set()

    def f(i):
        if i % 2 == 0:
            return i // 2
        else:
            return 3 * i + 1

    while True:
        d.add(s)
        s = f(s)
        if s in d:
            return len(d) + 1


if __name__ == "__main__":
    s = int(input())
    print(solve(s))


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int N[3];
	for (int i = 0; i < 3; i++) {
		scanf("%d", &N[i]);
	}

	int m = 1000000;

	m = min(m, abs(N[0] - N[1]) + abs(N[1] - N[2]));
	m = min(m, abs(N[0] - N[2]) + abs(N[2] - N[1]));
	m = min(m, abs(N[1] - N[0]) + abs(N[0] - N[2]));

	printf("%d", m);

}

Measured memory_bytes: 128
// C - Sum of gcd of Tuples (Easy)
import { readFileSync } from "fs";
const K = ~~readFileSync("/dev/stdin", "utf8");

const gcd = (a: number, b: number): number => {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

let anser = 0;

for (let c = 1; c <= K; c++) {
    for (let b = 1; b <= K; b++) {
        for (let a = 1; a <= K; a++) {
            anser = anser + gcd(gcd(a, b), c);
        }
    }
}
console.log(anser);



Measured memory_bytes: 31576
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 60000;
int nodeID[80000];
vector<vector<int> > g;
vector<pair<int,int> > val;
int n, L;
int Not(int u) {
	if (u < L)
		return u + L;
	return u - L;
}
void addEdge(int u, int v) {
	g[Not(u)].push_back(v);
	g[Not(v)].push_back(u);
}
vector<int> S;
int comp[N], low[N], idx[N], dfs, cmp;
bool vis[N];
void DFS(int u) {
	idx[u] = low[u] = ++dfs;
	vis[u] = true;
	S.push_back(u);
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		if (!low[v])
			DFS(v);
		if (vis[v])
			low[u] = min(low[u], low[v]);
	}
	if (low[u] == idx[u]) {
		while (true) {
			int v = S.back();
			S.pop_back();
			vis[v] = false;
			comp[v] = cmp;
			if (u == v)
				break;
		}
		++cmp;
	}
}
int id;
void setID(int n, int s, int e) {
	if (s == e)
		return;
	nodeID[n] = id++;
	setID(n * 2, s, (s + e) / 2);
	setID(n * 2 + 1, (s + e) / 2 + 1, e);
}
void initEdges(int n, int s, int e) {
	if (s == e) {
		nodeID[n] = val[s].second;
		return;
	}
	initEdges(n * 2, s, (s + e) / 2);
	initEdges(n * 2 + 1, (s + e) / 2 + 1, e);
	g[Not(nodeID[n])].push_back(Not(nodeID[n * 2]));
	g[Not(nodeID[n])].push_back(Not(nodeID[n * 2 + 1]));
}
int ql, qr;
void addEdges(int n, int s, int e, int u) {
	if (qr<s || ql>e)
		return;
	if (s >= ql && e <= qr) {
		g[u].push_back(Not(nodeID[n]));
		return;
	}
	addEdges(n * 2, s, (s + e) / 2, u);
	addEdges(n * 2 + 1, (s + e) / 2 + 1, e, u);
}
vector<int> sz;
bool check(int d) {
	for (int i = 0; i < g.size(); ++i)
		g[i].resize(sz[i]);
	for (int i = 1; i < val.size(); ++i) {
		ql = lower_bound(val.begin() + 1, val.end(), make_pair(val[i].first - d + 1, -1)) - val.begin();
		if (ql < i) {
			qr = i - 1;
			addEdges(1, 1, n * 2, val[i].second);
		}
		ql = i + 1;
		qr = lower_bound(val.begin() + 1, val.end(), make_pair(val[i].first + d, -1)) - val.begin();
		--qr;
		if (ql <= qr)
			addEdges(1, 1, n * 2, val[i].second);
	}
	memset(low, 0, sizeof(low));
	dfs = cmp = 0;
	for (int i = 0; i < g.size(); ++i)
		if (!low[i])
			DFS(i);
	for (int i = 0; i < L; ++i)
		if (comp[i] == comp[Not(i)])
			return false;
	return true;
}
int main()
{
	scanf("%d", &n);
	id = n;
	setID(1, 1, n * 2);
	L = id;
	val.resize(n * 2 + 1);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &val[i].first);
		val[i].second = i - 1;
		scanf("%d", &val[i + n].first);
		val[i + n].second = Not(i - 1);
	}
	sort(val.begin() + 1, val.end());
	g.resize(L << 1);
	initEdges(1, 1, n * 2);
	for (int i = 0; i < g.size(); ++i)
		sz.push_back(g[i].size());
	int l = 0, r = 1e9, m, res = 0;
	while (l <= r) {
		m = (l + r) / 2;
		if (check(m)) {
			res = m;
			l = m + 1;
		}else
			r = m - 1;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 10748
N = int(input())
AB = [[0] * 2 for _ in range(N)]
time = [0] * N
out = 0
q = []
for i in range(N):
    tmp = list(map(int, input().split()))
    AB[i][0] = tmp[0]
    AB[i][1] = tmp[1]
    if AB[i][1] - AB[i][0] < 0:
        out = 1

AB = sorted(AB, key=lambda x: x[1])

count = 0
for i in range(N):
    if count + AB[i][0] > AB[i][1]:
        out = 1
        break
    else:
        count += AB[i][0]
if out == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 82668
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
  long long int x, k, d;
  long long int q, r;
  scanf("%lld%lld%lld", &x, &k, &d);
  
  x = llabs(x);
  d = llabs(d);
  
  q = x/d;
  r = x%d;
  
  if (k <= q) {
    printf("%lld", x - d*k);
    return 0;
  }
  
  if ((k-q)%2==0) {
    printf("%lld", r);
    return 0;
  }
  
  if ((k-q)%2!=0) {
    printf("%lld", d-r);
    return 0;
  }
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int x,n,a;
  cin >> x;
  while (x!=1){
    a=n=x;
    while (a*a>n) a--;
    while (a>1){
      n=x;
      while (n%a==0) n/=a;
      if (n==1) break;
      a--;
    }
    if (a!=1) break;
    x--;
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int IINF = INT_MAX;
const int MAX_N = int(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)

int n, m, x[MAX_N];
vector<vector<P> > g;

bool dfs(int v){
    for(auto p : g[v]){
        int u = p.first, dif = p.second;
        if(x[u]==IINF){
            x[u] = x[v] + dif;
            if(!dfs(u)) return false;
        }
        if(x[u] != x[v] + dif) return false;
    }
    return true;
}

int main() {
    cin >> n >> m;
    g.resize(n);
    fill(x,x+n,IINF);
    REP(i,m){
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        g[l].push_back({r,d});
        g[r].push_back({l,-d});
    }
    bool ok = true;
    REP(i,n){
        if(x[i]==IINF){
            x[i]=0;
            if(!dfs(i)){
                ok = false;
            }
        }
    }
    cout << (ok?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int LIS(vector<int> &a) {
    int n = a.size();
    vector<int> dp(n, INF);
    for(int i=0;i<n;i++) *lower_bound(ALL(dp),a[i]) = a[i];
    return distance(begin(dp), lower_bound(ALL(dp), INF));
}
signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    cin>>a;
    cout<<LIS(a)<<endl;
    return 0;
}

Measured memory_bytes: 4364
solve :: [Int] -> [Int]
solve (x:y:xs)
  | null xs = []
  | otherwise =	length [1 | a<-[1..x], b<-[1..a], c<-[1..b], a /= b && b /= c && c /= a, a+b+c == y] : solve xs

main = getContents >>= mapM_ print . solve . map read . words

Measured memory_bytes: 4628
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int[] n = io.r<int>(' ');
        int c = 0;
        for (int i = n[0]; i <= n[1]; i++)
        {
            if (n[2] % i == 0) { c++; }
        }
        io.w(c);
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10332
// https://beta.atcoder.jp/contests/abc109

#define SUBMIT
//#define DEBUG

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

int a[500 + 1][500 + 1];
int H, W;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(2 3
1 2 3
0 1 1
)");
#endif
    stream >> H >> W;
    for (int y = 1; y <= H; ++y) {
        for (int x = 1; x <= W; ++x) {
            stream >> a[y][x];
        }
    }

    vector<string> ans;
    for (int y = 1; y <= H; ++y) {
        for (int x = 1; x <= W; ++x) {
            if (y == H && x == W) continue;

            if (a[y][x] % 2 == 1) {
                a[y][x]--;

                stringstream ss;
                // move right or down if odd
                if (x < W) {
                    a[y][x + 1]++;
                    ss << y << " " << x << " " << y << " " << (x + 1);
                }
                else {
                    a[y + 1][x]++;
                    ss << y << " " << x << " " << (y + 1) << " " << x;
                }

                ans.push_back(ss.str());
            }
        }
    }

    cout << ans.size() << endl;
    for (auto s : ans) cout << s << endl;
#ifdef DEBUG
    cout << "debug" << endl;
    for (int y = 1; y <= H; ++y) {
        for (int x = 1; x <= W; ++x) {
            cout << a[y][x] << " ";
        }
        cout << endl;
    }
#endif
    return 0;
}

Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
int d[100009];
int main()
{
	string s;
	cin>>s;
	int an=0;
	stack<char>st;
	for(char i:s)
	{
		if(st.empty())st.push(i);
		else if(st.top()==i)st.push(i);
		else {st.pop();an+=2;}
	
	}
	cout<<an<<endl;
}



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

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

    ll cnt_AB = N/(A+B);
    ll cnt_C = N-cnt_AB*(A+B);
    ll cnt_B = cnt_AB*A + (cnt_C<A ? cnt_C : A);

    cout << cnt_B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

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

    for(ll h=1;h<=3500;h++){
        for(ll n=1;n<=3500;n++){
            if((4*h*n-N*(h+n))==0) continue;
            if(N*h*n%(4*h*n-N*(h+n))==0 && N*h*n/(4*h*n-N*(h+n))>0){
                cout << h << " " <<  n << " " << N*h*n/(4*h*n-N*(h+n)) << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n==0) return 0;
    vector<LL> s(n),d(m);
    for(int i=0;i<n;i++) cin >> s[i];
    for(int i=0;i<m;i++) cin >> d[i];
    sort(d.begin(),d.end());
    vector<pair<LL,LL>> dp(1<<n,{INF,INF});
    dp[0]={0,0};
    LL sum,cost;
    for(int i=1;i<(1<<n);i++){
      for(int j=0;j<n;j++){
        if(i&(1<<j)){
          cost=dp[i-(1<<j)].first;
          sum=dp[i-(1<<j)].second;
          auto l=lower_bound(d.begin(),d.end(),sum);
          auto r=lower_bound(d.begin(),d.end(),sum+s[j]);
          for(auto itr=l;itr!=r;itr++){
            cost+=min((*itr)-sum,sum+s[j]-(*itr));
          }
          sum+=s[j];
          if(dp[i].first>cost){
            dp[i]={cost,sum};
          }
        }
      }
    }
    LL ans=dp[(1<<n)-1].first;
    for(auto itr=lower_bound(d.begin(),d.end(),dp[(1<<n)-1].second);itr!=d.end();itr++){
      ans+=(*itr)-dp[(1<<n)-1].second;
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3612