akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}

int main()
{
    int H, W; cin >> H >> W;
    vector<string> S(H); cin >> S;

    vector<vector<int>> dp(H, vector<int>(W, INT_MAX));

    dp[0][0] = (S[0][0] == '#');

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j + 1 < W) {
                chmin(dp[i][j+1], dp[i][j] + (S[i][j] == '.' && S[i][j+1] == '#'));
            }
            if (i + 1 < H) {
                chmin(dp[i+1][j], dp[i][j] + (S[i][j] == '.' && S[i+1][j] == '#'));
            }
        }
    }

    cout << dp.back().back() << endl;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (R, G, B) = listOf(0, 1, 2)
    val N = nextInt()
    val S = next()
    val A = S.map {
        when(it) {
            'R' -> 0
            'G' -> 1
            'B' -> 2
            else -> 999
        } }
    val RGB = Array(3) { IntArray(N) }
    A.forEachIndexed { index, ch -> RGB[ch][index] = 1 }
    for (m in 0 until 3)
        for (n in (1 until N).reversed()) RGB[m][n - 1] += RGB[m][n]
    fun get(c: Int, n: Int, m: Int): Int {
        var p = RGB[c][m + 1]
        if (p > 0 && m + (m - n) < N && c == A[m + (m - n)]) p -= 1
        return p
    }
    fun getC(n: Int, c1: Int, c2: Int): Long {
        var c = 0L
        for (m in n + 1 until N - 1) {
            when (A[m]) {
                c1 -> c += get(c2, n, m)
                c2 -> c += get(c1, n, m)
                else -> { }
            }
        }
        return c
    }
    var ans = 0L
    for (n in 0 until N - 2) {
        when (A[n]) {
            R -> { ans += getC(n, G, B) }
            G -> { ans += getC(n, B, R) }
            B -> { ans += getC(n, G, R) }
        }
    }
    return println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfInt(vararg offset: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + offset[index % offset.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfLong(vararg offset: Long) = listOfString().map { java.lang.Long.parseLong(it) }.mapIndexed { index, long -> long + offset[index % offset.size] }
fun listOfDouble(offset: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + offset }
fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }


Measured memory_bytes: 39704
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll dat[800005];
ll n;
void init(ll n_){
n=1;
  while(n<=n_)
    n*=2;
}
void add(ll k,ll a){
k+=n-1;
  dat[k]+=a;
  while(0<k){
  k=(k-1)/2;
    dat[k]=dat[2*k+1]+dat[2*k+2];
  }
}
ll query(ll a,ll b,ll k,ll l,ll r){
if(a<=l && r<=b)
  return dat[k];
  else if(b<=l || r<=a)
    return 0;
  else{
  ll val=query(a,b,2*k+1,l,(l+r)/2);
    ll var=query(a,b,2*k+2,(l+r)/2,r);
    return (val+var);
  }

}
ll N,K;
int main(){
  cin>>N>>K;init(N);
  vector<ll>a(N+1);a[0]=0;
  for(int i=1;i<=N;i++){
  ll x;cin>>x;x-=K;
    a[i]=a[i-1]+x;
  }vector<ll>b(N+1);
  for(int i=0;i<=N;i++)
    b[i]=a[i];
  sort(b.begin(),b.end());
  map<ll,ll>M;ll x=0;M[b[0]]=0;
  for(int i=1;i<=N;i++)
    if(b[i]!=b[i-1]){x++;M[b[i]]=x;}
  else{}
  for(int i=0;i<=N;i++)
    a[i]=M.at(a[i]);
  ll ans=0;
  for(int i=0;i<=N;i++){
  ll sum=query(0,a[i]+1,0,0,n);
    ans+=sum;
    add(a[i],1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 22120
#include <bits/stdc++.h>
using namespace std;
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; }

 
int main() {
  int AllDam =0;
  int H=0,N=0;
  cin >> H >> N;
  int A[N];
  for(int i=0;i<N;i++){ cin >> A[i];

  AllDam+=A[i];
  
  }
  if(AllDam >= H){
   cout << "Yes" << endl;
  }
  else{cout << "No" << endl;}
  
  
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (h,w,n) = get!(usize, usize, usize);
    let xy = get!(usize, usize; n);
    let mut map = BTreeMap::new();
    for (x,y) in xy {
        map.entry(x-1).or_insert(BTreeSet::new()).insert(y);
    }

    let mut maxy = 1;
    for x in 1..h+1 {
        if let Some(ref ys) = map.get(&x) {
            for &y in *ys {
                if y <= maxy {
                    println!("{}", x);
                    return;
                } else if y == maxy+1 {
                    maxy -= 1;
                }
            }
        }
        maxy += 1;
    }
    println!("{}", h);
}


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

template <class T>
void print(const T& a) {
    for (auto el : a) std::cout << el << " ";
    std::cout << std::endl;
}

std::deque<long long> cg[100100];

int main() {
    long long n;
    std::cin >> n;
    std::vector<long long> a(n + 1), b(n + 1);
    {
        std::map<long long, long long> cnt;
        long long x = 0;
        for (int i = 0; i < n; i++) {
            std::cin >> a[i];
            x ^= a[i];
            cnt[a[i]]++;
        }
        for (int i = 0; i < n; i++) {
            std::cin >> b[i];
            cnt[b[i]]--;
        }
        a[n] = x;
        cnt[x]++;
        for (auto& el : cnt) {
            if (el.second < 0) {
                std::cout << -1 << std::endl;
                return 0;
            }
            if (el.second > 0) x = el.first;
        }
        b[n] = x;
    }
    // print(a); print(b);
    {
        auto ca(a), cb(b);
        std::sort(ca.begin(), ca.end());
        ca.erase(std::unique(ca.begin(), ca.end()), ca.end());
        std::sort(cb.begin(), cb.end());
        cb.erase(std::unique(cb.begin(), cb.end()), cb.end());
        for (int i = 0; i <= n; i++) {
            a[i] = std::lower_bound(ca.begin(), ca.end(), a[i]) - ca.begin();
            b[i] = std::lower_bound(cb.begin(), cb.end(), b[i]) - cb.begin();
        }
    }
    
    // print(a); print(b);

    // std::vector<std::deque<long long>> cg(100010);
    std::set<long long> s;
    for (int i = 0; i <= n; i++) {
        if (a[i] != b[i]) {
            cg[a[i]].push_back(b[i]);
            s.insert(a[i]);
        }
    }

    auto ret = 0ll;
    while (!s.empty()) {
        // print(s);
        std::deque<long long> q;
        q.push_back(*s.begin());
        s.erase(s.begin());
        while (!q.empty()) {
            auto curr = *q.begin();
            if (curr == a[n]) ret--;
            ret += cg[curr].size();
            for (auto& to : cg[curr]) {
                if (s.find(to) != s.end()) {
                    q.push_back(to);
                    s.erase(s.find(to));
                }
            }
            q.pop_front();
        }
        ret++;
    }

    std::cout << ret - (a[n] == b[n] ? 0 : 1) << std::endl;

    return 0;
}

Measured memory_bytes: 75264
N = int(input())
BBB = list(map(int, input().split()))
BBB += [10**5]

AAA = [0] * N

AAA[0] = BBB[0]

for i, B in enumerate(BBB[:-1]):
    AAA[i + 1] = min(B, BBB[i + 1])

print(sum(AAA))


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	set<string> st;
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	for(int i = 0;i < n;i++){
		string now = "";
		int j = i;
		while(j <= min(n-1,i+k-1)){
			now += s[j];
			st.insert(now);
			j++;
		}
	}

	int cnt = 0;
	for(auto itr = st.begin();;itr++){
		if(cnt == k-1){
			cout << *itr << endl;
			return 0;
		}
		cnt++;
	}
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    A.erase(unique(all(A)), A.end());
    int overlap = N - A.size();

    write(A.size() - (overlap % 2));
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int n,t,a,h[1000],i,j=0,min;
  scanf("%d%d%d",&n,&t,&a);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  for(i=0;i<n;i++){
    h[i]=abs((t-a)*1000-6*h[i]);
  }
  min=h[0];
  for(i=1;i<n;i++){
    if(min>h[i]){
      min=h[i];
      j=i;
    }
  }
  printf("%d",j+1);
}

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

using namespace std;
using ll = long long;

const int N = 55 , M = 110;

ll mem[N][N][M];
int n;
ll a[N];

ll dp(int i , int j , int k){
    if(i > j)return 0;
    if(k == 0)return 0;

    ll &ret = mem[i][j][k];
    if(ret != -1)return ret;
       ret = 0;

    if(a[i] < 0){
        if(k > 1){
            ret = max(ret , dp(i+1 , j , k-2));
        }
        ret = max(ret , a[i] + dp(i+1 , j , k-1));
    }
    if(a[j] < 0){
        if(k > 1){
            ret = max(ret , dp(i , j-1 , k-2));
        }
        ret = max(ret , a[j] + dp(i , j-1 , k-1));
    }
    if(a[i] >= 0){
        ret = max(ret , a[i] + dp(i+1 , j , k-1));
    }
    if(a[j] >= 0){
        ret = max(ret , a[j] + dp(i , j-1 , k-1));
    }

    return ret;
}

main(){
    int k;
    scanf("%d %d" , &n , &k);

    for(int i = 0 ; i < n ; i ++)scanf("%lld" , &a[i]);
    memset(mem , -1 , sizeof mem);
    printf("%lld\n" , dp(0 , n-1 , k));

    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

string x, y;
int xl[27], yl[27];

int main() {
    std::cin >> x >> y;
    memset(xl, 0, sizeof(xl));
    memset(yl, 0, sizeof(yl));

    for (auto c: x) {
        xl[c-'a'] ++;
    }
    for (auto c: y) {
        yl[c-'a'] ++;
    }
    int i = 0, j = 25;
    bool flag = false;
    while (!flag) {
        while (i <= 25 && !xl[i]) i ++;
        while (j >= 0 && !yl[j]) j --;
        if (i > 25 || j < 0) {
            if (i > 25 && j >= 0) {
                flag = true;
            }
            break;
        }
        xl[i] --;
        yl[j] --;
        if (i < j) {
            flag = true;
            break;
        } else if (i > j) {
            flag = false;
            break;
        }
    }
    if (flag) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
void main() {
    writeln(readln.split.join.to!int % 4 == 0 ? "YES" : "NO");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;
    string s;
    cin>>s;
    int z = 0, o = 0;
    rep(i, s.length()){
        if(s[i]=='0')z++;else o++;
    }
    cout << min(z, o) * 2 << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int front = 0;
        int back = N+1;
        String result = "No";
        for(int i = 0; i < N; i++){
            long temp = sc.nextLong();
            if(temp%4 ==0){
                front+= 2;
            }else if(temp%2 == 0){
                back-=1;
            }
        }
        if(front+1 >= Math.min(back,N)){
            result = "Yes";
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 48072
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(){
  int n, l;
  while(cin >> n >> l, n){
    vector< pair<int,char> > V;
    vector<int> Odd, Even;
    int t = 0, p;
    char d;
    for(int i = 0; i < n; ++i){
      cin >> d >> p;
      if(d == 'R') t = max(t,l-p);
      else t = max(t,p);
      V.emplace_back(p,d);
      if(p%2) Odd.push_back(i+1);
      else Even.push_back(i+1);
    }
    cout << t << " ";
    int c = 0, id = 0;
    for(int i = 0; i < n; ++i){
      if(V[i].second == 'R') V[i].first += t-1;
      else V[i].first -= t-1;
    }
    sort(V.begin(),V.end());
    int odd = 0, even = 0;
    for(int i = 0; i < n; ++i){
      if(V[i].first > 0){
        if(((V[i].first-t+1)%2+2)%2) cout << Odd[odd] << endl;
        else cout << Even[even] << endl;
        break;
      }else{
        if(((V[i].first-t+1)%2+2)%2) ++odd;
        else ++even;
      }
      /*
      cout << V[i].first << " " ;
      */
    }
  }
  return 0;
}



Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            var t = ReadLine();

            int ans = int.MaxValue;
            for (int i = 0; i + t.Length - 1 < s.Length; i++)
            {
                var wk = s.Substring(i, t.Length);
                int cnt = 0;
                for (int j = 0; j < wk.Length; j++)
                {
                    if (wk[j] != t[j]) cnt++;
                }
                ans = Min(ans, cnt);
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 26296
main = do
    n:k:_ <- (fmap read).words <$> getLine
    main' n k 1

main' n k i
    | k<i = pure ()
    | otherwise = do
        print$solve n k i
        main' n k (i+1)

solve n k 1
    | n==k = 1
    | n==k+1 = 2
    | otherwise = 2+f z 2 where z=n-k
solve n k i = f k i *** (f z (i-1) + 2*f z i + f z (i+1)) where z=n-k

f l s = g (l-s) s
g l s = c (l+s-1) (s-1)
c _ 0 = 1
c n r = m///l where (m, l) = z n r
z n 1 = (n, 1)
z n r = (n***m, r***l) where (m, l) = z (n-1) (r-1)

inv = inv' y
inv' m = (flip mod y).snd.i m
i x 1 = (0, 1)
i x y
    | mod x y == 1 = (1, -div x y)
    | otherwise = (w, (v-w*k))
        where
            k = div x y
            (v, w) = i y (mod x y)
y = 10^9+7

(***) a b = mod (a * b) y
(///) a b = a *** inv b

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

int main() {
    ll num[2];
    cin >> num[0] >>num[1];
    if(num[0] != 0){
        num[0]--;
    }
    ll sum[2] ={};
    for(int i=0;i<2;i++){
        if(((num[i]%4)/2) ^ (num[i]%2)){
            sum[i] =1;
        }
    }
    // cerr <<"A=" << sum[0] << "B=" << sum[1] << endl;

    for(int i=0;i<2;i++)for(ll j=1ll;j<=50;j++){
        if(!(num[i]&1)){
            sum[i] |= (num[i] &(1<<j));
        }
    }
    //  cerr <<"sumA=" << sum[0] << "sumB=" << sum[1] << endl;
    cout << (sum[0]^sum[1]) << endl;

    

    return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>

const int N = 2e5 + 52;
struct edge {
	int to, next, w;
} e[N << 1];
int n, head[N], cnt;
void ad(int x, int y, int z) { e[++cnt] = {y, x[head], z}, x[head] = cnt; }

std::queue<int> q;
int dis[N];
int main() {
	memset(head, -1, sizeof head);
	memset(dis, 0x3f, sizeof dis), dis[1] = 1;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		if (i % 10 != 9) ad(i, (i + 1) % n, 1);
	for (int i = 1; i < n; i++) ad(i, i * 10 % n, 0);
	for (q.push(1); !q.empty(); q.pop())
		for (int x = q.front(), i = x[head], nx; ~i; i = e[i].next)
			if ((nx = e[i].to)[dis] > x[dis] + e[i].w) nx[dis] = x[dis] + e[i].w, q.push(nx);
	printf("%d", 0 [dis]);
}

Measured memory_bytes: 4480
//package Div2_655;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int x=Integer.parseInt(st.nextToken());
        int t=Integer.parseInt(st.nextToken());
        int ans=n/x;
        if(n%x!=0){
            ans++;
        }
        ans*=t;
        System.out.println(ans);
    }
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n, w;
  cin >> n >> w;
  vector<int> a(n), b(n); // wi, vi
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  vector<long long> dp(w + 1);
  for (int i = 0; i < n; i++) {
    for (int j = w; j >= a[i]; j--) {
      dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
    }
  }

  long long ans = 0;
  for (int i = 0; i <= w; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}

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

string plus_string(string a, string b){
	string c;
	reverse( a.begin() , a.end() );
	reverse( b.begin() , b.end() );
	while( a.size() != b.size() ){
		if( a.size() < b.size() ){
			a.push_back('0');
		}else{
			b.push_back('0');
		}
	}
	for(int i=0 ; i < a.size() ; i++ ){
		c.push_back('0');
	}
	int n=0;
	for(int i=0 ; i < a.size() ; i++ ){
		if( n+a[i]+b[i]-'0'-'0' <= 9 ){
			c[i] = a[i] + b[i] - '0' + n;
			n = 0;
		}else{
			c[i] = a[i] + b[i] - '0' - 10 + n;
			n = 1;
		}
	}
	if( n == 1 ){
		c.push_back( '1' );
	}
	reverse( c.begin() , c.end() );
	return c;
}

int main(void){
    string s;
    for(int k=0; cin>>s; k++){
        bool tf=false;
        string a=s.substr(0, s.find("+"));
        string b=s.substr(s.find("+")+1, s.find("=")-s.find("+")-1);
        string c=s.substr(s.find("=")+1);
        
        for(int num=0; num<10; num++){
            string a1="", b1="", c1="";
            if(num==0){
                if(a.size()>1 && a[0]=='X') continue;
                if(b.size()>1 && b[0]=='X') continue;
                if(c.size()>1 && c[0]=='X') continue;
            }
            
            for(int i=0; i<a.size(); i++){
                if(a[i]=='X'){
                    a1+=num+'0';
                }
                else{
                    a1+=a[i];
                }
            }
            for(int i=0; i<b.size(); i++){
                if(b[i]=='X'){
                    b1+=num+'0';
                }
                else{
                    b1+=b[i];
                }
            }
            for(int i=0; i<c.size(); i++){
                if(c[i]=='X'){
                    c1+=num+'0';
                }
                else{
                    c1+=c[i];
                }
            }
            //cout << a1 << "+"<<b1<<"="<<c1<<"\n";
            if(plus_string(a1, b1)==c1){
                tf=true;
                cout << num << "\n";
                break;
            }
        }
        if(!tf) cout << "NA\n"; 
    }
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
int n;
string s;
int main(){ _;
  cin>>n>>s;
  int ans=0;
  FOR(i,1,n){
    set<char> left,right;
    int temp=0;
    REP(j,i) left.insert(s[j]);
    FOR(j,i,n) right.insert(s[j]);
    for (set<char>::iterator itr=left.begin(); itr!=left.end(); itr++) {
      set<char>::iterator ritr = right.find(*itr);
      if(ritr!=right.end()) temp++;
    }
    ans=max(ans,temp);

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


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

using namespace std;

using ll = long long;
constexpr ll mod = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

ll mypow(ll a, ll b) {
  if (b == 0) return 1;
  ll tmp = mypow(a, b / 2);
  if (b % 2)
    return (((tmp * tmp) % mod) * a) % mod;
  else
    return (tmp * tmp) % mod;
}

using Graph = vector<vector<int>>;
const int MAX_N = 200010;
Graph g(MAX_N);
vector<ll> ch(MAX_N), ret(MAX_N);
vector<ll> two(MAX_N, 1);  // 2^(-i)
int n;

int dfs(int cur, int pre) {
  ch[cur] = 1;
  for (auto nxt : g[cur]) {
    if (nxt == pre) continue;
    ch[cur] += dfs(nxt, cur);
  }
  if (g[cur].size() <= 1) {
    return ch[cur];
  }
  ret[cur] = two[n - 1] - 1;
  for (auto nxt : g[cur]) {
    if (nxt == pre) continue;
    ret[cur] = (ret[cur] + mod - two[ch[nxt]] + 1) % mod;
  }
  ll r = n - ch[cur];
  ret[cur] = (ret[cur] + mod - two[r] + 1) % mod;
  return ch[cur];
}

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

  for (ll i = 1; i < MAX_N; i++) {
    two[i] = two[i - 1] * 2 % mod;
  }
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  ll sum = 0;
  for (int i = 0; i < n; i++) sum = (sum + ret[i]) % mod;
  ll tmp = mypow(2LL, mod - 2);
  tmp = mypow(tmp, ll(n));
  sum = sum * tmp % mod;
  cout << sum << endl;
}


Measured memory_bytes: 24832
import java.io.PrintWriter;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		long K = Long.parseLong(sc.next());
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=0 ; i<100000 ; i++){
			list.add(0);
		}
		for(int i=0;i<N;i++){
			Integer a = sc.nextInt();
			Integer b = sc.nextInt();
			int tmp = list.get(a-1);
			list.set(a-1,tmp+b);
		}
		int result = 0;
		for(int i=0;i<100000;i++) {
			K-=list.get(i);
			if(K<=0){
				result = i+1;
				break;
			}
			result = i+1;
		}
		out.println(result);

	sc.close();
	out.flush();
	}
}

Measured memory_bytes: 82808
from collections import defaultdict

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

d = defaultdict(int)
for i, (xi, yi) in enumerate(xy):
  for j, (xj, yj) in enumerate(xy):
    p, q = xi - xj, yi - yj
    d[(p, q)] += 1

d.pop((0, 0))
ans = N
for k in d:
  ans = min(ans, N-d[k])

print(ans)

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int BALL_NUM = 10;

int ball[BALL_NUM];

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

bool Simulate() {
    int left = 0, right = 0;
    bool flag = true;
    for (int j = 0; j < BALL_NUM; j++) {
        if (ball[j] < min(left, right)) {
            flag = false;
            break;
        }
        if (IsLeft(ball[j], left, right)) { left = ball[j]; }
        else { right = ball[j]; }
    }
    return flag;
}

int main() {
    long n;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &ball[j]);
        }
        if (Simulate()) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }
 
    return 0;
}

Measured memory_bytes: 3016
import collections
n = int(input())
v = list(map(int,input().split()))
if collections.Counter(v).most_common()[0][1] == n:
    print(n//2)
    exit()
c = collections.Counter(v[::2])
d = collections.Counter(v[1::2])
c_ = c.most_common()[0][1]
d_ = d.most_common()[0][1]
e = 0
if c.most_common()[0][0] == d.most_common()[0][0]:
    if len(c.most_common()) == 1:
        d_ = d.most_common()[1][1]
    elif len(d.most_common()) == 1:
        c_ = c.most_common()[1][1]
    else:
        if c.most_common()[1][1] < d.most_common()[1][1]:
            d_ = d.most_common()[1][1]
        else:
            c_ = c.most_common()[1][1]
    
cnt = (n//2) - c_
cnt += (n//2) - d_
print(cnt+e)

Measured memory_bytes: 21980
#include <stdio.h>

typedef struct data
{
    int come_num,student_num;
}data;


void quicksort(data[],int,int);


int main()
{
    int n,i;
    data a[100000];

    scanf("%d",&n);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&a[i].come_num);
        a[i].student_num = i + 1;
    }
    quicksort(a,0,n - 1);

    for (i = 0; i < n; i++)
    {    
        printf("%d ",a[i].student_num);
    }
}


void quicksort(data number[],int first,int last)
{
   int i, j, pivot;
   data temp;

   if(first < last){
      pivot = first;
      i = first;
      j = last;

      while(i < j){
         while((number[pivot].come_num >= number[i].come_num) && (i < last))
         {
            i++;
         }
         while(number[pivot].come_num < number[j].come_num)
         {
            j--;
         }
         if(i < j){
            temp = number[i];
            number[i] = number[j];
            number[j] = temp;
         }
      }

      temp = number[pivot];
      number[pivot] = number[j];
      number[j] = temp;

      quicksort(number,first,j - 1);
      quicksort(number,j+1,last);

   }
}


Measured memory_bytes: 1536
N, M = map(int, input().split())
if N == 1 or M == 1:
    print(1)
    exit()
MOD = 10**9+7
A = []
m = M
for i in range(2, int(M**0.5)+1):
    if m % i == 0:
        m //= i
        k = 1
        while m % i == 0:
            m //= i
            k += 1
        A.append(k)
        if m == 1:
            break
else:
    A.append(1)
B = [0] * max(A)
for a in A:
    B[a-1] += 1
fn_1 = 1
for i in range(1, N):
    fn_1 *= i
    fn_1 %= MOD
ans = 1
fk = fn_1
for i, b in enumerate(B, N):
    fk *= i
    fk %= MOD
    fk *= pow(max(1, i - N + 1), MOD-2, MOD)
    fk %= MOD
    ans *= pow(fk, b, MOD)
    ans %= MOD
    ans *= pow(pow(fn_1, b, MOD), MOD-2, MOD)
    ans %= MOD
print(ans)

Measured memory_bytes: 3064
n = int(input())
s1 = list(map(int, input().split()))
ans = 0

s2 = sorted(s1)
for i in range(n):
  if s1[i] != s2[i]:
  	ans += 1
    
if ans == 0 or ans == 2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

string _6_str(ll tmp){
  string ans = "";
  ll count = 0;
  while(tmp>0){
    ans = to_string(tmp%10) + ans;
    count++;
    tmp/=10;
  }
  while(count<6){
    ans = '0' + ans;
    count++;
  }
  return ans;
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N >> M;
  vector<HOGE<pair<ll, ll>, ll>> dp(M);
  REP(i, M){
    ll P, Y;
    cin >> P >> Y;
    pair<ll, ll> tmptmp(P-1, i);
    HOGE<pair<ll, ll>, ll> tmp(tmptmp, Y-1);
    dp[i] = tmp;
  }

  sort(dp.begin(), dp.end());

  vll num(N, 0);
  vector<HOGE<string, ll>> ans_vec(M);

  REP(i, M){
    ll P = dp[i].key.first;
    num[P]++;
    string ans = _6_str(P+1);
    ans += _6_str(num[P]);
    HOGE<string, ll> tmp(ans, dp[i].key.second);
    ans_vec[i] = tmp;
  }

  sort(ans_vec.begin(), ans_vec.end());

  REP(i, M){
    cout << ans_vec[i].key << "\n";
  }


  return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a<=5){
    cout<<0<<endl;
  }
  else if(13<=a){
    cout<<b<<endl;
  }
  else{
    cout<<b/2<<endl;
  }
}

Measured memory_bytes: 256
#include <string>
#include <assert.h>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]){
    long n, r, l_2 = 2, l_1 = 1;
    cin >> n;
    
    for (int i = 2; i <= n; i++) {
        r = l_2 + l_1;
        l_2 = l_1;
        l_1 = r;
    }
    cout << l_1 << endl;
    return 0;
}

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

int main(){
    int X; cin >> X;
    if(X >= 2000) {
        cout << 1 << endl;
        return 0;
    }
    else if(X < 100){
        cout << 0 << endl;
        return 0;
    }
    else {
        int S = X / 100;
        int R = X % (100*S);
        //cout << S << " " << R << endl;
        if(R <= S*5) {
                cout << 1 << endl; return 0;
            }
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl printf("\n")
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
int n,m,a,b,c,k,x,y,z,ans=0,total=0;
string s;
ll arr[1000005]={0};
ll sum[1000005]={0};
int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef FILE_INPUT
  ///freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  cin>>n;
  ans=0;
  if(n%10==0){
    cout<<10<<endl;
    return 0;
  }
  while(n>0){
    ans+=n%10;
    n/=10;
  }
  cout<<ans<<endl;

#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


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

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

int Main() {
	int k, a, b;

	scani(k);
	scani(a);
	scani(b);

	for (int i = a; i <= b; i++) {
		if (0 == i % k) {
			printf("OK");
			return 0;
		}
	}
	printf("NG");


	return 0;
}

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


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  ll n ;cin>> n;
  vector<ll> A(n) ; rep(i,n) cin>>A[i] ; 
  bool ok=0;
  rep(i,n){
    if( A[i]%2==1 ) ok=1 ;
  }
  if(ok==1) cout<<"first"<<endl ;
   else cout<<"second"<<endl ;
   return 0;
  }

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=4000010;
bitset<N>b;
int n,x,s;
int main()
{
	scanf("%d",&n);
    b[0]=1;
	for (int i=1;i<=n;i++) {scanf("%d",&x); b=((b<<x)|b);s+=x;}	
	if (s&1) s=s/2+1; else s/=2; 
	for (int i=s;i<N;i++) if (b[i]) {
		printf("%d\n",i); break;
	}
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <numeric>
#include <time.h>
#include <bitset>
#include <string.h>
#include <stack>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <complex>
#include <functional>
#include <limits.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef unsigned long long ull ;
#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define pi (acos(-1.0))
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lson (o<<1),l,mid
#define rson (o<<1|1),mid+1,r
#define MP make_pair
#define sqr(x) ((x)*(x))
#define ALL(v) (v).begin(),(v).end()
#define showtime fprintf(stderr,"time = %.15f\n",clock() / (double)CLOCKS_PER_SEC)
const double eps = 1e-9 ;
const int MOD=(int)1e9+7,BAS=233;
inline int sign(double x){return x<-eps?-1:x>eps;}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(ll x){return __builtin_clzll(x);}
inline int lg2(int x){return !x ? -1 : 31-clz(x);}
inline int lg2(ll x){return !x ? -1 : 63-clz(x);}
int AP (char *s) {
	unsigned hash=0;
	for(int i=0; s[i]; i++){
		if (i & 1) hash ^= (~((hash<<11)^s[i]^(hash>>5)));
		else hash ^= ((hash<<7)^s[i]^(hash>>3));
   } return hash & 0x7FFFFFFF;
}

const int M = 100000+10;
ll a[M];
ll sum;
ll f;
int n;
ll tot;

int main () {
	scanf ("%d", &n);
	for (int i=0; i<n; i++) {
		scanf (LLD, a+i);
		sum += a[i];
	}
	f = 1ll*(1+n)*n/2;
	if (sum%f) puts ("NO");
	else {
		f = sum/f;
		for (int i=n-1; i>0; i--) {
			a[i]-=a[i-1];
			if (f<a[i]) {
				puts ("NO");
				exit(0);
			}
			if ((f-a[i])%n) {
				puts ("NO");
				exit(0);
			}
			tot += (f-a[i])/n;
		}
		if (tot>f) puts ("NO");
		else puts ("YES");
	}
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

class MyClass
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = input[0];
        var b = input[1];
        var count = b + 1;
        for (int i = 0; i < a; i++)
        {
            if (b * i % a != 0)
            {
                count++;
            }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 20472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef pair<int, int> ii;
typedef long long int64;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
    int r;
    cin >> r;
    cout << (long long)3 * pow(r, 2) << endl;
    return 0;
}


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


int main(){
  int n; cin>>n;
  
  //ループでNより大きいすべての数字を網羅する。途中でbreak
  for(int i=n;i<=999;i++){
    if(i==111||i==222||i==333||i==444||i==555||i==666||i==777||i==888||i==999){
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_N 300'000

using namespace std;

int C[MAX_N]{};

int main() {
  int N;
  string S;
  cin >> N >> S;
  int t = 0;
  for (int i = 0; i < N; ++i) {
    C[i] = t;
    if (S[i] == 'W') {
      ++t;
    }
  }
  t = 0;
  for (int i = N - 1; i >= 0; --i) {
    C[i] += t;
    if (S[i] == 'E') {
      ++t;
    }
  }
  int res = MAX_N;
  for (int i = 0; i < N; ++i) {
    res = min(res, C[i]);
  }
  printf("%d\n", res);
}

Measured memory_bytes: 4520
#include<bits/stdc++.h>
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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> l(n + 1);
  for(int i = 0; i < n; i++) cin >> l[i];
 
  int d = 0;
  ll ans = 0;
  
  for (int i = 0; i <= n; i++)
  {
    
    if(d <= x){
      d = d + l[i];
      ans++;
    }
    else break;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll mod=1e9+7;
ll mul(ll a,ll b)
{
    ll ans=((a%mod)*(b%mod))%mod;
    return ans;
}
ll power(ll x,ll y)  
{  
    ll res=1;
    x=x%mod;
    if(x==0) return 0;
    while(y>0)  
    {    
        if(y&1)  res=(res*x)%mod; 
        y=y>>1;
        x=(x*x)%mod;  
    }  
    return res;  
}
int main()
{
    io
    ll n;
    cin>>n;
    ll ans=power(10,n);
    ans=(ans%mod+power(8,n)%mod)%mod;
    ans=(ans-mul(power(9,n),2));
    ans=(ans%mod+mod)%mod;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
def input_from_console():
    n = int(input())

    v = list(map(int, input().split()))
    c = list(map(int, input().split()))
    return n, v, c


def main():
    n, v, c = input_from_console()
    # print(n, v, c)
    diff_list = sorted([v[i] - c[i] for i in range(len(v)) if v[i] - c[i] > 0], reverse=True)
    # print(diff_list, n)
    print(sum([diff_list[i] for i in range(len(diff_list))]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
MOD = 10**9+7


def calc_primes(N):
    is_prime = {i: True for i in range(2, N+1)}
    primes = []
    for i in range(2, N+1):
        if is_prime[i]:
            primes.append(i)
            if i**2 <= N:
                for j in range(i**2, N+1, i):
                    is_prime[j] = False
    return primes


def main():
    N = int(input())
    primes = calc_primes(N)
    dp = [[0] * (N+1) for _ in range(N+1)]
    for i in range(1, N+1):
        x = i
        for p in primes:
            cnt = 0
            while x % p == 0:
                x //= p
                cnt += 1
            dp[i][p] = dp[i-1][p] + cnt
    ans = 1
    for p in primes:
        ans = (ans * (dp[N][p] + 1)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 47728
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=305;
int n;
int a[MAX_N];
int cnt[4];
double dp[MAX_N][MAX_N][MAX_N];
bool vis[MAX_N][MAX_N][MAX_N];
double dfs(int a,int b,int c)
{
	if(b<0 || c<0 || (n-a-b-c)<0)return 0;
	if(a==n)return 0;
	if(vis[a][b][c])return dp[a][b][c];
	vis[a][b][c]=true;
	dp[a][b][c]=(dfs(a+1,b-1,c)*b/n+dfs(a,b+1,c-1)*c/n+dfs(a,b,c+1)*(n-a-b-c)/n+1)*n/(n-a);
	return dp[a][b][c];
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	printf("%.10lf\n",dfs(cnt[0],cnt[1],cnt[2]));
	return 0;
}

Measured memory_bytes: 246016
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <bitset>
#include <assert.h>
//defines
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
//functions


using namespace std;



int main () {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int x;
    cin >> x;
    int mx = 0;
    if(x == 1){
        cout << 1;
        return 0;
    }
    for(int i = 1; i<x; i++){
        for(int j = 2; j<=5; j++){
            if(pow(i,j) > x)break;
            if(pow(i,j) <= x){
                mx = max((int)pow(i,j),mx);
            }
        }
    }
    cout << mx;
return 0;
}

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

int main() {
  int N; cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);
  int ans = 0;
  // 頂点 i から出発
  for (int i = 0; i < N; i++) {
    vector<int> G(N, -1);  // グループ番号
    G.at(i) = 1;
    vector<bool> visited(N);
    visited.at(i) = true;
    bool ng = false;
    queue<pair<int, int>> q;
    q.push(make_pair(i, -1));
    while (!q.empty()) {
      int cur = q.front().first;
      int prev = q.front().second;
      q.pop();
      // cur -> j
      for (int j = 0; j < N; j++) {
        if (j == prev) continue;
        if (S.at(cur).at(j) == '0') continue;
        if (visited.at(j)) {
          if (G.at(cur) == G.at(j)) { ng = true; break; }
          else if (abs(G.at(cur) - G.at(j)) > 1) { ng = true; break; }
          else continue;
        }
        visited.at(j) = true;
        G.at(j) = G.at(cur) + 1;
        q.push(make_pair(j, cur));
      }
      if (ng) break;
    }
    if (ng) continue;
    int cnt = 0;
    for (int i = 0; i < N; i++) cnt = max(cnt, G.at(i));
    ans = max(ans, cnt);
  }
  if (ans == 0) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256