akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int Rooms[4][3][10];

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int b, f, r, v;

		cin >> b >> f >> r >> v;

		b--, f--, r--;
		Rooms[b][f][r] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " " << Rooms[i][j][k];
			}
			cout << endl;
		}
		if (i < 3) {
			for (int l = 0; l < 20; l++)cout << "#";
			cout << endl;
		}
	}

	return 0;
}

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

vector<int> f(vector<int>& a) {
  int n = a.size();
  vector<int> res(n);
  rep(i,n) res[i] = a[i]^a[(i+1)%n];
  return res;
}

// Morris-Pratt
template<typename T>
struct MP {
  int n;
  T t;
  vector<int> a;
  MP() {}
  MP(const T& t): t(t) {
    n = t.size();
    a = vector<int>(n+1);
    a[0] = -1;
    int j = -1;
    for (int i = 0; i < n; ++i) {
      while (j != -1 && t[j] != t[i]) j = a[j];
      j++;
      a[i+1] = j;
    }
  }
  int operator[](int i) { return a[i];}
  vector<int> findAll(const T& s) {
    vector<int> res;
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      while (j != -1 && t[j] != s[i]) j = a[j];
      j++;
      if (j == n) {
        res.push_back(i-j+1);
        j = a[j];
      }
    }
    return res;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  vector<int> xa = f(a);
  vector<int> xb = f(b);
  MP<vector<int>> mp(xa);
  xb.insert(xb.end(), xb.begin(), xb.end());
  vector<int> res = mp.findAll(xb);
  vector<int> ks;
  for (int p : res) ks.push_back(n-p);
  sort(ks.begin(), ks.end());
  for (int k : ks) {
    if (k >= n) continue;
    int x = a[k]^b[0];
    printf("%d %d\n", k, x);
  }
  return 0;
}

Measured memory_bytes: 11504
#include<iostream>
#include<cstdio>
#define M 200010
using namespace std;
int n,top;
int L[M],R[M],a[M],st[M];
long long ans;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	top=0;st[0]=0;
	for(int i=1;i<=n;i++) {
		while(top&&a[st[top]]>a[i]) top--;
		L[i]=st[top]+1;st[++top]=i;
	}
	top=0;st[0]=n+1;
	for(int i=n;i>=1;i--) {
		while(top&&a[st[top]]>a[i]) top--;
		R[i]=st[top]-1;st[++top]=i;
	}
	for(int i=1;i<=n;i++) 
		ans+=1ll*(R[i]-i+1)*(i-L[i]+1)*a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll lcd(ll a, ll b) {
	ll c = gcd(a, b);
	return a / c * b;
}
int main() {
	ll N; cin >> N;

	ll ans = 1;
	ll T[101];
	T[0] = 1;
	repe(i, 1, N) {
		cin >> T[i];
		ans = lcd(T[i], ans);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    int sum = 0;
    rep(i, 1, N + 1) cin >> A.at(i);
    rep(i, 0, N + 1) sum += abs(A.at(i + 1) - A.at(i));
    rep(i, 1, N + 1){
        int x = A.at(i - 1);
        int y = A.at(i);
        int z = A.at(i + 1);
        if ((x - y)*(y - z) >= 0){
            cout << sum << endl;
        }
        else{
            cout << sum - 2 * min(abs(x - y), abs(y - z)) << endl;
        }
    }
}


Measured memory_bytes: 1664
X,Y = map(int,input().split())
M = X+Y
mod = 10**9 + 7
kaijou = [1]
for i in range(1,10**6+1):
    kaijou.append((kaijou[-1]*i)%mod)


def C(n,k):
    return (kaijou[n]*pow(kaijou[k],mod-2,mod)*pow(kaijou[n-k],mod-2,mod))%mod

    

if M%3!=0:
    print(0)
elif X<M//3 or Y<M//3:
    print(0)
else:
    print(C(M//3, X-M//3))

Measured memory_bytes: 93888
a = int(input())
b = int(input())
c = int(input())
x = int(input())
n = 0
ans = 0
for i in range(b+1):
  for j in range(c+1):
    n = x - 100*i - 50*j 
    if n % 500 == 0 and 0 <= n//500 <= a:
      ans += 1
print(ans)

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

int main(void) {
    bool c = false, f = false;
    string s;
    cin >> s;
    for (auto item : s) {
        if (item == 'C')
            c = true;
        if (item == 'F' && c)
            f = true;
    }
    cout << (c && f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<stdlib.h>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>

#define INF 99999999

using namespace std;

int main(){
	int n;

	cin >> n;
	do{
		int point[110];
		int sum = 0;

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

		sort(point, point+n);

		for (int i = 1;i < n - 1;i++){
			sum += point[i];
		}

		cout << sum / (n - 2) << endl;

		cin >> n;
	} while (n != 0);
	


	return 0;
}

Measured memory_bytes: 1176
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int cnt[4], fact[] = {1, 1, 2, 6};

vector <int> vec;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	string s;
	bool ans = 0;
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		if ((i & (n - 1)) == i)
			ans = (ans + s[i] - 48) % 2;
	}
	for (int i = 1; i < n; ++i) {
		int q = s[i - 1] - 48, w = s[i] - 48;
		++cnt[abs(q - w)];
		vec.push_back(abs(q - w));
	}
	if (!cnt[1]) {
		int sum = 0;
		for (int i = 0; i < n - 1; ++i) {
			int q = i, w = n - 2, p = 1;
			while (q) {
				if ((w % 4) < (q % 4))
					p = 0;
				else
					p *= (fact[w % 4] / fact[q % 4] / fact[(w % 4) - (q % 4)]) % 4;
				q /= 4;
				w /= 4;
			}
			sum += p * vec[i];
			sum %= 4;
		}
		cout << sum << '\n';
	}
	else
		cout << ans << '\n';
}


Measured memory_bytes: 8344
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    h+=max(a[i]-(mid//f[i]),0)
  if h<=k:ok=mid
  else:ng=mid
print(ok)

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int x, y;
    cin >> x >> y;
    cout << x * y << endl;

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




Measured memory_bytes: 3108
#include<cstdio>
int max(int a,int b) {return a>b?a:b;}
int min(int a,int b) {return a<b?a:b;}
int main()
{
	int x1=0,x2,y1=0,y2,n;
	scanf("%d%d%d",&x2,&y2,&n);
	while(n--)
	{
		int x,y,a;
		scanf("%d%d%d",&x,&y,&a);
		switch(a)
		{
			case 1:x1=max(x,x1);break;
			case 2:x2=min(x,x2);break;
			case 3:y1=max(y,y1);break;
			case 4:y2=min(y,y2);break;
		}
	}
	int ans;
	if(x1>=x2||y1>=y2) ans=0;
	else ans=(x2-x1)*(y2-y1);
	printf("%d\n",ans);
	return 0;
}

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

int ans, n, val[25], cost[25];

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

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

	ans = 0;
	for(int i = 0; i < n; i++){
		if(val[i]-cost[i] > 0) ans += val[i]-cost[i];
	}

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

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;
const ld INF = 1e18;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        ld a,b;
        cin>>a>>b;
        ld ans = floor(a*b);
        int fans = ans;
        cout<<fans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;


/*
  let's try computer shogi!!!
 */

int main(){

  int N, M, K;
  cin >> N >> M >> K;
  for(int i=0;i<=N;++i){
    for(int j=0;j<=M;++j){
      int ans = i*(M-j) + (N-i)*j;
      if(ans == K){
	cerr << i<<","<<j<<endl;
	cout<<"Yes"<<endl;
	return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

struct Edge {
  int cost;
  int to;
  Edge(){}
  Edge(int c, int t) : cost(c), to(t) {}
};

ll INF = 1e15;
int n, m, s, t;
vv<Edge> ga, gb;

typedef pair<ll, int> pli; // cost, node
vll dijkstra(int s, vv<Edge> & g) {
  vll d(n, INF);
  priority_queue<pli, vector<pli>, greater<pli> > q;

  d[s] = 0;
  q.push(make_pair(0, s));

  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto e : g[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }
  return d;
}


int main() {
  scanf("%d %d %d %d", &n, &m, &s, &t);
  s -= 1; t -= 1;
  ga.resize(n);
  gb.resize(n);
  rep (i, m) {
    int u, v, a, b;
    scanf("%d %d %d %d", &u, &v, &a, &b);
    u -= 1;
    v -= 1;
    ga[u].push_back(Edge(a, v));
    ga[v].push_back(Edge(a, u));
    gb[u].push_back(Edge(b, v));
    gb[v].push_back(Edge(b, u));
  }

  vll costa = dijkstra(s, ga);
  vll costb = dijkstra(t, gb);

  vll opt(n);
  opt[n-1] = costa[n-1] + costb[n-1];
  for (int i = n-2; i >= 0; --i) {
    opt[i] = min(costa[i] + costb[i], opt[i+1]);
  }
  ll money = 1e15;
  rep (i, n) {
    printf("%lld\n", money - opt[i]);
  }

  return 0;
}


Measured memory_bytes: 16124
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX


int a,b,n;
int f1(int x)
{
    return (a*x)/b - a*(x/b);
}

 
void solve()
{
    cin >> a >> b >> n;
    int l  = 0, r = min(b-1,n);
    cout << f1(r) << endl;
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

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

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

    if ((a + b) % 2 != 0) {
        cout << "IMPOSSIBLE";
        return 0;
    }

    int m = (a + b) / 2;
    cout << m;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int n = a*b;
    int m = c*d;
    if(n == m){
      System.out.println(n);
    }else if(n > m){
      System.out.println(n);
    }else{
      System.out.println(m);
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, a, b; cin >> x >> a >> b;
    char res = 'B';
    if(abs(a - x) < abs(b - x)){
        res = 'A';
    }

    cout << res << endl;

    return 0;
}


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

using namespace std;

int x[100010],ans = 1e9 + 10;

int main()
{
    int n,k,l,r;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
        scanf("%d",&x[i]);
    for(int i = 1; i <= n-k+1; i ++)
    {
        l = i,r = i+k-1;
        if(x[l] <= 0 && x[r] <= 0)
        {
            ans=min(ans,abs(x[l]));
        }
        else if(x[l] <= 0&&x[r] >= 0)
        {
            ans=min(ans,-2 * x[l] + x[r]);
            ans=min(ans,-x[l] + 2 * x[r]);
        }
        else ans=min(ans,abs(x[r]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import math
a, b = input().split()
a = int(a)
b = int(b.replace(".", ""))
ans = 0
for i in range(4):
    a_sub = a//(10**(4*i))%(10**4)
    # print(a_sub, b, a_sub*b*(10**(4*i))//100)
    ans += a_sub*b*(10**(4*i))//100

print(ans)


Measured memory_bytes: 9112
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String[] list = sc.next().split("");
    
    for(int i = 0; i < Math.pow(2, list.length - 1); i++) {
      int total = Integer.parseInt(list[0]);
      StringBuilder answer = new StringBuilder(list[0]);
      for(int j = 0; j < list.length - 1; j++) {
        
        if((1&i>>j) == 1) {
          total += Integer.parseInt(list[j + 1]);
          answer.append("+").append(list[j + 1]);
        } else {
          total -= Integer.parseInt(list[j + 1]);
          answer.append("-").append(list[j + 1]);
        }
      }
      if(total == 7) {
        System.out.println(answer.append("=7").toString());
        break;
      }
    }  
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,k;
    cin >> n >> k;
    vi p(n);
    rep(i,n) cin >> p.at(i);
    int64_t sum = 0;
    vector<pair<int64_t,int>> sums(n);
    for(int64_t i=0; i<n-k+1; i++){
        if(i==0){
            for(int j=0; j<k; j++){
                sum += p.at(j);
            }
        }else{
            sum += p.at(i+k-1);
            sum -= p.at(i-1);
        }
        sums.push_back(make_pair(sum, i));
    }
    sort(sums.begin(), sums.end(), greater<>());
    int index = sums.at(0).second;
    double res = 0.0;
    for(int i = index; i<index+k; i++){
        int64_t s = 0;
        for(int j=1; j<=p.at(i); j++){
            s += j;
        }
        res += (double)s/p.at(i);
    }
    cout << setprecision(8) << res << endl;
}


Measured memory_bytes: 10112
#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() {
  double T, X;
  cin >> T >> X;
  double ans = T / X;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 3700
a = input().split()
tg = a[0]
ok_nums = set(str(i) for i in range(10))
ng_nums = set(i for i in input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
intg = int(tg)
while intg > rt:
  if ok_nums >= set(d for d in str(i)):
    rt = i
  else:
    i+=1

print(rt)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    vector<ll> a(N) , b(N);
    REP(i,N) cin >> a[i] >> b[i];
    ll ans = 0;
    RREP(i,N-1) {
        ll x = a[i] + ans;
        if (x % b[i] != 0) ans += (b[i] - x % b[i]);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

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

	char N;
	int i,j;
	int tmp;
	int answer=0;
	int counter=0;
	vector<int> given;

	cin >> N;

	
	if('a'<=N && N<='z')
		cout << "a" << endl;
	else
		cout << "A" << endl;

	return 0;
}



Measured memory_bytes: 3636
#include<iostream>

using namespace std;


int main() {
	int N; cin >> N;
	int i, a, b, sum = 0;
	for (i = N; i < 1000; i++) {
		if (i % 10 == (i % 100 - i % 10) / 10 && i % 10 == (i - i % 100) / 100) {
			break;
		}
	}

	cout << i << endl;

	return 0;
}

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

int main()
{
	int x, a, b;
	cin >> x >> a >> b;

	if (b - a <= 0) {
		cout << "delicious" << endl;
	}
	else if(b - a > x){
		cout << "dangerous" << endl;
	}
	else{
		cout << "safe" << endl;
	}
	return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long X){
    cout << (X >= 30 ? "Yes" : "No") << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3656
#include <map>
#include <queue>
#include <vector>
#include <iostream>

using namespace std;

const vector<int> p2 = { 1, 2, 3, 15, 16, 30, 29, 28 };
const vector<int> p4 = { 7, 8, 9, 13, 18, 24, 23, 22 };
const vector<int> p5 = { 1, 4, 7, 10, 21, 30, 27, 24 };
const vector<int> p7 = { 3, 6, 9, 12, 19, 28, 25, 22 };

const vector<int> last = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 6, 6, 6, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

bool ok(vector<int> v)
{
	return v == last;
}

int solve(vector<int> v)
{
	map<vector<int>, int> d; d[v] = 1;

	queue<vector<int> > que; que.push(v);

	if (ok(v)) { return 0; }

	while (!que.empty())
	{
		vector<int> v1 = que.front(); que.pop();

		vector<int> v2, v4, v5, v7;

		v2 = v1; v4 = v1; v5 = v1; v7 = v1;

		for (int i = 0; i < 8; i++) { v2[p2[i] - 1] = v1[p2[7 - i] - 1]; } v2[18] = v1[20]; v2[20] = v1[18];
		for (int i = 0; i < 8; i++) { v4[p4[i] - 1] = v1[p4[7 - i] - 1]; } v4[9] = v1[11]; v4[11] = v1[9];
		for (int i = 0; i < 8; i++) { v5[p5[i] - 1] = v1[p5[7 - i] - 1]; } v5[15] = v1[17]; v5[17] = v1[15];
		for (int i = 0; i < 8; i++) { v7[p7[i] - 1] = v1[p7[7 - i] - 1]; } v7[12] = v1[14]; v7[14] = v1[12];

		if (ok(v2)) { return d[v1]; }
		if (ok(v4)) { return d[v1]; }
		if (ok(v5)) { return d[v1]; }
		if (ok(v7)) { return d[v1]; }

		if (d[v2] == 0) { d[v2] = d[v1] + 1; que.push(v2); }
		if (d[v4] == 0) { d[v4] = d[v1] + 1; que.push(v4); }
		if (d[v5] == 0) { d[v5] = d[v1] + 1; que.push(v5); }
		if (d[v7] == 0) { d[v7] = d[v1] + 1; que.push(v7); }
	}

	return -1;
}

int main()
{
	vector<int> v(30);

	int n; cin >> n;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 30; j++)
		{
			cin >> v[j];
		}

		cout << solve(v) << endl;
	}

	return 0;
}

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

// study

int main(){
    int n, x[16][16], y[16][16], a[16];
    cin >> n;
    rep(i, n){
        cin >> a[i+1];
        rep(j, a[i+1]){
            cin >> x[i+1][j+1];
            cin >> y[i+1][j+1];
            x[i+1][j+1] --; 
        }
    }

    int ans = 0;
    for (int bit = 1; bit < (1<<n); bit++) {
        bool flag = true;
        for (int i = 1; i <= n; i++){
            if (!(bit & (1 << (i - 1)))) continue;
            for (int j = 1; j <= a[i]; j++){
//              if((bit & (1 << x[i][j])) ^ y[i][j]) flag = false;
                if(((bit >> x[i][j]) & 1) ^ y[i][j]) flag = false;
            }
        }
        if(flag) ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

map<ll,ll> cnt;

int n;

int main(){
	cin >> n;
	rep(i,n){
		ll a;
		cin >> a;
		cnt[a]++;
	}
	ll ans = 1;
	int f = 0;
	for(map<ll,ll>::iterator it = cnt.end();it != cnt.begin();it--){
		if(it == cnt.end())continue;
		ll s = it->second;
		if(f == 0){
			if(s >= 4){
				ans = it->first * it->first;
				f = 2;
				break;
			}
			else if(s >= 2){
				ans *= it->first;
				f = 1;
			}
		}
		else if(f == 1){
			if(s >= 2){
				ans *= it->first;
				f = 2;
				break;
			}
		}
	}
	if(cnt.begin()->second >= 4){
		if(f == 0){
			ans = cnt.begin()->first * cnt.begin()->first;
			f = 2;
		}
		else if(f == 1){
			ans *= cnt.begin()->first;
			f = 2;
		}
	}
	else if(cnt.begin()->second >= 2){
		if(f == 1){
			ans *= cnt.begin()->first;
			f = 2;
		}
	}
	if(f == 2)cout << ans << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 6528
#include <iostream>
using namespace std;
 
int main(){
  int N, Y;
  cin >> N >> Y;
  int i, j, k;
  int check = 0;
  for (i=0; i<=N; i++){
    for (j=0; j<=N-i; j++){
      k = N-i-j;
      if (10000*i+5000*j+1000*k==Y){
        cout << i << ' ' << j << ' ' << k << endl;
        check = 1;
        break;
      }
    }
    if (check == 1) {
      break;
    }
  }
  if (check ==0){
    cout << "-1 -1 -1" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
using namespace std;

int main() {
    FIO;
    int k, n; cin >> k >> n;
    vi v(n);
    FOR(i,0,n-1) cin >> v[i];
    int Max = 0;
    FOR(i,1,n-1) Max = max(Max, v[i] - v[i-1]);
    Max = max(Max, v[0] + k - v[n-1]);
    cout << k - Max << '\n';
    return 0;
}

Measured memory_bytes: 1024
let rec input n =
		if n = 0
		then []
		else match List.map(fun x -> int_of_string x)(Str.split (Str.regexp " ") (read_line ())) with
		| x::y::xs -> (x,y) :: input (n-1)
		| x::xs -> (x,1) :: input (n-1)
		| [] -> (1,1) :: input n

let solve lst =
	let rec solve_loop before lst = match lst with
		| [] -> let(a,b) = before in a + b
		| first :: xs ->
			let (x,y) = first in
			let (a,b) = before in
			let ratio = max ((a-1)/x+1) ((b-1)/y+1) in
				solve_loop (x*ratio,y*ratio) xs
	in
		solve_loop (1,1) lst
	
let main =
	print_string (string_of_int (solve (input (int_of_string (read_line ())))))

let () = main

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

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

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

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

int N;
ll A[200005];
ll B[200005];
ll C[200005];
ll D[35];

//! under以上になる最小のindex
int getUnder(ll under)
{
    if (under <= 0)
        return 0;
    int ok = N, ng = -1;
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if (C[mid] >= under)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    return ok;
}
//! top未満になる最大のindex
int getTop(ll top)
{
    int ok = -1, ng = N;
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if (C[mid] < top)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    return ok;
}

int main()
{
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, N)
    {
        cin >> B[i];
    }
    ll ans = 0;
    REP(i, 29)
    {
        D[i] = 0;
        ll u = pow((ll)2, i);
        ll t = pow((ll)2, (i + 1));
        REP(j, N)
        {
            C[j] = (B[j] % t);
        }
        sort(C, C + N);
        REP(j, N)
        {
            ll a = A[j] % t;
            {
                int ui = getUnder(u - a);
                int ti = getTop(t - a);
                if (ui <= ti)
                {
                    D[i] += (ti - ui + 1);
                }
            }
            {
                int ui = getUnder(u + t - a);
                int ti = getTop(2 * t - a);
                if (ui <= ti)
                {
                    D[i] += (ti - ui + 1);
                }
            }
        }
        ans |= ((D[i] % 2) << i);
    }

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

Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

// 素因数分解
map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) {
        res[n] = 1;
    }
    return res;
}

int main(){
  ll N; cin >> N;
  map<ll,ll> p;
  p = prime_factor(N);

  cout << N << ":";
  for(auto a : p){
    rep(i,a.second){
      cout << " " << a.first;
    }
  }
  cout << endl;
}



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

#define int long long

//次数の問題でしょ。

main()
{
  int N, M;
  int cnt[100005] = {};
  string S[2] = {"NO", "YES"};
  
  cin >> N >> M;

  while(M--) {
    int A, B;

    cin >> A >> B; --A, --B;

    cnt[A]++, cnt[B]++;
  }


  bool flag = true;
  for(int i = 0; i < N; i++) {
    if(cnt[i] & 1) flag = false;
  }

  cout << S[flag] << endl;

  return 0;
}


Measured memory_bytes: 1024
Q,H,S,D = map(int,input().split())
N=int(input())
A=[]

A.append(4*Q)
A.append(2*H)
A.append(S)
A.append(D/2)

if min(A)==A[0]:
  print(N*A[0])
elif min(A)==A[1]:
  print(N*A[1])
elif min(A)==A[2]:
  print(N*A[2])
else:
  a = N//2
  p = a*D
  if a*2!=N:
    if A[0]<=A[1] and A[0]<=A[2]:
      p += A[0]
    elif A[1]<=A[2] and A[1]<=A[0]:
      p += A[1]
    else:
      p += A[2]
  print(p)

Measured memory_bytes: 3064
#include <iostream>
#include <list>
#include <algorithm>
#define INF 10e6
#define F first
#define S second
using namespace std;

typedef pair<int,int> P;

int main(void){
	P dolls[200];
	P dolls1[200];
	int dp[200];
	int dp1[200];
	int n,m;
	while(cin >> n,n){
		for(int i=0;i<n;i++)
			cin >> dolls[i].F >> dolls[i].S;
		cin >> m;
		for(int i=n;i<n+m;i++)
			cin >> dolls[i].F >> dolls[i].S;
		for(int i=0;i<n+m;i++)
			dolls1[i].F=dolls[i].S,dolls1[i].S=dolls[i].F;
		sort(dolls,dolls+n+m);
		sort(dolls1,dolls1+n+m);
		int cx,cy,ccx=0,ccy=0;
		fill(dp,dp+n+m,INF);
		fill(dp1,dp1+n+m,INF);
		for(int i=0;i<n+m;i++){
			if(dolls[i].F>ccx)
			*lower_bound(dp,dp+n+m,dolls[i].S)=dolls[i].S,ccx=dolls[i].F;
			if(dolls1[i].F>ccy)
			*lower_bound(dp1,dp1+n+m,dolls1[i].S)=dolls1[i].S,ccy=dolls1[i].F;
		}
		cx=lower_bound(dp,dp+n+m,INF)-dp;
		cy=lower_bound(dp1,dp1+n+m,INF)-dp1;
		cout << max(cx,cy) << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int a = sc.nextInt();
		int ans = h % a == 0 ? h / a : h / a + 1;
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <functional>
#include <map>
#include <queue>
#include <tuple>
#include <string.h>

using namespace std;

#define For(i,a,b) for(int i = a;i < b;i++)
#define rep(i,n) For(i,0,n)
#define clr(n) memset(n,0,sizeof(n))

const int dx[6] = { 0, -1, -1, 0, 1, 1 }, dy[6] = { 1, 0, -1, -1, 0, 1 };
bool cheak(int x, int y, int mx, int my){ return x >= 0 && y >= 0 && x < mx && y < my; }
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int main(){

	int t, n;

	while (cin >> t >> n && t){
		const int M = 100;
		bool d[M * 3][M * 3]; clr(d);
		bool f[M * 3][M * 3]; clr(f);
		rep(i, n){
			int x, y;
			cin >> x >> y;
			d[y + M][x + M] = true;
		}
		int sx,sy;
		cin >> sx >> sy;
		sx += M, sy += M;
		queue<T> q;
		q.push(T(sy, sx, 0));
		f[sy][sx] = true;
		while (q.size()){
			T nx = q.front(); q.pop();
			rep(i, 6){
				int ty = get<0>(nx) + dy[i], tx = get<1>(nx) + dx[i];
				if (!d[ty][tx] && !f[ty][tx] && get<2>(nx) < t){
					f[ty][tx] = true;
					q.push(T(ty, tx, get<2>(nx)+1));
				}
			}
		}
		int ans = 0;
		rep(i, M * 3)rep(j, M * 3){
			if (f[i][j])ans++;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1396
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

const int cap = 22;
const int max_width = 1 << 21;
const int mod = 1e9 + 7;
int N;
int A[cap][cap];
int P[cap];
int cnt[max_width];
vector<int> G[cap];
int dp[cap][max_width];

int dfs(int i, int j) {
    if (dp[i][j] == -1) {
        dp[i][j] = 0;
        if (cnt[j] == i && (P[i] & j) != 0)
            for (int b : G[i]) {
                if (j & b)
                    dp[i][j] = (dp[i][j] + dfs(i - 1, j - b)) % mod;
            }
    }
    return dp[i][j];
}

int main() {
    scanf("%d", &N);
    int width = 1 << N;
    fill(P, P + N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        G[i].clear();
        for (int j = 1; j <= N; ++j) {
            scanf(" %d", &A[i][j]);
            if (A[i][j] == 1) {
                G[i].push_back(1 << (j - 1));
                P[i] |= G[i].back();
            }
        }
    }
    fill(&dp[0][0], &dp[0][0] + max_width, 1);
    fill(&dp[0][0] + max_width, &dp[0][0] + cap * max_width, -1);
    fill(cnt, cnt + width, 0);
    for (int i = 1; i < width; ++i) {
        for (int j = i; j > 0; j >>= 1)
            cnt[i] += j & 1;
    }

    printf("%d\n", dfs(N, width - 1));
}











Measured memory_bytes: 188672
#include<cstdio>
#include<cstring>
const long long mod = 1e9+7;
long long f[2000005], invf[2000005];
long long p25[2000005], p26[2000005];
char s[1000005];

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

long long inv(long long u){ return power(u,mod-2); } 

void preWork(int n){
    f[0] = invf[0] = 1;
    p25[0] = p26[0] = 1;
    for(long long i = 1; i <= n; i++){
        p25[i] = p25[i-1]*25ll%mod;
        p26[i] = p26[i-1]*26ll%mod;
        f[i] = f[i-1]*i%mod;
        invf[i] = inv(f[i]);
    }
}

long long getC(int n,int m){
    if(m>n || m<0) return 0;
    else{
        long long res = f[n];
        res = res*invf[n-m]%mod;
        res = res*invf[m]%mod;
        return res;
    }
}

int main(){
    preWork(2000001);
    int k;
    scanf("%d%s",&k,s+1);
    int n = strlen(s+1);
    long long ans = 0;
    for(int i = n; i <= n+k; i++){
        long long cur = p25[i-n]*p26[n+k-i]%mod;
        cur = cur*getC(i-1,n-1)%mod;
        ans = (ans+cur)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 65152
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b){
	if(a<b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b){
	if(a>b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) {return std::vector<T>(len, elem);}
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i] <<std:: endl;
		else std::cout << da[i] << ' ';
	}
}
template<typename T>
void vvdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
}

using namespace std;

int main(){
	int n;cin >> n;
	vector<int> da(n);
	rip(i,n,0) cin >> da[i];
	ll su = 0, ans = 0, now = 0;
	rip(i,n,0) su += da[i];
	ans = LLONG_MAX;
	rip(i,n-1,0){
		now += da[i];
		chmin(ans, abs(su - now*2));
	}	
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
    string S;

  	int cnt=0;
  	bool sum=true;
    cin >> S;
    string pre[4]={"dream", "dreamer", "erase", "eraser" };
    int num=S.size();
    reverse( S.begin(), S.end() );
    for(int i=0;i<4;i++){
      reverse( pre[i].begin(), pre[i].end() );
    }
    
    for(int i=0;i < num;){
bool flag =false;
      for(int j=0;j<4;++j){
        string d = pre[j];
        if (S.substr(i, d.size()) == d){
          flag =true;
          i+=pre[j].size();
        }
      }
      if(!flag){
        sum=false;
        break;
      }
    }

    if(sum) cout << "YES" << endl;
    else cout <<"NO"<< endl;
}

Measured memory_bytes: 3764
x = gets.chomp.to_i
if x == 1
  puts 1
else
k = 2
l = 1
array = []
while k*k <= x do
  while k**l <=x do
    array << k**l
    l += 1
  end
  k += 1
  l = 1

end
puts array.max
end


Measured memory_bytes: 1788
#AGC023-B Find Symmetries
"""
各300*300の場所について、シフト数は300*300通り存在する。
実は、縦方向へのシフトをA,横方向へのシフトをBとした時、
A=Bとなるような状態では結果は等しくなる。
よって、縦方向もしくは横方向どちらかのみ動かせばよく、その時の判定にはN^2かかるので、
合計O(N^3)で求まった。
答えは、片方のシフトで求まった個数*nとなる(もう片方のシフトもn通りあるので)
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(readline().rstrip().decode('utf-8'))

def judge(k):
    for i in range(n):
        for j in range(n):
            if lst1[(i+k)%n][j] != lst1[(j+k)%n][i]:
                return 0
    
    return 1

ans = 0
for i in range(n):
    ans += judge(i)

print(ans*n)

Measured memory_bytes: 73848
#include<iostream>
#include<string>

using namespace std;

int main() {
	int ar[20];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}
	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if ((ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) || (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2]))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
int yakusu[101];
bool isprime[101];

int is_prime(int n) {
    for(int i = 2; i * i <= n; ++i)
        if(n % i == 0)
            return false;
    return n != 1;
}

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 1; i <= N; ++i)
        isprime[i] = is_prime(i);

    for(int i = 2; i <= N; ++i) {
        int num = i;
        for(int j = 2; j <= N; ++j)
            if(isprime[j])
                while(num % j == 0) {
                    yakusu[j]++;
                    num /= j;
                }
    }

    llong res = 0;
    for(int p = 2; p <= N; ++p)
        for(int q = p + 1; q <= N; ++q)
            for(int r = 2; r <= N; ++r) {
                if(r == p || r == q) continue;
                if(!isprime[p] || !isprime[q] || !isprime[r]) continue;

                if(yakusu[p] >= 4 && yakusu[q] >= 4 && yakusu[r] >= 2)
                    ++res;
            }

    for(int p = 2; p <= N; ++p)
        for(int q = 2; q <= N; ++q) {
            if(p == q) continue;
            if(!isprime[p] || !isprime[q]) continue;

            if(yakusu[p] >= 14 && yakusu[q] >= 4) ++res;
            if(yakusu[p] >= 24 && yakusu[q] >= 2) ++res;
        }

    for(int p = 2; p <= N; ++p) {
            if(!isprime[p]) continue;

            if(yakusu[p] >= 74) ++res;
        }


    cout << res << endl;
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> trees(N);
  for (int i = 0; i < N; ++i) {
    cin >> trees[i];
  }
  sort(trees.begin(), trees.end());
  int ans = trees.back();
  for (int i = K - 1; i < N; ++i) {
    ans = min(ans, trees[i] - trees[i - K + 1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
    while(1){
      int n;
      cin >> n;
      if(n==0) break;
      int min=10000000000000; 
     int fee;
      for(int a=0;a<=n/200+1;a++){
	for(int b=0;b<=n/300+1;b++){
	  for(int c=0;c<=n/500+1;c++){
	    if(a*200+b*300+c*500==n){
	      fee=a*380+b*550+c*850;
	      if(a>=5) fee+=((a/5)*5*380)*0.8-((a/5)*5*380);
	      if(b>=4) fee+=((b/4)*4*550)*0.85-((b/4)*4*550);
	      if(c>=3) fee+=((c/3)*3*850)*0.88-((c/3)*3*850);
	      if (min>fee)  min=fee;
	    }
	  }
	}
      }	
      cout << min <<endl;
     } 
   return 0;
    }



Measured memory_bytes: 3080
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = 1<<18;

int n, m, dp[N];
VII prz[N];

class treePM
{
  public:
    int w[2*N], W[2*N];

    void init()
    {
      for (int i = 0; i < 2*N; ++i)
        w[i] = W[i] = 0;
    }

    void insert(int a, int b, int v)
    {
      _insert(a, b, v, 0, N-1, 1);
    }

    int query(int a, int b)
    {
      return _query(a, b, 0, N-1, 1, 0);
    }

    void _insert(int a, int b, int v, int beg, int end, int k)
    {
      if (b < beg || a > end)
        return;
      if (a <= beg && end <= b) {
        w[k] += v;
        W[k] += v;
        return;
      }
      _insert(a, b, v, beg, (beg+end)/2, 2*k);
      _insert(a, b, v, (beg+end)/2+1, end, 2*k+1);
      W[k] = w[k] + max(W[2*k], W[2*k+1]);
    }

    int _query(int a, int b, int beg, int end, int k, int war)
    {
      if (b < beg || a > end)
        return 0;
      if (a <= beg && end <= b)
        return war + W[k];
      return max(_query(a, b, beg, (beg+end)/2, 2*k, war+w[k]), _query(a, b, (beg+end)/2+1, end, 2*k+1, war+w[k]));
    }
} drz;

int max(int a, int b) {
  if (a > b)
    return a;
  return b;
}

signed main() {
  init_ios();
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r, a;
    cin >> l >> r >> a;
    prz[r].PB({l, a});
  }
  for (int i = 1; i <= n; ++i)
    sort(prz[i].begin(), prz[i].end());
  for (int i = 1; i <= n; ++i) {
    dp[i] = max(0, drz.query(1, i-1));
    drz.insert(i, i, dp[i]);
    for (const auto& el: prz[i])
      drz.insert(el.ST, i, el.ND);
  }
  cout<<max(0, drz.query(1, n))<<"\n";
}

Measured memory_bytes: 21376
#include <iostream>
#include <cmath>

using namespace std;

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

	bool ans = true;
	int tb = 0, xb = 0, yb = 0;
	for (int i = 0; i < N; i++) {
		int t, x, y;
		cin >> t >> x >> y;

		int d = abs(x - xb) + abs(y - yb);
		if (!((d - (t - tb)) % 2 == 0 && d <= t - tb))
			ans = false;

		tb = t; xb = x; yb = y;
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, K = list(map(int, input().split()))

def factors(i):
    ans = []
    for j in range(1, i + 1):
        if i % j == 0:
            ans.append(j)
    return ans

fA = factors(A)
fB = factors(B)

AB = [a for a in fA if a in fB]
# print(A, fA)
# print(B, fB)
# print(AB)
print(AB[::-1][K - 1])

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

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
const long double eps = 1e-5;
typedef long long llint;

namespace Main {
    int n, a[200];
    void run() {
        cin >> n;
        n += n;
        REP (i, n) {
            cin >> a[i];
        }

        sort(a, a + n);
        reverse(a, a + n);
        int ans = 0;
        for (int i = 1; i < n; i += 2) {
            ans += a[i];
        }

        cout << ans << "\n";
    }
}

int main() {
#ifdef LOCAL_JUDGE
    freopen("main.in", "r", stdin);
#endif
    Main::run();
    fclose(stdin);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], ans, q;
int pref[N];

int32_t main(){_

   cin>>n>>q;
   string s;

   cin>>s;
   s = '#' + s;

   for (int i = 1; i <= n; ++i)
   {
      pref[i] = pref[i-1];
      if(s[i] == 'C' and s[i-1] == 'A')
         pref[i]++;
   }

   while(q--){
      int l, r;
      cin>>l>>r;
      if(l == r){
         cout<<0<<endl;
      }
      else if(r-l == 1){
         if(s[r] == 'C' and s[l] == 'A'){
            cout<<1<<endl;
         }
         else{
            cout<<0<<endl;
         }
      }
      else{
         cout<<pref[r]-pref[l]<<endl;
      }
   }


   #warning make sure N size is correct!
   return 0;
}

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

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

int main(){
	string S;
	cin >> S;
	int mn = 1e9;
	rep(i,(int)S.size()-2){
		string str = S.substr(i,3);
		int num = stoi(str);
		mn = min(mn, abs(num-753));
	}

	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256