akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = m; i >= l; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 1005;

int a[N], n, m, k, ans;

void Solve(){
    cin >> n;
    int mx = 0;
    Rp0(i, n) cin >> a[i], ans += a[i], mx = max(mx, a[i]);
    ans -= mx / 2;
    cout << ans;

}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<long long> a(n), b(n), c(n);
    long long d = 0; int count = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) { 
        c[i] = a[i] - b[i];
        if (c[i] < 0) d += -c[i], count++;
    }
    if (d == 0) {
        cout << 0 << endl;
        return 0;
    }
    sort(c.rbegin(), c.rend());
    for (int i = 0; i < n; i++) {
        if (c[i] <= 0) {
            cout << -1 << endl;
            return 0;
        }
        d -= c[i]; count++;
        if (d <= 0) {
            cout << count << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 2560
from collections import deque
c=deque([])
n=int(input())
for i in range(n):
    a=input()
    if "deleteFirst"in a:
        c.popleft()
    elif "deleteLast"in a:
        c.pop()
    else:
        a,b=a.split()
        if "insert"in a:
            c.appendleft(b)
        else:
            try:
                c.remove(b)
            except:
                continue

print(*c)


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

int N;int parent[100000];int size[100000];

struct Node{
  int from,to,weight;
  bool operator<(const Node &other) const{
    return weight < other.weight;
  }
};

int find(int id) {
  if (parent[id]==id) return id;
  else {
    return find(parent[id]);
  }
}

bool isSame(int a,int b) {
  return find(a)==find(b);
}

void unite(int a,int b) {
  int a_parent=find(a);int b_parent=find(b);
  if (a_parent==b_parent) return;
  else {
    if (size[a_parent]<size[b_parent]) {
      parent[a_parent]=b_parent;
      size[b_parent]+=size[a_parent];
    }
    else {
      parent[b_parent]=a_parent;
      size[a_parent]+=size[b_parent];
    }
  }
}

int main() {
  cin >> N;
  vector<vector<int>> A(N,vector<int>(2));vector<vector<int>> B(N,vector<int>(2));
  for (int i=0;i<N;i++) {
    cin >> A.at(i).at(0) >> B.at(i).at(0);
    A.at(i).at(1)=i;B.at(i).at(1)=i;
  }
  sort(A.begin(),A.end());sort(B.begin(),B.end());
  Node nodes[2*(N-1)];
  for (int i=0;i<N-1;i++) {
    nodes[i].from=A.at(i).at(1);nodes[i].to=A.at(i+1).at(1);
    nodes[i].weight=A.at(i+1).at(0)-A.at(i).at(0);
    nodes[i+N-1].from=B.at(i).at(1);nodes[i+N-1].to=B.at(i+1).at(1);
    nodes[i+N-1].weight=B.at(i+1).at(0)-B.at(i).at(0);
  }
  sort(nodes,nodes+2*N-2);
  for (int i=0;i<N;i++) {
    parent[i]=i;size[i]=1;
  }
  int sum=0;
  for (int i=0;i<2*(N-1);i++) {
    if (!isSame(nodes[i].from,nodes[i].to)) {
      sum+=nodes[i].weight;
      unite(nodes[i].from,nodes[i].to);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 14464
#include <stdio.h>
 int main(void){ 
   int i, n, count; 
   long min, max, sum;  
  max = -1000000;    
min = 1000000;   
 sum = 0;  
  scanf("%d", &count); 
   for (i = 0; i < count; i++){ 
       scanf("%d",&n);     
   if (max < n) max = n;  
      if (min > n) min = n; 
       sum += n; 
   }   
 printf("%ld %ld %ld\n",min,max,sum); 
   return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int k;
string s;
P p[10001];

string get_min(string a,string b){
	if(a=="")return b;
	for(int i=0;i<a.size();i++){
		if(a[i]<b[i])return a;
		if(a[i]>b[i])return b;
	}
	return a;
}

int main(void){
	scanf("%d%d",&n,&k);
	cin >> s;
	string ns="";
	ns=s;
	reverse(ns.begin(),ns.end());
	s+=ns;
	int mn=(s[0]-'a'),cnt=1,now=1;
	for(int i=1;i<s.size();i++){
		if((s[i]-'a')<mn){
			mn=(s[i]-'a');
			now=0;
		}
		if((s[i]-'a')==mn){
			now++;
		}
		if((s[i]-'a')>mn){
			now=0;
		}
		cnt=max(cnt,now);
		p[i]=P((s[i]-'a'),now);
	}
	int cnt_k1=cnt;
	for(int i=1;i<k;i++){
		if(cnt>=n)break;
		cnt*=2;
	}
	if(cnt>=n){
		string ans="";
		for(int i=0;i<n;i++){
			ans+=('a'+mn);
		}
		cout << ans << endl;
		return 0;
	}
	string ans="";
	for(int i=n-1;i<n*2;i++){
		if(p[i]!=P(mn,cnt_k1))continue;
		string tmp="";
		for(int j=0;j<cnt;j++){
			tmp+=s[i];
		}
		int pos=i-cnt_k1;
		while(tmp.size()<n){
			tmp+=s[pos];
			pos--;
		}
		ans=get_min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
n=int(input())

ans=[0]*(n+1)
r=int(n**0.5)+1

for x in range(1,r):
    for y in range(1,r):
        for z in range(1,r):
            t=x**2+y**2+z**2+x*y+y*z+z*x
            if t <= n:
                ans[t]+=1

for i in ans[1:]:
    print(i)


Measured memory_bytes: 9508
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

using namespace std;


ll a[100006];

int main() {
	ll x,y;
	cin >> x>>y;
	
	if (x%y == 0) {
		cout << -1 << endl;
	}
	else {
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

a.sort()

a_list = [0] * (a[-1]+1)
#print(a_list)
cnt = 0
tmp = 0

for i in range(a[-1]+1):
    #print(a[tmp])
    while a[tmp] == i:
        #print(i)
        cnt += 1
        tmp += 1
        if tmp == len(a):
            break
    a_list[i] = cnt
    cnt = 0

ans = 0

if len(a_list) == 1:
    print(a_list[-1])
    exit()

for i in range(0,a[-1]-1):
    ans = max(ans,a_list[i+2]+a_list[i+1]+a_list[i])
    
print(ans)

Measured memory_bytes: 13964
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort()
v.reverse()
ans=0
from collections import Counter
c=Counter()
k=0
tmp=0
for i in range(n):
    if i<a-1:
        ans+=v[i]
        c[v[i]]+=1
    elif i==a-1:
        tmp=v[i]
        c[v[i]]+=1
        ans+=v[i]
    else:
        if tmp!=v[i]:
            break
        else:
            c[v[i]]+=1
            k+=1
ans=ans/a
print(ans)
def f(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))
ans2=0

if ans==tmp:
    for i in range(c[tmp]-k,c[tmp]-k+b-a+1):
        ans2+=f(c[tmp],i)
    print(ans2)
else:
    print(f(c[tmp],k))




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

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int r,g,b; cin >> r >> g >> b;
	if ((10*g+b) % 4 == 0) cout << "YES";
	else cout << "NO";
}

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

int main(){
  int n, d;
  cin >> n >> d;
  std::vector<std::vector<int>> data(n, std::vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> data.at(i).at(j);
    }
  }

  std::vector<double> answer;
  for(int i = 0; i < n - 1; i++){
    for(int j = 1; j < n; j++){
      if(i >= j){
        continue;
      }
      double a = 0;
      for(int k = 0; k <= d; k++){
        if(k == d){
          a = sqrt(a);
          answer.push_back(a);
          continue;
        }
        a += pow(data.at(i).at(k) - data.at(j).at(k), 2.0);
      }
    }
  }

  int count = 0;
  for(auto y : answer){
    if(floor(y) == y){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,a,b,c,i,j,ori[101][101];
  
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++) ori[i][j]=0;
  }
  
  for(i=1;i<=n;i++){
    
    scanf("%d%d",&a,&b);
    
    for(j=1;j<=b;j++){
      scanf("%d",&c);
      ori[a][c]=1;
    }
    
  }

  for(i=1;i<=n;i++){
    
    for(j=1;j<=n;j++){
      if(j>1) printf(" ");
      printf("%d",ori[i][j]);
    }
    
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 2148
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 1000000007;
const ll cons = 100000;
const double pi = 3.141592653589793;



int main()
{
	int n, t;
	scanf("%d%d", &n, &t);

	vector < pair <int, int> > dat;
	int curProfit = 0;
	int minvl = INF;
	int indx = -1;

	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);

		if (x > minvl)
		{
			if (curProfit < x - minvl)
			{
				curProfit = x - minvl;
				dat.clear();
				dat.push_back(MP(indx, i));
			}
			else if (curProfit == x - minvl)
			{
				dat.push_back(MP(indx, i));
			}
		}
		else if (minvl > x)
		{
			minvl = x;
			indx = i;
		}
	}

	printf("%d\n", dat.size());

	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, K; cin >> N >> K;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(all(v));

	int ans = 0;
	for (int i = 0; i < K; i++) ans += v[i];
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3628
n = int(input())
a = [int(x) for x in input().split()]

plus = {}
minus = {}

for i in range(n):
    if str((i+1)+a[i]) not in plus:
        plus[str((i+1)+a[i])] = 1
    else:
        plus[str((i+1)+a[i])] += 1

    if str((i+1)-a[i]) not in minus:
        minus[str((i+1)-a[i])] = 1
    else:
        minus[str((i+1)-a[i])] += 1

total = 0
for key, value in plus.items():
    if key in minus:
        total += value * minus[key]

print(total)


Measured memory_bytes: 147792
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;

    int c = 1;
    for (auto e : a) {
        if (e == c) c++;
    }

    std::cout << (c == 1 ? -1 : n - c + 1) << std::endl;

    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N;
	cin >> N;
	int cost[300][300];
	fx(N) {
		fy(N) {
			if (x == y)cost[x][y] = 0;
			else cost[x][y] = INT_MAX / 2;
		}
	}
	set<pair<int, int> > K;
	fx(N) {
		string s;
		cin >> s;
		fy(N) {
			if (s[y]=='1') {
				cost[x][y] = 1;
				K.insert(make_pair(min(x,y),max(x,y)));
			}

		}
	}
	int maxi = 0, j = -1;
	fy(N) {
		fx(N) {
			fz(N) {
				cost[x][z] = min(cost[x][z], cost[x][y] + cost[y][z]);
			}
		}
	}

	fy(N) {
		fx(N) {
			fz(N) {
				if (cost[x][z] != INT_MAX / 2 && cost[x][z] > maxi) {
					maxi = cost[x][z];
					j = x;
				}
			}
		}
	}

	for (auto k : K) {
		if (abs(cost[j][k.first]-cost[j][k.second])!=1) {
			ce(-1);
			return 0;
		}
	}

	ce(maxi+1)
    return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

ll n;

void init(){
	cin>>n;
}

int main(void){
	init();
	cout<<3*n*n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  string s;
  cin >> s;
  ll n = s.size();

  string pre = "", now = "";
  ll ans = 0;
  for(ll i = 0; i < s.size(); i++){
    now += s[i];
    //cout << now << " " << pre << endl;
    if(pre != now){
      pre = now;
      now = "";
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll long long
#define MAX 100000

using namespace std;

int n;
long long a[200010];
int l,r;

int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n;
    l=1; r=n;

    ll ans = 2020202021;
    ll ji =0;
    ll al =0;

    lp(i,n) {
        cin>>a[i];
        al+=a[i];
    }
    lp(i,n - 1) {
        ji+=a[i];
        ans = min(ans, abs(ji-(al-ji)));
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1792
use proconio::input;

const M: usize = 300000;

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut st = SegTree::new(M, std::cmp::max);
    for _ in 0..n {
        input! {a: usize}
        let l = if a > k {a - k} else {0};
        let r = (a + k).min(M);
        let m = st.get(l, r + 1, None) + 1;
        st.set(a, m);
    }

    println!("{}", st.get(0, M + 1, None));
}


struct SegTree {
    tree: Vec<u64>,
    leaf_size: usize,
    op: fn(u64, u64) -> u64,
}

impl SegTree {
    fn new(n: usize, op: fn(u64, u64) -> u64) -> Self {
        let mut ls = 1;
        while ls < n {
            ls <<= 1;
        }
        Self {
            tree: vec![0; 2 * ls - 1],
            leaf_size: ls,
            op,
        }
    }

    fn set(&mut self, mut i: usize, v: u64) {
        i += self.leaf_size - 1;
        self.tree[i] = v;
        while i > 0 {
            i = (i - 1) / 2;
            self.tree[i] = (self.op)(self.tree[2 * i + 1], self.tree[2 * i + 2]);
        }
    }

    fn get(&self, s: usize, e: usize, rng: Option<(usize, usize, usize)>) -> u64 {
        let (i, l, r) = if let Some(rng) = rng { rng } else { (0, 0, self.leaf_size) };
        if l >= e || r <= s {
            0
        } else if l >= s && r <= e {
            self.tree[i]
        } else {
            let m = (l + r) / 2;
            let vl = self.get(s, e, Some((2 * i + 1, l, m)));
            let vr = self.get(s, e, Some((2 * i + 2, m, r)));
            (self.op)(vl, vr)
        }
    }
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

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

    int n;
    cin >> n;
    int c[n], s[n], f[n];
    rep(i, n-1){
        cin >> c[i] >> s[i] >> f[i];
    }
    rep(i, n){
        int t = 0;

        for(int j = i; j < n-1; ++j){
            if(t < s[j]){
                t = s[j];
            }
            else if(t % f[j] == 0){
                t = t;
            }
            else{
                t = t + f[j] - t%f[j];
            }
            t += c[j];

        }
        ppp(t);
    }










    return 0;
}


Measured memory_bytes: 256
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
    print("No")
else:
    print("Yes")
    k = 1000000
    R = [[0]*W for i in range(H)]
    for i in range(0, H, h):
        for j in range(0, W, w):
            R[i][j] += k
            if i+h-1 < H:
                R[i+h-1][j] += k
            if j+w-1 < W:
                R[i][j+w-1] += k
            if i+h-1 < H and j+w-1 < W:
                R[i+h-1][j+w-1] -= 3*k+1
    for r in R:
        print(*r)

Measured memory_bytes: 15192
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define rep(i, e) for ( int i = 0; i < (int)e; i++ )
#define MAX 50
#define MAXK 10
#define MAXL 7
#define INFTY (1<<21)

class Edge{
    public:
    int v, cost;
    Edge(){}
    Edge( int v, int cost): v(v), cost(cost){}
};

class State{
    public:
	int u, b, cost;
    State(){}
    State(int u, int b, int cost):u(u), b(b), cost(cost){}

    bool operator < ( const State &s) const{
	if ( cost == s.cost ) {
	    if ( u == s.u ){
		return b == s.b;
	    } else {
		return u > s.u;
	    }
	} else {
	    return cost > s.cost;
	}
    }
};

vector<Edge> G[MAX];
int D[MAX][MAXK][1<<MAXL];
bool V[MAX][MAXK][1<<MAXL];
int B[MAX];

int size, source, target, K, L;

void kthDijkstra(){
    priority_queue<State> PQ;
    int LV[MAX][1<<L]; // level

    rep(i, size) rep(k, K) rep(l, (1<<L)){
	D[i][k][l] = INFTY;
	V[i][k][l] = false;
    }
    rep(i, size) rep(l, (1<<L)) LV[i][l] = 0;

    int bs = 0;
    if ( B[source] != -1 ) bs = (bs | (1<<B[source]));

    D[source][0][bs] = 0;
    V[source][0][bs] = true;
    PQ.push(State(source, bs, 0));

    State s;
    while(!PQ.empty()){
	s = PQ.top(); PQ.pop();
	if ( LV[s.u][s.b] >= K ) continue;
	V[s.u][LV[s.u][s.b]][s.b] = true;
	D[s.u][LV[s.u][s.b]++][s.b] = s.cost;
	
	rep(i, G[s.u].size() ){
	    int v = G[s.u][i].v;
	    bs = s.b;
	    if ( B[v] != -1 ) bs = (bs | (1<<B[v]));
	    if ( LV[v][bs] <= K ){
		if ( !V[v][LV[v][bs]][bs] ){
		    PQ.push(State(v, bs, s.cost + G[s.u][i].cost ));
		}
	    }
	}
    }
}

void compute(){
    kthDijkstra();
    if ( D[target][K-1][(1<<L)-1] == INFTY ) printf("NA\n");
    else printf("%d\n", D[target][K-1][(1<<L)-1]);
}

bool input(){
    int m, s, t, c;
    scanf("%d %d %d %d", &size, &m, &L, &K);
    if ( size == 0 && m == 0 && L == 0 && K == 0) return false;

    rep(i, size) B[i] = -1;
    rep(i, size) G[i].clear();
    rep(i, m){
	scanf("%d %d %d", &s, &t, &c);
	s--; t--;
	G[s].push_back(Edge(t, c));
	G[t].push_back(Edge(s, c));
    }

    scanf("%d %d",  &source, &target);
    source--; target--;
    rep(i, L){
	int p;
	scanf("%d", &p);
	B[p-1] = i;
    }
    return true;
}

int main(){
    while(input()) compute();
    return 0;
}

Measured memory_bytes: 50236
#include<stdio.h>

int main(){
    int a=0, c=0, small=1;
    int len, cNum = 0;
    char s[10];
    scanf("%s", s);

    for(len=0; s[len]!='\0'; len++);

    if(s[0] == 'A') a=1;
    for(int i=2; i<len-1; i++){
        if(s[i] == 'C'){
            if(cNum != 0){
                c = 0;
                break;
            } 
            c = 1;
            cNum = i;
        }
    }
    for(int i=1; i<len; i++){
        if(i == cNum) continue;
        if(s[i]<'a' || 'z'<s[i]){
            small=0;
            break;
        }
    }
    if(a==1 && c==1 && small==1) printf("AC");
    else printf("WA");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <utility>
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;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    ll sum = 0;
    int t = 0;
    rep(i,n-1){
        sum += a[i];
        if(2*sum < a[i+1]){
            t = i+1;
        }
    }
    cout << n-t << endl;
}

Measured memory_bytes: 1024
#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(){
    int p,q,r;
    cin>>p>>q>>r;
    int ans=0;
    int a,b;
if(p<q){
if(q<r){
a=p;b=q;
}else{
a=p;b=r;
}
}else{
if(p<r){
a=p;b=q;
}else{
a=r;b=q;
}
}
ans=a+b;
cout<<ans;

}

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e6 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll mult (ll a, ll b) {
	return a * b % mod;
}

ll add (ll a, ll b) {
	int c = a + b;
	if (c >= mod) c -= mod;
	return c;
}

ll powmod (ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2) return mult (a, powmod (a, n - 1));
	ll b = powmod (a, n / 2);
	return mult (b, b);
}

ll inv (int a) {
	return powmod (a, mod - 2);
}

int f[maxn], rev[maxn];

int C (int n, int k) {
	return mult (f[n], mult (rev[k], rev[n - k]));
}

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	f[0] = rev[0] = 1;
	fl (i, 1, maxn) {
		f[i] = mult (f[i - 1], i);
		rev[i] = inv (f[i]);
	}
	int k;
	string s;
	cin >> k >> s;
	int n = sz (s);
	int ans = 0;
	fl (i, n, k + n + 1) {
		ans = add (ans, mult (C (k + n, i), powmod (25, k + n - i)));
		// dbg (C (k + n, i));
		// dbg (powmod (25, k + n - i));
		// dbg (ans);
	}
	cout << ans << '\n';









}

Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

bool dp[90][90][14000];

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int H,W;cin >> H >> W;
    int A[H][W],B[H][W];
    REP(i,H) REP(j,W) cin >> A[i][j];
    REP(i,H) REP(j,W) cin >> B[i][j];
    dp[0][0][0] = 1;
    REP(i,H){
        REP(j,W){
            REP(k,13000){
                if(dp[i][j][k]){
                    dp[i+1][j][k + abs(A[i][j] - B[i][j])] = 1;
                    dp[i+1][j][abs(k - abs(A[i][j] - B[i][j]))] = 1;
                    dp[i][j+1][k + abs(A[i][j] - B[i][j])] = 1;
                    dp[i][j+1][abs(k - abs(A[i][j] - B[i][j]))] = 1;
                }
            }
        }
    }
    REP(i,13000){
        if(dp[H][W-1][i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 99584
#include<iostream>
#include<cctype>
#include<string>
using namespace std;

int main(int argc, char const *argv[])
{
    string astr,bstr;
    int n,a=0,b=0;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> astr >> bstr;
        if(astr<bstr) b += 3;
        else if(astr==bstr) {
            a += 1; b += 1;
        }
        else a += 3;
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 998244353;



int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m; cin >> n >> m;
    priority_queue<int> pq;
    int sum = 0;
    FOR(i, 0, n)
    {
        int a; cin >> a;
        pq.push(a);
        sum += a;
    }
    int req = sum / (4 * m);
    if (sum % (4 * m) != 0) req++;
    while (m--)
    {
        int num = pq.top();
        pq.pop();
        if (num < req)
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}












Measured memory_bytes: 3128
n = int(input())
xn = list(map(int, input().split()))

ex = sum(xn)/len(xn)
if ex-round(ex) < ex-round(ex)+1:
  ex = round(ex)
else:
  ex = round(ex)+1
varx = [(i-ex)**2 for i in xn]

print(int(sum(varx)))


Measured memory_bytes: 2940
# Here your code !
n = gets.chomp
len = n.length
i = 0
flag = 0
flag2 = 0
if(n[0..(0+6)] == "erdream" or n[i..(i+7)] == "ereraser" or n[i..(i+6)] == "ererase")
    puts "NO"
    exit
end
while(i < len)
    if(n[i..(i+4)] == "dream")
        i+=5
        flag = 0
        next
    elsif(n[i..(i+3)] == "eras")
        i+=4
        flag = 1
        next
    elsif(n[i..(i+6)] == "erdream")
        i+=7
        flag = 0
        next
    elsif(n[i..(i+5)] == "ereras")
        i+=6
        flag = 1
        next
    else
        if(len - i == 2 and n[i..(i+1)]== "er") 
            break
        end
        if(n[i] == "e" and flag == 1)
            i+=1
            flag = 0
            next
        end

        puts "NO"
        exit
    end
    
end
puts "YES"

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=100100100;
const int mod=(int)1e9+7;

int main(){
    int x;
    cin>>x;
    ll a,b;
    rep(i,-1000,1000){
        rep(j,-1000,1000){
            if((ll)i*i*i*i*i-(ll)j*j*j*j*j==x){
                a=i;
                b=j;
            }
        }
    }
    cout<<a<<' '<<b<<endl;
}

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

int main( void )
{
    int x,a,b;
    cin >> x >> a >> b;
    
    if ( abs(a - x) < abs(b - x) )
        cout << 'A' << endl;
    else
        cout << "B" << endl;
}


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

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) {
            continue;
        }
        res.emplace_back(i, 0);
        while(n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) {
        res.emplace_back(n, 1);
    }
    return res;
}

int main() {
    ll N;
    cin >> N;
    vector<pair<ll, int>> factors = factorize(N);
    int ans = 0;
    set<int> used;
    L1:while(1) {
        ll z = 0;
        for(int i=0; i<factors.size(); i++){
            if(factors.at(i).second == 0){
                continue;
            }
            for(int e=1; e<=factors.at(i).second; e++){
                ll z_temp = pow(factors.at(i).first, e);
                if(used.count(z_temp) == 0){
                    z = z_temp;
                    N /= z;
                    used.insert(z);
                    factors.at(i).second -= e;
                    ans++;
                    break;
                }
            }
            if(z != 0){
                break;
            }
        }
        if(z == 0){
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4108
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define ld long double
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)
#define PI 3.14159265358979323846

int main()
{
    int key;
    cin >> key;
    string temp;
    cin >> temp;
    int num;
    num = temp.length();
    for (int i = 0; i < num; i++)
    {
        temp[i] = (temp[i] - 'A'+key)%26+'A';
    }
    cout << temp << endl;
    
}

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

int main() {
    int a , b , c , x;
    int count = 0;
    cin >> a >> b >> c;
    for (int x = a; x <= b; x++) {
        if(c % x == 0) {
            count += 1;
        }
    }
        cout << count << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int arr[1000007];

int dp[1000004]={-1};
int result(int n){

	if(n<=0)
	{
		return 0;
	}

	else{dp[0]=0;
	dp[1]=max(arr[0],arr[1])-min(arr[0],arr[1]);
	dp[2]=min(dp[1],max(arr[0],arr[2])-min(arr[0],arr[2]));

	for(int i=2;i<n;i++)
	{dp[i]=min(max(arr[i],arr[i-2])-min(arr[i],arr[i-2])+dp[i-2],max(arr[i],arr[i-1])-min(arr[i],arr[i-1])+dp[i-1]);}
return dp[n];}
}

int main(){
int t;
cin>>t;
for(int i=0;i<t;i++)
{
 cin>>arr[i];
}

int re=result(t);

cout<<dp[t-1]<<endl;
cout<<endl;
/*for(int i=0;i<t;i++)
{
	cout<<dp[i]<<endl;
}*/



	return 0;
}

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

int main(){
  int n,x,t;
  cin>>n>>x>>t;
  
  int ans;
  if(n%x==0) ans=n/x;
  else ans=n/x+1;
  
  cout << ans*t <<endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	ll n;
	cin>>n;
	cout<< (1000-n%1000)%1000 <<"\n";			
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<int> yop,yoc;
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x;
    cin>>x;
    yop.push_back(x);
  }
  sort(yop.begin(),yop.end());
  int ans=yop[m-1]-yop[0];
  for(int i=0;i<m-1;i++) yoc.push_back(yop[i+1]-yop[i]);
  sort(yoc.begin(),yoc.end(),greater<int>());
  for(int i=0;i<n-1&&i<yoc.size();i++) ans-=yoc[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 1400
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:usize, s:chars, t:chars};

    for i in 0..n {
        let mut f = true;
        for j in 0..n-i {
            //debug!(i,j,s[i+j],t[j]);
            if s[i+j] != t[j] {
                f = false;
            }
        }
        if f {
            println!("{}", n*2-(n-i));
            return();
        }
    }

    println!("{}", n*2);

}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>

typedef long long ll;

int countmask(ll mask, vector<ll> &v)
{
	int ret = 0;

	for(int i = 0; i < v.size(); i++)
	{
		if ( (mask & v[i]) == mask )
		{
			ret++;
		}
	}

	return ret;
}


int main(int argc, char **argv)
{
	int N, K;

	cin >> N >> K;

	ll a[N];

	vector<ll> sum;

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

	for (int i = 0; i < N; i++)
	{
		ll tmp_sum = 0;
		for (int j = i; j < N; j++)
		{
			tmp_sum += a[j];

			sum.push_back(tmp_sum);
		}
	}

	ll mask = 0;

	for (int i = 40; i >= 0; i--)
	{
		if (countmask(mask | (1LL << i), sum) >= K)
		{
			mask |= (1LL << i);
		}
	}

	cout << mask << endl;

	return 0;

}

Measured memory_bytes: 6512
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll extgcd(ll a, ll b, ll& x, ll& y) {
    for (ll v = x = 1, u = y = 0; b; ) { ll q = a / b; swap(a -= q * b, b); swap(x -= q * u, u); swap(y -= q * v, v); }
    return a;
}

ll minv(ll a) { ll x, y; extgcd(a, MOD, x, y); return (x % MOD + MOD) % MOD; }

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> S(N);
    rep(i, N) cin >> S[i];

    sort(all(S), greater<int>());

    vector<ll> inv(N + 1);
    rep(i, 1, N + 1) inv[i] = minv(i);

    ll Nfact = 1;
    rep(i, N) Nfact = Nfact * (i + 1) % MOD;

    vv<ll> dp = vvec(N + 1, X + 1, 0LL);
    dp[0][X] = 1;
    rep(i, N) rep(x, 0, X + 1) {
        dp[i + 1][x % S[i]] = (dp[i + 1][x % S[i]] + dp[i][x] * inv[N - i]) % MOD;
        dp[i + 1][x] = (dp[i + 1][x] + dp[i][x] * (N - i - 1) % MOD * inv[N - i]) % MOD;
    }

    ll ans = 0;
    rep(i, S[N - 1]) ans = (ans + i * dp[N][i] % MOD * Nfact) % MOD;
    write(ans);
}

Measured memory_bytes: 158592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            long yokin = 100;
            long X = sc.nextLong();

            long nen = 0;


            while(yokin<X){
                yokin*=1.01;
                nen++;
            }


            System.out.println(nen);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}


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

int main() {
  int N;
  cin >> N;
vector<int> X(N);
vector<int> Y(N);
vector<int> Vx(N*N);
vector<int> Vy(N*N);
vector<int> counter(N*N,0);
  
for(int i=0;i<N;i++){
  cin >> X.at(i)>>Y.at(i);
}

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      Vx.at(i*N+j)=X.at(j)-X.at(i);
      Vy.at(i*N+j)=Y.at(j)-Y.at(i);
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        for(int l=0;l<N;l++){
          if(Vx.at(i*N+j)!=0||Vy.at(i*N+j)!=0){
            if(Vx.at(i*N+j)==Vx.at(k*N+l)&&Vy.at(i*N+j)==Vy.at(k*N+l)){
            counter.at(i*N+j)=counter.at(i*N+j)+1;
          }
          }
        }
      }
    }
  }
  sort(counter.begin(), counter.end());
  cout<<N-counter.at(counter.size()-1)<<endl;
  return 0;
}



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

const int mod = 1e9 + 7;
int bin_pow(int x, int y) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        int curr = bin_pow(x, y / 2);
        return (curr * curr) % mod;
    }
    else {
        return (bin_pow(x, y - 1) * x) % mod;
    }
}

int cnt[200005];
int32_t main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = k; i >= 1; i--) {
        int curr_ans = bin_pow(k / i, n);
        cnt[i] = curr_ans;
        for (int j = i + i; j <= k; j += i) {
            cnt[i] = (cnt[i] - cnt[j] + mod) % mod;
        }
        ans += (i * cnt[i]) % mod;
        ans %= mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4416
def f(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n + 1
    elif n % 4 == 3:
        return 0


A, B = map(int, input().split())
print(f(B) ^ f(A - 1))

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    int sum=0;
    for(int i=0;i<(int)s.size();i++){
      if(s[i]=='I'){
	if(s[i+1]=='V'||s[i+1]=='X') sum-=1;
	else sum+=1;
      } else if(s[i]=='V'){
	sum+=5;
      } else if(s[i]=='X'){
	if(s[i+1]=='L'||s[i+1]=='C') sum-=10;
	else sum+=10;
      } else if(s[i]=='L'){
	sum+=50;
      } else if(s[i]=='C'){
	if(s[i+1]=='D'||s[i+1]=='M') sum-=100;
	else sum+=100;
      } else if(s[i]=='D'){
	sum+=500;
      } else if(s[i]=='M'){
	sum+=1000;
      }
    }
    cout << sum << "\n";
  }
}

Measured memory_bytes: 1180
#include <stdio.h>

#define N 25

typedef struct {
	int id, p, l, r, sibling, degree, depth, height;
}Node;

Node node[N];

int calc_degree(Node);
void calc_fa(int);
void calc_depth(int, int);
int calc_height(int);

void preorder(int);
void inorder(int);
void postorder(int);

int n,pc;

int main() {
	int i, id, root = 0;;
	scanf("%d", &n);
	for (i = 0; i<n; i++) {
		scanf("%d", &id);
		node[id].id = id;
		node[id].p = node[id].sibling = -1;
		scanf("%d %d", &node[id].l, &node[id].r);
	}
	for (i = 0; i < n; i++) {
		node[i].degree = calc_degree(node[i]);
	}
	calc_fa(n);
	for (i = 0; i < n; i++) {
		if (node[i].p == -1) {
			root = i;
			break;
		}
	}

	calc_depth(root, 0);
	calc_height(root);

	printf("Preorder\n");
	pc = 0;
	preorder(root);
	printf("\nInorder\n");
	pc = 0;
	inorder(root);
	printf("\nPostorder\n");
	pc = 0;
	postorder(root);
	printf("\n");
	return 0;
}

int calc_degree(Node n) {
	if (n.l != -1 && n.r != -1) return 2;
	if (n.l != -1 || n.r != -1) return 1;
	return 0;
}

void calc_fa(int n) {
	int i;
	for (i = 0; i < n; i++) {
		//parent
		//node[i].p = -1;
		if (node[i].l != -1) node[node[i].l].p = node[i].id;
		if (node[i].r != -1) node[node[i].r].p = node[i].id;
	}
	for (i = 0; i<n; i++) {
		//sibling
		//node[i].sibling = -1;
		if (node[node[i].p].l == node[i].id)
			node[i].sibling = node[node[i].p].r;
		if (node[node[i].p].r == node[i].id)
			node[i].sibling = node[node[i].p].l;
		if (node[i].p == -1) node[i].sibling = -1;
	}
}

void calc_depth(int now_id, int now_depth) {
	if (calc_degree(node[now_id]) == 0) {
		node[now_id].depth = now_depth;
		return;
	}
	if (node[now_id].l != -1) {
		calc_depth(node[now_id].l, now_depth + 1);
	}
	if (node[now_id].r != -1) {
		calc_depth(node[now_id].r, now_depth + 1);
	}
	node[now_id].depth = now_depth;
}

int calc_height(int now_id) {
	int lh, rh;
	if (node[now_id].degree == 0) {
		node[now_id].height = 0;
		return 0;
	}
	else {
		lh = calc_height(node[now_id].l) + 1;
		rh = calc_height(node[now_id].r) + 1;
		if (lh > rh) {
			node[now_id].height = lh;
			return lh;
		}
		else {
			node[now_id].height = rh;
			return rh;
		}
	}
}

void preorder(int now_id) {
	printf(" %d", node[now_id].id);
	if (node[now_id].l != -1) preorder(node[now_id].l);
	if (node[now_id].r != -1) preorder(node[now_id].r);
}

void inorder(int now_id) {
	if (node[now_id].l != -1) inorder(node[now_id].l);
	printf(" %d", node[now_id].id);
	if (node[now_id].r != -1) inorder(node[now_id].r);
}

void postorder(int now_id) {
	if (node[now_id].l != -1) postorder(node[now_id].l);
	if (node[now_id].r != -1) postorder(node[now_id].r);
	printf(" %d", node[now_id].id);
}


Measured memory_bytes: 2108
use proconio::{ input, fastout };

#[fastout]
fn main() {
    input! {
        mut s: String,
        mut t: String,
    };
    let len = s.len();
    let mut cnt = 0;

    for _i in 0..len {
        if !(s.pop() == t.pop()) {
            cnt += 1;
        }
    }

    println!("{}", cnt);
    
}


Measured memory_bytes: 2836