akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n+2, string(m+2, '*'));
    vector<vector<int>> d(n+2, vector<int>(m+2, -1)) ;
    for (int i = 1; i <= n; i++) {
        cin >> &s[i][1];
    }
    queue<pair<int, int>> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i][j] == '#') {
                q.emplace(i, j);
                d[i][j] = 0;
            }
        }
    }
    int res = 0;
    while (!q.empty()) {
        pair<int, int> p = q.front();
        int x = p.first;
        int y = p.second; 
        q.pop();
        for (int i = 0; i < 4; i++) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (s[xx][yy] == '.' && d[xx][yy] == -1) {
                d[xx][yy] = d[x][y] + 1;
                res = max(res, d[xx][yy]);
                q.emplace(xx, yy);
            }
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 13456
n = int(input())
b = list(map(int, input().split()))

ans = 0


def mini(x, y):
    if x > y:
        return y
    else:
        return x


for i in range(n):
    if i == 0:
        ans += b[0]
    elif i == n-1:
        ans += b[n-2]
    else:
        ans += mini(b[i-1], b[i])

print(ans)


Measured memory_bytes: 3060
n,m=map(int,input().split())
s=[]

for i in range(m):
    s.append(list(map(int,input().split())))

p=list(map(int,input().split()))
ans=0

for i in range(2**n):
    x=format(i,'010b')
    #print(x)
    flg=1
    for j in range(m):
        temp=0
        for k in range(1,s[j][0]+1):
            temp+=int(x[-s[j][k]])
        if temp % 2 != p[j]:
            flg=0
            break
    if flg:
        ans+=1


print(ans)

Measured memory_bytes: 9212
#include <stdio.h>

int main()
{
	int set;
	scanf("%d", &set);
	int i, in[3], swap, temp;
	for(i = 0; i < set; i++) {
		scanf("%d %d %d", &in[0], &in[1], &in[2]);
		for(swap = 0; swap < 2; swap++) {
			if(in[swap] > in[swap + 1]) {
				temp = in[swap];
				in[swap] = in[swap + 1];
				in[swap + 1] = temp;
			}
		}
		if(in[2] * in[2] == in[0] * in[0] + in[1] * in[1]) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
import sys

n = int(input())
h = list(map(int, input().split()))

if n == 1:
  print("Yes")
  sys.exit()

h[0] -= 1
for i in range(1, n-1):
  if h[i-1] < h[i]:
    h[i] -= 1
  if h[i] > h[i+1]:
    print("No")
    sys.exit()

if h[n-2] <= h[n-1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14396
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:i64, m:i64, k:i64};
    if k == 0 {
        println!("Yes");
        return();
    }
    for i in 1..n+1 {
        for j in 1..m+1 {
            let a1 = i * j;
            let a2 = (n-i) * (m-j);
            if a1+a2 == k {
                println!("Yes");
                return();
            }
        }
    }
    println!("No");

}

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

import collections
C = collections.Counter(a)

#logging.debug(C)

sum=0
for v in list(C.values()):
	sum+=v*(v-1)//2
 
for k in range(n):
	x = C[a[k]]
	print(sum-(x*(x-1)//2)+((x-1)*(x-2)//2))

Measured memory_bytes: 32260
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;


int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    bool res = true;
    cin >> v[0];
    v[0]--;
    for(int i = 1; i < n; i++)
    {
        cin >> v[i];
        v[i]--;
        if(v[i] >= v[i - 1])
            continue;
        if(v[i] + 1 >= v[i - 1])
        {
            v[i]++;
        }
        else
        {
            res = false;
        }
    }
    if(res)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <complex>
#include <cmath>
using namespace std;

vector<long long> ss,ps;

long long solve(long long n, long long x){
    if(n==0){
        return x;
    }
    if(x <= 1){
        return 0;
    }
    if(x <= ss[n-1]+1){
        return solve(n-1,x-1);
    }
    if(x == ss[n-1]+2){
        return ps[n-1] + 1;
    }
    if(x <= 2*ss[n-1]+2){
        return ps[n-1] + 1 + solve(n-1, x - 2 - ss[n-1]);
    }
    return ps[n];
}

int main(int argc, char const *argv[]) {
    long long n,x;cin>>n>>x;
    ss = vector<long long>(n+1);
    ps = vector<long long>(n+1);
    ss[0] = 1;
    ps[0] = 1;
    for(int i=0;i<n;++i){
        ss[i+1] = ss[i]*2 + 3;
        ps[i+1] = ps[i]*2 + 1;
    }
    cout<<solve(n,x)<<endl;
    return 0;
}

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



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

  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];

  map<int, int> m;
  m[0] = 2;
  rep(i, n) m[d[i]]++;
  set<int> s;
  rep(i, 12) {
    if (m[i] >= 3) {
      cout << 0 << '\n';
      return 0;
    }
    else if (m[i] == 2) {
      s.insert(i);
      s.insert(24 - i);
    }
  }
  if (m[12] >= 2) {
    cout << 0 << '\n';
    return 0;
  }
  else if (m[12] == 1) s.insert(12);
  int ans = 0;
  rep(i, (1 << 12)) {
    set<int> res = s;
    rep(j, 12) {
      if (m[j] != 1) continue;
      if (i >> j & 1) {
        res.insert(24 - j);
      }
      else {
        res.insert(j);
      }
    }
    int resv = 12, pre = -inf;
    for (auto idx = res.begin(); idx != res.end(); idx++) {
      chmin(resv, *idx - pre);
      pre = *idx;
    }
    chmax(ans, resv);
  }
  cout << ans << '\n';




  
  return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	ans := 1

	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	for _, v := range a {
		ans *= v
		if ans > 1000000000000000000 || ans < v {
			fmt.Println(-1)
			return
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 6320
#include <stdio.h>

int main(){
    int n, m, valor1=0, valor2 =0, i, i2;
    scanf("%d%d", &n, &m);
    for(i=1; n>i; ++i){
        valor1 = valor1 + i;
    }
    for(i2=1; m>i2; ++i2){
        valor2 = valor2 + i2;
    }
    printf("%d", valor1+valor2);
    
    return 0;
}


Measured memory_bytes: 128
N, T = map(int, input().split())
c, t = [], []
for _ in range(N):
    ci, ti = map(int, input().split())
    c.append(ci)
    t.append(ti)
    
if min(t) > T:
    print('TLE')
    exit()
    
#min_time = float('inf')
min_cost = float('inf')
for i in range(N):
    if t[i] <= T and c[i] < min_cost:
        min_cost = c[i]
        
print(min_cost)

Measured memory_bytes: 3064
N, Q = map( int, input().split())
S = input()
AAT = [0]*(N+1)
ATT = [0]*(N+1)
now = 0
ac = 0
for i in range(N):
    if S[i] == 'A':
        now = 1
    elif S[i] == 'C':
        if now == 1:
            ac += 1
        now = 0
    else:
        now = 0
    ATT[i] = ac
    if i == 0:
        continue
    AAT[i-1] = ac
AAT[N-1] = ac
for _ in range(Q):
    l, r = map( int, input().split())
    if l == 1:
        print(ATT[r-1])
    else:
        print( ATT[r-1] - AAT[l-2])


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

long long dp[110][100100]={};

int main(){
    int N,W; cin >> N >> W;
    dp[0][0]=0;
    int w[N],v[N];
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0;i<N;i++){
        for(int j=W;j>=0;j--){
            if(j-w[i]>=0){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            }
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
#include <string.h>
 
int main()
{
  char s[11], out[11]={'\0'};
  scanf("%s", s);
  int n = strlen(s);
  for(int i=0; i<n; i++){
    int m = strlen(out);
    if(s[i] == 'B') out[m-1]='\0';
    else out[m]=s[i];
  }
  printf("%s", out);
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  ll a = 1, b = 1;
  for (int i = 0; i < n; i++) {
    ll na, nb;
    cin >> na >> nb;

    ll d = max((a + na - 1) / na, (b + nb - 1) / nb);
    a = d * na, b = d * nb;
  }
  cout << a + b << endl;
  return 0;
} 

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  string result = "No";
  int half = s.size() / 2;
  if (n % 2 == 0 && s.substr(0, half) == s.substr(half, half)) {
    result = "Yes";
  }
  cout << result << endl;

  return 0;
}


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

int main(void)
{
  char card[201];
  int m;
  int h[100] = {0};
  int i, j, k;
  char shuffle[201];

  while(1) {
    scanf("%s", card);

    if(card[0] == '-')
      break;

    strcpy(shuffle, card);
      
    scanf("%d", &m);

    for(i = 0; i < m; i++)
      scanf("%d", &h[i]);

    for(i = 0; i < m; i++){
      for(j = h[i], k = 0; j < strlen(card); j++, k++)
	shuffle[k] = card[j];

      for(j = 0; j < h[i]; j++, k++)
	shuffle[k] = card[j];
      
      strcpy(card, shuffle);
    }
    
    printf("%s\n", card);
  }

  return 0;
}

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

int main(void) {
    int n; cin >> n;
    vector<pair<int64_t, int64_t>> ranges(n);

    for(int i = 0; i < n; ++i) {
        int64_t x, l; cin >> x >> l;
        ranges[i].first = x - l;
        ranges[i].second = x + l;
    }

    sort(ranges.begin(),
         ranges.end(),
         [](pair<int64_t, int64_t> x, pair<int64_t, int64_t> y) {
             if(x.second == y.second) return x.first < y.first;
             else return x.second < y.second;
         }
    );

    int ans = 1;
    int pos = ranges[0].second;
    for(int i = 1; i < n; ++i) {
        if(ranges[i].first < pos) continue;
        ans++;
        pos = ranges[i].second;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll a,b,x;

int main(){

	scanf("%lld %lld %lld",&a,&b,&x);

	ll ans = x%MOD;
	ll mult = max(0LL,(x-b)/(a-b));
	b %= MOD;
	mult %= MOD;

	printf("%lld\n",(ans+b*mult)%MOD);

	return 0;
}



Measured memory_bytes: 3216
#                         author:  kagemeka 
#                         created: 2019-11-06 22:04:18(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    a, b, c = (int(x) for x in sys.stdin.read().split())
    if c <= a + b:
        ans = 'Yes'
    else:
        ans = 'No'
    
    print(ans)



if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
n = int(input())
l, r = 0, n - 1
print(0)
data = input()
while data != "Vacant":
    m = (l + r) // 2
    print(m)
    s = input()
    if s == "Vacant":
        exit()
    if ( m % 2 == 0 and data == s) or ( m % 2 == 1 and data != s):
        l = m + 1
    else:
        r = m - 1
    


Measured memory_bytes: 62012
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
//const long long INF = 1LL << 60;
int INF = 1e6+10;
int main(){
  int n=0;
  cin >> n;
  vector<int> x(n,0);
  rep(i,n) cin >> x[i];
  int ans = INF;

  for(int i=0;i<100;i++){
    int tmp_total = 0;
    for(int j=0;j<n;j++){
    
      tmp_total+=abs((x[j]-i)*(x[j]-i));
    }
    ans = min(ans,tmp_total);
  }
  cout << ans << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  vector<vector<int>> DP(H, vector<int>(W, -1));
  for (int i = 0; i < H; i++) {
    if (A.at(i).at(0) == '#') break;
    DP.at(i).at(0) = 1;
  }
  for (int i = 0; i < W; i++) {
    if (A.at(0).at(i) == '#') break;
    DP.at(0).at(i) = 1;
  }
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (A.at(i).at(j) == '#') continue;
      if (DP.at(i - 1).at(j) == -1 && DP.at(i).at(j - 1) == -1) continue;
      if (DP.at(i - 1).at(j) == -1) DP.at(i).at(j) = DP.at(i).at(j - 1);
      else if (DP.at(i).at(j - 1) == -1) DP.at(i).at(j) = DP.at(i - 1).at(j);
      else DP.at(i).at(j) = (DP.at(i - 1).at(j) + DP.at(i).at(j - 1)) % 1000000007;
    }
  }
  int ans = DP.at(H - 1).at(W - 1);
  cout << ((ans == -1) ? 0 : ans) << "\n";
}

Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
  int a,b;
  string s;
  cin>>a>>b>>s;
  bool f = true;
  rep(i,s.size()){
    if(i != a){
      if('0' <= s[i] && s[i] <= '9');
      else f = false;
    }else{
      if('-' != s[i])f = false;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))

n,m= m()

print(n*m)


Measured memory_bytes: 6012
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	readLine()
	ins := strings.Split(readLine(), " ")

	n := len(ins)
	var d []int
	for _, v := range ins {
		di, _ := strconv.Atoi(v)
		d = append(d, di)
	}
	sort.Ints(d)

	var count int
	if d[(n-1)/2] == d[(n-1)/2+1] {
		fmt.Println(count)
		return
	}

	fmt.Println(d[(n-1)/2+1] - d[(n-1)/2])
}


Measured memory_bytes: 7680
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut s: Vec<char> = input::<String>().chars().collect();
    let sn = s[n - 1];
    s.insert(0, sn);
    let s1 = s[1];
    s.push(s1);

    let mut v = vec![0; n + 2];
    let mut ok = false;
    for &(v0, v1) in &[(0, 0), (0, 1), (1, 0), (1, 1)] {
        v[0] = v0;
        v[1] = v1;
        for i in 1..n + 1 {
            if v[i] == 0 {
                if s[i] == 'o' {
                    v[i + 1] = v[i - 1];
                } else {
                    v[i + 1] = 1 - v[i - 1];
                }
            } else {
                if s[i] == 'o' {
                    v[i + 1] = 1 - v[i - 1];
                } else {
                    v[i + 1] = v[i - 1];
                }
            }
        }
        if v[0] == v[n] && v[1] == v[n + 1] {
            ok = true;
            break;
        }
    }

    if ok {
        let out = std::io::stdout();
        let mut buf = std::io::BufWriter::new(out.lock());
        for i in 1..n + 1 {
            write!(buf, "{}", if v[i] == 0 { "S" } else { "W" }).unwrap();
        }
        writeln!(buf, "").unwrap();
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include<math.h>
using namespace std;
int main() {
	int n, p, q, cnt = 0;
	vector<pair<int,int>>a;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p >> q;
		a.push_back(make_pair(q, p));
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; ++i) {
		cnt = cnt + a[i].second;
		if (cnt > a[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

}

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

using namespace std;
int n;
bool comp(int a1[], int a2[])
{
  bool equal=false;
  for(int i=0;i<n;i++)
  {
    if(a1[i]!=a2[i])return equal;
  }
  equal=true;
  return equal;
}
int main()
{
  
  cin>>n;int p[n],q[n];
  for(int i=0;i<n;i++)
 	cin>>p[i];
  for(int i=0;i<n;i++)
    cin>>q[i];
  int perm[n];
  for(int i=0;i<n;i++)
  {
    perm[i]=i+1;
  }
  int i=1;
  bool equalp=false;
  bool equalq=false;
  int a,b;
  do
  {
    equalp=comp(perm,p);
    if(equalp)a=i;
    equalq=comp(perm, q);
    if(equalq)b=i;
    i++;
    
  }while(next_permutation(perm, perm+n));
 	cout<<abs(a-b);
}

Measured memory_bytes: 256
#include<iostream>

int a, b, n, m;

int main()
{
	while(std::cin>>a>>b)
	{
		n = a + b;
		m = 1;
		while(n>=10)
		{
			n=n/10;
			++m;
		}
		printf ("%d\n",m);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;


int main(){

	int N;
	cin >> N;
	int a[N];

	for(int i =0;i < N;i++){
		cin >> a[i];
	}

	sort(a,a + N);

	int alice = 0;
	int bob = 0;

	for(int i = 0;i < N;i++){
		if(i%2 == 0){
			alice += a[N-1-i];
		}else{
			bob   += a[N-1-i];
		}
	}

	cout << alice - bob << endl;

    return 0;

}


Measured memory_bytes: 256
def not_animal(animal):
    if animal == 'S':
        return 'W'
    return 'S'

def f(prev, animal, ans):
    x = g(animal, ans)
    if not x:
        return not_animal(prev)
    return prev

def g(animal, ans):
    ret = True
    if ans == 'x':
        ret = False

    if animal == 'S':
        return ret
    return not ret
    
def is_equal(x, y):
    return x == (y[0] == y[1])

N = int(input())
s = input()
circles = [['.' for i in range(N)] for i in range(4)]

_init = [('S', 'S'), ('W', 'W'),('S', 'W'), ('W', 'S')]

if s[0] == 'x':
    _init[:2], _init[2:] = _init[2:], _init[:2]

circles[0][0] = circles[1][0] = 'S'
circles[2][0] = circles[3][0] = 'W'

for i in range(4):
    circles[i][1], circles[i][-1] = _init[i]

for i in range(4):
    for j in range(1, N-2):
        circles[i][j+1] = f(circles[i][j-1], circles[i][j], s[j])
#    print(circles[i])


for i in range(4):
#    print(circles[i])
    for j in range(N):
#        print(g(circles[i][j], s[j]), circles[i][j-1], circles[i][(j+1)%N])
        if not is_equal(g(circles[i][j], s[j]), (circles[i][j-1], circles[i][(j+1)%N])):
            break
    else:
        print(''.join(circles[i]))
        break
else:
    print(-1)


Measured memory_bytes: 6772
#include<stdio.h>
#include<string.h>

#define M 4000000
#define L 14

char H[M][L]={0}; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int k){ 
  return k % M;
}

int h2(int k){ 
  return 1 + ( k % (M-1) );
}

int h(int k, int i){
  return ( h1(k) + i*h2(k) ) % M;
}

int find(char str[]){
  int i=0 ,j ,k;

  k = getKey(str);
  while(1){
    j = h(k,i);
    if( !strcmp(H[j],str) ){
      return j;
    } else if ( H[j][0] == NULL || j >= M ){
      return NULL;
    } else {
      i++;
    }
  }

}

int insert(char str[]){
  int i=0 ,j=0;
  long long k;

  k = getKey(str);
  while(1){    
    j = h(k,i);
    // fprintf(stdout, "%d: i = %d j = %d \n" ,__LINE__ ,i ,j );
    if( !(j<M) ){
      // fprintf(stdout, "%d: i = %d j = %d \n" ,__LINE__ ,i ,j );
      return NULL;
    }else if( H[j][0] == NULL ){
      // fprintf(stdout, "%d: i = %d j = %d \n" ,__LINE__ ,i ,j );
      strcpy(H[j],str);
      return j;
    }else{
      // fprintf(stdout, "%d: i = %d j = %d \n" ,__LINE__ ,i ,j );
      i++;
    }
  }
  
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	//	fprintf(stderr, "%d: i = %d \n" ,__LINE__ ,i );
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 55296
#include<stdio.h>
#include<string.h>
int main(){
    int a[101][101],b[101][101],c[101][101],d[101][101];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    memset(d,0,sizeof(d));
    a[1][0]=1;
    b[0][1]=1;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            a[i][j]=(a[i-1][j]+d[i-1][j])%100000;
            b[i][j]=(b[i][j-1]+c[i][j-1])%100000;
            c[i][j]=a[i][j-1]%100000;
            d[i][j]=b[i-1][j]%100000;
        }
    }
    while(1){
        int w,h;
        scanf("%d %d",&w,&h);
        if(w==0&&h==0) return 0;
        printf("%d\n",(a[w][h]+b[w][h]+c[w][h]+d[w][h])%100000);
    }
}

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

typedef long long LL;
const int MAXN=300+10;
const int mod=1e9+7;
const double EPS=1e-8;

int n,m,t,cnt;

vector<int> edge[MAXN];
int dfn[MAXN],low[MAXN],vis[MAXN],used[MAXN][MAXN];
stack<pair<int,int> >s;

LL fra[MAXN],inv[MAXN],bur[MAXN],ans;

LL gcd(LL a,LL b){
    if (b==0) return a;
    else return gcd(b,a%b);
}

LL power(LL a,LL b){
    LL c=1;
    while(b){
        if (b%2==1) c=c*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return c;
}

LL C(LL a,LL b){
    if (a<0 || b<0 || a<b) return 0;
    return (fra[a]*inv[b]%mod)*inv[a-b]%mod;
}

LL Burnside(LL len,LL col){
    if (bur[len]!=0) return bur[len];
    LL sum=0;
    for(int i=1;i<=len;i++){        
        sum+=power(col,gcd(i,len));
        if (sum>=mod) sum-=mod;
    }
    sum*=power(len,mod-2);
    sum%=mod;
    return sum;
}

void dfs(int u,int fa){
    dfn[u]=low[u]=++cnt;
    for(int i=0;i<edge[u].size();i++){
        int v=edge[u][i];
        if (used[u][v]!=0) continue;
        s.push(make_pair(min(u,v),max(u,v)));
        used[u][v]=used[v][u]=1;
        if (dfn[v]==0){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if (low[v]>=dfn[u]){
                int nume=0,numv=0;
                while(1){
                    pair<int,int> e=s.top(); s.pop();
                    nume++;
                    //cout<<e.first<<' '<<e.second<<endl;
                    if (vis[e.first]!=cnt) numv++,vis[e.first]=cnt;
                    if (vis[e.second]!=cnt) numv++,vis[e.second]=cnt;
                    if (e.first==min(u,v) && e.second==max(u,v)) break;
                }
                //cout<<endl;
                cnt++;
                if (numv==nume+1) ans=ans*t%mod;
                else{
                    if (numv==nume) ans=ans*Burnside(numv,t)%mod;
                    else ans=ans*C(nume+t-1,t-1)%mod;
                }
            }
        }
        else low[u]=min(low[u],dfn[v]);
    }
}

int main(){
    scanf("%d%d%d",&n,&m,&t);
    fra[0]=1; for(int i=1;i<=m+t;i++) fra[i]=fra[i-1]*i%mod;
    inv[m+t]=power(fra[m+t],mod-2); for(int i=m+t-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
    memset(bur,0,sizeof(bur));
    
    for(int i=1;i<=m;i++){
        int a,b; scanf("%d%d",&a,&b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    memset(vis,0,sizeof(vis));
    memset(used,0,sizeof(used));
    cnt=0; ans=1;
    for(int i=1;i<=n;i++)
        if (dfn[i]==0) dfs(i,0);
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
   int n,k;
   cin >> n >> k;
   set<int> box;
   rep(i,n){
      box.insert(i+1);
   }
   rep(i,k){
      int d;
      cin >> d;
      rep(i,d){
         int s;
         cin >> s;
         for(auto c:box){
            if (s==c){
               box.erase(c);
            }
         }
      }
   }


   cout << box.size() << endl;
   return 0;  
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n , m;
    long long sum = 0 ;
    cin >> n >> m ;
    int even[n], odd[m];
    even[0] = 2 , odd[0] = 1; 
    // cout << even[0] << " " << odd[0] << endl;
    vector<int> V(n+m);
    V[0] = 2; 
    for(int i = 1 ; i < n ; i++)
    {
        even[i] = even[ i - 1 ] + 2 ;
        V[i] = even[i];
    }
    V[n] = 1 ;
    for(int i = 1 ; i < m ; i++)
    {
        odd[i] = odd[ i - 1 ] + 2 ;
        V[n+i] = odd[i]; 
    }
    //for(auto x : V) cout << x << " ";
    for(int i = 0; i < n + m ; i++)
    {
        for(int j = i + 1 ; j < n + m ; j++)
        {
            if( (V[i] + V[j] ) % 2 == 0) sum++;
        }
    }
    cout << sum << endl ;
}
// odd + odd -> Even
// Even + even -> Even

Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n; cin >> n;
    vector<ll> cnt(n,0LL);
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    ll cntsum = 0LL;
    rep(i,n) if(cnt[i] >= 2) cntsum += cnt[i]*(cnt[i]-1)/2;
    rep(i,n){
        ll tmp = cntsum;
        if(cnt[a[i]] >= 2) tmp -= cnt[a[i]]*(cnt[a[i]]-1)/2;
        if(cnt[a[i]] >= 2) tmp += (cnt[a[i]]-1)*(cnt[a[i]]-2)/2;
        cout << tmp << "\n";
    }
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

  //find root of x
  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(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

  bool same(int x, int y){
	return find(x) == find(y);
  }
};

struct Edge{
  int to;
  double cost;

  Edge(int t, double c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph& graph, int u, int v, double cost){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

double kruskal(const Graph& G){
  int N = SZ(G);
  UnionFind uf(N);
  vector<pair<Edge,int>> edges;
  REP(i,N) for(auto& e:G[i]){
	edges.push_back(MP(e, i));
  }
  sort(ALL(edges));

  double res = 0;
  int i, n;
  for(i=0,n=1;n<N&&i<SZ(edges);++i){
	auto& e = edges[i].first;
	int v = edges[i].second;
	if(!uf.same(e.to,v)){
	  uf.unite(e.to, v);
	  res += e.cost;
	  ++n;
	}
  }
  return res;
}

double dist(PII& p, PII& q){
  int dx = p.FF - q.FF;
  int dy = p.SS - q.SS;
  return sqrt(dx*dx + dy*dy);
}

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

  int N, M; cin >> N >> M;
  vector<PII> ps(N);
  REP(i,N) cin >> ps[i];
  Graph G(N);
  double ans = 0.;
  REP(i,M){
	int p, q; cin >> p >> q;
	--p, --q;
	double c = dist(ps[p], ps[q]);
	add_edge(G, p, q, -c);
	ans += c;
  }
  ans += kruskal(G);
  cout << fixed << setprecision(9) << ans << endl;

  return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>

using namespace std;
typedef pair<int, int> P;
#define INF 999999999

int main(){
	int N;
	cin>>N;
	vector<P> x_arr;
	vector<P> y_arr;
	
	for (int i=0;i<N;i++){
		int buf;
		cin>>buf;
		x_arr.push_back(P(buf,i));
		cin>>buf;
		y_arr.push_back(P(buf,i));
	}

	sort(x_arr.begin(), x_arr.end());
	sort(y_arr.begin(), y_arr.end());

	vector< vector<P> > edge(N);
	for(int i=0;i<N-1;i++){
		int from=x_arr[i].second;
		int to=x_arr[i+1].second;
		int cost=x_arr[i+1].first-x_arr[i].first;
		edge[from].push_back(P(cost, to));
		edge[to].push_back(P(cost,from));
		
		from=y_arr[i].second;
		to=y_arr[i+1].second;
		cost=y_arr[i+1].first-y_arr[i].first;
		edge[from].push_back(P(cost, to));
		edge[to].push_back(P(cost,from));
	}


	int minCost[N];
	fill(minCost,minCost+N,INF);
	minCost[0]=0;
	priority_queue<P> pq;
	pq.push(P(-0,0));

	int totalCost=0;

	while(!pq.empty()){
		P p=pq.top();pq.pop();
		int u=p.second;
		if (minCost[u]<-p.first) continue;
		totalCost-=p.first;
		minCost[u]=-INF;
		
		for(int i=0;i<edge[u].size();i++){
			int v=edge[u][i].second;
			int c=edge[u][i].first;
			
			if (c<minCost[v]){
				minCost[v]=c;
				pq.push(P(-c,v));
			}
		}
	}

	cout<<totalCost<<endl;

	return 0;
}


Measured memory_bytes: 11372
#include<stdio.h>
int main(){
    int K,i;
    char S[100];
    scanf("%d",&K);
    scanf("%s",&S);
    for(i=0;i<K;i++){
        if(S[i])printf("%c",S[i]);
        else break;
    }
    if(i==K&&S[i])puts("...");
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

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

    ll memo = LINF,minmemo = 0,sum = 0;
    rep(i,1,n+1){
        sum += l+i-1;
        if(memo > abs(l+i-1)){
            minmemo = l+i-1;
            memo = abs(l+i-1);
        }
    }
    cout << sum - minmemo << endl;
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define TASK "task"
/// 2020.08.22

using namespace std;

void rwFile() {
    freopen(TASK ".in", "r", stdin);
    freopen(TASK ".out", "w", stdout);
}

void solveA() {
    int n, x, t; cin >> n >> x >> t;
    cout << (n + x - 1) / x * t;
}

void solveC() {
    int n; cin >> n;
    long long arr[n];
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    long long res = 0;
    for (int i = 1; i < n; ++i) {
        if (arr[i] < arr[i - 1]) {
            res += arr[i - 1] - arr[i];
            arr[i] = arr[i - 1];
        }
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //rwFile();
    solveC();
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n , m , x ;
  cin >> n >> m >> x ;
  int cost[n] ;
  int a[n][m] ; 
  rep(i,n){
    cin >> cost[i] ;
    rep(j,m){
      cin >> a[i][j] ;
    }
  }
  
 int ans = INF ;
 rep(s,(1<<n)){
   int Cost = 0 ;
   vector<int> d(m) ;
   rep(i,n){
     if(s>>i & 1){
       Cost += cost[i] ; 
       rep(j,m){
       d.at(j) += a[i][j] ;
       }
     }
   }
   bool ok = true ;
   rep(j,m) {
     if(d.at(j) < x ) ok = false ;
   }
   if(ok) ans = min(ans,Cost);
 }
  
  if(ans == INF) ans = -1 ;
  cout << ans ;
       
     

}



Measured memory_bytes: 3628
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    long[] h = new long[N];
    for (int i = 0; i < N; i++) {
      h[i] = sc.nextLong();
    }
    sc.close();

    long[] dp = new long[N];
    Arrays.fill(dp, Integer.MAX_VALUE);
    dp[0] = 0;
    for (int i = 0; i < N; i++)
      for (int k = i + 1; k < N && k <= i + K; k++)
        dp[k] = Math.min(dp[k],
            dp[i] + Math.abs(h[k] - h[i]));
    long ans = dp[N - 1];
    System.out.println(ans);
  }
}

Measured memory_bytes: 60496
#include<iostream>
#include<vector>
using namespace std;
int A[1000000];
int n, cnt;
vector<int> G;
void is(int g){
    for(int i=g;i<n;++i){
        int v = A[i];
        int j = i-g;
        while(j>=0 && A[j]>v){
            A[j+g] = A[j];
            j -= g;
            cnt++; 
        }
        A[j+g] = v;
    }
}
void ss(){
    for(int h=1;h<=n;h=3*h+1) G.push_back(h);
    for(int i=G.size()-1;i>=0;--i) is(G[i]);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;++i) cin>>A[i];
    ss();
    cout<<G.size()<<endl;
    for(int i=G.size()-1;i>=0;--i) cout<<G[i]<<(i?" ":"");
    cout<<endl;
    cout<<cnt<<endl;
    for(int i=0;i<n;++i) cout<<A[i]<<endl;
}

Measured memory_bytes: 7016
#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==25)cout<<"Christmas"<<endl;
  if(n==24)cout<<"Christmas Eve"<<endl;
  if(n==23)cout<<"Christmas Eve Eve"<<endl;
  if(n==22)cout<<"Christmas Eve Eve Eve"<<endl;
  
}

Measured memory_bytes: 764
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for(auto i=0; i<(n); i++)
#define repd(i,n) for(auto i=(n)-1; i>=0; i--)
#define repf(i,a,b) for(auto i=(a); i<=(b); i++)
#define repe(i,l) for(auto i: l)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w+",stdout);
#define read(x) freopen(x,"rt",stdin);
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define INF ((int)0x3f3f3f3f)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9
#define endl '\n'
#define _ ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.precision(10);cout<<fixed;
template<class T> T abs(T x) { return x > 0 ? x : -x; }
template<class T> T mini(T x, T y) { return x <  y? x : y; }
template<class T> T maxi(T x, T y) { return x <  y? y : x; }
template<class T> T gcd(T a, T b) { return a%b? gcd(b, a%b) : b; }
typedef long long i64;
typedef unsigned long long ui64;
typedef string st;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef unsigned long long ull;

#define MOD ((int)1e9 + 7)
#define MAX 1000007

class UnionFind {    //Funciona indexando desde 1..N                                         
private:
  vi p, rank, setSize;                       // remember: vi is vector<int>
  int numSets;
public:
  UnionFind(int N) {

    setSize.assign(N, 1); 
    numSets = N; 
    rank.assign(N, 0);
    p.assign(N, 0); 
    for (int i = 0; i < N; i++) 
    	p[i] = i; 
	}
  int findSet(int i) { 
  	return (p[i] == i) ? i : (p[i] = findSet(p[i])); 
  }
  bool isSameSet(int i, int j) { 
  	return findSet(i) == findSet(j); 
  }
  void unionSet(int i, int j) { 
    if (!isSameSet(i, j)) { 
    	numSets--; 
    	int x = findSet(i), y = findSet(j);
    	// rank is used to keep the tree short
    	if (rank[x] > rank[y]) { 
    		p[y] = x; 
    		setSize[x] += setSize[y]; 
    	}
    	else{ 
    		p[x] = y; 
    		setSize[y] += setSize[x];
            if (rank[x] == rank[y]) 
            	rank[y]++;
        } 
    }
  }
  int numDisjointSets() { 
  	return numSets; 
  }
  int sizeOfSet(int i) { 
  	return setSize[findSet(i)]; 
  }
};




int main() {_
	//Solution
	#ifdef LOCAL
		read("arc097_b.in");
		// rite("arc097_b.out");
	#endif
	int n, m;
	cin >> n >> m;

	int arr[n];
	rep(i, n) cin >> arr[i];


	UnionFind UF(n+7);
	int cnt= 0;
	rep(i, m){
		int x, y;
		cin >> x >> y;
		UF.unionSet(x, y);
	}

	rep(i, n){
		cnt += (UF.isSameSet(i+1, arr[i]) || i+1 == arr[i]);
	}
	
	cout << cnt << endl;
	
	
	
	
	
	
	
	
	#ifdef LOCAL
		//cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
	#endif
   	
	return 0;
}


/*

	g++-6 -std=c++11 arc097_b.cpp -o arc097_b -DLOCAL && ./arc097_b


*/






Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,a;
    cin>>n>>a;
    cout1(n*n-a);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <sstream>
using namespace std;

int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        int sum=a+b;
        stringstream ss;
        ss << sum;
        string s1=ss.str();
        int k=s1.size();
        printf("%d\n",k);
    }
}

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

using namespace std;

const int NS = (int)1e5 + 4;
int N;
int arr[NS];

int main(){
    int cnt = 0, ans = 0;
    scanf("%d", &N);
    for(int i = 1; i <= N; ++i){
        scanf("%d", arr + i);
    }
    for(int i = N; i >= 1; --i){
        if(arr[i] >= arr[i + 1]){
            ++cnt; ans = max(ans, cnt);
        }
        else{
            cnt = 1;
        }
    }
    printf("%d\n", ans - 1);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
  int K,S;
  cin >> K >> S;
  
  int i,j;
  int count = 0;
  for(i = 0; i <= K; i++) {
    for(j = 0; j <= K; j++) {
      int k = S - (i + j);
      if(0 <= k && k <= K) {
          count++;
      }
    }
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  ll a[100000], sm[100000] = {};
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> a[i];
  sm[0] = a[0];
  for(int i=1;i<n;i++)
    sm[i] = sm[i-1] + a[i];
  ll diff = 0, cnt = 0, ans = 0;

  for(int i=0;i<n;i++){
    ll dst = 0;
    if(i%2 == 0){
      dst = max((ll)0, 1 - (sm[i] + diff) );
      diff += dst;
    }else{
      dst = max((ll)0, 1 + (sm[i] + diff) );
      diff -= dst;
    }
    cnt += dst;
  }
  ans = cnt;
  diff = 0;
  cnt = 0;
  for(int i=0;i<n;i++){
    ll dst = 0;
    if(i%2 == 1){
      dst = max((ll)0, 1 - (sm[i] + diff) );
      diff += dst;
    }else{
      dst = max((ll)0, 1 + (sm[i] + diff) );
      diff -= dst;
    }
    cnt += dst;
  }
  ans = min(ans, cnt);
  cout << ans << endl;
}


Measured memory_bytes: 1792
def main():
    n,d =map(int,input().split())
    X = []
    for i in range(n):
        tmp = [int(i) for i in input().split()]
        X.append(tmp)
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            s = 0
            for k in range(d):
                s += (X[i][k]-X[j][k])**2
            s = s**0.5
            #print(s)
            if s.is_integer():
                ans += 1
    print(ans)
main()

Measured memory_bytes: 9452
#include <iostream>
#include <climits>

using namespace std;

int *A;
int N;
int SwapNum;

void BubbleSort()
{
  bool flag = true;
  int i = 0;

  do
  {

    flag = false;
    for(int j = N - 1; j >= i + 1; --j)
    {
      if(A[j] < A[j-1])
      {
	int tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;

	flag = true;
	++SwapNum;
      }

    }

    ++i;


  }while(flag);

  return;
}

int main()
{
  cin >> N;

  A = new int[N];

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

  BubbleSort();

 cout << A[0];
 for(int i = 1; i < N; ++i)
     cout << " " << A[i];

  cout << endl;
  cout << SwapNum << endl;

  delete [] A;


}



Measured memory_bytes: 3072
def main():
    L, R = map(int, input().split())
    mod = 2019

    if R - L >= 2019:
        ans = 0

    else:
        ans = float('inf')
        for i in range(L, R+1):
            for j in range(i+1, R+1):
                tmp = (i * j) % mod 
                if tmp < ans:
                    ans = tmp
    
    print(ans)

main()


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    string S; cin >> S;

    bool ans = false;

    for (int i = 0;i < S.size();i++){
        if(S[i] == '7') ans = true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 3640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	s := sc.Text()
	rs := []rune(s)
	ans := 0
	for _, v := range rs {
		if string(v) == "+" {
			ans++
		} else {
			ans--
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll inf=1e18;
const ll llf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
int n;
ll x;
char c;
ll f[maxn][3]; 
int main(){
	ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>x;
	f[1][0]=x;
	f[1][1]=f[1][2]=-inf;
	for(int i=2;i<=n;i++){
		cin>>c>>x;
		if(c=='+'){
			f[i][0]=max(f[i-1][0],f[i-1][1])+x;
			f[i][1]=f[i-1][1]-x;
			f[i][2]=f[i-1][2]+x;
		}else{
			f[i][0]=-inf;
			f[i][1]=max(f[i-1][0]-x,f[i-1][1]+x);
			f[i][2]=max(f[i-1][1],f[i-1][2])+x;
		}
	}
	cout<<max({f[n][0],f[n][1],f[n][2]});
	return 0;
}


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

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

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


Measured memory_bytes: 3632