akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0034
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            while ((input = Console.ReadLine()) != null)
            {
                int[] info = input.Split(',').Select(int.Parse).ToArray();
                Console.WriteLine(OnTheRail(info));

            }
        }
        internal static int OnTheRail(int[] info)
        {
            int railNum = 0;
            int juncPoint = 0;
            int distance = 0;
            int[] railDistance = { info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7], info[8], info[9] };
            int[] velocity = { info[10], info[11] };
            juncPoint = SumNums(railDistance) * velocity[0] / (velocity[0] + velocity[1]);
            for (int i = 0; distance < juncPoint; ++i)
            {
                distance += railDistance[i];
                ++railNum;
            }
            return railNum;
        }
        internal static int SumNums(int[] nums)
        {
            int sum = 0;
            foreach (int num in nums)
            {
                sum += num;
            }
            return sum;
        }
    }
}



Measured memory_bytes: 16360
S = input()
def dfs(s, i):
  if i == len(S) - 1:
    return sum(map(int, s.split("+")))
  return dfs(s + S[i + 1], i + 1) + dfs(f"{s} + {S[i + 1]}", i + 1)
print(dfs(S[0], 0))

Measured memory_bytes: 9116
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int, int>
#define pll pair<ll , ll>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define N 200005
#define INF 1000000000000000


int main()
{   
    fastio
    int n;
    cin>>n;
    int w;
    cin>>w;
    vector<pll> arr(n);
    for(int i = 0 ; i<n;i++)
    {   
        int a , b;
        cin>>a>>b;
        arr[i] = mpi(a , b);
    }

    ll dp[n+1][w+1];

    for(int i = 0 ; i<n;i++)
        for(int j = 0 ; j<=w;j++)
            dp[i][j] = 0;

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

        for(int j = arr[i-1].F ; j<=w;j++)
        {
            dp[i][j] = max(dp[i-1][j-arr[i-1].F] + arr[i-1].S , dp[i][j]);
        }
    }

    cout<<dp[n][w]<<endl;
    return 0;
} 

Measured memory_bytes: 79232
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::vector<long long> B){
  ll ans = 0;
  ans += B[0] + B[N-2];
  rep(i,N-2) ans += min(B[i],B[i+1]);
  cout << ans << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> B(N-1);
  for(int i = 0 ; i < N-1 ; i++){
    scanf("%lld",&B[i]);
  }
  solve(N, std::move(B));
  return 0;
}


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define pf push_front
#define pb push_back
#define FST first
#define SEC second
#define sz(obj) ((int)(obj).size())

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if (a[0] == 5 and a[1] == 5 and a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    int64_t t,n,m,a,b,c,d,e,i,j,k,x,y,cnt=0,cnt1=0;
    bool flag = false;   
    
    cin>>n;
    lve v(n);
    for(auto &ss:v) cin>>ss;
    sort(all(v));
    if(n&1)
    {
        cout<< 0 <<endl;
        return ;
    }
    n=n/2;
    cout<<v[n]-v[n-1]<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

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

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


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

int dp[100000][3];
int a[100000][3];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i][0] >> a[i][1] >> a[i][2];

	for (int j = 0; j < 3; j++)
		dp[0][j] = a[0][j];

	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			int mx = 0;
			for (int k = 0; k < 3; k++)
				if (j != k) mx = max(dp[i-1][k], mx);
			dp[i][j] = a[i][j] + mx; //max(dp[i][j], dp[i-1][j] + mx);
		}
	}

	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

Measured memory_bytes: 2560
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M, X = in.nextInt
  case class Book(price: Int, skills: Array[Int])
  val Books = Array.fill(N)(Book(in.nextInt, Array.fill(M)(in.nextInt)))

  val result = (1 to (1 << N) - 1).map {i =>
    (0 until N).foldLeft((0, Array.fill(M)(0))){case ((amount, as), n) =>
      if ((i & (1 << n)) != 0) {
        val b = Books(n)
        (amount + b.price, as.zip(b.skills).map(t => t._1 + t._2))
      } else (amount, as)
    }
  }

  val min = result.filter(_._2.forall(_ >= X)) match {
    case l if l.isEmpty => -1
    case l => l.minBy(_._1)._1
  }
  println(min)
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int x;
    ist >> x;

    /* ------- 計算 ------- */

    ost << !x << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3620
N, K = map(int, input().split())
a = [int(x) for x in input().split()]
d = {}

for i in a :
    if i in d.keys() :
        d[i] += 1
    else :
        d[i] = 1
    
    
sb = sorted(d.items(), key = lambda x : x[1])
types = len(sb)
cnt = 0

for k in sb :
    if types > K :
        types -= 1
        cnt += k[1]
    else: 
        break
        
print(cnt)

Measured memory_bytes: 40068
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<string> v(111);
set<string> s;

int main()
{
    int n;
    cin>>n;
    REP(i,n) cin>>v[i];
    bool flag = true;
    s.insert(v[0]);
    FOR(i,1,n) {
        if (v[i-1][v[i-1].size() - 1] ==  v[i][0] && s.count(v[i]) == 0) {
            s.insert(v[i]);
        } else {
            flag = false;
            break;
        }
    }
    Yes(flag);

    return 0;
}


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

int main(){
    int N; cin >> N; 
    int sum = 0;
    int Hotel[20];
    for(int i =0; i< N; i++){
        cin >> Hotel[i];
    }
    for(int i=0;i<N;i++){
        int highest;
        if(i==0){
            highest = Hotel[i];
            sum++;
        }else{
            if(highest <= Hotel[i]){
                sum++;
                highest = Hotel[i];
            }
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int cnt[1001];
    zero(cnt);
    int x,n;
    cin>>x>>n;
    rep(i,0,n){
        int y;
        cin>>y;
        cnt[y] = 1;
    }
    int i = x;
    int j = x+1;
    int ans1 = inf;
    while( i >= 0 ){
        if ( !cnt[i] ){
            ans1 = i;
            break;
        }
        i--;
    }
    int ans2 = inf;
    while( j < 1001 ){
        if (!cnt[j]){
            ans2 = j;
            break;
        }
        j++;
    }
    if ( abs(ans2-x) > abs(ans1-x) ){
        cout<<ans1<<endl;
    }
    else if ( abs(ans2-x) < abs(ans1-x) ){
        cout<<ans2<<endl;
    }
    else{
        cout<<min(ans1,ans2)<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3672
;/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    long long c = 0;
    for(int i = 0 ; i < N; i++){
        cin >> d[i];
        for(int j = 0 ; j < i; j++){
            c += d[i] * d[j];
        }
        
    }

    cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int h,w; cin >> h >> w;
  int k; cin >> k;
  char c[h][w];
  REP(i,h) REP(j,w) cin >> c[i][j];

  int ans = 0;
  REP(i,1<<h) REP(j,1<<w) {
    int count = 0;
    REP(ih,h) REP(jw,w) {
      // flagが立っているところは選ばれてない行/列
      // i,jのフラグが立っており、c[ih][jw]が黒の場合はincrement
      if ((i&(1<<ih)) && (j&(1<<jw)) && c[ih][jw]=='#') count++;
    }
    if (count==k) ans++;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
    int N, M, K, tmp;
    while(cin >> N >> M && (N || M))
    {
        vector<int> v(N+1);
        for(int t=0; t<3; t++)
        {
            cin >> K;
            for(int k=0; k<K; k++)
            {
                cin >> tmp;
                v[tmp] = t;
            }
        }

        vector<int> a(N+1), c(N+1), p(N+1);
        p[N] = 2;
        a[N] = v[N];
        c[N] = 2 - v[N];
        for(int n=N; n>1; n--)
        {
            p[n-1] = 3 * p[n] + 2;
            switch(v[n-1])
            {
            case 0:
                a[n-1] = a[n];
                c[n-1] = c[n] + 2 * p[n] + 2;
                break;
            case 1:
                a[n-1] = c[n] + p[n] + 1;
                c[n-1] = a[n] + p[n] + 1;
                break;
            case 2:
                a[n-1] = a[n] + 2 * p[n] + 2;
                c[n-1] = c[n];
                break;
            }
        }
        int res = min(a[1], c[1]);
        if(M < res) res = -1;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		int[] B = new int[M];
		int[][] A = new int[N][M];
		for (int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		int result = 0;
		int correct = 0;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				result += A[i][j]*B[j];
			}
			if(result+C > 0)correct += 1;
			result = 0;
		}
		System.out.println(correct);
	}
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int n, m;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> n;
	map<string, bool> ids;
	rep (i, n) {
		string u;
		cin >> u;
		ids[u] = true;
	}
	cin >> m;
	VS ans;
	VS ts;
	bool flag = false;
	rep (i, m) {
		string s;
		string t;
		cin >> t;
		if (!ids.count(t)) {
			s = "Unknown " + t;
		} else if (flag) {
			s = "Closed by " + t;
			flag = false;
		} else {
			s = "Opened by " + t;
			flag = true;
		}
		ans.pb(s);
	}
	for (string a : ans) {
		cout << a << endl;
	}
	return 0;
}

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

int digit(int n){
    int digit=0;
    while(n>0){
        digit+=1;
        n=n/10;
    }
    return digit;
}

int main(void){
    int a,b;
    while(cin>>a>>b){
        cout<<digit(a+b)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3072
# n = int(input())
# a, b = map(int, input().split())
# c = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]

alphabet = "abcdefghijklnmopqrstuvwxyz"
s = input()
k = int(input())
s_set = set(s)
ans = set()

if k == 1:
    s_set_list = list(s_set)
    s_set_list.sort()
    print(s_set_list[0])

elif k >= 2:
    for c in alphabet:
        for i in range(len(s)):
            if c == s[i]:
                ans.add(c)
                if i == len(s):
                    break
                for j in range(i+1, i+k+2):
                    if j > len(s):
                        break
                    ans.add(s[i:j])
        if len(ans) > k:
            break


    ans_list = list(ans)
    ans_list.sort()
    print(ans_list[k - 1])

Measured memory_bytes: 3188
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	ll N;
	int p[] = {0, 1, 2, 3, 5, 7, 8, 9 };

	while(cin >> N, N) {
		vi num;
		
		while(N > 0) {
			num.push_back(p[N%8]);
			N /= 8;
		}

		int size = num.size();
		REP(i, size) {
			cout << num[size-1-i];	
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define F first
#define S second
#define INF (1<<30)
using namespace std;
typedef pair<int,long long> P;
typedef struct{
  vector<P> to;
  long long min;
}Node;
int n;
int m;
long long daikusutora(int s);
Node node[15];
main(){
  int a,b;
  long long c;
  while(1){
    m=0;
    scanf("%d",&n);
    if(n==0){
      break;
    }
    for(int i=0;i<10;i++){
      node[i].to.clear();
    }
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&a,&b,&c);
      m=max(m,a);
      m=max(m,b);
      node[a].to.push_back(P(b,c));
      node[b].to.push_back(P(a,c));
    }
    m++;
    long long mins=INF;
    int pos=0;
    for(int i=0;i<m;i++){
      long long cnt=0;
      cnt=daikusutora(i);
      //cout<<cnt<<endl;
      if(mins>cnt){
	mins=min(mins,cnt);
	pos=i;
      }
    }
    printf("%d %d\n",pos,mins);
  }
}
long long daikusutora(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  for(int i=0;i<m;i++){
    node[i].min=INF;
  }
  node[s].min=0;
  que.push(P(s,0));
  while(!que.empty()){
    P now=que.top();
    que.pop();
    int basyo=now.F;
    int nowcos=now.S;
    for(int i=0;i<node[basyo].to.size();i++){
      int nbasyo=node[basyo].to[i].F;
      int ncost=node[basyo].to[i].S;
      if(node[nbasyo].min>nowcos+ncost){
	node[nbasyo].min=nowcos+ncost;
	que.push(P(nbasyo,nowcos+ncost));
      }
    }
  }
  long long cnt=0;
  for(int i=0;i<m;i++){
    cnt+=node[i].min;
  }
  return cnt;
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0546 : Lining up the cards **/

vector<string> card;
bool used[10];
set<string> ans;
int N, K;

void solve(int n, string s)
{
	if (n==K) ans.insert(s);
	else {
		rep(i, N) {
			if (!used[i]) {
				used[i] = true;
				solve(n+1, s+card[i]);
				used[i] = false;
			}
		}
	}
}

int main()
{
	while (cin>>N, N) {
		ans.clear();
		card.clear();
		fill(used, used+10, false);
		
		cin>>K;
		rep(i, N) {
			string s; cin>>s;
			card.push_back(s);
		}
		solve(0, "");
		cout << ans.size() << endl;
	}
}

Measured memory_bytes: 1460
def simple_calc(a, op, b):
    res = 0
    if op == "+":
        res = a + b
    elif op == "-":
        res = a - b
    elif op == "*":
        res = a * b
    elif op == "/":
        res = a// b

    return  res

if __name__ == "__main__":
    while True:
        a, op, b = input().split()
        if op == "?":
            break
        ans = simple_calc(int(a), op, int(b))
        print(f"{ans}")
        
    


Measured memory_bytes: 5608
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [x - y for x, y in zip(A, B)]
Minus = [i for i in C if i < 0]
minus = sum(Minus)
EX = [i for i in C if i > 0]
EX.sort(reverse=True)

if sum(A) < sum(B):
    print(-1)
    exit()

i = 0
while minus < 0:
    minus += EX[i]
    i += 1

print(len(Minus) + i)

Measured memory_bytes: 24400
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = 5000, D = 9;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 10, flag = 1;
//     cout << tc << "\n";
//     int n = 1;
//     while (tc--)
//     {
//     	int n = rand()%N + 1;
//     	int k = rand()%MAXI + 1;

//     	cout << n << " " << k << "\n";

//     	for(int i=0;i<n;i++)
//     	{
//     		for(int j=0;j<n;j++)
//     		{
//     			cout << rand()%2 << " ";
//     		}
//     		cout << "\n";
//     	}
    	
//     	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 

//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
//#define int long long
#define ll long long
#define mod (int)(1e9+7)
#define N 105
#define M 100005

int n, k;
int a[N], dp[N][M] = {0};

int MEM(int ind, int left)
{
	if(left==0)
		return 1;

	if(ind==0 or left<0)
		return 0;

	int &ans = dp[ind][left];

	if(ans!=-1)
		return ans;

	ans = MEM(ind, left-1);

	ans = (ans + MEM(ind-1, left))%mod;

	ans = (ans - MEM(ind-1, left-a[ind-1]-1) + mod)%mod;

	return ans;	
}

// Driver code to test above functions
int32_t main()
{
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
	cout.tie(NULL);

	cin >> n >> k;
	for(int i=0;i<n;i++)
		cin >> a[i];

	memset(dp, -1, sizeof dp);

	cout << MEM(n, k);

	// for(int i=0;i<=n;i++)
	// 	dp[i][0] = 1;

	// for(int i=1;i<=k;i++)
	// 	dp[0][i] = 0;

	

	// for(int i=1;i<=n;i++)
	// {
	// 	for(int j=1;j<=k;j++)
	// 	{
	// 		dp[i][j] = dp[i][j-1];

	// 		dp[i][j] += dp[i-1][j];

	// 		if(dp[i][j]>=mod)
	// 			dp[i][j] %= mod;

	// 		if(j-1-a[i-1]>=0)
	// 			dp[i][j] = (dp[i][j] - dp[i-1][j-1-a[i-1]] + mod)%mod;
	// 	}
	// }
	
	// cout << dp[n][k];
 
    return 0;
 
} 


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

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

  for (int i = 1; i <= n; i++)
  {
    string s = to_string(i);
    if (s.length() % 2 != 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3764
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

acc = B[-1] - (A[-1] % B[-1]) if (A[-1] % B[-1]) != 0 else 0
for i in range(N-2, -1, -1):
    A[i] += acc
    acc = acc + B[i] - (A[i] % B[i]) if (A[i] % B[i]) != 0 else acc
print(str(acc))

Measured memory_bytes: 58840
import java.util.*;
import java.io.*;

public class Main {	

	private static void solve(){
		//Implement solution here.
		int N = ni();
		int M = ni();
		System.out.println(N * (N - 1) / 2 + M * (M - 1) / 2);
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
template<typename T>void read(T &x){
	x = 0;int f(1);char c = getchar();
	for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
	for(;isdigit(c);c = getchar()) x = x*10+c-'0';
	x *= f;
}
const int maxn = 500005;
int n,a[maxn],c[maxn],m;
int nxt[maxn],hd[maxn],ans[maxn];
struct asks{
	int l,r,ind;
	bool operator <(const asks &x)const{
		if(l != x.l)	return l < x.l;
		return r < x.r;
	}
}q[maxn];
void add(int k){
	if(k == 0)	return;
	while(k <= n){
		c[k] += 1;
		k += (k&(-k));
	}
}
int query(int k){
	int ret = 0;
	while(k){
		ret += c[k];
		k -= (k&(-k));
	}
	return ret;
}
int main(){
	read(n); read(m);
	for(int i(1);i <= n;++i)	read(a[i]);
	for(int i = n;i >= 1;--i){
		nxt[i] = hd[a[i]];
		hd[a[i]] = i;
	}
	memset(hd,0,sizeof hd);
	for(int i(1);i <= n;++i){
		if(hd[a[i]] == 0)	add(i);
		hd[a[i]] = i;
	}
	for(int i(1);i <= m;++i)	read(q[i].l),read(q[i].r),q[i].ind = i;
	sort(q+1,q+1+m);
	int l = 1;
	for(int i(1);i <= m;++i){
		while(l < q[i].l)	add(nxt[l]),++l;
		ans[q[i].ind] = query(q[i].r)-query(l-1);
	}
	for(int i(1);i <= m;++i)	printf("%d\n",ans[i]);
	return 0;
}

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

int main() {
cout<<fixed<<setprecision(10);
int N;
string S;
cin >>N >> S;

ll a=0;
ll count=0;
  
ll r,g,b;
  r=0;
  g=0;
  b=0;
  for (int i=0; i<N;i++){
  	if (S.at(i)=='R') r++;
    if (S.at(i)=='G') g++;
    if (S.at(i)=='B') b++;
  }
  a=r*g*b;

for (int i=0; i<N-2;i++){
    for (int j=i+1; j<N-1; j++){
      		int k=2*j-i;
      		if (k>=N) continue;
            if (S.at(i)!=S.at(j) && S.at(j)!=S.at(k) && S.at(i)!=S.at(k)) count++;
    }
}
  
  
cout <<a - count;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ld = long double;

int main() {
  int h,n,p,m,k;
  cin >> h>>n>>p>>m>>k;
  --p;
  vector<tuple<int,int>> vb;
  REP(i,m) {
    int a,b;
    cin>>a>>b;
    --b;
    vb.emplace_back(a,b);
  }
  reverse(ALL(vb));
  size_t bi = 0;
  vector<vector<ld>> dp(n, vector<ld>(k+1));
  dp[p][0] = 1.0;
  for (int i = h; i > 0; --i) {
    vector<vector<ld>> tmp(n, vector<ld>(k+1));
    int a=-1,b=-1;
    if (bi < vb.size()) tie(a, b) = vb[bi];
    if (a == i) {
      REP(j,k+1) {
        REP(l,n) {
          if (l != b && l != b+1) {
            tmp[l][j] += dp[l][j];
          } else if (l == b) {
            tmp[l+1][j] += dp[l][j];
          } else {
            tmp[l-1][j] += dp[l][j];
          }
        }
      }
      ++bi;
    } else {
      REP(j,k+1) {
        if (j < k) {
          ld prob = ld(k-j) / (i-m+bi);
          REP(l,n) {
            if (l == 0 || l == n-1) {
              tmp[l][j] += dp[l][j] * (1.0 - prob);
              tmp[l][j+1] += dp[l][j] * (ld(n-2) / (n-1)) * prob;
              if (l==0)   tmp[l+1][j+1] += dp[l][j] * prob / (n-1);
              if (l==n-1) tmp[l-1][j+1] += dp[l][j] * prob / (n-1);
            } else {
              tmp[l][j] += dp[l][j] * (1.0 - prob);
              tmp[l][j+1] += dp[l][j] * (ld(n-3) / (n-1)) * prob;
              tmp[l-1][j+1] += dp[l][j] * prob / (n-1);
              tmp[l+1][j+1] += dp[l][j] * prob / (n-1);
            }
          }
        } else {
          REP(l,n) tmp[l][k] += dp[l][k];
        }
      }
    }
    swap(tmp, dp);
  }
  ld res = 0;
  REP(i,n) res = max(res, dp[i][k]);
  cout << fixed << setprecision(10) << res << endl;
  return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,k;cin >>n>>k;
    ll a;
    vector<ll>cnt(50,0);
    for (int i = 0; i < n; ++i) {
        cin >>a;
        for (int j= 0; j< 50; ++j) {
            if((a>>j)&1LL){
                cnt[j]++;
            }
        }
    }
    ll ans=0;
    vector<ll>f(50,1);
    for (int l = 0; l < 49; ++l) {
        f[l+1]=f[l]*2;
    }
//    for (int i = 0; i < 5; ++i) {
//        cout <<cnt[i]<<endl;
//    }
    ll num=0;
    for (int i = 49; i>=0; --i) {
        if(num+f[i]<=k){
            if(cnt[i]<n-cnt[i]){
                num+=f[i];
                ans+=f[i]*(n-cnt[i]);
            }
            else {
                ans+=f[i]*cnt[i];
            }
        }
        else  {
            ans+=f[i]*cnt[i];
        }
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
double n,sum=0;
  cin >>n;
  vector<double>a(n),b(n);
  for(int i =0;i<n;i++){
    double z;
    cin >>z;
    sum+=z;
    a.at(i)=z;
    b.at(i)=z;
    }
  sum/=n;
  for(int i=0;i<n;i++){
    a.at(i)=abs(a.at(i)-sum);
    b.at(i)=a.at(i);
    }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
     if(a.at(0)==b.at(i)){
       cout << i <<endl;
       break;
       }
    }
}







Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF (1<<30)
#define LLINF (1ll<<60)
typedef long long ll;
int main(void){
	int d,n,i,ans=0;
	bool flag[100];
	fill(flag,flag+100,false);
	cin >> n;
	for(i=0; i<n; i++){
		cin >> d;
		d--;
		flag[d]=true;
	}
	for(i=0; i<100; i++){
		if(flag[i]){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> T(N), A(N), maxh(N);
    vector<bool> dec(N);
    for (int i = 0; i < N; ++i) {
        cin >> T[i];
        maxh[i] = T[i];
        if (i == 0 || T[i - 1] < T[i])
            dec[i] = true;
    }

    for (int i = 0; i < N; ++i)
        cin >> A[i];

    bool isok = true;
    for (int i = N - 1; i >= 0; --i) {
        if (dec[i] && maxh[i] > A[i]) {
            isok = false;
            break;
        }
        if (dec[i])
            continue;
        maxh[i] = min(maxh[i], A[i]);
        if (i == N - 1 || A[i] > A[i + 1]) {
            dec[i] = true;
            maxh[i] = A[i];
            if (maxh[i] > T[i]) {
                isok = false;
                break;
            }
        }
    }

    if (!isok) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for (int i = 0; i < N; ++i) {
        if (dec[i])
            continue;
        (ans *= maxh[i]) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
using namespace std;
typedef long long ll;

int dp[3003][3003];

int main(){
	//freopen("stl.gir", "r", stdin);
	
	string s, t;
	cin >> s >> t;
	
	dp[0][0] = (s[0] == t[0]);
	
	// dp[i][j] = max(dp[i-1][j], dp[i][j-1], eğer i == j dp[i-1][j-1]+1);
	
	for (int i = 0; i < s.size(); i++){
		for (int j = 0; j < t.size(); j++){
			if (i == 0 || j == 0){
				if (i == 0 && j != 0){
					dp[i][j] = (s[i] == t[j]) ? 1 : dp[i][j-1];
				} else if (j == 0 && i != 0){
					dp[i][j] = (s[i] == t[j]) ? 1 : dp[i-1][j];
				} 
				continue;
			}
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if (s[i] == t[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
		}
	}
	
	string crt = "";
	int i = s.size()-1;
	int j = t.size()-1;
	while (i != -1 && j != -1){
		if (i > 0 && dp[i-1][j] == dp[i][j]) i--;
		else if (j > 0 && dp[i][j-1] == dp[i][j]) j--;
		else {
			if (s[i] == t[j])
				crt += s[i];
			i--;
			j--;
		}
	}
	
	for (i = 0; i < crt.size()/2; i++){
		char tmp = crt[i];
		crt[i] = crt[crt.size()-i-1];
		crt[crt.size()-i-1] = tmp;
	}
	cout << crt << endl;
	
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1


#ifndef ONLINE_JUDGE
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
						 stringstream _ss(_s); \
						 istream_iterator<string> _it(_ss); \
						 err(_it, args); }
#else
#define error(args...)		42
#endif


void err(istream_iterator<string> it) { cerr << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "; ";
	err(++it, args...);
}


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
#endif
}

int ceil2(int a, int b){
    int c = a / b;
    if (c * b < a) c++;
    return c;
}


int32_t main()
{
	c_p_c();

	int n,k; cin>>n>>k;

	int a[n+1];

	for (int i = 1; i < n+1; ++i)
	{
		cin>>a[i];
	}
	int dp[n+1][k+1];

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

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

	int psum[k+1];

	for (int i = 1; i < n+1; ++i)
	{
		psum[0] = dp[i-1][0]%mod;
		for (int j = 1; j < k+1; ++j)
		{
			psum[j] = (psum[j-1]%mod + dp[i-1][j]%mod)%mod;
		}

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

			dp[i][j] = psum[j] - (j-min(a[i], j) - 1 >= 0 ? psum[j-min(a[i], j)-1] : 0);

			dp[i][j] += mod;

			dp[i][j] %= mod;
		}

	}

	cout << dp[n][k];
	
	return 0;
}

Measured memory_bytes: 83168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*既に塗った色の配列　tuple(親、子、その間の辺の色)の配列
  を用意
*/



int main(){
    vector<int> n;
    vector<int> num(101);
    for(int i = 1;i<=100;i++){
      num[i] = i;
    }
    vector<int> x;
    
    while(true){
      int N,X;
      cin >> N >> X;
      if(N == 0 && X == 0) break;
      n.push_back(N);
      x.push_back(X);
    }
    int nn = n.size();
    for(int i  = 0;i<n.size();i++){
      int c = 0;
      for(int j  = 1;j<=n[i];j++){
        for(int k = j+1;k<=n[i];k++){
          for(int l = k+1;l<=n[i];l++){
            if(num[j] + num[k] + num[l] == x[i]) c++;
          }
        }
      }
      cout << c << endl;
    }
  }


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll A[112345];
ll D[112345];

bool solve(ll N) {
  ll M = (N+1)*N/2;
  ll S = accumulate(A, A+N, 0LL);
  if (S % M != 0) return false;
  ll K = S / M; // ちょうど K 回操作する
  REP(i, N) {
    D[i] = A[(i+1) % N] - A[i];
  }

  REP(i, N) D[i] -= K;

  ll kk = 0;
  REP(i, N) {
    if (D[i] % N != 0) return false;
    if (D[i] > 0) return false;
    else kk -= D[i] / N;
  }
  return kk == K;
}

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();

  bool ans = solve(N);
  cout << (ans?"YES":"NO") << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if((a*b)%2==0){
		cout << "Even" << endl;
	}
	else{
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int  n , m , cou=0;

    char a[100000],s;
    while(cin >> a)
    {
        for(int i = 0; i < strlen(a); i+=2)
        {
            cout << a[i];
        }
        cout<<endl;
    }
    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  string s, t;
  cin >> n >> s >> t;
  int ans = 2*n;
  for(int i = 1; i <= n; ++i) {
    if(s.substr(n-i, i) == t.substr(0, i)) ans = 2*n-i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;
int a[100005];
int gcd(int a,int b)
{
    while(a^=b^=a^=b%=a);
    return b;
}
int main()
{
    int flag=0;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=a[i]/2;
    }
    int res=0;
    long long ans=1;
    for(int i=0;i<n;i++)
    {
        if(i>=2&&(a[i]/gcd(ans,a[i])%2==0||ans/gcd(ans,a[i])%2==0))
        {
            flag=1;
            break;
        }
        ans*=a[i]/gcd(ans,a[i]);
        if(ans>m)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        cout<<0;
    else
    {
        long long ens=ans;
        while(ens<=m)
        {
            res++;
            ens+=2*ans;
        }
        cout<<res;
    }
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
int a[100001];
vector<int> G[100001];

int solve(int idx)
{
  vector<int> ch;
  for(int& to : G[idx]) ch.push_back(solve(to));
  sort(all(ch)); reverse(all(ch));
  int ret = ch.size();
  rep(i, ch.size()) ret = max(ret, ch[i] + i);
  return ret + 1;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N;
  reps(i, 1, N) cin >> a[i], G[--a[i]].push_back(i);
  cout << solve(0)-1 << endl;

  return 0;
}


Measured memory_bytes: 15872
#include<stdio.h>
int sum(int n,int s,int m,int x,int k){
	if(s<m)	return 0;
	if(n==0){
		if(m==s)return 1;
		return 0;
	}
	int d=0;
	int i;
	int j;
	for(i=k;i<10;i++){
		d+=sum(n-1,s,m+i,x,i+1);
	}
	return d;
}
int main(){
	int n,s;
	for(;scanf("%d %d",&n,&s)&&(n||s);){
		printf("%d\n",sum(n,s,0,n,0));
	}
	return 0;
}

Measured memory_bytes: 0
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    float x;
    string s;
    float ans = 0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x;
        cin >> s;
        if (s == "JPY") {
            ans += x;
        } else {
            ans += (380000.0 * x);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
# coding:utf-8

N, K = map(int, input().split())
an = [int(input()) for i in range(N)]

an.sort()

lmin = an[-1] - an[0]

for i in range(N-K+1):
    bn = an[i+K-1] - an[i]
    if lmin >= bn:
        lmin = bn
    if lmin == 0:
        break

print(lmin)

Measured memory_bytes: 7384
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

struct A{
	int x,y,h;
}a[100];

int main()
{
	int N,X,Y,H,h;
	int j,s;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>a[i].x>>a[i].y>>a[i].h;
		if(a[i].h) s=i;
	} 
	for(X=0;X<=100;X++)
	{
		for(Y=0;Y<=100;Y++)
		{
			H=abs(a[s].x-X)+abs(a[s].y-Y)+a[s].h;
			for(j=0;j<N;j++)
			{
				h=max(H-abs(a[j].x-X)-abs(a[j].y-Y),0);
				if(h!=a[j].h)	break;
			}
			if(j==N) cout<<X<<' '<<Y<<' '<<H;
		}
	}
	return 0;
 } 

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

int main(void) {
	int A, B, K;
	cin >> A >> B >> K;
	vector<int> vec;
	for (int i = 1; i < A * B + 1; i++) {
		if (A % i == 0 && B % i == 0) {
			vec.push_back(i);
			// cout << i << endl;
		}
	}

	cout << vec[vec.size() - K] << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Long, Long> list = new HashMap<>();
		for(int i = 0; i < n; i++) {
			long a = sc.nextLong();
			if(list.containsKey(a)) {
				list.put(a, list.get(a) + 1);
			} else {
				list.put(a, (long) 1);
			}
		}
		long ans = 0;
		for(Map.Entry<Long, Long> e : list.entrySet()) {
			long key = e.getKey();
			long value = e.getValue();
			if(value < key) {
				ans += value;
			} else if(value > key) {
				ans += (value - key);
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 63956
#include <stdio.h>

int main() {
	int a,b,c,total;
	
	scanf("%d%d%d", &a, &b, &c);
		
	total = a+b;
	if(total > (b+c)) total = b+c;
	if(total > (c+a)) total = c+a;
	
	printf("%d\n", total);
	return 0;
}

Measured memory_bytes: 128