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

typedef long long ll;
static const ll INF = 1ll<<60;
static const ll MOD = 1e9+7;

vector<int> ans;
int N;

void calc(){
    for(int x=1; x<=sqrt(N); x++){
        for(int y=1; y<=sqrt(N); y++){
            for(int z=1; z<=sqrt(N); z++){
                int n = x*x + y*y + z*z + x*y + y*z + z*x; 
                if(n > N) continue;
                ans[n-1]++;
            }
        }
    }
}

int main(){
    cin>>N;
    ans.resize(N+100);
    for(int i=0; i<=N; i++) ans[i] = 0;
    calc();

    for(int i=0; i<N; i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    ll cake[n][3], ans = -1LL;
    rep(i, n) {
        rep(j, 3) {
            cin >> cake[i][j];
        }
    }

    for(int b = 0; b < (1 << 3); b++) {
        ll a[n] = {};
        ll sum = 0;

        rep(i, n) {
            rep(j, 3) {
                if( b & (1 << j) ) {
                    a[i] += -cake[i][j];
                }
                else {
                    a[i] += cake[i][j];
                }
            }
        }

        sort(a, a+n);
        reverse(a, a+n);

        rep(i, m) {
            sum += a[i];
        }

        ans = max(ans, sum);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// 問題名: Railway Connection
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1182&lang=jp
// 所要時間: 100分
// --感想--
// 初めに(現在いる頂点, 直前まで使っていた鉄道会社, その鉄道会社の路線でここまで乗ってきた距離)の組を状態としてダイクストラ法で
// 運賃を最小化する方針で実装したが、時間計算量、空間計算量ともに少し厳しかった。同じ会社の鉄道に乗り続けるほど安くなることから、
// 同じ会社の鉄道の途中で一度降りてまたすぐに乗るような行動も認めてしまっても答えは変わらなく、こう考えて前処理をすると状態を
// 決めるのが頂点だけになることに中々気づけなかった。制約なども見て適切な解法を選択できるようにしたい。

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

typedef complex<double> point;

// 内積
double dot(point a, point b) { return (conj(a) * b).real(); }
// 外積(符号付き面積の2倍)
double cross(point a, point b) { return (conj(a) * b).imag(); }

#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)

int main(){
    vector<point> v;
    double x, y;
    while (scanf("%lf,%lf",&x,&y) != EOF)
        v.pb(point(x,y));
    int n = v.size();
    double ans = 0;
    for (int i = 0; i + 2 < n;i++)
        ans += cross(v[i + 1] - v[0], v[i + 2] - v[0]) / 2;
    cout << setprecision(10) << abs(ans) << endl;
}


Measured memory_bytes: 3264
/** Hien Jeony **/
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define getbit(n,i) ((n>>(i-1))&1)
#define offbit(n,i) (n^(1<<(i-1)))
#define onbit(n,i) (n|(1<<(i-1)))
#define cntone(x) (__builtin_popcount(x))
#define inpstr ({ char k; while((k=getchar())==' ' || k=='\n'); string s=""; s+=k; while((k=getchar())!=' ' && k!='\n') s+=k; s; })
const int mod=1e9+7;
using namespace std;
int n,a[100],b[100],dp[(1<<18)+10][20], res=INT_MAX;
vector<int> _1,_0;
template <typename T> inline void read(T & x)
{
    char c; bool nega=0;
    while((!isdigit(c=getchar()))&&c!='-');
    if(c=='-')
    {
        c=getchar();
        nega=1;
    }
    x=c-48;
    while(isdigit(c=getchar()))
    {
        x=x*10+c-48;
    }
    if(nega) x=-x;
}
template <typename T> void Write(T x) {if (x > 9) Write(x/10); putchar(x%10+48);}
template <typename T> void write(T x) {if (x < 0) {putchar('-'); x = -x;} Write(x);}
int main()
{

    //freopen("h.inp","r",stdin);
    read(n);
    for(int i=1;i<=n;i++)
        read(a[i]);
    for(int i=1;i<=n;i++)
        read(b[i]);
    for(int tt=1;tt<(1<<n);tt++)
        for(int i=1;i<=n;i++)
            dp[tt][i]=1e9;
    for(int i=1;i<=n;i++)
        dp[(1<<(i-1))][i]=0;
    for(int tt=1;tt<(1<<n);tt++){
        _1.clear(); _0.clear();
        for(int i=1;i<=n;i++){
            int bit=getbit(tt,i);
            if(bit==1)
                _1.push_back(i);
            else
                _0.push_back(i);
        }
        int M=_1.size();
        for(int i=0;i<M;i++){
            int x,y;
            if(abs(_1[i]-M)%2==0)
                x=a[_1[i]];
            else
                x=b[_1[i]];
            for(int j=0;j<_0.size();j++){
                if(abs(_0[j]-M-1)%2==0)
                    y=a[_0[j]];
                else
                    y=b[_0[j]];
                if(y<x)
                    continue;
                int cnt=0;
                for(int d=0;d<M;d++)
                    if(_1[d]>_0[j])
                        cnt++;
                int ttm=onbit(tt,_0[j]);
                dp[ttm][_0[j]]=min(dp[ttm][_0[j]],dp[tt][_1[i]]+cnt);
            }
        }
    }
    for(int i=1;i<=n;i++)
        res=min(res,dp[(1<<n)-1][i]);
    if(res==1e9)
        write(-1);
    else
        write(res);
}


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll a, b, k;
  cin >> a >> b >> k;
  for (int i = 0; i < k; ++i) {
    if (i % 2 == 0) {
      if (a % 2 == 1) {
        a--;
      }

      int dec = a / 2;
      b += dec;
      a -= dec;
    } else {
      if (b % 2 == 1) {
        b--;
      }

      int dec = b / 2;
      a += dec;
      b -= dec;
    }
  }

  cout << a << ' ' << b << '\n';
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

void init(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
}

int main() 
{
    init();
    string input;
    cin >> input;

    char before = '\0';
    REP(i, 4){
        if(before == input[i]) {
            cout << "Bad" << "\n";
            return 0;
        }
        before = input[i];
    }
    cout << "Good" << "\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static long dp[][] = new long[100001][2];
    public static long mod = (long)1000000007;

    public static long solve(int src,int constraint,int parent,ArrayList<ArrayList<Integer>> arr){
        if(dp[src][constraint] != -1) return dp[src][constraint];
        long ans = 0;
        long ans1 = 1;
        for(Integer child : arr.get(src)){
            if(child != parent)
            ans1 = (ans1 * solve(child,0,src,arr))%mod;
        }
        ans = (ans + ans1)%mod;
        if(constraint == 0){
            long ans2 = 1;
            for(Integer child : arr.get(src)){
                if(child != parent)
                ans2 = (ans2 * solve(child,1,src,arr))%mod;
            }
            ans = (ans + ans2)%mod;
        }
        return dp[src][constraint] = ans;
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int  n = sc.nextInt();
        ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
        for(int i=0;i<=n;i++){
            arr.add(new ArrayList<Integer>());
        }
        for(int i=0;i<n-1;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            ArrayList<Integer> old = arr.get(a);
            old.add(b);
            arr.set(a,old);
            ArrayList<Integer> old1 = arr.get(b);
            old1.add(a);
            arr.set(b,old1);
        }

        for(int i=0;i<=100000;i++){
            for(int j=0;j<=1;j++){
                dp[i][j] = -1;
            }
        }

        System.out.println(solve(1,0,-1,arr));

    }
}

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

class BinarySearch {
public:
	int n, q;
	vector< int > S, T;
	
	BinarySearch() {}
	
	bool search(int tar) {
		int lb = -1, ub = n;
		
		while (ub - lb > 1) {
			int med = (ub + lb) / 2;
			
			if (S[med] == tar) return true;
			
			if (S[med] < tar) lb = med;
			else ub = med;
		}
		
		return false;
	}
	
	void solve() {
		sort(S.begin(), S.end());
		
		int ans = 0;
		
		for (int i = 0; i < q; ++i) {
			int tar = T[i];
			if (search(tar)) ++ans;
		}
		
		cout << ans << endl;
	}
};

int main() {
	BinarySearch ls;
	
	cin >> ls.n;
	ls.S.assign(ls.n, 0);
	for (int i = 0; i < ls.n; ++i) cin >> ls.S[i];
	
	cin >> ls.q;
	ls.T.assign(ls.q, 0);
	for (int i = 0; i < ls.q; ++i) cin >> ls.T[i];
	
	ls.solve();
}

Measured memory_bytes: 1584
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  int state[N], max_s = 0, A[N];
  vector<pair<int, int> > testimony[N];
  for (int i = 0; i < N; i++){
    cin >> A[i];
    for (int j = 0; j < A[i]; j++){
      int x, y;
      cin >> x >> y;
      testimony[i].push_back(make_pair(x-1, y));
    }
  }
  
  for (int i = 0; i <(1<<N); i++){
    int flg = 0;
    for (int j = 0; j < N; j++){
      if (i & (1<<j)){
        state[j] = 1;
      }else{
        state[j] = 0;
      }
    }
    
    for (int j = 0; j < N; j++){
      if(state[j]==1){
        for (int k = 0; k < (int)testimony[j].size(); k++){
          int x = testimony[j][k].first, y = testimony[j][k].second; 
          if (state[x] != y){
            flg = 1;
            break;
          }
        }
      }
    }

    if(flg==0){
      int s = 0;
      for (int j = 0; j < N; j++){
        s += state[j];
      }
      if (s > max_s) max_s = s;
    }
  }

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


Measured memory_bytes: 3748
#include <stdio.h>

void CountingSort(int *, int *, int);

int n;

int main(){
  int *A;
  int *B;
  int i;

  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  
  for(i=1; i<=n; i++) scanf("%d", &A[i]);

  CountingSort(A, B, 10000);

  for(i=1; i<n; i++) printf("%d ", B[i]);
  printf("%d\n", B[i]);
  
  return 0;
}

void CountingSort(int *A, int *B, int k){
  int i, j;
  int C[k+1];

  for(i=0; i<=k; i++) C[i] = 0;
  for(j=1; j<=n; j++) C[A[j]]++;
  for(i=1; i<=k; i++) C[i] += C[i-1];
  for(j=n; j>=1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

Measured memory_bytes: 16268
class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in xrange(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

uf=UnionFind3(100001)

n = input()
cities = [map(int,raw_input().split(" "))+[i] for i in range(n)]

cities_x = sorted(cities, key=lambda a:a[0])
cities_y = sorted(cities, key=lambda a:a[1])

road = [[cities_x[i+1][0]-cities_x[i][0],cities_x[i][2],cities_x[i+1][2]] for i in range(n-1)]
road +=[[cities_y[i+1][1]-cities_y[i][1],cities_y[i][2],cities_y[i+1][2]] for i in range(n-1)]

sum = 0
for (cost,i,j) in sorted(road):
    if(uf.find(i)!=uf.find(j)):
        uf.union(i,j)
        sum += cost

print sum


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

int N = 0;

bool solve() {
  bool ans = false;
  for (int i = 0; i <= (N / 4); i++) {
    if ((N - (4 * i)) % 7 == 0) {
      ans = true;
    }
  }
  return ans;
}

int main() {
  cin >> N;
  if (solve()) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main(void)
{
	int W,H,x,y,r;
	
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
 
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-') f=-1; ch=nc(); }
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc(); }
	return i*f;
}
 
const int N=52;
int n;
vector <int> e1[N];
vector <int> e2[N];
vector <int> const_point; 
 
typedef set <int> :: iterator it;
 
struct Tree {
	int fa[N];
	set <int> e[N];
	inline void insert(int x,int y) {e[x].insert(y); fa[y]=x;}
	inline bool count(int u,int v) {return e[u].count(v);}
	inline void erase(int u,int v) {e[u].erase(v);}
	inline bool leaf(int u) {return e[u].empty();}
};
 
inline void dfs1(int x,Tree  &t,int f=0) {
	for(auto v:e1[x]) if(v!=f) {
		t.insert(x,v); dfs1(v,t,x);
	}
}
inline void dfs2(int x,Tree &t,int f=0) {
	for(auto v:e2[x]) if(v!=f) {
		t.insert(x,v); dfs2(v,t,x);
	}
}
 
inline int calc_cost(Tree &a,Tree &b) {
	if(const_point.size()==n) return 0;
	for(auto u:const_point)
		for(auto v:a.e[u])
			if(b.count(u,v)) {
				a.erase(u,v);
				b.erase(u,v);
				const_point.push_back(v);
				return calc_cost(a,b);
			}
	for(auto u:const_point)
		for(auto v:b.e[u]) {
			if(a.leaf(v)) {
				a.erase(a.fa[v],v);
				a.insert(u,v); a.fa[v]=u;
				return calc_cost(a,b)+1;
			}
		}
	return 1e9;
}
 
inline int calc(int rt) {
	Tree a; Tree b;
	const_point.clear();
	const_point.push_back(rt);
	dfs1(rt,a); dfs2(rt,b);
	return calc_cost(a,b);	
}
 
inline void erase_edge(int x,int y) {
	e1[x].erase(lower_bound(e1[x].begin(),e1[x].end(),y));
	e1[y].erase(lower_bound(e1[y].begin(),e1[y].end(),x));
}
inline void add_edge(int x,int y) {
	e1[x].push_back(y); e1[y].push_back(x);
	sort(e1[x].begin(),e1[x].end());
	sort(e1[y].begin(),e1[y].end());
}
int main() {
	for(int T=rd();T;T--) {
		n=rd();
		for(int i=1;i<=n;i++) e1[i].clear(), e2[i].clear();
		for(int i=1;i<n;i++) {
			int x=rd(), y=rd();
			e1[x].push_back(y);
			e1[y].push_back(x);
		}
		for(int i=1;i<n;i++) {
			int x=rd(), y=rd();
			e2[x].push_back(y);
			e2[y].push_back(x);
		}
		int ans=1e9;
		for(int i=1;i<=n;i++) sort(e1[i].begin(),e1[i].end()), sort(e2[i].begin(),e2[i].end());
		for(int i=1;i<=n && ans>1;i++) ans=min(ans,calc(i));
		for(int i=1;i<=n && ans>1;i++) {
			if(e1[i].size()==1) {
				int y=e1[i].front();
				erase_edge(y,i);
				for(int j=1;j<=n;j++)
					if(j!=i && j!=y) {
						add_edge(i,j);
						ans=min(ans,1+calc(i));
						erase_edge(i,j); 
					}
				add_edge(y,i);
			}
		}
		cout<<(ans<1e9 ? ans : -1)<<'\n'; 
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n, m, c, a[100][100], b[100];
  cin >> n >> m >> c;
  for(int i=0; i<m; i++){
    cin >> b[i];
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin >> a[i][j];
    }
  }
  int cnt = 0;
  for(int i=0; i<n; i++){
    int tmp = 0;
    for(int j=0; j<m; j++){
      tmp += a[i][j] * b[j];
    }
    if(tmp + c > 0){
      cnt ++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

using namespace std;

const int INF = 1 << 30;

struct edge {
	int cost; //重み(距離)
	int to; //行先の頂点
};

void dijkstra(const int n, const vector<vector<edge>> &G, const int stpoint) {

	//優先キューは最短距離と頂点番号のペア、 距離を降順に並べる
	//優先キューは通常大きい順に出していく。小さい順にする場合下のように書く。
	priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;

	vector<bool> seen(n,false); //訪問完了でtrue
	vector<int> cost(n,INF); //頂点nまでの距離

	cost[stpoint] = 0;
	pq.push(make_pair(0, stpoint));

	while (pq.empty() == false) {

		//ターゲット頂点設定（すでに決定したものの中のどれか）
		pair<int, int> target = pq.top();
		int tnum = target.second; //ターゲット頂点番号
		pq.pop();
		
		seen[tnum] = true;

		//キューに長い距離が既に入っている場合があるのでそれはもうスキップしていい。
		//（あとから短い距離が入ってきた場合優先キューでそれが処理されてるから。）
		if (cost[tnum] < target.first) { continue; } //これの意味が分からない保留

		for (unsigned int j = 0; j < G[tnum].size(); j++) { //ターゲットから繋がる先を全部探す

			int v = G[tnum][j].to; //繋がる先の頂点をvにする

			if (seen[v] == true) { continue; } //もう見たとこ（仲間に入ってる）ならスキップ

			if (cost[v] > cost[tnum] + G[tnum][j].cost) {
				cost[v] = cost[tnum] + G[tnum][j].cost;
				pq.push(make_pair(cost[v], v));
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << (cost[i]<INF? to_string(cost[i]) : "INF") << endl;
	}

}

int main() {

	int v,e,r;
	cin >> v >> e >>r;

	int stpoint = r;

	vector<vector<edge>> G(v);

	int in1, in2, in3;
	for (int i = 0; i < e; i++) {
		cin >> in1 >> in2 >> in3;
		G[in1].push_back({ in3, in2 });
	}

	dijkstra(v,G,stpoint);

	return 0;
}


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



signed main(){
    int n; cin>>n;
    vector<int> a(n);
    int one=0,two=0,four=0;
    rep(i,n){
        cin>>a.at(i);
        if(a.at(i)%2!=0) one++;
        else if(a.at(i)%4==0) four++;
        else two++;
    }
    if(two>=1 and four>=1) cout<<(four*2+two>=a.size()?"Yes":"No")<<endl;
    else if (four>=1) cout<<(four*2+1>=a.size()?"Yes":"No")<<endl;
    else if (two>=1) cout<<(two>=a.size()?"Yes":"No")<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long ll;

int main() {
    int N;
    string S;
    cin >> N >> S;
    bool f[1000], g[11][11], h[11][11];
    rep(i, 1000) f[i] = false;
    rep(i, 11) rep(j, 11) g[i][j] = false;
    g[10][10] = true;
    rep(i, N) {
        int x = S[i] - '0';
        rep(j, 11) rep(k, 11) h[j][k] = false;
        rep(j, 11) {
            rep(k, 11) {
                if (g[j][k]) {
                    h[k][x] = true;
                    if (j < 10 && k < 10) f[j * 100 + k * 10 + x] = true;
                }
            }
        }
        rep(j, 11) rep(k, 11) if(h[j][k]) g[j][k] = true;
    }
    int ans = 0;
    rep(i, 1000) if (f[i]) {
        ans++;
        //cout << i << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
p = [list(map(int, input().split())) for _ in range(n-1)]

ans = [-1] * (n+1)
lw = [[] for i in range(n+1)]
for path in p:
    lw[path[0]].append((path[1],path[2]))
    lw[path[1]].append((path[0],path[2]))

from _collections import deque
q = deque()
ans[1] = 0
q.append(1)
while q:
    r = q.popleft()
    prev = ans[r]
    assert prev >= 0
    for xx in lw[r]:
        nx = xx[0]
        if ans[nx] >= 0:
            continue  # already
        q.append(nx)
        if xx[1] % 2 == 0:
            ans[xx[0]] = ans[r]
        else:
            ans[xx[0]] = 1 - ans[r]

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

Measured memory_bytes: 53100
#input 
N,K=map(int,input().split())
S=input() #str

#s[j-1]=0,s[j]=1もしくはs[j-1]=1,s[j]=0になっているjをリストにしたものをiとする（スタート地点かつエンド地点候補）
i=[0]
for j in range(1,len(S)):
    if S[j]!=S[j-1]:
        i.append(j)

#スタート地点候補iに対して、
#s[i[m]]==1の場合、変更可能な変化点は2K個なので,その次の変化点までが求める文字数となり,X=i[2K+1+m]-i[m]
#s[i[m]]==0の場合、変更可能な変化点は2K-1個なので,その次の変化点までが求める文字数となり,X=i[2K+m]-i[m]

X=[]
for m in range(len(i)):
    if S[i[m]]=='1':
        #はみ出している->右方向は全て置換可能
        if 2*K+1+m >= len(i):
            X.append(N-i[m])
        else:
            X.append(i[2*K+1+m]-i[m])

    elif S[i[m]]=='0':
        #はみ出している->右方向は全て置換可能
        if 2*K+m >= len(i):
            X.append(N-i[m])
        else:
            X.append(i[2*K+m]-i[m])

print(max(X))


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

int main() {
    long long X, Y; cin >> X >> Y;
    long long ans = abs(abs(X) - abs(Y));
    if (abs(X) > abs(Y)) {
        if (X < 0) X += ans;
        else {
            X -= ans;
            X *= -1;
            ans++;
        }
    } 
    else {
        if (X < 0) {
            X -= ans;
            ans++;
            X *= -1;
        }
        else X += ans;
    }
    
    if (X * -1 == Y && (X != 0 && Y != 0)) ans++;
    cout << ans << endl;
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={0,0,0,1,-1},dy[]={-1,1,0,0,0};

int d[11][11], b[11][11], a[11][11];

void flip(int x, int y) {
  a[y][x]=1;
  for(int i=0; i<5; i++) {
    b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
  }
}

int main() {

  int n;
  cin>> n;
  while(n--) {
    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cin>> d[i][j];
      }
    }

    for(int i=0; i<1024; i++) {
      memset(a, 0, sizeof(a));
      memcpy(b, d, sizeof(d));
      for(int j=0; j<10; j++) {
	if((i>>j) & 1) flip(j, 0);
      }

      for(int j=1; j<10; j++) {
	for(int k=0; k<10; k++) {
	  if(b[j-1][k]) flip(k, j);
	}
      }

      int cnt=0;
      for(int j=0; j<10; j++) {
	if(b[9][j]) {
	  cnt=1; break;
	}
      }
      
      if(cnt==0) break;
    }

    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cout << a[i][j]<< (j==9 ? "" : " ");
      }
      cout<< endl;
    }
  }
}

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

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

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

int main(void){
	ll b,i,l,f,p,q;
	cin >> b;
	while(b){
		b *= 2;
		for(i=1ll; i*i<=b; ++i){
			if(b%i){
				continue;
			}
			p = i;
			q = (b/i)-1;
			if(q<p){
				continue;
			}else if((q-p)%2){
				continue;
			}
			l = (q-p)/2+1;
			f = i;
		}
		cout << l << " " << f << endl;
		cin >> b;
	}
	return 0;
}



Measured memory_bytes: 3080
def use_guard():
    same_num_count = 0
    firstlist_num = int(input())
    firstlist = set(input().split())
    secondlist_num = int(input())
    secondlist = set(input().split())

    for n in secondlist:
        if firstlist.__contains__(n):
            same_num_count += 1

    print(same_num_count)

def use_set():
    input()
    firstlist = set(input().split())
    input()
    secondlist = set(input().split())
    same_num_count = len(firstlist.intersection(secondlist))
    print(same_num_count)

use_set()


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

vector<vector<int>> adj;
vector<int> order, comp;
vector<bool> vis;

void dfs(int u, bool second_run = false){
    vis[u] = 1;
    if (second_run) comp.push_back(u);
    for (int v: adj[u]){
        if (!vis[v])
            dfs(v, second_run);
    }
    if (!second_run) order.push_back(u);
}

void scc(){
    int n, m;
    cin >> n >> m;
    // ^ INITIALISE n and m
    int ans = -1;
    adj.assign(n, {});
    order.clear();
    comp.clear();
    for (int i = 0; i < m; ++i){
        int u, v; // decrement u and v if necessary
        cin >> u >> v;
        --u, --v;
        // ^ INITIALISE u and v
        adj[u].push_back(v);
        adj[v].push_back(u);
        // ^ THINK: directed vs undirected?
    }
    vis.assign(n, 0);
    for (int i = 0; i < n; ++i){
        if (!vis[i])
            dfs(i);
    }
    vis.assign(n, 0);
    for (int i = 0; i < n; ++i){
        int u = order[n - 1 - i];
        if (!vis[u])
            dfs(u, true);
        // comp now contains vertices of a SCC
        ans = max(ans, (int) comp.size());
        comp.clear();
    }
    cout << ans << '\n';
}

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

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

int main(){
    int i, n, t;
    cin >> n;
    int a[2][n];
    for(i=0; i<n; i++){
        cin >> t;
        if(i == 0){
            a[0][i] = t;
        }else{
            a[0][i] = t + a[0][i-1];
        }
    }
    for(i=0; i<n; i++){
        cin >> t;
        if(i == 0){
            a[1][i] = t + a[0][i];
        }else{
            a[1][i] = max(a[0][i], a[1][i-1]) + t;
        }
    }
    cout << a[1][n-1];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <fstream>
#include <set>
#include <cmath>
#include <array>
#include <iomanip>


using namespace std;

void No() {
    cout << "Impossible\n";
    exit(0);
}


void Yes() {
    cout << "Possible\n";
    exit(0);
}
int main(void) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int h, w;
    cin >> h >> w;
    vector<vector<int>> v(h);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;

            if (c == '#') {
                v[i].push_back(j);
            }
        }
    }
    int mx_prev = -1;
    for (auto& cur : v) {
        if (cur.size() == 0) {
            No();
        }
        if (!(cur.back() - *cur.begin() == (int)cur.size() - 1)) {
            No();
        }
        if (mx_prev > *cur.begin()) {
            No();
        }
        mx_prev = cur.back();
    }
    if (v[0][0] != 0) {
        No();
    }
    if (v[h - 1].back() != w - 1) {
        No();
    }
    Yes();
}


Measured memory_bytes: 256
N = int(input())
D, X = map(int, input().split())
A_list = []
ans = 0
for i in range(N):
    cnt = 0
    day = 1
    A = int(input())
    while(D>=day):
        ans += 1
        cnt += 1
        day = cnt*A+1
print(ans+X)

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

int main() {
  int n, a, max, min;
  std::cin >> n;
  
  max = 0; min = 10000000000;
  for (int i = 0; i < n; i++) {
    std::cin >> a;
    if (a > max) {
      max = a;
    }
    if (a < min) {
      min = a;
    }
  }
  
  std::cout << max - min << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

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

int n,m,a[110],vis[110];

int main()
{
    n=read();m=read();
    rep(i,1,m)
    {
        int len=read();
        rep(j,1,len)
        {
            int x=read();vis[x]=1;
        }
    }
    int ans=0;
    rep(i,1,n) ans+=(!vis[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n;
  string s[110], l[110];
  
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s[i];
    if(s[i] == "goto"){
      cin >> l[i];
      l[i] = l[i].substr(0,l[i].size()-1);
    }else{
      s[i] = s[i].substr(0,s[i].size()-1);
    }
  }

  vector< vector<pii> > g(n+1);
  for(int i=0;i<n;i++){
    if(s[i]=="goto"){
      g[i].push_back(pii(1,i+1));
    }else{
      g[i].push_back(pii(0,i+1));
    }
  }

  for(int i=0;i<n;i++){
    if(s[i] == "goto"){
      for(int j=0;j<n;j++){
	if(l[i] == s[j]){
	  g[i].push_back(pii(0,j));
	}
      }
    }
  }

  vector<int> d(n+1,1e9);
  d[0] = 0;
  deque<int> q;
  q.push_back(0);

  while(q.size()){
    int v = q.front(); q.pop_front();
    if(v == n)break;

    for(int i=0;i<(int)g[v].size();i++){
      int u = g[v][i].second, c = g[v][i].first;
      if(c == 0){
	if(d[u] > d[v]){
	  d[u] = d[v];
	  q.push_front(u);
	}
      }else{
	if(d[u] > d[v]+1){
	  d[u] = d[v] + 1;
	  q.push_back(u);
	}
      }
    }
  }
  cout << d[n] << endl;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	bool flag = false;
	while(n!=0)
	{
		int x = n%10;
		if(x == 7)flag = true;
		n/=10;
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3760
from collections import deque
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7

cs = [0]*(1 << N)
used = [0]*(1 << N)
s = (1 << N) - 1
que = deque([(s, 0)])
cs[s] = 1
used[s] = 1

while que:
    state, c = que.popleft()
    v = cs[state] % MOD

    for i in range(N):
        if state & (1 << i) and A[c][i]:
            n_state = state ^ (1 << i)
            cs[n_state] += v
            if not used[n_state] and c+1 < N:
                que.append((n_state, c+1))
                used[n_state] = 1
print(cs[0] % MOD)

Measured memory_bytes: 122460
#include<bits/stdc++.h>
using namespace std ;
char p[10005];

int main()
{
	int  N , K , X , Y ,a = 0;
	cin >> N >> K >> X >> Y ;
	if ( N > K )
	{
		a = K * X + ( N - K ) * Y ;
	}
	else
	{
		a =	N * X ;
	}
	cout << a << endl ;
	return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
const int O=2e5+10;
const ll inf=2e9;
struct Data{
	int x,y;
	il bool operator<(Data A)const{
		return x<A.x;
	}
}a[O];
il void Max(int&x,int y){if(x<y)x=y;}
il void Min(int&x,int y){if(x>y)x=y;}
il int gi(){
    int o=0,fl=1;char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')fl=-1,ch=getchar();
    while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
    return fl*o;
}
int n,bmax,bmin,rmax,rmin,maxn[O],minl[O],ans2=inf;
ll ans1;
int main(){
	n=gi();
	bmax=rmax=-1;bmin=rmin=inf;
	for(int i=1;i<=n;++i){
		int x=gi(),y=gi();
		if(x>y)swap(x,y);
		a[i]=(Data){x,y};
		Max(bmax,y);Min(bmin,y);
		Max(rmax,x);Min(rmin,x);
	}
	ans1=1ll*(bmax-bmin)*(rmax-rmin);
	sort(a+1,a+n+1);bmin=rmin;
	maxn[1]=minl[1]=a[1].y;
	for(int i=2;i<=n;++i){
		maxn[i]=max(maxn[i-1],a[i].y);
		minl[i]=min(minl[i-1],a[i].y);
		if(i^n)Min(ans2,max(maxn[i],a[n].x)-min(minl[i],a[i+1].x));
	}
	printf("%lld\n",min(ans1,1ll*(bmax-bmin)*ans2));
//	printf("%lld %lld",ans1,1ll*(bmax-bmin)*ans2);
	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	int a = n/1000,b = (n/100)%10, c = ((n/10)%10), d = n%10;
	int ans = a;
	for(int i =0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				string s = "";
				if(i==0){
				   ans-=b;
				   s+='-';
				} 
				else{
				  ans+=b;
				  s+='+';
				} 
				
				if(j==0) {
					ans-=c;
					s+='-';
				}
				else{
				  ans+=c;
				  s+='+';
				} 
				
				if(k == 0){
				   ans-=d;
				   s+='-';
				} 
				else{
					ans+=d;
					s+='+';
				}
				
				if(ans == 7){
					cout<<a<<s[0]<<b<<s[1]<<c<<s[2]<<d<<"=7"<<"\n";
					return 0;
				}
		     ans = a;
			}
		}
	}
	
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}

int64_t gcd(int64_t x, int64_t y) {
	while (x && y) {
		if (x > y) x %= y;
		else y %= x;
	}
	return x + y;
}
int64_t lcm(int64_t x, int64_t y) {
	return x / gcd(x, y) * y;
}

int main() {
	int n = ri();
	int m = ri();
	int a[n];
	for (auto &i : a) i = ri() / 2;
	int gu = 0, ki = 0;
	for (int i = 0; i < n; i++) (a[i] % 2 ? ki : gu)++;
	int64_t lc = 1;
	for (int i = 0; i < n; i++) {
		lc = lcm(lc, a[i]);
		if (lc > 1000000000) {
			puts("0");
			return 0;
		}
	}
	for (int i = 0; i < n; i++) if (lc / a[i] % 2 == 0) {
		std::cout << 0 << std::endl;
		return 0;
	}
	std::cout << ((m / lc + 1) / 2) << std::endl;
	
	return 0;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 53;

LL k;
int n;
LL a[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	cin >> k;
}

void work ()
{
	// main work

	n = 50;

	LL divi = k / n;
	int mod =  k % n;
	lpi ( i, 1, n ) a[i] = n - 1 + divi;

	LL tar = n - 1 + divi;

	lpi ( i, 1, mod ){
		a[i] = tar + n - ( mod - 1 );
	}

	lpi ( i, mod+1, n ){
		a[i] = tar - mod;
	}

	cout << n << endl;
	lpi ( i, 1, n ) cout << a[i] << " ";
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
    int n; cin >> n;
    unordered_map<string, int> m;
    for (int i = 0; i < n; ++i)
    {
        string s; cin >> s;
        ++m[s];
    }
    for (auto i : {"AC", "WA", "TLE", "RE"})
    {
        cout << i << " x " << m[i] << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    vector<int> x(5, -1);
    rep(i, 5) cin >> x.at(i);
    rep(i, 5){
        if(x.at(i)==0){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> a(n,0),b(k+k,0);
    for(int i = 0; i<n; i++)
        scanf("%d",&a[i]);
    sort(a.begin(),a.end());
    ll sum = 0;
    for(int i = 0; i<n; i++)
        sum+=a[i];
    if(sum<k)
        printf("%d\n",n);
    else{
        int s = 0,e=n-1,ans = -1;
        while(s<=e){
            int m = (s+e)/2;
            if(a[m]>=k){
                ans = m;
                e = m-1;
                continue;
            }
            fill(b.begin(),b.end(),0);
            b[0] = 1;
            for(int i = 0; i<n; i++){
                if(i==m||a[i]>=k)
                    continue;
                for(int j = k+k-1; j>=0; j--){
                    if(b[j]&&j+a[i]<k+k)
                        b[j+a[i]] = 1;
                }
            }
            bool found = false;
            for(int i = k-a[m]; i<k; i++){
                if(b[i]){
                    found = true;
                    break;
                }
            }
            if(found){
                ans = m;
                e = m-1;
            }else
                s = m+1;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
outlist = [int(input()) for i in range(m)]


def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return (a)


def stepcount(x, y):
    if y - x <= 1:
        return 1
    else:
        return Fib(y - x)

if m != 0:
    answer = Fib(outlist[0] - 1)

    for i in range(m - 1):
        answer *= stepcount(outlist[i] + 1, outlist[i + 1] - 1)
        answer = answer % 1000000007

    answer = (answer * stepcount(outlist[m - 1] + 1, n)) % 1000000007

    for i in range(m - 1):
        if outlist[i + 1] - outlist[i] == 1:
            answer = 0
else:
    answer = Fib(n)

print(answer)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x>>y;
	if(x+y>=10) cout<<"error"<<endl;
	else cout<<x+y<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Array a(n);
	REP(i,n) cin>>a[i];
	ll sum=0;
	REP(i,n) sum+=a[i];
	if(sum%(n*(n+1)/2)!=0){
		cout<<"NO"<<en;
		return;
	}
	ll m=sum/(n*(n+1)/2);//操作回数

	bool flag=true;
	ll con=0;
	//cout<<m<<en;
	REP(i,n){
		ll b = a[(i+1)%n]-a[i];
		//cout<<i<<" "<<b<<en;
		if(b>m){
			flag = false;
		}else{
			ll x=m-b;
			if(x%n!=0) flag=false;
			con+=x/n;
		}
	}
	if(con!=m) flag=false;
	
	cout<<(flag?"YES":"NO")<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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;
}

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

	int ans = max(max(a + b, a - b), a * b);

	cout << ans << endl;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    ll d[n][n];
    rep(i,n) rep(j,n) cin >> d[i][j];

    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(d[i][j] > d[i][k]+d[k][j]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    rep(k,n){
        rep(i,n){
            if(i == k) continue;
            rep(j,n){
                if(j == k || i == j) continue;
                if(d[i][j] == d[i][k]+d[k][j]){
                    d[i][j] = INF;
                }
            }
        }
    }
    ll ans = 0;
    rep(i,n){
        for(int j=i+1; j<n; j++){
            if(d[i][j] != INF) ans += d[i][j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4312
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int n, k; cin >> n >> k;
    int h[100100];
    int ans = 0;
    rep(i, n) {
        cin >> h[i];
        if(h[i] >= k) ans ++;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cmath>
#include <numeric>

using ll = long long;
using std::cout;
using std::cin;
using std::endl;

const ll max = 100005;
typedef enum{ UNDEF=0, PRIME, NONP} Prime;

bool is_prime(ll num){
    static Prime prime_table[max] = {NONP,NONP,PRIME,PRIME};
    if(prime_table[num]!=UNDEF){
        return (prime_table[num]==PRIME);
    }
    ll eratos_max = (ll)(std::sqrt(num))+1;
    for(int i=2; i<=eratos_max; i++){
        if(num%i==0){
            prime_table[num] = NONP;
            return false;
        }
    }
    prime_table[num] = PRIME;
    return true;
    
}

int main(){
    ll q;
    cin >> q;
    std::vector<ll> l(q),r(q);
    for(int i=0; i<q; i++){
        cin >> l[i] >> r[i];
    }
    std::vector<ll> like2017(max);
    std::vector<ll> like2017_sum(max+1);
    like2017_sum[0] = 0;
    for(int i=1; i<max; i++){
        // cout << i << " " << is_prime(i) << " " << is_prime((i+1)/2) << endl;
        if( i%2!=0 && is_prime(i) && is_prime((i+1)/2) ){
            like2017[i] = 1; 
        }else{
            like2017[i] = 0; 
        }
    }
    like2017_sum[0] = 0;
    for(int i=0; i<max; i++){
        like2017_sum[i+1] = like2017_sum[i]+like2017[i];
    }

    
    // for(auto e: like2017){
    //     cout << e << " ";
    // }
    // cout << endl;
    // for(auto e: like2017_sum){
    //     cout << e << " ";
    // }
        
    for(int i=0; i<q; i++){
        cout << like2017_sum[r[i]+1] - like2017_sum[l[i]] << endl;
    }
    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;

    string s;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> s;
            if(s == "snuke"){
                cout << (char)('A' + j) << i+1 << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#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 = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    double R;
    cin >> R;
    cout << 2 * R * 3.14159265 << endl;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

int main(void){
    int N; cin >> N;
    vector<int> X(N); for(int i = 0; i < N; i++) cin >> X[i];
    
    int minimum_cost = 99999999;
    int position=0;
    for(int i = 1; i <= 100; i++){
        int cost = 0;
        for(int j = 0; j < N; j++){
            cost += pow((X[j] - i), 2);
        }
        if (cost < minimum_cost){
            minimum_cost = cost;
            position = i;
        }
    }
    cout << minimum_cost << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    for (int i = 1; i <= 9; i++)
    {
        if (N % i == 0 && N / i <= 9)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())

n,k=ma()
a=lis()
l,h=0,max(a)
while(l+1<h):
    m=(l+h)//2
    c=0
    for i in a:
        c+=ceil(i/m)-1
    if(c<=k):
        h=m
    else:
        l=m
print(h)
        
        
    


Measured memory_bytes: 109852
def readinput():
    n=int(input())
    nList=[]
    for _ in range(n+1):
        nList.append([])
    for _ in range(n):
        l=list(map(int,input().split()))
        nList[l[0]]=l[2:]
    return n,nList

WHITE=0
GRAY=1
BLACK=2
color=[]
d=[]
f=[]
_time=0

def dfs(u,nList):
    global color
    global d
    global f
    global _time

    S=[]

    if(color[u]==WHITE):
        S.append(u)
        color[u]=GRAY
        _time+=1
        d[u]=_time

    while(len(S)>0):
        u=S[-1]
        t=next(u,nList)
        if(t!=-1):
            if(color[t]==WHITE):
                S.append(t)
                color[t]=GRAY
                _time+=1
                d[t]=_time
        else:
            S.pop()
            color[u]=BLACK
            _time+=1
            f[u]=_time

def next(u,nList):
    global color
    for t in nList[u]:
        if color[t]==WHITE:
            return t
    else:
        return -1

def main(n,nList):
    global color
    global d
    global f

    color=[WHITE]*(n+1)
    d=[0]*(n+1)
    f=[0]*(n+1)

    for i in range(1,n+1):
        dfs(i,nList)
    for i in range(1,n+1):
        print('{} {} {}'.format(i,d[i],f[i]))

if __name__=='__main__':
    n,nList=readinput()
    main(n,nList)



Measured memory_bytes: 5616
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, L;
  cin>>N>>L;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  int index;
  bool can = false;
  for(int i=0;i<N-1;++i) {
    if(A[i]+A[i+1]>=L) {
      index = i+1;
      can = true;
      break;
    }
  }
  if(!can) {
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  for(int i=1;i<index;++i) cout<<i<<endl;
  for(int i=N-1;i>=index;--i) cout<<i<<endl;
}



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

int main() { 
  int n;
  cin >> n;
  
  int min = 100000000;
  

  vector<int> w(n);

  
  for (int i=0;i<n;i++){
    cin >> w.at(i);
  }

  for (int t=1;t<n;t++){
    int s1=0, s2=0;
    
    for(int i=0;i<n;i++){
      if(i<=t){s1 += w.at(i);}
      else{s2 += w.at(i);}
    }
    
    if (min > abs(s1-s2)) min = abs(s1-s2) ;
  
  }

  cout << min << endl;

  return 0;
}

Measured memory_bytes: 256