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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    ll n, k;
    cin >> n >> k;

    ll sum = 0;
    rep(i, k, n + 2) {
        sum = (sum + (i * (n + 1 - i) + 1)) % 1000000007;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#define N 1000000
  
int main(){
  int i,j,n,min,a,b,c;
  int G[100][100],k[100],d[100];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    k[i]=0;
    d[i]=N;
    for(j=0;j<n;j++){
      G[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d",&c);
      scanf("%d",&G[a][c]);
    }
  }
  d[0]=0;
  while(1){
    min=N;
    for(i=0;i<n;i++){
      if(k[i]!=1&&d[i]<min){
        min=d[i];
        a=i;
      }
    }
  
    if(min==N){
      break;
    }
    for(i=0;i<n;i++){
      if(G[a][i]!=-1&&k[i]!=1&&d[a]+G[a][i]<d[i])
        d[i]=d[a]+G[a][i];
    }
    k[a]=1;
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    ll N,M;cin>>N>>M;
    string s;cin>>s;
    vi ac(N+1);
    rep(i,0,N-1){
        if(s.at(i)=='A'&&s.at(i+1)=='C'){
            ac.at(i+1)=1;
        }
    }
    rep(i,1,N){
        ac.at(i+1)+=ac.at(i);
    }
    rep(i,0,M){
        ll x,y;cin>>x>>y;
        cout<<ac.at(y-1)-ac.at(x-1)<<endl;
    }
}






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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll dp[2000] ;
ll n ;

ll check (ll val)
{
    if (val == 0)   return 1 ;
    if (dp[val] != -1) return dp[val] ;

    ll ans = 0 ;
    for (int i = 3; i <= 2000; i++) {
        if (val - i >= 0) {
            ans += check(val - i) ;
            ans %= MOD ;
        }
    }
    return dp[val] = ans ;
}

int main()
{
    ll ans = 0 ;
    cin >> n ;

    memset(dp, -1, sizeof dp) ;

    for (int i = 3; i <= 2000; i++) {
        if (n - i >= 0) {
            ans += check(n - i) ;
            ans %= MOD ;
        }
    }
    cout << ans ;


    return 0 ;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

int main() {
  int D, T, S;
  cin >> D >> T >> S;
  if((D - 1) / S + 1 <= T) cout << "Yes"  << endl;
  else cout << "No" << endl;
  return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vi a(n+1); rrep(i, n) std::cin >> a[i];
  vi aa(n+1), ans;
  ddrep(i, n) {
    int sum = 0;
    for (int j = i+i; j <= n; j+=i)
      sum += aa[j];
    if (sum%2 != a[i]) aa[i] = 1, ans.pb(i);
  }
  std::cout << ans.size() << "\n";
  rep(i, ans.size()) std::cout << (i!=0 ? " " : "") << ans[i] << "\n";
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
#define mkpr make_pair
#define ft first
#define sd second

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>
inline void read(T &x) {
    x=0; int f=0; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-') f=1; if(ch==EOF) return; ch=getchar();}
    while(isdigit(ch)) {x=x*10+(ch-'0'); ch=getchar();} if(f) x=-x;
}

/***********************************************************/

const int MAXN=200011;
char s[MAXN];
int cnt[33];
int n;
LL ans=0;

int main() {
    scanf("%s", s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;++i) {
        ans+=(LL)(i-1-cnt[s[i]-'a']);
        cnt[s[i]-'a']++;
    }
    printf("%lld\n", ans+1);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  rep (i, n) {
    if (a[i] & 1) continue;
    if (a[i] % 3 != 0 && a[i] % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

string as,bs,cs;
int al,bl,cl;
int at=-1,bt=-1,ct=-1;
char flag='a';

inline void solve(){
	for( ; ; ){
		if(at>=al){
			puts("A");
			break;
		}
		if(bt>=bl){
			puts("B");
			break;
		}
		if(ct>=cl){
			puts("C");
			break;
		}
		if(flag=='a'){
			at++;
			flag=as[at];
		}
		if(flag=='b'){
			bt++;
			flag=bs[bt];
		}
		if(flag=='c'){
			ct++;
			flag=cs[ct];
		}
	}
}

int main(){
	cin>>as>>bs>>cs;
	al=as.size();
	bl=bs.size();
	cl=cs.size();
	solve();
	return 0;
}

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

int main() {
  int r, g, b, pro;
  cin >> r >> g >> b;
  
  pro = 100*r + 10*g + b;
  
  if (pro % 4 == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
w+=1

s = $<.map(&:bytes)

a = Array.new(h+1) { Array.new(w+1,0) }
blockers=Array.new(w+1) { Array.new }

h.times do |i|
  l=0
  w.times.select {|j| s[i][j]!=46 }.each do |j|
    blockers[j] << i
    l.upto(j-1) {|c_j| a[i][c_j] = j-l }
    l=j+1
  end
end

w.times { |k| blockers[k] << h }

blockers.each_with_index do |blocks, height|
  l=0
  blocks.each do |b|
    l.upto(b-1) {|j| a[j][height] += b-l }
    l = b+1
  end
end

p a.map(&:max).push(1).max-1


Measured memory_bytes: 122364
s = input()
l = len(s)

if s[0] != '1' or s[-2] != '1' or s[-1] != '0':
  print('-1')
  exit()
if s[:-1] != s[:-1][::-1]:
  print('-1')
  exit()

# 1頂点に全部ついた状態から始める
e = [l] + [-1] * (l-1)
now = 0
h = (l-1) // 2
for i in range(h, 0, -1):
  c = s[i]
  if c == '0':
    continue
  # now の木から子をi個取り出して繋げる
  e[now] = l - i
  e[l-i-1] = l
  now = l-i-1

for i, a in enumerate(e):
  for j in range(i+2, a+1):
    print(i+1, j)

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

int main() {
    int n, m, sum=0;
    cin >> n;
    m = n;
    while(true) {
        sum += m%10;
        m /=10;
        if(m == 0) {
            break;
        }
    }
    if(n%sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w;
char s[505][505],out[505][505];
int main(){
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i) scanf("%s",s[i]+1);
	for(int i=1;i<=h;++i,puts("")){
		if(i&1){
			for(int j=1;j<w;++j)
				printf("#");
			if(s[i][w]=='#')
				printf("#");
			else printf(".");
		}
		else{
			printf("#");
			for(int j=2;j<=w;++j)
				if(s[i][j]=='#')
					printf("#");
				else printf(".");
		}
	}
	puts("");
	for(int i=1;i<=h;++i,puts("")){
		if(i&1){
			for(int j=1;j<w;++j)
				if(s[i][j]=='#')
					printf("#");
				else printf(".");
			printf("#");
		}
		else{
			if(s[i][1]=='#')
				printf("#");
			else printf(".");
			for(int j=1;j<w;++j)
				printf("#");
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 3000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;

struct edge {ll to;ld cost;};
//=============dijkstra============================
vector<ld> dijkstra(ll s, ll V, vector<vector<edge>>& G)
{
  vector<ld> d(V, INF);
  typedef pair<ld, ll> P;// first は最短距離　second は頂点の番号
  priority_queue<P, vector<P>, greater<P>> que;
  d.at(s) = 0;
  que.push(P(0, s));
  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    ll v = p.second;
    if (d.at(v) < p.first) continue;
    for (ll i = 0; i < G.at(v).size(); ++i)
    {
      edge e = G.at(v).at(i);
      if (d.at(e.to) > d.at(v) + e.cost)
      {
        d.at(e.to) = d.at(v) + e.cost;
        que.push(P(d.at(e.to), e.to));
      }
    }
  }
  return d;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  ll N;
  cin >> N;
  N += 2;
  vector<vector<ll>> xyr(N);
  xyr.at(0) = {xs, ys, 0};
  xyr.at(1) = {xt, yt, 0};
  for (ll i = 2; i < N; ++i) {
    ll x, y, r;
    cin >> x >> y >> r;
    xyr.at(i) = {x, y, r};
  }
  vector<vector<edge>> connection(N);
  for (ll i = 0; i < N; ++i) {
    for (ll j = 0; j < N; ++j) {
      if (i == j) {
        continue;
      }
      ll p = pow(xyr.at(i).at(0) - xyr.at(j).at(0), 2) + pow(xyr.at(i).at(1) - xyr.at(j).at(1), 2);
      connection.at(i).push_back((edge){j, max((ld)0.0, (ld)pow(p, 0.5) - (xyr.at(i).at(2) + xyr.at(j).at(2)))});
    }
  }
  vector<ld> dist = dijkstra(0, N, connection);
  cout << fixed << setprecision(15) << dist.at(1) << "\n";
}


Measured memory_bytes: 44256
#include<stdio.h>
#include<math.h>

int square(double x){
	double a=sqrt(x);
	if((a-(int)a)==0)
		return 1;
	else
		return 0;
}
	

int main(){
	int n,d;
	scanf("%d%d",&n,&d);
	int x[30][30];
	int i,j,k;
	for(i=0;i<n;i++){
		for(j=0;j<d;j++){
			scanf("%d",&x[i][j]);
		}
	}
	int a[30],ans=0,count;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			for(k=0,count=0;k<d;k++){
				a[k]=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
				count +=a[k];
			}
			if(square(count)){
				ans++;
			}
		}
	}
	printf("%d",ans);
	return 0;
}
		

Measured memory_bytes: 128
#include<atcoder/all>
using namespace atcoder;

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int N, Q; scanf("%d%d", &N, &Q);
    fenwick_tree<LL> G(N);
    rep(i, N) { int a; scanf("%d", &a); G.add(i, a); }

    rep(q, Q) {
        int c; scanf("%d", &c);
        if (c == 0) {
            int p, x; scanf("%d%d", &p, &x);
            G.add(p, x);
        }
        if (c == 1) {
            int l, r; scanf("%d%d", &l, &r);
            printf("%lld\n", G.sum(l,r));
        }
    }

    return 0;
}

Measured memory_bytes: 8204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            Dictionary<char, int> Table = new Dictionary<char, int>();
            Dictionary<char, int> Last = new Dictionary<char, int>();
            for(int i = 0; i < s.Length; i++)
            {
                
                if (Table.ContainsKey(s[i]))
                {
                    Table[s[i]] = Math.Max(Table[s[i]], i - Last[s[i]]-1);
                    Last[s[i]] = i;
                }
                else
                {
                    Table[s[i]] = i;
                    Last[s[i]] = i;
                }
            }
            var Table2 = Table.Select(x => Math.Max(x.Value, s.Length - Last[x.Key]-1)).ToList();
            
            Console.WriteLine(Table2.Min());
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

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

int main() 
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D)
	{
		cout << "Left" << endl;
	}
	else if (A + B == C + D)
	{
		cout << "Balanced" << endl;
	}
	else
	{
		cout << "Right" << endl;
	}
}

Measured memory_bytes: 256
def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i * i <= x:
        if x % i == 0:
            return False
        i += 2

    return True


n = int(raw_input())
ans = 0

for i in range(n):
    x = int(raw_input())
    if (is_prime(x)):
        ans += 1

print ans

Measured memory_bytes: 6560
#include<bits/stdc++.h>
using namespace std;
int n;
int u;
int main(){
	cin>>n;
	while(n--){
		cin>>u;
		if(!(u&1)){
			if(u%3!=0&&u%5!=0){
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}


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

using namespace std;

int main(){
  int N; cin >> N;
  vector<tuple<string,int,int>> a;
  for(int i = 1; i <= N; i++){
    string s; int c; cin >> s >> c; c = -c;
    a.push_back(tie(s,c,i));}
  
  sort(a.begin(),a.end());
  
  for(int r = 0; r < N; r++){
    cout << get<2>(a[r]) << endl;
    
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using  namespace std;
int main(){
    int N,X;
    cin >> N >> X;
    int m[N];
    int count = N;
    for(int i = 0; i < N; i++){
        cin >> m[i];
        X -= m[i];
    }
    sort(m,m+N);
    count += X/m[0];
    cout << count << endl;
}

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

struct State{
	pair<int,int> t,k;
	int turn;
};


int dy[]={0,1,0,-1};
int dx[]={1,0,-1,0};
int w,h;
int field[52][52];
bool visited[52][52][52][52];

int main(){
	while(cin>>w>>h,w|h){
		memset(visited,false,sizeof(visited));
		queue<State> q;
		State a,b;
		a.turn=0;
		cin>>a.t.second>>a.t.first;
		cin>>a.k.second>>a.k.first;
		for(int i=0;i<52;i++){
			for(int j=0;j<52;j++)field[i][j]=1;
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++)cin>>field[i][j];
		}
		int ans=-1;
		q.push(a);
		visited[a.t.first][a.t.second][a.k.first][a.k.second]=true;
		while(!q.empty()){
			a=q.front();
			q.pop();
			if(a.t.first==a.k.first&&a.t.second==a.k.second){
				ans=a.turn;
				break;
			}
			if(100<=a.turn+abs(a.t.first-a.k.first)/2+abs(a.t.second-a.k.second)/2){
				break;
			}
			for(int i=0;i<4;i++){
				b=a;
				b.t.first+=dy[i];
				b.t.second+=dx[i];
				b.k.first-=dy[i];
				b.k.second-=dx[i];
				if(field[b.t.first][b.t.second])b.t=a.t;
				if(field[b.k.first][b.k.second])b.k=a.k;
				b.turn=a.turn+1;
				if(!visited[b.t.first][b.t.second][b.k.first][b.k.second]){
					visited[b.t.first][b.t.second][b.k.first][b.k.second]=true;
					q.push(b);
				}
			}
		}
		while(!q.empty())q.pop();
		if(ans==-1)cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 8528
#include <stdio.h>

int main(void)
{
	int x, y, ans = 0, i;
	
	scanf("%d" "%d", &x, &y);
	
	ans += (x + 1);
	ans += (y - 1);
	
	for(i = 2; i < 2 * x; i += 2){
		if(y * i % (2 * x) == 0){
			ans -= 1;
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>

const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    ll ans;
    ans=N/(A+B);
    ans*=A;
    ans+=min(A,N%(A+B));
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
	long long n;
	cin >> n;
	long long n_copy = n;

	int digit_sum = 0;

	while(n)
	{
		digit_sum += n%10;
		n /= 10;
	}
	if ((n_copy%digit_sum)==0) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}


int main(){
    int n;
    int m;
    cin >> n >> m;
    vector<int> line(n);
    map<int,map<int,int>> cnt;
    foreach(i,line){
        cin >> i;
        ++cnt[i%m][i];
    }
    int ans = 0;
    repa(i,m/2+1){
        if(i*2==m)continue;
        deque<int> l;
        deque<int> r;
        foreach(j,cnt[i]){
            if(j.second&1){
                l.push_front(j.second);
            }else{
                l.push_back(j.second);
            }
        }
        foreach(j,cnt[m-i]){
            if(j.second&1){
                r.push_front(j.second);
            }else{
                r.push_back(j.second);
            }
        }
        while(l.size()&&r.size()){
            int a = l.front();
            l.pop_front();
            int b = r.front();
            r.pop_front();
            ++ans;
            --a;
            --b;
            if(a){
                if(a&1){
                    l.push_front(a);
                }else{
                    l.push_back(a);
                }
            }
            if(b){
                if(b&1){
                    r.push_front(b);
                }else{
                    r.push_back(b);
                }
            }
        }
        while(l.size()){
            ans += l.front() / 2;
            l.pop_front();
        }
        while(r.size()){
            ans += r.front() / 2;
            r.pop_front();
        }
    }
    {
        int sum = 0;
        foreach(i,cnt[0]){
            sum += i.second;
        }
        ans += sum / 2;
    }
    if(~m&1){
        int d = m / 2;
        int sum = 0;
        foreach(i,cnt[d]){
            sum += i.second;
        }
        ans += sum / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 14720
using System;
using AtCorder;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var input1 = Console.ReadLine();
            var input2 = Console.ReadLine();

            if(input1 == "1")
            {
                if(input2 == "2")
                {
                    Console.WriteLine("3");
                }
                else
                {
                    Console.WriteLine("2");
                }
            }
            else if(input1 == "2")
            {
                if (input2 == "1")
                {
                    Console.WriteLine("3");
                }
                else
                {
                    Console.WriteLine("1");
                }
            }
            else
            {
                if (input2 == "1")
                {
                    Console.WriteLine("2");
                }
                else
                {
                    Console.WriteLine("1");
                }
            }
        }
    }
}


Measured memory_bytes: 11092
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);















int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, d, a;
  cin >> n >> d >> a;
  pii p[n];
  loop(n) cin >> p[i].F >> p[i].S;
  sort(p, p+n);
  ll ans = 0, c[n+9];
  int j=0;
  clr(c, 0);
  loop(n){
    if(i>0) c[i]+=c[i-1];
    if(p[i].S-(c[i]*a)<=0) C;
    int far = p[i].F+(2*d);
    while(p[j].F<=far&&j<n) j++;
    int bmbs = (p[i].S-(c[i]*a)+a-1)/a;
    c[i]+=bmbs;
    c[j]-=bmbs;
    ans+=bmbs;
  }
  cout << ans << endl;
  R 0;
}
/*

*/




























































ll po(ll x, ll n){
  if(n==0) R 1;
  ll y = po(x, n/2);
  y = ((y)*(y));
  if(n%2) y = (y*(x));
  R y;
}


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

# define fr first
# define sc second
# define ll unsigned long long
# define mk make_pair
# define pb emplace_back
# define sz(s) (int)s.size()
# define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5+10;
const int inf = 1e9+7;

int n, m, p[N], sz[N];
vector <int> v[N];

int f_s(int a) {
    return (p[a] == a) ? a : p[a] = f_s(p[a]);
}

void un_s(int a, int b) {
    a = f_s(a);
    b = f_s(b);
    if(a != b) {
        sz[a] += sz[b];
        p[b] = a;
    }
}

int main () {
    scanf("%d%d", &n, &m);
    for(int i = 1, k; i <= n; i++) {
        scanf("%d", &k);
        for(int j = 1, x; j <= k; j++) {
            scanf("%d", &x);
            v[x].pb(i);
        }
        p[i] = i, sz[i] = 1;
    }
    for(int i = 1; i <= m; i++) {
        if(sz(v[i]) == 0) continue;
        for(int j = 1; j < sz(v[i]); j++)
            un_s(v[i][j - 1], v[i][j]);
    }
    if(sz[f_s(1)] < n) puts("NO");
    else puts("YES");
}


Measured memory_bytes: 8320
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()

#define MOD 1000000007
int N;
int C[200000];
vector<int> pos[200000];
vector<pair<int,int> > koho;
LL dp[200000];
LL solve(int L){
	if(L >= N) return 1;
	if(dp[L] != -1) return dp[L];
	int idx = lower_bound(koho.begin(), koho.end(), MP(L, 0)) - koho.begin();
	if(idx == koho.size()) return dp[L] = 1;
	return dp[L] = ( solve(koho[idx].first+1) + solve(koho[idx].second) )%MOD;
}
int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> C[i];
		C[i]--;
		pos[C[i]].PB(i);
		dp[i] = -1;
	}

	for(int i=0; i<200000; i++){
		for(int j=1; j<pos[i].size(); j++){
			if(pos[i][j-1]+1 == pos[i][j]) continue;
			koho.PB(MP(pos[i][j-1], pos[i][j]));
		}
	}
	sort(koho.begin(), koho.end());
	cout << solve(0) << endl;
	//for(int i=0; i<N; i++) cout << solve(i) << endl;

	return 0;
}

Measured memory_bytes: 16248
#include <bits/stdc++.h> 
using namespace std; 
int countDivisibles(int A, int B, int M) 
{ 
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
    return (B / M) - (A / M); 
} 
  
// Driver Code 
int main() 
{ 
	int A,B,M;
	scanf("%d%d%d",&A,&B,&M);
    cout << countDivisibles(A, B, M) << endl; 
    return 0; 
} 

Measured memory_bytes: 3756
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    int h,w;
    cin >> h >> w;
    string s[h * 2];
    
    for(int i = 0; i < h * 2; i = i + 2){
        cin >> s[i];
        s[i + 1] = s[i];
    }

    rep(i,h * 2){
        cout << s[i] << endl;
    }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

bool map[21][21];
int N;

bool solve(){
  bool map[21][21];
  int x = 10, y = 10;
  int dx[] = {0,1,0,-1};
  int dy[] = {1,0,-1,0};
  REP(i,21){
    REP(j,21){
      map[i][j] = false;
    }
  }
  REP(i,N){
    int x, y;
    cin >> x >> y;
    map[x][y] = true;
  }
  if(map[x][y]){
    map[x][y] = false;
    N--;
  }
  int M;
  cin >> M;
  REP(i,M){
    char c;
    int l;
    int d;
    cin >> c >> l;
    switch(c){
    case 'N':
      d = 0;
      break;
    case 'E':
      d = 1;
      break;
    case 'S':
      d = 2;
      break;
    case 'W':
      d = 3;
      break;
    }
    REP(j,l){
      x += dx[d];
      y += dy[d];
      if(map[x][y]){
	map[x][y] = false;
	N--;
      }
    }
  }
  if(N == 0) return true;
  else return false;
}

int main(){
  while(true){
    cin >> N;
    if(N == 0) break;
    if(solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

int main() {
	string S;
	cin >> S;
	string tmp1 = S;
	int ans1 = 0;
	for (int i = 0; i < tmp1.size(); ++i) {
		if (i % 2) {
			if (tmp1[i] == '0') ++ans1;
		}
		else {
			if (tmp1[i] == '1') ++ans1;
		}
	}
	string tmp2 = S;
	int ans2 = 0;
	for (int i = 0; i < tmp2.size(); ++i) {
		if (i % 2) {
			if (tmp2[i] == '1') ++ans2;
		}
		else {
			if (tmp2[i] == '0') ++ans2;
		}
	}
	cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int e = 4*1e6 + 69;
const int mod = 1e9 + 7;

ll a[e], b[e];

int main()
{
    ll n;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    int dem = 0;
    sort(b+1, b+n+1);
    for(int i=1; i<=n; i++)
    {
        if(a[i] != b[i])
        {
            for(int j=1; j<=n; j++)
            {
                if(a[j] == b[i])
                {
                    swap(a[i], a[j]);
                    break;
                }
            }
            break;
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(a[i] != b[i])
        {
            cout <<"NO";
            return 0;
        }
    }
    cout << "YES";

}


Measured memory_bytes: 2304
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int r = Integer.parseInt (reader.readLine());
        System.out.println (String.format ("%.0f", Math.pow (r, 2)));
        return;
    }
}

Measured memory_bytes: 34680
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

vector<int> G[100001];
int N;
int root;
int MAX_LOG_V = 17;

int** parent;
int* depth;

void dfs(int node_id,int parent_id,int d){
	parent[0][node_id] = parent_id;
	depth[node_id] = d;
	for(int i = 0; i < G[node_id].size(); i++){
		if(G[node_id][i] != parent_id)dfs(G[node_id][i],node_id,d+1);
	}
}

//?????????
void init(){
	dfs(root,-1,0);
	for(int k = 0; k + 1 < MAX_LOG_V; k++){
		for(int node_id = 0; node_id < N; node_id++){
			if(parent[k][node_id] < 0)parent[k+1][node_id] = -1;
			else{
				parent[k+1][node_id] = parent[k][parent[k][node_id]];
			}
		}
	}
}

int lca(int left,int right){
	if(depth[left] > depth[right])swap(left,right);
	for(int k = 0; k < MAX_LOG_V; k++){
		if((depth[right]-depth[left]) >> k & 1){
			right = parent[k][right];
		}
	}
	if(left == right)return left;
	for(int k = MAX_LOG_V-1; k >= 0; k--){
		if(parent[k][left] != parent[k][right]){
			left = parent[k][left];
			right = parent[k][right];
		}
	}
	return parent[0][left];
}



int main(){

	scanf("%d",&N);

	int num,child;

	for(int i = 0; i < N; i++){
		scanf("%d",&num);
		for(int k = 0; k < num; k++){
			scanf("%d",&child);
			G[i].push_back(child);
		}
	}

	parent = new int*[MAX_LOG_V];
	for(int i = 0; i < MAX_LOG_V;i++)parent[i] = new int[N];
	depth = new int[N];
	root = 0;
	init();

	int Q;
	scanf("%d",&Q);

	int left,right;

	for(int i = 0; i < Q; i++){
		scanf("%d %d",&left,&right);
		printf("%d\n",lca(left,right));
	}

	return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[10][10];
bool fl=true;

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

       rep(i,3){
           rep(j,3){
               cin>>s[i][j];
               if(i==0&&j==0){
                   cout << s[i][j];
               }
               else if(i==1&&j==1){
                   cout <<s[i][j];
               }
               else if(i==2&&j==2){
                   cout <<s[i][j];
               }
           }
       }
       cout << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 2020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int to[N<<1], nxt[N<<1], head[N], cnt;
void insert(int x, int y) {
  to[++ cnt] = y; nxt[cnt] = head[x]; head[x] = cnt;
  to[++ cnt] = x; nxt[cnt] = head[y]; head[y] = cnt;
}
int n, k, max_d;
int dfs(int x, int f, int d) {
  if (d > max_d) return 0;
  int sz = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (f == to[i]) continue;
    sz += dfs(to[i], x, d + 1);
  }
  return sz;
}
int x[2020], y[2020];
int main(int argc, char const *argv[]) {
  n = read(); k = read();
  for (int i = 1; i < n; ++ i) {
    x[i] = read();
    y[i] = read();
    insert(x[i], y[i]);
  }
  int ans = 1 << 30;

  if (k & 1) {
    max_d = k >> 1;
    for (int i = 1; i < n; ++ i) {
      int sz = 0;
      sz += dfs(x[i], y[i], 0);
      sz += dfs(y[i], x[i], 0);
      ans = min(ans, n - sz);
    }
  } else {
    max_d = k >> 1;
    for (int i = 1; i <= n; ++ i) {
      int sz = dfs(i, 0, 0);
      ans = min(ans, n - sz);
    }
  }

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

/*
树的重心有一个特性：每个点离它的距离都<=d/2
于是枚举边/点直接 DFS 判断即可。
*/

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }


int main() {
  int n;
  while (cin >> n) {
    vint v(n), u;
    REP(i,n) cin >> v[i];
    u = v;
    sort(ALL(u));
    REP(i,n) {
      if (v[i] != u.back()) cout << u.back() << endl;
      else cout << u[n-2] << endl;
    }
  }
}


Measured memory_bytes: 3200
while True:
    n, m, a = map(int, input().split())
    if n == m == a == 0:
        break

    lines = [list(map(int, input().split())) for i in range(m)]
    lines.sort()

    place = [i for i in range(n + 1)]
    for line in lines:
        h, p, q = line
        place[p], place[q] = place[q], place[p]

    print(place[a])


Measured memory_bytes: 5884
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }

vll calcFactors(ll n) {
  vll result;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      result.push_back(i);
      result.push_back(n / i);
    }
  }
  return result;
}

bool ok(const vll &v, ll x, ll k) {
  const int n = v.size();
  vll a(n), b(n);
  REP(i,n) a[i] = v[i] - (v[i] / x * x);
  sort(ALL(a));
  REP(i,n) b[i] = x - a[i];

  vll aa(n), bb(n);
  REP(i,n) aa[i] += (i == 0 ? 0 : aa[i-1]) + a[i];
  for (int i = n - 1; i >= 0; --i) bb[i] += (i + 1 == n ? 0 : bb[i+1]) + b[i];
  // cout << "a, b" << endl;
  // pp(a); pp(b);
  // cout << "aa, bb" << endl;
  // pp(aa); pp(bb);
  REP(i,n-1) if (max(aa[i], bb[i+1]) <= k) {
    // cout << "ok " << k << ' ' << aa[i] << ' ' << bb[i+1] << endl;
    return true;
  }
  if (aa[n-1] <= k) return true;
  if (bb[0] <= k) return true;
  return false;
}

int main() {
  int n, k;
  while (cin >> n >> k) {
    vll v(n);
    REP(i,n) cin >> v[i];
    ll sum = accumulate(ALL(v), 0LL);
    vll factors = calcFactors(sum);

    sort(ALL(factors)); reverse(ALL(factors));
    REP(i,factors.size()) if (ok(v, factors[i], k)) {
      cout << factors[i] << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long n, a, b, c, d;
string s;
 
bool solve() {
  a--; b--; c--; d--;
  bool ch = 0;
  for(int i = a + 1; i <= c; ++i)
    if(s[i] == s[i - 1] && s[i] == '#') return 0;
  for(int i = b + 1; i <= d; ++i)
    if(s[i] == s[i - 1] && s[i] == '#') return 0;
  if(c < d) return 1;
  for(int i = b; i <= d; ++i)
    if(i > 0 && i + 1 < n && s[i - 1] == s[i] &&
       s[i] == s[i + 1] && s[i] == '.')
      ch = 1;
  return ch;
}

int main() {
  cin >> n >> a >> b >> c >> d;
  cin >> s;
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
 

Measured memory_bytes: 3760
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    D = list(input().split())
    for n in count(N):
        ok = True
        for c in str(n):
            if c in D:
                ok = False
                break
        if ok:
            print(n)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 4072
n,a,b = gets.split.map(&:to_i)
s = gets.chomp.split('')

passed_a = 0
passed_b = 0
n.times do |i|
  if s[i] == 'a'
    if passed_a + passed_b < a+b
      passed_a += 1
      puts 'Yes'
    else
      puts 'No'
    end
  elsif s[i] == 'b'
    if passed_a + passed_b < a+b && passed_b+1 <= b
      passed_b += 1
      puts 'Yes'
    else
      puts 'No'
    end
  else
    puts 'No'
  end
end

Measured memory_bytes: 9852
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[N],pos[N],num[N],top,ans;
bool check(int ans)
{
	top=0;
	for (int i=2;i<=n;i++)
	if (a[i]<=a[i-1])
	{
		int x=a[i];
		while (top&&pos[top]>x) top--;
		while (top&&pos[top]==x&&num[top]==ans) top--,x--;
		if (x==0) return 0;
		else if (pos[top]<x) {pos[++top]=x,num[top]=2;if (ans==1) return 0;}
		else num[top]++;
	}
	return 1;
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	int l=1,r=n;
	while (l<=r)
	{
		int mid=l+r>>1;
		if (check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
	while(kbd.hasNext()){
	    int ml = kbd.nextInt();
	    int bowl = kbd.nextInt();
	    if(ml!=0 && bowl!=0){
		int[] m = new int[ml];
		solve(bowl, m);
	    }
	}
    }

    static void solve(int bowl, int[] m){
	int t = 0;
	for(int i=1; i<=1000000; i++){
	    if(check(bowl, m)) break;
	    else if(bowl==0){
		bowl = m[t];
		m[t] = 0;
		t = (t+1)%m.length;
	    }
	    else {
		bowl -= 1;
		m[t] +=1;
		t = (t+1)%m.length;
	    }
	}
	for(t=0; m[t]==0; t++);
	System.out.println(t);
    }

    static boolean check(int bowl, int[] m) {
	int c = 0;
	for(int i=0; i<m.length; i++){
	    if(m[i]>0) c++;
	}
	if(bowl==0 && c==1) return true;
	return false;
    }
}

Measured memory_bytes: 12000
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int k, a, b;
	long long c = 1;
	cin >> k >> a >> b;



	auto x = min(k, a - 1);
	k -= x;
	c += x;

	if (c >= a && b > a + 2) {
		c += (long long)k / 2 * (b - a);
		k %= 2;
	}
	c += k;



	cout << c << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n; scanf("%d",&n);
  while(n --> 0){
    int m, p; scanf("%d",&m);
    int d = 0, u = 0;
    REP(i,m){
      int t,f; scanf("%d",&t);

      if(i != 0){
	f = t - p;
	if(f < 0) d = max(d, -f);
	else      u = max(u,  f);
      }

      p = t;
    }
    printf("%d %d\n",u,d);
  }
  return 0;
}

Measured memory_bytes: 0