akhauriyash/Code-Regression huggingface dataset:
/*Lucky_Glass*/
#include<map>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5;
const ll MOD=ll(1e9)+7;
int n;
ll ans,col;
vector<int> lnk[N+5];
void DFS(int u,int pre,int dep){
	int cnt=0;
	for(int it=0;it<lnk[u].size();it++){
		int v=lnk[u][it];
		if(v==pre) continue;
		if(dep==1) ans=ans*max(0ll,col-1-cnt)%MOD;
		if(dep>=2) ans=ans*max(0ll,col-2-cnt)%MOD;
		DFS(v,u,dep+1);
		cnt++;
	}
}
int main(){
	scanf("%d%lld",&n,&col);
	for(int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		lnk[u].push_back(v);
		lnk[v].push_back(u);
	}
	ans=col%MOD;
	DFS(1,0,1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11520
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto xs = readints;
    writeln(xs[0] ^ xs[1] ^ xs[2]);
}


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

int solve(string s){
    string left = "qwertasdfgzxcvb";
    map<char,bool> m;
    for(int i = 0;i < left.size();i++){
        m[left[i]] = true;
    }
    int res = 0;
    bool hand = m[s[0]];
    for(int i = 1;i < s.size();i++){
        if(hand != m[s[i]]){
            hand = !hand;
            res++;
        }
    }
    return res;
}

int main(){
    string s;
    while(true){
        cin >> s;
        if(s == "#")return 0;
        cout << solve(s) << endl;
    }
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <cmath>
#define _USE_MATH_DEFINES
#define EPS 1e-10
using namespace std;

int main(void) {
	double r;
	cin >> r;

	printf("%.6f %.6f\n", M_PI*r*r+EPS, M_PI*2.0*r+EPS);
	return 0;
}

Measured memory_bytes: 1240
#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;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll h[200001], a[200001], seg[800005];
ll merge(ll a, ll b) {
	return max(a, b);
}
ll query(ll pos, ll l, ll r, ll l1, ll r1) {
	if(l > r || r < l1 || l > r1) {
		return 0;
	}
	if(l1  <= l && r <= r1) {
		return seg[pos];
	}
	ll mid = (l + r) / 2;
	return merge(query(2*pos + 1, l, mid, l1 , r1), query(2*pos + 2, mid + 1, r, l1, r1));
}
void update(ll pos, ll l, ll r, ll x, ll val) {
	if(l > r || r < x || l > x) {
		return;
	}
	if(l == r) {
		seg[pos] = val;
		return; 
	}
	ll mid = (l + r) / 2;
	update(2*pos + 1, l, mid, x, val);
	update(2*pos + 2, mid + 1, r, x, val);
	seg[pos] = merge(seg[2*pos + 1], seg[2*pos + 2]);
	return;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, ans = 0;
    cin>>n;
    for(i = 0; i < n; i++) {
    	cin>>h[i];
    }
    for(i = 0; i < n; i++) {
    	cin>>a[i];	
    }
    for(i = 0; i < n; i++) {
    	ll cur = a[i] + query(0, 0, n, 0, h[i] - 1);
    	ans = max(ans, cur);
    	update(0, 0, n, h[i], cur);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 9728
class UnionFind
  def root(a)
    $parent[a] == a ? a : ($parent[a] = root($parent[a]))
  end

  def unite(a,b)
    x = root(a)
    y = root(b)
    if x != y then a < b ? $parent[y] = x : $parent[x] = y
    end
  end

  def same(a, b)
    a = root(a)
    b = root(b)
    if $parent[a] == $parent[b] then puts 1
    else puts 0
    end
  end
end

n, q = gets.split.map(&:to_i)
$parent = Array.new(n){ |i| i }
uf = UnionFind.new
q.times do
  cmd, x, y = gets.split.map(&:to_i)
  if cmd == 0 then uf.unite(x, y)
  else uf.same(x, y)
  end
end

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    for (int i = 0; i < s.size(); i++)
    {
        cout<<"x";
    }
    cout<<endl;
    
    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
    for(int i = 0; i < n; i++)
    {
        cout << a[i];
        for(int j = i; j < n; j++)
        {
            cout << b[i];
            break;
        }
    }
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;


class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		final int NUM = 28;
		final int NUMs = 30;
		HashSet<Integer> h = new HashSet<Integer>();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for(int i = 0; i < NUM ;i++){
			h.add(Integer.parseInt(in.readLine()));
		}
		for(int i= 0;i < NUMs ;i++){
			if(!h.contains(i+1)){
				System.out.println(i+1);
			}
		}
	}

}

Measured memory_bytes: 16872
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=list(accumulate(a))
B=list(accumulate(b))

ans=0
for i in range(n):
    if k-A[i]>=0:
        c = bisect.bisect_right(B, k-A[i])
        ans = max(i+c+1,ans)
print(max(ans,bisect.bisect_right(B, k)))


Measured memory_bytes: 126828
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000
#define mod 1000000007
const int N = 210;

long long solve(long long a,long long b){
	if(a > b) swap(a,b);
	if(a == 0) return 0;
	b *= 2 , a *= 2;
	if(b % a == 0){
		long long res = ((b / a) * a * 2 - a);
		return res / 2;
	}
	long long res = ((b / a) * a * 2)  + solve(b % a , a);
	return res / 2;
}

int main(){
	long long n , x;
	cin >> n >> x;
	long long ans = n + solve(x , n - x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

const int64 mod = 1e9 + 7;

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

    int N;
    std::cin >> N;

    std::vector<int> C(N);
    for (int i = 0; i < N; i++) {
        std::cin >> C[i];
    }
    std::vector<int> right_neighbor(N, -1);
    std::map<int, int> record;

    for (int i = N - 1; i >= 0; i--) {
        if (record.count(C[i]) > 0) {
            right_neighbor[i] = record[C[i]];
        }
        record[C[i]] = i;
    }
    std::vector<int64> dp(N, 0);
    dp[0] = 1;

    for (int i = 0; i < N - 1; i++) {
        (dp[i + 1] += dp[i]) %= mod;

        // std::cerr << "i: " << i << " " << dp[i] << std::endl;

        if (right_neighbor[i] >= 0 and right_neighbor[i] != i + 1) {
            (dp[right_neighbor[i]] += dp[i]) %= mod;
        }
    }
    /*
    for (int i = 0; i < N; i++) {
        std::cerr << "i: " << i << " " << dp[i] << std::endl;
    }
    */

    std::cout << dp[N - 1] << std::endl;

    return 0;
}


Measured memory_bytes: 12800
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cstring>

#define pb push_back
#define mp make_pair
#define l(x) x << 1
#define r(x) x << 1 | 1
#define scan(x) do {while((x=getchar())<'0') ; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0') ; } while(0)
char _;
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<float, float> pff;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

int x, a, b;
    
int main() {
    scanf("%d %d %d", &x, &a, &b);
    printf("%c\n", abs(x - a) < abs(x - b) ? 'A' : 'B');
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
    ll w,a,b,z=0;
    cin >> w >> a >> b;
    if (a<b){
        cout << max(b-(w+a),z) << endl;
    }else{
        cout << max(a-(w+b),z) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

if __name__ == '__main__':
    n, m, q = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    lst = []
    for i in range(q):
        a,b,c,d = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        lst += [[a-1,b-1,c,d]]
    lst = sorted(lst, key=lambda l:-l[3])

    score = 0
    seq = [1 for i in range(n)]
    seq[-1] = 0
    die = False
    # for i in range((n+1)*(m+1)):
    while True:
        tmpscore = 0
        seq[-1] += 1
        for j in reversed(range(len(seq))):
            if seq[j] == m + 1:
                if j-1 == -1:
                    die = True
                else:
                    seq[j-1] += 1
        if die:
            break
        for j in range(len(seq)):
            if seq[j] == m+1:
                seq[j] = seq[j-1]
        # print(seq)
        # seq完成
        for a, b, c, d in lst:
            if seq[b] - seq[a] == c:
                tmpscore += d
        if tmpscore > score:
            score = tmpscore
    print(score)


Measured memory_bytes: 9276
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String c1 = reader.readLine();
            final String c2 = reader.readLine();

            System.out.println(
                c1.charAt(0) == c2.charAt(2)
                    && c1.charAt(1) == c2.charAt(1)
                        && c1.charAt(2) == c2.charAt(0) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define faster ios_base::sync_with_stdio(0);
#define faster_tie cin.tie(0);
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define NL cout<<'\n'

ll n,k,x;
vector<ll>height;
ll sol[110000];

ll solve(ll x)
{
    if(x==1)
    {
        return 0;
    }
    if(sol[x]!=-1)return sol[x];
    ll a=INT_MAX;

    for(ll i=x-1;i>x-1-k;i--)
    {
        if(i==0)break;
        a=min(a,solve(i)+abs(height[i]-height[x]));
    }
    sol[x]=a;
    return a;

}


int main()
{
  
  	memset(sol,-1,sizeof sol);
    cin>>n>>k;
    height.push_back(-1);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        height.push_back(x);
    }

    ll ans=solve(n);
    cout<<ans;



    return 0;
}


Measured memory_bytes: 8308
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define all(c) (c).begin(), (c).end()
#define debug(x) cerr << #x << " = " << x << endl
#define eb emplace_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  vector<int> pw2(40);
  pw2[0] = 1;
  rep(i,1,40) pw2[i] = 2*pw2[i-1];

  int n;
  cin>>n;
  vector<int> v(n);
  unordered_map<int,int> m;
  rep(i,0,n) {
    cin>>v[i];
    ++m[v[i]];
  }
  sort(all(v));
  reverse(all(v));
  int cnt = 0;
  for(int a:v) {
    if(--m[a] < 0) continue;
    for(int i = 32; i>=0; --i) {
      auto r = m.find(pw2[i] - a);
      if(r != m.end() && r->second > 0) {
        ++cnt;
        --m[pw2[i]-a];
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

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

  double answer;
  if (N % 2 == 0) answer = 1.0 / 2.0;
  else answer = (N + 1.0) / 2.0 / N;

  cout << answer << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int miku = input.nextInt();
		int gumi = input.nextInt();
		
		if(miku>=10) {
			System.out.println(gumi);
		}
		else {
			System.out.println(100*(10-miku)+gumi);
		}
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

string s, t;
vector<Int> dp;

bool possible(){
	bool f[30] = {};
	for(auto i:s)
		f[i-'a'] = true;
	for(auto i:t)
		if(!f[i-'a'])
			return false;
	return true;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s >> t;
	if(!possible()){
		cout << -1 << "\n";
		return 0;
	}
	s += s + s;
	vector<vector<Int>> a(s.size(), vector<Int>(30, s.size()));
	for(size_t i=0; i<s.size(); ++i)
		a[i][s[i]-'a'] = i;
	for(Int i=s.size()-1; i>0; --i)
		for(Int j=0; j<26; ++j)
			a[i-1][j] = min(a[i-1][j], a[i][j]);
	dp.resize(t.size());
	for(size_t i=0; i<s.size(); ++i)
		if(s[i] == t[0]){
			dp[0] = i;
			break;
		}
	for(size_t i=1; i<t.size(); ++i){
		Int x = dp[i-1] % (s.size() / 3);
		dp[i] = dp[i-1] + a[x+1][t[i]-'a'] - x;
	}
	cout << dp[t.size()-1] + 1 << "\n";
//	for(size_t i=0; i<a.size(); ++i)
//		for(size_t j=0; j<a[i].size(); ++j)
//			cout << a[i][j] << " \n"[j+1==a[i].size()];
}

Measured memory_bytes: 83496
#include <iostream>
#include <queue>
  
int main(){
    std::priority_queue<u_int>  vegetable;
    u_int n, m, price;
     
    while(1){
        std::cin >> n >> m;
        if(n == 0 && m == 0)
            break;
             
        for(u_int i = 0; i < n; ++i){
            std::cin >> price;
            vegetable.push(price);
        }
         
        u_int sum = 0;
        for(u_int i = 1; i <= n; ++i){
            if(i % m != 0){
                sum += vegetable.top();
            }
            vegetable.pop();
        }
        std::cout << sum << std::endl;
    }
  
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=1;i<110;i++) if(i*d>=l && i*d<=r) ans++;
    cout<<ans<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;

int main() {
    int n; cin >> n;
    vector<ll> x(n), y(n);
    rep(i, n) {
        cin >> x[i];
        y[i] = x[i];
    }
    sort(all(x));

    int right_idx = (n - 0) / 2;
    int left_idx  = (n - 1) / 2;

    int right = x[(n - 0) / 2];
    int left  = x[(n - 1) / 2];

    rep(i, n) {
        int idx = lower_bound(all(x), y[i]) - x.begin();

        if (idx <= left_idx) cout << x[right_idx] << endl;
        else if (idx >= right_idx) cout << x[left_idx] << endl;
    }
}

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

int main(){
  int N,Ma,Mb;
  cin>>N>>Ma>>Mb;
  vector<int> a(N),b(N),c(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i)>>b.at(i)>>c.at(i);
  }

  vector<vector<int>> dp(500,vector<int>(500,INF));
  dp.at(0).at(0)=0;
  for(int i=0;i<N;i++){
    for(int j=400-a.at(i);j>=0;j--){
      for(int k=400-b.at(i);k>=0;k--){
        dp[j+a.at(i)][k+b.at(i)]=min(dp[j+a.at(i)][k+b.at(i)],dp[j][k]+c.at(i));
      }
    }
  }
  int ans=10000000;
  for(int i=1;i*Ma<=400&&i*Mb<=400;i++){
    ans=min(ans,dp[i*Ma][i*Mb]);
  }
  if(ans==INF){
    cout<<-1<<endl;
  }else{
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No");

  




  
  return 0;
}

Measured memory_bytes: 3644
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int w = sc.nextInt();
		int h = sc.nextInt();

		AP[] aps = new AP[n];
		for(int i = 0; i < n; i++){
			aps[i] = new AP(sc.nextInt(), sc.nextInt(), sc.nextInt());
		}

		Arrays.sort(aps, new Comparator<AP>() {

			@Override
			public int compare(AP o1, AP o2) {
				// TODO 自動生成されたメソッド・スタブ
				return o1.x - o1.w - o2.x + o2.w;
			}
		});

		boolean clear = true;
		int right = 0;
		for(int i = 0; i < n; i++){
			if(aps[i].x - aps[i].w > right){
//				System.out.println("No");
//				System.out.println("right not reached ");
//				return;
				clear = false;
				break;
			}

			right = Math.max(right, aps[i].x + aps[i].w);
//			System.out.println("right "+right);
		}

		if(right < w){
//			System.out.println("No");
//			return;
			clear = false;
		}

		if(clear){
			System.out.println("Yes");
			return;
		}

		Arrays.sort(aps, new Comparator<AP>() {

			@Override
			public int compare(AP o1, AP o2) {
				// TODO 自動生成されたメソッド・スタブ
				return o1.y - o1.w - o2.y + o2.w;
			}
		});

//		for(int i = 0; i < n; i++){
//			System.out.println(aps[i].x+" "+aps[i].y+" " + aps[i].w);
//		}
		clear = true;
		int top = 0;
		for(int i = 0; i < n; i++){
			if(aps[i].y - aps[i].w > top){
//				System.out.println("No");
//				System.out.println("i = "+i + "top "+ top +"not reached to " + (aps[i].y - aps[i].w));
//				return;
				clear = false;
				break;
			}

			top = Math.max(top, aps[i].y + aps[i].w);
//			System.out.println("top "+top);
		}
		if(top < h){
//			System.out.println("No");
//			return;
			clear = false;
		}

		if(clear){
			System.out.println("Yes");
			return;
		}
		System.out.println("No");

	}

}

class AP {
	int x;
	int y;
	int w;

	AP (int x, int y, int w){
		this.x = x;
		this.y = y;
		this.w = w;
	}
}


Measured memory_bytes: 107436
import sys
N,M = map(int,input().split())
L = [0]*M
R = [0]*M
for i in range(M):
    L[i],R[i] = map(int,input().split())
LL = L[0]
RR = R[0]
for i in range(1,M):
    if L[i] > RR or LL > R[i]:
        print(0)
        sys.exit()
    else:
        LL = max(LL, L[i])
        RR = min(RR, R[i])
print(RR - LL + 1)


Measured memory_bytes: 46448
while True:
  a,b,c=map(int,input().split())
  if a<0 and b<0 and c<0:
      break
  else:  
    if a<0 or b<0:
        print('F')
    elif a+b>=80:
        print('A')
    elif 65<=a+b<80:
        print('B')
    elif 50<=a+b<65:
        print('C')
    elif 30<=a+b<50:
        if c>=50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5596
#include<stdio.h>
int n,ans;
int nummem[2001]={0};
int main()
{
    for(int i=0;i<1001;i++)
    {
        for(int j=0;j<1001;j++)
        {
            nummem[i+j]++;
        }
    }
    while(scanf("%d",&n)!=-1)
    {
        ans=0;
        for(int i=0;i<1001;i++)
        {
            for(int j=0;j<1001;j++)
            {
                if(0<=n-i-j&&n-i-j<=2000)ans=ans+nummem[n-i-j];
            }
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
std::vector<long long int> v;
int main() {
     long long int a=0;
	for(long long int i=0;i<3;i+=1){
	     long long int x;
	     cin >> x;
	     if(x%2==0){
	          a=1;
	     }
	     v.push_back(x);
	}
	if(a==1){
	     cout << 0;
	}
	else{
	     sort(v.begin(),v.end());
	     cout << v[0]*v[1];
	}
	return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a[] =new int[3];
		for(int i = 0;i < 3 ;i++) {
			a[i] = scan.nextInt();
		}
		Arrays.sort(a);
		
		for(int j=0;j<3;j++) {
			System.out.print(a[j]);
			if(j != 2) {
				System.out.print(" ");
			}else {

			}
		}
		System.out.println();
		scan.close();
		}
}



Measured memory_bytes: 26368
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
s_ = list(inputS())

s=[]
for i in range(len(s_)-1):
  s.append(abs(int(s_[i])-int(s_[i+1])))
N = N-1

def decode(s):
  #print(s)
  N = len(s)
  news = []
  if set(s)!={0,2}:
    for n in range(20):
      if ((N-1)>>n)&1:
        d = pow(2,n)
        for i in range(N-d):
          news.append(abs(s[i]%2-s[i+d]%2))
        break
  else:
    for n in range(20):
      if ((N-1)>>n)&1:
        d = pow(2,n)
        for i in range(N-d):
          news.append(abs(s[i]-s[i+d]))
        break
    
  return news

  
while len(s) > 1:
  s = decode(s)

print(s[0])

Measured memory_bytes: 183216
#include <stdio.h>
#include <stdlib.h>
int line[100000],bus,n;
int compar(const int *v1,const int *v2){
    return *v1-*v2;
}
void search(int x,int c,int k){
    int i,sum=1;
    for(i=x+1;i<n;i++){
        if(line[i]<=line[x]+k && sum<c){
            sum++;
        }
        else
            break;
    }
    bus++;
    if(i==n)
        return;
    search(i,c,k);
}
int main(void){
    int c,k,i;
    scanf("%d %d %d",&n,&c,&k);
    for(i=0;i<n;i++)
        scanf("%d",&line[i]);
    qsort(line,n,4,(int (*)(const void *,const void *))compar);
    search(0,c,k);
    printf("%d\n",bus);
    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>

int main(void)
{
    char cards[400];
    int h, i, j, l, m;
    
    while (1) {
	scanf("%s", cards);
	if (cards[0] == '-' && cards[1] == '\0')
	    break;

	l = 0;
	while (cards[l] != '\0')
	    l++;
	
	scanf("%d", &m);
	for (i = 0; i < m; i++) {
	    scanf("%d", &h);
	    for (j = 0; j < h; j++)
		cards[l + j] = cards[j];
	    for (j = 0; j < l; j++)
		cards[j] = cards[j + h];
	}

	cards[l] = '\n'; cards[l + 1] = '\0';
	printf("%s", cards);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int MAX_N = 1e5 + 5, BLACK = 0, WHITE = 1, MOD = 1e9 + 7;
vector <int> tree[MAX_N];
long long no_of_ways[MAX_N][2];

long long dfs_count(int parent, int v, int colour)
{
    if(no_of_ways[v][colour] != -1)
    {
        return no_of_ways[v][colour];
    }

    no_of_ways[v][colour] = 1;

    for(int i = 0; i < tree[v].size(); i++)
    {
        int child = tree[v][i];

        if(child == parent) continue;

        long long no_of_subtrees = 1;

        if(colour == BLACK)
        {
            no_of_subtrees = dfs_count(v, child, WHITE);
        }
        else if(colour == WHITE)
        {
            no_of_subtrees = (dfs_count(v, child, BLACK) + dfs_count(v, child, WHITE))%MOD;
        }

        no_of_ways[v][colour] = (no_of_ways[v][colour]*no_of_subtrees)%MOD;
    }

    return no_of_ways[v][colour];
}

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

    for(int i = 1; i <= no_of_vertices - 1; i++)
    {
        int x, y;
        cin >> x >> y;

        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    memset(no_of_ways, -1, sizeof(no_of_ways));

    long long answer = (dfs_count(0, 1, BLACK) + dfs_count(0, 1, WHITE))%MOD;

    cout << answer;
    return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include<string>
#include<cmath>
#include<vector>
using std::cin;
using std::cout;
using std::vector;
int main()
{
	int n,k;
	long int z=0;
	cin>>n>>k;
	n-=1;
	if(n!=0)
	{
	z=k*pow((k-1),n);
	}
	else z=k;
	cout<<z;
	
			
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
#if !defined(ONLINE_JUDGE)
#include "debugging.h"
#endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 1e5+5;
int const inf = 2e9;

void solve(){  
    int i,j;
    int s,w;
    cin>>s>>w;
    if(w >= s){
        cout<<"unsafe"<<endl;
    }
    else{
        cout<<"safe"<<endl;
    }
}           

int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*

*/

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

int main(){
    int m,k,x=0;
    cin >> m >> k;
    for(int i = 0;i < (int)pow(2,m);i ++){
        if(i==k) continue;
        x = x^i;
    }
    if(k==0){
        cout << 0 << " " << 0;
        for(int i = 1;i < (int)pow(2,m);i ++){
            cout << " " << i << " " << i;
        }
        cout << endl;
    }
    else if(x==k){
        for(int i = 0;i < (int)pow(2,m);i ++){
            if(i==k) continue;
            cout << i << " ";
        }
        cout << k << " ";
        for(int i = (int)pow(2,m)-1;i >= 0;i --){
            if(i==k) continue;
            cout << i << " ";
        }
        cout << k << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++)cin >> a[i];
	int cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = n - 1; j >= 0; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				cnt++;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (i > 0)cout << " ";
		cout << a[i];
	}
	cout << endl << cnt << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VVI a(n,VI(n-1));
    REP(i,0,n) REP(j,0,n-1) cin >> a[i][j];
    REP(i,0,n) REP(j,0,n-1) --a[i][j];
    VI cnt(n*n);
    vector<set<int>> es(n*n);
    REP(i,0,n) REP(j,1,n-1) {
        es[min(i,a[i][j-1]) * n + max(i,a[i][j-1])].insert(min(i,a[i][j])*n + max(i,a[i][j]));
        cnt[min(i,a[i][j])*n + max(i,a[i][j])]++;
    }
    deque<int> q;
    int ans = 0;
    REP(i,0,n*n) if (cnt[i] == 0) q.push_back(i);
    while (!q.empty()) {
        ++ans;
        int len = q.size();
        REP(i,0,len) {
            int idx = q.front();
            q.pop_front();
            for (auto &&dst: es[idx]) {
                --cnt[dst];
                if (cnt[dst] == 0) q.push_back(dst);
            }
        }
    }
    REP(i,0,n*n) if (cnt[i] != 0) {
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 103808
import sys
N = int(input())
input = sys.stdin.readline

R = [None] * N


for i in range(N):
    x, l = list(map(int, input().split()))
    R[i] = (min(l+x, 1000000000), max(x - l, 0))

R.sort()

left = 0

ans = 0

for maximum, minimum in R:
    if left <= minimum:
        ans += 1
        left = maximum

print(ans)


Measured memory_bytes: 46172
import numpy as np

N = int(input())
XL = np.array([list(map(int, input().split())) for _ in range(N)])

A = np.zeros([N, 2])

A[:, 0] = XL[:, 0] - XL[:, 1]
A[:, 1] = XL[:, 0] + XL[:, 1]

A = A[np.argsort(A[:, 1])]

cnt = 0
right = A[0, 0] - 1

for aa in A:
    if right > aa[0]:
        continue
    else:
        cnt += 1
        right = aa[1]

print(cnt)


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

using namespace std;

#define MAX 100005
int dp[MAX][3];
int arr[MAX][3];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        for(int j=0; j<3; j++) scanf("%d", &arr[i][j]);
    }
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<3; j++){
            int maxs = 0;
            for(int k=0; k<3; k++){
                if(j == k) continue;
                int nows = arr[i][j] + dp[i-1][k];
                maxs = max(maxs, nows);
            }
            dp[i][j] = maxs;
        }
    }
    int ans = 0;
    for(int i=0; i<3; i++) ans = max(ans, dp[n][i]);
    printf("%d", ans);
}


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

using namespace std;

int main() {
    long long n;
    cin >> n;
    long long now = 0;
    long long base = 26;
    int w = 1;
    while (now + base < n) {
        now += base;
        base *= 26;
        w++;
    }
    long long k = n - now - 1;
    string ans;
    while (k) {
        ans += 'a' + k % 26;
        k /= 26;
    }
    while ((int)ans.length() < w) {
        ans += 'a';
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3552
///******* In the name of Allah *******///

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

int main()
{
    int n,i;
    double j,ans;
    cin>>n;
    for(i=1;i<=9;i++)
    {
        j = i;
        ans = n/j;
        if(ans<=9 && ans==(int)ans)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a > b)
			System.out.println("a > b");
		else if(a < b)
			System.out.println("a < b");
		else
			System.out.println("a == b");


	}

}



Measured memory_bytes: 26236
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<vector<int>> x(N, vector<int>(N, -1));
    vector<vector<int>> y(N, vector<int>(N, -1));
    REP(i, N) {
        int A;
        cin >> A;
        REP(j, A) {
            int xx, yy;
            cin >> xx >> yy;
            x[i][j] = xx-1;
            y[i][j] = yy;
        }
    }
    int ans = 0;
    REP(i, pow(2, N)) {
        int num = 0;
        bool flg = true;
        REP(j, N) {
            if(((i >> j)&1) == 1) {
                num++;
                REP(k, N) {
                    if(x[j][k] == -1) break;
                    if(y[j][k] == 1) {
                        if(((i >> x[j][k])&1) == 0) {
                            flg = false;
                        }
                    } else {
                        if(((i >> x[j][k])&1) == 1) {
                            flg = false;
                        }
                    }
                }
            }
        }
        if(flg && num > ans) ans = num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int a[12][12];

int main(void)
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) {
        cin >> c[i];
        for (int j = 0; j < M; ++j) {
            cin >> a[i][j];
        }
    }

    int ans =INF;
    for (int bit = 0; bit < (1<<N); ++bit) {
        int cost = 0;
        vector<int> d(M);//各アルゴリズムの理解度を保存する用の配列
        for (int i=0; i < N; ++i) {
            if (bit>>i&1) {
                cost += c[i];
                for (int j = 0; j < M; ++j) {
                    d[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < M; ++j) {
            if (d[j] < X) ok = false;
        }
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

VI a;
bool is_satisfied(int key) {
    return abs(a[key] * 2 - a.back()) - abs(a[key - 1] * 2 - a.back()) < 0;
}

// TTTTFFFFのときのTの最大indexを求めたいならsearch_max=true
// FFFFTTTTのときのTの最小indexを求めたいならsearch_max=false
int binary_search(int min, int max, bool search_max) {
    min--;
    max++;
    while(max - min > 1) {
        int mid = (max + min) / 2;
        if(is_satisfied(mid) xor not search_max) min = mid;
        else max = mid;
    }
    return search_max ? min : max;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    cout << a.back() << " " << a[binary_search(1, n - 1, true)] << endl;
      
    return 0;
}


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


int main(){
    long long R, G, B, N;
    long long count = 0;

    cin >> R >> G >> B >> N;

    for(long long i = 0; i <= N; i++){
      for(long long j = 0; j <= N-i; j++){
        if((N >= ((R*i)+(G*j))) && ((N - ((R*i)+(G*j))) % B == 0)) count++;
      }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3624
#include"bits/stdc++.h"
#define F(i,j,n) for(register int i=j;i<=n;i++)
#define D(i,j,n) for(register int i=j;i>=n;i--)
#define ll long long
#define N 200010
using namespace std;
namespace io{
	const int L=(1<<19)+1;
	char ibuf[L],*iS,*iT,c;int f;
	char gc(){
		if(iS==iT){
			iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
			return iS==iT?EOF:*iS++;
		}
		return*iS++;
	}
	template<class I>void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
};
using io::gi;
using io::gc;
int head[N],nxt[N<<1],to[N<<1],tot,n,f[N];
void adli(int u,int v){
	++tot;nxt[tot]=head[u];head[u]=tot;to[tot]=v;
	++tot;nxt[tot]=head[v];head[v]=tot;to[tot]=u;
}
void dfs(int u,int fa){
	int i,v;
	for(i=head[u];i;i=nxt[i]){
		v=to[i];if(v==fa)continue;
		dfs(v,u);f[u]^=f[v]+1;
	}
}
int main(){
	int u,v;
	gi(n);F(i,2,n)gi(u),gi(v),adli(u,v);
	dfs(1,0);puts(f[1]?"Alice":"Bob");
	return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<deque>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x[n][3],a[n],flag[n];;
	for(int i=0;i<n;i++){
		a[i]=0;
		for(int j=0;j<3;j++){
			cin>>x[i][j];
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<n;j++){
			flag[j]=0;
			for(int k=0;k<n;k++){
				if(x[j][i]==x[k][i])
				flag[j]++;
			}
			if(flag[j]==1)
			a[j]+=x[j][i];
		}
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<endl;
return 0;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()
	K := make([]int, N)

	total := 0
	for i := 0; i < N; i++ {
		K[i] = A[(i + 1) % N] - A[i]
		total += A[i]
	}

	p := N * (N + 1) / 2
	if total % p > 0 {
		fmt.Println("NO")
		return
	}
	t := total / p
	for i := 0; i < N; i++ {
		w := t - K[i]
		if w >= 0 && w % N == 0 {

		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        SetOut(sw);
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void solve()
    {
        int x = cin.nextint;
        int y = cin.nextint;
        int cnt = 0;

        if (x == y)
        {
            WriteLine(0);
        }
        else if (x * -1 == y)
        {
            WriteLine(1);
        }
        else if (Math.Abs(x) < Math.Abs(y))
        {
            if(x < 0)
            {
                cnt++;
            }
            cnt += Math.Abs(y) - Math.Abs(x);
            if (y < 0)
            {
                cnt++;
            }
            WriteLine(cnt);
        }
        else
        {
            if (x > 0)
            {
                cnt++;
            }
            cnt += Math.Abs(x) - Math.Abs(y);
            if (y > 0)
            {
                cnt++;
            }
            WriteLine(cnt);
        }
   
        
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> v(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &v[i]);
  }
  sort(v.begin(), v.end());
  int ans = 0, i = 0;
  while (i < N) {
    int j = i + 1;
    while (v[j] == v[i] and j < N) {
      ++j;
    }
    ans += (j - i) % 2;
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

int n, k, q, sa[101010], sb[101010], ta[101010], tb[101010], x, y, a, b;
string s, t;


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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> s >> t;
n = s.size()-1;
k = t.size()-1;


rep(i, 0, n){
if(s[i]=='A'){
    sa[i+1]= sa[i]+1;
    sb[i+1]=sb[i];
}
else {
    sb[i+1] = sb[i]+1;
    sa[i+1]=sa[i];
}
}


rep(i, 0, k){
if(t[i]=='A'){
    ta[i+1]= ta[i]+1;
    tb[i+1]=tb[i];
}
else {
    tb[i+1] = tb[i]+1;
    ta[i+1]=ta[i];
}
}

cin >> q;

rep(i, 1, q){
cin >> x >> y >> a >> b;
int temp = sa[y]-sa[x-1];
int tmp = sb[y]-sb[x-1];
x = ta[b]-ta[a-1];
y = tb[b]- tb[a-1];

if(x<temp){
    a = (temp-x+2)/3;
    a = a*3 + x;
}
else a = x - 3*((x-temp)/3);
if(y<tmp){
    b = (tmp-y+2)/3;
    b = b*3 + y;
}
else b = y - 3*((y-tmp)/3) ;
if(a-temp==b-tmp)cout << "YES" << endl;
else cout << "NO" << endl;;
}

return 0;}


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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int M[11][11];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin>>n>>m;
    for(int i = 0; i <= 9; ++i)
        for(int j = 0; j <= 9; ++j)
            cin>>M[i][j];
    for(int k = 0; k <= 9; ++k)
    for(int i = 0; i <= 9; ++i)
        for(int j = 0; j <= 9; ++j)
            M[i][j] = min(M[i][j], M[i][k] + M[k][j]);
    int ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
        {
            int inp;
            cin>>inp;
            if(inp>=0)
                ans += M[inp][1];
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

bool cmp(char a,char b){
	if(a < b)return true;
	else return false;
}

int main(void){
	string s,t;cin>>s>>t;
	VC sc(0);
	VC tc(0);
	for(int a = 0;a < s.size();a++)sc.push_back(s[a]);
	for(int b = 0;b < t.size();b++)tc.push_back(t[b]);

	SORT(sc);
	SORT(tc);
	reverse(tc.begin(),tc.end());

	cout<<(sc < tc?"Yes":"No");
}


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

const int N = 1e6 + 100;

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int M, D;
    cin >> M >> D;
    int ans = 0;
    for(int i = 1; i <= M; i++) {
        for(int j = 0; j <= D; j++) {
            int d0 = j%10, d10 = j/10;
            if(d0 >= 2 && d10 >= 2 && d0*d10 == i) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256