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

int main(void){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec[i];
    vector<int> sum(n+1,0);
    for(int i=0;i<n;i++) sum[i+1] = sum[i] + vec[i];

    int mindif = 100100;
    for(int i=1;i<n;i++){
        int s1 = sum[i];
        int s2 = sum[n] - s1;
        mindif = min(mindif, abs(s1-s2));
    }
    cout << mindif << endl;
}

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

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

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    int ans =0;
    for(ll i = x; i <= y; i *= 2) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        //int N = cin.nextint;
        //var A = new bool[N * 10, N * 10];
        //for (int i = 0; i < N; i++)
        //{
        //    for (int j = i; j < N; j++)
        //    {
        //        int u = i ^ j;
        //        int v = i + j;
        //        A[u, v] = true;
        //        //WriteLine($"a={i} b={j} u={u} v={v}");
        //    }
        //}
        //
        //int sum = 0;
        //for (int r = 0; r < N; r++)
        //{
        //    int ans = 0;
        //    for (int i = 0; i <= r; i++)
        //    {
        //        for (int j = 0; j <= r; j++)
        //        {
        //            if (A[i, j]) ans++;
        //        }
        //    }
        //    WriteLine(ans);
        //}

        var N = cin.nextlong;
        D = new Dictionary<long, long>() { [0] = 0, [1] = 1 };
        WriteLine(calc(N + 1));
    }
    Dictionary<long, long> D;
    long calc(long u)
    {
        if (D.ContainsKey(u)) return D[u];
        if (u % 2 == 0)
        {
            D[u] = (2 * calc(u / 2) % mod + calc(u / 2 - 1)) % mod;
            return D[u];
        }
        else
        {
            D[u] = (2 * calc(u / 2) % mod + calc(u / 2 + 1)) % mod;
            return D[u];
        }
    }

}

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

Measured memory_bytes: 13524
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := intScanner()
	if x < 1200 {
		fmt.Println("ABC")
	} else {
		fmt.Println("ARC")
	}
}


Measured memory_bytes: 1772
n=int(input())
l=list(map(int,input().split()))
count=0

for i in range(n):
  for j in range(n):
    if i==j:
      break
    for k in range(n):
      if i==k or j==k:
        break
      
      if l[i]+l[j] > l[k] and l[j]+l[k] > l[i] and l[k]+l[i] > l[j]:
        if l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
          count+=1
print(count)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
char s[5];
bool ok()
{
	for(int i=0;i<3;++i)
	if(s[i]==s[i+1])return 1;
	return 0;
}
int main()
{
	scanf("%s",s);
	puts(ok()?"Bad":"Good"); 
	return 0;
} 

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

using namespace std;

#define all(x) begin(x), end(x)

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

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

    int n;
    cin >> n;

    int off = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        off += x != i;
    }

    cout << ((off == 0 or off == 2) ? "YES" : "NO") << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

char s[4];

int i;

scanf("%s",&s);

for(i=0;i<4;i++){
  if(s[i]=='\0'){break;}
}

if(i!=3){
  printf("No");
}else if(s[0]!=s[1]||s[1]!=s[2]||s[2]!=s[0]){
printf("Yes");
}else{
printf("No");
}

return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {
    int r;
    cin >> r;
    cout << pow(r,2) << endl;


}

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

int main() {
  int n;
  cin >> n;
  double ans = (n / 2 + (n % 2)) * 1.0 / n;
  cout << setprecision(6) << ans << endl;
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X;
    cin >> X;
    if (400<=X && X<=599) cout << 8 << "\n";
    else if (600<=X && X<=799) cout << 7 << "\n";
    else if (800<=X && X<=999) cout << 6 << "\n";
    else if (1000<=X && X<=1199) cout << 5 << "\n";
    else if (1200<=X && X<=1399) cout << 4 << "\n";
    else if (1400<=X && X<=1599) cout << 3 << "\n";
    else if (1600<=X && X<=1799) cout << 2 << "\n";
    else if (1800<=X && X<=1999) cout << 1 << "\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const long long M = 1000000007;

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

    vector<char> v;
    rep(i,n){
        if(a[i] == b[i]){
            v.emplace_back('v');
        }else{
            v.emplace_back('h');
            i++;
        }
        //show(v.back())
    }

    long long ans = v.front() == 'v' ? 3 : 6;
    range(i,1,v.size()){
        long long k;
        if(v[i - 1] == 'v'){
            k = 2;
        }else{
            if(v[i] == 'v') k = 1;
            else k = 3;
        }
        (ans *= k) %= M;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

  int c[3][3];
  int a[3],b[3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      scanf("%d",&c[i][j]);
    }
  }
  for(int a1=0;a1<=100;a1++){
    int b1=c[0][0]-a1;
    int b2=c[0][1]-a1;
    int b3=c[0][2]-a1;
    int a2=c[1][0]-b1;
    int a3=c[2][0]-b1;

    if(a1+b1==c[0][0]&&a1+b2==c[0][1]&&a1+b3==c[0][2]&&
      a2+b1==c[1][0]&&a2+b2==c[1][1]&&a2+b3==c[1][2]&&a3+b1==c[2][0]&&a3+b2==c[2][1]&&
      a3+b3==c[2][2]){
        puts("Yes");
        return 0;
      }
    }
    puts("No");
    return 0;
  }


Measured memory_bytes: 1648
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};


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

    ll N;
    cin >> N;
    vec A(N);
    mint s(0);
    Rep (i, N) {
        cin >> A[i];
        s += mint(A[i]);
    }

    mint ans(0);
    Rep (i, N) {
        s -= mint(A[i]);
        ans += mint(A[i]) * s;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4776
N, M, X = map(int, input().split())
CA = []

for _ in range(N):
    C, *A = map(int, input().split())
    CA.append((C, A))

ans = 10**9
for i in range(2**N):
    flag = True
    tmp_C = 0
    tmp_A = [0]*M
    for j in range(N):
        if i >> j & 1:
            tmp_C += CA[j][0]
            for k in range(M):
                tmp_A[k] += CA[j][1][k]
    for tmp_a in tmp_A:
        if tmp_a < X:
            flag = False
            break
    if flag == True:
        ans = min(ans, tmp_C)

if ans < 10**9:
    print(ans)
else:
    print(-1)


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

char s[1010];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    if(s[n] == 's') printf("%s", s + 1), printf("es");
    else printf("%s", s + 1), putchar('s');
    return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int r = 0, b = 0;
  for(int i=0;i<n;i++){
    if(s[i] == 'R') r++;
    else b++;
  }
  cout << (r > b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

const int cap = 402;
int N;
int64_t A[cap];
int64_t dp[cap][cap];


int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) {
        scanf(" %" SCNd64, &A[i]);
        A[i] += A[i - 1];
    }
    fill(&dp[0][0], &dp[0][0] + cap * cap + 1, 0);

    for (int span = 2; span <= N; ++span) {
        for (int i = 1; i + span <= N + 1; ++i) {
            dp[i][i + span] = LLONG_MAX;
            for (int j = i + 1; j < i + span; ++j) {
                dp[i][i + span] = min(dp[i][i + span], dp[i][j] + dp[j][i + span] + A[i + span - 1] - A[i - 1]);
            }
        }
    }

    printf("%" PRId64 "\n", dp[1][N + 1]);
}











Measured memory_bytes: 1536
// can i beat Mod Love?
#include <bits/stdc++.h>

using namespace std;
#define eps 1e-8
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
typedef long long ll;
ll bin(ll x, ll n, ll MOD) {
    ll ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;
    return ret;
}
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = acos(-1.0);
constexpr ll mod = 1e9 + 7;
constexpr int maxn = 3333; // remember to calculate.
ll n, m, k, x, y, z, dp[maxn][maxn][4], a[maxn][maxn], f[maxn][maxn];
ll solve(int x, int y, int h) {
    if(x > n || y > m || h > 3)
        return -linf;
    if(x == n && y == m) {
        if(h < 3 && f[x][y])
            return a[x][y];
        return 0;
    }
    if(dp[x][y][h] != -1)
        return dp[x][y][h];
    ll ans = -linf;
    ans = max(ans, solve(x, y + 1, h));
    ans = max(ans, solve(x + 1, y, 0));
    if(f[x][y] && h < 3) {
        ans = max(ans, solve(x, y + 1, h + 1) + a[x][y]);
        ans = max(ans, solve(x + 1, y, 0) + a[x][y]);
    }
    return dp[x][y][h] = ans;
}
int main() {
    close;
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++) {
        cin >> x >> y >> z;
        a[x][y] = z;
        f[x][y] = 1;
    }
    memset(dp, 0xff, sizeof dp);
    cout << solve(1, 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 507168
using System;

class ABProblem{
        static void Main(string[] args){
	  string[] str = Console.ReadLine().Split(' ');
	  int a = int.Parse(str[0]);
	  int b = int.Parse(str[1]);
	  int d = a/b;
	  int r = a%b;
	  double f = (double)a/(double)b;
	  Console.WriteLine("{0} {1} {2:f5}",d,r,f);
	}
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    int sum = 0;
    int x = i;
    while(x) {
      sum += x % 10;
      x /= 10;
    }
    if(a <= sum && sum <= b) {
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3560
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S, T;
	long long LOOP = -1, NOW;
	vector<long long> V[26];
	cin >> S >> T;
	NOW = S.size() - 1;
	for (int i = 0; i < S.size(); i++) {
		V[S[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < T.size(); i++) {
		if (V[T[i] - 'a'].empty()) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i < T.size(); i++) {
		long long X = T[i] - 'a';
		if (NOW % S.size() >= V[X][V[X].size() - 1]) {
			NOW = V[X][0];
			LOOP++;
		}
		else {
			long long Y = upper_bound(V[X].begin(), V[X].end(), NOW) - V[X].begin();
			NOW = V[X][Y];
		}
	}
	cout << LOOP * S.size() + NOW + 1 << endl;
}

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

using namespace std;
using ll = long long;
const ll MOD = 1000003;

int main() {
    ll n;
    cin >> n;

    vector<ll> lucas(n+10);
    lucas[0] = 2;
    lucas[1] = 1;

//    if (n == 1) {
//        cout << 1 << endl;
//        exit(EXIT_SUCCESS);
//    }

    for (int i = 2; i <= n; ++i) {
        lucas[i] = lucas[i-1] + lucas[i-2];
    }

    cout << lucas[n] << endl;

    return 0;
}

Measured memory_bytes: 256
s=list(input())
q=int(input())
c=0
left=[]
right=[]
for i in range(q):
    s1=input()
    if s1[0]=='1':
        c+=1
    else:
        if s1[2] == '1':
            if c % 2 == 0:
                left.append(s1[4])
            else:
                right.append(s1[4])
        else:
            if c % 2 == 0:
                right.append(s1[4])
            else:
                left.append(s1[4])
left=left[::-1]
left.extend(s)
left.extend(right)
if c%2==0:
    print(''.join(left))
else:
    left=left[::-1]
    print(''.join(left))

Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,k;
int main() {
	cin>>a>>b>>c;
	if(b>=a) {
		cout<<1<<endl;
		return 0;
	}
	if(c>=b) {
		cout<<-1<<endl;
		return 0;
	}
	if((a-b)%(b-c)>=1)
		k=1;
	cout<<((a-b)/(b-c)+k)*2+1<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
memory = [-1]*N
ans = 1
for i in range(M):
  s, c = map(int, input().split())
  s -= 1
  if s == 0 and c == 0 and N != 1:
    ans = -1
  elif memory[s] == -1:
    memory[s] = c
  elif memory[s] == c:
    continue
  else:
    ans = -1
if memory == [-1] and ans == 1:
  print(0)
elif ans == -1:
  print(-1)
else:
  if memory[0] == -1:
    memory[0] = 1 
  for i in range(1,N):
    if memory[i] == -1:
       memory[i] = 0
  memory = [str(num) for num in memory]
  output = "".join(memory)
  print(int(output))
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

vector<vector<long long>> dp;
long long f(int i, int sig, const vector<long long> &v) {
  if (i == v.size() - 1) {
    return v[i] * sig;
  }

  long long &ret = dp[i][sig + 1];
  if (ret == -1) {
    long long a =  (v[i] * sig) + f(i + 1,  1, v);
    long long b = -(v[i] * sig) + f(i + 1, -1, v);
    ret = max(a, b);
  }

  return ret;
}

int main() { IO;
  int n;
  cin >> n;

  vector<long long> v(n);
  for (auto &x : v) cin >> x;

  dp.resize(n);
  for (auto &v : dp) {
    v.resize(3);
    fill(v.begin(), v.end(), -1);
  }

  long long ans = f(0, 1, v);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14336
#include <stdio.h>
int main() {
	int n, c[500], s[500], f[500], t;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
	}
	c[n - 1] = s[n - 1] = f[n - 1] = 0;
	for (int i = 0; i < n; i++) {
		t = s[i];
		for (int j = i; j < n; j++) {
			if (f[j] == 0) {
				break;
			}
			if (t >= s[j]) {
				if (t % f[j] != 0) {
					t = (t / f[j] + 1) * f[j];
				}
			} else {
				t = s[j];
			}
			t += c[j];
		}
		printf("%d\n", t);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
const int inf=2e6;
#define maxx 1005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

int main(){
    FASTIO;
    ll s,t,d;
    cin>>d>>t>>s;
    if(s*t>=d) cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

constexpr int64_t M = 998244353;

const int MAX_N = 2 * 1e6;

int n, dat[2 * MAX_N - 1];

void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;

    for (int i = 0; i < 2 * n - 1; ++i) {
        dat[i] = -1;
    }
}

void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

int query_(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) { return -1; }
    if (a <= l && r <= b) { return dat[k]; }
    else {
        int vl = query_(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query_(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
}

int query(int a, int b) {
    return query_(a, b, 0, 0, n);
}

struct xd {
    int64_t x, d;
    int i;
    const bool operator<(const xd & rhs) const {
        return x < rhs.x;
    }
};

int main() {
    int N;
    cin >> N;
    vector<xd> xds;
    for (int i = 0; i < N; ++i) {
        int64_t x, d;
        cin >> x >> d;
        xds.push_back(xd{x, d, -1});
    }
    sort(xds.begin(), xds.end());
    for (int i = 0; i < xds.size(); ++i) {
        xds[i].i = i;
    }
    init(N);

    for (int i = N - 1; i >= 0; --i) {
        const auto it = std::upper_bound(xds.begin() + i, xds.end(), xds[i].x + xds[i].d - 1, [&](const int v, const xd& xd) { return v < xd.x; } );
       const int t = std::distance(xds.begin(), it);
        debug(i);
        debug(t);
        update(i, max(t, query(i, t)));
        debug(query(i, i + 1));
    }
    
    vector<int64_t> dp(N + 1, 1);
    for (int i = N - 1; i >= 0; --i) {
        dp[i] = (dp[i + 1] + dp[query(i, i + 1)]) % M;
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 11500
let tuple3 a b c = (a, b, c)
;;

let tuple4 a b c d = (a, b, c, d)
;;

let rec f n m list a_list min =
  if Array.length a_list == n
  then
    list
    |> List.filter_map
      (fun (a, b, c, d) -> if a_list.(b-1) - a_list.(a-1) == c then Option.some d else Option.none) 
    |> List.fold_left (+) 0
  else
    List.init (m - min + 1) ((+) min)
    |> List.map (fun min -> f n m list (Array.append a_list [|min|]) min)
    |> List.fold_left max 0
;;

let () =
  let n, m, q = Scanf.scanf "%d %d %d\n" tuple3 in
  let list = List.init q (fun _ -> Scanf.scanf "%d %d %d %d\n" tuple4) in
  let res = f n m list [||] 1 in
  Printf.printf "%d\n" res
;;

Measured memory_bytes: 5848
#include <iostream>

using namespace std;
string s;
int ans=0;
int main()
{
    //freopen("B.INP","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> s;
    for (int i=0;s[i];i++)
    {
        if (s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G')
        {
            int tem=1;
            i++;
            while (s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G') i++,tem++;
            ans=max(ans,tem);
        }
    }
    cout << ans;
}


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

int n, m;
int dp[100005];

int f(int node, vector<vector<int>>& g) {
    if(dp[node] != -1) return dp[node];
    int res = 0;
    for(int i = 0; i < g[node].size(); i++) {
        res = max(res, f(g[node][i], g));
    }
    return dp[node] = 1 + res;
}

int main() {
	// your code goes here
	cin >> n >> m;
	vector<vector<int>> g(n);
	int x, y;

	for(int i = 0; i < m; i++) {
	    cin >> x >> y;
	    g[x-1].push_back(y-1);
	}
	memset(dp, -1, sizeof dp);
	
	int ans = 0;
	for(int i = 0; i <n; i++) {
	    ans = max(ans, f(i, g));
	}
	
	cout << ans - 1;
	return 0;
}


Measured memory_bytes: 8192
from collections import deque

inputs = open(0).readlines()
n, k = map(int, inputs[0].split())
V = deque(map(int, inputs[1].split()))
def calc(ii, jj, kk):
    W = []
    for i in range(ii):
        W.append(V[i])
    for j in range(jj):
        W.append(V[-j-1])
    W.sort(reverse=True)
    for _ in range(kk):
        if W[-1] < 0:
            W.pop()
    return sum(W)

ans = 0
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        for k_ in range(min(i+j, k+1-i-j)):
            ans = max(ans, calc(i, j, k_))
print(ans)

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

int main(void) {
    int ans = 0;
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    
    for(int i = 1; i <= n; ++i) {
        if(i <= k) ans += x;
        else ans += y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

//void push(int);
//int pop(void);

int main(){
  int opera[100],c=0;
  //int calc[2];
  char in[100];
  //long int ans = 0;
  int ans;

  while(scanf("%s",in)!=EOF){
    if(in[0]=='+'){
      opera[c-1] = opera[c-1] + opera[c];
      c = c - 1;
      //opera[c] = calc[0] + calc[1];
      //printf("+to%d,%d,%d\n",opera[0],opera[1],opera[2]);
    }
    else if(in[0]=='-'){
      opera[c-1] = opera[c-1] - opera[c];
      //calc[0]=opera[c-1];
      //calc[1]=opera[c];
      c = c - 1;
      //opera[c] = calc[0] - calc[1];
    }
    else if(in[0]=='*'){
      opera[c-1] = opera[c-1] * opera[c];
      //calc[0]=opera[c-1];
      //calc[1]=opera[c];
      c = c - 1;
      //opera[c] = calc[0] * calc[1];
    }
    else{
      c++;
      opera[c]=atoi(in);
      //printf("%d,%d,%d\n",opera[0],opera[1],opera[2]);
    }
    memset(in,'\n',100);
  }
  printf("%d\n",opera[1]);
  
  return 0;
}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
             
            int64_t divceil(int64_t numer, int64_t denom) {
                if (numer % denom == 0) {
                    return numer / denom;
                } else {
                    return 1L + numer / denom;
                }
            }
            int main() {
                int64_t N, K;
                cin >> N;
                cin >> K;
                int64_t max_a = -1;
             
                vector<int64_t> A(N);
                int64_t total_length = 0;
                for (uint64_t i = 0; i < N; i++) {
                    cin >> A[i];
                    total_length += A[i];
                }
             
                // 適当な初期値を与えて上界・下界とする
                double upper_bound = -1;
                double lower_bound = 10000000000;
                for (auto a : A) {
                    int64_t split_num_heuristic = (K * a) / total_length;
                    double val = 1.0 * a / (split_num_heuristic + 1);
                    upper_bound = max(upper_bound, val);
                    lower_bound = min(lower_bound, val);
                }
         
                int64_t result = upper_bound + 2;
                int64_t left = max(lower_bound, 1.0);
                int64_t right = upper_bound + 1;
                while (right >= left) {
                    int64_t mid = (left + right) / 2;
             
                    int64_t total_split = 0;
                    for (uint64_t i = 0; i < N; i++) {
                        int64_t split_num = divceil(A[i], mid) - 1L;
                        total_split += split_num;
                    }
             
                    if (total_split <= K) {
                        result = min(mid, result);
                        right = mid - 1;
                    } else {
                        left = mid + 1;
                    }
                }
                cout << result << endl;
            }

Measured memory_bytes: 4816
# 131 B

n, l = map(int, input().split())
cmin = float('inf')
sum = 0

for i in range(1, n+1):
    f = l + i - 1
    sum += f
    if cmin >= 0:
        cmin = min(cmin, f)
    else:
        cmin = max(cmin, f)

print(sum - cmin)

Measured memory_bytes: 9132
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  string s;
  cin>>s;
  n=s.size();
  bool flag1=0,flag2=0;
  int it1=0,it2=0;
  for(int i=1;i<n;i++){
    if(s[i]==s[i-1]){
      flag1=1;
      it1=i;
    }
  }
  for(int i=2;i<n;i++){
    if(s[i]==s[i-2]){
      flag2=1;
      it2=i-1;
    }
  }
  if(flag1){
    cout<<it1<<" "<<it1+1<<endl;
  }else if(flag2){
    cout<<it2<<" "<<it2+2<<endl;
  }else{
    cout<<-1<<" "<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 764
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int d, n; readV(d, n);
  writeln((n == 100 ? 101 : n)*100^^d);
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	boolean dp[] = new boolean[1000001];

	void init() {
		Arrays.fill(dp, true);
		dp[0] = false;
		dp[1] = false;
		for (int i = 0; i < dp.length; i++) {
			if (dp[i]) {
				for (int j = 2; j * i < dp.length; j++) {
					dp[j * i] = false;
				}
			}
		}
	}

	void run() {
		init();
		for (;;) {
			int a = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			if((a|d|n) == 0) {
				break;
			}
			int p = 0;
			int ret = 0;
			for(int k=a;p < n;k+=d){
				if(dp[k]){
					p++;
					ret = k;
				}
			}
			System.out.println(ret);
		}
	}

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

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


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

int solve(string s){
	int ans = 0;
	repA(i,1,sz(s)-1){
		if(s[i]==s[i-1]) s[i] = 'A',ans++;
	}
	return ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	string s;cin>>s;
	ll k;cin>>k;
	if(s==string(sz(s),s[0])){
		cout<<1ll*sz(s)*k/2;
	}
	else{
		int i=0;
		while(s[i]==s[0]) i++;
		int j = sz(s)-1;
		while(s[j]==s.back()) j--;
		cout<<1ll*solve(s.substr(i,j-i+1))*k+solve(s.substr(0,i))+solve(s.substr(j+1,sz(s)-j-1))+1ll*(k-1)*solve(s.substr(j+1,sz(s)-j-1)+s.substr(0,i));
	}
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int A,B;

    cin >> A >> B;

    for(int i = 1; i <= 20000; i++){
        if(((2*i)/25 == A) && (i/10 == B)){
            cout << i << endl;
            exit(0);
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int sum=a*n;
		int ans=Math.min(sum,b);
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    int N;
    string S;
    cin >> N >> S;
    vector<int> east(N);
    // east[i] はi以下で右向きの人数
    east[0] = (S[0]=='E');
    for(int i=1;i<N;i++)
    {
        east[i] = east[i-1] + (S[i]=='E');
    }
    
    int ans = east[N-1] - east[0];
    for(int i=1;i<N;i++)
    {
        ans = min(ans , (i - east[i-1]) + (east[N-1] - east[i]) );
    }
    
    cout << ans << endl;
    
    return 0;
}



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

int main() {
	int n,k;
	cin>>n>>k;
	k=min(k,n);
	vector<int> A(n);
	for(int i=0;i<n;i++)cin>>A[i];
	
	vector<int> dp(n,INT_MAX);
	dp[n-1]=0;
	
	for(int i=n-2;i>=n-k;i--)
	{
		for(int j=i+1;j<n;j++)
		{
			dp[i]=min(dp[i], 
				abs(A[i]-A[j])+dp[j]
			);
		}
	}
	
	for(int i=n-k-1;i>=0;i--)
	{
		for(int j=i+1;j-i<=k;j++)
		{
				dp[i]=min(dp[i], 
				abs(A[i]-A[j])+dp[j]
			);
		}
	}
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 4032
# coding: utf-8
# Your code here!

a,b,m = [int(x) for x in input().split()]
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = []
for i in range(m):
    ml.append([int(x) for x in input().split()])

ans = min(al) + min(bl)

for i in range(m):
    tmp = al[ml[i][0]-1] + bl[ml[i][1]-1] - ml[i][2]
    if tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 32500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<ll,ll>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}



const int INF = 1001001001;



int main() {
	int n, q;
	cin >> n;
	map<ll,ll>a;
	rep(i, n) {
		int x; cin >> x;
		a[x]++;
	}
	ll ans = 0;
	for (auto p : a) {
		ans += p.first * p.second;
	}
	cin >> q;
	vector<int>b(q), c(q);
	rep(i, q) {
		cin >> b[i] >> c[i];
	}
	rep(i, q) {
		if (a[b[i]] > 0) {
			ans += (c[i] - b[i]) * (a[b[i]]);
			a[c[i]] += a[b[i]];
		}
		a[b[i]] = 0;
		cout << ans << endl;
	}
	return 0;
}













Measured memory_bytes: 9812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "

int main()
{
  string s;
  while (cin >> s)
    {
      puts(((s.length()%2)^(s.front()==s.back()))?"First":"Second");
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

//! unionfind
int par[100005];
int r[100005];
void init(int n)
{
	REP(i, n)
	{
		par[i] = i;
		r[i] = 0;
	}
}

int find(int x)
{
	if (par[x] == x)
	{
		return x;
	}
	return par[x] = find(par[x]);
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (r[x] < r[y])
	{
		par[x] = y;
	}
	else
	{
		par[y] = x;
		if (r[x] == r[y])r[x]++;
	}

}

bool same(int x, int y)
{
	return find(x) == find(y);
}
int P[100005];
pair<int, int> xy[100005];
int main()
{
	int N, M;
	cin >> N >> M;
	REP(i, N)
	{
		cin >> P[i];
	}
	init(N);
	REP(i, M)
	{
		int x, y;
		cin >> x >> y;
		unite(x, y);
	}

	int ans = 0;
	REP(i, N)
	{
		int n = P[i];
		if (same(n, i + 1))
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	ll a,b,c;
	cin>>a>>b>>c;
	c=c-b-a;
	if(c<0){
		cout<<"No";
		return;
	}
	ll x=4*a*b;
	ll y=c*c;
	if(x<y)
		cout<<"Yes";
	else
		cout<<"No";	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int BASE = 10;
int N;

const char * solve() {
  switch (N % BASE) {
  case 3:
    return "bon";
  case 0:
  case 1:
  case 6:
  case 8:
    return "pon";
  default:
    return "hon";
  }
}

int main() {
  scanf("%d", &N);
  puts(solve());
  return 0;
}

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

#include <iostream>
using namespace std ; 

int main ( ) 
{
	int x ; 
	scanf("%d",&x) ; 
	int payback = (x/15) * 200 ; 
	
	cout << (x*800) - payback ; 
	
		return 0 ; 
}

Measured memory_bytes: 256
<?php
list($K)=sscanf(trim(fgets(STDIN)),"%d");
list($A,$B)=sscanf(trim(fgets(STDIN)),"%d %d");
$calc = floor($A / $K);
$calc2 = $A % $K;
if($calc2 == 0){
    print("OK");
    exit;
}
$cc2 = $calc * $K + $K;
if(($cc2 >= $A)&&($cc2 <= $B)){
    print("OK");
}else{
    print("NG");
}



Measured memory_bytes: 16144
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  ll  n ; cin>>n  ;
  vector<ll>b(n);
  vector<ll>a(n);
  rep(i,n){
    cin>>a[i];
  b[i]=a[i];
  }
  
  sort(a.begin(),a.end());
  if(a[n-1]==a[n-2]){
  rep(i,n){cout<<a[n-1]<<endl;}
  }
  else{
    ll t=a[n-1];
  rep(i,n){
  if(b[i]==t)cout<<a[n-2]<<endl;
    else cout<<t<<endl;
  }
  }
  
  
  
}

Measured memory_bytes: 4736
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

    int ans = a-2*b;
    if(0>=ans)cout<<"0"<<endl;
   else cout<<a-2*b<<endl;
   
    return 0;
}

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

int main(int argc, char *argv[]){
  int N;
  long long a;
  cin>>N;
  vector<long long> A(N+1,-1);
  vector<long long> cVec(N,0);
  vector<long long> vec;
  for(int i=0; i<N; i++){
    cin>>a;
    A[i]=a;
    
  }
  sort(A.begin(),A.end()-1);
  for(int i=0,j=0; i<N;i++ ){
    if( i==0) vec.push_back(A[i]);
    if ( find(vec.begin(), vec.end(), A[i]) != vec.end() ){}
    else {
      vec.push_back(A[i]);
    }
    if(A[i]!=A[i+1]){
      cVec[j]+=1;
      j++;
      
    }
    else{
      cVec[j]+=1;
    }
  }

  long long rem=0;
  long long count=0;
  for(int i=0; i<vec.size(); i++){
    if(cVec[i]>vec[i]){
      rem=cVec[i]-vec[i];
    }
    else if(cVec[i]<vec[i]){
      rem=cVec[i];
    }
    else{
      rem=0;
    }
    // cout<<cVec[i]<<"-"<<vec[i]<<endl;
    //cout<<rem<<endl;
    //cout<<cVec[i]<<endl;
    //cout<<vec[i]<<endl;
    count+=rem;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 2936
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double[] s = new double[1000000];
        s[1] = 1;
        for(int i=2;i<=123456;i++){
            for(int j=2;j<=123456;j++){
                if(i*j>250000)break;
                s[i*j]++;
            }
        }

        int count = 0;
        while(true){
            count = 0;
            int n = sc.nextInt();
            if(n==0)break;
            for(int i=n+1;i<=2*n;i++){
                if(s[i] == 0){
                    count++;
                }
            }
            System.out.println(count);
            
        }
    }

}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>P(N);
  for(int i=0;i<N;i++)cin>>P[i];
  vector<int>Q(N);
  for(int i=0;i<N;i++)Q[P[i]-1]=i;
  vector<int>lis(N+1,INF);
  int l=0;
  for(int i=0;i<N;i++){
    int res=1;
    while(Q[i]<Q[i+1]&&i+1<N){
      i++;
      res++;
    }
    l=max(l,res);
  }
  cout<<N-l<<endl;
  return 0;
}


Measured memory_bytes: 2560
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB = [[int(x) - 1 for x in input().split()] for _ in range(M)]

peaks = {i: set() for i in range(N)}
for a, b in AB:
    peaks[a].add(b)
    peaks[b].add(a)

count = len(
    [
        i + 1 
        for i in peaks.keys() 
        if len(peaks[i]) == 0 or H[i] > max(
            [ H[v] for v in peaks[i] ]
        )
    ]
)

print(count)


Measured memory_bytes: 65448
# coding: utf-8
# Your code here!


null = -1

class Node:
    def __init__(self):
        self.parent = null
        self.left = null
        self.right = null
        self.id = null
    

def preParse(u):
    if u == null:
        return
    print(" ", end = "")
    print(Tree[u].id, end = "")
    preParse(Tree[u].left)
    preParse(Tree[u].right)
    
def inParse(u):
    if u == null:
        return
    inParse(Tree[u].left)
    print(" ", end = "")
    print(Tree[u].id, end = "")
    inParse(Tree[u].right)
    
def postParse(u):
    if u == null:
        return
    postParse(Tree[u].left)
    postParse(Tree[u].right)
    print(" ", end = "")
    print(Tree[u].id, end = "")


Tree = []
root = 0

n = int(input())
for i in range(n):
    Tree.append(Node())
    
for i in range(n):
    tmp = list(map(int, input().split()))
    
    Tree[tmp[0]].id = tmp[0]
    
    if tmp[1] != -1:
        Tree[tmp[0]].left = tmp[1]
        Tree[tmp[1]].parent = tmp[0]
    if tmp[2] != -1:
        Tree[tmp[0]].right = tmp[2]
        Tree[tmp[2]].parent = tmp[0]

for i in range(n):
    if Tree[i].parent == null:
        root = i
        break

print("Preorder\n", end = "")
preParse(root)
print("\nInorder")
inParse(root)
print("\nPostorder")
postParse(root)
print("")
    













Measured memory_bytes: 5628