akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
string s;
signed main(){
	cin>>s;
	int a=0,b=0,c=0;
	rep(i,s.size()){
		if(s[i]=='a')a++;
		else if(s[i]=='b')b++;
		else c++;
	}
	if((s.size()+2)/3<a)puts("NO");
	else if((s.size()+2)/3<b)puts("NO");
	else if((s.size()+2)/3<c)puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool Possible(const vector<string>& field) {
  const int H = field.size();
  const int W = field[0].size();
  static const int U = 1 << 3;
  static const int D = 1 << 2;
  static const int L = 1 << 1;
  static const int R = 1 << 0;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (field[i][j] == '.')
        continue;
      int flag = ((i > 0 && field[i - 1][j] == '#') << 3)
          + (((i < H - 1) && field[i + 1][j] == '#') << 2)
          + ((j > 0 && field[i][j - 1] == '#') << 1)
          + (((j < W - 1) && field[i][j + 1] == '#'));
      switch (flag) {
        case (U | R): case U:
        case (U | D): case L:
        case (L | R): case D:
        case (L | D): case R:
          break;
        default:
          return false;
      }
    }
  }
  return true;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < h; ++i)
    cin >> field[i];

  cout << (Possible(field) ? "Possible\n" : "Impossible\n");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> P(N);
    REP(i, 0, N) cin >> P[i];

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

Measured memory_bytes: 1024
x = int(input())

n = 10**6
nums = [True]*(n+1)
nums[0] = nums[1] = False
for i in range(4, n+1, 2): nums[i] = False
for i in range(3, int(n**0.5)+1, 2):
  if nums[i]:
    for j in range(i+i, n, i):
      nums[j] = False

while True:
  if nums[x]:
    print(x)
    break
  x += 1

Measured memory_bytes: 10868
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f(A, B) :- A * B mod 2 =:= 1.

main :-
    get_number(A, B),
    f(A, B) -> writeln("Odd") ; writeln("Even"). 



Measured memory_bytes: 8084
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}
fn calc(n: i32) -> bool {
    let mut n = n;
    let ans = n % 10;

    n /= 10;

    if n % 10 != ans {
        return false;
    }

    n /= 10;

    if n % 10 != ans {
        return false;
    }

    true
}

fn main() {
    // 数値
    let mut n = {
        let i = read::<i32>();
        i[0]
    };

    while calc(n) == false {
        n += 1;
    }

    println!("{}", n);
}


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

int main(){
    int N;
    cin>>N;
    int d[N];
    rep(i, N){
        cin>>d[i];
    }
    int e=0;
    int count=0;
    rep(i, 101){
        e=0;
        rep(j, N){
            if (i==d[j]){
                e=1;
            }
        }
        count+=e;
    }
    cout<<count<<endl;
}

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

double round_off(double x);

int main(void)
{
  int n;
  int count = 0;
  double x1, x2, x3, y1, y2, y3, px, py;
  double r, a, b, c;
  double cosA, sinA;

  do{
    scanf("%d\n", &n);
  }while(n > 20);

  do{
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
    count++;

 a = sqrt(pow((x2-x3),2.0)+pow((y2-y3),2.0));
  b = sqrt(pow((x3-x1),2.0)+pow((y3-y1),2.0));
  c = sqrt(pow((x1-x2),2.0)+pow((y1-y2),2.0));

  cosA = (b*b+c*c-a*a)/(2.0*b*c);
  sinA = sqrt(1.0-cosA*cosA);

  r = (a/sinA)/2.0;

  px = ((y1-y3)*(y1*y1 -y2*y2 +x1*x1 -x2*x2)-(y1-y2)*(y1*y1 -y3*y3 +x1*x1 -x3*x3)) / (2.0*(y1-y3)*(x1-x2)-2.0*(y1-y2)*(x1-x3));
  py = ((x1-x3)*(x1*x1 -x2*x2 +y1*y1 -y2*y2)-(x1-x2)*(x1*x1 -x3*x3 +y1*y1 -y3*y3)) / (2.0*(x1-x3)*(y1-y2)-2.0*(x1-x2)*(y1-y3));

  printf("%.3f %.3f %.3f\n", round_off(px), round_off(py), round_off(r));
       }while(n != count);
  
 

  return 0;
}

double round_off(double x)
{
  int n;
  double  unit;

  n = 4;
  unit = pow(10, n-1);
  double a = round(x*unit);
  x =  a/unit;

  return x;
}

Measured memory_bytes: 676
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    ll N, x;
    cin >> N >> x;
    vector<ll> a, b;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll _a;
        cin >> _a;
        a.push_back(_a);
    }
    if (a[0] > x) b.push_back(x);
    else b.push_back(a[0]);

    for (int i = 1; i < N; i++) {
        if (b[i - 1] + a[i] <= x) b.push_back(a[i]);
        else b.push_back(x - b[i - 1]);
    }
    for (int i = 0; i < N; i++) {
        ans += a[i] - b[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, k, s;
    cin >> n >> k >> s;
    vector<int> a(n, s);
    k = n-k;
    if(s < 1e9){
        for(int i=0;i<k;i++){
            a[i]++;
        }
    }else{
        for(int i=0;i<k;i++){
            a[i] = 1;
        }
    }
    for(int i=0;i<n;i++){
        cout << a[i] << " ";
     }
     cout << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n; cin >> n;
    int b[n], ans[n];
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    for(int i = 0; i < n; i++){
        int ind = 1;
        int w = -1;

        for(int j = 0; j < n; j++){
            if(b[j] != INT_MIN){
                if(b[j] == ind){
                    w = j;
                }
                ind++;
            }
        }

        if(w == -1){cout << -1 << endl; return 0;}
        ans[i] = b[w]; b[w] = INT_MIN;
    }

    for(int i = n-1; i >= 0; i--){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(long long i = 0; i <  n ; i++)
#define  reps(i,n)         for(long long i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
const ll MOD = 1e9+7;
bool cmp(int X, int Y) {return X > Y;}
const double EPS = (1e-7);
int dcp(double A, double B){return fabs(A-B)<=EPS ? 0 : A<B ? -1:1;}
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;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
 
const int N = 100005;
vll adj[N];
ll dp[1000005];



int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;cin>>n;
for(ll i = 1; i<=n  ; i++){
	for(ll j = i; j<=n; j+=i){
		dp[j]++;
		}
	}
ll ans = 0;
for(ll i =1; i<n;i++){
	ll k = sqrt(i);
	ans+=dp[i];
	
	}
cout<<ans;

}		
		
				




Measured memory_bytes: 13692
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned int  ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 998244353
using namespace std;

ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
	        res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
} 

signed main(){
	FASTIO
	int n, x, m;
	cin >> n >> x >> m;
	unordered_map<int, int> mp, sum;
	int a = 0, b = 0, c = 0;
	int i = 0;
	while(mp.count(x) == 0){
		mp[x] = i;
		b += x;
		sum[i] = b;
		i++;
		x = (x * x) % m;
	}
	a = sum[mp[x]-1];
	b -= a;
	int numCycle = (n - mp[x]) / (i - mp[x]);
	b *= numCycle;
	int rem = (n - mp[x]) % (i - mp[x]);
	c = sum[mp[x] + rem - 1] - sum[mp[x] - 1];
	cout << a + b + c;
    return 0;
}


Measured memory_bytes: 7316
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(problem160a(s));
    }

    private static String problem160a(String s) {
        return (equal(s, 2, 3) && equal(s, 4, 5)) ? "Yes" : "No";
    }

    private static boolean equal(String s, int at1, int at2) {
        return s.charAt(at1) == s.charAt(at2);
    }
}

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e15);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
ll a[200005];
int main()
{
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		ll tmp;
		std::cin >> tmp;
		a[tmp] = i;
	}

	std::set<ll> st{ 0,n + 1 };
	ll ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		auto p = st.upper_bound(a[i]);
		auto r = *p;
		auto l = *(--p);
		ans += i * (r - a[i])*(a[i] - l);
		st.insert(a[i]);
	}

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


Measured memory_bytes: 11136
#include <stdio.h>
#include <numeric>
#include <unordered_set>
using namespace std;

int N, M;
int A[100001];  // 1-origin
unordered_set<int> S[100001];

int par[100001];

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

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    par[x] = y;
}


int main() {
    iota(par, par+100001, 0);
    int x, y;
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= M; i++) {
        scanf("%d %d", &x, &y);
        unite(x, y);
    }
    for (int i = 1; i <= N; i++) {
        S[root(i)].insert(A[i]);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (S[root(i)].count(i)) ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 12672
import java.util.Scanner;
public class Main {
public static void main(String[] kotai) {
	Scanner sc=new Scanner(System.in);
	int a=sc.nextInt();
	int b=sc.nextInt();
	if(a>b) {
		System.out.println("a > b");
	}
	if(a<b) {
		System.out.println("a < b");
	}
	if(a==b) {
		System.out.println("a == b");
	}
}
}



Measured memory_bytes: 26180
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
count = 0
dist = [0] * N
for k in range(N-1):
    for i in range(k+1,N):
        for j in range(D):
            dist[i] += (X[k][j] - X[i][j])** 2
        dist[i] = math.sqrt(dist[i])
        if dist[i].is_integer():
            count += 1
        dist[i]=0
print(count)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll b[1 << 17][2];
ll f[1 << 17][3];
ll r[1 << 17];
int main() {
	ll x; int k; cin >> x >> k;
	b[0][0] = 0; b[0][1] = x;
	f[0][0] = 0; f[0][1] = 0; f[0][2] = x;
	r[0] = 0;
	rep(i, k) {
		cin >> r[i+1];
	}
	k++;
	rep(i, k - 1) {
		ll dif = r[i + 1] - r[i];
		if (i % 2==0) {
			dif = min(dif, x);
			f[i + 1][0] = x - max(f[i][0]-dif, (ll)0);
			f[i + 1][2] = x - max(f[i][2] - dif, (ll)0);
			f[i + 1][1] = -f[i][1] + dif;
			b[i + 1][0] = max(b[i][0], dif-f[i][1]);
			b[i + 1][1] = b[i][1];
		}
		else {
			dif = min(dif, x);
			f[i + 1][0] = x - max(f[i][0] - dif, (ll)0);
			f[i + 1][2] = x - max(f[i][2] - dif, (ll)0);
			f[i + 1][1] = -f[i][1] + dif;
			b[i + 1][0] = b[i][0];
			b[i + 1][1] = min(b[i][1], x+f[i][1]-dif);
		}
	}
	int q; cin >> q;
	rep(i, q) {
		ll t, a; cin >> t >> a;
		int loc = upper_bound(r, r + k, t) - r; loc--;
		ll rest = t - r[loc];
		ll ans;
		if (loc % 2) {
			if (a <= b[loc][0]) {
				ans = f[loc][0];
			}
			else if (a >= b[loc][1]) {
				ans = f[loc][2];
			}
			else {
				ans = f[loc][1]-a+x;
			}
			ans = max((ll)0, ans - rest);
			ans = x - ans;
		}
		else {
			if (a <= b[loc][0]) {
				ans = f[loc][0];
			}
			else if (a >= b[loc][1]) {
				ans = f[loc][2];
			}
			else {
				ans = a + f[loc][1];
			}
			ans = max((ll)0, ans - rest);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 7040
#include<stdio.h>
int main(void)
{
	int a,b,c[25],n;
	for(;;)
	{
		n=32;
		scanf("%d",&a);
		for(b=0;b<a;b++)
			scanf("%d",&c[b]);
		if(a==0)
			break;
		for(b=0;;b++)
		{
			if(b==a)
				b=0;
			if(n>(n-1)%5)
				n-=(n-1)%5;
			else
				n=1;
			printf("%d\n",n);
			if(n!=1)
				n-=c[b];
			else
				n=0;
			printf("%d\n",n);
			if(n==0)
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 600
from itertools import accumulate
n = int(input())
a_list = list(map(int,input().split()))
cumsum = list(accumulate(a_list))
num_dict = {0:1}
for s in cumsum :
  if s in num_dict.keys():
    num_dict[s] += 1
  else:
    num_dict[s] = 1

res = 0
for val in num_dict.values():
  res += val * (val - 1)//2
  
print(res)
  

Measured memory_bytes: 41360
<?php
define("MOD", 10**9+7);
$n = int();
$A = ints();
$lcm = [];
foreach($A as $a){
    $f = factor($a);
    foreach($f as $num => $c){
        if(isset($lcm[$num])){
            chmax($lcm[$num], $c);
        }else{
            $lcm[$num] = $c;
        }
    }
}
$lcmNum = 1;
foreach($lcm as $num => $c){
    for($i = 0; $i < $c; $i++){
        $lcmNum *= $num;
        $lcmNum %= MOD;
    }
}
$sum = 0;
foreach($A as $a){
    $sum += divm($lcmNum, $a);
    $sum %= MOD;
}
echo $sum;

function factor($M){
    $rootM = $M**0.5+1;
    for($j = 2; $j <= $rootM; $j++){
        if($M%$j == 0){
            if(!isset($map[$j]))$map[$j] = 0;
            $map[$j]++;
            $M/=$j;
            $rootM = $M**0.5+1;
            $j--;
        }
    }
    if($M>1){
        if(!isset($map[$M]))$map[$M] = 0;
        $map[$M]++;
    }
    return $map;
}

function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}

//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}

//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}


Measured memory_bytes: 6648
//45
#include<iostream>

using namespace std;

int main(){
  for(int q,b,c,cc,qq;cin>>q>>b>>c>>cc>>qq,q;){
    int a=0;
    int n=b/cc;
    int r=b-n*cc;
    for(;;){
      int nr=r;
      int nn=n;
      while(nr<c){
	nr+=cc;
	nn--;
      }
      if(nn<0||a+1+nn<q||a+1>qq)break;
      a++;
      n=nn;
      r=nr-c;
    }
    if(a+n<q||a==0){
      cout<<"NA"<<endl;
    }else{
      cout<<a<<' '<<n<<endl;
    }
  }
  return 0;
}
	 

Measured memory_bytes: 1160
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var count = 0;
        var i = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        var odd = i.Where(x => x % 2 == 1).Count();
        var max = i.Max();
        var min = i.Min();
        i.RemoveAt(i.IndexOf(max));
        i.RemoveAt(i.IndexOf(min));
        var mid = i.Single();
        if (odd == 1)
        {
            count++;
            if (max % 2 == 0)
            {
                max++;
                if (min % 2 == 0)
                {
                    min++;
                }
                else
                {
                    mid++;
                }
            }
            else
            {
                min++;
                mid++;
            }
        }
        else if (odd == 2)
        {
            count++;
            if (max % 2 == 1)
            {
                max++;
                if (min % 2 == 1)
                {
                    min++;
                }
                else
                {
                    mid++;
                }
            }
            else
            {
                min++;
                mid++;
            }
        }
        Console.WriteLine(count + (max - mid) / 2 + (max - min) / 2);
    }
}


Measured memory_bytes: 11476
a,b,c,d = map(int,input().split())
if a%d==0:
    s = a//d
else:
    s = a//d + 1
if c%b ==0:
    r = c//b
else:
    r = c//b+1
if s >= r:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61788
def f(x):
  a=[]
  for i in range(1, int(pow(x, 1/2))+1, 1):
    if x%i==0:
      a.append(i)
      if x!=pow(i, 2):
        a.append(x//i)
        
  a.sort()
  return a

counter=0
N=int(input())
for i in range(1, N+1, 2):
  a=f(i)
  if len(a)==8:
    counter+=1
    
print(counter)


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

#include <ext/pb_ds/assoc_container.hpp>
template <class Key, class T>
using gp_hash_table = __gnu_pbds::gp_hash_table<Key, T>;

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const u64 B = 100'000'007ULL;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  V<pair<size_t, string>> S(N);
  REP(i, N) {
    string s;
    cin >> s;
    S[i] = {s.size(), s};
  }
  sort(S.begin(), S.end());
  V<gp_hash_table<u64, int>> mp(26);
  i64 ans = 0;
  REP(i, N) {
    int len = S[i].first;
    const string& ss = S[i].second;
    V<int> char_cnt(26);
    REP(j, len) {
      int ch = ss[j] - 'a';
      char_cnt[ch]++;
    }
    u64 shash = 0;
    u64 base = B;
    if (len > 1) {
      for (int j = len - 1; j >= 1; --j) {
        REP(c, 26) {
          if (char_cnt[c] > 0) {
            auto it = mp[c].find(shash);
            if (it == mp[c].end()) continue;
            ans += it->second;
          }
        }
        shash += base * ss[j];
        base *= B;
        --char_cnt[ss[j] - 'a'];
      }
    }
    int prefix = ss[0] - 'a';
    ++mp[prefix][shash];
  }
  cout << ans << endl;
}


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

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    int n;
    cin >> n;
    ll sol = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                int tmp = __gcd(i, j);
                sol += __gcd(tmp, k);
            }
        }
    }
    cout << sol;
}

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

typedef long long ll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define gcd(a, b) __gcd(a, b)
#define min3(a, b, c) min(c, min(a, b))
#define max3(a, b, c) max(c, max(a, b))

#define        MX        3005

int ara[MX];
ll dp[MX][MX][2];

void solve(int l, int r, bool who)
{
    if(l > r){
        dp[l][r][who] = 0;
        return;
    }
    ll &res = dp[l][r][who];

    if(res != -1) return;


    solve(l+1, r, !who);
    solve(l, r-1, !who);

    if(who) res = max(ara[l]+dp[l+1][r][!who], ara[r]+dp[l][r-1][!who]);
    else res = min(dp[l+1][r][!who]-ara[l], dp[l][r-1][!who]-ara[r]);

}

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

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

    RESET(dp, -1);
    solve(0, n-1, 1);

    cout<<dp[0][n-1][1]<<endl;
}


Measured memory_bytes: 144932
N = int(input())
raw_str = input().split()
temp = 1
breaked = 0

for i in raw_str:
    if int(i) > temp or int(i) < temp:
       breaked += 1
    else:
        temp += 1
        continue

if(breaked == N):
    if(raw_str[0] == '1'):
        print(0)
    else:
        print(-1)
else:
    print(breaked)


Measured memory_bytes: 17976
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
P=list(map(int,input().split()))
i=0
while i<n:
    if P[i]==i+1:
        i+=1
        count+=1
    i+=1
print(count)

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

int main(){
    string s;
    cin >> s;
    int ans;
    if(s == "SUN")ans = 7;
    else if(s == "MON")ans = 6;
    else if(s == "TUE")ans = 5;
    else if(s == "WED")ans = 4;
    else if(s == "THU")ans = 3;
    else if(s == "FRI")ans = 2;
    else if(s == "SAT")ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<math.h>
using namespace std;
int main(){
    int n;
    int m;
    cin>>n>>m;
//    set<pair<int,int>> points;
    int ans=0;
    for(int k=0;k<n;k++){
        double a,b;
        cin>>a>>b;
        pair<int,int> point(a,b);
//        if(points.count(point)){
//            continue;
//        }
//        points.insert(point);
        double an=sqrt(pow(a,2)+pow(b,2));
//        cout<<"ans: "<<an<<endl;
        if(an<=m){

           ans++;
//           cout<<"a"<<point.first<<" "<<point.second<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			B();
		}

		public static void B()
		{
			Scanner cin = new Scanner();
			int n = cin.NextInt();
			int[] hs = new int[n];
			for (int i = 0; i < n; ++i) {
				hs[i] = cin.NextInt();
			}

			int count = 1;
			int max = hs[0];
			for (int i = 1; i < n; ++i) {
				if (hs[i] >= max) {
					++count;
					max = hs[i];
				} 
			}

			Console.WriteLine(count);
		}



	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace  std;

using ll = long long;
const ll mod = 998244353;
typedef pair<int , int> pairs;
typedef complex<ll> G;
const int N = 1e6+5;

const int INF = 1e9+2;
void  done() {

}
void solve(){
    int k = 8;
    int n;cin >> n;
    for(int i = 600;i <=2000;i += 200) {
        if(n <= i-1) {
            cout << k;
            break;
        }
        k--;
    }

}

void another() {



}
void test_case() {
    int t;
    cin >> t;
    while(t--)another();
}
int main() {

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll a,b; cin >> a >> b;
  if((a+b)%2!=0) cout << "IMPOSSIBLE";
  else cout << (a+b)/2;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys, bisect, math, itertools
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

h, w = inpl()
maze = [list(input())[:-1] for _ in range(h)]
dp = [[0] * w for _ in range(h)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            continue
        left = dp[i][j-1] if j-1>=0 and maze[i][j-1] == "." else 0
        up = dp[i-1][j] if i-1>=0 and maze[i-1][j] == "." else 0
        dp[i][j] = left + up
print(dp[h-1][w-1] % mod)
# print(dp)

Measured memory_bytes: 249436
fun main(args: Array<String>) {
    val number=readLine()!!.toInt()
    var list = readLine()!!.split(" ").map(String::toInt)
    list=list.sorted()
    for (x in 0 until number-1){
        if (list[x]==list[x+1]){
            println("NO")
            return
        }
    }
    println("YES")
}

Measured memory_bytes: 79468
def main():
    n = int(input())
    xs, ys, hs = list(), list(), list()
    for i in range(n):
        x, y, h = map(int, input().split())
        xs.append(x)
        ys.append(y)
        hs.append(h)

    for cx in range(101):
        for cy in range(101):
            # In this case,
            # multiple candidates of H & 
            Hs = set()
            Hs_ub = set()
            for x, y, h in zip(xs, ys, hs):
                H_cand = h + abs(x - cx) + abs(y - cy)
                if h == 0:
                    Hs_ub.add(H_cand)
                else:
                    Hs.add(H_cand)

            if len(Hs) != 1:
                continue
            
            # accept No.9, reject 10 - 15
            Hs_rm = set()
            for H in Hs:
                if all([H <= H_ub for H_ub in Hs_ub]):
                    continue
                else:
                    Hs_rm.add(H)
            Hs = Hs - Hs_rm

            Hs = {H for H in Hs if H >= 1}
            if len(Hs) == 1:
                H = Hs.pop()
                print(cx, cy, H)
                return


if __name__ == "__main__":
    main()
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   string s;
   ll k;
   cin>>s>>k;

   ll n=s.size();

   rep(i,min(n,k)){
      if(s[i]!='1'){
         cout<<s[i];
         return 0;
      }
   }
   cout<<1<<endl;
   return 0;
}


Measured memory_bytes: 3624
program name
    implicit none
    integer(4):: d

    read*, d
    if (d == 25) then
        print*, 'Christmas'
    else if (d == 24) then
        print*, 'Christmas Eve'
    else if (d == 23) then
        print*, 'Christmas Eve Eve'
    else if (d == 22) then
        print*, 'Christmas Eve Eve Eve'
    end if
end program name

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

using namespace std;
							// Typedef's  start //
typedef long long   ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii > vpi;

							//	Typedef's end //
							//	Define's start //
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i < (b); i++)
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define endl '\n'

							// Define's end //
int main() {
	ios::sync_with_stdio(0);
		cin.tie(0);
	int n, k;
	cin >> n >> k;
	cout << (n%k > 0 ? 1 : 0 )<< endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int a[5],k;
	rep(i,5)
		cin >> a[i];
	cin >>k;
	bool flg=true;
	rep(i,5)
		rep(j,5)
			flg&=abs(a[i]-a[j])<=k;
	if (flg)
		cout <<"Yay!";
	else
		cout <<":(";


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
#define pb push_back 
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if(a == 0LL || b == 0LL)
        return max(a, b);
    return gcd(b%a, a);
}
 
ll lcm(ll a, ll b) {
    return a*b/(gcd(a, b));
}

int n, m;

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
   cin >> n >> m;
   set<int> st;
   for(int i=0; i<n; ++i) {
      int x;
      cin >> x;
      st.insert(x);
   }
   int mx = *st.rbegin();
   vector<int> v;
   ll l = 1ll;
   int flag = 0;
   for(int x: st) {
       v.pb(x); 
       if(!flag)
       		l = lcm(l, x);
       if(l > m) {
         flag = 1;
       }
   }
   int res = 0;
   for(int i=mx/2; i<=m; i+=mx) {
       int ok = 0;
       for(int x: v) {
           if(i%x == x/2)
               ++ok;
       }
       res += (ok == (int)v.size());
       if(res && !flag) {
         res += (m-i)/l;
         break;
       }
   }
   cout << res << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
} 

 




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

int main() {
        int n, m;
        cin >> n >> m;
        vector<int> a(n);
        rep(i, n) {
                cin >> a[i];
        }
        vector<vector<int>> g(n);
        map<pair<int, int>, int> mp;
        rep(i, m) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
                mp[minmax(a, b)] = i;
        }
        vector<int> ss;
        rep(i, n) {
                for (auto v : g[i]) {
                        if (a[i] == a[v]) {
                                ss.push_back(i);
                                break;
                        }
                }
        }
        if (ss.size() == 0) {
                cout << -1 << endl;
                return 0;
        }
        vector<bool> used(n);
        vector<int> color(n, -1);
        vector<int> ans(m);
        function<void (int, int, int)> dfs = [&](int u, int c, int o) {
                color[u] = c;
                for (auto v : g[u]) if (!used[v]) {
                        if (a[v] == o && a[u] == o) {
                                used[v] = true;
                                ans[mp[minmax(u, v)]] = o;
                                dfs(v, !c, o);
                        } else if (a[v] > a[u]) {
                                used[v] = true;
                                ans[mp[minmax(u, v)]] = a[v] - a[u];
                                dfs(v, c, o);
                        }
                }
        };
        sort(ss.begin(), ss.end(), [&](int p, int q) {
                return a[p] > a[q];
        });
        for (auto s : ss) if (!used[s]) {
                used[s] = true;
                dfs(s, 0, a[s]);
        }
        bool ok = true;
        rep(i, n) ok = ok && used[i];
        if (!ok) {
                cout << -1 << endl;
                return 0;
        }
        rep(i, m) {
                if (ans[i] == 0) {
                        ans[i] = 1e9;
                }
        }
        rep(i, n) cout << (color[i] == 1 ? 'B' : 'W');
        cout << endl;
        rep(i, m) cout << ans[i] << endl;
        return 0;
}



Measured memory_bytes: 24696
n=int(input())
a=input().split()
a=[int(i) for i in a]
l=0
r=0
s=sum(a)/2
for i in range(n):
	l=a[i]+l
	if l>=s and abs(l-s)>=abs(l-s-a[i]):
		print(int(abs(l-s-a[i])*2))
		exit()
	elif l>=s and abs(l-s)<=abs(l-s-a[i]):
		print(int(abs(s-l)*2))
		exit()

Measured memory_bytes: 26220
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define N (2000+100)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int n,k,u[N],v[N],dis[N],ans=2001;
int head[N],num_edge;
queue<int>q;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n-1; ++i)
	{
		scanf("%d%d",&u[i],&v[i]);
		add(u[i],v[i]); add(v[i],u[i]);
	}

	if (k%2==0)
	{
		for (int i=1; i<=n; ++i)
		{
			int cnt=1;
			memset(dis,-1,sizeof(dis));
			dis[i]=0; q.push(i);
			while (!q.empty())
			{
				int x=q.front(); q.pop();
				for (int j=head[x]; j; j=edge[j].next)
					if (dis[edge[j].to]==-1)
					{
						dis[edge[j].to]=dis[x]+1;
						if (dis[edge[j].to]<=k/2) cnt++;
						q.push(edge[j].to);
					}
			}
			ans=min(ans,n-cnt);
		}
	}
	else
	{
		for (int i=1; i<=n-1; ++i)
		{
			int cnt=2;
			memset(dis,-1,sizeof(dis));
			dis[u[i]]=dis[v[i]]=0; q.push(u[i]); q.push(v[i]);
			while (!q.empty())
			{
				int x=q.front(); q.pop();
				for (int j=head[x]; j; j=edge[j].next)
					if (dis[edge[j].to]==-1)
					{
						dis[edge[j].to]=dis[x]+1;
						if (dis[edge[j].to]<=k/2) cnt++;
						q.push(edge[j].to);
					}
			}
			ans=min(ans,n-cnt);
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class FPure {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N, M;
        in >> N >> M;
        vector<int> A(M), B(M);
        REP(i,0,M) in >> A[i] >> B[i];

        vector<unordered_set<int>> edges(N+1);
        REP(i,0,M) edges[A[i]].insert(B[i]);

        REP(start,1,N+1) {
            queue<int> que;
            que.push(start);
            unordered_map<int, int> fromWhere;
            bool found = false, wrong = false;
            while (!que.empty() && !found && !wrong) {
                const int current = que.front();
                que.pop();
                for (const auto next : edges[current]) {
                    if (fromWhere.find(next) != fromWhere.end() && next != start) {
                        wrong = true;
                        break;
                    }
                    fromWhere[next] = current;
                    if (next == start) {
                        found = true;
                        break;
                    }
                    que.push(next);
                }
            }
            if (found && !wrong) {
                vector<int> routes;
                int v = fromWhere[start];
                while (v != start) {
                    routes.push_back(v);
                    v = fromWhere[v];
                }
                routes.push_back(start);
                out << routes.size() << "\n";
                auto itr = routes.rbegin();
                while (itr != routes.rend()) {
                    out << *itr << "\n";
                    itr++;
                }
                return;
            }
        }
        out << -1 << "\n";
    }
};


int main() {
	FPure solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S; cin >> S;
  int ans = 0;
  rep(i,4) if(S[i]=='2') ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

////////////////////////////////////////


int main(){
    int n,m;cin>>n>>m;
    if(n>m)swap(n,m);
    
    if(n==1){
        if(m==1){
            cout<<1;
        }else{
            cout<<m-2;
        }
    }else{
        cout<<(ll)(n-2)*(ll)(m-2);
    }
    
    /*int s[n][m];memset(s,0,sizeof(s));
    rep(i,0,n-1){
        rep(j,0,m-1){
            rep(x,-1,1){
                rep(y,-1,1){
                    if(0<=i+x&&i+x<=n-1&&0<=j+y&&j+y<=m-1){
                        s[i][j]++;
                    }
                }
            }
        }
    }
    rep(i,0,n-1){
        rep(j,0,m-1){
            cout<<s[i][j];
        }cout<<endl;
    }*/
    
    
    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
Arr.forEach(function(v){
   v=v.replace(/@(\d)(.)/g,function(s,s1,s2){
      return Array((s1-0)+1).join(s2);
   });
   console.log(v);
});

Measured memory_bytes: 7640
#include<bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 2e5 + 10;
const int mod = 998244353;
int dp[N], qs[N];
pii p[25];
int main(){
	int n,k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= k; i++){
		scanf("%d %d", &p[i].st, &p[i].nd);
	}
	dp[1] = 1;
	for(int i = 1; i <= n; i++){
		qs[i] += qs[i - 1];
		qs[i] %= mod;
		dp[i] += qs[i];
		for(int j = 1; j <= k; j++){
			if(i + p[j].st > n) continue;
			int beg = i + p[j].st, des = min(n + 1, i + p[j].nd + 1);
			qs[beg] += dp[i], qs[des] += (mod - dp[i]);
			qs[beg] %= mod, qs[des] %= mod;
		}
	}
	printf("%d", dp[n]);
}

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

bool isp(int n) {
  if (n < 2) return false;
  else if (n == 2) return true;
  else if (n % 2 == 0) return false;
  for (int i = 3; i <= (int) sqrt(n); i += 2) if (n % i == 0) return false;
  return true;
}

int main() {
  int N;
  cin >> N;
  while (true) {
    if (isp(N)) return cout << N << "\n", 0;
    N++;
  }
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	bool flag = true;
	for (int i = 0; i < s.size() / 2; ++i) {
		if (s[i] != s[s.size() - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	int n = (s.size() - 1) / 2;
	for (int i = 0; i < n / 2; ++i) {
		if (s[i] != s[n - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = (s.size() + 3)/2; i < s.size() / 2; ++i) {
		if (s[i] != s[s.size() - 1 - i + (s.size() + 3) / 2]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	si arr[N+1];
	ll dp[N+5];

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

	memset(dp, 0, sizeof(dp));
	dp[2] = abs(arr[2]-arr[1]);

	for(int i=3;i<=N;i++){
		dp[i] += min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
	}

	cout << dp[N];

}

Measured memory_bytes: 1280
n = int(input().strip()) 
a = [int(x.strip()) for x in input().strip().split(' ')]

x = {}
sum = 0
for i in a:
  x[i] = (x[i] if i in x else 0) + 1
  sum = sum + i

q = int(input().strip())
for i in range(0, q):
  b, c = [int(x.strip()) for x in input().strip().split(' ')]
  if b in x and b != c:
    sum = sum + (c - b) * x[b]
    if c in x:
      x[c] = x[c] + x[b]
    else:
      x[c] = x[b]
    del x[b]    
  print(sum)

Measured memory_bytes: 86848
def isDaydream(s):
    while s != "":
        if s.endswith("dream"):
            s = s[:-5]
        elif s.endswith("dreamer"):
            s = s[:-7]
        elif s.endswith("erase"):
            s = s[:-5]
        elif s.endswith("eraser"):
            s = s[:-6]
        else :
            return False
    return True

if(isDaydream(input())):
    print("YES")
else:
    print("NO")
            
        

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int N, X;
const int MOD = 998244353;
int C[3030][3030];
int main(){
  scanf("%d%d", &N, &X);
  C[0][0] = 1;
  for(int i=1; i<=N; ++i)
  {
    C[i][0] = C[i][i] = 1;
    for(int j=1; j<i; ++j)
      C[i][j] = (C[i-1][j-1]+C[i-1][j])%MOD;
  }
  long long ans = 0;
  
  //case1 sum(a)<=X-1
  for(int c12=0; c12<=N; ++c12)
  {
    for(int s12=c12; s12<=min(c12*2, X-1); ++s12)
    {
      //        -#c12, sum s12   interleave 0
      ans += 1LL*C[c12][s12-c12]*C[N][c12];
      ans %= MOD;
    }
  }
  
  //case 2 sum(a) == X-1+2k
  
  int cc[3030]; memset(cc, 0, sizeof cc);  
  
  for(int k=1; k<=N; ++k)
  {
    int qq = X-1-2*k;
    if(qq>=0)
    {
      for(int c=(qq+1)/2; c<=qq; ++c)
      {
        if(c+2*k > N) break;
        //printf("%d %d %d\n", k, c, qq);
        cc[c+2*k] += C[c][qq-c];
        cc[c+2*k] %= MOD;
      }
    }
    else
    {
      //everything should be 2
      if( ((X-1)+2*k) %2 != 0) break;
      if( (X-1)+2*k > 2*N) break;
        ans += C[N][ ((X-1)+2*k)/2];
        ans %= MOD;
    }
  }
  
  for(int i=0; i<=N; ++i)
  {
    ans += 1LL*cc[i]*C[N][i];
    ans %= MOD;
  }
  printf("%lld\n", ans);
  return 0;
  
  
}

Measured memory_bytes: 34432