akhauriyash/Code-Regression huggingface dataset:
int main(int argc, const char * argv[]) {
    int a,b;
    scanf("%d %d",&a,&b);
    if(-1000<=a&&a<=1000&&-1000<=b&&b<=1000){
        if(a<b){
            printf("a < b\n");
        }if(a==b){
            printf("a == b\n");
        }if(a>b){
            printf("a > b\n");
        }
    }
        
    
    return 0;
}

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

int main(){
    int n,l;
    cin>>n>>l;
    vector<string>s;
    while(n--){
        string x;
        cin>>x;
        s.push_back(x);
    }
    sort(s.begin(),s.end());
    for(int i=0; i<s.size(); i++)cout<<s[i];
return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static final long MOD=1000000007;//998244353;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		long X=Math.abs(sc.nextLong());
		long K=sc.nextLong();
		long D=sc.nextLong();
		double x=X;
		double d=D;
		double k=K;
		if (x/d>=k) {
			System.out.println(X-K*D);
		}else {
			long c=X/D;
			if ((K-c)%2==0) {
				System.out.println(X%D);
			}else {
				System.out.println(Math.abs((X%D-D)));
			}
			
		}
 	}
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 32484
if __name__ == "__main__":
    N, T = map(lambda x: int(x), input().split())
    table = [0] * (T + 1)
    for idx in range(N):
        l, r = map(lambda x: int(x), input().split())
        table[l] += 1
        table[r] -= 1

    ans = table[0]
    for idx in range(1, T + 1):
        table[idx] += table[idx - 1]
        ans = max(ans, table[idx])

    print(ans)



Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define FDST int hogehogehoge;cin>>hogehogehoge
#define int long long

int foo(string s){//cout<<"s "<<s<<endl;
  int size = s.size(), ans = 0;
  for(int i = size-1, d = 1; i >= 0; i--, d *= 10){
    ans += d*( s[i]- '0');
  }
  //cout<<"ans "<<ans<<endl;
  return ans;
}

signed main(){
  map<string, int> ma;
  string S;
  int n;

  while(true){
    cin>>S;
    if(S == "END_OF_FIRST_PART") break;
    cin>>n;
    ma[S] = n;
  }

  while(true){
    int ans = 0;
      stack<int> st;
    cin>>S;
    if(S == "0")break;
    int size = S.size();
    for(int i  = 0; i < size; i++){ //cout<<i<<endl;//if(!st.empty())cout<<i<<" "<<st.top()<<endl;
      int  tn;
      if('A' <= S[i] && S[i] <= 'Z'){
	string temp; temp +=  S[i];
	if(i == size - 1){
	  tn = ma[temp];
	  //cout<<"tn "<<tn<<endl;
	  if(tn){
	    st.push(tn);
	  } else {
	    ans = -1;
	    break;
	  }
	} else {
	  if('a' <= S[i+1] && S[i+1] <= 'z'){
	    temp += S[i+1];
	    tn = ma[temp];
	    if(tn){
	      st.push(tn);
	    } else {
	      ans = -1;
	      break;
	    }
	    i++;
	  } else{
	    tn = ma[temp];
	    if(tn){
	      st.push(tn);
	    } else {
	      ans = -1;
	      break;
	    }
	  }
	  
	}
      } else if(S[i] == '('){
	st.push(-1);
      } else if(S[i] == ')'){
	int stemp = 0;
	while(true){
	  int stemp2 = st.top(); st.pop();
	  if(stemp2 == -1)break;
	  stemp += stemp2;
	}
	st.push(stemp);	
      } else if('0' <= S[i] && S[i] <= '9'){
	string num;
	int j = i;
	while(true){
	  if(j == size) break;
	  if('0' <= S[j] && S[j] <= '9') num += S[j];
	  else break;
	  j++;
	}
	i = j-1;
	int n = foo(num), tnn;
	//cout<<"n = "<<n<<endl;
	tnn = st.top(); st.pop();
	//cout<<"tnn "<<tnn<<endl;
	st.push(n*tnn);
      }
    }
   
    
    if(ans == -1) cout<<"UNKNOWN"<<endl;
    else {
      while(!st.empty()){
	ans += st.top(); st.pop();
      }
      cout<<ans<<endl;
    } 
  }
  

  return 0;
}



Measured memory_bytes: 3068
a = int(input())
s = []
s.append(a)
for i in range(1000000):
    if s[i] % 2 == 0:
        next = s[i] // 2
    else:
        next = 3 * s[i] + 1
    if next in s:
        ans = i + 2
        print(ans)
        break
    else:
        s.append(next)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
int main(int argc, char const *argv[]) {
    std::string even,odd;
    std::cin >> odd >> even;
    int total=odd.size()+even.size();
    for (size_t i = 0; i < total; i++) {
        if (i%2==0) {
            std::cout << odd[i/2];
        }else{
            std::cout << even[(i-1)/2];
        }
    }
    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            ans++;
            a[i] = -1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	int number[3][3];
	bool bingo[3][3] = { false };

	for (size_t i = 0; i < 3; i++)
	{
		for (size_t j = 0; j < 3; j++)
		{
			std::cin >> number[i][j];
		}
	}

	int n;
	std::cin >> n;

	for (size_t i = 0; i < n; i++)
	{
		int b;
		std::cin >> b;
		for (size_t j = 0; j < 3; j++)
		{
			for (size_t k = 0; k < 3; k++)
			{
				if (number[j][k] == b) {
					bingo[j][k] = true;
				}
			}
		}
	}

	for (size_t i = 0; i < 3; i++)
	{
		int flag = true;
		for (size_t j = 0; j < 3; j++)
		{
			if (bingo[i][j] == false) {
				flag = false;
			}
		}
		if (flag == true) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
		flag = true;
		for (size_t j = 0; j < 3; j++)
		{
			if (bingo[j][i] == false) {
				flag = false;
			}
		}
		if (flag == true) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}

	if ((bingo[0][0] && bingo[1][1] && bingo[2][2]) || (bingo[0][2] && bingo[1][1] && bingo[2][0])) {
		std::cout << "Yes" << std::endl;
		return 0;
	}
	std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		
		String[] s = r.readLine().split(" ");
		int[] stack = new int[s.length];
		int topOfStack = 0;
		
		for (int i = 0; i < s.length; i++) {
			switch (s[i].charAt(0)) {
				case '+':
					topOfStack--;
					stack[topOfStack-1] = stack[topOfStack - 1] + stack[topOfStack];
					break;
				case '-':
					topOfStack--;
					stack[topOfStack-1] = stack[topOfStack - 1] - stack[topOfStack];
					break;
				case '*':
					topOfStack--;
					stack[topOfStack-1] = stack[topOfStack - 1] * stack[topOfStack];
					break;
				default:
					stack[topOfStack] = Integer.parseInt(s[i]);
					topOfStack++;
					break;
			}
		}
		
		System.out.println(stack[0]);
	}
	
}


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

using namespace std;

int n,mydata[200002]={0},temp;

int main()

{

    scanf("%d",&n);

    for(int i=2;i<=n;i++)

    {

        scanf("%d",&temp);

        mydata[temp]++;

    }

    for(int i=1;i<=n;i++)

        printf("%d\n",mydata[i]);

    return 0;

}

Measured memory_bytes: 4504
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e5+10;
int n,v[N],len;
char s[N],t[N];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	for (int i=1;i<=n;++i) 
		if (s[i]=='x') ++v[len];
		else t[++len]=s[i];
	int ans=0;
	for (int i=1;i<=(len+1)>>1;++i) 
		if (t[i]!=t[len-i+1]) return puts("-1"),0;
		else ans+=abs(v[i-1]-v[len-i+1]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

#[fastout]
fn main() {
   input! {
      n: usize,
      cn: usize,
      d: [[usize;cn];cn],
      c: [[Usize1;n];n]
   }

   let mut cx = vec![vec![0; cn]; 3];
   for i in 0..n {
      for j in 0..n {
         cx[(i + j) % 3][c[i][j]] += 1;
      }
   }
   let mut ans = std::usize::MAX;
   for c0 in 0..cn {
      for c1 in 0..cn {
         if c0 == c1 {
            continue;
         }
         for c2 in 0..cn {
            if c2 == c0 || c2 == c1 {
               continue;
            }
            let mut x = 0;
            for k in 0..3 {
               for i in 0..cn {
                  x += cx[k][i]
                     * match k {
                        0 => d[i][c0],
                        1 => d[i][c1],
                        _ => d[i][c2],
                     };
               }
            }
            ans = std::cmp::min(ans, x);
         }
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 4792
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int l[200000];
int r[200000];
int p[100000];
int q[100000];
int dp[501][501];
int th[6];
int main() {
  int n,i;
  cin >> n >> i;
  cout << (n - i + 1)  << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x;
cin>>x;

x/=100;
x=10-x/2;
if(x>=9)
    x=8;
cout<<x<<endl;
















    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000003;
ll Q;
ll mod_pow(ll x, ll n, ll mod=MOD){
    if (n==0) return 1;
    ll res=mod_pow(x*x%mod, n/2, mod);
    if (n%2==1) res=res*x%mod;
    return res;
}
ll extgcd(ll a, ll b, ll& x, ll&y){
    ll d=a;
    if(b!=0){
        d=extgcd(b, a%b, y, x);
        y-=(a/b)*x;
    }
    else {
        x=1; y=0;
    }
    return d;
}
ll mod_inverse(ll a, ll m=MOD){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
const int MAX_N=1000010;
ll fact[MAX_N], invfact[MAX_N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>Q;
    fact[0]=1;
    invfact[0]=1;
    rep(i,1,MAX_N){
        fact[i]=fact[i-1]*i%MOD;
        invfact[i]=mod_inverse(fact[i]);
    }
    rep(_,0,Q){
        ll x,d,n;
        cin>>x>>d>>n;
        if(d==0){
            cout <<mod_pow(x, n)<<"\n";
        }
        else{
            if(x==0){
                cout <<0<<"\n";
                continue;
            }
            if(n==1){
                cout <<x<<"\n";
                continue;
            }
            ll k=-x*mod_inverse(d)%MOD;
            k=(k+MOD)%MOD;
            if(k<=n-1){
                cout <<0<<"\n";
                continue;
            }
            cout <<((mod_pow(-d, n)*fact[k]%MOD*invfact[k-n]%MOD)+MOD)%MOD<<"\n";
        }
    }
}

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

vector<int> g[100009];
int dfs(int cur) {
  vector<int> num;
  for (int to: g[cur]) {
    num.push_back(dfs(to));
  }
  sort(num.begin(), num.end());
  int ans = 0;
  for (int n: num) {
    ans += max(n - ans, 0) + 1;
  }
  return ans;
}
int main() {
  int n;
  cin>>n;
  for (int i=1; i<n; i++) {
    int a;
    cin>>a;
    --a;
    g[a].push_back(i);
  }
  cout<<dfs(0)<<endl;
}

Measured memory_bytes: 13568
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = readline().decode().rstrip()
ans = 0
for i in range(1, n):
    cnt = 0
    for j in set(s[:i:]):
        if j in set(s[i::]):
            cnt += 1
    ans = max(ans, cnt)
print(ans)


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

#define pb push_back
#define f first 
#define s second
#define ll long long
#define FOR(i, s) for(int i = 0; i<s; i++)
#define sz(s) (int)s.size()
#define vi vector<int>
#define ii pair<int, int>
#define vvi vector<vi>

ll n, m, q;

const ll mod = 1e9+7; 

int A[80][80], B[80][80], C[80][80];
bitset<80*2*80> dp[80][80];

void dodaj(bitset<80*2*80>&a, bitset<80*2*80>&b, int val){
	a |= (b << val);
	a |= (b >> val);
	for(int i = 0; i < val; i++)
		if(b[i])
			a[val-i] = 1;
}

bool good(int x, int y){
	return x >= 0 && x < n && y >= 0 && y < m;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	cin >> n >> m;
	FOR(i, n)
		FOR(j, m)
			cin >> A[i][j];
	FOR(i, n)
		FOR(j, m){
			cin >> B[i][j];
			C[i][j] = abs(A[i][j] - B[i][j]);
		}
	dp[0][0][C[0][0]] = 1;
	FOR(i, n)
		FOR(j, m){
			if(i+j == 0)
				continue;
			if(good(i-1, j))
				dodaj(dp[i][j], dp[i-1][j], C[i][j]);
			if(good(i, j-1))
				dodaj(dp[i][j], dp[i][j-1], C[i][j]);
		}
	FOR(i, 80*2*80)
		if(dp[n-1][m-1][i]){
			cout << i << '\n';
			exit(0);
		}
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

using ll = long long;
int const MOD = 1000000007;

vector<ll> factorials;
void init_factorial(int N)
{
    factorials.assign(N+1, 1);
    rep(i, 2, N+1)
    {
        factorials[i] = factorials[i-1] *i;
        factorials[i] %= MOD;
    }
}

ll power_mod(ll n, ll m)
{
    ll res = 1;
    ll base = n;
    while (m > 0)
    {
        if (m&1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        m >>= 1;
    }
    return res;
}

ll inv_mod(ll n)
{
    return power_mod(n, MOD-2);
}

ll comb(ll n, ll m)
{
    m = min(m, n-m);
    ll res = factorials[n];
    res *= inv_mod(factorials[n-m]);
    res %= MOD;
    res *= inv_mod(factorials[m]);
    res %= MOD;
    return res;
}

ll perm(ll n, ll m)
{
    ll res = factorials[n];
    res %= MOD;
    res *= inv_mod(factorials[n-m]);
    res %= MOD;
    return res;
}

int main()
{
    init_factorial(1000000);

    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    rep(i, 0, N+1)
    {
        ll now = comb(N, i);
        now *= perm(M-i, N-i);
        now %= MOD;
        ans += (i&1)? MOD-now: now;
        ans %= MOD;

        // printf("i: %lld, now: %lld\n", i, now);
    }
    ans *= perm(M, N);
    ans %= MOD;

    if (ans<0) ans += MOD;

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


Measured memory_bytes: 11020
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

int main(void) {
    int n; cin >> n;
    string s; cin >> s;
    REP(i, (int)s.size()) {
        if (s[i] + n > 'Z') cout << (char)('A' + s[i] + n - 1 - 'Z');
        else cout << (char)(s[i] + n);
    }
    cout << endl;
}

Measured memory_bytes: 256
function main(input){
    let nums = input.split("\n").map(x=>parseInt(x));
    let length = nums.shift();
    let count=0;
    for(let i=0;i<length;i++){
        if(nums[i]===1) continue;
        if(nums[i]===2) {
            count++;
            continue;
        }
        if(nums[i]%2===0)continue;
        let j=3;
        let notPrime=false;
        while(j<=Math.sqrt(nums[i])){
            if(nums[i]%j===0){
                notPrime=true;
                break;
            }
            j+=2;
            
        }
        if(!notPrime) {
            count++;
        }
    }

   
    console.log(count);
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


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

int main() {
  int N, P,W,G,Y;
  string S;
  cin >> N ;
  P,W,G,Y = 0;
  string sum ;
  
  for(int i = 0; i < N ; i++){
    cin >> S ;
    if (S == "P" ){
      P = 1;
    }
    else if (S == " W " ){
      W = 1;
    }
    else if ( S == "G"){
      G = 1;
    }
    else if ( S == "Y"){
      Y = 1;
    }
    
  }
  if( P + G + W + Y == 3){
    sum = "Three";
  }
   else if(P+G+W+Y == 4){
    sum ="Four";
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int box[4]={0},num=1,plus=0;
	char blood[10];
	while(scanf("%s",blood)!=EOF){
		if(blood[2+plus]=='A'){
			if(blood[3+plus]=='B'){box[2]++;}
			else {box[0]++;}
		}
		else if(blood[2+plus]=='B'){box[1]++;}
		else{box[3]++;}
		num++;
		if(num>=10)plus=1;
		if(num>=100)plus=2;
		if(num>=1000)plus=3;
	}
		for(num=0;num<4;num++){printf("%d\n",box[num]);}
	return 0;
}

Measured memory_bytes: 540
n = int(input())
a = list(map(int,input().split()))

s = sum(a)
one = n * (n+1) // 2
if s % one:
    print('NO')
    exit()
times = s // one

cnt = 0
b = a[1:]+[a[0]]
for i,j in zip(a,b):
    dif = j - i
    if (times - dif) % n:
        print('NO')
        exit()
    if (times-dif) // n < 0:
        print('NO')
        exit()
    cnt += (times-dif) // n
if times != cnt:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 14492
#include<stdio.h>

void insertionsort(int A[], int N);

int main(void)
{
    int N;
    
    scanf("%d", &N);
    
    int A[N];
    
    for(int i=0; i<N; i++)
    {
        scanf("%d", &A[i]);
        
    }
    
    for(int l=0; l<N; l++)
    {
        if(l>0)
        {
            printf(" ");
        }
        printf("%d", A[l]);
        
    }
    
    printf("\n");
    
    insertionsort(A, N);
    
}

void insertionsort(int A[], int N)
{
    int j, record;
    
    for(int i=1; i<N; i++)
    {
        record = A[i];
        j = i-1;
        
        while(j>=0 && A[j] > record)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = record;
        
        for(int k=0; k<N; k++)
        {
            if( k > 0)
            {
                printf(" ");   
            }
            
            printf("%d", A[k]);
        }
        
        printf("\n");
        
    }
    
    
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)

class Cube {
public:
    int f[6];

    Cube() {}

    void roll_z() { roll(1, 2, 4, 3); }//
    void roll_y() { roll(0, 2, 5, 3); }//
    void roll_x() { roll(0, 1, 5, 4); }//
    void roll(int i, int j, int k, int l) {
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    };

    void move(char ch) {
        if (ch == 'E') REP(i, 3) roll_y();
        if (ch == 'W') roll_y();
        if (ch == 'N') roll_x();
        if (ch == 'S') REP(i, 3) roll_x();
    }
};

int main() {
    Cube c;
    string com;

    REP(i, 6) cin >> c.f[i];
    cin >> com;

    REP(i, com.size()) c.move(com[i]);
    cout << c.f[0] << endl;
}

Measured memory_bytes: 3220
s = input()
n = len(s)
score = 0
for i in range(2**(n - 1)):
    temp = s[0]
    for j in range(n - 1):
        #j桁目が1の時
        if (i>>j)&1:
            temp += '+' + s[j + 1]
        #ｊ桁目が0の時
        else:
            temp += s[j + 1]
    score += eval(temp)

print(score)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a, b, str; cin >> a >> b;
	if (a.size() > b.size())str = "GREATER";
	else if (a.size() < b.size())str = "LESS";
	else if (a == b)str = "EQUAL";
	else for (int i = 0; i < a.size(); i++){
		if (a[i] == b[i])continue;
		else{
			if (a[i] - '0' > b[i] - '0')str = "GREATER";
			else str = "LESS";
			break;
		}
	}
	cout << str << endl;
}

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

int main(){
    while(1){
        int h,w;
        cin >> h >> w;
        if(h==0) break;
        
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if((i+j)%2==0){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
//abc170
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll x,n;
    cin>>x>>n;
    V<ll> a(n);
    cinf(n,a);
    sort(all(a));
    ll ans=INF;
    ll cnt=INF;
    set<ll> st; 
    for(ll i=-1000;i<=1000;i++) st.insert(i);
    rep(i,n){
        if(st.count(a[i])) st.erase(a[i]);
    }
    for(auto it:st){
        ll v=*begin(st);
        st.erase(v);
        if(abs(x-v)<cnt){
            ans=v;
            cnt=abs(x-v);
        }
    }
    /*rep(i,n){
        if(abs(x-a[i])<cnt){
            cnt=abs(x-a[i]);
            ans=a[i];
        }
    }*/
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

template<class T> struct dinic {
  struct edge {
    int to, rev;
    T cap;
  };
  static constexpr T inf = numeric_limits<T>::max();
  vector<vector<edge>> g;
  vector<int> dist, i;
  dinic(int n) : g(n), dist(n), i(n) {}
  void add(int from, int to, T cap, bool directed = true) {
    assert(cap >= 0);
    if (from == to or cap == 0) return;
    g[from].push_back({to, (int)g[to].size(), cap});
    g[to].push_back({from, (int)g[from].size() - 1, directed ? 0 : cap});
  }
  void bfs(int s) {
    fill(begin(dist), end(dist), -1);
    queue<int> que;
    dist[s] = 0, que.push(s);
    while (not que.empty()) {
      int v = que.front();
      que.pop();
      for (auto&& e : g[v]) if (e.cap and dist[e.to] == -1)
        dist[e.to] = dist[v] + 1, que.push(e.to);
    }
  }
  T dfs(int v, int s, T f) {
    if (v == s) return f;
    for (; i[v] < (int)g[v].size(); ++i[v]) {
      edge &e = g[v][i[v]];
      if (g[e.to][e.rev].cap and dist[e.to] < dist[v])
        if (T d = dfs(e.to, s, min(f, g[e.to][e.rev].cap)))
          return g[e.to][e.rev].cap -= d, e.cap += d, d;
    }
    return 0;
  }
  T max_flow(int s, int t) {
    assert(s != t);
    T res = 0;
    while (true) {
      bfs(s);
      if (dist[t] == -1) return res;
      fill(begin(i), end(i), 0);
      while (T f = dfs(t, s, inf)) res += f;
    }
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> u(m), v(m);
    for (int i = 0; i < m; ++i) {
      cin >> u[i] >> v[i];
      --u[i], --v[i];
    }
    auto chk = [&](int lower, int upper) {
      int s = n + m, t = s + 1, ss = t + 1, tt = ss + 1;
      dinic<int> g(tt + 1);
      vector<int> b(ss);
      auto add = [&](int from, int to, int lcap, int ucap) {
        g.add(from, to, ucap - lcap);
        b[to] += lcap;
        b[from] -= lcap;
      };
      for (int i = 0; i < m; ++i) {
        add(s, i, 1, 1);
        add(i, m + u[i], 0, 1);
        add(i, m + v[i], 0, 1);
      }
      for (int j = 0; j < n; ++j) {
        add(m + j, t, lower, upper);
      }
      add(t, s, m, m);
      for (int i = 0; i < ss; ++i) {
        g.add(ss, i, max(+b[i], 0));
        g.add(i, tt, max(-b[i], 0));
      }
      g.max_flow(ss, tt);
      for (auto&& e : g.g[ss]) {
        if (e.cap) {
          return false;
        }
      }
      return true;
    };
    [&] {
      for (int d = 0; ; ++d) {
        for (int l = m / n; l >= 0; --l) {
          if (chk(l, l + d)) {
            cout << l << ' ' << l + d << '\n';
            return;
          }
        }
      }
    }();
  }
}



Measured memory_bytes: 3560
def main():
    from collections import Counter
    n, m, *abc = map(int, open(0).read().split())
    a = Counter(abc[:n])
    bc = abc[n:]
    for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

    cnt = n
    ans = 0
    keys = sorted(list(a.keys()), reverse=True)
    
    for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

    print(ans)


if __name__ == '__main__':
    main()


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

#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 ALL(v) v.begin(), v.end()

int N;
vector<int64_t> A;

int INIT = 1000;

int64_t MONEY;
int64_t KABU;

int main() {
  //std::cout << std::fixed << std::setprecision(20);
  
  
  cin >> N;
  A = vector<int64_t>(N,0);
  REP(i,N){
    cin >> A[i];
  }

  MONEY = INIT;
  KABU = 0;

  REP(i,N){
    //ノーポジ
    if(i == N-1){
      MONEY += A[i] * KABU;
      KABU = 0;
      cout << MONEY << endl;
      return 0;
    }
    
    //買い時
    if(A[i] < A[i+1] ){
      double tmp = MONEY / (double)A[i];
      KABU += (int64_t)tmp;
      MONEY -= A[i] * (int64_t)tmp;
      
      continue;
    }
    
    //売り時
    if(A[i] > A[i+1]){
      MONEY += A[i] * KABU;
      KABU = 0;
      continue;
    }
    
    
    
  

  }

}

Measured memory_bytes: 3672
#include <iostream>

int main( void ) {
    int r, g, b;

    // 3つの数の並びを読み込む
    std::cin >> r >> g >> b;

    // r, g, bを左から並べるということは
    // つまり
    // 100の位はr
    //  10の位はg
    //   1の位はb
    // ということ。
    // そこで、実際にそういう数を作ってみる。
    const int number = r*100 + g*10 + b*1;

    // 並べた数が4の倍数かどうかを調べる。
    // 4の倍数であるということは、
    // 「4で割ってあまりがない(0である)」
    // ということだ。
    if( number % 4 == 0 ) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < 3; i++)
            {
                if (s[i] == '1')
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,x,t;
  x=0;
  cin>>a>>b;
  int i;
  for(i=0;i<b;i++)
  {
    cin>>t;
    x+=t;
  }
  if(x>a)
    cout<<"-1"<<endl;
  else
    cout<<a-x<<endl;
  return 0;
}

Measured memory_bytes: 3624
// Nurstan Duisengaliev
// ASA KONKRETNO KATAIMASH

/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/                   
      
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
 
using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;                         

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;

void solve () {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max ({a * c, a * d, b * d, b * c});
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void) {

    int a,b,d,r;
    double f;

    scanf("%d%d",&a,&b);
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    printf("%d %d %.6lf\n",d,r,f);

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	char S[12];
	scanf("%s", S);
	if (10 * (S[5] - '0') + S[6] - '0' <= 4) printf("Heisei\n");
	else printf("TBD\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1620
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	int broj=0;
	int brojac=0;
	for(int i=1;i<=100000;i++)
	{
		int broj=i*a;
		if(broj%b==c)
		{
			cout<<"YES"<<endl;
			return 0;
		}

	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        
        for(int i=0;i<K;i++){
            if(i % 2 == 0){
                B += A / 2;
                A /= 2;
                
            }else{
                A += B / 2;
                B /= 2;
            }            
        }
        System.out.println(A+" "+B);
    }
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll K; cin >> K;
	vector<vll> dp (100, vll (10));
	F0R(i, 10) dp[0][i] = 1;
	FOR(i, 1, 100) {
		F0R(j, 10) {
			dp[i][j] += dp[i-1][j];
			if (j - 1 >= 0) dp[i][j] += dp[i-1][j-1];
			if (j + 1 < 10) dp[i][j] += dp[i-1][j+1];
		}
	}

	
	int ai = 100;
	int aj = 100;
	ll total = 0;
	ll gay = 0;
	F0R(i, 100) {
		F0R(j, 10) {
			total += dp[i][j];
			if (j == 0) K += dp[i][j];
			if (K <= total) {
				ai = i;
				aj = j;
				i = 100;
				j = 10;
			}
			// if (j == 0) total += dp[i][j];
		}
	}
	// print(ai, aj);
	// print(lt[0]);
	// print(lt[1]);
	K = total - K;
	string ans = "";
	while (ai >= 0) {
		// print(ai, aj);
		ans += to_string(aj);
		if (ai == 0) break;
		
		if (aj + 1 < 10 && dp[ai-1][aj+1] > K) {
			aj = aj + 1;
		} else {
			if (aj + 1 < 10) K -= dp[ai-1][aj+1];
			if (dp[ai-1][aj] > K) {
				aj = aj;
			} else {
				K -= dp[ai-1][aj];
				aj = aj - 1;
			}
		}
		--ai;
	}
	print(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int x, a, b;

    cin >> x >> a >> b;

    if (b - a > x)
    {
        cout << "dangerous" << endl;
    }
    else if (b - a > 0)
        cout << "safe" << endl;
    else
        cout << "delicious" << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
sum=0
for i in range(n-2):
    if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
        sum+=1
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
string s;

int32_t main(){_

   cin>>n;
   cin>>s;

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      if(s[i] != '.'){
         ans++;
      }
   }

   int fans = ans, pref = ans, suff = 0;
   for (int i = n-1; i >= 0; --i)
   {
      if(s[i] == '#')
         --pref;
      if(s[i] == '.'){
         suff++;
      }
      tr(i, s[i], fans, pref, suff);
      smin(fans, pref+suff);         
   }
   
   cout<<fans;
   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

Measured memory_bytes: 720
#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime> 
#include <stack>
#include <iostream>
#include <fstream>

#define mp make_pair
#define pb push_back

using ll = long long;
using ld = long double;

using namespace std;

const int MAXN = 200001;

int w[MAXN];

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(20);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		w[a]++, w[b]++;
	}
	for (int i = 1; i <= n; i++) {
		if (w[i] & 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "NO\n"; return;}
#define yes {cout << "YES\n"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int MOD = 1e9 + 7;

map <int, int> factorize(int x) {
    map <int, int> ans;
    for (int i = 2; i * i <= x; ++i)
        while (x % i == 0) {
            x /= i; ++ans[i];
        }
    if (x > 1)
        ++ans[x];
    return ans;
}

int binpow(int x, int d) {
    int ans = 1;
    while (d) {
        if (d & 1)
            ans = ans * x % MOD;
        x = x * x % MOD;
        d >>= 1;
    }
    return ans;
}

void solve() {
    int n; cin >> n;
    vector <int> a(n);
    map <int, int> d;
    loop(i, n) {
        cin >> a[i];
        map <int, int> cd = factorize(a[i]);
        for (auto it : cd)
            d[it.F] = max(d[it.F], it.S);
    }
    int mult = 1;
    for (auto it : d)
        loop(i, it.S)
            mult = mult * it.F % MOD;
    int ans = 0;
    loop(i, n)
        ans = (ans + mult * binpow(a[i], MOD - 2)) % MOD;
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 4204
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll a,b,c;cin>>a>>b>>c;

  ll ans=0;
  if(a==b&&b==c&&c==a&&a%2==0)out(-1);
  else{
    ll l,m,n;
    while(a%2==0&&b%2==0&&c%2==0){
      l=a/2,m=b/2,n=c/2;
      a=m+n;
      b=l+n;
      c=l+m;
      ans++;
    }
    out(ans);
  }


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main() {
    int n;
    scanf("%d",&n);
    int x,mm=-1,ans=0;
    for(int i=0;i<n;++i) {
        scanf("%d",&x);
        if(x>=mm) {
            mm = x;
        }
        if(mm <= x) {
            ans++;
        }
    }
    printf("%d\n",ans);
}

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

int main(){
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	while(1) {
		if(n == 0) break;
		n /= k;
		ans++;
	}
	cout << ans << endl;
}

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

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int k3(int v, int r) {
    return v + (v * r) / 100;
  }

  int pop_count(int bs) {
    int cnt = 0;
    for (int i = 0; i < 16; ++i) {
      cnt += (bs >> i) & 1;
    }
    return cnt;
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    for (; ; ) {
      int x = ni();
      int y = ni();
      int s = ni();

      if ((x | y | s) == 0) {
        break;
      }

      int ans = 0;
      for (int l = 1; l < s; ++l) {
        for (int r = 1; r < s; ++r) {
          if (k3(l, x) + k3(r, x) == s) {
            ans = Math.max(ans, k3(l, y) + k3(r, y));
          }
        }
      }

      System.out.println(ans);
    }
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 29760
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (x, y) = (v[0], v[1]);
    if x == 2 || y == 2 {
        println!("No");
        return;
    }
    let g2 = vec![4, 6, 9, 11].into_iter().collect::<HashSet<_>>();
    if g2.contains(&x) == g2.contains(&y) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];

	sort(A.begin(), A.end());
	ll ma = A.back();
	double h = ma * 0.5;
	ll t;
	double abs_t{INF};

	for (ll i = 0; i < N; ++i)
	{
		if (abs_t > abs(A[i] - h))
		{
			abs_t = abs(A[i] - h);
			t = A[i];
		}
	}

	std::cout << ma << " " << t << std::endl;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))

ans = 0
c = 0
tmp_m = 10**9
zero = False
for i in range(n):
    if a[i] < 0:
        c += 1
    elif a[i] == 0:
        zero = True
    tmp = abs(a[i])
    ans += tmp
    tmp_m = min(tmp_m,tmp)

if zero:
    print(ans)
else:
    if c%2 == 0:
        print(ans)
    else:
        print(ans-tmp_m*2)


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

const int MAX = 210000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
    COMinit();
    int K, N;
    cin >> K >> N;
    for (int query = 2; query <= K*2; ++query) {
        long long res = 0;
        int Q = query;
        if (query > K + 1) Q = (K+1)*2 - query;
        int a = Q/2;
        for (int i = 0; i <= a; ++i) {
            long long tmp = COM(a, i) * COM(K - a + N - i - 1, N - i) % MOD;
            res = (res + tmp) % MOD;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
    double A,B,K;
    cin >> A >> B >> K;
    for(int i = A; i <= B; i++){
        if(i < A+K or B-K < i){
            cout << i << endl;
        }
    }
}



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

const int MAX = 998244353;
 
 


vector<int> k[26];
signed main(){
    string s,t;
    cin>>s >>t;
    
    for(int i=0;i<s.size();i++){
        k[s[i]-'a'].push_back(i);
    }
    int ans1=0,ans2=-1,ok,ng,mid;
    for(int i=0;i<t.size();i++){
        if(k[t[i]-'a'].size()==0){
                cout<<-1;
                return 0;
            }
        if(ans2>=k[t[i]-'a'][k[t[i]-'a'].size()-1]){
           ans1++;
            
            ans2=k[t[i]-'a'][0];
     
        }else{
            ng=-1;ok=k[t[i]-'a'].size()-1;
        while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            if(ans2<k[t[i]-'a'][mid]){
                ok=mid;
            }else ng=mid;
        }
         ans2=k[t[i]-'a'][ok];
       
        }
        
      
    }
    cout<<ans1*s.size()+ans2+1;

    
    return 0;
}

Measured memory_bytes: 1724